Пример #1
0
        void OnConfirmation(int playerID, GameConfirmation confirmation)
        {
            if (confirmation.LockstepTurn < lockstepTurn)               // Discard
            {
                return;
            }

            if (confirmation.LockstepTurn > lockstepTurn + 2)
            {
                Debug.LogError("Lockstep : Confirmation from player " + playerID + " on impossible turn (> 2)");
                return;
            }

            uint turn = confirmation.LockstepTurn - lockstepTurn;

            NetworkUI.Log("Receive confirmation from player " + playerID + " for turn " + turn);

            if (confirmation.Wait)
            {
                NetworkUI.Log("Player " + playerID + " want me to wait, i'm too overhead !");
                wait[turn][playerID] = WaitingTime;
                return;
            }

            if (!playerHaveConfirmedMyAction[turn][playerID])
            {
                playerHaveConfirmedMyAction[turn][playerID] = true;
                ++numberOfPlayerWhoConfirmedMyAction[turn];
            }
            else
            {
                NetworkUI.Log("Confirmation allready received for LockstepTurn " + confirmation.LockstepTurn);
            }
        }
Пример #2
0
        public static void SendConfirmation(GameConfirmation confirmation)
        {
            byte[] buffer = confirmation.ToBytes();
            NetworkTransport.Send(hostId, connectionId, channelConfirmationId, buffer, buffer.Length, out error);

            if (error != (byte)NetworkError.Ok)
            {
                Debug.LogError("[ERROR] NetworkAPI :: SendConfirmation :: Send : " + error);
            }
        }
Пример #3
0
        void Update()
        {
            eventType = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, buffer, bufferSize, out dataSize, out error);
            if (error != (byte)NetworkError.Ok)
            {
                Debug.LogError("[ERROR] NetworkAPI :: Update :: Receive : " + error);
                if (dataSize > bufferSize)
                {
                    Debug.LogError("[ERROR] NetworkAPI :: Update : Message too big for be handled by buffer...");
                }
                return;
            }
            if (channelId == channelSetupId)
            {
                switch (eventType)
                {
                case NetworkEventType.ConnectEvent:
                    NetworkUI.Log("Connection on socket " + recHostId + ", connection : " + connectionId + ", channelId : " + channelId);
                    if (PlayerId == 0)
                    {
                        OnConnection();
                    }
                    break;

//					case NetworkEventType.DataEvent: break;
                case NetworkEventType.DisconnectEvent:
                    Application.Quit();                             // TEST quit on disconnect
                    break;
                }
            }
            else if (eventType == NetworkEventType.DataEvent)
            {
                if (channelId == channelActionId && OnAction != null)
                {
                    OnAction(PlayerId == 0 ? 1 : 0, GameActionFactory.Get(buffer));
                }
                else if (channelId == channelConfirmationId && OnConfirmation != null)
                {
                    OnConfirmation(PlayerId == 0 ? 1 : 0, GameConfirmation.FromBytes(buffer));
                }
            }
        }