2 * Client-side functions which perform room operations
4 * Copyright (c) 1987-2016 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
23 #include <sys/types.h>
28 #include <libcitadel.h>
29 #include "citadel_ipc.h"
30 #include "citadel_decls.h"
34 #include "tuiconfig.h"
37 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
40 void stty_ctdl(int cmd);
41 void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto);
42 void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax);
43 int pattern(char *search, char *patn);
44 int file_checksum(char *filename);
45 int nukedir(char *dirname);
47 extern unsigned room_flags;
48 extern char room_name[];
50 extern char tempdir[];
51 extern int editor_pid;
52 extern int screenwidth;
53 extern int screenheight;
54 extern char fullname[];
55 extern char sigcaught;
56 extern char floor_mode;
57 extern char curr_floor;
62 extern char *uglist[];
63 extern long uglistlsn[];
64 extern int uglistsize;
66 extern char floorlist[128][SIZ];
69 void load_floorlist(CtdlIPC *ipc)
74 int r; /* IPC response code */
76 for (a = 0; a < 128; ++a)
79 r = CtdlIPCFloorListing(ipc, &listing, buf);
81 strcpy(floorlist[0], "Main Floor");
84 while (*listing && !IsEmptyStr(listing)) {
85 extract_token(buf, listing, 0, '\n', sizeof buf);
86 remove_token(listing, 0, '\n');
87 extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', SIZ);
93 void room_tree_list(struct ctdlroomlisting *rp)
96 char rmname[ROOMNAMELEN];
104 if (rp->lnext != NULL) {
105 room_tree_list(rp->lnext);
108 if (sigcaught == 0) {
109 strcpy(rmname, rp->rlname);
111 if ((c + strlen(rmname) + 4) > screenwidth) {
113 /* line break, check the paginator */
117 if (f & QR_MAILBOX) {
118 color(BRIGHT_YELLOW);
119 } else if (f & QR_PRIVATE) {
124 scr_printf("%s", rmname);
125 if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
127 else if (f & QR_DIRECTORY)
129 else if (f & QR_NETWORK)
133 c = c + strlen(rmname) + 3;
136 if (rp->rnext != NULL) {
137 room_tree_list(rp->rnext);
145 * Room ordering stuff (compare first by floor, then by order)
147 int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2)
149 if ((r1 == NULL) && (r2 == NULL))
155 if (r1->rlfloor < r2->rlfloor)
157 if (r1->rlfloor > r2->rlfloor)
159 if (r1->rlorder < r2->rlorder)
161 if (r1->rlorder > r2->rlorder)
168 * Common code for all room listings
170 static void listrms(struct march *listing, int new_only, int floor_only, unsigned int flags, char *match)
173 struct ctdlroomlisting *rl = NULL;
174 struct ctdlroomlisting *rp;
175 struct ctdlroomlisting *rs;
178 for (mptr = listing; mptr != NULL; mptr = mptr->next) {
181 if ( (new_only == LISTRMS_NEW_ONLY)
182 && ((mptr->march_access & UA_HASNEWMSGS) == 0))
185 if ( (new_only == LISTRMS_OLD_ONLY)
186 && ((mptr->march_access & UA_HASNEWMSGS) != 0))
189 if ( (floor_only >= 0)
190 && (mptr->march_floor != floor_only))
193 if (flags && (mptr->march_flags & flags) == 0)
196 if (match && (pattern(mptr->march_name, match) == -1))
200 rp = malloc(sizeof(struct ctdlroomlisting));
201 strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
202 rp->rlflags = mptr->march_flags;
203 rp->rlfloor = mptr->march_floor;
204 rp->rlorder = mptr->march_order;
213 if (rordercmp(rp, rs) < 0) {
214 if (rs->lnext == NULL) {
221 if (rs->rnext == NULL) {
233 room_tree_list(NULL);
239 void list_other_floors(void)
244 for (a = 0; a < 128; ++a) {
245 if ((strlen(floorlist[a]) > 0) && (a != curr_floor)) {
246 if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
250 scr_printf("%s: ", floorlist[a]);
251 c = c + strlen(floorlist[a]) + 3;
258 * List known rooms. kn_floor_mode should be set to 0 for a 'flat' listing,
259 * 1 to list rooms on the current floor, or 2 to list rooms on all floors.
261 void knrooms(CtdlIPC *ipc, int kn_floor_mode)
264 struct march *listing = NULL;
266 int r; /* IPC response code */
270 /* Ask the server for a room list */
271 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
279 if (kn_floor_mode == 0) {
281 scr_printf("\n Rooms with unread messages:\n");
282 listrms(listing, LISTRMS_NEW_ONLY, -1, 0, NULL);
284 scr_printf("\n\n No unseen messages in:\n");
285 listrms(listing, LISTRMS_OLD_ONLY, -1, 0, NULL);
289 if (kn_floor_mode == 1) {
291 scr_printf("\n Rooms with unread messages on %s:\n",
292 floorlist[(int) curr_floor]);
293 listrms(listing, LISTRMS_NEW_ONLY, curr_floor, 0, NULL);
295 scr_printf("\n\n Rooms with no new messages on %s:\n",
296 floorlist[(int) curr_floor]);
297 listrms(listing, LISTRMS_OLD_ONLY, curr_floor, 0, NULL);
299 scr_printf("\n\n Other floors:\n");
304 if (kn_floor_mode == 2) {
305 for (a = 0; a < 128; ++a) {
306 if (floorlist[a][0] != 0) {
308 scr_printf("\n Rooms on %s:\n",
310 listrms(listing, LISTRMS_ALL, a, 0, NULL);
316 /* Free the room list */
318 mptr = listing->next;
327 void listzrooms(CtdlIPC *ipc)
328 { /* list public forgotten rooms */
329 struct march *listing = NULL;
331 int r; /* IPC response code */
335 /* Ask the server for a room list */
336 r = CtdlIPCKnownRooms(ipc, UnsubscribedRooms, (-1), &listing, buf);
342 scr_printf("\n Forgotten public rooms:\n");
343 listrms(listing, LISTRMS_ALL, -1, 0, NULL);
346 /* Free the room list */
348 mptr = listing->next;
356 void dotknown(CtdlIPC *ipc, int what, char *match)
357 { /* list rooms according to attribute */
358 struct march *listing = NULL;
360 int r; /* IPC response code */
363 /* Ask the server for a room list */
364 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, (-1), &listing, buf);
373 scr_printf("\n Anonymous rooms:\n");
374 listrms(listing, LISTRMS_ALL, -1, QR_ANONONLY|QR_ANONOPT, NULL);
378 scr_printf("\n Directory rooms:\n");
379 listrms(listing, LISTRMS_ALL, -1, QR_DIRECTORY, NULL);
383 scr_printf("\n Matching \"%s\" rooms:\n", match);
384 listrms(listing, LISTRMS_ALL, -1, 0, match);
388 scr_printf("\n Preferred only rooms:\n");
389 listrms(listing, LISTRMS_ALL, -1, QR_PREFONLY, NULL);
393 scr_printf("\n Private rooms:\n");
394 listrms(listing, LISTRMS_ALL, -1, QR_PRIVATE, NULL);
398 scr_printf("\n Read only rooms:\n");
399 listrms(listing, LISTRMS_ALL, -1, QR_READONLY, NULL);
403 scr_printf("\n Shared rooms:\n");
404 listrms(listing, LISTRMS_ALL, -1, QR_NETWORK, NULL);
409 /* Free the room list */
411 mptr = listing->next;
420 int set_room_attr(CtdlIPC *ipc, unsigned int ibuf, char *prompt, unsigned int sbit)
424 a = boolprompt(prompt, (ibuf & sbit));
425 ibuf = (ibuf | sbit);
427 ibuf = (ibuf ^ sbit);
435 * Select a floor (used in several commands)
436 * The supplied argument is the 'default' floor number.
437 * This function returns the selected floor number.
439 int select_floor(CtdlIPC *ipc, int rfloor)
444 if (floor_mode == 1) {
445 if (floorlist[(int) curr_floor][0] == 0) {
451 safestrncpy(floorstr, floorlist[rfloor],
453 strprompt("Which floor", floorstr, 255);
454 for (a = 0; a < 128; ++a) {
456 (floorstr, &floorlist[a][0]))
461 (floorstr, &floorlist[a][0],
465 && (pattern(&floorlist[a][0], floorstr)
470 scr_printf("\n One of:\n");
471 for (a = 0; a < 128; ++a) {
472 if (floorlist[a][0] != 0) {
478 } while (newfloor < 0);
483 scr_printf("Floor selection bypassed because you have "
484 "floor mode disabled.\n");
494 * .<A>ide <E>dit room
496 void editthisroom(CtdlIPC *ipc)
499 char room_admin_name[USERNAME_SIZE];
501 struct ctdlroom *attr = NULL;
502 struct ExpirePolicy *eptr = NULL;
503 int r; /* IPC response code */
505 /* Fetch the existing room config */
506 r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
508 scr_printf("%s\n", buf);
511 eptr = &(attr->QRep);
513 /* Fetch the name of the current room admin */
514 r = CtdlIPCGetRoomAide(ipc, buf);
516 safestrncpy(room_admin_name, buf, sizeof room_admin_name);
518 strcpy(room_admin_name, "");
520 if (IsEmptyStr(room_admin_name)) {
521 strcpy(room_admin_name, "none");
524 /* Fetch the expire policy (this will silently fail on old servers,
525 * resulting in "default" policy)
527 r = CtdlIPCGetMessageExpirationPolicy(ipc, 0, &eptr, buf);
529 /* Now interact with the user. */
531 strprompt("Room name", attr->QRname, ROOMNAMELEN-1);
532 attr->QRfloor = select_floor(ipc, attr->QRfloor);
533 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
534 if (attr->QRflags & QR_PRIVATE) {
535 attr->QRflags = set_room_attr(ipc, attr->QRflags,
536 "Hidden room (accessible to anyone who knows the room name)",
540 /* if it's public, clear the privacy classes */
541 if ((attr->QRflags & QR_PRIVATE) == 0) {
542 if (attr->QRflags & QR_GUESSNAME) {
543 attr->QRflags = attr->QRflags - QR_GUESSNAME;
545 if (attr->QRflags & QR_PASSWORDED) {
546 attr->QRflags = attr->QRflags - QR_PASSWORDED;
550 /* if it's private, choose the privacy classes */
551 if ((attr->QRflags & QR_PRIVATE)
552 && ((attr->QRflags & QR_GUESSNAME) == 0)) {
553 attr->QRflags = set_room_attr(ipc, attr->QRflags,
554 "Accessible by entering a password",
557 if ((attr->QRflags & QR_PRIVATE)
558 && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
559 strprompt("Room password", attr->QRpasswd, 9);
562 if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
563 rbump = boolprompt("Cause current users to forget room", 0);
566 attr->QRflags = set_room_attr(ipc, attr->QRflags,
567 "Preferred users only", QR_PREFONLY);
568 attr->QRflags = set_room_attr(ipc, attr->QRflags,
569 "Read-only room", QR_READONLY);
570 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
571 "Allow message deletion by anyone who can post",
573 attr->QRflags = set_room_attr(ipc, attr->QRflags,
574 "Permanent room", QR_PERMANENT);
575 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
576 "Subject Required (Force "
577 "users to specify a message "
578 "subject)", QR2_SUBJECTREQ);
579 attr->QRflags = set_room_attr(ipc, attr->QRflags,
580 "Directory room", QR_DIRECTORY);
581 if (attr->QRflags & QR_DIRECTORY) {
582 strprompt("Directory name", attr->QRdirname, 14);
584 set_room_attr(ipc, attr->QRflags,
585 "Uploading allowed", QR_UPLOAD);
587 set_room_attr(ipc, attr->QRflags, "Downloading allowed",
590 set_room_attr(ipc, attr->QRflags,
591 "Visible directory", QR_VISDIR);
593 attr->QRflags = set_room_attr(ipc, attr->QRflags,
594 "Network shared room", QR_NETWORK);
595 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
596 "Self-service list subscribe/unsubscribe",
598 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
599 "public posting to this room via room_roomname@yourcitadel.org",
601 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
602 "moderated mailinglist",
604 attr->QRflags = set_room_attr(ipc, attr->QRflags,
605 "Automatically make all messages anonymous",
607 if ((attr->QRflags & QR_ANONONLY) == 0) {
608 attr->QRflags = set_room_attr(ipc, attr->QRflags,
609 "Ask users whether to make messages anonymous",
612 attr->QRorder = intprompt("Listing order", attr->QRorder, 0, 127);
614 /* Ask about the room admin */
616 strprompt("Room admin (or 'none')", room_admin_name, 29);
617 if (!strcasecmp(room_admin_name, "none")) {
618 strcpy(room_admin_name, "");
621 r = CtdlIPCQueryUsername(ipc, room_admin_name, buf);
623 scr_printf("%s\n", buf);
625 } while (r / 100 != 2);
627 /* Angels and demons dancing in my head... */
629 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
630 strprompt("Message expire policy (? for list)", buf, 1);
633 "0. Use the default for this floor\n"
634 "1. Never automatically expire messages\n"
635 "2. Expire by message count\n"
636 "3. Expire by message age\n");
638 } while ((buf[0] < 48) || (buf[0] > 51));
639 attr->QRep.expire_mode = buf[0] - 48;
641 /* ...lunatics and monsters underneath my bed */
642 if (attr->QRep.expire_mode == 2) {
643 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
644 strprompt("Keep how many messages online?", buf, 10);
645 attr->QRep.expire_value = atol(buf);
648 if (attr->QRep.expire_mode == 3) {
649 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
650 strprompt("Keep messages for how many days?", buf, 10);
651 attr->QRep.expire_value = atol(buf);
654 /* Give 'em a chance to change their minds */
655 scr_printf("Save changes (y/n)? ");
658 r = CtdlIPCSetRoomAide(ipc, room_admin_name, buf);
660 scr_printf("%s\n", buf);
663 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
665 scr_printf("%s\n", buf);
668 r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
669 scr_printf("%s\n", buf);
670 strncpy(buf, attr->QRname, ROOMNAMELEN);
673 dotgoto(ipc, buf, 2, 0);
680 * un-goto the previous room, or a specified room
682 void dotungoto(CtdlIPC *ipc, char *towhere)
684 /* Find this 'towhere' room in the list ungoto from this room to
685 that at the messagepointer position in that room in our ungoto list.
686 I suppose I could be a real dick and just ungoto that many places
691 struct ctdlipcroom *rret = NULL; /* ignored */
696 scr_printf("No rooms to ungoto.\n");
701 scr_printf("Must specify a room to ungoto.\n");
704 if (IsEmptyStr(towhere))
706 scr_printf("Must specify a room to ungoto.\n");
709 for (lp = uglistsize-1; lp >= 0; lp--)
711 if (strcasecmp(towhere, uglist[lp]) == 0)
719 scr_printf("Room: %s not in ungoto list.\n", towhere);
723 r = CtdlIPCGotoRoom(ipc, uglist[found], "", &rret, buf);
724 if (rret) free(rret); /* ignored */
726 scr_printf("%s\n", buf);
729 r = CtdlIPCSetLastRead(ipc, uglistlsn[found] ? uglistlsn[found] : 1, buf);
731 scr_printf("%s\n", buf);
733 safestrncpy(buf, uglist[found], sizeof(buf));
734 /* we queue ungoto information here, because we're not really
735 ungotoing, we're really going to a random spot in some arbitrary
737 dotgoto(ipc, buf, 0, 0);
740 void ungoto(CtdlIPC *ipc)
743 struct ctdlipcroom *rret = NULL; /* ignored */
749 r = CtdlIPCGotoRoom(ipc, uglist[uglistsize-1], "", &rret, buf);
750 if (rret) free(rret); /* ignored */
752 scr_printf("%s\n", buf);
755 r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize-1] ? uglistlsn[uglistsize-1] : 1, buf);
757 scr_printf("%s\n", buf);
759 safestrncpy(buf, uglist[uglistsize-1], sizeof(buf));
761 free(uglist[uglistsize]);
762 /* Don't queue ungoto info or we end up in a loop */
763 dotgoto(ipc, buf, 0, 1);
768 * saves filelen bytes from file at pathname
770 int save_buffer(void *file, size_t filelen, const char *pathname)
773 size_t bytes_written = 0;
776 fp = fopen(pathname, "w");
778 scr_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
782 block = fwrite((char *)file + bytes_written, 1,
783 filelen - bytes_written, fp);
784 bytes_written += block;
785 } while (errno == EINTR && bytes_written < filelen);
788 if (bytes_written < filelen) {
789 scr_printf("Trouble saving '%s': %s\n", pathname,
798 * Save supplied_filename in dest directory; gets the name only
800 void destination_directory(char *dest, const char *supplied_filename)
802 static char save_dir[SIZ] = { 0 };
804 if (IsEmptyStr(save_dir)) {
805 if (getenv("HOME") == NULL) {
806 strcpy(save_dir, ".");
809 sprintf(save_dir, "%s/Desktop", getenv("HOME"));
810 if (access(save_dir, W_OK) != 0) {
811 sprintf(save_dir, "%s", getenv("HOME"));
812 if (access(save_dir, W_OK) != 0) {
813 sprintf(save_dir, ".");
819 sprintf(dest, "%s/%s", save_dir, supplied_filename);
820 strprompt("Save as", dest, PATH_MAX);
822 /* Remember the directory for next time */
823 strcpy(save_dir, dest);
824 if (strrchr(save_dir, '/') != NULL) {
825 strcpy(strrchr(save_dir, '/'), "");
828 strcpy(save_dir, ".");
834 * download() - download a file or files. The argument passed to this
835 * function determines which protocol to use.
836 * proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
838 void download(CtdlIPC *ipc, int proto)
841 char filename[PATH_MAX];
842 char tempname[PATH_MAX];
843 char transmit_cmd[SIZ];
848 void *file = NULL; /* The downloaded file */
849 size_t filelen = 0L; /* The downloaded file length */
851 if ((room_flags & QR_DOWNLOAD) == 0) {
852 scr_printf("*** You cannot download from this room.\n");
856 newprompt("Enter filename: ", filename, PATH_MAX);
858 /* Save to local disk, for folks with their own copy of the client */
860 destination_directory(tempname, filename);
861 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
863 scr_printf("%s\n", buf);
866 save_buffer(file, (size_t)extract_long(buf, 0), tempname);
871 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
873 scr_printf("%s\n", buf);
876 filelen = extract_unsigned_long(buf, 0);
878 /* Meta-download for public clients */
879 /* scr_printf("Fetching file from Citadel server...\n"); */
880 mkdir(tempdir, 0700);
881 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
882 tpipe = fopen(tempname, "wb");
883 if (fwrite(file, filelen, 1, tpipe) < filelen) {
884 /* FIXME: restart syscall on EINTR
888 if (file) free(file);
891 /* FIXME: display internally instead */
892 snprintf(transmit_cmd, sizeof transmit_cmd,
893 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",
897 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
899 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
901 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
903 /* FIXME: display internally instead */
904 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
906 stty_ctdl(SB_RESTORE);
907 rv = system(transmit_cmd);
909 scr_printf("failed to download '%s': %d\n", transmit_cmd, rv);
910 stty_ctdl(SB_NO_INTR);
912 /* clean up the temporary directory */
914 ctdl_beep(); /* Beep beep! */
919 * read directory of this room
921 void roomdir(CtdlIPC *ipc)
928 char *listing = NULL; /* Returned directory listing */
931 r = CtdlIPCReadDirectory(ipc, &listing, buf);
933 scr_printf("%s\n", buf);
937 extract_token(comment, buf, 0, '|', sizeof comment);
938 extract_token(flnm, buf, 1, '|', sizeof flnm);
939 scr_printf("\nDirectory of %s on %s\n", flnm, comment);
940 scr_printf("-----------------------\n");
941 while (listing && *listing && !IsEmptyStr(listing)) {
942 extract_token(buf, listing, 0, '\n', sizeof buf);
943 remove_token(listing, 0, '\n');
945 extract_token(flnm, buf, 0, '|', sizeof flnm);
946 extract_token(flsz, buf, 1, '|', sizeof flsz);
947 extract_token(mimetype, buf, 2, '|', sizeof mimetype);
948 extract_token(comment, buf, 3, '|', sizeof comment);
949 if (strlen(flnm) <= 14)
950 scr_printf("%-14s %8s %s [%s]\n", flnm, flsz, comment, mimetype);
952 scr_printf("%s\n%14s %8s %s [%s]\n", flnm, "", flsz,
955 if (listing) free(listing);
960 * add a user to a private room
962 void invite(CtdlIPC *ipc)
964 char username[USERNAME_SIZE];
967 newprompt("Name of user? ", username, USERNAME_SIZE);
968 if (username[0] == 0)
971 CtdlIPCInviteUserToRoom(ipc, username, buf);
972 scr_printf("%s\n", buf);
977 * kick a user out of a room
979 void kickout(CtdlIPC *ipc)
981 char username[USERNAME_SIZE];
984 newprompt("Name of user? ", username, USERNAME_SIZE);
985 if (username[0] == 0)
988 CtdlIPCKickoutUserFromRoom(ipc, username, buf);
989 scr_printf("%s\n", buf);
994 * aide command: kill the current room
996 void killroom(CtdlIPC *ipc)
1001 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
1003 scr_printf("%s\n", aaa);
1007 scr_printf("Are you sure you want to kill this room? ");
1011 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
1012 scr_printf("%s\n", aaa);
1015 dotgoto(ipc, "_BASEROOM_", 0, 0);
1018 void forget(CtdlIPC *ipc)
1019 { /* forget the current room */
1022 scr_printf("Are you sure you want to forget this room? ");
1026 remove_march(room_name, 0);
1027 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
1028 scr_printf("%s\n", buf);
1032 /* now return to the lobby */
1033 dotgoto(ipc, "_BASEROOM_", 0, 0);
1040 void entroom(CtdlIPC *ipc)
1043 char new_room_name[ROOMNAMELEN];
1045 char new_room_pass[10];
1048 int r; /* IPC response code */
1050 /* Check permission to create room */
1051 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
1053 scr_printf("%s\n", buf);
1057 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
1058 if (IsEmptyStr(new_room_name)) {
1061 for (a = 0; !IsEmptyStr(&new_room_name[a]); ++a) {
1062 if (new_room_name[a] == '|') {
1063 new_room_name[a] = '_';
1067 new_room_floor = select_floor(ipc, (int) curr_floor);
1069 IFNEXPERT formout(ipc, "roomaccess");
1071 scr_printf("<?>Help\n"
1072 "<1>Public room (shown to all users by default)\n"
1073 "<2>Hidden room (accessible to anyone who knows the room name)\n"
1074 "<3>Passworded room (hidden, plus requires a password to enter)\n"
1075 "<4>Invitation-only room (requires access to be granted by an Admin)\n"
1076 "<5>Personal room (accessible to you only)\n"
1081 } while (((b < '1') || (b > '5')) && (b != '?'));
1084 formout(ipc, "roomaccess");
1086 } while ((b < '1') || (b > '5'));
1087 b -= '0'; /* Portable */
1088 scr_printf("%d\n", b);
1089 new_room_type = b - 1;
1090 if (new_room_type == 2) {
1091 newprompt("Enter a room password: ", new_room_pass, 9);
1092 for (a = 0; !IsEmptyStr(&new_room_pass[a]); ++a)
1093 if (new_room_pass[a] == '|')
1094 new_room_pass[a] = '_';
1096 strcpy(new_room_pass, "");
1099 scr_printf("\042%s\042, a", new_room_name);
1101 scr_printf(" public room.");
1103 scr_printf(" hidden room.");
1105 scr_printf(" passworded room, password: %s", new_room_pass);
1107 scr_printf("n invitation-only room.");
1109 scr_printf(" personal room.");
1110 scr_printf("\nInstall it? (y/n) : ");
1115 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type,
1116 new_room_pass, new_room_floor, buf);
1118 scr_printf("%s\n", buf);
1122 /* command succeeded... now GO to the new room! */
1123 dotgoto(ipc, new_room_name, 0, 0);
1128 void readinfo(CtdlIPC *ipc)
1129 { /* read info file for current room */
1131 char room_admin_name[64];
1132 int r; /* IPC response code */
1135 /* Name of currernt room admin */
1136 r = CtdlIPCGetRoomAide(ipc, buf);
1138 safestrncpy(room_admin_name, buf, sizeof room_admin_name);
1140 strcpy(room_admin_name, "");
1142 if (!IsEmptyStr(room_admin_name))
1143 scr_printf("Room admin is %s.\n\n", room_admin_name);
1145 r = CtdlIPCRoomInfo(ipc, &text, buf);
1150 fmout(screenwidth, NULL, text, NULL, 1);
1157 * <W>ho knows room...
1159 void whoknows(CtdlIPC *ipc)
1162 char *listing = NULL;
1165 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1167 scr_printf("%s\n", buf);
1170 while (!IsEmptyStr(listing)) {
1171 extract_token(buf, listing, 0, '\n', sizeof buf);
1172 remove_token(listing, 0, '\n');
1174 scr_printf("%s\n", buf);
1180 void do_edit(CtdlIPC *ipc,
1181 char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
1185 int b, cksum, editor_exit;
1187 if (IsEmptyStr(editor_path)) {
1188 scr_printf("Do you wish to re-enter %s? ", desc);
1193 fp = fopen(temp, "w");
1196 CtdlIPC_chat_send(ipc, check_cmd);
1197 CtdlIPC_chat_recv(ipc, cmd);
1198 if (cmd[0] != '2') {
1199 scr_printf("%s\n", &cmd[4]);
1203 if (!IsEmptyStr(editor_path)) {
1204 CtdlIPC_chat_send(ipc, read_cmd);
1205 CtdlIPC_chat_recv(ipc, cmd);
1206 if (cmd[0] == '1') {
1207 fp = fopen(temp, "w");
1208 while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
1209 fprintf(fp, "%s\n", cmd);
1215 cksum = file_checksum(temp);
1217 if (!IsEmptyStr(editor_path)) {
1220 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1222 stty_ctdl(SB_RESTORE);
1223 editor_pid = fork();
1224 if (editor_pid == 0) {
1226 execlp(editor_path, editor_path, temp, NULL);
1232 b = ka_wait(&editor_exit);
1233 } while ((b != editor_pid) && (b >= 0));
1235 scr_printf("Executed %s\n", editor_path);
1238 scr_printf("Entering %s. Press return twice when finished.\n", desc);
1239 fp = fopen(temp, "r+");
1244 if (file_checksum(temp) == cksum) {
1245 scr_printf("*** Aborted.\n");
1249 CtdlIPC_chat_send(ipc, write_cmd);
1250 CtdlIPC_chat_recv(ipc, cmd);
1251 if (cmd[0] != '4') {
1252 scr_printf("%s\n", &cmd[4]);
1256 fp = fopen(temp, "r");
1257 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1258 cmd[strlen(cmd) - 1] = 0;
1259 CtdlIPC_chat_send(ipc, cmd);
1262 CtdlIPC_chat_send(ipc, "000");
1269 void enterinfo(CtdlIPC *ipc)
1270 { /* edit info file for current room */
1271 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1274 void enter_bio(CtdlIPC *ipc)
1277 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1278 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1282 * create a new floor
1284 void create_floor(CtdlIPC *ipc)
1287 char newfloorname[SIZ];
1288 int r; /* IPC response code */
1290 load_floorlist(ipc);
1292 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1293 if ( (r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE) ) {
1294 scr_printf("%s\n", buf);
1298 newprompt("Name for new floor: ", newfloorname, 255);
1299 if (!*newfloorname) return;
1300 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1302 scr_printf("Floor has been created.\n");
1304 scr_printf("%s\n", buf);
1307 load_floorlist(ipc);
1311 * edit the current floor
1313 void edit_floor(CtdlIPC *ipc)
1316 struct ExpirePolicy *ep = NULL;
1318 load_floorlist(ipc);
1320 /* Fetch the expire policy (this will silently fail on old servers,
1321 * resulting in "default" policy)
1323 CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1325 /* Interact with the user */
1326 scr_printf("You are editing the floor called \"%s\"\n",
1327 &floorlist[(int) curr_floor][0] );
1328 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1330 /* Angels and demons dancing in my head... */
1332 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1334 ("Floor default message expire policy (? for list)",
1336 if (buf[0] == '?') {
1338 "0. Use the system default\n"
1339 "1. Never automatically expire messages\n"
1340 "2. Expire by message count\n"
1341 "3. Expire by message age\n");
1343 } while ((buf[0] < '0') || (buf[0] > '3'));
1344 ep->expire_mode = buf[0] - '0';
1346 /* ...lunatics and monsters underneath my bed */
1347 if (ep->expire_mode == 2) {
1348 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1349 strprompt("Keep how many messages online?", buf, 10);
1350 ep->expire_value = atol(buf);
1353 if (ep->expire_mode == 3) {
1354 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1355 strprompt("Keep messages for how many days?", buf, 10);
1356 ep->expire_value = atol(buf);
1360 CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1361 CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf);
1362 scr_printf("%s\n", buf);
1363 load_floorlist(ipc);
1370 * kill the current floor
1372 void kill_floor(CtdlIPC *ipc)
1374 int floornum_to_delete, a;
1377 load_floorlist(ipc);
1379 floornum_to_delete = (-1);
1380 scr_printf("(Press return to abort)\n");
1381 newprompt("Delete which floor? ", buf, 255);
1382 if (IsEmptyStr(buf))
1384 for (a = 0; a < 128; ++a)
1385 if (!strcasecmp(&floorlist[a][0], buf))
1386 floornum_to_delete = a;
1387 if (floornum_to_delete < 0) {
1388 scr_printf("No such floor. Select one of:\n");
1389 for (a = 0; a < 128; ++a)
1390 if (floorlist[a][0] != 0)
1391 scr_printf("%s\n", &floorlist[a][0]);
1393 } while (floornum_to_delete < 0);
1394 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1395 scr_printf("%s\n", buf);
1396 load_floorlist(ipc);