3bd9698dcdda95d7f1f849e0b82808252679c406
[citadel.git] / citadel / textclient / rooms.c
1 /*
2  * $Id$
3  *
4  * Client-side functions which perform room operations
5  *
6  * Copyright (c) 1987-2010 by the citadel.org team
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include "sysdep.h"
24 #include <stdlib.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include <stdio.h>
28 #include <ctype.h>
29 #include <string.h>
30 #include <signal.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <sys/wait.h>
34 #include <errno.h>
35 #include <stdarg.h>
36 #include <libcitadel.h>
37 #include "citadel.h"
38 #include "citadel_ipc.h"
39 #include "citadel_decls.h"
40 #include "rooms.h"
41 #include "commands.h"
42 #include "messages.h"
43 #ifndef HAVE_SNPRINTF
44 #include "snprintf.h"
45 #endif
46 #include "screen.h"
47 #include "citadel_dirs.h"
48
49 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
50
51
52 void stty_ctdl(int cmd);
53 void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto);
54 void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax);
55 int pattern(char *search, char *patn);
56 int file_checksum(char *filename);
57 int nukedir(char *dirname);
58
59 extern unsigned room_flags;
60 extern char room_name[];
61 extern char temp[];
62 extern char tempdir[];
63 extern int editor_pid;
64 extern int screenwidth;
65 extern int screenheight;
66 extern char fullname[];
67 extern char sigcaught;
68 extern char floor_mode;
69 extern char curr_floor;
70
71
72 extern int ugnum;
73 extern long uglsn;
74 extern char *uglist[];
75 extern long uglistlsn[];
76 extern int uglistsize;
77
78 extern char floorlist[128][SIZ];
79
80
81 void load_floorlist(CtdlIPC *ipc)
82 {
83         int a;
84         char buf[SIZ];
85         char *listing = NULL;
86         int r;                  /* IPC response code */
87
88         for (a = 0; a < 128; ++a)
89                 floorlist[a][0] = 0;
90
91         r = CtdlIPCFloorListing(ipc, &listing, buf);
92         if (r / 100 != 1) {
93                 strcpy(floorlist[0], "Main Floor");
94                 return;
95         }
96         while (*listing && !IsEmptyStr(listing)) {
97                 extract_token(buf, listing, 0, '\n', sizeof buf);
98                 remove_token(listing, 0, '\n');
99                 extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', SIZ);
100         }
101         free(listing);
102 }
103
104
105 void room_tree_list(struct ctdlroomlisting *rp)
106 {
107         static int c = 0;
108         char rmname[ROOMNAMELEN];
109         int f;
110
111         if (rp == NULL) {
112                 c = 1;
113                 return;
114         }
115
116         if (rp->lnext != NULL) {
117                 room_tree_list(rp->lnext);
118         }
119
120         if (sigcaught == 0) {
121                 strcpy(rmname, rp->rlname);
122                 f = rp->rlflags;
123                 if ((c + strlen(rmname) + 4) > screenwidth) {
124
125                         /* line break, check the paginator */
126                         pprintf("\n");
127                         c = 1;
128                 }
129                 if (f & QR_MAILBOX) {
130                         color(BRIGHT_YELLOW);
131                 } else if (f & QR_PRIVATE) {
132                         color(BRIGHT_RED);
133                 } else {
134                         color(DIM_WHITE);
135                 }
136                 pprintf("%s", rmname);
137                 if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
138                         pprintf("}  ");
139                 else if (f & QR_DIRECTORY)
140                         pprintf("]  ");
141                 else if (f & QR_NETWORK)
142                         pprintf(")  ");
143                 else
144                         pprintf(">  ");
145                 c = c + strlen(rmname) + 3;
146         }
147
148         if (rp->rnext != NULL) {
149                 room_tree_list(rp->rnext);
150         }
151
152         free(rp);
153 }
154
155
156 /* 
157  * Room ordering stuff (compare first by floor, then by order)
158  */
159 int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2)
160 {
161         if ((r1 == NULL) && (r2 == NULL))
162                 return (0);
163         if (r1 == NULL)
164                 return (-1);
165         if (r2 == NULL)
166                 return (1);
167         if (r1->rlfloor < r2->rlfloor)
168                 return (-1);
169         if (r1->rlfloor > r2->rlfloor)
170                 return (1);
171         if (r1->rlorder < r2->rlorder)
172                 return (-1);
173         if (r1->rlorder > r2->rlorder)
174                 return (1);
175         return (0);
176 }
177
178
179 /*
180  * Common code for all room listings
181  */
182 static void listrms(struct march *listing, int new_only, int floor_only, unsigned int flags, char *match)
183 {
184         struct march *mptr;
185         struct ctdlroomlisting *rl = NULL;
186         struct ctdlroomlisting *rp;
187         struct ctdlroomlisting *rs;
188         int list_it;
189
190         for (mptr = listing; mptr != NULL; mptr = mptr->next) {
191                 list_it = 1;
192
193                 if ( (new_only == LISTRMS_NEW_ONLY)
194                    && ((mptr->march_access & UA_HASNEWMSGS) == 0)) 
195                         list_it = 0;
196
197                 if ( (new_only == LISTRMS_OLD_ONLY)
198                    && ((mptr->march_access & UA_HASNEWMSGS) != 0)) 
199                         list_it = 0;
200
201                 if ( (floor_only >= 0)
202                    && (mptr->march_floor != floor_only))
203                         list_it = 0;
204
205                 if (flags && (mptr->march_flags & flags) == 0)
206                     list_it = 0;
207
208             if (match && (pattern(mptr->march_name, match) == -1))
209                         list_it = 0;
210
211                 if (list_it) {
212                         rp = malloc(sizeof(struct ctdlroomlisting));
213                         strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
214                         rp->rlflags = mptr->march_flags;
215                         rp->rlfloor = mptr->march_floor;
216                         rp->rlorder = mptr->march_order;
217                         rp->lnext = NULL;
218                         rp->rnext = NULL;
219         
220                         rs = rl;
221                         if (rl == NULL) {
222                                 rl = rp;
223                         } else {
224                                 while (rp != NULL) {
225                                         if (rordercmp(rp, rs) < 0) {
226                                                 if (rs->lnext == NULL) {
227                                                         rs->lnext = rp;
228                                                         rp = NULL;
229                                                 } else {
230                                                         rs = rs->lnext;
231                                                 }
232                                         } else {
233                                                 if (rs->rnext == NULL) {
234                                                         rs->rnext = rp;
235                                                         rp = NULL;
236                                                 } else {
237                                                         rs = rs->rnext;
238                                                 }
239                                         }
240                                 }
241                         }
242                 }
243         }
244
245         room_tree_list(NULL);
246         room_tree_list(rl);
247         color(DIM_WHITE);
248 }
249
250
251 void list_other_floors(void)
252 {
253         int a, c;
254
255         c = 1;
256         for (a = 0; a < 128; ++a) {
257                 if ((strlen(floorlist[a]) > 0) && (a != curr_floor)) {
258                         if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
259                                 pprintf("\n");
260                                 c = 1;
261                         }
262                         pprintf("%s:  ", floorlist[a]);
263                         c = c + strlen(floorlist[a]) + 3;
264                 }
265         }
266 }
267
268
269 /*
270  * List known rooms.  kn_floor_mode should be set to 0 for a 'flat' listing,
271  * 1 to list rooms on the current floor, or 2 to list rooms on all floors.
272  */
273 void knrooms(CtdlIPC *ipc, int kn_floor_mode)
274 {
275         int a;
276         struct march *listing = NULL;
277         struct march *mptr;
278         int r;          /* IPC response code */
279         char buf[SIZ];
280
281
282         /* Ask the server for a room list */
283         r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
284         if (r / 100 != 1) {
285                 listing = NULL;
286         }
287
288         load_floorlist(ipc);
289
290
291         if (kn_floor_mode == 0) {
292                 color(BRIGHT_CYAN);
293                 pprintf("\n   Rooms with unread messages:\n");
294                 listrms(listing, LISTRMS_NEW_ONLY, -1, 0, NULL);
295                 color(BRIGHT_CYAN);
296                 pprintf("\n\n   No unseen messages in:\n");
297                 listrms(listing, LISTRMS_OLD_ONLY, -1, 0, NULL);
298                 pprintf("\n");
299         }
300
301         if (kn_floor_mode == 1) {
302                 color(BRIGHT_CYAN);
303                 pprintf("\n   Rooms with unread messages on %s:\n",
304                         floorlist[(int) curr_floor]);
305                 listrms(listing, LISTRMS_NEW_ONLY, curr_floor, 0, NULL);
306                 color(BRIGHT_CYAN);
307                 pprintf("\n\n   Rooms with no new messages on %s:\n",
308                         floorlist[(int) curr_floor]);
309                 listrms(listing, LISTRMS_OLD_ONLY, curr_floor, 0, NULL);
310                 color(BRIGHT_CYAN);
311                 pprintf("\n\n   Other floors:\n");
312                 list_other_floors();
313                 pprintf("\n");
314         }
315
316         if (kn_floor_mode == 2) {
317                 for (a = 0; a < 128; ++a) {
318                         if (floorlist[a][0] != 0) {
319                                 color(BRIGHT_CYAN);
320                                 pprintf("\n   Rooms on %s:\n",
321                                         floorlist[a]);
322                                 listrms(listing, LISTRMS_ALL, a, 0, NULL);
323                                 pprintf("\n");
324                         }
325                 }
326         }
327
328         /* Free the room list */
329         while (listing) {
330                 mptr = listing->next;
331                 free(listing);
332                 listing = mptr;
333         };
334
335         color(DIM_WHITE);
336         IFNEXPERT hit_any_key(ipc);
337 }
338
339
340 void listzrooms(CtdlIPC *ipc)
341 {                               /* list public forgotten rooms */
342         struct march *listing = NULL;
343         struct march *mptr;
344         int r;          /* IPC response code */
345         char buf[SIZ];
346
347
348         /* Ask the server for a room list */
349         r = CtdlIPCKnownRooms(ipc, UnsubscribedRooms, (-1), &listing, buf);
350         if (r / 100 != 1) {
351                 listing = NULL;
352         }
353
354         color(BRIGHT_CYAN);
355         pprintf("\n   Forgotten public rooms:\n");
356         listrms(listing, LISTRMS_ALL, -1, 0, NULL);
357         pprintf("\n");
358
359         /* Free the room list */
360         while (listing) {
361                 mptr = listing->next;
362                 free(listing);
363                 listing = mptr;
364         };
365
366         color(DIM_WHITE);
367         IFNEXPERT hit_any_key(ipc);
368 }
369
370 void dotknown(CtdlIPC *ipc, int what, char *match)
371 {                               /* list rooms according to attribute */
372         struct march *listing = NULL;
373         struct march *mptr;
374         int r;          /* IPC response code */
375         char buf[SIZ];
376
377         /* Ask the server for a room list */
378         r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, (-1), &listing, buf);
379         if (r / 100 != 1) {
380                 listing = NULL;
381         }
382
383         color(BRIGHT_CYAN);
384
385         switch (what) {
386     case 0:
387         pprintf("\n   Anonymous rooms:\n");
388             listrms(listing, LISTRMS_ALL, -1, QR_ANONONLY|QR_ANONOPT, NULL);
389         pprintf("\n");
390                 break;
391     case 1:
392         pprintf("\n   Directory rooms:\n");
393             listrms(listing, LISTRMS_ALL, -1, QR_DIRECTORY, NULL);
394         pprintf("\n");
395                 break;
396     case 2:
397         pprintf("\n   Matching \"%s\" rooms:\n", match);
398             listrms(listing, LISTRMS_ALL, -1, 0, match);
399         pprintf("\n");
400                 break;
401     case 3:
402         pprintf("\n   Preferred only rooms:\n");
403             listrms(listing, LISTRMS_ALL, -1, QR_PREFONLY, NULL);
404         pprintf("\n");
405                 break;
406     case 4:
407         pprintf("\n   Private rooms:\n");
408             listrms(listing, LISTRMS_ALL, -1, QR_PRIVATE, NULL);
409         pprintf("\n");
410                 break;
411     case 5:
412         pprintf("\n   Read only rooms:\n");
413             listrms(listing, LISTRMS_ALL, -1, QR_READONLY, NULL);
414         pprintf("\n");
415                 break;
416     case 6:
417         pprintf("\n   Shared rooms:\n");
418             listrms(listing, LISTRMS_ALL, -1, QR_NETWORK, NULL);
419         pprintf("\n");
420                 break;
421         }
422
423         /* Free the room list */
424         while (listing) {
425                 mptr = listing->next;
426                 free(listing);
427                 listing = mptr;
428         };
429
430         color(DIM_WHITE);
431         IFNEXPERT hit_any_key(ipc);
432 }
433
434
435 int set_room_attr(CtdlIPC *ipc, unsigned int ibuf, char *prompt, unsigned int sbit)
436 {
437         int a;
438
439         a = boolprompt(prompt, (ibuf & sbit));
440         ibuf = (ibuf | sbit);
441         if (!a) {
442                 ibuf = (ibuf ^ sbit);
443         }
444         return (ibuf);
445 }
446
447
448
449 /*
450  * Select a floor (used in several commands)
451  * The supplied argument is the 'default' floor number.
452  * This function returns the selected floor number.
453  */
454 int select_floor(CtdlIPC *ipc, int rfloor)
455 {
456         int a, newfloor;
457         char floorstr[SIZ];
458
459         if (floor_mode == 1) {
460                 if (floorlist[(int) curr_floor][0] == 0) {
461                         load_floorlist(ipc);
462                 }
463
464                 do {
465                         newfloor = (-1);
466                         safestrncpy(floorstr, floorlist[rfloor],
467                                     sizeof floorstr);
468                         strprompt("Which floor", floorstr, 255);
469                         for (a = 0; a < 128; ++a) {
470                                 if (!strcasecmp
471                                     (floorstr, &floorlist[a][0]))
472                                         newfloor = a;
473                                 if ((newfloor < 0)
474                                     &&
475                                     (!strncasecmp
476                                      (floorstr, &floorlist[a][0],
477                                       strlen(floorstr))))
478                                         newfloor = a;
479                                 if ((newfloor < 0)
480                                     && (pattern(&floorlist[a][0], floorstr)
481                                         >= 0))
482                                         newfloor = a;
483                         }
484                         if (newfloor < 0) {
485                                 scr_printf("\n One of:\n");
486                                 for (a = 0; a < 128; ++a) {
487                                         if (floorlist[a][0] != 0) {
488                                                 scr_printf("%s\n",
489                                                        &floorlist[a][0]);
490                                         }
491                                 }
492                         }
493                 } while (newfloor < 0);
494                 return (newfloor);
495         }
496
497         else {
498                 scr_printf("Floor selection bypassed because you have "
499                         "floor mode disabled.\n");
500         }
501
502         return (rfloor);
503 }
504
505
506
507
508 /*
509  * .<A>ide <E>dit room
510  */
511 void editthisroom(CtdlIPC *ipc)
512 {
513         int rbump = 0;
514         char raide[USERNAME_SIZE];
515         char buf[SIZ];
516         struct ctdlroom *attr = NULL;
517         struct ExpirePolicy *eptr = NULL;
518         int r;                          /* IPC response code */
519
520         /* Fetch the existing room config */
521         r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
522         if (r / 100 != 2) {
523                 scr_printf("%s\n", buf);
524                 return;
525         }
526         eptr = &(attr->QRep);
527
528         /* Fetch the name of the current room aide */
529         r = CtdlIPCGetRoomAide(ipc, buf);
530         if (r / 100 == 2) {
531                 safestrncpy(raide, buf, sizeof raide);
532         } else {
533                 strcpy(raide, "");
534         }
535         if (IsEmptyStr(raide)) {
536                 strcpy(raide, "none");
537         }
538
539         /* Fetch the expire policy (this will silently fail on old servers,
540          * resulting in "default" policy)
541          */
542         r = CtdlIPCGetMessageExpirationPolicy(ipc, 0, &eptr, buf);
543
544         /* Now interact with the user. */
545
546         strprompt("Room name", attr->QRname, ROOMNAMELEN-1);
547         attr->QRfloor = select_floor(ipc, attr->QRfloor);
548         attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
549         if (attr->QRflags & QR_PRIVATE) {
550                 attr->QRflags = set_room_attr(ipc, attr->QRflags,
551                                        "Hidden room (accessible to anyone who knows the room name)",
552                                        QR_GUESSNAME);
553         }
554
555         /* if it's public, clear the privacy classes */
556         if ((attr->QRflags & QR_PRIVATE) == 0) {
557                 if (attr->QRflags & QR_GUESSNAME) {
558                         attr->QRflags = attr->QRflags - QR_GUESSNAME;
559                 }
560                 if (attr->QRflags & QR_PASSWORDED) {
561                         attr->QRflags = attr->QRflags - QR_PASSWORDED;
562                 }
563         }
564
565         /* if it's private, choose the privacy classes */
566         if ((attr->QRflags & QR_PRIVATE)
567             && ((attr->QRflags & QR_GUESSNAME) == 0)) {
568                 attr->QRflags = set_room_attr(ipc, attr->QRflags,
569                                        "Accessible by entering a password",
570                                        QR_PASSWORDED);
571         }
572         if ((attr->QRflags & QR_PRIVATE)
573             && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
574                 strprompt("Room password", attr->QRpasswd, 9);
575         }
576
577         if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
578                 rbump = boolprompt("Cause current users to forget room", 0);
579         }
580
581         attr->QRflags = set_room_attr(ipc, attr->QRflags,
582                                         "Preferred users only", QR_PREFONLY);
583         attr->QRflags = set_room_attr(ipc, attr->QRflags,
584                                         "Read-only room", QR_READONLY);
585         attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
586                                 "Allow message deletion by anyone who can post",
587                                 QR2_COLLABDEL);
588         attr->QRflags = set_room_attr(ipc, attr->QRflags,
589                                         "Permanent room", QR_PERMANENT);
590         attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
591                                                                    "Subject Required (Force "
592                                                                    "users to specify a message "
593                                    "subject)", QR2_SUBJECTREQ);
594         attr->QRflags = set_room_attr(ipc, attr->QRflags,
595                                         "Directory room", QR_DIRECTORY);
596         if (attr->QRflags & QR_DIRECTORY) {
597                 strprompt("Directory name", attr->QRdirname, 14);
598                 attr->QRflags =
599                     set_room_attr(ipc, attr->QRflags,
600                                                 "Uploading allowed", QR_UPLOAD);
601                 attr->QRflags =
602                     set_room_attr(ipc, attr->QRflags, "Downloading allowed",
603                                   QR_DOWNLOAD);
604                 attr->QRflags =
605                     set_room_attr(ipc, attr->QRflags,
606                                                 "Visible directory", QR_VISDIR);
607         }
608         attr->QRflags = set_room_attr(ipc, attr->QRflags,
609                                         "Network shared room", QR_NETWORK);
610         attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
611                                 "Self-service list subscribe/unsubscribe",
612                                 QR2_SELFLIST);
613         attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
614                                 "public posting to this room via room_roomname@yourcitadel.org",
615                                 QR2_SMTP_PUBLIC);
616         attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
617                                 "moderated mailinglist",
618                                 QR2_MODERATED);
619         attr->QRflags = set_room_attr(ipc, attr->QRflags,
620                                "Automatically make all messages anonymous",
621                                QR_ANONONLY);
622         if ((attr->QRflags & QR_ANONONLY) == 0) {
623                 attr->QRflags = set_room_attr(ipc, attr->QRflags,
624                                        "Ask users whether to make messages anonymous",
625                                        QR_ANONOPT);
626         }
627         attr->QRorder = intprompt("Listing order", attr->QRorder, 0, 127);
628
629         /* Ask about the room aide */
630         do {
631                 strprompt("Room aide (or 'none')", raide, 29);
632                 if (!strcasecmp(raide, "none")) {
633                         strcpy(raide, "");
634                         break;
635                 } else {
636                         r = CtdlIPCQueryUsername(ipc, raide, buf);
637                         if (r / 100 != 2)
638                                 scr_printf("%s\n", buf);
639                 }
640         } while (r / 100 != 2);
641
642         /* Angels and demons dancing in my head... */
643         do {
644                 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
645                 strprompt("Message expire policy (? for list)", buf, 1);
646                 if (buf[0] == '?') {
647                         scr_printf("\n"
648                                 "0. Use the default for this floor\n"
649                                 "1. Never automatically expire messages\n"
650                                 "2. Expire by message count\n"
651                                 "3. Expire by message age\n");
652                 }
653         } while ((buf[0] < 48) || (buf[0] > 51));
654         attr->QRep.expire_mode = buf[0] - 48;
655
656         /* ...lunatics and monsters underneath my bed */
657         if (attr->QRep.expire_mode == 2) {
658                 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
659                 strprompt("Keep how many messages online?", buf, 10);
660                 attr->QRep.expire_value = atol(buf);
661         }
662
663         if (attr->QRep.expire_mode == 3) {
664                 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
665                 strprompt("Keep messages for how many days?", buf, 10);
666                 attr->QRep.expire_value = atol(buf);
667         }
668
669         /* Give 'em a chance to change their minds */
670         scr_printf("Save changes (y/n)? ");
671
672         if (yesno() == 1) {
673                 r = CtdlIPCSetRoomAide(ipc, raide, buf);
674                 if (r / 100 != 2) {
675                         scr_printf("%s\n", buf);
676                 }
677
678                 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
679                 if (r / 100 != 2) {
680                         scr_printf("%s\n", buf);
681                 }
682
683                 r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
684                 scr_printf("%s\n", buf);
685                 strncpy(buf, attr->QRname, ROOMNAMELEN);
686                 free(attr);
687                 if (r / 100 == 2)
688                         dotgoto(ipc, buf, 2, 0);
689         }
690         else free(attr);
691 }
692
693
694 /*
695  * un-goto the previous room, or a specified room
696  */
697 void dotungoto(CtdlIPC *ipc, char *towhere)
698   {
699     /* Find this 'towhere' room in the list ungoto from this room to
700        that at the messagepointer position in that room in our ungoto list.
701        I suppose I could be a real dick and just ungoto that many places
702        in our list. */
703     int found = -1;
704     int lp;
705         char buf[SIZ];
706         struct ctdlipcroom *rret = NULL;        /* ignored */
707         int r;
708
709         if (uglistsize == 0)
710       {
711                 scr_printf("No rooms to ungoto.\n");
712                 return;
713       }
714         if (towhere == NULL)
715       {
716                 scr_printf("Must specify a room to ungoto.\n");
717                 return;
718       }
719         if (IsEmptyStr(towhere))
720       {
721                 scr_printf("Must specify a room to ungoto.\n");
722                 return;
723       }
724     for (lp = uglistsize-1; lp >= 0; lp--)
725       {
726         if (strcasecmp(towhere, uglist[lp]) == 0)
727           {
728             found = lp;
729             break;
730           }
731       }
732     if (found == -1)
733       {
734                 scr_printf("Room: %s not in ungoto list.\n", towhere);
735         return;
736       }
737
738         r = CtdlIPCGotoRoom(ipc, uglist[found], "", &rret, buf);
739         if (rret) free(rret);   /* ignored */
740         if (r / 100 != 2) {
741                 scr_printf("%s\n", buf);
742                 return;
743         }
744         r = CtdlIPCSetLastRead(ipc, uglistlsn[found] ? uglistlsn[found] : 1, buf);
745         if (r / 100 != 2) {
746                 scr_printf("%s\n", buf);
747         }
748         safestrncpy(buf, uglist[found], sizeof(buf));
749     /* we queue ungoto information here, because we're not really
750        ungotoing, we're really going to a random spot in some arbitrary
751        room list. */
752         dotgoto(ipc, buf, 0, 0);
753   }
754
755 void ungoto(CtdlIPC *ipc)
756 {
757         char buf[SIZ];
758         struct ctdlipcroom *rret = NULL;        /* ignored */
759         int r;
760
761         if (uglistsize == 0)
762                 return;
763
764         r = CtdlIPCGotoRoom(ipc, uglist[uglistsize-1], "", &rret, buf);
765         if (rret) free(rret);   /* ignored */
766         if (r / 100 != 2) {
767                 scr_printf("%s\n", buf);
768                 return;
769         }
770         r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize-1] ? uglistlsn[uglistsize-1] : 1, buf);
771         if (r / 100 != 2) {
772                 scr_printf("%s\n", buf);
773         }
774         safestrncpy(buf, uglist[uglistsize-1], sizeof(buf));
775         uglistsize--;
776         free(uglist[uglistsize]);
777         /* Don't queue ungoto info or we end up in a loop */
778         dotgoto(ipc, buf, 0, 1);
779 }
780
781
782 /*
783  * saves filelen bytes from file at pathname
784  */
785 int save_buffer(void *file, size_t filelen, const char *pathname)
786 {
787         size_t block = 0;
788         size_t bytes_written = 0;
789         FILE *fp;
790
791         fp = fopen(pathname, "w");
792         if (!fp) {
793                 err_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
794                 return 0;
795         }
796         do {
797                 block = fwrite((char *)file + bytes_written, 1,
798                                 filelen - bytes_written, fp);
799                 bytes_written += block;
800         } while (errno == EINTR && bytes_written < filelen);
801         fclose(fp);
802
803         if (bytes_written < filelen) {
804                 err_printf("Trouble saving '%s': %s\n", pathname,
805                                 strerror(errno));
806                 return 0;
807         }
808         return 1;
809 }
810
811
812 /*
813  * Save supplied_filename in dest directory; gets the name only
814  */
815 void destination_directory(char *dest, const char *supplied_filename)
816 {
817         static char save_dir[SIZ] = { 0 };
818
819         if (IsEmptyStr(save_dir)) {
820                 if (getenv("HOME") == NULL) {
821                         strcpy(save_dir, ".");
822                 }
823                 else {
824                         sprintf(save_dir, "%s/Desktop", getenv("HOME"));
825                         if (access(save_dir, W_OK) != 0) {
826                                 sprintf(save_dir, "%s", getenv("HOME"));
827                                 if (access(save_dir, W_OK) != 0) {
828                                         sprintf(save_dir, ".");
829                                 }
830                         }
831                 }
832         }
833
834         sprintf(dest, "%s/%s", save_dir, supplied_filename);
835         strprompt("Save as", dest, PATH_MAX);
836
837         /* Remember the directory for next time */
838         strcpy(save_dir, dest);
839         if (strrchr(save_dir, '/') != NULL) {
840                 strcpy(strrchr(save_dir, '/'), "");
841         }
842         else {
843                 strcpy(save_dir, ".");
844         }
845 }
846
847
848 /*
849  * download()  -  download a file or files.  The argument passed to this
850  *                function determines which protocol to use.
851  *  proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
852  */
853 void download(CtdlIPC *ipc, int proto)
854 {
855         char buf[SIZ];
856         char filename[PATH_MAX];
857         char tempname[PATH_MAX];
858         char transmit_cmd[SIZ];
859         FILE *tpipe = NULL;
860         int broken = 0;
861         int r;
862         int rv = 0;
863         void *file = NULL;      /* The downloaded file */
864         size_t filelen = 0L;    /* The downloaded file length */
865
866         if ((room_flags & QR_DOWNLOAD) == 0) {
867                 scr_printf("*** You cannot download from this room.\n");
868                 return;
869         }
870
871         newprompt("Enter filename: ", filename, PATH_MAX);
872
873         /* Save to local disk, for folks with their own copy of the client */
874         if (proto == 5) {
875                 destination_directory(tempname, filename);
876                 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
877                 if (r / 100 != 2) {
878                         scr_printf("%s\n", buf);
879                         return;
880                 }
881                 save_buffer(file, (size_t)extract_long(buf, 0), tempname);
882                 free(file);
883                 return;
884         }
885
886         r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
887         if (r / 100 != 2) {
888                 scr_printf("%s\n", buf);
889                 return;
890         }
891         filelen = extract_unsigned_long(buf, 0);
892
893         /* Meta-download for public clients */
894         /* scr_printf("Fetching file from Citadel server...\n"); */
895         mkdir(tempdir, 0700);
896         snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
897         tpipe = fopen(tempname, "wb");
898         if (fwrite(file, filelen, 1, tpipe) < filelen) {
899                 /* FIXME: restart syscall on EINTR */
900                 broken = 1;
901         }
902         fclose(tpipe);
903         if (file) free(file);
904
905         if (proto == 0) {
906                 /* FIXME: display internally instead */
907                 snprintf(transmit_cmd, sizeof transmit_cmd,
908                         "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",
909                         tempname);
910         }
911         else if (proto == 1)
912                 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
913         else if (proto == 3)
914                 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
915         else if (proto == 4)
916                 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
917         else
918                 /* FIXME: display internally instead */
919                 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
920
921         screen_reset();
922         stty_ctdl(SB_RESTORE);
923         rv = system(transmit_cmd);
924         stty_ctdl(SB_NO_INTR);
925         screen_set();
926
927         /* clean up the temporary directory */
928         nukedir(tempdir);
929         ctdl_beep();    /* Beep beep! */
930 }
931
932
933 /*
934  * read directory of this room
935  */
936 void roomdir(CtdlIPC *ipc)
937 {
938         char flnm[256];
939         char flsz[32];
940         char comment[256];
941         char mimetype[256];
942         char buf[256];
943         char *listing = NULL;   /* Returned directory listing */
944         int r;
945
946         r = CtdlIPCReadDirectory(ipc, &listing, buf);
947         if (r / 100 != 1) {
948                 pprintf("%s\n", buf);
949                 return;
950         }
951
952         extract_token(comment, buf, 0, '|', sizeof comment);
953         extract_token(flnm, buf, 1, '|', sizeof flnm);
954         pprintf("\nDirectory of %s on %s\n", flnm, comment);
955         pprintf("-----------------------\n");
956         while (listing && *listing && !IsEmptyStr(listing)) {
957                 extract_token(buf, listing, 0, '\n', sizeof buf);
958                 remove_token(listing, 0, '\n');
959
960                 extract_token(flnm, buf, 0, '|', sizeof flnm);
961                 extract_token(flsz, buf, 1, '|', sizeof flsz);
962                 extract_token(mimetype, buf, 2, '|', sizeof mimetype);
963                 extract_token(comment, buf, 3, '|', sizeof comment);
964                 if (strlen(flnm) <= 14)
965                         pprintf("%-14s %8s %s [%s]\n", flnm, flsz, comment, mimetype);
966                 else
967                         pprintf("%s\n%14s %8s %s [%s]\n", flnm, "", flsz,
968                                 comment, mimetype);
969         }
970         if (listing) free(listing);
971 }
972
973
974 /*
975  * add a user to a private room
976  */
977 void invite(CtdlIPC *ipc)
978 {
979         char username[USERNAME_SIZE];
980         char buf[SIZ];
981         int r;                          /* IPC response code */
982
983         newprompt("Name of user? ", username, USERNAME_SIZE);
984         if (username[0] == 0)
985                 return;
986
987         r = CtdlIPCInviteUserToRoom(ipc, username, buf);
988         scr_printf("%s\n", buf);
989 }
990
991
992 /*
993  * kick a user out of a room
994  */
995 void kickout(CtdlIPC *ipc)
996 {
997         char username[USERNAME_SIZE];
998         char buf[SIZ];
999         int r;                          /* IPC response code */
1000
1001         newprompt("Name of user? ", username, USERNAME_SIZE);
1002         if (username[0] == 0)
1003                 return;
1004
1005         r = CtdlIPCKickoutUserFromRoom(ipc, username, buf);
1006         scr_printf("%s\n", buf);
1007 }
1008
1009
1010 /*
1011  * aide command: kill the current room
1012  */
1013 void killroom(CtdlIPC *ipc)
1014 {
1015         char aaa[100];
1016         int r;
1017
1018         r = CtdlIPCDeleteRoom(ipc, 0, aaa);
1019         if (r / 100 != 2) {
1020                 scr_printf("%s\n", aaa);
1021                 return;
1022         }
1023
1024         scr_printf("Are you sure you want to kill this room? ");
1025         if (yesno() == 0)
1026                 return;
1027
1028         r = CtdlIPCDeleteRoom(ipc, 1, aaa);
1029         scr_printf("%s\n", aaa);
1030         if (r / 100 != 2)
1031                 return;
1032         dotgoto(ipc, "_BASEROOM_", 0, 0);
1033 }
1034
1035 void forget(CtdlIPC *ipc)
1036 {                               /* forget the current room */
1037         char buf[SIZ];
1038
1039         scr_printf("Are you sure you want to forget this room? ");
1040         if (yesno() == 0)
1041                 return;
1042
1043         remove_march(room_name, 0);
1044         if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
1045                 scr_printf("%s\n", buf);
1046                 return;
1047         }
1048
1049         /* now return to the lobby */
1050         dotgoto(ipc, "_BASEROOM_", 0, 0);
1051 }
1052
1053
1054 /*
1055  * create a new room
1056  */
1057 void entroom(CtdlIPC *ipc)
1058 {
1059         char buf[SIZ];
1060         char new_room_name[ROOMNAMELEN];
1061         int new_room_type;
1062         char new_room_pass[10];
1063         int new_room_floor;
1064         int a, b;
1065         int r;                          /* IPC response code */
1066
1067         /* Check permission to create room */
1068         r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
1069         if (r / 100 != 2) {
1070                 scr_printf("%s\n", buf);
1071                 return;
1072         }
1073
1074         newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
1075         if (IsEmptyStr(new_room_name)) {
1076                 return;
1077         }
1078         for (a = 0; !IsEmptyStr(&new_room_name[a]); ++a) {
1079                 if (new_room_name[a] == '|') {
1080                         new_room_name[a] = '_';
1081                 }
1082         }
1083
1084         new_room_floor = select_floor(ipc, (int) curr_floor);
1085
1086         IFNEXPERT formout(ipc, "roomaccess");
1087         do {
1088                 scr_printf("<?>Help\n"
1089                         "<1>Public room (shown to all users by default)\n"
1090                         "<2>Hidden room (accessible to anyone who knows the room name)\n"
1091                         "<3>Passworded room (hidden, plus requires a password to enter)\n"
1092                         "<4>Invitation-only room (requires access to be granted by an Aide)\n"
1093                         "<5>Personal room (accessible to you only)\n"
1094                         "Enter room type: "
1095                 );
1096                 do {
1097                         b = inkey();
1098                 } while (((b < '1') || (b > '5')) && (b != '?'));
1099                 if (b == '?') {
1100                         scr_printf("?\n");
1101                         formout(ipc, "roomaccess");
1102                 }
1103         } while ((b < '1') || (b > '5'));
1104         b -= '0';                       /* Portable */
1105         scr_printf("%d\n", b);
1106         new_room_type = b - 1;
1107         if (new_room_type == 2) {
1108                 newprompt("Enter a room password: ", new_room_pass, 9);
1109                 for (a = 0; !IsEmptyStr(&new_room_pass[a]); ++a)
1110                         if (new_room_pass[a] == '|')
1111                                 new_room_pass[a] = '_';
1112         } else {
1113                 strcpy(new_room_pass, "");
1114         }
1115
1116         scr_printf("\042%s\042, a", new_room_name);
1117         if (b == 1)
1118                 scr_printf(" public room.");
1119         if (b == 2)
1120                 scr_printf(" hidden room.");
1121         if (b == 3)
1122                 scr_printf(" passworded room, password: %s", new_room_pass);
1123         if (b == 4)
1124                 scr_printf("n invitation-only room.");
1125         if (b == 5)
1126                 scr_printf(" personal room.");
1127         scr_printf("\nInstall it? (y/n) : ");
1128         if (yesno() == 0) {
1129                 return;
1130         }
1131
1132         r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type,
1133                               new_room_pass, new_room_floor, buf);
1134         if (r / 100 != 2) {
1135                 scr_printf("%s\n", buf);
1136                 return;
1137         }
1138
1139         /* command succeeded... now GO to the new room! */
1140         dotgoto(ipc, new_room_name, 0, 0);
1141 }
1142
1143
1144
1145 void readinfo(CtdlIPC *ipc)
1146 {                               /* read info file for current room */
1147         char buf[SIZ];
1148         char raide[64];
1149         int r;                  /* IPC response code */
1150         char *text = NULL;
1151
1152         /* Name of currernt room aide */
1153         r = CtdlIPCGetRoomAide(ipc, buf);
1154         if (r / 100 == 2)
1155                 safestrncpy(raide, buf, sizeof raide);
1156         else
1157                 strcpy(raide, "");
1158
1159         if (!IsEmptyStr(raide))
1160                 scr_printf("Room aide is %s.\n\n", raide);
1161
1162         r = CtdlIPCRoomInfo(ipc, &text, buf);
1163         if (r / 100 != 1)
1164                 return;
1165
1166         if (text) {
1167                 fmout(screenwidth, NULL, text, NULL,
1168                       ((userflags & US_PAGINATOR) ? 1 : 0), screenheight, 
1169                       (*raide) ? 2 : 0, 1);
1170                 free(text);
1171         }
1172 }
1173
1174
1175 /*
1176  * <W>ho knows room...
1177  */
1178 void whoknows(CtdlIPC *ipc)
1179 {
1180         char buf[256];
1181         char *listing = NULL;
1182         int r;
1183
1184         r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1185         if (r / 100 != 1) {
1186                 pprintf("%s\n", buf);
1187                 return;
1188         }
1189         while (!IsEmptyStr(listing)) {
1190                 extract_token(buf, listing, 0, '\n', sizeof buf);
1191                 remove_token(listing, 0, '\n');
1192                 if (sigcaught == 0)
1193                         pprintf("%s\n", buf);
1194         }
1195         free(listing);
1196 }
1197
1198
1199 void do_edit(CtdlIPC *ipc,
1200                 char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
1201 {
1202         FILE *fp;
1203         char cmd[SIZ];
1204         int b, cksum, editor_exit;
1205
1206         if (IsEmptyStr(editor_paths[0])) {
1207                 scr_printf("Do you wish to re-enter %s? ", desc);
1208                 if (yesno() == 0)
1209                         return;
1210         }
1211
1212         fp = fopen(temp, "w");
1213         fclose(fp);
1214
1215         CtdlIPC_chat_send(ipc, check_cmd);
1216         CtdlIPC_chat_recv(ipc, cmd);
1217         if (cmd[0] != '2') {
1218                 scr_printf("%s\n", &cmd[4]);
1219                 return;
1220         }
1221
1222         if (!IsEmptyStr(editor_paths[0])) {
1223                 CtdlIPC_chat_send(ipc, read_cmd);
1224                 CtdlIPC_chat_recv(ipc, cmd);
1225                 if (cmd[0] == '1') {
1226                         fp = fopen(temp, "w");
1227                         while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
1228                                 fprintf(fp, "%s\n", cmd);
1229                         }
1230                         fclose(fp);
1231                 }
1232         }
1233
1234         cksum = file_checksum(temp);
1235
1236         if (!IsEmptyStr(editor_paths[0])) {
1237                 char tmp[SIZ];
1238
1239                 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1240                 putenv(tmp);
1241                 screen_reset();
1242                 stty_ctdl(SB_RESTORE);
1243                 editor_pid = fork();
1244                 if (editor_pid == 0) {
1245                         chmod(temp, 0600);
1246                         execlp(editor_paths[0], editor_paths[0], temp, NULL);
1247                         exit(1);
1248                 }
1249                 if (editor_pid > 0)
1250                         do {
1251                                 editor_exit = 0;
1252                                 b = ka_wait(&editor_exit);
1253                         } while ((b != editor_pid) && (b >= 0));
1254                 editor_pid = (-1);
1255                 scr_printf("Executed %s\n", editor_paths[0]);
1256                 stty_ctdl(0);
1257                 screen_set();
1258         } else {
1259                 scr_printf("Entering %s.  Press return twice when finished.\n", desc);
1260                 fp = fopen(temp, "r+");
1261                 citedit(fp);
1262                 fclose(fp);
1263         }
1264
1265         if (file_checksum(temp) == cksum) {
1266                 scr_printf("*** Aborted.\n");
1267         }
1268
1269         else {
1270                 CtdlIPC_chat_send(ipc, write_cmd);
1271                 CtdlIPC_chat_recv(ipc, cmd);
1272                 if (cmd[0] != '4') {
1273                         scr_printf("%s\n", &cmd[4]);
1274                         return;
1275                 }
1276
1277                 fp = fopen(temp, "r");
1278                 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1279                         cmd[strlen(cmd) - 1] = 0;
1280                         CtdlIPC_chat_send(ipc, cmd);
1281                 }
1282                 fclose(fp);
1283                 CtdlIPC_chat_send(ipc, "000");
1284         }
1285
1286         unlink(temp);
1287 }
1288
1289
1290 void enterinfo(CtdlIPC *ipc)
1291 {                               /* edit info file for current room */
1292         do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1293 }
1294
1295 void enter_bio(CtdlIPC *ipc)
1296 {
1297         char cmd[SIZ];
1298         snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1299         do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1300 }
1301
1302 /*
1303  * create a new floor
1304  */
1305 void create_floor(CtdlIPC *ipc)
1306 {
1307         char buf[SIZ];
1308         char newfloorname[SIZ];
1309         int r;                  /* IPC response code */
1310
1311         load_floorlist(ipc);
1312
1313         r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1314         if ( (r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE) ) {
1315                 scr_printf("%s\n", buf);
1316                 return;
1317         }
1318
1319         newprompt("Name for new floor: ", newfloorname, 255);
1320         if (!*newfloorname) return;
1321         r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1322         if (r / 100 == 2) {
1323                 scr_printf("Floor has been created.\n");
1324         } else {
1325                 scr_printf("%s\n", buf);
1326         }
1327
1328         load_floorlist(ipc);
1329 }
1330
1331 /*
1332  * edit the current floor
1333  */
1334 void edit_floor(CtdlIPC *ipc)
1335 {
1336         char buf[SIZ];
1337         struct ExpirePolicy *ep = NULL;
1338         int r;                          /* IPC response code */
1339
1340         load_floorlist(ipc);
1341
1342         /* Fetch the expire policy (this will silently fail on old servers,
1343          * resulting in "default" policy)
1344          */
1345         r = CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1346
1347         /* Interact with the user */
1348         scr_printf("You are editing the floor called \"%s\"\n", 
1349                 &floorlist[(int) curr_floor][0] );
1350         strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1351
1352         /* Angels and demons dancing in my head... */
1353         do {
1354                 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1355                 strprompt
1356                     ("Floor default message expire policy (? for list)",
1357                      buf, 1);
1358                 if (buf[0] == '?') {
1359                         scr_printf("\n"
1360                                 "0. Use the system default\n"
1361                                 "1. Never automatically expire messages\n"
1362                                 "2. Expire by message count\n"
1363                                 "3. Expire by message age\n");
1364                 }
1365         } while ((buf[0] < '0') || (buf[0] > '3'));
1366         ep->expire_mode = buf[0] - '0';
1367
1368         /* ...lunatics and monsters underneath my bed */
1369         if (ep->expire_mode == 2) {
1370                 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1371                 strprompt("Keep how many messages online?", buf, 10);
1372                 ep->expire_value = atol(buf);
1373         }
1374
1375         if (ep->expire_mode == 3) {
1376                 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1377                 strprompt("Keep messages for how many days?", buf, 10);
1378                 ep->expire_value = atol(buf);
1379         }
1380
1381         /* Save it */
1382         r = CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1383         r = CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf);
1384         scr_printf("%s\n", buf);
1385         load_floorlist(ipc);
1386 }
1387
1388
1389
1390
1391 /*
1392  * kill the current floor 
1393  */
1394 void kill_floor(CtdlIPC *ipc)
1395 {
1396         int floornum_to_delete, a;
1397         char buf[SIZ];
1398
1399         load_floorlist(ipc);
1400         do {
1401                 floornum_to_delete = (-1);
1402                 scr_printf("(Press return to abort)\n");
1403                 newprompt("Delete which floor? ", buf, 255);
1404                 if (IsEmptyStr(buf))
1405                         return;
1406                 for (a = 0; a < 128; ++a)
1407                         if (!strcasecmp(&floorlist[a][0], buf))
1408                                 floornum_to_delete = a;
1409                 if (floornum_to_delete < 0) {
1410                         scr_printf("No such floor.  Select one of:\n");
1411                         for (a = 0; a < 128; ++a)
1412                                 if (floorlist[a][0] != 0)
1413                                         scr_printf("%s\n", &floorlist[a][0]);
1414                 }
1415         } while (floornum_to_delete < 0);
1416         CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1417         scr_printf("%s\n", buf);
1418         load_floorlist(ipc);
1419 }