mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-23 13:46:24 +00:00
feat(Core/Packets): Port packet handling from TrinityCore (#5617)
* feat(Core/Packets): Port packet handling from TrinityCore * 1 * 2 * 3 * 1 * 2 * #3670 * 3 * 1 * codestyle * fix msvc warnings
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version.
|
||||
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version.
|
||||
* Copyright (C) 2021+ WarheadCore <https://github.com/WarheadCore>
|
||||
*/
|
||||
|
||||
/// \addtogroup u2w
|
||||
@@ -11,12 +10,12 @@
|
||||
#ifndef _OPCODES_H
|
||||
#define _OPCODES_H
|
||||
|
||||
#include "Common.h"
|
||||
#include "Define.h"
|
||||
#include <string>
|
||||
|
||||
/// List of Opcodes
|
||||
enum Opcodes
|
||||
enum Opcodes : uint16
|
||||
{
|
||||
MSG_NULL_ACTION = 0x000,
|
||||
CMSG_BOOTME = 0x001,
|
||||
CMSG_DBLOOKUP = 0x002,
|
||||
SMSG_DBLOOKUP = 0x003,
|
||||
@@ -1330,6 +1329,15 @@ enum Opcodes
|
||||
NUM_MSG_TYPES = 0x51F
|
||||
};
|
||||
|
||||
enum OpcodeMisc : uint16
|
||||
{
|
||||
NUM_OPCODE_HANDLERS = NUM_MSG_TYPES,
|
||||
NULL_OPCODE = 0x0000
|
||||
};
|
||||
|
||||
typedef Opcodes OpcodeClient;
|
||||
typedef Opcodes OpcodeServer;
|
||||
|
||||
/// Player state
|
||||
enum SessionStatus
|
||||
{
|
||||
@@ -1350,34 +1358,63 @@ enum PacketProcessing
|
||||
class WorldSession;
|
||||
class WorldPacket;
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#pragma pack(1)
|
||||
#else
|
||||
#pragma pack(push, 1)
|
||||
#endif
|
||||
|
||||
struct OpcodeHandler
|
||||
class OpcodeHandler
|
||||
{
|
||||
char const* name;
|
||||
SessionStatus status;
|
||||
PacketProcessing packetProcessing;
|
||||
void (WorldSession::*handler)(WorldPacket& recvPacket);
|
||||
public:
|
||||
OpcodeHandler(char const* name, SessionStatus status) : Name(name), Status(status) { }
|
||||
virtual ~OpcodeHandler() { }
|
||||
|
||||
char const* Name;
|
||||
SessionStatus Status;
|
||||
};
|
||||
|
||||
extern OpcodeHandler opcodeTable[NUM_MSG_TYPES];
|
||||
class ClientOpcodeHandler : public OpcodeHandler
|
||||
{
|
||||
public:
|
||||
ClientOpcodeHandler(char const* name, SessionStatus status, PacketProcessing processing)
|
||||
: OpcodeHandler(name, status), ProcessingPlace(processing) { }
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#pragma pack()
|
||||
#else
|
||||
#pragma pack(pop)
|
||||
#endif
|
||||
virtual void Call(WorldSession* session, WorldPacket& packet) const = 0;
|
||||
|
||||
PacketProcessing ProcessingPlace;
|
||||
};
|
||||
|
||||
class ServerOpcodeHandler : public OpcodeHandler
|
||||
{
|
||||
public:
|
||||
ServerOpcodeHandler(char const* name, SessionStatus status)
|
||||
: OpcodeHandler(name, status) { }
|
||||
};
|
||||
|
||||
class OpcodeTable
|
||||
{
|
||||
public:
|
||||
OpcodeTable();
|
||||
|
||||
OpcodeTable(OpcodeTable const&) = delete;
|
||||
OpcodeTable& operator=(OpcodeTable const&) = delete;
|
||||
|
||||
~OpcodeTable();
|
||||
|
||||
void Initialize();
|
||||
|
||||
ClientOpcodeHandler const* operator[](Opcodes index) const
|
||||
{
|
||||
return _internalTableClient[index];
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename Handler, Handler HandlerFunction>
|
||||
void ValidateAndSetClientOpcode(OpcodeClient opcode, char const* name, SessionStatus status, PacketProcessing processing);
|
||||
|
||||
void ValidateAndSetServerOpcode(OpcodeServer opcode, char const* name, SessionStatus status);
|
||||
|
||||
ClientOpcodeHandler* _internalTableClient[NUM_OPCODE_HANDLERS];
|
||||
};
|
||||
|
||||
extern OpcodeTable opcodeTable;
|
||||
|
||||
/// Lookup opcode name for human understandable logging
|
||||
inline const char* LookupOpcodeName(uint16 id)
|
||||
{
|
||||
if (id >= NUM_MSG_TYPES)
|
||||
return "Received unknown opcode, it's more than max!";
|
||||
return opcodeTable[id].name;
|
||||
}
|
||||
std::string GetOpcodeNameForLogging(Opcodes opcode);
|
||||
|
||||
#endif
|
||||
/// @}
|
||||
|
||||
Reference in New Issue
Block a user