Ejemplo n.º 1
0
        public override void run()
        {
            try
            {
                Account player = _client._player;
                if (player == null || string.IsNullOrEmpty(text) || text.Length > 60 ||
                    player.player_name.Length == 0)
                {
                    return;
                }


                Room room = player._room;
                SLOT sender;
                switch (type)
                {
                case ChattingType.Team:
                    if (room == null)
                    {
                        return;
                    }

                    sender = room._slots[player._slotId];
                    int[] array = room.GetTeamArray(sender._team);
                    using (ROOM_CHATTING_PAK packet = new ROOM_CHATTING_PAK((int)type,sender._id,player.UseChatGM(),text))
                    {
                        byte[] data = packet.GetCompleteBytes();
                        lock (room._slots)
                            foreach (int slotIdx in array)
                            {
                                SLOT    receiver = room._slots[slotIdx];
                                Account pR       = room.getPlayerBySlot(receiver);
                                if (pR != null && SlotValidMessage(sender,receiver))
                                {
                                    pR.SendCompletePacket(data);
                                }
                            }
                    }
                    break;

                case ChattingType.All:
                case ChattingType.Lobby:
                    if (room != null)
                    {
                        if (!serverCommands(player,room))
                        {
                            sender = room._slots[player._slotId];
                            using (ROOM_CHATTING_PAK packet = new ROOM_CHATTING_PAK((int)type,sender._id,player.UseChatGM(),text))
                            {
                                byte[] data = packet.GetCompleteBytes();
                                lock (room._slots)
                                    for (int slotIdx = 0; slotIdx < 16; ++slotIdx)
                                    {
                                        SLOT    receiver = room._slots[slotIdx];
                                        Account pR       = room.getPlayerBySlot(receiver);
                                        if (pR != null && SlotValidMessage(sender,receiver))
                                        {
                                            pR.SendCompletePacket(data);
                                        }
                                    }
                            }
                        }
                        else
                        {
                            _client.SendPacket(new ROOM_CHATTING_PAK((int)type,player._slotId,true,text));
                        }
                    }
                    else
                    {
                        Channel channel = player.getChannel();
                        if (channel == null)
                        {
                            return;
                        }

                        if (!serverCommands(player,room))
                        {
                            using (LOBBY_CHATTING_PAK packet = new LOBBY_CHATTING_PAK(player,text))
                                channel.SendPacketToWaitPlayers(packet);
                        }
                        else
                        {
                            _client.SendPacket(new LOBBY_CHATTING_PAK(player,text,true));
                        }
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                SaveLog.fatal(ex.ToString());
                Printf.b_danger("[BASE_CHATTING_REC.run] Erro fatal!");
            }
        }
Ejemplo n.º 2
0
        public override void run()
        {
            try
            {
                Account player = this._client._player;
                if (player == null || string.IsNullOrEmpty(this.text) || (this.text.Length > 60 || player.player_name.Length == 0))
                {
                    return;
                }
                Room room = player._room;
                switch (this.type)
                {
                case ChattingType.All:
                case ChattingType.Lobby:
                    if (room != null)
                    {
                        if (!this.serverCommands(player, room))
                        {
                            SLOT slot1 = room._slots[player._slotId];
                            using (ROOM_CHATTING_PAK roomChattingPak = new ROOM_CHATTING_PAK((int)this.type,slot1._id,player.UseChatGM(),this.text))
                            {
                                byte[] completeBytes = roomChattingPak.GetCompleteBytes("CHAT_NORMAL_REC-2");
                                lock (room._slots)
                                {
                                    for (int index = 0; index < 16; ++index)
                                    {
                                        SLOT    slot2        = room._slots[index];
                                        Account playerBySlot = room.getPlayerBySlot(slot2);
                                        if (playerBySlot != null && this.SlotValidMessage(slot1,slot2))
                                        {
                                            playerBySlot.SendCompletePacket(completeBytes);
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                        else
                        {
                            this._client.SendPacket((SendPacket) new ROOM_CHATTING_PAK((int)this.type,player._slotId,true,this.text));
                            break;
                        }
                    }
                    else
                    {
                        Channel channel = player.getChannel();
                        if (channel == null)
                        {
                            break;
                        }
                        if (!this.serverCommands(player,room))
                        {
                            using (LOBBY_CHATTING_PAK lobbyChattingPak = new LOBBY_CHATTING_PAK(player,this.text,false))
                            {
                                channel.SendPacketToWaitPlayers((SendPacket)lobbyChattingPak);
                                break;
                            }
                        }
                        else
                        {
                            this._client.SendPacket((SendPacket) new LOBBY_CHATTING_PAK(player,this.text,true));
                            break;
                        }
                    }

                case ChattingType.Team:
                    if (room == null)
                    {
                        break;
                    }
                    SLOT  slot3     = room._slots[player._slotId];
                    int[] teamArray = room.GetTeamArray(slot3._team);
                    using (ROOM_CHATTING_PAK roomChattingPak = new ROOM_CHATTING_PAK((int)this.type,slot3._id,player.UseChatGM(),this.text))
                    {
                        byte[] completeBytes = roomChattingPak.GetCompleteBytes("CHAT_NORMAL_REC-1");
                        lock (room._slots)
                        {
                            foreach (int index in teamArray)
                            {
                                SLOT    slot1        = room._slots[index];
                                Account playerBySlot = room.getPlayerBySlot(slot1);
                                if (playerBySlot != null && this.SlotValidMessage(slot3,slot1))
                                {
                                    playerBySlot.SendCompletePacket(completeBytes);
                                }
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.warning(ex.ToString());
            }
        }