diff options
| author | KingPin <none@none> | 2008-10-26 13:32:42 -0500 |
|---|---|---|
| committer | KingPin <none@none> | 2008-10-26 13:32:42 -0500 |
| commit | a0f843a3ebe505dabe138294dd7c6dbc0dcfe094 (patch) | |
| tree | e6d8c282355f1affbe5bce524a7d3df23e7e4661 /src/game/World.cpp | |
| parent | 6f2e0ee48a24dff1ac7acf441b1559e9d7c26657 (diff) | |
[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
Diffstat (limited to 'src/game/World.cpp')
| -rw-r--r-- | src/game/World.cpp | 98 |
1 files changed, 46 insertions, 52 deletions
diff --git a/src/game/World.cpp b/src/game/World.cpp index 8bdea8996ec..de89643257f 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -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") - { - //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()); + 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; } - 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() |
