예제 #1
0
 public override void RunImplement()
 {
     try
     {
         Account player = client.SessionPlayer;
         if (player == null || player.nickname.Length == 0)
         {
             return;
         }
         Clan clan = ClanManager.GetClan(clanId);
         if (clan.id == 0)
         {
             client.SendCompletePacket(PackageDataManager.CLAN_MESSAGE_REQUEST_ACCEPT_2147487835_PAK);
             return;
         }
         if (player.clanId > 0)
         {
             client.SendCompletePacket(PackageDataManager.CLAN_MESSAGE_REQUEST_ACCEPT_2147487832_PAK);
             return;
         }
         List <Account> clanPlayers = clan.GetPlayers(-1, true);
         if (clan.maxPlayers <= clanPlayers.Count)
         {
             client.SendCompletePacket(PackageDataManager.CLAN_MESSAGE_REQUEST_ACCEPT_2147487830_PAK);
         }
         else if (type == 0 || type == 1)
         {
             Account owner = AccountManager.GetAccount(clan.ownerId, 0);
             if (owner != null)
             {
                 if (owner.GetMessagesCount() < 100)
                 {
                     Message message = new Message(15)
                     {
                         senderName = clan.name,
                         senderId   = player.playerId,
                         clanId     = clan.id,
                         type       = 4,
                         text       = player.nickname,
                         state      = 1,
                         noteEnum   = type == 0 ? NoteMessageClanEnum.JoinDenial : NoteMessageClanEnum.JoinAccept
                     };
                     if (message != null && owner.InsertMessage(message) && owner.isOnline)
                     {
                         owner.SendPacket(new BOX_MESSAGE_RECEIVE_PAK(message));
                     }
                 }
                 if (type == 1)
                 {
                     int date = int.Parse(DateTime.Now.ToString("yyyyMMdd"));
                     if (player.ExecuteQuery($"UPDATE accounts SET clan_id='{clan.id}', clan_authority='3', clan_date='{date}' WHERE id='{player.playerId}'"))
                     {
                         using (CLAN_MEMBER_INFO_INSERT_PAK packet = new CLAN_MEMBER_INFO_INSERT_PAK(player))
                         {
                             player.SendPacketForPlayers(packet, clanPlayers);
                         }
                         player.clanId        = clan.id;
                         player.clanDate      = date;
                         player.clanAuthority = ClanAuthorityEnum.Membro;
                         client.SendPacket(new CLAN_GET_CLAN_MEMBERS_PAK(clanPlayers));
                         Room room = player.room;
                         if (room != null)
                         {
                             room.SendPacketToPlayers(new PROTOCOL_ROOM_GET_SLOTONEINFO_ACK(player, clan));
                         }
                         client.SendPacket(new CLAN_NEW_INFOS_PAK(clan, owner, clanPlayers.Count + 1));
                     }
                     else
                     {
                         client.SendCompletePacket(PackageDataManager.BOX_MESSAGE_SEND_ERROR_0x80000000_PAK);
                     }
                 }
                 client.SendCompletePacket(PackageDataManager.BOX_MESSAGE_SEND_SUCCESS_PAK);
             }
             else
             {
                 client.SendCompletePacket(PackageDataManager.BOX_MESSAGE_SEND_ERROR_0x80000000_PAK);
             }
         }
         clanPlayers = null;
     }
     catch (Exception ex)
     {
         PacketLog(ex);
     }
 }
예제 #2
0
        public override void RunImplement()
        {
            try
            {
                Account player = client.SessionPlayer;
                if (player == null)
                {
                    return;
                }
                Clan clan = ClanManager.GetClan(player.clanId);
                if (clan.id > 0 && (player.clanAuthority >= ClanAuthorityEnum.Master && player.clanAuthority <= ClanAuthorityEnum.Auxiliar || player.playerId == clan.ownerId))
                {
                    List <Account> clanPlayers = clan.GetPlayers(-1, true);
                    if (clanPlayers.Count >= clan.maxPlayers)
                    {
                        client.SendPacket(new CLAN_REQUEST_ACCEPT_PAK(-1));
                        return;
                    }
                    int result = 0;
                    for (int i = 0; i < players.Count; i++)
                    {
                        Account member = AccountManager.GetAccount(players[i], 0);
                        if (member != null && clanPlayers.Count < clan.maxPlayers && member.clanId == 0 && member.GetRequestClanId() > 0)
                        {
                            using (CLAN_MEMBER_INFO_INSERT_PAK packet = new CLAN_MEMBER_INFO_INSERT_PAK(member))
                            {
                                member.SendPacketForPlayers(packet, clanPlayers);
                            }
                            member.clanId        = player.clanId;
                            member.clanDate      = int.Parse(DateTime.Now.ToString("yyyyMMdd"));
                            member.clanAuthority = ClanAuthorityEnum.Membro;

                            member.ExecuteQuery($"UPDATE accounts SET clan_id='{clan.id}', clan_authority='{member.clanAuthority}', clan_date='{member.clanDate}', clan_id='{member.clanId}' WHERE id='{member.playerId}'");

                            member.DeleteInvite(player.clanId);
                            if (member.isOnline)
                            {
                                member.SendPacket(new CLAN_GET_CLAN_MEMBERS_PAK(clanPlayers));
                                Room room = member.room;
                                if (room != null)
                                {
                                    room.SendPacketToPlayers(new PROTOCOL_ROOM_GET_SLOTONEINFO_ACK(member, clan));
                                }
                                member.SendPacket(new CLAN_NEW_INFOS_PAK(clan, clanPlayers.Count + 1));
                            }
                            if (member.GetMessagesCount() < 100)
                            {
                                Message message = new Message(15)
                                {
                                    senderName = clan.name,
                                    senderId   = player.playerId,
                                    clanId     = clan.id,
                                    type       = 4,
                                    state      = 1,
                                    noteEnum   = NoteMessageClanEnum.InviteAccept
                                };
                                if (message != null && member.InsertMessage(message) && member.isOnline)
                                {
                                    //Envia mensagem para o jogador, notificando que foi aceito no clã.
                                    member.SendPacket(new BOX_MESSAGE_RECEIVE_PAK(message));
                                }
                            }
                            result++;
                            clanPlayers.Add(member);
                        }
                    }
                    client.SendPacket(new CLAN_REQUEST_ACCEPT_PAK(result));
                    clanPlayers = null;
                }
                else
                {
                    client.SendPacket(new CLAN_REQUEST_ACCEPT_PAK(-1));
                }
            }
            catch (Exception ex)
            {
                PacketLog(ex);
            }
            finally
            {
                players = null;
            }
        }