Implemented account_muted and feature mutehistory command (#753)

* Implemented account_muted and feature

mutehistory command.

* Added some Syntax.

* Fix sql_rev
This commit is contained in:
Nefertumm
2018-01-15 00:18:23 -03:00
committed by Lee
parent 90ed2548c0
commit 4158d2a0d8
6 changed files with 91 additions and 1 deletions

View File

@@ -5,7 +5,7 @@ CREATE PROCEDURE updateDb ()
proc:BEGIN DECLARE OK VARCHAR(100) DEFAULT 'FALSE';
SELECT COUNT(*) INTO @COLEXISTS
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'version_db_world' AND COLUMN_NAME = '2017_12_08_00';
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'version_db_world' AND COLUMN_NAME = '2017_11_21_00';
IF @COLEXISTS = 0 THEN LEAVE proc; END IF;
START TRANSACTION;
ALTER TABLE version_db_world CHANGE COLUMN 2017_11_21_00 2017_12_08_00 bit;

View File

@@ -0,0 +1,13 @@
INSERT INTO version_db_auth (`sql_rev`) VALUES ('1515646234610593200');
DROP TABLE IF EXISTS `account_muted`;
CREATE TABLE `account_muted` (
`guid` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Global Unique Identifier',
`mutedate` INT(10) UNSIGNED NOT NULL DEFAULT '0',
`mutetime` INT(10) UNSIGNED NOT NULL DEFAULT '0',
`mutedby` VARCHAR(50) NOT NULL,
`mutereason` VARCHAR(255) NOT NULL,
PRIMARY KEY (`guid`, `mutedate`)
)
COMMENT='mute List' ENGINE=InnoDB;

View File

@@ -0,0 +1,5 @@
INSERT INTO version_db_world (`sql_rev`) VALUES ('1515648036333645900');
/* Create the command. */
DELETE FROM `command` WHERE `name` = "mutehistory";
INSERT INTO `command` (`name`,`security`,`help`) VALUES ('mutehistory', 2, "Syntax: .mutehistory $accountName. Shows mute history for an account.");

View File

@@ -81,4 +81,6 @@ void LoginDatabaseConnection::DoPrepareStatements()
PrepareStatement(LOGIN_DEL_ACCOUNT, "DELETE FROM account WHERE id = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_SEL_IP2NATION_COUNTRY, "SELECT c.country FROM ip2nationCountries c, ip2nation i WHERE i.ip < ? AND c.code = i.country ORDER BY i.ip DESC LIMIT 0,1", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_AUTOBROADCAST, "SELECT id, weight, text FROM autobroadcast WHERE realmid = ? OR realmid = -1", CONNECTION_SYNCH);
PrepareStatement(LOGIN_INS_ACCOUNT_MUTE, "INSERT INTO account_muted VALUES (?, UNIX_TIMESTAMP(), ?, ?, ?)", CONNECTION_ASYNC);
PrepareStatement(LOGIN_SEL_ACCOUNT_MUTE_INFO, "SELECT mutedate, mutetime, mutereason, mutedby FROM account_muted WHERE guid = ? ORDER BY mutedate ASC", CONNECTION_SYNCH);
}

View File

@@ -102,6 +102,9 @@ enum LoginDatabaseStatements
LOGIN_SEL_IP2NATION_COUNTRY,
LOGIN_SEL_AUTOBROADCAST,
LOGIN_INS_ACCOUNT_MUTE,
LOGIN_SEL_ACCOUNT_MUTE_INFO,
MAX_LOGINDATABASE_STATEMENTS
};

View File

@@ -96,6 +96,7 @@ public:
{ "send", SEC_GAMEMASTER, true, nullptr, "", sendCommandTable },
{ "pet", SEC_GAMEMASTER, false, nullptr, "", petCommandTable },
{ "mute", SEC_GAMEMASTER, true, &HandleMuteCommand, "" },
{ "mutehistory", SEC_GAMEMASTER, true, &HandleMuteInfoCommand, "" },
{ "unmute", SEC_GAMEMASTER, true, &HandleUnmuteCommand, "" },
{ "movegens", SEC_ADMINISTRATOR, false, &HandleMovegensCommand, "" },
{ "cometome", SEC_ADMINISTRATOR, false, &HandleComeToMeCommand, "" },
@@ -2159,6 +2160,13 @@ public:
stmt->setString(2, muteBy.c_str());
stmt->setUInt32(3, accountId);
LoginDatabase.Execute(stmt);
stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ACCOUNT_MUTE);
stmt->setUInt32(0, accountId);
stmt->setUInt32(1, notSpeakTime);
stmt->setString(2, muteBy.c_str());
stmt->setString(3, muteReasonStr.c_str());
LoginDatabase.Execute(stmt);
std::string nameLink = handler->playerLink(targetName);
// pussywizard: notify all online GMs
@@ -2220,6 +2228,65 @@ public:
return true;
}
// mutehistory command
static bool HandleMuteInfoCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char *nameStr = strtok((char*)args, "");
if (!nameStr)
return false;
std::string accountName = nameStr;
if (!AccountMgr::normalizeString(accountName))
{
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
handler->SetSentErrorMessage(true);
return false;
}
uint32 accountId = AccountMgr::GetId(accountName);
if (!accountId)
{
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
return false;
}
return HandleMuteInfoHelper(accountId, accountName.c_str(), handler);
}
// helper for mutehistory
static bool HandleMuteInfoHelper(uint32 accountId, char const* accountName, ChatHandler* handler)
{
PreparedStatement *stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_MUTE_INFO);
stmt->setUInt16(0, accountId);
PreparedQueryResult result = LoginDatabase.Query(stmt);
if (!result)
{
handler->PSendSysMessage(LANG_COMMAND_MUTEHISTORY_EMPTY, accountName);
return true;
}
handler->PSendSysMessage(LANG_COMMAND_MUTEHISTORY, accountName);
do
{
Field* fields = result->Fetch();
// we have to manually set the string for mutedate
time_t sqlTime = fields[0].GetUInt32();
tm timeInfo;
char buffer[80];
// set it to string
ACE_OS::localtime_r(&sqlTime, &timeInfo);
strftime(buffer, sizeof(buffer), "%Y-%m-%d %I:%M%p", &timeInfo);
handler->PSendSysMessage(LANG_COMMAND_MUTEHISTORY_OUTPUT, buffer, fields[1].GetUInt32(), fields[2].GetCString(), fields[3].GetCString());
} while (result->NextRow());
return true;
}
static bool HandleMovegensCommand(ChatHandler* handler, char const* /*args*/)
{