Skip to content

Commit

Permalink
feat(Core/WorldSession): rework mute system (#16)
Browse files Browse the repository at this point in the history
- Removed very old mute system (in `account` db table)
- The system has been moved to a separate manager (Implement mute manager)
- Added config option `Mute.AddAfterLogin.Enable` for mute now or after login if the target offline
  • Loading branch information
Winfidonarleyan authored Jul 3, 2020
1 parent 4c111a6 commit 097df4e
Show file tree
Hide file tree
Showing 21 changed files with 415 additions and 154 deletions.
12 changes: 12 additions & 0 deletions data/sql/custom/db_auth/2020_06_26_00_mute_system.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ALTER TABLE `account_muted`
CHANGE COLUMN `guid` `accountid` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Global Unique Identifier' FIRST,
ADD COLUMN `id` int(10) NOT NULL AUTO_INCREMENT FIRST,
ADD COLUMN `active` tinyint(1) NOT NULL AFTER `mutereason`,
MODIFY COLUMN `mutetime` int(10) NOT NULL DEFAULT 0 AFTER `mutedate`,
DROP PRIMARY KEY,
ADD PRIMARY KEY (`id`) USING BTREE;

ALTER TABLE `account`
DROP COLUMN `mutetime`,
DROP COLUMN `mutereason`,
DROP COLUMN `muteby`;
4 changes: 4 additions & 0 deletions data/sql/custom/db_world/2020_06_26_00_rework_mute_system.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
UPDATE `acore_string` SET `locale_ruRU` = '%s отключил чат %s на %u минут, действующий при следующем входе игрока в игру. Причина: %s.' WHERE `entry` = 283;
UPDATE `acore_string` SET `locale_ruRU` = 'У вас отключен чат на %u минут. Отключил %s. Причина %s.' WHERE `entry` = 300;
UPDATE `acore_string` SET `locale_ruRU` = 'Вы отключили чат %s на %u минут. Причина: %s.', `content_default` = 'You has disabled %s\'s chat for %u minutes. Reason: %s.', `locale_deDE` = NULL WHERE `entry` = 301;
UPDATE `acore_string` SET `locale_ruRU` = 'Server: %s замутил %s на %u минут. Причина: %s' WHERE `entry` = 11003;
3 changes: 2 additions & 1 deletion modules/mod-anti-ad/src/AntiAD_SC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "AccountMgr.h"
#include "GameTime.h"
#include "GameLocale.h"
#include "MuteManager.h"
#include <vector>

enum LocaleStrings
Expand Down Expand Up @@ -129,7 +130,7 @@ class AntiAD_Player : public PlayerScript

uint32 muteTime = CONF_GET_INT("AntiAD.Mute.Time");

player->GetSession()->m_muteTime = time(nullptr) + muteTime * MINUTE;
sMute->MutePlayer(player->GetName(), muteTime, "Console", "Advertisment");

if (CONF_GET_BOOL("AntiAD.SelfMessage.Enable"))
sGameLocale->SendPlayerMessage(player, "mod-anti-ad", ANTIAD_SEND_SELF, muteTime);
Expand Down
3 changes: 2 additions & 1 deletion modules/mod-notify-muted/src/NotifyMuted_SC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "Chat.h"
#include "Player.h"
#include "GameTime.h"
#include "MuteManager.h"

namespace lang
{
Expand All @@ -43,7 +44,7 @@ class NotifyMuted_Player : public PlayerScript
if (receiver->CanSpeak())
return;

uint64 MuteTime = receiver->GetSession()->m_muteTime;
uint64 MuteTime = sMute->GetMuteTime(receiver->GetSession()->GetAccountId());
if (!MuteTime)
return;

Expand Down
18 changes: 11 additions & 7 deletions src/server/database/Database/Implementation/LoginDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void LoginDatabaseConnection::DoPrepareStatements()
PrepareStatement(LOGIN_SEL_FAILEDLOGINS, "SELECT id, failed_logins FROM account WHERE username = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_ID_BY_NAME, "SELECT id FROM account WHERE username = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_LIST_BY_NAME, "SELECT id, username FROM account WHERE username = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_INFO_BY_NAME, "SELECT id, sessionkey, last_ip, locked, lock_country, expansion, mutetime, locale, recruiter, os, totaltime FROM account WHERE username = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_INFO_BY_NAME, "SELECT id, sessionkey, last_ip, locked, lock_country, expansion, locale, recruiter, os, totaltime FROM account WHERE username = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_LIST_BY_EMAIL, "SELECT id, username FROM account WHERE email = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_NUM_CHARS_ON_REALM, "SELECT numchars FROM realmcharacters WHERE realmid = ? AND acctid= ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_BY_IP, "SELECT id, username FROM account WHERE last_ip = ?", CONNECTION_SYNCH);
Expand All @@ -63,8 +63,6 @@ void LoginDatabaseConnection::DoPrepareStatements()
PrepareStatement(LOGIN_UPD_ACCOUNT_LOCK_CONTRY, "UPDATE account SET lock_country = ? WHERE id = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_UPD_USERNAME, "UPDATE account SET v = 0, s = 0, username = ?, sha_pass_hash = ? WHERE id = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_UPD_PASSWORD, "UPDATE account SET v = 0, s = 0, sha_pass_hash = ? WHERE id = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_UPD_MUTE_TIME, "UPDATE account SET mutetime = ? , mutereason = ? , muteby = ? WHERE id = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_UPD_MUTE_TIME_LOGIN, "UPDATE account SET mutetime = ? WHERE id = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_UPD_LAST_IP, "UPDATE account SET last_ip = ? WHERE username = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_UPD_LAST_ATTEMPT_IP, "UPDATE account SET last_attempt_ip = ? WHERE username = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_UPD_ACCOUNT_ONLINE, "UPDATE account SET online = ? WHERE id = ?", CONNECTION_ASYNC);
Expand All @@ -79,7 +77,7 @@ void LoginDatabaseConnection::DoPrepareStatements()
PrepareStatement(LOGIN_GET_USERNAME_BY_ID, "SELECT username FROM account WHERE id = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_CHECK_PASSWORD, "SELECT 1 FROM account WHERE id = ? AND sha_pass_hash = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_CHECK_PASSWORD_BY_NAME, "SELECT 1 FROM account WHERE username = ? AND sha_pass_hash = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_PINFO, "SELECT a.username, aa.gmlevel, a.email, a.reg_mail, a.last_ip, DATE_FORMAT(a.last_login, '%Y-%m-%d %T'), a.mutetime, a.mutereason, a.muteby, a.failed_logins, a.locked, a.OS FROM account a LEFT JOIN account_access aa ON (a.id = aa.id AND (aa.RealmID = ? OR aa.RealmID = -1)) WHERE a.id = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_PINFO, "SELECT a.username, aa.gmlevel, a.email, a.reg_mail, a.last_ip, DATE_FORMAT(a.last_login, '%Y-%m-%d %T'), a.failed_logins, a.locked, a.OS FROM account a LEFT JOIN account_access aa ON (a.id = aa.id AND (aa.RealmID = ? OR aa.RealmID = -1)) WHERE a.id = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_PINFO_BANS, "SELECT unbandate, bandate = unbandate, bannedby, banreason FROM account_banned WHERE id = ? AND active ORDER BY bandate ASC LIMIT 1", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_GM_ACCOUNTS, "SELECT a.username, aa.gmlevel FROM account a, account_access aa WHERE a.id=aa.id AND aa.gmlevel >= ? AND (aa.realmid = -1 OR aa.realmid = ?)", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_INFO, "SELECT a.username, a.last_ip, aa.gmlevel, a.expansion FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE a.id = ? ORDER BY a.last_ip", CONNECTION_SYNCH); // Only used in ".account onlinelist" command
Expand All @@ -94,9 +92,15 @@ 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);
PrepareStatement(LOGIN_DEL_ACCOUNT_MUTEDEL, "DELETE FROM account_muted WHERE guid = ?", CONNECTION_ASYNC);

// Mute system
PrepareStatement(LOGIN_INS_ACCOUNT_MUTE, "INSERT INTO `account_muted` (`accountid`, `mutedate`, `mutetime`, `mutedby`, `mutereason`, `active`) VALUES (?, ?, ?, ?, ?, 1)", CONNECTION_ASYNC);
PrepareStatement(LOGIN_UPD_ACCOUNT_MUTE, "UPDATE `account_muted` SET `mutedate` = ?, `mutetime` = ? WHERE `accountid` = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_SEL_ACCOUNT_MUTE_INFO, "SELECT `mutedate`, `mutetime`, `mutereason`, `mutedby` FROM `account_muted` WHERE `accountid` = ? ORDER BY `mutedate` ASC", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_MUTE, "SELECT `mutedate`, `mutetime` FROM `account_muted` WHERE `accountid` = ? AND `active` = 1 AND UNIX_TIMESTAMP() <= `mutedate` + ABS(`mutetime`) ORDER BY `mutedate` + ABS(`mutetime`) DESC LIMIT 1", CONNECTION_SYNCH);
PrepareStatement(LOGIN_UPD_ACCOUNT_MUTE_EXPIRED, "UPDATE `account_muted` SET `active` = 0 WHERE `active` = 1 AND `mutetime` > 0 AND `accountid` = ? AND UNIX_TIMESTAMP() >= `mutedate` + `mutetime`", CONNECTION_ASYNC);
PrepareStatement(LOGIN_DEL_ACCOUNT_MUTE, "UPDATE `account_muted` SET `active` = 0 WHERE `active` = 1 AND `accountid` = ?", CONNECTION_ASYNC);

// 0: uint32, 1: uint32, 2: uint8, 3: uint32, 4: string // Complete name: "Login_Insert_AccountLoginDeLete_IP_Logging"
PrepareStatement(LOGIN_INS_ALDL_IP_LOGGING, "INSERT INTO logs_ip_actions (account_id,character_guid,type,ip,systemnote,unixtime,time) VALUES (?, ?, ?, (SELECT last_ip FROM account WHERE id = ?), ?, unix_timestamp(NOW()), NOW())", CONNECTION_ASYNC);
// 0: uint32, 1: uint32, 2: uint8, 3: uint32, 4: string // Complete name: "Login_Insert_FailedAccountLogin_IP_Logging"
Expand Down
8 changes: 4 additions & 4 deletions src/server/database/Database/Implementation/LoginDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ enum LoginDatabaseStatements
LOGIN_UPD_ACCOUNT_LOCK_CONTRY,
LOGIN_UPD_USERNAME,
LOGIN_UPD_PASSWORD,
LOGIN_UPD_MUTE_TIME,
LOGIN_UPD_MUTE_TIME_LOGIN,
LOGIN_UPD_LAST_IP,
LOGIN_UPD_LAST_ATTEMPT_IP,
LOGIN_UPD_ACCOUNT_ONLINE,
Expand Down Expand Up @@ -118,10 +116,12 @@ enum LoginDatabaseStatements
LOGIN_INS_FACL_IP_LOGGING,
LOGIN_INS_CHAR_IP_LOGGING,
LOGIN_INS_FALP_IP_LOGGING,

LOGIN_INS_ACCOUNT_MUTE,
LOGIN_UPD_ACCOUNT_MUTE,
LOGIN_SEL_ACCOUNT_MUTE_INFO,
LOGIN_DEL_ACCOUNT_MUTEDEL,
LOGIN_SEL_ACCOUNT_MUTE,
LOGIN_UPD_ACCOUNT_MUTE_EXPIRED,
LOGIN_DEL_ACCOUNT_MUTE,

MAX_LOGINDATABASE_STATEMENTS
};
Expand Down
3 changes: 1 addition & 2 deletions src/server/game/Accounts/AccountMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ namespace AccountMgr
stmt->setUInt32(0, accountId);
trans->Append(stmt);

stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_MUTEDEL);
stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_MUTE_EXPIRED);
stmt->setUInt32(0, accountId);
trans->Append(stmt);

Expand All @@ -132,7 +132,6 @@ namespace AccountMgr
return AOR_OK;
}


AccountOpResult ChangeUsername(uint32 accountId, std::string newUsername, std::string newPassword)
{
// Check if accounts exists
Expand Down
1 change: 1 addition & 0 deletions src/server/game/Config/GameConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ void GameConfig::LoadBoolConfigs(bool reload /*= false*/)
// AddBoolConfig("ShowKickInWorld"); //not used
AddBoolConfig("ShowBanInWorld");
AddBoolConfig("ShowMuteInWorld");
AddBoolConfig("Mute.AddAfterLogin.Enable");

AddBoolConfig("Warden.Enabled");
AddBoolConfig("AutoBroadcast.On");
Expand Down
20 changes: 6 additions & 14 deletions src/server/game/Entities/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
#include "GameGraveyard.h"
#include "GameTime.h"
#include "GameLocale.h"
#include "MuteManager.h"

#define ZONE_UPDATE_INTERVAL (2*IN_MILLISECONDS)

Expand Down Expand Up @@ -1614,16 +1615,7 @@ void Player::Update(uint32 p_time)
}

// If mute expired, remove it from the DB
if (GetSession()->m_muteTime && GetSession()->m_muteTime < now)
{
GetSession()->m_muteTime = 0;
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_MUTE_TIME);
stmt->setInt64(0, 0); // Set the mute time to 0
stmt->setString(1, "");
stmt->setString(2, "");
stmt->setUInt32(3, GetSession()->GetAccountId());
LoginDatabase.Execute(stmt);
}
sMute->CheckMuteExpired(GetSession()->GetAccountId());

if (!m_timedquests.empty())
{
Expand Down Expand Up @@ -20396,7 +20388,7 @@ void Player::UpdateSpeakTime(uint32 specialMessageLimit)
if (!AccountMgr::IsPlayerAccount(GetSession()->GetSecurity()))
return;

time_t current = time (NULL);
time_t current = GameTime::GetGameTime();
if (m_speakTime > current)
{
uint32 max_count = specialMessageLimit ? specialMessageLimit : sGameConfig->GetIntConfig("ChatFlood.MessageCount");
Expand All @@ -20408,8 +20400,8 @@ void Player::UpdateSpeakTime(uint32 specialMessageLimit)
{
// prevent overwrite mute time, if message send just before mutes set, for example.
time_t new_mute = current + sGameConfig->GetIntConfig("ChatFlood.MuteTime");
if (GetSession()->m_muteTime < new_mute)
GetSession()->m_muteTime = new_mute;
if (sMute->GetMuteTime(GetSession()->GetAccountId()) < new_mute)
sMute->SetMuteTime(GetSession()->GetAccountId(), new_mute);

m_speakCount = 0;
}
Expand All @@ -20422,7 +20414,7 @@ void Player::UpdateSpeakTime(uint32 specialMessageLimit)

bool Player::CanSpeak() const
{
return GetSession()->m_muteTime <= time (NULL);
return sMute->CanSpeak(GetSession()->GetAccountId());
}

/*********************************************************/
Expand Down
11 changes: 5 additions & 6 deletions src/server/game/Handlers/ChatHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "AccountMgr.h"
#include "GameTime.h"
#include "GameConfig.h"
#include "MuteManager.h"

void WorldSession::HandleMessagechatOpcode(WorldPacket & recvData)
{
Expand Down Expand Up @@ -270,10 +271,9 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket & recvData)
if (ChatHandler(this).ParseCommands(msg.c_str()))
return;

if (!_player->CanSpeak())
if (!sMute->CanSpeak(GetAccountId()))
{
std::string timeStr = secsToTimeString(m_muteTime - GameTime::GetGameTime());
SendNotification(GetAcoreString(LANG_WAIT_BEFORE_SPEAKING), timeStr.c_str());
SendNotification(GetAcoreString(LANG_WAIT_BEFORE_SPEAKING), sMute->GetMuteTimeString(GetAccountId()).c_str());
return;
}

Expand Down Expand Up @@ -647,10 +647,9 @@ void WorldSession::HandleTextEmoteOpcode(WorldPacket & recvData)

GetPlayer()->UpdateSpeakTime();

if (!GetPlayer()->CanSpeak())
if (!sMute->CanSpeak(GetAccountId()))
{
std::string timeStr = secsToTimeString(m_muteTime - GameTime::GetGameTime());
SendNotification(GetAcoreString(LANG_WAIT_BEFORE_SPEAKING), timeStr.c_str());
SendNotification(GetAcoreString(LANG_WAIT_BEFORE_SPEAKING), sMute->GetMuteTimeString(GetAccountId()).c_str());
return;
}

Expand Down
Loading

0 comments on commit 097df4e

Please sign in to comment.