コード例 #1
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();
        }
    }