All pastes #974249 Raw Edit

Stuff

public text v1 · immutable
·published 2008-04-06 17:57 UTC
rendered paste body
/// Update the WorldSession (triggered by World update)
bool WorldSession::Update(uint32 /*diff*/)
{
//	//we delete socket only if it not connected	in current
// 	if (_socket && !_socket->IsConnected())
// 	{
// 		LogoutPlayer(true);
// 		sLog.outError("ROGNAR: WorldSession::Update - _socket && !_socket->IsConnected() 1 socket handle [%u]", 
// 			_socket->GetSocket());
// 		WorldSocket *tempSocket = _socket;
// 		_socket = NULL;
// 		tempSocket->CloseSocket();
// 		tempSocket = NULL;
// 		return false;                                       //Will remove this session from the world session map
// 	}
// 
// 	if (!_socket)
// 	{
// 		LogoutPlayer(true);
// 		return false;
// 	}

    WorldPacket *packet;

    ///- Retrieve packets from the receive queue and call the appropriate handlers
    /// \todo Is there a way to consolidate the OpcondeHandlerTable and the g_worldOpcodeNames to only maintain 1 list?
    /// answer : there is a way, but this is better, because it would use redundant RAM
    while (!_recvQueue.empty())
    {
        packet = _recvQueue.next();

        /*#if 1
        sLog.outError( "MOEP: %s (0x%.4X)",
                        LookupOpcodeName(packet->GetOpcode()),
                        packet->GetOpcode());
        #endif*/
        OpcodeTableMap::const_iterator iter = objmgr.opcodeTable.find( packet->GetOpcode() );

        if (iter == objmgr.opcodeTable.end())
        {
            sLog.outError( "SESSION: received unhandled opcode %s (0x%.4X)",
                LookupOpcodeName(packet->GetOpcode()),
                packet->GetOpcode());
        }
        else
        {
            if (iter->second.status == STATUS_LOGGEDIN && _player)
            {
                (this->*iter->second.handler)(*packet);
            }
            else if (iter->second.status == STATUS_AUTHED)
            {
                m_playerRecentlyLogout = false;
                (this->*iter->second.handler)(*packet);
            }
            else
                // skip STATUS_LOGGEDIN opcode unexpected errors if player logout sometime ago - this can be network lag delayed packets
            if(!m_playerRecentlyLogout)
            {
                sLog.outError( "SESSION: received unexpected opcode %s (0x%.4X)",
                    LookupOpcodeName(packet->GetOpcode()),
                    packet->GetOpcode());
            }
        }

        delete packet;
    }

    ///- If necessary, log the player out
    time_t currTime = time(NULL);
    if (!_socket || !_socket->IsConnected() || (ShouldLogOut(currTime) && !m_playerLoading))
        LogoutPlayer(true);
	
    if (!_socket || !_socket->IsConnected())
		return false; //session already not active, delete if at update world

//	//we delete socket only if it not connected	in current
// 	if (_socket && !_socket->IsConnected())
// 	{
// 		sLog.outError("ROGNAR: WorldSession::Update - _socket && !_socket->IsConnected() 2 socket handle [%u]", 
// 			_socket->GetSocket());
// 		WorldSocket * tempSocket = _socket;
// 		_socket = NULL;
// 		tempSocket->CloseSocket();
// 		tempSocket = NULL;
// 		return false;                                       //Will remove this session from the world session map
// 	}

    return true;
}