Exemplo n.º 1
0
        private PlayersMessage CreatePlayerMessage(MessageOperation operation, IPlayerID playerID)
        {
            List <PlayerInfo> list = new List <PlayerInfo>();
            PlayersMessage    msg  = (PlayersMessage)MessageFactory.Create(MessageType.Players);

            msg.Operation = (byte)operation;
            switch (operation)
            {
            case MessageOperation.List:
                foreach (IPlayerID pid in _players.Values)
                {
                    if (pid.GetID() != playerID.GetID())
                    {
                        ServerPlayerInfo spi = pid as ServerPlayerInfo;
                        list.Add(spi.GePlayerInfo());
                    }
                }
                break;

            case MessageOperation.Add:
                list.Add(((ServerPlayerInfo)playerID).GePlayerInfo());
                break;

            case MessageOperation.Remove:
                list.Add(((ServerPlayerInfo)playerID).GePlayerInfo());
                break;

            case MessageOperation.Modify:
                list.Add(((ServerPlayerInfo)playerID).GePlayerInfo());
                break;
            }
            msg.PlayerList = list;
            return(msg);
        }
Exemplo n.º 2
0
        public override void AddPlayer(IPlayerID player)
        {
            base.AddPlayer(player);
            PlayersMessage pim = CreatePlayerMessage(MessageOperation.Modify, (ServerPlayerInfo)_players[player.GetID()]);

            SendMessage(pim, player.GetID());
            CancelGameStart();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Process plater data modification
        /// </summary>
        /// <param name="playersMessage"></param>
        private void ProcessPlayers(PlayersMessage playersMessage)
        {
            Player player = _server.GetPlayer(playersMessage.SenderId);

            InfoLog.WriteInfo(string.Format(ProcessStringFormat, "Start Game", player.Login), EPrefix.ServerProcessInfo);
            if (player == null || player.State != MenuState.GameJoin)
            {
                return;
            }
            _server.GameManager.ModifyPlayer(player.Id, playersMessage.PlayerList[0]);
        }
Exemplo n.º 4
0
 public override void RemovePlayer(IPlayerID playerID)
 {
     base.RemovePlayer(playerID);
     lock (((ICollection)_players).SyncRoot) {
         CancelGameStart();
         if (RepairTeams())
         {
             PlayersMessage msg = CreatePlayerMessage(MessageOperation.Modify, _players.GetEnumerator().Current.Value);
             BroadcastExcl(msg, -1);
         }
     }
 }
Exemplo n.º 5
0
        public void ProcessMessage(Message message)
        {
            handlerSuspender.WaitOne();
            switch (message.Type)
            {
            case MessageType.Result:
            {
                ResultMessage result = message as ResultMessage;
                switch ((ResponseType)result.ResponseType)
                {
                case ResponseType.Login:
                    if (LoginRequestReply != null)
                    {
                        LoginRequestReply(this, new RequestReplyEventArgs(!Convert.ToBoolean(result.Result), ((ResultType)(result.Result)).ToString()));
                    }
                    break;

                case ResponseType.Register:
                    if (RegisterRequestReply != null)
                    {
                        RegisterRequestReply(this, new RequestReplyEventArgs(!Convert.ToBoolean(result.Result), ((ResultType)(result.Result)).ToString()));
                    }
                    break;

                case ResponseType.Remind:
                    if (RemindRequestReply != null)
                    {
                        RemindRequestReply(this, new RequestReplyEventArgs(!Convert.ToBoolean(result.Result), ((ResultType)(result.Result)).ToString()));
                    }
                    break;

                case ResponseType.CreateGame:
                    if (CreateGameRequestReply != null)
                    {
                        CreateGameRequestReply(this, new RequestReplyEventArgs(!Convert.ToBoolean(result.Result), ((ResultType)(result.Result)).ToString()));
                    }
                    break;

                case ResponseType.JoinGame:
                    if (JoinGameRequestReply != null)
                    {
                        JoinGameRequestReply(this, new RequestReplyEventArgs(!Convert.ToBoolean(result.Result), ((ResultType)(result.Result)).ToString()));
                    }
                    break;

                case ResponseType.StartGame:
                    if (StartGameRequestReply != null)
                    {
                        StartGameRequestReply(this, new RequestReplyEventArgs(!Convert.ToBoolean(result.Result), ((ResultType)(result.Result)).ToString()));
                    }
                    break;
                }
            }
            break;

            case MessageType.IdInformation:
            {
                NumericMessage numericMessage = message as NumericMessage;
                ClientPlayerInfo.SenderId = (short)numericMessage.Number;
            }
            break;

            case MessageType.ChatUsers:
            {
                ChatUsersMessage chatMessage = message as ChatUsersMessage;
                switch ((MessageOperation)chatMessage.Option)
                {
                case MessageOperation.Add:
                    if (NewChatUsers != null)
                    {
                        NewChatUsers(this, new ChatEventArgs(chatMessage.ChatUsers.ToArray()));
                    }
                    break;

                case MessageOperation.Remove:
                    if (DeleteChatUsers != null)
                    {
                        DeleteChatUsers(this, new ChatEventArgs(chatMessage.ChatUsers.ToArray()));
                    }
                    break;

                case MessageOperation.List:
                    if (ResetChatUsers != null)
                    {
                        ResetChatUsers(this, new ChatEventArgs(chatMessage.ChatUsers.ToArray()));
                    }
                    break;
                }
            }
            break;

            case MessageType.ChatText:
                if (ChatTextReceive != null)
                {
                    TextMessage textMessage = message as TextMessage;
                    ChatTextReceive(this, new ChatEventArgs(textMessage.Text));
                }
                break;

            case MessageType.PlayerInfoResponse:
                if (PlayerInfoRequestReply != null)
                {
                    PlayerInfoMessage playerInfoMessage = message as PlayerInfoMessage;
                    PlayerInfoRequestReply(this, new RequestReplyEventArgs(true, playerInfoMessage.PlayerData.ToString()));
                }
                break;

            case MessageType.Games:
            {
                GamesMessage gamesMessage = message as GamesMessage;
                switch ((MessageOperation)gamesMessage.Operation)
                {
                case MessageOperation.Add:
                    if (NewGamesInfo != null)
                    {
                        NewGamesInfo(this, new GameEventArgs(gamesMessage.ListGameInfo.ToArray()));
                    }
                    break;

                case MessageOperation.Remove:
                    if (DeleteGamesInfo != null)
                    {
                        DeleteGamesInfo(this, new GameEventArgs(gamesMessage.ListGameInfo.ToArray()));
                    }
                    break;

                case MessageOperation.List:
                    if (ResetGamesInfo != null)
                    {
                        ResetGamesInfo(this, new GameEventArgs(gamesMessage.ListGameInfo.ToArray()));
                    }
                    break;
                }
            }
            break;

            case MessageType.GameParams:
            {
                GameInfoMessage gameInfoMessage = message as GameInfoMessage;
                ClientPlayerInfo.GameInfo = gameInfoMessage.GameInfo;
                if (GameParamsRequestReply != null)
                {
                    GameParamsRequestReply(this, new RequestReplyEventArgs(true, gameInfoMessage.GameInfo.Description));
                }
            }
            break;

            case MessageType.Players:
            {
                PlayersMessage playersMessage = message as PlayersMessage;
                switch ((MessageOperation)playersMessage.Operation)
                {
                case MessageOperation.Add:
                    ClientPlayerInfo.Enemies.Add(playersMessage.PlayerList.ToArray());
                    if (NewPlayers != null)
                    {
                        NewPlayers(this, new PlayerEventArgs(playersMessage.PlayerList.ToArray()));
                    }
                    break;

                case MessageOperation.Remove:
                    ClientPlayerInfo.Enemies.Remove(playersMessage.PlayerList.ToArray());
                    if (DeletePlayers != null)
                    {
                        DeletePlayers(this, new PlayerEventArgs(playersMessage.PlayerList.ToArray()));
                    }
                    break;

                case MessageOperation.Modify:
                {
                    PlayerInfo[] players = playersMessage.PlayerList.ToArray();
                    for (int i = 0; i < players.Length; i++)
                    {
                        if (ClientPlayerInfo.Player.Id == players[i].Id)
                        {
                            ClientPlayerInfo.Player = players[i];
                            break;
                        }
                    }
                    ClientPlayerInfo.Enemies.Modify(players);
                    if (UpdatePlayers != null)
                    {
                        UpdatePlayers(this, new PlayerEventArgs(players));
                    }
                }
                break;

                case MessageOperation.List:
                    ClientPlayerInfo.Enemies.Clear();
                    ClientPlayerInfo.Enemies.Add(playersMessage.PlayerList.ToArray());
                    if (ResetPlayers != null)
                    {
                        ResetPlayers(this, new PlayerEventArgs(playersMessage.PlayerList.ToArray()));
                    }
                    break;
                }
            }
            break;

            default:
                InfoLog.WriteInfo("MenuMessageHandler received unknown message type: " + message.Type, EPrefix.ClientInformation);
                break;
            }
            handlerSuspender.Release();
        }