Exemplo n.º 1
0
        private void HandleSelectServerMessage(String address, AbstractMessage message)
        {
            if (serverStatus == ServerStatus.WaitingPlayer)
            {
                SelectServerMessage selectServerMessage = (SelectServerMessage)message;

                Player player = new Player(IPAddress.Parse(address));

                if (selectServerMessage.PlayerName == controller.GetLocalPlayer().Name)
                {
                    selectServerMessage.PlayerName += "2";
                }

                player.Name = selectServerMessage.PlayerName;

                controller.AddPlayer(player.IPAddress, player);

                selectServerMessage.RemotePlayerName = controller.GetLocalPlayer().Name;
                selectServerMessage.Success          = true;

                controller.Server.SendData(player.IPAddress, selectServerMessage);

                if (controller.GetPlayers().Count == Constants.MAX_PLAYERS)
                {
                    serverStatus = ServerStatus.WaitingCharacterSelection;

                    controller.Server.StopSendBroadCast();
                    controller.Server.SendToAll(new CharacterSelectionMessage());
                    controller.Server.StartPing();
                }
            }
        }
Exemplo n.º 2
0
        private void HandleSelectServerMessage(String address, AbstractMessage message)
        {
            if (clientStatus == ClientStatus.WaitingApproval)
            {
                SelectServerMessage selectServerMessage = (SelectServerMessage)message;

                if (selectServerMessage.Success)
                {
                    if (!controller.IsServer)
                    {
                        controller.GetLocalPlayer().Name = selectServerMessage.PlayerName;

                        Player player = new Player(IPAddress.Parse(address));
                        player.Name = selectServerMessage.RemotePlayerName;
                        controller.AddPlayer(player.IPAddress, player);
                    }

                    clientStatus = ClientStatus.WaitingPlayers;

                    if (address != IPAddress.Loopback.ToString())
                    {
                        controller.SupressUpdate();
                    }
                    ScreenManager.GetInstance().RemoveLastScreen();
                    ScreenManager.GetInstance().AddScreen(new WaitingPlayerScreen());
                    controller.ReleaseUpdate();
                }
            }
        }