#
# ShowKickInWorld
# Description: Determines whether a message is broadcasted to the entire server when a
# player gets kicked.
# Default: 0 - (Disabled)
# 1 - (Enabled)
ShowKickInWorld = 0
# ShowMuteInWorld
# Description: Determines whether a message is broadcasted to the entire server when a
# player gets muted.
# Default: 0 - (Disabled)
# 1 - (Enabled)
ShowMuteInWorld = 0
#
# ShowBanInWorld
# Description: Determines whether a message is broadcasted to the entire server when a
# player gets banned.
# Default: 0 - (Disabled)
# 1 - (Enabled)
ShowBanInWorld = 0
[COLOR="#808080"]
/// Kick a player out of the World
void WorldSession::KickPlayer()
{
if (m_Socket)
m_Socket->CloseSocket();
}[/COLOR]
[COLOR="#808080"]
/// Ban an account or ban an IP address, duration_secs if it is positive used, otherwise permban
BanReturn World::BanAccount(BanMode mode, std::string nameOrIP, uint32 duration_secs, std::string reason, const std::string& author)
{
LoginDatabase.escape_string(nameOrIP);
LoginDatabase.escape_string(reason);
std::string safe_author = author;
LoginDatabase.escape_string(safe_author);
QueryResult* resultAccounts = nullptr; // used for kicking
///- Update the database with ban information
switch (mode)
{
case BAN_IP:
// No SQL injection as strings are escaped
resultAccounts = LoginDatabase.PQuery("SELECT id FROM account WHERE last_ip = '%s'", nameOrIP.c_str());
LoginDatabase.PExecute("INSERT INTO ip_banned VALUES ('%s',UNIX_TIMESTAMP(),UNIX_TIMESTAMP()+%u,'%s','%s')", nameOrIP.c_str(), duration_secs, safe_author.c_str(), reason.c_str());
break;
case BAN_ACCOUNT:
// No SQL injection as string is escaped
resultAccounts = LoginDatabase.PQuery("SELECT id FROM account WHERE username = '%s'", nameOrIP.c_str());
break;
case BAN_CHARACTER:
// No SQL injection as string is escaped
resultAccounts = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name = '%s'", nameOrIP.c_str());
break;
default:
return BAN_SYNTAX_ERROR;
}
if (!resultAccounts)
{
if (mode == BAN_IP)
return BAN_SUCCESS; // ip correctly banned but nobody affected (yet)
else
return BAN_NOTFOUND; // Nobody to ban
}
///- Disconnect all affected players (for IP it can be several)
do
{
Field* fieldsAccount = resultAccounts->Fetch();
uint32 account = fieldsAccount->GetUInt32();
if (mode != BAN_IP)
{
// No SQL injection as strings are escaped
LoginDatabase.PExecute("INSERT INTO account_banned VALUES ('%u', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()+%u, '%s', '%s', '1')",
account, duration_secs, safe_author.c_str(), reason.c_str());
}
if (WorldSession* sess = FindSession(account))
if (std::string(sess->GetPlayerName()) != author)
sess->KickPlayer();
}
while (resultAccounts->NextRow());
delete resultAccounts;
return BAN_SUCCESS;
} [/COLOR]
[COLOR="#808080"]
/// Sends a server message to the specified or all players
void World::SendServerMessage(ServerMessageType type, const char* text /*=""*/, Player* player /*= nullptr*/)
[/COLOR]
[COLOR="#808080"]
/// Ban an account or ban an IP address, duration_secs if it is positive used, otherwise permban
BanReturn World::BanAccount(BanMode mode, std::string nameOrIP, uint32 duration_secs, std::string reason, const std::string& author)
{
LoginDatabase.escape_string(nameOrIP);
LoginDatabase.escape_string(reason);
std::string safe_author = author;
LoginDatabase.escape_string(safe_author);
QueryResult* resultAccounts = nullptr; // used for kicking
///- Update the database with ban information
switch (mode)
{
case BAN_IP:
// No SQL injection as strings are escaped
resultAccounts = LoginDatabase.PQuery("SELECT id FROM account WHERE last_ip = '%s'", nameOrIP.c_str());
LoginDatabase.PExecute("INSERT INTO ip_banned VALUES ('%s',UNIX_TIMESTAMP(),UNIX_TIMESTAMP()+%u,'%s','%s')", nameOrIP.c_str(), duration_secs, safe_author.c_str(), reason.c_str());
[COLOR="#FF0000"]World::SendServerMessage(1, "IP:" + nameOrIP + " was banned by " + author + " due to: " + reason, nullptr);[/COLOR]
break;
case BAN_ACCOUNT:
// No SQL injection as string is escaped
resultAccounts = LoginDatabase.PQuery("SELECT id FROM account WHERE username = '%s'", nameOrIP.c_str());
[COLOR="#FF0000"]World::SendServerMessage(1, "ACCT:" + nameOrIP + " was banned by " + author + " due to: " + reason, nullptr);[/COLOR]
break;
case BAN_CHARACTER:
// No SQL injection as string is escaped
resultAccounts = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name = '%s'", nameOrIP.c_str());
[COLOR="#FF0000"]World::SendServerMessage(1, nameOrIP + " was banned by " + author + " due to: " + reason, nullptr);[/COLOR]
break;
default:
return BAN_SYNTAX_ERROR;
}
if (!resultAccounts)
{
if (mode == BAN_IP)
return BAN_SUCCESS; // ip correctly banned but nobody affected (yet)
else
return BAN_NOTFOUND; // Nobody to ban
}
///- Disconnect all affected players (for IP it can be several)
do
{
Field* fieldsAccount = resultAccounts->Fetch();
uint32 account = fieldsAccount->GetUInt32();
if (mode != BAN_IP)
{
// No SQL injection as strings are escaped
LoginDatabase.PExecute("INSERT INTO account_banned VALUES ('%u', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()+%u, '%s', '%s', '1')",
account, duration_secs, safe_author.c_str(), reason.c_str());
}
if (WorldSession* sess = FindSession(account))
if (std::string(sess->GetPlayerName()) != author)
sess->KickPlayer();
} while (resultAccounts->NextRow());
delete resultAccounts;
return BAN_SUCCESS;
}[/COLOR]