[10848] New system for parallelizing client packet processing. Handle WorldSession updates in Map::Update() where we are safe to proceed. Thank you for all your feedback!

Signed-off-by: Ambal <pogrebniak@gala.net>
This commit is contained in:
Ambal 2010-12-09 20:20:58 +02:00
parent 4e72ead2fb
commit 5f539117a4
8 changed files with 1447 additions and 1322 deletions

View file

@ -39,6 +39,47 @@
#include "Auth/HMACSHA1.h"
#include "zlib/zlib.h"
bool MapSessionFilter::Process(WorldPacket * packet)
{
OpcodeHandler const& opHandle = opcodeTable[packet->GetOpcode()];
//let's check if our opcode can be really processed in Map::Update()
if(opHandle.packetProcessing == PROCESS_INPLACE)
return true;
//we do not process thread-unsafe packets
if(opHandle.packetProcessing == PROCESS_THREADUNSAFE)
return false;
Player * plr = m_pSession->GetPlayer();
if(!plr)
return false;
//in Map::Update() we do not process packets where player is not in world!
return plr->IsInWorld();
}
//we should process ALL packets when player is not in world/logged in
//OR packet handler is not thread-safe!
bool WorldSessionFilter::Process(WorldPacket* packet)
{
OpcodeHandler const& opHandle = opcodeTable[packet->GetOpcode()];
//check if packet handler is supposed to be safe
if(opHandle.packetProcessing == PROCESS_INPLACE)
return true;
//thread-unsafe packets should be processed in World::UpdateSessions()
if(opHandle.packetProcessing == PROCESS_THREADUNSAFE)
return true;
//no player attached? -> our client! ^^
Player * plr = m_pSession->GetPlayer();
if(!plr)
return true;
//lets process all packets for non-in-the-world player
return (plr->IsInWorld() == false);
}
/// WorldSession constructor
WorldSession::WorldSession(uint32 id, WorldSocket *sock, AccountTypes sec, uint8 expansion, time_t mute_time, LocaleConstant locale) :
LookingForGroup_auto_join(false), LookingForGroup_auto_add(false), m_muteTime(mute_time),
@ -158,12 +199,12 @@ void WorldSession::LogUnprocessedTail(WorldPacket *packet)
}
/// Update the WorldSession (triggered by World update)
bool WorldSession::Update(uint32 /*diff*/)
bool WorldSession::Update(uint32 diff, PacketFilter& updater)
{
///- Retrieve packets from the receive queue and call the appropriate handlers
/// not proccess packets if socket already closed
/// not process packets if socket already closed
WorldPacket* packet;
while (m_Socket && !m_Socket->IsClosed() && _recvQueue.next(packet))
while (m_Socket && !m_Socket->IsClosed() && _recvQueue.next(packet, updater))
{
/*#if 1
sLog.outError( "MOEP: %s (0x%.4X)",
@ -266,13 +307,18 @@ bool WorldSession::Update(uint32 /*diff*/)
m_Socket = NULL;
}
///- If necessary, log the player out
time_t currTime = time(NULL);
if (!m_Socket || (ShouldLogOut(currTime) && !m_playerLoading))
LogoutPlayer(true);
//check if we are safe to proceed with logout
//logout procedure should happen only in World::UpdateSessions() method!!!
if(updater.ProcessLogout())
{
///- If necessary, log the player out
time_t currTime = time(NULL);
if (!m_Socket || (ShouldLogOut(currTime) && !m_playerLoading))
LogoutPlayer(true);
if (!m_Socket)
return false; //Will remove this session from the world session map
if (!m_Socket)
return false; //Will remove this session from the world session map
}
return true;
}