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

[svn] Merge from Mangos:
3c7ac5bd3e20c33a22ac57c5c3bac23a0798dc9e 2008-10-23 19:06:27
Some endianess related fixes and cleanups. By VladimirMangos?.

Original author: megamage
Date: 2008-11-06 16:10:28-06:00

Files:
1 modified

Legend:

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

    r168 r181  
    129129 
    130130    if(m_resultQueue) delete m_resultQueue; 
    131      
     131 
    132132    //TODO free addSessQueue 
    133133} 
     
    183183void World::AddSession(WorldSession* s) 
    184184{ 
    185   addSessQueue.add(s); 
     185    addSessQueue.add(s); 
    186186} 
    187187 
     
    189189World::AddSession_ (WorldSession* s) 
    190190{ 
    191   ASSERT (s); 
    192  
    193   //NOTE - Still there is race condition in WorldSession* being used in the Sockets 
    194  
    195   ///- kick already loaded player with same account (if any) and remove session 
    196   ///- if player is in loading and want to load again, return 
    197   if (!RemoveSession (s->GetAccountId ())) 
    198     { 
    199       s->KickPlayer (); 
    200       m_kicked_sessions.insert (s); 
    201       return; 
    202     } 
    203  
    204   WorldSession* old = m_sessions[s->GetAccountId ()]; 
    205   m_sessions[s->GetAccountId ()] = s; 
    206  
    207   // if session already exist, prepare to it deleting at next world update 
    208   // NOTE - KickPlayer() should be called on "old" in RemoveSession() 
    209   if (old) 
    210     m_kicked_sessions.insert (old); 
    211  
    212   uint32 Sessions = GetActiveAndQueuedSessionCount (); 
    213   uint32 pLimit = GetPlayerAmountLimit (); 
    214   uint32 QueueSize = GetQueueSize (); //number of players in the queue 
    215   bool inQueue = false; 
    216   //so we don't count the user trying to  
    217   //login as a session and queue the socket that we are using 
    218   --Sessions; 
    219  
    220   if (pLimit > 0 && Sessions >= pLimit && s->GetSecurity () == SEC_PLAYER ) 
    221     { 
    222       AddQueuedPlayer (s); 
    223       UpdateMaxSessionCounters (); 
    224       sLog.outDetail ("PlayerQueue: Account id %u is in Queue Position (%u).", s->GetAccountId (), ++QueueSize); 
    225       return; 
    226     } 
    227    
    228   WorldPacket packet(SMSG_AUTH_RESPONSE, 1 + 4 + 1 + 4 + 1); 
    229   packet << uint8 (AUTH_OK); 
    230   packet << uint32 (0); // unknown random value... 
    231   packet << uint8 (0); 
    232   packet << uint32 (0); 
    233   packet << uint8 (s->Expansion () ? 1 : 0); // 0 - normal, 1 - TBC, must be set in database manually for each account 
    234   s->SendPacket (&packet); 
    235  
    236   UpdateMaxSessionCounters (); 
    237  
    238   // Updates the population 
    239   if (pLimit > 0) 
    240     { 
    241       float popu = GetActiveSessionCount (); //updated number of users on the server 
    242       popu /= pLimit; 
    243       popu *= 2; 
    244       loginDatabase.PExecute ("UPDATE realmlist SET population = '%f' WHERE id = '%d'", popu, realmID); 
    245       sLog.outDetail ("Server Population (%f).", popu); 
     191    ASSERT (s); 
     192 
     193    //NOTE - Still there is race condition in WorldSession* being used in the Sockets 
     194 
     195    ///- kick already loaded player with same account (if any) and remove session 
     196    ///- if player is in loading and want to load again, return 
     197    if (!RemoveSession (s->GetAccountId ())) 
     198    { 
     199        s->KickPlayer (); 
     200        m_kicked_sessions.insert (s); 
     201        return; 
     202    } 
     203 
     204    WorldSession* old = m_sessions[s->GetAccountId ()]; 
     205    m_sessions[s->GetAccountId ()] = s; 
     206 
     207    // if session already exist, prepare to it deleting at next world update 
     208    // NOTE - KickPlayer() should be called on "old" in RemoveSession() 
     209    if (old) 
     210        m_kicked_sessions.insert (old); 
     211 
     212    uint32 Sessions = GetActiveAndQueuedSessionCount (); 
     213    uint32 pLimit = GetPlayerAmountLimit (); 
     214    uint32 QueueSize = GetQueueSize (); //number of players in the queue 
     215    bool inQueue = false; 
     216    //so we don't count the user trying to 
     217    //login as a session and queue the socket that we are using 
     218    --Sessions; 
     219 
     220    if (pLimit > 0 && Sessions >= pLimit && s->GetSecurity () == SEC_PLAYER ) 
     221    { 
     222        AddQueuedPlayer (s); 
     223        UpdateMaxSessionCounters (); 
     224        sLog.outDetail ("PlayerQueue: Account id %u is in Queue Position (%u).", s->GetAccountId (), ++QueueSize); 
     225        return; 
     226    } 
     227 
     228    WorldPacket packet(SMSG_AUTH_RESPONSE, 1 + 4 + 1 + 4 + 1); 
     229    packet << uint8 (AUTH_OK); 
     230    packet << uint32 (0); // unknown random value... 
     231    packet << uint8 (0); 
     232    packet << uint32 (0); 
     233    packet << uint8 (s->Expansion()); // 0 - normal, 1 - TBC, must be set in database manually for each account 
     234    s->SendPacket (&packet); 
     235 
     236    UpdateMaxSessionCounters (); 
     237 
     238    // Updates the population 
     239    if (pLimit > 0) 
     240    { 
     241        float popu = GetActiveSessionCount (); //updated number of users on the server 
     242        popu /= pLimit; 
     243        popu *= 2; 
     244        loginDatabase.PExecute ("UPDATE realmlist SET population = '%f' WHERE id = '%d'", popu, realmID); 
     245        sLog.outDetail ("Server Population (%f).", popu); 
    246246    } 
    247247} 
     
    261261{ 
    262262    m_QueuedPlayer.push_back (sess); 
    263      
     263 
    264264    // The 1st SMSG_AUTH_RESPONSE needs to contain other info too. 
    265265    WorldPacket packet (SMSG_AUTH_RESPONSE, 1 + 4 + 1 + 4 + 1); 
     
    271271    packet << uint32(GetQueuePos (sess)); 
    272272    sess->SendPacket (&packet); 
    273      
     273 
    274274    //sess->SendAuthWaitQue (GetQueuePos (sess)); 
    275275} 
     
    22832283 
    22842284    ///- Update the database with ban information 
    2285         switch(mode) 
     2285    switch(mode) 
    22862286    { 
    22872287        case BAN_IP: 
    2288                         //No SQL injection as strings are escaped 
    2289                         resultAccounts = loginDatabase.PQuery("SELECT id FROM account WHERE last_ip = '%s'",nameOrIP.c_str()); 
    2290                         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()); 
    2291                         break; 
    2292                 case BAN_ACCOUNT: 
    2293                         //No SQL injection as string is escaped 
    2294                         resultAccounts = loginDatabase.PQuery("SELECT id FROM account WHERE username = '%s'",nameOrIP.c_str()); 
    2295                         break; 
    2296                 case BAN_CHARACTER: 
    2297                         //No SQL injection as string is escaped 
    2298                         resultAccounts = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name = '%s'",nameOrIP.c_str()); 
    2299                         break; 
    2300                 default: 
    2301                         return BAN_SYNTAX_ERROR; 
    2302     } 
    2303      
    2304         if(!resultAccounts) 
    2305         { 
    2306                 if(mode==BAN_IP) 
    2307             return BAN_SUCCESS; 
    2308                 else 
    2309                         return BAN_NOTFOUND;                                // Nobody to ban 
    2310         } 
     2288            //No SQL injection as strings are escaped 
     2289            resultAccounts = loginDatabase.PQuery("SELECT id FROM account WHERE last_ip = '%s'",nameOrIP.c_str()); 
     2290            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()); 
     2291            break; 
     2292        case BAN_ACCOUNT: 
     2293            //No SQL injection as string is escaped 
     2294            resultAccounts = loginDatabase.PQuery("SELECT id FROM account WHERE username = '%s'",nameOrIP.c_str()); 
     2295            break; 
     2296        case BAN_CHARACTER: 
     2297            //No SQL injection as string is escaped 
     2298            resultAccounts = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name = '%s'",nameOrIP.c_str()); 
     2299            break; 
     2300        default: 
     2301            return BAN_SYNTAX_ERROR; 
     2302    } 
     2303 
     2304    if(!resultAccounts) 
     2305    { 
     2306        if(mode==BAN_IP) 
     2307            return BAN_SUCCESS;                             // ip correctly banned but nobody affected (yet) 
     2308        else 
     2309            return BAN_NOTFOUND;                                // Nobody to ban 
     2310    } 
    23112311 
    23122312    ///- Disconnect all affected players (for IP it can be several) 
     
    23172317 
    23182318        if(mode!=BAN_IP) 
    2319                 { 
     2319        { 
    23202320            //No SQL injection as strings are escaped 
    23212321            loginDatabase.PExecute("INSERT INTO account_banned VALUES ('%u', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()+%u, '%s', '%s', '1')", 
    23222322                account,duration_secs,safe_author.c_str(),reason.c_str()); 
    2323                 } 
     2323        } 
    23242324 
    23252325        if (WorldSession* sess = FindSession(account)) 
     
    23432343    else 
    23442344    { 
    2345         uint32 account=0; 
     2345        uint32 account = 0; 
    23462346        if (mode == BAN_ACCOUNT) 
    23472347            account = accmgr.GetId (nameOrIP); 
     
    23492349            account = objmgr.GetPlayerAccountIdByPlayerName (nameOrIP); 
    23502350 
    2351         if(!account) 
     2351        if (!account) 
    23522352            return false; 
    2353              
     2353 
    23542354        //NO SQL injection as account is uint32 
    23552355        loginDatabase.PExecute("UPDATE account_banned SET active = '0' WHERE id = '%u'",account); 
     
    24342434 
    24352435        SendServerMessage(msgid,str.c_str(),player); 
    2436         outstring_log("Server will %s in %s", (m_ShutdownMask & SHUTDOWN_MASK_RESTART ? "restart" : "shutdown"), str.c_str()); 
     2436        DEBUG_LOG("Server is %s in %s",(m_ShutdownMask & SHUTDOWN_MASK_RESTART ? "restart" : "shuttingdown"),str.c_str()); 
    24372437    } 
    24382438} 
     
    24742474      AddSession_ (sess); 
    24752475    } 
    2476          
     2476 
    24772477    ///- Delete kicked sessions at add new session 
    24782478    for (std::set<WorldSession*>::iterator itr = m_kicked_sessions.begin(); itr != m_kicked_sessions.end(); ++itr) 
    2479     {    
     2479    { 
    24802480        RemoveQueuedPlayer (*itr); 
    24812481        delete *itr; 
     
    25052505{ 
    25062506    if (cliCmdQueue.empty()) 
    2507                 return; 
     2507        return; 
    25082508 
    25092509    CliCommandHolder::Print* zprint; 
     2510 
    25102511    while (!cliCmdQueue.empty()) 
    25112512    { 
     
    25132514        CliCommandHolder *command = cliCmdQueue.next(); 
    25142515 
    2515                 zprint = command->m_print; 
    2516  
    2517                 CliHandler(zprint).ParseCommands(command->m_command); 
     2516        zprint = command->m_print; 
     2517 
     2518        CliHandler(zprint).ParseCommands(command->m_command); 
    25182519 
    25192520        delete command; 
     
    26232624void World::LoadDBVersion() 
    26242625{ 
    2625         QueryResult* result = WorldDatabase.Query("SELECT version FROM db_version LIMIT 1"); 
    2626         if(result) 
    2627         { 
    2628                 Field* fields = result->Fetch(); 
    2629  
    2630                 m_DBVersion = fields[0].GetString(); 
    2631                 delete result; 
    2632         } 
    2633         else 
    2634                 m_DBVersion = "unknown world database"; 
    2635 } 
     2626    QueryResult* result = WorldDatabase.Query("SELECT version FROM db_version LIMIT 1"); 
     2627    if(result) 
     2628    { 
     2629        Field* fields = result->Fetch(); 
     2630 
     2631        m_DBVersion = fields[0].GetString(); 
     2632        delete result; 
     2633    } 
     2634    else 
     2635        m_DBVersion = "unknown world database"; 
     2636}