0d4b0b2279
- $ann implemented - concurrency removed; server is now single-threaded, event-driven and much more stable - rare seed is no longer the game id; ids are sequential from server startup so they weren't random at all before - supports dropping privileges; now you can run it as root so it can open a sockets on low ports, then it will switch to the given user before serving any traffic - newserv now behaves like a proxy if you run it with the --proxy-destination=<IP_OR_HOSTNAME> argument; there's also an (invisible) shell in this mode where you can inject commands to the server or client. e.g. it can always be christmas in the lobby if you do `sc DA 01 00 00` - increased the mtu on PSODolphinConfig's tap0 configuration; this seems to make the connection more stable - fixed some uninitialized memory bugs - the shell is now event-driven and now uses libevent too; unfortunately this means readline doesn't work anymore (no history and vim-like shortcuts) - made network command display consistent for input vs. output (the header appears in both cases now) - fixed bugs in some subcommand handling (the BB logic was being applied to non-BB clients erroneously, causing most item drops not to work at all) - fixed player tags in the short lobby data struct. unclear if this was actually a problem but it was inconsistent with other servers - fixed "unused" field in game join command (actually it appears to be disable_udp and should be 1, not 0) - cleaned up Server abstraction a bit - rewrote some text functions; asan was complaining about the built-in ones for some reason - added an optional welcome message
64 lines
2.4 KiB
C++
64 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include <event2/event.h>
|
|
|
|
#include <unordered_set>
|
|
#include <vector>
|
|
#include <string>
|
|
#include <memory>
|
|
|
|
#include "PSOEncryption.hh"
|
|
#include "PSOProtocol.hh"
|
|
|
|
|
|
|
|
class ProxyServer {
|
|
public:
|
|
ProxyServer() = delete;
|
|
ProxyServer(const ProxyServer&) = delete;
|
|
ProxyServer(ProxyServer&&) = delete;
|
|
ProxyServer(std::shared_ptr<struct event_base> base,
|
|
const struct sockaddr_storage& initial_destination, int listen_port);
|
|
virtual ~ProxyServer() = default;
|
|
|
|
void send_to_client(const std::string& data);
|
|
void send_to_server(const std::string& data);
|
|
|
|
private:
|
|
std::shared_ptr<struct event_base> base;
|
|
std::unique_ptr<struct evconnlistener, void(*)(struct evconnlistener*)> listener;
|
|
std::unique_ptr<struct bufferevent, void(*)(struct bufferevent*)> client_bev;
|
|
std::unique_ptr<struct bufferevent, void(*)(struct bufferevent*)> server_bev;
|
|
struct sockaddr_storage next_destination;
|
|
int listen_port;
|
|
|
|
PSOCommandHeaderDCGC client_input_header;
|
|
PSOCommandHeaderDCGC server_input_header;
|
|
std::shared_ptr<PSOEncryption> client_input_crypt;
|
|
std::shared_ptr<PSOEncryption> client_output_crypt;
|
|
std::shared_ptr<PSOEncryption> server_input_crypt;
|
|
std::shared_ptr<PSOEncryption> server_output_crypt;
|
|
|
|
void send_to_end(const std::string& data, bool to_server);
|
|
|
|
static void dispatch_on_listen_accept(struct evconnlistener* listener,
|
|
evutil_socket_t fd, struct sockaddr *address, int socklen, void* ctx);
|
|
static void dispatch_on_listen_error(struct evconnlistener* listener, void* ctx);
|
|
static void dispatch_on_client_input(struct bufferevent* bev, void* ctx);
|
|
static void dispatch_on_client_error(struct bufferevent* bev, short events,
|
|
void* ctx);
|
|
static void dispatch_on_server_input(struct bufferevent* bev, void* ctx);
|
|
static void dispatch_on_server_error(struct bufferevent* bev, short events,
|
|
void* ctx);
|
|
|
|
void on_listen_accept(struct evconnlistener* listener, evutil_socket_t fd,
|
|
struct sockaddr *address, int socklen);
|
|
void on_listen_error(struct evconnlistener* listener);
|
|
void on_client_input(struct bufferevent* bev);
|
|
void on_client_error(struct bufferevent* bev, short events);
|
|
void on_server_input(struct bufferevent* bev);
|
|
void on_server_error(struct bufferevent* bev, short events);
|
|
|
|
void receive_and_process_commands(bool from_server);
|
|
};
|