4 * Main source module for the client program.
15 #if TIME_WITH_SYS_TIME
16 # include <sys/time.h>
20 # include <sys/time.h>
27 #include <sys/types.h>
30 #include <sys/ioctl.h>
38 #include "serv_info.h"
40 #include "routines2.h"
45 #include "client_chat.h"
46 #include "client_passwords.h"
47 #include "citadel_decls.h"
50 #include "client_crypto.h"
60 char march_name[ROOMNAMELEN];
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)
70 struct march *march = NULL;
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);
81 struct CtdlServInfo serv_info; /* Info on the server connected */
85 char room_name[ROOMNAMELEN];
86 char *uglist[UGLISTLEN]; /* size of the ungoto list */
87 long uglistlsn[UGLISTLEN]; /* current read position for all the ungoto's. Not going to make any friends with this one. */
89 char is_mail = 0; /* nonzero when we're in a mail room */
90 char axlevel = 0; /* access level */
91 char is_room_aide = 0; /* boolean flag, 1 if room aide */
95 long usernum = 0L; /* user number */
96 time_t lastcall = 0L; /* Date/time of previous login */
98 long highest_msg_read; /* used for <A>bandon room cmd */
99 long maxmsgnum; /* used for <G>oto */
101 char have_xterm = 0; /* are we running on an xterm? */
102 char rc_username[32];
103 char rc_password[32];
108 char curr_floor = 0; /* number of current floor */
109 char floorlist[128][SIZ]; /* names of floors */
110 char express_msgs = 0; /* express messages waiting! */
111 int termn8 = 0; /* Set to nonzero to cause a logoff */
112 int secure; /* Set to nonzero when wire is encrypted */
114 extern int rc_ansi_color; /* ansi color value from citadel.rc */
115 extern int next_lazy_cmd;
118 * here is our 'clean up gracefully and exit' routine
120 void logoff(int code)
123 if (editor_pid > 0) { /* kill the editor if it's running */
124 kill(editor_pid, SIGHUP);
127 /* Free the ungoto list */
128 for (lp = 0; lp < uglistsize; lp++)
131 /* shut down the server... but not if the logoff code is 3, because
132 * that means we're exiting because we already lost the server
138 * now clean up various things
147 /* Violently kill off any child processes if Citadel is
150 if (getppid() == 1) {
151 kill(0 - getpgrp(), SIGTERM);
153 kill(0 - getpgrp(), SIGKILL);
155 sttybbs(SB_RESTORE); /* return the old terminal settings */
156 exit(code); /* exit with the proper exit code */
162 * signal catching function for hangups...
164 void dropcarr(int signum)
172 * catch SIGCONT to reset terminal modes when were are put back into the
175 void catch_sigcont(int signum)
178 signal(SIGCONT, catch_sigcont);
183 /* general purpose routines */
185 void formout(char *name)
186 { /* display a file */
188 snprintf(cmd, sizeof cmd, "MESG %s", name);
192 scr_printf("%s\n", &cmd[4]);
195 fmout(screenwidth, NULL, NULL,
196 ((userflags & US_PAGINATOR) ? 1 : 0),
201 void userlist(char *patn)
211 pprintf("%s\n", &buf[4]);
214 pprintf(" User Name Num L LastCall Calls Posts\n");
215 pprintf("------------------------- ----- - ---------- ----- -----\n");
216 while (serv_gets(buf), strcmp(buf, "000")) {
217 if (sigcaught == 0) {
219 if (pattern(fl, patn) >= 0) {
220 pprintf("%-25s ", fl);
221 pprintf("%5ld %d ", extract_long(buf, 2),
222 extract_int(buf, 1));
223 lc = extract_long(buf, 3);
224 tmbuf = (struct tm *) localtime(&lc);
225 pprintf("%02d/%02d/%04d ",
228 (tmbuf->tm_year + 1900));
229 pprintf("%5ld %5ld\n", extract_long(buf, 4), extract_long(buf, 5));
239 * grab assorted info about the user...
241 void load_user_info(char *params)
243 extract(fullname, params, 0);
244 axlevel = extract_int(params, 1);
245 timescalled = extract_int(params, 2);
246 posted = extract_int(params, 3);
247 userflags = extract_int(params, 4);
248 usernum = extract_long(params, 5);
249 lastcall = extract_long(params, 6);
254 * Remove a room from the march list. 'floornum' is ignored unless
255 * 'roomname' is set to _FLOOR_, in which case all rooms on the requested
256 * floor will be removed from the march list.
258 void remove_march(char *roomname, int floornum)
260 struct march *mptr, *mptr2;
265 if ((!strcasecmp(march->march_name, roomname))
266 || ((!strcasecmp(roomname, "_FLOOR_")) && (march->march_floor == floornum))) {
273 for (mptr = march; mptr != NULL; mptr = mptr->next) {
275 if ((!strcasecmp(mptr->march_name, roomname))
276 || ((!strcasecmp(roomname, "_FLOOR_"))
277 && (mptr->march_floor == floornum))) {
279 mptr2->next = mptr->next;
290 * Locate the room on the march list which we most want to go to. Each room
291 * is measured given a "weight" of preference based on various factors.
293 char *pop_march(int desired_floor)
295 static char TheRoom[ROOMNAMELEN];
297 int TheOrder = 32767;
300 struct march *mptr = NULL;
302 strcpy(TheRoom, "_BASEROOM_");
306 for (mptr = march; mptr != NULL; mptr = mptr->next) {
308 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
309 weight = weight + 10000;
310 if (mptr->march_floor == desired_floor)
311 weight = weight + 5000;
313 weight = weight + ((128 - (mptr->march_floor)) * 128);
314 weight = weight + (128 - (mptr->march_order));
316 if (weight > TheWeight) {
318 strcpy(TheRoom, mptr->march_name);
319 TheFloor = mptr->march_floor;
320 TheOrder = mptr->march_order;
328 * jump directly to a room
330 void dotgoto(char *towhere, int display_name, int fromungoto)
332 char aaa[SIZ], bbb[SIZ], psearch[SIZ];
334 int newmailcount = 0;
335 int partial_match, best_match;
337 int ugpos = uglistsize;
339 /* store ungoto information */
342 if (uglistsize >= (UGLISTLEN-1))
343 { /* sloppy slide them all down, hey it's the client, who cares. :-) */
346 for (lp = 0; lp < (UGLISTLEN-1); lp++)
348 uglist[lp] = uglist[lp+1];
349 uglistlsn[lp] = uglistlsn[lp+1];
356 uglist[ugpos] = malloc(strlen(room_name)+1);
357 strcpy(uglist[ugpos], room_name);
358 uglistlsn[ugpos] = ls;
361 /* first try an exact match */
362 snprintf(aaa, sizeof aaa, "GOTO %s", towhere);
367 if (!strncmp(aaa, "54", 2)) {
368 newprompt("Enter room password: ", bbb, 9);
369 snprintf(aaa, sizeof aaa, "GOTO %s|%s", towhere, bbb);
375 if (!strncmp(aaa, "54", 2)) {
376 scr_printf("Wrong password.\n");
380 * If a match is not found, try a partial match.
381 * Partial matches anywhere in the string carry a weight of 1,
382 * left-aligned matches carry a weight of 2. Pick the room that
383 * has the highest-weighted match.
391 while (serv_gets(aaa), strcmp(aaa, "000")) {
392 extract(psearch, aaa, 0);
394 if (pattern(psearch, towhere) >= 0) {
397 if (!strncasecmp(towhere, psearch, strlen(towhere))) {
400 if (partial_match > best_match) {
401 strcpy(bbb, psearch);
402 best_match = partial_match;
405 if (strlen(bbb) == 0) {
406 scr_printf("No room '%s'.\n", towhere);
409 snprintf(aaa, sizeof aaa, "GOTO %s", bbb);
416 scr_printf("%s\n", aaa);
419 extract(room_name, &aaa[4], 0);
420 room_flags = extract_int(&aaa[4], 4);
421 from_floor = curr_floor;
422 curr_floor = extract_int(&aaa[4], 10);
424 remove_march(room_name, 0);
425 if (!strcasecmp(towhere, "_BASEROOM_"))
426 remove_march(towhere, 0);
427 if (!extract_int(&aaa[4], 1))
428 next_lazy_cmd = 5; /* Don't read new if no new msgs */
429 if ((from_floor != curr_floor) && (display_name > 0) && (floor_mode == 1)) {
430 if (floorlist[(int) curr_floor][0] == 0)
432 scr_printf("(Entering floor: %s)\n", &floorlist[(int) curr_floor][0]);
434 if (display_name == 1) {
436 scr_printf("%s ", room_name);
440 if (display_name != 2) {
441 color(BRIGHT_YELLOW);
442 scr_printf("%d ", extract_int(&aaa[4], 1));
444 scr_printf("new of ");
445 color(BRIGHT_YELLOW);
446 scr_printf("%d ", extract_int(&aaa[4], 2));
448 scr_printf("messages.\n");
450 highest_msg_read = extract_int(&aaa[4], 6);
451 maxmsgnum = extract_int(&aaa[4], 5);
452 is_mail = (char) extract_int(&aaa[4], 7);
453 is_room_aide = (char) extract_int(&aaa[4], 8);
454 ls = extract_long(&aaa[4], 6);
456 /* read info file if necessary */
457 if (extract_int(&aaa[4], 3) > 0)
460 /* check for newly arrived mail if we can */
461 if (num_parms(&aaa[4]) >= 10) {
462 newmailcount = extract_int(&aaa[4], 9);
463 if (newmailcount > 0) {
465 scr_printf("*** You have %d new mail message%s\n",
466 newmailcount - oldmailcount,
467 (newmailcount - oldmailcount == 1) ?
471 status_line(serv_info.serv_humannode, serv_info.serv_bbs_city,
472 room_name, secure, newmailcount);
474 status_line(serv_info.serv_humannode, serv_info.serv_bbs_city,
475 room_name, secure, -1);
479 /* Goto next room having unread messages.
480 * We want to skip over rooms that the user has already been to, and take the
481 * user back to the lobby when done. The room we end up in is placed in
482 * newroom - which is set to 0 (the lobby) initially.
487 struct march *mptr, *mptr2;
488 char next_room[ROOMNAMELEN];
490 /* Check to see if the march-mode list is already allocated.
491 * If it is, pop the first room off the list and go there.
497 while (serv_gets(buf), strcmp(buf, "000")) {
498 mptr = (struct march *) malloc(sizeof(struct march));
500 extract(mptr->march_name, buf, 0);
501 mptr->march_floor = (char) (extract_int(buf, 2) & 0x7F);
502 mptr->march_order = (char) (extract_int(buf, 3) & 0x7F);
507 while (mptr2->next != NULL)
512 /* add _BASEROOM_ to the end of the march list, so the user will end up
513 * in the system base room (usually the Lobby>) at the end of the loop
515 mptr = (struct march *) malloc(sizeof(struct march));
517 strcpy(mptr->march_name, "_BASEROOM_");
522 while (mptr2->next != NULL)
527 * ...and remove the room we're currently in, so a <G>oto doesn't make us
528 * walk around in circles
530 remove_march(room_name, 0);
533 strcpy(next_room, pop_march(curr_floor));
535 strcpy(next_room, "_BASEROOM_");
537 remove_march(next_room, 0);
538 dotgoto(next_room, 1, 0);
542 * forget all rooms on a given floor
544 void forget_all_rooms_on(int ffloor)
547 struct march *flist, *fptr;
549 scr_printf("Forgetting all rooms on %s...\r", &floorlist[ffloor][0]);
551 snprintf(buf, sizeof buf, "LKRA %d", ffloor);
555 scr_printf("%-72s\n", &buf[4]);
559 while (serv_gets(buf), strcmp(buf, "000")) {
560 fptr = (struct march *) malloc(sizeof(struct march));
563 extract(fptr->march_name, buf, 0);
565 while (flist != NULL) {
566 snprintf(buf, sizeof buf, "GOTO %s", flist->march_name);
577 scr_printf("%-72s\r", "");
582 * routine called by gotofloor() to move to a new room on a new floor
584 void gf_toroom(char *towhere, int mode)
586 int floor_being_left;
588 floor_being_left = curr_floor;
590 if (mode == GF_GOTO) { /* <;G>oto mode */
592 dotgoto(towhere, 1, 0);
594 if (mode == GF_SKIP) { /* <;S>kip mode */
595 dotgoto(towhere, 1, 0);
596 remove_march("_FLOOR_", floor_being_left);
598 if (mode == GF_ZAP) { /* <;Z>ap mode */
599 dotgoto(towhere, 1, 0);
600 remove_march("_FLOOR_", floor_being_left);
601 forget_all_rooms_on(floor_being_left);
609 void gotofloor(char *towhere, int mode)
613 char buf[SIZ], targ[SIZ];
615 if (floorlist[0][0] == 0)
618 for (a = 0; a < 128; ++a)
619 if (!strcasecmp(&floorlist[a][0], towhere))
623 for (a = 0; a < 128; ++a) {
624 if (!strncasecmp(&floorlist[a][0], towhere, strlen(towhere))) {
630 for (a = 0; a < 128; ++a)
631 if (pattern(towhere, &floorlist[a][0]) > 0)
635 scr_printf("No floor '%s'.\n", towhere);
638 for (mptr = march; mptr != NULL; mptr = mptr->next) {
639 if ((mptr->march_floor) == tofloor)
640 gf_toroom(mptr->march_name, mode);
645 snprintf(buf, sizeof buf, "LKRA %d", tofloor);
649 while (serv_gets(buf), strcmp(buf, "000")) {
650 if ((extract_int(buf, 2) == tofloor) && (strlen(targ) == 0))
651 extract(targ, buf, 0);
653 if (strlen(targ) > 0) {
654 gf_toroom(targ, mode);
656 scr_printf("There are no rooms on '%s'.\n", &floorlist[tofloor][0]);
662 * forget all rooms on current floor
664 void forget_this_floor(void)
667 if (curr_floor == 0) {
668 scr_printf("Can't forget this floor.\n");
671 if (floorlist[0][0] == 0)
673 scr_printf("Are you sure you want to forget all rooms on %s? ",
674 &floorlist[(int) curr_floor][0]);
678 gf_toroom("_BASEROOM_", GF_ZAP);
683 * Figure out the physical screen dimensions, if we can
684 * WARNING: this is now called from a signal handler!
686 void check_screen_dims(void)
690 unsigned short height; /* rows */
691 unsigned short width; /* columns */
692 unsigned short xpixels;
693 unsigned short ypixels; /* pixels */
696 if (have_xterm) { /* dynamically size screen if on an xterm */
697 if (ioctl(0, TIOCGWINSZ, &xwinsz) == 0) {
699 screenheight = is_curses_enabled() ? (int)xwinsz.height - 1 : (int) xwinsz.height;
701 screenwidth = (int) xwinsz.width;
709 * set floor mode depending on client, server, and user settings
711 void set_floor_mode(void)
713 if (serv_info.serv_ok_floors == 0) {
714 floor_mode = 0; /* Don't use floors if the server */
716 /* doesn't support them! */
718 if (rc_floor_mode == RC_NO) { /* never use floors */
721 if (rc_floor_mode == RC_YES) { /* always use floors */
724 if (rc_floor_mode == RC_DEFAULT) { /* user choice */
725 floor_mode = ((userflags & US_FLOORS) ? 1 : 0);
731 * Set or change the user's password
733 int set_password(void)
739 if (strlen(rc_password) > 0) {
740 strcpy(pass1, rc_password);
741 strcpy(pass2, rc_password);
743 IFNEXPERT formout("changepw");
744 newprompt("Enter a new password: ", pass1, -19);
745 newprompt("Enter it again to confirm: ", pass2, -19);
749 if (!strcasecmp(pass1, pass2)) {
750 snprintf(buf, sizeof buf, "SETP %s", pass1);
753 scr_printf("%s\n", &buf[4]);
754 offer_to_remember_password(hostbuf, portbuf, fullname, pass1);
757 scr_printf("*** They don't match... try again.\n");
765 * get info about the server we've connected to
767 void get_serv_info(char *supplied_hostname)
771 CtdlInternalGetServInfo(&serv_info);
773 /* be nice and identify ourself to the server */
774 snprintf(buf, sizeof buf, "IDEN %d|%d|%d|%s|",
775 SERVER_TYPE, 0, REV_LEVEL,
776 (server_is_local ? "local" : CITADEL));
778 /* Append a hostname */
779 if (supplied_hostname != NULL) {
780 strcat(buf, supplied_hostname);
783 locate_host(&buf[strlen(buf)]); /* append to the end */
787 serv_gets(buf); /* we don't care about the result code */
795 * Display list of users currently logged on to the server
797 void who_is_online(int longlist)
799 char buf[SIZ], username[SIZ], roomname[SIZ], fromhost[SIZ];
801 char actual_user[SIZ], actual_room[SIZ], actual_host[SIZ];
802 char tbuf[SIZ], clientsoft[SIZ];
804 time_t idletime, idlehours, idlemins, idlesecs;
805 int last_session = (-1);
816 if (tbuf[0] == '2') {
817 timenow = extract_long(&tbuf[4], 0);
825 pprintf("FLG ### User Name Room From host\n");
827 pprintf("--- --- ------------------------- -------------------- ------------------------\n");
832 while (serv_gets(buf), strcmp(buf, "000")) {
834 extract(username, buf, 1);
835 extract(roomname, buf, 2);
836 extract(fromhost, buf, 3);
837 extract(clientsoft, buf, 4);
838 extract(flags, buf, 7);
840 idletime = timenow - extract_long(buf, 5);
841 idlehours = idletime / 3600;
842 idlemins = (idletime - (idlehours * 3600)) / 60;
843 idlesecs = (idletime - (idlehours * 3600) - (idlemins * 60));
845 if (idletime > rc_idle_threshold) {
846 while (strlen(roomname) < 20) {
847 strcat(roomname, " ");
849 strcpy(&roomname[14], "[idle]");
856 extract(actual_user, buf, 8);
857 extract(actual_room, buf, 9);
858 extract(actual_host, buf, 10);
860 pprintf(" Flags: %s\n", flags);
861 pprintf("Session: %d\n", extract_int(buf, 0));
862 pprintf(" Name: %s\n", username);
863 pprintf("In room: %s\n", roomname);
864 pprintf(" Host: %s\n", fromhost);
865 pprintf(" Client: %s\n", clientsoft);
866 pprintf(" Idle: %ld:%02ld:%02ld\n",
871 if ( (strlen(actual_user)+strlen(actual_room)+strlen(actual_host)) > 0) {
873 if (strlen(actual_user)>0) pprintf("<%s> ", actual_user);
874 if (strlen(actual_room)>0) pprintf("in <%s> ", actual_room);
875 if (strlen(actual_host)>0) pprintf("from <%s> ", actual_host);
882 if (extract_int(buf, 0) == last_session) {
885 color(BRIGHT_MAGENTA);
886 pprintf("%-3s ", flags);
888 pprintf("%-3d ", extract_int(buf, 0));
890 last_session = extract_int(buf, 0);
892 pprintf("%-25s ", username);
893 color(BRIGHT_MAGENTA);
895 pprintf("%-20s ", roomname);
898 pprintf("%-24s\n", fromhost);
906 void enternew(char *desc, char *buf, int maxlen)
909 snprintf(bbb, sizeof bbb, "Enter in your new %s: ", desc);
910 newprompt(bbb, buf, maxlen);
915 int shift(int argc, char **argv, int start, int count) {
918 for (i=start; i<(argc-count); ++i) {
919 argv[i] = argv[i+count];
925 static void statusHook(char *s) {
933 int main(int argc, char **argv)
936 char aaa[100], bbb[100];/* general purpose variables */
937 char argbuf[32]; /* command line buf */
938 char nonce[NONCE_SIZE];
939 char *telnet_client_host = NULL;
940 char *sptr, *sptr2; /* USed to extract the nonce */
941 char hexstring[MD5_HEXSTRING_SIZE];
942 int stored_password = 0;
945 setIPCDeathHook(screen_delete);
946 setIPCErrorPrintf(err_printf);
947 setCryptoStatusHook(statusHook);
949 /* Permissions sanity check - don't run citadel setuid/setgid */
950 if (getuid() != geteuid()) {
951 err_printf("Please do not run citadel setuid!\n");
953 } else if (getgid() != getegid()) {
954 err_printf("Please do not run citadel setgid!\n");
958 sttybbs(SB_SAVE); /* Store the old terminal parameters */
959 load_command_set(); /* parse the citadel.rc file */
960 sttybbs(SB_NO_INTR); /* Install the new ones */
961 signal(SIGHUP, dropcarr); /* Cleanup gracefully if carrier is dropped */
962 signal(SIGTERM, dropcarr); /* Cleanup gracefully if terminated */
963 signal(SIGCONT, catch_sigcont); /* Catch SIGCONT so we can reset terminal */
965 signal(SIGWINCH, scr_winch); /* Window resize signal */
969 arg_encrypt = RC_DEFAULT;
972 arg_screen = RC_DEFAULT;
976 * Handle command line options as if we were called like /bin/login
977 * (i.e. from in.telnetd)
979 for (a=0; a<argc; ++a) {
980 if ((argc > a+1) && (!strcmp(argv[a], "-h")) ) {
981 telnet_client_host = argv[a+1];
982 argc = shift(argc, argv, a, 2);
984 if (!strcmp(argv[a], "-x")) {
988 argc = shift(argc, argv, a, 1);
990 if (!strcmp(argv[a], "-X")) {
992 arg_encrypt = RC_YES;
993 argc = shift(argc, argv, a, 1);
995 fprintf(stderr, "Not compiled with encryption support");
999 if (!strcmp(argv[a], "-s")) {
1000 #ifdef HAVE_CURSES_H
1003 argc = shift(argc, argv, a, 1);
1005 if (!strcmp(argv[a], "-S")) {
1006 #ifdef HAVE_CURSES_H
1007 arg_screen = RC_YES;
1009 argc = shift(argc, argv, a, 1);
1011 if (!strcmp(argv[a], "-p")) {
1014 if (chdir(BBSDIR) < 0) {
1015 perror("can't change to " BBSDIR);
1020 * Drop privileges if necessary. We stat
1021 * citadel.config to get the uid/gid since it's
1022 * guaranteed to have the uid/gid we want.
1024 if (!getuid() || !getgid()) {
1025 if (stat(BBSDIR "/citadel.config", &st) < 0) {
1026 perror("couldn't stat citadel.config");
1029 if (!getgid() && (setgid(st.st_gid) < 0)) {
1030 perror("couldn't change gid");
1033 if (!getuid() && (setuid(st.st_uid) < 0)) {
1034 perror("couldn't change uid");
1038 scr_printf("Privileges changed to uid %d gid %d\n",
1039 getuid(), getgid());
1042 argc = shift(argc, argv, a, 1);
1048 sln_printf("Attaching to server... \r");
1050 attach_to_server(argc, argv, hostbuf, portbuf);
1053 if (aaa[0] != '2') {
1054 scr_printf("%s\n", &aaa[4]);
1058 /* If there is a [nonce] at the end, put the nonce in <nonce>, else nonce
1062 if ((sptr = strchr(aaa, '<')) == NULL)
1068 if ((sptr2 = strchr(sptr, '>')) == NULL)
1076 strncpy(nonce, sptr, NONCE_SIZE);
1080 get_serv_info(telnet_client_host);
1082 scr_printf("%-24s\n%s\n%s\n", serv_info.serv_software, serv_info.serv_humannode,
1083 serv_info.serv_bbs_city);
1086 secure = starttls();
1087 status_line(serv_info.serv_humannode, serv_info.serv_bbs_city, NULL,
1090 screenwidth = 80; /* default screen dimensions */
1093 scr_printf(" pause next stop\n");
1094 scr_printf(" ctrl-s ctrl-o ctrl-c\n\n");
1095 formout("hello"); /* print the opening greeting */
1098 GSTA: /* See if we have a username and password on disk */
1099 if (rc_remember_passwords) {
1100 get_stored_password(hostbuf, portbuf, fullname, password);
1101 if (strlen(fullname) > 0) {
1102 snprintf(aaa, sizeof(aaa)-1, "USER %s", fullname);
1107 snprintf(aaa, sizeof aaa, "PAS2 %s", make_apop_string(password, nonce, hexstring, sizeof hexstring));
1109 else /* Else no APOP */
1111 snprintf(aaa, sizeof(aaa)-1, "PASS %s", password);
1116 if (aaa[0] == '2') {
1117 load_user_info(&aaa[4]);
1118 stored_password = 1;
1122 set_stored_password(hostbuf, portbuf, "", "");
1130 if (strlen(rc_username) > 0) {
1131 strcpy(fullname, rc_username);
1133 newprompt("Enter your name: ", fullname, 29);
1136 if (!strcasecmp(fullname, "new")) { /* just in case */
1137 scr_printf("Please enter the name you wish to log in with.\n");
1140 (!strcasecmp(fullname, "bbs"))
1141 || (!strcasecmp(fullname, "new"))
1142 || (strlen(fullname) == 0));
1144 if (!strcasecmp(fullname, "off")) {
1148 /* sign on to the server */
1149 snprintf(aaa, sizeof aaa, "USER %s", fullname);
1155 /* password authentication */
1156 if (strlen(rc_password) > 0) {
1157 strcpy(password, rc_password);
1159 newprompt("\rPlease enter your password: ", password, -19);
1165 snprintf(aaa, sizeof aaa, "PAS2 %s", make_apop_string(password, nonce, hexstring, sizeof hexstring));
1167 else /* Else no APOP */
1169 snprintf(aaa, sizeof aaa, "PASS %s", password);
1174 if (aaa[0] == '2') {
1175 load_user_info(&aaa[4]);
1176 offer_to_remember_password(hostbuf, portbuf,
1177 fullname, password);
1180 scr_printf("<< wrong password >>\n");
1181 if (strlen(rc_password) > 0)
1185 NEWUSR: if (strlen(rc_password) == 0) {
1186 scr_printf("No record. Enter as new user? ");
1190 snprintf(aaa, sizeof aaa, "NEWU %s", fullname);
1193 if (aaa[0] != '2') {
1194 scr_printf("%s\n", aaa);
1197 load_user_info(&aaa[4]);
1199 while (set_password() != 0);;
1205 /* Switch color support on or off if we're in user mode */
1206 if (rc_ansi_color == 3) {
1207 if (userflags & US_COLOR)
1213 scr_printf("%s\nAccess level: %d (%s)\n"
1214 "User #%ld / Login #%d",
1215 fullname, axlevel, axdefs[(int) axlevel],
1216 usernum, timescalled);
1217 if (lastcall > 0L) {
1218 scr_printf(" / Last login: %s\n",
1219 asctime(localtime(&lastcall)) );
1225 if (aaa[0] == '2') {
1226 b = extract_int(&aaa[4], 0);
1230 scr_printf("*** You have a new private message in Mail>\n");
1232 scr_printf("*** You have %d new private messages in Mail>\n", b);
1235 if ((axlevel >= 6) && (extract_int(&aaa[4], 2) > 0)) {
1236 scr_printf("*** Users need validation\n");
1238 if (extract_int(&aaa[4], 1) > 0) {
1239 scr_printf("*** Please register.\n");
1240 formout("register");
1244 /* Make up some temporary filenames for use in various parts of the
1245 * program. Don't mess with these once they've been set, because we
1246 * will be unlinking them later on in the program and we don't
1247 * want to delete something that we didn't create. */
1248 snprintf(temp, sizeof temp, tmpnam(NULL));
1249 snprintf(temp2, sizeof temp2, tmpnam(NULL));
1250 snprintf(tempdir, sizeof tempdir, tmpnam(NULL));
1252 /* Get screen dimensions. First we go to a default of 80x24. Then
1253 * we try to get the user's actual screen dimensions off the server.
1254 * However, if we're running on an xterm, all this stuff is
1255 * irrelevant because we're going to dynamically size the screen
1256 * during the session.
1262 if (aaa[0] == '2') {
1263 screenwidth = extract_int(&aaa[4], 0);
1264 screenheight = extract_int(&aaa[4], 1);
1266 if (getenv("TERM") != NULL)
1267 if (!strcmp(getenv("TERM"), "xterm")) {
1271 check_screen_dims();
1277 /* Enter the lobby */
1278 dotgoto("_BASEROOM_", 1, 0);
1280 /* Main loop for the system... user is logged in. */
1288 /* MAIN COMMAND LOOP */
1290 mcmd = getcmd(argbuf); /* Get keyboard command */
1293 check_screen_dims(); /* if xterm, get screen size */
1311 newprompt("What do you want your username to be? ", aaa, 32);
1312 snprintf(bbb, sizeof bbb, "ENT0 2|0|0|0|%s", aaa);
1315 if (strncmp("200", aaa, 3))
1316 scr_printf("\n%s\n", aaa);
1325 if (!rc_alt_semantics)
1330 if (!rc_alt_semantics)
1332 dotgoto(argbuf, 0, 0);
1336 dotgoto("_MAIL_", 1, 0);
1340 dotgoto(argbuf, 0, 0);
1343 if (rc_alt_semantics)
1345 dotgoto(argbuf, 0, 0);
1357 readmsgs(0, (-1), 0);
1360 readmsgs(2, (-1), 0);
1363 readmsgs(3, 1, atoi(argbuf));
1436 if (!rc_alt_semantics)
1441 if (!rc_alt_semantics)
1452 cli_image_upload("_userpic_");
1455 cli_image_upload("_roompic_");
1459 snprintf(aaa, sizeof aaa, "_floorpic_|%d", curr_floor);
1460 cli_image_upload(aaa);
1464 enternew("roomname", aaa, 20);
1465 snprintf(bbb, sizeof bbb, "RCHG %s", aaa);
1468 if (strncmp("200", aaa, 3))
1469 scr_printf("\n%s\n", aaa);
1472 enternew("hostname", aaa, 25);
1473 snprintf(bbb, sizeof bbb, "HCHG %s", aaa);
1476 if (strncmp("200", aaa, 3))
1477 scr_printf("\n%s\n", aaa);
1480 enternew("username", aaa, 32);
1481 snprintf(bbb, sizeof bbb, "UCHG %s", aaa);
1484 if (strncmp("200", aaa, 3))
1485 scr_printf("\n%s\n", aaa);
1495 display_help(argbuf);
1499 formout("register");
1504 scr_printf("Are you sure (y/n)? ");
1513 scr_printf("All users will be disconnected! "
1514 "Really terminate the server? ");
1518 scr_printf("%s\n", &aaa[4]);
1528 scr_printf("Do you really want to schedule a "
1529 "server shutdown? ");
1531 serv_puts("SCDN 1");
1534 if (atoi(&aaa[4])) {
1536 "The Citadel server will terminate when all users are logged off.\n"
1541 "The Citadel server will not terminate.\n"
1549 network_config_management("listrecp",
1550 "Mailing list recipients");
1554 network_config_management("ignet_push_share",
1555 "Nodes with which we share this room");
1559 do_ignet_configuration();
1563 do_filterlist_configuration();
1567 if (rc_alt_semantics)
1577 if (server_is_local) {
1579 sttybbs(SB_RESTORE);
1580 snprintf(aaa, sizeof aaa, "USERNAME=\042%s\042; export USERNAME;"
1581 "exec ./subsystem %ld %d %d", fullname,
1582 usernum, screenwidth, axlevel);
1584 sttybbs(SB_NO_INTR);
1587 scr_printf("*** Can't run doors when server is not local.\n");
1604 do_system_configuration();
1608 do_internet_configuration();
1612 check_message_base();
1638 gotofloor(argbuf, GF_GOTO);
1642 gotofloor(argbuf, GF_SKIP);
1646 forget_this_floor();
1674 knrooms(floor_mode);
1684 misc_server_cmd(argbuf);
1688 edit_system_message(argbuf);
1713 } while (termn8 == 0);
1715 TERMN8: scr_printf("%s logged out.\n", fullname);
1716 while (march != NULL) {
1717 remove_march(march->march_name, 0);
1720 sln_printf("\n\nType 'off' to disconnect, or next user...\n");
1722 snprintf(aaa, sizeof aaa, "LOUT");
1726 sttybbs(SB_RESTORE);
1727 if ((mcmd == 29) || (mcmd == 15)) {