[svn] * Merge CLI Commands with regular commands and give them level4 access. sec_console. Source mangos - thanks to ogeraisi for the amalgamated patch.

* Redid/Fixed/Added some lang strings.
* As usual remember this is a trunk rev so stability only guaranteed on northern countries of Mars and western parts of Pluto. No warranties outside the solar system, sorry :( . Check with your local government or dictator on regulations regarding export.

--HG--
branch : trunk
This commit is contained in:
KingPin
2008-10-26 13:32:42 -05:00
parent 6f2e0ee48a
commit a0f843a3eb
22 changed files with 2303 additions and 2126 deletions

View File

@@ -2264,45 +2264,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")
return BAN_SUCCESS; // ip correctly banned but nobody affected (yet)
else
return BAN_NOTFOUND; // Nobody to ban
if(!resultAccounts)
{
if(mode==BAN_IP)
return BAN_SUCCESS;
else
return BAN_NOTFOUND; // Nobody to ban
}
///- Disconnect all affected players (for IP it can be several)
do
@@ -2310,13 +2308,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();
}
@@ -2327,9 +2326,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());
@@ -2337,20 +2336,11 @@ 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;
@@ -2503,20 +2493,24 @@ void World::UpdateSessions( time_t diff )
// This handles the issued and queued CLI commands
void World::ProcessCliCommands()
{
if (cliCmdQueue.empty()) return;
if (cliCmdQueue.empty())
return;
CliCommandHolder *command;
pPrintf p_zprintf;
CliCommandHolder::Print* zprint;
while (!cliCmdQueue.empty())
{
sLog.outDebug("CLI command under processing...");
command = cliCmdQueue.next();
command->Execute();
p_zprintf=command->GetOutputMethod();
CliCommandHolder *command = cliCmdQueue.next();
zprint = command->m_print;
CliHandler(zprint).ParseCommands(command->m_command);
delete command;
}
// print the console message here so it looks right
p_zprintf("TC> ");
zprint("TC> ");
}
void World::InitResultQueue()