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) {
471 set_room_attr(ipc, attr->QRflags, "Hidden room (accessible to anyone who knows the room name)", QR_GUESSNAME);
474 // if it's public, clear the privacy classes
475 if ((attr->QRflags & QR_PRIVATE) == 0) {
476 if (attr->QRflags & QR_GUESSNAME) {
477 attr->QRflags = attr->QRflags - QR_GUESSNAME;
479 if (attr->QRflags & QR_PASSWORDED) {
480 attr->QRflags = attr->QRflags - QR_PASSWORDED;
484 // if it's private, choose the privacy classes
485 if ((attr->QRflags & QR_PRIVATE)
486 && ((attr->QRflags & QR_GUESSNAME) == 0)) {
487 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Accessible by entering a password", QR_PASSWORDED);
489 if ((attr->QRflags & QR_PRIVATE)
490 && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
491 strprompt("Room password", attr->QRpasswd, 9);
494 if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
495 rbump = boolprompt("Cause current users to forget room", 0);
498 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Preferred users only", QR_PREFONLY);
499 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Read-only room", QR_READONLY);
500 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Allow message deletion by anyone who can post", QR2_COLLABDEL);
501 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Permanent room", QR_PERMANENT);
503 set_room_attr(ipc, attr->QRflags2, "Subject Required (Force users to specify a message subject)", QR2_SUBJECTREQ);
504 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Directory room", QR_DIRECTORY);
505 if (attr->QRflags & QR_DIRECTORY) {
506 strprompt("Directory name", attr->QRdirname, 14);
507 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Uploading allowed", QR_UPLOAD);
508 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Downloading allowed", QR_DOWNLOAD);
509 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Visible directory", QR_VISDIR);
511 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Self-service list subscribe/unsubscribe", QR2_SELFLIST);
512 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Allow non-subscribers to mail to this room", QR2_SMTP_PUBLIC);
513 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Moderated mailing list", QR2_MODERATED);
514 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Automatically make all messages anonymous", QR_ANONONLY);
515 if ((attr->QRflags & QR_ANONONLY) == 0) {
516 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Ask users whether to make messages anonymous", QR_ANONOPT);
518 attr->QRorder = intprompt("Listing order", attr->QRorder, 0, 127);
520 // Ask about the room admin
522 strprompt("Room admin (or 'none')", room_admin_name, 29);
523 if (!strcasecmp(room_admin_name, "none")) {
524 strcpy(room_admin_name, "");
528 r = CtdlIPCQueryUsername(ipc, room_admin_name, buf);
530 scr_printf("%s\n", buf);
533 } while (r / 100 != 2);
535 // Angels and demons dancing in my head...
537 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
538 strprompt("Message expire policy (? for list)", buf, 1);
541 "0. Use the default for this floor\n"
542 "1. Never automatically expire messages\n"
543 "2. Expire by message count\n" "3. Expire by message age\n");
545 } while ((buf[0] < 48) || (buf[0] > 51));
546 attr->QRep.expire_mode = buf[0] - 48;
548 // ...lunatics and monsters underneath my bed
549 if (attr->QRep.expire_mode == 2) {
550 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
551 strprompt("Keep how many messages online?", buf, 10);
552 attr->QRep.expire_value = atol(buf);
555 if (attr->QRep.expire_mode == 3) {
556 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
557 strprompt("Keep messages for how many days?", buf, 10);
558 attr->QRep.expire_value = atol(buf);
561 // Give 'em a chance to change their minds
562 scr_printf("Save changes (y/n)? ");
565 r = CtdlIPCSetRoomAide(ipc, room_admin_name, buf);
567 scr_printf("%s\n", buf);
570 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
572 scr_printf("%s\n", buf);
575 r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
576 scr_printf("%s\n", buf);
577 strncpy(buf, attr->QRname, ROOMNAMELEN);
580 dotgoto(ipc, buf, 2, 0);
589 // un-goto the previous room, or a specified room
590 void dotungoto(CtdlIPC * ipc, char *towhere) {
591 // Find this 'towhere' room in the list ungoto from this room to
592 // that at the messagepointer position in that room in our ungoto list.
593 // I suppose I could be a real dick and just ungoto that many places
598 struct ctdlipcroom *rret = NULL; // ignored
601 if (uglistsize == 0) {
602 scr_printf("No rooms to ungoto.\n");
605 if (towhere == NULL) {
606 scr_printf("Must specify a room to ungoto.\n");
609 if (IsEmptyStr(towhere)) {
610 scr_printf("Must specify a room to ungoto.\n");
613 for (lp = uglistsize - 1; lp >= 0; lp--) {
614 if (strcasecmp(towhere, uglist[lp]) == 0) {
620 scr_printf("Room: %s not in ungoto list.\n", towhere);
624 r = CtdlIPCGotoRoom(ipc, uglist[found], "", &rret, buf);
626 free(rret); // ignored
628 scr_printf("%s\n", buf);
631 r = CtdlIPCSetLastRead(ipc, uglistlsn[found] ? uglistlsn[found] : 1, buf);
633 scr_printf("%s\n", buf);
635 strncpy(buf, uglist[found], sizeof(buf));
636 // we queue ungoto information here, because we're not really
637 // ungotoing, we're really going to a random spot in some arbitrary
639 dotgoto(ipc, buf, 0, 0);
643 void ungoto(CtdlIPC * ipc) {
645 struct ctdlipcroom *rret = NULL; // ignored
648 if (uglistsize == 0) {
652 r = CtdlIPCGotoRoom(ipc, uglist[uglistsize - 1], "", &rret, buf);
654 free(rret); // ignored
657 scr_printf("%s\n", buf);
660 r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize - 1] ? uglistlsn[uglistsize - 1] : 1, buf);
662 scr_printf("%s\n", buf);
664 strncpy(buf, uglist[uglistsize - 1], sizeof(buf));
666 free(uglist[uglistsize]);
667 // Don't queue ungoto info or we end up in a loop
668 dotgoto(ipc, buf, 0, 1);
672 // saves filelen bytes from file at pathname
673 int save_buffer(void *file, size_t filelen, const char *pathname) {
675 size_t bytes_written = 0;
678 fp = fopen(pathname, "w");
680 scr_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
684 block = fwrite((char *) file + bytes_written, 1, filelen - bytes_written, fp);
685 bytes_written += block;
686 } while (errno == EINTR && bytes_written < filelen);
689 if (bytes_written < filelen) {
690 scr_printf("Trouble saving '%s': %s\n", pathname, strerror(errno));
697 // Save supplied_filename in dest directory; gets the name only
698 void destination_directory(char *dest, const char *supplied_filename) {
699 static char save_dir[SIZ] = { 0 };
701 if (IsEmptyStr(save_dir)) {
702 if (getenv("HOME") == NULL) {
703 strcpy(save_dir, ".");
706 sprintf(save_dir, "%s/Desktop", getenv("HOME"));
707 if (access(save_dir, W_OK) != 0) {
708 sprintf(save_dir, "%s", getenv("HOME"));
709 if (access(save_dir, W_OK) != 0) {
710 sprintf(save_dir, ".");
716 sprintf(dest, "%s/%s", save_dir, supplied_filename);
717 strprompt("Save as", dest, PATH_MAX);
719 // Remember the directory for next time
720 strcpy(save_dir, dest);
721 if (strrchr(save_dir, '/') != NULL) {
722 strcpy(strrchr(save_dir, '/'), "");
725 strcpy(save_dir, ".");
730 // download() - download a file or files. The argument passed to this
731 // function determines which protocol to use.
732 // proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
733 void download(CtdlIPC * ipc, int proto) {
735 char filename[PATH_MAX];
736 char tempname[PATH_MAX];
737 char transmit_cmd[SIZ];
742 void *file = NULL; // The downloaded file
743 size_t filelen = 0L; // The downloaded file length
745 if ((room_flags & QR_DOWNLOAD) == 0) {
746 scr_printf("*** You cannot download from this room.\n");
750 newprompt("Enter filename: ", filename, PATH_MAX);
752 // Save to local disk, for folks with their own copy of the client
754 destination_directory(tempname, filename);
755 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
757 scr_printf("%s\n", buf);
760 save_buffer(file, (size_t) extract_long(buf, 0), tempname);
765 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
767 scr_printf("%s\n", buf);
770 filelen = extract_unsigned_long(buf, 0);
772 // Meta-download for public clients
773 // scr_printf("Fetching file from Citadel server...\n");
774 mkdir(tempdir, 0700);
775 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
776 tpipe = fopen(tempname, "wb");
777 if (fwrite(file, filelen, 1, tpipe) < filelen) {
778 // FIXME: restart syscall on EINTR
786 // FIXME: display internally instead
787 snprintf(transmit_cmd, sizeof transmit_cmd,
788 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s", tempname);
791 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
793 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
795 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
797 // FIXME: display internally instead
798 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
800 stty_ctdl(SB_RESTORE);
801 rv = system(transmit_cmd);
803 scr_printf("failed to download '%s': %d\n", transmit_cmd, rv);
804 stty_ctdl(SB_NO_INTR);
806 // clean up the temporary directory
808 ctdl_beep(); // Beep beep!
812 // read directory of this room
813 void roomdir(CtdlIPC * ipc) {
819 char *listing = NULL; // Returned directory listing
822 r = CtdlIPCReadDirectory(ipc, &listing, buf);
824 scr_printf("%s\n", buf);
828 extract_token(comment, buf, 0, '|', sizeof comment);
829 extract_token(flnm, buf, 1, '|', sizeof flnm);
830 scr_printf("\nDirectory of %s on %s\n", flnm, comment);
831 scr_printf("-----------------------\n");
832 while (listing && *listing && !IsEmptyStr(listing)) {
833 extract_token(buf, listing, 0, '\n', sizeof buf);
834 remove_token(listing, 0, '\n');
836 extract_token(flnm, buf, 0, '|', sizeof flnm);
837 extract_token(flsz, buf, 1, '|', sizeof flsz);
838 extract_token(mimetype, buf, 2, '|', sizeof mimetype);
839 extract_token(comment, buf, 3, '|', sizeof comment);
840 if (strlen(flnm) <= 14)
841 scr_printf("%-14s %8s %s [%s]\n", flnm, flsz, comment, mimetype);
843 scr_printf("%s\n%14s %8s %s [%s]\n", flnm, "", flsz, comment, mimetype);
850 // add a user to a private room
851 void invite(CtdlIPC * ipc) {
852 char username[USERNAME_SIZE];
855 newprompt("Name of user? ", username, USERNAME_SIZE);
856 if (username[0] == 0)
859 CtdlIPCInviteUserToRoom(ipc, username, buf);
860 scr_printf("%s\n", buf);
864 // kick a user out of a room
865 void kickout(CtdlIPC * ipc) {
866 char username[USERNAME_SIZE];
869 newprompt("Name of user? ", username, USERNAME_SIZE);
870 if (username[0] == 0)
873 CtdlIPCKickoutUserFromRoom(ipc, username, buf);
874 scr_printf("%s\n", buf);
878 // aide command: kill the current room
879 void killroom(CtdlIPC * ipc) {
883 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
885 scr_printf("%s\n", aaa);
889 scr_printf("Are you sure you want to kill this room? ");
893 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
894 scr_printf("%s\n", aaa);
897 dotgoto(ipc, "_BASEROOM_", 0, 0);
901 void forget(CtdlIPC * ipc) { // forget the current room
904 scr_printf("Are you sure you want to forget this room? ");
908 remove_march(room_name, 0);
909 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
910 scr_printf("%s\n", buf);
914 // now return to the lobby
915 dotgoto(ipc, "_BASEROOM_", 0, 0);
920 void entroom(CtdlIPC * ipc) {
922 char new_room_name[ROOMNAMELEN];
924 char new_room_pass[10];
927 int r; // IPC response code
929 // Check permission to create room
930 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
932 scr_printf("%s\n", buf);
936 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
937 if (IsEmptyStr(new_room_name)) {
940 for (a = 0; !IsEmptyStr(&new_room_name[a]); ++a) {
941 if (new_room_name[a] == '|') {
942 new_room_name[a] = '_';
946 new_room_floor = select_floor(ipc, (int) curr_floor);
948 IFNEXPERT formout(ipc, "roomaccess");
950 scr_printf("<?>Help\n"
951 "<1>Public room (shown to all users by default)\n"
952 "<2>Hidden room (accessible to anyone who knows the room name)\n"
953 "<3>Passworded room (hidden, plus requires a password to enter)\n"
954 "<4>Invitation-only room (requires access to be granted by an Admin)\n"
955 "<5>Personal room (accessible to you only)\n" "Enter room type: ");
958 } while (((b < '1') || (b > '5')) && (b != '?'));
961 formout(ipc, "roomaccess");
963 } while ((b < '1') || (b > '5'));
964 b -= '0'; // Portable
965 scr_printf("%d\n", b);
966 new_room_type = b - 1;
967 if (new_room_type == 2) {
968 newprompt("Enter a room password: ", new_room_pass, 9);
969 for (a = 0; !IsEmptyStr(&new_room_pass[a]); ++a)
970 if (new_room_pass[a] == '|')
971 new_room_pass[a] = '_';
974 strcpy(new_room_pass, "");
977 scr_printf("\042%s\042, a", new_room_name);
979 scr_printf(" public room.");
981 scr_printf(" hidden room.");
983 scr_printf(" passworded room, password: %s", new_room_pass);
985 scr_printf("n invitation-only room.");
987 scr_printf(" personal room.");
988 scr_printf("\nInstall it? (y/n) : ");
993 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type, new_room_pass, new_room_floor, buf);
995 scr_printf("%s\n", buf);
999 // command succeeded... now GO to the new room!
1000 dotgoto(ipc, new_room_name, 0, 0);
1005 void readinfo(CtdlIPC * ipc) { // read info file for current room
1007 char room_admin_name[64];
1008 int r; // IPC response code
1011 // Name of currernt room admin
1012 r = CtdlIPCGetRoomAide(ipc, buf);
1014 strncpy(room_admin_name, buf, sizeof room_admin_name);
1016 strcpy(room_admin_name, "");
1018 if (!IsEmptyStr(room_admin_name))
1019 scr_printf("Room admin is %s.\n\n", room_admin_name);
1021 r = CtdlIPCRoomInfo(ipc, &text, buf);
1026 fmout(screenwidth, NULL, text, NULL, 1);
1032 // <W>ho knows room...
1033 void whoknows(CtdlIPC * ipc) {
1035 char *listing = NULL;
1038 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1040 scr_printf("%s\n", buf);
1043 while (!IsEmptyStr(listing)) {
1044 extract_token(buf, listing, 0, '\n', sizeof buf);
1045 remove_token(listing, 0, '\n');
1047 scr_printf("%s\n", buf);
1053 void do_edit(CtdlIPC * ipc, char *desc, char *read_cmd, char *check_cmd, char *write_cmd) {
1056 int b, cksum, editor_exit;
1058 if (IsEmptyStr(editor_path)) {
1059 scr_printf("Do you wish to re-enter %s? ", desc);
1064 fp = fopen(temp, "w");
1067 CtdlIPC_chat_send(ipc, check_cmd);
1068 CtdlIPC_chat_recv(ipc, cmd);
1069 if (cmd[0] != '2') {
1070 scr_printf("%s\n", &cmd[4]);
1074 if (!IsEmptyStr(editor_path)) {
1075 CtdlIPC_chat_send(ipc, read_cmd);
1076 CtdlIPC_chat_recv(ipc, cmd);
1077 if (cmd[0] == '1') {
1078 fp = fopen(temp, "w");
1079 while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
1080 fprintf(fp, "%s\n", cmd);
1086 cksum = file_checksum(temp);
1088 if (!IsEmptyStr(editor_path)) {
1091 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1093 stty_ctdl(SB_RESTORE);
1094 editor_pid = fork();
1095 if (editor_pid == 0) {
1097 execlp(editor_path, editor_path, temp, NULL);
1103 b = ka_wait(&editor_exit);
1104 } while ((b != editor_pid) && (b >= 0));
1106 scr_printf("Executed %s\n", editor_path);
1110 scr_printf("Entering %s. Press return twice when finished.\n", desc);
1111 fp = fopen(temp, "r+");
1116 if (file_checksum(temp) == cksum) {
1117 scr_printf("*** Aborted.\n");
1121 CtdlIPC_chat_send(ipc, write_cmd);
1122 CtdlIPC_chat_recv(ipc, cmd);
1123 if (cmd[0] != '4') {
1124 scr_printf("%s\n", &cmd[4]);
1128 fp = fopen(temp, "r");
1129 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1130 cmd[strlen(cmd) - 1] = 0;
1131 CtdlIPC_chat_send(ipc, cmd);
1134 CtdlIPC_chat_send(ipc, "000");
1141 // edit info file for current room
1142 void enterinfo(CtdlIPC * ipc) {
1143 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1147 void enter_bio(CtdlIPC * ipc) {
1149 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1150 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1154 // create a new floor
1155 void create_floor(CtdlIPC * ipc) {
1157 char newfloorname[SIZ];
1158 int r; // IPC response code
1160 load_floorlist(ipc);
1162 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1163 if ((r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE)) {
1164 scr_printf("%s\n", buf);
1168 newprompt("Name for new floor: ", newfloorname, 255);
1171 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1173 scr_printf("Floor has been created.\n");
1176 scr_printf("%s\n", buf);
1179 load_floorlist(ipc);
1183 // edit the current floor
1184 void edit_floor(CtdlIPC * ipc) {
1186 struct ExpirePolicy *ep = NULL;
1188 load_floorlist(ipc);
1190 // Fetch the expire policy (this will silently fail on old servers, resulting in "default" policy)
1191 CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1193 // Interact with the user
1194 scr_printf("You are editing the floor called \"%s\"\n", &floorlist[(int) curr_floor][0]);
1195 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1197 // Angels and demons dancing in my head...
1199 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1200 strprompt("Floor default message expire policy (? for list)", buf, 1);
1201 if (buf[0] == '?') {
1203 "0. Use the system default\n"
1204 "1. Never automatically expire messages\n"
1205 "2. Expire by message count\n" "3. Expire by message age\n");
1207 } while ((buf[0] < '0') || (buf[0] > '3'));
1208 ep->expire_mode = buf[0] - '0';
1210 // ...lunatics and monsters underneath my bed
1211 if (ep->expire_mode == 2) {
1212 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1213 strprompt("Keep how many messages online?", buf, 10);
1214 ep->expire_value = atol(buf);
1217 if (ep->expire_mode == 3) {
1218 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1219 strprompt("Keep messages for how many days?", buf, 10);
1220 ep->expire_value = atol(buf);
1224 CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1225 CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int) curr_floor][0], buf);
1226 scr_printf("%s\n", buf);
1227 load_floorlist(ipc);
1231 // kill the current floor
1232 void kill_floor(CtdlIPC * ipc) {
1233 int floornum_to_delete, a;
1236 load_floorlist(ipc);
1238 floornum_to_delete = (-1);
1239 scr_printf("(Press return to abort)\n");
1240 newprompt("Delete which floor? ", buf, 255);
1241 if (IsEmptyStr(buf))
1243 for (a = 0; a < 128; ++a)
1244 if (!strcasecmp(&floorlist[a][0], buf))
1245 floornum_to_delete = a;
1246 if (floornum_to_delete < 0) {
1247 scr_printf("No such floor. Select one of:\n");
1248 for (a = 0; a < 128; ++a)
1249 if (floorlist[a][0] != 0)
1250 scr_printf("%s\n", &floorlist[a][0]);
1252 } while (floornum_to_delete < 0);
1253 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1254 scr_printf("%s\n", buf);
1255 load_floorlist(ipc);