diff --git a/manual/chapters/07-network.typ b/manual/chapters/07-network.typ index 9a796df..3608f3c 100644 --- a/manual/chapters/07-network.typ +++ b/manual/chapters/07-network.typ @@ -22,7 +22,7 @@ With `[master] enabled`, the server announces itself to our master server every - `url` empty: the server is not listed and no browser can find it. - `SP_MASTER=0` keeps a run off the list; use it for every test server (tests, benchmarks and the install script's test start do). - `SP_MASTER_URL` replaces the address and turns the list on; `SP_MASTER_KEY` points at another key. -- The 0.75 profile also announces to the public 0.75 master (`[master075]`, default `67.205.183.163:32886`, 32 players at most). A server in both lists is shown once, as ours. +- The 0.75 profile also announces to the public 0.75 masters (`[master075]`; the shipped config lists `67.205.183.163:32886`, Build and Shoot, and `66.135.15.57:32886`, mastercgi; the code's default is the first). The announce carries the server's real player limit (32 at most) and the name, mode and map cut to 31, 7 and 20 bytes, because mastercgi drops an announce with longer ones. A server in both lists is shown once, as ours. - `[server] master` is a leftover switch: on a 1.0 server it only logs `Not announcing on the 0.75 master list`. === Connect tokens diff --git a/server/Resources/config-075.toml b/server/Resources/config-075.toml index d3a0802..6600fdb 100644 --- a/server/Resources/config-075.toml +++ b/server/Resources/config-075.toml @@ -174,10 +174,12 @@ country = "" # The public 0.75 master (docs/plan-075-server.md 8.6), the one the vanilla # clients' lists read (services.buildandshoot.com): the classic ENet # announce, 32 players at most. A server in both lists is listed once, as -# ours. SP_MASTER=0 turns it off. +# ours. SP_MASTER=0 turns it off. Up to 4 addresses; 66.135.15.57 is +# mastercgi (LSD's default list). Name, mode and map are cut to 31, 7 and +# 20 bytes, the most mastercgi keeps. [master075] enabled = true -address = "67.205.183.163:32886" +address = ["67.205.183.163:32886", "66.135.15.57:32886"] # The 0.75 protocol extensions the server offers (plan 7.4, the aosprotocol # specification, github.com/zerospades/aosprotocol), each only to the diff --git a/server/Source/Server/Legacy/Master075.c b/server/Source/Server/Legacy/Master075.c index b257305..f9628fa 100644 --- a/server/Source/Server/Legacy/Master075.c +++ b/server/Source/Server/Legacy/Master075.c @@ -35,6 +35,12 @@ #define M075_VERSION 31 /* the master protocol's version, the connect data */ #define M075_MAX_PLAYERS 32 /* the classic limit the list shows */ #define M075_MAX_MASTERS 4 +/* the longest strings the classic masters keep (the bytes before the \0): + the strictest one (mastercgi) drops the whole announce, silently, when one + of them is longer, so every master gets them cut to these */ +#define M075_NAME_MAX 31 +#define M075_MODE_MAX 7 +#define M075_MAP_MAX 20 /* a lost or refused master is tried again after this (the old code's 30 s) */ #define M075_RETRY_NS (30ULL * NANO_IN_SECOND) /* the player count goes out at most once a second (joins come in bursts) */ @@ -153,11 +159,36 @@ static const char* _m075_mode(server_t* server) return ops != NULL ? ops->name : server->gamemode_name; } +/* the server's real limit, at most the classic 32 */ +static int _m075_max_players(server_t* server) +{ + int max = server->protocol.max_players; + return max <= 0 || max > M075_MAX_PLAYERS ? M075_MAX_PLAYERS : max; +} + static int _m075_players(server_t* server) { /* bots count, as on our own list and in HELLOLAN */ - int n = server->protocol.num_players; - return n > M075_MAX_PLAYERS ? M075_MAX_PLAYERS : n; + int n = server->protocol.num_players; + int max = _m075_max_players(server); + return n > max ? max : n; +} + +/* src cut to at most max bytes, never inside a UTF-8 sequence */ +static void _m075_clip(char* dst, size_t dst_size, const char* src, size_t max) +{ + size_t n = src != NULL ? strlen(src) : 0; + if (n > max) { + n = max; + while (n > 0 && ((unsigned char) src[n] & 0xC0) == 0x80) { + n--; /* src[n] continues a character: cut before its start */ + } + } + if (n >= dst_size) { + n = dst_size - 1; + } + memcpy(dst, src != NULL ? src : "", n); + dst[n] = '\0'; } static void _m075_listing(server_t* server, char* out, size_t size) @@ -167,16 +198,18 @@ static void _m075_listing(server_t* server, char* out, size_t size) static void _m075_send_major(server_t* server, m075_master_t* m) { - const char* name = server->server_name; - const char* mode = _m075_mode(server); - const char* map = server->map_name; + char name[M075_NAME_MAX + 1], mode[M075_MODE_MAX + 1], map[M075_MAP_MAX + 1]; + _m075_clip(name, sizeof name, server->server_name, M075_NAME_MAX); + _m075_clip(mode, sizeof mode, _m075_mode(server), M075_MODE_MAX); + _m075_clip(map, sizeof map, server->map_name, M075_MAP_MAX); + int max = _m075_max_players(server); size_t ln = strlen(name) + 1, lm = strlen(mode) + 1, lp = strlen(map) + 1; ENetPacket* packet = enet_packet_create(NULL, 3 + ln + lm + lp, ENET_PACKET_FLAG_RELIABLE); if (packet == NULL) { return; } uint8_t* d = packet->data; - d[0] = M075_MAX_PLAYERS; + d[0] = (uint8_t) max; d[1] = (uint8_t) (server->port & 0xFF); d[2] = (uint8_t) (server->port >> 8); memcpy(d + 3, name, ln); @@ -193,7 +226,7 @@ static void _m075_send_major(server_t* server, m075_master_t* m) LOG_STATUS("Announced to the 0.75 master %s as '%s' (%s on %s, port %u)", m->address, name, mode, map, (unsigned) server->port); evt_log(NULL, "master075", "action=listed master=%s name=\"%s\" map=%s mode=%s port=%u max=%d", m->address, name, - map, mode, (unsigned) server->port, M075_MAX_PLAYERS); + map, mode, (unsigned) server->port, max); } static void _m075_send_count(server_t* server, m075_master_t* m, uint64_t now)