1 // Client-side functions which perform room operations
3 // Copyright (c) 1987-2018 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 safestrncpy(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 safestrncpy(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,
528 "Subject Required (Force " "users to specify a message " "subject)", QR2_SUBJECTREQ);
529 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Directory room", QR_DIRECTORY);
530 if (attr->QRflags & QR_DIRECTORY) {
531 strprompt("Directory name", attr->QRdirname, 14);
532 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Uploading allowed", QR_UPLOAD);
533 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Downloading allowed", QR_DOWNLOAD);
534 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Visible directory", QR_VISDIR);
536 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Self-service list subscribe/unsubscribe", QR2_SELFLIST);
537 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
538 "public posting to this room via room_roomname@yourcitadel.org", QR2_SMTP_PUBLIC);
539 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "moderated mailinglist", QR2_MODERATED);
540 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Automatically make all messages anonymous", QR_ANONONLY);
541 if ((attr->QRflags & QR_ANONONLY) == 0) {
542 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Ask users whether to make messages anonymous", QR_ANONOPT);
544 attr->QRorder = intprompt("Listing order", attr->QRorder, 0, 127);
546 /* Ask about the room admin */
548 strprompt("Room admin (or 'none')", room_admin_name, 29);
549 if (!strcasecmp(room_admin_name, "none")) {
550 strcpy(room_admin_name, "");
553 r = CtdlIPCQueryUsername(ipc, room_admin_name, buf);
555 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);
611 * un-goto the previous room, or a specified room
613 void dotungoto(CtdlIPC * ipc, char *towhere)
615 /* Find this 'towhere' room in the list ungoto from this room to
616 that at the messagepointer position in that room in our ungoto list.
617 I suppose I could be a real dick and just ungoto that many places
622 struct ctdlipcroom *rret = NULL; /* ignored */
625 if (uglistsize == 0) {
626 scr_printf("No rooms to ungoto.\n");
629 if (towhere == NULL) {
630 scr_printf("Must specify a room to ungoto.\n");
633 if (IsEmptyStr(towhere)) {
634 scr_printf("Must specify a room to ungoto.\n");
637 for (lp = uglistsize - 1; lp >= 0; lp--) {
638 if (strcasecmp(towhere, uglist[lp]) == 0) {
644 scr_printf("Room: %s not in ungoto list.\n", towhere);
648 r = CtdlIPCGotoRoom(ipc, uglist[found], "", &rret, buf);
650 free(rret); /* ignored */
652 scr_printf("%s\n", buf);
655 r = CtdlIPCSetLastRead(ipc, uglistlsn[found] ? uglistlsn[found] : 1, buf);
657 scr_printf("%s\n", buf);
659 safestrncpy(buf, uglist[found], sizeof(buf));
660 /* we queue ungoto information here, because we're not really
661 ungotoing, we're really going to a random spot in some arbitrary
663 dotgoto(ipc, buf, 0, 0);
666 void ungoto(CtdlIPC * ipc)
669 struct ctdlipcroom *rret = NULL; /* ignored */
675 r = CtdlIPCGotoRoom(ipc, uglist[uglistsize - 1], "", &rret, buf);
677 free(rret); /* ignored */
679 scr_printf("%s\n", buf);
682 r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize - 1] ? uglistlsn[uglistsize - 1] : 1, buf);
684 scr_printf("%s\n", buf);
686 safestrncpy(buf, uglist[uglistsize - 1], sizeof(buf));
688 free(uglist[uglistsize]);
689 /* Don't queue ungoto info or we end up in a loop */
690 dotgoto(ipc, buf, 0, 1);
695 * saves filelen bytes from file at pathname
697 int save_buffer(void *file, size_t filelen, const char *pathname)
700 size_t bytes_written = 0;
703 fp = fopen(pathname, "w");
705 scr_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
709 block = fwrite((char *) file + bytes_written, 1, filelen - bytes_written, fp);
710 bytes_written += block;
711 } while (errno == EINTR && bytes_written < filelen);
714 if (bytes_written < filelen) {
715 scr_printf("Trouble saving '%s': %s\n", pathname, strerror(errno));
723 * Save supplied_filename in dest directory; gets the name only
725 void destination_directory(char *dest, const char *supplied_filename)
727 static char save_dir[SIZ] = { 0 };
729 if (IsEmptyStr(save_dir)) {
730 if (getenv("HOME") == NULL) {
731 strcpy(save_dir, ".");
733 sprintf(save_dir, "%s/Desktop", getenv("HOME"));
734 if (access(save_dir, W_OK) != 0) {
735 sprintf(save_dir, "%s", getenv("HOME"));
736 if (access(save_dir, W_OK) != 0) {
737 sprintf(save_dir, ".");
743 sprintf(dest, "%s/%s", save_dir, supplied_filename);
744 strprompt("Save as", dest, PATH_MAX);
746 /* Remember the directory for next time */
747 strcpy(save_dir, dest);
748 if (strrchr(save_dir, '/') != NULL) {
749 strcpy(strrchr(save_dir, '/'), "");
751 strcpy(save_dir, ".");
757 * download() - download a file or files. The argument passed to this
758 * function determines which protocol to use.
759 * proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
761 void download(CtdlIPC * ipc, int proto)
764 char filename[PATH_MAX];
765 char tempname[PATH_MAX];
766 char transmit_cmd[SIZ];
771 void *file = NULL; /* The downloaded file */
772 size_t filelen = 0L; /* The downloaded file length */
774 if ((room_flags & QR_DOWNLOAD) == 0) {
775 scr_printf("*** You cannot download from this room.\n");
779 newprompt("Enter filename: ", filename, PATH_MAX);
781 /* Save to local disk, for folks with their own copy of the client */
783 destination_directory(tempname, filename);
784 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
786 scr_printf("%s\n", buf);
789 save_buffer(file, (size_t) extract_long(buf, 0), tempname);
794 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
796 scr_printf("%s\n", buf);
799 filelen = extract_unsigned_long(buf, 0);
801 /* Meta-download for public clients */
802 /* scr_printf("Fetching file from Citadel server...\n"); */
803 mkdir(tempdir, 0700);
804 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
805 tpipe = fopen(tempname, "wb");
806 if (fwrite(file, filelen, 1, tpipe) < filelen) {
807 /* FIXME: restart syscall on EINTR
815 /* FIXME: display internally instead */
816 snprintf(transmit_cmd, sizeof transmit_cmd,
817 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s", tempname);
818 } else if (proto == 1)
819 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
821 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
823 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
825 /* FIXME: display internally instead */
826 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
828 stty_ctdl(SB_RESTORE);
829 rv = system(transmit_cmd);
831 scr_printf("failed to download '%s': %d\n", transmit_cmd, rv);
832 stty_ctdl(SB_NO_INTR);
834 /* clean up the temporary directory */
836 ctdl_beep(); /* Beep beep! */
841 * read directory of this room
843 void roomdir(CtdlIPC * ipc)
850 char *listing = NULL; /* Returned directory listing */
853 r = CtdlIPCReadDirectory(ipc, &listing, buf);
855 scr_printf("%s\n", buf);
859 extract_token(comment, buf, 0, '|', sizeof comment);
860 extract_token(flnm, buf, 1, '|', sizeof flnm);
861 scr_printf("\nDirectory of %s on %s\n", flnm, comment);
862 scr_printf("-----------------------\n");
863 while (listing && *listing && !IsEmptyStr(listing)) {
864 extract_token(buf, listing, 0, '\n', sizeof buf);
865 remove_token(listing, 0, '\n');
867 extract_token(flnm, buf, 0, '|', sizeof flnm);
868 extract_token(flsz, buf, 1, '|', sizeof flsz);
869 extract_token(mimetype, buf, 2, '|', sizeof mimetype);
870 extract_token(comment, buf, 3, '|', sizeof comment);
871 if (strlen(flnm) <= 14)
872 scr_printf("%-14s %8s %s [%s]\n", flnm, flsz, comment, mimetype);
874 scr_printf("%s\n%14s %8s %s [%s]\n", flnm, "", flsz, comment, mimetype);
882 * add a user to a private room
884 void invite(CtdlIPC * ipc)
886 char username[USERNAME_SIZE];
889 newprompt("Name of user? ", username, USERNAME_SIZE);
890 if (username[0] == 0)
893 CtdlIPCInviteUserToRoom(ipc, username, buf);
894 scr_printf("%s\n", buf);
899 * kick a user out of a room
901 void kickout(CtdlIPC * ipc)
903 char username[USERNAME_SIZE];
906 newprompt("Name of user? ", username, USERNAME_SIZE);
907 if (username[0] == 0)
910 CtdlIPCKickoutUserFromRoom(ipc, username, buf);
911 scr_printf("%s\n", buf);
916 * aide command: kill the current room
918 void killroom(CtdlIPC * ipc)
923 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
925 scr_printf("%s\n", aaa);
929 scr_printf("Are you sure you want to kill this room? ");
933 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
934 scr_printf("%s\n", aaa);
937 dotgoto(ipc, "_BASEROOM_", 0, 0);
940 void forget(CtdlIPC * ipc)
941 { /* forget the current room */
944 scr_printf("Are you sure you want to forget this room? ");
948 remove_march(room_name, 0);
949 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
950 scr_printf("%s\n", buf);
954 /* now return to the lobby */
955 dotgoto(ipc, "_BASEROOM_", 0, 0);
962 void entroom(CtdlIPC * ipc)
965 char new_room_name[ROOMNAMELEN];
967 char new_room_pass[10];
970 int r; /* IPC response code */
972 /* Check permission to create room */
973 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
975 scr_printf("%s\n", buf);
979 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
980 if (IsEmptyStr(new_room_name)) {
983 for (a = 0; !IsEmptyStr(&new_room_name[a]); ++a) {
984 if (new_room_name[a] == '|') {
985 new_room_name[a] = '_';
989 new_room_floor = select_floor(ipc, (int) curr_floor);
991 IFNEXPERT formout(ipc, "roomaccess");
993 scr_printf("<?>Help\n"
994 "<1>Public room (shown to all users by default)\n"
995 "<2>Hidden room (accessible to anyone who knows the room name)\n"
996 "<3>Passworded room (hidden, plus requires a password to enter)\n"
997 "<4>Invitation-only room (requires access to be granted by an Admin)\n"
998 "<5>Personal room (accessible to you only)\n" "Enter room type: ");
1001 } while (((b < '1') || (b > '5')) && (b != '?'));
1004 formout(ipc, "roomaccess");
1006 } while ((b < '1') || (b > '5'));
1007 b -= '0'; /* Portable */
1008 scr_printf("%d\n", b);
1009 new_room_type = b - 1;
1010 if (new_room_type == 2) {
1011 newprompt("Enter a room password: ", new_room_pass, 9);
1012 for (a = 0; !IsEmptyStr(&new_room_pass[a]); ++a)
1013 if (new_room_pass[a] == '|')
1014 new_room_pass[a] = '_';
1016 strcpy(new_room_pass, "");
1019 scr_printf("\042%s\042, a", new_room_name);
1021 scr_printf(" public room.");
1023 scr_printf(" hidden room.");
1025 scr_printf(" passworded room, password: %s", new_room_pass);
1027 scr_printf("n invitation-only room.");
1029 scr_printf(" personal room.");
1030 scr_printf("\nInstall it? (y/n) : ");
1035 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type, new_room_pass, new_room_floor, buf);
1037 scr_printf("%s\n", buf);
1041 /* command succeeded... now GO to the new room! */
1042 dotgoto(ipc, new_room_name, 0, 0);
1047 void readinfo(CtdlIPC * ipc)
1048 { /* read info file for current room */
1050 char room_admin_name[64];
1051 int r; /* IPC response code */
1054 /* Name of currernt room admin */
1055 r = CtdlIPCGetRoomAide(ipc, buf);
1057 safestrncpy(room_admin_name, buf, sizeof room_admin_name);
1059 strcpy(room_admin_name, "");
1061 if (!IsEmptyStr(room_admin_name))
1062 scr_printf("Room admin is %s.\n\n", room_admin_name);
1064 r = CtdlIPCRoomInfo(ipc, &text, buf);
1069 fmout(screenwidth, NULL, text, NULL, 1);
1076 * <W>ho knows room...
1078 void whoknows(CtdlIPC * ipc)
1081 char *listing = NULL;
1084 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1086 scr_printf("%s\n", buf);
1089 while (!IsEmptyStr(listing)) {
1090 extract_token(buf, listing, 0, '\n', sizeof buf);
1091 remove_token(listing, 0, '\n');
1093 scr_printf("%s\n", buf);
1099 void do_edit(CtdlIPC * ipc, char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
1103 int b, cksum, editor_exit;
1105 if (IsEmptyStr(editor_path)) {
1106 scr_printf("Do you wish to re-enter %s? ", desc);
1111 fp = fopen(temp, "w");
1114 CtdlIPC_chat_send(ipc, check_cmd);
1115 CtdlIPC_chat_recv(ipc, cmd);
1116 if (cmd[0] != '2') {
1117 scr_printf("%s\n", &cmd[4]);
1121 if (!IsEmptyStr(editor_path)) {
1122 CtdlIPC_chat_send(ipc, read_cmd);
1123 CtdlIPC_chat_recv(ipc, cmd);
1124 if (cmd[0] == '1') {
1125 fp = fopen(temp, "w");
1126 while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
1127 fprintf(fp, "%s\n", cmd);
1133 cksum = file_checksum(temp);
1135 if (!IsEmptyStr(editor_path)) {
1138 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1140 stty_ctdl(SB_RESTORE);
1141 editor_pid = fork();
1142 if (editor_pid == 0) {
1144 execlp(editor_path, editor_path, temp, NULL);
1150 b = ka_wait(&editor_exit);
1151 } while ((b != editor_pid) && (b >= 0));
1153 scr_printf("Executed %s\n", editor_path);
1156 scr_printf("Entering %s. Press return twice when finished.\n", desc);
1157 fp = fopen(temp, "r+");
1162 if (file_checksum(temp) == cksum) {
1163 scr_printf("*** Aborted.\n");
1167 CtdlIPC_chat_send(ipc, write_cmd);
1168 CtdlIPC_chat_recv(ipc, cmd);
1169 if (cmd[0] != '4') {
1170 scr_printf("%s\n", &cmd[4]);
1174 fp = fopen(temp, "r");
1175 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1176 cmd[strlen(cmd) - 1] = 0;
1177 CtdlIPC_chat_send(ipc, cmd);
1180 CtdlIPC_chat_send(ipc, "000");
1187 void enterinfo(CtdlIPC * ipc)
1188 { /* edit info file for current room */
1189 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1192 void enter_bio(CtdlIPC * ipc)
1195 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1196 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1200 * create a new floor
1202 void create_floor(CtdlIPC * ipc)
1205 char newfloorname[SIZ];
1206 int r; /* IPC response code */
1208 load_floorlist(ipc);
1210 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1211 if ((r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE)) {
1212 scr_printf("%s\n", buf);
1216 newprompt("Name for new floor: ", newfloorname, 255);
1219 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1221 scr_printf("Floor has been created.\n");
1223 scr_printf("%s\n", buf);
1226 load_floorlist(ipc);
1230 * edit the current floor
1232 void edit_floor(CtdlIPC * ipc)
1235 struct ExpirePolicy *ep = NULL;
1237 load_floorlist(ipc);
1239 /* Fetch the expire policy (this will silently fail on old servers,
1240 * resulting in "default" policy)
1242 CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1244 /* Interact with the user */
1245 scr_printf("You are editing the floor called \"%s\"\n", &floorlist[(int) curr_floor][0]);
1246 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1248 /* Angels and demons dancing in my head... */
1250 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1251 strprompt("Floor default message expire policy (? for list)", buf, 1);
1252 if (buf[0] == '?') {
1254 "0. Use the system default\n"
1255 "1. Never automatically expire messages\n"
1256 "2. Expire by message count\n" "3. Expire by message age\n");
1258 } while ((buf[0] < '0') || (buf[0] > '3'));
1259 ep->expire_mode = buf[0] - '0';
1261 /* ...lunatics and monsters underneath my bed */
1262 if (ep->expire_mode == 2) {
1263 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1264 strprompt("Keep how many messages online?", buf, 10);
1265 ep->expire_value = atol(buf);
1268 if (ep->expire_mode == 3) {
1269 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1270 strprompt("Keep messages for how many days?", buf, 10);
1271 ep->expire_value = atol(buf);
1275 CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1276 CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int) curr_floor][0], buf);
1277 scr_printf("%s\n", buf);
1278 load_floorlist(ipc);
1285 * kill the current floor
1287 void kill_floor(CtdlIPC * ipc)
1289 int floornum_to_delete, a;
1292 load_floorlist(ipc);
1294 floornum_to_delete = (-1);
1295 scr_printf("(Press return to abort)\n");
1296 newprompt("Delete which floor? ", buf, 255);
1297 if (IsEmptyStr(buf))
1299 for (a = 0; a < 128; ++a)
1300 if (!strcasecmp(&floorlist[a][0], buf))
1301 floornum_to_delete = a;
1302 if (floornum_to_delete < 0) {
1303 scr_printf("No such floor. Select one of:\n");
1304 for (a = 0; a < 128; ++a)
1305 if (floorlist[a][0] != 0)
1306 scr_printf("%s\n", &floorlist[a][0]);
1308 } while (floornum_to_delete < 0);
1309 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1310 scr_printf("%s\n", buf);
1311 load_floorlist(ipc);