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