/[LeafOK_CVS]/pvpgn-1.7.4/src/client/bnstat.c
ViewVC logotype

Annotation of /pvpgn-1.7.4/src/client/bnstat.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (hide annotations) (vendor branch)
Tue Jun 6 03:41:38 2006 UTC (19 years, 9 months ago) by sysadm
Branch: GNU, MAIN
CVS Tags: arelease, HEAD
Changes since 1.1: +0 -0 lines
Content type: text/x-csrc
no message

1 sysadm 1.1 /*
2     * Copyright (C) 1998,1999,2000 Ross Combs (rocombs@cs.nmsu.edu)
3     *
4     * This program is free software; you can redistribute it and/or
5     * modify it under the terms of the GNU General Public License
6     * as published by the Free Software Foundation; either version 2
7     * of the License, or (at your option) any later version.
8     *
9     * This program is distributed in the hope that it will be useful,
10     * but WITHOUT ANY WARRANTY; without even the implied warranty of
11     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12     * GNU General Public License for more details.
13     *
14     * You should have received a copy of the GNU General Public License
15     * along with this program; if not, write to the Free Software
16     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17     */
18     #include "common/setup_before.h"
19     #include <stdio.h>
20     #ifdef HAVE_STDDEF_H
21     # include <stddef.h>
22     #else
23     # ifndef NULL
24     # define NULL ((void *)0)
25     # endif
26     #endif
27     #ifdef STDC_HEADERS
28     # include <stdlib.h>
29     #endif
30     #include "compat/exitstatus.h"
31     #ifdef HAVE_STRING_H
32     # include <string.h>
33     #else
34     # ifdef HAVE_STRINGS_H
35     # include <strings.h>
36     # endif
37     #endif
38     #ifdef HAVE_MEMORY_H
39     # include <memory.h>
40     #endif
41     #include "compat/memset.h"
42     #include "compat/memcpy.h"
43     #include <ctype.h>
44     #include <errno.h>
45     #include "compat/strerror.h"
46     #ifdef TIME_WITH_SYS_TIME
47     # include <sys/time.h>
48     # include <time.h>
49     #else
50     # ifdef HAVE_SYS_TIME_H
51     # include <sys/time.h>
52     # else
53     # include <time.h>
54     # endif
55     #endif
56     #include "compat/strftime.h"
57     #ifdef HAVE_UNISTD_H
58     # include <unistd.h>
59     #endif
60     #ifdef HAVE_TERMIOS_H
61     # include <termios.h>
62     #endif
63     #include "compat/termios.h"
64     #ifdef HAVE_SYS_TYPES_H
65     # include <sys/types.h>
66     #endif
67     #ifdef HAVE_SYS_SOCKET_H
68     # include <sys/socket.h>
69     #endif
70     #include "compat/socket.h"
71     #include "compat/recv.h"
72     #include "compat/send.h"
73     #ifdef HAVE_SYS_PARAM_H
74     # include <sys/param.h>
75     #endif
76     #ifdef HAVE_NETINET_IN_H
77     # include <netinet/in.h>
78     #endif
79     #include "compat/netinet_in.h"
80     #ifdef HAVE_ARPA_INET_H
81     # include <arpa/inet.h>
82     #endif
83     #include "compat/inet_ntoa.h"
84     #include "compat/psock.h"
85     #include "common/packet.h"
86     #include "common/init_protocol.h"
87     #include "common/udp_protocol.h"
88     #include "common/bnet_protocol.h"
89     #include "common/tag.h"
90     #include "common/bn_type.h"
91     #include "common/field_sizes.h"
92     #include "common/network.h"
93     #include "common/version.h"
94     #include "common/util.h"
95     #ifdef CLIENTDEBUG
96     # include "common/eventlog.h"
97     #endif
98     #include "common/bnettime.h"
99     #include "client.h"
100     #include "udptest.h"
101     #include "client_connect.h"
102     #include "common/setup_after.h"
103    
104    
105     #ifdef CLIENTDEBUG
106     # define dprintf printf
107     #else
108     # define dprintf if (0) printf
109     #endif
110    
111     static char const * bnclass_get_str(unsigned int class); /* FIXME: this is also in command.c */
112     static void usage(char const * progname);
113    
114    
115     static char const * bnclass_get_str(unsigned int class)
116     {
117     switch (class)
118     {
119     case PLAYERINFO_DRTL_CLASS_WARRIOR:
120     return "warrior";
121     case PLAYERINFO_DRTL_CLASS_ROGUE:
122     return "rogue";
123     case PLAYERINFO_DRTL_CLASS_SORCERER:
124     return "sorcerer";
125     default:
126     return "unknown";
127     }
128     }
129    
130    
131     static void usage(char const * progname)
132     {
133     fprintf(stderr,"usage: %s [<options>] [<servername> [<TCP portnumber>]]\n",progname);
134     fprintf(stderr,
135     " -b, --client=SEXP report client as Brood Wars\n"
136     " -d, --client=DRTL report client as Diablo Retail\n"
137     " --client=DSHR report client as Diablo Shareware\n"
138     " -s, --client=STAR report client as Starcraft (default)\n");
139     fprintf(stderr,
140     " --client=SSHR report client as Starcraft Shareware\n"
141     " -w, --client=W2BN report client as Warcraft II BNE\n"
142     " --client=D2DV report client as Diablo II\n"
143     " --client=D2XP report client as Diablo II: LoD\n"
144     " --client=WAR3 report client as Warcraft III\n");
145     fprintf(stderr,
146     " -o NAME, --owner=NAME report CD owner as NAME\n"
147     " -k KEY, --cdkey=KEY report CD key as KEY\n"
148     " -p PLR, --player=PLR print stats for player PLR\n"
149     " --bnetd also print BNETD-specific stats\n"
150     " --fsgs also print FSGS-specific stats\n"
151     " -h, --help, --usage show this information and exit\n"
152     " -v, --version print version number and exit\n");
153     exit(STATUS_FAILURE);
154     }
155    
156    
157     extern int main(int argc, char * argv[])
158     {
159     int a;
160     int sd;
161     int gotplayer=0;
162     struct sockaddr_in saddr;
163     t_packet * packet;
164     t_packet * rpacket;
165     char const * cdowner=NULL;
166     char const * cdkey=NULL;
167     char const * clienttag=NULL;
168     char const * servname=NULL;
169     unsigned short servport=0;
170     char text[MAX_MESSAGE_LEN]="";
171     unsigned int commpos;
172     struct termios in_attr_old;
173     struct termios in_attr_new;
174     int changed_in;
175     unsigned int count;
176     unsigned int sessionkey;
177     unsigned int sessionnum;
178     unsigned int val;
179     int fd_stdin=0;
180     int use_bnetd=0;
181     int use_fsgs=0;
182     unsigned int screen_width,screen_height;
183     int munged=0;
184    
185     if (argc<1 || !argv || !argv[0])
186     {
187     fprintf(stderr,"bad arguments\n");
188     return STATUS_FAILURE;
189     }
190    
191     for (a=1; a<argc; a++)
192     if (servname && isdigit((int)argv[a][0]) && a+1>=argc)
193     {
194     if (str_to_ushort(argv[a],&servport)<0)
195     {
196     fprintf(stderr,"%s: \"%s\" should be a positive integer\n",argv[0],argv[a]);
197     usage(argv[0]);
198     }
199     }
200     else if (!servname && argv[a][0]!='-' && a+2>=argc)
201     servname = argv[a];
202     else if (strcmp(argv[a],"-b")==0 || strcmp(argv[a],"--client=SEXP")==0)
203     {
204     if (clienttag)
205     {
206     fprintf(stderr,"%s: client type was already specified as \"%s\"\n",argv[0],clienttag);
207     usage(argv[0]);
208     }
209     clienttag = CLIENTTAG_BROODWARS;
210     }
211     else if (strcmp(argv[a],"-d")==0 || strcmp(argv[a],"--client=DRTL")==0)
212     {
213     if (clienttag)
214     {
215     fprintf(stderr,"%s: client type was already specified as \"%s\"\n",argv[0],clienttag);
216     usage(argv[0]);
217     }
218     clienttag = CLIENTTAG_DIABLORTL;
219     }
220     else if (strcmp(argv[a],"--client=DSHR")==0)
221     {
222     if (clienttag)
223     {
224     fprintf(stderr,"%s: client type was already specified as \"%s\"\n",argv[0],clienttag);
225     usage(argv[0]);
226     }
227     clienttag = CLIENTTAG_DIABLOSHR;
228     }
229     else if (strcmp(argv[a],"-s")==0 || strcmp(argv[a],"--client=STAR")==0)
230     {
231     if (clienttag)
232     {
233     fprintf(stderr,"%s: client type was already specified as \"%s\"\n",argv[0],clienttag);
234     usage(argv[0]);
235     }
236     clienttag = CLIENTTAG_STARCRAFT;
237     }
238     else if (strcmp(argv[a],"--client=SSHR")==0)
239     {
240     if (clienttag)
241     {
242     fprintf(stderr,"%s: client type was already specified as \"%s\"\n",argv[0],clienttag);
243     usage(argv[0]);
244     }
245     clienttag = CLIENTTAG_SHAREWARE;
246     }
247     else if (strcmp(argv[a],"-w")==0 || strcmp(argv[a],"--client=W2BN")==0)
248     {
249     if (clienttag)
250     {
251     fprintf(stderr,"%s: client type was already specified as \"%s\"\n",argv[0],clienttag);
252     usage(argv[0]);
253     }
254     clienttag = CLIENTTAG_WARCIIBNE;
255     }
256     else if (strcmp(argv[a],"--client=D2DV")==0)
257     {
258     if (clienttag)
259     {
260     fprintf(stderr,"%s: client type was already specified as \"%s\"\n",argv[0],clienttag
261     );
262     usage(argv[0]);
263     }
264     clienttag = CLIENTTAG_DIABLO2DV;
265     }
266     else if (strcmp(argv[a],"--client=D2XP")==0)
267     {
268     if (clienttag)
269     {
270     fprintf(stderr,"%s: client type was already specified as \"%s\"\n",argv[0],clienttag
271     );
272     usage(argv[0]);
273     }
274     clienttag = CLIENTTAG_DIABLO2XP;
275     }
276     else if (strcmp(argv[a],"--client=WAR3")==0)
277     {
278     if (clienttag)
279     {
280     fprintf(stderr,"%s: client type was already specified as \"%s\"\n",argv[0],clienttag
281     );
282     usage(argv[0]);
283     }
284     clienttag = CLIENTTAG_WARCRAFT3;
285     }
286     else if (strncmp(argv[a],"--client=",9)==0)
287     {
288     fprintf(stderr,"%s: unknown client tag \"%s\"\n",argv[0],&argv[a][9]);
289     usage(argv[0]);
290     }
291     else if (strcmp(argv[a],"-o")==0)
292     {
293     if (a+1>=argc)
294     {
295     fprintf(stderr,"%s: option \"%s\" requires an argument\n",argv[0],argv[a]);
296     usage(argv[0]);
297     }
298     if (cdowner)
299     {
300     fprintf(stderr,"%s: CD owner was already specified as \"%s\"\n",argv[0],cdowner);
301     usage(argv[0]);
302     }
303     cdowner = argv[++a];
304     }
305     else if (strncmp(argv[a],"--owner=",8)==0)
306     {
307     if (cdowner)
308     {
309     fprintf(stderr,"%s: CD owner was already specified as \"%s\"\n",argv[0],cdowner);
310     usage(argv[0]);
311     }
312     cdowner = &argv[a][8];
313     }
314     else if (strcmp(argv[a],"-k")==0)
315     {
316     if (a+1>=argc)
317     {
318     fprintf(stderr,"%s: option \"%s\" requires an argument\n",argv[0],argv[a]);
319     usage(argv[0]);
320     }
321     if (cdkey)
322     {
323     fprintf(stderr,"%s: CD key was already specified as \"%s\"\n",argv[0],cdkey);
324     usage(argv[0]);
325     }
326     cdkey = argv[++a];
327     }
328     else if (strncmp(argv[a],"--cdkey=",8)==0)
329     {
330     if (cdkey)
331     {
332     fprintf(stderr,"%s: CD key was already specified as \"%s\"\n",argv[0],cdkey);
333     usage(argv[0]);
334     }
335     cdkey = &argv[a][8];
336     }
337     else if (strcmp(argv[a],"-p")==0)
338     {
339     if (a+1>=argc)
340     {
341     fprintf(stderr,"%s: option \"%s\" requires an argument\n",argv[0],argv[a]);
342     usage(argv[0]);
343     }
344     if (gotplayer)
345     {
346     fprintf(stderr,"%s: player was already specified as \"%s\"\n",argv[0],text);
347     usage(argv[0]);
348     }
349     a++;
350     if (argv[a][0]=='\0')
351     {
352     fprintf(stderr,"%s: player name can not be empty\n",argv[0]);
353     usage(argv[0]);
354     }
355     strncpy(text,argv[a],sizeof(text));
356     text[sizeof(text)-1] = '\0';
357     gotplayer = 1;
358     }
359     else if (strncmp(argv[a],"--player=",9)==0)
360     {
361     if (gotplayer)
362     {
363     fprintf(stderr,"%s: player was already specified as \"%s\"\n",argv[0],text);
364     usage(argv[0]);
365     }
366     if (argv[a][9]=='\0')
367     {
368     fprintf(stderr,"%s: player name can not be empty\n",argv[0]);
369     usage(argv[0]);
370     }
371     strncpy(text,&argv[a][9],sizeof(text));
372     text[sizeof(text)-1] = '\0';
373     gotplayer = 1;
374     }
375     else if (strcmp(argv[a],"--bnetd")==0)
376     use_bnetd = 1;
377     else if (strcmp(argv[a],"--fsgs")==0)
378     use_fsgs = 1;
379     else if (strcmp(argv[a],"-h")==0 || strcmp(argv[a],"--help")==0 || strcmp(argv[a],"--usage")
380     ==0)
381     usage(argv[0]);
382     else if (strcmp(argv[a],"-v")==0 || strcmp(argv[a],"--version")==0)
383     {
384     printf("version "PVPGN_VERSION"\n");
385     return STATUS_SUCCESS;
386     }
387     else if (strcmp(argv[a],"--client")==0 || strcmp(argv[a],"--owner")==0 ||
388     strcmp(argv[a],"--cdkey")==0 || strcmp(argv[a],"--player")==0)
389     {
390     fprintf(stderr,"%s: option \"%s\" requires an argument\n",argv[0],argv[a]);
391     usage(argv[0]);
392     }
393     else
394     {
395     fprintf(stderr,"%s: unknown option \"%s\"\n",argv[0],argv[a]);
396     usage(argv[0]);
397     }
398    
399     if (servport==0)
400     servport = BNETD_SERV_PORT;
401     if (!cdowner)
402     cdowner = BNETD_DEFAULT_OWNER;
403     if (!cdkey)
404     cdkey = BNETD_DEFAULT_KEY;
405     if (!clienttag)
406     clienttag = CLIENTTAG_STARCRAFT;
407     if (!servname)
408     servname = BNETD_DEFAULT_HOST;
409    
410     if (gotplayer)
411     changed_in = 0; /* no need to change terminal attributes */
412     else
413     {
414     fd_stdin = fileno(stdin);
415     if (tcgetattr(fd_stdin,&in_attr_old)>=0)
416     {
417     in_attr_new = in_attr_old;
418     in_attr_new.c_lflag &= ~(ECHO | ICANON); /* turn off ECHO and ICANON */
419     in_attr_new.c_cc[VMIN] = 1; /* require reads to return at least one byte */
420     in_attr_new.c_cc[VTIME] = 0; /* no timeout */
421     tcsetattr(fd_stdin,TCSANOW,&in_attr_new);
422     changed_in = 1;
423     }
424     else
425     {
426     fprintf(stderr,"%s: could not set terminal attributes for stdin\n",argv[0]);
427     changed_in = 0;
428     }
429    
430     if (client_get_termsize(fd_stdin,&screen_width,&screen_height)<0)
431     {
432     fprintf(stderr,"%s: could not determine screen size, assuming 80x24\n",argv[0]);
433     screen_width = 80;
434     screen_height = 24;
435     }
436     }
437    
438     if ((sd = client_connect(argv[0],servname,servport,cdowner,cdkey,clienttag,&saddr,&sessionkey,&sessionnum,ARCHTAG_WINX86))<0)
439     {
440     fprintf(stderr,"%s: fatal error during handshake\n",argv[0]);
441     if (changed_in)
442     tcsetattr(fd_stdin,TCSAFLUSH,&in_attr_old);
443     return STATUS_FAILURE;
444     }
445    
446     /* reuse this same packet over and over */
447     if (!(rpacket = packet_create(packet_class_bnet)))
448     {
449     fprintf(stderr,"%s: could not create packet\n",argv[0]);
450     psock_close(sd);
451     if (changed_in)
452     tcsetattr(fd_stdin,TCSAFLUSH,&in_attr_old);
453     return STATUS_FAILURE;
454     }
455    
456     if (!(packet = packet_create(packet_class_bnet)))
457     {
458     fprintf(stderr,"%s: could not create packet\n",argv[0]);
459     psock_close(sd);
460     if (changed_in)
461     tcsetattr(fd_stdin,TCSAFLUSH,&in_attr_old);
462     return STATUS_FAILURE;
463     }
464     packet_set_size(packet,sizeof(t_client_fileinforeq));
465     packet_set_type(packet,CLIENT_FILEINFOREQ);
466     bn_int_set(&packet->u.client_fileinforeq.type,CLIENT_FILEINFOREQ_TYPE_TOS);
467     bn_int_set(&packet->u.client_fileinforeq.unknown2,CLIENT_FILEINFOREQ_UNKNOWN2);
468     packet_append_string(packet,CLIENT_FILEINFOREQ_FILE_TOSUSA);
469     client_blocksend_packet(sd,packet);
470     packet_del_ref(packet);
471     do
472     if (client_blockrecv_packet(sd,rpacket)<0)
473     {
474     fprintf(stderr,"%s: server closed connection\n",argv[0]);
475     psock_close(sd);
476     if (changed_in)
477     tcsetattr(fd_stdin,TCSAFLUSH,&in_attr_old);
478     return STATUS_FAILURE;
479     }
480     while (packet_get_type(rpacket)!=SERVER_FILEINFOREPLY);
481     dprintf("Got FILEINFOREPLY\n");
482    
483     if (!gotplayer)
484     {
485     munged = 1;
486     commpos = 0;
487     text[0] = '\0';
488     }
489    
490     for (;;)
491     {
492     unsigned int i;
493    
494     if (!gotplayer)
495     {
496     switch (client_get_comm("player: ",text,sizeof(text),&commpos,1,munged,screen_width))
497     {
498     case -1: /* cancel or error */
499     break;
500    
501     case 0: /* timeout */
502     munged = 0;
503     continue;
504    
505     case 1:
506     munged = 0;
507     if (text[0]=='\0')
508     continue;
509     }
510    
511     if (text[0]=='\0')
512     break;
513     printf("\r");
514     for (i=0; i<strlen(text) && i<screen_width; i++)
515     printf(" ");
516     printf("\r");
517     }
518    
519     if (!(packet = packet_create(packet_class_bnet)))
520     {
521     fprintf(stderr,"%s: could not create packet\n",argv[0]);
522     psock_close(sd);
523     if (changed_in)
524     tcsetattr(fd_stdin,TCSAFLUSH,&in_attr_old);
525     return STATUS_FAILURE;
526     }
527     packet_set_size(packet,sizeof(t_client_statsreq));
528     packet_set_type(packet,CLIENT_STATSREQ);
529     bn_int_set(&packet->u.client_statsreq.name_count,1);
530     bn_int_set(&packet->u.client_statsreq.requestid,0);
531     packet_append_string(packet,text);
532     count = 0;
533    
534     if (use_bnetd)
535     {
536     packet_append_string(packet,"BNET\\acct\\username");
537     packet_append_string(packet,"BNET\\acct\\userid");
538     packet_append_string(packet,"BNET\\acct\\lastlogin_clienttag");
539     packet_append_string(packet,"BNET\\acct\\lastlogin_connection");
540     packet_append_string(packet,"BNET\\acct\\lastlogin_time");
541     packet_append_string(packet,"BNET\\acct\\firstlogin_clienttag");
542     packet_append_string(packet,"BNET\\acct\\firstlogin_connection");
543     packet_append_string(packet,"BNET\\acct\\firstlogin_time");
544     count += 8;
545     }
546     if (use_fsgs)
547     {
548     packet_append_string(packet,"FSGS\\Created");
549     count += 1;
550     }
551    
552     packet_append_string(packet,"profile\\sex");
553     packet_append_string(packet,"profile\\age");
554     packet_append_string(packet,"profile\\location");
555     packet_append_string(packet,"profile\\description");
556     count += 4;
557    
558     if (strcmp(clienttag,"STAR")==0)
559     {
560     packet_append_string(packet,"Record\\STAR\\0\\last game");
561     packet_append_string(packet,"Record\\STAR\\0\\last game result");
562     packet_append_string(packet,"Record\\STAR\\0\\wins");
563     packet_append_string(packet,"Record\\STAR\\0\\losses");
564     packet_append_string(packet,"Record\\STAR\\0\\disconnects");
565     packet_append_string(packet,"Record\\STAR\\0\\draws");
566     count += 6;
567    
568     packet_append_string(packet,"Record\\STAR\\1\\last game");
569     packet_append_string(packet,"Record\\STAR\\1\\last game result");
570     packet_append_string(packet,"Record\\STAR\\1\\rating");
571     packet_append_string(packet,"Record\\STAR\\1\\active rating");
572     packet_append_string(packet,"Record\\STAR\\1\\high rating");
573     packet_append_string(packet,"Record\\STAR\\1\\rank");
574     packet_append_string(packet,"Record\\STAR\\1\\active rank");
575     packet_append_string(packet,"Record\\STAR\\1\\high rank");
576     packet_append_string(packet,"Record\\STAR\\1\\wins");
577     packet_append_string(packet,"Record\\STAR\\1\\losses");
578     packet_append_string(packet,"Record\\STAR\\1\\disconnects");
579     packet_append_string(packet,"Record\\STAR\\1\\draws");
580     count += 12;
581     }
582     else if (strcmp(clienttag,"SEXP")==0)
583     {
584     packet_append_string(packet,"Record\\SEXP\\0\\last game");
585     packet_append_string(packet,"Record\\SEXP\\0\\last game result");
586     packet_append_string(packet,"Record\\SEXP\\0\\wins");
587     packet_append_string(packet,"Record\\SEXP\\0\\losses");
588     packet_append_string(packet,"Record\\SEXP\\0\\disconnects");
589     packet_append_string(packet,"Record\\SEXP\\0\\draws");
590     count += 6;
591    
592     packet_append_string(packet,"Record\\SEXP\\1\\last game");
593     packet_append_string(packet,"Record\\SEXP\\1\\last game result");
594     packet_append_string(packet,"Record\\SEXP\\1\\rating");
595     packet_append_string(packet,"Record\\SEXP\\1\\active rating");
596     packet_append_string(packet,"Record\\SEXP\\1\\high rating");
597     packet_append_string(packet,"Record\\SEXP\\1\\rank");
598     packet_append_string(packet,"Record\\SEXP\\1\\active rank");
599     packet_append_string(packet,"Record\\SEXP\\1\\high rank");
600     packet_append_string(packet,"Record\\SEXP\\1\\wins");
601     packet_append_string(packet,"Record\\SEXP\\1\\losses");
602     packet_append_string(packet,"Record\\SEXP\\1\\disconnects");
603     packet_append_string(packet,"Record\\SEXP\\1\\draws");
604     count += 12;
605     }
606     else if (strcmp(clienttag,"SSHR")==0)
607     {
608     packet_append_string(packet,"Record\\SSHR\\0\\last game");
609     packet_append_string(packet,"Record\\SSHR\\0\\last game result");
610     packet_append_string(packet,"Record\\SSHR\\0\\wins");
611     packet_append_string(packet,"Record\\SSHR\\0\\losses");
612     packet_append_string(packet,"Record\\SSHR\\0\\disconnects");
613     packet_append_string(packet,"Record\\SSHR\\0\\draws");
614     count += 6;
615     }
616     else if (strcmp(clienttag,"DSHR")==0 ||
617     strcmp(clienttag,"DRTL")==0)
618     {
619     if (use_bnetd)
620     {
621     packet_append_string(packet,"BNET\\Record\\DRTL\\0\\level");
622     packet_append_string(packet,"BNET\\Record\\DRTL\\0\\class");
623     packet_append_string(packet,"BNET\\Record\\DRTL\\0\\strength");
624     packet_append_string(packet,"BNET\\Record\\DRTL\\0\\magic");
625     packet_append_string(packet,"BNET\\Record\\DRTL\\0\\dexterity");
626     packet_append_string(packet,"BNET\\Record\\DRTL\\0\\vitality");
627     packet_append_string(packet,"BNET\\Record\\DRTL\\0\\gold");
628     packet_append_string(packet,"BNET\\Record\\DRTL\\0\\diablo kills");
629     count += 8;
630     }
631     }
632     else if (strcmp(clienttag,"W2BN")==0)
633     {
634     packet_append_string(packet,"Record\\W2BN\\0\\last game");
635     packet_append_string(packet,"Record\\W2BN\\0\\last game result");
636     packet_append_string(packet,"Record\\W2BN\\0\\wins");
637     packet_append_string(packet,"Record\\W2BN\\0\\losses");
638     packet_append_string(packet,"Record\\W2BN\\0\\disconnects");
639     packet_append_string(packet,"Record\\W2BN\\0\\draws");
640     count += 6;
641    
642     packet_append_string(packet,"Record\\W2BN\\1\\last game");
643     packet_append_string(packet,"Record\\W2BN\\1\\last game result");
644     packet_append_string(packet,"Record\\W2BN\\1\\rating");
645     packet_append_string(packet,"Record\\W2BN\\1\\active rating");
646     packet_append_string(packet,"Record\\W2BN\\1\\high rating");
647     packet_append_string(packet,"Record\\W2BN\\1\\rank");
648     packet_append_string(packet,"Record\\W2BN\\1\\active rank");
649     packet_append_string(packet,"Record\\W2BN\\1\\high rank");
650     packet_append_string(packet,"Record\\W2BN\\1\\wins");
651     packet_append_string(packet,"Record\\W2BN\\1\\losses");
652     packet_append_string(packet,"Record\\W2BN\\1\\disconnects");
653     packet_append_string(packet,"Record\\W2BN\\1\\draws");
654     count += 12;
655    
656     packet_append_string(packet,"Record\\W2BN\\3\\last game");
657     packet_append_string(packet,"Record\\W2BN\\3\\last game result");
658     packet_append_string(packet,"Record\\W2BN\\3\\rating");
659     packet_append_string(packet,"Record\\W2BN\\3\\active rating");
660     packet_append_string(packet,"Record\\W2BN\\3\\high rating");
661     packet_append_string(packet,"Record\\W2BN\\3\\rank");
662     packet_append_string(packet,"Record\\W2BN\\3\\active rank");
663     packet_append_string(packet,"Record\\W2BN\\3\\high rank");
664     packet_append_string(packet,"Record\\W2BN\\3\\wins");
665     packet_append_string(packet,"Record\\W2BN\\3\\losses");
666     packet_append_string(packet,"Record\\W2BN\\3\\disconnects");
667     packet_append_string(packet,"Record\\W2BN\\3\\draws");
668     count += 12;
669     }
670     bn_int_set(&packet->u.client_statsreq.key_count,count);
671     client_blocksend_packet(sd,packet);
672     packet_del_ref(packet);
673    
674     do
675     if (client_blockrecv_packet(sd,rpacket)<0)
676     {
677     fprintf(stderr,"%s: server closed connection\n",argv[0]);
678     if (changed_in)
679     tcsetattr(fd_stdin,TCSAFLUSH,&in_attr_old);
680     return STATUS_FAILURE;
681     }
682     while (packet_get_type(rpacket)!=SERVER_STATSREPLY);
683     dprintf("Got STATSREPLY\n");
684    
685     {
686     unsigned int names,keys;
687     unsigned int j;
688     unsigned int strpos;
689     char const * temp;
690     unsigned int uid;
691     struct in_addr laddr;
692     time_t tm;
693     char timestr[STAT_TIME_MAXLEN];
694    
695     names = bn_int_get(rpacket->u.server_statsreply.name_count);
696     keys = bn_int_get(rpacket->u.server_statsreply.key_count);
697    
698     printf("----\n");
699    
700     strpos = sizeof(t_server_statsreply);
701     for (i=0; i<names; i++)
702     {
703     j = 0;
704     if (use_bnetd)
705     {
706     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
707     strpos += strlen(temp)+1;
708     else
709     temp = "";
710     j++;
711     if (temp[0]=='\0')
712     printf(" Username: UNKNOWN\n");
713     else
714     printf(" Username: %s\n",temp);
715    
716     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
717     strpos += strlen(temp)+1;
718     else
719     temp = "";
720     j++;
721     if (str_to_uint(temp,&uid)<0 || uid<1)
722     printf(" Account: UNKNOWN\n");
723     else
724     printf(" Account: "UID_FORMAT"\n",uid);
725    
726     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
727     strpos += strlen(temp)+1;
728     else
729     temp = "";
730     j++;
731     printf(" Last login client: %s\n",temp);
732    
733     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
734     strpos += strlen(temp)+1;
735     else
736     temp = "";
737     j++;
738     if (str_to_uint(temp,&val)<0)
739     printf(" Last login host: UNKNOWN\n");
740     else
741     {
742     laddr.s_addr = htonl(val);
743     printf(" Last login host: %s\n",inet_ntoa(laddr));
744     }
745    
746     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
747     strpos += strlen(temp)+1;
748     else
749     temp = "";
750     j++;
751     if (str_to_uint(temp,&val)<0 || val==0)
752     printf(" Last login time: NEVER\n");
753     else
754     {
755     tm = (time_t)val;
756     strftime(timestr,STAT_TIME_MAXLEN,STAT_TIME_FORMAT,localtime(&tm));
757     printf(" Last login time: %s\n",timestr);
758     }
759    
760     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
761     strpos += strlen(temp)+1;
762     else
763     temp = "";
764     j++;
765     printf(" First login client: %s\n",temp);
766    
767     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
768     strpos += strlen(temp)+1;
769     else
770     temp = "";
771     j++;
772     if (str_to_uint(temp,&val)<0)
773     printf(" First login host: UNKNOWN\n");
774     else
775     {
776     laddr.s_addr = htonl(val);
777     printf(" First login host: %s\n",inet_ntoa(laddr));
778     }
779    
780     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
781     strpos += strlen(temp)+1;
782     else
783     temp = "";
784     j++;
785     if (str_to_uint(temp,&val)<0 || val==0)
786     printf(" First login time: NEVER\n");
787     else
788     {
789     tm = (time_t)val;
790     strftime(timestr,STAT_TIME_MAXLEN,STAT_TIME_FORMAT,localtime(&tm));
791     printf(" First login time: %s\n",timestr);
792     }
793     }
794     else
795     printf(" Username: %s\n",text);
796     if (use_fsgs)
797     {
798     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
799     strpos += strlen(temp)+1;
800     else
801     temp = "";
802     j++;
803     if (str_to_uint(temp,&val)<0 || val==0)
804     printf(" Creation time: NEVER\n");
805     else
806     {
807     tm = (time_t)val;
808     strftime(timestr,STAT_TIME_MAXLEN,STAT_TIME_FORMAT,localtime(&tm));
809     printf(" Creation time: %s\n",timestr);
810     }
811     }
812    
813     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
814     strpos += strlen(temp)+1;
815     else
816     temp = "";
817     j++;
818     printf(" Sex: %s\n",temp);
819    
820     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
821     strpos += strlen(temp)+1;
822     else
823     temp = "";
824     j++;
825     printf(" Age: %s\n",temp);
826    
827     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
828     strpos += strlen(temp)+1;
829     else
830     temp = "";
831     j++;
832     printf(" Location: %s\n",temp);
833    
834     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
835     strpos += strlen(temp)+1;
836     else
837     temp = "";
838     j++;
839     printf(" Description: %s\n",temp);
840    
841     if (strcmp(clienttag,"STAR")==0 ||
842     strcmp(clienttag,"SSHR")==0 ||
843     strcmp(clienttag,"SEXP")==0 ||
844     strcmp(clienttag,"W2BN")==0)
845     {
846     t_bnettime bntime;
847     unsigned int wins,losses,disconnects,draws;
848    
849     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
850     strpos += strlen(temp)+1;
851     else
852     temp = "";
853     j++;
854     if (bnettime_set_str(&bntime,temp)<0)
855     strcpy(timestr,"NEVER");
856     else
857     {
858     tm = bnettime_to_time(bntime);
859     strftime(timestr,STAT_TIME_MAXLEN,STAT_TIME_FORMAT,localtime(&tm));
860     }
861     printf(" Last game time: %s\n",timestr);
862    
863     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
864     strpos += strlen(temp)+1;
865     else
866     temp = "";
867     j++;
868     printf(" Last game result: %s\n",temp);
869    
870     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
871     strpos += strlen(temp)+1;
872     else
873     temp = "";
874     j++;
875     if (str_to_uint(temp,&wins)<0)
876     wins = 0;
877     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
878     strpos += strlen(temp)+1;
879     else
880     temp = "";
881     j++;
882     if (str_to_uint(temp,&losses)<0)
883     losses = 0;
884     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
885     strpos += strlen(temp)+1;
886     else
887     temp = "";
888     j++;
889     if (str_to_uint(temp,&disconnects)<0)
890     disconnects = 0;
891     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
892     strpos += strlen(temp)+1;
893     else
894     temp = "";
895     j++;
896     if (str_to_uint(temp,&draws)<0)
897     draws = 0;
898     printf(" Record: (%u/%u/%u) %u draws\n",wins,losses,disconnects,draws);
899     }
900    
901     if (strcmp(clienttag,"STAR")==0 ||
902     strcmp(clienttag,"SEXP")==0 ||
903     strcmp(clienttag,"W2BN")==0)
904     {
905     t_bnettime bntime;
906     unsigned int wins,losses,disconnects,draws;
907     unsigned int rating,rank;
908     unsigned int active_rating,active_rank;
909     unsigned int high_rating,high_rank;
910    
911     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
912     strpos += strlen(temp)+1;
913     else
914     temp = "";
915     j++;
916     if (bnettime_set_str(&bntime,temp)<0)
917     strcpy(timestr,"NEVER");
918     else
919     {
920     tm = bnettime_to_time(bntime);
921     strftime(timestr,STAT_TIME_MAXLEN,STAT_TIME_FORMAT,localtime(&tm));
922     }
923     printf(" Last standard ladder game time: %s\n",timestr);
924    
925     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
926     strpos += strlen(temp)+1;
927     else
928     temp = "";
929     j++;
930     printf("Last standard ladder game result: %s\n",temp);
931    
932     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
933     strpos += strlen(temp)+1;
934     else
935     temp = "";
936     j++;
937     if (str_to_uint(temp,&rating)<0)
938     rating = 0;
939     if (rating)
940     printf(" Current standard ladder rating: %u\n",rating);
941     else
942     printf(" Current standard ladder rating: UNRATED\n");
943    
944     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
945     strpos += strlen(temp)+1;
946     else
947     temp = "";
948     j++;
949     if (str_to_uint(temp,&active_rating)<0)
950     active_rating = 0;
951     if (active_rating)
952     printf(" Active standard ladder rating: %u\n",active_rating);
953     else
954     printf(" Active standard ladder rating: UNRATED\n");
955    
956     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
957     strpos += strlen(temp)+1;
958     else
959     temp = "";
960     j++;
961     if (str_to_uint(temp,&high_rating)<0)
962     high_rating = 0;
963     if (high_rating)
964     printf(" High standard ladder rating: %u\n",high_rating);
965     else
966     printf(" High standard ladder rating: UNRATED\n");
967    
968     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
969     strpos += strlen(temp)+1;
970     else
971     temp = "";
972     j++;
973     if (str_to_uint(temp,&rank)<0)
974     rank = 0;
975     if (rank)
976     printf(" Current standard ladder rank: #%u\n",rank);
977     else
978     printf(" Current standard ladder rank: UNRANKED\n");
979    
980     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
981     strpos += strlen(temp)+1;
982     else
983     temp = "";
984     j++;
985     if (str_to_uint(temp,&active_rank)<0)
986     active_rank = 0;
987     if (active_rank)
988     printf(" Active standard ladder rank: #%u\n",active_rank);
989     else
990     printf(" Active standard ladder rank: UNRANKED\n");
991    
992     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
993     strpos += strlen(temp)+1;
994     else
995     temp = "";
996     j++;
997     if (str_to_uint(temp,&high_rank)<0)
998     high_rank = 0;
999     if (high_rank)
1000     printf(" High standard ladder rank: #%u\n",high_rank);
1001     else
1002     printf(" High standard ladder rank: UNRANKED\n");
1003    
1004     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1005     strpos += strlen(temp)+1;
1006     else
1007     temp = "";
1008     j++;
1009     if (str_to_uint(temp,&wins)<0)
1010     wins = 0;
1011     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1012     strpos += strlen(temp)+1;
1013     else
1014     temp = "";
1015     j++;
1016     if (str_to_uint(temp,&losses)<0)
1017     losses = 0;
1018     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1019     strpos += strlen(temp)+1;
1020     else
1021     temp = "";
1022     j++;
1023     if (str_to_uint(temp,&disconnects)<0)
1024     disconnects = 0;
1025     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1026     strpos += strlen(temp)+1;
1027     else
1028     temp = "";
1029     j++;
1030     if (str_to_uint(temp,&draws)<0)
1031     draws = 0;
1032     printf(" Standard ladder record: (%u/%u/%u) %u draws\n",wins,losses,disconnects,draws);
1033     }
1034    
1035     if (strcmp(clienttag,"W2BN")==0)
1036     {
1037     t_bnettime bntime;
1038     unsigned int wins,losses,disconnects,draws;
1039     unsigned int rating,rank;
1040     unsigned int active_rating,active_rank;
1041     unsigned int high_rating,high_rank;
1042    
1043     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1044     strpos += strlen(temp)+1;
1045     else
1046     temp = "";
1047     j++;
1048     if (bnettime_set_str(&bntime,temp)<0)
1049     strcpy(timestr,"NEVER");
1050     else
1051     {
1052     tm = bnettime_to_time(bntime);
1053     strftime(timestr,STAT_TIME_MAXLEN,STAT_TIME_FORMAT,localtime(&tm));
1054     }
1055     printf(" Last Ironman ladder game time: %s\n",timestr);
1056    
1057     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1058     strpos += strlen(temp)+1;
1059     else
1060     temp = "";
1061     j++;
1062     printf(" Last Ironman ladder game result: %s\n",temp);
1063    
1064     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1065     strpos += strlen(temp)+1;
1066     else
1067     temp = "";
1068     j++;
1069     if (str_to_uint(temp,&rating)<0)
1070     rating = 0;
1071     if (rating)
1072     printf(" Current Ironman ladder rating: %u\n",rating);
1073     else
1074     printf(" Current Ironman ladder rating: UNRATED\n");
1075    
1076     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1077     strpos += strlen(temp)+1;
1078     else
1079     temp = "";
1080     j++;
1081     if (str_to_uint(temp,&active_rating)<0)
1082     active_rating = 0;
1083     if (active_rating)
1084     printf(" Active Ironman ladder rating: %u\n",active_rating);
1085     else
1086     printf(" Active Ironman ladder rating: UNRATED\n");
1087    
1088     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1089     strpos += strlen(temp)+1;
1090     else
1091     temp = "";
1092     j++;
1093     if (str_to_uint(temp,&high_rating)<0)
1094     high_rating = 0;
1095     if (high_rating)
1096     printf(" High Ironman ladder rating: %u\n",high_rating);
1097     else
1098     printf(" High Ironman ladder rating: UNRATED\n");
1099    
1100     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1101     strpos += strlen(temp)+1;
1102     else
1103     temp = "";
1104     j++;
1105     if (str_to_uint(temp,&rank)<0)
1106     rank = 0;
1107     if (rank)
1108     printf(" Current Ironman ladder rank: #%u\n",rank);
1109     else
1110     printf(" Current Ironman ladder rank: UNRANKED\n");
1111    
1112     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1113     strpos += strlen(temp)+1;
1114     else
1115     temp = "";
1116     j++;
1117     if (str_to_uint(temp,&active_rank)<0)
1118     active_rank = 0;
1119     if (active_rank)
1120     printf(" Active Ironman ladder rank: #%u\n",active_rank);
1121     else
1122     printf(" Active Ironman ladder rank: UNRANKED\n");
1123    
1124     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1125     strpos += strlen(temp)+1;
1126     else
1127     temp = "";
1128     j++;
1129     if (str_to_uint(temp,&high_rank)<0)
1130     high_rank = 0;
1131     if (high_rank)
1132     printf(" High Ironman ladder rank: #%u\n",high_rank);
1133     else
1134     printf(" High Ironman ladder rank: UNRANKED\n");
1135    
1136     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1137     strpos += strlen(temp)+1;
1138     else
1139     temp = "";
1140     j++;
1141     if (str_to_uint(temp,&wins)<0)
1142     wins = 0;
1143     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1144     strpos += strlen(temp)+1;
1145     else
1146     temp = "";
1147     j++;
1148     if (str_to_uint(temp,&losses)<0)
1149     losses = 0;
1150     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1151     strpos += strlen(temp)+1;
1152     else
1153     temp = "";
1154     j++;
1155     if (str_to_uint(temp,&disconnects)<0)
1156     disconnects = 0;
1157     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1158     strpos += strlen(temp)+1;
1159     else
1160     temp = "";
1161     j++;
1162     if (str_to_uint(temp,&draws)<0)
1163     draws = 0;
1164     printf(" Ironman ladder record: (%u/%u/%u) %u draws\n",wins,losses,disconnects,draws);
1165     }
1166    
1167     if (strcmp(clienttag,"DSHR")==0 ||
1168     strcmp(clienttag,"DRTL")==0)
1169     {
1170     unsigned int level;
1171     unsigned int class;
1172     unsigned int diablo_kills;
1173     unsigned int strength;
1174     unsigned int magic;
1175     unsigned int dexterity;
1176     unsigned int vitality;
1177     unsigned int gold;
1178    
1179     if (use_bnetd)
1180     {
1181     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1182     strpos += strlen(temp)+1;
1183     else
1184     temp = "";
1185     j++;
1186     if (str_to_uint(temp,&level)<0)
1187     level = 0;
1188     if (level>0)
1189     printf(" Level: %u\n",level);
1190     else
1191     printf(" Level: NONE\n");
1192    
1193     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1194     strpos += strlen(temp)+1;
1195     else
1196     temp = "";
1197     j++;
1198     if (str_to_uint(temp,&class)<0)
1199     class = 99;
1200     printf(" Class: %s\n",bnclass_get_str(class));
1201    
1202     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1203     strpos += strlen(temp)+1;
1204     else
1205     temp = "";
1206     j++;
1207     if (str_to_uint(temp,&strength)<0)
1208     strength = 0;
1209    
1210     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1211     strpos += strlen(temp)+1;
1212     else
1213     temp = "";
1214     j++;
1215     if (str_to_uint(temp,&magic)<0)
1216     magic = 0;
1217    
1218     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1219     strpos += strlen(temp)+1;
1220     else
1221     temp = "";
1222     j++;
1223     if (str_to_uint(temp,&dexterity)<0)
1224     dexterity = 0;
1225    
1226     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1227     strpos += strlen(temp)+1;
1228     else
1229     temp = "";
1230     j++;
1231     if (str_to_uint(temp,&vitality)<0)
1232     vitality = 0;
1233    
1234     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1235     strpos += strlen(temp)+1;
1236     else
1237     temp = "";
1238     j++;
1239     if (str_to_uint(temp,&gold)<0)
1240     gold = 0;
1241    
1242     printf(" Stats: %u str %u mag %u dex %u vit %u gld\n",
1243     strength,
1244     magic,
1245     dexterity,
1246     vitality,
1247     gold);
1248    
1249     if (j<keys && (temp = packet_get_str_const(rpacket,strpos,256)))
1250     strpos += strlen(temp)+1;
1251     else
1252     temp = "";
1253     j++;
1254     if (str_to_uint(temp,&diablo_kills)<0)
1255     diablo_kills = 0;
1256     printf(" Diablo Kills: %u\n",diablo_kills);
1257     }
1258     }
1259     }
1260     printf("----\n");
1261     }
1262    
1263     if (gotplayer)
1264     break;
1265     commpos = 0;
1266     text[0] = '\0';
1267     }
1268    
1269     psock_close(sd);
1270     if (changed_in)
1271     tcsetattr(fd_stdin,TCSAFLUSH,&in_attr_old);
1272     return STATUS_SUCCESS;
1273     }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1