From b503b842d60c52fd96005c07cc92413c1a621300 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Thu, 14 Jan 2021 18:12:17 -0500 Subject: [PATCH] Core/Commands: Fixes npc delete command not working. Also addes missing TeleCommands. --- Source/Framework/Constants/Language.cs | 2 +- Source/Game/Chat/Commands/NPCCommands.cs | 2 +- Source/Game/Chat/Commands/TeleCommands.cs | 136 +++++++++++++++++++++- Source/Game/Globals/ObjectManager.cs | 50 +++++++- 4 files changed, 184 insertions(+), 6 deletions(-) diff --git a/Source/Framework/Constants/Language.cs b/Source/Framework/Constants/Language.cs index 96168ad36..6cb659c4c 100644 --- a/Source/Framework/Constants/Language.cs +++ b/Source/Framework/Constants/Language.cs @@ -503,7 +503,7 @@ namespace Framework.Constants CommandZonenografaction = 461, CommandTpAlreadyexist = 462, CommandTpAdded = 463, - CommandTpAddederr = 464, + CommandTpAddedError = 464, CommandTpDeleted = 465, CommandNotaxinodefound = 466, CommandTargetListauras = 467, diff --git a/Source/Game/Chat/Commands/NPCCommands.cs b/Source/Game/Chat/Commands/NPCCommands.cs index 72ed00812..a30c32ef4 100644 --- a/Source/Game/Chat/Commands/NPCCommands.cs +++ b/Source/Game/Chat/Commands/NPCCommands.cs @@ -863,7 +863,7 @@ namespace Game.Chat [CommandGroup("delete", RBACPermissions.CommandNpcDelete)] class DeleteCommands { - [Command("delete", RBACPermissions.CommandNpcDelete)] + [Command("", RBACPermissions.CommandNpcDelete)] static bool HandleNpcDeleteCommand(StringArguments args, CommandHandler handler) { Creature creature; diff --git a/Source/Game/Chat/Commands/TeleCommands.cs b/Source/Game/Chat/Commands/TeleCommands.cs index 564aa2d6c..65220083f 100644 --- a/Source/Game/Chat/Commands/TeleCommands.cs +++ b/Source/Game/Chat/Commands/TeleCommands.cs @@ -16,10 +16,12 @@ */ using Framework.Constants; +using Framework.Database; using Framework.IO; using Game.DataStorage; using Game.Entities; using Game.Groups; +using System; using System.Collections.Generic; namespace Game.Chat @@ -73,13 +75,60 @@ namespace Game.Chat [Command("add", RBACPermissions.CommandTeleAdd)] static bool HandleTeleAddCommand(StringArguments args, CommandHandler handler) { - return false; + if (args.Empty()) + return false; + + Player player = handler.GetSession().GetPlayer(); + if (player == null) + return false; + + string name = args.NextString(); + + if (Global.ObjectMgr.GetGameTele(name) != null) + { + handler.SendSysMessage(CypherStrings.CommandTpAlreadyexist); + return false; + } + + GameTele tele = new GameTele(); + tele.posX = player.GetPositionX(); + tele.posY = player.GetPositionY(); + tele.posZ = player.GetPositionZ(); + tele.orientation = player.GetOrientation(); + tele.mapId = player.GetMapId(); + tele.name = name; + tele.nameLow = name.ToLowerInvariant(); + + if (Global.ObjectMgr.AddGameTele(tele)) + { + handler.SendSysMessage(CypherStrings.CommandTpAdded); + } + else + { + handler.SendSysMessage(CypherStrings.CommandTpAddedError); + return false; + } + + return true; } [Command("del", RBACPermissions.CommandTeleDel, true)] static bool HandleTeleDelCommand(StringArguments args, CommandHandler handler) { - return false; + if (args.Empty()) + return false; + + // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r + GameTele tele = handler.ExtractGameTeleFromLink(args); + if (tele == null) + { + handler.SendSysMessage(CypherStrings.CommandTeleNotfound); + return false; + } + + Global.ObjectMgr.DeleteGameTele(tele.name); + handler.SendSysMessage(CypherStrings.CommandTpDeleted); + return true; } [Command("group", RBACPermissions.CommandTeleGroup)] @@ -164,7 +213,88 @@ namespace Game.Chat [Command("name", RBACPermissions.CommandTeleName, true)] static bool HandleTeleNameCommand(StringArguments args, CommandHandler handler) { - return false; + handler.ExtractOptFirstArg(args, out string nameStr, out string teleStr); + if (teleStr.IsEmpty()) + return false; + + if (!handler.ExtractPlayerTarget(new StringArguments(nameStr), out Player target, out ObjectGuid targetGuid, out string targetName)) + return false; + + if (teleStr.Equals("$home")) // References target's homebind + { + if (target) + target.TeleportTo(target.GetHomebind()); + else + { + PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHAR_HOMEBIND); + stmt.AddValue(0, targetGuid.GetCounter()); + SQLResult result = DB.Characters.Query(stmt); + + if (!result.IsEmpty()) + { + WorldLocation loc = new WorldLocation(result.Read(0), result.Read(2), result.Read(3), result.Read(4), 0.0f); + uint zoneId = result.Read(1); + + Player.SavePositionInDB(loc, zoneId, targetGuid, null); + } + } + + return true; + } + + // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r + GameTele tele = handler.ExtractGameTeleFromLink(new StringArguments(teleStr)); + if (tele == null) + { + handler.SendSysMessage(CypherStrings.CommandTeleNotfound); + return false; + } + + if (target) + { + // check online security + if (handler.HasLowerSecurity(target, ObjectGuid.Empty)) + return false; + + string chrNameLink = handler.PlayerLink(targetName); + + if (target.IsBeingTeleported() == true) + { + handler.SendSysMessage(CypherStrings.IsTeleported, chrNameLink); + return false; + } + + handler.SendSysMessage(CypherStrings.TeleportingTo, chrNameLink, "", tele.name); + if (handler.NeedReportToTarget(target)) + target.SendSysMessage(CypherStrings.TeleportedToBy, handler.GetNameLink()); + + // stop flight if need + if (target.IsInFlight()) + { + target.GetMotionMaster().MovementExpired(); + target.CleanupAfterTaxiFlight(); + } + // save only in non-flight case + else + target.SaveRecallPosition(); + + target.TeleportTo(tele.mapId, tele.posX, tele.posY, tele.posZ, tele.orientation); + } + else + { + // check offline security + if (handler.HasLowerSecurity(null, targetGuid)) + return false; + + string nameLink = handler.PlayerLink(targetName); + + handler.SendSysMessage(CypherStrings.TeleportingTo, nameLink, handler.GetCypherString(CypherStrings.Offline), tele.name); + + Player.SavePositionInDB(new WorldLocation(tele.mapId, tele.posX, tele.posY, tele.posZ, tele.orientation), + Global.MapMgr.GetZoneId(PhasingHandler.EmptyPhaseShift, tele.mapId, tele.posX, tele.posY, tele.posZ), targetGuid, null); + } + + return true; } } } diff --git a/Source/Game/Globals/ObjectManager.cs b/Source/Game/Globals/ObjectManager.cs index d3c229358..4b87f0349 100644 --- a/Source/Game/Globals/ObjectManager.cs +++ b/Source/Game/Globals/ObjectManager.cs @@ -4976,6 +4976,8 @@ namespace Game gt.mapId = result.Read(5); gt.name = result.Read(6); + gt.nameLow = gt.name.ToLowerInvariant(); + if (!GridDefines.IsValidMapCoord(gt.mapId, gt.posX, gt.posY, gt.posZ, gt.orientation)) { Log.outError(LogFilter.Sql, "Wrong position for id {0} (name: {1}) in `game_tele` table, ignoring.", id, gt.name); @@ -5438,7 +5440,53 @@ namespace Game } public GameTele GetGameTele(string name) { - return gameTeleStorage.Values.FirstOrDefault(p => p.name.ToLower() == name.ToLower()); + return gameTeleStorage.Values.FirstOrDefault(p => p.nameLow == name.ToLower()); + } + public bool AddGameTele(GameTele tele) + { + // find max id + uint newId = 0; + foreach (var itr in gameTeleStorage) + if (itr.Key > newId) + newId = itr.Key; + + // use next + ++newId; + + gameTeleStorage[newId] = tele; + + PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.INS_GAME_TELE); + + stmt.AddValue(0, newId); + stmt.AddValue(1, tele.posX); + stmt.AddValue(2, tele.posY); + stmt.AddValue(3, tele.posZ); + stmt.AddValue(4, tele.orientation); + stmt.AddValue(5, tele.mapId); + stmt.AddValue(6, tele.name); + + DB.World.Execute(stmt); + + return true; + } + public bool DeleteGameTele(string name) + { + name = name.ToLowerInvariant(); + + foreach (var pair in gameTeleStorage.ToList()) + { + if (pair.Value.nameLow == name) + { + PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.DEL_GAME_TELE); + stmt.AddValue(0, pair.Value.name); + DB.World.Execute(stmt); + + gameTeleStorage.Remove(pair.Key); + return true; + } + } + + return false; } public List GetDungeonEncounterList(uint mapId, Difficulty difficulty) {