/*- * wmQStat - WindowMaker/AfterStep/BB/FB/Waimea dockable front-end to * Steve Jankowski's qstat (http://www.qstat.org/). * * Copyright (c) 2003-2005 Alexey Dokuchaev. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $Id: srv_query.c,v 1.16 2005/02/21 10:24:15 danfe Exp $ */ #include #define _SRV_QUERY #include "proto.h" /* * Remember, when parsing time, it is always %d since we told qstat(1) to * emit it this way (via `-ts' switch). Ping is always %d%s, where %s is * either "ms" (milliseconds), "s" (seconds), or "m" (minutes). */ /* * Query Quake-type server (qs, h2s). * XXX Untested! XXX */ void query_q_server(FILE *p, struct player *pl) { fscanf(p, "\t#%*d %d frags %d %*d:%*d %32[^\n]", &pl->frags, &pl->time, pl->name); } /* * Query QuakeWorld-type server (qws, hws). */ void query_qw_server(FILE *p, struct player *pl) { fscanf(p, "\t#%*d %d frags %d@%d%*s %*d:%*d %32[^\n]", &pl->frags, &pl->time, &pl->ping, pl->name); } /* * Query Quake2-type server (q2s, q3s, rws, efs, sns, sgs, kps, hrs, sfs, * jk3s, sgs). * XXX NO_TEAMS (FLAG_PLAYER_TEAMS) XXX */ void query_q2_server(FILE *p, struct player *pl) { fscanf(p, "\t%d frags %d%*s %32[^\n]", &pl->frags, &pl->ping, pl->name); } #if 0 /* * Query Unreal Tournament-type server (ut2s, uns, gps). * Currently, identical to query_q2_server() since we don't support * server flags (FLAG_PLAYER_TEAMS) yet. * XXX NO_TEAMS, Untested! XXX */ void query_ut_server(FILE *p, struct player *pl) { fscanf(p, "\t%d frags %d%*s %32[^\n]", &pl->frags, &pl->ping, pl->name); } /* * Query Shogo: Mobile Armor Division-type server (sgs). * Again, just copy'n'paste from query_q2_server(), for the same * FLAG_PLAYER_TEAMS flag reason (since query_sg_server() does not need it, * and query_q2_server() does not implement it). * XXX Untested! XXX */ void query_sg_server(FILE *p, struct player *pl) { fscanf(p, "\t%d frags %d%*s %32[^\n]", &pl->frags, &pl->ping, pl->name); } #endif /* * Query Half-Life-type server (hls, hl2s, rss, sas, fcs). * Differs to query_q2_server() with just that we want time instead of * ping. Like query_q2_server(), this function is suitable for quite * a number of games out there. */ void query_hl_server(FILE *p, struct player *pl) { fscanf(p, "\t%d frags %d %32[^\n]", &pl->frags, &pl->time, pl->name); } /* * Query Tribes-type server (tbs). * XXX Untested! XXX */ void query_trb_server(FILE *p, struct player *pl) { fscanf(p, "\t%d score team#%*d %d%*s %32[^\n]", &pl->frags, &pl->ping, pl->name); } /* * Query Tribes2-type server (t2s). * XXX Untested! XXX */ void query_trb2_server(FILE *p, struct player *pl) { fscanf(p, "\tscore %d %*s %32[^\n]", &pl->frags, pl->name); } /* * Query BFRIS-type server (bfs). * We use dirty hack here: since there is no time statistics available * for this type of server, but there is extra `score' field, treat it * as it was time, just for the heck ot it. ;-) * XXX Untested! XXX */ void query_bfris_server(FILE *p, struct player *pl) { fscanf(p, "\ttid: %*d, ship: %*d, team: %*s, ping: %d, score: %d," " kills: %d, name: %32[^\n]", &pl->ping, &pl->time, &pl->frags, pl->name); } /* * Query Descent3-type server (d3g, d3s, d3p). * XXX Untested! XXX */ void query_dc3_server(FILE *p, struct player *pl) { fscanf(p, "\t%d frags %*d deaths team#%*d %d%*s %32[^\n]", &pl->frags, &pl->ping, pl->name); } /* * Query Ghost Recon-type server (grs). * It seems that this game is really screwed up: they don't count frags, * but only deaths. I don't get it. *sigh* * Anyway, use `frag' field to store the number of deaths. * XXX Untested! XXX */ void query_ghrec_server(FILE *p, struct player *pl) { fscanf(p, "\tdead=%d team#%*d %32[^\n]", &pl->frags, pl->name); } /* * Query All Seeing Eye-type server (eye, gs2, dm3s). * Strangely, in qstat(1) code, display_eye_player_info() and * display_gs2_player_info() are just the same, unless I'm missing * some mimor but essential difference. Same for DOOM III, wonderful! * XXX NO_TEAMS, Untested! XXX */ void query_eye_server(FILE *p, struct player *pl) { fscanf(p, "\tscore %d %d%*s team#%*d %32[^\n]", &pl->frags, &pl->ping, pl->name); }