Files
psopeeps-newserv/License.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

67 lines
2.1 KiB
C++

#pragma once
#include <phosg/Concurrency.hh>
#include <unordered_map>
#include <string>
enum Privilege {
KickUser = 0x00000001,
BanUser = 0x00000002,
SilenceUser = 0x00000004,
ChangeLobbyInfo = 0x00000008,
ChangeEvent = 0x00000010,
Announce = 0x00000020,
FreeJoinGames = 0x00000040,
UnlockGames = 0x00000080,
Moderator = 0x00000007,
Administrator = 0x0000003F,
Root = 0xFFFFFFFF,
};
enum LicenseVerifyAction {
BB = 0x00,
GC = 0x01,
PC = 0x02,
SerialNumber = 0x03,
};
struct License {
char username[20]; // BB username (max. 16 chars; should technically be Unicode)
char bb_password[20]; // BB password (max. 16 chars)
uint32_t serial_number; // PC/GC serial number. MUST BE PRESENT FOR BB LICENSES TOO; this is also the player's guild card number.
char access_key[16]; // PC/GC access key. (to log in using PC on a GC license, just enter the first 8 characters of the GC access key)
char gc_password[12]; // GC password
uint32_t privileges; // privilege level
uint64_t ban_end_time; // end time of ban (zero = not banned)
std::string str() const;
} __attribute__((packed));
class LicenseManager {
public:
LicenseManager(const std::string& filename);
~LicenseManager() = default;
std::shared_ptr<const License> verify_pc(uint32_t serial_number,
const char* access_key, const char* password) const;
std::shared_ptr<const License> verify_gc(uint32_t serial_number,
const char* access_key, const char* password) const;
std::shared_ptr<const License> verify_bb(const char* username,
const char* password) const;
void ban_until(uint32_t serial_number, uint64_t seconds);
size_t count() const;
void add(std::shared_ptr<License> l);
void remove(uint32_t serial_number);
std::vector<License> snapshot() const;
protected:
void save() const;
std::string filename;
std::unordered_map<std::string, std::shared_ptr<License>> bb_username_to_license;
std::unordered_map<uint32_t, std::shared_ptr<License>> serial_number_to_license;
};