add parent pointers to eliminate code duplication in many places

This commit is contained in:
Martin Michelsen
2023-09-19 22:15:41 -07:00
parent adad870aff
commit 2eb429436f
25 changed files with 1668 additions and 1705 deletions
+18 -15
View File
@@ -16,7 +16,7 @@
#include "PSOProtocol.hh"
#include "ServerState.hh"
class ProxyServer {
class ProxyServer : public std::enable_shared_from_this<ProxyServer> {
public:
ProxyServer() = delete;
ProxyServer(const ProxyServer&) = delete;
@@ -31,8 +31,8 @@ public:
void connect_client(struct bufferevent* bev, uint16_t server_port);
struct LinkedSession {
ProxyServer* server;
struct LinkedSession : std::enable_shared_from_this<LinkedSession> {
std::weak_ptr<ProxyServer> server;
uint64_t id;
PrefixedLogger log;
@@ -77,13 +77,10 @@ public:
uint32_t next_item_id;
struct LobbyPlayer {
uint32_t guild_card_number;
uint32_t guild_card_number = 0;
std::string name;
uint8_t section_id;
uint8_t char_class;
LobbyPlayer() : guild_card_number(0),
section_id(0),
char_class(0) {}
uint8_t section_id = 0;
uint8_t char_class = 0;
};
std::vector<LobbyPlayer> lobby_players;
size_t lobby_client_id;
@@ -115,29 +112,32 @@ public:
// TODO: This first constructor should be private
LinkedSession(
ProxyServer* server,
std::shared_ptr<ProxyServer> server,
uint64_t id,
uint16_t local_port,
GameVersion version);
LinkedSession(
ProxyServer* server,
std::shared_ptr<ProxyServer> server,
uint16_t local_port,
GameVersion version,
std::shared_ptr<const License> license,
const ClientConfigBB& newserv_client_config);
LinkedSession(
ProxyServer* server,
std::shared_ptr<ProxyServer> server,
uint16_t local_port,
GameVersion version,
std::shared_ptr<const License> license,
const struct sockaddr_storage& next_destination);
LinkedSession(
ProxyServer* server,
std::shared_ptr<ProxyServer> server,
uint64_t id,
uint16_t local_port,
GameVersion version,
const struct sockaddr_storage& next_destination);
std::shared_ptr<ProxyServer> require_server() const;
std::shared_ptr<ServerState> require_server_state() const;
void resume(
Channel&& client_channel,
std::shared_ptr<PSOBBMultiKeyDetectorEncryption> detector_crypt,
@@ -205,7 +205,7 @@ private:
};
struct UnlinkedSession {
ProxyServer* server;
std::weak_ptr<ProxyServer> server;
PrefixedLogger log;
Channel channel;
@@ -215,7 +215,10 @@ private:
std::shared_ptr<PSOBBMultiKeyDetectorEncryption> detector_crypt;
UnlinkedSession(ProxyServer* server, struct bufferevent* bev, uint16_t port, GameVersion version);
UnlinkedSession(std::shared_ptr<ProxyServer> server, struct bufferevent* bev, uint16_t port, GameVersion version);
std::shared_ptr<ProxyServer> require_server() const;
std::shared_ptr<ServerState> require_server_state() const;
void receive_and_process_commands();