Core/Commands: Convert more misc commands in commandscript

This commit is contained in:
Vincent-Michael committed 2012-07-29 15:03:26 +02:00
1 parent e40a088b15
commit 4a3df36bd9
6 files changed
+308 -402

No files matched your search

+4 -41
View File
@@ -38,13 +38,6 @@
bool ChatHandler::load_command_table = true;
// wrapper for old-style handlers
template<bool (ChatHandler::*F)(const char*)>
bool OldHandler(ChatHandler* chatHandler, const char* args)
{
return (chatHandler->*F)(args);
}
// get number of commands in table
static size_t getCommandTableSize(const ChatCommand* commands)
{
@@ -67,35 +60,6 @@ static size_t appendCommandTable(ChatCommand* target, const ChatCommand* source)
ChatCommand* ChatHandler::getCommandTable()
{
static ChatCommand groupCommandTable[] =
{
{ "leader", SEC_ADMINISTRATOR, false, OldHandler<&ChatHandler::HandleGroupLeaderCommand>, "", NULL },
{ "disband", SEC_ADMINISTRATOR, false, OldHandler<&ChatHandler::HandleGroupDisbandCommand>, "", NULL },
{ "remove", SEC_ADMINISTRATOR, false, OldHandler<&ChatHandler::HandleGroupRemoveCommand>, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand pdumpCommandTable[] =
{
{ "load", SEC_ADMINISTRATOR, true, OldHandler<&ChatHandler::HandlePDumpLoadCommand>, "", NULL },
{ "write", SEC_ADMINISTRATOR, true, OldHandler<&ChatHandler::HandlePDumpWriteCommand>, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "pdump", SEC_ADMINISTRATOR, true, NULL, "", pdumpCommandTable },
{ "group", SEC_ADMINISTRATOR, false, NULL, "", groupCommandTable },
{ "possess", SEC_ADMINISTRATOR, false, OldHandler<&ChatHandler::HandlePossessCommand>, "", NULL },
{ "unpossess", SEC_ADMINISTRATOR, false, OldHandler<&ChatHandler::HandleUnPossessCommand>, "", NULL },
{ "bindsight", SEC_ADMINISTRATOR, false, OldHandler<&ChatHandler::HandleBindSightCommand>, "", NULL },
{ "unbindsight", SEC_ADMINISTRATOR, false, OldHandler<&ChatHandler::HandleUnbindSightCommand>, "", NULL },
{ "playall", SEC_GAMEMASTER, false, OldHandler<&ChatHandler::HandlePlayAllCommand>, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
// cache for commands, needed because some commands are loaded dynamically through ScriptMgr
// cache is never freed and will show as a memory leak in diagnostic tools
// can't use vector as vector storage is implementation-dependent, eg, there can be alignment gaps between elements
@@ -107,25 +71,23 @@ ChatCommand* ChatHandler::getCommandTable()
{
// count total number of top-level commands
size_t total = getCommandTableSize(commandTable);
size_t total = 0;
std::vector<ChatCommand*> const& dynamic = sScriptMgr->GetChatCommands();
for (std::vector<ChatCommand*>::const_iterator it = dynamic.begin(); it != dynamic.end(); ++it)
total += getCommandTableSize(*it);
total += 1; // ending zero
// cache top-level commands
size_t added = 0;
commandTableCache = (ChatCommand*)malloc(sizeof(ChatCommand) * total);
memset(commandTableCache, 0, sizeof(ChatCommand) * total);
ACE_ASSERT(commandTableCache);
size_t added = appendCommandTable(commandTableCache, commandTable);
for (std::vector<ChatCommand*>::const_iterator it = dynamic.begin(); it != dynamic.end(); ++it)
added += appendCommandTable(commandTableCache + added, *it);
}
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_COMMANDS);
PreparedQueryResult result = WorldDatabase.Query(stmt);
if (result)
{
do
@@ -135,7 +97,8 @@ ChatCommand* ChatHandler::getCommandTable()
SetDataForCommandInTable(commandTableCache, name.c_str(), fields[1].GetUInt8(), fields[2].GetString(), name);
} while (result->NextRow());
}
while (result->NextRow());
}
}