public static void Load(ReceiveGPacket p)
        {
            int    type   = p.readC();
            int    clanId = p.readD();
            long   ownerId;
            int    date;
            string name, info;
            Clan   clanCache = ClanManager.getClan(clanId);

            if (type == 0)
            {
                if (clanCache != null)
                {
                    return;
                }
                ownerId = p.readQ();
                date    = p.readD();
                name    = p.readS(p.readC());
                info    = p.readS(p.readC());
                Clan clan = new Clan {
                    _id = clanId, _name = name, owner_id = ownerId, _logo = 0, _info = info, creationDate = date
                };
                ClanManager.AddClan(clan);
            }
            else
            {
                if (clanCache != null)
                {
                    ClanManager.RemoveClan(clanCache);
                }
            }
        }
        public static void Load(ReceiveGPacket p)
        {
            int  num1 = (int)p.readC();
            int  id   = p.readD();
            Clan clan = ClanManager.getClan(id);

            if (num1 == 0)
            {
                if (clan != null)
                {
                    return;
                }
                long   num2 = p.readQ();
                int    num3 = p.readD();
                string str1 = p.readS((int)p.readC());
                string str2 = p.readS((int)p.readC());
                ClanManager.AddClan(new Clan()
                {
                    _id          = id,
                    _name        = str1,
                    owner_id     = num2,
                    _logo        = 0U,
                    _info        = str2,
                    creationDate = num3
                });
            }
            else
            {
                if (clan == null)
                {
                    return;
                }
                ClanManager.RemoveClan(clan);
            }
        }
Beispiel #3
0
        public override void RunImplement()
        {
            try
            {
                Account player = client.SessionPlayer;
                if (player == null)
                {
                    return;
                }
                Clan clan = new Clan
                {
                    name         = clanName,
                    informations = clanInfo,
                    logo         = 0,
                    ownerId      = player.playerId,
                    creationDate = int.Parse(DateTime.Now.ToString("yyyyMMdd"))
                };
                if (player.clanId > 0 || player.GetRequestClanId() > 0)
                {
                    client.SendCompletePacket(PackageDataManager.CLAN_CREATE_0x8000105C_PAK);
                }
                else if ((player.gold - Settings.ClanCreateGold) < 0 || Settings.ClanCreateRank > player.rankId)
                {
                    client.SendCompletePacket(PackageDataManager.CLAN_CREATE_0x8000104A_PAK);
                }
                else if (ClanManager.clans.Count > Settings.MaxClanActive)
                {
                    client.SendCompletePacket(PackageDataManager.CLAN_CREATE_0x80001055_PAK);
                }
                if ((player.gold - Settings.ClanCreateGold) < 0)
                {
                    client.SendCompletePacket(PackageDataManager.CLAN_CREATE_0x80001048_PAK);
                }
                else if (!ClanManager.IsClanNameExist(clan.name).Result&& clan.CreateClan().Result&& player.UpdateAccountGold(player.gold - Settings.ClanCreateGold) && player.ExecuteQuery($"UPDATE accounts SET clan_authority='1', clan_date='{clan.creationDate}', clan_id='{clan.id}' WHERE id='{player.playerId}'"))
                {
                    clan.BestPlayers.SetDefault();
                    player.clanDate      = clan.creationDate;
                    player.clanId        = clan.id;
                    player.clanAuthority = ClanAuthorityEnum.Master;
                    ClanManager.AddClan(clan);
                    player.gold -= Settings.ClanCreateGold;
                    client.SendPacket(new CLAN_CREATE_PAK(0, clan, player));
                }
                else
                {
                    client.SendCompletePacket(PackageDataManager.CLAN_CREATE_0x8000105A_PAK);
                }
            }
            catch (Exception ex)
            {
                PacketLog(ex);
            }

            /*
             * 80001055 - STBL_IDX_CLAN_MESSAGE_FAIL_CREATING_OVERFLOW
             * 8000105C - STBL_IDX_CLAN_MESSAGE_FAIL_CREATING_ALREADY
             * 8000105A - STBL_IDX_CLAN_MESSAGE_FAIL_CREATING_OVERLAPPING
             * 80001048 - STBL_IDX_CLAN_MESSAGE_FAIL_CREATING
             * Padrão: STBL_IDX_CLAN_MESSAGE_FAIL_CREATING_ADMIN
             */
        }
Beispiel #4
0
 public static bool Hook(ClientInfo _cInfo, string _message, string _playerName, string _secondaryName, bool _localizeSecondary)
 {
     if (!string.IsNullOrEmpty(_message) && _cInfo != null && _playerName != "Server" && _secondaryName != "ServerTools")
     {
         if (ChatFlood)
         {
             if (_message.Length > 500)
             {
                 _cInfo.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}Message to long.[-]", CustomCommands.ChatColor), "Server", false, "ServerTools", false));
                 return(false);
             }
         }
         if (ChatLog.IsEnabled)
         {
             ChatLog.Log(_message, _playerName);
         }
         if (MutePlayer.Dict.ContainsKey(_cInfo.playerId))
         {
             _cInfo.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, "You are muted.", "Server", false, "ServerTools", false));
             return(false);
         }
         if (AdminNameColoring && !_message.StartsWith("/") && !_message.StartsWith("@") && _secondaryName != "ServerTools1" && GameManager.Instance.adminTools.IsAdmin(_cInfo.playerId))
         {
             AdminToolsClientInfo Admin = GameManager.Instance.adminTools.GetAdminToolsClientInfo(_cInfo.playerId);
             if (Admin.PermissionLevel == AdminLevel)
             {
                 _playerName = string.Format("{0}{1} {2}[-]", AdminColor, AdminPrefix, _playerName);
                 GameManager.Instance.GameMessageServer(_cInfo, EnumGameMessages.Chat, _message, _playerName, false, "ServerTools1", false);
                 return(false);
             }
             if (Admin.PermissionLevel == ModLevel)
             {
                 _playerName = string.Format("{0}{1} {2}[-]", ModColor, ModPrefix, _playerName);
                 GameManager.Instance.GameMessageServer(_cInfo, EnumGameMessages.Chat, _message, _playerName, false, "ServerTools1", false);
                 return(false);
             }
         }
         if (Badwords.IsEnabled)
         {
             bool   _hasBadWord = false;
             string _message1   = _message.ToLower();
             foreach (string _word in Badwords.List)
             {
                 if (_message1.Contains(_word))
                 {
                     string _replace = "";
                     for (int i = 0; i < _word.Length; i++)
                     {
                         _replace = string.Format("{0}*", _replace);
                     }
                     _message1   = _message1.Replace(_word, _replace);
                     _hasBadWord = true;
                 }
             }
             if (_hasBadWord)
             {
                 GameManager.Instance.GameMessageServer(_cInfo, EnumGameMessages.Chat, _message1, _playerName, false, "ServerTools", false);
                 return(false);
             }
         }
         if (_message.StartsWith("/") || _message.StartsWith("!"))
         {
             bool _announce = false;
             if (_message.StartsWith("!"))
             {
                 _announce = true;
                 _message  = _message.Replace("!", "");
             }
             if (_message.StartsWith("/"))
             {
                 _message = _message.Replace("/", "");
             }
             if (_message.StartsWith("w ") || _message.StartsWith("W ") || _message.StartsWith("pm ") || _message.StartsWith("PM "))
             {
                 if (CustomCommands.IsEnabled)
                 {
                     Whisper.Send(_cInfo, _message);
                     return(false);
                 }
             }
             if (_message.StartsWith("r ") || _message.StartsWith("R ") || _message.StartsWith("RE ") || _message.StartsWith("re "))
             {
                 if (CustomCommands.IsEnabled)
                 {
                     Whisper.Reply(_cInfo, _message);
                     return(false);
                 }
             }
             _message = _message.ToLower();
             if (_message == "sethome")
             {
                 if (_announce)
                 {
                     GameManager.Instance.GameMessageServer(_cInfo, EnumGameMessages.Chat, string.Format("!{0}", _message), _playerName, false, "ServerTools", true);
                 }
                 if (TeleportHome.IsEnabled)
                 {
                     TeleportHome.SetHome(_cInfo);
                 }
                 else
                 {
                     _cInfo.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}Sethome is not enabled.[-]", CustomCommands.ChatColor), "Server", false, "ServerTools", false));
                 }
                 return(false);
             }
             if (_message == "home")
             {
                 if (_announce)
                 {
                     GameManager.Instance.GameMessageServer(_cInfo, EnumGameMessages.Chat, string.Format("!{0}", _message), _playerName, false, "ServerTools", true);
                 }
                 if (TeleportHome.IsEnabled)
                 {
                     TeleportHome.TeleHome(_cInfo);
                 }
                 else
                 {
                     _cInfo.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}Home is not enabled.[-]", CustomCommands.ChatColor), "Server", false, "ServerTools", false));
                 }
                 return(false);
             }
             if (AdminChat.IsEnabled)
             {
                 if (_message.StartsWith("mute ") || _message.StartsWith("unmute "))
                 {
                     if (_message.StartsWith("mute "))
                     {
                         MutePlayer.Add(_cInfo, _message);
                     }
                     if (_message.StartsWith("unmute "))
                     {
                         MutePlayer.Remove(_cInfo, _message);
                     }
                     return(false);
                 }
             }
             if (_message == "commands")
             {
                 string _commands = CustomCommands.GetChatCommands(_cInfo);
                 if (_announce)
                 {
                     GameManager.Instance.GameMessageServer(_cInfo, EnumGameMessages.Chat, string.Format("!{0}", _message), _playerName, false, "ServerTools", true);
                     GameManager.Instance.GameMessageServer(_cInfo, EnumGameMessages.Chat, _commands, "Server", false, "ServerTools", false);
                 }
                 else
                 {
                     _cInfo.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, _commands, "Server", false, "ServerTools", false));
                 }
                 return(false);
             }
             if (_message == "day7")
             {
                 if (Day7.IsEnabled)
                 {
                     if (_announce)
                     {
                         GameManager.Instance.GameMessageServer(_cInfo, EnumGameMessages.Chat, string.Format("!{0}", _message), _playerName, false, "ServerTools", true);
                     }
                     Day7.GetInfo(_cInfo, _announce);
                     return(false);
                 }
             }
             if (_message == "killme" || _message == "wrist" || _message == "suicide")
             {
                 if (_announce)
                 {
                     GameManager.Instance.GameMessageServer(_cInfo, EnumGameMessages.Chat, string.Format("!{0}", _message), _playerName, false, "ServerTools", true);
                 }
                 if (KillMe.IsEnabled)
                 {
                     KillMe.CheckPlayer(_cInfo, _announce);
                 }
                 else
                 {
                     _cInfo.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}Killme is not enabled.[-]", CustomCommands.ChatColor), "Server", false, "ServerTools", false));
                 }
                 return(false);
             }
             if (_message == "gimme" || _message == "gimmie")
             {
                 if (_announce)
                 {
                     GameManager.Instance.GameMessageServer(_cInfo, EnumGameMessages.Chat, string.Format("!{0}", _message), _playerName, false, "ServerTools", true);
                 }
                 if (Gimme.AlwaysShowResponse && !_announce)
                 {
                     GameManager.Instance.GameMessageServer(_cInfo, EnumGameMessages.Chat, string.Format("/{0}", _message), _playerName, false, "ServerTools", true);
                 }
                 if (Gimme.IsEnabled)
                 {
                     Gimme.Checkplayer(_cInfo, _announce, _playerName);
                 }
                 else
                 {
                     return(true);
                 }
                 return(false);
             }
             if (_message.StartsWith("clanadd") || _message == "clandel" || _message.StartsWith("claninvite") || _message == "clanaccept" || _message == "clandecline" || _message.StartsWith("clanremove") || _message.StartsWith("clanpromote") || _message.StartsWith("clandemote") || _message.StartsWith("clan") || _message.StartsWith("c") || _message == "clancommands")
             {
                 if (ClanManager.IsEnabled)
                 {
                     if (_message == "clancommands")
                     {
                         ClanManager.GetChatCommands(_cInfo);
                         return(false);
                     }
                     if (_message.StartsWith("clanadd"))
                     {
                         if (_message == "clanadd")
                         {
                             _cInfo.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}Usage: /clanadd clanName[-]", CustomCommands.ChatColor), "Server", false, "ServerTools", false));
                         }
                         else
                         {
                             _message = _message.Replace("clanadd ", "");
                             ClanManager.AddClan(_cInfo, _message);
                         }
                         return(false);
                     }
                     if (_message == "clandel")
                     {
                         ClanManager.RemoveClan(_cInfo);
                         return(false);
                     }
                     if (_message.StartsWith("claninvite"))
                     {
                         if (_message == "claninvite")
                         {
                             _cInfo.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}Usage: /claninvite playerName[-]", CustomCommands.ChatColor), "Server", false, "ServerTools", false));
                         }
                         else
                         {
                             _message = _message.Replace("claninvite ", "");
                             ClanManager.InviteMember(_cInfo, _message);
                         }
                         return(false);
                     }
                     if (_message == "clanaccept")
                     {
                         ClanManager.InviteAccept(_cInfo);
                         return(false);
                     }
                     if (_message == "clandecline")
                     {
                         ClanManager.InviteDecline(_cInfo);
                         return(false);
                     }
                     if (_message.StartsWith("clanremove"))
                     {
                         if (_message == "clanremove")
                         {
                             _cInfo.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}Usage: /clanremove playerName[-]", CustomCommands.ChatColor), "Server", false, "ServerTools", false));
                         }
                         else
                         {
                             _message = _message.Replace("clanremove ", "");
                             ClanManager.RemoveMember(_cInfo, _message);
                         }
                         return(false);
                     }
                     if (_message.StartsWith("clanpromote"))
                     {
                         if (_message == "clanpromote")
                         {
                             _cInfo.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}Usage: /clanpromote playerName[-]", CustomCommands.ChatColor), "Server", false, "ServerTools", false));
                         }
                         else
                         {
                             _message = _message.Replace("clanpromote ", "");
                             ClanManager.PromoteMember(_cInfo, _message);
                         }
                         return(false);
                     }
                     if (_message.StartsWith("clandemote"))
                     {
                         if (_message == "clandemote")
                         {
                             _cInfo.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}Usage: /clandemote playerName[-]", CustomCommands.ChatColor), "Server", false, "ServerTools", false));
                         }
                         else
                         {
                             _message = _message.Replace("clandemote ", "");
                             ClanManager.DemoteMember(_cInfo, _message);
                         }
                         return(false);
                     }
                     if (_message == "clanleave")
                     {
                         ClanManager.LeaveClan(_cInfo);
                         return(false);
                     }
                     if (_message.StartsWith("clan"))
                     {
                         if (_message == "clan")
                         {
                             _cInfo.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}Usage: /clan message[-]", CustomCommands.ChatColor), "Server", false, "ServerTools", false));
                         }
                         else
                         {
                             _message = _message.Replace("clan ", "");
                             ClanManager.Clan(_cInfo, _message);
                         }
                         return(false);
                     }
                     if (_message.StartsWith("c"))
                     {
                         if (_message == "c")
                         {
                             _cInfo.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}Usage: /c message[-]", CustomCommands.ChatColor), "Server", false, "ServerTools", false));
                         }
                         else
                         {
                             _message = _message.Replace("c ", "");
                             ClanManager.Clan(_cInfo, _message);
                         }
                         return(false);
                     }
                 }
                 else
                 {
                     return(true);
                 }
             }
             if (CustomCommands.IsEnabled && CustomCommands.Dict.Count > 0 && CustomCommands.Dict.ContainsKey(_message))
             {
                 string[] _r;
                 if (CustomCommands.Dict.TryGetValue(_message, out _r))
                 {
                     string _response = _r[0];
                     _response = _response.Replace("{EntityId}", _cInfo.entityId.ToString());
                     _response = _response.Replace("{SteamId}", _cInfo.playerId);
                     _response = _response.Replace("{PlayerName}", _playerName);
                     if (_announce)
                     {
                         GameManager.Instance.GameMessageServer(_cInfo, EnumGameMessages.Chat, string.Format("!{0}", _message), _playerName, false, "ServerTools", true);
                     }
                     if (_response.StartsWith("say "))
                     {
                         if (_announce)
                         {
                             SdtdConsole.Instance.ExecuteSync(_response, _cInfo);
                         }
                         else
                         {
                             _response = _response.Replace("say ", "");
                             _response = _response.Replace("\"", "");
                             _cInfo.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, string.Format(_response), "Server", false, "ServerTools", false));
                         }
                     }
                     else
                     {
                         SdtdConsole.Instance.ExecuteSync(_response, _cInfo);
                     }
                 }
                 return(false);
             }
         }
         if (_message.StartsWith("@"))
         {
             if (_message.StartsWith("@admins ") || _message.StartsWith("@ADMINS "))
             {
                 if (!AdminChat.IsEnabled)
                 {
                     _cInfo.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}AdminChat is not enabled.[-]", CustomCommands.ChatColor), "Server", false, "ServerTools", false));
                 }
                 else
                 {
                     AdminChat.SendAdmins(_cInfo, _message);
                 }
                 return(false);
             }
             if (_message.StartsWith("@all ") || _message.StartsWith("@ALL "))
             {
                 if (!AdminChat.IsEnabled)
                 {
                     _cInfo.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}AdminChat is not enabled.[-]", CustomCommands.ChatColor), "Server", false, "ServerTools", false));
                 }
                 else
                 {
                     AdminChat.SendAll(_cInfo, _message);
                 }
                 return(false);
             }
         }
     }
     return(true);
 }
        public override void Handle(virtualUser User)
        {
            int Operation = Convert.ToInt32(getBlock(0));

            if (Operation == 0) // Check duplicate
            {
                string[] clanData = DB.runReadRow("SELECT * FROM clans WHERE clanname='" + getBlock(1) + "'");
                if (clanData.Length > 0 && getBlock(1).Length > 0)
                {
                    User.send(new Packets.PACKET_CLAN(Packets.PACKET_CLAN.ErrorCodes.Exist, Operation));
                }
                else
                {
                    User.send(new Packets.PACKET_CLAN(Packets.PACKET_CLAN.ErrorCodes.NotExist, Operation));
                }
            }
            else if (Operation == 1) // Create clan
            {
                ClanManager.AddClan(User, getBlock(1), getBlock(2));
                // ClanManager.AddClan(User, getBlock(1));
                return;
            }
            else if (Operation == 2) // Apply Clan
            {
                int      ClanID                 = Convert.ToInt32(getBlock(1));
                string   ActualTime             = DateTime.Now.ToString("yyyy.MM.dd");
                string[] checkForAlreadyRequest = DB.runReadRow("SELECT * FROM clans_invite WHERE userid='" + User.UserID + "'");
                DB.runQuery("UPDATE users SET clanrank='9', clanid='" + ClanID + "' WHERE id='" + User.UserID + "'");
                if (checkForAlreadyRequest.Length > 0)
                {
                    DB.runQuery("UPDATE clans_invite SET clanid='" + ClanID + "' WHERE userid='" + User.UserID + "'");
                }
                else
                {
                    DB.runQuery("INSERT INTO clans_invite (userid, clanid) VALUES ('" + User.UserID + "', '" + ClanID + "')");
                }
                User.ClanID   = ClanID;
                User.ClanRank = 9;
                User.Clan     = ClanManager.getClan(ClanID);
                User.send(new PACKET_CLAN(-1));
                return;
            }
            else if (Operation == 3) // Leave Clan
            {
                if (User.ClanRank == 2)
                {
                    DB.runQuery("DELETE * FROM clans WHERE id='" + User.ClanID + "'");
                    DB.runQuery("UPDATE users SET clanid='-1', clanrank='-1' WHERE clanid='" + User.ClanID + "'");
                    foreach (virtualUser Player in Managers.UserManager.getAllUsers())
                    {
                        if (Player.ClanID == User.ClanID)
                        {
                            Player.ClanID = Player.ClanRank = -1;
                        }
                    }
                }
                DB.runQuery("UPDATE users SET clanid='-1', clanrank='-1' WHERE id='" + User.UserID + "'");
                User.ClanID = User.ClanRank = -1;
                User.send(new PACKET_CLAN_PENDING_USERS());
            }
            else if (Operation == 4) // Open 'My Clan'
            {
                if (User.ClanRank == -1 || User.ClanRank == 9)
                {
                    User.send(new PACKET_CHAT(User, PACKET_CHAT.ChatType.Whisper, "You need to be accepted before.", User.SessionID, User.Nickname));
                }
                User.send(new Packets.PACKET_CLAN(User));
                User.send(new Packets.PACKET_CLAN(Packets.PACKET_CLAN.ClanCodes.Open));
                return;
            }
            else if (Operation == 5) // Member Information's
            {
                int Page = Convert.ToInt32(getBlock(1));
                if (Page == 1)
                {
                    User.send(new PACKET_CLAN_USERLIST(User));
                }
                else if (Page == 2 && (User.ClanRank == 1 || User.ClanRank == 2))
                {
                    User.send(new PACKET_CLAN_PENDING_USERS(User));
                }
            }
            else if (Operation == 6) // Search clan
            {
                //Log.WriteDebug(string.Join(" ", getAllBlocks()));
                int Subtype = Convert.ToInt32(getBlock(1));
                switch (Subtype)
                {
                case 0:
                {
                    string   ClanName = getBlock(2);
                    string[] ClanData = DB.runReadRow("SELECT * FROM clans WHERE clanname='" + ClanName + "'");
                    if (ClanData.Length > 0)
                    {
                        User.send(new PACKET_CLAN_USERLIST(User, ClanName));
                    }
                    else
                    {
                        User.send(new PACKET_CLAN(PACKET_CLAN.ErrorCodes.NotFound, Operation));
                    }
                    break;
                }

                default:
                {
                    User.send(new PACKET_CLAN(PACKET_CLAN.ErrorCodes.NotFound, Operation));
                    break;
                }
                }
            }
            else if (Operation == 7) // Clan Info
            {
                int ClanID = Convert.ToInt32(getBlock(1));
                User.send(new PACKET_CLAN_USERLIST(ClanID));
            }
            else if (Operation == 8) // Change announcment
            {
                string Check = (getBlock(1) == "1" ? "announcment" : "description");
                DB.runQuery("UPDATE clans SET " + Check + "='" + getBlock(2) + "' WHERE id='" + User.ClanID + "'");
            }
            else if (Operation == 9) // Accept/defuse clan join
            {
                int Connection = Convert.ToInt32(getBlock(1));
                int UserID     = Convert.ToInt32(getBlock(2));
                if (Connection == 0) // Accept Join
                {
                    if (ClanManager.getClanMembersCount(User.ClanID) >= ClanManager.getClanMembersMaxCount(User.ClanID))
                    {
                        User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> No more slot available for the clan, please expand if is possible", User.SessionID, User.Nickname));
                        return;
                    }
                    string ActualTime = DateTime.Now.ToString("yyyy.MM.dd");
                    foreach (virtualUser Player in Managers.UserManager.getAllUsers())
                    {
                        if (Player.UserID == UserID)
                        {
                            Player.ClanRank = 0;
                        }
                    }
                    DB.runQuery("DELETE FROM clans_invite WHERE userid='" + UserID + "'");
                    DB.runQuery("UPDATE users SET clanid='" + User.ClanID + "', clanrank='0', clanjoindate='" + ActualTime + "' WHERE id='" + UserID + "'");
                }
                else if (Connection == 1) // Refuse Join
                {
                    DB.runQuery("DELETE FROM clans_invite WHERE userid='" + UserID + "'");
                    DB.runQuery("UPDATE users SET clanid='-1' WHERE id='" + UserID + "'");
                    string ActualTime = DateTime.Now.ToString("yyyy.MM.dd");
                    foreach (virtualUser Player in Managers.UserManager.getAllUsers())
                    {
                        if (Player.UserID == UserID)
                        {
                            Player.ClanRank   = -1;
                            Player.ClanID     = -1;
                            Player.ClanIconID = 0;
                        }
                    }
                }
                User.send(new PACKET_CLAN_PENDING_USERS(Connection, UserID));
            }
            else if (Operation == 10) // Promote / degrade / remove
            {
                int SubType = Convert.ToInt32(getBlock(1));
                int UserID  = Convert.ToInt32(getBlock(2));
                if (SubType == 0)
                {
                    DB.runQuery("UPDATE users SET clanrank=clanrank+1 WHERE id='" + UserID + "'");
                }
                else if (SubType == 1)
                {
                    DB.runQuery("UPDATE users SET clanrank=clanrank-1 WHERE id='" + UserID + "'");
                }
                else if (SubType == 2)
                {
                    DB.runQuery("UPDATE users SET clanid='-1', clanrank='-1' WHERE id='" + UserID + "'");
                    foreach (virtualUser Player in Managers.UserManager.getAllUsers())
                    {
                        if (Player.UserID == UserID)
                        {
                            Player.ClanID = Player.ClanRank = -1;
                        }
                    }
                }
                User.send(new PACKET_CLAN_CHANGE(SubType, UserID));
            }
            else if (Operation == 11) // Promote master
            {
                //26384 11 23343041
                int UserID = Convert.ToInt32(getBlock(1));
                DB.runQuery("UPDATE users SET clanrank='0' WHERE id='" + User.UserID + "'");
                DB.runQuery("UPDATE users SET clanrank='2' WHERE id='" + UserID + "'");
                User.ClanRank = 0;
                foreach (virtualUser Player in Managers.UserManager.getAllUsers())
                {
                    if (Player.UserID == UserID)
                    {
                        Player.ClanRank = 2;
                    }
                }
                User.send(new PACKET_CLAN_CHANGE());
            }
            else if (Operation == 12) // Clan change nick
            {
                string   newNick        = getBlock(1);
                string[] CheckForLength = DB.runReadRow("SELECT * FROM clans WHERE clanname='" + newNick + "'");
                if (CheckForLength.Length > 0)
                {
                    User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> A clan has already this name, please choose another one", User.SessionID, User.Nickname));
                }
                else
                {
                    DB.runQuery("UPDATE clans SET clanname='" + newNick + "' WHERE id='" + User.ClanID + "'");
                    DB.runQuery("DELETE FROM inventory WHERE ownerid='" + User.UserID + "' AND itemcode='CB02'");
                    User.Inventory = new InventoryItem[105];
                    User.LoadItems();
                    User.send(new PACKET_CLAN_CHANGE(User, true));
                }
            }
            else if (Operation == 14) // Clan Mark Change
            {
                int iconID = Convert.ToInt32(getBlock(1));
                DB.runQuery("DELETE FROM inventory WHERE ownerid='" + User.UserID + "' AND itemcode='CB54'");
                User.Inventory = new InventoryItem[105];
                User.LoadItems();
                DB.runQuery("UPDATE clans SET iconid='" + iconID + "' WHERE id='" + User.ClanID + "'");
                foreach (virtualUser Player in Managers.UserManager.getAllUsers())
                {
                    if (Player.ClanID == User.ClanID)
                    {
                        Player.ClanIconID = iconID;
                    }
                }
                User.send(new PACKET_CLAN_CHANGE(User, false));
            }
            else if (Operation == 16) // Disband Clan
            {
                ClanManager.RemoveClan(User);
            }
            else
            {
                Log.AppendError("Unknown Operation for ClanSystem: " + Operation);
                Log.AppendError("Blocks: " + string.Join(" ", getAllBlocks()));
            }
        }
Beispiel #6
0
 public static bool IsCommand(ClientInfo _cInfo, string _message, string _playerName)
 {
     if (!string.IsNullOrEmpty(_message) && _cInfo != null && _playerName != "" && _playerName != "Server")
     {
         if (AdminChat.MutedPlayersList.Contains(_cInfo.playerId))
         {
             _cInfo.SendPackage(new NetPackageGameMessage(string.Format("{0}You are currently muted.[-]", CustomCommands._chatcolor), "Server"));
             return(false);
         }
         string _filter = "[ffffffff][/url][/b][/i][/u][/s][/sub][/sup][ff]";
         if (_message.EndsWith(_filter + _filter))
         {
             _message = _message.Remove(_message.Length - 2 * _filter.Length);
         }
         if (ChatLog.IsEnabled && !_message.EndsWith(_filter))
         {
             ChatLog.Send(_message, _playerName);
         }
         if (Badwords.IsEnabled && !_message.EndsWith(_filter))
         {
             string _message1 = _message.ToLower();
             foreach (string _word in Badwords.BadWordslist)
             {
                 if (_message1.Contains(_word))
                 {
                     _message1 = _message1.Replace(_word, "*****");
                     GameManager.Instance.GameMessageServer(_cInfo, _message1, _playerName);
                     return(false);
                 }
             }
         }
         if (_message.StartsWith("/") || _message.StartsWith("!") || _message.StartsWith("@"))
         {
             bool _announce = false;
             if (_message.StartsWith("!"))
             {
                 _announce = true;
                 _message  = _message.Replace("!", "");
             }
             if (_message.StartsWith("/"))
             {
                 _message = _message.Replace("/", "");
             }
             if (_message.StartsWith("mute ") || _message.StartsWith("unmute "))
             {
                 if (AdminChat.IsEnabled)
                 {
                     if (_message.StartsWith("mute "))
                     {
                         _message = _message.Replace("mute ", "");
                         AdminChat.MutePlayer(_cInfo, _message);
                     }
                     if (_message.StartsWith("unmute "))
                     {
                         _message = _message.Replace("unmute ", "");
                         AdminChat.UnMutePlayer(_cInfo, _message);
                     }
                 }
                 else
                 {
                     _cInfo.SendPackage(new NetPackageGameMessage(string.Format("{0}AdminChat is not enabled.[-]", CustomCommands._chatcolor), "Server"));
                 }
                 return(false);
             }
             if (_message.StartsWith("clanadd ") || _message == "clandel" || _message.StartsWith("claninvite ") || _message == "clanaccept" || _message == "clandecline" || _message.StartsWith("clanremove ") || _message.StartsWith("clanpromote ") || _message.StartsWith("clandemote "))
             {
                 if (ClanManager.IsEnabled)
                 {
                     if (_message.StartsWith("clanadd "))
                     {
                         _message = _message.Replace("clanadd ", "");
                         ClanManager.AddClan(_cInfo, _message);
                     }
                     if (_message == "clandel")
                     {
                         ClanManager.RemoveClan(_cInfo);
                     }
                     if (_message.StartsWith("claninvite "))
                     {
                         _message = _message.Replace("claninvite ", "");
                         ClanManager.InviteMember(_cInfo, _message);
                     }
                     if (_message == "clanaccept")
                     {
                         ClanManager.InviteAccept(_cInfo);
                     }
                     if (_message == "clandecline")
                     {
                         ClanManager.InviteDecline(_cInfo);
                     }
                     if (_message.StartsWith("clanremove "))
                     {
                         _message = _message.Replace("clanremove ", "");
                         ClanManager.RemoveMember(_cInfo, _message);
                     }
                     if (_message.StartsWith("clanpromote "))
                     {
                         _message = _message.Replace("clanpromote ", "");
                         ClanManager.PromoteMember(_cInfo, _message);
                     }
                     if (_message.StartsWith("clandemote "))
                     {
                         _message = _message.Replace("clandemote ", "");
                         ClanManager.DemoteMember(_cInfo, _message);
                     }
                     if (_message == "clanleave")
                     {
                         ClanManager.LeaveClan(_cInfo);
                     }
                 }
                 else
                 {
                     _cInfo.SendPackage(new NetPackageGameMessage(string.Format("{0}ClanManager is not enabled.[-]", CustomCommands._chatcolor), "Server"));
                 }
                 return(false);
             }
             if (_message.StartsWith("@admins ") || _message.StartsWith("@all ") || _message.StartsWith("@ADMINS ") || _message.StartsWith("@ALL "))
             {
                 if (!AdminChat.IsEnabled)
                 {
                     _cInfo.SendPackage(new NetPackageGameMessage(string.Format("{0}AdminChat is not enabled.[-]", CustomCommands._chatcolor), "Server"));
                 }
                 else
                 {
                     if (_message.StartsWith("@ADMINS "))
                     {
                         _message = _message.Replace("@ADMINS ", "");
                         AdminChat.SendAdmins(_cInfo, _message);
                     }
                     if (_message.StartsWith("@admins "))
                     {
                         _message = _message.Replace("@admins ", "");
                         _message = "hello " + _message;
                         AdminChat.SendAdmins(_cInfo, _message);
                     }
                     if (_message.StartsWith("@ALL "))
                     {
                         _message = _message.Replace("@ALL ", "");
                         AdminChat.SendAll(_cInfo, _message);
                     }
                     if (_message.StartsWith("@all "))
                     {
                         _message = _message.Replace("@all ", "");
                         AdminChat.SendAll(_cInfo, _message);
                     }
                 }
                 return(false);
             }
             if (_message.StartsWith("w ") || _message.StartsWith("W ") || _message.StartsWith("pm ") || _message.StartsWith("PM "))
             {
                 if (_message.StartsWith("PM "))
                 {
                     _message = _message.Replace("PM ", "");
                 }
                 if (_message.StartsWith("pm "))
                 {
                     _message = _message.Replace("pm ", "");
                 }
                 if (_message.StartsWith("W "))
                 {
                     _message = _message.Replace("W ", "");
                 }
                 if (_message.StartsWith("w "))
                 {
                     _message = _message.Replace("w ", "");
                 }
                 Whisper.Send(_cInfo, _message);
                 return(false);
             }
             _message = _message.ToLower();
             if (_message == "info" || _message == "help" || _message == "commands")
             {
                 string _commands = CustomCommands.GetChatCommands(_cInfo);
                 if (_announce)
                 {
                     GameManager.Instance.GameMessageServer(_cInfo, string.Format("!{0}", _message), _playerName);
                     GameManager.Instance.GameMessageServer(_cInfo, _commands, "Server");
                 }
                 else
                 {
                     _cInfo.SendPackage(new NetPackageGameMessage(_commands, "Server"));
                 }
                 return(false);
             }
             if (_message == "killme" || _message == "wrist" || _message == "suicide")
             {
                 if (_announce)
                 {
                     GameManager.Instance.GameMessageServer(_cInfo, string.Format("!{0}", _message), _playerName);
                 }
                 if (KillMe.IsEnabled)
                 {
                     KillMe.KillPlayer(_cInfo, _announce, _message, _playerName);
                 }
                 else
                 {
                     _cInfo.SendPackage(new NetPackageGameMessage(string.Format("{0}Killme is not enabled.[-]", CustomCommands._chatcolor), "Server"));
                 }
                 return(false);
             }
             if (_message == "gimme" || _message == "gimmie")
             {
                 if (_announce)
                 {
                     GameManager.Instance.GameMessageServer(_cInfo, string.Format("!{0}", _message), _playerName);
                 }
                 if (Gimme.AlwaysShowResponse && !_announce)
                 {
                     GameManager.Instance.GameMessageServer(_cInfo, string.Format("/{0}", _message), _playerName);
                 }
                 if (Gimme.IsEnabled)
                 {
                     Gimme.Checkplayer(_cInfo, _announce, _playerName);
                 }
                 else
                 {
                     _cInfo.SendPackage(new NetPackageGameMessage(string.Format("{0}Gimme is not enabled.[-]", CustomCommands._chatcolor), "Server"));
                 }
                 return(false);
             }
             if (_message == "sethome")
             {
                 if (_announce)
                 {
                     GameManager.Instance.GameMessageServer(_cInfo, string.Format("!{0}", _message), _playerName);
                 }
                 if (TeleportHome.IsEnabled)
                 {
                     TeleportHome.SetHome(_cInfo);
                 }
                 else
                 {
                     _cInfo.SendPackage(new NetPackageGameMessage(string.Format("{0}Sethome is not enabled.[-]", CustomCommands._chatcolor), "Server"));
                 }
                 return(false);
             }
             if (_message == "delhome")
             {
                 if (_announce)
                 {
                     GameManager.Instance.GameMessageServer(_cInfo, string.Format("!{0}", _message), _playerName);
                 }
                 if (TeleportHome.IsEnabled)
                 {
                     TeleportHome.DelHome(_cInfo);
                 }
                 else
                 {
                     _cInfo.SendPackage(new NetPackageGameMessage(string.Format("{0}Delhome is not enabled.[-]", CustomCommands._chatcolor), "Server"));
                 }
                 return(false);
             }
             if (_message == "home")
             {
                 if (_announce)
                 {
                     GameManager.Instance.GameMessageServer(_cInfo, string.Format("!{0}", _message), _playerName);
                 }
                 if (TeleportHome.IsEnabled)
                 {
                     TeleportHome.TeleHome(_cInfo);
                 }
                 else
                 {
                     _cInfo.SendPackage(new NetPackageGameMessage(string.Format("{0}Home is not enabled.[-]", CustomCommands._chatcolor), "Server"));
                 }
                 return(false);
             }
             if (_message == "setreturn")
             {
                 if (_announce)
                 {
                     GameManager.Instance.GameMessageServer(_cInfo, string.Format("!{0}", _message), _playerName);
                 }
                 if (TeleportReturn.IsEnabled)
                 {
                     TeleportReturn.SetReturn(_cInfo);
                 }
                 else
                 {
                     _cInfo.SendPackage(new NetPackageGameMessage(string.Format("{0}SetReturn is not enabled.[-]", CustomCommands._chatcolor), "Server"));
                 }
                 return(false);
             }
             if (_message == "delreturn")
             {
                 if (_announce)
                 {
                     GameManager.Instance.GameMessageServer(_cInfo, string.Format("!{0}", _message), _playerName);
                 }
                 if (TeleportReturn.IsEnabled)
                 {
                     TeleportReturn.DelReturn(_cInfo);
                 }
                 else
                 {
                     _cInfo.SendPackage(new NetPackageGameMessage(string.Format("{0}DelReturn is not enabled.[-]", CustomCommands._chatcolor), "Server"));
                 }
                 return(false);
             }
             if (_message == "return")
             {
                 if (_announce)
                 {
                     GameManager.Instance.GameMessageServer(_cInfo, string.Format("!{0}", _message), _playerName);
                 }
                 if (TeleportReturn.IsEnabled)
                 {
                     TeleportReturn.TeleReturn(_cInfo);
                 }
                 else
                 {
                     _cInfo.SendPackage(new NetPackageGameMessage(string.Format("{0}Return is not enabled.[-]", CustomCommands._chatcolor), "Server"));
                 }
                 return(false);
             }
             if (_message == "day7")
             {
                 if (_announce)
                 {
                     GameManager.Instance.GameMessageServer(_cInfo, string.Format("!{0}", _message), _playerName);
                 }
                 if (Day7.IsEnabled)
                 {
                     Day7.GetInfo(_cInfo, _announce);
                 }
                 return(false);
             }
             if (_message == "clancommands")
             {
                 if (ClanManager.IsEnabled)
                 {
                     ClanManager.GetChatCommands(_cInfo);
                 }
                 return(false);
             }
             string _response = null;
             if (CustomCommands.IsEnabled && CustomCommands._customCommands.TryGetValue(_message, out _response))
             {
                 _response = _response.Replace("{0}", _cInfo.entityId.ToString());
                 _response = _response.Replace("{1}", _cInfo.playerId);
                 _response = _response.Replace("{2}", _playerName);
                 _response = _response.Replace("{EntityId}", _cInfo.entityId.ToString());
                 _response = _response.Replace("{SteamId}", _cInfo.playerId);
                 _response = _response.Replace("{PlayerName}", _playerName);
                 if (_announce)
                 {
                     GameManager.Instance.GameMessageServer(_cInfo, string.Format("!{0}", _message), _playerName);
                 }
                 if (_response.StartsWith("say "))
                 {
                     if (_announce)
                     {
                         SdtdConsole.Instance.ExecuteSync(_response, _cInfo);
                     }
                     else
                     {
                         _response = _response.Replace("say ", "");
                         _response = _response.Replace("\"", "");
                         _cInfo.SendPackage(new NetPackageGameMessage(string.Format(_response), "Server"));
                     }
                 }
                 else
                 {
                     SdtdConsole.Instance.ExecuteSync(_response, _cInfo);
                 }
                 return(false);
             }
         }
     }
     return(true);
 }
        public override void run()
        {
            try
            {
                Account p = _client._player;
                if (p == null)
                {
                    return;
                }
                Clan clan = new Clan
                {
                    _name        = clanName,
                    _info        = clanInfo,
                    _logo        = 0,
                    owner_id     = p.player_id,
                    creationDate = int.Parse(DateTime.Now.ToString("yyyyMMdd"))
                };
                if (p.clanId > 0 || PlayerManager.getRequestClanId(p.player_id) > 0)
                {
                    erro = 0x8000105C;
                }
                else if (0 > p._gp - ConfigGS.minCreateGold || ConfigGS.minCreateRank > p._rank)
                {
                    erro = 0x8000104A;
                }
                else if (ClanManager.isClanNameExist(clan._name))
                {
                    erro = 0x8000105A;
                    return;
                }
                else if (ClanManager._clans.Count > ConfigGS.maxActiveClans)
                {
                    erro = 0x80001055;
                }
                else if (PlayerManager.CreateClan(out clan._id, clan._name, clan.owner_id, clan._info, clan.creationDate) && PlayerManager.updateAccountGold(p.player_id, p._gp - ConfigGS.minCreateGold))
                {
                    clan.BestPlayers.SetDefault();
                    p.clanDate = clan.creationDate;
                    if (ComDiv.updateDB("contas", "player_id", p.player_id, new string[] { "clanaccess", "clandate", "clan_id" }, 1, clan.creationDate, clan._id))
                    {
                        if (clan._id > 0)
                        {
                            p.clanId     = clan._id;
                            p.clanAccess = 1;
                            ClanManager.AddClan(clan);
                            SEND_CLAN_INFOS.Load(clan, 0);
                            p._gp -= ConfigGS.minCreateGold;
                        }
                        else
                        {
                            erro = 0x8000104B;
                        }
                    }
                    else
                    {
                        erro = 0x80001048;
                    }
                }
                else
                {
                    erro = 0x80001048;
                }
                _client.SendPacket(new CLAN_CREATE_PAK(erro, clan, p));
            }
            catch (Exception ex)
            {
                SaveLog.fatal(ex.ToString());
                Printf.b_danger("[CLAN_CREATE_REC.run] Erro fatal!");
            }

            /*
             * 80001055 - STBL_IDX_CLAN_MESSAGE_FAIL_CREATING_OVERFLOW
             * 8000105C - STBL_IDX_CLAN_MESSAGE_FAIL_CREATING_ALREADY
             * 8000105A - STBL_IDX_CLAN_MESSAGE_FAIL_CREATING_OVERLAPPING
             * 80001048 - STBL_IDX_CLAN_MESSAGE_FAIL_CREATING
             * Padrão: STBL_IDX_CLAN_MESSAGE_FAIL_CREATING_ADMIN
             */
        }
Beispiel #8
0
        public override void Handle(User usr)
        {
            Subtype type = (Subtype)int.Parse(getBlock(0));

            switch (type)
            {
            case Subtype.CheckForDuplicate:
            {
                string name = getBlock(1).Replace(" ", "");
                if (name.Length > 4)
                {
                    ClanManager.CheckForDuplicate(usr, name);
                }
                break;
            }

            case Subtype.AddClan:
            {
                string name = getBlock(1).Replace(" ", "");
                if (name.Length > 4)
                {
                    ClanManager.AddClan(usr, name);
                }
                break;
            }

            case Subtype.ApplyClan:
            {
                int clanId = int.Parse(getBlock(1));
                if (clanId > 0)
                {
                    string time = DateTime.Now.ToString("dd/MM/yyyy");

                    Clan clan = ClanManager.GetClan(clanId);
                    if (clan != null)
                    {
                        if (clan.ClanUsers.Count >= clan.maxUsers)
                        {
                            return;
                        }

                        ClanPendingUsers pending = new ClanPendingUsers(usr.userId, usr.nickname, usr.exp.ToString(), time);
                        clan.pendingUsers.TryAdd(usr.userId, pending);

                        usr.clan = clan;

                        usr.send(new SP_Clan(SP_Clan.ClanCodes.ApplyClan));

                        if (usr.clan != null)
                        {
                            DB.RunQuery("UPDATE clans_invite SET clanid='" + clanId + "' WHERE userid='" + usr.userId + "'");
                        }
                        else
                        {
                            DB.RunQuery("INSERT INTO clans_invite (userid, clanid) VALUES ('" + usr.userId + "', '" + clanId + "')");
                        }

                        DB.RunQuery("UPDATE users SET clanrank='9', clanid='" + clanId + "' WHERE id='" + usr.userId + "'");
                    }
                }
                break;
            }

            case Subtype.LeaveClan:
            {
                if (usr.clan != null)
                {
                    Clan clan = usr.clan;
                    if (clan.pendingUsers.ContainsKey(usr.userId))
                    {
                        ClanPendingUsers u;
                        clan.pendingUsers.TryRemove(usr.userId, out u);
                    }

                    int clanrank = clan.clanRank(usr);
                    if (clanrank == 2)
                    {
                        foreach (User u in clan.GetUsers())
                        {
                            u.clan = null;
                        }

                        ClanManager.RemoveClan(usr);

                        DB.RunQuery("UPDATE users SET clanid='-1', clanrank='0' WHERE clanid='" + clan.id + "'");
                        DB.RunQuery("DELETE FROM clans WHERE id='" + clan.id + "'");
                    }
                    else
                    {
                        usr.clan = null;

                        if (clanrank == 9)
                        {
                            ClanPendingUsers u;
                            clan.pendingUsers.TryRemove(usr.userId, out u);
                        }
                        else
                        {
                            ClanUsers u;
                            clan.ClanUsers.TryRemove(usr.userId, out u);
                        }

                        usr.send(new SP_Clan(SP_Clan.ClanCodes.LeaveClan));

                        DB.RunQuery("UPDATE users SET clanid='-1', clanrank='0' WHERE id='" + usr.userId + "'");
                        DB.RunQuery("UPDATE clans SET count='" + usr.clan.ClanUsers.Count + "' WHERE id='" + usr.clan.id + "'");
                    }
                }
                break;
            }

            case Subtype.MyClan:
            {
                if (usr.clan == null)
                {
                    return;
                }
                usr.send(new SP_Clan.MyClanInformation(usr));
                break;
            }

            case Subtype.Members:
            {
                if (usr.clan == null)
                {
                    return;
                }
                int page     = int.Parse(getBlock(1));
                int clanrank = usr.clan.clanRank(usr);

                if (page == 1)
                {
                    usr.send(new SP_Clan.UserList.NormalUser(usr.clan));
                }
                else if (page == 2 && (clanrank == 1 || clanrank == 2))
                {
                    usr.send(new SP_Clan.UserList.Pending(usr));
                }

                break;
            }

            case Subtype.SearchClan:
            {
                int         t       = int.Parse(getBlock(1));
                SearchType  subtype = (SearchType)t;
                int         page    = int.Parse(getBlock(1));
                string      key     = getBlock(2);
                List <Clan> list    = new List <Clan>();

                switch (subtype)
                {
                case SearchType.Name:
                {
                    list = new List <Clan>(ClanManager.Clans.Values.Where(c => c != null && c.name.ToLower().Contains(key.ToLower())).ToArray());
                    break;
                }

                case SearchType.Master:
                {
                    list = new List <Clan>(ClanManager.Clans.Values.Where(c => c != null && c.Master.ToLower().Contains(key.ToLower())).ToArray());
                    break;
                }

                default:
                {
                    list = new List <Clan>(ClanManager.Clans.Values.Where(c => c != null && (c.Master.ToLower().Contains(key.ToLower()) || c.name.ToLower().Contains(key.ToLower()))).ToArray());
                    break;
                }
                }

                if (key.Length >= 3)
                {
                    usr.send(new SP_Clan.SearchClan(list));
                }
                else
                {
                    usr.send(new SP_Clan.CheckClan(SP_Clan.CheckClan.ErrorCodes.NotFound));
                }
                break;
            }

            case Subtype.ClanInfo:
            {
                int clanId = int.Parse(getBlock(1));
                if (clanId > 0)
                {
                    Clan clan = ClanManager.GetClan(clanId);
                    if (clan != null)
                    {
                        usr.send(new SP_Clan.UserList.NormalUser(usr, clan));
                    }
                }
                break;
            }

            case Subtype.ChangeAnnDec:
            {
                if (usr.clan == null)
                {
                    return;
                }
                int clanrank = usr.clan.clanRank(usr);
                if (clanrank < 1 || clanrank == 9 || usr.clan == null)
                {
                    return;
                }

                string Message = DB.Stripslash(getBlock(2));

                bool description = getBlock(1) == "0";
                if (description)
                {
                    usr.clan.Description = Message;
                }
                else
                {
                    usr.clan.Announcment = Message;
                }

                // Send query after to let the server be lagfree

                DB.RunQuery("UPDATE clans SET description='" + usr.clan.Description + "', announcment='" + usr.clan.Announcment + "' WHERE id='" + usr.clan.id + "'");
                break;
            }

            case Subtype.JoinAction:
            {
                if (usr.clan == null)
                {
                    return;
                }
                int subtype = int.Parse(getBlock(1));
                int userId  = int.Parse(getBlock(2));

                Clan clan = usr.clan;

                switch (subtype)
                {
                case 0:             // Accept Join
                {
                    if (clan.ClanUsers.Count >= clan.maxUsers)
                    {
                        usr.send(new SP_Chat("SYSTEM", SP_Chat.ChatType.Whisper, "SYSTEM >> No more slot available for the clan, please expand if is possible", usr.sessionId, usr.nickname));
                        return;
                    }

                    string time = DateTime.Now.ToString("dd/MM/yyyy");

                    DataTable dt = DB.RunReader("SELECT * FROM users WHERE id='" + userId + "'");
                    if (dt.Rows.Count > 0)
                    {
                        DataRow row = dt.Rows[0];
                        DB.RunQuery("DELETE FROM clans_invite WHERE userid='" + userId + "'");
                        DB.RunQuery("UPDATE clans SET count='" + clan.ClanUsers.Count + "' WHERE id='" + clan.id + "'");
                        DB.RunQuery("UPDATE users SET clanid='" + clan.id + "', clanrank='0', clanjoindate='" + time + "' WHERE id='" + userId + "'");
                        if (clan.pendingUsers.ContainsKey(userId))
                        {
                            ClanPendingUsers u;
                            clan.pendingUsers.TryRemove(userId, out u);
                        }
                        ClanUsers c = new ClanUsers(userId, row["nickname"].ToString(), row["exp"].ToString(), time, 0);
                        clan.ClanUsers.TryAdd(userId, c);
                    }

                    User user = UserManager.GetUser(userId);
                    if (user != null)
                    {
                        user.clan = clan;
                        clan.Users.TryAdd(userId, user);
                    }

                    ClanPendingUsers cc;
                    if (clan.pendingUsers.ContainsKey(userId))
                    {
                        clan.pendingUsers.TryRemove(userId, out cc);
                    }

                    break;
                }

                case 1:             // Refuse Join
                {
                    DB.RunQuery("DELETE FROM clans_invite WHERE userid='" + userId + "'");
                    DB.RunQuery("UPDATE users SET clanid='-1', clanrank='0' WHERE id='" + userId + "'");
                    User u = UserManager.GetUser(userId);
                    if (u != null)
                    {
                        u.clan = null;
                    }

                    ClanPendingUsers c;
                    if (clan.pendingUsers.ContainsKey(userId))
                    {
                        clan.pendingUsers.TryRemove(userId, out c);
                    }
                    break;
                }
                }

                DB.RunQuery("DELETE FROM clans_invite WHERE userid='" + userId + "'");

                usr.send(new SP_Clan.UserList.Pending(subtype, userId));

                break;
            }

            case Subtype.RankAction:
            {
                if (usr.clan == null)
                {
                    return;
                }
                int subtype  = int.Parse(getBlock(1));
                int userId   = int.Parse(getBlock(2));
                int clanrank = usr.clan.clanRank(usr);
                if (clanrank >= 1)
                {
                    clanrank = 0;
                    switch (subtype)
                    {
                    case 0:
                    {
                        clanrank = 1;
                        DB.RunQuery("UPDATE users SET clanrank='1' WHERE id='" + userId + "'");
                        break;
                    }

                    case 1:
                    {
                        clanrank = 0;
                        DB.RunQuery("UPDATE users SET clanrank='0' WHERE id='" + userId + "'");
                        break;
                    }

                    case 2:
                    {
                        DB.RunQuery("UPDATE users SET clanid='-1', clanrank='0' WHERE id='" + userId + "'");
                        DB.RunQuery("UPDATE clans SET count='" + usr.clan.ClanUsers.Count + "' WHERE id='" + usr.clan.id + "'");
                        User      u2;
                        ClanUsers u;
                        usr.clan.Users.TryRemove(userId, out u2);
                        usr.clan.ClanUsers.TryRemove(userId, out u);
                        break;
                    }
                    }

                    if (subtype != 2)
                    {
                        usr.clan.ClanUsers.Values.Where(s => s.id == userId).First().clanrank = clanrank;
                    }
                    else
                    {
                        User u = UserManager.GetUser(userId);
                        if (u != null)
                        {
                            u.clan = null;
                        }
                    }

                    usr.send(new SP_Clan.Change(subtype, userId));
                }
                break;
            }

            case Subtype.Promote:
            {
                if (usr.clan == null)
                {
                    return;
                }
                int  userId = int.Parse(getBlock(1));
                Clan clan   = usr.clan;

                if (clan != null)
                {
                    DataTable dt = DB.RunReader("SELECT * FROM users WHERE id='" + userId + "'");
                    if (dt.Rows.Count > 0)
                    {
                        DataRow row = dt.Rows[0];
                        if (userId != usr.userId)
                        {
                            DB.RunQuery("UPDATE users SET clanrank='0' WHERE id='" + usr.userId + "'");
                            DB.RunQuery("UPDATE users SET clanrank='2' WHERE id='" + userId + "'");
                            clan.Master    = row["nickname"].ToString();
                            clan.MasterEXP = row["exp"].ToString();
                            clan.ClanUsers.Values.Where(r => string.Compare(r.nickname, clan.Master, true) == 0).First().clanrank  = 2;
                            clan.ClanUsers.Values.Where(r => string.Compare(r.nickname, usr.nickname, true) == 0).First().clanrank = 0;

                            byte[] buffer = (new SP_Chat("ClanSystem", SP_Chat.ChatType.Clan, "ClanSystem >> " + usr.nickname + " passed master to " + clan.Master + " :/", (uint)clan.id, "NULL")).GetBytes();

                            foreach (User u in clan.Users.Values)
                            {
                                u.sendBuffer(buffer);
                            }

                            usr.send(new SP_Clan.Change());
                        }
                    }
                }
                break;
            }

            case Subtype.NickChange:
            {
                if (usr.clan == null)
                {
                    return;
                }
                string newNick = getBlock(1);
                Clan   c       = ClanManager.GetClanByName(newNick);
                if (usr.clan != null)
                {
                    if (c == null)
                    {
                        if (usr.HasItem("CB02"))         //>--- CHG_CLANNICK
                        {
                            DB.RunQuery("UPDATE clans SET name='" + newNick + "' WHERE id='" + usr.clan.id + "'");
                            c.name = newNick;
                            usr.deleteItem("CB02");
                            usr.send(new SP_Clan.Change(usr, true));
                        }
                    }
                    else
                    {
                        usr.send(new SP_Chat("SYSTEM", SP_Chat.ChatType.Whisper, "SYSTEM >> A clan has already this name, please choose another one", usr.sessionId, usr.nickname));
                    }
                }

                break;
            }

            case Subtype.MarkChange:
            {
                if (usr.clan == null)
                {
                    return;
                }
                uint iconID = uint.Parse(getBlock(1));
                if (usr.HasItem("CB54") && usr.clan != null)         //>--- CHG_CLANMARK
                {
                    DB.RunQuery("UPDATE clans SET iconid='" + iconID + "' WHERE id='" + usr.clan.id + "'");
                    usr.clan.iconid = iconID;

                    usr.deleteItem("CB54");
                    usr.send(new SP_Clan.Change(usr, false));
                }
                break;
            }

            case Subtype.DisbandClan:
            {
                if (usr.clan == null)
                {
                    return;
                }
                ClanManager.RemoveClan(usr);
                break;
            }

            case Subtype.NewSearchClan:
            {
                int         page     = int.Parse(getBlock(1));
                int         sortType = int.Parse(getBlock(2));
                List <Clan> clans    = new List <Clan>();

                switch (sortType)
                {
                case 0:             // By rank desc
                {
                    clans = ClanManager.Clans.Values.OrderByDescending(r => r.exp).Skip(page * 10).Take(10).ToList();
                    break;
                }

                case 1:             // By rank asc
                {
                    clans = ClanManager.Clans.Values.OrderBy(r => r.exp).Skip(page * 10).Take(10).ToList();
                    break;
                }
                }

                usr.send(new SP_Clan.SearchClan(page, sortType, clans));
                break;
            }

            default:
            {
                Log.WriteError("Unknown Clan Subtype " + (int)Subtype.DisbandClan);
                break;
            }
            }
        }
Beispiel #9
0
 public override void run()
 {
     try
     {
         Account player = this._client._player;
         if (player == null)
         {
             return;
         }
         Clan clan = new Clan()
         {
             _name        = this.clanName,
             _info        = this.clanInfo,
             _logo        = 0,
             owner_id     = player.player_id,
             creationDate = int.Parse(DateTime.Now.ToString("yyyyMMdd"))
         };
         if (player.clanId > 0 || PlayerManager.getRequestClanId(player.player_id) > 0)
         {
             this.erro = 2147487836U;
         }
         else if (0 > player._gp - ConfigGS.minCreateGold || ConfigGS.minCreateRank > player._rank)
         {
             this.erro = 2147487818U;
         }
         else
         {
             if (ClanManager.isClanNameExist(clan._name))
             {
                 this.erro = 2147487834U;
                 return;
             }
             if (ClanManager._clans.Count > ConfigGS.maxActiveClans)
             {
                 this.erro = 2147487829U;
             }
             else if (PlayerManager.CreateClan(out clan._id, clan._name, clan.owner_id, clan._info, clan.creationDate) && PlayerManager.updateAccountGold(player.player_id, player._gp - ConfigGS.minCreateGold))
             {
                 clan.BestPlayers.SetDefault();
                 player.clanDate = clan.creationDate;
                 if (ComDiv.updateDB("accounts", "player_id", (object)player.player_id, new string[3]
                 {
                     "clanaccess",
                     "clandate",
                     "clan_id"
                 }, new object[3]
                 {
                     (object)1,
                     (object)clan.creationDate,
                     (object)clan._id
                 }))
                 {
                     if (clan._id > 0)
                     {
                         player.clanId     = clan._id;
                         player.clanAccess = 1;
                         ClanManager.AddClan(clan);
                         SEND_CLAN_INFOS.Load(clan, 0);
                         player._gp -= ConfigGS.minCreateGold;
                     }
                     else
                     {
                         this.erro = 2147487819U;
                     }
                 }
                 else
                 {
                     this.erro = 2147487816U;
                 }
             }
             else
             {
                 this.erro = 2147487816U;
             }
         }
         this._client.SendPacket((SendPacket) new CLAN_CREATE_PAK(this.erro, clan, player));
     }
     catch (Exception ex)
     {
         Logger.warning("[CLAN_CREATE_REC] " + ex.ToString());
     }
 }