Example #1
0
        protected void OnUdpProtocolPeerEvent(UdpProtocolEvent evt, int queue)
        {
            OnUdpProtocolEvent(evt, QueueToPlayerHandle(queue));

            switch (evt.EventType)
            {
            case UdpProtocolEvent.Type.Input:
                var inputEvt = evt as InputEvent;
                if (!localConnectStatus[queue].Disconnected)
                {
                    int currentRemoteFrame = localConnectStatus[queue].LastFrame;
                    int newRemoteFrame     = inputEvt.Input.frame;
                    Log($"currentRemoteFrame: {currentRemoteFrame}  newRemoteFrame: {newRemoteFrame}");
                    Debug.Assert(currentRemoteFrame == -1 || newRemoteFrame == (currentRemoteFrame + 1));

                    GameInput input = inputEvt.Input;
                    sync.AddRemoteInput(queue, ref input);

                    // Notify the other endpoints which frame we received from a peer
                    Log($"setting remote connect status for queue {queue} to {input.frame}");
                    localConnectStatus[queue].LastFrame = input.frame;
                }
                break;

            case UdpProtocolEvent.Type.Disconnected:
                DisconnectPlayer(QueueToPlayerHandle(queue));
                break;
            }
        }