]> code.citadel.org Git - citadel.git/blob - citadel/rooms.c
* Makefile.in: simplified to use pattern rules; files compiled with
[citadel.git] / citadel / rooms.c
1 /* Citadel/UX room-oriented routines */
2
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <fcntl.h>
6 #include <stdio.h>
7 #include <ctype.h>
8 #include <string.h>
9 #include <signal.h>
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <sys/wait.h>
13 #include <errno.h>
14 #include "citadel.h"
15 #include "rooms.h"
16 #include "tools.h"
17
18 #define IFEXPERT if (userflags&US_EXPERT)
19 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
20 #define IFAIDE if (axlevel>=6)
21 #define IFNAIDE if (axlevel<6)
22
23
24 void sttybbs(int cmd);
25 void extract(char *dest, char *source, int parmnum);
26 int extract_int(char *source, int parmnum);
27 void hit_any_key(void);
28 int yesno(void);
29 int yesno_d(int d);
30 void strprompt(char *prompt, char *str, int len);
31 void newprompt(char *prompt, char *str, int len);
32 int struncmp(char *lstr, char *rstr, int len);
33 void dotgoto(char *towhere, int display_name);
34 long extract_long(char *source, int parmnum);
35 void serv_read(char *buf, int bytes);
36 void formout(char *name);
37 int inkey(void);
38 int fmout(int width, FILE *fp, char pagin, int height, int starting_lp, char subst);
39 void citedit(FILE *fp, long int base_pos);
40 void progress(long int curr, long int cmax);
41 int pattern(char *search, char *patn);
42 int file_checksum(char *filename);
43 int nukedir(char *dirname);
44 void color(int colornum);
45
46 extern unsigned room_flags;
47 extern char room_name[];
48 extern char temp[];
49 extern char tempdir[];
50 extern int editor_pid;
51 extern char editor_path[];
52 extern int screenwidth;
53 extern int screenheight;
54 extern char fullname[];
55 extern int userflags;
56 extern char sigcaught;
57 extern char floor_mode;
58 extern char curr_floor;
59
60
61 extern int ugnum;
62 extern long uglsn;
63 extern char ugname[];
64
65 extern char floorlist[128][256];
66
67
68 void load_floorlist(void) {
69         int a;
70         char buf[256];
71
72         for (a=0; a<128; ++a) floorlist[a][0] = 0;
73
74         serv_puts("LFLR");
75         serv_gets(buf);
76         if (buf[0]!='1') {
77                 strcpy(floorlist[0],"Main Floor");
78                 return;
79                 }
80         while (serv_gets(buf), strcmp(buf,"000")) {
81                 extract(floorlist[extract_int(buf,0)],buf,1);
82                 }
83         }
84
85 void listrms(char *variety)
86 {
87         char buf[256];
88         char rmname[32];
89         int f,c;
90
91         serv_puts(variety);
92         serv_gets(buf);
93         if (buf[0]!='1') return;
94         c = 1;
95         sigcaught = 0;
96         sttybbs(SB_YES_INTR);
97         while (serv_gets(buf), strcmp(buf,"000")) if (sigcaught==0) {
98                 extract(rmname,buf,0);
99                 if ((c + strlen(rmname) + 4) > screenwidth) {
100                         printf("\n");
101                         c = 1;
102                         }
103                 f = extract_int(buf,1);
104                 if (f & QR_PRIVATE) {
105                         color(1);
106                         }
107                 else {
108                         color(2);
109                         }
110                 printf("%s",rmname);
111                 if ((f & QR_DIRECTORY) && (f & QR_NETWORK)) printf("}  ");
112                 else if (f & QR_DIRECTORY) printf("]  ");
113                 else if (f & QR_NETWORK) printf(")  ");
114                 else printf(">  ");
115                 c = c + strlen(rmname) + 3;
116                 }
117         color(7);
118         sttybbs(SB_NO_INTR);
119         }
120
121
122 void list_other_floors(void) {
123         int a,c;
124
125         c = 1;
126         for (a=0; a<128; ++a) if ((strlen(floorlist[a])>0)&&(a!=curr_floor)) {
127                 if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
128                         printf("\n");
129                         c = 1;
130                         }
131                 printf("%s:  ",floorlist[a]);
132                 c = c + strlen(floorlist[a]) + 3;
133                 }
134         }
135
136
137 /*
138  * List known rooms.  kn_floor_mode should be set to 0 for a 'flat' listing,
139  * 1 to list rooms on the current floor, or 1 to list rooms on all floors.
140  */
141 void knrooms(int kn_floor_mode)
142 {
143         char buf[256];
144         int a;
145
146         load_floorlist();
147
148         if (kn_floor_mode == 0) {
149                 color(3);
150                 printf("\n   Rooms with unread messages:\n");
151                 listrms("LKRN");
152                 color(3);
153                 printf("\n\n   No unseen messages in:\n");
154                 listrms("LKRO");
155                 printf("\n");
156                 }
157
158         if (kn_floor_mode == 1) {
159                 color(3);
160                 printf("\n   Rooms with unread messages on %s:\n",
161                         floorlist[(int)curr_floor]);
162                 sprintf(buf,"LKRN %d",curr_floor);
163                 listrms(buf);
164                 color(3);
165                 printf("\n\n   Rooms with no new messages on %s:\n",
166                         floorlist[(int)curr_floor]);
167                 sprintf(buf,"LKRO %d",curr_floor);
168                 listrms(buf);
169                 color(3);
170                 printf("\n\n   Other floors:\n");
171                 list_other_floors();
172                 printf("\n");
173                 }
174
175         if (kn_floor_mode == 2) {
176                 for (a=0; a<128; ++a) if (floorlist[a][0]!=0) {
177                         color(3);
178                         printf("\n   Rooms on %s:\n",floorlist[a]);
179                         sprintf(buf,"LKRA %d",a);
180                         listrms(buf);
181                         printf("\n");
182                         }
183                 }
184         
185         color(7);
186         IFNEXPERT hit_any_key();
187         }
188
189
190 void listzrooms(void) {         /* list public forgotten rooms */
191         color(3);
192         printf("\n   Forgotten public rooms:\n");
193         listrms("LZRM");
194         printf("\n");
195         color(7);
196         IFNEXPERT hit_any_key();
197         }
198
199
200 int set_room_attr(int ibuf, char *prompt, unsigned int sbit)
201 {
202         int a;
203
204         printf("%s [%s]? ",prompt,((ibuf&sbit) ? "Yes":"No"));
205         a=yesno_d(ibuf&sbit);
206         ibuf=(ibuf|sbit);
207         if (!a) ibuf=(ibuf^sbit);
208         return(ibuf);
209         }
210
211
212
213 /*
214  * Select a floor (used in several commands)
215  * The supplied argument is the 'default' floor number.
216  * This function returns the selected floor number.
217  */
218 int select_floor(int rfloor)
219 {
220         int a, newfloor;
221         char floorstr[256];
222
223         if (floor_mode == 1) {
224                 if (floorlist[(int)curr_floor][0]==0) load_floorlist();
225
226                 do {
227                         newfloor = (-1);
228                         safestrncpy(floorstr,floorlist[rfloor],sizeof floorstr);
229                         strprompt("Which floor",floorstr,256);
230                         for (a=0; a<128; ++a) {
231                                 if (!strucmp(floorstr,&floorlist[a][0]))
232                                         newfloor = a;
233                                 if ((newfloor<0)&&(!struncmp(floorstr,
234                                         &floorlist[a][0],strlen(floorstr))))
235                                                 newfloor = a;
236                                 if ((newfloor<0)&&(pattern(&floorlist[a][0],
237                                         floorstr)>=0)) newfloor = a;
238                                 }
239                         if (newfloor<0) {
240                                 printf("\n One of:\n");
241                                 for (a=0; a<128; ++a)
242                                         if (floorlist[a][0]!=0)
243                                                 printf("%s\n",
244                                                         &floorlist[a][0]);
245                                 }
246                         } while(newfloor < 0);
247                 return(newfloor);
248                 }
249         return(rfloor);
250         }
251
252
253
254
255 /*
256  * .<A>ide <E>dit room
257  */
258 void editthisroom(void) {
259         char rname[ROOMNAMELEN];
260         char rpass[10];
261         char rdir[15];
262         unsigned rflags;
263         int rbump;
264         char raide[32];
265         char buf[256];
266         int rfloor;
267
268         serv_puts("GETR");
269         serv_gets(buf);
270         if (buf[0]!='2') {
271                 printf("%s\n",&buf[4]);
272                 return;
273                 }
274
275         extract(rname,&buf[4],0);
276         extract(rpass,&buf[4],1);
277         extract(rdir, &buf[4],2);
278         rflags = extract_int(&buf[4],3);
279         rfloor = extract_int(&buf[4],4);
280         rbump = 0;
281
282         serv_puts("GETA");
283         serv_gets(buf);
284         if (buf[0]=='2') safestrncpy(raide,&buf[4],sizeof raide);
285         else strcpy(raide,"");
286         if (strlen(raide)==0) strcpy(raide,"none");
287
288         strprompt("Room name",rname,ROOMNAMELEN-1);
289
290         rfloor = select_floor(rfloor);
291         rflags = set_room_attr(rflags,"Private room",QR_PRIVATE);
292         if (rflags & QR_PRIVATE)
293                 rflags = set_room_attr(rflags,
294                         "Accessible by guessing room name",QR_GUESSNAME);
295
296         /* if it's public, clear the privacy classes */
297         if ((rflags & QR_PRIVATE)==0) {
298                 if (rflags & QR_GUESSNAME)  rflags = rflags - QR_GUESSNAME;
299                 if (rflags & QR_PASSWORDED) rflags = rflags - QR_PASSWORDED;
300                 }
301
302         /* if it's private, choose the privacy classes */
303         if ( (rflags & QR_PRIVATE)
304            && ( (rflags & QR_GUESSNAME) == 0) ) {
305                 rflags = set_room_attr(rflags,
306                         "Accessible by entering a password",QR_PASSWORDED);
307                 }
308         if ( (rflags & QR_PRIVATE)
309            && ((rflags&QR_PASSWORDED)==QR_PASSWORDED) ) {
310                 strprompt("Room password",rpass,9);
311                 }
312
313         if ((rflags&QR_PRIVATE)==QR_PRIVATE) {
314                 printf("Cause current users to forget room [No] ? ");
315                 if (yesno_d(0)==1) rbump = 1;
316                 }
317
318         rflags = set_room_attr(rflags,"Preferred users only",QR_PREFONLY);
319         rflags = set_room_attr(rflags,"Read-only room",QR_READONLY);
320         rflags = set_room_attr(rflags,"Directory room",QR_DIRECTORY);
321         rflags = set_room_attr(rflags,"Permanent room",QR_PERMANENT);
322         if (rflags & QR_DIRECTORY) {
323                 strprompt("Directory name",rdir,14);
324                 rflags = set_room_attr(rflags,"Uploading allowed",QR_UPLOAD);
325                 rflags = set_room_attr(rflags,"Downloading allowed",
326                                                                 QR_DOWNLOAD);
327                 rflags = set_room_attr(rflags,"Visible directory",QR_VISDIR);
328                 }
329         rflags = set_room_attr(rflags,"Network shared room",QR_NETWORK);
330         rflags = set_room_attr(rflags,
331                 "Automatically make all messages anonymous",QR_ANONONLY);
332         if ( (rflags & QR_ANONONLY) == 0) {
333                 rflags = set_room_attr(rflags,
334                         "Ask users whether to make messages anonymous",
335                         QR_ANONOPT);
336                 }
337
338         do {
339                 strprompt("Room aide (or 'none')",raide,29);
340                 if (!strucmp(raide,"none")) {
341                         strcpy(raide,"");
342                         strcpy(buf,"200");
343                         }
344                 else {
345                         snprintf(buf,sizeof buf,"QUSR %s",raide);
346                         serv_puts(buf);
347                         serv_gets(buf);
348                         if (buf[0]!='2') printf("%s\n",&buf[4]);
349                         }
350                 } while(buf[0]!='2');
351
352         if (!strucmp(raide,"none")) strcpy(raide,"");
353
354         printf("Save changes (y/n)? ");
355         if (yesno()==1) {
356                 snprintf(buf,sizeof buf,"SETR %s|%s|%s|%d|%d|%d",
357                         rname,rpass,rdir,rflags,rbump,rfloor);
358                 serv_puts(buf);
359                 serv_gets(buf);
360                 printf("%s\n",&buf[4]);
361                 snprintf(buf,sizeof buf,"SETA %s",raide);
362                 serv_puts(buf);
363                 serv_gets(buf);
364                 if (buf[0]=='2') dotgoto(rname,2);
365                 }
366         }
367
368
369 /*
370  * un-goto the previous room
371  */
372 void ungoto(void) { 
373         char buf[256];
374         
375         if (!strcmp(ugname,"")) return;
376         snprintf(buf,sizeof buf,"GOTO %s",ugname);
377         serv_puts(buf);
378         serv_gets(buf);
379         if (buf[0]!='2') {
380                 printf("%s\n",&buf[4]);
381                 return;
382                 }
383         sprintf(buf,"SLRP %ld",uglsn);
384         serv_puts(buf);
385         serv_gets(buf);
386         if (buf[0]!='2') printf("%s\n",&buf[4]);
387         safestrncpy(buf,ugname,sizeof buf);
388         strcpy(ugname,"");
389         dotgoto(buf,0);
390         }
391
392
393 /*
394  * download()  -  download a file or files.  The argument passed to this
395  *                function determines which protocol to use.
396  */
397 void download(int proto)
398 {
399
400 /*
401   - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
402 */
403
404
405         char buf[256];
406         char dbuf[4096];
407         char filename[256];
408         long total_bytes = 0L;
409         long transmitted_bytes = 0L;
410         long aa,bb;
411         int a,b;
412         int packet;
413         FILE *tpipe = NULL;
414         FILE *savefp = NULL;
415         int proto_pid;
416         int broken = 0;
417
418         if ((room_flags & QR_DOWNLOAD) == 0) {
419                 printf("*** You cannot download from this room.\n");
420                 return;
421                 }
422         
423         newprompt("Enter filename: ",filename,255);
424
425         snprintf(buf,sizeof buf,"OPEN %s",filename);
426         serv_puts(buf);
427         serv_gets(buf);
428         if (buf[0]!='2') {
429                 printf("%s\n",&buf[4]);
430                 return;
431                 }
432         total_bytes = extract_long(&buf[4],0);
433
434
435         /* Here's the code for simply transferring the file to the client,
436          * for folks who have their own clientware.  It's a lot simpler than
437          * the [XYZ]modem code below...
438          */
439         if (proto == 5) {
440                 printf("Enter the name of the directory to save '%s'\n",
441                         filename);
442                 printf("to, or press return for the current directory.\n");
443                 newprompt("Directory: ",dbuf,256);
444                 if (strlen(dbuf)==0) strcpy(dbuf,".");
445                 strcat(dbuf,"/");
446                 strcat(dbuf,filename);
447                 
448                 savefp = fopen(dbuf,"w");
449                 if (savefp == NULL) {
450                         printf("Cannot open '%s': %s\n",dbuf,strerror(errno));
451                         /* close the download file at the server */
452                         serv_puts("CLOS");
453                         serv_gets(buf);
454                         if (buf[0]!='2') {
455                                 printf("%s\n",&buf[4]);
456                                 }
457                         return;
458                         }
459                 progress(0,total_bytes);
460                 while ( (transmitted_bytes < total_bytes) && (broken == 0) ) {
461                         bb = total_bytes - transmitted_bytes;
462                         aa = ((bb < 4096) ? bb : 4096);
463                         sprintf(buf,"READ %ld|%ld",transmitted_bytes,aa);
464                         serv_puts(buf);
465                         serv_gets(buf);
466                         if (buf[0]!='6') {
467                                 printf("%s\n",&buf[4]);
468                                 return;
469                                 }
470                         packet = extract_int(&buf[4],0);
471                         serv_read(dbuf,packet);
472                         if (fwrite(dbuf,packet,1,savefp) < 1) broken = 1;
473                         transmitted_bytes = transmitted_bytes + (long)packet;
474                         progress(transmitted_bytes,total_bytes);
475                         }
476                 fclose(savefp);
477                 /* close the download file at the server */
478                 serv_puts("CLOS");
479                 serv_gets(buf);
480                 if (buf[0]!='2') {
481                         printf("%s\n",&buf[4]);
482                         }
483                 return;
484                 }
485
486
487         mkdir(tempdir,0700);
488         snprintf(buf,sizeof buf,"%s/%s",tempdir,filename);
489         mkfifo(buf, 0777);
490
491         /* We do the remainder of this function as a separate process in
492          * order to allow recovery if the transfer is aborted.  If the
493          * file transfer program aborts, the first child process receives a
494          * "broken pipe" signal and aborts.  We *should* be able to catch
495          * this condition with signal(), but it doesn't seem to work on all
496          * systems.
497          */
498         a = fork();
499         if (a!=0) {
500                 /* wait for the download to finish */
501                 while (wait(&b)!=a) ;;
502                 sttybbs(0);
503                 /* close the download file at the server */
504                 serv_puts("CLOS");
505                 serv_gets(buf);
506                 if (buf[0]!='2') {
507                         printf("%s\n",&buf[4]);
508                         }
509                 /* clean up the temporary directory */
510                 nukedir(tempdir);
511                 return;
512                 }
513
514         snprintf(buf,sizeof buf,"%s/%s",tempdir,filename); /* full pathname */
515
516         /* The next fork() creates a second child process that is used for
517          * the actual file transfer program (usually sz).
518          */
519         proto_pid = fork();
520         if (proto_pid == 0) {
521                 if (proto==0)  {
522                         sttybbs(0);
523                         signal(SIGINT,SIG_DFL);
524                         signal(SIGQUIT,SIG_DFL);
525                         snprintf(dbuf,sizeof dbuf,"SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",buf);
526                         system(dbuf);
527                         sttybbs(SB_NO_INTR);
528                         exit(0);
529                         }
530                 sttybbs(3);
531                 signal(SIGINT,SIG_DFL);
532                 signal(SIGQUIT,SIG_DFL);
533                 if (proto==1) execlp("sx","sx",buf,NULL);
534                 if (proto==2) execlp("cat","cat",buf,NULL);
535                 if (proto==3) execlp("sb","sb",buf,NULL);
536                 if (proto==4) execlp("sz","sz",buf,NULL);
537                 execlp("cat","cat",buf,NULL);
538                 exit(1);
539                 }
540
541         tpipe = fopen(buf,"w");
542
543         while ( (transmitted_bytes < total_bytes) && (broken == 0) ) {
544                 bb = total_bytes - transmitted_bytes;
545                 aa = ((bb < 4096) ? bb : 4096);
546                 sprintf(buf,"READ %ld|%ld",transmitted_bytes,aa);
547                 serv_puts(buf);
548                 serv_gets(buf);
549                 if (buf[0]!='6') {
550                         printf("%s\n",&buf[4]);
551                         return;
552                         }
553                 packet = extract_int(&buf[4],0);
554                 serv_read(dbuf,packet);
555                 if (fwrite(dbuf,packet,1,tpipe) < 1) broken = 1;
556                 transmitted_bytes = transmitted_bytes + (long)packet;
557                 }
558         if (tpipe!=NULL) fclose(tpipe);
559
560         /* Hang out and wait for the file transfer program to finish */
561         while (wait(&a) != proto_pid) ;;
562
563
564         putc(7,stdout);
565         exit(0);        /* transfer control back to the main program */
566         }
567
568
569 /*
570  * read directory of this room
571  */
572 void roomdir(void) {
573         char flnm[256];
574         char flsz[32];
575         char comment[256];
576         char buf[256];
577
578         serv_puts("RDIR");
579         serv_gets(buf);
580         if (buf[0]!='1') {
581                 printf("%s\n",&buf[4]);
582                 return;
583                 }
584
585         extract(comment,&buf[4],0);
586         extract(flnm,&buf[4],1);
587         printf("\nDirectory of %s on %s\n",flnm,comment);
588         printf("-----------------------\n");
589         while (serv_gets(buf), strcmp(buf,"000")) {
590                 extract(flnm,buf,0);
591                 extract(flsz,buf,1);
592                 extract(comment,buf,2);
593                 if (strlen(flnm)<=14)
594                         printf("%-14s %8s %s\n",flnm,flsz,comment);
595                 else
596                         printf("%s\n%14s %8s %s\n",flnm,"",flsz,comment);
597                 }
598         }
599
600
601 /*
602  * add a user to a private room
603  */
604 void invite(void) {
605         char aaa[31],bbb[256];
606
607         if ((room_flags & QR_PRIVATE)==0) {
608                 printf("This is not a private room.\n");
609                 return;
610                 }
611
612         newprompt("Name of user? ",aaa,30);
613         if (aaa[0]==0) return;
614
615         snprintf(bbb,sizeof bbb,"INVT %s",aaa);
616         serv_puts(bbb);
617         serv_gets(bbb);
618         printf("%s\n",&bbb[4]);
619         }
620
621
622 /*
623  * kick a user out of a room
624  */
625 void kickout(void) {
626         char aaa[31],bbb[256];
627
628         if ((room_flags & QR_PRIVATE)==0) {
629                 printf("Note: this is not a private room.  Kicking a user ");
630                 printf("out of this room will only\nhave the same effect ");
631                 printf("as if they <Z>apped the room.\n\n");
632                 }
633
634         newprompt("Name of user? ",aaa,30);
635         if (aaa[0]==0) return;
636
637         snprintf(bbb,sizeof bbb,"KICK %s",aaa);
638         serv_puts(bbb);
639         serv_gets(bbb);
640         printf("%s\n",&bbb[4]);
641         }
642
643
644 /*
645  * aide command: kill the current room
646  */
647 void killroom(void) {
648         char aaa[100];
649
650         serv_puts("KILL 0");
651         serv_gets(aaa);
652         if (aaa[0]!='2') {
653                 printf("%s\n",&aaa[4]);
654                 return;
655                 }
656
657         printf("Are you sure you want to kill this room? ");
658         if (yesno()==0) return;
659
660         serv_puts("KILL 1");
661         serv_gets(aaa);
662         printf("%s\n",&aaa[4]);
663         if (aaa[0]!='2') return;
664         dotgoto("_BASEROOM_",0);
665         }
666
667 void forget(void) {     /* forget the current room */
668         char cmd[256];
669
670         printf("Are you sure you want to forget this room? ");
671         if (yesno()==0) return;
672
673         serv_puts("FORG");
674         serv_gets(cmd);
675         if (cmd[0]!='2') {
676                 printf("%s\n",&cmd[4]);
677                 return;
678                 }
679
680         /* now return to the lobby */
681         dotgoto("_BASEROOM_",0);
682         }
683
684
685 /*
686  * create a new room
687  */
688 void entroom(void) {
689         char cmd[256];
690         char new_room_name[ROOMNAMELEN];
691         int new_room_type;
692         char new_room_pass[10];
693         int new_room_floor;
694         int a,b;
695
696         serv_puts("CRE8 0");
697         serv_gets(cmd);
698         
699         if (cmd[0]!='2') {
700                 printf("%s\n",&cmd[4]);
701                 return;
702                 }
703         
704         newprompt("Name for new room? ",new_room_name,ROOMNAMELEN-1);
705         if (strlen(new_room_name)==0) return;
706         for (a=0; a<strlen(new_room_name); ++a)
707                 if (new_room_name[a] == '|') new_room_name[a]='_';
708
709         new_room_floor = select_floor((int)curr_floor);
710
711         IFNEXPERT formout("roomaccess");
712         do {
713                 printf("<?>Help\n<1>Public room\n<2>Guess-name room\n");
714                 printf("<3>Passworded room\n<4>Invitation-only room\n");
715                 printf("Enter room type: ");
716                 do {
717                         b=inkey();
718                         } while (((b<'1')||(b>'4')) && (b!='?'));
719                 if (b=='?') {
720                         printf("?\n");
721                         formout("roomaccess");
722                         }
723                 } while ((b<'1')||(b>'4'));
724         b=b-48;
725         printf("%d\n",b);
726         new_room_type = b - 1;
727         if (new_room_type==2) {
728                 newprompt("Enter a room password: ",new_room_pass,9);
729                 for (a=0; a<strlen(new_room_pass); ++a)
730                         if (new_room_pass[a] == '|') new_room_pass[a]='_';
731                 }
732         else strcpy(new_room_pass,"");
733
734         printf("\042%s\042, a",new_room_name);
735         if (b==1) printf(" public room.");
736         if (b==2) printf(" guess-name room.");
737         if (b==3) printf(" passworded room, password: %s",new_room_pass);
738         if (b==4) printf("n invitation-only room.");
739         printf("\nInstall it? (y/n) : ");
740         a=yesno();
741         if (a==0) return;
742
743         snprintf(cmd, sizeof cmd, "CRE8 1|%s|%d|%s|%d", new_room_name,
744                 new_room_type, new_room_pass, new_room_floor);
745         serv_puts(cmd);
746         serv_gets(cmd);
747         if (cmd[0]!='2') {
748                 printf("%s\n",&cmd[4]);
749                 return;
750                 }
751
752         /* command succeeded... now GO to the new room! */
753         dotgoto(new_room_name,0);
754         }
755
756
757
758 void readinfo(void) {   /* read info file for current room */
759         char cmd[256];
760         
761         sprintf(cmd,"RINF");
762         serv_puts(cmd);
763         serv_gets(cmd);
764
765         if (cmd[0]!='1') return;
766
767         fmout(screenwidth,NULL,
768                 ((userflags & US_PAGINATOR) ? 1 : 0),
769                 screenheight,0,1);
770         }
771
772
773 /*
774  * <W>ho knows room...
775  */
776 void whoknows(void) {
777         char buf[256];
778         serv_puts("WHOK");
779         serv_gets(buf);
780         if (buf[0]!='1') {
781                 printf("%s\n",&buf[5]);
782                 return;
783                 }
784         sigcaught = 0;
785         sttybbs(SB_YES_INTR);
786         while (serv_gets(buf), strncmp(buf,"000",3)) {
787                 if (sigcaught==0) printf("%s\n",buf);
788                 }
789         sttybbs(SB_NO_INTR);
790         }
791
792
793 void do_edit(char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
794 {
795         FILE *fp;
796         char cmd[256];
797         int b,cksum,editor_exit;
798
799
800         if (strlen(editor_path)==0) {
801                 printf("Do you wish to re-enter %s? ",desc);
802                 if (yesno()==0) return;
803                 }
804
805         fp = fopen(temp,"w");
806         fclose(fp);
807
808         serv_puts(check_cmd);
809         serv_gets(cmd);
810         if (cmd[0]!='2') {
811                 printf("%s\n",&cmd[4]);
812                 return;
813                 }
814
815         if (strlen(editor_path)>0) {
816                 serv_puts(read_cmd);
817                 serv_gets(cmd);
818                 if (cmd[0]=='1') {
819                         fp = fopen(temp,"w");
820                         while (serv_gets(cmd), strcmp(cmd,"000")) {
821                                 fprintf(fp,"%s\n",cmd);
822                                 }
823                         fclose(fp);
824                         }
825                 }
826
827         cksum = file_checksum(temp);
828
829         if (strlen(editor_path)>0) {
830                 editor_pid=fork();
831                 if (editor_pid==0) {
832                         chmod(temp,0600);
833                         sttybbs(SB_RESTORE);
834                         execlp(editor_path,editor_path,temp,NULL);
835                         exit(1);
836                         }
837                 if (editor_pid>0) do {
838                         editor_exit = 0;
839                         b=wait(&editor_exit);
840                         } while((b!=editor_pid)&&(b>=0));
841                 editor_pid = (-1);
842                 printf("Executed %s\n", editor_path);
843                 sttybbs(0);
844                 }
845         else {
846                 printf("Entering %s.  ",desc);
847                 printf("Press return twice when finished.\n");
848                 fp=fopen(temp,"r+");
849                 citedit(fp,0);
850                 fclose(fp);
851                 }
852
853         if (file_checksum(temp) == cksum) {
854                 printf("*** Aborted.\n");
855                 }
856
857         else {
858                 serv_puts(write_cmd);
859                 serv_gets(cmd);
860                 if (cmd[0]!='4') {
861                         printf("%s\n",&cmd[4]);
862                         return;
863                         }
864
865                 fp=fopen(temp,"r");
866                 while (fgets(cmd,255,fp)!=NULL) {
867                         cmd[strlen(cmd)-1] = 0;
868                         serv_puts(cmd);
869                         }
870                 fclose(fp);
871                 serv_puts("000");
872                 }
873
874         unlink(temp);
875         }
876
877
878 void enterinfo(void) {          /* edit info file for current room */
879         do_edit("the Info file for this room","RINF","EINF 0","EINF 1");
880         }
881
882 void enter_bio(void) {
883         char cmd[256];
884         snprintf(cmd,sizeof cmd,"RBIO %s",fullname);
885         do_edit("your Bio",cmd,"NOOP","EBIO");
886         }
887
888 /*
889  * create a new floor
890  */
891 void create_floor(void) {
892         char buf[256];
893         char newfloorname[256];
894
895         serv_puts("CFLR xx|0");
896         serv_gets(buf);
897         if (buf[0]!='2') {
898                 printf("%s\n",&buf[4]);
899                 return;
900                 }
901
902         newprompt("Name for new floor: ",newfloorname,255);
903         snprintf(buf,sizeof buf,"CFLR %s|1",newfloorname);
904         serv_puts(buf);
905         serv_gets(buf);
906         if (buf[0]=='2') {
907                 printf("Floor has been created.\n");
908                 }
909         else {
910                 printf("%s\n",&buf[4]);
911                 }
912         }
913
914 /*
915  * edit the current floor
916  */
917 void edit_floor(void) {
918         char buf[256];
919
920         if (floorlist[(int)curr_floor][0]==0) load_floorlist();
921         strprompt("New floor name",&floorlist[(int)curr_floor][0],255);
922         snprintf(buf,sizeof buf,"EFLR %d|%s",curr_floor,
923                  &floorlist[(int)curr_floor][0]);
924         serv_puts(buf);
925         serv_gets(buf);
926         printf("%s\n",&buf[4]);
927         load_floorlist();
928         }
929
930
931
932
933 /*
934  * kill the current floor 
935  */
936 void kill_floor(void) {
937         int floornum_to_delete,a;
938         char buf[256];
939
940         if (floorlist[(int)curr_floor][0]==0) load_floorlist();
941         do {
942                 floornum_to_delete = (-1);
943                 printf("(Press return to abort)\n");
944                 newprompt("Delete which floor? ",buf,255);
945                 if (strlen(buf)==0) return;
946                 for (a=0; a<128; ++a)
947                         if (!strucmp(&floorlist[a][0],buf))
948                                 floornum_to_delete = a;
949                 if (floornum_to_delete < 0) {
950                         printf("No such floor.  Select one of:\n");
951                         for (a=0; a<128; ++a)
952                                 if (floorlist[a][0]!=0)
953                                         printf("%s\n",&floorlist[a][0]);
954                         }
955                 } while (floornum_to_delete < 0);
956         sprintf(buf,"KFLR %d|1",floornum_to_delete);
957         serv_puts(buf);
958         serv_gets(buf);
959         printf("%s\n",&buf[4]);
960         }