mirror of
https://github.com/mangosfour/server.git
synced 2025-12-15 01:37:00 +00:00
[sql/updates/2008_10_21_03_mangos_command.sql]
slit ban/baninfi/banlist/unban commands to subcommands (this allow write not full subcomand string ".ban acc ...". Fixed crash at unexpected use .account in console. Fixed hide .gm on by .gm online (renamed to .gm ingame)
This commit is contained in:
parent
88981a4c25
commit
6892cc3d2c
10 changed files with 523 additions and 309 deletions
|
|
@ -2205,45 +2205,43 @@ bool World::KickPlayer(std::string playerName)
|
|||
}
|
||||
|
||||
/// Ban an account or ban an IP address, duration will be parsed using TimeStringToSecs if it is positive, otherwise permban
|
||||
uint8 World::BanAccount(std::string type, std::string nameOrIP, std::string duration, std::string reason, std::string author)
|
||||
BanReturn World::BanAccount(BanMode mode, std::string nameOrIP, std::string duration, std::string reason, std::string author)
|
||||
{
|
||||
loginDatabase.escape_string(nameOrIP);
|
||||
loginDatabase.escape_string(reason);
|
||||
std::string safe_author=author;
|
||||
loginDatabase.escape_string(safe_author);
|
||||
|
||||
if(type != "ip" && !normalizePlayerName(nameOrIP))
|
||||
return BAN_NOTFOUND; // Nobody to ban
|
||||
|
||||
uint32 duration_secs = TimeStringToSecs(duration);
|
||||
QueryResult *resultAccounts = NULL; //used for kicking
|
||||
|
||||
///- Update the database with ban information
|
||||
|
||||
if(type=="ip")
|
||||
switch(mode)
|
||||
{
|
||||
//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());
|
||||
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;
|
||||
}
|
||||
else if(type=="account")
|
||||
{
|
||||
//No SQL injection as string is escaped
|
||||
resultAccounts = loginDatabase.PQuery("SELECT id FROM account WHERE username = '%s'",nameOrIP.c_str());
|
||||
}
|
||||
else if(type=="character")
|
||||
{
|
||||
//No SQL injection as string is escaped
|
||||
resultAccounts = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name = '%s'",nameOrIP.c_str());
|
||||
}
|
||||
else
|
||||
return BAN_SYNTAX_ERROR; //Syntax problem
|
||||
|
||||
if(!resultAccounts)
|
||||
if(type=="ip")
|
||||
{
|
||||
if(mode==BAN_IP)
|
||||
return BAN_SUCCESS; // ip correctly banned but nobody affected (yet)
|
||||
else
|
||||
return BAN_NOTFOUND; // Nobody to ban
|
||||
else
|
||||
return BAN_NOTFOUND; // Nobody to ban
|
||||
}
|
||||
|
||||
///- Disconnect all affected players (for IP it can be several)
|
||||
do
|
||||
|
|
@ -2251,13 +2249,14 @@ uint8 World::BanAccount(std::string type, std::string nameOrIP, std::string dura
|
|||
Field* fieldsAccount = resultAccounts->Fetch();
|
||||
uint32 account = fieldsAccount->GetUInt32();
|
||||
|
||||
if(type != "ip")
|
||||
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());
|
||||
}
|
||||
|
||||
WorldSession* sess = FindSession(account);
|
||||
if( sess )
|
||||
if (WorldSession* sess = FindSession(account))
|
||||
if(std::string(sess->GetPlayerName()) != author)
|
||||
sess->KickPlayer();
|
||||
}
|
||||
|
|
@ -2268,9 +2267,9 @@ uint8 World::BanAccount(std::string type, std::string nameOrIP, std::string dura
|
|||
}
|
||||
|
||||
/// Remove a ban from an account or IP address
|
||||
bool World::RemoveBanAccount(std::string type, std::string nameOrIP)
|
||||
bool World::RemoveBanAccount(BanMode mode, std::string nameOrIP)
|
||||
{
|
||||
if(type == "ip")
|
||||
if (mode == BAN_IP)
|
||||
{
|
||||
loginDatabase.escape_string(nameOrIP);
|
||||
loginDatabase.PExecute("DELETE FROM ip_banned WHERE ip = '%s'",nameOrIP.c_str());
|
||||
|
|
@ -2278,20 +2277,10 @@ bool World::RemoveBanAccount(std::string type, std::string nameOrIP)
|
|||
else
|
||||
{
|
||||
uint32 account = 0;
|
||||
if (type == "account")
|
||||
{
|
||||
if (!AccountMgr::normilizeString (nameOrIP))
|
||||
return false;
|
||||
|
||||
if (mode == BAN_ACCOUNT)
|
||||
account = accmgr.GetId (nameOrIP);
|
||||
}
|
||||
else if (type == "character")
|
||||
{
|
||||
if (!normalizePlayerName (nameOrIP))
|
||||
return false;
|
||||
|
||||
else if (mode == BAN_CHARACTER)
|
||||
account = objmgr.GetPlayerAccountIdByPlayerName (nameOrIP);
|
||||
}
|
||||
|
||||
if (!account)
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue