* Placated users who whine about privacy policy by adding MESG ROOMACCESS to
[citadel.git] / webcit / roomops.c
1 /* $Id$ */
2
3
4 #include <ctype.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <stdio.h>
8 #include <fcntl.h>
9 #include <signal.h>
10 #include <sys/types.h>
11 #include <sys/wait.h>
12 #include <sys/socket.h>
13 #include <sys/time.h>
14 #include <limits.h>
15 #include <netinet/in.h>
16 #include <netdb.h>
17 #include <string.h>
18 #include <pwd.h>
19 #include <errno.h>
20 #include <stdarg.h>
21 #include <pthread.h>
22 #include <signal.h>
23 #include "webcit.h"
24
25
26
27
28
29
30
31 char floorlist[128][256];
32
33
34 /*
35  * load the list of floors
36  */
37 void load_floorlist(void)
38 {
39         int a;
40         char buf[256];
41
42         for (a = 0; a < 128; ++a)
43                 floorlist[a][0] = 0;
44
45         serv_puts("LFLR");
46         serv_gets(buf);
47         if (buf[0] != '1') {
48                 strcpy(floorlist[0], "Main Floor");
49                 return;
50         }
51         while (serv_gets(buf), strcmp(buf, "000")) {
52                 extract(floorlist[extract_int(buf, 0)], buf, 1);
53         }
54 }
55
56
57 /*
58  * remove a room from the march list
59  */
60 void remove_march(char *aaa)
61 {
62         struct march *mptr, *mptr2;
63
64         if (WC->march == NULL)
65                 return;
66
67         if (!strcasecmp(WC->march->march_name, aaa)) {
68                 mptr = WC->march->next;
69                 free(WC->march);
70                 WC->march = mptr;
71                 return;
72         }
73         mptr2 = WC->march;
74         for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
75                 if (!strcasecmp(mptr->march_name, aaa)) {
76                         mptr2->next = mptr->next;
77                         free(mptr);
78                         mptr = mptr2;
79                 } else {
80                         mptr2 = mptr;
81                 }
82         }
83 }
84
85
86
87
88
89 void room_tree_list(struct roomlisting *rp)
90 {
91         char rmname[64];
92         int f;
93
94         if (rp == NULL)
95                 return;
96
97         if (rp->lnext != NULL) {
98                 room_tree_list(rp->lnext);
99         }
100         strcpy(rmname, rp->rlname);
101         f = rp->rlflags;
102
103         wprintf("<A HREF=\"/dotgoto&room=");
104         urlescputs(rmname);
105         wprintf("\"");
106         wprintf(">");
107         escputs1(rmname, 1);
108         if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
109                 wprintf("}");
110         else if (f & QR_DIRECTORY)
111                 wprintf("]");
112         else if (f & QR_NETWORK)
113                 wprintf(")");
114         else
115                 wprintf("&gt;");
116         wprintf("</A><TT> </TT>\n");
117
118         if (rp->rnext != NULL) {
119                 room_tree_list(rp->rnext);
120         }
121         free(rp);
122 }
123
124
125 /* 
126  * Room ordering stuff (compare first by floor, then by order)
127  */
128 int rordercmp(struct roomlisting *r1, struct roomlisting *r2)
129 {
130         if ((r1 == NULL) && (r2 == NULL))
131                 return (0);
132         if (r1 == NULL)
133                 return (-1);
134         if (r2 == NULL)
135                 return (1);
136         if (r1->rlfloor < r2->rlfloor)
137                 return (-1);
138         if (r1->rlfloor > r2->rlfloor)
139                 return (1);
140         if (r1->rlorder < r2->rlorder)
141                 return (-1);
142         if (r1->rlorder > r2->rlorder)
143                 return (1);
144         return (0);
145 }
146
147
148 /*
149  * Common code for all room listings
150  */
151 void listrms(char *variety)
152 {
153         char buf[256];
154         int num_rooms = 0;
155
156         struct roomlisting *rl = NULL;
157         struct roomlisting *rp;
158         struct roomlisting *rs;
159
160
161         /* Ask the server for a room list */
162         serv_puts(variety);
163         serv_gets(buf);
164         if (buf[0] != '1') {
165                 wprintf("&nbsp;");
166                 return;
167         }
168         while (serv_gets(buf), strcmp(buf, "000")) {
169                 ++num_rooms;
170                 rp = malloc(sizeof(struct roomlisting));
171                 extract(rp->rlname, buf, 0);
172                 rp->rlflags = extract_int(buf, 1);
173                 rp->rlfloor = extract_int(buf, 2);
174                 rp->rlorder = extract_int(buf, 3);
175                 rp->lnext = NULL;
176                 rp->rnext = NULL;
177
178                 rs = rl;
179                 if (rl == NULL) {
180                         rl = rp;
181                 } else
182                         while (rp != NULL) {
183                                 if (rordercmp(rp, rs) < 0) {
184                                         if (rs->lnext == NULL) {
185                                                 rs->lnext = rp;
186                                                 rp = NULL;
187                                         } else {
188                                                 rs = rs->lnext;
189                                         }
190                                 } else {
191                                         if (rs->rnext == NULL) {
192                                                 rs->rnext = rp;
193                                                 rp = NULL;
194                                         } else {
195                                                 rs = rs->rnext;
196                                         }
197                                 }
198                         }
199         }
200
201         room_tree_list(rl);
202
203         /* If no rooms were listed, print an nbsp to make the cell
204          * borders show up anyway.
205          */
206         if (num_rooms == 0) wprintf("&nbsp;");
207 }
208
209
210
211
212
213
214
215
216
217 /*
218  * list all rooms by floor
219  */
220 void list_all_rooms_by_floor(void)
221 {
222         int a;
223         char buf[256];
224
225         load_floorlist();
226
227         output_headers(1);
228
229         wprintf("<TABLE width=100%% border><TR><TH>Floor</TH>");
230         wprintf("<TH>Rooms with new messages</TH>");
231         wprintf("<TH>Rooms with no new messages</TH></TR>\n");
232
233         for (a = 0; a < 128; ++a)
234                 if (floorlist[a][0] != 0) {
235
236                         /* Floor name column */
237                         wprintf("<TR><TD>");
238
239                         serv_printf("OIMG _floorpic_|%d", a);
240                         serv_gets(buf);
241                         if (buf[0] == '2') {
242                                 serv_puts("CLOS");
243                                 serv_gets(buf);
244                                 wprintf("<IMG SRC=\"/image&name=_floorpic_&parm=%d\" ALT=\"%s\">",
245                                         a, &floorlist[a][0]);
246                         } else {
247                                 escputs(&floorlist[a][0]);
248                         }
249
250                         wprintf("</TD>");
251
252                         /* Rooms with new messages column */
253                         wprintf("<TD>");
254                         sprintf(buf, "LKRN %d", a);
255                         listrms(buf);
256                         wprintf("</TD>\n<TD>");
257
258                         /* Rooms with old messages column */
259                         sprintf(buf, "LKRO %d", a);
260                         listrms(buf);
261                         wprintf("</TD></TR>\n");
262                 }
263         wprintf("</TABLE>\n");
264         wDumpContent(1);
265 }
266
267
268 /*
269  * list all forgotten rooms
270  */
271 void zapped_list(void)
272 {
273         output_headers(1);
274         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
275         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
276         wprintf("<B>Zapped (forgotten) rooms</B>\n");
277         wprintf("</TD></TR></TABLE><BR>\n");
278         listrms("LZRM -1");
279         wprintf("<BR><BR>\n");
280         wprintf("Click on any room to un-zap it and goto that room.\n");
281         wDumpContent(1);
282 }
283
284
285 /*
286  * read this room's info file (set v to 1 for verbose mode)
287  */
288 void readinfo(void)
289 {
290         char buf[256];
291
292         serv_puts("RINF");
293         serv_gets(buf);
294         if (buf[0] == '1') {
295                 wprintf("<FONT SIZE=-1>");
296                 fmout(NULL);
297                 wprintf("</FONT>");
298         }
299 }
300
301
302
303
304 /* Display room graphic.  The server doesn't actually
305  * need the room name, but we supply it in order to
306  * keep the browser from using a cached graphic from 
307  * another room.
308  */
309 void embed_room_graphic(void) {
310         char buf[256];
311
312         serv_puts("OIMG _roompic_");
313         serv_gets(buf);
314         if (buf[0] == '2') {
315                 wprintf("<TD>");
316                 wprintf("<IMG SRC=\"/image&name=_roompic_&room=");
317                 urlescputs(WC->wc_roomname);
318                 wprintf("\"></TD>");
319                 serv_puts("CLOS");
320                 serv_gets(buf);
321         }
322
323 }
324
325
326 /* Let the user know if new mail has arrived 
327  */
328 void embed_newmail_button(void) {
329         if ( (WC->new_mail > WC->remember_new_mail) && (WC->new_mail>0) ) {
330                 wprintf("<TD VALIGN=TOP>"
331                         "<IMG SRC=\"/static/mail.gif\" border=0 "
332                         "ALT=\"You have new mail\">"
333                         "<BR><BLINK>%d</BLINK>", WC->new_mail);
334                 wprintf("<FONT SIZE=-2> new mail messages</FONT></TD>");
335                 WC->remember_new_mail = WC->new_mail;
336         }
337 }
338
339
340
341 void embed_room_banner(char *got) {
342         char fakegot[256];
343
344         /* We need to have the information returned by a GOTO server command.
345          * If it isn't supplied, we fake it by issuing our own GOTO.
346          */
347         if (got == NULL) {
348                 serv_printf("GOTO %s", WC->wc_roomname);
349                 serv_gets(fakegot);
350                 got = fakegot;
351         }
352
353         /* Check for new mail. */
354         WC->new_mail = extract_int(&got[4], 9);
355
356         svprintf("ROOMNAME", WCS_STRING, "%s", WC->wc_roomname);
357         svprintf("NEWMSGS", WCS_STRING, "%d", extract_int(&got[4], 1));
358         svprintf("TOTALMSGS", WCS_STRING, "%d", extract_int(&got[4], 2));
359         svcallback("ROOMPIC", embed_room_graphic);
360         svcallback("ROOMINFO", readinfo);
361         svcallback("YOUHAVEMAIL", embed_newmail_button);
362
363         do_template("roombanner.html");
364         clear_local_substs();
365 }
366
367
368
369
370
371 /*
372  * generic routine to take the session to a new room
373  *
374  * display_name values:  0 = goto only
375  *                       1 = goto and display
376  *                       2 = display only
377  */
378 void gotoroom(char *gname, int display_name)
379 {
380         char buf[256];
381         static long ls = (-1L);
382
383
384         if (display_name) {
385                 output_headers(0);
386                 wprintf("Pragma: no-cache\n");
387                 wprintf("Cache-Control: no-store\n");
388
389                 wprintf("<HTML><HEAD>\n"
390                         "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n"
391                         "</HEAD>\n");
392                 do_template("background.html");
393         }
394         if (display_name != 2) {
395                 /* store ungoto information */
396                 strcpy(WC->ugname, WC->wc_roomname);
397                 WC->uglsn = ls;
398         }
399         /* move to the new room */
400         serv_printf("GOTO %s", gname);
401         serv_gets(buf);
402         if (buf[0] != '2') {
403                 serv_puts("GOTO _BASEROOM_");
404                 serv_gets(buf);
405         }
406         if (buf[0] != '2') {
407                 if (display_name) {
408                         wprintf("<EM>%s</EM><BR>\n", &buf[4]);
409                         wDumpContent(1);
410                 }
411                 return;
412         }
413         extract(WC->wc_roomname, &buf[4], 0);
414         WC->room_flags = extract_int(&buf[4], 4);
415         /* highest_msg_read = extract_int(&buf[4],6);
416            maxmsgnum = extract_int(&buf[4],5);
417            is_mail = (char) extract_int(&buf[4],7); */
418         ls = extract_long(&buf[4], 6);
419
420         if (WC->is_aide)
421                 WC->is_room_aide = WC->is_aide;
422         else
423                 WC->is_room_aide = (char) extract_int(&buf[4], 8);
424
425         remove_march(WC->wc_roomname);
426         if (!strcasecmp(gname, "_BASEROOM_"))
427                 remove_march(gname);
428
429         /* Display the room banner */
430         if (display_name) {
431                 embed_room_banner(buf);
432                 wDumpContent(1);
433         }
434         strcpy(WC->wc_roomname, WC->wc_roomname);
435 }
436
437
438 /*
439  * Locate the room on the march list which we most want to go to.  Each room
440  * is measured given a "weight" of preference based on various factors.
441  */
442 char *pop_march(int desired_floor)
443 {
444         static char TheRoom[64];
445         int TheFloor = 0;
446         int TheOrder = 32767;
447         int TheWeight = 0;
448         int weight;
449         struct march *mptr = NULL;
450
451         strcpy(TheRoom, "_BASEROOM_");
452         if (WC->march == NULL)
453                 return (TheRoom);
454
455         for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
456                 weight = 0;
457                 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
458                         weight = weight + 10000;
459                 if (mptr->march_floor == desired_floor)
460                         weight = weight + 5000;
461
462                 weight = weight + ((128 - (mptr->march_floor)) * 128);
463                 weight = weight + (128 - (mptr->march_order));
464
465                 if (weight > TheWeight) {
466                         TheWeight = weight;
467                         strcpy(TheRoom, mptr->march_name);
468                         TheFloor = mptr->march_floor;
469                         TheOrder = mptr->march_order;
470                 }
471         }
472         return (TheRoom);
473 }
474
475
476
477 /* Goto next room having unread messages.
478  * We want to skip over rooms that the user has already been to, and take the
479  * user back to the lobby when done.  The room we end up in is placed in
480  * newroom - which is set to 0 (the lobby) initially.
481  * We start the search in the current room rather than the beginning to prevent
482  * two or more concurrent users from dragging each other back to the same room.
483  */
484 void gotonext(void)
485 {
486         char buf[256];
487         struct march *mptr, *mptr2;
488         char next_room[32];
489
490         /* First check to see if the march-mode list is already allocated.
491          * If it is, pop the first room off the list and go there.
492          */
493
494         if (WC->march == NULL) {
495                 serv_puts("LKRN");
496                 serv_gets(buf);
497                 if (buf[0] == '1')
498                         while (serv_gets(buf), strcmp(buf, "000")) {
499                                 mptr = (struct march *) malloc(sizeof(struct march));
500                                 mptr->next = NULL;
501                                 extract(mptr->march_name, buf, 0);
502                                 mptr->march_floor = extract_int(buf, 2);
503                                 mptr->march_order = extract_int(buf, 3);
504                                 if (WC->march == NULL) {
505                                         WC->march = mptr;
506                                 } else {
507                                         mptr2 = WC->march;
508                                         while (mptr2->next != NULL)
509                                                 mptr2 = mptr2->next;
510                                         mptr2->next = mptr;
511                                 }
512                         }
513 /* add _BASEROOM_ to the end of the march list, so the user will end up
514  * in the system base room (usually the Lobby>) at the end of the loop
515  */
516                 mptr = (struct march *) malloc(sizeof(struct march));
517                 mptr->next = NULL;
518                 strcpy(mptr->march_name, "_BASEROOM_");
519                 if (WC->march == NULL) {
520                         WC->march = mptr;
521                 } else {
522                         mptr2 = WC->march;
523                         while (mptr2->next != NULL)
524                                 mptr2 = mptr2->next;
525                         mptr2->next = mptr;
526                 }
527 /*
528  * ...and remove the room we're currently in, so a <G>oto doesn't make us
529  * walk around in circles
530  */
531                 remove_march(WC->wc_roomname);
532         }
533         if (WC->march != NULL) {
534                 strcpy(next_room, pop_march(-1));
535         } else {
536                 strcpy(next_room, "_BASEROOM_");
537         }
538
539
540         smart_goto(next_room);
541 }
542
543
544 void smart_goto(char *next_room) {
545         gotoroom(next_room, 0);
546         readloop("readnew");
547 }
548
549
550
551 /*
552  * mark all messages in current room as having been read
553  */
554 void slrp_highest(void)
555 {
556         char buf[256];
557
558         /* set pointer */
559         serv_puts("SLRP HIGHEST");
560         serv_gets(buf);
561         if (buf[0] != '2') {
562                 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
563                 return;
564         }
565 }
566
567
568 /*
569  * un-goto the previous room
570  */
571 void ungoto(void)
572 {
573         char buf[256];
574
575         if (!strcmp(WC->ugname, "")) {
576                 smart_goto(WC->wc_roomname);
577                 return;
578         }
579         serv_printf("GOTO %s", WC->ugname);
580         serv_gets(buf);
581         if (buf[0] != '2') {
582                 smart_goto(WC->wc_roomname);
583                 return;
584         }
585         if (WC->uglsn >= 0L) {
586                 serv_printf("SLRP %ld", WC->uglsn);
587                 serv_gets(buf);
588         }
589         strcpy(buf, WC->ugname);
590         strcpy(WC->ugname, "");
591         smart_goto(buf);
592 }
593
594 /*
595  * display the form for editing a room
596  */
597 void display_editroom(void)
598 {
599         char buf[256];
600         char er_name[20];
601         char er_password[10];
602         char er_dirname[15];
603         char er_roomaide[26];
604         unsigned er_flags;
605         int er_floor;
606         int i;
607
608         serv_puts("GETR");
609         serv_gets(buf);
610
611         if (buf[0] != '2') {
612                 display_error(&buf[4]);
613                 return;
614         }
615         extract(er_name, &buf[4], 0);
616         extract(er_password, &buf[4], 1);
617         extract(er_dirname, &buf[4], 2);
618         er_flags = extract_int(&buf[4], 3);
619         er_floor = extract_int(&buf[4], 4);
620
621
622         output_headers(1);
623
624         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>");
625         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
626         wprintf("<B>Room administration</B>\n");
627         wprintf("</FONT></TD></TR></TABLE>\n");
628
629         wprintf("<UL>"
630                 "<LI><A HREF=\"/confirm_delete_room\">\n"
631                 "Delete this room</A>\n"
632                 "<LI><A HREF=\"/display_editroompic\">\n"
633                 "Set or change the graphic for this room's banner</A>\n"
634                 "<LI><A HREF=\"/display_editinfo\">\n"
635                 "Edit this room's Info file</A>\n"
636                 "</UL>");
637
638         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>");
639         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
640         wprintf("<B>Room editing</B>\n");
641         wprintf("</FONT></TD></TR></TABLE>\n");
642
643         wprintf("<FORM METHOD=\"POST\" ACTION=\"/editroom\">\n");
644
645         wprintf("<UL><LI>Name of room: ");
646         wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", er_name);
647
648         wprintf("<LI>Resides on floor: ");
649         load_floorlist();
650         wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
651         for (i = 0; i < 128; ++i)
652                 if (strlen(floorlist[i]) > 0) {
653                         wprintf("<OPTION ");
654                         if (i == er_floor)
655                                 wprintf("SELECTED ");
656                         wprintf("VALUE=\"%d\">", i);
657                         escputs(floorlist[i]);
658                         wprintf("</OPTION>\n");
659                 }
660         wprintf("</SELECT>\n");
661
662         wprintf("<LI>Type of room:<UL>\n");
663
664         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
665         if ((er_flags & QR_PRIVATE) == 0)
666                 wprintf("CHECKED ");
667         wprintf("> Public room\n");
668
669         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
670         if ((er_flags & QR_PRIVATE) &&
671             (er_flags & QR_GUESSNAME))
672                 wprintf("CHECKED ");
673         wprintf("> Private - guess name\n");
674
675         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
676         if ((er_flags & QR_PRIVATE) &&
677             (er_flags & QR_PASSWORDED))
678                 wprintf("CHECKED ");
679         wprintf("> Private - require password:\n");
680         wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n", er_password);
681
682         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
683         if ((er_flags & QR_PRIVATE)
684             && ((er_flags & QR_GUESSNAME) == 0)
685             && ((er_flags & QR_PASSWORDED) == 0))
686                 wprintf("CHECKED ");
687         wprintf("> Private - invitation only\n");
688
689         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"bump\" VALUE=\"yes\" ");
690         wprintf("> If private, cause current users to forget room\n");
691
692         wprintf("</UL>\n");
693
694         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"prefonly\" VALUE=\"yes\" ");
695         if (er_flags & QR_PREFONLY)
696                 wprintf("CHECKED ");
697         wprintf("> Preferred users only\n");
698
699         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"readonly\" VALUE=\"yes\" ");
700         if (er_flags & QR_READONLY)
701                 wprintf("CHECKED ");
702         wprintf("> Read-only room\n");
703
704 /* directory stuff */
705         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"directory\" VALUE=\"yes\" ");
706         if (er_flags & QR_DIRECTORY)
707                 wprintf("CHECKED ");
708         wprintf("> File directory room\n");
709
710         wprintf("<UL><LI>Directory name: ");
711         wprintf("<INPUT TYPE=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n", er_dirname);
712
713         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"ulallowed\" VALUE=\"yes\" ");
714         if (er_flags & QR_UPLOAD)
715                 wprintf("CHECKED ");
716         wprintf("> Uploading allowed\n");
717
718         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"dlallowed\" VALUE=\"yes\" ");
719         if (er_flags & QR_DOWNLOAD)
720                 wprintf("CHECKED ");
721         wprintf("> Downloading allowed\n");
722
723         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"visdir\" VALUE=\"yes\" ");
724         if (er_flags & QR_VISDIR)
725                 wprintf("CHECKED ");
726         wprintf("> Visible directory</UL>\n");
727
728 /* end of directory stuff */
729
730         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"network\" VALUE=\"yes\" ");
731         if (er_flags & QR_NETWORK)
732                 wprintf("CHECKED ");
733         wprintf("> Network shared room\n");
734
735 /* start of anon options */
736
737         wprintf("<LI>Anonymous messages<UL>\n");
738
739         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"no\" ");
740         if (((er_flags & QR_ANONONLY) == 0)
741             && ((er_flags & QR_ANONOPT) == 0))
742                 wprintf("CHECKED ");
743         wprintf("> No anonymous messages\n");
744
745         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anononly\" ");
746         if (er_flags & QR_ANONONLY)
747                 wprintf("CHECKED ");
748         wprintf("> All messages are anonymous\n");
749
750         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anon2\" ");
751         if (er_flags & QR_ANONOPT)
752                 wprintf("CHECKED ");
753         wprintf("> Prompt user when entering messages</UL>\n");
754
755 /* end of anon options */
756
757         wprintf("<LI>Room aide: \n");
758         serv_puts("GETA");
759         serv_gets(buf);
760         if (buf[0] != '2') {
761                 wprintf("<EM>%s</EM>\n", &buf[4]);
762         } else {
763                 extract(er_roomaide, &buf[4], 0);
764                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n", er_roomaide);
765         }
766
767         wprintf("</UL><CENTER>\n");
768         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
769         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
770         wprintf("</CENTER>\n");
771
772         wDumpContent(1);
773 }
774
775
776 /*
777  * save new parameters for a room
778  */
779 void editroom(void)
780 {
781         char buf[256];
782         char er_name[20];
783         char er_password[10];
784         char er_dirname[15];
785         char er_roomaide[26];
786         int er_floor;
787         unsigned er_flags;
788         int bump;
789
790
791         if (strcmp(bstr("sc"), "OK")) {
792                 display_error("Cancelled.  Changes were not saved.");
793                 return;
794         }
795         serv_puts("GETR");
796         serv_gets(buf);
797
798         if (buf[0] != '2') {
799                 display_error(&buf[4]);
800                 return;
801         }
802         extract(er_name, &buf[4], 0);
803         extract(er_password, &buf[4], 1);
804         extract(er_dirname, &buf[4], 2);
805         er_flags = extract_int(&buf[4], 3);
806
807         strcpy(er_roomaide, bstr("er_roomaide"));
808         if (strlen(er_roomaide) == 0) {
809                 serv_puts("GETA");
810                 serv_gets(buf);
811                 if (buf[0] != '2') {
812                         strcpy(er_roomaide, "");
813                 } else {
814                         extract(er_roomaide, &buf[4], 0);
815                 }
816         }
817         strcpy(buf, bstr("er_name"));
818         buf[20] = 0;
819         if (strlen(buf) > 0)
820                 strcpy(er_name, buf);
821
822         strcpy(buf, bstr("er_password"));
823         buf[10] = 0;
824         if (strlen(buf) > 0)
825                 strcpy(er_password, buf);
826
827         strcpy(buf, bstr("er_dirname"));
828         buf[15] = 0;
829         if (strlen(buf) > 0)
830                 strcpy(er_dirname, buf);
831
832         strcpy(buf, bstr("type"));
833         er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
834
835         if (!strcmp(buf, "invonly")) {
836                 er_flags |= (QR_PRIVATE);
837         }
838         if (!strcmp(buf, "guessname")) {
839                 er_flags |= (QR_PRIVATE | QR_GUESSNAME);
840         }
841         if (!strcmp(buf, "passworded")) {
842                 er_flags |= (QR_PRIVATE | QR_PASSWORDED);
843         }
844         if (!strcmp(bstr("prefonly"), "yes")) {
845                 er_flags |= QR_PREFONLY;
846         } else {
847                 er_flags &= ~QR_PREFONLY;
848         }
849
850         if (!strcmp(bstr("readonly"), "yes")) {
851                 er_flags |= QR_READONLY;
852         } else {
853                 er_flags &= ~QR_READONLY;
854         }
855
856         if (!strcmp(bstr("network"), "yes")) {
857                 er_flags |= QR_NETWORK;
858         } else {
859                 er_flags &= ~QR_NETWORK;
860         }
861
862         if (!strcmp(bstr("directory"), "yes")) {
863                 er_flags |= QR_DIRECTORY;
864         } else {
865                 er_flags &= ~QR_DIRECTORY;
866         }
867
868         if (!strcmp(bstr("ulallowed"), "yes")) {
869                 er_flags |= QR_UPLOAD;
870         } else {
871                 er_flags &= ~QR_UPLOAD;
872         }
873
874         if (!strcmp(bstr("dlallowed"), "yes")) {
875                 er_flags |= QR_DOWNLOAD;
876         } else {
877                 er_flags &= ~QR_DOWNLOAD;
878         }
879
880         if (!strcmp(bstr("visdir"), "yes")) {
881                 er_flags |= QR_VISDIR;
882         } else {
883                 er_flags &= ~QR_VISDIR;
884         }
885
886         strcpy(buf, bstr("anon"));
887
888         er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
889         if (!strcmp(buf, "anononly"))
890                 er_flags |= QR_ANONONLY;
891         if (!strcmp(buf, "anon2"))
892                 er_flags |= QR_ANONOPT;
893
894         bump = 0;
895         if (!strcmp(bstr("bump"), "yes"))
896                 bump = 1;
897
898         er_floor = atoi(bstr("er_floor"));
899
900         sprintf(buf, "SETR %s|%s|%s|%u|%d|%d",
901              er_name, er_password, er_dirname, er_flags, bump, er_floor);
902         serv_puts(buf);
903         serv_gets(buf);
904         if (buf[0] != '2') {
905                 display_error(&buf[4]);
906                 return;
907         }
908         gotoroom(er_name, 0);
909
910         if (strlen(er_roomaide) > 0) {
911                 sprintf(buf, "SETA %s", er_roomaide);
912                 serv_puts(buf);
913                 serv_gets(buf);
914                 if (buf[0] != '2') {
915                         display_error(&buf[4]);
916                         return;
917                 }
918         }
919         smart_goto(er_name);
920 }
921
922 /*
923  * Invite, Kick, and show Who Knows a room
924  */
925 void display_whok(void)
926 {
927         char buf[256], room[256], username[256];
928
929         serv_puts("GETR");
930         serv_gets(buf);
931
932         if (buf[0] != '2') {
933                 display_error(&buf[4]);
934                 return;
935         }
936         extract(room, &buf[4], 0);
937
938         strcpy(username, bstr("username"));
939
940         output_headers(1);
941
942         if(!strcmp(bstr("sc"), "Kick")) {
943                 sprintf(buf, "KICK %s", username);
944                 serv_puts(buf);
945                 serv_gets(buf);
946
947                 if (buf[0] != '2') {
948                         display_error(&buf[4]);
949                         return;
950                 } else {
951                         wprintf("User %s kicked out of room %s.\n", 
952                                 username, room);
953                 }
954         } else if(!strcmp(bstr("sc"), "Invite")) {
955                 sprintf(buf, "INVT %s", username);
956                 serv_puts(buf);
957                 serv_gets(buf);
958
959                 if (buf[0] != '2') {
960                         display_error(&buf[4]);
961                         return;
962                 } else {
963                         wprintf("User %s invited to room %s.\n", 
964                                 username, room);
965                 }
966         }
967         
968
969         wprintf("<FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
970         wprintf("<SELECT NAME=\"username\" SIZE=10>\n");
971         serv_puts("WHOK");
972         serv_gets(buf);
973         if (buf[0] == '1') {
974                 while (serv_gets(buf), strcmp(buf, "000")) {
975                         extract(username, buf, 0);
976                         wprintf("<OPTION>");
977                         escputs(username);
978                         wprintf("\n");
979                 }
980         }
981         wprintf("</SELECT>\n");
982
983         wprintf("<CENTER>\n");
984         wprintf("<input type=submit name=sc value=\"Kick\">");
985         wprintf("</CENTER>\n");
986         wprintf("</FORM>\n");
987         wprintf("<FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
988         wprintf("Invite: ");
989         wprintf("<input type=text name=username>\n");
990         wprintf("<input type=hidden name=sc value=\"Invite\">");
991         wprintf("<input type=submit value=\"Invite\">");
992         wDumpContent(1);
993 }
994
995
996
997 /*
998  * display the form for entering a new room
999  */
1000 void display_entroom(void)
1001 {
1002         int i;
1003         char buf[256];
1004
1005         serv_puts("CRE8 0");
1006         serv_gets(buf);
1007
1008         if (buf[0] != '2') {
1009                 display_error(&buf[4]);
1010                 return;
1011         }
1012         output_headers(1);
1013
1014         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>");
1015         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1016         wprintf("<B>Enter (create) a new room</B>\n");
1017         wprintf("</FONT></TD></TR></TABLE>\n");
1018
1019         wprintf("<FORM METHOD=\"POST\" ACTION=\"/entroom\">\n");
1020
1021         wprintf("<UL><LI>Name of room: ");
1022         wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" MAXLENGTH=\"19\">\n");
1023
1024         wprintf("<LI>Type of room:<UL>\n");
1025
1026         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
1027         wprintf("CHECKED > Public room\n");
1028
1029         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
1030         wprintf("> Private - guess name\n");
1031
1032         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
1033         wprintf("> Private - require password:\n");
1034         wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
1035
1036         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
1037         wprintf("> Private - invitation only\n");
1038         wprintf("</UL>\n");
1039
1040         wprintf("<LI>Resides on floor: ");
1041         load_floorlist(); 
1042         wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
1043         for (i = 0; i < 128; ++i)
1044                 if (strlen(floorlist[i]) > 0) {
1045                         wprintf("<OPTION ");
1046                         wprintf("VALUE=\"%d\">", i);
1047                         escputs(floorlist[i]);
1048                         wprintf("</OPTION>\n");
1049                 }
1050         wprintf("</SELECT>\n");                
1051         wprintf("</UL>\n");
1052
1053
1054         wprintf("<CENTER>\n");
1055         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1056         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1057         wprintf("</CENTER>\n");
1058         wprintf("</FORM>\n<HR>");
1059         serv_printf("MESG roomaccess");
1060         serv_gets(buf);
1061         if (buf[0] == '1') {
1062                 fmout(NULL);
1063         }
1064         wDumpContent(1);
1065 }
1066
1067
1068
1069 /*
1070  * enter a new room
1071  */
1072 void entroom(void)
1073 {
1074         char buf[256];
1075         char er_name[20];
1076         char er_type[20];
1077         char er_password[10];
1078         int er_floor;
1079         int er_num_type;
1080
1081         if (strcmp(bstr("sc"), "OK")) {
1082                 display_error("Cancelled.  No new room was created.");
1083                 return;
1084         }
1085         strcpy(er_name, bstr("er_name"));
1086         strcpy(er_type, bstr("type"));
1087         strcpy(er_password, bstr("er_password"));
1088         er_floor = atoi(bstr("er_floor"));
1089
1090         er_num_type = 0;
1091         if (!strcmp(er_type, "guessname"))
1092                 er_num_type = 1;
1093         if (!strcmp(er_type, "passworded"))
1094                 er_num_type = 2;
1095         if (!strcmp(er_type, "invonly"))
1096                 er_num_type = 3;
1097
1098         sprintf(buf, "CRE8 1|%s|%d|%s|%d", 
1099                 er_name, er_num_type, er_password, er_floor);
1100         serv_puts(buf);
1101         serv_gets(buf);
1102         if (buf[0] != '2') {
1103                 display_error(&buf[4]);
1104                 return;
1105         }
1106         smart_goto(er_name);
1107 }
1108
1109
1110 /*
1111  * display the screen to enter a private room
1112  */
1113 void display_private(char *rname, int req_pass)
1114 {
1115
1116         output_headers(1);
1117
1118         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1119         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1120         wprintf("<B>Goto a private room</B>\n");
1121         wprintf("</FONT></TD></TR></TABLE>\n");
1122
1123         wprintf("<CENTER>\n");
1124         wprintf("If you know the name of a hidden (guess-name) or\n");
1125         wprintf("passworded room, you can enter that room by typing\n");
1126         wprintf("its name below.  Once you gain access to a private\n");
1127         wprintf("room, it will appear in your regular room listings\n");
1128         wprintf("so you don't have to keep returning here.\n");
1129         wprintf("<BR><BR>");
1130
1131         wprintf("<FORM METHOD=\"POST\" ACTION=\"/goto_private\">\n");
1132
1133         wprintf("<TABLE border><TR><TD>");
1134         wprintf("Enter room name:</TD><TD>");
1135         wprintf("<INPUT TYPE=\"text\" NAME=\"gr_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", rname);
1136
1137         if (req_pass) {
1138                 wprintf("</TD></TR><TR><TD>");
1139                 wprintf("Enter room password:</TD><TD>");
1140                 wprintf("<INPUT TYPE=\"password\" NAME=\"gr_pass\" MAXLENGTH=\"9\">\n");
1141         }
1142         wprintf("</TD></TR></TABLE>\n");
1143
1144         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1145         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1146         wprintf("</FORM>\n");
1147         wDumpContent(1);
1148 }
1149
1150 /* 
1151  * goto a private room
1152  */
1153 void goto_private(void)
1154 {
1155         char hold_rm[32];
1156         char buf[256];
1157
1158         if (strcasecmp(bstr("sc"), "OK")) {
1159                 display_main_menu();
1160                 return;
1161         }
1162         strcpy(hold_rm, WC->wc_roomname);
1163         strcpy(buf, "GOTO ");
1164         strcat(buf, bstr("gr_name"));
1165         strcat(buf, "|");
1166         strcat(buf, bstr("gr_pass"));
1167         serv_puts(buf);
1168         serv_gets(buf);
1169
1170         if (buf[0] == '2') {
1171                 smart_goto(bstr("gr_name"));
1172                 return;
1173         }
1174         if (!strncmp(buf, "540", 3)) {
1175                 display_private(bstr("gr_name"), 1);
1176                 return;
1177         }
1178         output_headers(1);
1179         wprintf("%s\n", &buf[4]);
1180         wDumpContent(1);
1181         return;
1182 }
1183
1184
1185 /*
1186  * display the screen to zap a room
1187  */
1188 void display_zap(void)
1189 {
1190         output_headers(1);
1191
1192         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1193         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1194         wprintf("<B>Zap (forget) the current room</B>\n");
1195         wprintf("</FONT></TD></TR></TABLE>\n");
1196
1197         wprintf("If you select this option, <em>%s</em> will ", WC->wc_roomname);
1198         wprintf("disappear from your room list.  Is this what you wish ");
1199         wprintf("to do?<BR>\n");
1200
1201         wprintf("<FORM METHOD=\"POST\" ACTION=\"/zap\">\n");
1202         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1203         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1204         wprintf("</FORM>\n");
1205         wDumpContent(1);
1206 }
1207
1208
1209 /* 
1210  * zap a room
1211  */
1212 void zap(void)
1213 {
1214         char buf[256];
1215         char final_destination[256];
1216
1217         /* If the forget-room routine fails for any reason, we fall back
1218          * to the current room; otherwise, we go to the Lobby
1219          */
1220         strcpy(final_destination, WC->wc_roomname);
1221
1222         if (!strcasecmp(bstr("sc"), "OK")) {
1223                 serv_printf("GOTO %s", WC->wc_roomname);
1224                 serv_gets(buf);
1225                 if (buf[0] != '2') {
1226                         /* ExpressMessageCat(&buf[4]);   FIXME    */
1227                 } else {
1228                         serv_puts("FORG");
1229                         serv_gets(buf);
1230                         if (buf[0] != '2') {
1231                                 /* ExpressMessageCat(&buf[4]);  FIXME   */
1232                         } else {
1233                                 strcpy(final_destination, "_BASEROOM_");
1234                         }
1235                 }
1236         }
1237         smart_goto(final_destination);
1238 }
1239
1240
1241
1242
1243 /*
1244  * Confirm deletion of the current room
1245  */
1246 void confirm_delete_room(void)
1247 {
1248         char buf[256];
1249
1250         serv_puts("KILL 0");
1251         serv_gets(buf);
1252         if (buf[0] != '2') {
1253                 display_error(&buf[4]);
1254                 return;
1255         }
1256         output_headers(1);
1257         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1258         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1259         wprintf("<B>Confirm deletion of room</B>\n");
1260         wprintf("</FONT></TD></TR></TABLE>\n");
1261
1262         wprintf("<CENTER>");
1263         wprintf("<FORM METHOD=\"POST\" ACTION=\"/delete_room\">\n");
1264
1265         wprintf("Are you sure you want to delete <FONT SIZE=+1>");
1266         escputs(WC->wc_roomname);
1267         wprintf("</FONT>?<BR>\n");
1268
1269         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">");
1270         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1271
1272         wprintf("</FORM></CENTER>\n");
1273         wDumpContent(1);
1274 }
1275
1276
1277 /*
1278  * Delete the current room
1279  */
1280 void delete_room(void)
1281 {
1282         char buf[256];
1283         char sc[256];
1284
1285         strcpy(sc, bstr("sc"));
1286
1287         if (strcasecmp(sc, "Delete")) {
1288                 display_error("Cancelled.  This room was not deleted.");
1289                 return;
1290         }
1291         serv_puts("KILL 1");
1292         serv_gets(buf);
1293         if (buf[0] != '2') {
1294                 display_error(&buf[4]);
1295         } else {
1296                 smart_goto("_BASEROOM_");
1297         }
1298 }