1 // Client-side functions which perform room operations
3 // Copyright (c) 1987-2023 by the citadel.org team
5 // This program is open source software. Use, duplication, or disclosure
6 // is subject to the terms of the GNU General Public License, version 3.
8 #include "textclient.h"
10 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
12 void stty_ctdl(int cmd);
13 void dotgoto(CtdlIPC * ipc, char *towhere, int display_name, int fromungoto);
14 void progress(CtdlIPC * ipc, unsigned long curr, unsigned long cmax);
15 int pattern(char *search, char *patn);
16 int file_checksum(char *filename);
17 int nukedir(char *dirname);
19 extern unsigned room_flags;
20 extern char room_name[];
22 extern char tempdir[];
23 extern int editor_pid;
24 extern int screenwidth;
25 extern int screenheight;
26 extern char fullname[];
27 extern char sigcaught;
28 extern char floor_mode;
29 extern char curr_floor;
34 extern char *uglist[];
35 extern long uglistlsn[];
36 extern int uglistsize;
38 extern char floorlist[128][SIZ];
41 void load_floorlist(CtdlIPC * ipc) {
45 int r; // IPC response code
47 for (a = 0; a < 128; ++a)
50 r = CtdlIPCFloorListing(ipc, &listing, buf);
52 strcpy(floorlist[0], "Main Floor");
55 while (*listing && !IsEmptyStr(listing)) {
56 extract_token(buf, listing, 0, '\n', sizeof buf);
57 remove_token(listing, 0, '\n');
58 extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', SIZ);
64 void room_tree_list(struct ctdlroomlisting *rp) {
66 char rmname[ROOMNAMELEN];
74 if (rp->lnext != NULL) {
75 room_tree_list(rp->lnext);
79 strcpy(rmname, rp->rlname);
81 if ((c + strlen(rmname) + 4) > screenwidth) {
83 // line break, check the paginator
90 else if (f & QR_PRIVATE) {
96 scr_printf("%s", rmname);
97 if (f & QR_DIRECTORY) {
103 c = c + strlen(rmname) + 3;
106 if (rp->rnext != NULL) {
107 room_tree_list(rp->rnext);
114 // Room ordering stuff (compare first by floor, then by order)
115 int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2) {
116 if ((r1 == NULL) && (r2 == NULL))
122 if (r1->rlfloor < r2->rlfloor)
124 if (r1->rlfloor > r2->rlfloor)
126 if (r1->rlorder < r2->rlorder)
128 if (r1->rlorder > r2->rlorder)
134 // Common code for all room listings
135 static void listrms(struct march *listing, int new_only, int floor_only, unsigned int flags, char *match) {
137 struct ctdlroomlisting *rl = NULL;
138 struct ctdlroomlisting *rp;
139 struct ctdlroomlisting *rs;
142 for (mptr = listing; mptr != NULL; mptr = mptr->next) {
145 if ((new_only == LISTRMS_NEW_ONLY) && ((mptr->march_access & UA_HASNEWMSGS) == 0))
148 if ((new_only == LISTRMS_OLD_ONLY) && ((mptr->march_access & UA_HASNEWMSGS) != 0))
151 if ((floor_only >= 0) && (mptr->march_floor != floor_only))
154 if (flags && (mptr->march_flags & flags) == 0)
157 if (match && (pattern(mptr->march_name, match) == -1))
161 rp = malloc(sizeof(struct ctdlroomlisting));
162 strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
163 rp->rlflags = mptr->march_flags;
164 rp->rlfloor = mptr->march_floor;
165 rp->rlorder = mptr->march_order;
175 if (rordercmp(rp, rs) < 0) {
176 if (rs->lnext == NULL) {
185 if (rs->rnext == NULL) {
198 room_tree_list(NULL);
204 void list_other_floors(void) {
208 for (a = 0; a < 128; ++a) {
209 if ((strlen(floorlist[a]) > 0) && (a != curr_floor)) {
210 if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
214 scr_printf("%s: ", floorlist[a]);
215 c = c + strlen(floorlist[a]) + 3;
221 // List known rooms. kn_floor_mode should be set to 0 for a 'flat' listing,
222 // 1 to list rooms on the current floor, or 2 to list rooms on all floors.
223 void knrooms(CtdlIPC * ipc, int kn_floor_mode) {
225 struct march *listing = NULL;
227 int r; // IPC response code
231 // Ask the server for a room list
232 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
240 if (kn_floor_mode == 0) {
242 scr_printf("\n Rooms with unread messages:\n");
243 listrms(listing, LISTRMS_NEW_ONLY, -1, 0, NULL);
245 scr_printf("\n\n No unseen messages in:\n");
246 listrms(listing, LISTRMS_OLD_ONLY, -1, 0, NULL);
250 if (kn_floor_mode == 1) {
252 scr_printf("\n Rooms with unread messages on %s:\n", floorlist[(int) curr_floor]);
253 listrms(listing, LISTRMS_NEW_ONLY, curr_floor, 0, NULL);
255 scr_printf("\n\n Rooms with no new messages on %s:\n", floorlist[(int) curr_floor]);
256 listrms(listing, LISTRMS_OLD_ONLY, curr_floor, 0, NULL);
258 scr_printf("\n\n Other floors:\n");
263 if (kn_floor_mode == 2) {
264 for (a = 0; a < 128; ++a) {
265 if (floorlist[a][0] != 0) {
267 scr_printf("\n Rooms on %s:\n", floorlist[a]);
268 listrms(listing, LISTRMS_ALL, a, 0, NULL);
274 // Free the room list
276 mptr = listing->next;
285 void listzrooms(CtdlIPC * ipc) { // list public forgotten rooms
286 struct march *listing = NULL;
288 int r; // IPC response code
292 // Ask the server for a room list
293 r = CtdlIPCKnownRooms(ipc, UnsubscribedRooms, (-1), &listing, buf);
299 scr_printf("\n Forgotten public rooms:\n");
300 listrms(listing, LISTRMS_ALL, -1, 0, NULL);
303 // Free the room list
305 mptr = listing->next;
314 // list rooms according to attribute
315 void dotknown(CtdlIPC * ipc, int what, char *match) {
316 struct march *listing = NULL;
318 int r; // IPC response code
321 // Ask the server for a room list
322 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, (-1), &listing, buf);
331 scr_printf("\n Anonymous rooms:\n");
332 listrms(listing, LISTRMS_ALL, -1, QR_ANONONLY | QR_ANONOPT, NULL);
336 scr_printf("\n Directory rooms:\n");
337 listrms(listing, LISTRMS_ALL, -1, QR_DIRECTORY, NULL);
341 scr_printf("\n Matching \"%s\" rooms:\n", match);
342 listrms(listing, LISTRMS_ALL, -1, 0, match);
346 scr_printf("\n Preferred only rooms:\n");
347 listrms(listing, LISTRMS_ALL, -1, QR_PREFONLY, NULL);
351 scr_printf("\n Private rooms:\n");
352 listrms(listing, LISTRMS_ALL, -1, QR_PRIVATE, NULL);
356 scr_printf("\n Read only rooms:\n");
357 listrms(listing, LISTRMS_ALL, -1, QR_READONLY, NULL);
362 // Free the room list
364 mptr = listing->next;
373 int set_room_attr(CtdlIPC * ipc, unsigned int ibuf, char *prompt, unsigned int sbit) {
376 a = boolprompt(prompt, (ibuf & sbit));
377 ibuf = (ibuf | sbit);
379 ibuf = (ibuf ^ sbit);
385 // Select a floor (used in several commands)
386 // The supplied argument is the 'default' floor number.
387 // This function returns the selected floor number.
388 int select_floor(CtdlIPC * ipc, int rfloor) {
392 if (floor_mode == 1) {
393 if (floorlist[(int) curr_floor][0] == 0) {
399 strncpy(floorstr, floorlist[rfloor], sizeof floorstr);
400 strprompt("Which floor", floorstr, 255);
401 for (a = 0; a < 128; ++a) {
402 if (!strcasecmp(floorstr, &floorlist[a][0]))
405 && (!strncasecmp(floorstr, &floorlist[a][0], strlen(floorstr))))
408 && (pattern(&floorlist[a][0], floorstr)
413 scr_printf("\n One of:\n");
414 for (a = 0; a < 128; ++a) {
415 if (floorlist[a][0] != 0) {
416 scr_printf("%s\n", &floorlist[a][0]);
420 } while (newfloor < 0);
425 scr_printf("Floor selection bypassed because you have floor mode disabled.\n");
432 // .<A>ide <E>dit room
433 void editthisroom(CtdlIPC * ipc) {
435 char room_admin_name[USERNAME_SIZE];
437 struct ctdlroom *attr = NULL;
438 struct ExpirePolicy *eptr = NULL;
439 int r; // IPC response code
441 // Fetch the existing room config
442 r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
444 scr_printf("%s\n", buf);
447 eptr = &(attr->QRep);
449 // Fetch the name of the current room admin
450 r = CtdlIPCGetRoomAide(ipc, buf);
452 strncpy(room_admin_name, buf, sizeof room_admin_name);
455 strcpy(room_admin_name, "");
457 if (IsEmptyStr(room_admin_name)) {
458 strcpy(room_admin_name, "none");
461 // Fetch the expire policy (this will silently fail on old servers, resulting in "default" policy)
462 r = CtdlIPCGetMessageExpirationPolicy(ipc, 0, &eptr, buf);
464 // Now interact with the user.
466 strprompt("Room name", attr->QRname, ROOMNAMELEN - 1);
467 attr->QRfloor = select_floor(ipc, attr->QRfloor);
468 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
469 if (attr->QRflags & QR_PRIVATE) {
470 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Hidden room (accessible to anyone who knows the room name)", QR_GUESSNAME);
473 // if it's public, clear the privacy classes
474 if ((attr->QRflags & QR_PRIVATE) == 0) {
475 if (attr->QRflags & QR_GUESSNAME) {
476 attr->QRflags = attr->QRflags - QR_GUESSNAME;
478 if (attr->QRflags & QR_PASSWORDED) {
479 attr->QRflags = attr->QRflags - QR_PASSWORDED;
483 // if it's private, choose the privacy classes
484 if ((attr->QRflags & QR_PRIVATE)
485 && ((attr->QRflags & QR_GUESSNAME) == 0)) {
486 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Accessible by entering a password", QR_PASSWORDED);
488 if ((attr->QRflags & QR_PRIVATE)
489 && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
490 strprompt("Room password", attr->QRpasswd, 9);
493 if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
494 rbump = boolprompt("Cause current users to forget room", 0);
497 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Preferred users only", QR_PREFONLY);
498 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Read-only room", QR_READONLY);
499 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Allow message deletion by anyone who can post", QR2_COLLABDEL);
500 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Permanent room", QR_PERMANENT);
501 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Subject Required (Force users to specify a message subject)", QR2_SUBJECTREQ);
502 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Directory room", QR_DIRECTORY);
503 if (attr->QRflags & QR_DIRECTORY) {
504 strprompt("Directory name", attr->QRdirname, 14);
505 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Uploading allowed", QR_UPLOAD);
506 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Downloading allowed", QR_DOWNLOAD);
507 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Visible directory", QR_VISDIR);
509 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Self-service list subscribe/unsubscribe", QR2_SELFLIST);
510 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Allow non-subscribers to mail to this room", QR2_SMTP_PUBLIC);
511 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Moderated mailing list", QR2_MODERATED);
512 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Automatically make all messages anonymous", QR_ANONONLY);
513 if ((attr->QRflags & QR_ANONONLY) == 0) {
514 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Ask users whether to make messages anonymous", QR_ANONOPT);
516 attr->QRorder = intprompt("Listing order", attr->QRorder, 0, 127);
518 // Ask about the room admin
520 strprompt("Room admin (or 'none')", room_admin_name, 29);
521 if (!strcasecmp(room_admin_name, "none")) {
522 strcpy(room_admin_name, "");
526 r = CtdlIPCQueryUsername(ipc, room_admin_name, buf);
528 scr_printf("%s\n", buf);
531 } while (r / 100 != 2);
533 // Angels and demons dancing in my head...
535 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
536 strprompt("Message expire policy (? for list)", buf, 1);
539 "0. Use the default for this floor\n"
540 "1. Never automatically expire messages\n"
541 "2. Expire by message count\n" "3. Expire by message age\n");
543 } while ((buf[0] < 48) || (buf[0] > 51));
544 attr->QRep.expire_mode = buf[0] - 48;
546 // ...lunatics and monsters underneath my bed
547 if (attr->QRep.expire_mode == 2) {
548 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
549 strprompt("Keep how many messages online?", buf, 10);
550 attr->QRep.expire_value = atol(buf);
553 if (attr->QRep.expire_mode == 3) {
554 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
555 strprompt("Keep messages for how many days?", buf, 10);
556 attr->QRep.expire_value = atol(buf);
559 // Give 'em a chance to change their minds
560 scr_printf("Save changes (y/n)? ");
563 r = CtdlIPCSetRoomAide(ipc, room_admin_name, buf);
565 scr_printf("%s\n", buf);
568 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
570 scr_printf("%s\n", buf);
573 r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
574 scr_printf("%s\n", buf);
575 strncpy(buf, attr->QRname, ROOMNAMELEN);
578 dotgoto(ipc, buf, 2, 0);
587 // un-goto the previous room, or a specified room
588 void dotungoto(CtdlIPC * ipc, char *towhere) {
589 // Find this 'towhere' room in the list ungoto from this room to
590 // that at the messagepointer position in that room in our ungoto list.
591 // I suppose I could be a real dick and just ungoto that many places
596 struct ctdlipcroom *rret = NULL; // ignored
599 if (uglistsize == 0) {
600 scr_printf("No rooms to ungoto.\n");
603 if (towhere == NULL) {
604 scr_printf("Must specify a room to ungoto.\n");
607 if (IsEmptyStr(towhere)) {
608 scr_printf("Must specify a room to ungoto.\n");
611 for (lp = uglistsize - 1; lp >= 0; lp--) {
612 if (strcasecmp(towhere, uglist[lp]) == 0) {
618 scr_printf("Room: %s not in ungoto list.\n", towhere);
622 r = CtdlIPCGotoRoom(ipc, uglist[found], "", &rret, buf);
624 free(rret); // ignored
626 scr_printf("%s\n", buf);
629 r = CtdlIPCSetLastRead(ipc, uglistlsn[found] ? uglistlsn[found] : 1, buf);
631 scr_printf("%s\n", buf);
633 strncpy(buf, uglist[found], sizeof(buf));
634 // we queue ungoto information here, because we're not really
635 // ungotoing, we're really going to a random spot in some arbitrary
637 dotgoto(ipc, buf, 0, 0);
641 void ungoto(CtdlIPC * ipc) {
643 struct ctdlipcroom *rret = NULL; // ignored
646 if (uglistsize == 0) {
650 r = CtdlIPCGotoRoom(ipc, uglist[uglistsize - 1], "", &rret, buf);
652 free(rret); // ignored
655 scr_printf("%s\n", buf);
658 r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize - 1] ? uglistlsn[uglistsize - 1] : 1, buf);
660 scr_printf("%s\n", buf);
662 strncpy(buf, uglist[uglistsize - 1], sizeof(buf));
664 free(uglist[uglistsize]);
665 // Don't queue ungoto info or we end up in a loop
666 dotgoto(ipc, buf, 0, 1);
670 // saves filelen bytes from file at pathname
671 int save_buffer(void *file, size_t filelen, const char *pathname) {
673 size_t bytes_written = 0;
676 fp = fopen(pathname, "w");
678 scr_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
682 block = fwrite((char *) file + bytes_written, 1, filelen - bytes_written, fp);
683 bytes_written += block;
684 } while (errno == EINTR && bytes_written < filelen);
687 if (bytes_written < filelen) {
688 scr_printf("Trouble saving '%s': %s\n", pathname, strerror(errno));
695 // Save supplied_filename in dest directory; gets the name only
696 void destination_directory(char *dest, const char *supplied_filename) {
697 static char save_dir[SIZ] = { 0 };
699 if (IsEmptyStr(save_dir)) {
700 if (getenv("HOME") == NULL) {
701 strcpy(save_dir, ".");
704 sprintf(save_dir, "%s/Desktop", getenv("HOME"));
705 if (access(save_dir, W_OK) != 0) {
706 sprintf(save_dir, "%s", getenv("HOME"));
707 if (access(save_dir, W_OK) != 0) {
708 sprintf(save_dir, ".");
714 sprintf(dest, "%s/%s", save_dir, supplied_filename);
715 strprompt("Save as", dest, PATH_MAX);
717 // Remember the directory for next time
718 strcpy(save_dir, dest);
719 if (strrchr(save_dir, '/') != NULL) {
720 strcpy(strrchr(save_dir, '/'), "");
723 strcpy(save_dir, ".");
728 // download() - download a file or files. The argument passed to this
729 // function determines which protocol to use.
730 // proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
731 void download(CtdlIPC * ipc, int proto) {
733 char filename[PATH_MAX];
734 char tempname[PATH_MAX];
735 char transmit_cmd[SIZ];
740 void *file = NULL; // The downloaded file
741 size_t filelen = 0L; // The downloaded file length
743 if ((room_flags & QR_DOWNLOAD) == 0) {
744 scr_printf("*** You cannot download from this room.\n");
748 newprompt("Enter filename: ", filename, PATH_MAX);
750 // Save to local disk, for folks with their own copy of the client
752 destination_directory(tempname, filename);
753 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
755 scr_printf("%s\n", buf);
758 save_buffer(file, (size_t) extract_long(buf, 0), tempname);
763 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
765 scr_printf("%s\n", buf);
768 filelen = extract_unsigned_long(buf, 0);
770 // Meta-download for public clients
771 // scr_printf("Fetching file from Citadel server...\n");
772 mkdir(tempdir, 0700);
773 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
774 tpipe = fopen(tempname, "wb");
775 if (fwrite(file, filelen, 1, tpipe) < filelen) {
776 // FIXME: restart syscall on EINTR
784 // FIXME: display internally instead
785 snprintf(transmit_cmd, sizeof transmit_cmd,
786 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s", tempname);
789 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
791 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
793 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
795 // FIXME: display internally instead
796 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
798 stty_ctdl(SB_RESTORE);
799 rv = system(transmit_cmd);
801 scr_printf("failed to download '%s': %d\n", transmit_cmd, rv);
802 stty_ctdl(SB_NO_INTR);
804 // clean up the temporary directory
806 ctdl_beep(); // Beep beep!
810 // read directory of this room
811 void roomdir(CtdlIPC * ipc) {
817 char *listing = NULL; // Returned directory listing
820 r = CtdlIPCReadDirectory(ipc, &listing, buf);
822 scr_printf("%s\n", buf);
826 extract_token(comment, buf, 0, '|', sizeof comment);
827 extract_token(flnm, buf, 1, '|', sizeof flnm);
828 scr_printf("\nDirectory of %s on %s\n", flnm, comment);
829 scr_printf("-----------------------\n");
830 while (listing && *listing && !IsEmptyStr(listing)) {
831 extract_token(buf, listing, 0, '\n', sizeof buf);
832 remove_token(listing, 0, '\n');
834 extract_token(flnm, buf, 0, '|', sizeof flnm);
835 extract_token(flsz, buf, 1, '|', sizeof flsz);
836 extract_token(mimetype, buf, 2, '|', sizeof mimetype);
837 extract_token(comment, buf, 3, '|', sizeof comment);
838 if (strlen(flnm) <= 14)
839 scr_printf("%-14s %8s %s [%s]\n", flnm, flsz, comment, mimetype);
841 scr_printf("%s\n%14s %8s %s [%s]\n", flnm, "", flsz, comment, mimetype);
848 // add a user to a private room
849 void invite(CtdlIPC * ipc) {
850 char username[USERNAME_SIZE];
853 newprompt("Name of user? ", username, USERNAME_SIZE);
854 if (username[0] == 0)
857 CtdlIPCInviteUserToRoom(ipc, username, buf);
858 scr_printf("%s\n", buf);
862 // kick a user out of a room
863 void kickout(CtdlIPC * ipc) {
864 char username[USERNAME_SIZE];
867 newprompt("Name of user? ", username, USERNAME_SIZE);
868 if (username[0] == 0)
871 CtdlIPCKickoutUserFromRoom(ipc, username, buf);
872 scr_printf("%s\n", buf);
876 // aide command: kill the current room
877 void killroom(CtdlIPC * ipc) {
881 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
883 scr_printf("%s\n", aaa);
887 scr_printf("Are you sure you want to kill this room? ");
891 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
892 scr_printf("%s\n", aaa);
895 dotgoto(ipc, "_BASEROOM_", 0, 0);
899 void forget(CtdlIPC * ipc) { // forget the current room
902 scr_printf("Are you sure you want to forget this room? ");
906 remove_march(room_name, 0);
907 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
908 scr_printf("%s\n", buf);
912 // now return to the lobby
913 dotgoto(ipc, "_BASEROOM_", 0, 0);
918 void entroom(CtdlIPC * ipc) {
920 char new_room_name[ROOMNAMELEN];
922 char new_room_pass[10];
925 int r; // IPC response code
927 // Check permission to create room
928 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
930 scr_printf("%s\n", buf);
934 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
935 if (IsEmptyStr(new_room_name)) {
938 for (a = 0; !IsEmptyStr(&new_room_name[a]); ++a) {
939 if (new_room_name[a] == '|') {
940 new_room_name[a] = '_';
944 new_room_floor = select_floor(ipc, (int) curr_floor);
946 IFNEXPERT formout(ipc, "roomaccess");
948 scr_printf("<?>Help\n"
949 "<1>Public room (shown to all users by default)\n"
950 "<2>Hidden room (accessible to anyone who knows the room name)\n"
951 "<3>Passworded room (hidden, plus requires a password to enter)\n"
952 "<4>Invitation-only room (requires access to be granted by an Admin)\n"
953 "<5>Personal room (accessible to you only)\n" "Enter room type: ");
956 } while (((b < '1') || (b > '5')) && (b != '?'));
959 formout(ipc, "roomaccess");
961 } while ((b < '1') || (b > '5'));
962 b -= '0'; // Portable
963 scr_printf("%d\n", b);
964 new_room_type = b - 1;
965 if (new_room_type == 2) {
966 newprompt("Enter a room password: ", new_room_pass, 9);
967 for (a = 0; !IsEmptyStr(&new_room_pass[a]); ++a)
968 if (new_room_pass[a] == '|')
969 new_room_pass[a] = '_';
972 strcpy(new_room_pass, "");
975 scr_printf("\042%s\042, a", new_room_name);
977 scr_printf(" public room.");
979 scr_printf(" hidden room.");
981 scr_printf(" passworded room, password: %s", new_room_pass);
983 scr_printf("n invitation-only room.");
985 scr_printf(" personal room.");
986 scr_printf("\nInstall it? (y/n) : ");
991 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type, new_room_pass, new_room_floor, buf);
993 scr_printf("%s\n", buf);
997 // command succeeded... now GO to the new room!
998 dotgoto(ipc, new_room_name, 0, 0);
1003 void readinfo(CtdlIPC * ipc) { // read info file for current room
1005 char room_admin_name[64];
1006 int r; // IPC response code
1009 // Name of currernt room admin
1010 r = CtdlIPCGetRoomAide(ipc, buf);
1012 strncpy(room_admin_name, buf, sizeof room_admin_name);
1014 strcpy(room_admin_name, "");
1016 if (!IsEmptyStr(room_admin_name))
1017 scr_printf("Room admin is %s.\n\n", room_admin_name);
1019 r = CtdlIPCRoomInfo(ipc, &text, buf);
1024 fmout(screenwidth, NULL, text, NULL, 1);
1030 // <W>ho knows room...
1031 void whoknows(CtdlIPC * ipc) {
1033 char *listing = NULL;
1036 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1038 scr_printf("%s\n", buf);
1041 while (!IsEmptyStr(listing)) {
1042 extract_token(buf, listing, 0, '\n', sizeof buf);
1043 remove_token(listing, 0, '\n');
1045 scr_printf("%s\n", buf);
1051 void do_edit(CtdlIPC * ipc, char *desc, char *read_cmd, char *check_cmd, char *write_cmd) {
1054 int b, cksum, editor_exit;
1056 if (IsEmptyStr(editor_path)) {
1057 scr_printf("Do you wish to re-enter %s? ", desc);
1062 fp = fopen(temp, "w");
1065 CtdlIPC_chat_send(ipc, check_cmd);
1066 CtdlIPC_chat_recv(ipc, cmd);
1067 if (cmd[0] != '2') {
1068 scr_printf("%s\n", &cmd[4]);
1072 if (!IsEmptyStr(editor_path)) {
1073 CtdlIPC_chat_send(ipc, read_cmd);
1074 CtdlIPC_chat_recv(ipc, cmd);
1075 if (cmd[0] == '1') {
1076 fp = fopen(temp, "w");
1077 while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
1078 fprintf(fp, "%s\n", cmd);
1084 cksum = file_checksum(temp);
1086 if (!IsEmptyStr(editor_path)) {
1089 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1091 stty_ctdl(SB_RESTORE);
1092 editor_pid = fork();
1093 if (editor_pid == 0) {
1095 execlp(editor_path, editor_path, temp, NULL);
1101 b = ka_wait(&editor_exit);
1102 } while ((b != editor_pid) && (b >= 0));
1104 scr_printf("Executed %s\n", editor_path);
1108 scr_printf("Entering %s. Press return twice when finished.\n", desc);
1109 fp = fopen(temp, "r+");
1114 if (file_checksum(temp) == cksum) {
1115 scr_printf("*** Aborted.\n");
1119 CtdlIPC_chat_send(ipc, write_cmd);
1120 CtdlIPC_chat_recv(ipc, cmd);
1121 if (cmd[0] != '4') {
1122 scr_printf("%s\n", &cmd[4]);
1126 fp = fopen(temp, "r");
1127 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1128 cmd[strlen(cmd) - 1] = 0;
1129 CtdlIPC_chat_send(ipc, cmd);
1132 CtdlIPC_chat_send(ipc, "000");
1139 // edit info file for current room
1140 void enterinfo(CtdlIPC * ipc) {
1141 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1145 void enter_bio(CtdlIPC * ipc) {
1147 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1148 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1152 // create a new floor
1153 void create_floor(CtdlIPC * ipc) {
1155 char newfloorname[SIZ];
1156 int r; // IPC response code
1158 load_floorlist(ipc);
1160 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1161 if ((r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE)) {
1162 scr_printf("%s\n", buf);
1166 newprompt("Name for new floor: ", newfloorname, 255);
1169 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1171 scr_printf("Floor has been created.\n");
1174 scr_printf("%s\n", buf);
1177 load_floorlist(ipc);
1181 // edit the current floor
1182 void edit_floor(CtdlIPC * ipc) {
1184 struct ExpirePolicy *ep = NULL;
1186 load_floorlist(ipc);
1188 // Fetch the expire policy (this will silently fail on old servers, resulting in "default" policy)
1189 CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1191 // Interact with the user
1192 scr_printf("You are editing the floor called \"%s\"\n", &floorlist[(int) curr_floor][0]);
1193 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1195 // Angels and demons dancing in my head...
1197 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1198 strprompt("Floor default message expire policy (? for list)", buf, 1);
1199 if (buf[0] == '?') {
1201 "0. Use the system default\n"
1202 "1. Never automatically expire messages\n"
1203 "2. Expire by message count\n" "3. Expire by message age\n");
1205 } while ((buf[0] < '0') || (buf[0] > '3'));
1206 ep->expire_mode = buf[0] - '0';
1208 // ...lunatics and monsters underneath my bed
1209 if (ep->expire_mode == 2) {
1210 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1211 strprompt("Keep how many messages online?", buf, 10);
1212 ep->expire_value = atol(buf);
1215 if (ep->expire_mode == 3) {
1216 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1217 strprompt("Keep messages for how many days?", buf, 10);
1218 ep->expire_value = atol(buf);
1222 CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1223 CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int) curr_floor][0], buf);
1224 scr_printf("%s\n", buf);
1225 load_floorlist(ipc);
1229 // kill the current floor
1230 void kill_floor(CtdlIPC * ipc) {
1231 int floornum_to_delete, a;
1234 load_floorlist(ipc);
1236 floornum_to_delete = (-1);
1237 scr_printf("(Press return to abort)\n");
1238 newprompt("Delete which floor? ", buf, 255);
1239 if (IsEmptyStr(buf))
1241 for (a = 0; a < 128; ++a)
1242 if (!strcasecmp(&floorlist[a][0], buf))
1243 floornum_to_delete = a;
1244 if (floornum_to_delete < 0) {
1245 scr_printf("No such floor. Select one of:\n");
1246 for (a = 0; a < 128; ++a)
1247 if (floorlist[a][0] != 0)
1248 scr_printf("%s\n", &floorlist[a][0]);
1250 } while (floornum_to_delete < 0);
1251 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1252 scr_printf("%s\n", buf);
1253 load_floorlist(ipc);