Skip to content

Commit

Permalink
Initialize opcode table on world socket creation.
Browse files Browse the repository at this point in the history
Fixed disconnect on login.
  • Loading branch information
Fabian committed Aug 17, 2016
1 parent e7b730b commit 5319c06
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/game/Opcodes.cpp
Expand Up @@ -23,7 +23,7 @@
#include "Opcodes.h"
#include "WorldSession.h"

static void DefineOpcode(uint16 opcode, const char* name, SessionStatus status, PacketProcessing packetProcessing, void (WorldSession::*handler)(WorldPacket& recvPacket))
static void DefineOpcode(Opcodes opcode, const char* name, SessionStatus status, PacketProcessing packetProcessing, void (WorldSession::*handler)(WorldPacket& recvPacket))
{
opcodeTable[opcode].name = name;
opcodeTable[opcode].status = status;
Expand All @@ -39,7 +39,7 @@ OpcodeHandler opcodeTable[MAX_OPCODE_TABLE_SIZE];
void InitializeOpcodes()
{
for(uint16 i = 0; i < MAX_OPCODE_TABLE_SIZE; ++i)
DefineOpcode(i, "UNKNOWN", STATUS_UNHANDLED, PROCESS_INPLACE, &WorldSession::Handle_NULL);
DefineOpcode(Opcodes(i), "UNKNOWN", STATUS_UNHANDLED, PROCESS_INPLACE, &WorldSession::Handle_NULL);

OPCODE(MSG_WOW_CONNECTION, STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_EarlyProccess );
OPCODE(SMSG_AUTH_CHALLENGE, STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_ServerSide );
Expand Down
2 changes: 1 addition & 1 deletion src/game/Opcodes.h
Expand Up @@ -1462,7 +1462,7 @@ struct OpcodeHandler
extern OpcodeHandler opcodeTable[MAX_OPCODE_TABLE_SIZE];

/// Lookup opcode name for human understandable logging
inline const char* LookupOpcodeName(uint16 id)
inline const char* LookupOpcodeName(Opcodes id)
{
return opcodeTable[id].name;
}
Expand Down
4 changes: 2 additions & 2 deletions src/game/Unit.cpp
Expand Up @@ -67,7 +67,7 @@ float baseMoveSpeed[MAX_MOVE_TYPE] =
////////////////////////////////////////////////////////////
// Methods of class MovementInfo

void MovementInfo::Read(ByteBuffer& data, uint16 opcode)
void MovementInfo::Read(ByteBuffer& data, Opcodes opcode)
{
bool hasTransportData = false,
hasMovementFlags = false,
Expand Down Expand Up @@ -268,7 +268,7 @@ void MovementInfo::Read(ByteBuffer& data, uint16 opcode)
}
}

void MovementInfo::Write(ByteBuffer& data, uint16 opcode) const
void MovementInfo::Write(ByteBuffer& data, Opcodes opcode) const
{
bool hasTransportData = !t_guid.IsEmpty();

Expand Down
4 changes: 2 additions & 2 deletions src/game/Unit.h
Expand Up @@ -698,8 +698,8 @@ class MovementInfo
t_time(0), t_seat(-1), t_time2(0), s_pitch(0.0f), fallTime(0), splineElevation(0.0f), byteParam(0) {}

// Read/Write methods
void Read(ByteBuffer& data, uint16 opcode);
void Write(ByteBuffer& data, uint16 opcode) const;
void Read(ByteBuffer& data, Opcodes opcode);
void Write(ByteBuffer& data, Opcodes opcode) const;

// Movement flags manipulations
void AddMovementFlag(MovementFlags f) { moveFlags |= f; }
Expand Down
33 changes: 18 additions & 15 deletions src/game/WorldSocket.cpp
Expand Up @@ -84,7 +84,9 @@ struct ServerPktHeader
WorldSocket::WorldSocket(boost::asio::io_service &service, std::function<void (Socket *)> closeHandler)
: Socket(service, closeHandler), m_lastPingTime(std::chrono::system_clock::time_point::min()), m_sessionFinalized(false),
m_overSpeedPings(0), m_session(nullptr), m_seed(static_cast<uint32>(rand32())), m_useExistingHeader(false)
{}
{
InitializeOpcodes();
}

WorldSocket::~WorldSocket()
{
Expand Down Expand Up @@ -117,14 +119,22 @@ bool WorldSocket::Open()
return false;

std::string ServerToClient = "RLD OF WARCRAFT CONNECTION - SERVER TO CLIENT";
WorldPacket data(MSG_WOW_CONNECTION,46);
WorldPacket data(MSG_WOW_CONNECTION, 46);

data << ServerToClient;

SendPacket(data);

// Send startup packet.
return true;
}

bool WorldSocket::HandleWowConnection(WorldPacket& recvPacket)
{
std::string ClientToServerMsg;
recvPacket >> ClientToServerMsg;

WorldPacket packet (SMSG_AUTH_CHALLENGE, 37);

for (uint32 i = 0; i < 8; i++)
packet << uint32(0);

Expand All @@ -136,13 +146,6 @@ bool WorldSocket::Open()
return true;
}

int WorldSocket::HandleWowConnection(WorldPacket& recvPacket)
{
std::string ClientToServerMsg;
recvPacket >> ClientToServerMsg;
return 0;
}

bool WorldSocket::ProcessIncomingData()
{
ClientPktHeader header;
Expand Down Expand Up @@ -170,7 +173,7 @@ bool WorldSocket::ProcessIncomingData()

// there must always be at least four bytes for the opcode,
// and 0x2800 is the largest supported buffer in the client
if ((header.size < 4) || (header.size > 0x2800))
if ((header.size < 4) || (header.size > 0x2800) && header.cmd != 0x4C524F57)
{
sLog.outError("WorldSocket::ProcessIncomingData: client sent malformed packet size = %u , cmd = %u", header.size, header.cmd);

Expand Down Expand Up @@ -201,11 +204,11 @@ bool WorldSocket::ProcessIncomingData()
if (IsClosed())
return false;

// Dump received packet.
//sLog.outWorldPacketDump(uint32(get_handle()), new_pct->GetOpcode(), new_pct->GetOpcodeName(), new_pct, true);

WorldPacket *pct = new WorldPacket(opcode, validBytesRemaining);

// Dump received packet.
//sLog.outWorldPacketDump(uint32(get_handle()), pct->GetOpcode(), pct->GetOpcodeName(), pct, true);

if (validBytesRemaining)
{
pct->append(InPeak(), validBytesRemaining);
Expand All @@ -216,7 +219,7 @@ bool WorldSocket::ProcessIncomingData()
{
switch (opcode)
{
case MSG_WOW_CONNECTION:
case 0x4C524F57:
return HandleWowConnection(*pct);
case CMSG_AUTH_SESSION:
if (m_session)
Expand Down
2 changes: 1 addition & 1 deletion src/game/WorldSocket.h
Expand Up @@ -116,7 +116,7 @@ class WorldSocket : public MaNGOS::Socket
virtual bool ProcessIncomingData() override;

/// Called on open ,the void* is the acceptor.
int HandleWowConnection(WorldPacket& recvPacket);
bool HandleWowConnection(WorldPacket& recvPacket);

/// Called by ProcessIncoming() on CMSG_AUTH_SESSION.
bool HandleAuthSession(WorldPacket &recvPacket);
Expand Down
2 changes: 1 addition & 1 deletion src/game/movement/MovementStructures.h
Expand Up @@ -2674,7 +2674,7 @@ MovementStatusElements ChangeSeatsOnControlledVehicleSequence[] =
MSEEnd,
};

MovementStatusElements* GetMovementStatusElementsSequence(uint16 opcode)
MovementStatusElements* GetMovementStatusElementsSequence(Opcodes opcode)
{
switch (opcode)
{
Expand Down
2 changes: 1 addition & 1 deletion src/shared/ByteBuffer.h
Expand Up @@ -638,7 +638,7 @@ class ByteBuffer

std::string ReadString()
{
std::string s = 0;
std::string s = "";
(*this) >> s;
return s;
}
Expand Down

0 comments on commit 5319c06

Please sign in to comment.