static bool HandlePetCreateCommand(StringArguments args, CommandHandler handler) { Player player = handler.GetSession().GetPlayer(); Creature creatureTarget = handler.getSelectedCreature(); if (!creatureTarget || creatureTarget.IsPet() || creatureTarget.IsTypeId(TypeId.Player)) { handler.SendSysMessage(CypherStrings.SelectCreature); return(false); } CreatureTemplate creatureTemplate = creatureTarget.GetCreatureTemplate(); // Creatures with family CreatureFamily.None crashes the server if (creatureTemplate.Family == CreatureFamily.None) { handler.SendSysMessage("This creature cannot be tamed. (Family id: 0)."); return(false); } if (!player.GetPetGUID().IsEmpty()) { handler.SendSysMessage("You already have a pet"); return(false); } // Everything looks OK, create new pet Pet pet = new Pet(player, PetType.Hunter); if (!pet.CreateBaseAtCreature(creatureTarget)) { handler.SendSysMessage("Error 1"); return(false); } creatureTarget.setDeathState(DeathState.JustDied); creatureTarget.RemoveCorpse(); creatureTarget.SetHealth(0); // just for nice GM-mode view pet.SetGuidValue(UnitFields.CreatedBy, player.GetGUID()); pet.SetUInt32Value(UnitFields.FactionTemplate, player.getFaction()); if (!pet.InitStatsForLevel(creatureTarget.getLevel())) { Log.outError(LogFilter.ChatSystem, "InitStatsForLevel() in EffectTameCreature failed! Pet deleted."); handler.SendSysMessage("Error 2"); return(false); } // prepare visual effect for levelup pet.SetUInt32Value(UnitFields.Level, creatureTarget.getLevel() - 1); pet.GetCharmInfo().SetPetNumber(Global.ObjectMgr.GeneratePetNumber(), true); // this enables pet details window (Shift+P) pet.InitPetCreateSpells(); pet.SetFullHealth(); pet.GetMap().AddToMap(pet.ToCreature()); // visual effect for levelup pet.SetUInt32Value(UnitFields.Level, creatureTarget.getLevel()); player.SetMinion(pet, true); pet.SavePetToDB(PetSaveMode.AsCurrent); player.PetSpellInitialize(); return(true); }
static bool HandleAccountSetSecLevelCommand(CommandHandler handler, string accountName, byte securityLevel, int?realmId) { uint accountId; if (!accountName.IsEmpty()) { accountId = Global.AccountMgr.GetId(accountName); if (accountId == 0) { handler.SendSysMessage(CypherStrings.AccountNotExist, accountName); return(false); } } else { Player player = handler.GetSelectedPlayer(); if (!player) { return(false); } accountId = player.GetSession().GetAccountId(); Global.AccountMgr.GetName(accountId, out accountName); } if (securityLevel > (uint)AccountTypes.Console) { handler.SendSysMessage(CypherStrings.BadValue); return(false); } int realmID = -1; if (realmId.HasValue) { realmID = realmId.Value; } AccountTypes playerSecurity; if (handler.GetSession() != null) { playerSecurity = Global.AccountMgr.GetSecurity(handler.GetSession().GetAccountId(), realmID); } 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 AccountTypes targetSecurity = Global.AccountMgr.GetSecurity(accountId, realmID); if (targetSecurity >= playerSecurity || (AccountTypes)securityLevel >= 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 (realmID == -1 && !Global.AccountMgr.IsConsoleAccount(playerSecurity)) { stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_ACCESS_SECLEVEL_TEST); stmt.AddValue(0, accountId); stmt.AddValue(1, securityLevel); 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 (realmID < -1) { handler.SendSysMessage(CypherStrings.InvalidRealmid); return(false); } Global.AccountMgr.UpdateAccountAccess(null, accountId, (byte)securityLevel, realmID); handler.SendSysMessage(CypherStrings.YouChangeSecurity, accountName, securityLevel); return(true); }
static bool HandleGameObjectTargetCommand(StringArguments args, CommandHandler handler) { Player player = handler.GetSession().GetPlayer(); SQLResult result; var activeEventsList = Global.GameEventMgr.GetActiveEventList(); if (!args.Empty()) { // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r string idStr = handler.extractKeyFromLink(args, "Hgameobject_entry"); if (string.IsNullOrEmpty(idStr)) { return(false); } if (!uint.TryParse(idStr, out uint objectId) || objectId != 0) { result = DB.World.Query("SELECT guid, id, position_x, position_y, position_z, orientation, map, PhaseId, PhaseGroup, (POW(position_x - '{0}', 2) + POW(position_y - '{1}', 2) + POW(position_z - '{2}', 2)) AS order_ FROM gameobject WHERE map = '{3}' AND id = '{4}' ORDER BY order_ ASC LIMIT 1", player.GetPositionX(), player.GetPositionY(), player.GetPositionZ(), player.GetMapId(), objectId); } else { result = DB.World.Query( "SELECT guid, id, position_x, position_y, position_z, orientation, map, PhaseId, PhaseGroup, (POW(position_x - {0}, 2) + POW(position_y - {1}, 2) + POW(position_z - {2}, 2)) AS order_ " + "FROM gameobject LEFT JOIN gameobject_template ON gameobject_template.entry = gameobject.id WHERE map = {3} AND name LIKE CONCAT('%%', '{4}', '%%') ORDER BY order_ ASC LIMIT 1", player.GetPositionX(), player.GetPositionY(), player.GetPositionZ(), player.GetMapId(), objectId); } } else { StringBuilder eventFilter = new StringBuilder(); eventFilter.Append(" AND (eventEntry IS NULL "); bool initString = true; foreach (var entry in activeEventsList) { if (initString) { eventFilter.Append("OR eventEntry IN (" + entry); initString = false; } else { eventFilter.Append(',' + entry); } } if (!initString) { eventFilter.Append("))"); } else { eventFilter.Append(')'); } result = DB.World.Query("SELECT gameobject.guid, id, position_x, position_y, position_z, orientation, map, PhaseId, PhaseGroup, " + "(POW(position_x - {0}, 2) + POW(position_y - {1}, 2) + POW(position_z - {2}, 2)) AS order_ FROM gameobject " + "LEFT OUTER JOIN game_event_gameobject on gameobject.guid = game_event_gameobject.guid WHERE map = '{3}' {4} ORDER BY order_ ASC LIMIT 10", handler.GetSession().GetPlayer().GetPositionX(), handler.GetSession().GetPlayer().GetPositionY(), handler.GetSession().GetPlayer().GetPositionZ(), handler.GetSession().GetPlayer().GetMapId(), eventFilter.ToString()); } if (result.IsEmpty()) { handler.SendSysMessage(CypherStrings.CommandTargetobjnotfound); return(true); } bool found = false; float x, y, z, o; ulong guidLow; uint id, phaseId, phaseGroup; ushort mapId; uint poolId; do { guidLow = result.Read <ulong>(0); id = result.Read <uint>(1); x = result.Read <float>(2); y = result.Read <float>(3); z = result.Read <float>(4); o = result.Read <float>(5); mapId = result.Read <ushort>(6); phaseId = result.Read <uint>(7); phaseGroup = result.Read <uint>(8); poolId = Global.PoolMgr.IsPartOfAPool <GameObject>(guidLow); if (poolId == 0 || Global.PoolMgr.IsSpawnedObject <GameObject>(guidLow)) { found = true; } } while (result.NextRow() && !found); if (!found) { handler.SendSysMessage(CypherStrings.GameobjectNotExist, id); return(false); } GameObjectTemplate objectInfo = Global.ObjectMgr.GetGameObjectTemplate(id); if (objectInfo == null) { handler.SendSysMessage(CypherStrings.GameobjectNotExist, id); return(false); } GameObject target = handler.GetObjectFromPlayerMapByDbGuid(guidLow); handler.SendSysMessage(CypherStrings.GameobjectDetail, guidLow, objectInfo.name, guidLow, id, x, y, z, mapId, o, phaseId, phaseGroup); if (target) { int curRespawnDelay = (int)(target.GetRespawnTimeEx() - Time.UnixTime); if (curRespawnDelay < 0) { curRespawnDelay = 0; } string curRespawnDelayStr = Time.secsToTimeString((uint)curRespawnDelay, true); string defRespawnDelayStr = Time.secsToTimeString(target.GetRespawnDelay(), true); handler.SendSysMessage(CypherStrings.CommandRawpawntimes, defRespawnDelayStr, curRespawnDelayStr); } return(true); }
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 HandleCharacterReputationCommand(StringArguments args, CommandHandler handler) { Player target; if (!handler.ExtractPlayerTarget(args, out target)) { return(false); } Locale loc = handler.GetSessionDbcLocale(); var targetFSL = target.GetReputationMgr().GetStateList(); foreach (var pair in targetFSL) { FactionState faction = pair.Value; FactionRecord factionEntry = CliDB.FactionStorage.LookupByKey(faction.Id); string factionName = factionEntry != null ? factionEntry.Name[loc] : "#Not found#"; ReputationRank rank = target.GetReputationMgr().GetRank(factionEntry); string rankName = handler.GetCypherString(ReputationMgr.ReputationRankStrIndex[(int)rank]); StringBuilder ss = new StringBuilder(); if (handler.GetSession() != null) { ss.AppendFormat("{0} - |cffffffff|Hfaction:{0}|h[{1} {2}]|h|r", faction.Id, factionName, loc); } else { ss.AppendFormat("{0} - {1} {2}", faction.Id, factionName, loc); } ss.AppendFormat(" {0} ({1})", rankName, target.GetReputationMgr().GetReputation(factionEntry)); if (faction.Flags.HasAnyFlag(FactionFlags.Visible)) { ss.Append(handler.GetCypherString(CypherStrings.FactionVisible)); } if (faction.Flags.HasAnyFlag(FactionFlags.AtWar)) { ss.Append(handler.GetCypherString(CypherStrings.FactionAtwar)); } if (faction.Flags.HasAnyFlag(FactionFlags.PeaceForced)) { ss.Append(handler.GetCypherString(CypherStrings.FactionPeaceForced)); } if (faction.Flags.HasAnyFlag(FactionFlags.Hidden)) { ss.Append(handler.GetCypherString(CypherStrings.FactionHidden)); } if (faction.Flags.HasAnyFlag(FactionFlags.InvisibleForced)) { ss.Append(handler.GetCypherString(CypherStrings.FactionInvisibleForced)); } if (faction.Flags.HasAnyFlag(FactionFlags.Inactive)) { ss.Append(handler.GetCypherString(CypherStrings.FactionInactive)); } handler.SendSysMessage(ss.ToString()); } return(true); }
static bool HandleAccountEmailCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { handler.SendSysMessage(CypherStrings.CmdSyntax); return(false); } string oldEmail = args.NextString(); string password = args.NextString(); string email = args.NextString(); string emailConfirmation = args.NextString(); if (string.IsNullOrEmpty(oldEmail) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(emailConfirmation)) { handler.SendSysMessage(CypherStrings.CmdSyntax); return(false); } if (!Global.AccountMgr.CheckEmail(handler.GetSession().GetAccountId(), oldEmail)) { handler.SendSysMessage(CypherStrings.CommandWrongemail); Log.outInfo(LogFilter.Player, "Account: {0} (IP: {1}) Character:[{2}] (GUID: {3}) Tried to change email, but the provided email [{4}] is not equal to registration email [{5}].", handler.GetSession().GetAccountId(), handler.GetSession().GetRemoteAddress(), handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString(), email, oldEmail); return(false); } if (!Global.AccountMgr.CheckPassword(handler.GetSession().GetAccountId(), password)) { handler.SendSysMessage(CypherStrings.CommandWrongoldpassword); Log.outInfo(LogFilter.Player, "Account: {0} (IP: {1}) Character:[{2}] (GUID: {3}) Tried to change email, but the provided password is wrong.", handler.GetSession().GetAccountId(), handler.GetSession().GetRemoteAddress(), handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString()); return(false); } if (email == oldEmail) { handler.SendSysMessage(CypherStrings.OldEmailIsNewEmail); return(false); } if (email != emailConfirmation) { handler.SendSysMessage(CypherStrings.NewEmailsNotMatch); Log.outInfo(LogFilter.Player, "Account: {0} (IP: {1}) Character:[{2}] (GUID: {3}) Tried to change email, but the provided password is wrong.", handler.GetSession().GetAccountId(), handler.GetSession().GetRemoteAddress(), handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString()); return(false); } AccountOpResult result = Global.AccountMgr.ChangeEmail(handler.GetSession().GetAccountId(), email); switch (result) { case AccountOpResult.Ok: handler.SendSysMessage(CypherStrings.CommandEmail); Log.outInfo(LogFilter.Player, "Account: {0} (IP: {1}) Character:[{2}] (GUID: {3}) Changed Email from [{4}] to [{5}].", handler.GetSession().GetAccountId(), handler.GetSession().GetRemoteAddress(), handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString(), oldEmail, email); break; case AccountOpResult.EmailTooLong: handler.SendSysMessage(CypherStrings.EmailTooLong); return(false); default: handler.SendSysMessage(CypherStrings.CommandNotchangeemail); return(false); } return(true); }
static bool HandleSetAddonCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } // Get the command line arguments string account = args.NextString(); string exp = args.NextString(); if (string.IsNullOrEmpty(account)) { return(false); } string accountName; uint accountId; if (string.IsNullOrEmpty(exp)) { Player player = handler.getSelectedPlayer(); if (!player) { return(false); } accountId = player.GetSession().GetAccountId(); Global.AccountMgr.GetName(accountId, out accountName); exp = account; } else { // Convert Account name to Upper Format accountName = account.ToUpper(); accountId = Global.AccountMgr.GetId(accountName); if (accountId == 0) { handler.SendSysMessage(CypherStrings.AccountNotExist, accountName); return(false); } } // Let set addon state only for lesser (strong) security level // or to self account if (handler.GetSession() != null && handler.GetSession().GetAccountId() != accountId && handler.HasLowerSecurityAccount(null, accountId, true)) { return(false); } if (!byte.TryParse(exp, out byte expansion)) { return(false); } if (expansion > WorldConfig.GetIntValue(WorldCfg.Expansion)) { return(false); } PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_EXPANSION); stmt.AddValue(0, expansion); stmt.AddValue(1, accountId); DB.Login.Execute(stmt); handler.SendSysMessage(CypherStrings.AccountSetaddon, accountName, accountId, expansion); return(true); }
static bool HandleGroupSummonCommand(StringArguments args, CommandHandler handler) { Player target; if (!handler.ExtractPlayerTarget(args, out target)) { return(false); } // check online security if (handler.HasLowerSecurity(target, ObjectGuid.Empty)) { return(false); } Group group = target.GetGroup(); string nameLink = handler.GetNameLink(target); if (!group) { handler.SendSysMessage(CypherStrings.NotInGroup, nameLink); return(false); } Player gmPlayer = handler.GetSession().GetPlayer(); Map gmMap = gmPlayer.GetMap(); bool toInstance = gmMap.Instanceable(); bool onlyLocalSummon = false; // make sure people end up on our instance of the map, disallow far summon if intended destination is different from actual destination // note: we could probably relax this further by checking permanent saves and the like, but eh // :close enough: if (toInstance) { Player groupLeader = Global.ObjAccessor.GetPlayer(gmMap, group.GetLeaderGUID()); if (!groupLeader || (groupLeader.GetMapId() != gmMap.GetId()) || (groupLeader.GetInstanceId() != gmMap.GetInstanceId())) { handler.SendSysMessage(CypherStrings.PartialGroupSummon); onlyLocalSummon = true; } } for (GroupReference refe = group.GetFirstMember(); refe != null; refe = refe.Next()) { Player player = refe.GetSource(); if (!player || player == gmPlayer || player.GetSession() == null) { continue; } // check online security if (handler.HasLowerSecurity(player, ObjectGuid.Empty)) { continue; } string plNameLink = handler.GetNameLink(player); if (player.IsBeingTeleported()) { handler.SendSysMessage(CypherStrings.IsTeleported, plNameLink); continue; } if (toInstance) { Map playerMap = player.GetMap(); if ((onlyLocalSummon || (playerMap.Instanceable() && playerMap.GetId() == gmMap.GetId())) && // either no far summon allowed or we're in the same map as player (no map switch) ((playerMap.GetId() != gmMap.GetId()) || (playerMap.GetInstanceId() != gmMap.GetInstanceId()))) // so we need to be in the same map and instance of the map, otherwise skip { // cannot summon from instance to instance handler.SendSysMessage(CypherStrings.CannotSummonInstInst, plNameLink); continue; } } handler.SendSysMessage(CypherStrings.Summoning, plNameLink, ""); if (handler.NeedReportToTarget(player)) { player.SendSysMessage(CypherStrings.SummonedBy, handler.GetNameLink()); } // stop flight if need if (player.IsInFlight()) { player.GetMotionMaster().MovementExpired(); player.CleanupAfterTaxiFlight(); } // save only in non-flight case else { player.SaveRecallPosition(); } // before GM float x, y, z; gmPlayer.GetClosePoint(out x, out y, out z, player.GetCombatReach()); player.TeleportTo(gmPlayer.GetMapId(), x, y, z, player.GetOrientation()); } return(true); }
static bool HandleGroupSummonCommand(StringArguments args, CommandHandler handler) { Player target; if (!handler.extractPlayerTarget(args, out target)) { return(false); } // check online security if (handler.HasLowerSecurity(target, ObjectGuid.Empty)) { return(false); } Group group = target.GetGroup(); string nameLink = handler.GetNameLink(target); if (!group) { handler.SendSysMessage(CypherStrings.NotInGroup, nameLink); return(false); } Player gmPlayer = handler.GetSession().GetPlayer(); Group gmGroup = gmPlayer.GetGroup(); Map gmMap = gmPlayer.GetMap(); bool toInstance = gmMap.Instanceable(); // we are in instance, and can summon only player in our group with us as lead if (toInstance && ( !gmGroup || group.GetLeaderGUID() != gmPlayer.GetGUID() || gmGroup.GetLeaderGUID() != gmPlayer.GetGUID())) // the last check is a bit excessive, but let it be, just in case { handler.SendSysMessage(CypherStrings.CannotSummonToInst); return(false); } for (GroupReference refe = group.GetFirstMember(); refe != null; refe = refe.next()) { Player player = refe.GetSource(); if (!player || player == gmPlayer || player.GetSession() == null) { continue; } // check online security if (handler.HasLowerSecurity(player, ObjectGuid.Empty)) { return(false); } string plNameLink = handler.GetNameLink(player); if (player.IsBeingTeleported()) { handler.SendSysMessage(CypherStrings.IsTeleported, plNameLink); return(false); } if (toInstance) { Map playerMap = player.GetMap(); if (playerMap.Instanceable() && playerMap.GetInstanceId() != gmMap.GetInstanceId()) { // cannot summon from instance to instance handler.SendSysMessage(CypherStrings.CannotSummonToInst, plNameLink); return(false); } } handler.SendSysMessage(CypherStrings.Summoning, plNameLink, ""); if (handler.needReportToTarget(player)) { player.SendSysMessage(CypherStrings.SummonedBy, handler.GetNameLink()); } // stop flight if need if (player.IsInFlight()) { player.GetMotionMaster().MovementExpired(); player.CleanupAfterTaxiFlight(); } // save only in non-flight case else { player.SaveRecallPosition(); } // before GM float x, y, z; gmPlayer.GetClosePoint(out x, out y, out z, player.GetObjectSize()); player.TeleportTo(gmPlayer.GetMapId(), x, y, z, player.GetOrientation()); } return(true); }
static bool HandleGameObjectInfoCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } string param1 = handler.ExtractKeyFromLink(args, "Hgameobject_entry"); if (param1.IsEmpty()) { return(false); } uint entry; if (param1.Equals("guid")) { string cValue = handler.ExtractKeyFromLink(args, "Hgameobject"); if (cValue.IsEmpty()) { return(false); } if (!ulong.TryParse(cValue, out ulong guidLow)) { return(false); } GameObjectData data = Global.ObjectMgr.GetGameObjectData(guidLow); if (data == null) { return(false); } entry = data.Id; } else { if (!uint.TryParse(param1, out entry)) { return(false); } } GameObjectTemplate gameObjectInfo = Global.ObjectMgr.GetGameObjectTemplate(entry); if (gameObjectInfo == null) { return(false); } GameObject thisGO = null; if (handler.GetSession().GetPlayer()) { thisGO = handler.GetSession().GetPlayer().FindNearestGameObject(entry, 30); } else if (handler.GetSelectedObject() != null && handler.GetSelectedObject().IsTypeId(TypeId.GameObject)) { thisGO = handler.GetSelectedObject().ToGameObject(); } GameObjectTypes type = gameObjectInfo.type; uint displayId = gameObjectInfo.displayId; string name = gameObjectInfo.name; uint lootId = gameObjectInfo.GetLootId(); // If we have a real object, send some info about it if (thisGO != null) { handler.SendSysMessage(CypherStrings.SpawninfoGuidinfo, thisGO.GetGUID().ToString()); handler.SendSysMessage(CypherStrings.SpawninfoSpawnidLocation, thisGO.GetSpawnId(), thisGO.GetPositionX(), thisGO.GetPositionY(), thisGO.GetPositionZ()); Player player = handler.GetSession().GetPlayer(); if (player != null) { Position playerPos = player.GetPosition(); float dist = thisGO.GetExactDist(playerPos); handler.SendSysMessage(CypherStrings.SpawninfoDistancefromplayer, dist); } } handler.SendSysMessage(CypherStrings.GoinfoEntry, entry); handler.SendSysMessage(CypherStrings.GoinfoType, type); handler.SendSysMessage(CypherStrings.GoinfoLootid, lootId); handler.SendSysMessage(CypherStrings.GoinfoDisplayid, displayId); WorldObject obj = handler.GetSelectedObject(); if (obj != null) { if (obj.IsGameObject() && obj.ToGameObject().GetGameObjectData() != null && obj.ToGameObject().GetGameObjectData().spawnGroupData.groupId != 0) { SpawnGroupTemplateData groupData = obj.ToGameObject().GetGameObjectData().spawnGroupData; handler.SendSysMessage(CypherStrings.SpawninfoGroupId, groupData.name, groupData.groupId, groupData.flags, obj.GetMap().IsSpawnGroupActive(groupData.groupId)); } if (obj.IsGameObject()) { handler.SendSysMessage(CypherStrings.SpawninfoCompatibilityMode, obj.ToGameObject().GetRespawnCompatibilityMode()); } } handler.SendSysMessage(CypherStrings.GoinfoName, name); handler.SendSysMessage(CypherStrings.GoinfoSize, gameObjectInfo.size); GameObjectTemplateAddon addon = Global.ObjectMgr.GetGameObjectTemplateAddon(entry); if (addon != null) { handler.SendSysMessage(CypherStrings.GoinfoAddon, addon.faction, addon.flags); } GameObjectDisplayInfoRecord modelInfo = CliDB.GameObjectDisplayInfoStorage.LookupByKey(displayId); if (modelInfo != null) { handler.SendSysMessage(CypherStrings.GoinfoModel, modelInfo.GeoBoxMax.X, modelInfo.GeoBoxMax.Y, modelInfo.GeoBoxMax.Z, modelInfo.GeoBoxMin.X, modelInfo.GeoBoxMin.Y, modelInfo.GeoBoxMin.Z); } 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 PathCommand(StringArguments args, CommandHandler handler) { if (Global.MMapMgr.GetNavMesh(handler.GetPlayer().GetMapId(), handler.GetSession().GetPlayer().GetTerrainSwaps()) == 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 HandleMmapStatsCommand(StringArguments args, CommandHandler handler) { uint mapId = handler.GetPlayer().GetMapId(); handler.SendSysMessage("mmap stats:"); handler.SendSysMessage(" global mmap pathfinding is {0}abled", Global.DisableMgr.IsPathfindingEnabled(mapId) ? "En" : "Dis"); handler.SendSysMessage(" {0} maps loaded with {1} tiles overall", Global.MMapMgr.getLoadedMapsCount(), Global.MMapMgr.getLoadedTilesCount()); Detour.dtNavMesh navmesh = Global.MMapMgr.GetNavMesh(handler.GetPlayer().GetMapId(), handler.GetSession().GetPlayer().GetTerrainSwaps()); if (navmesh == null) { handler.SendSysMessage("NavMesh not loaded for current map."); return(true); } uint tileCount = 0; int nodeCount = 0; int polyCount = 0; int vertCount = 0; int triCount = 0; int triVertCount = 0; for (int i = 0; i < navmesh.getMaxTiles(); ++i) { Detour.dtMeshTile tile = navmesh.getTile(i); if (tile == null) { continue; } tileCount++; nodeCount += tile.header.bvNodeCount; polyCount += tile.header.polyCount; vertCount += tile.header.vertCount; triCount += tile.header.detailTriCount; triVertCount += tile.header.detailVertCount; } handler.SendSysMessage("Navmesh stats:"); handler.SendSysMessage(" {0} tiles loaded", tileCount); handler.SendSysMessage(" {0} BVTree nodes", nodeCount); handler.SendSysMessage(" {0} polygons ({1} vertices)", polyCount, vertCount); handler.SendSysMessage(" {0} triangles ({1} vertices)", triCount, triVertCount); return(true); }
static bool LocCommand(StringArguments args, CommandHandler handler) { handler.SendSysMessage("mmap tileloc:"); // grid tile location Player player = handler.GetPlayer(); int gx = (int)(32 - player.GetPositionX() / MapConst.SizeofGrids); int gy = (int)(32 - player.GetPositionY() / MapConst.SizeofGrids); handler.SendSysMessage("{0:D4}{1:D2}{2:D2}.mmtile", player.GetMapId(), gy, gx); handler.SendSysMessage("gridloc [{0}, {1}]", gx, gy); // calculate navmesh tile location Detour.dtNavMesh navmesh = Global.MMapMgr.GetNavMesh(handler.GetPlayer().GetMapId(), handler.GetSession().GetPlayer().GetTerrainSwaps()); Detour.dtNavMeshQuery navmeshquery = Global.MMapMgr.GetNavMeshQuery(handler.GetPlayer().GetMapId(), player.GetInstanceId(), handler.GetSession().GetPlayer().GetTerrainSwaps()); if (navmesh == null || navmeshquery == null) { handler.SendSysMessage("NavMesh not loaded for current map."); return(true); } float[] min = navmesh.getParams().orig; float x, y, z; player.GetPosition(out x, out y, out z); float[] location = { y, z, x }; float[] extents = { 3.0f, 5.0f, 3.0f }; int tilex = (int)((y - min[0]) / MapConst.SizeofGrids); int tiley = (int)((x - min[2]) / MapConst.SizeofGrids); handler.SendSysMessage("Calc [{0:D2}, {1:D2}]", tilex, tiley); // navmesh poly . navmesh tile location Detour.dtQueryFilter filter = new Detour.dtQueryFilter(); float[] nothing = new float[3]; ulong polyRef = 0; if (Detour.dtStatusFailed(navmeshquery.findNearestPoly(location, extents, filter, ref polyRef, ref nothing))) { handler.SendSysMessage("Dt [??,??] (invalid poly, probably no tile loaded)"); return(true); } if (polyRef == 0) { handler.SendSysMessage("Dt [??, ??] (invalid poly, probably no tile loaded)"); } else { Detour.dtMeshTile tile = new Detour.dtMeshTile(); Detour.dtPoly poly = new Detour.dtPoly(); if (Detour.dtStatusSucceed(navmesh.getTileAndPolyByRef(polyRef, ref tile, ref poly))) { if (tile != null) { handler.SendSysMessage("Dt [{0:D2},{1:D2}]", tile.header.x, tile.header.y); return(false); } } handler.SendSysMessage("Dt [??,??] (no tile loaded)"); } return(true); }
static bool HandleArenaRenameCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } string oldArenaStr = handler.extractQuotedArg(args.NextString()); if (string.IsNullOrEmpty(oldArenaStr)) { handler.SendSysMessage(CypherStrings.BadValue); return(false); } string newArenaStr = handler.extractQuotedArg(args.NextString()); if (string.IsNullOrEmpty(newArenaStr)) { handler.SendSysMessage(CypherStrings.BadValue); return(false); } ArenaTeam arena = Global.ArenaTeamMgr.GetArenaTeamByName(oldArenaStr); if (arena == null) { handler.SendSysMessage(CypherStrings.AreanErrorNameNotFound, oldArenaStr); return(false); } if (Global.ArenaTeamMgr.GetArenaTeamByName(newArenaStr) != null) { handler.SendSysMessage(CypherStrings.ArenaErrorNameExists, oldArenaStr); return(false); } if (arena.IsFighting()) { handler.SendSysMessage(CypherStrings.ArenaErrorCombat); return(false); } if (!arena.SetName(newArenaStr)) { handler.SendSysMessage(CypherStrings.BadValue); return(false); } handler.SendSysMessage(CypherStrings.ArenaRename, arena.GetId(), oldArenaStr, newArenaStr); if (handler.GetSession() != null) { Log.outDebug(LogFilter.Arena, "GameMaster: {0} [GUID: {1}] rename arena team \"{2}\"[Id: {3}] to \"{4}\"", handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString(), oldArenaStr, arena.GetId(), newArenaStr); } else { Log.outDebug(LogFilter.Arena, "Console: rename arena team \"{0}\"[Id: {1}] to \"{2}\"", oldArenaStr, arena.GetId(), newArenaStr); } return(true); }
static bool ShutdownServer(StringArguments args, CommandHandler handler, ShutdownMask shutdownMask, ShutdownExitCode defaultExitCode) { if (args.Empty()) { return(false); } string delayStr = args.NextString(); if (delayStr.IsEmpty()) { return(false); } int delay; if (int.TryParse(delayStr, out delay)) { // Prevent interpret wrong arg value as 0 secs shutdown time if ((delay == 0 && (delayStr[0] != '0' || delayStr.Length > 1 && delayStr[1] != '\0')) || delay < 0) { return(false); } } else { delay = (int)Time.TimeStringToSecs(delayStr); if (delay == 0) { return(false); } } string reason = ""; string exitCodeStr = ""; string nextToken; while (!(nextToken = args.NextString()).IsEmpty()) { if (nextToken.IsNumber()) { exitCodeStr = nextToken; } else { reason = nextToken; reason += args.NextString("\0"); break; } } int exitCode = (int)defaultExitCode; if (!exitCodeStr.IsEmpty()) { if (!ParseExitCode(exitCodeStr, out exitCode)) { return(false); } } // Override parameter "delay" with the configuration value if there are still players connected and "force" parameter was not specified if (delay < WorldConfig.GetIntValue(WorldCfg.ForceShutdownThreshold) && !shutdownMask.HasAnyFlag(ShutdownMask.Force) && !IsOnlyUser(handler.GetSession())) { delay = WorldConfig.GetIntValue(WorldCfg.ForceShutdownThreshold); handler.SendSysMessage(CypherStrings.ShutdownDelayed, delay); } Global.WorldMgr.ShutdownServ((uint)delay, shutdownMask, (ShutdownExitCode)exitCode, reason); return(true); }
static bool HandleArenaCaptainCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } string idStr; string nameStr; handler.extractOptFirstArg(args, out idStr, out nameStr); if (string.IsNullOrEmpty(idStr)) { return(false); } if (!uint.TryParse(idStr, out uint teamId) || teamId == 0) { return(false); } Player target; ObjectGuid targetGuid; if (!handler.extractPlayerTarget(new StringArguments(nameStr), out target, out targetGuid)) { return(false); } ArenaTeam arena = Global.ArenaTeamMgr.GetArenaTeamById(teamId); if (arena == null) { handler.SendSysMessage(CypherStrings.ArenaErrorNotFound, teamId); return(false); } if (!target) { handler.SendSysMessage(CypherStrings.PlayerNotExistOrOffline, nameStr); return(false); } if (arena.IsFighting()) { handler.SendSysMessage(CypherStrings.ArenaErrorCombat); return(false); } if (!arena.IsMember(targetGuid)) { handler.SendSysMessage(CypherStrings.ArenaErrorNotMember, nameStr, arena.GetName()); return(false); } if (arena.GetCaptain() == targetGuid) { handler.SendSysMessage(CypherStrings.ArenaErrorCaptain, nameStr, arena.GetName()); return(false); } arena.SetCaptain(targetGuid); CharacterInfo oldCaptainNameData = Global.WorldMgr.GetCharacterInfo(arena.GetCaptain()); if (oldCaptainNameData == null) { return(false); } handler.SendSysMessage(CypherStrings.ArenaCaptain, arena.GetName(), arena.GetId(), oldCaptainNameData.Name, target.GetName()); if (handler.GetSession() != null) { Log.outDebug(LogFilter.Arena, "GameMaster: {0} [GUID: {1}] promoted player: {2} [GUID: {3}] to leader of arena team \"{4}\"[Id: {5}]", handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString(), target.GetName(), target.GetGUID().ToString(), arena.GetName(), arena.GetId()); } else { Log.outDebug(LogFilter.Arena, "Console: promoted player: {0} [GUID: {1}] to leader of arena team \"{2}\"[Id: {3}]", target.GetName(), target.GetGUID().ToString(), arena.GetName(), arena.GetId()); } 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 HandleAccountPasswordCommand(StringArguments args, CommandHandler handler) { // If no args are given at all, we can return false right away. if (args.Empty()) { handler.SendSysMessage(CypherStrings.CmdSyntax); return(false); } // First, we check config. What security type (sec type) is it ? Depending on it, the command branches out uint pwConfig = WorldConfig.GetUIntValue(WorldCfg.AccPasschangesec); // 0 - PW_NONE, 1 - PW_EMAIL, 2 - PW_RBAC // Command is supposed to be: .account password [$oldpassword] [$newpassword] [$newpasswordconfirmation] [$emailconfirmation] string oldPassword = args.NextString(); // This extracts [$oldpassword] string newPassword = args.NextString(); // This extracts [$newpassword] string passwordConfirmation = args.NextString(); // This extracts [$newpasswordconfirmation] string emailConfirmation = args.NextString(); // This defines the emailConfirmation variable, which is optional depending on sec type. //Is any of those variables missing for any reason ? We return false. if (string.IsNullOrEmpty(oldPassword) || string.IsNullOrEmpty(newPassword) || string.IsNullOrEmpty(passwordConfirmation)) { handler.SendSysMessage(CypherStrings.CmdSyntax); return(false); } // We compare the old, saved password to the entered old password - no chance for the unauthorized. if (!Global.AccountMgr.CheckPassword(handler.GetSession().GetAccountId(), oldPassword)) { handler.SendSysMessage(CypherStrings.CommandWrongoldpassword); Log.outInfo(LogFilter.Player, "Account: {0} (IP: {1}) Character:[{2}] (GUID: {3}) Tried to change password, but the provided old password is wrong.", handler.GetSession().GetAccountId(), handler.GetSession().GetRemoteAddress(), handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString()); return(false); } // This compares the old, current email to the entered email - however, only... if ((pwConfig == 1 || (pwConfig == 2 && handler.GetSession().HasPermission(RBACPermissions.EmailConfirmForPassChange))) && // ...if either PW_EMAIL or PW_RBAC with the Permission is active... !Global.AccountMgr.CheckEmail(handler.GetSession().GetAccountId(), emailConfirmation)) // ... and returns false if the comparison fails. { handler.SendSysMessage(CypherStrings.CommandWrongemail); Log.outInfo(LogFilter.Player, "Account: {0} (IP: {1}) Character:[{2}] (GUID: {3}) Tried to change password, but the entered email [{4}] is wrong.", handler.GetSession().GetAccountId(), handler.GetSession().GetRemoteAddress(), handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString(), emailConfirmation); return(false); } // Making sure that newly entered password is correctly entered. if (newPassword != passwordConfirmation) { handler.SendSysMessage(CypherStrings.NewPasswordsNotMatch); return(false); } // Changes password and prints result. AccountOpResult result = Global.AccountMgr.ChangePassword(handler.GetSession().GetAccountId(), newPassword); switch (result) { case AccountOpResult.Ok: handler.SendSysMessage(CypherStrings.CommandPassword); Log.outInfo(LogFilter.Player, "Account: {0} (IP: {1}) Character:[{2}] (GUID: {3}) Changed Password.", handler.GetSession().GetAccountId(), handler.GetSession().GetRemoteAddress(), handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString()); break; case AccountOpResult.PassTooLong: handler.SendSysMessage(CypherStrings.PasswordTooLong); return(false); default: handler.SendSysMessage(CypherStrings.CommandNotchangepassword); return(false); } return(true); }
static bool HandleResetTalentsCommand(StringArguments args, CommandHandler handler) { Player target; ObjectGuid targetGuid; string targetName; if (!handler.extractPlayerTarget(args, out target, out targetGuid, out targetName)) { /* TODO: 6.x remove/update pet talents * // Try reset talents as Hunter Pet * Creature* creature = handler.getSelectedCreature(); * if (!*args && creature && creature.IsPet()) * { * Unit* owner = creature.GetOwner(); * if (owner && owner.GetTypeId() == TYPEID_PLAYER && creature.ToPet().IsPermanentPetFor(owner.ToPlayer())) * { * creature.ToPet().resetTalents(); * owner.ToPlayer().SendTalentsInfoData(true); * * ChatHandler(owner.ToPlayer().GetSession()).SendSysMessage(LANG_RESET_PET_TALENTS); * if (!handler.GetSession() || handler.GetSession().GetPlayer() != owner.ToPlayer()) * handler.PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE, handler.GetNameLink(owner.ToPlayer()).c_str()); * } * return true; * } */ handler.SendSysMessage(CypherStrings.NoCharSelected); return(false); } if (target) { target.ResetTalents(true); target.ResetTalentSpecialization(); target.SendTalentsInfoData(); target.SendSysMessage(CypherStrings.ResetTalents); if (handler.GetSession() == null || handler.GetSession().GetPlayer() != target) { handler.SendSysMessage(CypherStrings.ResetTalentsOnline, handler.GetNameLink(target)); } /* TODO: 6.x remove/update pet talents * Pet* pet = target.GetPet(); * Pet.resetTalentsForAllPetsOf(target, pet); * if (pet) * target.SendTalentsInfoData(true); */ return(true); } else if (!targetGuid.IsEmpty()) { PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_ADD_AT_LOGIN_FLAG); stmt.AddValue(0, (ushort)(AtLoginFlags.None | AtLoginFlags.ResetPetTalents)); stmt.AddValue(1, targetGuid.GetCounter()); DB.Characters.Execute(stmt); string nameLink = handler.playerLink(targetName); handler.SendSysMessage(CypherStrings.ResetTalentsOffline, nameLink); return(true); } handler.SendSysMessage(CypherStrings.NoCharSelected); return(false); }
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); }
static bool HandleInstanceGetBossState(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } string param1 = args.NextString(); string param2 = args.NextString(); uint encounterId = 0; Player player = null; // Character name must be provided when using this from console. if (string.IsNullOrEmpty(param1) || (string.IsNullOrEmpty(param2) && handler.GetSession() == null)) { handler.SendSysMessage(CypherStrings.CmdSyntax); return(false); } if (string.IsNullOrEmpty(param2)) { player = handler.GetSession().GetPlayer(); } else { if (ObjectManager.NormalizePlayerName(ref param2)) { player = Global.ObjAccessor.FindPlayerByName(param2); } } if (!player) { handler.SendSysMessage(CypherStrings.PlayerNotFound); return(false); } InstanceMap map = player.GetMap().ToInstanceMap(); if (map == null) { handler.SendSysMessage(CypherStrings.NotDungeon); return(false); } if (map.GetInstanceScript() == null) { handler.SendSysMessage(CypherStrings.NoInstanceData); return(false); } if (!uint.TryParse(param1, out encounterId)) { return(false); } if (encounterId > map.GetInstanceScript().GetEncounterCount()) { handler.SendSysMessage(CypherStrings.BadValue); return(false); } EncounterState state = map.GetInstanceScript().GetBossState(encounterId); handler.SendSysMessage(CypherStrings.CommandInstGetBossState, encounterId, state); return(true); }
static bool HandleCharacterChangeAccountCommand(StringArguments args, CommandHandler handler) { string playerNameStr; string accountName; handler.ExtractOptFirstArg(args, out playerNameStr, out accountName); if (accountName.IsEmpty()) { return(false); } ObjectGuid targetGuid; string targetName; if (!handler.ExtractPlayerTarget(new StringArguments(playerNameStr), out _, out targetGuid, out targetName)) { return(false); } CharacterCacheEntry characterInfo = Global.CharacterCacheStorage.GetCharacterCacheByGuid(targetGuid); if (characterInfo == null) { handler.SendSysMessage(CypherStrings.PlayerNotFound); return(false); } uint oldAccountId = characterInfo.AccountId; uint newAccountId = oldAccountId; PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_ID_BY_NAME); stmt.AddValue(0, accountName); SQLResult result = DB.Login.Query(stmt); if (!result.IsEmpty()) { newAccountId = result.Read <uint>(0); } else { handler.SendSysMessage(CypherStrings.AccountNotExist, accountName); return(false); } // nothing to do :) if (newAccountId == oldAccountId) { return(true); } uint charCount = Global.AccountMgr.GetCharactersCount(newAccountId); if (charCount != 0) { if (charCount >= WorldConfig.GetIntValue(WorldCfg.CharactersPerRealm)) { handler.SendSysMessage(CypherStrings.AccountCharacterListFull, accountName, newAccountId); return(false); } } stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_ACCOUNT_BY_GUID); stmt.AddValue(0, newAccountId); stmt.AddValue(1, targetGuid.GetCounter()); DB.Characters.DirectExecute(stmt); Global.WorldMgr.UpdateRealmCharCount(oldAccountId); Global.WorldMgr.UpdateRealmCharCount(newAccountId); Global.CharacterCacheStorage.UpdateCharacterAccountId(targetGuid, newAccountId); handler.SendSysMessage(CypherStrings.ChangeAccountSuccess, targetName, accountName); string logString = $"changed ownership of player {targetName} ({targetGuid}) from account {oldAccountId} to account {newAccountId}"; WorldSession session = handler.GetSession(); if (session != null) { Player player = session.GetPlayer(); if (player != null) { Log.outCommand(session.GetAccountId(), $"GM {player.GetName()} (Account: {session.GetAccountId()}) {logString}"); } } else { Log.outCommand(0, $"{handler.GetCypherString(CypherStrings.Console)} {logString}"); } 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); } } Map map = obj.GetMap(); obj.Relocate(x, y, z, obj.GetOrientation()); obj.SaveToDB(); // Generate a completely new spawn with new guid // client caches recently deleted objects and brings them back to life // when CreateObject block for this guid is received again // however it entirely skips parsing that block and only uses already known location obj.Delete(); obj = GameObject.CreateGameObjectFromDB(guidLow, map); if (!obj) { return(false); } handler.SendSysMessage(CypherStrings.CommandMoveobjmessage, obj.GetSpawnId(), obj.GetGoInfo().name, obj.GetGUID().ToString()); 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); } Global.CharacterCacheStorage.GetCharacterNameByGuid(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.CharacterCacheStorage.UpdateCharacterData(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, Global.CharacterCacheStorage.GetCharacterAccountIdByGuid(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 HandleAccountPasswordCommand(CommandHandler handler, string oldPassword, string newPassword, string confirmPassword, string confirmEmail) { // First, we check config. What security type (sec type) is it ? Depending on it, the command branches out uint pwConfig = WorldConfig.GetUIntValue(WorldCfg.AccPasschangesec); // 0 - PW_NONE, 1 - PW_EMAIL, 2 - PW_RBAC // We compare the old, saved password to the entered old password - no chance for the unauthorized. if (!Global.AccountMgr.CheckPassword(handler.GetSession().GetAccountId(), oldPassword)) { handler.SendSysMessage(CypherStrings.CommandWrongoldpassword); Log.outInfo(LogFilter.Player, "Account: {0} (IP: {1}) Character:[{2}] (GUID: {3}) Tried to change password, but the provided old password is wrong.", handler.GetSession().GetAccountId(), handler.GetSession().GetRemoteAddress(), handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString()); return(false); } // This compares the old, current email to the entered email - however, only... if ((pwConfig == 1 || (pwConfig == 2 && handler.GetSession().HasPermission(RBACPermissions.EmailConfirmForPassChange))) && // ...if either PW_EMAIL or PW_RBAC with the Permission is active... !Global.AccountMgr.CheckEmail(handler.GetSession().GetAccountId(), confirmEmail)) // ... and returns false if the comparison fails. { handler.SendSysMessage(CypherStrings.CommandWrongemail); Log.outInfo(LogFilter.Player, "Account: {0} (IP: {1}) Character:[{2}] (GUID: {3}) Tried to change password, but the entered email [{4}] is wrong.", handler.GetSession().GetAccountId(), handler.GetSession().GetRemoteAddress(), handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString(), confirmEmail); return(false); } // Making sure that newly entered password is correctly entered. if (newPassword != confirmPassword) { handler.SendSysMessage(CypherStrings.NewPasswordsNotMatch); return(false); } // Changes password and prints result. AccountOpResult result = Global.AccountMgr.ChangePassword(handler.GetSession().GetAccountId(), newPassword); switch (result) { case AccountOpResult.Ok: handler.SendSysMessage(CypherStrings.CommandPassword); Log.outInfo(LogFilter.Player, "Account: {0} (IP: {1}) Character:[{2}] (GUID: {3}) Changed Password.", handler.GetSession().GetAccountId(), handler.GetSession().GetRemoteAddress(), handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString()); break; case AccountOpResult.PassTooLong: handler.SendSysMessage(CypherStrings.PasswordTooLong); return(false); default: handler.SendSysMessage(CypherStrings.CommandNotchangepassword); return(false); } return(true); }