Created
October 27, 2019 23:23
-
-
Save vhiperdev/1b0cf4de3127d726fa7be14146b88a0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ScriptMgr.h" | |
#include "Chat.h" | |
#include <list> | |
#include "Containers.h" | |
std::vector<string>chat; | |
class LoadChatTable : public WorldScript | |
{ | |
public: | |
LoadChatTable() : WorldScript("load_system_censure") { } | |
void OnLoadCustomDatabaseTable() | |
{ | |
sLog->outString("Loading corpses..."); | |
QueryResult result = CharacterDatabase.PQuery("SELECT * FROM corpse"); | |
if (!result) | |
{ | |
sLog->outErrorDb(">> Loaded 0 Chat Censures. DB table `corpses` is empty!"); | |
sLog->outString(); | |
return; | |
} | |
uint32 count = 0; | |
uint32 oldMSTime = getMSTime(); | |
do | |
{ | |
Field* field = result->Fetch(); | |
uint8 id = field[0].GetUInt8(); | |
chat.push_back(field[1].GetString()); | |
count++; | |
} while (result->NextRow()); | |
sLog->outString(">> Loaded", count, GetMSTimeDiffToNow(oldMSTime)); | |
sLog->outString(""); | |
} | |
}; | |
class CleanCorpsesCommand : public CommandScript | |
{ | |
public: | |
CleanCorpsesCommand() : CommandScript("CleanCorpsesCommand") { } | |
std::vector<ChatCommand> GetCommands() const override | |
{ | |
static std::vector<ChatCommand> CleanCorpsesCommandTable = | |
{ | |
{ "reload", SEC_MODERATOR, false, &HandleReloadCommand, "" }, | |
{ "del", SEC_MODERATOR, false, &HandleDelCommand, "" } | |
}; | |
static std::vector<ChatCommand> CleanCorpsesBaseTable = | |
{ | |
{ "wowerro", SEC_MODERATOR, false, nullptr, "", CleanCorpsesCommandTable } | |
}; | |
return CleanCorpsesBaseTable; | |
} | |
static bool HandleReloadCommand(ChatHandler* handler, char const* args) | |
{ | |
Player* me = handler->GetSession()->GetPlayer(); | |
if (!me) | |
return false; | |
chat.clear(); | |
QueryResult result = CharacterDatabase.Query("SELECT `corpseGuid`,`guid` FROM corpse"); | |
uint32 count = 0; | |
uint32 oldMSTime = getMSTime(); | |
do | |
{ | |
Field* field = result->Fetch(); | |
uint8 id = field[0].GetUInt8(); | |
chat.push_back(field[1].GetString()); | |
count++; | |
} while (result->NextRow()); | |
ChatHandler(me->GetSession()).PSendSysMessage("Reloaded", count, GetMSTimeDiffToNow(oldMSTime)); | |
return true; | |
} | |
static bool HandleDelCommand(ChatHandler* handler, const char* args) | |
{ | |
Player* player = handler->GetSession()->GetPlayer(); | |
QueryResult DeleteCharacters = CharacterDatabase.PQuery("DELETE FROM corpse"); | |
return true; | |
} | |
}; | |
void AddSC_CleanCorpses() | |
{ | |
new CleanCorpsesCommand(); | |
new LoadChatTable(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment