Ask a Question

Ask a Question
Back to All

Ghost events when SimClient connects to a network

I'm encountering an issue that I can't seem to resolve.

I've observed that when I create a new SimClient, set up its event handlers, and initialize it, I encounter one of two situations, depending on the time elapsed since the last opening of a SimNetworkEventStream with the same matchId/roomName:

  1. I receive all the events and ticks from the entire previous session, which uselessly triggers the relevant event handlers. This occurs within approximately 1 minute of the last SimNetwork connection to the room.
  2. I don't receive any information from the previous session, and the ticks start from 0. This happens after approximately 1 minute since the last SimNetwork connection to that room.

The problem lies in the fact that I cannot determine from the code which case it is, making it challenging to decide how to handle these "ghost events" coming from a previous, yet fresh, run of my game.

        _multiplayerData.localPlayerDbid = GameManager.Instance.BeamContext.PlayerId;
        _multiplayerData.matchId = matchId;
        _multiplayerData.sessionState = SessionState.Initializing;

        // Create Multiplayer Session
        SimNetworkEventStream networkEventStream;
        networkEventStream = new SimNetworkEventStream(_multiplayerData.matchId, GameManager.Instance.BeamContext.ServiceProvider);
        _simClient = new SimClient(networkEventStream, framesPerSecond, targetNetworkLead);

        // Handle Common Events
        _simClient.OnInit(SimClient_OnInit);
        _simClient.OnConnect(SimClient_OnConnect);
        _simClient.OnDisconnect(SimClient_OnDisconnect);
        _simClient.OnTick(SimClient_OnTick);
        _simClient.OnErrorStarted += (e) =>
        {
            // TODO: show "connecting to server error message"
            Debug.Log($"Sim Client Errors Starting... {e.ErrorMessage}");
        };
        _simClient.OnErrorRecovered += (r) =>
        {
            // TODO: remove any error UI and resume the game
            Debug.Log($"Sim Client disaster averted...");
        };
        _simClient.OnErrorFailed += r =>
        {
            // TODO: force exit the match, because the network is too unstable to continue or recover.
            Debug.Log($"Sim Client wasn't able to recover. {r.ErrorMessage}");
        };