Merge pull request #7258 from myran2/DisableCommands

Added disable commands.
This commit is contained in:
Nay
2012-08-02 15:33:18 -07:00
5 changed files with 202 additions and 0 deletions

View File

@@ -50,6 +50,7 @@ void AddSC_ban_commandscript();
void AddSC_cast_commandscript();
void AddSC_character_commandscript();
void AddSC_debug_commandscript();
void AddSC_disable_commandscript();
void AddSC_event_commandscript();
void AddSC_gm_commandscript();
void AddSC_go_commandscript();
@@ -663,6 +664,7 @@ void AddCommandScripts()
AddSC_cast_commandscript();
AddSC_character_commandscript();
AddSC_debug_commandscript();
AddSC_disable_commandscript();
AddSC_event_commandscript();
AddSC_gm_commandscript();
AddSC_go_commandscript();

View File

@@ -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

View File

@@ -0,0 +1,195 @@
/*
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/* 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();
}

View File

@@ -88,4 +88,6 @@ void WorldDatabaseConnection::DoPrepareStatements()
PREPARE_STATEMENT(WORLD_DEL_GAME_EVENT_CREATURE, "DELETE FROM game_event_creature WHERE guid = ?", CONNECTION_ASYNC);
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 entry FROM disables WHERE entry = ? AND sourceType = ? AND flags > 0", CONNECTION_SYNCH);
}

View File

@@ -109,6 +109,8 @@ enum WorldDatabaseStatements
WORLD_DEL_GAME_EVENT_CREATURE,
WORLD_DEL_GAME_EVENT_MODEL_EQUIP,
WORLD_INS_GAMEOBJECT,
WORLD_SEL_DISABLES,
WORLD_INS_DISABLES,
MAX_WORLDDATABASE_STATEMENTS,
};