Ejemplo n.º 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();
        }
    }
Ejemplo n.º 2
0
        private async Task HandleRequests(HttpContext context, Func <Task> next)
        {
            if (context.Request.Path == "/connect_client")
            {
                if (context.WebSockets.IsWebSocketRequest)
                {
                    WebSocket socket = await context.WebSockets.AcceptWebSocketAsync();

                    GameSocket gameSock = server.AcceptClient(socket);
                    await gameSock.Receive();
                }
                else
                {
                    context.Response.StatusCode = 400;
                }
            }
            else
            {
                await next();
            }
        }