Skip to content

Commit d4d9908

Browse files
committed
cgame ABI: give all server info, not just selected fields
When the cgame calls trap_LAN_GetServerInfo, pass it the server's entire info string, not just some hard-coded fields. That way we can start using new fields in the server browser without an engine change. Also separate info about the server which does not come from the infostring into a trustedServerInfo_t struct, instead of mixing it into the info string.
1 parent cee882d commit d4d9908

File tree

7 files changed

+29
-78
lines changed

7 files changed

+29
-78
lines changed

src/engine/client/cg_api.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2626

2727
#include "engine/qcommon/q_shared.h"
2828

29+
#define MAX_FEATLABEL_CHARS 32
30+
2931
#define CMD_BACKUP 64
3032
#define CMD_MASK ( CMD_BACKUP - 1 )
3133
// allow a lot of command backups for very fast systems
@@ -87,6 +89,15 @@ enum class serverResponseProtocol_t : uint8_t
8789
IP6,
8890
};
8991

92+
// "Trusted" as in we know it is correct and present, as opposed to the server's info string
93+
// which is self-reported data whose fields may be missing, false or not of the right format
94+
struct trustedServerInfo_t
95+
{
96+
serverResponseProtocol_t responseProto;
97+
char addr[ MAX_ADDR_CHARS ];
98+
char featuredLabel[ MAX_FEATLABEL_CHARS ];
99+
};
100+
90101
using markMsgInput_t = std::pair<
91102
std::vector<std::array<float, 3>>, // points
92103
std::array<float, 3> // projection

src/engine/client/cg_msgdef.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ namespace LAN {
434434
IPC::Reply<int>
435435
>;
436436
using GetServerInfoMsg = IPC::SyncMessage<
437-
IPC::Message<IPC::Id<VM::QVM, CG_LAN_GETSERVERINFO>, int, int, int>,
438-
IPC::Reply<std::string>
437+
IPC::Message<IPC::Id<VM::QVM, CG_LAN_GETSERVERINFO>, int, int>,
438+
IPC::Reply<trustedServerInfo_t, std::string>
439439
>;
440440
using GetServerPingMsg = IPC::SyncMessage<
441441
IPC::Message<IPC::Id<VM::QVM, CG_LAN_GETSERVERPING>, int, int>,

src/engine/client/cl_cgame.cpp

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -395,13 +395,10 @@ static int LAN_GetServerCount( int source )
395395
* LAN_GetServerInfo
396396
* ====================
397397
*/
398-
static void LAN_GetServerInfo( int source, int n, char *buf, int buflen )
398+
static void LAN_GetServerInfo( int source, int n, trustedServerInfo_t &trustedInfo, std::string &info )
399399
{
400-
char info[ MAX_STRING_CHARS ];
401400
serverInfo_t *server = nullptr;
402401

403-
info[ 0 ] = '\0';
404-
405402
switch ( source )
406403
{
407404
case AS_LOCAL:
@@ -421,32 +418,17 @@ static void LAN_GetServerInfo( int source, int n, char *buf, int buflen )
421418
break;
422419
}
423420

424-
if ( server && buf )
421+
if ( server )
425422
{
426-
buf[ 0 ] = '\0';
427-
Info_SetValueForKey( info, "hostname", server->hostName, false );
428-
Info_SetValueForKey( info, "serverload", va( "%i", server->load ), false );
429-
Info_SetValueForKey( info, "mapname", server->mapName, false );
430-
Info_SetValueForKey( info, "label", server->label, false );
431-
Info_SetValueForKey( info, "clients", va( "%i", server->clients ), false );
432-
Info_SetValueForKey( info, "bots", va( "%i", server->bots ), false );
433-
Info_SetValueForKey( info, "sv_maxclients", va( "%i", server->maxClients ), false );
434-
Info_SetValueForKey( info, "ping", va( "%i", server->ping ), false );
435-
Info_SetValueForKey( info, "minping", va( "%i", server->minPing ), false );
436-
Info_SetValueForKey( info, "maxping", va( "%i", server->maxPing ), false );
437-
Info_SetValueForKey( info, "game", server->game, false );
438-
Info_SetValueForKey( info, "nettype", Util::enum_str( server->responseProto ), false );
439-
Info_SetValueForKey( info, "addr", Net::AddressToString( server->adr, true ).c_str(), false );
440-
Info_SetValueForKey( info, "needpass", va( "%i", server->needpass ), false ); // NERVE - SMF
441-
Info_SetValueForKey( info, "gamename", server->gameName, false ); // Arnout
442-
Q_strncpyz( buf, info, buflen );
423+
trustedInfo.responseProto = server->responseProto;
424+
Q_strncpyz( trustedInfo.addr, Net::AddressToString( server->adr, true ).c_str(), sizeof( trustedInfo.addr ) );
425+
Q_strncpyz( trustedInfo.featuredLabel, server->label, sizeof( trustedInfo.featuredLabel ) );
426+
info = server->infoString;
443427
}
444428
else
445429
{
446-
if ( buf )
447-
{
448-
buf[ 0 ] = '\0';
449-
}
430+
trustedInfo = {};
431+
info.clear();
450432
}
451433
}
452434

@@ -1419,11 +1401,8 @@ void CGameVM::QVMSyscall(int syscallNum, Util::Reader& reader, IPC::Channel& cha
14191401
break;
14201402

14211403
case CG_LAN_GETSERVERINFO:
1422-
IPC::HandleMsg<LAN::GetServerInfoMsg>(channel, std::move(reader), [this] (int source, int n, int len, std::string& info) {
1423-
std::unique_ptr<char[]> buffer(new char[len]);
1424-
buffer[0] = '\0';
1425-
LAN_GetServerInfo(source, n, buffer.get(), len);
1426-
info.assign(buffer.get());
1404+
IPC::HandleMsg<LAN::GetServerInfoMsg>(channel, std::move(reader), [this] (int source, int n, trustedServerInfo_t& trustedInfo, std::string& info) {
1405+
LAN_GetServerInfo(source, n, trustedInfo, info);
14271406
});
14281407
break;
14291408

src/engine/client/cl_serverlist.cpp

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,10 @@ CL_InitServerInfo
8282
static void CL_InitServerInfo( serverInfo_t *server, netadr_t *address )
8383
{
8484
server->adr = *address;
85-
server->clients = 0;
86-
server->hostName[ 0 ] = '\0';
87-
server->mapName[ 0 ] = '\0';
8885
server->label[ 0 ] = '\0';
89-
server->maxClients = 0;
90-
server->maxPing = 0;
91-
server->minPing = 0;
9286
server->pingStatus = pingStatus_t::WAITING;
9387
server->pingAttempts = 0;
9488
server->ping = -1;
95-
server->game[ 0 ] = '\0';
9689
server->responseProto = serverResponseProtocol_t::UNKNOWN;
9790
}
9891

@@ -492,17 +485,7 @@ static void CL_SetServerInfo(
492485
{
493486
if ( info )
494487
{
495-
server->clients = atoi( Info_ValueForKey( info, "clients" ) );
496-
server->bots = atoi( Info_ValueForKey( info, "bots" ) );
497-
Q_strncpyz( server->hostName, Info_ValueForKey( info, "hostname" ), MAX_NAME_LENGTH );
498-
server->load = atoi( Info_ValueForKey( info, "serverload" ) );
499-
Q_strncpyz( server->mapName, Info_ValueForKey( info, "mapname" ), MAX_NAME_LENGTH );
500-
server->maxClients = atoi( Info_ValueForKey( info, "sv_maxclients" ) );
501-
Q_strncpyz( server->game, Info_ValueForKey( info, "game" ), MAX_NAME_LENGTH );
502-
server->minPing = atoi( Info_ValueForKey( info, "minping" ) );
503-
server->maxPing = atoi( Info_ValueForKey( info, "maxping" ) );
504-
server->needpass = atoi( Info_ValueForKey( info, "g_needpass" ) ); // NERVE - SMF
505-
Q_strncpyz( server->gameName, Info_ValueForKey( info, "gamename" ), MAX_NAME_LENGTH ); // Arnout
488+
server->infoString = info;
506489
}
507490

508491
server->responseProto = proto;
@@ -640,20 +623,11 @@ void CL_ServerInfoPacket( const netadr_t& from, msg_t *msg )
640623
// add this to the list
641624
cls.numlocalservers = i + 1;
642625
cls.localServers[ i ].adr = from;
643-
cls.localServers[ i ].clients = 0;
644-
cls.localServers[ i ].hostName[ 0 ] = '\0';
645-
cls.localServers[ i ].load = -1;
646-
cls.localServers[ i ].mapName[ 0 ] = '\0';
647-
cls.localServers[ i ].maxClients = 0;
648-
cls.localServers[ i ].maxPing = 0;
649-
cls.localServers[ i ].minPing = 0;
650626
cls.localServers[ i ].ping = -1;
651627
cls.localServers[ i ].pingStatus = pingStatus_t::WAITING;
652628
cls.localServers[ i ].pingAttempts = 0;
653-
cls.localServers[ i ].game[ 0 ] = '\0';
654629
cls.localServers[ i ].responseProto = serverResponseProtocol_t::UNKNOWN;
655-
cls.localServers[ i ].needpass = 0;
656-
cls.localServers[ i ].gameName[ 0 ] = '\0'; // Arnout
630+
cls.localServers[ i ].infoString.clear();
657631

658632
Q_strncpyz( info, MSG_ReadString( msg ), MAX_INFO_STRING );
659633

src/engine/client/client.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,27 +250,16 @@ enum class pingStatus_t
250250
TIMEOUT,
251251
};
252252

253-
#define MAX_FEATLABEL_CHARS 32
254253
struct serverInfo_t
255254
{
256255
netadr_t adr;
257-
char hostName[ MAX_NAME_LENGTH ];
258-
int load;
259-
char mapName[ MAX_NAME_LENGTH ];
260-
char game[ MAX_NAME_LENGTH ];
261256
char label[ MAX_FEATLABEL_CHARS ]; // for featured servers, nullptr otherwise
262257
serverResponseProtocol_t responseProto;
263-
int clients;
264-
int bots;
265-
int maxClients;
266-
int minPing;
267-
int maxPing;
268258
pingStatus_t pingStatus;
269259
int ping;
270260
int pingAttempts;
271261
bool visible;
272-
int needpass;
273-
char gameName[ MAX_NAME_LENGTH ]; // Arnout
262+
std::string infoString;
274263
};
275264

276265
struct clientStatic_t

src/shared/client/cg_api.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,11 +627,9 @@ int trap_LAN_GetServerCount( int source )
627627
return count;
628628
}
629629

630-
void trap_LAN_GetServerInfo( int source, int n, char *buf, int buflen )
630+
void trap_LAN_GetServerInfo( int source, int n, trustedServerInfo_t &trustedInfo, std::string &info )
631631
{
632-
std::string info;
633-
VM::SendMsg<LAN::GetServerInfoMsg>(source, n, buflen, info);
634-
Q_strncpyz(buf, info.c_str(), buflen);
632+
VM::SendMsg<LAN::GetServerInfoMsg>(source, n, trustedInfo, info);
635633
}
636634

637635
int trap_LAN_GetServerPing( int source, int n )

src/shared/client/cg_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void trap_SetColorGrading( int slot, qhandle_t hShader );
124124
void trap_R_ScissorEnable( bool enable );
125125
void trap_R_ScissorSet( int x, int y, int w, int h );
126126
int trap_LAN_GetServerCount( int source );
127-
void trap_LAN_GetServerInfo( int source, int n, char *buf, int buflen );
127+
void trap_LAN_GetServerInfo( int source, int n, trustedServerInfo_t &trustedInfo, std::string &info );
128128
int trap_LAN_GetServerPing( int source, int n );
129129
void trap_LAN_MarkServerVisible( int source, int n, bool visible );
130130
int trap_LAN_ServerIsVisible( int source, int n );

0 commit comments

Comments
 (0)