WorldPacket packet; packet.SetOpcode(OPCODE_LOGIN_REQUEST);
WorldPacket packet; packet.SetOpcode(OPCODE_CHAT_MESSAGE); packet << username << message;Here, a packet is created with an opcode of OPCODE_CHAT_MESSAGE, indicating that the packet contains a chat message. The variables username and message are then written into the packet (using the << operator) before it is sent. This might be used when a client is sending a chat message to the server, which will then broadcast it to all other clients. These examples demonstrate how SetOpcode might be used in a networking library or framework (such as Boost.Asio or RakNet) to set the opcode for a packet before sending it over a connection.