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