Example #1
0
        private async Task CheckPlayerSetup(ClientMessage route, WebSocket websocket)
        {
            command = "UpdatePlayerSetup";
            bool playerSetupOK = true;

            if (!game.IsUserNameAvailable(route.Name))
            {
                playerSetupOK = false;
            }
            else
            {
                game.AssignUserName(route.Name, route.From);
                game.AssignIcon(route.Icon, route.From);
                // the icon on pos route.Icon is not available
                availableIcons[route.Icon] = false;
                game.GetPlayer(route.From).waitingRoomState = WaitingRoomState.Ready;
            }
            // send setup result to the user's websocket
            await SendJSON(websocket, new { command, playerSetupOK });

            // update other players' availableIcons list
            command = "UpdateAvailableIcons";
            int readyPlayers = game.GetNumberOfReadyPlayers();

            await DistributeJSONToWebSockets(new { command, availableIcons, readyPlayers });
        }