Files
psopeeps-newserv/Client.hh
T
Martin Michelsen 0d4b0b2279 fix a lot of issues on psogc; add proxy module
- $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
2020-02-16 21:42:29 -08:00

83 lines
2.2 KiB
C++

#pragma once
#include <netinet/in.h>
#include <memory>
#include <phosg/Concurrency.hh>
#include "License.hh"
#include "Player.hh"
#include "PSOEncryption.hh"
enum class ServerBehavior {
SplitReconnect = 0,
LoginServer,
LobbyServer,
DataServerBB,
PatchServer,
};
struct ClientConfig {
uint32_t magic; // must be set to 0x48615467
uint8_t bb_game_state; // status of client connecting on BB
uint8_t bb_player_index; // selected char
uint16_t flags; // just in case we lose them somehow between connections
uint16_t ports[4]; // used by shipgate clients
uint32_t unused[4];
};
struct ClientConfigBB {
ClientConfig cfg;
uint32_t unused[2];
};
struct Client {
// license & account
std::shared_ptr<const License> license;
char16_t name[0x20];
ClientConfigBB config;
GameVersion version;
uint16_t flags;
// encryption
std::unique_ptr<PSOEncryption> crypt_in;
std::unique_ptr<PSOEncryption> crypt_out;
// network
struct sockaddr_storage local_addr;
struct sockaddr_storage remote_addr;
struct bufferevent* bev;
struct sockaddr_storage next_connection_addr;
ServerBehavior server_behavior;
bool should_disconnect;
std::string recv_buffer;
// timing & menus
uint64_t play_time_begin; // time of connection (used for incrementing play time on BB)
uint64_t last_recv_time; // time of last data received
uint64_t last_send_time; // time of last data sent
// lobby/positioning
uint32_t area; // which area is the client in?
uint32_t lobby_id; // which lobby is this person in?
uint8_t lobby_client_id; // which client number is this person?
uint8_t lobby_arrow_color; // lobby arrow color ID
Player player;
// miscellaneous (used by chat commands)
uint32_t next_exp_value; // next EXP value to give
bool infinite_hp; // cheats enabled
bool infinite_tp; // cheats enabled
bool can_chat;
std::string pending_bb_save_username;
uint8_t pending_bb_save_player_index;
Client(struct bufferevent* bev, GameVersion version,
ServerBehavior server_behavior);
// adds data to the client's output buffer, encrypting it first
bool send(std::string&& data);
};