[10850] Move common check part for recently added filter classes to helper function.

This is more safe have expected tio be same check in one function.

Also apply some code style fixes.
This commit is contained in:
VladimirMangos 2010-12-10 01:52:46 +03:00
parent 028fda6b64
commit 92ce21d009
3 changed files with 43 additions and 44 deletions

View file

@ -39,45 +39,44 @@
#include "Auth/HMACSHA1.h"
#include "zlib/zlib.h"
bool MapSessionFilter::Process(WorldPacket * packet)
// select opcodes appropriate for processing in Map::Update context for current session state
static bool MapSessionFilterHelper(WorldSession* session, OpcodeHandler const& opHandle)
{
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)
// we do not process thread-unsafe packets
if (opHandle.packetProcessing == PROCESS_THREADUNSAFE)
return false;
Player * plr = m_pSession->GetPlayer();
if(!plr)
// we do not process not loggined player packets
Player * plr = session->GetPlayer();
if (!plr)
return false;
//in Map::Update() we do not process packets where player is not in world!
// 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 MapSessionFilter::Process(WorldPacket * packet)
{
OpcodeHandler const& opHandle = opcodeTable[packet->GetOpcode()];
if (opHandle.packetProcessing == PROCESS_INPLACE)
return true;
// let's check if our opcode can be really processed in Map::Update()
return MapSessionFilterHelper(m_pSession, opHandle);
}
// 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)
// 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);
// let's check if our opcode can't be processed in Map::Update()
return !MapSessionFilterHelper(m_pSession, opHandle);
}
/// WorldSession constructor

View file

@ -148,37 +148,37 @@ enum TutorialDataState
//allows to determine if next packet is safe to be processed
class PacketFilter
{
public:
explicit PacketFilter(WorldSession * pSession) : m_pSession(pSession) {}
virtual ~PacketFilter() {}
public:
explicit PacketFilter(WorldSession * pSession) : m_pSession(pSession) {}
virtual ~PacketFilter() {}
virtual bool Process(WorldPacket * packet) { return true; }
virtual bool ProcessLogout() const { return true; }
virtual bool Process(WorldPacket * packet) { return true; }
virtual bool ProcessLogout() const { return true; }
protected:
WorldSession * const m_pSession;
protected:
WorldSession * const m_pSession;
};
//process only thread-safe packets in Map::Update()
class MapSessionFilter : public PacketFilter
{
public:
explicit MapSessionFilter(WorldSession * pSession) : PacketFilter(pSession) {}
~MapSessionFilter() {}
public:
explicit MapSessionFilter(WorldSession * pSession) : PacketFilter(pSession) {}
~MapSessionFilter() {}
virtual bool Process(WorldPacket * packet);
//in Map::Update() we do not process player logout!
virtual bool ProcessLogout() const { return false; }
virtual bool Process(WorldPacket * packet);
//in Map::Update() we do not process player logout!
virtual bool ProcessLogout() const { return false; }
};
//class used to filer only thread-unsafe packets from queue
//in order to update only be used in World::UpdateSessions()
class WorldSessionFilter : public PacketFilter
{
public:
explicit WorldSessionFilter(WorldSession * pSession) : PacketFilter(pSession) {}
~WorldSessionFilter() {}
public:
explicit WorldSessionFilter(WorldSession * pSession) : PacketFilter(pSession) {}
~WorldSessionFilter() {}
virtual bool Process(WorldPacket* packet);
virtual bool Process(WorldPacket* packet);
};
/// Player session in the World

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "10849"
#define REVISION_NR "10850"
#endif // __REVISION_NR_H__