]> code.citadel.org Git - citadel.git/blob - citadel/whobbs.c
* Moved num_parms() and all the extract() type functions into tools.c
[citadel.git] / citadel / whobbs.c
1 /* $Id$ */
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include "citadel.h"
7 #include "ipc.h"
8 #include "tools.h"
9
10 void logoff(int code)
11 {
12         exit(code);
13         }
14
15 int main(int argc, char **argv)
16 {
17         char buf[256];
18         char nodetitle[256];
19         int a;
20         int s_pid = 0;
21         int my_pid = 0;
22         char s_user[256];
23         char s_room[256];
24         char s_host[256];
25
26         attach_to_server(argc,argv);
27         serv_gets(buf);
28         if ((buf[0]!='2')&&(strncmp(buf,"551",3))) {
29                 fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
30                 logoff(atoi(buf));
31                 }
32         strcpy(nodetitle, "this BBS");
33         serv_puts("INFO");
34         serv_gets(buf);
35         if (buf[0]=='1') {
36                 a = 0;
37                 while (serv_gets(buf), strcmp(buf,"000")) {
38                         if (a==0) my_pid = atoi(buf);
39                         if (a==2) strcpy(nodetitle, buf);
40                         ++a;
41                         }
42                 }
43         printf("            Users currently logged on to %s\n", nodetitle);
44         serv_puts("RWHO");
45         serv_gets(buf);
46         if (buf[0]!='1') {
47                 fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
48                 logoff(atoi(buf));
49                 }
50
51         printf("Session         User name               Room                  From host\n");
52         printf("------- ------------------------- -------------------- ------------------------\n");
53         while (serv_gets(buf), strcmp(buf,"000")) {
54                 s_pid = extract_int(buf,0);
55                 extract(s_user,buf,1);
56                 extract(s_room,buf,2);
57                 extract(s_host,buf,3);
58                 if (s_pid != my_pid) {
59                         printf("%-7d%c%-25s %-20s %-24s\n",
60                                 s_pid,
61                                 ((s_pid == my_pid) ? '*' : ' '),
62                                 s_user,s_room,s_host);
63                         }
64                 }
65
66         serv_puts("QUIT");
67         serv_gets(buf);
68         return 0;
69         }
70
71
72 #ifndef HAVE_STRERROR
73 /*
74  * replacement strerror() for systems that don't have it
75  */
76 char *strerror(int e)
77 {
78         static char buf[32];
79
80         sprintf(buf,"errno = %d",e);
81         return(buf);
82         }
83 #endif