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