Skip to content

Commit

Permalink
Port Opcode system from MangosThree
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1arm committed Aug 27, 2024
1 parent 6ead39b commit 6a7ae14
Show file tree
Hide file tree
Showing 7 changed files with 1,101 additions and 1,067 deletions.
4 changes: 2 additions & 2 deletions src/game/ChatCommands/DebugCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ bool ChatHandler::HandleDebugSendOpcodeCommand(char* /*args*/)
return false;
}

WorldPacket data(Opcodes(opcode), 0);
WorldPacket data(OpcodesList(opcode), 0);

std::string type;
while (stream >> type)
Expand Down Expand Up @@ -1392,7 +1392,7 @@ bool ChatHandler::HandleDebugSpellModsCommand(char* args)
return false;
}

Opcodes opcode;
OpcodesList opcode;
if (strncmp(typeStr, "flat", strlen(typeStr)) == 0)
{
opcode = SMSG_SET_FLAT_SPELL_MODIFIER;
Expand Down
2 changes: 1 addition & 1 deletion src/game/Object/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20359,7 +20359,7 @@ bool Player::IsAffectedBySpellmod(SpellEntry const* spellInfo, SpellModifier* mo

void Player::AddSpellMod(SpellModifier* mod, bool apply)
{
Opcodes opcode = (mod->type == SPELLMOD_FLAT) ? SMSG_SET_FLAT_SPELL_MODIFIER : SMSG_SET_PCT_SPELL_MODIFIER;
OpcodesList opcode = (mod->type == SPELLMOD_FLAT) ? SMSG_SET_FLAT_SPELL_MODIFIER : SMSG_SET_PCT_SPELL_MODIFIER;

for (int eff = 0; eff < 64; ++eff)
{
Expand Down
2,145 changes: 1,084 additions & 1,061 deletions src/game/Server/Opcodes.cpp

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/game/Server/Opcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define MANGOS_H_OPCODES

#include "Common.h"
#include "Policies/Singleton.h"

// Note: this include need for be sure have full definition of class WorldSession
// if this class definition not complite then VS for x64 release use different size for
Expand All @@ -49,7 +50,7 @@
* \see WorldPacket
* \todo Replace the Pack GUID part with a packed GUID, ie: it's shorter than usual?
*/
enum Opcodes
enum OpcodesList
{
MSG_NULL_ACTION = 0x000,
CMSG_BOOTME = 0x001,
Expand Down Expand Up @@ -521,7 +522,7 @@ enum Opcodes
CMSG_WRAP_ITEM = 0x1D3,
SMSG_LEVELUP_INFO = 0x1D4,
MSG_MINIMAP_PING = 0x1D5,
SMSG_RESISTLOG = 0x1D6,
SMSG_RESISTLOG = 0x1D6,// GUID, GUID, int32, float, float, int32, int32
SMSG_ENCHANTMENTLOG = 0x1D7,
CMSG_SET_SKILL_CHEAT = 0x1D8,
SMSG_START_MIRROR_TIMER = 0x1D9,
Expand Down Expand Up @@ -1116,6 +1117,8 @@ enum Opcodes
// Don't forget to change this value and add opcode name to Opcodes.cpp when you add new opcode!
#define NUM_MSG_TYPES 0x424

extern void InitializeOpcodes();

/// Player state
enum SessionStatus
{
Expand Down
6 changes: 6 additions & 0 deletions src/game/Server/WorldSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ void WorldSession::SendPacket(WorldPacket const* packet)
return;
}

if (opcodeTable[packet->GetOpcode()].status == STATUS_UNHANDLED)
{
sLog.outError("SESSION: tried to send an unhandled opcode 0x%.4X", packet->GetOpcode());
return;
}

#ifdef MANGOS_DEBUG

// Code for network use statistic
Expand Down
2 changes: 1 addition & 1 deletion src/game/Server/WorldSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ int WorldSocket::handle_input_header(void)

header.size -= 4;

ACE_NEW_RETURN(m_RecvWPct, WorldPacket(Opcodes(header.cmd), header.size), -1);
ACE_NEW_RETURN(m_RecvWPct, WorldPacket(OpcodesList(header.cmd), header.size), -1);

if (header.size > 0)
{
Expand Down
2 changes: 2 additions & 0 deletions src/game/Server/WorldSocketMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "Config/Config.h"
#include "WorldSocket.h"
#include "WorldSocketMgr.h"
#include "Opcodes.h"

#include <ace/ACE.h>
#include <ace/TP_Reactor.h>
Expand All @@ -46,6 +47,7 @@ WorldSocketMgr::WorldSocketMgr()
: m_SockOutKBuff(-1), m_SockOutUBuff(65536), m_UseNoDelay(true),
reactor_(NULL), acceptor_(NULL)
{
InitializeOpcodes();
}

WorldSocketMgr::~WorldSocketMgr()
Expand Down

0 comments on commit 6a7ae14

Please sign in to comment.