Files
DarkflameServer/dNet/AuthPackets.h
Aaron Kimbrell 70f1c2b19e refactor: common and auth packets as structs
Adds CommonPackets (ServiceType::COMMON): ClientVersionConfirm (the
client's handshake, with the handler that logs it and answers),
ServerVersionConfirm, DisconnectNotify and GeneralNotify (layout from the
1.10.64 client's PacketHandler_MSG_SERVER_GENERAL_NOTIFY; DLU does not send
it yet). AuthPackets::LoginRequest reads the login and keeps the old login
logic in its Handle; ClientPackets::LoginResponse (with the Stamp list)
replaces the hand written response, and AuthPackets::SendLoginResponse
fills it from the settings as before. dServer::Disconnect writes a
DisconnectNotify. AuthServer's if-chain and WorldServer's COMMON case
become CommonPackets::Handle / AuthPackets::Handle, dispatch maps that
read the struct, drop and log it if it does not deserialize, then Handle.
HandleHandshake and SendHandshake are gone.

No wire change. Verified against a frozen verbatim copy of the old
functions (tests/dGameTests/dNetTests/Legacy): the old handshake and login
handlers and the new dispatchers are fed the same packets and must send
identical bytes to the same address (same RNG seed for the session key),
over grids of versions, service types, ports, response codes, error
messages, IPs and stamp lists; plus hand computed golden bytes, round
trips, truncation checks, and a deliberate field width mutation that made
the tests fail. The only behaviour difference: truncated handshake and
login packets are now dropped instead of handled with whatever was read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 22:30:48 -05:00

75 lines
2.2 KiB
C++

#ifndef AUTHPACKETS_H
#define AUTHPACKETS_H
#define _VARIADIC_MAX 10
#include "dCommonVars.h"
#include "dNetCommon.h"
#include "magic_enum.hpp"
#include "BitStreamUtils.h"
#include "ClientPackets.h"
#include "MessageType/Auth.h"
enum class eLoginResponse : uint8_t;
enum class ServiceType : uint16_t;
class dServer;
enum class ClientOS : uint8_t {
UNKNOWN,
WINDOWS,
MACOS
};
enum class LanguageCodeID : uint16_t {
de_DE = 0x0407,
en_US = 0x0409,
en_GB = 0x0809
};
template <>
struct magic_enum::customize::enum_range<LanguageCodeID> {
static constexpr int min = 1031;
static constexpr int max = 2057;
};
namespace AuthPackets {
// Client -> auth server. The username and password, plus a description of the client's machine.
struct LoginRequest : public LUBitStream {
// Set by the dispatcher before Deserialize and Handle.
SystemAddress sysAddr = UNASSIGNED_SYSTEM_ADDRESS;
LUWString username{ 33 };
LUWString password{ 41 };
LanguageCodeID localeID{};
ClientOS clientOS{};
LUWString memoryStats{ 256 };
LUWString videoCard{ 128 };
// Processor
uint32_t numberOfProcessors{};
uint32_t processorType{};
uint16_t processorLevel{};
uint16_t processorRevision{};
// OS version
uint32_t osVersionInfoSize{};
uint32_t majorVersion{};
uint32_t minorVersion{};
uint32_t buildNumber{};
uint32_t platformID{};
LoginRequest() : LUBitStream(ServiceType::AUTH, MessageType::Auth::LOGIN_REQUEST) {}
void Serialize(RakNet::BitStream& bitStream) const override;
bool Deserialize(RakNet::BitStream& bitStream) override;
void Handle() override;
};
// Handles a ServiceType::AUTH packet whose header has already been read from inStream.
void Handle(RakNet::BitStream& inStream, const SystemAddress& sysAddr, uint32_t packetID);
// Answers a login with a ClientPackets::LoginResponse filled from the server's settings (event gating, client
// version) and a new session key; on success also registers that session key with the master server.
void SendLoginResponse(dServer* server, const SystemAddress& sysAddr, eLoginResponse responseCode, const std::string& errorMsg, const std::string& wServerIP, uint16_t wServerPort, std::string username, std::vector<Stamp>& stamps);
void LoadClaimCodes();
}
#endif // AUTHPACKETS_H