1 // Client-side functions which perform room operations
3 // Copyright (c) 1987-2022 by the citadel.org team
5 // This program is open source software. Use, duplication, and/or
6 // disclosure are subject to the GNU General Purpose License version 3.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 #include "textclient.h"
15 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
18 void stty_ctdl(int cmd);
19 void dotgoto(CtdlIPC * ipc, char *towhere, int display_name, int fromungoto);
20 void progress(CtdlIPC * ipc, unsigned long curr, unsigned long cmax);
21 int pattern(char *search, char *patn);
22 int file_checksum(char *filename);
23 int nukedir(char *dirname);
25 extern unsigned room_flags;
26 extern char room_name[];
28 extern char tempdir[];
29 extern int editor_pid;
30 extern int screenwidth;
31 extern int screenheight;
32 extern char fullname[];
33 extern char sigcaught;
34 extern char floor_mode;
35 extern char curr_floor;
40 extern char *uglist[];
41 extern long uglistlsn[];
42 extern int uglistsize;
44 extern char floorlist[128][SIZ];
47 void load_floorlist(CtdlIPC * ipc)
52 int r; /* IPC response code */
54 for (a = 0; a < 128; ++a)
57 r = CtdlIPCFloorListing(ipc, &listing, buf);
59 strcpy(floorlist[0], "Main Floor");
62 while (*listing && !IsEmptyStr(listing)) {
63 extract_token(buf, listing, 0, '\n', sizeof buf);
64 remove_token(listing, 0, '\n');
65 extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', SIZ);
71 void room_tree_list(struct ctdlroomlisting *rp)
74 char rmname[ROOMNAMELEN];
82 if (rp->lnext != NULL) {
83 room_tree_list(rp->lnext);
87 strcpy(rmname, rp->rlname);
89 if ((c + strlen(rmname) + 4) > screenwidth) {
91 /* line break, check the paginator */
97 } else if (f & QR_PRIVATE) {
102 scr_printf("%s", rmname);
103 if (f & QR_DIRECTORY) {
108 c = c + strlen(rmname) + 3;
111 if (rp->rnext != NULL) {
112 room_tree_list(rp->rnext);
120 * Room ordering stuff (compare first by floor, then by order)
122 int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2)
124 if ((r1 == NULL) && (r2 == NULL))
130 if (r1->rlfloor < r2->rlfloor)
132 if (r1->rlfloor > r2->rlfloor)
134 if (r1->rlorder < r2->rlorder)
136 if (r1->rlorder > r2->rlorder)
143 * Common code for all room listings
145 static void listrms(struct march *listing, int new_only, int floor_only, unsigned int flags, char *match)
148 struct ctdlroomlisting *rl = NULL;
149 struct ctdlroomlisting *rp;
150 struct ctdlroomlisting *rs;
153 for (mptr = listing; mptr != NULL; mptr = mptr->next) {
156 if ((new_only == LISTRMS_NEW_ONLY)
157 && ((mptr->march_access & UA_HASNEWMSGS) == 0))
160 if ((new_only == LISTRMS_OLD_ONLY)
161 && ((mptr->march_access & UA_HASNEWMSGS) != 0))
164 if ((floor_only >= 0)
165 && (mptr->march_floor != floor_only))
168 if (flags && (mptr->march_flags & flags) == 0)
171 if (match && (pattern(mptr->march_name, match) == -1))
175 rp = malloc(sizeof(struct ctdlroomlisting));
176 strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
177 rp->rlflags = mptr->march_flags;
178 rp->rlfloor = mptr->march_floor;
179 rp->rlorder = mptr->march_order;
188 if (rordercmp(rp, rs) < 0) {
189 if (rs->lnext == NULL) {
196 if (rs->rnext == NULL) {
208 room_tree_list(NULL);
214 void list_other_floors(void)
219 for (a = 0; a < 128; ++a) {
220 if ((strlen(floorlist[a]) > 0) && (a != curr_floor)) {
221 if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
225 scr_printf("%s: ", floorlist[a]);
226 c = c + strlen(floorlist[a]) + 3;
233 * List known rooms. kn_floor_mode should be set to 0 for a 'flat' listing,
234 * 1 to list rooms on the current floor, or 2 to list rooms on all floors.
236 void knrooms(CtdlIPC * ipc, int kn_floor_mode)
239 struct march *listing = NULL;
241 int r; /* IPC response code */
245 /* Ask the server for a room list */
246 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
254 if (kn_floor_mode == 0) {
256 scr_printf("\n Rooms with unread messages:\n");
257 listrms(listing, LISTRMS_NEW_ONLY, -1, 0, NULL);
259 scr_printf("\n\n No unseen messages in:\n");
260 listrms(listing, LISTRMS_OLD_ONLY, -1, 0, NULL);
264 if (kn_floor_mode == 1) {
266 scr_printf("\n Rooms with unread messages on %s:\n", floorlist[(int) curr_floor]);
267 listrms(listing, LISTRMS_NEW_ONLY, curr_floor, 0, NULL);
269 scr_printf("\n\n Rooms with no new messages on %s:\n", floorlist[(int) curr_floor]);
270 listrms(listing, LISTRMS_OLD_ONLY, curr_floor, 0, NULL);
272 scr_printf("\n\n Other floors:\n");
277 if (kn_floor_mode == 2) {
278 for (a = 0; a < 128; ++a) {
279 if (floorlist[a][0] != 0) {
281 scr_printf("\n Rooms on %s:\n", floorlist[a]);
282 listrms(listing, LISTRMS_ALL, a, 0, NULL);
288 /* Free the room list */
290 mptr = listing->next;
299 void listzrooms(CtdlIPC * ipc)
300 { /* list public forgotten rooms */
301 struct march *listing = NULL;
303 int r; /* IPC response code */
307 /* Ask the server for a room list */
308 r = CtdlIPCKnownRooms(ipc, UnsubscribedRooms, (-1), &listing, buf);
314 scr_printf("\n Forgotten public rooms:\n");
315 listrms(listing, LISTRMS_ALL, -1, 0, NULL);
318 /* Free the room list */
320 mptr = listing->next;
328 void dotknown(CtdlIPC * ipc, int what, char *match)
329 { /* list rooms according to attribute */
330 struct march *listing = NULL;
332 int r; /* IPC response code */
335 /* Ask the server for a room list */
336 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, (-1), &listing, buf);
345 scr_printf("\n Anonymous rooms:\n");
346 listrms(listing, LISTRMS_ALL, -1, QR_ANONONLY | QR_ANONOPT, NULL);
350 scr_printf("\n Directory rooms:\n");
351 listrms(listing, LISTRMS_ALL, -1, QR_DIRECTORY, NULL);
355 scr_printf("\n Matching \"%s\" rooms:\n", match);
356 listrms(listing, LISTRMS_ALL, -1, 0, match);
360 scr_printf("\n Preferred only rooms:\n");
361 listrms(listing, LISTRMS_ALL, -1, QR_PREFONLY, NULL);
365 scr_printf("\n Private rooms:\n");
366 listrms(listing, LISTRMS_ALL, -1, QR_PRIVATE, NULL);
370 scr_printf("\n Read only rooms:\n");
371 listrms(listing, LISTRMS_ALL, -1, QR_READONLY, NULL);
376 /* Free the room list */
378 mptr = listing->next;
387 int set_room_attr(CtdlIPC * ipc, unsigned int ibuf, char *prompt, unsigned int sbit)
391 a = boolprompt(prompt, (ibuf & sbit));
392 ibuf = (ibuf | sbit);
394 ibuf = (ibuf ^ sbit);
402 * Select a floor (used in several commands)
403 * The supplied argument is the 'default' floor number.
404 * This function returns the selected floor number.
406 int select_floor(CtdlIPC * ipc, int rfloor)
411 if (floor_mode == 1) {
412 if (floorlist[(int) curr_floor][0] == 0) {
418 strncpy(floorstr, floorlist[rfloor], sizeof floorstr);
419 strprompt("Which floor", floorstr, 255);
420 for (a = 0; a < 128; ++a) {
421 if (!strcasecmp(floorstr, &floorlist[a][0]))
424 && (!strncasecmp(floorstr, &floorlist[a][0], strlen(floorstr))))
427 && (pattern(&floorlist[a][0], floorstr)
432 scr_printf("\n One of:\n");
433 for (a = 0; a < 128; ++a) {
434 if (floorlist[a][0] != 0) {
435 scr_printf("%s\n", &floorlist[a][0]);
439 } while (newfloor < 0);
444 scr_printf("Floor selection bypassed because you have " "floor mode disabled.\n");
454 * .<A>ide <E>dit room
456 void editthisroom(CtdlIPC * ipc)
459 char room_admin_name[USERNAME_SIZE];
461 struct ctdlroom *attr = NULL;
462 struct ExpirePolicy *eptr = NULL;
463 int r; /* IPC response code */
465 /* Fetch the existing room config */
466 r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
468 scr_printf("%s\n", buf);
471 eptr = &(attr->QRep);
473 /* Fetch the name of the current room admin */
474 r = CtdlIPCGetRoomAide(ipc, buf);
476 strncpy(room_admin_name, buf, sizeof room_admin_name);
478 strcpy(room_admin_name, "");
480 if (IsEmptyStr(room_admin_name)) {
481 strcpy(room_admin_name, "none");
484 /* Fetch the expire policy (this will silently fail on old servers,
485 * resulting in "default" policy)
487 r = CtdlIPCGetMessageExpirationPolicy(ipc, 0, &eptr, buf);
489 /* Now interact with the user. */
491 strprompt("Room name", attr->QRname, ROOMNAMELEN - 1);
492 attr->QRfloor = select_floor(ipc, attr->QRfloor);
493 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
494 if (attr->QRflags & QR_PRIVATE) {
495 attr->QRflags = set_room_attr(ipc, attr->QRflags,
496 "Hidden room (accessible to anyone who knows the room name)", QR_GUESSNAME);
499 /* if it's public, clear the privacy classes */
500 if ((attr->QRflags & QR_PRIVATE) == 0) {
501 if (attr->QRflags & QR_GUESSNAME) {
502 attr->QRflags = attr->QRflags - QR_GUESSNAME;
504 if (attr->QRflags & QR_PASSWORDED) {
505 attr->QRflags = attr->QRflags - QR_PASSWORDED;
509 /* if it's private, choose the privacy classes */
510 if ((attr->QRflags & QR_PRIVATE)
511 && ((attr->QRflags & QR_GUESSNAME) == 0)) {
512 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Accessible by entering a password", QR_PASSWORDED);
514 if ((attr->QRflags & QR_PRIVATE)
515 && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
516 strprompt("Room password", attr->QRpasswd, 9);
519 if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
520 rbump = boolprompt("Cause current users to forget room", 0);
523 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Preferred users only", QR_PREFONLY);
524 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Read-only room", QR_READONLY);
525 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Allow message deletion by anyone who can post", QR2_COLLABDEL);
526 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Permanent room", QR_PERMANENT);
527 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Subject Required (Force users to specify a message subject)", QR2_SUBJECTREQ);
528 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Directory room", QR_DIRECTORY);
529 if (attr->QRflags & QR_DIRECTORY) {
530 strprompt("Directory name", attr->QRdirname, 14);
531 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Uploading allowed", QR_UPLOAD);
532 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Downloading allowed", QR_DOWNLOAD);
533 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Visible directory", QR_VISDIR);
535 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Self-service list subscribe/unsubscribe", QR2_SELFLIST);
536 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Allow non-subscribers to mail to this room", QR2_SMTP_PUBLIC);
537 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Moderated mailing list", QR2_MODERATED);
538 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Automatically make all messages anonymous", QR_ANONONLY);
539 if ((attr->QRflags & QR_ANONONLY) == 0) {
540 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Ask users whether to make messages anonymous", QR_ANONOPT);
542 attr->QRorder = intprompt("Listing order", attr->QRorder, 0, 127);
544 /* Ask about the room admin */
546 strprompt("Room admin (or 'none')", room_admin_name, 29);
547 if (!strcasecmp(room_admin_name, "none")) {
548 strcpy(room_admin_name, "");
552 r = CtdlIPCQueryUsername(ipc, room_admin_name, buf);
554 scr_printf("%s\n", buf);
557 } while (r / 100 != 2);
559 /* Angels and demons dancing in my head... */
561 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
562 strprompt("Message expire policy (? for list)", buf, 1);
565 "0. Use the default for this floor\n"
566 "1. Never automatically expire messages\n"
567 "2. Expire by message count\n" "3. Expire by message age\n");
569 } while ((buf[0] < 48) || (buf[0] > 51));
570 attr->QRep.expire_mode = buf[0] - 48;
572 /* ...lunatics and monsters underneath my bed */
573 if (attr->QRep.expire_mode == 2) {
574 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
575 strprompt("Keep how many messages online?", buf, 10);
576 attr->QRep.expire_value = atol(buf);
579 if (attr->QRep.expire_mode == 3) {
580 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
581 strprompt("Keep messages for how many days?", buf, 10);
582 attr->QRep.expire_value = atol(buf);
585 /* Give 'em a chance to change their minds */
586 scr_printf("Save changes (y/n)? ");
589 r = CtdlIPCSetRoomAide(ipc, room_admin_name, buf);
591 scr_printf("%s\n", buf);
594 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
596 scr_printf("%s\n", buf);
599 r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
600 scr_printf("%s\n", buf);
601 strncpy(buf, attr->QRname, ROOMNAMELEN);
604 dotgoto(ipc, buf, 2, 0);
614 * un-goto the previous room, or a specified room
616 void dotungoto(CtdlIPC * ipc, char *towhere) {
617 // Find this 'towhere' room in the list ungoto from this room to
618 // that at the messagepointer position in that room in our ungoto list.
619 // I suppose I could be a real dick and just ungoto that many places
624 struct ctdlipcroom *rret = NULL; // ignored
627 if (uglistsize == 0) {
628 scr_printf("No rooms to ungoto.\n");
631 if (towhere == NULL) {
632 scr_printf("Must specify a room to ungoto.\n");
635 if (IsEmptyStr(towhere)) {
636 scr_printf("Must specify a room to ungoto.\n");
639 for (lp = uglistsize - 1; lp >= 0; lp--) {
640 if (strcasecmp(towhere, uglist[lp]) == 0) {
646 scr_printf("Room: %s not in ungoto list.\n", towhere);
650 r = CtdlIPCGotoRoom(ipc, uglist[found], "", &rret, buf);
652 free(rret); // ignored
654 scr_printf("%s\n", buf);
657 r = CtdlIPCSetLastRead(ipc, uglistlsn[found] ? uglistlsn[found] : 1, buf);
659 scr_printf("%s\n", buf);
661 strncpy(buf, uglist[found], sizeof(buf));
662 // we queue ungoto information here, because we're not really
663 // ungotoing, we're really going to a random spot in some arbitrary
665 dotgoto(ipc, buf, 0, 0);
669 void ungoto(CtdlIPC * ipc) {
671 struct ctdlipcroom *rret = NULL; // ignored
674 if (uglistsize == 0) {
678 r = CtdlIPCGotoRoom(ipc, uglist[uglistsize - 1], "", &rret, buf);
680 free(rret); // ignored
683 scr_printf("%s\n", buf);
686 r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize - 1] ? uglistlsn[uglistsize - 1] : 1, buf);
688 scr_printf("%s\n", buf);
690 strncpy(buf, uglist[uglistsize - 1], sizeof(buf));
692 free(uglist[uglistsize]);
693 // Don't queue ungoto info or we end up in a loop
694 dotgoto(ipc, buf, 0, 1);
699 * saves filelen bytes from file at pathname
701 int save_buffer(void *file, size_t filelen, const char *pathname) {
703 size_t bytes_written = 0;
706 fp = fopen(pathname, "w");
708 scr_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
712 block = fwrite((char *) file + bytes_written, 1, filelen - bytes_written, fp);
713 bytes_written += block;
714 } while (errno == EINTR && bytes_written < filelen);
717 if (bytes_written < filelen) {
718 scr_printf("Trouble saving '%s': %s\n", pathname, strerror(errno));
726 * Save supplied_filename in dest directory; gets the name only
728 void destination_directory(char *dest, const char *supplied_filename) {
729 static char save_dir[SIZ] = { 0 };
731 if (IsEmptyStr(save_dir)) {
732 if (getenv("HOME") == NULL) {
733 strcpy(save_dir, ".");
735 sprintf(save_dir, "%s/Desktop", getenv("HOME"));
736 if (access(save_dir, W_OK) != 0) {
737 sprintf(save_dir, "%s", getenv("HOME"));
738 if (access(save_dir, W_OK) != 0) {
739 sprintf(save_dir, ".");
745 sprintf(dest, "%s/%s", save_dir, supplied_filename);
746 strprompt("Save as", dest, PATH_MAX);
748 /* Remember the directory for next time */
749 strcpy(save_dir, dest);
750 if (strrchr(save_dir, '/') != NULL) {
751 strcpy(strrchr(save_dir, '/'), "");
753 strcpy(save_dir, ".");
759 * download() - download a file or files. The argument passed to this
760 * function determines which protocol to use.
761 * proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
763 void download(CtdlIPC * ipc, int proto) {
765 char filename[PATH_MAX];
766 char tempname[PATH_MAX];
767 char transmit_cmd[SIZ];
772 void *file = NULL; /* The downloaded file */
773 size_t filelen = 0L; /* The downloaded file length */
775 if ((room_flags & QR_DOWNLOAD) == 0) {
776 scr_printf("*** You cannot download from this room.\n");
780 newprompt("Enter filename: ", filename, PATH_MAX);
782 /* Save to local disk, for folks with their own copy of the client */
784 destination_directory(tempname, filename);
785 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
787 scr_printf("%s\n", buf);
790 save_buffer(file, (size_t) extract_long(buf, 0), tempname);
795 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
797 scr_printf("%s\n", buf);
800 filelen = extract_unsigned_long(buf, 0);
802 /* Meta-download for public clients */
803 /* scr_printf("Fetching file from Citadel server...\n"); */
804 mkdir(tempdir, 0700);
805 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
806 tpipe = fopen(tempname, "wb");
807 if (fwrite(file, filelen, 1, tpipe) < filelen) {
808 /* FIXME: restart syscall on EINTR
816 /* FIXME: display internally instead */
817 snprintf(transmit_cmd, sizeof transmit_cmd,
818 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s", tempname);
819 } else if (proto == 1)
820 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
822 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
824 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
826 /* FIXME: display internally instead */
827 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
829 stty_ctdl(SB_RESTORE);
830 rv = system(transmit_cmd);
832 scr_printf("failed to download '%s': %d\n", transmit_cmd, rv);
833 stty_ctdl(SB_NO_INTR);
835 /* clean up the temporary directory */
837 ctdl_beep(); /* Beep beep! */
842 * read directory of this room
844 void roomdir(CtdlIPC * ipc)
851 char *listing = NULL; /* Returned directory listing */
854 r = CtdlIPCReadDirectory(ipc, &listing, buf);
856 scr_printf("%s\n", buf);
860 extract_token(comment, buf, 0, '|', sizeof comment);
861 extract_token(flnm, buf, 1, '|', sizeof flnm);
862 scr_printf("\nDirectory of %s on %s\n", flnm, comment);
863 scr_printf("-----------------------\n");
864 while (listing && *listing && !IsEmptyStr(listing)) {
865 extract_token(buf, listing, 0, '\n', sizeof buf);
866 remove_token(listing, 0, '\n');
868 extract_token(flnm, buf, 0, '|', sizeof flnm);
869 extract_token(flsz, buf, 1, '|', sizeof flsz);
870 extract_token(mimetype, buf, 2, '|', sizeof mimetype);
871 extract_token(comment, buf, 3, '|', sizeof comment);
872 if (strlen(flnm) <= 14)
873 scr_printf("%-14s %8s %s [%s]\n", flnm, flsz, comment, mimetype);
875 scr_printf("%s\n%14s %8s %s [%s]\n", flnm, "", flsz, comment, mimetype);
883 * add a user to a private room
885 void invite(CtdlIPC * ipc)
887 char username[USERNAME_SIZE];
890 newprompt("Name of user? ", username, USERNAME_SIZE);
891 if (username[0] == 0)
894 CtdlIPCInviteUserToRoom(ipc, username, buf);
895 scr_printf("%s\n", buf);
900 * kick a user out of a room
902 void kickout(CtdlIPC * ipc)
904 char username[USERNAME_SIZE];
907 newprompt("Name of user? ", username, USERNAME_SIZE);
908 if (username[0] == 0)
911 CtdlIPCKickoutUserFromRoom(ipc, username, buf);
912 scr_printf("%s\n", buf);
917 * aide command: kill the current room
919 void killroom(CtdlIPC * ipc)
924 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
926 scr_printf("%s\n", aaa);
930 scr_printf("Are you sure you want to kill this room? ");
934 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
935 scr_printf("%s\n", aaa);
938 dotgoto(ipc, "_BASEROOM_", 0, 0);
941 void forget(CtdlIPC * ipc)
942 { /* forget the current room */
945 scr_printf("Are you sure you want to forget this room? ");
949 remove_march(room_name, 0);
950 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
951 scr_printf("%s\n", buf);
955 /* now return to the lobby */
956 dotgoto(ipc, "_BASEROOM_", 0, 0);
963 void entroom(CtdlIPC * ipc)
966 char new_room_name[ROOMNAMELEN];
968 char new_room_pass[10];
971 int r; /* IPC response code */
973 /* Check permission to create room */
974 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
976 scr_printf("%s\n", buf);
980 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
981 if (IsEmptyStr(new_room_name)) {
984 for (a = 0; !IsEmptyStr(&new_room_name[a]); ++a) {
985 if (new_room_name[a] == '|') {
986 new_room_name[a] = '_';
990 new_room_floor = select_floor(ipc, (int) curr_floor);
992 IFNEXPERT formout(ipc, "roomaccess");
994 scr_printf("<?>Help\n"
995 "<1>Public room (shown to all users by default)\n"
996 "<2>Hidden room (accessible to anyone who knows the room name)\n"
997 "<3>Passworded room (hidden, plus requires a password to enter)\n"
998 "<4>Invitation-only room (requires access to be granted by an Admin)\n"
999 "<5>Personal room (accessible to you only)\n" "Enter room type: ");
1002 } while (((b < '1') || (b > '5')) && (b != '?'));
1005 formout(ipc, "roomaccess");
1007 } while ((b < '1') || (b > '5'));
1008 b -= '0'; /* Portable */
1009 scr_printf("%d\n", b);
1010 new_room_type = b - 1;
1011 if (new_room_type == 2) {
1012 newprompt("Enter a room password: ", new_room_pass, 9);
1013 for (a = 0; !IsEmptyStr(&new_room_pass[a]); ++a)
1014 if (new_room_pass[a] == '|')
1015 new_room_pass[a] = '_';
1017 strcpy(new_room_pass, "");
1020 scr_printf("\042%s\042, a", new_room_name);
1022 scr_printf(" public room.");
1024 scr_printf(" hidden room.");
1026 scr_printf(" passworded room, password: %s", new_room_pass);
1028 scr_printf("n invitation-only room.");
1030 scr_printf(" personal room.");
1031 scr_printf("\nInstall it? (y/n) : ");
1036 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type, new_room_pass, new_room_floor, buf);
1038 scr_printf("%s\n", buf);
1042 /* command succeeded... now GO to the new room! */
1043 dotgoto(ipc, new_room_name, 0, 0);
1048 void readinfo(CtdlIPC * ipc)
1049 { /* read info file for current room */
1051 char room_admin_name[64];
1052 int r; /* IPC response code */
1055 /* Name of currernt room admin */
1056 r = CtdlIPCGetRoomAide(ipc, buf);
1058 strncpy(room_admin_name, buf, sizeof room_admin_name);
1060 strcpy(room_admin_name, "");
1062 if (!IsEmptyStr(room_admin_name))
1063 scr_printf("Room admin is %s.\n\n", room_admin_name);
1065 r = CtdlIPCRoomInfo(ipc, &text, buf);
1070 fmout(screenwidth, NULL, text, NULL, 1);
1077 * <W>ho knows room...
1079 void whoknows(CtdlIPC * ipc)
1082 char *listing = NULL;
1085 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1087 scr_printf("%s\n", buf);
1090 while (!IsEmptyStr(listing)) {
1091 extract_token(buf, listing, 0, '\n', sizeof buf);
1092 remove_token(listing, 0, '\n');
1094 scr_printf("%s\n", buf);
1100 void do_edit(CtdlIPC * ipc, char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
1104 int b, cksum, editor_exit;
1106 if (IsEmptyStr(editor_path)) {
1107 scr_printf("Do you wish to re-enter %s? ", desc);
1112 fp = fopen(temp, "w");
1115 CtdlIPC_chat_send(ipc, check_cmd);
1116 CtdlIPC_chat_recv(ipc, cmd);
1117 if (cmd[0] != '2') {
1118 scr_printf("%s\n", &cmd[4]);
1122 if (!IsEmptyStr(editor_path)) {
1123 CtdlIPC_chat_send(ipc, read_cmd);
1124 CtdlIPC_chat_recv(ipc, cmd);
1125 if (cmd[0] == '1') {
1126 fp = fopen(temp, "w");
1127 while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
1128 fprintf(fp, "%s\n", cmd);
1134 cksum = file_checksum(temp);
1136 if (!IsEmptyStr(editor_path)) {
1139 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1141 stty_ctdl(SB_RESTORE);
1142 editor_pid = fork();
1143 if (editor_pid == 0) {
1145 execlp(editor_path, editor_path, temp, NULL);
1151 b = ka_wait(&editor_exit);
1152 } while ((b != editor_pid) && (b >= 0));
1154 scr_printf("Executed %s\n", editor_path);
1157 scr_printf("Entering %s. Press return twice when finished.\n", desc);
1158 fp = fopen(temp, "r+");
1163 if (file_checksum(temp) == cksum) {
1164 scr_printf("*** Aborted.\n");
1168 CtdlIPC_chat_send(ipc, write_cmd);
1169 CtdlIPC_chat_recv(ipc, cmd);
1170 if (cmd[0] != '4') {
1171 scr_printf("%s\n", &cmd[4]);
1175 fp = fopen(temp, "r");
1176 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1177 cmd[strlen(cmd) - 1] = 0;
1178 CtdlIPC_chat_send(ipc, cmd);
1181 CtdlIPC_chat_send(ipc, "000");
1188 void enterinfo(CtdlIPC * ipc)
1189 { /* edit info file for current room */
1190 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1193 void enter_bio(CtdlIPC * ipc)
1196 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1197 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1201 * create a new floor
1203 void create_floor(CtdlIPC * ipc)
1206 char newfloorname[SIZ];
1207 int r; /* IPC response code */
1209 load_floorlist(ipc);
1211 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1212 if ((r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE)) {
1213 scr_printf("%s\n", buf);
1217 newprompt("Name for new floor: ", newfloorname, 255);
1220 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1222 scr_printf("Floor has been created.\n");
1224 scr_printf("%s\n", buf);
1227 load_floorlist(ipc);
1231 * edit the current floor
1233 void edit_floor(CtdlIPC * ipc)
1236 struct ExpirePolicy *ep = NULL;
1238 load_floorlist(ipc);
1240 /* Fetch the expire policy (this will silently fail on old servers,
1241 * resulting in "default" policy)
1243 CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1245 /* Interact with the user */
1246 scr_printf("You are editing the floor called \"%s\"\n", &floorlist[(int) curr_floor][0]);
1247 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1249 /* Angels and demons dancing in my head... */
1251 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1252 strprompt("Floor default message expire policy (? for list)", buf, 1);
1253 if (buf[0] == '?') {
1255 "0. Use the system default\n"
1256 "1. Never automatically expire messages\n"
1257 "2. Expire by message count\n" "3. Expire by message age\n");
1259 } while ((buf[0] < '0') || (buf[0] > '3'));
1260 ep->expire_mode = buf[0] - '0';
1262 /* ...lunatics and monsters underneath my bed */
1263 if (ep->expire_mode == 2) {
1264 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1265 strprompt("Keep how many messages online?", buf, 10);
1266 ep->expire_value = atol(buf);
1269 if (ep->expire_mode == 3) {
1270 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1271 strprompt("Keep messages for how many days?", buf, 10);
1272 ep->expire_value = atol(buf);
1276 CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1277 CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int) curr_floor][0], buf);
1278 scr_printf("%s\n", buf);
1279 load_floorlist(ipc);
1286 * kill the current floor
1288 void kill_floor(CtdlIPC * ipc)
1290 int floornum_to_delete, a;
1293 load_floorlist(ipc);
1295 floornum_to_delete = (-1);
1296 scr_printf("(Press return to abort)\n");
1297 newprompt("Delete which floor? ", buf, 255);
1298 if (IsEmptyStr(buf))
1300 for (a = 0; a < 128; ++a)
1301 if (!strcasecmp(&floorlist[a][0], buf))
1302 floornum_to_delete = a;
1303 if (floornum_to_delete < 0) {
1304 scr_printf("No such floor. Select one of:\n");
1305 for (a = 0; a < 128; ++a)
1306 if (floorlist[a][0] != 0)
1307 scr_printf("%s\n", &floorlist[a][0]);
1309 } while (floornum_to_delete < 0);
1310 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1311 scr_printf("%s\n", buf);
1312 load_floorlist(ipc);