diff --git a/src/server/game/Handlers/MovementHandler.cpp b/src/server/game/Handlers/MovementHandler.cpp
index 193135c5067..0cc9263bfbd 100644
--- a/src/server/game/Handlers/MovementHandler.cpp
+++ b/src/server/game/Handlers/MovementHandler.cpp
@@ -422,7 +422,6 @@ void WorldSession::HandleMovementOpcodes(WorldPacket& recvPacket)
void WorldSession::HandleForceSpeedChangeAck(WorldPacket &recvData)
{
uint32 opcode = recvData.GetOpcode();
- sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Recvd %s (%u, 0x%X) opcode", LookupOpcodeName(Opcodes(opcode)), opcode, opcode);
/* extract packet */
uint64 guid;
diff --git a/src/server/game/Server/Protocol/Opcodes.cpp b/src/server/game/Server/Protocol/Opcodes.cpp
index b25a7d3f1c6..f4f77dbe702 100644
--- a/src/server/game/Server/Protocol/Opcodes.cpp
+++ b/src/server/game/Server/Protocol/Opcodes.cpp
@@ -16,30 +16,41 @@
* with this program. If not, see .
*/
-/** \file
- \ingroup u2w
-*/
-
#include "Opcodes.h"
#include "WorldSession.h"
OpcodeHandler* opcodeTable[NUM_OPCODE_HANDLERS] = { };
+template
+inline void ValidateAndSetOpcode(uint16 opcode, char const* name, SessionStatus status, PacketProcessing processing, pOpcodeHandler handler)
+{
+ if (opcodeTable[opcode] != NULL)
+ {
+ sLog->outError(LOG_FILTER_NETWORKIO, "Tried to override handler of %s with %s (opcode %u)", opcodeTable[opcode]->name, name, opcode);
+ return;
+ }
+
+ opcodeTable[opcode] = new OpcodeHandler(name, status, processing, handler);
+}
+
+template<>
+void ValidateAndSetOpcode(uint16 opcode, char const* /*name*/, SessionStatus /*status*/, PacketProcessing /*processing*/, pOpcodeHandler /*handler*/)
+{
+ sLog->outError(LOG_FILTER_NETWORKIO, "Tried to set handler for an invalid opcode %d", opcode);
+}
+
+template<>
+void ValidateAndSetOpcode(uint16 /*opcode*/, char const* name, SessionStatus /*status*/, PacketProcessing /*processing*/, pOpcodeHandler /*handler*/)
+{
+ sLog->outError(LOG_FILTER_NETWORKIO, "Opcode %s got value 0", name);
+}
+
+#define DEFINE_OPCODE_HANDLER(opcode, status, processing, handler) \
+ ValidateAndSetOpcode<(opcode < NUM_OPCODE_HANDLERS), (opcode != 0)>(opcode, #opcode, status, processing, handler);
+
/// Correspondence between opcodes and their names
void InitOpcodes()
{
-#define DEFINE_OPCODE_HANDLER(opcode, status, processing, handler) \
- if (opcode == 0) \
- sLog->outError(LOG_FILTER_NETWORKIO, "Opcode %s got value 0", #opcode); \
- if (opcode < NUM_OPCODE_HANDLERS) { \
- if (opcodeTable[opcode] != NULL) \
- { \
- sLog->outError(LOG_FILTER_NETWORKIO, "Tried to override handler of %s with %s (opcode %u)", \
- opcodeTable[opcode]->name, #opcode, opcode); \
- } \
- else opcodeTable[opcode] = new OpcodeHandler(#opcode, #opcode "_COMPRESSED", status, processing, handler); \
- }
-
memset(opcodeTable, 0, sizeof(opcodeTable));
DEFINE_OPCODE_HANDLER(CMSG_ACCEPT_LEVEL_GRANT, STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::HandleAcceptGrantLevel );
diff --git a/src/server/game/Server/Protocol/Opcodes.h b/src/server/game/Server/Protocol/Opcodes.h
index 63da75e8885..b4ccb87f204 100755
--- a/src/server/game/Server/Protocol/Opcodes.h
+++ b/src/server/game/Server/Protocol/Opcodes.h
@@ -1431,11 +1431,10 @@ typedef void(WorldSession::*pOpcodeHandler)(WorldPacket& recvPacket);
struct OpcodeHandler
{
OpcodeHandler() {}
- OpcodeHandler(char const* _name, char const* _compressedName, SessionStatus _status, PacketProcessing _processing, pOpcodeHandler _handler)
- : name(_name), compressedName(_compressedName), status(_status), packetProcessing(_processing), handler(_handler) {}
+ OpcodeHandler(char const* _name, SessionStatus _status, PacketProcessing _processing, pOpcodeHandler _handler)
+ : name(_name), status(_status), packetProcessing(_processing), handler(_handler) {}
char const* name;
- char const* compressedName;
SessionStatus status;
PacketProcessing packetProcessing;
pOpcodeHandler handler;
@@ -1445,26 +1444,28 @@ extern OpcodeHandler* opcodeTable[NUM_OPCODE_HANDLERS];
void InitOpcodes();
/// Lookup opcode name for human understandable logging
-inline const char* LookupOpcodeName(Opcodes id)
-{
- if (id < UNKNOWN_OPCODE)
- {
- bool isCompressed = uint32(id) & COMPRESSED_OPCODE_MASK;
- if (OpcodeHandler* handler = opcodeTable[uint32(id) & 0x7FFF])
- return isCompressed ? handler->compressedName : handler->name;
-
- return "UNKNOWN OPCODE";
- }
-
- return "INVALID OPCODE";
-}
-
inline std::string GetOpcodeNameForLogging(Opcodes id)
{
uint32 opcode = uint32(id);
std::ostringstream ss;
- ss << '[' << LookupOpcodeName(id) << " 0x" << std::hex << std::uppercase << opcode << std::nouppercase << " (" << std::dec << opcode << ")]";
- return ss.str().c_str();
+ ss << '[';
+
+ if (id < UNKNOWN_OPCODE)
+ {
+ if (OpcodeHandler* handler = opcodeTable[uint32(id) & 0x7FFF])
+ {
+ ss << handler->name;
+ if (opcode & COMPRESSED_OPCODE_MASK)
+ ss << "_COMPRESSED";
+ }
+ else
+ ss << "UNKNOWN OPCODE";
+ }
+ else
+ ss << "INVALID OPCODE";
+
+ ss << " 0x" << std::hex << std::uppercase << opcode << std::nouppercase << " (" << std::dec << opcode << ")]";
+ return ss.str();
}
#endif