2 * Client-side functions which perform room operations
4 * Copyright (c) 1987-2018 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include "textclient.h"
17 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
20 void stty_ctdl(int cmd);
21 void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto);
22 void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax);
23 int pattern(char *search, char *patn);
24 int file_checksum(char *filename);
25 int nukedir(char *dirname);
27 extern unsigned room_flags;
28 extern char room_name[];
30 extern char tempdir[];
31 extern int editor_pid;
32 extern int screenwidth;
33 extern int screenheight;
34 extern char fullname[];
35 extern char sigcaught;
36 extern char floor_mode;
37 extern char curr_floor;
42 extern char *uglist[];
43 extern long uglistlsn[];
44 extern int uglistsize;
46 extern char floorlist[128][SIZ];
49 void load_floorlist(CtdlIPC *ipc)
54 int r; /* IPC response code */
56 for (a = 0; a < 128; ++a)
59 r = CtdlIPCFloorListing(ipc, &listing, buf);
61 strcpy(floorlist[0], "Main Floor");
64 while (*listing && !IsEmptyStr(listing)) {
65 extract_token(buf, listing, 0, '\n', sizeof buf);
66 remove_token(listing, 0, '\n');
67 extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', SIZ);
73 void room_tree_list(struct ctdlroomlisting *rp)
76 char rmname[ROOMNAMELEN];
84 if (rp->lnext != NULL) {
85 room_tree_list(rp->lnext);
89 strcpy(rmname, rp->rlname);
91 if ((c + strlen(rmname) + 4) > screenwidth) {
93 /* line break, check the paginator */
99 } else if (f & QR_PRIVATE) {
104 scr_printf("%s", rmname);
105 if (f & QR_DIRECTORY) {
111 c = c + strlen(rmname) + 3;
114 if (rp->rnext != NULL) {
115 room_tree_list(rp->rnext);
123 * Room ordering stuff (compare first by floor, then by order)
125 int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2)
127 if ((r1 == NULL) && (r2 == NULL))
133 if (r1->rlfloor < r2->rlfloor)
135 if (r1->rlfloor > r2->rlfloor)
137 if (r1->rlorder < r2->rlorder)
139 if (r1->rlorder > r2->rlorder)
146 * Common code for all room listings
148 static void listrms(struct march *listing, int new_only, int floor_only, unsigned int flags, char *match)
151 struct ctdlroomlisting *rl = NULL;
152 struct ctdlroomlisting *rp;
153 struct ctdlroomlisting *rs;
156 for (mptr = listing; mptr != NULL; mptr = mptr->next) {
159 if ( (new_only == LISTRMS_NEW_ONLY)
160 && ((mptr->march_access & UA_HASNEWMSGS) == 0))
163 if ( (new_only == LISTRMS_OLD_ONLY)
164 && ((mptr->march_access & UA_HASNEWMSGS) != 0))
167 if ( (floor_only >= 0)
168 && (mptr->march_floor != floor_only))
171 if (flags && (mptr->march_flags & flags) == 0)
174 if (match && (pattern(mptr->march_name, match) == -1))
178 rp = malloc(sizeof(struct ctdlroomlisting));
179 strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
180 rp->rlflags = mptr->march_flags;
181 rp->rlfloor = mptr->march_floor;
182 rp->rlorder = mptr->march_order;
191 if (rordercmp(rp, rs) < 0) {
192 if (rs->lnext == NULL) {
199 if (rs->rnext == NULL) {
211 room_tree_list(NULL);
217 void list_other_floors(void)
222 for (a = 0; a < 128; ++a) {
223 if ((strlen(floorlist[a]) > 0) && (a != curr_floor)) {
224 if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
228 scr_printf("%s: ", floorlist[a]);
229 c = c + strlen(floorlist[a]) + 3;
236 * List known rooms. kn_floor_mode should be set to 0 for a 'flat' listing,
237 * 1 to list rooms on the current floor, or 2 to list rooms on all floors.
239 void knrooms(CtdlIPC *ipc, int kn_floor_mode)
242 struct march *listing = NULL;
244 int r; /* IPC response code */
248 /* Ask the server for a room list */
249 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
257 if (kn_floor_mode == 0) {
259 scr_printf("\n Rooms with unread messages:\n");
260 listrms(listing, LISTRMS_NEW_ONLY, -1, 0, NULL);
262 scr_printf("\n\n No unseen messages in:\n");
263 listrms(listing, LISTRMS_OLD_ONLY, -1, 0, NULL);
267 if (kn_floor_mode == 1) {
269 scr_printf("\n Rooms with unread messages on %s:\n",
270 floorlist[(int) curr_floor]);
271 listrms(listing, LISTRMS_NEW_ONLY, curr_floor, 0, NULL);
273 scr_printf("\n\n Rooms with no new messages on %s:\n",
274 floorlist[(int) curr_floor]);
275 listrms(listing, LISTRMS_OLD_ONLY, curr_floor, 0, NULL);
277 scr_printf("\n\n Other floors:\n");
282 if (kn_floor_mode == 2) {
283 for (a = 0; a < 128; ++a) {
284 if (floorlist[a][0] != 0) {
286 scr_printf("\n Rooms on %s:\n",
288 listrms(listing, LISTRMS_ALL, a, 0, NULL);
294 /* Free the room list */
296 mptr = listing->next;
305 void listzrooms(CtdlIPC *ipc)
306 { /* list public forgotten rooms */
307 struct march *listing = NULL;
309 int r; /* IPC response code */
313 /* Ask the server for a room list */
314 r = CtdlIPCKnownRooms(ipc, UnsubscribedRooms, (-1), &listing, buf);
320 scr_printf("\n Forgotten public rooms:\n");
321 listrms(listing, LISTRMS_ALL, -1, 0, NULL);
324 /* Free the room list */
326 mptr = listing->next;
334 void dotknown(CtdlIPC *ipc, int what, char *match)
335 { /* list rooms according to attribute */
336 struct march *listing = NULL;
338 int r; /* IPC response code */
341 /* Ask the server for a room list */
342 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, (-1), &listing, buf);
351 scr_printf("\n Anonymous rooms:\n");
352 listrms(listing, LISTRMS_ALL, -1, QR_ANONONLY|QR_ANONOPT, NULL);
356 scr_printf("\n Directory rooms:\n");
357 listrms(listing, LISTRMS_ALL, -1, QR_DIRECTORY, NULL);
361 scr_printf("\n Matching \"%s\" rooms:\n", match);
362 listrms(listing, LISTRMS_ALL, -1, 0, match);
366 scr_printf("\n Preferred only rooms:\n");
367 listrms(listing, LISTRMS_ALL, -1, QR_PREFONLY, NULL);
371 scr_printf("\n Private rooms:\n");
372 listrms(listing, LISTRMS_ALL, -1, QR_PRIVATE, NULL);
376 scr_printf("\n Read only rooms:\n");
377 listrms(listing, LISTRMS_ALL, -1, QR_READONLY, NULL);
382 /* Free the room list */
384 mptr = listing->next;
393 int set_room_attr(CtdlIPC *ipc, unsigned int ibuf, char *prompt, unsigned int sbit)
397 a = boolprompt(prompt, (ibuf & sbit));
398 ibuf = (ibuf | sbit);
400 ibuf = (ibuf ^ sbit);
408 * Select a floor (used in several commands)
409 * The supplied argument is the 'default' floor number.
410 * This function returns the selected floor number.
412 int select_floor(CtdlIPC *ipc, int rfloor)
417 if (floor_mode == 1) {
418 if (floorlist[(int) curr_floor][0] == 0) {
424 safestrncpy(floorstr, floorlist[rfloor],
426 strprompt("Which floor", floorstr, 255);
427 for (a = 0; a < 128; ++a) {
429 (floorstr, &floorlist[a][0]))
434 (floorstr, &floorlist[a][0],
438 && (pattern(&floorlist[a][0], floorstr)
443 scr_printf("\n One of:\n");
444 for (a = 0; a < 128; ++a) {
445 if (floorlist[a][0] != 0) {
451 } while (newfloor < 0);
456 scr_printf("Floor selection bypassed because you have "
457 "floor mode disabled.\n");
467 * .<A>ide <E>dit room
469 void editthisroom(CtdlIPC *ipc)
472 char room_admin_name[USERNAME_SIZE];
474 struct ctdlroom *attr = NULL;
475 struct ExpirePolicy *eptr = NULL;
476 int r; /* IPC response code */
478 /* Fetch the existing room config */
479 r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
481 scr_printf("%s\n", buf);
484 eptr = &(attr->QRep);
486 /* Fetch the name of the current room admin */
487 r = CtdlIPCGetRoomAide(ipc, buf);
489 safestrncpy(room_admin_name, buf, sizeof room_admin_name);
491 strcpy(room_admin_name, "");
493 if (IsEmptyStr(room_admin_name)) {
494 strcpy(room_admin_name, "none");
497 /* Fetch the expire policy (this will silently fail on old servers,
498 * resulting in "default" policy)
500 r = CtdlIPCGetMessageExpirationPolicy(ipc, 0, &eptr, buf);
502 /* Now interact with the user. */
504 strprompt("Room name", attr->QRname, ROOMNAMELEN-1);
505 attr->QRfloor = select_floor(ipc, attr->QRfloor);
506 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
507 if (attr->QRflags & QR_PRIVATE) {
508 attr->QRflags = set_room_attr(ipc, attr->QRflags,
509 "Hidden room (accessible to anyone who knows the room name)",
513 /* if it's public, clear the privacy classes */
514 if ((attr->QRflags & QR_PRIVATE) == 0) {
515 if (attr->QRflags & QR_GUESSNAME) {
516 attr->QRflags = attr->QRflags - QR_GUESSNAME;
518 if (attr->QRflags & QR_PASSWORDED) {
519 attr->QRflags = attr->QRflags - QR_PASSWORDED;
523 /* if it's private, choose the privacy classes */
524 if ((attr->QRflags & QR_PRIVATE)
525 && ((attr->QRflags & QR_GUESSNAME) == 0)) {
526 attr->QRflags = set_room_attr(ipc, attr->QRflags,
527 "Accessible by entering a password",
530 if ((attr->QRflags & QR_PRIVATE)
531 && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
532 strprompt("Room password", attr->QRpasswd, 9);
535 if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
536 rbump = boolprompt("Cause current users to forget room", 0);
539 attr->QRflags = set_room_attr(ipc, attr->QRflags,
540 "Preferred users only", QR_PREFONLY);
541 attr->QRflags = set_room_attr(ipc, attr->QRflags,
542 "Read-only room", QR_READONLY);
543 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
544 "Allow message deletion by anyone who can post",
546 attr->QRflags = set_room_attr(ipc, attr->QRflags,
547 "Permanent room", QR_PERMANENT);
548 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
549 "Subject Required (Force "
550 "users to specify a message "
551 "subject)", QR2_SUBJECTREQ);
552 attr->QRflags = set_room_attr(ipc, attr->QRflags,
553 "Directory room", QR_DIRECTORY);
554 if (attr->QRflags & QR_DIRECTORY) {
555 strprompt("Directory name", attr->QRdirname, 14);
557 set_room_attr(ipc, attr->QRflags,
558 "Uploading allowed", QR_UPLOAD);
560 set_room_attr(ipc, attr->QRflags, "Downloading allowed",
563 set_room_attr(ipc, attr->QRflags,
564 "Visible directory", QR_VISDIR);
566 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
567 "Self-service list subscribe/unsubscribe",
569 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
570 "public posting to this room via room_roomname@yourcitadel.org",
572 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
573 "moderated mailinglist",
575 attr->QRflags = set_room_attr(ipc, attr->QRflags,
576 "Automatically make all messages anonymous",
578 if ((attr->QRflags & QR_ANONONLY) == 0) {
579 attr->QRflags = set_room_attr(ipc, attr->QRflags,
580 "Ask users whether to make messages anonymous",
583 attr->QRorder = intprompt("Listing order", attr->QRorder, 0, 127);
585 /* Ask about the room admin */
587 strprompt("Room admin (or 'none')", room_admin_name, 29);
588 if (!strcasecmp(room_admin_name, "none")) {
589 strcpy(room_admin_name, "");
592 r = CtdlIPCQueryUsername(ipc, room_admin_name, buf);
594 scr_printf("%s\n", buf);
596 } while (r / 100 != 2);
598 /* Angels and demons dancing in my head... */
600 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
601 strprompt("Message expire policy (? for list)", buf, 1);
604 "0. Use the default for this floor\n"
605 "1. Never automatically expire messages\n"
606 "2. Expire by message count\n"
607 "3. Expire by message age\n");
609 } while ((buf[0] < 48) || (buf[0] > 51));
610 attr->QRep.expire_mode = buf[0] - 48;
612 /* ...lunatics and monsters underneath my bed */
613 if (attr->QRep.expire_mode == 2) {
614 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
615 strprompt("Keep how many messages online?", buf, 10);
616 attr->QRep.expire_value = atol(buf);
619 if (attr->QRep.expire_mode == 3) {
620 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
621 strprompt("Keep messages for how many days?", buf, 10);
622 attr->QRep.expire_value = atol(buf);
625 /* Give 'em a chance to change their minds */
626 scr_printf("Save changes (y/n)? ");
629 r = CtdlIPCSetRoomAide(ipc, room_admin_name, buf);
631 scr_printf("%s\n", buf);
634 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
636 scr_printf("%s\n", buf);
639 r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
640 scr_printf("%s\n", buf);
641 strncpy(buf, attr->QRname, ROOMNAMELEN);
644 dotgoto(ipc, buf, 2, 0);
651 * un-goto the previous room, or a specified room
653 void dotungoto(CtdlIPC *ipc, char *towhere)
655 /* Find this 'towhere' room in the list ungoto from this room to
656 that at the messagepointer position in that room in our ungoto list.
657 I suppose I could be a real dick and just ungoto that many places
662 struct ctdlipcroom *rret = NULL; /* ignored */
667 scr_printf("No rooms to ungoto.\n");
672 scr_printf("Must specify a room to ungoto.\n");
675 if (IsEmptyStr(towhere))
677 scr_printf("Must specify a room to ungoto.\n");
680 for (lp = uglistsize-1; lp >= 0; lp--)
682 if (strcasecmp(towhere, uglist[lp]) == 0)
690 scr_printf("Room: %s not in ungoto list.\n", towhere);
694 r = CtdlIPCGotoRoom(ipc, uglist[found], "", &rret, buf);
695 if (rret) free(rret); /* ignored */
697 scr_printf("%s\n", buf);
700 r = CtdlIPCSetLastRead(ipc, uglistlsn[found] ? uglistlsn[found] : 1, buf);
702 scr_printf("%s\n", buf);
704 safestrncpy(buf, uglist[found], sizeof(buf));
705 /* we queue ungoto information here, because we're not really
706 ungotoing, we're really going to a random spot in some arbitrary
708 dotgoto(ipc, buf, 0, 0);
711 void ungoto(CtdlIPC *ipc)
714 struct ctdlipcroom *rret = NULL; /* ignored */
720 r = CtdlIPCGotoRoom(ipc, uglist[uglistsize-1], "", &rret, buf);
721 if (rret) free(rret); /* ignored */
723 scr_printf("%s\n", buf);
726 r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize-1] ? uglistlsn[uglistsize-1] : 1, buf);
728 scr_printf("%s\n", buf);
730 safestrncpy(buf, uglist[uglistsize-1], sizeof(buf));
732 free(uglist[uglistsize]);
733 /* Don't queue ungoto info or we end up in a loop */
734 dotgoto(ipc, buf, 0, 1);
739 * saves filelen bytes from file at pathname
741 int save_buffer(void *file, size_t filelen, const char *pathname)
744 size_t bytes_written = 0;
747 fp = fopen(pathname, "w");
749 scr_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
753 block = fwrite((char *)file + bytes_written, 1,
754 filelen - bytes_written, fp);
755 bytes_written += block;
756 } while (errno == EINTR && bytes_written < filelen);
759 if (bytes_written < filelen) {
760 scr_printf("Trouble saving '%s': %s\n", pathname,
769 * Save supplied_filename in dest directory; gets the name only
771 void destination_directory(char *dest, const char *supplied_filename)
773 static char save_dir[SIZ] = { 0 };
775 if (IsEmptyStr(save_dir)) {
776 if (getenv("HOME") == NULL) {
777 strcpy(save_dir, ".");
780 sprintf(save_dir, "%s/Desktop", getenv("HOME"));
781 if (access(save_dir, W_OK) != 0) {
782 sprintf(save_dir, "%s", getenv("HOME"));
783 if (access(save_dir, W_OK) != 0) {
784 sprintf(save_dir, ".");
790 sprintf(dest, "%s/%s", save_dir, supplied_filename);
791 strprompt("Save as", dest, PATH_MAX);
793 /* Remember the directory for next time */
794 strcpy(save_dir, dest);
795 if (strrchr(save_dir, '/') != NULL) {
796 strcpy(strrchr(save_dir, '/'), "");
799 strcpy(save_dir, ".");
805 * download() - download a file or files. The argument passed to this
806 * function determines which protocol to use.
807 * proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
809 void download(CtdlIPC *ipc, int proto)
812 char filename[PATH_MAX];
813 char tempname[PATH_MAX];
814 char transmit_cmd[SIZ];
819 void *file = NULL; /* The downloaded file */
820 size_t filelen = 0L; /* The downloaded file length */
822 if ((room_flags & QR_DOWNLOAD) == 0) {
823 scr_printf("*** You cannot download from this room.\n");
827 newprompt("Enter filename: ", filename, PATH_MAX);
829 /* Save to local disk, for folks with their own copy of the client */
831 destination_directory(tempname, filename);
832 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
834 scr_printf("%s\n", buf);
837 save_buffer(file, (size_t)extract_long(buf, 0), tempname);
842 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
844 scr_printf("%s\n", buf);
847 filelen = extract_unsigned_long(buf, 0);
849 /* Meta-download for public clients */
850 /* scr_printf("Fetching file from Citadel server...\n"); */
851 mkdir(tempdir, 0700);
852 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
853 tpipe = fopen(tempname, "wb");
854 if (fwrite(file, filelen, 1, tpipe) < filelen) {
855 /* FIXME: restart syscall on EINTR
859 if (file) free(file);
862 /* FIXME: display internally instead */
863 snprintf(transmit_cmd, sizeof transmit_cmd,
864 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",
868 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
870 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
872 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
874 /* FIXME: display internally instead */
875 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
877 stty_ctdl(SB_RESTORE);
878 rv = system(transmit_cmd);
880 scr_printf("failed to download '%s': %d\n", transmit_cmd, rv);
881 stty_ctdl(SB_NO_INTR);
883 /* clean up the temporary directory */
885 ctdl_beep(); /* Beep beep! */
890 * read directory of this room
892 void roomdir(CtdlIPC *ipc)
899 char *listing = NULL; /* Returned directory listing */
902 r = CtdlIPCReadDirectory(ipc, &listing, buf);
904 scr_printf("%s\n", buf);
908 extract_token(comment, buf, 0, '|', sizeof comment);
909 extract_token(flnm, buf, 1, '|', sizeof flnm);
910 scr_printf("\nDirectory of %s on %s\n", flnm, comment);
911 scr_printf("-----------------------\n");
912 while (listing && *listing && !IsEmptyStr(listing)) {
913 extract_token(buf, listing, 0, '\n', sizeof buf);
914 remove_token(listing, 0, '\n');
916 extract_token(flnm, buf, 0, '|', sizeof flnm);
917 extract_token(flsz, buf, 1, '|', sizeof flsz);
918 extract_token(mimetype, buf, 2, '|', sizeof mimetype);
919 extract_token(comment, buf, 3, '|', sizeof comment);
920 if (strlen(flnm) <= 14)
921 scr_printf("%-14s %8s %s [%s]\n", flnm, flsz, comment, mimetype);
923 scr_printf("%s\n%14s %8s %s [%s]\n", flnm, "", flsz,
926 if (listing) free(listing);
931 * add a user to a private room
933 void invite(CtdlIPC *ipc)
935 char username[USERNAME_SIZE];
938 newprompt("Name of user? ", username, USERNAME_SIZE);
939 if (username[0] == 0)
942 CtdlIPCInviteUserToRoom(ipc, username, buf);
943 scr_printf("%s\n", buf);
948 * kick a user out of a room
950 void kickout(CtdlIPC *ipc)
952 char username[USERNAME_SIZE];
955 newprompt("Name of user? ", username, USERNAME_SIZE);
956 if (username[0] == 0)
959 CtdlIPCKickoutUserFromRoom(ipc, username, buf);
960 scr_printf("%s\n", buf);
965 * aide command: kill the current room
967 void killroom(CtdlIPC *ipc)
972 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
974 scr_printf("%s\n", aaa);
978 scr_printf("Are you sure you want to kill this room? ");
982 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
983 scr_printf("%s\n", aaa);
986 dotgoto(ipc, "_BASEROOM_", 0, 0);
989 void forget(CtdlIPC *ipc)
990 { /* forget the current room */
993 scr_printf("Are you sure you want to forget this room? ");
997 remove_march(room_name, 0);
998 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
999 scr_printf("%s\n", buf);
1003 /* now return to the lobby */
1004 dotgoto(ipc, "_BASEROOM_", 0, 0);
1011 void entroom(CtdlIPC *ipc)
1014 char new_room_name[ROOMNAMELEN];
1016 char new_room_pass[10];
1019 int r; /* IPC response code */
1021 /* Check permission to create room */
1022 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
1024 scr_printf("%s\n", buf);
1028 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
1029 if (IsEmptyStr(new_room_name)) {
1032 for (a = 0; !IsEmptyStr(&new_room_name[a]); ++a) {
1033 if (new_room_name[a] == '|') {
1034 new_room_name[a] = '_';
1038 new_room_floor = select_floor(ipc, (int) curr_floor);
1040 IFNEXPERT formout(ipc, "roomaccess");
1042 scr_printf("<?>Help\n"
1043 "<1>Public room (shown to all users by default)\n"
1044 "<2>Hidden room (accessible to anyone who knows the room name)\n"
1045 "<3>Passworded room (hidden, plus requires a password to enter)\n"
1046 "<4>Invitation-only room (requires access to be granted by an Admin)\n"
1047 "<5>Personal room (accessible to you only)\n"
1052 } while (((b < '1') || (b > '5')) && (b != '?'));
1055 formout(ipc, "roomaccess");
1057 } while ((b < '1') || (b > '5'));
1058 b -= '0'; /* Portable */
1059 scr_printf("%d\n", b);
1060 new_room_type = b - 1;
1061 if (new_room_type == 2) {
1062 newprompt("Enter a room password: ", new_room_pass, 9);
1063 for (a = 0; !IsEmptyStr(&new_room_pass[a]); ++a)
1064 if (new_room_pass[a] == '|')
1065 new_room_pass[a] = '_';
1067 strcpy(new_room_pass, "");
1070 scr_printf("\042%s\042, a", new_room_name);
1072 scr_printf(" public room.");
1074 scr_printf(" hidden room.");
1076 scr_printf(" passworded room, password: %s", new_room_pass);
1078 scr_printf("n invitation-only room.");
1080 scr_printf(" personal room.");
1081 scr_printf("\nInstall it? (y/n) : ");
1086 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type,
1087 new_room_pass, new_room_floor, buf);
1089 scr_printf("%s\n", buf);
1093 /* command succeeded... now GO to the new room! */
1094 dotgoto(ipc, new_room_name, 0, 0);
1099 void readinfo(CtdlIPC *ipc)
1100 { /* read info file for current room */
1102 char room_admin_name[64];
1103 int r; /* IPC response code */
1106 /* Name of currernt room admin */
1107 r = CtdlIPCGetRoomAide(ipc, buf);
1109 safestrncpy(room_admin_name, buf, sizeof room_admin_name);
1111 strcpy(room_admin_name, "");
1113 if (!IsEmptyStr(room_admin_name))
1114 scr_printf("Room admin is %s.\n\n", room_admin_name);
1116 r = CtdlIPCRoomInfo(ipc, &text, buf);
1121 fmout(screenwidth, NULL, text, NULL, 1);
1128 * <W>ho knows room...
1130 void whoknows(CtdlIPC *ipc)
1133 char *listing = NULL;
1136 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1138 scr_printf("%s\n", buf);
1141 while (!IsEmptyStr(listing)) {
1142 extract_token(buf, listing, 0, '\n', sizeof buf);
1143 remove_token(listing, 0, '\n');
1145 scr_printf("%s\n", buf);
1151 void do_edit(CtdlIPC *ipc,
1152 char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
1156 int b, cksum, editor_exit;
1158 if (IsEmptyStr(editor_path)) {
1159 scr_printf("Do you wish to re-enter %s? ", desc);
1164 fp = fopen(temp, "w");
1167 CtdlIPC_chat_send(ipc, check_cmd);
1168 CtdlIPC_chat_recv(ipc, cmd);
1169 if (cmd[0] != '2') {
1170 scr_printf("%s\n", &cmd[4]);
1174 if (!IsEmptyStr(editor_path)) {
1175 CtdlIPC_chat_send(ipc, read_cmd);
1176 CtdlIPC_chat_recv(ipc, cmd);
1177 if (cmd[0] == '1') {
1178 fp = fopen(temp, "w");
1179 while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
1180 fprintf(fp, "%s\n", cmd);
1186 cksum = file_checksum(temp);
1188 if (!IsEmptyStr(editor_path)) {
1191 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1193 stty_ctdl(SB_RESTORE);
1194 editor_pid = fork();
1195 if (editor_pid == 0) {
1197 execlp(editor_path, editor_path, temp, NULL);
1203 b = ka_wait(&editor_exit);
1204 } while ((b != editor_pid) && (b >= 0));
1206 scr_printf("Executed %s\n", editor_path);
1209 scr_printf("Entering %s. Press return twice when finished.\n", desc);
1210 fp = fopen(temp, "r+");
1215 if (file_checksum(temp) == cksum) {
1216 scr_printf("*** Aborted.\n");
1220 CtdlIPC_chat_send(ipc, write_cmd);
1221 CtdlIPC_chat_recv(ipc, cmd);
1222 if (cmd[0] != '4') {
1223 scr_printf("%s\n", &cmd[4]);
1227 fp = fopen(temp, "r");
1228 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1229 cmd[strlen(cmd) - 1] = 0;
1230 CtdlIPC_chat_send(ipc, cmd);
1233 CtdlIPC_chat_send(ipc, "000");
1240 void enterinfo(CtdlIPC *ipc)
1241 { /* edit info file for current room */
1242 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1245 void enter_bio(CtdlIPC *ipc)
1248 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1249 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1253 * create a new floor
1255 void create_floor(CtdlIPC *ipc)
1258 char newfloorname[SIZ];
1259 int r; /* IPC response code */
1261 load_floorlist(ipc);
1263 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1264 if ( (r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE) ) {
1265 scr_printf("%s\n", buf);
1269 newprompt("Name for new floor: ", newfloorname, 255);
1270 if (!*newfloorname) return;
1271 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1273 scr_printf("Floor has been created.\n");
1275 scr_printf("%s\n", buf);
1278 load_floorlist(ipc);
1282 * edit the current floor
1284 void edit_floor(CtdlIPC *ipc)
1287 struct ExpirePolicy *ep = NULL;
1289 load_floorlist(ipc);
1291 /* Fetch the expire policy (this will silently fail on old servers,
1292 * resulting in "default" policy)
1294 CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1296 /* Interact with the user */
1297 scr_printf("You are editing the floor called \"%s\"\n",
1298 &floorlist[(int) curr_floor][0] );
1299 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1301 /* Angels and demons dancing in my head... */
1303 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1305 ("Floor default message expire policy (? for list)",
1307 if (buf[0] == '?') {
1309 "0. Use the system default\n"
1310 "1. Never automatically expire messages\n"
1311 "2. Expire by message count\n"
1312 "3. Expire by message age\n");
1314 } while ((buf[0] < '0') || (buf[0] > '3'));
1315 ep->expire_mode = buf[0] - '0';
1317 /* ...lunatics and monsters underneath my bed */
1318 if (ep->expire_mode == 2) {
1319 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1320 strprompt("Keep how many messages online?", buf, 10);
1321 ep->expire_value = atol(buf);
1324 if (ep->expire_mode == 3) {
1325 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1326 strprompt("Keep messages for how many days?", buf, 10);
1327 ep->expire_value = atol(buf);
1331 CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1332 CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf);
1333 scr_printf("%s\n", buf);
1334 load_floorlist(ipc);
1341 * kill the current floor
1343 void kill_floor(CtdlIPC *ipc)
1345 int floornum_to_delete, a;
1348 load_floorlist(ipc);
1350 floornum_to_delete = (-1);
1351 scr_printf("(Press return to abort)\n");
1352 newprompt("Delete which floor? ", buf, 255);
1353 if (IsEmptyStr(buf))
1355 for (a = 0; a < 128; ++a)
1356 if (!strcasecmp(&floorlist[a][0], buf))
1357 floornum_to_delete = a;
1358 if (floornum_to_delete < 0) {
1359 scr_printf("No such floor. Select one of:\n");
1360 for (a = 0; a < 128; ++a)
1361 if (floorlist[a][0] != 0)
1362 scr_printf("%s\n", &floorlist[a][0]);
1364 } while (floornum_to_delete < 0);
1365 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1366 scr_printf("%s\n", buf);
1367 load_floorlist(ipc);