aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Server/Protocol
diff options
context:
space:
mode:
authorDDuarte <dnpd.dd@gmail.com>2014-10-25 15:41:42 +0100
committerDDuarte <dnpd.dd@gmail.com>2014-10-25 15:42:16 +0100
commitf37e5b9afd6b9d45afaf2c951d4fac0b72832865 (patch)
tree79e76963809a2bc512dd3ef43056fb106816dae3 /src/server/game/Server/Protocol
parentc67fa90f3e4afd95141546676a959e89d2ac73ef (diff)
Core/Opcodes: Support opcodes with the same ids and different direction
- Split enum Opcodes in enum OpcodeMisc/OpcodeClient/OpcodeServer - Old MSGs are temporarly in the enum OpcodeClient - Split _internalTable of OpcodeTable in two tables, one for CMSG opcodes and another for SMSG opcodes Note: most added static_cast<OpcodeX> will be removed once WorldPacket is split in two classes (ServerPacket/ClientPacket, see #13434)
Diffstat (limited to 'src/server/game/Server/Protocol')
-rw-r--r--src/server/game/Server/Protocol/Opcodes.cpp44
-rw-r--r--src/server/game/Server/Protocol/Opcodes.h62
2 files changed, 79 insertions, 27 deletions
diff --git a/src/server/game/Server/Protocol/Opcodes.cpp b/src/server/game/Server/Protocol/Opcodes.cpp
index 86267d4c035..e0901bf9708 100644
--- a/src/server/game/Server/Protocol/Opcodes.cpp
+++ b/src/server/game/Server/Protocol/Opcodes.cpp
@@ -22,31 +22,61 @@
OpcodeTable opcodeTable;
template<bool isInValidRange, bool isNonZero>
-void OpcodeTable::ValidateAndSetOpcode(uint16 /*opcode*/, char const* /*name*/, SessionStatus /*status*/, PacketProcessing /*processing*/, pOpcodeHandler /*handler*/)
+void OpcodeTable::ValidateAndSetOpcode(OpcodeClient /*opcode*/, char const* /*name*/, SessionStatus /*status*/, PacketProcessing /*processing*/, pOpcodeHandler /*handler*/)
+{
+ // if for some reason we are here, that means NUM_OPCODE_HANDLERS == 0 (or your compiler is broken)
+}
+
+template<bool isInValidRange, bool isNonZero>
+void OpcodeTable::ValidateAndSetOpcode(OpcodeServer /*opcode*/, char const* /*name*/, SessionStatus /*status*/, PacketProcessing /*processing*/, pOpcodeHandler /*handler*/)
{
// if for some reason we are here, that means NUM_OPCODE_HANDLERS == 0 (or your compiler is broken)
}
template<>
-void OpcodeTable::ValidateAndSetOpcode<true, true>(uint16 opcode, char const* name, SessionStatus status, PacketProcessing processing, pOpcodeHandler handler)
+void OpcodeTable::ValidateAndSetOpcode<true, true>(OpcodeClient opcode, char const* name, SessionStatus status, PacketProcessing processing, pOpcodeHandler handler)
{
- if (_internalTable[opcode] != NULL)
+ if (_internalTableClient[opcode] != NULL)
{
- TC_LOG_ERROR("network", "Tried to override handler of %s with %s (opcode %u)", opcodeTable[opcode]->Name, name, opcode);
+ TC_LOG_ERROR("network", "Tried to override client handler of %s with %s (opcode %u)", opcodeTable[opcode]->Name, name, opcode);
return;
}
- _internalTable[opcode] = new OpcodeHandler(name, status, processing, handler);
+ _internalTableClient[opcode] = new OpcodeHandler(name, status, processing, handler);
}
template<>
-void OpcodeTable::ValidateAndSetOpcode<false, true>(uint16 opcode, char const* /*name*/, SessionStatus /*status*/, PacketProcessing /*processing*/, pOpcodeHandler /*handler*/)
+void OpcodeTable::ValidateAndSetOpcode<true, true>(OpcodeServer opcode, char const* name, SessionStatus status, PacketProcessing processing, pOpcodeHandler handler)
+{
+ if (_internalTableServer[opcode] != NULL)
+ {
+ TC_LOG_ERROR("network", "Tried to override server handler of %s with %s (opcode %u)", opcodeTable[opcode]->Name, name, opcode);
+ return;
+ }
+
+ _internalTableServer[opcode] = new OpcodeHandler(name, status, processing, handler);
+}
+
+template<>
+void OpcodeTable::ValidateAndSetOpcode<false, true>(OpcodeClient opcode, char const* /*name*/, SessionStatus /*status*/, PacketProcessing /*processing*/, pOpcodeHandler /*handler*/)
+{
+ TC_LOG_ERROR("network", "Tried to set handler for an invalid opcode %d", opcode);
+}
+
+template<>
+void OpcodeTable::ValidateAndSetOpcode<false, true>(OpcodeServer opcode, char const* /*name*/, SessionStatus /*status*/, PacketProcessing /*processing*/, pOpcodeHandler /*handler*/)
{
TC_LOG_ERROR("network", "Tried to set handler for an invalid opcode %d", opcode);
}
template<>
-void OpcodeTable::ValidateAndSetOpcode<true, false>(uint16 /*opcode*/, char const* name, SessionStatus /*status*/, PacketProcessing /*processing*/, pOpcodeHandler /*handler*/)
+void OpcodeTable::ValidateAndSetOpcode<true, false>(OpcodeClient /*opcode*/, char const* name, SessionStatus /*status*/, PacketProcessing /*processing*/, pOpcodeHandler /*handler*/)
+{
+ TC_LOG_ERROR("network", "Opcode %s got value 0", name);
+}
+
+template<>
+void OpcodeTable::ValidateAndSetOpcode<true, false>(OpcodeServer /*opcode*/, char const* name, SessionStatus /*status*/, PacketProcessing /*processing*/, pOpcodeHandler /*handler*/)
{
TC_LOG_ERROR("network", "Opcode %s got value 0", name);
}
diff --git a/src/server/game/Server/Protocol/Opcodes.h b/src/server/game/Server/Protocol/Opcodes.h
index 3ba5864d913..acd40f41aa7 100644
--- a/src/server/game/Server/Protocol/Opcodes.h
+++ b/src/server/game/Server/Protocol/Opcodes.h
@@ -25,15 +25,18 @@
#include "Common.h"
-/// List of Opcodes
-enum Opcodes
+enum OpcodeMisc : uint32
{
- MAX_OPCODE = 0x1FFF,
- NUM_OPCODE_HANDLERS = (MAX_OPCODE+1),
- UNKNOWN_OPCODE = (0xFFFF+1),
- NULL_OPCODE = 0,
- COMPRESSED_OPCODE_MASK = 0x8000,
+ MAX_OPCODE = 0x1FFF,
+ NUM_OPCODE_HANDLERS = (MAX_OPCODE + 1),
+ UNKNOWN_OPCODE = (0xFFFF + 1),
+ NULL_OPCODE = 0,
+ COMPRESSED_OPCODE_MASK = 0x8000
+};
+// CMSGs
+enum OpcodeClient : uint32
+{
CMSG_ACCEPT_LEVEL_GRANT = 0x0000,
CMSG_ACCEPT_TRADE = 0x0000,
CMSG_ACTIVATETAXI = 0x0000,
@@ -657,7 +660,12 @@ enum Opcodes
MSG_SET_DUNGEON_DIFFICULTY = 0x0000,
MSG_SET_RAID_DIFFICULTY = 0x0000,
MSG_TABARDVENDOR_ACTIVATE = 0x0000,
- MSG_TALENT_WIPE_CONFIRM = 0x0000,
+ MSG_TALENT_WIPE_CONFIRM = 0x0000
+};
+
+// SMSGs
+enum OpcodeServer : uint32
+{
SMSG_ACCOUNT_DATA_TIMES = 0x11AC,
SMSG_ACCOUNT_INFO_RESPONSE = 0x0000,
SMSG_ACCOUNT_RESTRICTED_WARNING = 0x0000,
@@ -1444,31 +1452,43 @@ class OpcodeTable
public:
OpcodeTable()
{
- memset(_internalTable, 0, sizeof(_internalTable));
+ memset(_internalTableClient, 0, sizeof(_internalTableClient));
+ memset(_internalTableServer, 0, sizeof(_internalTableServer));
}
+ OpcodeTable(OpcodeTable const&) = delete;
+ OpcodeTable& operator=(OpcodeTable const&) = delete;
+
~OpcodeTable()
{
for (uint16 i = 0; i < NUM_OPCODE_HANDLERS; ++i)
- delete _internalTable[i];
+ {
+ delete _internalTableClient[i];
+ delete _internalTableServer[i];
+ }
}
void Initialize();
- OpcodeHandler const* operator[](uint32 index) const
+ OpcodeHandler const* operator[](OpcodeClient index) const
{
- return _internalTable[index];
+ return _internalTableClient[index];
+ }
+
+ OpcodeHandler const* operator[](OpcodeServer index) const
+ {
+ return _internalTableServer[index];
}
private:
template<bool isInValidRange, bool isNonZero>
- void ValidateAndSetOpcode(uint16 opcode, char const* name, SessionStatus status, PacketProcessing processing, pOpcodeHandler handler);
+ void ValidateAndSetOpcode(OpcodeClient opcode, char const* name, SessionStatus status, PacketProcessing processing, pOpcodeHandler handler);
- // Prevent copying this structure
- OpcodeTable(OpcodeTable const&);
- OpcodeTable& operator=(OpcodeTable const&);
+ template<bool isInValidRange, bool isNonZero>
+ void ValidateAndSetOpcode(OpcodeServer opcode, char const* name, SessionStatus status, PacketProcessing processing, pOpcodeHandler handler);
- OpcodeHandler* _internalTable[NUM_OPCODE_HANDLERS];
+ OpcodeHandler* _internalTableClient[NUM_OPCODE_HANDLERS];
+ OpcodeHandler* _internalTableServer[NUM_OPCODE_HANDLERS];
};
extern OpcodeTable opcodeTable;
@@ -1481,8 +1501,9 @@ extern OpcodeTable opcodeTable;
void InitOpcodes();
-/// Lookup opcode name for human understandable logging
-inline std::string GetOpcodeNameForLogging(Opcodes id)
+/// Lookup opcode name for human understandable logging (T = OpcodeClient|OpcodeServer)
+template<typename T>
+inline std::string GetOpcodeNameForLogging(T id)
{
uint32 opcode = uint32(id);
std::ostringstream ss;
@@ -1490,7 +1511,7 @@ inline std::string GetOpcodeNameForLogging(Opcodes id)
if (id < UNKNOWN_OPCODE)
{
- if (OpcodeHandler const* handler = opcodeTable[uint32(id) & 0x7FFF])
+ if (OpcodeHandler const* handler = opcodeTable[T(opcode & 0x7FFF)])
{
ss << handler->Name;
if (opcode & COMPRESSED_OPCODE_MASK)
@@ -1506,5 +1527,6 @@ inline std::string GetOpcodeNameForLogging(Opcodes id)
return ss.str();
}
+
#endif
/// @}