]> code.citadel.org Git - citadel.git/blob - citadel/citadel.c
* CtdlSaveMsg() is now CtdlSubmitMsg() and can accept any combination of
[citadel.git] / citadel / citadel.c
1 /*
2  * $Id$
3  *
4  * Main source module for the client program.
5  */
6
7 #include "sysdep.h"
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <fcntl.h>
11 #include <stdio.h>
12 #include <ctype.h>
13 #include <string.h>
14
15 #if TIME_WITH_SYS_TIME
16 # include <sys/time.h>
17 # include <time.h>
18 #else
19 # if HAVE_SYS_TIME_H
20 #  include <sys/time.h>
21 # else
22 #  include <time.h>
23 # endif
24 #endif
25
26 #include <limits.h>
27 #include <sys/types.h>
28 #include <sys/wait.h>
29 #include <sys/stat.h>
30 #include <sys/ioctl.h>
31 #include <signal.h>
32 #include <pwd.h>
33 #include <setjmp.h>
34 #include <stdarg.h>
35
36 #include "citadel.h"
37 #include "axdefs.h"
38 #include "serv_info.h"
39 #include "routines.h"
40 #include "routines2.h"
41 #include "rooms.h"
42 #include "messages.h"
43 #include "commands.h"
44 #include "ipc.h"
45 #include "client_chat.h"
46 #include "client_passwords.h"
47 #include "citadel_decls.h"
48 #include "tools.h"
49 #include "acconfig.h"
50 #ifndef HAVE_SNPRINTF
51 #include "snprintf.h"
52 #endif
53
54 #include "md5.h"
55
56 struct march {
57         struct march *next;
58         char march_name[ROOMNAMELEN];
59         char march_floor;
60         char march_order;
61         };
62
63 #define IFEXPERT if (userflags&US_EXPERT)
64 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
65 #define IFAIDE if (axlevel>=6)
66 #define IFNAIDE if (axlevel<6)
67
68 struct march *march = NULL;
69
70 /* globals associated with the client program */
71 char temp[PATH_MAX];            /* Name of general temp file */
72 char temp2[PATH_MAX];           /* Name of general temp file */
73 char tempdir[PATH_MAX];         /* Name of general temp dir */
74 char editor_path[SIZ];          /* path to external editor */
75 char printcmd[SIZ];             /* print command */
76 int editor_pid = (-1);
77 char fullname[32];
78 jmp_buf nextbuf;
79 struct CtdlServInfo serv_info;  /* Info on the server connected */
80 int screenwidth;
81 int screenheight;
82 unsigned room_flags;
83 char room_name[ROOMNAMELEN];
84 char ugname[ROOMNAMELEN];
85 long uglsn;                     /* holds <u>ngoto info */
86 char is_mail = 0;               /* nonzero when we're in a mail room */
87 char axlevel = 0;               /* access level */
88 char is_room_aide = 0;          /* boolean flag, 1 if room aide */
89 int timescalled;
90 int posted;
91 unsigned userflags;
92 long usernum = 0L;              /* user number */
93 time_t lastcall = 0L;           /* Date/time of previous login */
94 char newnow;
95 long highest_msg_read;          /* used for <A>bandon room cmd */
96 long maxmsgnum;                 /* used for <G>oto */
97 char sigcaught = 0;
98 char have_xterm = 0;            /* are we running on an xterm? */
99 char rc_username[32];
100 char rc_password[32];
101 char hostbuf[SIZ];
102 char portbuf[SIZ];
103 char rc_floor_mode;
104 char floor_mode;
105 char curr_floor = 0;            /* number of current floor */
106 char floorlist[128][SIZ];       /* names of floors */
107 char express_msgs = 0;          /* express messages waiting! */
108 int termn8 = 0;                 /* Set to nonzero to cause a logoff */
109
110 extern int rc_ansi_color;       /* ansi color value from citadel.rc */
111
112 /*
113  * here is our 'clean up gracefully and exit' routine
114  */
115 void logoff(int code)
116 {
117         if (editor_pid > 0) {   /* kill the editor if it's running */
118                 kill(editor_pid, SIGHUP);
119         }
120 /* shut down the server... but not if the logoff code is 3, because
121  * that means we're exiting because we already lost the server
122  */
123         if (code != 3)
124                 serv_puts("QUIT");
125
126 /*
127  * now clean up various things
128  */
129
130         unlink(temp);
131         unlink(temp2);
132         nukedir(tempdir);
133
134         /* Violently kill off any child processes if Citadel is
135          * the login shell. 
136          */
137         if (getppid() == 1) {
138                 kill(0 - getpgrp(), SIGTERM);
139                 sleep(1);
140                 kill(0 - getpgrp(), SIGKILL);
141         }
142         sttybbs(SB_RESTORE);    /* return the old terminal settings */
143         exit(code);             /* exit with the proper exit code */
144 }
145
146
147
148 /*
149  * signal catching function for hangups...
150  */
151 void dropcarr(int signum)
152 {
153         logoff(SIGHUP);
154 }
155
156
157
158 /*
159  * catch SIGCONT to reset terminal modes when were are put back into the
160  * foreground.
161  */
162 void catch_sigcont(int signum)
163 {
164         sttybbs(SB_LAST);
165         signal(SIGCONT, catch_sigcont);
166 }
167
168
169
170 /* general purpose routines */
171
172 void formout(char *name)
173 {                               /* display a file */
174         char cmd[SIZ];
175         snprintf(cmd, sizeof cmd, "MESG %s", name);
176         serv_puts(cmd);
177         serv_gets(cmd);
178         if (cmd[0] != '1') {
179                 printf("%s\n", &cmd[4]);
180                 return;
181         }
182         fmout(screenwidth, NULL,
183               ((userflags & US_PAGINATOR) ? 1 : 0),
184               screenheight, 1, 1);
185 }
186
187
188 void userlist(char *patn)
189 {
190         char buf[SIZ];
191         char fl[SIZ];
192         struct tm *tmbuf;
193         time_t lc;
194
195         serv_puts("LIST");
196         serv_gets(buf);
197         if (buf[0] != '1') {
198                 pprintf("%s\n", &buf[4]);
199                 return;
200         }
201         pprintf("       User Name           Num  L  LastCall  Calls Posts\n");
202         pprintf("------------------------- ----- - ---------- ----- -----\n");
203         while (serv_gets(buf), strcmp(buf, "000")) {
204                 if (sigcaught == 0) {
205                     extract(fl, buf, 0);
206                     if (pattern(fl, patn) >= 0) {
207                         pprintf("%-25s ", fl);
208                         pprintf("%5ld %d ", extract_long(buf, 2),
209                                extract_int(buf, 1));
210                         lc = extract_long(buf, 3);
211                         tmbuf = (struct tm *) localtime(&lc);
212                         pprintf("%02d/%02d/%04d ",
213                                (tmbuf->tm_mon + 1),
214                                tmbuf->tm_mday,
215                                (tmbuf->tm_year + 1900));
216                         pprintf("%5ld %5ld\n", extract_long(buf, 4), extract_long(buf, 5));
217                     }
218
219                 }
220         }
221         pprintf("\n");
222 }
223
224
225 /*
226  * grab assorted info about the user...
227  */
228 void load_user_info(char *params)
229 {
230         extract(fullname, params, 0);
231         axlevel = extract_int(params, 1);
232         timescalled = extract_int(params, 2);
233         posted = extract_int(params, 3);
234         userflags = extract_int(params, 4);
235         usernum = extract_long(params, 5);
236         lastcall = extract_long(params, 6);
237 }
238
239
240 /*
241  * Remove a room from the march list.  'floornum' is ignored unless
242  * 'roomname' is set to _FLOOR_, in which case all rooms on the requested
243  * floor will be removed from the march list.
244  */
245 void remove_march(char *roomname, int floornum)
246 {
247         struct march *mptr, *mptr2;
248
249         if (march == NULL)
250                 return;
251
252         if ((!strcasecmp(march->march_name, roomname))
253             || ((!strcasecmp(roomname, "_FLOOR_")) && (march->march_floor == floornum))) {
254                 mptr = march->next;
255                 free(march);
256                 march = mptr;
257                 return;
258         }
259         mptr2 = march;
260         for (mptr = march; mptr != NULL; mptr = mptr->next) {
261
262                 if ((!strcasecmp(mptr->march_name, roomname))
263                     || ((!strcasecmp(roomname, "_FLOOR_"))
264                         && (mptr->march_floor == floornum))) {
265
266                         mptr2->next = mptr->next;
267                         free(mptr);
268                         mptr = mptr2;
269                 } else {
270                         mptr2 = mptr;
271                 }
272         }
273 }
274
275
276 /*
277  * Locate the room on the march list which we most want to go to.  Each room
278  * is measured given a "weight" of preference based on various factors.
279  */
280 char *pop_march(int desired_floor)
281 {
282         static char TheRoom[ROOMNAMELEN];
283         int TheFloor = 0;
284         int TheOrder = 32767;
285         int TheWeight = 0;
286         int weight;
287         struct march *mptr = NULL;
288
289         strcpy(TheRoom, "_BASEROOM_");
290         if (march == NULL)
291                 return (TheRoom);
292
293         for (mptr = march; mptr != NULL; mptr = mptr->next) {
294                 weight = 0;
295                 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
296                         weight = weight + 10000;
297                 if (mptr->march_floor == desired_floor)
298                         weight = weight + 5000;
299
300                 weight = weight + ((128 - (mptr->march_floor)) * 128);
301                 weight = weight + (128 - (mptr->march_order));
302
303                 if (weight > TheWeight) {
304                         TheWeight = weight;
305                         strcpy(TheRoom, mptr->march_name);
306                         TheFloor = mptr->march_floor;
307                         TheOrder = mptr->march_order;
308                 }
309         }
310         return (TheRoom);
311 }
312
313
314 /*
315  * jump directly to a room
316  */
317 void dotgoto(char *towhere, int display_name)
318 {
319         char aaa[SIZ], bbb[SIZ], psearch[SIZ];
320         static long ls = 0L;
321         int newmailcount;
322         static int oldmailcount = (-1);
323         int partial_match, best_match;
324         char from_floor;
325
326         /* store ungoto information */
327         strcpy(ugname, room_name);
328         uglsn = ls;
329
330         /* first try an exact match */
331         snprintf(aaa, sizeof aaa, "GOTO %s", towhere);
332         serv_puts(aaa);
333         serv_gets(aaa);
334         if (aaa[3] == '*')
335                 express_msgs = 1;
336         if (!strncmp(aaa, "54", 2)) {
337                 newprompt("Enter room password: ", bbb, 9);
338                 snprintf(aaa, sizeof aaa, "GOTO %s|%s", towhere, bbb);
339                 serv_puts(aaa);
340                 serv_gets(aaa);
341                 if (aaa[3] == '*')
342                         express_msgs = 1;
343         }
344         if (!strncmp(aaa, "54", 2)) {
345                 printf("Wrong password.\n");
346                 return;
347         }
348         /*
349          * If a match is not found, try a partial match.
350          * Partial matches anywhere in the string carry a weight of 1,
351          * left-aligned matches carry a weight of 2.  Pick the room that
352          * has the highest-weighted match.
353          */
354         if (aaa[0] != '2') {
355                 best_match = 0;
356                 strcpy(bbb, "");
357                 serv_puts("LKRA");
358                 serv_gets(aaa);
359                 if (aaa[0] == '1')
360                         while (serv_gets(aaa), strcmp(aaa, "000")) {
361                                 extract(psearch, aaa, 0);
362                                 partial_match = 0;
363                                 if (pattern(psearch, towhere) >= 0) {
364                                         partial_match = 1;
365                                 }
366                                 if (!strncasecmp(towhere, psearch, strlen(towhere))) {
367                                         partial_match = 2;
368                                 }
369                                 if (partial_match > best_match) {
370                                         strcpy(bbb, psearch);
371                                         best_match = partial_match;
372                                 }
373                         }
374                 if (strlen(bbb) == 0) {
375                         printf("No room '%s'.\n", towhere);
376                         return;
377                 }
378                 snprintf(aaa, sizeof aaa, "GOTO %s", bbb);
379                 serv_puts(aaa);
380                 serv_gets(aaa);
381                 if (aaa[3] == '*')
382                         express_msgs = 1;
383         }
384         if (aaa[0] != '2') {
385                 printf("%s\n", aaa);
386                 return;
387         }
388         extract(room_name, &aaa[4], 0);
389         room_flags = extract_int(&aaa[4], 4);
390         from_floor = curr_floor;
391         curr_floor = extract_int(&aaa[4], 10);
392
393         remove_march(room_name, 0);
394         if (!strcasecmp(towhere, "_BASEROOM_"))
395                 remove_march(towhere, 0);
396         if ((from_floor != curr_floor) && (display_name > 0) && (floor_mode == 1)) {
397                 if (floorlist[(int) curr_floor][0] == 0)
398                         load_floorlist();
399                 printf("(Entering floor: %s)\n", &floorlist[(int) curr_floor][0]);
400         }
401         if (display_name == 1) {
402                 color(BRIGHT_WHITE);
403                 printf("%s ", room_name);
404                 color(DIM_WHITE);
405                 printf("- ");
406         }
407         if (display_name != 2) {
408                 color(BRIGHT_YELLOW);
409                 printf("%d ", extract_int(&aaa[4], 1));
410                 color(DIM_WHITE);
411                 printf("new of ");
412                 color(BRIGHT_YELLOW);
413                 printf("%d ", extract_int(&aaa[4], 2));
414                 color(DIM_WHITE);
415                 printf("messages.\n");
416         }
417         highest_msg_read = extract_int(&aaa[4], 6);
418         maxmsgnum = extract_int(&aaa[4], 5);
419         is_mail = (char) extract_int(&aaa[4], 7);
420         is_room_aide = (char) extract_int(&aaa[4], 8);
421         ls = extract_long(&aaa[4], 6);
422
423         /* read info file if necessary */
424         if (extract_int(&aaa[4], 3) > 0)
425                 readinfo();
426
427         /* check for newly arrived mail if we can */
428         if (num_parms(&aaa[4]) >= 10) {
429                 newmailcount = extract_int(&aaa[4], 9);
430                 if ((oldmailcount >= 0) && (newmailcount > oldmailcount)) {
431                         color(BRIGHT_RED);
432                         printf("*** You have new mail\n");
433                         color(DIM_WHITE);
434                 }
435                 oldmailcount = newmailcount;
436         }
437 }
438
439 /* Goto next room having unread messages.
440  * We want to skip over rooms that the user has already been to, and take the
441  * user back to the lobby when done.  The room we end up in is placed in
442  * newroom - which is set to 0 (the lobby) initially.
443  */
444 void gotonext(void)
445 {
446         char buf[SIZ];
447         struct march *mptr, *mptr2;
448         char next_room[ROOMNAMELEN];
449
450         /* Check to see if the march-mode list is already allocated.
451          * If it is, pop the first room off the list and go there.
452          */
453         if (march == NULL) {
454                 serv_puts("LKRN");
455                 serv_gets(buf);
456                 if (buf[0] == '1')
457                         while (serv_gets(buf), strcmp(buf, "000")) {
458                                 mptr = (struct march *) malloc(sizeof(struct march));
459                                 mptr->next = NULL;
460                                 extract(mptr->march_name, buf, 0);
461                                 mptr->march_floor = (char) (extract_int(buf, 2) & 0x7F);
462                                 mptr->march_order = (char) (extract_int(buf, 3) & 0x7F);
463                                 if (march == NULL) {
464                                         march = mptr;
465                                 } else {
466                                         mptr2 = march;
467                                         while (mptr2->next != NULL)
468                                                 mptr2 = mptr2->next;
469                                         mptr2->next = mptr;
470                                 }
471                         }
472 /* add _BASEROOM_ to the end of the march list, so the user will end up
473  * in the system base room (usually the Lobby>) at the end of the loop
474  */
475                 mptr = (struct march *) malloc(sizeof(struct march));
476                 mptr->next = NULL;
477                 strcpy(mptr->march_name, "_BASEROOM_");
478                 if (march == NULL) {
479                         march = mptr;
480                 } else {
481                         mptr2 = march;
482                         while (mptr2->next != NULL)
483                                 mptr2 = mptr2->next;
484                         mptr2->next = mptr;
485                 }
486 /*
487  * ...and remove the room we're currently in, so a <G>oto doesn't make us
488  * walk around in circles
489  */
490                 remove_march(room_name, 0);
491         }
492         if (march != NULL) {
493                 strcpy(next_room, pop_march(curr_floor));
494         } else {
495                 strcpy(next_room, "_BASEROOM_");
496         }
497         remove_march(next_room, 0);
498         dotgoto(next_room, 1);
499 }
500
501 /*
502  * forget all rooms on a given floor
503  */
504 void forget_all_rooms_on(int ffloor)
505 {
506         char buf[SIZ];
507         struct march *flist, *fptr;
508
509         printf("Forgetting all rooms on %s...\r", &floorlist[ffloor][0]);
510         fflush(stdout);
511         snprintf(buf, sizeof buf, "LKRA %d", ffloor);
512         serv_puts(buf);
513         serv_gets(buf);
514         if (buf[0] != '1') {
515                 printf("%-72s\n", &buf[4]);
516                 return;
517         }
518         flist = NULL;
519         while (serv_gets(buf), strcmp(buf, "000")) {
520                 fptr = (struct march *) malloc(sizeof(struct march));
521                 fptr->next = flist;
522                 flist = fptr;
523                 extract(fptr->march_name, buf, 0);
524         }
525         while (flist != NULL) {
526                 snprintf(buf, sizeof buf, "GOTO %s", flist->march_name);
527                 serv_puts(buf);
528                 serv_gets(buf);
529                 if (buf[0] == '2') {
530                         serv_puts("FORG");
531                         serv_gets(buf);
532                 }
533                 fptr = flist;
534                 flist = flist->next;
535                 free(fptr);
536         }
537         printf("%-72s\r", "");
538 }
539
540
541 /*
542  * routine called by gotofloor() to move to a new room on a new floor
543  */
544 void gf_toroom(char *towhere, int mode)
545 {
546         int floor_being_left;
547
548         floor_being_left = curr_floor;
549
550         if (mode == GF_GOTO) {  /* <;G>oto mode */
551                 updatels();
552                 dotgoto(towhere, 1);
553         }
554         if (mode == GF_SKIP) {  /* <;S>kip mode */
555                 dotgoto(towhere, 1);
556                 remove_march("_FLOOR_", floor_being_left);
557         }
558         if (mode == GF_ZAP) {   /* <;Z>ap mode */
559                 dotgoto(towhere, 1);
560                 remove_march("_FLOOR_", floor_being_left);
561                 forget_all_rooms_on(floor_being_left);
562         }
563 }
564
565
566 /*
567  * go to a new floor
568  */
569 void gotofloor(char *towhere, int mode)
570 {
571         int a, tofloor;
572         struct march *mptr;
573         char buf[SIZ], targ[SIZ];
574
575         if (floorlist[0][0] == 0)
576                 load_floorlist();
577         tofloor = (-1);
578         for (a = 0; a < 128; ++a)
579                 if (!strcasecmp(&floorlist[a][0], towhere))
580                         tofloor = a;
581
582         if (tofloor < 0) {
583                 for (a = 0; a < 128; ++a) {
584                         if (!strncasecmp(&floorlist[a][0], towhere, strlen(towhere))) {
585                                 tofloor = a;
586                         }
587                 }
588         }
589         if (tofloor < 0) {
590                 for (a = 0; a < 128; ++a)
591                         if (pattern(towhere, &floorlist[a][0]) > 0)
592                                 tofloor = a;
593         }
594         if (tofloor < 0) {
595                 printf("No floor '%s'.\n", towhere);
596                 return;
597         }
598         for (mptr = march; mptr != NULL; mptr = mptr->next) {
599                 if ((mptr->march_floor) == tofloor)
600                         gf_toroom(mptr->march_name, mode);
601                 return;
602         }
603
604         strcpy(targ, "");
605         snprintf(buf, sizeof buf, "LKRA %d", tofloor);
606         serv_puts(buf);
607         serv_gets(buf);
608         if (buf[0] == '1')
609                 while (serv_gets(buf), strcmp(buf, "000")) {
610                         if ((extract_int(buf, 2) == tofloor) && (strlen(targ) == 0))
611                                 extract(targ, buf, 0);
612                 }
613         if (strlen(targ) > 0) {
614                 gf_toroom(targ, mode);
615         } else {
616                 printf("There are no rooms on '%s'.\n", &floorlist[tofloor][0]);
617         }
618 }
619
620
621 /*
622  * forget all rooms on current floor
623  */
624 void forget_this_floor(void)
625 {
626
627         if (curr_floor == 0) {
628                 printf("Can't forget this floor.\n");
629                 return;
630         }
631         if (floorlist[0][0] == 0)
632                 load_floorlist();
633         printf("Are you sure you want to forget all rooms on %s? ",
634                &floorlist[(int) curr_floor][0]);
635         if (yesno() == 0)
636                 return;
637
638         gf_toroom("_BASEROOM_", GF_ZAP);
639 }
640
641
642 /* 
643  * Figure out the physical screen dimensions, if we can
644  */
645 void check_screen_dims(void)
646 {
647 #ifdef TIOCGWINSZ
648         struct {
649                 unsigned short height;  /* rows */
650                 unsigned short width;   /* columns */
651                 unsigned short xpixels;
652                 unsigned short ypixels;         /* pixels */
653         } xwinsz;
654
655         if (have_xterm) {       /* dynamically size screen if on an xterm */
656                 if (ioctl(0, TIOCGWINSZ, &xwinsz) == 0) {
657                         if (xwinsz.height)
658                                 screenheight = (int) xwinsz.height;
659                         if (xwinsz.width)
660                                 screenwidth = (int) xwinsz.width;
661                 }
662         }
663 #endif
664 }
665
666
667 /*
668  * set floor mode depending on client, server, and user settings
669  */
670 void set_floor_mode(void)
671 {
672         if (serv_info.serv_ok_floors == 0) {
673                 floor_mode = 0; /* Don't use floors if the server */
674         }
675         /* doesn't support them!          */
676         else {
677                 if (rc_floor_mode == RC_NO) {   /* never use floors */
678                         floor_mode = 0;
679                 }
680                 if (rc_floor_mode == RC_YES) {  /* always use floors */
681                         floor_mode = 1;
682                 }
683                 if (rc_floor_mode == RC_DEFAULT) {      /* user choice */
684                         floor_mode = ((userflags & US_FLOORS) ? 1 : 0);
685                 }
686         }
687 }
688
689 /*
690  * Set or change the user's password
691  */
692 int set_password(void)
693 {
694         char pass1[20];
695         char pass2[20];
696         char buf[SIZ];
697
698         if (strlen(rc_password) > 0) {
699                 strcpy(pass1, rc_password);
700                 strcpy(pass2, rc_password);
701         } else {
702                 IFNEXPERT formout("changepw");
703                 newprompt("Enter a new password: ", pass1, -19);
704                 newprompt("Enter it again to confirm: ", pass2, -19);
705         }
706         strproc(pass1);
707         strproc(pass2);
708         if (!strcasecmp(pass1, pass2)) {
709                 snprintf(buf, sizeof buf, "SETP %s", pass1);
710                 serv_puts(buf);
711                 serv_gets(buf);
712                 printf("%s\n", &buf[4]);
713                 offer_to_remember_password(hostbuf, portbuf, fullname, pass1);
714                 return (0);
715         } else {
716                 printf("*** They don't match... try again.\n");
717                 return (1);
718         }
719 }
720
721
722
723 /*
724  * get info about the server we've connected to
725  */
726 void get_serv_info(char *supplied_hostname)
727 {
728         char buf[512];
729
730         CtdlInternalGetServInfo(&serv_info);
731
732         /* be nice and identify ourself to the server */
733         snprintf(buf, sizeof buf, "IDEN %d|%d|%d|%s|",
734                  SERVER_TYPE, 0, REV_LEVEL,
735                  (server_is_local ? "local" : CITADEL));
736
737         /* Append a hostname */
738         if (supplied_hostname != NULL) {
739                 strcat(buf, supplied_hostname);
740         }
741         else {
742                 locate_host(&buf[strlen(buf)]); /* append to the end */
743         }
744
745         serv_puts(buf);
746         serv_gets(buf);         /* we don't care about the result code */
747 }
748
749
750
751
752
753 /*
754  * Display list of users currently logged on to the server
755  */
756 void who_is_online(int longlist)
757 {
758         char buf[SIZ], username[SIZ], roomname[SIZ], fromhost[SIZ];
759         char flags[SIZ];
760         char actual_user[SIZ], actual_room[SIZ], actual_host[SIZ];
761         char tbuf[SIZ], clientsoft[SIZ];
762         time_t timenow = 0;
763         time_t idletime, idlehours, idlemins, idlesecs;
764         int last_session = (-1);
765
766         serv_puts("TIME");
767         serv_gets(tbuf);
768         if (tbuf[0] == '2') {
769                 timenow = extract_long(&tbuf[4], 0);
770         }
771         else {
772                 time(&timenow);
773         }
774
775         if (!longlist) {
776                 color(BRIGHT_WHITE);
777                 pprintf("FLG ###        User Name                 Room                 From host\n");
778                 color(DIM_WHITE);
779                 pprintf("--- --- ------------------------- -------------------- ------------------------\n");
780         }
781         serv_puts("RWHO");
782         serv_gets(buf);
783         if (buf[0] == '1') {
784                 while (serv_gets(buf), strcmp(buf, "000")) {
785                         extract(username, buf, 1);
786                         extract(roomname, buf, 2);
787                         extract(fromhost, buf, 3);
788                         extract(clientsoft, buf, 4);
789                         extract(flags, buf, 7);
790
791                         idletime = timenow - extract_long(buf, 5);
792                         idlehours = idletime / 3600;
793                         idlemins = (idletime - (idlehours * 3600)) / 60;
794                         idlesecs = (idletime - (idlehours * 3600) - (idlemins * 60));
795
796                         if (idletime > 900) {
797                                 while (strlen(roomname) < 20) {
798                                         strcat(roomname, " ");
799                                 }
800                                 strcpy(&roomname[14], "[idle]");
801                         }
802
803                         if (longlist) {
804
805                                 extract(actual_user, buf, 8);
806                                 extract(actual_room, buf, 9);
807                                 extract(actual_host, buf, 10);
808
809                                 pprintf("  Flags: %s\n", flags);
810                                 pprintf("Session: %d\n", extract_int(buf, 0));
811                                 pprintf("   Name: %s\n", username);
812                                 pprintf("In room: %s\n", roomname);
813                                 pprintf("   Host: %s\n", fromhost);
814                                 pprintf(" Client: %s\n", clientsoft);
815                                 pprintf("   Idle: %ld:%02ld:%02ld\n",
816                                         (long) idlehours,
817                                         (long) idlemins,
818                                         (long) idlesecs);
819
820                                 if ( (strlen(actual_user)+strlen(actual_room)+strlen(actual_host)) > 0) {
821                                         pprintf("(really ");
822                                         if (strlen(actual_user)>0) pprintf("<%s> ", actual_user);
823                                         if (strlen(actual_room)>0) pprintf("in <%s> ", actual_room);
824                                         if (strlen(actual_host)>0) pprintf("from <%s> ", actual_host);
825                                         pprintf(")\n");
826                                 }
827                                 pprintf("\n");
828
829                         } else {
830                                 if (extract_int(buf, 0) == last_session) {
831                                         pprintf("        ");
832                                 } else {
833                                         color(BRIGHT_MAGENTA);
834                                         pprintf("%-3s ", flags);
835                                         color(DIM_WHITE);
836                                         pprintf("%-3d ", extract_int(buf, 0));
837                                 }
838                                 last_session = extract_int(buf, 0);
839                                 color(BRIGHT_CYAN);
840                                 pprintf("%-25s ", username);
841                                 color(BRIGHT_MAGENTA);
842                                 roomname[20] = 0;
843                                 pprintf("%-20s ", roomname);
844                                 color(BRIGHT_CYAN);
845                                 fromhost[24] = '\0';
846                                 pprintf("%-24s\n", fromhost);
847                                 color(DIM_WHITE);
848                         }
849                 }
850         }
851 }
852
853 void enternew(char *desc, char *buf, int maxlen)
854 {
855         char bbb[128];
856         snprintf(bbb, sizeof bbb, "Enter in your new %s: ", desc);
857         newprompt(bbb, buf, maxlen);
858 }
859
860
861
862 int shift(int argc, char **argv, int start, int count) {
863         int i;
864
865         for (i=start; i<(argc-count); ++i) {
866                 argv[i] = argv[i+count];
867         }
868         argc = argc - count;
869         return argc;
870 }
871
872 /*
873  * main
874  */
875 int main(int argc, char **argv)
876 {
877         int a, b, mcmd;
878         char aaa[100], bbb[100];/* general purpose variables */
879         char argbuf[32];        /* command line buf */
880         char nonce[NONCE_SIZE];
881         char *telnet_client_host = NULL;
882         char *sptr, *sptr2;     /* USed to extract the nonce */
883         char hexstring[MD5_HEXSTRING_SIZE];
884         int stored_password = 0;
885         char password[SIZ];
886
887         /* Permissions sanity check - don't run citadel setuid/setgid */
888         if (getuid() != geteuid()) {
889                 fprintf(stderr, "Please do not run citadel setuid!\n");
890                 logoff(3);
891         } else if (getgid() != getegid()) {
892                 fprintf(stderr, "Please do not run citadel setgid!\n");
893                 logoff(3);
894         }
895
896         sttybbs(SB_SAVE);       /* Store the old terminal parameters */
897         load_command_set();     /* parse the citadel.rc file */
898         sttybbs(SB_NO_INTR);    /* Install the new ones */
899         signal(SIGHUP, dropcarr);       /* Cleanup gracefully if carrier is dropped */
900         signal(SIGTERM, dropcarr);      /* Cleanup gracefully if terminated */
901         signal(SIGCONT, catch_sigcont);         /* Catch SIGCONT so we can reset terminal */
902
903         /* 
904          * Handle command line options as if we were called like /bin/login
905          * (i.e. from in.telnetd)
906          */
907         for (a=0; a<argc; ++a) {
908                 if ((argc > a+1) && (!strcmp(argv[a], "-h")) ) {
909                         telnet_client_host = argv[a+1];
910                         argc = shift(argc, argv, a, 2);
911                 }
912                 if (!strcmp(argv[a], "-p")) {
913                         struct stat st;
914                 
915                         if (chdir(BBSDIR) < 0) {
916                                 perror("can't change to " BBSDIR);
917                                 logoff(3);
918                         }
919
920                         /*
921                          * Drop privileges if necessary. We stat
922                          * citadel.config to get the uid/gid since it's
923                          * guaranteed to have the uid/gid we want.
924                          */
925                         if (!getuid() || !getgid()) {
926                                 if (stat(BBSDIR "/citadel.config", &st) < 0) {
927                                         perror("couldn't stat citadel.config");
928                                         logoff(3);
929                                 }
930                                 if (!getgid() && (setgid(st.st_gid) < 0)) {
931                                         perror("couldn't change gid");
932                                         logoff(3);
933                                 }
934                                 if (!getuid() && (setuid(st.st_uid) < 0)) {
935                                         perror("couldn't change uid");
936                                         logoff(3);
937                                 }
938                                 /*
939                                 printf("Privileges changed to uid %d gid %d\n",
940                                                 getuid(), getgid());
941                                 */
942                         }
943                         argc = shift(argc, argv, a, 1);
944                 }
945         }
946
947         printf("Attaching to server... \r");
948         fflush(stdout);
949         attach_to_server(argc, argv, hostbuf, portbuf);
950
951         send_ansi_detect();
952
953         serv_gets(aaa);
954         if (aaa[0] != '2') {
955                 printf("%s\n", &aaa[4]);
956                 logoff(atoi(aaa));
957         }
958
959 /* If there is a [nonce] at the end, put the nonce in <nonce>, else nonce
960  * is zeroized.
961  */
962         
963         if ((sptr = strchr(aaa, '<')) == NULL)
964         {
965            nonce[0] = '\0';
966         }
967         else
968         {
969            if ((sptr2 = strchr(sptr, '>')) == NULL)
970            {
971               nonce[0] = '\0';
972            }
973            else
974            {
975               sptr2++;
976               *sptr2 = '\0';
977               strncpy(nonce, sptr, NONCE_SIZE);
978            }
979         }
980         
981         get_serv_info(telnet_client_host);
982
983         look_for_ansi();
984         cls(0);
985         color(7);
986
987         printf("%-23s\n%s\n%s\n", serv_info.serv_software, serv_info.serv_humannode,
988                serv_info.serv_bbs_city);
989         screenwidth = 80;       /* default screen dimensions */
990         screenheight = 24;
991
992         printf(" pause    next    stop\n");
993         printf(" ctrl-s  ctrl-o  ctrl-c\n\n");
994         formout("hello");       /* print the opening greeting */
995         printf("\n");
996
997 GSTA:   /* See if we have a username and password on disk */
998         if (rc_remember_passwords) {
999                 get_stored_password(hostbuf, portbuf, fullname, password);
1000                 if (strlen(fullname) > 0) {
1001                         snprintf(aaa, sizeof(aaa)-1, "USER %s", fullname);
1002                         serv_puts(aaa);
1003                         serv_gets(aaa);
1004                         if (nonce[0])
1005                         {
1006                                 sprintf(aaa, "PAS2 %s", make_apop_string(password, nonce, hexstring));
1007                         }
1008                         else    /* Else no APOP */
1009                         {
1010                                 snprintf(aaa, sizeof(aaa)-1, "PASS %s", password);
1011                         }
1012                         
1013                         serv_puts(aaa);
1014                         serv_gets(aaa);
1015                         if (aaa[0] == '2') {
1016                                 load_user_info(&aaa[4]);
1017                                 stored_password = 1;
1018                                 goto PWOK;
1019                         }
1020                         else {
1021                                 set_stored_password(hostbuf, portbuf, "", "");
1022                         }
1023                 }
1024         }
1025
1026         termn8 = 0;
1027         newnow = 0;
1028         do {
1029                 if (strlen(rc_username) > 0) {
1030                         strcpy(fullname, rc_username);
1031                 } else {
1032                         newprompt("Enter your name: ", fullname, 29);
1033                 }
1034                 strproc(fullname);
1035                 if (!strcasecmp(fullname, "new")) {     /* just in case */
1036                         printf("Please enter the name you wish to log in with.\n");
1037                 }
1038         } while (
1039                         (!strcasecmp(fullname, "bbs"))
1040                         || (!strcasecmp(fullname, "new"))
1041                         || (strlen(fullname) == 0));
1042
1043         if (!strcasecmp(fullname, "off")) {
1044                 mcmd = 29;
1045                 goto TERMN8;
1046         }
1047         /* sign on to the server */
1048         snprintf(aaa, sizeof aaa, "USER %s", fullname);
1049         serv_puts(aaa);
1050         serv_gets(aaa);
1051         if (aaa[0] != '3')
1052                 goto NEWUSR;
1053
1054         /* password authentication */
1055         if (strlen(rc_password) > 0) {
1056                 strcpy(password, rc_password);
1057         } else {
1058                 newprompt("\rPlease enter your password: ", password, -19);
1059         }
1060         strproc(password);
1061
1062         if (nonce[0])
1063         {
1064                 sprintf(aaa, "PAS2 %s", make_apop_string(password, nonce, hexstring));
1065         }
1066         else    /* Else no APOP */
1067         {
1068                         snprintf(aaa, sizeof(aaa)-1, "PASS %s", password);
1069         }
1070         
1071         serv_puts(aaa);
1072         serv_gets(aaa);
1073         if (aaa[0] == '2') {
1074                 load_user_info(&aaa[4]);
1075                 offer_to_remember_password(hostbuf, portbuf,
1076                                         fullname, password);
1077                 goto PWOK;
1078         }
1079         printf("<< wrong password >>\n");
1080         if (strlen(rc_password) > 0)
1081                 logoff(0);
1082         goto GSTA;
1083
1084 NEWUSR: if (strlen(rc_password) == 0) {
1085                 printf("No record. Enter as new user? ");
1086                 if (yesno() == 0)
1087                         goto GSTA;
1088         }
1089         snprintf(aaa, sizeof aaa, "NEWU %s", fullname);
1090         serv_puts(aaa);
1091         serv_gets(aaa);
1092         if (aaa[0] != '2') {
1093                 printf("%s\n", aaa);
1094                 goto GSTA;
1095         }
1096         load_user_info(&aaa[4]);
1097
1098         while (set_password() != 0);;
1099         newnow = 1;
1100
1101         enter_config(1);
1102
1103 PWOK:
1104         /* Switch color support on or off if we're in user mode */
1105         if (rc_ansi_color == 3) {
1106                 if (userflags & US_COLOR)
1107                         enable_color = 1;
1108                 else
1109                         enable_color = 0;
1110         }
1111
1112         printf("%s\nAccess level: %d (%s)\n"
1113                 "User #%ld / Login #%d",
1114                 fullname, axlevel, axdefs[(int) axlevel],
1115                 usernum, timescalled);
1116         if (lastcall > 0L) {
1117                 printf(" / Last login: %s\n",
1118                         asctime(localtime(&lastcall)) );
1119         }
1120         printf("\n");
1121
1122         serv_puts("CHEK");
1123         serv_gets(aaa);
1124         if (aaa[0] == '2') {
1125                 b = extract_int(&aaa[4], 0);
1126                 if (b > 0) {
1127                         color(BRIGHT_RED);
1128                         if (b == 1)
1129                                 printf("*** You have a new private message in Mail>\n");
1130                         if (b > 1)
1131                                 printf("*** You have %d new private messages in Mail>\n", b);
1132                         color(DIM_WHITE);
1133                 }
1134                 if ((axlevel >= 6) && (extract_int(&aaa[4], 2) > 0)) {
1135                         printf("*** Users need validation\n");
1136                 }
1137                 if (extract_int(&aaa[4], 1) > 0) {
1138                         printf("*** Please register.\n");
1139                         formout("register");
1140                         entregis();
1141                 }
1142         }
1143         /* Make up some temporary filenames for use in various parts of the
1144          * program.  Don't mess with these once they've been set, because we
1145          * will be unlinking them later on in the program and we don't
1146          * want to delete something that we didn't create. */
1147         snprintf(temp, sizeof temp, tmpnam(NULL));
1148         snprintf(temp2, sizeof temp2, tmpnam(NULL));
1149         snprintf(tempdir, sizeof tempdir, tmpnam(NULL));
1150
1151         /* Get screen dimensions.  First we go to a default of 80x24.  Then
1152          * we try to get the user's actual screen dimensions off the server.
1153          * However, if we're running on an xterm, all this stuff is
1154          * irrelevant because we're going to dynamically size the screen
1155          * during the session.
1156          */
1157         screenwidth = 80;
1158         screenheight = 24;
1159         serv_puts("GETU");
1160         serv_gets(aaa);
1161         if (aaa[0] == '2') {
1162                 screenwidth = extract_int(&aaa[4], 0);
1163                 screenheight = extract_int(&aaa[4], 1);
1164         }
1165         if (getenv("TERM") != NULL)
1166                 if (!strcmp(getenv("TERM"), "xterm")) {
1167                         have_xterm = 1;
1168                 }
1169 #ifdef TIOCGWINSZ
1170         check_screen_dims();
1171 #endif
1172
1173         set_floor_mode();
1174
1175
1176         /* Enter the lobby */
1177         dotgoto("_BASEROOM_", 1);
1178
1179 /* Main loop for the system... user is logged in. */
1180         strcpy(ugname, "");
1181         uglsn = 0L;
1182
1183         if (newnow == 1)
1184                 readmsgs(3, 1, 5);
1185         else
1186                 readmsgs(1, 1, 0);
1187
1188         /* MAIN COMMAND LOOP */
1189         do {
1190                 mcmd = getcmd(argbuf);          /* Get keyboard command */
1191
1192 #ifdef TIOCGWINSZ
1193                 check_screen_dims();            /* if xterm, get screen size */
1194 #endif
1195
1196                 if (termn8 == 0)
1197                         switch (mcmd) {
1198                         case 1:
1199                                 formout("help");
1200                                 break;
1201                         case 4:
1202                                 entmsg(0, 0);
1203                                 break;
1204                         case 36:
1205                                 entmsg(0, 1);
1206                                 break;
1207                         case 46:
1208                                 entmsg(0, 2);
1209                                 break;
1210                         case 78:
1211                                 newprompt("What do you want your username to be? ", aaa, 32);
1212                                 snprintf(bbb, sizeof bbb, "ENT0 2|0|0|0|%s", aaa);
1213                                 serv_puts(bbb);
1214                                 serv_gets(aaa);
1215                                 if (strncmp("200", aaa, 3))
1216                                         printf("\n%s\n", aaa);
1217                                 else
1218                                         entmsg(0, 0);
1219                                 break;
1220                         case 5:
1221                                 updatels();
1222                                 gotonext();
1223                                 break;
1224                         case 47:
1225                                 updatelsa();
1226                                 gotonext();
1227                                 break;
1228                         case 58:
1229                                 updatelsa();
1230                                 dotgoto("_MAIL_", 1);
1231                                 break;
1232                         case 20:
1233                                 updatels();
1234                         case 52:
1235                                 dotgoto(argbuf, 0);
1236                                 break;
1237                         case 10:
1238                                 readmsgs(0, 1, 0);
1239                                 break;
1240                         case 9:
1241                                 readmsgs(3, 1, 5);
1242                                 break;
1243                         case 13:
1244                                 readmsgs(1, 1, 0);
1245                                 break;
1246                         case 11:
1247                                 readmsgs(0, (-1), 0);
1248                                 break;
1249                         case 12:
1250                                 readmsgs(2, (-1), 0);
1251                                 break;
1252                         case 71:
1253                                 readmsgs(3, 1, atoi(argbuf));
1254                                 break;
1255                         case 7:
1256                                 forget();
1257                                 break;
1258                         case 18:
1259                                 subshell();
1260                                 break;
1261                         case 38:
1262                                 updatels();
1263                                 entroom();
1264                                 break;
1265                         case 22:
1266                                 killroom();
1267                                 break;
1268                         case 32:
1269                                 userlist(argbuf);
1270                                 break;
1271                         case 27:
1272                                 invite();
1273                                 break;
1274                         case 28:
1275                                 kickout();
1276                                 break;
1277                         case 23:
1278                                 editthisroom();
1279                                 break;
1280                         case 14:
1281                                 roomdir();
1282                                 break;
1283                         case 33:
1284                                 download(0);
1285                                 break;
1286                         case 34:
1287                                 download(1);
1288                                 break;
1289                         case 31:
1290                                 download(2);
1291                                 break;
1292                         case 43:
1293                                 download(3);
1294                                 break;
1295                         case 45:
1296                                 download(4);
1297                                 break;
1298                         case 55:
1299                                 download(5);
1300                                 break;
1301                         case 39:
1302                                 upload(0);
1303                                 break;
1304                         case 40:
1305                                 upload(1);
1306                                 break;
1307                         case 42:
1308                                 upload(2);
1309                                 break;
1310                         case 44:
1311                                 upload(3);
1312                                 break;
1313                         case 57:
1314                                 cli_upload();
1315                                 break;
1316                         case 16:
1317                                 ungoto();
1318                                 break;
1319                         case 24:
1320                                 whoknows();
1321                                 break;
1322                         case 26:
1323                                 validate();
1324                                 break;
1325                         case 29:
1326                                 updatels();
1327                                 termn8 = 1;
1328                                 break;
1329                         case 30:
1330                                 updatels();
1331                                 termn8 = 1;
1332                                 break;
1333                         case 48:
1334                                 enterinfo();
1335                                 break;
1336                         case 49:
1337                                 readinfo();
1338                                 break;
1339                         case 72:
1340                                 cli_image_upload("_userpic_");
1341                                 break;
1342                         case 73:
1343                                 cli_image_upload("_roompic_");
1344                                 break;
1345
1346                         case 74:
1347                                 snprintf(aaa, sizeof aaa, "_floorpic_|%d", curr_floor);
1348                                 cli_image_upload(aaa);
1349                                 break;
1350
1351                         case 75:
1352                                 enternew("roomname", aaa, 20);
1353                                 snprintf(bbb, sizeof bbb, "RCHG %s", aaa);
1354                                 serv_puts(bbb);
1355                                 serv_gets(aaa);
1356                                 if (strncmp("200", aaa, 3))
1357                                         printf("\n%s\n", aaa);
1358                                 break;
1359                         case 76:
1360                                 enternew("hostname", aaa, 25);
1361                                 snprintf(bbb, sizeof bbb, "HCHG %s", aaa);
1362                                 serv_puts(bbb);
1363                                 serv_gets(aaa);
1364                                 if (strncmp("200", aaa, 3))
1365                                         printf("\n%s\n", aaa);
1366                                 break;
1367                         case 77:
1368                                 enternew("username", aaa, 32);
1369                                 snprintf(bbb, sizeof bbb, "UCHG %s", aaa);
1370                                 serv_puts(bbb);
1371                                 serv_gets(aaa);
1372                                 if (strncmp("200", aaa, 3))
1373                                         printf("\n%s\n", aaa);
1374                                 break;
1375
1376                         case 35:
1377                                 set_password();
1378                                 break;
1379
1380                         case 21:
1381                                 if (argbuf[0] == 0)
1382                                         strcpy(aaa, "?");
1383                                 display_help(argbuf);
1384                                 break;
1385
1386                         case 41:
1387                                 formout("register");
1388                                 entregis();
1389                                 break;
1390
1391                         case 15:
1392                                 printf("Are you sure (y/n)? ");
1393                                 if (yesno() == 1) {
1394                                         updatels();
1395                                         a = 0;
1396                                         termn8 = 1;
1397                                 }
1398                                 break;
1399
1400                         case 85:
1401                                 printf("All users will be disconnected!  "
1402                                         "Really terminate the server? ");
1403                                 if (yesno() == 1) {
1404                                         serv_puts("DOWN");
1405                                         serv_gets(aaa);
1406                                         printf("%s\n", &aaa[4]);
1407                                         if (aaa[0]=='2') {
1408                                                 updatels();
1409                                                 a = 0;
1410                                                 termn8 = 1;
1411                                         }
1412                                 }
1413                                 break;
1414
1415                         case 86:
1416                                 printf("Do you really want to schedule a "
1417                                         "server shutdown? ");
1418                                 if (yesno() == 1) {
1419                                         serv_puts("SCDN 1");
1420                                         serv_gets(aaa);
1421                                         if (aaa[0]=='2') {
1422                                                 if (atoi(&aaa[4])) {
1423                                                         printf(
1424 "The Citadel server will terminate when all users are logged off.\n"
1425                                                                 );
1426                                                 }
1427                                                 else {
1428                                                         printf(
1429 "The Citadel server will not terminate.\n"
1430                                                                 );
1431                                                 }
1432                                         }
1433                                 }
1434                                 break;
1435
1436                         case 87:
1437                                 network_config_management("listrecp",
1438                                         "Mailing list recipients");
1439                                 break;
1440
1441                         case 89:
1442                                 network_config_management("ignet_push_share",
1443                                         "Nodes with which we share this room");
1444                                 break;
1445
1446                         case 88:
1447                                 do_ignet_configuration();
1448                                 break;
1449
1450                         case 6:
1451                                 gotonext();
1452                                 break;
1453
1454                         case 3:
1455                                 chatmode();
1456                                 break;
1457
1458                         case 2:
1459                                 if (server_is_local) {
1460                                         sttybbs(SB_RESTORE);
1461                                         snprintf(aaa, sizeof aaa, "USERNAME=\042%s\042; export USERNAME;"
1462                                                  "exec ./subsystem %ld %d %d", fullname,
1463                                           usernum, screenwidth, axlevel);
1464                                         ka_system(aaa);
1465                                         sttybbs(SB_NO_INTR);
1466                                 } else {
1467                                         printf("*** Can't run doors when server is not local.\n");
1468                                 }
1469                                 break;
1470
1471                         case 17:
1472                                 who_is_online(0);
1473                                 break;
1474
1475                         case 79:
1476                                 who_is_online(1);
1477                                 break;
1478
1479                         case 80:
1480                                 do_system_configuration();
1481                                 break;
1482
1483                         case 82:
1484                                 do_internet_configuration();
1485                                 break;
1486
1487                         case 83:
1488                                 check_message_base();
1489                                 break;
1490
1491                         case 84:
1492                                 quiet_mode();
1493                                 break;
1494
1495                         case 50:
1496                                 enter_config(2);
1497                                 break;
1498
1499                         case 37:
1500                                 enter_config(0);
1501                                 set_floor_mode();
1502                                 break;
1503
1504                         case 59:
1505                                 enter_config(3);
1506                                 set_floor_mode();
1507                                 break;
1508
1509                         case 60:
1510                                 gotofloor(argbuf, GF_GOTO);
1511                                 break;
1512
1513                         case 61:
1514                                 gotofloor(argbuf, GF_SKIP);
1515                                 break;
1516
1517                         case 62:
1518                                 forget_this_floor();
1519                                 break;
1520
1521                         case 63:
1522                                 create_floor();
1523                                 break;
1524
1525                         case 64:
1526                                 edit_floor();
1527                                 break;
1528
1529                         case 65:
1530                                 kill_floor();
1531                                 break;
1532
1533                         case 66:
1534                                 enter_bio();
1535                                 break;
1536
1537                         case 67:
1538                                 read_bio();
1539                                 break;
1540
1541                         case 25:
1542                                 edituser();
1543                                 break;
1544
1545                         case 8:
1546                                 knrooms(floor_mode);
1547                                 printf("\n");
1548                                 break;
1549
1550                         case 68:
1551                                 knrooms(2);
1552                                 printf("\n");
1553                                 break;
1554
1555                         case 69:
1556                                 misc_server_cmd(argbuf);
1557                                 break;
1558
1559                         case 70:
1560                                 edit_system_message(argbuf);
1561                                 break;
1562
1563                         case 19:
1564                                 listzrooms();
1565                                 printf("\n");
1566                                 break;
1567
1568                         case 51:
1569                                 deletefile();
1570                                 break;
1571
1572                         case 53:
1573                                 netsendfile();
1574                                 break;
1575
1576                         case 54:
1577                                 movefile();
1578                                 break;
1579
1580                         case 56:
1581                                 page_user();
1582                                 break;
1583
1584                         }       /* end switch */
1585         } while (termn8 == 0);
1586
1587 TERMN8: printf("%s logged out.\n", fullname);
1588         while (march != NULL) {
1589                 remove_march(march->march_name, 0);
1590         }
1591         if (mcmd == 30) {
1592                 printf("\n\nType 'off' to disconnect, or next user...\n");
1593         }
1594         snprintf(aaa, sizeof aaa, "LOUT");
1595         serv_puts(aaa);
1596         serv_gets(aaa);
1597         if ((mcmd == 29) || (mcmd == 15)) {
1598                 formout("goodbye");
1599                 logoff(0);
1600         }
1601         goto GSTA;
1602
1603 }       /* end main() */