static bool HandleSetRegEmailCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } //- We do not want anything short of console to use this by default. //- So we force that. if (handler.GetSession()) { return(false); } // Get the command line arguments string accountName = args.NextString(); string email = args.NextString(); string emailConfirmation = args.NextString(); if (string.IsNullOrEmpty(accountName) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(emailConfirmation)) { handler.SendSysMessage(CypherStrings.CmdSyntax); return(false); } uint targetAccountId = Global.AccountMgr.GetId(accountName); if (targetAccountId == 0) { handler.SendSysMessage(CypherStrings.AccountNotExist, accountName); return(false); } // can set email only for target with less security // This also restricts setting handler's own email. if (handler.HasLowerSecurityAccount(null, targetAccountId, true)) { return(false); } if (!email.Equals(emailConfirmation)) { handler.SendSysMessage(CypherStrings.NewEmailsNotMatch); return(false); } AccountOpResult result = Global.AccountMgr.ChangeRegEmail(targetAccountId, email); switch (result) { case AccountOpResult.Ok: handler.SendSysMessage(CypherStrings.CommandEmail); Log.outInfo(LogFilter.Player, "ChangeRegEmail: Account {0} [Id: {1}] had it's Registration Email changed to {2}.", accountName, targetAccountId, email); break; case AccountOpResult.NameNotExist: handler.SendSysMessage(CypherStrings.AccountNotExist, accountName); return(false); case AccountOpResult.EmailTooLong: handler.SendSysMessage(CypherStrings.EmailTooLong); return(false); default: handler.SendSysMessage(CypherStrings.CommandNotchangeemail); return(false); } return(true); }
static bool HandleListItemCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } string id = handler.ExtractKeyFromLink(args, "Hitem"); if (string.IsNullOrEmpty(id)) { return(false); } if (!uint.TryParse(id, out uint itemId) || itemId == 0) { handler.SendSysMessage(CypherStrings.CommandItemidinvalid, itemId); return(false); } ItemTemplate itemTemplate = Global.ObjectMgr.GetItemTemplate(itemId); if (itemTemplate == null) { handler.SendSysMessage(CypherStrings.CommandItemidinvalid, itemId); return(false); } if (!uint.TryParse(args.NextString(), out uint count)) { count = 10; } if (count == 0) { return(false); } // inventory case uint inventoryCount = 0; PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHAR_INVENTORY_COUNT_ITEM); stmt.AddValue(0, itemId); SQLResult result = DB.Characters.Query(stmt); if (!result.IsEmpty()) { inventoryCount = result.Read <uint>(0); } stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHAR_INVENTORY_ITEM_BY_ENTRY); stmt.AddValue(0, itemId); stmt.AddValue(1, count); result = DB.Characters.Query(stmt); if (!result.IsEmpty()) { do { ObjectGuid itemGuid = ObjectGuid.Create(HighGuid.Item, result.Read <ulong>(0)); uint itemBag = result.Read <uint>(1); byte itemSlot = result.Read <byte>(2); ObjectGuid ownerGuid = ObjectGuid.Create(HighGuid.Player, result.Read <ulong>(3)); uint ownerAccountId = result.Read <uint>(4); string ownerName = result.Read <string>(5); string itemPos; if (Player.IsEquipmentPos((byte)itemBag, itemSlot)) { itemPos = "[equipped]"; } else if (Player.IsInventoryPos((byte)itemBag, itemSlot)) { itemPos = "[in inventory]"; } else if (Player.IsBankPos((byte)itemBag, itemSlot)) { itemPos = "[in bank]"; } else { itemPos = ""; } handler.SendSysMessage(CypherStrings.ItemlistSlot, itemGuid.ToString(), ownerName, ownerGuid.ToString(), ownerAccountId, itemPos); count--; }while (result.NextRow()); } // mail case uint mailCount = 0; stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_MAIL_COUNT_ITEM); stmt.AddValue(0, itemId); result = DB.Characters.Query(stmt); if (!result.IsEmpty()) { mailCount = result.Read <uint>(0); } if (count > 0) { stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_MAIL_ITEMS_BY_ENTRY); stmt.AddValue(0, itemId); stmt.AddValue(1, count); result = DB.Characters.Query(stmt); } else { result = null; } if (result != null && !result.IsEmpty()) { do { ulong itemGuid = result.Read <ulong>(0); ulong itemSender = result.Read <ulong>(1); ulong itemReceiver = result.Read <ulong>(2); uint itemSenderAccountId = result.Read <uint>(3); string itemSenderName = result.Read <string>(4); uint itemReceiverAccount = result.Read <uint>(5); string itemReceiverName = result.Read <string>(6); string itemPos = "[in mail]"; handler.SendSysMessage(CypherStrings.ItemlistMail, itemGuid, itemSenderName, itemSender, itemSenderAccountId, itemReceiverName, itemReceiver, itemReceiverAccount, itemPos); count--; }while (result.NextRow()); } // auction case uint auctionCount = 0; stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_AUCTIONHOUSE_COUNT_ITEM); stmt.AddValue(0, itemId); result = DB.Characters.Query(stmt); if (!result.IsEmpty()) { auctionCount = result.Read <uint>(0); } if (count > 0) { stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_AUCTIONHOUSE_ITEM_BY_ENTRY); stmt.AddValue(0, itemId); stmt.AddValue(1, count); result = DB.Characters.Query(stmt); } else { result = null; } if (result != null && !result.IsEmpty()) { do { ObjectGuid itemGuid = ObjectGuid.Create(HighGuid.Item, result.Read <ulong>(0)); ObjectGuid owner = ObjectGuid.Create(HighGuid.Player, result.Read <ulong>(1)); uint ownerAccountId = result.Read <uint>(2); string ownerName = result.Read <string>(3); string itemPos = "[in auction]"; handler.SendSysMessage(CypherStrings.ItemlistAuction, itemGuid.ToString(), ownerName, owner.ToString(), ownerAccountId, itemPos); }while (result.NextRow()); } // guild bank case uint guildCount = 0; stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_GUILD_BANK_COUNT_ITEM); stmt.AddValue(0, itemId); result = DB.Characters.Query(stmt); if (!result.IsEmpty()) { guildCount = result.Read <uint>(0); } stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_GUILD_BANK_ITEM_BY_ENTRY); stmt.AddValue(0, itemId); stmt.AddValue(1, count); result = DB.Characters.Query(stmt); if (!result.IsEmpty()) { do { ObjectGuid itemGuid = ObjectGuid.Create(HighGuid.Item, result.Read <ulong>(0)); ObjectGuid guildGuid = ObjectGuid.Create(HighGuid.Guild, result.Read <ulong>(1)); string guildName = result.Read <string>(2); string itemPos = "[in guild bank]"; handler.SendSysMessage(CypherStrings.ItemlistGuild, itemGuid.ToString(), guildName, guildGuid.ToString(), itemPos); count--; }while (result.NextRow()); } if (inventoryCount + mailCount + auctionCount + guildCount == 0) { handler.SendSysMessage(CypherStrings.CommandNoitemfound); return(false); } handler.SendSysMessage(CypherStrings.CommandListitemmessage, itemId, inventoryCount + mailCount + auctionCount + guildCount, inventoryCount, mailCount, auctionCount, guildCount); return(true); }
static bool PathCommand(StringArguments args, CommandHandler handler) { if (Global.MMapMgr.GetNavMesh(handler.GetPlayer().GetMapId()) == null) { handler.SendSysMessage("NavMesh not loaded for current map."); return(true); } handler.SendSysMessage("mmap path:"); // units Player player = handler.GetPlayer(); Unit target = handler.getSelectedUnit(); if (player == null || target == null) { handler.SendSysMessage("Invalid target/source selection."); return(true); } string para = args.NextString(); bool useStraightPath = false; if (para.Equals("true")) { useStraightPath = true; } bool useStraightLine = false; if (para.Equals("line")) { useStraightLine = true; } // unit locations float x, y, z; player.GetPosition(out x, out y, out z); // path PathGenerator path = new PathGenerator(target); path.SetUseStraightPath(useStraightPath); bool result = path.CalculatePath(x, y, z, false, useStraightLine); var pointPath = path.GetPath(); handler.SendSysMessage("{0}'s path to {1}:", target.GetName(), player.GetName()); handler.SendSysMessage("Building: {0}", useStraightPath ? "StraightPath" : useStraightLine ? "Raycast" : "SmoothPath"); handler.SendSysMessage("Result: {0} - Length: {1} - Type: {2}", (result ? "true" : "false"), pointPath.Length, path.GetPathType()); var start = path.GetStartPosition(); var end = path.GetEndPosition(); var actualEnd = path.GetActualEndPosition(); handler.SendSysMessage("StartPosition ({0:F3}, {1:F3}, {2:F3})", start.X, start.Y, start.Z); handler.SendSysMessage("EndPosition ({0:F3}, {1:F3}, {2:F3})", end.X, end.Y, end.Z); handler.SendSysMessage("ActualEndPosition ({0:F3}, {1:F3}, {2:F3})", actualEnd.X, actualEnd.Y, actualEnd.Z); if (!player.IsGameMaster()) { handler.SendSysMessage("Enable GM mode to see the path points."); } for (uint i = 0; i < pointPath.Length; ++i) { player.SummonCreature(1, pointPath[i].X, pointPath[i].Y, pointPath[i].Z, 0, TempSummonType.TimedDespawn, 9000); } return(true); }
static bool HandleModifyFactionCommand(StringArguments args, CommandHandler handler) { string pfactionid = handler.extractKeyFromLink(args, "Hfaction"); Creature target = handler.getSelectedCreature(); if (!target) { handler.SendSysMessage(CypherStrings.SelectCreature); return(false); } if (string.IsNullOrEmpty(pfactionid)) { uint _factionid = target.getFaction(); uint _flag = target.GetUInt32Value(UnitFields.Flags); ulong _npcflag = target.GetUInt64Value(UnitFields.NpcFlags); uint _dyflag = target.GetUInt32Value(ObjectFields.DynamicFlags); handler.SendSysMessage(CypherStrings.CurrentFaction, target.GetGUID().ToString(), _factionid, _flag, _npcflag, _dyflag); return(true); } uint factionid = uint.Parse(pfactionid); uint flag; string pflag = args.NextString(); if (string.IsNullOrEmpty(pflag)) { flag = target.GetUInt32Value(UnitFields.Flags); } else { flag = uint.Parse(pflag); } string pnpcflag = args.NextString(); ulong npcflag; if (string.IsNullOrEmpty(pnpcflag)) { npcflag = target.GetUInt64Value(UnitFields.NpcFlags); } else { npcflag = ulong.Parse(pnpcflag); } string pdyflag = args.NextString(); uint dyflag; if (string.IsNullOrEmpty(pdyflag)) { dyflag = target.GetUInt32Value(ObjectFields.DynamicFlags); } else { dyflag = uint.Parse(pdyflag); } if (!CliDB.FactionTemplateStorage.ContainsKey(factionid)) { handler.SendSysMessage(CypherStrings.WrongFaction, factionid); return(false); } handler.SendSysMessage(CypherStrings.YouChangeFaction, target.GetGUID().ToString(), factionid, flag, npcflag, dyflag); target.SetFaction(factionid); target.SetUInt32Value(UnitFields.Flags, flag); target.SetUInt64Value(UnitFields.NpcFlags, npcflag); target.SetUInt32Value(ObjectFields.DynamicFlags, dyflag); return(true); }
static bool Rep(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } Player target = handler.getSelectedPlayerOrSelf(); if (!target) { handler.SendSysMessage(CypherStrings.PlayerNotFound); return(false); } // check online security if (handler.HasLowerSecurity(target, ObjectGuid.Empty)) { return(false); } string factionTxt = handler.extractKeyFromLink(args, "Hfaction"); if (string.IsNullOrEmpty(factionTxt)) { return(false); } uint factionId = uint.Parse(factionTxt); int amount = 0; string rankTxt = args.NextString(); if (factionId == 0 || rankTxt.IsEmpty()) { return(false); } amount = int.Parse(rankTxt); if ((amount == 0) && !(amount < 0) && !rankTxt.IsNumber()) { string rankStr = rankTxt.ToLower(); int r = 0; amount = -42000; for (; r < (int)ReputationRank.Max; ++r) { string rank = handler.GetCypherString(ReputationMgr.ReputationRankStrIndex[r]); if (string.IsNullOrEmpty(rank)) { continue; } if (rank.Equals(rankStr)) { string deltaTxt = args.NextString(); if (!string.IsNullOrEmpty(deltaTxt)) { int delta = int.Parse(deltaTxt); if ((delta < 0) || (delta > ReputationMgr.PointsInRank[r] - 1)) { handler.SendSysMessage(CypherStrings.CommandFactionDelta, (ReputationMgr.PointsInRank[r] - 1)); return(false); } amount += delta; } break; } amount += ReputationMgr.PointsInRank[r]; } if (r >= (int)ReputationRank.Max) { handler.SendSysMessage(CypherStrings.CommandFactionInvparam, rankTxt); return(false); } } FactionRecord factionEntry = CliDB.FactionStorage.LookupByKey(factionId); if (factionEntry == null) { handler.SendSysMessage(CypherStrings.CommandFactionUnknown, factionId); return(false); } if (factionEntry.ReputationIndex < 0) { handler.SendSysMessage(CypherStrings.CommandFactionNorepError, factionEntry.Name[handler.GetSessionDbcLocale()], factionId); return(false); } target.GetReputationMgr().SetOneFactionReputation(factionEntry, amount, false); target.GetReputationMgr().SendState(target.GetReputationMgr().GetState(factionEntry)); handler.SendSysMessage(CypherStrings.CommandModifyRep, factionEntry.Name[handler.GetSessionDbcLocale()], factionId, handler.GetNameLink(target), target.GetReputationMgr().GetReputation(factionEntry)); return(true); }
static bool HandleChannelSetOwnership(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } string channelStr = args.NextString(); string argStr = args.NextString(""); if (channelStr.IsEmpty() || argStr.IsEmpty()) { return(false); } uint channelId = 0; foreach (var channelEntry in CliDB.ChatChannelsStorage.Values) { if (channelEntry.Name[handler.GetSessionDbcLocale()].Equals(channelStr)) { channelId = channelEntry.Id; break; } } AreaTableRecord zoneEntry = null; foreach (var entry in CliDB.AreaTableStorage.Values) { if (entry.AreaName[handler.GetSessionDbcLocale()].Equals(channelStr)) { zoneEntry = entry; break; } } Player player = handler.GetSession().GetPlayer(); Channel channel = null; ChannelManager cMgr = ChannelManager.ForTeam(player.GetTeam()); if (cMgr != null) { channel = cMgr.GetChannel(channelId, channelStr, player, false, zoneEntry); } if (argStr.ToLower() == "on") { if (channel != null) { channel.SetOwnership(true); } PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_CHANNEL_OWNERSHIP); stmt.AddValue(0, 1); stmt.AddValue(1, channelStr); DB.Characters.Execute(stmt); handler.SendSysMessage(CypherStrings.ChannelEnableOwnership, channelStr); } else if (argStr.ToLower() == "off") { if (channel != null) { channel.SetOwnership(false); } PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_CHANNEL_OWNERSHIP); stmt.AddValue(0, 0); stmt.AddValue(1, channelStr); DB.Characters.Execute(stmt); handler.SendSysMessage(CypherStrings.ChannelDisableOwnership, channelStr); } else { return(false); } return(true); }
static bool HandleGameObjectTurnCommand(StringArguments args, CommandHandler handler) { // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r string id = handler.extractKeyFromLink(args, "Hgameobject"); if (string.IsNullOrEmpty(id)) { return(false); } if (!ulong.TryParse(id, out ulong guidLow) || guidLow == 0) { return(false); } GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow); if (!obj) { handler.SendSysMessage(CypherStrings.CommandObjnotfound, guidLow); return(false); } string orientation = args.NextString(); float oz = 0.0f, oy = 0.0f, ox = 0.0f; if (!orientation.IsEmpty()) { if (!float.TryParse(orientation, out oz)) { return(false); } orientation = args.NextString(); if (!orientation.IsEmpty()) { if (!float.TryParse(orientation, out oy)) { return(false); } orientation = args.NextString(); if (!orientation.IsEmpty()) { if (!float.TryParse(orientation, out ox)) { return(false); } } } } else { Player player = handler.GetPlayer(); oz = player.GetOrientation(); } obj.Relocate(obj.GetPositionX(), obj.GetPositionY(), obj.GetPositionZ()); obj.RelocateStationaryPosition(obj.GetPositionX(), obj.GetPositionY(), obj.GetPositionZ(), obj.GetOrientation()); obj.SetWorldRotationAngles(oz, oy, ox); obj.DestroyForNearbyPlayers(); obj.UpdateObjectVisibility(); obj.SaveToDB(); handler.SendSysMessage(CypherStrings.CommandTurnobjmessage, obj.GetSpawnId(), obj.GetGoInfo().name, obj.GetGUID().ToString(), obj.GetOrientation()); return(true); }
static bool HandleAccountCreateCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } // Parse the command line arguments string accountName = args.NextString(); string password = args.NextString(); if (string.IsNullOrEmpty(accountName) || string.IsNullOrEmpty(password)) { return(false); } if (!accountName.Contains('@')) { handler.SendSysMessage(CypherStrings.AccountInvalidBnetName); return(false); } if (!bool.TryParse(args.NextString(), out bool createGameAccount)) { createGameAccount = true; } string gameAccountName; switch (Global.BNetAccountMgr.CreateBattlenetAccount(accountName, password, createGameAccount, out gameAccountName)) { case AccountOpResult.Ok: if (createGameAccount) { handler.SendSysMessage(CypherStrings.AccountCreatedBnetWithGame, accountName, gameAccountName); } else { handler.SendSysMessage(CypherStrings.AccountCreated, accountName); } if (handler.GetSession() != null) { Log.outInfo(LogFilter.Player, "Account: {0} (IP: {1}) Character:[{2}] ({3}) created Battle.net account {4}{5}{6}", handler.GetSession().GetAccountId(), handler.GetSession().GetRemoteAddress(), handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString(), accountName, createGameAccount ? " with game account " : "", createGameAccount ? gameAccountName : ""); } break; case AccountOpResult.NameTooLong: handler.SendSysMessage(CypherStrings.AccountNameTooLong); return(false); case AccountOpResult.PassTooLong: handler.SendSysMessage(CypherStrings.AccountPassTooLong); return(false); case AccountOpResult.NameAlreadyExist: handler.SendSysMessage(CypherStrings.AccountAlreadyExist); return(false); default: break; } return(true); }
static bool HandleWpEventCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } string show = args.NextString(); PreparedStatement stmt; // Check if ((show != "add") && (show != "mod") && (show != "del") && (show != "listid")) { return(false); } string arg_id = args.NextString(); uint id = 0; if (show == "add") { if (!string.IsNullOrEmpty(arg_id)) { id = uint.Parse(arg_id); } if (id != 0) { stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_SCRIPT_ID_BY_GUID); stmt.AddValue(0, id); SQLResult result = DB.World.Query(stmt); if (result.IsEmpty()) { stmt = DB.World.GetPreparedStatement(WorldStatements.INS_WAYPOINT_SCRIPT); stmt.AddValue(0, id); DB.World.Execute(stmt); handler.SendSysMessage("|cff00ff00Wp Event: New waypoint event added: {0}|r", "", id); } else { handler.SendSysMessage("|cff00ff00Wp Event: You have choosed an existing waypoint script guid: {0}|r", id); } } else { stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_SCRIPTS_MAX_ID); SQLResult result = DB.World.Query(stmt); id = result.Read <uint>(0); stmt = DB.World.GetPreparedStatement(WorldStatements.INS_WAYPOINT_SCRIPT); stmt.AddValue(0, id + 1); DB.World.Execute(stmt); handler.SendSysMessage("|cff00ff00Wp Event: New waypoint event added: |r|cff00ffff{0}|r", id + 1); } return(true); } if (show == "listid") { if (string.IsNullOrEmpty(arg_id)) { handler.SendSysMessage("|cff33ffffWp Event: You must provide waypoint script id.|r"); return(true); } id = uint.Parse(arg_id); uint a2, a3, a4, a5, a6; float a8, a9, a10, a11; string a7; stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_SCRIPT_BY_ID); stmt.AddValue(0, id); SQLResult result = DB.World.Query(stmt); if (result.IsEmpty()) { handler.SendSysMessage("|cff33ffffWp Event: No waypoint scripts found on id: {0}|r", id); return(true); } do { a2 = result.Read <uint>(0); a3 = result.Read <uint>(1); a4 = result.Read <uint>(2); a5 = result.Read <uint>(3); a6 = result.Read <uint>(4); a7 = result.Read <string>(5); a8 = result.Read <float>(6); a9 = result.Read <float>(7); a10 = result.Read <float>(8); a11 = result.Read <float>(9); handler.SendSysMessage("|cffff33ffid:|r|cff00ffff {0}|r|cff00ff00, guid: |r|cff00ffff{1}|r|cff00ff00, delay: |r|cff00ffff{2}|r|cff00ff00, command: |r|cff00ffff{3}|r|cff00ff00," + "datalong: |r|cff00ffff{4}|r|cff00ff00, datalong2: |r|cff00ffff{5}|r|cff00ff00, datatext: |r|cff00ffff{6}|r|cff00ff00, posx: |r|cff00ffff{7}|r|cff00ff00, " + "posy: |r|cff00ffff{8}|r|cff00ff00, posz: |r|cff00ffff{9}|r|cff00ff00, orientation: |r|cff00ffff{10}|r", id, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11); }while (result.NextRow()); } if (show == "del") { if (arg_id.IsEmpty()) { handler.SendSysMessage("|cffff33ffERROR: Waypoint script guid not present.|r"); return(true); } id = uint.Parse(arg_id); stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_SCRIPT_ID_BY_GUID); stmt.AddValue(0, id); SQLResult result = DB.World.Query(stmt); if (!result.IsEmpty()) { stmt = DB.World.GetPreparedStatement(WorldStatements.DEL_WAYPOINT_SCRIPT); stmt.AddValue(0, id); DB.World.Execute(stmt); handler.SendSysMessage("|cff00ff00{0}{1}|r", "Wp Event: Waypoint script removed: ", id); } else { handler.SendSysMessage("|cffff33ffWp Event: ERROR: you have selected a non existing script: {0}|r", id); } return(true); } if (show == "mod") { if (string.IsNullOrEmpty(arg_id)) { handler.SendSysMessage("|cffff33ffERROR: Waypoint script guid not present.|r"); return(true); } id = uint.Parse(arg_id); if (id == 0) { handler.SendSysMessage("|cffff33ffERROR: No vallid waypoint script id not present.|r"); return(true); } string arg_string = args.NextString(); if (string.IsNullOrEmpty(arg_string)) { handler.SendSysMessage("|cffff33ffERROR: No argument present.|r"); return(true); } if ((arg_string != "setid") && (arg_string != "delay") && (arg_string != "command") && (arg_string != "datalong") && (arg_string != "datalong2") && (arg_string != "dataint") && (arg_string != "posx") && (arg_string != "posy") && (arg_string != "posz") && (arg_string != "orientation")) { handler.SendSysMessage("|cffff33ffERROR: No valid argument present.|r"); return(true); } string arg_3 = args.NextString(); if (string.IsNullOrEmpty(arg_3)) { handler.SendSysMessage("|cffff33ffERROR: No additional argument present.|r"); return(true); } if (arg_string == "setid") { uint newid = uint.Parse(arg_3); handler.SendSysMessage("|cff00ff00Wp Event: Wypoint scipt guid: {0}|r|cff00ffff id changed: |r|cff00ff00{1}|r", newid, id); stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_ID); stmt.AddValue(0, newid); stmt.AddValue(1, id); DB.World.Execute(stmt); return(true); } else { stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_SCRIPT_ID_BY_GUID); stmt.AddValue(0, id); SQLResult result = DB.World.Query(stmt); if (result.IsEmpty()) { handler.SendSysMessage("|cffff33ffERROR: You have selected an non existing waypoint script guid.|r"); return(true); } if (arg_string == "posx") { stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_X); stmt.AddValue(0, float.Parse(arg_3)); stmt.AddValue(1, id); DB.World.Execute(stmt); handler.SendSysMessage("|cff00ff00Waypoint script:|r|cff00ffff {0}|r|cff00ff00 position_x updated.|r", id); return(true); } else if (arg_string == "posy") { stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_Y); stmt.AddValue(0, float.Parse(arg_3)); stmt.AddValue(1, id); DB.World.Execute(stmt); handler.SendSysMessage("|cff00ff00Waypoint script: {0} position_y updated.|r", id); return(true); } else if (arg_string == "posz") { stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_Z); stmt.AddValue(0, float.Parse(arg_3)); stmt.AddValue(1, id); DB.World.Execute(stmt); handler.SendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff{0}|r|cff00ff00 position_z updated.|r", id); return(true); } else if (arg_string == "orientation") { stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_O); stmt.AddValue(0, float.Parse(arg_3)); stmt.AddValue(1, id); DB.World.Execute(stmt); handler.SendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff{0}|r|cff00ff00 orientation updated.|r", id); return(true); } else if (arg_string == "dataint") { DB.World.Execute("UPDATE waypoint_scripts SET {0}='{1}' WHERE guid='{2}'", arg_string, uint.Parse(arg_3), id); // Query can't be a prepared statement handler.SendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff{0}|r|cff00ff00 dataint updated.|r", id); return(true); } else { DB.World.Execute("UPDATE waypoint_scripts SET {0}='{1}' WHERE guid='{2}'", arg_string, arg_string, id); // Query can't be a prepared statement } } handler.SendSysMessage("|cff00ff00Waypoint script:|r|cff00ffff{0}:|r|cff00ff00 {1} updated.|r", id, arg_string); } return(true); }
static bool HandleModifyGenderCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } Player target = handler.GetSelectedPlayerOrSelf(); if (!target) { handler.SendSysMessage(CypherStrings.PlayerNotFound); return(false); } PlayerInfo info = Global.ObjectMgr.GetPlayerInfo(target.GetRace(), target.GetClass()); if (info == null) { return(false); } string gender_str = args.NextString(); Gender gender; if (gender_str == "male") // MALE { if (target.GetGender() == Gender.Male) { return(true); } gender = Gender.Male; } else if (gender_str == "female") // FEMALE { if (target.GetGender() == Gender.Female) { return(true); } gender = Gender.Female; } else { handler.SendSysMessage(CypherStrings.MustMaleOrFemale); return(false); } // Set gender target.SetGender(gender); target.SetNativeSex(gender); // Change display ID target.InitDisplayIds(); target.RestoreDisplayId(false); Global.CharacterCacheStorage.UpdateCharacterGender(target.GetGUID(), (byte)gender); // Generate random customizations List <ChrCustomizationChoice> customizations = new(); var options = Global.DB2Mgr.GetCustomiztionOptions(target.GetRace(), gender); WorldSession worldSession = target.GetSession(); foreach (ChrCustomizationOptionRecord option in options) { ChrCustomizationReqRecord optionReq = CliDB.ChrCustomizationReqStorage.LookupByKey(option.ChrCustomizationReqID); if (optionReq != null && !worldSession.MeetsChrCustomizationReq(optionReq, target.GetClass(), false, customizations)) { continue; } // Loop over the options until the first one fits var choicesForOption = Global.DB2Mgr.GetCustomiztionChoices(option.Id); foreach (ChrCustomizationChoiceRecord choiceForOption in choicesForOption) { var choiceReq = CliDB.ChrCustomizationReqStorage.LookupByKey(choiceForOption.ChrCustomizationReqID); if (choiceReq != null && !worldSession.MeetsChrCustomizationReq(choiceReq, target.GetClass(), false, customizations)) { continue; } ChrCustomizationChoiceRecord choiceEntry = choicesForOption[0]; ChrCustomizationChoice choice = new(); choice.ChrCustomizationOptionID = option.Id; choice.ChrCustomizationChoiceID = choiceEntry.Id; customizations.Add(choice); break; } } target.SetCustomizations(customizations); handler.SendSysMessage(CypherStrings.YouChangeGender, handler.GetNameLink(target), gender); if (handler.NeedReportToTarget(target)) { target.SendSysMessage(CypherStrings.YourGenderChanged, gender, handler.GetNameLink()); } return(true); }
static bool HandleTicketAssignToCommand <T>(StringArguments args, CommandHandler handler) where T : Ticket { if (args.Empty()) { return(false); } uint ticketId = args.NextUInt32(); string target = args.NextString(); if (string.IsNullOrEmpty(target)) { return(false); } if (!ObjectManager.NormalizePlayerName(ref target)) { return(false); } T ticket = Global.SupportMgr.GetTicket <T>(ticketId); if (ticket == null || ticket.IsClosed()) { handler.SendSysMessage(CypherStrings.CommandTicketnotexist); return(true); } ObjectGuid targetGuid = Global.CharacterCacheStorage.GetCharacterGuidByName(target); uint accountId = Global.CharacterCacheStorage.GetCharacterAccountIdByGuid(targetGuid); // Target must exist and have administrative rights if (!Global.AccountMgr.HasPermission(accountId, RBACPermissions.CommandsBeAssignedTicket, Global.WorldMgr.GetRealm().Id.Realm)) { handler.SendSysMessage(CypherStrings.CommandTicketassignerrorA); return(true); } // If already assigned, leave if (ticket.IsAssignedTo(targetGuid)) { handler.SendSysMessage(CypherStrings.CommandTicketassignerrorB, ticket.GetId()); return(true); } // If assigned to different player other than current, leave //! Console can override though Player player = handler.GetSession() != null?handler.GetSession().GetPlayer() : null; if (player && ticket.IsAssignedNotTo(player.GetGUID())) { handler.SendSysMessage(CypherStrings.CommandTicketalreadyassigned, ticket.GetId()); return(true); } // Assign ticket ticket.SetAssignedTo(targetGuid, Global.AccountMgr.IsAdminAccount(Global.AccountMgr.GetSecurity(accountId, (int)Global.WorldMgr.GetRealm().Id.Realm))); ticket.SaveToDB(); string msg = ticket.FormatViewMessageString(handler, null, target, null, null); handler.SendGlobalGMSysMessage(msg); return(true); }
static bool HandleModifyRepCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } Player target = handler.GetSelectedPlayerOrSelf(); if (!target) { handler.SendSysMessage(CypherStrings.PlayerNotFound); return(false); } // check online security if (handler.HasLowerSecurity(target, ObjectGuid.Empty)) { return(false); } string factionTxt = handler.ExtractKeyFromLink(args, "Hfaction"); if (string.IsNullOrEmpty(factionTxt)) { return(false); } if (!uint.TryParse(factionTxt, out uint factionId)) { return(false); } string rankTxt = args.NextString(); if (factionId == 0 || !int.TryParse(rankTxt, out int amount)) { return(false); } var factionEntry = CliDB.FactionStorage.LookupByKey(factionId); if (factionEntry == null) { handler.SendSysMessage(CypherStrings.CommandFactionUnknown, factionId); return(false); } if (factionEntry.ReputationIndex < 0) { handler.SendSysMessage(CypherStrings.CommandFactionNorepError, factionEntry.Name[handler.GetSessionDbcLocale()], factionId); return(false); } // try to find rank by name if ((amount == 0) && !(amount < 0) && !rankTxt.IsNumber()) { string rankStr = rankTxt.ToLower(); int i = 0; int r = 0; for (; i != ReputationMgr.ReputationRankThresholds.Length - 1; ++i, ++r) { string rank = handler.GetCypherString(ReputationMgr.ReputationRankStrIndex[r]); if (string.IsNullOrEmpty(rank)) { continue; } if (rank.Equals(rankStr)) { break; } if (i == ReputationMgr.ReputationRankThresholds.Length - 1) { handler.SendSysMessage(CypherStrings.CommandFactionInvparam, rankTxt); return(false); } amount = ReputationMgr.ReputationRankThresholds[i]; string deltaTxt = args.NextString(); if (!string.IsNullOrEmpty(deltaTxt)) { int toNextRank = 0; var nextThresholdIndex = i; ++nextThresholdIndex; if (nextThresholdIndex != ReputationMgr.ReputationRankThresholds.Length - 1) { toNextRank = nextThresholdIndex - i; } if (!int.TryParse(deltaTxt, out int delta) || delta < 0 || delta >= toNextRank) { handler.SendSysMessage(CypherStrings.CommandFactionDelta, Math.Max(0, toNextRank - 1)); return(false); } amount += delta; } } } target.GetReputationMgr().SetOneFactionReputation(factionEntry, amount, false); target.GetReputationMgr().SendState(target.GetReputationMgr().GetState(factionEntry)); handler.SendSysMessage(CypherStrings.CommandModifyRep, factionEntry.Name[handler.GetSessionDbcLocale()], factionId, handler.GetNameLink(target), target.GetReputationMgr().GetReputation(factionEntry)); return(true); }
static RBACCommandData ReadParams(StringArguments args, CommandHandler handler, bool checkParams = true) { if (args.Empty()) { return(null); } string param1 = args.NextString(); string param2 = args.NextString(); string param3 = args.NextString(); int realmId = -1; uint accountId; string accountName; uint id = 0; RBACData rdata = null; bool useSelectedPlayer = false; if (checkParams) { if (string.IsNullOrEmpty(param3)) { if (!int.TryParse(param2, out realmId)) { return(null); } if (!uint.TryParse(param1, out id)) { return(null); } useSelectedPlayer = true; } else { if (!uint.TryParse(param2, out id)) { return(null); } if (!int.TryParse(param3, out realmId)) { return(null); } } if (id == 0) { handler.SendSysMessage(CypherStrings.RbacWrongParameterId, id); return(null); } if (realmId < -1 || realmId == 0) { handler.SendSysMessage(CypherStrings.RbacWrongParameterRealm, realmId); return(null); } } else if (string.IsNullOrEmpty(param1)) { useSelectedPlayer = true; } if (useSelectedPlayer) { Player player = handler.GetSelectedPlayer(); if (!player) { return(null); } rdata = player.GetSession().GetRBACData(); accountId = rdata.GetId(); Global.AccountMgr.GetName(accountId, out accountName); } else { accountName = param1; accountId = Global.AccountMgr.GetId(accountName); if (accountId == 0) { handler.SendSysMessage(CypherStrings.AccountNotExist, accountName); return(null); } } if (checkParams && handler.HasLowerSecurityAccount(null, accountId, true)) { return(null); } RBACCommandData data = new RBACCommandData(); if (rdata == null) { data.rbac = new RBACData(accountId, accountName, (int)Global.WorldMgr.GetRealm().Id.Index, (byte)Global.AccountMgr.GetSecurity(accountId, (int)Global.WorldMgr.GetRealm().Id.Index)); data.rbac.LoadFromDB(); data.needDelete = true; } else { data.rbac = rdata; } data.id = id; data.realmId = realmId; return(data); }
static bool HandleListCreatureCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r string id = handler.ExtractKeyFromLink(args, "Hcreature_entry"); if (string.IsNullOrEmpty(id)) { return(false); } if (!uint.TryParse(id, out uint creatureId) || creatureId == 0) { handler.SendSysMessage(CypherStrings.CommandInvalidcreatureid, creatureId); return(false); } CreatureTemplate cInfo = Global.ObjectMgr.GetCreatureTemplate(creatureId); if (cInfo == null) { handler.SendSysMessage(CypherStrings.CommandInvalidcreatureid, creatureId); return(false); } if (!uint.TryParse(args.NextString(), out uint count)) { count = 10; } if (count == 0) { return(false); } uint creatureCount = 0; SQLResult result = DB.World.Query("SELECT COUNT(guid) FROM creature WHERE id='{0}'", creatureId); if (!result.IsEmpty()) { creatureCount = result.Read <uint>(0); } if (handler.GetSession() != null) { Player player = handler.GetSession().GetPlayer(); result = DB.World.Query("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '{0}', 2) + POW(position_y - '{1}', 2) + POW(position_z - '{2}', 2)) AS order_ FROM creature WHERE id = '{3}' ORDER BY order_ ASC LIMIT {4}", player.GetPositionX(), player.GetPositionY(), player.GetPositionZ(), creatureId, count); } else { result = DB.World.Query("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '{0}' LIMIT {1}", creatureId, count); } if (!result.IsEmpty()) { do { ulong guid = result.Read <ulong>(0); float x = result.Read <float>(1); float y = result.Read <float>(2); float z = result.Read <float>(3); ushort mapId = result.Read <ushort>(4); if (handler.GetSession() != null) { handler.SendSysMessage(CypherStrings.CreatureListChat, guid, guid, cInfo.Name, x, y, z, mapId); } else { handler.SendSysMessage(CypherStrings.CreatureListConsole, guid, cInfo.Name, x, y, z, mapId); } }while (result.NextRow()); } handler.SendSysMessage(CypherStrings.CommandListcreaturemessage, creatureId, creatureCount); return(true); }
static bool HandleBanListCharacterCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } string filter = args.NextString(); if (string.IsNullOrEmpty(filter)) { return(false); } PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_GUID_BY_NAME_FILTER); stmt.AddValue(0, filter); SQLResult result = DB.Characters.Query(stmt); if (result.IsEmpty()) { handler.SendSysMessage(CypherStrings.BanlistNocharacter); return(true); } handler.SendSysMessage(CypherStrings.BanlistMatchingcharacter); // Chat short output if (handler.GetSession()) { do { PreparedStatement stmt2 = DB.Characters.GetPreparedStatement(CharStatements.SEL_BANNED_NAME); stmt2.AddValue(0, result.Read <ulong>(0)); SQLResult banResult = DB.Characters.Query(stmt2); if (!banResult.IsEmpty()) { handler.SendSysMessage(banResult.Read <string>(0)); } }while (result.NextRow()); } // Console wide output else { handler.SendSysMessage(CypherStrings.BanlistCharacters); handler.SendSysMessage(" =============================================================================== "); handler.SendSysMessage(CypherStrings.BanlistCharactersHeader); do { handler.SendSysMessage("-------------------------------------------------------------------------------"); string char_name = result.Read <string>(1); PreparedStatement stmt2 = DB.Characters.GetPreparedStatement(CharStatements.SEL_BANINFO_LIST); stmt2.AddValue(0, result.Read <ulong>(0)); SQLResult banInfo = DB.Characters.Query(stmt2); if (!banInfo.IsEmpty()) { do { long timeBan = banInfo.Read <uint>(0); DateTime tmBan = Time.UnixTimeToDateTime(timeBan); string bannedby = banInfo.Read <string>(2).Substring(0, 15); string banreason = banInfo.Read <string>(3).Substring(0, 15); if (banInfo.Read <uint>(0) == banInfo.Read <uint>(1)) { handler.SendSysMessage("|{0}|{1:D2}-{2:D2}-{3:D2} {4:D2}:{5:D2}| permanent |{6}|{7}|", char_name, tmBan.Year % 100, tmBan.Month + 1, tmBan.Day, tmBan.Hour, tmBan.Minute, bannedby, banreason); } else { long timeUnban = banInfo.Read <uint>(1); DateTime tmUnban = Time.UnixTimeToDateTime(timeUnban); handler.SendSysMessage("|{0}|{1:D2}-{2:D2}-{3:D2} {4:D2}:{5:D2}|{6:D2}-{7:D2}-{8:D2} {9:D2}:{10:D2}|{11}|{12}|", char_name, tmBan.Year % 100, tmBan.Month + 1, tmBan.Day, tmBan.Hour, tmBan.Minute, tmUnban.Year % 100, tmUnban.Month + 1, tmUnban.Day, tmUnban.Hour, tmUnban.Minute, bannedby, banreason); } }while (banInfo.NextRow()); } }while (result.NextRow()); handler.SendSysMessage(" =============================================================================== "); } return(true); }
static bool HandleWpAddCommand(StringArguments args, CommandHandler handler) { // optional string path_number = null; uint pathid = 0; if (!args.Empty()) { path_number = args.NextString(); } uint point = 0; Creature target = handler.getSelectedCreature(); PreparedStatement stmt; if (string.IsNullOrEmpty(path_number)) { if (target) { pathid = target.GetWaypointPath(); } else { stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_MAX_ID); SQLResult result1 = DB.World.Query(stmt); uint maxpathid = result1.Read <uint>(0); pathid = maxpathid + 1; handler.SendSysMessage("|cff00ff00New path started.|r"); } } else { pathid = uint.Parse(path_number); } // path_id . ID of the Path // point . number of the waypoint (if not 0) if (pathid == 0) { handler.SendSysMessage("|cffff33ffCurrent creature haven't loaded path.|r"); return(true); } stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_MAX_POINT); stmt.AddValue(0, pathid); SQLResult result = DB.World.Query(stmt); if (result.IsEmpty()) { point = result.Read <uint>(0); } Player player = handler.GetSession().GetPlayer(); stmt = DB.World.GetPreparedStatement(WorldStatements.INS_WAYPOINT_DATA); stmt.AddValue(0, pathid); stmt.AddValue(1, point + 1); stmt.AddValue(2, player.GetPositionX()); stmt.AddValue(3, player.GetPositionY()); stmt.AddValue(4, player.GetPositionZ()); DB.World.Execute(stmt); handler.SendSysMessage("|cff00ff00PathID: |r|cff00ffff{0} |r|cff00ff00: Waypoint |r|cff00ffff{1}|r|cff00ff00 created.|r", pathid, point + 1); return(true); }
static bool HandleBanListIPCommand(StringArguments args, CommandHandler handler) { PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.DEL_EXPIRED_IP_BANS); DB.Login.Execute(stmt); string filterStr = args.NextString(); string filter = !string.IsNullOrEmpty(filterStr) ? filterStr : ""; SQLResult result; if (string.IsNullOrEmpty(filter)) { stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_IP_BANNED_ALL); result = DB.Login.Query(stmt); } else { stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_IP_BANNED_BY_IP); stmt.AddValue(0, filter); result = DB.Login.Query(stmt); } if (result.IsEmpty()) { handler.SendSysMessage(CypherStrings.BanlistNoip); return(true); } handler.SendSysMessage(CypherStrings.BanlistMatchingip); // Chat short output if (handler.GetSession()) { do { handler.SendSysMessage("{0}", result.Read <string>(0)); }while (result.NextRow()); } // Console wide output else { handler.SendSysMessage(CypherStrings.BanlistIps); handler.SendSysMessage(" ==============================================================================="); handler.SendSysMessage(CypherStrings.BanlistIpsHeader); do { handler.SendSysMessage("-------------------------------------------------------------------------------"); long timeBan = result.Read <uint>(1); DateTime tmBan = Time.UnixTimeToDateTime(timeBan); string bannedby = result.Read <string>(3).Substring(0, 15); string banreason = result.Read <string>(4).Substring(0, 15); if (result.Read <uint>(1) == result.Read <uint>(2)) { handler.SendSysMessage("|{0}|{1:D2}-{2:D2}-{3:D2} {4:D2}:{5:D2}| permanent |{6}|{7}|", result.Read <string>(0), tmBan.Year % 100, tmBan.Month + 1, tmBan.Day, tmBan.Hour, tmBan.Minute, bannedby, banreason); } else { long timeUnban = result.Read <uint>(2); DateTime tmUnban; tmUnban = Time.UnixTimeToDateTime(timeUnban); handler.SendSysMessage("|{0}|{1:D2}-{2:D2}-{3:D2} {4:D2}:{5:D2}|{6:D2}-{7:D2}-{8:D2} {9:D2}:{10:D2}|{11}|{12}|", result.Read <string>(0), tmBan.Year % 100, tmBan.Month + 1, tmBan.Day, tmBan.Hour, tmBan.Minute, tmUnban.Year % 100, tmUnban.Month + 1, tmUnban.Day, tmUnban.Hour, tmUnban.Minute, bannedby, banreason); } }while (result.NextRow()); handler.SendSysMessage(" ==============================================================================="); } return(true); }
static bool HandleWpLoadCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } // optional string path_number = args.NextString(); uint pathid; ulong guidLow; Creature target = handler.getSelectedCreature(); // Did player provide a path_id? if (string.IsNullOrEmpty(path_number)) { return(false); } if (!target) { handler.SendSysMessage(CypherStrings.SelectCreature); return(false); } if (target.GetEntry() == 1) { handler.SendSysMessage("|cffff33ffYou want to load path to a waypoint? Aren't you?|r"); return(false); } pathid = uint.Parse(path_number); if (pathid == 0) { handler.SendSysMessage("|cffff33ffNo valid path number provided.|r"); return(true); } guidLow = target.GetSpawnId(); PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_CREATURE_ADDON_BY_GUID); stmt.AddValue(0, guidLow); SQLResult result = DB.World.Query(stmt); if (!result.IsEmpty()) { stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_CREATURE_ADDON_PATH); stmt.AddValue(0, pathid); stmt.AddValue(1, guidLow); } else { stmt = DB.World.GetPreparedStatement(WorldStatements.INS_CREATURE_ADDON); stmt.AddValue(0, guidLow); stmt.AddValue(1, pathid); } DB.World.Execute(stmt); stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_CREATURE_MOVEMENT_TYPE); stmt.AddValue(0, (byte)MovementGeneratorType.Waypoint); stmt.AddValue(1, guidLow); DB.World.Execute(stmt); target.LoadPath(pathid); target.SetDefaultMovementType(MovementGeneratorType.Waypoint); target.GetMotionMaster().Initialize(); target.Say("Path loaded.", Language.Universal); return(true); }
static bool HandleGameObjectMoveCommand(StringArguments args, CommandHandler handler) { // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r string id = handler.extractKeyFromLink(args, "Hgameobject"); if (string.IsNullOrEmpty(id)) { return(false); } if (!ulong.TryParse(id, out ulong guidLow) || guidLow == 0) { return(false); } GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow); if (!obj) { handler.SendSysMessage(CypherStrings.CommandObjnotfound, guidLow); return(false); } string toX = args.NextString(); string toY = args.NextString(); string toZ = args.NextString(); float x, y, z; if (string.IsNullOrEmpty(toX)) { Player player = handler.GetSession().GetPlayer(); player.GetPosition(out x, out y, out z); } else { if (!float.TryParse(toX, out x)) { return(false); } if (!float.TryParse(toY, out y)) { return(false); } if (!float.TryParse(toZ, out z)) { return(false); } if (!GridDefines.IsValidMapCoord(obj.GetMapId(), x, y, z)) { handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, obj.GetMapId()); return(false); } } obj.DestroyForNearbyPlayers(); obj.RelocateStationaryPosition(x, y, z, obj.GetOrientation()); obj.GetMap().GameObjectRelocation(obj, x, y, z, obj.GetOrientation()); obj.SaveToDB(); handler.SendSysMessage(CypherStrings.CommandMoveobjmessage, obj.GetSpawnId(), obj.GetGoInfo().name, obj.GetGUID().ToString()); return(true); }
static bool HandleWpModifyCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } // first arg: add del text emote spell waittime move string show = args.NextString(); if (string.IsNullOrEmpty(show)) { return(false); } // Check // Remember: "show" must also be the name of a column! if ((show != "delay") && (show != "action") && (show != "action_chance") && (show != "move_flag") && (show != "del") && (show != "move")) { return(false); } // Next arg is: <PATHID> <WPNUM> <ARGUMENT> string arg_str; // Did user provide a GUID // or did the user select a creature? // . variable lowguid is filled with the GUID of the NPC uint pathid; uint point; Creature target = handler.getSelectedCreature(); // User did select a visual waypoint? if (!target || target.GetEntry() != 1) { handler.SendSysMessage("|cffff33ffERROR: You must select a waypoint.|r"); return(false); } // Check the creature PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_BY_WPGUID); stmt.AddValue(0, target.GetSpawnId()); SQLResult result = DB.World.Query(stmt); if (result.IsEmpty()) { handler.SendSysMessage(CypherStrings.WaypointNotfoundsearch, target.GetGUID().ToString()); // Select waypoint number from database // Since we compare float values, we have to deal with // some difficulties. // Here we search for all waypoints that only differ in one from 1 thousand // See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html string maxDiff = "0.01"; stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_BY_POS); stmt.AddValue(0, target.GetPositionX()); stmt.AddValue(1, maxDiff); stmt.AddValue(2, target.GetPositionY()); stmt.AddValue(3, maxDiff); stmt.AddValue(4, target.GetPositionZ()); stmt.AddValue(5, maxDiff); result = DB.World.Query(stmt); if (result.IsEmpty()) { handler.SendSysMessage(CypherStrings.WaypointNotfounddbproblem, target.GetGUID().ToString()); return(true); } } do { pathid = result.Read <uint>(0); point = result.Read <uint>(1); }while (result.NextRow()); // We have the waypoint number and the GUID of the "master npc" // Text is enclosed in "<>", all other arguments not arg_str = args.NextString(); // Check for argument if (show != "del" && show != "move" && arg_str == null) { handler.SendSysMessage(CypherStrings.WaypointArgumentreq, show); return(false); } if (show == "del") { handler.SendSysMessage("|cff00ff00DEBUG: wp modify del, PathID: |r|cff00ffff{0}|r", pathid); target.DeleteFromDB(); target.AddObjectToRemoveList(); stmt = DB.World.GetPreparedStatement(WorldStatements.DEL_WAYPOINT_DATA); stmt.AddValue(0, pathid); stmt.AddValue(1, point); DB.World.Execute(stmt); stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_DATA_POINT); stmt.AddValue(0, pathid); stmt.AddValue(1, point); DB.World.Execute(stmt); handler.SendSysMessage(CypherStrings.WaypointRemoved); return(true); } // del if (show == "move") { handler.SendSysMessage("|cff00ff00DEBUG: wp move, PathID: |r|cff00ffff{0}|r", pathid); Player chr = handler.GetSession().GetPlayer(); Map map = chr.GetMap(); // What to do: // Move the visual spawnpoint // Respawn the owner of the waypoints target.DeleteFromDB(); target.AddObjectToRemoveList(); // re-create Creature wpCreature = new Creature(); if (!wpCreature.Create(map.GenerateLowGuid(HighGuid.Creature), map, chr.GetPhaseMask(), 1, chr.GetPositionX(), chr.GetPositionY(), chr.GetPositionZ(), chr.GetOrientation())) { wpCreature.CopyPhaseFrom(chr); wpCreature.SaveToDB(map.GetId(), (1u << (int)map.GetSpawnMode()), chr.GetPhaseMask()); // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells(); /// @todo Should we first use "Create" then use "LoadFromDB"? if (!wpCreature.LoadCreatureFromDB(wpCreature.GetSpawnId(), map)) { handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, 1); return(false); } stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_DATA_POSITION); stmt.AddValue(0, chr.GetPositionX()); stmt.AddValue(1, chr.GetPositionY()); stmt.AddValue(2, chr.GetPositionZ()); stmt.AddValue(3, pathid); stmt.AddValue(4, point); DB.World.Execute(stmt); handler.SendSysMessage(CypherStrings.WaypointChanged); } return(true); } // move if (string.IsNullOrEmpty(arg_str)) { // show_str check for present in list of correct values, no sql injection possible DB.World.Execute("UPDATE waypoint_data SET {0}=null WHERE id='{1}' AND point='{2}'", show, pathid, point); // Query can't be a prepared statement } else { // show_str check for present in list of correct values, no sql injection possible DB.World.Execute("UPDATE waypoint_data SET {0}='{1}' WHERE id='{2}' AND point='{3}'", show, arg_str, pathid, point); // Query can't be a prepared statement } handler.SendSysMessage(CypherStrings.WaypointChangedNo, show); return(true); }
static bool HandleGameObjectSetStateCommand(StringArguments args, CommandHandler handler) { // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r string id = handler.extractKeyFromLink(args, "Hgameobject"); if (string.IsNullOrEmpty(id)) { return(false); } if (!ulong.TryParse(id, out ulong guidLow) || guidLow == 0) { return(false); } GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow); if (!obj) { handler.SendSysMessage(CypherStrings.CommandObjnotfound, guidLow); return(false); } string type = args.NextString(); if (string.IsNullOrEmpty(type)) { return(false); } if (!int.TryParse(type, out int objectType)) { return(false); } if (objectType < 0) { if (objectType == -1) { obj.SendGameObjectDespawn(); } else if (objectType == -2) { return(false); } return(true); } string state = args.NextString(); if (string.IsNullOrEmpty(state)) { return(false); } if (!uint.TryParse(state, out uint objectState)) { return(false); } if (objectType < 4) { obj.SetByteValue(GameObjectFields.Bytes1, (byte)objectType, (byte)objectState); } else if (objectType == 4) { obj.SendCustomAnim(objectState); } else if (objectType == 5) { if (objectState < 0 || objectState > (uint)GameObjectDestructibleState.Rebuilding) { return(false); } obj.SetDestructibleState((GameObjectDestructibleState)objectState); } handler.SendSysMessage("Set gobject type {0} state {1}", objectType, objectState); return(true); }
static bool HandleWpShowCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } // first arg: on, off, first, last string show = args.NextString(); if (string.IsNullOrEmpty(show)) { return(false); } // second arg: GUID (optional, if a creature is selected) string guid_str = args.NextString(); uint pathid = 0; Creature target = handler.getSelectedCreature(); // Did player provide a PathID? if (string.IsNullOrEmpty(guid_str)) { // No PathID provided // . Player must have selected a creature if (!target) { handler.SendSysMessage(CypherStrings.SelectCreature); return(false); } pathid = target.GetWaypointPath(); } else { // PathID provided // Warn if player also selected a creature // . Creature selection is ignored <- if (target) { handler.SendSysMessage(CypherStrings.WaypointCreatselected); } pathid = uint.Parse(guid_str); } // Show info for the selected waypoint if (show == "info") { // Check if the user did specify a visual waypoint if (!target || target.GetEntry() != 1) { handler.SendSysMessage(CypherStrings.WaypointVpSelect); return(false); } PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_ALL_BY_WPGUID); stmt.AddValue(0, target.GetSpawnId()); SQLResult result = DB.World.Query(stmt); if (result.IsEmpty()) { handler.SendSysMessage(CypherStrings.WaypointNotfounddbproblem, target.GetSpawnId()); return(true); } handler.SendSysMessage("|cff00ffffDEBUG: wp show info:|r"); do { pathid = result.Read <uint>(0); uint point = result.Read <uint>(1); uint delay = result.Read <uint>(2); uint flag = result.Read <uint>(3); uint ev_id = result.Read <uint>(4); uint ev_chance = result.Read <uint>(5); handler.SendSysMessage("|cff00ff00Show info: for current point: |r|cff00ffff{0}|r|cff00ff00, Path ID: |r|cff00ffff{1}|r", point, pathid); handler.SendSysMessage("|cff00ff00Show info: delay: |r|cff00ffff{0}|r", delay); handler.SendSysMessage("|cff00ff00Show info: Move flag: |r|cff00ffff{0}|r", flag); handler.SendSysMessage("|cff00ff00Show info: Waypoint event: |r|cff00ffff{0}|r", ev_id); handler.SendSysMessage("|cff00ff00Show info: Event chance: |r|cff00ffff{0}|r", ev_chance); }while (result.NextRow()); return(true); } if (show == "on") { PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_POS_BY_ID); stmt.AddValue(0, pathid); SQLResult result = DB.World.Query(stmt); if (result.IsEmpty()) { handler.SendSysMessage("|cffff33ffPath no found.|r"); return(false); } handler.SendSysMessage("|cff00ff00DEBUG: wp on, PathID: |cff00ffff{0}|r", pathid); // Delete all visuals for this NPC stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_WPGUID_BY_ID); stmt.AddValue(0, pathid); SQLResult result2 = DB.World.Query(stmt); if (!result2.IsEmpty()) { bool hasError = false; do { ulong wpguid = result2.Read <ulong>(0); Creature creature = handler.GetCreatureFromPlayerMapByDbGuid(wpguid); if (!creature) { handler.SendSysMessage(CypherStrings.WaypointNotremoved, wpguid); hasError = true; stmt = DB.World.GetPreparedStatement(WorldStatements.DEL_CREATURE); stmt.AddValue(0, wpguid); DB.World.Execute(stmt); } else { creature.CombatStop(); creature.DeleteFromDB(); creature.AddObjectToRemoveList(); } }while (result2.NextRow()); if (hasError) { handler.SendSysMessage(CypherStrings.WaypointToofar1); handler.SendSysMessage(CypherStrings.WaypointToofar2); handler.SendSysMessage(CypherStrings.WaypointToofar3); } } do { uint point = result.Read <uint>(0); float x = result.Read <float>(1); float y = result.Read <float>(2); float z = result.Read <float>(3); uint id = 1; Player chr = handler.GetSession().GetPlayer(); Map map = chr.GetMap(); float o = chr.GetOrientation(); Creature wpCreature = new Creature(); if (!wpCreature.Create(map.GenerateLowGuid(HighGuid.Creature), map, chr.GetPhaseMask(), id, x, y, z, o)) { handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, id); return(false); } wpCreature.CopyPhaseFrom(chr); wpCreature.SaveToDB(map.GetId(), (1u << (int)map.GetSpawnMode()), chr.GetPhaseMask()); // Set "wpguid" column to the visual waypoint stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_DATA_WPGUID); stmt.AddValue(0, wpCreature.GetSpawnId()); stmt.AddValue(1, pathid); stmt.AddValue(2, point); DB.World.Execute(stmt); // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells(); if (!wpCreature.LoadCreatureFromDB(wpCreature.GetSpawnId(), map)) { handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, id); return(false); } if (target) { wpCreature.SetDisplayId(target.GetDisplayId()); wpCreature.SetObjectScale(0.5f); wpCreature.SetLevel(Math.Min(point, SharedConst.StrongMaxLevel)); } }while (result.NextRow()); handler.SendSysMessage("|cff00ff00Showing the current creature's path.|r"); return(true); } if (show == "first") { handler.SendSysMessage("|cff00ff00DEBUG: wp first, GUID: {0}|r", pathid); PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_POS_FIRST_BY_ID); stmt.AddValue(0, pathid); SQLResult result = DB.World.Query(stmt); if (result.IsEmpty()) { handler.SendSysMessage(CypherStrings.WaypointNotfound, pathid); return(false); } float x = result.Read <float>(0); float y = result.Read <float>(1); float z = result.Read <float>(2); uint id = 1; Player chr = handler.GetSession().GetPlayer(); float o = chr.GetOrientation(); Map map = chr.GetMap(); Creature creature = new Creature(); if (!creature.Create(map.GenerateLowGuid(HighGuid.Creature), map, chr.GetPhaseMask(), id, x, y, z, o)) { handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, id); return(false); } creature.CopyPhaseFrom(chr); creature.SaveToDB(map.GetId(), (uint)(1 << (int)map.GetSpawnMode()), chr.GetPhaseMask()); if (!creature.LoadCreatureFromDB(creature.GetSpawnId(), map)) { handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, id); return(false); } if (target) { creature.SetDisplayId(target.GetDisplayId()); creature.SetObjectScale(0.5f); } return(true); } if (show == "last") { handler.SendSysMessage("|cff00ff00DEBUG: wp last, PathID: |r|cff00ffff{0}|r", pathid); PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_POS_LAST_BY_ID); stmt.AddValue(0, pathid); SQLResult result = DB.World.Query(stmt); if (result.IsEmpty()) { handler.SendSysMessage(CypherStrings.WaypointNotfoundlast, pathid); return(false); } float x = result.Read <float>(0); float y = result.Read <float>(1); float z = result.Read <float>(2); float o = result.Read <float>(3); uint id = 1; Player chr = handler.GetSession().GetPlayer(); Map map = chr.GetMap(); Creature creature = new Creature(); if (!creature.Create(map.GenerateLowGuid(HighGuid.Creature), map, chr.GetPhaseMask(), id, x, y, z, o)) { handler.SendSysMessage(CypherStrings.WaypointNotcreated, id); return(false); } creature.CopyPhaseFrom(chr); creature.SaveToDB(map.GetId(), (uint)(1 << (int)map.GetSpawnMode()), chr.GetPhaseMask()); if (!creature.LoadCreatureFromDB(creature.GetSpawnId(), map)) { handler.SendSysMessage(CypherStrings.WaypointNotcreated, id); return(false); } if (target) { creature.SetDisplayId(target.GetDisplayId()); creature.SetObjectScale(0.5f); } return(true); } if (show == "off") { PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_CREATURE_BY_ID); stmt.AddValue(0, 1); SQLResult result = DB.World.Query(stmt); if (result.IsEmpty()) { handler.SendSysMessage(CypherStrings.WaypointVpNotfound); return(false); } bool hasError = false; do { ulong lowguid = result.Read <ulong>(0); Creature creature = handler.GetCreatureFromPlayerMapByDbGuid(lowguid); if (!creature) { handler.SendSysMessage(CypherStrings.WaypointNotremoved, lowguid); hasError = true; stmt = DB.World.GetPreparedStatement(WorldStatements.DEL_CREATURE); stmt.AddValue(0, lowguid); DB.World.Execute(stmt); } else { creature.CombatStop(); creature.DeleteFromDB(); creature.AddObjectToRemoveList(); } }while (result.NextRow()); // set "wpguid" column to "empty" - no visual waypoint spawned stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_DATA_ALL_WPGUID); DB.World.Execute(stmt); //DB.World.PExecute("UPDATE creature_movement SET wpguid = '0' WHERE wpguid <> '0'"); if (hasError) { handler.SendSysMessage(CypherStrings.WaypointToofar1); handler.SendSysMessage(CypherStrings.WaypointToofar2); handler.SendSysMessage(CypherStrings.WaypointToofar3); } handler.SendSysMessage(CypherStrings.WaypointVpAllremoved); return(true); } handler.SendSysMessage("|cffff33ffDEBUG: wpshow - no valid command found|r"); return(true); }
static bool HandleModifySpellCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } byte spellflatid = args.NextByte(); if (spellflatid == 0) { return(false); } byte op = args.NextByte(); if (op == 0) { return(false); } ushort val = args.NextUInt16(); if (val == 0) { return(false); } ushort mark; string pmark = args.NextString(); if (string.IsNullOrEmpty(pmark)) { mark = 65535; } else { mark = ushort.Parse(pmark); } Player target = handler.getSelectedPlayerOrSelf(); if (!target) { handler.SendSysMessage(CypherStrings.NoCharSelected); return(false); } // check online security if (handler.HasLowerSecurity(target, ObjectGuid.Empty)) { return(false); } handler.SendSysMessage(CypherStrings.YouChangeSpellflatid, spellflatid, val, mark, handler.GetNameLink(target)); if (handler.needReportToTarget(target)) { target.SendSysMessage(CypherStrings.YoursSpellflatidChanged, handler.GetNameLink(), spellflatid, val, mark); } SetSpellModifier packet = new SetSpellModifier(ServerOpcodes.SetFlatSpellModifier); SpellModifierInfo spellMod = new SpellModifierInfo(); spellMod.ModIndex = op; SpellModifierData modData; modData.ClassIndex = spellflatid; modData.ModifierValue = val; spellMod.ModifierData.Add(modData); packet.Modifiers.Add(spellMod); target.SendPacket(packet); return(true); }
static bool HandleCharacterRenameCommand(StringArguments args, CommandHandler handler) { Player target; ObjectGuid targetGuid; string targetName; if (!handler.extractPlayerTarget(args, out target, out targetGuid, out targetName)) { return(false); } string newNameStr = args.NextString(); if (!string.IsNullOrEmpty(newNameStr)) { string playerOldName; string newName = newNameStr; if (target) { // check online security if (handler.HasLowerSecurity(target, ObjectGuid.Empty)) { return(false); } playerOldName = target.GetName(); } else { // check offline security if (handler.HasLowerSecurity(null, targetGuid)) { return(false); } ObjectManager.GetPlayerNameByGUID(targetGuid, out playerOldName); } if (!ObjectManager.NormalizePlayerName(ref newName)) { handler.SendSysMessage(CypherStrings.BadValue); return(false); } if (ObjectManager.CheckPlayerName(newName, target ? target.GetSession().GetSessionDbcLocale() : Global.WorldMgr.GetDefaultDbcLocale(), true) != ResponseCodes.CharNameSuccess) { handler.SendSysMessage(CypherStrings.BadValue); return(false); } WorldSession session = handler.GetSession(); if (session != null) { if (!session.HasPermission(RBACPermissions.SkipCheckCharacterCreationReservedname) && Global.ObjectMgr.IsReservedName(newName)) { handler.SendSysMessage(CypherStrings.ReservedName); return(false); } } PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHECK_NAME); stmt.AddValue(0, newName); SQLResult result = DB.Characters.Query(stmt); if (!result.IsEmpty()) { handler.SendSysMessage(CypherStrings.RenamePlayerAlreadyExists, newName); return(false); } // Remove declined name from db stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CHAR_DECLINED_NAME); stmt.AddValue(0, targetGuid.GetCounter()); DB.Characters.Execute(stmt); if (target) { target.SetName(newName); session = target.GetSession(); if (session != null) { session.KickPlayer(); } } else { stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_NAME_BY_GUID); stmt.AddValue(0, newName); stmt.AddValue(1, targetGuid.GetCounter()); DB.Characters.Execute(stmt); } Global.WorldMgr.UpdateCharacterInfo(targetGuid, newName); handler.SendSysMessage(CypherStrings.RenamePlayerWithNewName, playerOldName, newName); Player player = handler.GetPlayer(); if (player) { Log.outCommand(session.GetAccountId(), "GM {0} (Account: {1}) forced rename {2} to player {3} (Account: {4})", player.GetName(), session.GetAccountId(), newName, playerOldName, ObjectManager.GetPlayerAccountIdByGUID(targetGuid)); } else { Log.outCommand(0, "CONSOLE forced rename '{0}' to '{1}' ({2})", playerOldName, newName, targetGuid.ToString()); } } else { if (target) { // check online security if (handler.HasLowerSecurity(target, ObjectGuid.Empty)) { return(false); } handler.SendSysMessage(CypherStrings.RenamePlayer, handler.GetNameLink(target)); target.SetAtLoginFlag(AtLoginFlags.Rename); } else { // check offline security if (handler.HasLowerSecurity(null, targetGuid)) { return(false); } string oldNameLink = handler.playerLink(targetName); handler.SendSysMessage(CypherStrings.RenamePlayerGuid, oldNameLink, targetGuid.ToString()); PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_ADD_AT_LOGIN_FLAG); stmt.AddValue(0, AtLoginFlags.Rename); stmt.AddValue(1, targetGuid.GetCounter()); DB.Characters.Execute(stmt); } } return(true); }
static bool HandleModifyGenderCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } Player target = handler.getSelectedPlayerOrSelf(); if (!target) { handler.SendSysMessage(CypherStrings.PlayerNotFound); return(false); } PlayerInfo info = Global.ObjectMgr.GetPlayerInfo(target.GetRace(), target.GetClass()); if (info == null) { return(false); } string gender_str = args.NextString(); Gender gender; if (gender_str == "male") // MALE { if (target.GetGender() == Gender.Male) { return(true); } gender = Gender.Male; } else if (gender_str == "female") // FEMALE { if (target.GetGender() == Gender.Female) { return(true); } gender = Gender.Female; } else { handler.SendSysMessage(CypherStrings.MustMaleOrFemale); return(false); } // Set gender target.SetByteValue(UnitFields.Bytes0, 3, (byte)gender); target.SetByteValue(PlayerFields.Bytes3, PlayerFieldOffsets.Bytes3OffsetGender, (byte)gender); // Change display ID target.InitDisplayIds(); handler.SendSysMessage(CypherStrings.YouChangeGender, handler.GetNameLink(target), gender); if (handler.needReportToTarget(target)) { target.SendSysMessage(CypherStrings.YourGenderChanged, gender, handler.GetNameLink()); } return(true); }
static bool HandleBanHelper(BanMode mode, StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } string nameOrIP = args.NextString(); if (string.IsNullOrEmpty(nameOrIP)) { return(false); } string durationStr = args.NextString(); if (!uint.TryParse(durationStr, out uint duration)) { return(false); } string reasonStr = args.NextString(""); if (string.IsNullOrEmpty(reasonStr)) { return(false); } switch (mode) { case BanMode.Character: if (!ObjectManager.NormalizePlayerName(ref nameOrIP)) { handler.SendSysMessage(CypherStrings.PlayerNotFound); return(false); } break; case BanMode.IP: IPAddress address; if (!IPAddress.TryParse(nameOrIP, out address)) { return(false); } break; } string author = handler.GetSession() ? handler.GetSession().GetPlayerName() : "Server"; switch (Global.WorldMgr.BanAccount(mode, nameOrIP, durationStr, reasonStr, author)) { case BanReturn.Success: if (!uint.TryParse(durationStr, out uint tempValue) || tempValue > 0) { if (WorldConfig.GetBoolValue(WorldCfg.ShowBanInWorld)) { Global.WorldMgr.SendWorldText(CypherStrings.BanAccountYoubannedmessageWorld, author, nameOrIP, Time.secsToTimeString(Time.TimeStringToSecs(durationStr)).ToString(), reasonStr); } else { handler.SendSysMessage(CypherStrings.BanYoubanned, nameOrIP, Time.secsToTimeString(Time.TimeStringToSecs(durationStr), true), reasonStr); } } else { if (WorldConfig.GetBoolValue(WorldCfg.ShowBanInWorld)) { Global.WorldMgr.SendWorldText(CypherStrings.BanAccountYoupermbannedmessageWorld, author, nameOrIP, reasonStr); } else { handler.SendSysMessage(CypherStrings.BanYoupermbanned, nameOrIP, reasonStr); } } break; case BanReturn.SyntaxError: return(false); case BanReturn.Notfound: switch (mode) { default: handler.SendSysMessage(CypherStrings.BanNotfound, "account", nameOrIP); break; case BanMode.Character: handler.SendSysMessage(CypherStrings.BanNotfound, "character", nameOrIP); break; case BanMode.IP: handler.SendSysMessage(CypherStrings.BanNotfound, "ip", nameOrIP); break; } return(false); } return(true); }
static bool HandleListCreatureCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r string id = handler.ExtractKeyFromLink(args, "Hcreature_entry"); if (string.IsNullOrEmpty(id)) { return(false); } if (!uint.TryParse(id, out uint creatureId) || creatureId == 0) { handler.SendSysMessage(CypherStrings.CommandInvalidcreatureid, creatureId); return(false); } CreatureTemplate cInfo = Global.ObjectMgr.GetCreatureTemplate(creatureId); if (cInfo == null) { handler.SendSysMessage(CypherStrings.CommandInvalidcreatureid, creatureId); return(false); } if (!uint.TryParse(args.NextString(), out uint count)) { count = 10; } if (count == 0) { return(false); } uint creatureCount = 0; SQLResult result = DB.World.Query("SELECT COUNT(guid) FROM creature WHERE id='{0}'", creatureId); if (!result.IsEmpty()) { creatureCount = result.Read <uint>(0); } if (handler.GetSession() != null) { Player player = handler.GetSession().GetPlayer(); result = DB.World.Query("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '{0}', 2) + POW(position_y - '{1}', 2) + POW(position_z - '{2}', 2)) AS order_ FROM creature WHERE id = '{3}' ORDER BY order_ ASC LIMIT {4}", player.GetPositionX(), player.GetPositionY(), player.GetPositionZ(), creatureId, count); } else { result = DB.World.Query("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '{0}' LIMIT {1}", creatureId, count); } if (!result.IsEmpty()) { do { ulong guid = result.Read <ulong>(0); float x = result.Read <float>(1); float y = result.Read <float>(2); float z = result.Read <float>(3); ushort mapId = result.Read <ushort>(4); bool liveFound = false; // Get map (only support base map from console) Map thisMap; if (handler.GetSession() != null) { thisMap = handler.GetSession().GetPlayer().GetMap(); } else { thisMap = Global.MapMgr.FindBaseNonInstanceMap(mapId); } // If map found, try to find active version of this creature if (thisMap) { var creBounds = thisMap.GetCreatureBySpawnIdStore().LookupByKey(guid); if (!creBounds.Empty()) { foreach (var creature in creBounds) { if (handler.GetSession()) { handler.SendSysMessage(CypherStrings.CreatureListChat, guid, guid, cInfo.Name, x, y, z, mapId, creature.GetGUID().ToString(), creature.IsAlive() ? "*" : " "); } else { handler.SendSysMessage(CypherStrings.CreatureListConsole, guid, cInfo.Name, x, y, z, mapId, creature.GetGUID().ToString(), creature.IsAlive() ? "*" : " "); } } liveFound = true; } } if (!liveFound) { if (handler.GetSession()) { handler.SendSysMessage(CypherStrings.CreatureListChat, guid, guid, cInfo.Name, x, y, z, mapId, "", ""); } else { handler.SendSysMessage(CypherStrings.CreatureListConsole, guid, cInfo.Name, x, y, z, mapId, "", ""); } } }while (result.NextRow()); } handler.SendSysMessage(CypherStrings.CommandListcreaturemessage, creatureId, creatureCount); return(true); }
static bool HandleBanCharacterCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } string name = args.NextString(); if (string.IsNullOrEmpty(name)) { return(false); } string durationStr = args.NextString(); if (string.IsNullOrEmpty(durationStr)) { return(false); } if (!uint.TryParse(durationStr, out uint duration)) { return(false); } string reasonStr = args.NextString(""); if (string.IsNullOrEmpty(reasonStr)) { return(false); } if (!ObjectManager.NormalizePlayerName(ref name)) { handler.SendSysMessage(CypherStrings.PlayerNotFound); return(false); } string author = handler.GetSession() != null?handler.GetSession().GetPlayerName() : "Server"; switch (Global.WorldMgr.BanCharacter(name, durationStr, reasonStr, author)) { case BanReturn.Success: { if (duration > 0) { if (WorldConfig.GetBoolValue(WorldCfg.ShowBanInWorld)) { Global.WorldMgr.SendWorldText(CypherStrings.BanCharacterYoubannedmessageWorld, author, name, Time.secsToTimeString(Time.TimeStringToSecs(durationStr), true), reasonStr); } else { handler.SendSysMessage(CypherStrings.BanYoubanned, name, Time.secsToTimeString(Time.TimeStringToSecs(durationStr), true), reasonStr); } } else { if (WorldConfig.GetBoolValue(WorldCfg.ShowBanInWorld)) { Global.WorldMgr.SendWorldText(CypherStrings.BanCharacterYoupermbannedmessageWorld, author, name, reasonStr); } else { handler.SendSysMessage(CypherStrings.BanYoupermbanned, name, reasonStr); } } break; } case BanReturn.Notfound: { handler.SendSysMessage(CypherStrings.BanNotfound, "character", name); return(false); } default: break; } return(true); }
static bool HandleRemoveDisables(StringArguments args, CommandHandler handler, DisableType disableType) { string entryStr = args.NextString(); if (string.IsNullOrEmpty(entryStr) || uint.Parse(entryStr) == 0) { return(false); } uint entry = uint.Parse(entryStr); string disableTypeStr = ""; switch (disableType) { case DisableType.Spell: disableTypeStr = "spell"; break; case DisableType.Quest: disableTypeStr = "quest"; break; case DisableType.Map: disableTypeStr = "map"; break; case DisableType.Battleground: disableTypeStr = "Battleground"; break; case DisableType.Criteria: disableTypeStr = "criteria"; break; case DisableType.OutdoorPVP: disableTypeStr = "outdoorpvp"; break; case DisableType.VMAP: disableTypeStr = "vmap"; break; case DisableType.MMAP: disableTypeStr = "mmap"; break; } PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_DISABLES); stmt.AddValue(0, entry); stmt.AddValue(1, disableType); SQLResult result = DB.World.Query(stmt); if (result.IsEmpty()) { handler.SendSysMessage("This {0} (Id: {1}) is not disabled.", disableTypeStr, entry); return(false); } stmt = DB.World.GetPreparedStatement(WorldStatements.DEL_DISABLES); stmt.AddValue(0, entry); stmt.AddValue(1, disableType); DB.World.Execute(stmt); handler.SendSysMessage("Remove Disabled {0} (Id: {1})", disableTypeStr, entry); return(true); }
static bool HandleSetGmLevelCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { handler.SendSysMessage(CypherStrings.CmdSyntax); return(false); } string targetAccountName = ""; uint targetAccountId = 0; AccountTypes targetSecurity = 0; uint gm = 0; string arg1 = args.NextString(); string arg2 = args.NextString(); string arg3 = args.NextString(); bool isAccountNameGiven = true; if (string.IsNullOrEmpty(arg3)) { if (!handler.getSelectedPlayer()) { return(false); } isAccountNameGiven = false; } if (!isAccountNameGiven && string.IsNullOrEmpty(arg2)) { return(false); } if (isAccountNameGiven) { targetAccountName = arg1; if (Global.AccountMgr.GetId(targetAccountName) == 0) { handler.SendSysMessage(CypherStrings.AccountNotExist, targetAccountName); return(false); } } // Check for invalid specified GM level. if (!uint.TryParse(isAccountNameGiven ? arg2 : arg1, out gm)) { return(false); } if (gm > (uint)AccountTypes.Console) { handler.SendSysMessage(CypherStrings.BadValue); return(false); } // command.getSession() == NULL only for console targetAccountId = (isAccountNameGiven) ? Global.AccountMgr.GetId(targetAccountName) : handler.getSelectedPlayer().GetSession().GetAccountId(); if (!int.TryParse(isAccountNameGiven ? arg3 : arg2, out int gmRealmID)) { return(false); } AccountTypes playerSecurity; if (handler.GetSession() != null) { playerSecurity = Global.AccountMgr.GetSecurity(handler.GetSession().GetAccountId(), gmRealmID); } else { playerSecurity = AccountTypes.Console; } // can set security level only for target with less security and to less security that we have // This is also reject self apply in fact targetSecurity = Global.AccountMgr.GetSecurity(targetAccountId, gmRealmID); if (targetSecurity >= playerSecurity || (AccountTypes)gm >= playerSecurity) { handler.SendSysMessage(CypherStrings.YoursSecurityIsLow); return(false); } PreparedStatement stmt; // Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1 if (gmRealmID == -1 && !Global.AccountMgr.IsConsoleAccount(playerSecurity)) { stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_ACCESS_GMLEVEL_TEST); stmt.AddValue(0, targetAccountId); stmt.AddValue(1, gm); SQLResult result = DB.Login.Query(stmt); if (!result.IsEmpty()) { handler.SendSysMessage(CypherStrings.YoursSecurityIsLow); return(false); } } // Check if provided realmID has a negative value other than -1 if (gmRealmID < -1) { handler.SendSysMessage(CypherStrings.InvalidRealmid); return(false); } RBACData rbac = isAccountNameGiven ? null : handler.getSelectedPlayer().GetSession().GetRBACData(); Global.AccountMgr.UpdateAccountAccess(rbac, targetAccountId, (byte)gm, gmRealmID); handler.SendSysMessage(CypherStrings.YouChangeSecurity, targetAccountName, gm); return(true); }