Core Network

Opcodes in WoW servers refers to the types of commands that the server and client can send to each others. An opcode corresponds to a specific binary packet structure that the client and server will know how to read.

These opcodes and packet structures all come from reverse-engineering the packets exchanged between Blizzards official servers and the client, meaning it is very hard (and rarely feasible) to change their structure or even what data they should contain.

All opcodes in the game are defined in Opcodes.h, and have three common prefixes:

  • MSG_: Means that the packet is sent both by the server to the clients, and from the clients to the server.
    • For example, movement packets like MSG_MOVE_START_FORWARD and MSG_MOVE_STOP
  • CSMG_: Means that the packet is sent by the client to the server

  • SMSG_: Means that the packet is sent by the server to the client

Both inbound and outbound packets in the game are represented by the WorldPacket class, which is just a basic class that can read and write data from a raw binary buffer.

Sending Packets

When the server sends a packet to the client, it will construct a WorldPacket instance and send it to players usually by any of the following methods:

Receiving Packets

The server can handle incoming packets in one of three PacketProcessing phases:

  • Inplace: Packets handled directly on the network thread, cannot access much of the game world at all and mostly used for unhandled packets.
  • ThreadUnsafe: Packets that need to be handled in the main thread inside World::UpdateSessions.
  • ThreadSafe: Packets that can be handled multithreaded in Map::Update.

There are also various rules deciding for what SessionStatus the player must have for packets to be accepted:

  • Authed: Packet is accepted once the player has authenticated but not entered the game world.

  • Logged In: Packet is accepted if the player has entered the game world.

  • Transferring: Packet is accepted if the player is currently transferring to another map.

  • Logged In or recently logged out: Packet is accepted even if player logged out just recently

  • Never / Unimplemeted: Packet is not handled.

Incoming packet handlers are all registered in Opcodes.cpp.

This registry has the format:

DEFINE_HANDLER(<opcode>,<player_status>,<process_phase>,<handler_function>)

Where:

  • opcode: refers to the numeric opcode as defined in Opcodes.h.
  • player_status: refers to the required SessionPlayers to accept the packet
  • process_phase: refers to what PacketProcessing phase should process the packet
  • handler_function: is a function pointer to the function that should process the packet when the server can handle it.

For example, if we look at the opcode handler for CMSG_CAST_SPELL, we get the following properties: