110 lines
3.1 KiB
C++
110 lines
3.1 KiB
C++
#pragma once
|
|
// ClassicParser — 40250 GC packet bodies -> shared world model (EntityStore via
|
|
// its protocol-neutral mut_* API) + login/char-list state.
|
|
// Counterpart of EntityStore::apply() for MT_PROTOCOL=classic.
|
|
// See docs/CLIENT-40250-PORT.md §4 / §5.
|
|
//
|
|
// `body` is the bytes AFTER the 1-byte header (for dynamic packets: after the
|
|
// [header][uint16 size] prefix); `len` its length — i.e. exactly what
|
|
// ClassicStream::on_packet delivers.
|
|
|
|
#include "wire_classic.h"
|
|
|
|
#include "../entity_store.h"
|
|
|
|
#include <cstdint>
|
|
#include <functional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace mtnet::classic {
|
|
|
|
struct CharSlot {
|
|
uint32_t id = 0;
|
|
std::string name;
|
|
uint8_t job = 0;
|
|
uint8_t level = 0;
|
|
uint8_t st = 0, ht = 0, dx = 0, iq = 0;
|
|
uint32_t play_minutes = 0;
|
|
int32_t x = 0, y = 0;
|
|
uint16_t main_part = 0, hair_part = 0;
|
|
uint8_t skill_group = 0;
|
|
// Server requires this character to be renamed before entering the game.
|
|
bool change_name = false;
|
|
uint32_t guild_id = 0;
|
|
std::string guild_name;
|
|
bool empty() const { return id == 0 && name.empty(); }
|
|
};
|
|
|
|
class ClassicParser {
|
|
public:
|
|
struct CharEvent {
|
|
enum Kind { CreateOk, CreateFail, DeleteOk, DeleteFail } kind;
|
|
int slot = -1;
|
|
int fail_type = 0;
|
|
};
|
|
struct NameEvent {
|
|
uint32_t pid = 0;
|
|
std::string name;
|
|
};
|
|
|
|
explicit ClassicParser(EntityStore &world) : m_world(world) {}
|
|
|
|
// one GC packet. returns false to abort the connection.
|
|
bool on_gc(uint8_t header, const uint8_t *body, uint32_t len);
|
|
|
|
// --- login / select state ---
|
|
const std::vector<CharSlot> &char_slots() const { return m_slots; }
|
|
int slot_count() const { return m_slot_count; } // 3 or 4
|
|
uint32_t handle() const { return m_handle; }
|
|
uint32_t random_key() const { return m_random_key; }
|
|
bool char_list_ready() const { return m_char_list_ready; }
|
|
const std::string &login_failure() const { return m_login_failure; }
|
|
uint32_t login_key() const { return m_login_key; } // GC_LOGIN_KEY (auth path)
|
|
uint8_t empire() const { return m_empire; }
|
|
std::vector<CharEvent> drain_char_events() {
|
|
auto v = std::move(m_char_events);
|
|
m_char_events.clear();
|
|
return v;
|
|
}
|
|
std::vector<NameEvent> drain_name_events() {
|
|
auto v = std::move(m_name_events);
|
|
m_name_events.clear();
|
|
return v;
|
|
}
|
|
int drain_guild_make_requests() {
|
|
int count = m_guild_make_requests;
|
|
m_guild_make_requests = 0;
|
|
return count;
|
|
}
|
|
|
|
private:
|
|
template <class T>
|
|
static bool fill(T &t, uint8_t header, const uint8_t *body, uint32_t len) {
|
|
if (len + 1u < sizeof(T)) {
|
|
return false;
|
|
}
|
|
t.header = header;
|
|
std::memcpy(reinterpret_cast<uint8_t *>(&t) + 1, body, sizeof(T) - 1);
|
|
return true;
|
|
}
|
|
void parse_login_success(const SimplePlayer *players, const uint32_t *guild_id,
|
|
const char (*guild_name)[GUILD_NAME_MAX_LEN + 1], int n, uint32_t handle,
|
|
uint32_t rkey);
|
|
|
|
EntityStore &m_world;
|
|
std::vector<CharSlot> m_slots;
|
|
int m_slot_count = 0;
|
|
uint32_t m_handle = 0;
|
|
uint32_t m_random_key = 0;
|
|
uint32_t m_login_key = 0;
|
|
uint8_t m_empire = 0;
|
|
std::vector<CharEvent> m_char_events;
|
|
std::vector<NameEvent> m_name_events;
|
|
int m_guild_make_requests = 0;
|
|
bool m_char_list_ready = false;
|
|
std::string m_login_failure;
|
|
};
|
|
|
|
} // namespace mtnet::classic
|