2 * Client-side functions which perform room operations
4 * Copyright (c) 1987-2012 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>
30 #include "citadel_ipc.h"
31 #include "citadel_decls.h"
35 #include "tuiconfig.h"
40 #include "citadel_dirs.h"
42 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
45 void stty_ctdl(int cmd);
46 void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto);
47 void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax);
48 int pattern(char *search, char *patn);
49 int file_checksum(char *filename);
50 int nukedir(char *dirname);
52 extern unsigned room_flags;
53 extern char room_name[];
55 extern char tempdir[];
56 extern int editor_pid;
57 extern int screenwidth;
58 extern int screenheight;
59 extern char fullname[];
60 extern char sigcaught;
61 extern char floor_mode;
62 extern char curr_floor;
67 extern char *uglist[];
68 extern long uglistlsn[];
69 extern int uglistsize;
71 extern char floorlist[128][SIZ];
74 void load_floorlist(CtdlIPC *ipc)
79 int r; /* IPC response code */
81 for (a = 0; a < 128; ++a)
84 r = CtdlIPCFloorListing(ipc, &listing, buf);
86 strcpy(floorlist[0], "Main Floor");
89 while (*listing && !IsEmptyStr(listing)) {
90 extract_token(buf, listing, 0, '\n', sizeof buf);
91 remove_token(listing, 0, '\n');
92 extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', SIZ);
98 void room_tree_list(struct ctdlroomlisting *rp)
101 char rmname[ROOMNAMELEN];
109 if (rp->lnext != NULL) {
110 room_tree_list(rp->lnext);
113 if (sigcaught == 0) {
114 strcpy(rmname, rp->rlname);
116 if ((c + strlen(rmname) + 4) > screenwidth) {
118 /* line break, check the paginator */
122 if (f & QR_MAILBOX) {
123 color(BRIGHT_YELLOW);
124 } else if (f & QR_PRIVATE) {
129 scr_printf("%s", rmname);
130 if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
132 else if (f & QR_DIRECTORY)
134 else if (f & QR_NETWORK)
138 c = c + strlen(rmname) + 3;
141 if (rp->rnext != NULL) {
142 room_tree_list(rp->rnext);
150 * Room ordering stuff (compare first by floor, then by order)
152 int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2)
154 if ((r1 == NULL) && (r2 == NULL))
160 if (r1->rlfloor < r2->rlfloor)
162 if (r1->rlfloor > r2->rlfloor)
164 if (r1->rlorder < r2->rlorder)
166 if (r1->rlorder > r2->rlorder)
173 * Common code for all room listings
175 static void listrms(struct march *listing, int new_only, int floor_only, unsigned int flags, char *match)
178 struct ctdlroomlisting *rl = NULL;
179 struct ctdlroomlisting *rp;
180 struct ctdlroomlisting *rs;
183 for (mptr = listing; mptr != NULL; mptr = mptr->next) {
186 if ( (new_only == LISTRMS_NEW_ONLY)
187 && ((mptr->march_access & UA_HASNEWMSGS) == 0))
190 if ( (new_only == LISTRMS_OLD_ONLY)
191 && ((mptr->march_access & UA_HASNEWMSGS) != 0))
194 if ( (floor_only >= 0)
195 && (mptr->march_floor != floor_only))
198 if (flags && (mptr->march_flags & flags) == 0)
201 if (match && (pattern(mptr->march_name, match) == -1))
205 rp = malloc(sizeof(struct ctdlroomlisting));
206 strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
207 rp->rlflags = mptr->march_flags;
208 rp->rlfloor = mptr->march_floor;
209 rp->rlorder = mptr->march_order;
218 if (rordercmp(rp, rs) < 0) {
219 if (rs->lnext == NULL) {
226 if (rs->rnext == NULL) {
238 room_tree_list(NULL);
244 void list_other_floors(void)
249 for (a = 0; a < 128; ++a) {
250 if ((strlen(floorlist[a]) > 0) && (a != curr_floor)) {
251 if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
255 scr_printf("%s: ", floorlist[a]);
256 c = c + strlen(floorlist[a]) + 3;
263 * List known rooms. kn_floor_mode should be set to 0 for a 'flat' listing,
264 * 1 to list rooms on the current floor, or 2 to list rooms on all floors.
266 void knrooms(CtdlIPC *ipc, int kn_floor_mode)
269 struct march *listing = NULL;
271 int r; /* IPC response code */
275 /* Ask the server for a room list */
276 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
284 if (kn_floor_mode == 0) {
286 scr_printf("\n Rooms with unread messages:\n");
287 listrms(listing, LISTRMS_NEW_ONLY, -1, 0, NULL);
289 scr_printf("\n\n No unseen messages in:\n");
290 listrms(listing, LISTRMS_OLD_ONLY, -1, 0, NULL);
294 if (kn_floor_mode == 1) {
296 scr_printf("\n Rooms with unread messages on %s:\n",
297 floorlist[(int) curr_floor]);
298 listrms(listing, LISTRMS_NEW_ONLY, curr_floor, 0, NULL);
300 scr_printf("\n\n Rooms with no new messages on %s:\n",
301 floorlist[(int) curr_floor]);
302 listrms(listing, LISTRMS_OLD_ONLY, curr_floor, 0, NULL);
304 scr_printf("\n\n Other floors:\n");
309 if (kn_floor_mode == 2) {
310 for (a = 0; a < 128; ++a) {
311 if (floorlist[a][0] != 0) {
313 scr_printf("\n Rooms on %s:\n",
315 listrms(listing, LISTRMS_ALL, a, 0, NULL);
321 /* Free the room list */
323 mptr = listing->next;
332 void listzrooms(CtdlIPC *ipc)
333 { /* list public forgotten rooms */
334 struct march *listing = NULL;
336 int r; /* IPC response code */
340 /* Ask the server for a room list */
341 r = CtdlIPCKnownRooms(ipc, UnsubscribedRooms, (-1), &listing, buf);
347 scr_printf("\n Forgotten public rooms:\n");
348 listrms(listing, LISTRMS_ALL, -1, 0, NULL);
351 /* Free the room list */
353 mptr = listing->next;
361 void dotknown(CtdlIPC *ipc, int what, char *match)
362 { /* list rooms according to attribute */
363 struct march *listing = NULL;
365 int r; /* IPC response code */
368 /* Ask the server for a room list */
369 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, (-1), &listing, buf);
378 scr_printf("\n Anonymous rooms:\n");
379 listrms(listing, LISTRMS_ALL, -1, QR_ANONONLY|QR_ANONOPT, NULL);
383 scr_printf("\n Directory rooms:\n");
384 listrms(listing, LISTRMS_ALL, -1, QR_DIRECTORY, NULL);
388 scr_printf("\n Matching \"%s\" rooms:\n", match);
389 listrms(listing, LISTRMS_ALL, -1, 0, match);
393 scr_printf("\n Preferred only rooms:\n");
394 listrms(listing, LISTRMS_ALL, -1, QR_PREFONLY, NULL);
398 scr_printf("\n Private rooms:\n");
399 listrms(listing, LISTRMS_ALL, -1, QR_PRIVATE, NULL);
403 scr_printf("\n Read only rooms:\n");
404 listrms(listing, LISTRMS_ALL, -1, QR_READONLY, NULL);
408 scr_printf("\n Shared rooms:\n");
409 listrms(listing, LISTRMS_ALL, -1, QR_NETWORK, NULL);
414 /* Free the room list */
416 mptr = listing->next;
425 int set_room_attr(CtdlIPC *ipc, unsigned int ibuf, char *prompt, unsigned int sbit)
429 a = boolprompt(prompt, (ibuf & sbit));
430 ibuf = (ibuf | sbit);
432 ibuf = (ibuf ^ sbit);
440 * Select a floor (used in several commands)
441 * The supplied argument is the 'default' floor number.
442 * This function returns the selected floor number.
444 int select_floor(CtdlIPC *ipc, int rfloor)
449 if (floor_mode == 1) {
450 if (floorlist[(int) curr_floor][0] == 0) {
456 safestrncpy(floorstr, floorlist[rfloor],
458 strprompt("Which floor", floorstr, 255);
459 for (a = 0; a < 128; ++a) {
461 (floorstr, &floorlist[a][0]))
466 (floorstr, &floorlist[a][0],
470 && (pattern(&floorlist[a][0], floorstr)
475 scr_printf("\n One of:\n");
476 for (a = 0; a < 128; ++a) {
477 if (floorlist[a][0] != 0) {
483 } while (newfloor < 0);
488 scr_printf("Floor selection bypassed because you have "
489 "floor mode disabled.\n");
499 * .<A>ide <E>dit room
501 void editthisroom(CtdlIPC *ipc)
504 char raide[USERNAME_SIZE];
506 struct ctdlroom *attr = NULL;
507 struct ExpirePolicy *eptr = NULL;
508 int r; /* IPC response code */
510 /* Fetch the existing room config */
511 r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
513 scr_printf("%s\n", buf);
516 eptr = &(attr->QRep);
518 /* Fetch the name of the current room aide */
519 r = CtdlIPCGetRoomAide(ipc, buf);
521 safestrncpy(raide, buf, sizeof raide);
525 if (IsEmptyStr(raide)) {
526 strcpy(raide, "none");
529 /* Fetch the expire policy (this will silently fail on old servers,
530 * resulting in "default" policy)
532 r = CtdlIPCGetMessageExpirationPolicy(ipc, 0, &eptr, buf);
534 /* Now interact with the user. */
536 strprompt("Room name", attr->QRname, ROOMNAMELEN-1);
537 attr->QRfloor = select_floor(ipc, attr->QRfloor);
538 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
539 if (attr->QRflags & QR_PRIVATE) {
540 attr->QRflags = set_room_attr(ipc, attr->QRflags,
541 "Hidden room (accessible to anyone who knows the room name)",
545 /* if it's public, clear the privacy classes */
546 if ((attr->QRflags & QR_PRIVATE) == 0) {
547 if (attr->QRflags & QR_GUESSNAME) {
548 attr->QRflags = attr->QRflags - QR_GUESSNAME;
550 if (attr->QRflags & QR_PASSWORDED) {
551 attr->QRflags = attr->QRflags - QR_PASSWORDED;
555 /* if it's private, choose the privacy classes */
556 if ((attr->QRflags & QR_PRIVATE)
557 && ((attr->QRflags & QR_GUESSNAME) == 0)) {
558 attr->QRflags = set_room_attr(ipc, attr->QRflags,
559 "Accessible by entering a password",
562 if ((attr->QRflags & QR_PRIVATE)
563 && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
564 strprompt("Room password", attr->QRpasswd, 9);
567 if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
568 rbump = boolprompt("Cause current users to forget room", 0);
571 attr->QRflags = set_room_attr(ipc, attr->QRflags,
572 "Preferred users only", QR_PREFONLY);
573 attr->QRflags = set_room_attr(ipc, attr->QRflags,
574 "Read-only room", QR_READONLY);
575 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
576 "Allow message deletion by anyone who can post",
578 attr->QRflags = set_room_attr(ipc, attr->QRflags,
579 "Permanent room", QR_PERMANENT);
580 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
581 "Subject Required (Force "
582 "users to specify a message "
583 "subject)", QR2_SUBJECTREQ);
584 attr->QRflags = set_room_attr(ipc, attr->QRflags,
585 "Directory room", QR_DIRECTORY);
586 if (attr->QRflags & QR_DIRECTORY) {
587 strprompt("Directory name", attr->QRdirname, 14);
589 set_room_attr(ipc, attr->QRflags,
590 "Uploading allowed", QR_UPLOAD);
592 set_room_attr(ipc, attr->QRflags, "Downloading allowed",
595 set_room_attr(ipc, attr->QRflags,
596 "Visible directory", QR_VISDIR);
598 attr->QRflags = set_room_attr(ipc, attr->QRflags,
599 "Network shared room", QR_NETWORK);
600 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
601 "Self-service list subscribe/unsubscribe",
603 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
604 "public posting to this room via room_roomname@yourcitadel.org",
606 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
607 "moderated mailinglist",
609 attr->QRflags = set_room_attr(ipc, attr->QRflags,
610 "Automatically make all messages anonymous",
612 if ((attr->QRflags & QR_ANONONLY) == 0) {
613 attr->QRflags = set_room_attr(ipc, attr->QRflags,
614 "Ask users whether to make messages anonymous",
617 attr->QRorder = intprompt("Listing order", attr->QRorder, 0, 127);
619 /* Ask about the room aide */
621 strprompt("Room aide (or 'none')", raide, 29);
622 if (!strcasecmp(raide, "none")) {
626 r = CtdlIPCQueryUsername(ipc, raide, buf);
628 scr_printf("%s\n", buf);
630 } while (r / 100 != 2);
632 /* Angels and demons dancing in my head... */
634 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
635 strprompt("Message expire policy (? for list)", buf, 1);
638 "0. Use the default for this floor\n"
639 "1. Never automatically expire messages\n"
640 "2. Expire by message count\n"
641 "3. Expire by message age\n");
643 } while ((buf[0] < 48) || (buf[0] > 51));
644 attr->QRep.expire_mode = buf[0] - 48;
646 /* ...lunatics and monsters underneath my bed */
647 if (attr->QRep.expire_mode == 2) {
648 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
649 strprompt("Keep how many messages online?", buf, 10);
650 attr->QRep.expire_value = atol(buf);
653 if (attr->QRep.expire_mode == 3) {
654 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
655 strprompt("Keep messages for how many days?", buf, 10);
656 attr->QRep.expire_value = atol(buf);
659 /* Give 'em a chance to change their minds */
660 scr_printf("Save changes (y/n)? ");
663 r = CtdlIPCSetRoomAide(ipc, raide, buf);
665 scr_printf("%s\n", buf);
668 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
670 scr_printf("%s\n", buf);
673 r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
674 scr_printf("%s\n", buf);
675 strncpy(buf, attr->QRname, ROOMNAMELEN);
678 dotgoto(ipc, buf, 2, 0);
685 * un-goto the previous room, or a specified room
687 void dotungoto(CtdlIPC *ipc, char *towhere)
689 /* Find this 'towhere' room in the list ungoto from this room to
690 that at the messagepointer position in that room in our ungoto list.
691 I suppose I could be a real dick and just ungoto that many places
696 struct ctdlipcroom *rret = NULL; /* ignored */
701 scr_printf("No rooms to ungoto.\n");
706 scr_printf("Must specify a room to ungoto.\n");
709 if (IsEmptyStr(towhere))
711 scr_printf("Must specify a room to ungoto.\n");
714 for (lp = uglistsize-1; lp >= 0; lp--)
716 if (strcasecmp(towhere, uglist[lp]) == 0)
724 scr_printf("Room: %s not in ungoto list.\n", towhere);
728 r = CtdlIPCGotoRoom(ipc, uglist[found], "", &rret, buf);
729 if (rret) free(rret); /* ignored */
731 scr_printf("%s\n", buf);
734 r = CtdlIPCSetLastRead(ipc, uglistlsn[found] ? uglistlsn[found] : 1, buf);
736 scr_printf("%s\n", buf);
738 safestrncpy(buf, uglist[found], sizeof(buf));
739 /* we queue ungoto information here, because we're not really
740 ungotoing, we're really going to a random spot in some arbitrary
742 dotgoto(ipc, buf, 0, 0);
745 void ungoto(CtdlIPC *ipc)
748 struct ctdlipcroom *rret = NULL; /* ignored */
754 r = CtdlIPCGotoRoom(ipc, uglist[uglistsize-1], "", &rret, buf);
755 if (rret) free(rret); /* ignored */
757 scr_printf("%s\n", buf);
760 r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize-1] ? uglistlsn[uglistsize-1] : 1, buf);
762 scr_printf("%s\n", buf);
764 safestrncpy(buf, uglist[uglistsize-1], sizeof(buf));
766 free(uglist[uglistsize]);
767 /* Don't queue ungoto info or we end up in a loop */
768 dotgoto(ipc, buf, 0, 1);
773 * saves filelen bytes from file at pathname
775 int save_buffer(void *file, size_t filelen, const char *pathname)
778 size_t bytes_written = 0;
781 fp = fopen(pathname, "w");
783 scr_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
787 block = fwrite((char *)file + bytes_written, 1,
788 filelen - bytes_written, fp);
789 bytes_written += block;
790 } while (errno == EINTR && bytes_written < filelen);
793 if (bytes_written < filelen) {
794 scr_printf("Trouble saving '%s': %s\n", pathname,
803 * Save supplied_filename in dest directory; gets the name only
805 void destination_directory(char *dest, const char *supplied_filename)
807 static char save_dir[SIZ] = { 0 };
809 if (IsEmptyStr(save_dir)) {
810 if (getenv("HOME") == NULL) {
811 strcpy(save_dir, ".");
814 sprintf(save_dir, "%s/Desktop", getenv("HOME"));
815 if (access(save_dir, W_OK) != 0) {
816 sprintf(save_dir, "%s", getenv("HOME"));
817 if (access(save_dir, W_OK) != 0) {
818 sprintf(save_dir, ".");
824 sprintf(dest, "%s/%s", save_dir, supplied_filename);
825 strprompt("Save as", dest, PATH_MAX);
827 /* Remember the directory for next time */
828 strcpy(save_dir, dest);
829 if (strrchr(save_dir, '/') != NULL) {
830 strcpy(strrchr(save_dir, '/'), "");
833 strcpy(save_dir, ".");
839 * download() - download a file or files. The argument passed to this
840 * function determines which protocol to use.
841 * proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
843 void download(CtdlIPC *ipc, int proto)
846 char filename[PATH_MAX];
847 char tempname[PATH_MAX];
848 char transmit_cmd[SIZ];
853 void *file = NULL; /* The downloaded file */
854 size_t filelen = 0L; /* The downloaded file length */
856 if ((room_flags & QR_DOWNLOAD) == 0) {
857 scr_printf("*** You cannot download from this room.\n");
861 newprompt("Enter filename: ", filename, PATH_MAX);
863 /* Save to local disk, for folks with their own copy of the client */
865 destination_directory(tempname, filename);
866 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
868 scr_printf("%s\n", buf);
871 save_buffer(file, (size_t)extract_long(buf, 0), tempname);
876 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
878 scr_printf("%s\n", buf);
881 filelen = extract_unsigned_long(buf, 0);
883 /* Meta-download for public clients */
884 /* scr_printf("Fetching file from Citadel server...\n"); */
885 mkdir(tempdir, 0700);
886 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
887 tpipe = fopen(tempname, "wb");
888 if (fwrite(file, filelen, 1, tpipe) < filelen) {
889 /* FIXME: restart syscall on EINTR
893 if (file) free(file);
896 /* FIXME: display internally instead */
897 snprintf(transmit_cmd, sizeof transmit_cmd,
898 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",
902 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
904 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
906 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
908 /* FIXME: display internally instead */
909 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
911 stty_ctdl(SB_RESTORE);
912 rv = system(transmit_cmd);
914 scr_printf("failed to download '%s': %d\n", transmit_cmd, rv);
915 stty_ctdl(SB_NO_INTR);
917 /* clean up the temporary directory */
919 ctdl_beep(); /* Beep beep! */
924 * read directory of this room
926 void roomdir(CtdlIPC *ipc)
933 char *listing = NULL; /* Returned directory listing */
936 r = CtdlIPCReadDirectory(ipc, &listing, buf);
938 scr_printf("%s\n", buf);
942 extract_token(comment, buf, 0, '|', sizeof comment);
943 extract_token(flnm, buf, 1, '|', sizeof flnm);
944 scr_printf("\nDirectory of %s on %s\n", flnm, comment);
945 scr_printf("-----------------------\n");
946 while (listing && *listing && !IsEmptyStr(listing)) {
947 extract_token(buf, listing, 0, '\n', sizeof buf);
948 remove_token(listing, 0, '\n');
950 extract_token(flnm, buf, 0, '|', sizeof flnm);
951 extract_token(flsz, buf, 1, '|', sizeof flsz);
952 extract_token(mimetype, buf, 2, '|', sizeof mimetype);
953 extract_token(comment, buf, 3, '|', sizeof comment);
954 if (strlen(flnm) <= 14)
955 scr_printf("%-14s %8s %s [%s]\n", flnm, flsz, comment, mimetype);
957 scr_printf("%s\n%14s %8s %s [%s]\n", flnm, "", flsz,
960 if (listing) free(listing);
965 * add a user to a private room
967 void invite(CtdlIPC *ipc)
969 char username[USERNAME_SIZE];
972 newprompt("Name of user? ", username, USERNAME_SIZE);
973 if (username[0] == 0)
976 CtdlIPCInviteUserToRoom(ipc, username, buf);
977 scr_printf("%s\n", buf);
982 * kick a user out of a room
984 void kickout(CtdlIPC *ipc)
986 char username[USERNAME_SIZE];
989 newprompt("Name of user? ", username, USERNAME_SIZE);
990 if (username[0] == 0)
993 CtdlIPCKickoutUserFromRoom(ipc, username, buf);
994 scr_printf("%s\n", buf);
999 * aide command: kill the current room
1001 void killroom(CtdlIPC *ipc)
1006 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
1008 scr_printf("%s\n", aaa);
1012 scr_printf("Are you sure you want to kill this room? ");
1016 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
1017 scr_printf("%s\n", aaa);
1020 dotgoto(ipc, "_BASEROOM_", 0, 0);
1023 void forget(CtdlIPC *ipc)
1024 { /* forget the current room */
1027 scr_printf("Are you sure you want to forget this room? ");
1031 remove_march(room_name, 0);
1032 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
1033 scr_printf("%s\n", buf);
1037 /* now return to the lobby */
1038 dotgoto(ipc, "_BASEROOM_", 0, 0);
1045 void entroom(CtdlIPC *ipc)
1048 char new_room_name[ROOMNAMELEN];
1050 char new_room_pass[10];
1053 int r; /* IPC response code */
1055 /* Check permission to create room */
1056 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
1058 scr_printf("%s\n", buf);
1062 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
1063 if (IsEmptyStr(new_room_name)) {
1066 for (a = 0; !IsEmptyStr(&new_room_name[a]); ++a) {
1067 if (new_room_name[a] == '|') {
1068 new_room_name[a] = '_';
1072 new_room_floor = select_floor(ipc, (int) curr_floor);
1074 IFNEXPERT formout(ipc, "roomaccess");
1076 scr_printf("<?>Help\n"
1077 "<1>Public room (shown to all users by default)\n"
1078 "<2>Hidden room (accessible to anyone who knows the room name)\n"
1079 "<3>Passworded room (hidden, plus requires a password to enter)\n"
1080 "<4>Invitation-only room (requires access to be granted by an Aide)\n"
1081 "<5>Personal room (accessible to you only)\n"
1086 } while (((b < '1') || (b > '5')) && (b != '?'));
1089 formout(ipc, "roomaccess");
1091 } while ((b < '1') || (b > '5'));
1092 b -= '0'; /* Portable */
1093 scr_printf("%d\n", b);
1094 new_room_type = b - 1;
1095 if (new_room_type == 2) {
1096 newprompt("Enter a room password: ", new_room_pass, 9);
1097 for (a = 0; !IsEmptyStr(&new_room_pass[a]); ++a)
1098 if (new_room_pass[a] == '|')
1099 new_room_pass[a] = '_';
1101 strcpy(new_room_pass, "");
1104 scr_printf("\042%s\042, a", new_room_name);
1106 scr_printf(" public room.");
1108 scr_printf(" hidden room.");
1110 scr_printf(" passworded room, password: %s", new_room_pass);
1112 scr_printf("n invitation-only room.");
1114 scr_printf(" personal room.");
1115 scr_printf("\nInstall it? (y/n) : ");
1120 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type,
1121 new_room_pass, new_room_floor, buf);
1123 scr_printf("%s\n", buf);
1127 /* command succeeded... now GO to the new room! */
1128 dotgoto(ipc, new_room_name, 0, 0);
1133 void readinfo(CtdlIPC *ipc)
1134 { /* read info file for current room */
1137 int r; /* IPC response code */
1140 /* Name of currernt room aide */
1141 r = CtdlIPCGetRoomAide(ipc, buf);
1143 safestrncpy(raide, buf, sizeof raide);
1147 if (!IsEmptyStr(raide))
1148 scr_printf("Room aide is %s.\n\n", raide);
1150 r = CtdlIPCRoomInfo(ipc, &text, buf);
1155 fmout(screenwidth, NULL, text, NULL, 1);
1162 * <W>ho knows room...
1164 void whoknows(CtdlIPC *ipc)
1167 char *listing = NULL;
1170 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1172 scr_printf("%s\n", buf);
1175 while (!IsEmptyStr(listing)) {
1176 extract_token(buf, listing, 0, '\n', sizeof buf);
1177 remove_token(listing, 0, '\n');
1179 scr_printf("%s\n", buf);
1185 void do_edit(CtdlIPC *ipc,
1186 char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
1190 int b, cksum, editor_exit;
1192 if (IsEmptyStr(editor_path)) {
1193 scr_printf("Do you wish to re-enter %s? ", desc);
1198 fp = fopen(temp, "w");
1201 CtdlIPC_chat_send(ipc, check_cmd);
1202 CtdlIPC_chat_recv(ipc, cmd);
1203 if (cmd[0] != '2') {
1204 scr_printf("%s\n", &cmd[4]);
1208 if (!IsEmptyStr(editor_path)) {
1209 CtdlIPC_chat_send(ipc, read_cmd);
1210 CtdlIPC_chat_recv(ipc, cmd);
1211 if (cmd[0] == '1') {
1212 fp = fopen(temp, "w");
1213 while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
1214 fprintf(fp, "%s\n", cmd);
1220 cksum = file_checksum(temp);
1222 if (!IsEmptyStr(editor_path)) {
1225 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1227 stty_ctdl(SB_RESTORE);
1228 editor_pid = fork();
1229 if (editor_pid == 0) {
1231 execlp(editor_path, editor_path, temp, NULL);
1237 b = ka_wait(&editor_exit);
1238 } while ((b != editor_pid) && (b >= 0));
1240 scr_printf("Executed %s\n", editor_path);
1243 scr_printf("Entering %s. Press return twice when finished.\n", desc);
1244 fp = fopen(temp, "r+");
1249 if (file_checksum(temp) == cksum) {
1250 scr_printf("*** Aborted.\n");
1254 CtdlIPC_chat_send(ipc, write_cmd);
1255 CtdlIPC_chat_recv(ipc, cmd);
1256 if (cmd[0] != '4') {
1257 scr_printf("%s\n", &cmd[4]);
1261 fp = fopen(temp, "r");
1262 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1263 cmd[strlen(cmd) - 1] = 0;
1264 CtdlIPC_chat_send(ipc, cmd);
1267 CtdlIPC_chat_send(ipc, "000");
1274 void enterinfo(CtdlIPC *ipc)
1275 { /* edit info file for current room */
1276 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1279 void enter_bio(CtdlIPC *ipc)
1282 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1283 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1287 * create a new floor
1289 void create_floor(CtdlIPC *ipc)
1292 char newfloorname[SIZ];
1293 int r; /* IPC response code */
1295 load_floorlist(ipc);
1297 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1298 if ( (r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE) ) {
1299 scr_printf("%s\n", buf);
1303 newprompt("Name for new floor: ", newfloorname, 255);
1304 if (!*newfloorname) return;
1305 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1307 scr_printf("Floor has been created.\n");
1309 scr_printf("%s\n", buf);
1312 load_floorlist(ipc);
1316 * edit the current floor
1318 void edit_floor(CtdlIPC *ipc)
1321 struct ExpirePolicy *ep = NULL;
1323 load_floorlist(ipc);
1325 /* Fetch the expire policy (this will silently fail on old servers,
1326 * resulting in "default" policy)
1328 CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1330 /* Interact with the user */
1331 scr_printf("You are editing the floor called \"%s\"\n",
1332 &floorlist[(int) curr_floor][0] );
1333 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1335 /* Angels and demons dancing in my head... */
1337 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1339 ("Floor default message expire policy (? for list)",
1341 if (buf[0] == '?') {
1343 "0. Use the system default\n"
1344 "1. Never automatically expire messages\n"
1345 "2. Expire by message count\n"
1346 "3. Expire by message age\n");
1348 } while ((buf[0] < '0') || (buf[0] > '3'));
1349 ep->expire_mode = buf[0] - '0';
1351 /* ...lunatics and monsters underneath my bed */
1352 if (ep->expire_mode == 2) {
1353 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1354 strprompt("Keep how many messages online?", buf, 10);
1355 ep->expire_value = atol(buf);
1358 if (ep->expire_mode == 3) {
1359 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1360 strprompt("Keep messages for how many days?", buf, 10);
1361 ep->expire_value = atol(buf);
1365 CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1366 CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf);
1367 scr_printf("%s\n", buf);
1368 load_floorlist(ipc);
1375 * kill the current floor
1377 void kill_floor(CtdlIPC *ipc)
1379 int floornum_to_delete, a;
1382 load_floorlist(ipc);
1384 floornum_to_delete = (-1);
1385 scr_printf("(Press return to abort)\n");
1386 newprompt("Delete which floor? ", buf, 255);
1387 if (IsEmptyStr(buf))
1389 for (a = 0; a < 128; ++a)
1390 if (!strcasecmp(&floorlist[a][0], buf))
1391 floornum_to_delete = a;
1392 if (floornum_to_delete < 0) {
1393 scr_printf("No such floor. Select one of:\n");
1394 for (a = 0; a < 128; ++a)
1395 if (floorlist[a][0] != 0)
1396 scr_printf("%s\n", &floorlist[a][0]);
1398 } while (floornum_to_delete < 0);
1399 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1400 scr_printf("%s\n", buf);
1401 load_floorlist(ipc);