1 // Client-side functions which perform room operations
3 // Copyright (c) 1987-2022 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) {
51 int r; /* IPC response code */
53 for (a = 0; a < 128; ++a)
56 r = CtdlIPCFloorListing(ipc, &listing, buf);
58 strcpy(floorlist[0], "Main Floor");
61 while (*listing && !IsEmptyStr(listing)) {
62 extract_token(buf, listing, 0, '\n', sizeof buf);
63 remove_token(listing, 0, '\n');
64 extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', SIZ);
70 void room_tree_list(struct ctdlroomlisting *rp) {
72 char rmname[ROOMNAMELEN];
80 if (rp->lnext != NULL) {
81 room_tree_list(rp->lnext);
85 strcpy(rmname, rp->rlname);
87 if ((c + strlen(rmname) + 4) > screenwidth) {
89 /* line break, check the paginator */
96 else if (f & QR_PRIVATE) {
102 scr_printf("%s", rmname);
103 if (f & QR_DIRECTORY) {
109 c = c + strlen(rmname) + 3;
112 if (rp->rnext != NULL) {
113 room_tree_list(rp->rnext);
121 * Room ordering stuff (compare first by floor, then by order)
123 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) {
147 struct ctdlroomlisting *rl = NULL;
148 struct ctdlroomlisting *rp;
149 struct ctdlroomlisting *rs;
152 for (mptr = listing; mptr != NULL; mptr = mptr->next) {
155 if ((new_only == LISTRMS_NEW_ONLY)
156 && ((mptr->march_access & UA_HASNEWMSGS) == 0))
159 if ((new_only == LISTRMS_OLD_ONLY)
160 && ((mptr->march_access & UA_HASNEWMSGS) != 0))
163 if ((floor_only >= 0)
164 && (mptr->march_floor != floor_only))
167 if (flags && (mptr->march_flags & flags) == 0)
170 if (match && (pattern(mptr->march_name, match) == -1))
174 rp = malloc(sizeof(struct ctdlroomlisting));
175 strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
176 rp->rlflags = mptr->march_flags;
177 rp->rlfloor = mptr->march_floor;
178 rp->rlorder = mptr->march_order;
188 if (rordercmp(rp, rs) < 0) {
189 if (rs->lnext == NULL) {
198 if (rs->rnext == NULL) {
211 room_tree_list(NULL);
217 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) {
240 struct march *listing = NULL;
242 int r; /* IPC response code */
246 /* Ask the server for a room list */
247 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
255 if (kn_floor_mode == 0) {
257 scr_printf("\n Rooms with unread messages:\n");
258 listrms(listing, LISTRMS_NEW_ONLY, -1, 0, NULL);
260 scr_printf("\n\n No unseen messages in:\n");
261 listrms(listing, LISTRMS_OLD_ONLY, -1, 0, NULL);
265 if (kn_floor_mode == 1) {
267 scr_printf("\n Rooms with unread messages on %s:\n", floorlist[(int) curr_floor]);
268 listrms(listing, LISTRMS_NEW_ONLY, curr_floor, 0, NULL);
270 scr_printf("\n\n Rooms with no new messages on %s:\n", floorlist[(int) curr_floor]);
271 listrms(listing, LISTRMS_OLD_ONLY, curr_floor, 0, NULL);
273 scr_printf("\n\n Other floors:\n");
278 if (kn_floor_mode == 2) {
279 for (a = 0; a < 128; ++a) {
280 if (floorlist[a][0] != 0) {
282 scr_printf("\n Rooms on %s:\n", floorlist[a]);
283 listrms(listing, LISTRMS_ALL, a, 0, NULL);
289 /* Free the room list */
291 mptr = listing->next;
300 void listzrooms(CtdlIPC * ipc) { /* 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) { /* list rooms according to attribute */
329 struct march *listing = NULL;
331 int r; /* IPC response code */
334 /* Ask the server for a room list */
335 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, (-1), &listing, buf);
344 scr_printf("\n Anonymous rooms:\n");
345 listrms(listing, LISTRMS_ALL, -1, QR_ANONONLY | QR_ANONOPT, NULL);
349 scr_printf("\n Directory rooms:\n");
350 listrms(listing, LISTRMS_ALL, -1, QR_DIRECTORY, NULL);
354 scr_printf("\n Matching \"%s\" rooms:\n", match);
355 listrms(listing, LISTRMS_ALL, -1, 0, match);
359 scr_printf("\n Preferred only rooms:\n");
360 listrms(listing, LISTRMS_ALL, -1, QR_PREFONLY, NULL);
364 scr_printf("\n Private rooms:\n");
365 listrms(listing, LISTRMS_ALL, -1, QR_PRIVATE, NULL);
369 scr_printf("\n Read only rooms:\n");
370 listrms(listing, LISTRMS_ALL, -1, QR_READONLY, NULL);
375 /* Free the room list */
377 mptr = listing->next;
386 int set_room_attr(CtdlIPC * ipc, unsigned int ibuf, char *prompt, unsigned int sbit) {
389 a = boolprompt(prompt, (ibuf & sbit));
390 ibuf = (ibuf | sbit);
392 ibuf = (ibuf ^ sbit);
400 * Select a floor (used in several commands)
401 * The supplied argument is the 'default' floor number.
402 * This function returns the selected floor number.
404 int select_floor(CtdlIPC * ipc, int rfloor) {
408 if (floor_mode == 1) {
409 if (floorlist[(int) curr_floor][0] == 0) {
415 strncpy(floorstr, floorlist[rfloor], sizeof floorstr);
416 strprompt("Which floor", floorstr, 255);
417 for (a = 0; a < 128; ++a) {
418 if (!strcasecmp(floorstr, &floorlist[a][0]))
421 && (!strncasecmp(floorstr, &floorlist[a][0], strlen(floorstr))))
424 && (pattern(&floorlist[a][0], floorstr)
429 scr_printf("\n One of:\n");
430 for (a = 0; a < 128; ++a) {
431 if (floorlist[a][0] != 0) {
432 scr_printf("%s\n", &floorlist[a][0]);
436 } while (newfloor < 0);
441 scr_printf("Floor selection bypassed because you have " "floor mode disabled.\n");
451 * .<A>ide <E>dit room
453 void editthisroom(CtdlIPC * ipc) {
455 char room_admin_name[USERNAME_SIZE];
457 struct ctdlroom *attr = NULL;
458 struct ExpirePolicy *eptr = NULL;
459 int r; /* IPC response code */
461 /* Fetch the existing room config */
462 r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
464 scr_printf("%s\n", buf);
467 eptr = &(attr->QRep);
469 /* Fetch the name of the current room admin */
470 r = CtdlIPCGetRoomAide(ipc, buf);
472 strncpy(room_admin_name, buf, sizeof room_admin_name);
475 strcpy(room_admin_name, "");
477 if (IsEmptyStr(room_admin_name)) {
478 strcpy(room_admin_name, "none");
481 /* Fetch the expire policy (this will silently fail on old servers,
482 * resulting in "default" policy)
484 r = CtdlIPCGetMessageExpirationPolicy(ipc, 0, &eptr, buf);
486 /* Now interact with the user. */
488 strprompt("Room name", attr->QRname, ROOMNAMELEN - 1);
489 attr->QRfloor = select_floor(ipc, attr->QRfloor);
490 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
491 if (attr->QRflags & QR_PRIVATE) {
492 attr->QRflags = set_room_attr(ipc, attr->QRflags,
493 "Hidden room (accessible to anyone who knows the room name)", QR_GUESSNAME);
496 /* if it's public, clear the privacy classes */
497 if ((attr->QRflags & QR_PRIVATE) == 0) {
498 if (attr->QRflags & QR_GUESSNAME) {
499 attr->QRflags = attr->QRflags - QR_GUESSNAME;
501 if (attr->QRflags & QR_PASSWORDED) {
502 attr->QRflags = attr->QRflags - QR_PASSWORDED;
506 /* if it's private, choose the privacy classes */
507 if ((attr->QRflags & QR_PRIVATE)
508 && ((attr->QRflags & QR_GUESSNAME) == 0)) {
509 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Accessible by entering a password", QR_PASSWORDED);
511 if ((attr->QRflags & QR_PRIVATE)
512 && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
513 strprompt("Room password", attr->QRpasswd, 9);
516 if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
517 rbump = boolprompt("Cause current users to forget room", 0);
520 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Preferred users only", QR_PREFONLY);
521 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Read-only room", QR_READONLY);
522 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Allow message deletion by anyone who can post", QR2_COLLABDEL);
523 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Permanent room", QR_PERMANENT);
525 set_room_attr(ipc, attr->QRflags2, "Subject Required (Force users to specify a message subject)", QR2_SUBJECTREQ);
526 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Directory room", QR_DIRECTORY);
527 if (attr->QRflags & QR_DIRECTORY) {
528 strprompt("Directory name", attr->QRdirname, 14);
529 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Uploading allowed", QR_UPLOAD);
530 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Downloading allowed", QR_DOWNLOAD);
531 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Visible directory", QR_VISDIR);
533 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Self-service list subscribe/unsubscribe", QR2_SELFLIST);
534 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Allow non-subscribers to mail to this room", QR2_SMTP_PUBLIC);
535 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Moderated mailing list", QR2_MODERATED);
536 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Automatically make all messages anonymous", QR_ANONONLY);
537 if ((attr->QRflags & QR_ANONONLY) == 0) {
538 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Ask users whether to make messages anonymous", QR_ANONOPT);
540 attr->QRorder = intprompt("Listing order", attr->QRorder, 0, 127);
542 /* Ask about the room admin */
544 strprompt("Room admin (or 'none')", room_admin_name, 29);
545 if (!strcasecmp(room_admin_name, "none")) {
546 strcpy(room_admin_name, "");
550 r = CtdlIPCQueryUsername(ipc, room_admin_name, buf);
552 scr_printf("%s\n", buf);
555 } while (r / 100 != 2);
557 /* Angels and demons dancing in my head... */
559 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
560 strprompt("Message expire policy (? for list)", buf, 1);
563 "0. Use the default for this floor\n"
564 "1. Never automatically expire messages\n"
565 "2. Expire by message count\n" "3. Expire by message age\n");
567 } while ((buf[0] < 48) || (buf[0] > 51));
568 attr->QRep.expire_mode = buf[0] - 48;
570 /* ...lunatics and monsters underneath my bed */
571 if (attr->QRep.expire_mode == 2) {
572 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
573 strprompt("Keep how many messages online?", buf, 10);
574 attr->QRep.expire_value = atol(buf);
577 if (attr->QRep.expire_mode == 3) {
578 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
579 strprompt("Keep messages for how many days?", buf, 10);
580 attr->QRep.expire_value = atol(buf);
583 /* Give 'em a chance to change their minds */
584 scr_printf("Save changes (y/n)? ");
587 r = CtdlIPCSetRoomAide(ipc, room_admin_name, buf);
589 scr_printf("%s\n", buf);
592 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
594 scr_printf("%s\n", buf);
597 r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
598 scr_printf("%s\n", buf);
599 strncpy(buf, attr->QRname, ROOMNAMELEN);
602 dotgoto(ipc, buf, 2, 0);
612 * un-goto the previous room, or a specified room
614 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 strncpy(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);
667 void ungoto(CtdlIPC * ipc) {
669 struct ctdlipcroom *rret = NULL; // ignored
672 if (uglistsize == 0) {
676 r = CtdlIPCGotoRoom(ipc, uglist[uglistsize - 1], "", &rret, buf);
678 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 strncpy(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) {
701 size_t bytes_written = 0;
704 fp = fopen(pathname, "w");
706 scr_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
710 block = fwrite((char *) file + bytes_written, 1, filelen - bytes_written, fp);
711 bytes_written += block;
712 } while (errno == EINTR && bytes_written < filelen);
715 if (bytes_written < filelen) {
716 scr_printf("Trouble saving '%s': %s\n", pathname, strerror(errno));
724 * Save supplied_filename in dest directory; gets the name only
726 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, ".");
734 sprintf(save_dir, "%s/Desktop", getenv("HOME"));
735 if (access(save_dir, W_OK) != 0) {
736 sprintf(save_dir, "%s", getenv("HOME"));
737 if (access(save_dir, W_OK) != 0) {
738 sprintf(save_dir, ".");
744 sprintf(dest, "%s/%s", save_dir, supplied_filename);
745 strprompt("Save as", dest, PATH_MAX);
747 /* Remember the directory for next time */
748 strcpy(save_dir, dest);
749 if (strrchr(save_dir, '/') != NULL) {
750 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) {
765 char filename[PATH_MAX];
766 char tempname[PATH_MAX];
767 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);
822 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
824 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
826 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
828 /* FIXME: display internally instead */
829 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
831 stty_ctdl(SB_RESTORE);
832 rv = system(transmit_cmd);
834 scr_printf("failed to download '%s': %d\n", transmit_cmd, rv);
835 stty_ctdl(SB_NO_INTR);
837 /* clean up the temporary directory */
839 ctdl_beep(); /* Beep beep! */
844 * read directory of this room
846 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) {
887 char username[USERNAME_SIZE];
890 newprompt("Name of user? ", username, USERNAME_SIZE);
891 if (username[0] == 0)
894 CtdlIPCInviteUserToRoom(ipc, username, buf);
895 scr_printf("%s\n", buf);
900 * kick a user out of a room
902 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) {
922 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
924 scr_printf("%s\n", aaa);
928 scr_printf("Are you sure you want to kill this room? ");
932 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
933 scr_printf("%s\n", aaa);
936 dotgoto(ipc, "_BASEROOM_", 0, 0);
939 void forget(CtdlIPC * ipc) { /* forget the current room */
942 scr_printf("Are you sure you want to forget this room? ");
946 remove_march(room_name, 0);
947 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
948 scr_printf("%s\n", buf);
952 /* now return to the lobby */
953 dotgoto(ipc, "_BASEROOM_", 0, 0);
960 void entroom(CtdlIPC * ipc) {
962 char new_room_name[ROOMNAMELEN];
964 char new_room_pass[10];
967 int r; /* IPC response code */
969 /* Check permission to create room */
970 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
972 scr_printf("%s\n", buf);
976 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
977 if (IsEmptyStr(new_room_name)) {
980 for (a = 0; !IsEmptyStr(&new_room_name[a]); ++a) {
981 if (new_room_name[a] == '|') {
982 new_room_name[a] = '_';
986 new_room_floor = select_floor(ipc, (int) curr_floor);
988 IFNEXPERT formout(ipc, "roomaccess");
990 scr_printf("<?>Help\n"
991 "<1>Public room (shown to all users by default)\n"
992 "<2>Hidden room (accessible to anyone who knows the room name)\n"
993 "<3>Passworded room (hidden, plus requires a password to enter)\n"
994 "<4>Invitation-only room (requires access to be granted by an Admin)\n"
995 "<5>Personal room (accessible to you only)\n" "Enter room type: ");
998 } while (((b < '1') || (b > '5')) && (b != '?'));
1001 formout(ipc, "roomaccess");
1003 } while ((b < '1') || (b > '5'));
1004 b -= '0'; /* Portable */
1005 scr_printf("%d\n", b);
1006 new_room_type = b - 1;
1007 if (new_room_type == 2) {
1008 newprompt("Enter a room password: ", new_room_pass, 9);
1009 for (a = 0; !IsEmptyStr(&new_room_pass[a]); ++a)
1010 if (new_room_pass[a] == '|')
1011 new_room_pass[a] = '_';
1014 strcpy(new_room_pass, "");
1017 scr_printf("\042%s\042, a", new_room_name);
1019 scr_printf(" public room.");
1021 scr_printf(" hidden room.");
1023 scr_printf(" passworded room, password: %s", new_room_pass);
1025 scr_printf("n invitation-only room.");
1027 scr_printf(" personal room.");
1028 scr_printf("\nInstall it? (y/n) : ");
1033 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type, new_room_pass, new_room_floor, buf);
1035 scr_printf("%s\n", buf);
1039 /* command succeeded... now GO to the new room! */
1040 dotgoto(ipc, new_room_name, 0, 0);
1045 void readinfo(CtdlIPC * ipc) { /* read info file for current room */
1047 char room_admin_name[64];
1048 int r; /* IPC response code */
1051 /* Name of currernt room admin */
1052 r = CtdlIPCGetRoomAide(ipc, buf);
1054 strncpy(room_admin_name, buf, sizeof room_admin_name);
1056 strcpy(room_admin_name, "");
1058 if (!IsEmptyStr(room_admin_name))
1059 scr_printf("Room admin is %s.\n\n", room_admin_name);
1061 r = CtdlIPCRoomInfo(ipc, &text, buf);
1066 fmout(screenwidth, NULL, text, NULL, 1);
1073 * <W>ho knows room...
1075 void whoknows(CtdlIPC * ipc) {
1077 char *listing = NULL;
1080 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1082 scr_printf("%s\n", buf);
1085 while (!IsEmptyStr(listing)) {
1086 extract_token(buf, listing, 0, '\n', sizeof buf);
1087 remove_token(listing, 0, '\n');
1089 scr_printf("%s\n", buf);
1095 void do_edit(CtdlIPC * ipc, char *desc, char *read_cmd, char *check_cmd, char *write_cmd) {
1098 int b, cksum, editor_exit;
1100 if (IsEmptyStr(editor_path)) {
1101 scr_printf("Do you wish to re-enter %s? ", desc);
1106 fp = fopen(temp, "w");
1109 CtdlIPC_chat_send(ipc, check_cmd);
1110 CtdlIPC_chat_recv(ipc, cmd);
1111 if (cmd[0] != '2') {
1112 scr_printf("%s\n", &cmd[4]);
1116 if (!IsEmptyStr(editor_path)) {
1117 CtdlIPC_chat_send(ipc, read_cmd);
1118 CtdlIPC_chat_recv(ipc, cmd);
1119 if (cmd[0] == '1') {
1120 fp = fopen(temp, "w");
1121 while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
1122 fprintf(fp, "%s\n", cmd);
1128 cksum = file_checksum(temp);
1130 if (!IsEmptyStr(editor_path)) {
1133 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1135 stty_ctdl(SB_RESTORE);
1136 editor_pid = fork();
1137 if (editor_pid == 0) {
1139 execlp(editor_path, editor_path, temp, NULL);
1145 b = ka_wait(&editor_exit);
1146 } while ((b != editor_pid) && (b >= 0));
1148 scr_printf("Executed %s\n", editor_path);
1152 scr_printf("Entering %s. Press return twice when finished.\n", desc);
1153 fp = fopen(temp, "r+");
1158 if (file_checksum(temp) == cksum) {
1159 scr_printf("*** Aborted.\n");
1163 CtdlIPC_chat_send(ipc, write_cmd);
1164 CtdlIPC_chat_recv(ipc, cmd);
1165 if (cmd[0] != '4') {
1166 scr_printf("%s\n", &cmd[4]);
1170 fp = fopen(temp, "r");
1171 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1172 cmd[strlen(cmd) - 1] = 0;
1173 CtdlIPC_chat_send(ipc, cmd);
1176 CtdlIPC_chat_send(ipc, "000");
1183 void enterinfo(CtdlIPC * ipc) { /* edit info file for current room */
1184 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1187 void enter_bio(CtdlIPC * ipc) {
1189 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1190 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1194 * create a new floor
1196 void create_floor(CtdlIPC * ipc) {
1198 char newfloorname[SIZ];
1199 int r; /* IPC response code */
1201 load_floorlist(ipc);
1203 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1204 if ((r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE)) {
1205 scr_printf("%s\n", buf);
1209 newprompt("Name for new floor: ", newfloorname, 255);
1212 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1214 scr_printf("Floor has been created.\n");
1217 scr_printf("%s\n", buf);
1220 load_floorlist(ipc);
1224 * edit the current floor
1226 void edit_floor(CtdlIPC * ipc) {
1228 struct ExpirePolicy *ep = NULL;
1230 load_floorlist(ipc);
1232 /* Fetch the expire policy (this will silently fail on old servers,
1233 * resulting in "default" policy)
1235 CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1237 /* Interact with the user */
1238 scr_printf("You are editing the floor called \"%s\"\n", &floorlist[(int) curr_floor][0]);
1239 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1241 /* Angels and demons dancing in my head... */
1243 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1244 strprompt("Floor default message expire policy (? for list)", buf, 1);
1245 if (buf[0] == '?') {
1247 "0. Use the system default\n"
1248 "1. Never automatically expire messages\n"
1249 "2. Expire by message count\n" "3. Expire by message age\n");
1251 } while ((buf[0] < '0') || (buf[0] > '3'));
1252 ep->expire_mode = buf[0] - '0';
1254 /* ...lunatics and monsters underneath my bed */
1255 if (ep->expire_mode == 2) {
1256 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1257 strprompt("Keep how many messages online?", buf, 10);
1258 ep->expire_value = atol(buf);
1261 if (ep->expire_mode == 3) {
1262 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1263 strprompt("Keep messages for how many days?", buf, 10);
1264 ep->expire_value = atol(buf);
1268 CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1269 CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int) curr_floor][0], buf);
1270 scr_printf("%s\n", buf);
1271 load_floorlist(ipc);
1278 * kill the current floor
1280 void kill_floor(CtdlIPC * ipc) {
1281 int floornum_to_delete, a;
1284 load_floorlist(ipc);
1286 floornum_to_delete = (-1);
1287 scr_printf("(Press return to abort)\n");
1288 newprompt("Delete which floor? ", buf, 255);
1289 if (IsEmptyStr(buf))
1291 for (a = 0; a < 128; ++a)
1292 if (!strcasecmp(&floorlist[a][0], buf))
1293 floornum_to_delete = a;
1294 if (floornum_to_delete < 0) {
1295 scr_printf("No such floor. Select one of:\n");
1296 for (a = 0; a < 128; ++a)
1297 if (floorlist[a][0] != 0)
1298 scr_printf("%s\n", &floorlist[a][0]);
1300 } while (floornum_to_delete < 0);
1301 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1302 scr_printf("%s\n", buf);
1303 load_floorlist(ipc);