private void HandleCommand(LobbyServerCommands command)
    {
        switch (command)
        {
        case LobbyServerCommands.Connect:
            ConnectResponse();
            break;

        case LobbyServerCommands.CreateLobby:
            CreateLobbyResponse();
            break;

        case LobbyServerCommands.Disconnect:
            DisconnectResponse();
            break;

        case LobbyServerCommands.HeartBeat:
            HeartBeatResponse();
            break;

        case LobbyServerCommands.JoinLobby:
            JoinLobbyResponse();
            break;

        case LobbyServerCommands.LeaveLobby:
            LeaveLobbyResponse();
            break;

        case LobbyServerCommands.LobbyRequest:
            LobbyListResponse();
            break;

        case LobbyServerCommands.StartFailed:
            StartFailedResponse();
            break;

        case LobbyServerCommands.StartGame:
            LoadGameScene();
            break;

        case LobbyServerCommands.StartDelay:
            //TODO: deactivate the buttons so the client cant send several requests
            //waiting for server response
            _lobbyObject.SetActive(false);
            _lobbyTextField.text = "Game is starting, please wait.";
            break;
        }
    }
Exemplo n.º 2
0
        //handles the client input (will probably outsourced to another class)
        private void HandleClientInput(LobbyServerCommands command, int index)
        {
            switch (command)
            {
            case LobbyServerCommands.Connect:
                ConnectClient(_readers[index], _writers[index]);
                //tell the connected client that he is allowed to play and give him a network ID if he doesnt have one
                break;

            case LobbyServerCommands.CreateLobby:
                CreateLobbyForClient(index);
                //create a new lobby and put the client into this lobby
                break;

            case LobbyServerCommands.Disconnect:
                DisconnectClient(index);
                //get rid of this traitor
                break;

            case LobbyServerCommands.HeartBeat:
                HeartBeatResponse(index);
                //pfew this client is still here send a response back
                break;

            case LobbyServerCommands.JoinLobby:
                ClientJoinLobby(index);
                //put the client into an existing lobby send an error if it failed
                break;

            case LobbyServerCommands.LeaveLobby:
                ClientLeaveLobby(index);
                //remove the client from the lobby
                //if it is the last client in that lobby get rid of the lobby --> no ghosts allowed
                break;

            case LobbyServerCommands.StartGame:
                StartGame(index);
                //if the lobby is full the leader of the lobby can request to start the game
                //start a game instance with a specific port and send the ip and the port to the client so he can connect to that game
                //also tell the game instance the client networking ID´s so that the instance knows for which players he has to spawn player objects
                break;

            case LobbyServerCommands.LobbyRequest:
                LobbyListResponse(index);
                //send all the available lobby to the requesting player
                break;
            }
        }