From f303782de4ec739bb175b7a503fb3a74a1d8a1f9 Mon Sep 17 00:00:00 2001 From: Alternative Date: Thu, 2 Aug 2012 16:33:35 -0400 Subject: Added disable commands. --- src/server/scripts/Commands/CMakeLists.txt | 1 + src/server/scripts/Commands/cs_disable.cpp | 195 +++++++++++++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 src/server/scripts/Commands/cs_disable.cpp (limited to 'src/server/scripts/Commands') diff --git a/src/server/scripts/Commands/CMakeLists.txt b/src/server/scripts/Commands/CMakeLists.txt index ca4a964ffb3..bd439c2c473 100644 --- a/src/server/scripts/Commands/CMakeLists.txt +++ b/src/server/scripts/Commands/CMakeLists.txt @@ -16,6 +16,7 @@ set(scripts_STAT_SRCS Commands/cs_cast.cpp Commands/cs_character.cpp Commands/cs_debug.cpp + Commands/cs_disable.cpp Commands/cs_event.cpp Commands/cs_gm.cpp Commands/cs_go.cpp diff --git a/src/server/scripts/Commands/cs_disable.cpp b/src/server/scripts/Commands/cs_disable.cpp new file mode 100644 index 00000000000..d748db56a1a --- /dev/null +++ b/src/server/scripts/Commands/cs_disable.cpp @@ -0,0 +1,195 @@ +/* + * Copyright (C) 2008-2012 TrinityCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +/* ScriptData +Name: disable_commandscript +%Complete: 100 +Comment: All disable related commands +Category: commandscripts +EndScriptData */ + +#include "ScriptMgr.h" +#include "ObjectMgr.h" +#include "Chat.h" +#include "DisableMgr.h" + +class disable_commandscript : public CommandScript +{ +public: + disable_commandscript() : CommandScript("disable_commandscript") { } + + ChatCommand* GetCommands() const + { + + static ChatCommand disableCommandTable[] = + { + { "spell", SEC_GAMEMASTER, false, &HandleDisableSpellCommand, "", NULL }, + { "map", SEC_GAMEMASTER, false, &HandleDisableMapCommand, "", NULL }, + { "battleground", SEC_GAMEMASTER, false, &HandleDisableBattlegroundCommand, "", NULL }, + { "achievement_criteria", SEC_GAMEMASTER, false, &HandleDisableAchievementCriteriaCommand, "", NULL }, + { "outdoorpvp", SEC_GAMEMASTER, false, &HandleDisableOutdoorPvPCommand, "", NULL }, + { "vmap", SEC_GAMEMASTER, false, &HandleDisableVmapCommand, "", NULL }, + { NULL, 0, false, NULL, "", NULL } + }; + + static ChatCommand commandTable[] = + { + { "disable", SEC_GAMEMASTER, false, NULL, "", disableCommandTable }, + { NULL, 0, false, NULL, "", NULL } + }; + return commandTable; + } + + + static void HandleDisables(ChatHandler* handler, char const* args, uint8 disableType) + { + char* cEntry = strtok((char*)args, " "); + if (!cEntry || !atoi(cEntry)) + { + handler->SendSysMessage("No entry specified."); + return; + } + + char* cFlags = strtok(NULL, " "); + if (!cFlags || !atoi(cFlags)) + { + handler->SendSysMessage("No flags specified."); + return; + } + + char* cComment = strtok(NULL, ""); + if (!cComment) + { + handler->SendSysMessage("No comment specified."); + return; + } + + std::string entryStr = cEntry; + std::string disableComment = cComment; + uint32 entry = (uint32)atoi(cEntry); + uint8 flags = atoi(cFlags); + + + + std::string disableTypeStr = ""; + + switch(disableType) + { + case DISABLE_TYPE_SPELL: + disableTypeStr = "spell"; + break; + case DISABLE_TYPE_MAP: + disableTypeStr = "map"; + break; + case DISABLE_TYPE_BATTLEGROUND: + disableTypeStr = "battleground"; + break; + case DISABLE_TYPE_ACHIEVEMENT_CRITERIA: + disableTypeStr = "achievement criteria"; + break; + case DISABLE_TYPE_OUTDOORPVP: + disableTypeStr = "outdoorpvp"; + break; + case DISABLE_TYPE_VMAP: + disableTypeStr = "vmap"; + break; + } + + PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_DISABLES); + stmt->setUInt32(0, entry); + stmt->setUInt8(1, disableType); + PreparedQueryResult result = WorldDatabase.Query(stmt); + + + if (result) + { + handler->PSendSysMessage("This %s (id %u) is already disabled.", disableTypeStr.c_str(), entry); + return; + } + + PreparedStatement* stmt2 = WorldDatabase.GetPreparedStatement(WORLD_INS_DISABLES); + stmt2->setUInt32(0, entry); + stmt2->setUInt8(1, disableType); + stmt->setUInt16(2, flags); + stmt2->setString(3, disableComment); + WorldDatabase.Execute(stmt2); + + handler->PSendSysMessage("Disabled %s %u for reason %s", disableTypeStr.c_str(), entry, disableComment.c_str()); + return; + + } + + static bool HandleDisableSpellCommand(ChatHandler* handler, char const* args) + { + if (!*args) + return false; + + HandleDisables(handler, args, DISABLE_TYPE_SPELL); + return true; + } + + static bool HandleDisableMapCommand(ChatHandler* handler, char const* args) + { + if (!*args) + return false; + + HandleDisables(handler, args, DISABLE_TYPE_MAP); + return true; + } + + static bool HandleDisableBattlegroundCommand(ChatHandler* handler, char const* args) + { + if (!*args) + return false; + + HandleDisables(handler, args, DISABLE_TYPE_BATTLEGROUND); + return true; + } + + static bool HandleDisableAchievementCriteriaCommand(ChatHandler* handler, char const* args) + { + if (!*args) + return false; + + HandleDisables(handler, args, DISABLE_TYPE_ACHIEVEMENT_CRITERIA); + return true; + } + + static bool HandleDisableOutdoorPvPCommand(ChatHandler* handler, char const* args) + { + if (!*args) + return false; + + HandleDisables(handler, args, DISABLE_TYPE_OUTDOORPVP); + return true; + } + + static bool HandleDisableVmapCommand(ChatHandler* handler, char const* args) + { + if (!*args) + return false; + + HandleDisables(handler, args, DISABLE_TYPE_VMAP); + return true; + } + +}; + +void AddSC_disable_commandscript() +{ + new disable_commandscript(); +} \ No newline at end of file -- cgit v1.2.3 From dc7030ced686aca85893cdd80376e705e6bfb513 Mon Sep 17 00:00:00 2001 From: Alternative Date: Thu, 2 Aug 2012 16:47:28 -0400 Subject: Some codestyle changes. --- src/server/scripts/Commands/cs_disable.cpp | 2 +- src/server/shared/Database/Implementation/WorldDatabase.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/server/scripts/Commands') diff --git a/src/server/scripts/Commands/cs_disable.cpp b/src/server/scripts/Commands/cs_disable.cpp index d748db56a1a..d3475ac10ae 100644 --- a/src/server/scripts/Commands/cs_disable.cpp +++ b/src/server/scripts/Commands/cs_disable.cpp @@ -87,7 +87,7 @@ public: std::string disableTypeStr = ""; - switch(disableType) + switch (disableType) { case DISABLE_TYPE_SPELL: disableTypeStr = "spell"; diff --git a/src/server/shared/Database/Implementation/WorldDatabase.cpp b/src/server/shared/Database/Implementation/WorldDatabase.cpp index dfee1e2f11f..3b59f283ddb 100755 --- a/src/server/shared/Database/Implementation/WorldDatabase.cpp +++ b/src/server/shared/Database/Implementation/WorldDatabase.cpp @@ -89,5 +89,5 @@ void WorldDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(WORLD_DEL_GAME_EVENT_MODEL_EQUIP, "DELETE FROM game_event_model_equip WHERE guid = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(WORLD_INS_GAMEOBJECT, "INSERT INTO gameobject (guid, id, map, spawnMask, phaseMask, position_x, position_y, position_z, orientation, rotation0, rotation1, rotation2, rotation3, spawntimesecs, animprogress, state) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC); PREPARE_STATEMENT(WORLD_INS_DISABLES, "INSERT INTO disables (entry, sourceType, flags, comment) VALUES (?, ?, ?, ?)", CONNECTION_ASYNC); - PREPARE_STATEMENT(WORLD_SEL_DISABLES, "SELECT * FROM disables WHERE entry = ? AND sourceType = ? AND flags > 0", CONNECTION_SYNCH); + PREPARE_STATEMENT(WORLD_SEL_DISABLES, "SELECT entry FROM disables WHERE entry = ? AND sourceType = ? AND flags > 0", CONNECTION_SYNCH); } -- cgit v1.2.3