Changeset 112 for trunk/src/game/World.cpp
- Timestamp:
- 11/19/08 13:37:14 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/game/World.cpp
r111 r112 2265 2265 2266 2266 /// Ban an account or ban an IP address, duration will be parsed using TimeStringToSecs if it is positive, otherwise permban 2267 uint8 World::BanAccount(std::string type, std::string nameOrIP, std::string duration, std::string reason, std::string author)2267 BanReturn World::BanAccount(BanMode mode, std::string nameOrIP, std::string duration, std::string reason, std::string author) 2268 2268 { 2269 2269 loginDatabase.escape_string(nameOrIP); … … 2272 2272 loginDatabase.escape_string(safe_author); 2273 2273 2274 if(type != "ip" && !normalizePlayerName(nameOrIP))2275 return BAN_NOTFOUND; // Nobody to ban2276 2277 2274 uint32 duration_secs = TimeStringToSecs(duration); 2278 2275 QueryResult *resultAccounts = NULL; //used for kicking 2279 2276 2280 2277 ///- Update the database with ban information 2281 2282 if(type=="ip") 2283 { 2284 //No SQL injection as strings are escaped 2285 resultAccounts = loginDatabase.PQuery("SELECT id FROM account WHERE last_ip = '%s'",nameOrIP.c_str()); 2286 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()); 2287 } 2288 else if(type=="account") 2289 { 2290 //No SQL injection as string is escaped 2291 resultAccounts = loginDatabase.PQuery("SELECT id FROM account WHERE username = '%s'",nameOrIP.c_str()); 2292 } 2293 else if(type=="character") 2294 { 2295 //No SQL injection as string is escaped 2296 resultAccounts = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name = '%s'",nameOrIP.c_str()); 2297 } 2298 else 2299 return BAN_SYNTAX_ERROR; //Syntax problem 2300 2301 if(!resultAccounts) 2302 if(type=="ip") 2303 return BAN_SUCCESS; // ip correctly banned but nobody affected (yet) 2304 else 2305 return BAN_NOTFOUND; // Nobody to ban 2278 switch(mode) 2279 { 2280 case BAN_IP: 2281 //No SQL injection as strings are escaped 2282 resultAccounts = loginDatabase.PQuery("SELECT id FROM account WHERE last_ip = '%s'",nameOrIP.c_str()); 2283 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()); 2284 break; 2285 case BAN_ACCOUNT: 2286 //No SQL injection as string is escaped 2287 resultAccounts = loginDatabase.PQuery("SELECT id FROM account WHERE username = '%s'",nameOrIP.c_str()); 2288 break; 2289 case BAN_CHARACTER: 2290 //No SQL injection as string is escaped 2291 resultAccounts = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name = '%s'",nameOrIP.c_str()); 2292 break; 2293 default: 2294 return BAN_SYNTAX_ERROR; 2295 } 2296 2297 if(!resultAccounts) 2298 { 2299 if(mode==BAN_IP) 2300 return BAN_SUCCESS; 2301 else 2302 return BAN_NOTFOUND; // Nobody to ban 2303 } 2306 2304 2307 2305 ///- Disconnect all affected players (for IP it can be several) … … 2311 2309 uint32 account = fieldsAccount->GetUInt32(); 2312 2310 2313 if(type != "ip") 2311 if(mode!=BAN_IP) 2312 { 2314 2313 //No SQL injection as strings are escaped 2315 2314 loginDatabase.PExecute("INSERT INTO account_banned VALUES ('%u', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()+%u, '%s', '%s', '1')", 2316 2315 account,duration_secs,safe_author.c_str(),reason.c_str()); 2317 2318 WorldSession* sess = FindSession(account); 2319 if ( sess)2316 } 2317 2318 if (WorldSession* sess = FindSession(account)) 2320 2319 if(std::string(sess->GetPlayerName()) != author) 2321 2320 sess->KickPlayer(); … … 2328 2327 2329 2328 /// Remove a ban from an account or IP address 2330 bool World::RemoveBanAccount( std::string type, std::string nameOrIP)2331 { 2332 if (type == "ip")2329 bool World::RemoveBanAccount(BanMode mode, std::string nameOrIP) 2330 { 2331 if (mode == BAN_IP) 2333 2332 { 2334 2333 loginDatabase.escape_string(nameOrIP); … … 2338 2337 { 2339 2338 uint32 account=0; 2340 if(type == "account") 2341 { 2342 if (!AccountMgr::normilizeString (nameOrIP)) 2343 return false; 2344 2339 if (mode == BAN_ACCOUNT) 2345 2340 account = accmgr.GetId (nameOrIP); 2346 } 2347 else if(type == "character") 2348 { 2349 if(!normalizePlayerName(nameOrIP)) 2350 return false; 2351 2341 else if (mode == BAN_CHARACTER) 2352 2342 account = objmgr.GetPlayerAccountIdByPlayerName (nameOrIP); 2353 } 2343 2354 2344 if(!account) 2355 2345 return false; … … 2504 2494 void World::ProcessCliCommands() 2505 2495 { 2506 if (cliCmdQueue.empty()) return;2507 2508 CliCommandHolder *command; 2509 pPrintf p_zprintf;2496 if (cliCmdQueue.empty()) 2497 return; 2498 2499 CliCommandHolder::Print* zprint; 2510 2500 while (!cliCmdQueue.empty()) 2511 2501 { 2512 2502 sLog.outDebug("CLI command under processing..."); 2513 command = cliCmdQueue.next(); 2514 command->Execute(); 2515 p_zprintf=command->GetOutputMethod(); 2503 CliCommandHolder *command = cliCmdQueue.next(); 2504 2505 zprint = command->m_print; 2506 2507 CliHandler(zprint).ParseCommands(command->m_command); 2508 2516 2509 delete command; 2517 2510 } 2511 2518 2512 // print the console message here so it looks right 2519 p_zprintf("TC> ");2513 zprint("TC> "); 2520 2514 } 2521 2515