Changeset 6 for trunk/src/game/World.cpp

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

[svn] * Added ACE for Linux and Windows (Thanks Derex for Linux part and partial Windows part)
* Updated to 6721 and 676
* Fixed TrinityScript? logo
* Version updated to 0.2.6721.676

Original author: Neo2003
Date: 2008-10-04 06:17:19-05:00

Files:
1 modified

Legend:

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

    r2 r6  
    2222 
    2323#include "Common.h" 
     24//#include "WorldSocket.h" 
    2425#include "Database/DatabaseEnv.h" 
    2526#include "Config/ConfigEnv.h" 
     
    5152#include "GameEvent.h" 
    5253#include "Database/DatabaseImpl.h" 
    53 #include "WorldSocket.h" 
    5454#include "GridNotifiersImpl.h" 
    5555#include "CellImpl.h" 
     
    124124 
    125125    if(m_resultQueue) delete m_resultQueue; 
     126     
     127    //TODO free addSessQueue 
    126128} 
    127129 
     
    174176} 
    175177 
    176 /// Add a session to the session list 
    177178void World::AddSession(WorldSession* s) 
    178179{ 
    179     ASSERT(s); 
    180  
    181     WorldSession* old = m_sessions[s->GetAccountId()]; 
    182     m_sessions[s->GetAccountId()] = s; 
    183  
    184     // if session already exist, prepare to it deleting at next world update 
    185     if(old) 
    186         m_kicked_sessions.insert(old); 
    187 } 
    188  
    189 int32 World::GetQueuePos(WorldSocket* socket) 
     180  addSessQueue.add(s); 
     181} 
     182 
     183void 
     184World::AddSession_ (WorldSession* s) 
     185{ 
     186  ASSERT (s); 
     187 
     188  //NOTE - Still there is race condition in WorldSession* being used in the Sockets 
     189 
     190  ///- kick already loaded player with same account (if any) and remove session 
     191  ///- if player is in loading and want to load again, return 
     192  if (!RemoveSession (s->GetAccountId ())) 
     193    { 
     194      s->KickPlayer (); 
     195      m_kicked_sessions.insert (s); 
     196      return; 
     197    } 
     198 
     199  WorldSession* old = m_sessions[s->GetAccountId ()]; 
     200  m_sessions[s->GetAccountId ()] = s; 
     201 
     202  // if session already exist, prepare to it deleting at next world update 
     203  // NOTE - KickPlayer() should be called on "old" in RemoveSession() 
     204  if (old) 
     205    m_kicked_sessions.insert (old); 
     206 
     207  uint32 Sessions = GetActiveAndQueuedSessionCount (); 
     208  uint32 pLimit = GetPlayerAmountLimit (); 
     209  uint32 QueueSize = GetQueueSize (); //number of players in the queue 
     210  bool inQueue = false; 
     211  //so we don't count the user trying to  
     212  //login as a session and queue the socket that we are using 
     213  --Sessions; 
     214 
     215  if (pLimit > 0 && Sessions >= pLimit && s->GetSecurity () == SEC_PLAYER ) 
     216    { 
     217      AddQueuedPlayer (s); 
     218      UpdateMaxSessionCounters (); 
     219      sLog.outDetail ("PlayerQueue: Account id %u is in Queue Position (%u).", s->GetAccountId (), ++QueueSize); 
     220      return; 
     221    } 
     222   
     223  WorldPacket packet(SMSG_AUTH_RESPONSE, 1 + 4 + 1 + 4 + 1); 
     224  packet << uint8 (AUTH_OK); 
     225  packet << uint32 (0); // unknown random value... 
     226  packet << uint8 (0); 
     227  packet << uint32 (0); 
     228  packet << uint8 (s->IsTBC () ? 1 : 0); // 0 - normal, 1 - TBC, must be set in database manually for each account 
     229  s->SendPacket (&packet); 
     230 
     231  UpdateMaxSessionCounters (); 
     232 
     233  // Updates the population 
     234  if (pLimit > 0) 
     235    { 
     236      float popu = GetActiveSessionCount (); //updated number of users on the server 
     237      popu /= pLimit; 
     238      popu *= 2; 
     239      loginDatabase.PExecute ("UPDATE realmlist SET population = '%f' WHERE id = '%d'", popu, realmID); 
     240      sLog.outDetail ("Server Population (%f).", popu); 
     241    } 
     242} 
     243 
     244int32 World::GetQueuePos(WorldSession* sess) 
    190245{ 
    191246    uint32 position = 1; 
    192247 
    193248    for(Queue::iterator iter = m_QueuedPlayer.begin(); iter != m_QueuedPlayer.end(); ++iter, ++position) 
    194         if((*iter) == socket) 
     249        if((*iter) == sess) 
    195250            return position; 
    196251 
     
    198253} 
    199254 
    200 void World::AddQueuedPlayer(WorldSocket* socket) 
    201 { 
    202     m_QueuedPlayer.push_back(socket); 
    203 } 
    204  
    205 void World::RemoveQueuedPlayer(WorldSocket* socket) 
     255void World::AddQueuedPlayer(WorldSession* sess) 
     256{ 
     257    m_QueuedPlayer.push_back (sess); 
     258     
     259    // The 1st SMSG_AUTH_RESPONSE needs to contain other info too. 
     260    WorldPacket packet (SMSG_AUTH_RESPONSE, 1 + 4 + 1 + 4 + 1); 
     261    packet << uint8 (AUTH_WAIT_QUEUE); 
     262    packet << uint32 (0); // unknown random value... 
     263    packet << uint8 (0); 
     264    packet << uint32 (0); 
     265    packet << uint8 (sess->IsTBC () ? 1 : 0); // 0 - normal, 1 - TBC, must be set in database manually for each account 
     266    packet << uint32(GetQueuePos (sess)); 
     267    sess->SendPacket (&packet); 
     268     
     269    //sess->SendAuthWaitQue (GetQueuePos (sess)); 
     270} 
     271 
     272void World::RemoveQueuedPlayer(WorldSession* sess) 
    206273{ 
    207274    // sessions count including queued to remove (if removed_session set) 
     
    214281    bool decrease_session = true; 
    215282 
    216     // search socket to remove and count skipped positions 
     283    // search to remove and count skipped positions 
    217284    for(;iter != m_QueuedPlayer.end(); ++iter, ++position) 
    218285    { 
    219         if(*iter==socket) 
     286        if(*iter==sess) 
    220287        { 
    221288            Queue::iterator iter2 = iter; 
     
    237304    if( (!m_playerLimit || sessions < m_playerLimit) && !m_QueuedPlayer.empty() ) 
    238305    { 
    239         WorldSocket * socket = m_QueuedPlayer.front(); 
     306        WorldSession * socket = m_QueuedPlayer.front(); 
    240307        socket->SendAuthWaitQue(0); 
    241308        m_QueuedPlayer.pop_front(); 
     
    10161083    objmgr.LoadBattleMastersEntry(); 
    10171084 
     1085    sLog.outString( "Loading GameTeleports..." ); 
     1086    objmgr.LoadGameTele(); 
     1087 
     1088    sLog.outString( "Loading Npc Text Id..." ); 
     1089    objmgr.LoadNpcTextId();                                 // must be after load Creature and NpcText 
     1090 
     1091    sLog.outString( "Loading vendors..." ); 
     1092    objmgr.LoadVendors();                                   // must be after load CreatureTemplate and ItemTemplate 
     1093 
     1094    sLog.outString( "Loading trainers..." ); 
     1095    objmgr.LoadTrainerSpell();                              // must be after load CreatureTemplate 
     1096 
    10181097    sLog.outString( "Loading Waypoints..." ); 
    10191098    WaypointMgr.Load(); 
     
    20692148{ 
    20702149    // session not removed at kick and will removed in next update tick 
    2071     for (Queue::iterator itr = m_QueuedPlayer.begin(); itr != m_QueuedPlayer.end(); ++itr) 
    2072         if(WorldSession* session = (*itr)->GetSession()) 
    2073             session->KickPlayer(); 
     2150  //TODO here 
     2151//    for (Queue::iterator itr = m_QueuedPlayer.begin(); itr != m_QueuedPlayer.end(); ++itr) 
     2152//        if(WorldSession* session = (*itr)->GetSession()) 
     2153//            session->KickPlayer(); 
    20742154 
    20752155    m_QueuedPlayer.empty(); 
     
    23212401void World::UpdateSessions( time_t diff ) 
    23222402{ 
     2403    while(!addSessQueue.empty()) 
     2404    { 
     2405      WorldSession* sess = addSessQueue.next (); 
     2406      AddSession_ (sess); 
     2407    } 
     2408         
    23232409    ///- Delete kicked sessions at add new session 
    23242410    for (std::set<WorldSession*>::iterator itr = m_kicked_sessions.begin(); itr != m_kicked_sessions.end(); ++itr)