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