Show
Ignore:
Timestamp:
11/19/08 13:37:14 (17 years ago)
Author:
yumileroy
Message:

[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.

Original author: KingPin?
Date: 2008-10-26 13:32:42-05:00

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/game/World.cpp

    r111 r112  
    22652265 
    22662266/// 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) 
     2267BanReturn World::BanAccount(BanMode mode, std::string nameOrIP, std::string duration, std::string reason, std::string author) 
    22682268{ 
    22692269    loginDatabase.escape_string(nameOrIP); 
     
    22722272    loginDatabase.escape_string(safe_author); 
    22732273 
    2274     if(type != "ip" && !normalizePlayerName(nameOrIP)) 
    2275         return BAN_NOTFOUND;                                // Nobody to ban 
    2276  
    22772274    uint32 duration_secs = TimeStringToSecs(duration); 
    22782275    QueryResult *resultAccounts = NULL;                     //used for kicking 
    22792276 
    22802277    ///- 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        } 
    23062304 
    23072305    ///- Disconnect all affected players (for IP it can be several) 
     
    23112309        uint32 account = fieldsAccount->GetUInt32(); 
    23122310 
    2313         if(type != "ip") 
     2311        if(mode!=BAN_IP) 
     2312                { 
    23142313            //No SQL injection as strings are escaped 
    23152314            loginDatabase.PExecute("INSERT INTO account_banned VALUES ('%u', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()+%u, '%s', '%s', '1')", 
    23162315                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)) 
    23202319            if(std::string(sess->GetPlayerName()) != author) 
    23212320                sess->KickPlayer(); 
     
    23282327 
    23292328/// Remove a ban from an account or IP address 
    2330 bool World::RemoveBanAccount(std::string type, std::string nameOrIP) 
    2331 { 
    2332     if(type == "ip") 
     2329bool World::RemoveBanAccount(BanMode mode, std::string nameOrIP) 
     2330{ 
     2331    if (mode == BAN_IP) 
    23332332    { 
    23342333        loginDatabase.escape_string(nameOrIP); 
     
    23382337    { 
    23392338        uint32 account=0; 
    2340         if(type == "account") 
    2341         { 
    2342             if (!AccountMgr::normilizeString (nameOrIP)) 
    2343                 return false; 
    2344              
     2339        if (mode == BAN_ACCOUNT) 
    23452340            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) 
    23522342            account = objmgr.GetPlayerAccountIdByPlayerName (nameOrIP); 
    2353         } 
     2343 
    23542344        if(!account) 
    23552345            return false; 
     
    25042494void World::ProcessCliCommands() 
    25052495{ 
    2506     if (cliCmdQueue.empty()) return; 
    2507  
    2508     CliCommandHolder *command; 
    2509     pPrintf p_zprintf; 
     2496    if (cliCmdQueue.empty()) 
     2497                return; 
     2498 
     2499    CliCommandHolder::Print* zprint; 
    25102500    while (!cliCmdQueue.empty()) 
    25112501    { 
    25122502        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 
    25162509        delete command; 
    25172510    } 
     2511 
    25182512    // print the console message here so it looks right 
    2519     p_zprintf("TC> "); 
     2513    zprint("TC> "); 
    25202514} 
    25212515