Changeset 6 for trunk/src/game/World.cpp
- Timestamp:
- 11/19/08 13:22:12 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/game/World.cpp
r2 r6 22 22 23 23 #include "Common.h" 24 //#include "WorldSocket.h" 24 25 #include "Database/DatabaseEnv.h" 25 26 #include "Config/ConfigEnv.h" … … 51 52 #include "GameEvent.h" 52 53 #include "Database/DatabaseImpl.h" 53 #include "WorldSocket.h"54 54 #include "GridNotifiersImpl.h" 55 55 #include "CellImpl.h" … … 124 124 125 125 if(m_resultQueue) delete m_resultQueue; 126 127 //TODO free addSessQueue 126 128 } 127 129 … … 174 176 } 175 177 176 /// Add a session to the session list177 178 void World::AddSession(WorldSession* s) 178 179 { 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 183 void 184 World::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 244 int32 World::GetQueuePos(WorldSession* sess) 190 245 { 191 246 uint32 position = 1; 192 247 193 248 for(Queue::iterator iter = m_QueuedPlayer.begin(); iter != m_QueuedPlayer.end(); ++iter, ++position) 194 if((*iter) == s ocket)249 if((*iter) == sess) 195 250 return position; 196 251 … … 198 253 } 199 254 200 void World::AddQueuedPlayer(WorldSocket* socket) 201 { 202 m_QueuedPlayer.push_back(socket); 203 } 204 205 void World::RemoveQueuedPlayer(WorldSocket* socket) 255 void 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 272 void World::RemoveQueuedPlayer(WorldSession* sess) 206 273 { 207 274 // sessions count including queued to remove (if removed_session set) … … 214 281 bool decrease_session = true; 215 282 216 // search socketto remove and count skipped positions283 // search to remove and count skipped positions 217 284 for(;iter != m_QueuedPlayer.end(); ++iter, ++position) 218 285 { 219 if(*iter==s ocket)286 if(*iter==sess) 220 287 { 221 288 Queue::iterator iter2 = iter; … … 237 304 if( (!m_playerLimit || sessions < m_playerLimit) && !m_QueuedPlayer.empty() ) 238 305 { 239 WorldS ocket* socket = m_QueuedPlayer.front();306 WorldSession * socket = m_QueuedPlayer.front(); 240 307 socket->SendAuthWaitQue(0); 241 308 m_QueuedPlayer.pop_front(); … … 1016 1083 objmgr.LoadBattleMastersEntry(); 1017 1084 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 1018 1097 sLog.outString( "Loading Waypoints..." ); 1019 1098 WaypointMgr.Load(); … … 2069 2148 { 2070 2149 // 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(); 2074 2154 2075 2155 m_QueuedPlayer.empty(); … … 2321 2401 void World::UpdateSessions( time_t diff ) 2322 2402 { 2403 while(!addSessQueue.empty()) 2404 { 2405 WorldSession* sess = addSessQueue.next (); 2406 AddSession_ (sess); 2407 } 2408 2323 2409 ///- Delete kicked sessions at add new session 2324 2410 for (std::set<WorldSession*>::iterator itr = m_kicked_sessions.begin(); itr != m_kicked_sessions.end(); ++itr)