Changeset 6 for trunk/src/game/WorldSession.cpp
- Timestamp:
- 11/19/08 13:22:12 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/game/WorldSession.cpp
r2 r6 21 21 */ 22 22 23 #include "WorldSocket.h" 23 24 #include "Common.h" 24 25 #include "Database/DatabaseEnv.h" … … 43 44 WorldSession::WorldSession(uint32 id, WorldSocket *sock, uint32 sec, bool tbc, time_t mute_time, LocaleConstant locale) : 44 45 LookingForGroup_auto_join(false), LookingForGroup_auto_add(false), m_muteTime(mute_time), 45 _player(NULL), _socket(sock),_security(sec), _accountId(id), m_isTBC(tbc),46 _player(NULL), m_Socket(sock),_security(sec), _accountId(id), m_isTBC(tbc), 46 47 m_sessionDbcLocale(sWorld.GetAvailableDbcLocale(locale)), m_sessionDbLocaleIndex(objmgr.GetIndexForLocale(locale)), 47 48 _logoutTime(0), m_playerLoading(false), m_playerLogout(false), m_playerRecentlyLogout(false), m_latency(0) 48 49 { 50 if (sock) 51 { 52 m_Address = sock->GetRemoteAddress (); 53 sock->AddReference (); 54 } 49 55 } 50 56 … … 57 63 58 64 /// - If have unclosed socket, close it 59 if(_socket) 60 _socket->CloseSocket(); 61 62 _socket = NULL; 65 if (m_Socket) 66 { 67 m_Socket->CloseSocket (); 68 m_Socket->RemoveReference (); 69 m_Socket = NULL; 70 } 63 71 64 72 ///- empty incoming packet queue … … 68 76 delete packet; 69 77 } 78 79 sWorld.RemoveQueuedPlayer(this); 70 80 } 71 81 … … 82 92 } 83 93 84 /// Set the WorldSocket associated with this session85 void WorldSession::SetSocket(WorldSocket *sock)86 {87 _socket = sock;88 }89 90 94 /// Send a packet to the client 91 95 void WorldSession::SendPacket(WorldPacket const* packet) 92 96 { 93 if (! _socket)97 if (!m_Socket) 94 98 return; 95 99 #ifdef MANGOS_DEBUG … … 125 129 sendLastPacketBytes = packet->wpos(); // wpos is real written size 126 130 } 127 #endif // !MANGOS_DEBUG 128 129 _socket->SendPacket(packet); 131 #endif // !MANGOS_DEBUG 132 133 if (m_Socket->SendPacket (*packet) == -1) 134 { 135 m_Socket->CloseSocket (); 136 } 130 137 } 131 138 132 139 /// Add an incoming packet to the queue 133 void WorldSession::QueuePacket(WorldPacket& packet) 134 { 135 WorldPacket *pck = new WorldPacket(packet); 136 _recvQueue.add(pck); 140 void WorldSession::QueuePacket(WorldPacket* new_packet) 141 { 142 _recvQueue.add(new_packet); 137 143 } 138 144 … … 149 155 bool WorldSession::Update(uint32 /*diff*/) 150 156 { 157 if (m_Socket) 158 if (m_Socket->IsClosed ()) 159 { 160 m_Socket->RemoveReference (); 161 m_Socket = NULL; 162 } 163 151 164 WorldPacket *packet; 152 165 … … 211 224 ///- If necessary, log the player out 212 225 time_t currTime = time(NULL); 213 if (! _socket || (ShouldLogOut(currTime) && !m_playerLoading))226 if (!m_Socket || (ShouldLogOut(currTime) && !m_playerLoading)) 214 227 LogoutPlayer(true); 215 228 216 if (! _socket)229 if (!m_Socket) 217 230 return false; //Will remove this session from the world session map 218 231 … … 344 357 // remove player from the group if he is: 345 358 // a) in group; b) not in raid group; c) logging out normally (not being kicked or disconnected) 346 if(_player->GetGroup() && !_player->GetGroup()->isRaidGroup() && _socket)359 if(_player->GetGroup() && !_player->GetGroup()->isRaidGroup() && m_Socket) 347 360 _player->RemoveFromGroup(); 348 361 … … 386 399 void WorldSession::KickPlayer() 387 400 { 388 if(!_socket) 389 return; 390 391 // player will be logout and session will removed in next update tick 392 _socket->CloseSocket(); 393 _socket = NULL; 401 if (m_Socket) 402 { 403 m_Socket->CloseSocket (); 404 } 394 405 } 395 406 … … 462 473 recvPacket.GetOpcode()); 463 474 } 475 476 void WorldSession::SendAuthWaitQue(uint32 position) 477 { 478 if(position == 0) 479 { 480 WorldPacket packet( SMSG_AUTH_RESPONSE, 1 ); 481 packet << uint8( AUTH_OK ); 482 SendPacket(&packet); 483 } 484 else 485 { 486 WorldPacket packet( SMSG_AUTH_RESPONSE, 5 ); 487 packet << uint8( AUTH_WAIT_QUEUE ); 488 packet << uint32 (position); 489 SendPacket(&packet); 490 } 491 } 492 493