Beispiel #1
0
        public void HandleSetName(AdressedMessage adressedMessage)
        {
            if (game.started)
            {
                SendRequestDenied(adressedMessage);
                return;
            }

            SetNameMessage setNameMessage = (SetNameMessage)adressedMessage.message;

            lobby.players[adressedMessage.connectionID].name = setNameMessage.Name;
            int connectionID = adressedMessage.connectionID;
            NewPlayerMessage newPlayerMessage = new NewPlayerMessage {
                PlayerID    = connectionID,
                PlayerColor = ColorExtentions.ToUInt(lobby.players[adressedMessage.connectionID].color),
                PlayerName  = lobby.players[adressedMessage.connectionID].name
            };

            //send new player to lobby
            foreach (KeyValuePair <int, Player> player in lobby.players)
            {
                if (player.Key == connectionID)
                {
                    continue;
                }
                serverBehaviour.QeueMessage(new AdressedMessage(newPlayerMessage, player.Key));
            }
        }
Beispiel #2
0
    public INetworkMessage ReadJoingingAreaMessages(NetworkConnection connection, DataStreamReader reader, Message message)
    {
        switch (message.messageType)
        {
        // Send a stay alive message.
        case MessageType.None:
            Send(connection, new Message(0, MessageType.None));
            return(null);

        // Set the name of the player and send NewPlayerMessages to all existing connections.
        case MessageType.SetName:
            var setNameMessage = new SetNameMessage(message.id);
            setNameMessage.Deserialize(ref reader);

            var playerInfo = playerInfoByID[connection.InternalId];
            playerInfo._name = setNameMessage._name;
            playerInfoByID.Remove(connection.InternalId);
            playerInfoByID.Add(connection.InternalId, playerInfo);
            var newPlayerMessage = new NewPlayerMessage(MessageID.nextID, connection.InternalId, playerInfo.color, setNameMessage.name);
            foreach (var otherConnection in connections)
            {
                if (otherConnection == connection)
                {
                    continue;
                }

                Send(otherConnection, newPlayerMessage);
            }

            return(setNameMessage);

        default:
            return(null);
        }
    }
    private void WelcomeFromServer(ref DataStreamReader reader)
    {
        var welcomeMessage = new WelcomeMessage();

        welcomeMessage.DeserializeObject(ref reader);
        dataHolder.myData.playerIndex = welcomeMessage.PlayerID;
        dataHolder.myData.color       = UIntToColor(welcomeMessage.Colour);

        var setNameMessage = new SetNameMessage
        {
            Name = DataBaseHandeler.userNickname
        };

        SendMessage(setNameMessage);
    }
        public void HandleWelcome(Message message)
        {
            WelcomeMessage welcomeMessage = (WelcomeMessage)message;
            Player         newPlayer      = new Player(welcomeMessage.Color);

            newPlayer.name = Login.Username;
            lobby.SetPlayer(welcomeMessage.PlayerID, newPlayer);
            Menu.Singleton.UpdateLobbyWindows(lobby);
            //immediately set player name
            var setNameMessage = new SetNameMessage {
                Name = Login.Username
            };

            clientBehaviour.QeueMessage(setNameMessage);
        }
Beispiel #5
0
    // Update is called once per frame
    void Update()
    {
        networkJobHandle.Complete();

        if (!connection.IsCreated)
        {
            return;
        }

        DataStreamReader reader;

        NetworkEvent.Type cmd;
        while ((cmd = connection.PopEvent(networkDriver, out reader)) != NetworkEvent.Type.Empty)
        {
            if (cmd == NetworkEvent.Type.Connect)
            {
                Debug.Log("Connected to server");
            }
            else if (cmd == NetworkEvent.Type.Data)
            {
                var messageType = (MessageHeader.MessageType)reader.ReadUShort();
                switch (messageType)
                {
                case MessageHeader.MessageType.None:
                    break;

                case MessageHeader.MessageType.NewPlayer:
                    break;

                case MessageHeader.MessageType.Welcome:
                    var welcomeMessage = new WelcomeMessage();
                    welcomeMessage.DeserializeObject(ref reader);

                    Debug.Log("Got a welcome message");

                    var setNameMessage = new SetNameMessage
                    {
                        Name = "Vincent"
                    };
                    var writer = networkDriver.BeginSend(connection);
                    setNameMessage.SerializeObject(ref writer);
                    networkDriver.EndSend(writer);
                    break;

                case MessageHeader.MessageType.SetName:
                    break;

                case MessageHeader.MessageType.RequestDenied:
                    break;

                case MessageHeader.MessageType.PlayerLeft:
                    break;

                case MessageHeader.MessageType.StartGame:
                    break;

                case MessageHeader.MessageType.Count:
                    break;

                default:
                    break;
                }
            }
            else if (cmd == NetworkEvent.Type.Disconnect)
            {
                Debug.Log("Disconnected from server");
                connection = default;
            }
        }

        networkJobHandle = networkDriver.ScheduleUpdate();
    }
Beispiel #6
0
    void Update()
    {
        networkJobHandle.Complete();

        for (int i = 0; i < connections.Length; ++i)
        {
            if (!connections[i].IsCreated)
            {
                connections.RemoveAtSwapBack(i);
                --i;
            }
        }

        NetworkConnection c;

        while ((c = networkDriver.Accept()) != default)
        {
            connections.Add(c);
            Debug.Log("Accepted connection");

            var colour  = (Color32)Color.magenta;
            var message = new WelcomeMessage
            {
                PlayerID = c.InternalId,
                Colour   = ((uint)colour.r << 24) | ((uint)colour.g << 16) | ((uint)colour.b << 8) | colour.a
            };

            var writer = networkDriver.BeginSend(c);
            message.SerializeObject(ref writer);
            networkDriver.EndSend(writer);
        }

        DataStreamReader reader;

        for (int i = 0; i < connections.Length; ++i)
        {
            if (!connections[i].IsCreated)
            {
                continue;
            }

            NetworkEvent.Type cmd;
            while ((cmd = networkDriver.PopEventForConnection(connections[i], out reader)) != NetworkEvent.Type.Empty)
            {
                if (cmd == NetworkEvent.Type.Data)
                {
                    var messageType = (MessageHeader.MessageType)reader.ReadUShort();
                    switch (messageType)
                    {
                    case MessageHeader.MessageType.None:
                        break;

                    case MessageHeader.MessageType.NewPlayer:
                        break;

                    case MessageHeader.MessageType.Welcome:
                        break;

                    case MessageHeader.MessageType.SetName:
                        var message = new SetNameMessage();
                        message.DeserializeObject(ref reader);
                        messagesQueue.Enqueue(message);
                        break;

                    case MessageHeader.MessageType.RequestDenied:
                        break;

                    case MessageHeader.MessageType.PlayerLeft:
                        break;

                    case MessageHeader.MessageType.StartGame:
                        break;

                    case MessageHeader.MessageType.Count:
                        break;

                    default:
                        break;
                    }
                }
                else if (cmd == NetworkEvent.Type.Disconnect)
                {
                    Debug.Log("Client disconnected");
                    connections[i] = default;
                }
            }
        }

        networkJobHandle = networkDriver.ScheduleUpdate();

        ProcessMessagesQueue();
    }
    void Update()
    {
        networkJobHandle.Complete();

        for (int i = 0; i < connections.Length; ++i)
        {
            if (!connections[i].IsCreated)
            {
                connections.RemoveAtSwapBack(i);
                --i;
            }
        }

        NetworkConnection newConnection;

        while ((newConnection = networkDriver.Accept()) != default)
        {
            if (connections.Length >= 4)
            {
                return;
            }
            connections.Add(newConnection);
            //Debug.Log("Accepted new connection");


            //new player data is set
            //Color col = Random.ColorHSV();
            Color col = ColorExtensions.colors[(ColorExtensions.RandomStartIndex + newConnection.InternalId) % ColorExtensions.colors.Length];
            col.a = 1;
            var colour         = (Color32)col;
            var playerID       = newConnection.InternalId;
            var welcomeMessage = new WelcomeMessage
            {
                PlayerID = playerID,
                Colour   = ((uint)colour.r << 24) | ((uint)colour.g << 16) | ((uint)colour.b << 8) | colour.a
            };
            SendMessage(welcomeMessage, newConnection);

            //save it to list
            PlayerData newData = new PlayerData();
            newData.color       = colour;
            newData.playerIndex = playerID;
            if (serverDataHolder.players == null)
            {
                serverDataHolder.players = new List <PlayerData>();
            }
            serverDataHolder.players.Add(newData);

            //Debug.Log("server data holder players count: " + serverDataHolder.players.Count);
        }

        DataStreamReader reader;

        for (int i = 0; i < connections.Length; ++i)
        {
            if (!connections[i].IsCreated)
            {
                continue;
            }

            NetworkEvent.Type cmd;
            while ((cmd = networkDriver.PopEventForConnection(connections[i], out reader)) != NetworkEvent.Type.Empty)
            {
                if (cmd == NetworkEvent.Type.Data)
                {
                    var messageType = (MessageHeader.MessageType)reader.ReadUShort();
                    switch (messageType)
                    {
                    case MessageHeader.MessageType.none:
                        StayAlive(i);
                        break;

                    case MessageHeader.MessageType.newPlayer:
                        break;

                    case MessageHeader.MessageType.welcome:
                        break;

                    case MessageHeader.MessageType.setName:
                        var message = new SetNameMessage();
                        message.DeserializeObject(ref reader);
                        messagesQueue.Enqueue(message);

                        PlayerData newPlayerData = GetPlayerData(connections[i]);
                        newPlayerData.name = message.Name;

                        NewPlayerJoined(connections[i]);

                        break;

                    case MessageHeader.MessageType.playerLeft:
                        break;

                    case MessageHeader.MessageType.moveRequest:
                        var moveRequest = new MoverequestMessage();
                        moveRequest.DeserializeObject(ref reader);
                        //messagesQueue.Enqueue(moveRequest);
                        bool canmove = HandleMoveRequest(moveRequest, i);
                        if (canmove)
                        {
                            NextPlayerTurn();
                        }
                        break;

                    case MessageHeader.MessageType.claimTreasureRequest:

                        var treasureRquest = new ClaimTreasureRequestMessage();
                        treasureRquest.DeserializeObject(ref reader);
                        HandleTreasureClaim(treasureRquest, i);
                        break;

                    case MessageHeader.MessageType.leaveDungeonRequest:
                        var leaveDungeonRequest = new LeavesDungeonRequestMessage();
                        leaveDungeonRequest.DeserializeObject(ref reader);
                        HandleLeaveDungeonRequest(leaveDungeonRequest, i);
                        break;

                    case MessageHeader.MessageType.defendRequest:
                        var defendRequest = new DefendRequestMessage();
                        defendRequest.DeserializeObject(ref reader);
                        HandleDefendRequest(defendRequest, i);
                        break;

                    case MessageHeader.MessageType.attackRequest:
                        var attackRequest = new AttackRequestMessage();
                        attackRequest.DeserializeObject(ref reader);
                        HandleAttackRequest(attackRequest, i);
                        break;

                    default:
                        break;
                    }
                }
                else if (cmd == NetworkEvent.Type.Disconnect)
                {
                    PlayerLeftMessage playerLeftMessage = new PlayerLeftMessage
                    {
                        PlayerLeftID = i
                    };

                    SendMessageToAll(playerLeftMessage);
                    Debug.Log("Client disconnected");
                    connections[i] = default;
                }
            }
        }

        networkJobHandle = networkDriver.ScheduleUpdate();

        ProcessMessagesQueue();
    }
Beispiel #8
0
    void Update()
    {
        networkJobHandle.Complete();
        for (int i = 0; i < connections.Length; ++i)
        {
            if (!connections[i].IsCreated)
            {
                connections.RemoveAtSwapBack(i);
                --i;
            }
        }

        NetworkConnection c;

        while ((c = networkDriver.Accept()) != default)
        {
            if (GameHasStarted)
            {
                MakeRequestDeniedMessage(c, 0);
                c.Disconnect(networkDriver);
                return;
            }

            if (connections.Length > 4)
            {
                MakeRequestDeniedMessage(c, 1);
                c.Disconnect(networkDriver);
                return;
            }

            //Accepted Connection
            connections.Add(c);

            var colour         = (Color32)UnityEngine.Random.ColorHSV();
            var welcomeMessage = new WelcomeMessage
            {
                PlayerID = playerID,
                Colour   = ((uint)colour.r << 24) | ((uint)colour.g << 16) | ((uint)colour.b << 8) | colour.a
            };

            PlayerManager.Instance.Players.Add(new Players(playerID, "", welcomeMessage.Colour));
            playerID++;
            NetworkManager.SendMessage(networkDriver, welcomeMessage, c);
        }

        DataStreamReader reader;

        for (int i = 0; i < connections.Length; ++i)
        {
            if (!connections[i].IsCreated)
            {
                continue;
            }

            NetworkEvent.Type cmd;
            while ((cmd = networkDriver.PopEventForConnection(connections[i], out reader)) != NetworkEvent.Type.Empty)
            {
                if (cmd == NetworkEvent.Type.Data)
                {
                    var messageType = (MessageHeader.MessageType)reader.ReadUShort();
                    switch (messageType)
                    {
                    case MessageHeader.MessageType.None:
                        var noneMessage = NetworkManager.ReadMessage <StayAliveMessage>(reader, ServerMessageQueue);
                        NetworkManager.SendMessage(networkDriver, noneMessage, connections[i]);
                        break;

                    case MessageHeader.MessageType.SetName:
                        SetNameMessage setNameMessage = NetworkManager.ReadMessage <SetNameMessage>(reader, ServerMessageQueue) as SetNameMessage;
                        PlayerManager.Instance.Players[i].clientName = setNameMessage.Name;

                        var newPlayerMessage = new NewPlayerMessage()
                        {
                            PlayerID    = PlayerManager.Instance.Players[i].playerID,
                            PlayerColor = PlayerManager.Instance.Players[i].clientColor,
                            PlayerName  = setNameMessage.Name
                        };

                        //looping through all the connections to send the new player message
                        for (int j = 0; j < connections.Length; j++)
                        {
                            if (j != i)
                            {
                                NetworkManager.SendMessage(networkDriver, newPlayerMessage, connections[j]);

                                var connectedPlayersMessage = new NewPlayerMessage()
                                {
                                    PlayerID    = PlayerManager.Instance.Players[j].playerID,
                                    PlayerColor = PlayerManager.Instance.Players[j].clientColor,
                                    PlayerName  = PlayerManager.Instance.Players[j].clientName
                                };
                                NetworkManager.SendMessage(networkDriver, connectedPlayersMessage, connections[i]);
                            }
                        }

                        break;

                    case MessageHeader.MessageType.PlayerLeft:
                        PlayerLeftMessage leftMessage = NetworkManager.ReadMessage <PlayerLeftMessage>(reader, ServerMessageQueue) as PlayerLeftMessage;
                        leftMessage.playerLeftID = (uint)i;

                        for (int j = 0; j < connections.Length; j++)
                        {
                            if (leftMessage.playerLeftID != PlayerManager.Instance.Players[i].playerID)
                            {
                                NetworkManager.SendMessage(networkDriver, leftMessage, connections[i]);
                            }
                        }
                        connections[i] = default;
                        break;

                    case MessageHeader.MessageType.MoveRequest:
                        var moveRequest = NetworkManager.ReadMessage <MoveRequest>(reader, ServerMessageQueue);
                        Debug.Log("MoveRequest");
                        if (CheckTileContent(i, TileContent.Monster) || CheckTileContent(i, TileContent.Both))
                        {
                            MakeRequestDeniedMessage(i, 2);
                            SendNewRoomInfo();
                            return;
                        }

                        MakeLeaveRoomMessage(i);
                        PlayerManager.Instance.MovePlayer(moveRequest, i);
                        MakeEnterRoommessage(i);

                        SendNewRoomInfo();
                        MonsterTurn();
                        NewTurnMessage();
                        break;

                    case MessageHeader.MessageType.AttackRequest:
                        var request = NetworkManager.ReadMessage <AttackRequestMessage>(reader, serverMessagesQueue);
                        Debug.Log(DebugTileContent(i));

                        if (!CheckTileContent(i, TileContent.Monster) && !CheckTileContent(i, TileContent.Both))
                        {
                            Debug.Log(CheckTileContent(i, TileContent.Monster));
                            Debug.Log(CheckTileContent(i, TileContent.Both));

                            MakeRequestDeniedMessage(i, 4);
                            SendNewRoomInfo();
                            return;
                        }

                        if (CheckTileContent(i, TileContent.Monster))
                        {
                            SetTileContent(i, TileContent.None);
                        }
                        if (CheckTileContent(i, TileContent.Both))
                        {
                            SetTileContent(i, TileContent.Treasure);
                        }


                        var message = new HitMonsterMessage();
                        NetworkManager.SendMessage(networkDriver, message, connections[i]);
                        SendNewRoomInfo();
                        NewTurnMessage();
                        MonsterTurn();
                        break;

                    case MessageHeader.MessageType.DefendRequest:
                        NetworkManager.ReadMessage <DefendRequestMessage>(reader, serverMessagesQueue);
                        PlayerManager.Instance.Players[i].DefendOneTurn = true;
                        var playerDefendMessage = new PlayerDefendsMessage()
                        {
                            PlayerID = PlayerManager.Instance.Players[i].playerID
                        };

                        Debug.Log(connections.Length);
                        for (int j = 0; j < connections.Length; j++)
                        {
                            NetworkManager.SendMessage(networkDriver, playerDefendMessage, connections[j]);
                        }

                        SendNewRoomInfo();
                        NewTurnMessage();
                        MonsterTurn();
                        break;

                    case MessageHeader.MessageType.ObtainTreasureRequest:
                        NetworkManager.ReadMessage <ClaimTreasureRequestMessage>(reader, serverMessagesQueue);

                        if (!CheckTileContent(i, TileContent.Treasure) && !CheckTileContent(i, TileContent.Both))
                        {
                            MakeRequestDeniedMessage(i, 5);
                            SendNewRoomInfo();
                            return;
                        }
                        if (CheckTileContent(i, TileContent.Both))
                        {
                            MakeRequestDeniedMessage(i, 6);
                            SendNewRoomInfo();
                            return;
                        }

                        Dictionary <Players, uint> players = PlayerManager.Instance.ClaimTreasureDivideItForPlayers(i);

                        uint amount;

                        int SendedItem = 0;

                        foreach (KeyValuePair <Players, uint> item in players)
                        {
                            amount = item.Value;
                            ObtainTreasureMessage obtainTreasure = new ObtainTreasureMessage()
                            {
                                Amount = (ushort)amount
                            };

                            for (int j = 0; j < PlayerManager.Instance.Players.Count; j++)
                            {
                                if (PlayerManager.Instance.Players[j].playerID == item.Key.playerID)
                                {
                                    NetworkManager.SendMessage(networkDriver, obtainTreasure, connections[j]);
                                    SendedItem++;
                                }
                            }
                        }

                        SetTileContent(i, TileContent.None);
                        SendNewRoomInfo();
                        MonsterTurn();
                        NewTurnMessage();
                        break;


                    case MessageHeader.MessageType.LeaveDungeonRequest:
                        NetworkManager.ReadMessage <LeaveDungeonRequest>(reader, serverMessagesQueue);
                        PlayerManager.Instance.PlayersWhoLeft.Add(PlayerManager.Instance.Players[i]);

                        PlayerLeftDungeonMessage playerLeftDungeonMessage = new PlayerLeftDungeonMessage()
                        {
                            playerID = i
                        };

                        PlayerManager.Instance.Players.RemoveAt(i);

                        for (int j = 0; j < connections.Length; j++)
                        {
                            if (i != j)
                            {
                                NetworkManager.SendMessage(networkDriver, playerLeftDungeonMessage, connections[j]);
                            }
                        }

                        if (PlayerManager.Instance.Players.Count < 1)
                        {
                            EndGameMessage endGameMessage = new EndGameMessage();
                            for (int j = 0; j < PlayerManager.Instance.PlayersWhoLeft.Count; j++)
                            {
                                endGameMessage.playerID.Add(PlayerManager.Instance.PlayersWhoLeft[j].playerID);
                                endGameMessage.highScorePairs.Add((ushort)PlayerManager.Instance.PlayersWhoLeft[j].treasureAmount);
                                NetworkManager.SendMessage(networkDriver, endGameMessage, connections[j]);
                                connections[j].Disconnect(networkDriver);
                            }
                        }
                        else
                        {
                            MonsterTurn();
                            SendNewRoomInfo();
                            NewTurnMessage();
                        }
                        break;
                    }
                }
                else if (cmd == NetworkEvent.Type.Disconnect)
                {
                    PlayerLeftMessage leftMessage = new PlayerLeftMessage();
                    leftMessage.playerLeftID = (uint)i;

                    for (int j = 0; j < connections.Length; j++)
                    {
                        if (leftMessage.playerLeftID != PlayerManager.Instance.Players[j].playerID)
                        {
                            NetworkManager.SendMessage(networkDriver, leftMessage, connections[j]);
                        }
                    }

                    Debug.Log("Client disconnected");
                    connections[i] = default;
                }
            }
        }

        networkJobHandle = networkDriver.ScheduleUpdate();

        ProcessMessagesQueue();
    }
    public void Update()
    {
        networkJobHandle.Complete();

        for (int i = 0; i < connections.Length; ++i)
        {
            if (!connections[i].IsCreated)
            {
                connections.RemoveAtSwapBack(i);
                --i;
            }
        }

        NetworkConnection c;

        while (!serverManager.game.started && serverManager.lobby.players.Count < ServerManager.maxPlayers && (c = networkDriver.Accept()) != default)
        {
            connections.Add(c);
            Debug.Log("Accepted connection");
            serverManager.HandleNewConnection(c.InternalId);
        }

        DataStreamReader reader;

        for (int i = 0; i < connections.Length; ++i)
        {
            if (!connections[i].IsCreated)
            {
                continue;
            }

            NetworkEvent.Type cmd;
            while ((cmd = networkDriver.PopEventForConnection(connections[i], out reader)) != NetworkEvent.Type.Empty)
            {
                if (cmd == NetworkEvent.Type.Data)
                {
                    var messageType = (Message.MessageType)reader.ReadUShort();
                    Debug.Log("Host Received: " + messageType + " from " + connections[i].InternalId);

                    Message message = null;
                    switch (messageType)
                    {
                    case Message.MessageType.None: break;     //stay alive

                    case Message.MessageType.SetName: message = new SetNameMessage(); break;

                    case Message.MessageType.MoveRequest: message = new MoveRequestMessage(); break;

                    case Message.MessageType.AttackRequest: message = new AttackRequestMessage(); break;

                    case Message.MessageType.DefendRequest: message = new DefendRequestMessage(); break;

                    case Message.MessageType.ClaimTreasureRequest: message = new ClaimTreasureRequestMessage(); break;

                    case Message.MessageType.LeaveDungeonRequest: message = new LeaveDungeonRequestMessage(); break;

                    default: break;
                    }
                    if (message != null)
                    {
                        message.DeserializeObject(ref reader);
                        receivedMessagesQueue.Enqueue(new AdressedMessage(message, connections[i].InternalId));
                    }
                }
                else if (cmd == NetworkEvent.Type.Disconnect)
                {
                    Debug.Log("Client disconnected");
                    serverManager.HandleDisconnect(connections[i].InternalId);
                    connections[i] = default;
                }
            }
        }

        ProcessMessagesQueue();

        //order slightly wrong but will be sent next cycle
        foreach (KeyValuePair <int, float> lastSendTime in lastSendTimes)
        {
            if (Time.time - lastSendTime.Value > STAY_ALIVE_AFTER_SECONDS)
            {
                QeueMessage(new AdressedMessage(new NoneMessage(), lastSendTime.Key));
            }
        }
        networkJobHandle = networkDriver.ScheduleUpdate();
    }
    // Update is called once per frame
    private void Update()
    {
        networkJobHandle.Complete();

        if (!connection.IsCreated)
        {
            return;
        }

        DataStreamReader reader;

        NetworkEvent.Type cmd;
        while ((cmd = connection.PopEvent(networkDriver, out reader)) != NetworkEvent.Type.Empty)
        {
            if (cmd == NetworkEvent.Type.Connect)
            {
            }
            else if (cmd == NetworkEvent.Type.Data)
            {
                var messageType = (MessageHeader.MessageType)reader.ReadUShort();
                switch (messageType)
                {
                case MessageHeader.MessageType.None:
                    var stayAliveMessage = NetworkManager.ReadMessage <StayAliveMessage>(reader, clientMessagesQueue) as StayAliveMessage;
                    TimerManager.Instance.AddTimer(StayAlive, 10);
                    break;

                case MessageHeader.MessageType.NewPlayer:
                    NewPlayerMessage newPlayerMessage = (NewPlayerMessage)NetworkManager.ReadMessage <NewPlayerMessage>(reader, clientMessagesQueue);
                    break;

                case MessageHeader.MessageType.Welcome:
                    var welcomeMessage = (WelcomeMessage)NetworkManager.ReadMessage <WelcomeMessage>(reader, clientMessagesQueue) as WelcomeMessage;

                    var setNameMessage = new SetNameMessage
                    {
                        Name = playerName
                    };

                    Players currentPlayer = new Players(welcomeMessage.PlayerID, playerName, welcomeMessage.Colour);
                    PlayerManager.Instance.CurrentPlayer = currentPlayer;
                    UIManager.Instance.SpawnPlayerLabel(currentPlayer);
                    PlayerManager.Instance.SpawnSprite(currentPlayer);
                    NetworkManager.SendMessage(networkDriver, setNameMessage, connection);
                    break;

                case MessageHeader.MessageType.RequestDenied:
                    NetworkManager.ReadMessage <RequestDeniedMessage>(reader, clientMessagesQueue);
                    break;

                case MessageHeader.MessageType.PlayerLeft:
                    NetworkManager.ReadMessage <PlayerLeftMessage>(reader, clientMessagesQueue);
                    break;

                case MessageHeader.MessageType.StartGame:
                    PlayerManager.Instance.SortingPlayerList();
                    NetworkManager.ReadMessage <StartGameMessage>(reader, clientMessagesQueue);
                    break;

                case MessageHeader.MessageType.PlayerTurn:
                    NetworkManager.ReadMessage <PlayerTurnMessage>(reader, clientMessagesQueue);
                    break;

                case MessageHeader.MessageType.RoomInfo:
                    NetworkManager.ReadMessage <RoomInfoMessage>(reader, clientMessagesQueue);
                    break;

                case MessageHeader.MessageType.PlayerEnterRoom:
                    NetworkManager.ReadMessage <PlayerLeaveRoomMessage>(reader, clientMessagesQueue);
                    break;

                case MessageHeader.MessageType.PlayerLeaveRoom:
                    NetworkManager.ReadMessage <PlayerLeaveRoomMessage>(reader, clientMessagesQueue);
                    break;

                case MessageHeader.MessageType.ObtainTreasure:
                    NetworkManager.ReadMessage <ObtainTreasureMessage>(reader, clientMessagesQueue);
                    break;

                case MessageHeader.MessageType.HitMonster:
                    NetworkManager.ReadMessage <HitMonsterMessage>(reader, clientMessagesQueue);
                    break;

                case MessageHeader.MessageType.HitByMonster:
                    NetworkManager.ReadMessage <HitByMonsterMessage>(reader, clientMessagesQueue);
                    break;

                case MessageHeader.MessageType.PlayerDefends:
                    NetworkManager.ReadMessage <PlayerDefendsMessage>(reader, clientMessagesQueue);
                    break;

                case MessageHeader.MessageType.PlayerLeftDungeon:
                    NetworkManager.ReadMessage <PlayerLeftDungeonMessage>(reader, clientMessagesQueue);
                    break;

                case MessageHeader.MessageType.PlayerDies:
                    NetworkManager.ReadMessage <PlayerDiesMessage>(reader, clientMessagesQueue);
                    connection.Disconnect(networkDriver);
                    break;

                case MessageHeader.MessageType.EndGame:
                    NetworkManager.ReadMessage <EndGameMessage>(reader, clientMessagesQueue);
                    break;
                }
            }
            else if (cmd == NetworkEvent.Type.Disconnect)
            {
                Debug.Log("Disconnected from server");
                UIManager.Instance.DisconnectedPanel();
                connection = default;
            }
        }

        networkJobHandle = networkDriver.ScheduleUpdate();

        ProcessMessagesQueue();
    }