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 f89125c commit 7ac665e
Show file tree
Hide file tree
Showing 8 changed files with 1,377 additions and 1,333 deletions.
4 changes: 2 additions & 2 deletions src/game/ChatCommands/DebugCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,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 @@ -1436,7 +1436,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 @@ -21770,7 +21770,7 @@ void Player::RemovePetActionBar()
void Player::AddSpellMod(Aura* aura, bool apply)
{
Modifier const* mod = aura->GetModifier();
Opcodes opcode = (mod->m_auraname == SPELL_AURA_ADD_FLAT_MODIFIER) ? SMSG_SET_FLAT_SPELL_MODIFIER : SMSG_SET_PCT_SPELL_MODIFIER;
OpcodesList opcode = (mod->m_auraname == SPELL_AURA_ADD_FLAT_MODIFIER) ? SMSG_SET_FLAT_SPELL_MODIFIER : SMSG_SET_PCT_SPELL_MODIFIER;

for (int eff = 0; eff < 96; ++eff)
{
Expand Down
2,647 changes: 1,335 additions & 1,312 deletions src/game/Server/Opcodes.cpp

Large diffs are not rendered by default.

29 changes: 17 additions & 12 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 @@ -1362,21 +1363,25 @@ enum Opcodes
SMSG_COMMENTATOR_SKIRMISH_QUEUE_RESULT1 = 0x51C,// event EVENT_COMMENTATOR_SKIRMISH_QUEUE_REQUEST, CGCommentator::QueueNode
SMSG_COMMENTATOR_SKIRMISH_QUEUE_RESULT2 = 0x51D,// event EVENT_COMMENTATOR_SKIRMISH_QUEUE_REQUEST
SMSG_COMPRESSED_UNKNOWN_1310 = 0x51E,// some compressed packet
SMSG_PLAYER_NOT_FOUND_FAILURE = 0x523,
SMSG_GM_RESURRECT_FAILURE = 0x524,
SMSG_GM_RESURRECT_SUCCESS = 0x528,
NUM_MSG_TYPES
SMSG_PLAYER_NOT_FOUND_FAILURE = 0x523,
SMSG_GM_RESURRECT_FAILURE = 0x524,
SMSG_GM_RESURRECT_SUCCESS = 0x528,
};

// Don't forget to change this value and add opcode name to Opcodes.cpp when you add new opcode!
#define NUM_MSG_TYPES 0x529

extern void InitializeOpcodes();

/// Player state
enum SessionStatus
{
STATUS_AUTHED = 0, ///< Player authenticated (_player==NULL, m_playerRecentlyLogout = false or will be reset before handler call, m_GUID have garbage)
STATUS_LOGGEDIN, ///< Player in game (_player!=NULL, m_GUID == _player->GetGUID(), inWorld())
STATUS_TRANSFER, ///< Player transferring to another map (_player!=NULL, m_GUID == _player->GetGUID(), !inWorld())
STATUS_LOGGEDIN_OR_RECENTLY_LOGGEDOUT, ///< _player!= NULL or _player==NULL && m_playerRecentlyLogout, m_GUID store last _player guid)
STATUS_NEVER, ///< Opcode not accepted from client (deprecated or server side only)
STATUS_UNHANDLED ///< We don' handle this opcode yet
STATUS_AUTHED = 0, ///< Player authenticated (_player==NULL, m_playerRecentlyLogout = false or will be reset before handler call)
STATUS_LOGGEDIN, ///< Player in game (_player!=NULL, inWorld())
STATUS_TRANSFER, ///< Player transferring to another map (_player!=NULL, !inWorld())
STATUS_LOGGEDIN_OR_RECENTLY_LOGGEDOUT, ///< _player!= NULL or _player==NULL && m_playerRecentlyLogout)
STATUS_NEVER, ///< Opcode not accepted from client (deprecated or server side only)
STATUS_UNHANDLED ///< We don' handle this opcode yet
};

/**
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 @@ -167,6 +167,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
1 change: 1 addition & 0 deletions src/game/Server/WorldSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ class WorldSession

void HandleGameObjectQueryOpcode(WorldPacket& recvPacket);

// Movement Handler
void HandleMoveWorldportAckOpcode(WorldPacket& recvPacket);
void HandleMoveWorldportAckOpcode(); // for server-side calls

Expand Down
3 changes: 1 addition & 2 deletions src/game/Server/WorldSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,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 Expand Up @@ -997,7 +997,6 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
{
WorldPacket packet(SMSG_AUTH_RESPONSE, 1);
packet << uint8(AUTH_FAILED);

SendPacket(packet);

sLog.outError("WorldSocket::HandleAuthSession: Sent Auth Response (authentification failed).");
Expand Down
18 changes: 14 additions & 4 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 @@ -47,13 +48,18 @@ WorldSocketMgr::WorldSocketMgr()
acceptor_(NULL),reactor_(NULL),
sockets_()
{
InitializeOpcodes();
}

WorldSocketMgr::~WorldSocketMgr()
{
if (reactor_) delete reactor_;
if (reactor_)
{
if (acceptor_) delete acceptor_;
delete reactor_;
}
if (acceptor_)
{
delete acceptor_;
}
}

Expand Down Expand Up @@ -140,9 +146,13 @@ int WorldSocketMgr::StartNetwork(ACE_INET_Addr& addr)

void WorldSocketMgr::StopNetwork()
{
if (acceptor_) acceptor_->close();
if (acceptor_)
{
acceptor_->close();
}
if (reactor_)
{
if (reactor_) reactor_->end_reactor_event_loop();
reactor_->end_reactor_event_loop();
}
wait();
}
Expand Down

0 comments on commit 7ac665e

Please sign in to comment.