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.
23 #include <sys/types.h>
28 #include <libcitadel.h>
29 #include "citadel_ipc.h"
30 #include "citadel_decls.h"
34 #include "tuiconfig.h"
37 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
40 void stty_ctdl(int cmd);
41 void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto);
42 void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax);
43 int pattern(char *search, char *patn);
44 int file_checksum(char *filename);
45 int nukedir(char *dirname);
47 extern unsigned room_flags;
48 extern char room_name[];
50 extern char tempdir[];
51 extern int editor_pid;
52 extern int screenwidth;
53 extern int screenheight;
54 extern char fullname[];
55 extern char sigcaught;
56 extern char floor_mode;
57 extern char curr_floor;
62 extern char *uglist[];
63 extern long uglistlsn[];
64 extern int uglistsize;
66 extern char floorlist[128][SIZ];
69 void load_floorlist(CtdlIPC *ipc)
74 int r; /* IPC response code */
76 for (a = 0; a < 128; ++a)
79 r = CtdlIPCFloorListing(ipc, &listing, buf);
81 strcpy(floorlist[0], "Main Floor");
84 while (*listing && !IsEmptyStr(listing)) {
85 extract_token(buf, listing, 0, '\n', sizeof buf);
86 remove_token(listing, 0, '\n');
87 extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', SIZ);
93 void room_tree_list(struct ctdlroomlisting *rp)
96 char rmname[ROOMNAMELEN];
104 if (rp->lnext != NULL) {
105 room_tree_list(rp->lnext);
108 if (sigcaught == 0) {
109 strcpy(rmname, rp->rlname);
111 if ((c + strlen(rmname) + 4) > screenwidth) {
113 /* line break, check the paginator */
117 if (f & QR_MAILBOX) {
118 color(BRIGHT_YELLOW);
119 } else if (f & QR_PRIVATE) {
124 scr_printf("%s", rmname);
125 if (f & QR_DIRECTORY) {
131 c = c + strlen(rmname) + 3;
134 if (rp->rnext != NULL) {
135 room_tree_list(rp->rnext);
143 * Room ordering stuff (compare first by floor, then by order)
145 int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2)
147 if ((r1 == NULL) && (r2 == NULL))
153 if (r1->rlfloor < r2->rlfloor)
155 if (r1->rlfloor > r2->rlfloor)
157 if (r1->rlorder < r2->rlorder)
159 if (r1->rlorder > r2->rlorder)
166 * Common code for all room listings
168 static void listrms(struct march *listing, int new_only, int floor_only, unsigned int flags, char *match)
171 struct ctdlroomlisting *rl = NULL;
172 struct ctdlroomlisting *rp;
173 struct ctdlroomlisting *rs;
176 for (mptr = listing; mptr != NULL; mptr = mptr->next) {
179 if ( (new_only == LISTRMS_NEW_ONLY)
180 && ((mptr->march_access & UA_HASNEWMSGS) == 0))
183 if ( (new_only == LISTRMS_OLD_ONLY)
184 && ((mptr->march_access & UA_HASNEWMSGS) != 0))
187 if ( (floor_only >= 0)
188 && (mptr->march_floor != floor_only))
191 if (flags && (mptr->march_flags & flags) == 0)
194 if (match && (pattern(mptr->march_name, match) == -1))
198 rp = malloc(sizeof(struct ctdlroomlisting));
199 strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
200 rp->rlflags = mptr->march_flags;
201 rp->rlfloor = mptr->march_floor;
202 rp->rlorder = mptr->march_order;
211 if (rordercmp(rp, rs) < 0) {
212 if (rs->lnext == NULL) {
219 if (rs->rnext == NULL) {
231 room_tree_list(NULL);
237 void list_other_floors(void)
242 for (a = 0; a < 128; ++a) {
243 if ((strlen(floorlist[a]) > 0) && (a != curr_floor)) {
244 if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
248 scr_printf("%s: ", floorlist[a]);
249 c = c + strlen(floorlist[a]) + 3;
256 * List known rooms. kn_floor_mode should be set to 0 for a 'flat' listing,
257 * 1 to list rooms on the current floor, or 2 to list rooms on all floors.
259 void knrooms(CtdlIPC *ipc, int kn_floor_mode)
262 struct march *listing = NULL;
264 int r; /* IPC response code */
268 /* Ask the server for a room list */
269 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
277 if (kn_floor_mode == 0) {
279 scr_printf("\n Rooms with unread messages:\n");
280 listrms(listing, LISTRMS_NEW_ONLY, -1, 0, NULL);
282 scr_printf("\n\n No unseen messages in:\n");
283 listrms(listing, LISTRMS_OLD_ONLY, -1, 0, NULL);
287 if (kn_floor_mode == 1) {
289 scr_printf("\n Rooms with unread messages on %s:\n",
290 floorlist[(int) curr_floor]);
291 listrms(listing, LISTRMS_NEW_ONLY, curr_floor, 0, NULL);
293 scr_printf("\n\n Rooms with no new messages on %s:\n",
294 floorlist[(int) curr_floor]);
295 listrms(listing, LISTRMS_OLD_ONLY, curr_floor, 0, NULL);
297 scr_printf("\n\n Other floors:\n");
302 if (kn_floor_mode == 2) {
303 for (a = 0; a < 128; ++a) {
304 if (floorlist[a][0] != 0) {
306 scr_printf("\n Rooms on %s:\n",
308 listrms(listing, LISTRMS_ALL, a, 0, NULL);
314 /* Free the room list */
316 mptr = listing->next;
325 void listzrooms(CtdlIPC *ipc)
326 { /* list public forgotten rooms */
327 struct march *listing = NULL;
329 int r; /* IPC response code */
333 /* Ask the server for a room list */
334 r = CtdlIPCKnownRooms(ipc, UnsubscribedRooms, (-1), &listing, buf);
340 scr_printf("\n Forgotten public rooms:\n");
341 listrms(listing, LISTRMS_ALL, -1, 0, NULL);
344 /* Free the room list */
346 mptr = listing->next;
354 void dotknown(CtdlIPC *ipc, int what, char *match)
355 { /* list rooms according to attribute */
356 struct march *listing = NULL;
358 int r; /* IPC response code */
361 /* Ask the server for a room list */
362 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, (-1), &listing, buf);
371 scr_printf("\n Anonymous rooms:\n");
372 listrms(listing, LISTRMS_ALL, -1, QR_ANONONLY|QR_ANONOPT, NULL);
376 scr_printf("\n Directory rooms:\n");
377 listrms(listing, LISTRMS_ALL, -1, QR_DIRECTORY, NULL);
381 scr_printf("\n Matching \"%s\" rooms:\n", match);
382 listrms(listing, LISTRMS_ALL, -1, 0, match);
386 scr_printf("\n Preferred only rooms:\n");
387 listrms(listing, LISTRMS_ALL, -1, QR_PREFONLY, NULL);
391 scr_printf("\n Private rooms:\n");
392 listrms(listing, LISTRMS_ALL, -1, QR_PRIVATE, NULL);
396 scr_printf("\n Read only rooms:\n");
397 listrms(listing, LISTRMS_ALL, -1, QR_READONLY, NULL);
402 /* Free the room list */
404 mptr = listing->next;
413 int set_room_attr(CtdlIPC *ipc, unsigned int ibuf, char *prompt, unsigned int sbit)
417 a = boolprompt(prompt, (ibuf & sbit));
418 ibuf = (ibuf | sbit);
420 ibuf = (ibuf ^ sbit);
428 * Select a floor (used in several commands)
429 * The supplied argument is the 'default' floor number.
430 * This function returns the selected floor number.
432 int select_floor(CtdlIPC *ipc, int rfloor)
437 if (floor_mode == 1) {
438 if (floorlist[(int) curr_floor][0] == 0) {
444 safestrncpy(floorstr, floorlist[rfloor],
446 strprompt("Which floor", floorstr, 255);
447 for (a = 0; a < 128; ++a) {
449 (floorstr, &floorlist[a][0]))
454 (floorstr, &floorlist[a][0],
458 && (pattern(&floorlist[a][0], floorstr)
463 scr_printf("\n One of:\n");
464 for (a = 0; a < 128; ++a) {
465 if (floorlist[a][0] != 0) {
471 } while (newfloor < 0);
476 scr_printf("Floor selection bypassed because you have "
477 "floor mode disabled.\n");
487 * .<A>ide <E>dit room
489 void editthisroom(CtdlIPC *ipc)
492 char room_admin_name[USERNAME_SIZE];
494 struct ctdlroom *attr = NULL;
495 struct ExpirePolicy *eptr = NULL;
496 int r; /* IPC response code */
498 /* Fetch the existing room config */
499 r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
501 scr_printf("%s\n", buf);
504 eptr = &(attr->QRep);
506 /* Fetch the name of the current room admin */
507 r = CtdlIPCGetRoomAide(ipc, buf);
509 safestrncpy(room_admin_name, buf, sizeof room_admin_name);
511 strcpy(room_admin_name, "");
513 if (IsEmptyStr(room_admin_name)) {
514 strcpy(room_admin_name, "none");
517 /* Fetch the expire policy (this will silently fail on old servers,
518 * resulting in "default" policy)
520 r = CtdlIPCGetMessageExpirationPolicy(ipc, 0, &eptr, buf);
522 /* Now interact with the user. */
524 strprompt("Room name", attr->QRname, ROOMNAMELEN-1);
525 attr->QRfloor = select_floor(ipc, attr->QRfloor);
526 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
527 if (attr->QRflags & QR_PRIVATE) {
528 attr->QRflags = set_room_attr(ipc, attr->QRflags,
529 "Hidden room (accessible to anyone who knows the room name)",
533 /* if it's public, clear the privacy classes */
534 if ((attr->QRflags & QR_PRIVATE) == 0) {
535 if (attr->QRflags & QR_GUESSNAME) {
536 attr->QRflags = attr->QRflags - QR_GUESSNAME;
538 if (attr->QRflags & QR_PASSWORDED) {
539 attr->QRflags = attr->QRflags - QR_PASSWORDED;
543 /* if it's private, choose the privacy classes */
544 if ((attr->QRflags & QR_PRIVATE)
545 && ((attr->QRflags & QR_GUESSNAME) == 0)) {
546 attr->QRflags = set_room_attr(ipc, attr->QRflags,
547 "Accessible by entering a password",
550 if ((attr->QRflags & QR_PRIVATE)
551 && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
552 strprompt("Room password", attr->QRpasswd, 9);
555 if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
556 rbump = boolprompt("Cause current users to forget room", 0);
559 attr->QRflags = set_room_attr(ipc, attr->QRflags,
560 "Preferred users only", QR_PREFONLY);
561 attr->QRflags = set_room_attr(ipc, attr->QRflags,
562 "Read-only room", QR_READONLY);
563 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
564 "Allow message deletion by anyone who can post",
566 attr->QRflags = set_room_attr(ipc, attr->QRflags,
567 "Permanent room", QR_PERMANENT);
568 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
569 "Subject Required (Force "
570 "users to specify a message "
571 "subject)", QR2_SUBJECTREQ);
572 attr->QRflags = set_room_attr(ipc, attr->QRflags,
573 "Directory room", QR_DIRECTORY);
574 if (attr->QRflags & QR_DIRECTORY) {
575 strprompt("Directory name", attr->QRdirname, 14);
577 set_room_attr(ipc, attr->QRflags,
578 "Uploading allowed", QR_UPLOAD);
580 set_room_attr(ipc, attr->QRflags, "Downloading allowed",
583 set_room_attr(ipc, attr->QRflags,
584 "Visible directory", QR_VISDIR);
586 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
587 "Self-service list subscribe/unsubscribe",
589 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
590 "public posting to this room via room_roomname@yourcitadel.org",
592 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
593 "moderated mailinglist",
595 attr->QRflags = set_room_attr(ipc, attr->QRflags,
596 "Automatically make all messages anonymous",
598 if ((attr->QRflags & QR_ANONONLY) == 0) {
599 attr->QRflags = set_room_attr(ipc, attr->QRflags,
600 "Ask users whether to make messages anonymous",
603 attr->QRorder = intprompt("Listing order", attr->QRorder, 0, 127);
605 /* Ask about the room admin */
607 strprompt("Room admin (or 'none')", room_admin_name, 29);
608 if (!strcasecmp(room_admin_name, "none")) {
609 strcpy(room_admin_name, "");
612 r = CtdlIPCQueryUsername(ipc, room_admin_name, buf);
614 scr_printf("%s\n", buf);
616 } while (r / 100 != 2);
618 /* Angels and demons dancing in my head... */
620 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
621 strprompt("Message expire policy (? for list)", buf, 1);
624 "0. Use the default for this floor\n"
625 "1. Never automatically expire messages\n"
626 "2. Expire by message count\n"
627 "3. Expire by message age\n");
629 } while ((buf[0] < 48) || (buf[0] > 51));
630 attr->QRep.expire_mode = buf[0] - 48;
632 /* ...lunatics and monsters underneath my bed */
633 if (attr->QRep.expire_mode == 2) {
634 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
635 strprompt("Keep how many messages online?", buf, 10);
636 attr->QRep.expire_value = atol(buf);
639 if (attr->QRep.expire_mode == 3) {
640 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
641 strprompt("Keep messages for how many days?", buf, 10);
642 attr->QRep.expire_value = atol(buf);
645 /* Give 'em a chance to change their minds */
646 scr_printf("Save changes (y/n)? ");
649 r = CtdlIPCSetRoomAide(ipc, room_admin_name, buf);
651 scr_printf("%s\n", buf);
654 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
656 scr_printf("%s\n", buf);
659 r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
660 scr_printf("%s\n", buf);
661 strncpy(buf, attr->QRname, ROOMNAMELEN);
664 dotgoto(ipc, buf, 2, 0);
671 * un-goto the previous room, or a specified room
673 void dotungoto(CtdlIPC *ipc, char *towhere)
675 /* Find this 'towhere' room in the list ungoto from this room to
676 that at the messagepointer position in that room in our ungoto list.
677 I suppose I could be a real dick and just ungoto that many places
682 struct ctdlipcroom *rret = NULL; /* ignored */
687 scr_printf("No rooms to ungoto.\n");
692 scr_printf("Must specify a room to ungoto.\n");
695 if (IsEmptyStr(towhere))
697 scr_printf("Must specify a room to ungoto.\n");
700 for (lp = uglistsize-1; lp >= 0; lp--)
702 if (strcasecmp(towhere, uglist[lp]) == 0)
710 scr_printf("Room: %s not in ungoto list.\n", towhere);
714 r = CtdlIPCGotoRoom(ipc, uglist[found], "", &rret, buf);
715 if (rret) free(rret); /* ignored */
717 scr_printf("%s\n", buf);
720 r = CtdlIPCSetLastRead(ipc, uglistlsn[found] ? uglistlsn[found] : 1, buf);
722 scr_printf("%s\n", buf);
724 safestrncpy(buf, uglist[found], sizeof(buf));
725 /* we queue ungoto information here, because we're not really
726 ungotoing, we're really going to a random spot in some arbitrary
728 dotgoto(ipc, buf, 0, 0);
731 void ungoto(CtdlIPC *ipc)
734 struct ctdlipcroom *rret = NULL; /* ignored */
740 r = CtdlIPCGotoRoom(ipc, uglist[uglistsize-1], "", &rret, buf);
741 if (rret) free(rret); /* ignored */
743 scr_printf("%s\n", buf);
746 r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize-1] ? uglistlsn[uglistsize-1] : 1, buf);
748 scr_printf("%s\n", buf);
750 safestrncpy(buf, uglist[uglistsize-1], sizeof(buf));
752 free(uglist[uglistsize]);
753 /* Don't queue ungoto info or we end up in a loop */
754 dotgoto(ipc, buf, 0, 1);
759 * saves filelen bytes from file at pathname
761 int save_buffer(void *file, size_t filelen, const char *pathname)
764 size_t bytes_written = 0;
767 fp = fopen(pathname, "w");
769 scr_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
773 block = fwrite((char *)file + bytes_written, 1,
774 filelen - bytes_written, fp);
775 bytes_written += block;
776 } while (errno == EINTR && bytes_written < filelen);
779 if (bytes_written < filelen) {
780 scr_printf("Trouble saving '%s': %s\n", pathname,
789 * Save supplied_filename in dest directory; gets the name only
791 void destination_directory(char *dest, const char *supplied_filename)
793 static char save_dir[SIZ] = { 0 };
795 if (IsEmptyStr(save_dir)) {
796 if (getenv("HOME") == NULL) {
797 strcpy(save_dir, ".");
800 sprintf(save_dir, "%s/Desktop", getenv("HOME"));
801 if (access(save_dir, W_OK) != 0) {
802 sprintf(save_dir, "%s", getenv("HOME"));
803 if (access(save_dir, W_OK) != 0) {
804 sprintf(save_dir, ".");
810 sprintf(dest, "%s/%s", save_dir, supplied_filename);
811 strprompt("Save as", dest, PATH_MAX);
813 /* Remember the directory for next time */
814 strcpy(save_dir, dest);
815 if (strrchr(save_dir, '/') != NULL) {
816 strcpy(strrchr(save_dir, '/'), "");
819 strcpy(save_dir, ".");
825 * download() - download a file or files. The argument passed to this
826 * function determines which protocol to use.
827 * proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
829 void download(CtdlIPC *ipc, int proto)
832 char filename[PATH_MAX];
833 char tempname[PATH_MAX];
834 char transmit_cmd[SIZ];
839 void *file = NULL; /* The downloaded file */
840 size_t filelen = 0L; /* The downloaded file length */
842 if ((room_flags & QR_DOWNLOAD) == 0) {
843 scr_printf("*** You cannot download from this room.\n");
847 newprompt("Enter filename: ", filename, PATH_MAX);
849 /* Save to local disk, for folks with their own copy of the client */
851 destination_directory(tempname, filename);
852 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
854 scr_printf("%s\n", buf);
857 save_buffer(file, (size_t)extract_long(buf, 0), tempname);
862 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
864 scr_printf("%s\n", buf);
867 filelen = extract_unsigned_long(buf, 0);
869 /* Meta-download for public clients */
870 /* scr_printf("Fetching file from Citadel server...\n"); */
871 mkdir(tempdir, 0700);
872 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
873 tpipe = fopen(tempname, "wb");
874 if (fwrite(file, filelen, 1, tpipe) < filelen) {
875 /* FIXME: restart syscall on EINTR
879 if (file) free(file);
882 /* FIXME: display internally instead */
883 snprintf(transmit_cmd, sizeof transmit_cmd,
884 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",
888 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
890 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
892 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
894 /* FIXME: display internally instead */
895 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
897 stty_ctdl(SB_RESTORE);
898 rv = system(transmit_cmd);
900 scr_printf("failed to download '%s': %d\n", transmit_cmd, rv);
901 stty_ctdl(SB_NO_INTR);
903 /* clean up the temporary directory */
905 ctdl_beep(); /* Beep beep! */
910 * read directory of this room
912 void roomdir(CtdlIPC *ipc)
919 char *listing = NULL; /* Returned directory listing */
922 r = CtdlIPCReadDirectory(ipc, &listing, buf);
924 scr_printf("%s\n", buf);
928 extract_token(comment, buf, 0, '|', sizeof comment);
929 extract_token(flnm, buf, 1, '|', sizeof flnm);
930 scr_printf("\nDirectory of %s on %s\n", flnm, comment);
931 scr_printf("-----------------------\n");
932 while (listing && *listing && !IsEmptyStr(listing)) {
933 extract_token(buf, listing, 0, '\n', sizeof buf);
934 remove_token(listing, 0, '\n');
936 extract_token(flnm, buf, 0, '|', sizeof flnm);
937 extract_token(flsz, buf, 1, '|', sizeof flsz);
938 extract_token(mimetype, buf, 2, '|', sizeof mimetype);
939 extract_token(comment, buf, 3, '|', sizeof comment);
940 if (strlen(flnm) <= 14)
941 scr_printf("%-14s %8s %s [%s]\n", flnm, flsz, comment, mimetype);
943 scr_printf("%s\n%14s %8s %s [%s]\n", flnm, "", flsz,
946 if (listing) free(listing);
951 * add a user to a private room
953 void invite(CtdlIPC *ipc)
955 char username[USERNAME_SIZE];
958 newprompt("Name of user? ", username, USERNAME_SIZE);
959 if (username[0] == 0)
962 CtdlIPCInviteUserToRoom(ipc, username, buf);
963 scr_printf("%s\n", buf);
968 * kick a user out of a room
970 void kickout(CtdlIPC *ipc)
972 char username[USERNAME_SIZE];
975 newprompt("Name of user? ", username, USERNAME_SIZE);
976 if (username[0] == 0)
979 CtdlIPCKickoutUserFromRoom(ipc, username, buf);
980 scr_printf("%s\n", buf);
985 * aide command: kill the current room
987 void killroom(CtdlIPC *ipc)
992 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
994 scr_printf("%s\n", aaa);
998 scr_printf("Are you sure you want to kill this room? ");
1002 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
1003 scr_printf("%s\n", aaa);
1006 dotgoto(ipc, "_BASEROOM_", 0, 0);
1009 void forget(CtdlIPC *ipc)
1010 { /* forget the current room */
1013 scr_printf("Are you sure you want to forget this room? ");
1017 remove_march(room_name, 0);
1018 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
1019 scr_printf("%s\n", buf);
1023 /* now return to the lobby */
1024 dotgoto(ipc, "_BASEROOM_", 0, 0);
1031 void entroom(CtdlIPC *ipc)
1034 char new_room_name[ROOMNAMELEN];
1036 char new_room_pass[10];
1039 int r; /* IPC response code */
1041 /* Check permission to create room */
1042 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
1044 scr_printf("%s\n", buf);
1048 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
1049 if (IsEmptyStr(new_room_name)) {
1052 for (a = 0; !IsEmptyStr(&new_room_name[a]); ++a) {
1053 if (new_room_name[a] == '|') {
1054 new_room_name[a] = '_';
1058 new_room_floor = select_floor(ipc, (int) curr_floor);
1060 IFNEXPERT formout(ipc, "roomaccess");
1062 scr_printf("<?>Help\n"
1063 "<1>Public room (shown to all users by default)\n"
1064 "<2>Hidden room (accessible to anyone who knows the room name)\n"
1065 "<3>Passworded room (hidden, plus requires a password to enter)\n"
1066 "<4>Invitation-only room (requires access to be granted by an Admin)\n"
1067 "<5>Personal room (accessible to you only)\n"
1072 } while (((b < '1') || (b > '5')) && (b != '?'));
1075 formout(ipc, "roomaccess");
1077 } while ((b < '1') || (b > '5'));
1078 b -= '0'; /* Portable */
1079 scr_printf("%d\n", b);
1080 new_room_type = b - 1;
1081 if (new_room_type == 2) {
1082 newprompt("Enter a room password: ", new_room_pass, 9);
1083 for (a = 0; !IsEmptyStr(&new_room_pass[a]); ++a)
1084 if (new_room_pass[a] == '|')
1085 new_room_pass[a] = '_';
1087 strcpy(new_room_pass, "");
1090 scr_printf("\042%s\042, a", new_room_name);
1092 scr_printf(" public room.");
1094 scr_printf(" hidden room.");
1096 scr_printf(" passworded room, password: %s", new_room_pass);
1098 scr_printf("n invitation-only room.");
1100 scr_printf(" personal room.");
1101 scr_printf("\nInstall it? (y/n) : ");
1106 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type,
1107 new_room_pass, new_room_floor, buf);
1109 scr_printf("%s\n", buf);
1113 /* command succeeded... now GO to the new room! */
1114 dotgoto(ipc, new_room_name, 0, 0);
1119 void readinfo(CtdlIPC *ipc)
1120 { /* read info file for current room */
1122 char room_admin_name[64];
1123 int r; /* IPC response code */
1126 /* Name of currernt room admin */
1127 r = CtdlIPCGetRoomAide(ipc, buf);
1129 safestrncpy(room_admin_name, buf, sizeof room_admin_name);
1131 strcpy(room_admin_name, "");
1133 if (!IsEmptyStr(room_admin_name))
1134 scr_printf("Room admin is %s.\n\n", room_admin_name);
1136 r = CtdlIPCRoomInfo(ipc, &text, buf);
1141 fmout(screenwidth, NULL, text, NULL, 1);
1148 * <W>ho knows room...
1150 void whoknows(CtdlIPC *ipc)
1153 char *listing = NULL;
1156 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1158 scr_printf("%s\n", buf);
1161 while (!IsEmptyStr(listing)) {
1162 extract_token(buf, listing, 0, '\n', sizeof buf);
1163 remove_token(listing, 0, '\n');
1165 scr_printf("%s\n", buf);
1171 void do_edit(CtdlIPC *ipc,
1172 char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
1176 int b, cksum, editor_exit;
1178 if (IsEmptyStr(editor_path)) {
1179 scr_printf("Do you wish to re-enter %s? ", desc);
1184 fp = fopen(temp, "w");
1187 CtdlIPC_chat_send(ipc, check_cmd);
1188 CtdlIPC_chat_recv(ipc, cmd);
1189 if (cmd[0] != '2') {
1190 scr_printf("%s\n", &cmd[4]);
1194 if (!IsEmptyStr(editor_path)) {
1195 CtdlIPC_chat_send(ipc, read_cmd);
1196 CtdlIPC_chat_recv(ipc, cmd);
1197 if (cmd[0] == '1') {
1198 fp = fopen(temp, "w");
1199 while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
1200 fprintf(fp, "%s\n", cmd);
1206 cksum = file_checksum(temp);
1208 if (!IsEmptyStr(editor_path)) {
1211 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1213 stty_ctdl(SB_RESTORE);
1214 editor_pid = fork();
1215 if (editor_pid == 0) {
1217 execlp(editor_path, editor_path, temp, NULL);
1223 b = ka_wait(&editor_exit);
1224 } while ((b != editor_pid) && (b >= 0));
1226 scr_printf("Executed %s\n", editor_path);
1229 scr_printf("Entering %s. Press return twice when finished.\n", desc);
1230 fp = fopen(temp, "r+");
1235 if (file_checksum(temp) == cksum) {
1236 scr_printf("*** Aborted.\n");
1240 CtdlIPC_chat_send(ipc, write_cmd);
1241 CtdlIPC_chat_recv(ipc, cmd);
1242 if (cmd[0] != '4') {
1243 scr_printf("%s\n", &cmd[4]);
1247 fp = fopen(temp, "r");
1248 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1249 cmd[strlen(cmd) - 1] = 0;
1250 CtdlIPC_chat_send(ipc, cmd);
1253 CtdlIPC_chat_send(ipc, "000");
1260 void enterinfo(CtdlIPC *ipc)
1261 { /* edit info file for current room */
1262 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1265 void enter_bio(CtdlIPC *ipc)
1268 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1269 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1273 * create a new floor
1275 void create_floor(CtdlIPC *ipc)
1278 char newfloorname[SIZ];
1279 int r; /* IPC response code */
1281 load_floorlist(ipc);
1283 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1284 if ( (r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE) ) {
1285 scr_printf("%s\n", buf);
1289 newprompt("Name for new floor: ", newfloorname, 255);
1290 if (!*newfloorname) return;
1291 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1293 scr_printf("Floor has been created.\n");
1295 scr_printf("%s\n", buf);
1298 load_floorlist(ipc);
1302 * edit the current floor
1304 void edit_floor(CtdlIPC *ipc)
1307 struct ExpirePolicy *ep = NULL;
1309 load_floorlist(ipc);
1311 /* Fetch the expire policy (this will silently fail on old servers,
1312 * resulting in "default" policy)
1314 CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1316 /* Interact with the user */
1317 scr_printf("You are editing the floor called \"%s\"\n",
1318 &floorlist[(int) curr_floor][0] );
1319 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1321 /* Angels and demons dancing in my head... */
1323 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1325 ("Floor default message expire policy (? for list)",
1327 if (buf[0] == '?') {
1329 "0. Use the system default\n"
1330 "1. Never automatically expire messages\n"
1331 "2. Expire by message count\n"
1332 "3. Expire by message age\n");
1334 } while ((buf[0] < '0') || (buf[0] > '3'));
1335 ep->expire_mode = buf[0] - '0';
1337 /* ...lunatics and monsters underneath my bed */
1338 if (ep->expire_mode == 2) {
1339 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1340 strprompt("Keep how many messages online?", buf, 10);
1341 ep->expire_value = atol(buf);
1344 if (ep->expire_mode == 3) {
1345 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1346 strprompt("Keep messages for how many days?", buf, 10);
1347 ep->expire_value = atol(buf);
1351 CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1352 CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf);
1353 scr_printf("%s\n", buf);
1354 load_floorlist(ipc);
1361 * kill the current floor
1363 void kill_floor(CtdlIPC *ipc)
1365 int floornum_to_delete, a;
1368 load_floorlist(ipc);
1370 floornum_to_delete = (-1);
1371 scr_printf("(Press return to abort)\n");
1372 newprompt("Delete which floor? ", buf, 255);
1373 if (IsEmptyStr(buf))
1375 for (a = 0; a < 128; ++a)
1376 if (!strcasecmp(&floorlist[a][0], buf))
1377 floornum_to_delete = a;
1378 if (floornum_to_delete < 0) {
1379 scr_printf("No such floor. Select one of:\n");
1380 for (a = 0; a < 128; ++a)
1381 if (floorlist[a][0] != 0)
1382 scr_printf("%s\n", &floorlist[a][0]);
1384 } while (floornum_to_delete < 0);
1385 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1386 scr_printf("%s\n", buf);
1387 load_floorlist(ipc);