mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 02:43:44 +00:00
refactor: world packets as structs
WorldPackets now holds what a client sends a world server, one struct per packet with Serialize/Deserialize: Validation, CharacterListRequest, CharacterCreateRequest, CharacterLoginRequest, GameMessage, CharacterDeleteRequest, CharacterRenameRequest, LevelLoadComplete, PositionUpdate, MailPacket, RoutePacket, StringCheck, GeneralChatMessage, HandleFunness, UIHelpTop5. WorldServer's switch became a dispatch map of handlers (each overrides Handle in WorldServer.cpp, logic unchanged: dashboard hooks, LoadPlayer, chat logging, migration checks, message inspector capture all still run); a packet that does not deserialize is logged and dropped. UserManager's create/delete/rename take the structs. The answers are ClientPackets (the CLIENT service): LoadStaticZone, CharacterListResponse, CharacterCreateResponse, CharacterRenameResponse, DeleteCharacterResponse, TransferToWorld, ServerStates, CreateCharacter, ChatModerationString, MakeGMResponse, HTTPMonitorInfoResponse and DebugOutput, built at the call sites (world server, UserManager, slash commands, dashboard actions, components, migration). The world -> chat forward of a routed packet is ChatPackets::RoutedFromClient. All WorldPackets::Send* functions, HTTPMonitorInfo and the ClientPackets parse functions are gone. The architecture doc now states the file rule: a packet lives in the file of the ServiceType in its header. No wire change. Verified against frozen verbatim copies of the old code (tests/dGameTests/dNetTests/Legacy/WorldPacketsLegacy.h): every response is sent through the old function and the struct over grids of inputs (all enum values, strings of every length class, IDs, >64 moderation segments, big XML) and must match byte for byte; every request is read by the old code and the struct and must give the same values; plus golden bytes, round trips, truncation checks and a field width mutation that made the tests fail. Only differences: malformed requests are dropped instead of handled with partial values, and LevelLoadComplete now reads the zone ID the client sends after it (lu_packets and captures show the 1.10.64 client always sends it; DLU ignored it). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,41 +1,214 @@
|
||||
#ifndef WORLDPACKETS_H
|
||||
#define WORLDPACKETS_H
|
||||
|
||||
#include "BitStreamUtils.h"
|
||||
#include "ChatPackets.h"
|
||||
#include "dCommonVars.h"
|
||||
#include <vector>
|
||||
#include "eFunnessTypes.h"
|
||||
#include "MessageType/Game.h"
|
||||
#include "MessageType/World.h"
|
||||
#include "PositionUpdate.h"
|
||||
#include "RakNetTypes.h"
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class User;
|
||||
struct SystemAddress;
|
||||
enum class eGameMasterLevel : uint8_t;
|
||||
enum class eCharacterCreationResponse : uint8_t;
|
||||
enum class eRenameResponse : uint8_t;
|
||||
namespace RakNet {
|
||||
class BitStream;
|
||||
};
|
||||
|
||||
struct HTTPMonitorInfo {
|
||||
uint16_t port = 80;
|
||||
bool openWeb = false;
|
||||
bool supportsSum = false;
|
||||
bool supportsDetail = false;
|
||||
bool supportsWho = false;
|
||||
bool supportsObjects = false;
|
||||
void Serialize(RakNet::BitStream &bitstream) const;
|
||||
};
|
||||
|
||||
// Packets of ServiceType::WORLD: what a client sends to a world server. The server's answers are ClientPackets.
|
||||
// The structs only read and write bytes; the world server attaches the handlers (see WorldServer.cpp).
|
||||
namespace WorldPackets {
|
||||
void SendLoadStaticZone(const SystemAddress& sysAddr, float x, float y, float z, uint32_t checksum, LWOZONEID zone);
|
||||
void SendCharacterCreationResponse(const SystemAddress& sysAddr, eCharacterCreationResponse response);
|
||||
void SendCharacterRenameResponse(const SystemAddress& sysAddr, eRenameResponse response);
|
||||
void SendCharacterDeleteResponse(const SystemAddress& sysAddr, bool response);
|
||||
void SendTransferToWorld(const SystemAddress& sysAddr, const std::string& serverIP, uint32_t serverPort, bool mythranShift);
|
||||
void SendServerState(const SystemAddress& sysAddr);
|
||||
void SendCreateCharacter(const SystemAddress& sysAddr, int64_t reputation, LWOOBJID player, const std::string& xmlData, const std::u16string& username, eGameMasterLevel gm, const LWOCLONEID cloneID);
|
||||
void SendChatModerationResponse(const SystemAddress& sysAddr, bool requestAccepted, uint32_t requestID, const std::string& receiver, std::set<std::pair<uint8_t, uint8_t>> unacceptedItems);
|
||||
void SendGMLevelChange(const SystemAddress& sysAddr, bool success, eGameMasterLevel highestLevel, eGameMasterLevel prevLevel, eGameMasterLevel newLevel);
|
||||
void SendHTTPMonitorInfo(const SystemAddress& sysAddr, const HTTPMonitorInfo& info);
|
||||
void SendDebugOuput(const SystemAddress& sysAddr, const std::string& data);
|
||||
// Base of every world packet: the dispatcher sets sysAddr before Deserialize and Handle.
|
||||
struct WorldLUBitStream : public LUBitStream {
|
||||
SystemAddress sysAddr = UNASSIGNED_SYSTEM_ADDRESS;
|
||||
|
||||
WorldLUBitStream() = default;
|
||||
template<typename T>
|
||||
WorldLUBitStream(T internalPacketID) : LUBitStream(ServiceType::WORLD, internalPacketID) {}
|
||||
};
|
||||
|
||||
// Client -> server. Who the client is and the session key auth gave it.
|
||||
struct Validation : public WorldLUBitStream {
|
||||
LUWString username{ 33 };
|
||||
LUWString sessionKey{ 33 };
|
||||
LUString fdbChecksum{ 32 };
|
||||
// The client may send one more byte after the checksum (a null terminator); it is ignored.
|
||||
|
||||
Validation() : WorldLUBitStream(MessageType::World::VALIDATION) {}
|
||||
void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
bool Deserialize(RakNet::BitStream& bitStream) override;
|
||||
};
|
||||
|
||||
// Client -> server. No payload.
|
||||
struct CharacterListRequest : public WorldLUBitStream {
|
||||
CharacterListRequest() : WorldLUBitStream(MessageType::World::CHARACTER_LIST_REQUEST) {}
|
||||
};
|
||||
|
||||
// Client -> server. A new character from the character creator.
|
||||
struct CharacterCreateRequest : public WorldLUBitStream {
|
||||
LUWString name{ 33 };
|
||||
uint32_t firstNameIndex{};
|
||||
uint32_t middleNameIndex{};
|
||||
uint32_t lastNameIndex{};
|
||||
std::array<uint8_t, 9> unknown{}; // Not used by DLU
|
||||
uint32_t shirtColor{};
|
||||
uint32_t shirtStyle{};
|
||||
uint32_t pantsColor{};
|
||||
uint32_t hairStyle{};
|
||||
uint32_t hairColor{};
|
||||
uint32_t leftHand{};
|
||||
uint32_t rightHand{};
|
||||
uint32_t eyebrows{};
|
||||
uint32_t eyes{};
|
||||
uint32_t mouth{};
|
||||
// The client sends one more byte; it is ignored.
|
||||
|
||||
CharacterCreateRequest() : WorldLUBitStream(MessageType::World::CHARACTER_CREATE_REQUEST) {}
|
||||
void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
bool Deserialize(RakNet::BitStream& bitStream) override;
|
||||
};
|
||||
|
||||
// Client -> server. The character the player picked to play.
|
||||
struct CharacterLoginRequest : public WorldLUBitStream {
|
||||
LWOOBJID playerID{};
|
||||
|
||||
CharacterLoginRequest() : WorldLUBitStream(MessageType::World::LOGIN_REQUEST) {}
|
||||
void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
bool Deserialize(RakNet::BitStream& bitStream) override;
|
||||
};
|
||||
|
||||
// Client -> server. A game message; data holds its parameters for GameMessageHandler.
|
||||
struct GameMessage : public WorldLUBitStream {
|
||||
LWOOBJID objectID{};
|
||||
MessageType::Game messageID{};
|
||||
RakNet::BitStream data;
|
||||
|
||||
GameMessage() : WorldLUBitStream(MessageType::World::GAME_MSG) {}
|
||||
void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
bool Deserialize(RakNet::BitStream& bitStream) override;
|
||||
};
|
||||
|
||||
// Client -> server.
|
||||
struct CharacterDeleteRequest : public WorldLUBitStream {
|
||||
LWOOBJID objectID{};
|
||||
|
||||
CharacterDeleteRequest() : WorldLUBitStream(MessageType::World::CHARACTER_DELETE_REQUEST) {}
|
||||
void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
bool Deserialize(RakNet::BitStream& bitStream) override;
|
||||
};
|
||||
|
||||
// Client -> server.
|
||||
struct CharacterRenameRequest : public WorldLUBitStream {
|
||||
LWOOBJID objectID{};
|
||||
LUWString name{ 33 };
|
||||
|
||||
CharacterRenameRequest() : WorldLUBitStream(MessageType::World::CHARACTER_RENAME_REQUEST) {}
|
||||
void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
bool Deserialize(RakNet::BitStream& bitStream) override;
|
||||
};
|
||||
|
||||
// Client -> server. The client finished loading the zone from LoadStaticZone.
|
||||
struct LevelLoadComplete : public WorldLUBitStream {
|
||||
// The zone the client loaded; not used by DLU
|
||||
uint16_t mapID{};
|
||||
uint16_t instanceID{};
|
||||
uint32_t cloneID{};
|
||||
|
||||
LevelLoadComplete() : WorldLUBitStream(MessageType::World::LEVEL_LOAD_COMPLETE) {}
|
||||
void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
bool Deserialize(RakNet::BitStream& bitStream) override;
|
||||
};
|
||||
|
||||
// Client -> server. Where the player's character is.
|
||||
struct PositionUpdate : public WorldLUBitStream {
|
||||
::PositionUpdate update{};
|
||||
// Which optional sections are present
|
||||
bool hasVelocity{};
|
||||
bool hasAngularVelocity{};
|
||||
bool hasLocalSpaceInfo{};
|
||||
bool hasLinearVelocity{}; // Inside the local space info
|
||||
bool hasRemoteInputInfo{};
|
||||
|
||||
PositionUpdate() : WorldLUBitStream(MessageType::World::POSITION_UPDATE) {}
|
||||
void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
bool Deserialize(RakNet::BitStream& bitStream) override;
|
||||
};
|
||||
|
||||
// Client -> server. A mail request; data holds it for Mail::HandleMail (which has its own sub-header).
|
||||
struct MailPacket : public WorldLUBitStream {
|
||||
RakNet::BitStream data;
|
||||
|
||||
MailPacket() : WorldLUBitStream(MessageType::World::MAIL) {}
|
||||
void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
bool Deserialize(RakNet::BitStream& bitStream) override;
|
||||
};
|
||||
|
||||
// Client -> server. A packet for the chat server, wrapped: its size, then the chat packet's own header
|
||||
// (service, id, pad) and body.
|
||||
struct RoutePacket : public WorldLUBitStream {
|
||||
uint32_t size{};
|
||||
ServiceType routedService{};
|
||||
uint32_t routedMessageID{};
|
||||
uint8_t padding{};
|
||||
std::vector<uint8_t> routedData{}; // Everything after the routed header
|
||||
|
||||
RoutePacket() : WorldLUBitStream(MessageType::World::ROUTE_PACKET) {}
|
||||
void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
bool Deserialize(RakNet::BitStream& bitStream) override;
|
||||
|
||||
// What DLU forwards to the chat server: the first byte of the routed id, the sender, then at most size bytes
|
||||
// of the routed data from 4 bytes in (the chat server skips 4 bytes after the sender ID it reads).
|
||||
ChatPackets::RoutedFromClient ToChat(LWOOBJID senderID) const;
|
||||
};
|
||||
|
||||
// Client -> server. Asks whether what the player is typing may be sent.
|
||||
struct StringCheck : public WorldLUBitStream {
|
||||
uint8_t chatLevel{};
|
||||
uint8_t requestID{};
|
||||
std::u16string receiver = std::u16string(42, u'\0'); // Always 42 characters on the wire
|
||||
std::u16string message{}; // After a u16 character count
|
||||
|
||||
StringCheck() : WorldLUBitStream(MessageType::World::STRING_CHECK) {}
|
||||
void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
bool Deserialize(RakNet::BitStream& bitStream) override;
|
||||
|
||||
// The receiver as DLU has always used it: each character cut to one byte, all 42 of them (the text is
|
||||
// followed by nulls and whatever else the client left in its buffer), without a leading "[GM]".
|
||||
std::string GetNarrowReceiver() const;
|
||||
// The message with each character cut to one byte.
|
||||
std::string GetNarrowMessage() const;
|
||||
};
|
||||
|
||||
// Client -> server. A message in the zone's chat.
|
||||
struct GeneralChatMessage : public WorldLUBitStream {
|
||||
uint8_t chatChannel{};
|
||||
uint16_t unknown{};
|
||||
// On the wire: an i32 count that includes a null terminator, the characters, then the terminator
|
||||
std::u16string message{};
|
||||
|
||||
GeneralChatMessage() : WorldLUBitStream(MessageType::World::GENERAL_CHAT_MESSAGE) {}
|
||||
void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
bool Deserialize(RakNet::BitStream& bitStream) override;
|
||||
};
|
||||
|
||||
// Client -> server. The client's anti cheat noticed something.
|
||||
struct HandleFunness : public WorldLUBitStream {
|
||||
float cheatInfo{};
|
||||
eFunnessTypes cheatType{};
|
||||
|
||||
HandleFunness() : WorldLUBitStream(MessageType::World::HANDLE_FUNNESS) {}
|
||||
void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
bool Deserialize(RakNet::BitStream& bitStream) override;
|
||||
};
|
||||
|
||||
// Client -> server. The help screen wants its top 5 issues.
|
||||
struct UIHelpTop5 : public WorldLUBitStream {
|
||||
int32_t language{}; // 0: en_US, 1: pl_US, 2: de_DE, 3: en_GB
|
||||
|
||||
UIHelpTop5() : WorldLUBitStream(MessageType::World::UI_HELP_TOP_5) {}
|
||||
void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
bool Deserialize(RakNet::BitStream& bitStream) override;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // WORLDPACKETS_H
|
||||
|
||||
Reference in New Issue
Block a user