1 // Client-side functions which perform room operations
3 // Copyright (c) 1987-2023 by the citadel.org team
5 // This program is open source software. Use, duplication, or disclosure is subject to the GNU General Public License version 3.
7 #include "textclient.h"
9 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
11 void stty_ctdl(int cmd);
12 void dotgoto(CtdlIPC * ipc, char *towhere, int display_name, int fromungoto);
13 void progress(CtdlIPC * ipc, unsigned long curr, unsigned long cmax);
14 int pattern(char *search, char *patn);
15 int file_checksum(char *filename);
16 int nukedir(char *dirname);
18 extern unsigned room_flags;
19 extern char room_name[];
21 extern char tempdir[];
22 extern int editor_pid;
23 extern int screenwidth;
24 extern int screenheight;
25 extern char fullname[];
26 extern char sigcaught;
27 extern char floor_mode;
28 extern char curr_floor;
33 extern char *uglist[];
34 extern long uglistlsn[];
35 extern int uglistsize;
37 extern char floorlist[128][SIZ];
40 void load_floorlist(CtdlIPC * ipc) {
44 int r; // IPC response code
46 for (a = 0; a < 128; ++a)
49 r = CtdlIPCFloorListing(ipc, &listing, buf);
51 strcpy(floorlist[0], "Main Floor");
54 while (*listing && !IsEmptyStr(listing)) {
55 extract_token(buf, listing, 0, '\n', sizeof buf);
56 remove_token(listing, 0, '\n');
57 extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', SIZ);
63 void room_tree_list(struct ctdlroomlisting *rp) {
65 char rmname[ROOMNAMELEN];
73 if (rp->lnext != NULL) {
74 room_tree_list(rp->lnext);
78 strcpy(rmname, rp->rlname);
80 if ((c + strlen(rmname) + 4) > screenwidth) {
82 // line break, check the paginator
89 else if (f & QR_PRIVATE) {
95 scr_printf("%s", rmname);
96 if (f & QR_DIRECTORY) {
102 c = c + strlen(rmname) + 3;
105 if (rp->rnext != NULL) {
106 room_tree_list(rp->rnext);
113 // Room ordering stuff (compare first by floor, then by order)
114 int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2) {
115 if ((r1 == NULL) && (r2 == NULL))
121 if (r1->rlfloor < r2->rlfloor)
123 if (r1->rlfloor > r2->rlfloor)
125 if (r1->rlorder < r2->rlorder)
127 if (r1->rlorder > r2->rlorder)
133 // Common code for all room listings
134 static void listrms(struct march *listing, int new_only, int floor_only, unsigned int flags, char *match) {
136 struct ctdlroomlisting *rl = NULL;
137 struct ctdlroomlisting *rp;
138 struct ctdlroomlisting *rs;
141 for (mptr = listing; mptr != NULL; mptr = mptr->next) {
144 if ((new_only == LISTRMS_NEW_ONLY) && ((mptr->march_access & UA_HASNEWMSGS) == 0))
147 if ((new_only == LISTRMS_OLD_ONLY) && ((mptr->march_access & UA_HASNEWMSGS) != 0))
150 if ((floor_only >= 0) && (mptr->march_floor != floor_only))
153 if (flags && (mptr->march_flags & flags) == 0)
156 if (match && (pattern(mptr->march_name, match) == -1))
160 rp = malloc(sizeof(struct ctdlroomlisting));
161 strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
162 rp->rlflags = mptr->march_flags;
163 rp->rlfloor = mptr->march_floor;
164 rp->rlorder = mptr->march_order;
174 if (rordercmp(rp, rs) < 0) {
175 if (rs->lnext == NULL) {
184 if (rs->rnext == NULL) {
197 room_tree_list(NULL);
203 void list_other_floors(void) {
207 for (a = 0; a < 128; ++a) {
208 if ((strlen(floorlist[a]) > 0) && (a != curr_floor)) {
209 if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
213 scr_printf("%s: ", floorlist[a]);
214 c = c + strlen(floorlist[a]) + 3;
220 // List known rooms. kn_floor_mode should be set to 0 for a 'flat' listing,
221 // 1 to list rooms on the current floor, or 2 to list rooms on all floors.
222 void knrooms(CtdlIPC * ipc, int kn_floor_mode) {
224 struct march *listing = NULL;
226 int r; // IPC response code
230 // Ask the server for a room list
231 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
239 if (kn_floor_mode == 0) {
241 scr_printf("\n Rooms with unread messages:\n");
242 listrms(listing, LISTRMS_NEW_ONLY, -1, 0, NULL);
244 scr_printf("\n\n No unseen messages in:\n");
245 listrms(listing, LISTRMS_OLD_ONLY, -1, 0, NULL);
249 if (kn_floor_mode == 1) {
251 scr_printf("\n Rooms with unread messages on %s:\n", floorlist[(int) curr_floor]);
252 listrms(listing, LISTRMS_NEW_ONLY, curr_floor, 0, NULL);
254 scr_printf("\n\n Rooms with no new messages on %s:\n", floorlist[(int) curr_floor]);
255 listrms(listing, LISTRMS_OLD_ONLY, curr_floor, 0, NULL);
257 scr_printf("\n\n Other floors:\n");
262 if (kn_floor_mode == 2) {
263 for (a = 0; a < 128; ++a) {
264 if (floorlist[a][0] != 0) {
266 scr_printf("\n Rooms on %s:\n", floorlist[a]);
267 listrms(listing, LISTRMS_ALL, a, 0, NULL);
273 // Free the room list
275 mptr = listing->next;
284 void listzrooms(CtdlIPC * ipc) { // list public forgotten rooms
285 struct march *listing = NULL;
287 int r; // IPC response code
291 // Ask the server for a room list
292 r = CtdlIPCKnownRooms(ipc, UnsubscribedRooms, (-1), &listing, buf);
298 scr_printf("\n Forgotten public rooms:\n");
299 listrms(listing, LISTRMS_ALL, -1, 0, NULL);
302 // Free the room list
304 mptr = listing->next;
313 // list rooms according to attribute
314 void dotknown(CtdlIPC * ipc, int what, char *match) {
315 struct march *listing = NULL;
317 int r; // IPC response code
320 // Ask the server for a room list
321 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, (-1), &listing, buf);
330 scr_printf("\n Anonymous rooms:\n");
331 listrms(listing, LISTRMS_ALL, -1, QR_ANONONLY | QR_ANONOPT, NULL);
335 scr_printf("\n Directory rooms:\n");
336 listrms(listing, LISTRMS_ALL, -1, QR_DIRECTORY, NULL);
340 scr_printf("\n Matching \"%s\" rooms:\n", match);
341 listrms(listing, LISTRMS_ALL, -1, 0, match);
345 scr_printf("\n Preferred only rooms:\n");
346 listrms(listing, LISTRMS_ALL, -1, QR_PREFONLY, NULL);
350 scr_printf("\n Private rooms:\n");
351 listrms(listing, LISTRMS_ALL, -1, QR_PRIVATE, NULL);
355 scr_printf("\n Read only rooms:\n");
356 listrms(listing, LISTRMS_ALL, -1, QR_READONLY, NULL);
361 // Free the room list
363 mptr = listing->next;
372 int set_room_attr(CtdlIPC * ipc, unsigned int ibuf, char *prompt, unsigned int sbit) {
375 a = boolprompt(prompt, (ibuf & sbit));
376 ibuf = (ibuf | sbit);
378 ibuf = (ibuf ^ sbit);
384 // Select a floor (used in several commands)
385 // The supplied argument is the 'default' floor number.
386 // This function returns the selected floor number.
387 int select_floor(CtdlIPC * ipc, int rfloor) {
391 if (floor_mode == 1) {
392 if (floorlist[(int) curr_floor][0] == 0) {
398 strncpy(floorstr, floorlist[rfloor], sizeof floorstr);
399 strprompt("Which floor", floorstr, 255);
400 for (a = 0; a < 128; ++a) {
401 if (!strcasecmp(floorstr, &floorlist[a][0]))
404 && (!strncasecmp(floorstr, &floorlist[a][0], strlen(floorstr))))
407 && (pattern(&floorlist[a][0], floorstr)
412 scr_printf("\n One of:\n");
413 for (a = 0; a < 128; ++a) {
414 if (floorlist[a][0] != 0) {
415 scr_printf("%s\n", &floorlist[a][0]);
419 } while (newfloor < 0);
424 scr_printf("Floor selection bypassed because you have floor mode disabled.\n");
431 // .<A>ide <E>dit room
432 void editthisroom(CtdlIPC * ipc) {
434 char room_admin_name[USERNAME_SIZE];
436 struct ctdlroom *attr = NULL;
437 struct ExpirePolicy *eptr = NULL;
438 int r; // IPC response code
440 // Fetch the existing room config
441 r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
443 scr_printf("%s\n", buf);
446 eptr = &(attr->QRep);
448 // Fetch the name of the current room admin
449 r = CtdlIPCGetRoomAide(ipc, buf);
451 strncpy(room_admin_name, buf, sizeof room_admin_name);
454 strcpy(room_admin_name, "");
456 if (IsEmptyStr(room_admin_name)) {
457 strcpy(room_admin_name, "none");
460 // Fetch the expire policy (this will silently fail on old servers, resulting in "default" policy)
461 r = CtdlIPCGetMessageExpirationPolicy(ipc, 0, &eptr, buf);
463 // Now interact with the user.
465 strprompt("Room name", attr->QRname, ROOMNAMELEN - 1);
466 attr->QRfloor = select_floor(ipc, attr->QRfloor);
467 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
468 if (attr->QRflags & QR_PRIVATE) {
470 set_room_attr(ipc, attr->QRflags, "Hidden room (accessible to anyone who knows the room name)", QR_GUESSNAME);
473 // if it's public, clear the privacy classes
474 if ((attr->QRflags & QR_PRIVATE) == 0) {
475 if (attr->QRflags & QR_GUESSNAME) {
476 attr->QRflags = attr->QRflags - QR_GUESSNAME;
478 if (attr->QRflags & QR_PASSWORDED) {
479 attr->QRflags = attr->QRflags - QR_PASSWORDED;
483 // if it's private, choose the privacy classes
484 if ((attr->QRflags & QR_PRIVATE)
485 && ((attr->QRflags & QR_GUESSNAME) == 0)) {
486 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Accessible by entering a password", QR_PASSWORDED);
488 if ((attr->QRflags & QR_PRIVATE)
489 && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
490 strprompt("Room password", attr->QRpasswd, 9);
493 if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
494 rbump = boolprompt("Cause current users to forget room", 0);
497 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Preferred users only", QR_PREFONLY);
498 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Read-only room", QR_READONLY);
499 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Allow message deletion by anyone who can post", QR2_COLLABDEL);
500 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Permanent room", QR_PERMANENT);
502 set_room_attr(ipc, attr->QRflags2, "Subject Required (Force users to specify a message subject)", QR2_SUBJECTREQ);
503 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Directory room", QR_DIRECTORY);
504 if (attr->QRflags & QR_DIRECTORY) {
505 strprompt("Directory name", attr->QRdirname, 14);
506 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Uploading allowed", QR_UPLOAD);
507 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Downloading allowed", QR_DOWNLOAD);
508 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Visible directory", QR_VISDIR);
510 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Self-service list subscribe/unsubscribe", QR2_SELFLIST);
511 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Allow non-subscribers to mail to this room", QR2_SMTP_PUBLIC);
512 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2, "Moderated mailing list", QR2_MODERATED);
513 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Automatically make all messages anonymous", QR_ANONONLY);
514 if ((attr->QRflags & QR_ANONONLY) == 0) {
515 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Ask users whether to make messages anonymous", QR_ANONOPT);
517 attr->QRorder = intprompt("Listing order", attr->QRorder, 0, 127);
519 // Ask about the room admin
521 strprompt("Room admin (or 'none')", room_admin_name, 29);
522 if (!strcasecmp(room_admin_name, "none")) {
523 strcpy(room_admin_name, "");
527 r = CtdlIPCQueryUsername(ipc, room_admin_name, buf);
529 scr_printf("%s\n", buf);
532 } while (r / 100 != 2);
534 // Angels and demons dancing in my head...
536 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
537 strprompt("Message expire policy (? for list)", buf, 1);
540 "0. Use the default for this floor\n"
541 "1. Never automatically expire messages\n"
542 "2. Expire by message count\n" "3. Expire by message age\n");
544 } while ((buf[0] < 48) || (buf[0] > 51));
545 attr->QRep.expire_mode = buf[0] - 48;
547 // ...lunatics and monsters underneath my bed
548 if (attr->QRep.expire_mode == 2) {
549 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
550 strprompt("Keep how many messages online?", buf, 10);
551 attr->QRep.expire_value = atol(buf);
554 if (attr->QRep.expire_mode == 3) {
555 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
556 strprompt("Keep messages for how many days?", buf, 10);
557 attr->QRep.expire_value = atol(buf);
560 // Give 'em a chance to change their minds
561 scr_printf("Save changes (y/n)? ");
564 r = CtdlIPCSetRoomAide(ipc, room_admin_name, buf);
566 scr_printf("%s\n", buf);
569 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
571 scr_printf("%s\n", buf);
574 r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
575 scr_printf("%s\n", buf);
576 strncpy(buf, attr->QRname, ROOMNAMELEN);
579 dotgoto(ipc, buf, 2, 0);
588 // un-goto the previous room, or a specified room
589 void dotungoto(CtdlIPC * ipc, char *towhere) {
590 // Find this 'towhere' room in the list ungoto from this room to
591 // that at the messagepointer position in that room in our ungoto list.
592 // I suppose I could be a real dick and just ungoto that many places
597 struct ctdlipcroom *rret = NULL; // ignored
600 if (uglistsize == 0) {
601 scr_printf("No rooms to ungoto.\n");
604 if (towhere == NULL) {
605 scr_printf("Must specify a room to ungoto.\n");
608 if (IsEmptyStr(towhere)) {
609 scr_printf("Must specify a room to ungoto.\n");
612 for (lp = uglistsize - 1; lp >= 0; lp--) {
613 if (strcasecmp(towhere, uglist[lp]) == 0) {
619 scr_printf("Room: %s not in ungoto list.\n", towhere);
623 r = CtdlIPCGotoRoom(ipc, uglist[found], "", &rret, buf);
625 free(rret); // ignored
627 scr_printf("%s\n", buf);
630 r = CtdlIPCSetLastRead(ipc, uglistlsn[found] ? uglistlsn[found] : 1, buf);
632 scr_printf("%s\n", buf);
634 strncpy(buf, uglist[found], sizeof(buf));
635 // we queue ungoto information here, because we're not really
636 // ungotoing, we're really going to a random spot in some arbitrary
638 dotgoto(ipc, buf, 0, 0);
642 void ungoto(CtdlIPC * ipc) {
644 struct ctdlipcroom *rret = NULL; // ignored
647 if (uglistsize == 0) {
651 r = CtdlIPCGotoRoom(ipc, uglist[uglistsize - 1], "", &rret, buf);
653 free(rret); // ignored
656 scr_printf("%s\n", buf);
659 r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize - 1] ? uglistlsn[uglistsize - 1] : 1, buf);
661 scr_printf("%s\n", buf);
663 strncpy(buf, uglist[uglistsize - 1], sizeof(buf));
665 free(uglist[uglistsize]);
666 // Don't queue ungoto info or we end up in a loop
667 dotgoto(ipc, buf, 0, 1);
671 // saves filelen bytes from file at pathname
672 int save_buffer(void *file, size_t filelen, const char *pathname) {
674 size_t bytes_written = 0;
677 fp = fopen(pathname, "w");
679 scr_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
683 block = fwrite((char *) file + bytes_written, 1, filelen - bytes_written, fp);
684 bytes_written += block;
685 } while (errno == EINTR && bytes_written < filelen);
688 if (bytes_written < filelen) {
689 scr_printf("Trouble saving '%s': %s\n", pathname, strerror(errno));
696 // Save supplied_filename in dest directory; gets the name only
697 void destination_directory(char *dest, const char *supplied_filename) {
698 static char save_dir[SIZ] = { 0 };
700 if (IsEmptyStr(save_dir)) {
701 if (getenv("HOME") == NULL) {
702 strcpy(save_dir, ".");
705 sprintf(save_dir, "%s/Desktop", getenv("HOME"));
706 if (access(save_dir, W_OK) != 0) {
707 sprintf(save_dir, "%s", getenv("HOME"));
708 if (access(save_dir, W_OK) != 0) {
709 sprintf(save_dir, ".");
715 sprintf(dest, "%s/%s", save_dir, supplied_filename);
716 strprompt("Save as", dest, PATH_MAX);
718 // Remember the directory for next time
719 strcpy(save_dir, dest);
720 if (strrchr(save_dir, '/') != NULL) {
721 strcpy(strrchr(save_dir, '/'), "");
724 strcpy(save_dir, ".");
729 // download() - download a file or files. The argument passed to this
730 // function determines which protocol to use.
731 // proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
732 void download(CtdlIPC * ipc, int proto) {
734 char filename[PATH_MAX];
735 char tempname[PATH_MAX];
736 char transmit_cmd[SIZ];
741 void *file = NULL; // The downloaded file
742 size_t filelen = 0L; // The downloaded file length
744 if ((room_flags & QR_DOWNLOAD) == 0) {
745 scr_printf("*** You cannot download from this room.\n");
749 newprompt("Enter filename: ", filename, PATH_MAX);
751 // Save to local disk, for folks with their own copy of the client
753 destination_directory(tempname, filename);
754 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
756 scr_printf("%s\n", buf);
759 save_buffer(file, (size_t) extract_long(buf, 0), tempname);
764 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
766 scr_printf("%s\n", buf);
769 filelen = extract_unsigned_long(buf, 0);
771 // Meta-download for public clients
772 // scr_printf("Fetching file from Citadel server...\n");
773 mkdir(tempdir, 0700);
774 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
775 tpipe = fopen(tempname, "wb");
776 if (fwrite(file, filelen, 1, tpipe) < filelen) {
777 // FIXME: restart syscall on EINTR
785 // FIXME: display internally instead
786 snprintf(transmit_cmd, sizeof transmit_cmd,
787 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s", tempname);
790 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
792 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
794 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
796 // FIXME: display internally instead
797 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
799 stty_ctdl(SB_RESTORE);
800 rv = system(transmit_cmd);
802 scr_printf("failed to download '%s': %d\n", transmit_cmd, rv);
803 stty_ctdl(SB_NO_INTR);
805 // clean up the temporary directory
807 ctdl_beep(); // Beep beep!
811 // read directory of this room
812 void roomdir(CtdlIPC * ipc) {
818 char *listing = NULL; // Returned directory listing
821 r = CtdlIPCReadDirectory(ipc, &listing, buf);
823 scr_printf("%s\n", buf);
827 extract_token(comment, buf, 0, '|', sizeof comment);
828 extract_token(flnm, buf, 1, '|', sizeof flnm);
829 scr_printf("\nDirectory of %s on %s\n", flnm, comment);
830 scr_printf("-----------------------\n");
831 while (listing && *listing && !IsEmptyStr(listing)) {
832 extract_token(buf, listing, 0, '\n', sizeof buf);
833 remove_token(listing, 0, '\n');
835 extract_token(flnm, buf, 0, '|', sizeof flnm);
836 extract_token(flsz, buf, 1, '|', sizeof flsz);
837 extract_token(mimetype, buf, 2, '|', sizeof mimetype);
838 extract_token(comment, buf, 3, '|', sizeof comment);
839 if (strlen(flnm) <= 14)
840 scr_printf("%-14s %8s %s [%s]\n", flnm, flsz, comment, mimetype);
842 scr_printf("%s\n%14s %8s %s [%s]\n", flnm, "", flsz, comment, mimetype);
849 // add a user to a private room
850 void invite(CtdlIPC * ipc) {
851 char username[USERNAME_SIZE];
854 newprompt("Name of user? ", username, USERNAME_SIZE);
855 if (username[0] == 0)
858 CtdlIPCInviteUserToRoom(ipc, username, buf);
859 scr_printf("%s\n", buf);
863 // kick a user out of a room
864 void kickout(CtdlIPC * ipc) {
865 char username[USERNAME_SIZE];
868 newprompt("Name of user? ", username, USERNAME_SIZE);
869 if (username[0] == 0)
872 CtdlIPCKickoutUserFromRoom(ipc, username, buf);
873 scr_printf("%s\n", buf);
877 // aide command: kill the current room
878 void killroom(CtdlIPC * ipc) {
882 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
884 scr_printf("%s\n", aaa);
888 scr_printf("Are you sure you want to kill this room? ");
892 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
893 scr_printf("%s\n", aaa);
896 dotgoto(ipc, "_BASEROOM_", 0, 0);
900 void forget(CtdlIPC * ipc) { // forget the current room
903 scr_printf("Are you sure you want to forget this room? ");
907 remove_march(room_name, 0);
908 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
909 scr_printf("%s\n", buf);
913 // now return to the lobby
914 dotgoto(ipc, "_BASEROOM_", 0, 0);
919 void entroom(CtdlIPC * ipc) {
921 char new_room_name[ROOMNAMELEN];
923 char new_room_pass[10];
926 int r; // IPC response code
928 // Check permission to create room
929 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
931 scr_printf("%s\n", buf);
935 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
936 if (IsEmptyStr(new_room_name)) {
939 for (a = 0; !IsEmptyStr(&new_room_name[a]); ++a) {
940 if (new_room_name[a] == '|') {
941 new_room_name[a] = '_';
945 new_room_floor = select_floor(ipc, (int) curr_floor);
947 IFNEXPERT formout(ipc, "roomaccess");
949 scr_printf("<?>Help\n"
950 "<1>Public room (shown to all users by default)\n"
951 "<2>Hidden room (accessible to anyone who knows the room name)\n"
952 "<3>Passworded room (hidden, plus requires a password to enter)\n"
953 "<4>Invitation-only room (requires access to be granted by an Admin)\n"
954 "<5>Personal room (accessible to you only)\n" "Enter room type: ");
957 } while (((b < '1') || (b > '5')) && (b != '?'));
960 formout(ipc, "roomaccess");
962 } while ((b < '1') || (b > '5'));
963 b -= '0'; // Portable
964 scr_printf("%d\n", b);
965 new_room_type = b - 1;
966 if (new_room_type == 2) {
967 newprompt("Enter a room password: ", new_room_pass, 9);
968 for (a = 0; !IsEmptyStr(&new_room_pass[a]); ++a)
969 if (new_room_pass[a] == '|')
970 new_room_pass[a] = '_';
973 strcpy(new_room_pass, "");
976 scr_printf("\042%s\042, a", new_room_name);
978 scr_printf(" public room.");
980 scr_printf(" hidden room.");
982 scr_printf(" passworded room, password: %s", new_room_pass);
984 scr_printf("n invitation-only room.");
986 scr_printf(" personal room.");
987 scr_printf("\nInstall it? (y/n) : ");
992 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type, new_room_pass, new_room_floor, buf);
994 scr_printf("%s\n", buf);
998 // command succeeded... now GO to the new room!
999 dotgoto(ipc, new_room_name, 0, 0);
1004 void readinfo(CtdlIPC * ipc) { // read info file for current room
1006 char room_admin_name[64];
1007 int r; // IPC response code
1010 // Name of currernt room admin
1011 r = CtdlIPCGetRoomAide(ipc, buf);
1013 strncpy(room_admin_name, buf, sizeof room_admin_name);
1015 strcpy(room_admin_name, "");
1017 if (!IsEmptyStr(room_admin_name))
1018 scr_printf("Room admin is %s.\n\n", room_admin_name);
1020 r = CtdlIPCRoomInfo(ipc, &text, buf);
1025 fmout(screenwidth, NULL, text, NULL, 1);
1031 // <W>ho knows room...
1032 void whoknows(CtdlIPC * ipc) {
1034 char *listing = NULL;
1037 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1039 scr_printf("%s\n", buf);
1042 while (!IsEmptyStr(listing)) {
1043 extract_token(buf, listing, 0, '\n', sizeof buf);
1044 remove_token(listing, 0, '\n');
1046 scr_printf("%s\n", buf);
1052 void do_edit(CtdlIPC * ipc, char *desc, char *read_cmd, char *check_cmd, char *write_cmd) {
1055 int b, cksum, editor_exit;
1057 if (IsEmptyStr(editor_path)) {
1058 scr_printf("Do you wish to re-enter %s? ", desc);
1063 fp = fopen(temp, "w");
1066 CtdlIPC_chat_send(ipc, check_cmd);
1067 CtdlIPC_chat_recv(ipc, cmd);
1068 if (cmd[0] != '2') {
1069 scr_printf("%s\n", &cmd[4]);
1073 if (!IsEmptyStr(editor_path)) {
1074 CtdlIPC_chat_send(ipc, read_cmd);
1075 CtdlIPC_chat_recv(ipc, cmd);
1076 if (cmd[0] == '1') {
1077 fp = fopen(temp, "w");
1078 while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
1079 fprintf(fp, "%s\n", cmd);
1085 cksum = file_checksum(temp);
1087 if (!IsEmptyStr(editor_path)) {
1090 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1092 stty_ctdl(SB_RESTORE);
1093 editor_pid = fork();
1094 if (editor_pid == 0) {
1096 execlp(editor_path, editor_path, temp, NULL);
1102 b = ka_wait(&editor_exit);
1103 } while ((b != editor_pid) && (b >= 0));
1105 scr_printf("Executed %s\n", editor_path);
1109 scr_printf("Entering %s. Press return twice when finished.\n", desc);
1110 fp = fopen(temp, "r+");
1115 if (file_checksum(temp) == cksum) {
1116 scr_printf("*** Aborted.\n");
1120 CtdlIPC_chat_send(ipc, write_cmd);
1121 CtdlIPC_chat_recv(ipc, cmd);
1122 if (cmd[0] != '4') {
1123 scr_printf("%s\n", &cmd[4]);
1127 fp = fopen(temp, "r");
1128 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1129 cmd[strlen(cmd) - 1] = 0;
1130 CtdlIPC_chat_send(ipc, cmd);
1133 CtdlIPC_chat_send(ipc, "000");
1140 // edit info file for current room
1141 void enterinfo(CtdlIPC * ipc) {
1142 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1146 void enter_bio(CtdlIPC * ipc) {
1148 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1149 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1153 // create a new floor
1154 void create_floor(CtdlIPC * ipc) {
1156 char newfloorname[SIZ];
1157 int r; // IPC response code
1159 load_floorlist(ipc);
1161 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1162 if ((r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE)) {
1163 scr_printf("%s\n", buf);
1167 newprompt("Name for new floor: ", newfloorname, 255);
1170 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1172 scr_printf("Floor has been created.\n");
1175 scr_printf("%s\n", buf);
1178 load_floorlist(ipc);
1182 // edit the current floor
1183 void edit_floor(CtdlIPC * ipc) {
1185 struct ExpirePolicy *ep = NULL;
1187 load_floorlist(ipc);
1189 // Fetch the expire policy (this will silently fail on old servers, resulting in "default" policy)
1190 CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1192 // Interact with the user
1193 scr_printf("You are editing the floor called \"%s\"\n", &floorlist[(int) curr_floor][0]);
1194 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1196 // Angels and demons dancing in my head...
1198 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1199 strprompt("Floor default message expire policy (? for list)", buf, 1);
1200 if (buf[0] == '?') {
1202 "0. Use the system default\n"
1203 "1. Never automatically expire messages\n"
1204 "2. Expire by message count\n" "3. Expire by message age\n");
1206 } while ((buf[0] < '0') || (buf[0] > '3'));
1207 ep->expire_mode = buf[0] - '0';
1209 // ...lunatics and monsters underneath my bed
1210 if (ep->expire_mode == 2) {
1211 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1212 strprompt("Keep how many messages online?", buf, 10);
1213 ep->expire_value = atol(buf);
1216 if (ep->expire_mode == 3) {
1217 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1218 strprompt("Keep messages for how many days?", buf, 10);
1219 ep->expire_value = atol(buf);
1223 CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1224 CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int) curr_floor][0], buf);
1225 scr_printf("%s\n", buf);
1226 load_floorlist(ipc);
1230 // kill the current floor
1231 void kill_floor(CtdlIPC * ipc) {
1232 int floornum_to_delete, a;
1235 load_floorlist(ipc);
1237 floornum_to_delete = (-1);
1238 scr_printf("(Press return to abort)\n");
1239 newprompt("Delete which floor? ", buf, 255);
1240 if (IsEmptyStr(buf))
1242 for (a = 0; a < 128; ++a)
1243 if (!strcasecmp(&floorlist[a][0], buf))
1244 floornum_to_delete = a;
1245 if (floornum_to_delete < 0) {
1246 scr_printf("No such floor. Select one of:\n");
1247 for (a = 0; a < 128; ++a)
1248 if (floorlist[a][0] != 0)
1249 scr_printf("%s\n", &floorlist[a][0]);
1251 } while (floornum_to_delete < 0);
1252 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1253 scr_printf("%s\n", buf);
1254 load_floorlist(ipc);