Example #1
0
    private void ProcessReadyToStart(GameServer gameServer, ReadyToStart msg, INetworkAddress address)
    {
        Debug.LogFormat("ReadyToStart, Address: {0}", address.ToString());

        var clientInfo = gameServer.GetClientInfoByAddress(address);

        if (clientInfo != null && clientInfo.IsReadyToStart)
        {
            return;
        }

        gameServer.SetReadyToStart(address);
    }
Example #2
0
    public void ProcessMessage(GameServer gameServer, NetworkMessage netMsg, INetworkAddress address)
    {
        if (netMsg.m_type != NetworkMessageType.JoinRequest && !gameServer.IsClientConnected(address))
        {
            Debug.LogFormat("Received the message {0} from not connected client {1}", netMsg.m_type, address.ToString());
            return;
        }

        switch (netMsg.m_type)
        {
        case NetworkMessageType.JoinRequest:
            ProcessJoinRequest(gameServer, netMsg.m_msg as JoinRequest, address);
            break;

        case NetworkMessageType.ReadyToStart:
            ProcessReadyToStart(gameServer, netMsg.m_msg as ReadyToStart, address);
            break;
        }
    }
Example #3
0
    private void ProcessJoinRequest(GameServer gameServer, JoinRequest msg, INetworkAddress address)
    {
        Debug.LogFormat("Join request from player {0}. Address {1}", msg.m_playerName, address.ToString());

        if (gameServer.GetClientCount() == 2)
        {
            Debug.Log("Server is full.");
            return;
        }

        if (gameServer.IsClientConnected(address))
        {
            Debug.Log("Client is already connected.");
            return;
        }

        gameServer.AddClient(new ClientInfo(msg.m_playerName, (byte)gameServer.GetClientCount(), address));
        gameServer.AcceptClient(address);

        //
        if (gameServer.GetClientCount() == 2)
        {
            gameServer.SendOpponentFound();
            gameServer.NotifyPlayersConnected();
        }
    }
    public void ProcessMessage(GameServer gameServer, NetworkMessage netMsg, INetworkAddress address)
    {
        if (!gameServer.IsClientConnected(address))
        {
            Debug.LogFormat("Received the message {0} from not connected client {1}", netMsg.m_type, address.ToString());
            return;
        }

        var clientInfo = gameServer.GetClientInfoByAddress(address);

        switch (netMsg.m_type)
        {
        case NetworkMessageType.PlayerMove:
        {
            var playerMove = netMsg.m_msg as PlayerMove;
            playerMove.m_team = clientInfo.Team;
            MatchMessage matchMsg = new MatchMessage();
            matchMsg.m_message     = playerMove;
            matchMsg.m_messageType = MessageType.PlayerMove;
            gameServer.AddMatchMessage(matchMsg);

            // Not sure it it supposed to be here.
            clientInfo.LastMsgNum = Mathf.Max(clientInfo.LastMsgNum, playerMove.m_messageNumber);
            break;
        }

        case NetworkMessageType.PlayerAction:
        {
            var msg = netMsg.m_msg as Action;
            msg.m_team = clientInfo.Team;
            MatchMessage matchMsg = new MatchMessage();
            matchMsg.m_message     = msg;
            matchMsg.m_messageType = MessageType.PlayerAction;
            gameServer.AddMatchMessage(matchMsg);

            // Not sure it it supposed to be here.
            clientInfo.LastMsgNum = Mathf.Max(clientInfo.LastMsgNum, msg.m_messageNumber);
            break;
        }
        }
    }