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) {
110 c = c + strlen(rmname) + 3;
113 if (rp->rnext != NULL) {
114 room_tree_list(rp->rnext);
122 * Room ordering stuff (compare first by floor, then by order)
124 int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2)
126 if ((r1 == NULL) && (r2 == NULL))
132 if (r1->rlfloor < r2->rlfloor)
134 if (r1->rlfloor > r2->rlfloor)
136 if (r1->rlorder < r2->rlorder)
138 if (r1->rlorder > r2->rlorder)
145 * Common code for all room listings
147 static void listrms(struct march *listing, int new_only, int floor_only, unsigned int flags, char *match)
150 struct ctdlroomlisting *rl = NULL;
151 struct ctdlroomlisting *rp;
152 struct ctdlroomlisting *rs;
155 for (mptr = listing; mptr != NULL; mptr = mptr->next) {
158 if ((new_only == LISTRMS_NEW_ONLY)
159 && ((mptr->march_access & UA_HASNEWMSGS) == 0))
162 if ((new_only == LISTRMS_OLD_ONLY)
163 && ((mptr->march_access & UA_HASNEWMSGS) != 0))
166 if ((floor_only >= 0)
167 && (mptr->march_floor != floor_only))
170 if (flags && (mptr->march_flags & flags) == 0)
173 if (match && (pattern(mptr->march_name, match) == -1))
177 rp = malloc(sizeof(struct ctdlroomlisting));
178 strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
179 rp->rlflags = mptr->march_flags;
180 rp->rlfloor = mptr->march_floor;
181 rp->rlorder = mptr->march_order;
190 if (rordercmp(rp, rs) < 0) {
191 if (rs->lnext == NULL) {
198 if (rs->rnext == NULL) {
210 room_tree_list(NULL);
216 void list_other_floors(void)
221 for (a = 0; a < 128; ++a) {
222 if ((strlen(floorlist[a]) > 0) && (a != curr_floor)) {
223 if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
227 scr_printf("%s: ", floorlist[a]);
228 c = c + strlen(floorlist[a]) + 3;
235 * List known rooms. kn_floor_mode should be set to 0 for a 'flat' listing,
236 * 1 to list rooms on the current floor, or 2 to list rooms on all floors.
238 void knrooms(CtdlIPC * ipc, int kn_floor_mode)
241 struct march *listing = NULL;
243 int r; /* IPC response code */
247 /* Ask the server for a room list */
248 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
256 if (kn_floor_mode == 0) {
258 scr_printf("\n Rooms with unread messages:\n");
259 listrms(listing, LISTRMS_NEW_ONLY, -1, 0, NULL);
261 scr_printf("\n\n No unseen messages in:\n");
262 listrms(listing, LISTRMS_OLD_ONLY, -1, 0, NULL);
266 if (kn_floor_mode == 1) {
268 scr_printf("\n Rooms with unread messages on %s:\n", floorlist[(int) curr_floor]);
269 listrms(listing, LISTRMS_NEW_ONLY, curr_floor, 0, NULL);
271 scr_printf("\n\n Rooms with no new messages on %s:\n", floorlist[(int) curr_floor]);
272 listrms(listing, LISTRMS_OLD_ONLY, curr_floor, 0, NULL);
274 scr_printf("\n\n Other floors:\n");
279 if (kn_floor_mode == 2) {
280 for (a = 0; a < 128; ++a) {
281 if (floorlist[a][0] != 0) {
283 scr_printf("\n Rooms on %s:\n", floorlist[a]);
284 listrms(listing, LISTRMS_ALL, a, 0, NULL);
290 /* Free the room list */
292 mptr = listing->next;
301 void listzrooms(CtdlIPC * ipc)
302 { /* list public forgotten rooms */
303 struct march *listing = NULL;
305 int r; /* IPC response code */
309 /* Ask the server for a room list */
310 r = CtdlIPCKnownRooms(ipc, UnsubscribedRooms, (-1), &listing, buf);
316 scr_printf("\n Forgotten public rooms:\n");
317 listrms(listing, LISTRMS_ALL, -1, 0, NULL);
320 /* Free the room list */
322 mptr = listing->next;
330 void dotknown(CtdlIPC * ipc, int what, char *match)
331 { /* list rooms according to attribute */
332 struct march *listing = NULL;
334 int r; /* IPC response code */
337 /* Ask the server for a room list */
338 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, (-1), &listing, buf);
347 scr_printf("\n Anonymous rooms:\n");
348 listrms(listing, LISTRMS_ALL, -1, QR_ANONONLY | QR_ANONOPT, NULL);
352 scr_printf("\n Directory rooms:\n");
353 listrms(listing, LISTRMS_ALL, -1, QR_DIRECTORY, NULL);
357 scr_printf("\n Matching \"%s\" rooms:\n", match);
358 listrms(listing, LISTRMS_ALL, -1, 0, match);
362 scr_printf("\n Preferred only rooms:\n");
363 listrms(listing, LISTRMS_ALL, -1, QR_PREFONLY, NULL);
367 scr_printf("\n Private rooms:\n");
368 listrms(listing, LISTRMS_ALL, -1, QR_PRIVATE, NULL);
372 scr_printf("\n Read only rooms:\n");
373 listrms(listing, LISTRMS_ALL, -1, QR_READONLY, NULL);
378 /* Free the room list */
380 mptr = listing->next;
389 int set_room_attr(CtdlIPC * ipc, unsigned int ibuf, char *prompt, unsigned int sbit)
393 a = boolprompt(prompt, (ibuf & sbit));
394 ibuf = (ibuf | sbit);
396 ibuf = (ibuf ^ sbit);
404 * Select a floor (used in several commands)
405 * The supplied argument is the 'default' floor number.
406 * This function returns the selected floor number.
408 int select_floor(CtdlIPC * ipc, int rfloor)
413 if (floor_mode == 1) {
414 if (floorlist[(int) curr_floor][0] == 0) {
420 safestrncpy(floorstr, floorlist[rfloor], sizeof floorstr);
421 strprompt("Which floor", floorstr, 255);
422 for (a = 0; a < 128; ++a) {
423 if (!strcasecmp(floorstr, &floorlist[a][0]))
426 && (!strncasecmp(floorstr, &floorlist[a][0], strlen(floorstr))))
429 && (pattern(&floorlist[a][0], floorstr)
434 scr_printf("\n One of:\n");
435 for (a = 0; a < 128; ++a) {
436 if (floorlist[a][0] != 0) {
437 scr_printf("%s\n", &floorlist[a][0]);
441 } while (newfloor < 0);
446 scr_printf("Floor selection bypassed because you have " "floor mode disabled.\n");
456 * .<A>ide <E>dit room
458 void editthisroom(CtdlIPC * ipc)
461 char room_admin_name[USERNAME_SIZE];
463 struct ctdlroom *attr = NULL;
464 struct ExpirePolicy *eptr = NULL;
465 int r; /* IPC response code */
467 /* Fetch the existing room config */
468 r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
470 scr_printf("%s\n", buf);
473 eptr = &(attr->QRep);
475 /* Fetch the name of the current room admin */
476 r = CtdlIPCGetRoomAide(ipc, buf);
478 safestrncpy(room_admin_name, buf, sizeof room_admin_name);
480 strcpy(room_admin_name, "");
482 if (IsEmptyStr(room_admin_name)) {
483 strcpy(room_admin_name, "none");
486 /* Fetch the expire policy (this will silently fail on old servers,
487 * resulting in "default" policy)
489 r = CtdlIPCGetMessageExpirationPolicy(ipc, 0, &eptr, buf);
491 /* Now interact with the user. */
493 strprompt("Room name", attr->QRname, ROOMNAMELEN - 1);
494 attr->QRfloor = select_floor(ipc, attr->QRfloor);
495 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
496 if (attr->QRflags & QR_PRIVATE) {
497 attr->QRflags = set_room_attr(ipc, attr->QRflags,
498 "Hidden room (accessible to anyone who knows the room name)", QR_GUESSNAME);
501 /* if it's public, clear the privacy classes */
502 if ((attr->QRflags & QR_PRIVATE) == 0) {
503 if (attr->QRflags & QR_GUESSNAME) {
504 attr->QRflags = attr->QRflags - QR_GUESSNAME;
506 if (attr->QRflags & QR_PASSWORDED) {
507 attr->QRflags = attr->QRflags - QR_PASSWORDED;
511 /* if it's private, choose the privacy classes */
512 if ((attr->QRflags & QR_PRIVATE)
513 && ((attr->QRflags & QR_GUESSNAME) == 0)) {
514 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Accessible by entering a password", QR_PASSWORDED);
516 if ((attr->QRflags & QR_PRIVATE)
517 && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
518 strprompt("Room password", attr->QRpasswd, 9);
521 if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
522 rbump = boolprompt("Cause current users to forget room", 0);
525 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Preferred users only", QR_PREFONLY);
526 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Read-only room", QR_READONLY);
527 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Allow message deletion by anyone who can post", QR2_COLLABDEL);
528 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Permanent room", QR_PERMANENT);
529 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
530 "Subject Required (Force " "users to specify a message " "subject)", QR2_SUBJECTREQ);
531 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Directory room", QR_DIRECTORY);
532 if (attr->QRflags & QR_DIRECTORY) {
533 strprompt("Directory name", attr->QRdirname, 14);
534 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Uploading allowed", QR_UPLOAD);
535 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Downloading allowed", QR_DOWNLOAD);
536 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Visible directory", QR_VISDIR);
538 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Self-service list subscribe/unsubscribe", QR2_SELFLIST);
539 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
540 "public posting to this room via room_roomname@yourcitadel.org", QR2_SMTP_PUBLIC);
541 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "moderated mailinglist", QR2_MODERATED);
542 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Automatically make all messages anonymous", QR_ANONONLY);
543 if ((attr->QRflags & QR_ANONONLY) == 0) {
544 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Ask users whether to make messages anonymous", QR_ANONOPT);
546 attr->QRorder = intprompt("Listing order", attr->QRorder, 0, 127);
548 /* Ask about the room admin */
550 strprompt("Room admin (or 'none')", room_admin_name, 29);
551 if (!strcasecmp(room_admin_name, "none")) {
552 strcpy(room_admin_name, "");
555 r = CtdlIPCQueryUsername(ipc, room_admin_name, buf);
557 scr_printf("%s\n", buf);
559 } while (r / 100 != 2);
561 /* Angels and demons dancing in my head... */
563 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
564 strprompt("Message expire policy (? for list)", buf, 1);
567 "0. Use the default for this floor\n"
568 "1. Never automatically expire messages\n"
569 "2. Expire by message count\n" "3. Expire by message age\n");
571 } while ((buf[0] < 48) || (buf[0] > 51));
572 attr->QRep.expire_mode = buf[0] - 48;
574 /* ...lunatics and monsters underneath my bed */
575 if (attr->QRep.expire_mode == 2) {
576 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
577 strprompt("Keep how many messages online?", buf, 10);
578 attr->QRep.expire_value = atol(buf);
581 if (attr->QRep.expire_mode == 3) {
582 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
583 strprompt("Keep messages for how many days?", buf, 10);
584 attr->QRep.expire_value = atol(buf);
587 /* Give 'em a chance to change their minds */
588 scr_printf("Save changes (y/n)? ");
591 r = CtdlIPCSetRoomAide(ipc, room_admin_name, buf);
593 scr_printf("%s\n", buf);
596 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
598 scr_printf("%s\n", buf);
601 r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
602 scr_printf("%s\n", buf);
603 strncpy(buf, attr->QRname, ROOMNAMELEN);
606 dotgoto(ipc, buf, 2, 0);
613 * un-goto the previous room, or a specified room
615 void dotungoto(CtdlIPC * ipc, char *towhere)
617 /* Find this 'towhere' room in the list ungoto from this room to
618 that at the messagepointer position in that room in our ungoto list.
619 I suppose I could be a real dick and just ungoto that many places
624 struct ctdlipcroom *rret = NULL; /* ignored */
627 if (uglistsize == 0) {
628 scr_printf("No rooms to ungoto.\n");
631 if (towhere == NULL) {
632 scr_printf("Must specify a room to ungoto.\n");
635 if (IsEmptyStr(towhere)) {
636 scr_printf("Must specify a room to ungoto.\n");
639 for (lp = uglistsize - 1; lp >= 0; lp--) {
640 if (strcasecmp(towhere, uglist[lp]) == 0) {
646 scr_printf("Room: %s not in ungoto list.\n", towhere);
650 r = CtdlIPCGotoRoom(ipc, uglist[found], "", &rret, buf);
652 free(rret); /* ignored */
654 scr_printf("%s\n", buf);
657 r = CtdlIPCSetLastRead(ipc, uglistlsn[found] ? uglistlsn[found] : 1, buf);
659 scr_printf("%s\n", buf);
661 safestrncpy(buf, uglist[found], sizeof(buf));
662 /* we queue ungoto information here, because we're not really
663 ungotoing, we're really going to a random spot in some arbitrary
665 dotgoto(ipc, buf, 0, 0);
668 void ungoto(CtdlIPC * ipc)
671 struct ctdlipcroom *rret = NULL; /* ignored */
677 r = CtdlIPCGotoRoom(ipc, uglist[uglistsize - 1], "", &rret, buf);
679 free(rret); /* ignored */
681 scr_printf("%s\n", buf);
684 r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize - 1] ? uglistlsn[uglistsize - 1] : 1, buf);
686 scr_printf("%s\n", buf);
688 safestrncpy(buf, uglist[uglistsize - 1], sizeof(buf));
690 free(uglist[uglistsize]);
691 /* Don't queue ungoto info or we end up in a loop */
692 dotgoto(ipc, buf, 0, 1);
697 * saves filelen bytes from file at pathname
699 int save_buffer(void *file, size_t filelen, const char *pathname)
702 size_t bytes_written = 0;
705 fp = fopen(pathname, "w");
707 scr_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
711 block = fwrite((char *) file + bytes_written, 1, filelen - bytes_written, fp);
712 bytes_written += block;
713 } while (errno == EINTR && bytes_written < filelen);
716 if (bytes_written < filelen) {
717 scr_printf("Trouble saving '%s': %s\n", pathname, strerror(errno));
725 * Save supplied_filename in dest directory; gets the name only
727 void destination_directory(char *dest, const char *supplied_filename)
729 static char save_dir[SIZ] = { 0 };
731 if (IsEmptyStr(save_dir)) {
732 if (getenv("HOME") == NULL) {
733 strcpy(save_dir, ".");
735 sprintf(save_dir, "%s/Desktop", getenv("HOME"));
736 if (access(save_dir, W_OK) != 0) {
737 sprintf(save_dir, "%s", getenv("HOME"));
738 if (access(save_dir, W_OK) != 0) {
739 sprintf(save_dir, ".");
745 sprintf(dest, "%s/%s", save_dir, supplied_filename);
746 strprompt("Save as", dest, PATH_MAX);
748 /* Remember the directory for next time */
749 strcpy(save_dir, dest);
750 if (strrchr(save_dir, '/') != NULL) {
751 strcpy(strrchr(save_dir, '/'), "");
753 strcpy(save_dir, ".");
759 * download() - download a file or files. The argument passed to this
760 * function determines which protocol to use.
761 * proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
763 void download(CtdlIPC * ipc, int proto)
766 char filename[PATH_MAX];
767 char tempname[PATH_MAX];
768 char transmit_cmd[SIZ];
773 void *file = NULL; /* The downloaded file */
774 size_t filelen = 0L; /* The downloaded file length */
776 if ((room_flags & QR_DOWNLOAD) == 0) {
777 scr_printf("*** You cannot download from this room.\n");
781 newprompt("Enter filename: ", filename, PATH_MAX);
783 /* Save to local disk, for folks with their own copy of the client */
785 destination_directory(tempname, filename);
786 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
788 scr_printf("%s\n", buf);
791 save_buffer(file, (size_t) extract_long(buf, 0), tempname);
796 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
798 scr_printf("%s\n", buf);
801 filelen = extract_unsigned_long(buf, 0);
803 /* Meta-download for public clients */
804 /* scr_printf("Fetching file from Citadel server...\n"); */
805 mkdir(tempdir, 0700);
806 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
807 tpipe = fopen(tempname, "wb");
808 if (fwrite(file, filelen, 1, tpipe) < filelen) {
809 /* FIXME: restart syscall on EINTR
817 /* FIXME: display internally instead */
818 snprintf(transmit_cmd, sizeof transmit_cmd,
819 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s", tempname);
820 } else if (proto == 1)
821 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
823 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
825 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
827 /* FIXME: display internally instead */
828 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
830 stty_ctdl(SB_RESTORE);
831 rv = system(transmit_cmd);
833 scr_printf("failed to download '%s': %d\n", transmit_cmd, rv);
834 stty_ctdl(SB_NO_INTR);
836 /* clean up the temporary directory */
838 ctdl_beep(); /* Beep beep! */
843 * read directory of this room
845 void roomdir(CtdlIPC * ipc)
852 char *listing = NULL; /* Returned directory listing */
855 r = CtdlIPCReadDirectory(ipc, &listing, buf);
857 scr_printf("%s\n", buf);
861 extract_token(comment, buf, 0, '|', sizeof comment);
862 extract_token(flnm, buf, 1, '|', sizeof flnm);
863 scr_printf("\nDirectory of %s on %s\n", flnm, comment);
864 scr_printf("-----------------------\n");
865 while (listing && *listing && !IsEmptyStr(listing)) {
866 extract_token(buf, listing, 0, '\n', sizeof buf);
867 remove_token(listing, 0, '\n');
869 extract_token(flnm, buf, 0, '|', sizeof flnm);
870 extract_token(flsz, buf, 1, '|', sizeof flsz);
871 extract_token(mimetype, buf, 2, '|', sizeof mimetype);
872 extract_token(comment, buf, 3, '|', sizeof comment);
873 if (strlen(flnm) <= 14)
874 scr_printf("%-14s %8s %s [%s]\n", flnm, flsz, comment, mimetype);
876 scr_printf("%s\n%14s %8s %s [%s]\n", flnm, "", flsz, comment, mimetype);
884 * add a user to a private room
886 void invite(CtdlIPC * ipc)
888 char username[USERNAME_SIZE];
891 newprompt("Name of user? ", username, USERNAME_SIZE);
892 if (username[0] == 0)
895 CtdlIPCInviteUserToRoom(ipc, username, buf);
896 scr_printf("%s\n", buf);
901 * kick a user out of a room
903 void kickout(CtdlIPC * ipc)
905 char username[USERNAME_SIZE];
908 newprompt("Name of user? ", username, USERNAME_SIZE);
909 if (username[0] == 0)
912 CtdlIPCKickoutUserFromRoom(ipc, username, buf);
913 scr_printf("%s\n", buf);
918 * aide command: kill the current room
920 void killroom(CtdlIPC * ipc)
925 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
927 scr_printf("%s\n", aaa);
931 scr_printf("Are you sure you want to kill this room? ");
935 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
936 scr_printf("%s\n", aaa);
939 dotgoto(ipc, "_BASEROOM_", 0, 0);
942 void forget(CtdlIPC * ipc)
943 { /* forget the current room */
946 scr_printf("Are you sure you want to forget this room? ");
950 remove_march(room_name, 0);
951 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
952 scr_printf("%s\n", buf);
956 /* now return to the lobby */
957 dotgoto(ipc, "_BASEROOM_", 0, 0);
964 void entroom(CtdlIPC * ipc)
967 char new_room_name[ROOMNAMELEN];
969 char new_room_pass[10];
972 int r; /* IPC response code */
974 /* Check permission to create room */
975 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
977 scr_printf("%s\n", buf);
981 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
982 if (IsEmptyStr(new_room_name)) {
985 for (a = 0; !IsEmptyStr(&new_room_name[a]); ++a) {
986 if (new_room_name[a] == '|') {
987 new_room_name[a] = '_';
991 new_room_floor = select_floor(ipc, (int) curr_floor);
993 IFNEXPERT formout(ipc, "roomaccess");
995 scr_printf("<?>Help\n"
996 "<1>Public room (shown to all users by default)\n"
997 "<2>Hidden room (accessible to anyone who knows the room name)\n"
998 "<3>Passworded room (hidden, plus requires a password to enter)\n"
999 "<4>Invitation-only room (requires access to be granted by an Admin)\n"
1000 "<5>Personal room (accessible to you only)\n" "Enter room type: ");
1003 } while (((b < '1') || (b > '5')) && (b != '?'));
1006 formout(ipc, "roomaccess");
1008 } while ((b < '1') || (b > '5'));
1009 b -= '0'; /* Portable */
1010 scr_printf("%d\n", b);
1011 new_room_type = b - 1;
1012 if (new_room_type == 2) {
1013 newprompt("Enter a room password: ", new_room_pass, 9);
1014 for (a = 0; !IsEmptyStr(&new_room_pass[a]); ++a)
1015 if (new_room_pass[a] == '|')
1016 new_room_pass[a] = '_';
1018 strcpy(new_room_pass, "");
1021 scr_printf("\042%s\042, a", new_room_name);
1023 scr_printf(" public room.");
1025 scr_printf(" hidden room.");
1027 scr_printf(" passworded room, password: %s", new_room_pass);
1029 scr_printf("n invitation-only room.");
1031 scr_printf(" personal room.");
1032 scr_printf("\nInstall it? (y/n) : ");
1037 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type, new_room_pass, new_room_floor, buf);
1039 scr_printf("%s\n", buf);
1043 /* command succeeded... now GO to the new room! */
1044 dotgoto(ipc, new_room_name, 0, 0);
1049 void readinfo(CtdlIPC * ipc)
1050 { /* read info file for current room */
1052 char room_admin_name[64];
1053 int r; /* IPC response code */
1056 /* Name of currernt room admin */
1057 r = CtdlIPCGetRoomAide(ipc, buf);
1059 safestrncpy(room_admin_name, buf, sizeof room_admin_name);
1061 strcpy(room_admin_name, "");
1063 if (!IsEmptyStr(room_admin_name))
1064 scr_printf("Room admin is %s.\n\n", room_admin_name);
1066 r = CtdlIPCRoomInfo(ipc, &text, buf);
1071 fmout(screenwidth, NULL, text, NULL, 1);
1078 * <W>ho knows room...
1080 void whoknows(CtdlIPC * ipc)
1083 char *listing = NULL;
1086 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1088 scr_printf("%s\n", buf);
1091 while (!IsEmptyStr(listing)) {
1092 extract_token(buf, listing, 0, '\n', sizeof buf);
1093 remove_token(listing, 0, '\n');
1095 scr_printf("%s\n", buf);
1101 void do_edit(CtdlIPC * ipc, char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
1105 int b, cksum, editor_exit;
1107 if (IsEmptyStr(editor_path)) {
1108 scr_printf("Do you wish to re-enter %s? ", desc);
1113 fp = fopen(temp, "w");
1116 CtdlIPC_chat_send(ipc, check_cmd);
1117 CtdlIPC_chat_recv(ipc, cmd);
1118 if (cmd[0] != '2') {
1119 scr_printf("%s\n", &cmd[4]);
1123 if (!IsEmptyStr(editor_path)) {
1124 CtdlIPC_chat_send(ipc, read_cmd);
1125 CtdlIPC_chat_recv(ipc, cmd);
1126 if (cmd[0] == '1') {
1127 fp = fopen(temp, "w");
1128 while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
1129 fprintf(fp, "%s\n", cmd);
1135 cksum = file_checksum(temp);
1137 if (!IsEmptyStr(editor_path)) {
1140 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1142 stty_ctdl(SB_RESTORE);
1143 editor_pid = fork();
1144 if (editor_pid == 0) {
1146 execlp(editor_path, editor_path, temp, NULL);
1152 b = ka_wait(&editor_exit);
1153 } while ((b != editor_pid) && (b >= 0));
1155 scr_printf("Executed %s\n", editor_path);
1158 scr_printf("Entering %s. Press return twice when finished.\n", desc);
1159 fp = fopen(temp, "r+");
1164 if (file_checksum(temp) == cksum) {
1165 scr_printf("*** Aborted.\n");
1169 CtdlIPC_chat_send(ipc, write_cmd);
1170 CtdlIPC_chat_recv(ipc, cmd);
1171 if (cmd[0] != '4') {
1172 scr_printf("%s\n", &cmd[4]);
1176 fp = fopen(temp, "r");
1177 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1178 cmd[strlen(cmd) - 1] = 0;
1179 CtdlIPC_chat_send(ipc, cmd);
1182 CtdlIPC_chat_send(ipc, "000");
1189 void enterinfo(CtdlIPC * ipc)
1190 { /* edit info file for current room */
1191 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1194 void enter_bio(CtdlIPC * ipc)
1197 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1198 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1202 * create a new floor
1204 void create_floor(CtdlIPC * ipc)
1207 char newfloorname[SIZ];
1208 int r; /* IPC response code */
1210 load_floorlist(ipc);
1212 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1213 if ((r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE)) {
1214 scr_printf("%s\n", buf);
1218 newprompt("Name for new floor: ", newfloorname, 255);
1221 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1223 scr_printf("Floor has been created.\n");
1225 scr_printf("%s\n", buf);
1228 load_floorlist(ipc);
1232 * edit the current floor
1234 void edit_floor(CtdlIPC * ipc)
1237 struct ExpirePolicy *ep = NULL;
1239 load_floorlist(ipc);
1241 /* Fetch the expire policy (this will silently fail on old servers,
1242 * resulting in "default" policy)
1244 CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1246 /* Interact with the user */
1247 scr_printf("You are editing the floor called \"%s\"\n", &floorlist[(int) curr_floor][0]);
1248 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1250 /* Angels and demons dancing in my head... */
1252 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1253 strprompt("Floor default message expire policy (? for list)", buf, 1);
1254 if (buf[0] == '?') {
1256 "0. Use the system default\n"
1257 "1. Never automatically expire messages\n"
1258 "2. Expire by message count\n" "3. Expire by message age\n");
1260 } while ((buf[0] < '0') || (buf[0] > '3'));
1261 ep->expire_mode = buf[0] - '0';
1263 /* ...lunatics and monsters underneath my bed */
1264 if (ep->expire_mode == 2) {
1265 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1266 strprompt("Keep how many messages online?", buf, 10);
1267 ep->expire_value = atol(buf);
1270 if (ep->expire_mode == 3) {
1271 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1272 strprompt("Keep messages for how many days?", buf, 10);
1273 ep->expire_value = atol(buf);
1277 CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1278 CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int) curr_floor][0], buf);
1279 scr_printf("%s\n", buf);
1280 load_floorlist(ipc);
1287 * kill the current floor
1289 void kill_floor(CtdlIPC * ipc)
1291 int floornum_to_delete, a;
1294 load_floorlist(ipc);
1296 floornum_to_delete = (-1);
1297 scr_printf("(Press return to abort)\n");
1298 newprompt("Delete which floor? ", buf, 255);
1299 if (IsEmptyStr(buf))
1301 for (a = 0; a < 128; ++a)
1302 if (!strcasecmp(&floorlist[a][0], buf))
1303 floornum_to_delete = a;
1304 if (floornum_to_delete < 0) {
1305 scr_printf("No such floor. Select one of:\n");
1306 for (a = 0; a < 128; ++a)
1307 if (floorlist[a][0] != 0)
1308 scr_printf("%s\n", &floorlist[a][0]);
1310 } while (floornum_to_delete < 0);
1311 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1312 scr_printf("%s\n", buf);
1313 load_floorlist(ipc);