Displaying a server list in MenuQC/CSQC
Moderator: InsideQC Admins
8 posts
• Page 1 of 1
Displaying a server list in MenuQC/CSQC
How can I parse the output of net_slist and display it in MenuQC? I tried looking in the nexuiz QC source but I couldn't figure out what it was doing. Any help appreciated!
- c0burn
- Posts: 208
- Joined: Fri Nov 05, 2004 12:48 pm
- Location: Liverpool, England
enum{
SLIST_HOSTCACHEVIEWCOUNT,
SLIST_HOSTCACHETOTALCOUNT,
SLIST_MASTERQUERYCOUNT,
SLIST_MASTERREPLYCOUNT,
SLIST_SERVERQUERYCOUNT,
SLIST_SERVERREPLYCOUNT,
SLIST_SORTFIELD,
SLIST_SORTDESCENDING
};
float gethostcachevalue(float val) = #611
string gethostcachestring(float key, string server) =#612
void resethostcachemasks(void) = #615;
void sethostcachemaskstring(float mask, float fld, string str, float op) = #616;
void sethostcachemasknumber(float mask, float fld, float num, float op) = #617;
void resorthostcache(void) = #618;
void sethostcachesort(float fld, float descending) = #619;
void refreshhostcache(void) = #620;
float gethostcachenumber(float fld, float hostnr) = #621;
float gethostcacheindexforkey(string key) = #622;
void addwantedhostcachekey(string key) = #623;
to print out a list of all server addresses:
refreshhostcache();
waitabit();
shownservers = gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT);
for(i = 0; i < shownservers; i++)
print(gethostcachestring(gethostcacheindexforkey("address"), i), "\n");
obviously cache the result(s) of gethostcacheindexforkey. Other fields include 'map', 'name', 'ping', 'game', 'numplayers', 'maxplayers'. There are some other fields, and servers are potentially able to provide whatever fields they wish via their serverinfo.
more complex use is available if you wish to ask the engine to sort them or filter them, in which case configure that in response to user-clicks, rather than every frame/refresh.
If you're using FTE, the engine might re-sort/filter/add servers to the list each time gethostcachevalue is called to query the counts - note that currently you must query it or FTE might drop packets *cough*.
SLIST_HOSTCACHEVIEWCOUNT,
SLIST_HOSTCACHETOTALCOUNT,
SLIST_MASTERQUERYCOUNT,
SLIST_MASTERREPLYCOUNT,
SLIST_SERVERQUERYCOUNT,
SLIST_SERVERREPLYCOUNT,
SLIST_SORTFIELD,
SLIST_SORTDESCENDING
};
float gethostcachevalue(float val) = #611
string gethostcachestring(float key, string server) =#612
void resethostcachemasks(void) = #615;
void sethostcachemaskstring(float mask, float fld, string str, float op) = #616;
void sethostcachemasknumber(float mask, float fld, float num, float op) = #617;
void resorthostcache(void) = #618;
void sethostcachesort(float fld, float descending) = #619;
void refreshhostcache(void) = #620;
float gethostcachenumber(float fld, float hostnr) = #621;
float gethostcacheindexforkey(string key) = #622;
void addwantedhostcachekey(string key) = #623;
to print out a list of all server addresses:
refreshhostcache();
waitabit();
shownservers = gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT);
for(i = 0; i < shownservers; i++)
print(gethostcachestring(gethostcacheindexforkey("address"), i), "\n");
obviously cache the result(s) of gethostcacheindexforkey. Other fields include 'map', 'name', 'ping', 'game', 'numplayers', 'maxplayers'. There are some other fields, and servers are potentially able to provide whatever fields they wish via their serverinfo.
more complex use is available if you wish to ask the engine to sort them or filter them, in which case configure that in response to user-clicks, rather than every frame/refresh.
If you're using FTE, the engine might re-sort/filter/add servers to the list each time gethostcachevalue is called to query the counts - note that currently you must query it or FTE might drop packets *cough*.
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
Thanks a lot for the help Spike.
I'm getting the error on the console
Seems to be when I call
Any ideas?
I'm using DP btw.
I'm getting the error on the console
- Code: Select all
VM_M_getserverliststring: bad field number passed!
Seems to be when I call
- Code: Select all
print(gethostcachestring(gethostcacheindexforkey("address"), i), "\n");
Any ideas?
I'm using DP btw.
- c0burn
- Posts: 208
- Joined: Fri Nov 05, 2004 12:48 pm
- Location: Liverpool, England
maybe its stupid and doesn't recognise names for built in fields.
instead of gethostcacheindexforkey, hardcode these:
ping=0
map=1
name=2
address=3
numplayers=4
maxplayers=5
gamedir=6
instead of gethostcacheindexforkey, hardcode these:
ping=0
map=1
name=2
address=3
numplayers=4
maxplayers=5
gamedir=6
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
From the DP source...
"address" wasn't valid. Fixed it by using "cname". Thanks again Spike, all working dandy now!
- Code: Select all
if( !strcmp( key, "cname" ) )
PRVM_G_FLOAT( OFS_RETURN ) = SLIF_CNAME;
else if( !strcmp( key, "ping" ) )
PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PING;
else if( !strcmp( key, "game" ) )
PRVM_G_FLOAT( OFS_RETURN ) = SLIF_GAME;
else if( !strcmp( key, "mod" ) )
PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MOD;
else if( !strcmp( key, "map" ) )
PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAP;
else if( !strcmp( key, "name" ) )
PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NAME;
else if( !strcmp( key, "qcstatus" ) )
PRVM_G_FLOAT( OFS_RETURN ) = SLIF_QCSTATUS;
else if( !strcmp( key, "players" ) )
PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PLAYERS;
else if( !strcmp( key, "maxplayers" ) )
PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAXPLAYERS;
else if( !strcmp( key, "numplayers" ) )
PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMPLAYERS;
else if( !strcmp( key, "numbots" ) )
PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMBOTS;
else if( !strcmp( key, "numhumans" ) )
PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMHUMANS;
else if( !strcmp( key, "freeslots" ) )
PRVM_G_FLOAT( OFS_RETURN ) = SLIF_FREESLOTS;
else if( !strcmp( key, "protocol" ) )
PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PROTOCOL;
else if( !strcmp( key, "isfavorite" ) )
PRVM_G_FLOAT( OFS_RETURN ) = SLIF_ISFAVORITE;
else
PRVM_G_FLOAT( OFS_RETURN ) = -1;
"address" wasn't valid. Fixed it by using "cname". Thanks again Spike, all working dandy now!
- c0burn
- Posts: 208
- Joined: Fri Nov 05, 2004 12:48 pm
- Location: Liverpool, England
8 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
