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