]> code.citadel.org Git - citadel.git/blob - webcit/roomops.c
* Removed HTTP date fields because it was confusing browser caches (weird)
[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("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(int v)
289 {
290         char buf[256];
291
292         serv_puts("RINF");
293         serv_gets(buf);
294         if (buf[0] == '1')
295                 fmout(NULL);
296         else {
297                 if (v == 1)
298                         wprintf("<EM>%s</EM><BR>\n", &buf[4]);
299         }
300 }
301
302
303
304 void embed_room_banner(char *got) {
305         char buf[256];
306         char fakegot[256];
307         static int remember_new_mail = (-1);
308
309         /* We need to have the information returned by a GOTO server command.
310          * If it isn't supplied, we fake it by issuing our own GOTO.
311          */
312         if (got == NULL) {
313                 serv_printf("GOTO %s", WC->wc_roomname);
314                 serv_gets(fakegot);
315                 got = fakegot;
316         }
317
318         /* Check for new mail. */
319         WC->new_mail = extract_int(&got[4], 9);
320
321         /* Now start spewing HTML. */
322         wprintf("<CENTER><TABLE border=0><TR>");
323
324         if ((strlen(WC->ugname) > 0) && (strcasecmp(WC->ugname, WC->wc_roomname))) {
325                 wprintf("<TD VALIGN=TOP><A HREF=\"/ungoto\">");
326                 wprintf("<IMG SRC=\"/static/back.gif\" BORDER=0></A></TD>");
327         }
328         wprintf("<TD VALIGN=TOP><FONT SIZE=+2>%s</FONT><BR>", WC->wc_roomname);
329         wprintf("%d new of %d messages</TD>\n",
330                 extract_int(&got[4], 1),
331                 extract_int(&got[4], 2));
332
333         /* Display room graphic.  The server doesn't actually
334          * need the room name, but we supply it in order to
335          * keep the browser from using a cached graphic from 
336          * another room.
337          */
338         serv_puts("OIMG _roompic_");
339         serv_gets(buf);
340         if (buf[0] == '2') {
341                 wprintf("<TD>");
342                 wprintf("<IMG SRC=\"/image&name=_roompic_&room=");
343                 urlescputs(WC->wc_roomname);
344                 wprintf("\"></TD>");
345                 serv_puts("CLOS");
346                 serv_gets(buf);
347         }
348         wprintf("<TD VALIGN=TOP>");
349         readinfo(0);
350         wprintf("</TD>");
351
352         /* Let the user know if new mail has arrived */
353         if ( (WC->new_mail > remember_new_mail) && (WC->new_mail>0) ) {
354                 wprintf("<TD VALIGN=TOP>"
355                         "<IMG SRC=\"/static/mail.gif\" border=0 "
356                         "ALT=\"You have new mail\">"
357                         "<BR><BLINK>%d</BLINK></TD>", WC->new_mail);
358                 remember_new_mail = WC->new_mail;
359         }
360
361         wprintf("<TD VALIGN=TOP><A HREF=\"/gotonext\">");
362         wprintf("<IMG SRC=\"/static/forward.gif\" border=0></A></TD>");
363         wprintf("</TR></TABLE></CENTER>\n");
364 }
365
366
367
368
369
370 /*
371  * generic routine to take the session to a new room
372  *
373  * display_name values:  0 = goto only
374  *                       1 = goto and display
375  *                       2 = display only
376  */
377 void gotoroom(char *gname, int display_name)
378 {
379         char buf[256];
380         static long ls = (-1L);
381
382
383         if (display_name) {
384                 output_headers(0);
385                 wprintf("Pragma: no-cache\n");
386                 wprintf("Cache-Control: no-store\n");
387
388                 wprintf("<HTML><HEAD>\n"
389                         "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n"
390                         "</HEAD>\n<BODY ");
391                 wprintf("BACKGROUND=\"/image&name=background\" TEXT=\"#000000\" LINK=\"#004400\">\n");
392         }
393         if (display_name != 2) {
394                 /* store ungoto information */
395                 strcpy(WC->ugname, WC->wc_roomname);
396                 WC->uglsn = ls;
397         }
398         /* move to the new room */
399         serv_printf("GOTO %s", gname);
400         serv_gets(buf);
401         if (buf[0] != '2') {
402                 serv_puts("GOTO _BASEROOM_");
403                 serv_gets(buf);
404         }
405         if (buf[0] != '2') {
406                 if (display_name) {
407                         wprintf("<EM>%s</EM><BR>\n", &buf[4]);
408                         wDumpContent(1);
409                 }
410                 return;
411         }
412         extract(WC->wc_roomname, &buf[4], 0);
413         WC->room_flags = extract_int(&buf[4], 4);
414         /* highest_msg_read = extract_int(&buf[4],6);
415            maxmsgnum = extract_int(&buf[4],5);
416            is_mail = (char) extract_int(&buf[4],7); */
417         ls = extract_long(&buf[4], 6);
418
419         if (WC->is_aide)
420                 WC->is_room_aide = WC->is_aide;
421         else
422                 WC->is_room_aide = (char) extract_int(&buf[4], 8);
423
424         remove_march(WC->wc_roomname);
425         if (!strcasecmp(gname, "_BASEROOM_"))
426                 remove_march(gname);
427
428         /* Display the room banner */
429         if (display_name) {
430                 embed_room_banner(buf);
431                 wDumpContent(1);
432         }
433         strcpy(WC->wc_roomname, WC->wc_roomname);
434 }
435
436
437 /*
438  * Locate the room on the march list which we most want to go to.  Each room
439  * is measured given a "weight" of preference based on various factors.
440  */
441 char *pop_march(int desired_floor)
442 {
443         static char TheRoom[64];
444         int TheFloor = 0;
445         int TheOrder = 32767;
446         int TheWeight = 0;
447         int weight;
448         struct march *mptr = NULL;
449
450         strcpy(TheRoom, "_BASEROOM_");
451         if (WC->march == NULL)
452                 return (TheRoom);
453
454         for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
455                 weight = 0;
456                 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
457                         weight = weight + 10000;
458                 if (mptr->march_floor == desired_floor)
459                         weight = weight + 5000;
460
461                 weight = weight + ((128 - (mptr->march_floor)) * 128);
462                 weight = weight + (128 - (mptr->march_order));
463
464                 if (weight > TheWeight) {
465                         TheWeight = weight;
466                         strcpy(TheRoom, mptr->march_name);
467                         TheFloor = mptr->march_floor;
468                         TheOrder = mptr->march_order;
469                 }
470         }
471         return (TheRoom);
472 }
473
474
475
476 /* Goto next room having unread messages.
477  * We want to skip over rooms that the user has already been to, and take the
478  * user back to the lobby when done.  The room we end up in is placed in
479  * newroom - which is set to 0 (the lobby) initially.
480  * We start the search in the current room rather than the beginning to prevent
481  * two or more concurrent users from dragging each other back to the same room.
482  */
483 void gotonext(void)
484 {
485         char buf[256];
486         struct march *mptr, *mptr2;
487         char next_room[32];
488
489         /* First check to see if the march-mode list is already allocated.
490          * If it is, pop the first room off the list and go there.
491          */
492
493         if (WC->march == NULL) {
494                 serv_puts("LKRN");
495                 serv_gets(buf);
496                 if (buf[0] == '1')
497                         while (serv_gets(buf), strcmp(buf, "000")) {
498                                 mptr = (struct march *) malloc(sizeof(struct march));
499                                 mptr->next = NULL;
500                                 extract(mptr->march_name, buf, 0);
501                                 mptr->march_floor = extract_int(buf, 2);
502                                 mptr->march_order = extract_int(buf, 3);
503                                 if (WC->march == NULL) {
504                                         WC->march = mptr;
505                                 } else {
506                                         mptr2 = WC->march;
507                                         while (mptr2->next != NULL)
508                                                 mptr2 = mptr2->next;
509                                         mptr2->next = mptr;
510                                 }
511                         }
512 /* add _BASEROOM_ to the end of the march list, so the user will end up
513  * in the system base room (usually the Lobby>) at the end of the loop
514  */
515                 mptr = (struct march *) malloc(sizeof(struct march));
516                 mptr->next = NULL;
517                 strcpy(mptr->march_name, "_BASEROOM_");
518                 if (WC->march == NULL) {
519                         WC->march = mptr;
520                 } else {
521                         mptr2 = WC->march;
522                         while (mptr2->next != NULL)
523                                 mptr2 = mptr2->next;
524                         mptr2->next = mptr;
525                 }
526 /*
527  * ...and remove the room we're currently in, so a <G>oto doesn't make us
528  * walk around in circles
529  */
530                 remove_march(WC->wc_roomname);
531         }
532         if (WC->march != NULL) {
533                 strcpy(next_room, pop_march(-1));
534         } else {
535                 strcpy(next_room, "_BASEROOM_");
536         }
537
538
539         smart_goto(next_room);
540 }
541
542
543 void smart_goto(char *next_room) {
544         gotoroom(next_room, 0);
545         readloop("readnew");
546 }
547
548
549
550 /*
551  * mark all messages in current room as having been read
552  */
553 void slrp_highest(void)
554 {
555         char buf[256];
556
557         /* set pointer */
558         serv_puts("SLRP HIGHEST");
559         serv_gets(buf);
560         if (buf[0] != '2') {
561                 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
562                 return;
563         }
564 }
565
566
567 /*
568  * un-goto the previous room
569  */
570 void ungoto(void)
571 {
572         char buf[256];
573
574         if (!strcmp(WC->ugname, "")) {
575                 smart_goto(WC->wc_roomname);
576                 return;
577         }
578         serv_printf("GOTO %s", WC->ugname);
579         serv_gets(buf);
580         if (buf[0] != '2') {
581                 smart_goto(WC->wc_roomname);
582                 return;
583         }
584         if (WC->uglsn >= 0L) {
585                 serv_printf("SLRP %ld", WC->uglsn);
586                 serv_gets(buf);
587         }
588         strcpy(buf, WC->ugname);
589         strcpy(WC->ugname, "");
590         smart_goto(buf);
591 }
592
593 /*
594  * display the form for editing a room
595  */
596 void display_editroom(void)
597 {
598         char buf[256];
599         char er_name[20];
600         char er_password[10];
601         char er_dirname[15];
602         char er_roomaide[26];
603         unsigned er_flags;
604         int er_floor;
605         int i;
606
607         serv_puts("GETR");
608         serv_gets(buf);
609
610         if (buf[0] != '2') {
611                 display_error(&buf[4]);
612                 return;
613         }
614         extract(er_name, &buf[4], 0);
615         extract(er_password, &buf[4], 1);
616         extract(er_dirname, &buf[4], 2);
617         er_flags = extract_int(&buf[4], 3);
618         er_floor = extract_int(&buf[4], 4);
619
620
621         output_headers(1);
622
623         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
624         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
625         wprintf("<B>Room administration</B>\n");
626         wprintf("</FONT></TD></TR></TABLE>\n");
627
628         wprintf("<UL>"
629                 "<LI><A HREF=\"/confirm_delete_room\">\n"
630                 "Delete this room</A>\n"
631                 "<LI><A HREF=\"/display_editroompic\">\n"
632                 "Set or change the graphic for this room's banner</A>\n"
633                 "<LI><A HREF=\"/display_editinfo\">\n"
634                 "Edit this room's Info file</A>\n"
635                 "</UL>");
636
637         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
638         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
639         wprintf("<B>Room editing</B>\n");
640         wprintf("</FONT></TD></TR></TABLE>\n");
641
642         wprintf("<FORM METHOD=\"POST\" ACTION=\"/editroom\">\n");
643
644         wprintf("<UL><LI>Name of room: ");
645         wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", er_name);
646
647         wprintf("<LI>Resides on floor: ");
648         load_floorlist();
649         wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
650         for (i = 0; i < 128; ++i)
651                 if (strlen(floorlist[i]) > 0) {
652                         wprintf("<OPTION ");
653                         if (i == er_floor)
654                                 wprintf("SELECTED ");
655                         wprintf("VALUE=\"%d\">", i);
656                         escputs(floorlist[i]);
657                         wprintf("</OPTION>\n");
658                 }
659         wprintf("</SELECT>\n");
660
661         wprintf("<LI>Type of room:<UL>\n");
662
663         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
664         if ((er_flags & QR_PRIVATE) == 0)
665                 wprintf("CHECKED ");
666         wprintf("> Public room\n");
667
668         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
669         if ((er_flags & QR_PRIVATE) &&
670             (er_flags & QR_GUESSNAME))
671                 wprintf("CHECKED ");
672         wprintf("> Private - guess name\n");
673
674         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
675         if ((er_flags & QR_PRIVATE) &&
676             (er_flags & QR_PASSWORDED))
677                 wprintf("CHECKED ");
678         wprintf("> Private - require password:\n");
679         wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n", er_password);
680
681         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
682         if ((er_flags & QR_PRIVATE)
683             && ((er_flags & QR_GUESSNAME) == 0)
684             && ((er_flags & QR_PASSWORDED) == 0))
685                 wprintf("CHECKED ");
686         wprintf("> Private - invitation only\n");
687
688         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"bump\" VALUE=\"yes\" ");
689         wprintf("> If private, cause current users to forget room\n");
690
691         wprintf("</UL>\n");
692
693         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"prefonly\" VALUE=\"yes\" ");
694         if (er_flags & QR_PREFONLY)
695                 wprintf("CHECKED ");
696         wprintf("> Preferred users only\n");
697
698         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"readonly\" VALUE=\"yes\" ");
699         if (er_flags & QR_READONLY)
700                 wprintf("CHECKED ");
701         wprintf("> Read-only room\n");
702
703 /* directory stuff */
704         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"directory\" VALUE=\"yes\" ");
705         if (er_flags & QR_DIRECTORY)
706                 wprintf("CHECKED ");
707         wprintf("> File directory room\n");
708
709         wprintf("<UL><LI>Directory name: ");
710         wprintf("<INPUT TYPE=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n", er_dirname);
711
712         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"ulallowed\" VALUE=\"yes\" ");
713         if (er_flags & QR_UPLOAD)
714                 wprintf("CHECKED ");
715         wprintf("> Uploading allowed\n");
716
717         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"dlallowed\" VALUE=\"yes\" ");
718         if (er_flags & QR_DOWNLOAD)
719                 wprintf("CHECKED ");
720         wprintf("> Downloading allowed\n");
721
722         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"visdir\" VALUE=\"yes\" ");
723         if (er_flags & QR_VISDIR)
724                 wprintf("CHECKED ");
725         wprintf("> Visible directory</UL>\n");
726
727 /* end of directory stuff */
728
729         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"network\" VALUE=\"yes\" ");
730         if (er_flags & QR_NETWORK)
731                 wprintf("CHECKED ");
732         wprintf("> Network shared room\n");
733
734 /* start of anon options */
735
736         wprintf("<LI>Anonymous messages<UL>\n");
737
738         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"no\" ");
739         if (((er_flags & QR_ANONONLY) == 0)
740             && ((er_flags & QR_ANONOPT) == 0))
741                 wprintf("CHECKED ");
742         wprintf("> No anonymous messages\n");
743
744         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anononly\" ");
745         if (er_flags & QR_ANONONLY)
746                 wprintf("CHECKED ");
747         wprintf("> All messages are anonymous\n");
748
749         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anon2\" ");
750         if (er_flags & QR_ANONOPT)
751                 wprintf("CHECKED ");
752         wprintf("> Prompt user when entering messages</UL>\n");
753
754 /* end of anon options */
755
756         wprintf("<LI>Room aide: \n");
757         serv_puts("GETA");
758         serv_gets(buf);
759         if (buf[0] != '2') {
760                 wprintf("<EM>%s</EM>\n", &buf[4]);
761         } else {
762                 extract(er_roomaide, &buf[4], 0);
763                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n", er_roomaide);
764         }
765
766         wprintf("</UL><CENTER>\n");
767         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
768         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
769         wprintf("</CENTER>\n");
770
771         wDumpContent(1);
772 }
773
774
775 /*
776  * save new parameters for a room
777  */
778 void editroom(void)
779 {
780         char buf[256];
781         char er_name[20];
782         char er_password[10];
783         char er_dirname[15];
784         char er_roomaide[26];
785         int er_floor;
786         unsigned er_flags;
787         int bump;
788
789
790         if (strcmp(bstr("sc"), "OK")) {
791                 display_error("Cancelled.  Changes were not saved.");
792                 return;
793         }
794         serv_puts("GETR");
795         serv_gets(buf);
796
797         if (buf[0] != '2') {
798                 display_error(&buf[4]);
799                 return;
800         }
801         extract(er_name, &buf[4], 0);
802         extract(er_password, &buf[4], 1);
803         extract(er_dirname, &buf[4], 2);
804         er_flags = extract_int(&buf[4], 3);
805
806         strcpy(er_roomaide, bstr("er_roomaide"));
807         if (strlen(er_roomaide) == 0) {
808                 serv_puts("GETA");
809                 serv_gets(buf);
810                 if (buf[0] != '2') {
811                         strcpy(er_roomaide, "");
812                 } else {
813                         extract(er_roomaide, &buf[4], 0);
814                 }
815         }
816         strcpy(buf, bstr("er_name"));
817         buf[20] = 0;
818         if (strlen(buf) > 0)
819                 strcpy(er_name, buf);
820
821         strcpy(buf, bstr("er_password"));
822         buf[10] = 0;
823         if (strlen(buf) > 0)
824                 strcpy(er_password, buf);
825
826         strcpy(buf, bstr("er_dirname"));
827         buf[15] = 0;
828         if (strlen(buf) > 0)
829                 strcpy(er_dirname, buf);
830
831         strcpy(buf, bstr("type"));
832         er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
833
834         if (!strcmp(buf, "invonly")) {
835                 er_flags |= (QR_PRIVATE);
836         }
837         if (!strcmp(buf, "guessname")) {
838                 er_flags |= (QR_PRIVATE | QR_GUESSNAME);
839         }
840         if (!strcmp(buf, "passworded")) {
841                 er_flags |= (QR_PRIVATE | QR_PASSWORDED);
842         }
843         if (!strcmp(bstr("prefonly"), "yes")) {
844                 er_flags |= QR_PREFONLY;
845         } else {
846                 er_flags &= ~QR_PREFONLY;
847         }
848
849         if (!strcmp(bstr("readonly"), "yes")) {
850                 er_flags |= QR_READONLY;
851         } else {
852                 er_flags &= ~QR_READONLY;
853         }
854
855         if (!strcmp(bstr("network"), "yes")) {
856                 er_flags |= QR_NETWORK;
857         } else {
858                 er_flags &= ~QR_NETWORK;
859         }
860
861         if (!strcmp(bstr("directory"), "yes")) {
862                 er_flags |= QR_DIRECTORY;
863         } else {
864                 er_flags &= ~QR_DIRECTORY;
865         }
866
867         if (!strcmp(bstr("ulallowed"), "yes")) {
868                 er_flags |= QR_UPLOAD;
869         } else {
870                 er_flags &= ~QR_UPLOAD;
871         }
872
873         if (!strcmp(bstr("dlallowed"), "yes")) {
874                 er_flags |= QR_DOWNLOAD;
875         } else {
876                 er_flags &= ~QR_DOWNLOAD;
877         }
878
879         if (!strcmp(bstr("visdir"), "yes")) {
880                 er_flags |= QR_VISDIR;
881         } else {
882                 er_flags &= ~QR_VISDIR;
883         }
884
885         strcpy(buf, bstr("anon"));
886
887         er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
888         if (!strcmp(buf, "anononly"))
889                 er_flags |= QR_ANONONLY;
890         if (!strcmp(buf, "anon2"))
891                 er_flags |= QR_ANONOPT;
892
893         bump = 0;
894         if (!strcmp(bstr("bump"), "yes"))
895                 bump = 1;
896
897         er_floor = atoi(bstr("er_floor"));
898
899         sprintf(buf, "SETR %s|%s|%s|%u|%d|%d",
900              er_name, er_password, er_dirname, er_flags, bump, er_floor);
901         serv_puts(buf);
902         serv_gets(buf);
903         if (buf[0] != '2') {
904                 display_error(&buf[4]);
905                 return;
906         }
907         gotoroom(er_name, 0);
908
909         if (strlen(er_roomaide) > 0) {
910                 sprintf(buf, "SETA %s", er_roomaide);
911                 serv_puts(buf);
912                 serv_gets(buf);
913                 if (buf[0] != '2') {
914                         display_error(&buf[4]);
915                         return;
916                 }
917         }
918         smart_goto(er_name);
919 }
920
921
922
923 /*
924  * display the form for entering a new room
925  */
926 void display_entroom(void)
927 {
928         char buf[256];
929
930         serv_puts("CRE8 0");
931         serv_gets(buf);
932
933         if (buf[0] != '2') {
934                 display_error(&buf[4]);
935                 return;
936         }
937         output_headers(1);
938
939         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
940         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
941         wprintf("<B>Enter (create) a new room</B>\n");
942         wprintf("</FONT></TD></TR></TABLE>\n");
943
944         wprintf("<FORM METHOD=\"POST\" ACTION=\"/entroom\">\n");
945
946         wprintf("<UL><LI>Name of room: ");
947         wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" MAXLENGTH=\"19\">\n");
948
949         wprintf("<LI>Type of room:<UL>\n");
950
951         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
952         wprintf("CHECKED > Public room\n");
953
954         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
955         wprintf("> Private - guess name\n");
956
957         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
958         wprintf("> Private - require password:\n");
959         wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
960
961         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
962         wprintf("> Private - invitation only\n");
963
964         wprintf("<CENTER>\n");
965         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
966         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
967         wprintf("</CENTER>\n");
968         wprintf("</FORM>\n");
969         wDumpContent(1);
970 }
971
972
973
974 /*
975  * enter a new room
976  */
977 void entroom(void)
978 {
979         char buf[256];
980         char er_name[20];
981         char er_type[20];
982         char er_password[10];
983         int er_num_type;
984
985         if (strcmp(bstr("sc"), "OK")) {
986                 display_error("Cancelled.  No new room was created.");
987                 return;
988         }
989         strcpy(er_name, bstr("er_name"));
990         strcpy(er_type, bstr("type"));
991         strcpy(er_password, bstr("er_password"));
992
993         er_num_type = 0;
994         if (!strcmp(er_type, "guessname"))
995                 er_num_type = 1;
996         if (!strcmp(er_type, "passworded"))
997                 er_num_type = 2;
998         if (!strcmp(er_type, "invonly"))
999                 er_num_type = 3;
1000
1001         sprintf(buf, "CRE8 1|%s|%d|%s", er_name, er_num_type, er_password);
1002         serv_puts(buf);
1003         serv_gets(buf);
1004         if (buf[0] != '2') {
1005                 display_error(&buf[4]);
1006                 return;
1007         }
1008         smart_goto(er_name);
1009 }
1010
1011
1012 /*
1013  * display the screen to enter a private room
1014  */
1015 void display_private(char *rname, int req_pass)
1016 {
1017
1018         output_headers(1);
1019
1020         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
1021         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1022         wprintf("<B>Goto a private room</B>\n");
1023         wprintf("</FONT></TD></TR></TABLE>\n");
1024
1025         wprintf("<CENTER>\n");
1026         wprintf("If you know the name of a hidden (guess-name) or\n");
1027         wprintf("passworded room, you can enter that room by typing\n");
1028         wprintf("its name below.  Once you gain access to a private\n");
1029         wprintf("room, it will appear in your regular room listings\n");
1030         wprintf("so you don't have to keep returning here.\n");
1031         wprintf("<BR><BR>");
1032
1033         wprintf("<FORM METHOD=\"POST\" ACTION=\"/goto_private\">\n");
1034
1035         wprintf("<TABLE border><TR><TD>");
1036         wprintf("Enter room name:</TD><TD>");
1037         wprintf("<INPUT TYPE=\"text\" NAME=\"gr_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", rname);
1038
1039         if (req_pass) {
1040                 wprintf("</TD></TR><TR><TD>");
1041                 wprintf("Enter room password:</TD><TD>");
1042                 wprintf("<INPUT TYPE=\"password\" NAME=\"gr_pass\" MAXLENGTH=\"9\">\n");
1043         }
1044         wprintf("</TD></TR></TABLE>\n");
1045
1046         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1047         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1048         wprintf("</FORM>\n");
1049         wDumpContent(1);
1050 }
1051
1052 /* 
1053  * goto a private room
1054  */
1055 void goto_private(void)
1056 {
1057         char hold_rm[32];
1058         char buf[256];
1059
1060         if (strcasecmp(bstr("sc"), "OK")) {
1061                 display_main_menu();
1062                 return;
1063         }
1064         strcpy(hold_rm, WC->wc_roomname);
1065         strcpy(buf, "GOTO ");
1066         strcat(buf, bstr("gr_name"));
1067         strcat(buf, "|");
1068         strcat(buf, bstr("gr_pass"));
1069         serv_puts(buf);
1070         serv_gets(buf);
1071
1072         if (buf[0] == '2') {
1073                 smart_goto(bstr("gr_name"));
1074                 return;
1075         }
1076         if (!strncmp(buf, "540", 3)) {
1077                 display_private(bstr("gr_name"), 1);
1078                 return;
1079         }
1080         output_headers(1);
1081         wprintf("%s\n", &buf[4]);
1082         wDumpContent(1);
1083         return;
1084 }
1085
1086
1087 /*
1088  * display the screen to zap a room
1089  */
1090 void display_zap(void)
1091 {
1092         output_headers(1);
1093
1094         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
1095         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1096         wprintf("<B>Zap (forget) the current room</B>\n");
1097         wprintf("</FONT></TD></TR></TABLE>\n");
1098
1099         wprintf("If you select this option, <em>%s</em> will ", WC->wc_roomname);
1100         wprintf("disappear from your room list.  Is this what you wish ");
1101         wprintf("to do?<BR>\n");
1102
1103         wprintf("<FORM METHOD=\"POST\" ACTION=\"/zap\">\n");
1104         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1105         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1106         wprintf("</FORM>\n");
1107         wDumpContent(1);
1108 }
1109
1110
1111 /* 
1112  * zap a room
1113  */
1114 void zap(void)
1115 {
1116         char buf[256];
1117         char final_destination[256];
1118
1119         /* If the forget-room routine fails for any reason, we fall back
1120          * to the current room; otherwise, we go to the Lobby
1121          */
1122         strcpy(final_destination, WC->wc_roomname);
1123
1124         if (!strcasecmp(bstr("sc"), "OK")) {
1125                 serv_printf("GOTO %s", WC->wc_roomname);
1126                 serv_gets(buf);
1127                 if (buf[0] != '2') {
1128                         /* ExpressMessageCat(&buf[4]);   FIXME    */
1129                 } else {
1130                         serv_puts("FORG");
1131                         serv_gets(buf);
1132                         if (buf[0] != '2') {
1133                                 /* ExpressMessageCat(&buf[4]);  FIXME   */
1134                         } else {
1135                                 strcpy(final_destination, "_BASEROOM_");
1136                         }
1137                 }
1138         }
1139         smart_goto(final_destination);
1140 }
1141
1142
1143
1144
1145 /*
1146  * Confirm deletion of the current room
1147  */
1148 void confirm_delete_room(void)
1149 {
1150         char buf[256];
1151
1152         serv_puts("KILL 0");
1153         serv_gets(buf);
1154         if (buf[0] != '2') {
1155                 display_error(&buf[4]);
1156                 return;
1157         }
1158         output_headers(1);
1159         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
1160         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1161         wprintf("<B>Confirm deletion of room</B>\n");
1162         wprintf("</FONT></TD></TR></TABLE>\n");
1163
1164         wprintf("<CENTER>");
1165         wprintf("<FORM METHOD=\"POST\" ACTION=\"/delete_room\">\n");
1166
1167         wprintf("Are you sure you want to delete <FONT SIZE=+1>");
1168         escputs(WC->wc_roomname);
1169         wprintf("</FONT>?<BR>\n");
1170
1171         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">");
1172         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1173
1174         wprintf("</FORM></CENTER>\n");
1175         wDumpContent(1);
1176 }
1177
1178
1179 /*
1180  * Delete the current room
1181  */
1182 void delete_room(void)
1183 {
1184         char buf[256];
1185         char sc[256];
1186
1187         strcpy(sc, bstr("sc"));
1188
1189         if (strcasecmp(sc, "Delete")) {
1190                 display_error("Cancelled.  This room was not deleted.");
1191                 return;
1192         }
1193         serv_puts("KILL 1");
1194         serv_gets(buf);
1195         if (buf[0] != '2') {
1196                 display_error(&buf[4]);
1197         } else {
1198                 smart_goto("_BASEROOM_");
1199         }
1200 }