]> code.citadel.org Git - citadel.git/blob - webcit/roomops.c
* view
[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][SIZ];
32
33
34 /*
35  * load the list of floors
36  */
37 void load_floorlist(void)
38 {
39         int a;
40         char buf[SIZ];
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[SIZ];
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[SIZ];
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[SIZ];
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[SIZ];
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                         "<A HREF=\"/dotgoto?room=_MAIL_\">"
332                         "<IMG SRC=\"/static/mail.gif\" border=0 "
333                         "ALT=\"You have new mail\">"
334                         "<BR><BLINK>%d</BLINK>", WC->new_mail);
335                 wprintf("<FONT SIZE=-2> new mail messages</FONT></A></TD>");
336                 WC->remember_new_mail = WC->new_mail;
337         }
338 }
339
340
341
342 void embed_room_banner(char *got) {
343         char fakegot[SIZ];
344
345         /* We need to have the information returned by a GOTO server command.
346          * If it isn't supplied, we fake it by issuing our own GOTO.
347          */
348         if (got == NULL) {
349                 serv_printf("GOTO %s", WC->wc_roomname);
350                 serv_gets(fakegot);
351                 got = fakegot;
352         }
353
354         /* Check for new mail. */
355         WC->new_mail = extract_int(&got[4], 9);
356         WC->wc_view = extract_int(&got[4], 11);
357
358         svprintf("ROOMNAME", WCS_STRING, "%s", WC->wc_roomname);
359         svprintf("NEWMSGS", WCS_STRING, "%d", extract_int(&got[4], 1));
360         svprintf("TOTALMSGS", WCS_STRING, "%d", extract_int(&got[4], 2));
361         svcallback("ROOMPIC", embed_room_graphic);
362         svcallback("ROOMINFO", readinfo);
363         svcallback("YOUHAVEMAIL", embed_newmail_button);
364
365         do_template("roombanner.html");
366         clear_local_substs();
367 }
368
369
370
371
372
373 /*
374  * generic routine to take the session to a new room
375  *
376  * display_name values:  0 = goto only
377  *                       1 = goto and display
378  *                       2 = display only
379  */
380 void gotoroom(char *gname, int display_name)
381 {
382         char buf[SIZ];
383         static long ls = (-1L);
384
385
386         if (display_name) {
387                 output_headers(0);
388                 wprintf("Pragma: no-cache\n");
389                 wprintf("Cache-Control: no-store\n");
390
391                 wprintf("<HTML><HEAD>\n"
392                         "<META HTTP-EQUIV=\"refresh\" CONTENT=\"500363689;\">\n"
393                         "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n"
394                         "<META HTTP-EQUIV=\"expired\" CONTENT=\"28-May-1971 18:10:00 GMT\">\n"
395                         "<meta name=\"MSSmartTagsPreventParsing\" content=\"TRUE\">\n"
396                         "</HEAD>\n");
397                 do_template("background.html");
398         }
399         if (display_name != 2) {
400                 /* store ungoto information */
401                 strcpy(WC->ugname, WC->wc_roomname);
402                 WC->uglsn = ls;
403         }
404         /* move to the new room */
405         serv_printf("GOTO %s", gname);
406         serv_gets(buf);
407         if (buf[0] != '2') {
408                 serv_puts("GOTO _BASEROOM_");
409                 serv_gets(buf);
410         }
411         if (buf[0] != '2') {
412                 if (display_name) {
413                         wprintf("<EM>%s</EM><BR>\n", &buf[4]);
414                         wDumpContent(1);
415                 }
416                 return;
417         }
418         extract(WC->wc_roomname, &buf[4], 0);
419         WC->room_flags = extract_int(&buf[4], 4);
420         /* highest_msg_read = extract_int(&buf[4],6);
421            maxmsgnum = extract_int(&buf[4],5);
422            is_mail = (char) extract_int(&buf[4],7); */
423         ls = extract_long(&buf[4], 6);
424
425         if (WC->is_aide)
426                 WC->is_room_aide = WC->is_aide;
427         else
428                 WC->is_room_aide = (char) extract_int(&buf[4], 8);
429
430         remove_march(WC->wc_roomname);
431         if (!strcasecmp(gname, "_BASEROOM_"))
432                 remove_march(gname);
433
434         /* Display the room banner */
435         if (display_name) {
436                 embed_room_banner(buf);
437                 wDumpContent(1);
438         }
439         strcpy(WC->wc_roomname, WC->wc_roomname);
440         WC->wc_view = extract_int(&buf[4], 11);
441 }
442
443
444 /*
445  * Locate the room on the march list which we most want to go to.  Each room
446  * is measured given a "weight" of preference based on various factors.
447  */
448 char *pop_march(int desired_floor)
449 {
450         static char TheRoom[64];
451         int TheFloor = 0;
452         int TheOrder = 32767;
453         int TheWeight = 0;
454         int weight;
455         struct march *mptr = NULL;
456
457         strcpy(TheRoom, "_BASEROOM_");
458         if (WC->march == NULL)
459                 return (TheRoom);
460
461         for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
462                 weight = 0;
463                 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
464                         weight = weight + 10000;
465                 if (mptr->march_floor == desired_floor)
466                         weight = weight + 5000;
467
468                 weight = weight + ((128 - (mptr->march_floor)) * 128);
469                 weight = weight + (128 - (mptr->march_order));
470
471                 if (weight > TheWeight) {
472                         TheWeight = weight;
473                         strcpy(TheRoom, mptr->march_name);
474                         TheFloor = mptr->march_floor;
475                         TheOrder = mptr->march_order;
476                 }
477         }
478         return (TheRoom);
479 }
480
481
482
483 /* Goto next room having unread messages.
484  * We want to skip over rooms that the user has already been to, and take the
485  * user back to the lobby when done.  The room we end up in is placed in
486  * newroom - which is set to 0 (the lobby) initially.
487  * We start the search in the current room rather than the beginning to prevent
488  * two or more concurrent users from dragging each other back to the same room.
489  */
490 void gotonext(void)
491 {
492         char buf[SIZ];
493         struct march *mptr, *mptr2;
494         char next_room[32];
495
496         /* First check to see if the march-mode list is already allocated.
497          * If it is, pop the first room off the list and go there.
498          */
499
500         if (WC->march == NULL) {
501                 serv_puts("LKRN");
502                 serv_gets(buf);
503                 if (buf[0] == '1')
504                         while (serv_gets(buf), strcmp(buf, "000")) {
505                                 mptr = (struct march *) malloc(sizeof(struct march));
506                                 mptr->next = NULL;
507                                 extract(mptr->march_name, buf, 0);
508                                 mptr->march_floor = extract_int(buf, 2);
509                                 mptr->march_order = extract_int(buf, 3);
510                                 if (WC->march == NULL) {
511                                         WC->march = mptr;
512                                 } else {
513                                         mptr2 = WC->march;
514                                         while (mptr2->next != NULL)
515                                                 mptr2 = mptr2->next;
516                                         mptr2->next = mptr;
517                                 }
518                         }
519 /* add _BASEROOM_ to the end of the march list, so the user will end up
520  * in the system base room (usually the Lobby>) at the end of the loop
521  */
522                 mptr = (struct march *) malloc(sizeof(struct march));
523                 mptr->next = NULL;
524                 strcpy(mptr->march_name, "_BASEROOM_");
525                 if (WC->march == NULL) {
526                         WC->march = mptr;
527                 } else {
528                         mptr2 = WC->march;
529                         while (mptr2->next != NULL)
530                                 mptr2 = mptr2->next;
531                         mptr2->next = mptr;
532                 }
533 /*
534  * ...and remove the room we're currently in, so a <G>oto doesn't make us
535  * walk around in circles
536  */
537                 remove_march(WC->wc_roomname);
538         }
539         if (WC->march != NULL) {
540                 strcpy(next_room, pop_march(-1));
541         } else {
542                 strcpy(next_room, "_BASEROOM_");
543         }
544
545
546         smart_goto(next_room);
547 }
548
549
550 void smart_goto(char *next_room) {
551         gotoroom(next_room, 0);
552         readloop("readnew");
553 }
554
555
556
557 /*
558  * mark all messages in current room as having been read
559  */
560 void slrp_highest(void)
561 {
562         char buf[SIZ];
563
564         /* set pointer */
565         serv_puts("SLRP HIGHEST");
566         serv_gets(buf);
567         if (buf[0] != '2') {
568                 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
569                 return;
570         }
571 }
572
573
574 /*
575  * un-goto the previous room
576  */
577 void ungoto(void)
578 {
579         char buf[SIZ];
580
581         if (!strcmp(WC->ugname, "")) {
582                 smart_goto(WC->wc_roomname);
583                 return;
584         }
585         serv_printf("GOTO %s", WC->ugname);
586         serv_gets(buf);
587         if (buf[0] != '2') {
588                 smart_goto(WC->wc_roomname);
589                 return;
590         }
591         if (WC->uglsn >= 0L) {
592                 serv_printf("SLRP %ld", WC->uglsn);
593                 serv_gets(buf);
594         }
595         strcpy(buf, WC->ugname);
596         strcpy(WC->ugname, "");
597         smart_goto(buf);
598 }
599
600 /*
601  * display the form for editing a room
602  */
603 void display_editroom(void)
604 {
605         char buf[SIZ];
606         char cmd[SIZ];
607         char node[SIZ];
608         char recp[SIZ];
609         char er_name[20];
610         char er_password[10];
611         char er_dirname[15];
612         char er_roomaide[26];
613         unsigned er_flags;
614         int er_floor;
615         int i, j;
616         char *tab;
617         char *shared_with;
618         char *not_shared_with;
619
620         tab = bstr("tab");
621         if (strlen(tab) == 0) tab = "admin";
622
623         serv_puts("GETR");
624         serv_gets(buf);
625
626         if (buf[0] != '2') {
627                 display_error(&buf[4]);
628                 return;
629         }
630         extract(er_name, &buf[4], 0);
631         extract(er_password, &buf[4], 1);
632         extract(er_dirname, &buf[4], 2);
633         er_flags = extract_int(&buf[4], 3);
634         er_floor = extract_int(&buf[4], 4);
635
636         output_headers(1);
637
638         /* print the tabbed dialog */
639         wprintf("<TABLE border=0 width=100%%><TR BGCOLOR=FFFFFF><TD> </TD>");
640
641         if (!strcmp(tab, "admin")) {
642                 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
643         }
644         else {
645                 wprintf("<TD><A HREF=\"/display_editroom&tab=admin\">");
646         }
647         wprintf("Room administration");
648         if (!strcmp(tab, "admin")) {
649                 wprintf("</B></FONT></TD>\n");
650         }
651         else {
652                 wprintf("</A></TD>\n");
653         }
654
655         wprintf("<TD> </TD>\n");
656
657         if (!strcmp(tab, "config")) {
658                 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
659         }
660         else {
661                 wprintf("<TD><A HREF=\"/display_editroom&tab=config\">");
662         }
663         wprintf("Room configuration");
664         if (!strcmp(tab, "config")) {
665                 wprintf("</B></FONT></TD>\n");
666         }
667         else {
668                 wprintf("</A></TD>\n");
669         }
670
671         wprintf("<TD> </TD>\n");
672
673         if (!strcmp(tab, "sharing")) {
674                 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
675         }
676         else {
677                 wprintf("<TD><A HREF=\"/display_editroom&tab=sharing\">");
678         }
679         wprintf("Sharing");
680         if (!strcmp(tab, "sharing")) {
681                 wprintf("</B></FONT></TD>\n");
682         }
683         else {
684                 wprintf("</A></TD>\n");
685         }
686
687         wprintf("<TD> </TD>\n");
688
689         if (!strcmp(tab, "listserv")) {
690                 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
691         }
692         else {
693                 wprintf("<TD><A HREF=\"/display_editroom&tab=listserv\">");
694         }
695         wprintf("Mailing list service");
696         if (!strcmp(tab, "listserv")) {
697                 wprintf("</B></FONT></TD>\n");
698         }
699         else {
700                 wprintf("</A></TD>\n");
701         }
702
703         wprintf("<TD> </TD></TR></TABLE>\n");
704
705         /* end tabbed dialog */ 
706
707
708         if (!strcmp(tab, "admin")) {
709                 wprintf("<UL>"
710                         "<LI><A HREF=\"/confirm_delete_room\">\n"
711                         "Delete this room</A>\n"
712                         "<LI><A HREF=\"/display_editroompic\">\n"
713                         "Set or change the graphic for this room's banner</A>\n"
714                         "<LI><A HREF=\"/display_editinfo\">\n"
715                         "Edit this room's Info file</A>\n"
716                         "</UL>");
717         }
718
719         if (!strcmp(tab, "config")) {
720                 wprintf("<FORM METHOD=\"POST\" ACTION=\"/editroom\">\n");
721         
722                 wprintf("<UL><LI>Name of room: ");
723                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", er_name);
724         
725                 wprintf("<LI>Resides on floor: ");
726                 load_floorlist();
727                 wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
728                 for (i = 0; i < 128; ++i)
729                         if (strlen(floorlist[i]) > 0) {
730                                 wprintf("<OPTION ");
731                                 if (i == er_floor)
732                                         wprintf("SELECTED ");
733                                 wprintf("VALUE=\"%d\">", i);
734                                 escputs(floorlist[i]);
735                                 wprintf("</OPTION>\n");
736                         }
737                 wprintf("</SELECT>\n");
738         
739                 wprintf("<LI>Type of room:<UL>\n");
740
741                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
742                 if ((er_flags & QR_PRIVATE) == 0)
743                 wprintf("CHECKED ");
744                 wprintf("> Public room\n");
745
746                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
747                 if ((er_flags & QR_PRIVATE) &&
748                     (er_flags & QR_GUESSNAME))
749                         wprintf("CHECKED ");
750                 wprintf("> Private - guess name\n");
751         
752                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
753                 if ((er_flags & QR_PRIVATE) &&
754                     (er_flags & QR_PASSWORDED))
755                         wprintf("CHECKED ");
756                 wprintf("> Private - require password:\n");
757                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n", er_password);
758         
759                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
760                 if ((er_flags & QR_PRIVATE)
761                     && ((er_flags & QR_GUESSNAME) == 0)
762                     && ((er_flags & QR_PASSWORDED) == 0))
763                         wprintf("CHECKED ");
764                 wprintf("> Private - invitation only\n");
765         
766                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"bump\" VALUE=\"yes\" ");
767                 wprintf("> If private, cause current users to forget room\n");
768         
769                 wprintf("</UL>\n");
770         
771                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"prefonly\" VALUE=\"yes\" ");
772                 if (er_flags & QR_PREFONLY)
773                         wprintf("CHECKED ");
774                 wprintf("> Preferred users only\n");
775         
776                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"readonly\" VALUE=\"yes\" ");
777                 if (er_flags & QR_READONLY)
778                         wprintf("CHECKED ");
779                 wprintf("> Read-only room\n");
780         
781         /* directory stuff */
782                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"directory\" VALUE=\"yes\" ");
783                 if (er_flags & QR_DIRECTORY)
784                         wprintf("CHECKED ");
785                 wprintf("> File directory room\n");
786
787                 wprintf("<UL><LI>Directory name: ");
788                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n", er_dirname);
789
790                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"ulallowed\" VALUE=\"yes\" ");
791                 if (er_flags & QR_UPLOAD)
792                         wprintf("CHECKED ");
793                 wprintf("> Uploading allowed\n");
794         
795                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"dlallowed\" VALUE=\"yes\" ");
796                 if (er_flags & QR_DOWNLOAD)
797                         wprintf("CHECKED ");
798                 wprintf("> Downloading allowed\n");
799         
800                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"visdir\" VALUE=\"yes\" ");
801                 if (er_flags & QR_VISDIR)
802                         wprintf("CHECKED ");
803                 wprintf("> Visible directory</UL>\n");
804         
805         /* end of directory stuff */
806         
807                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"network\" VALUE=\"yes\" ");
808                 if (er_flags & QR_NETWORK)
809                         wprintf("CHECKED ");
810                 wprintf("> Network shared room\n");
811
812         /* start of anon options */
813         
814                 wprintf("<LI>Anonymous messages<UL>\n");
815         
816                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"no\" ");
817                 if (((er_flags & QR_ANONONLY) == 0)
818                     && ((er_flags & QR_ANONOPT) == 0))
819                         wprintf("CHECKED ");
820                 wprintf("> No anonymous messages\n");
821         
822                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anononly\" ");
823                 if (er_flags & QR_ANONONLY)
824                         wprintf("CHECKED ");
825                 wprintf("> All messages are anonymous\n");
826         
827                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anon2\" ");
828                 if (er_flags & QR_ANONOPT)
829                         wprintf("CHECKED ");
830                 wprintf("> Prompt user when entering messages</UL>\n");
831         
832         /* end of anon options */
833         
834                 wprintf("<LI>Room aide: \n");
835                 serv_puts("GETA");
836                 serv_gets(buf);
837                 if (buf[0] != '2') {
838                         wprintf("<EM>%s</EM>\n", &buf[4]);
839                 } else {
840                         extract(er_roomaide, &buf[4], 0);
841                         wprintf("<INPUT TYPE=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n", er_roomaide);
842                 }
843         
844                 wprintf("</UL><CENTER>\n");
845                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
846                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
847                 wprintf("</CENTER>\n");
848         }
849
850
851         /* Sharing the room with other Citadel nodes... */
852         if (!strcmp(tab, "sharing")) {
853
854                 shared_with = strdup("");
855                 not_shared_with = strdup("");
856
857                 /* Learn the current configuration */
858                 serv_puts("CONF getsys|application/x-citadel-ignet-config");
859                 serv_gets(buf);
860                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
861                         extract(node, buf, 0);
862                         not_shared_with = realloc(not_shared_with,
863                                         strlen(not_shared_with) + 32);
864                         strcat(not_shared_with, node);
865                         strcat(not_shared_with, "|");
866                 }
867
868                 serv_puts("GNET");
869                 serv_gets(buf);
870                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
871                         extract(cmd, buf, 0);
872                         extract(node, buf, 1);
873                         if (!strcasecmp(cmd, "ignet_push_share")) {
874                                 shared_with = realloc(shared_with,
875                                                 strlen(shared_with) + 32);
876                                 strcat(shared_with, node);
877                                 strcat(shared_with, "|");
878                         }
879                 }
880
881                 for (i=0; i<num_tokens(shared_with, '|'); ++i) {
882                         extract(node, shared_with, i);
883                         for (j=0; j<num_tokens(not_shared_with, '|'); ++j) {
884                                 extract(cmd, not_shared_with, j);
885                                 if (!strcasecmp(node, cmd)) {
886                                         remove_token(not_shared_with, j, '|');
887                                 }
888                         }
889                 }
890
891                 /* Display the stuff */
892                 wprintf("<CENTER><BR>"
893                         "<TABLE border=1 cellpadding=5><TR>"
894                         "<TD><B><I>Shared with</I></B></TD>"
895                         "<TD><B><I>Not shared with</I></B></TD></TR>\n"
896                         "<TR><TD>\n");
897
898                 for (i=0; i<num_tokens(shared_with, '|'); ++i) {
899                         extract(node, shared_with, i);
900                         if (strlen(node) > 0) {
901                                 wprintf("%s ", node);
902                                 wprintf("<A HREF=\"/netedit&cmd=remove&line="
903                                         "ignet_push_share|");
904                                 urlescputs(node);
905                                 wprintf("&tab=sharing\">(unshare)</A><BR>");
906                         }
907                 }
908
909                 wprintf("</TD><TD>\n");
910
911                 for (i=0; i<num_tokens(not_shared_with, '|'); ++i) {
912                         extract(node, not_shared_with, i);
913                         if (strlen(node) > 0) {
914                                 wprintf("%s ", node);
915                                 wprintf("<A HREF=\"/netedit&cmd=add&line="
916                                         "ignet_push_share|");
917                                 urlescputs(node);
918                                 wprintf("&tab=sharing\">(share)</A><BR>");
919                         }
920                 }
921
922                 wprintf("</TD></TR></TABLE><BR>\n"
923                         "<I><B>Reminder:</B> When sharing a room, "
924                         "it must be shared from both ends.  Adding a node to "
925                         "the 'shared' list sends messages out, but in order to"
926                         " receive messages, the other nodes must be configured"
927                         " to send messages out to your system as well.</I><BR>"
928                         "</CENTER>\n");
929
930         }
931
932         /* Mailing list management */
933         if (!strcmp(tab, "listserv")) {
934
935                 wprintf("<BR><center><i>The contents of this room are being "
936                         "mailed to the following list recipients:"
937                         "</i><br><br>\n");
938
939                 serv_puts("GNET");
940                 serv_gets(buf);
941                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
942                         extract(cmd, buf, 0);
943                         if (!strcasecmp(cmd, "listrecp")) {
944                                 extract(recp, buf, 1);
945                         
946                                 escputs(recp);
947                                 wprintf(" <A HREF=\"/netedit&cmd=remove&line="
948                                         "listrecp|");
949                                 urlescputs(recp);
950                                 wprintf("&tab=listserv\">(remove)</A><BR>");
951
952                         }
953                 }
954                 wprintf("<BR><FORM METHOD=\"POST\" ACTION=\"/netedit\">\n"
955                         "<INPUT TYPE=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
956                         "<INPUT TYPE=\"hidden\" NAME=\"prefix\" VALUE=\"listrecp|\">\n");
957                 wprintf("<INPUT TYPE=\"text\" NAME=\"line\">\n");
958                 wprintf("<INPUT TYPE=\"submit\" NAME=\"cmd\" VALUE=\"Add\">");
959                 wprintf("</FORM><BR></CENTER>\n");
960         }
961
962         wDumpContent(1);
963 }
964
965
966 /*
967  * save new parameters for a room
968  */
969 void editroom(void)
970 {
971         char buf[SIZ];
972         char er_name[20];
973         char er_password[10];
974         char er_dirname[15];
975         char er_roomaide[26];
976         int er_floor;
977         unsigned er_flags;
978         int bump;
979
980
981         if (strcmp(bstr("sc"), "OK")) {
982                 display_error("Cancelled.  Changes were not saved.");
983                 return;
984         }
985         serv_puts("GETR");
986         serv_gets(buf);
987
988         if (buf[0] != '2') {
989                 display_error(&buf[4]);
990                 return;
991         }
992         extract(er_name, &buf[4], 0);
993         extract(er_password, &buf[4], 1);
994         extract(er_dirname, &buf[4], 2);
995         er_flags = extract_int(&buf[4], 3);
996
997         strcpy(er_roomaide, bstr("er_roomaide"));
998         if (strlen(er_roomaide) == 0) {
999                 serv_puts("GETA");
1000                 serv_gets(buf);
1001                 if (buf[0] != '2') {
1002                         strcpy(er_roomaide, "");
1003                 } else {
1004                         extract(er_roomaide, &buf[4], 0);
1005                 }
1006         }
1007         strcpy(buf, bstr("er_name"));
1008         buf[20] = 0;
1009         if (strlen(buf) > 0)
1010                 strcpy(er_name, buf);
1011
1012         strcpy(buf, bstr("er_password"));
1013         buf[10] = 0;
1014         if (strlen(buf) > 0)
1015                 strcpy(er_password, buf);
1016
1017         strcpy(buf, bstr("er_dirname"));
1018         buf[15] = 0;
1019         if (strlen(buf) > 0)
1020                 strcpy(er_dirname, buf);
1021
1022         strcpy(buf, bstr("type"));
1023         er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
1024
1025         if (!strcmp(buf, "invonly")) {
1026                 er_flags |= (QR_PRIVATE);
1027         }
1028         if (!strcmp(buf, "guessname")) {
1029                 er_flags |= (QR_PRIVATE | QR_GUESSNAME);
1030         }
1031         if (!strcmp(buf, "passworded")) {
1032                 er_flags |= (QR_PRIVATE | QR_PASSWORDED);
1033         }
1034         if (!strcmp(bstr("prefonly"), "yes")) {
1035                 er_flags |= QR_PREFONLY;
1036         } else {
1037                 er_flags &= ~QR_PREFONLY;
1038         }
1039
1040         if (!strcmp(bstr("readonly"), "yes")) {
1041                 er_flags |= QR_READONLY;
1042         } else {
1043                 er_flags &= ~QR_READONLY;
1044         }
1045
1046         if (!strcmp(bstr("network"), "yes")) {
1047                 er_flags |= QR_NETWORK;
1048         } else {
1049                 er_flags &= ~QR_NETWORK;
1050         }
1051
1052         if (!strcmp(bstr("directory"), "yes")) {
1053                 er_flags |= QR_DIRECTORY;
1054         } else {
1055                 er_flags &= ~QR_DIRECTORY;
1056         }
1057
1058         if (!strcmp(bstr("ulallowed"), "yes")) {
1059                 er_flags |= QR_UPLOAD;
1060         } else {
1061                 er_flags &= ~QR_UPLOAD;
1062         }
1063
1064         if (!strcmp(bstr("dlallowed"), "yes")) {
1065                 er_flags |= QR_DOWNLOAD;
1066         } else {
1067                 er_flags &= ~QR_DOWNLOAD;
1068         }
1069
1070         if (!strcmp(bstr("visdir"), "yes")) {
1071                 er_flags |= QR_VISDIR;
1072         } else {
1073                 er_flags &= ~QR_VISDIR;
1074         }
1075
1076         strcpy(buf, bstr("anon"));
1077
1078         er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
1079         if (!strcmp(buf, "anononly"))
1080                 er_flags |= QR_ANONONLY;
1081         if (!strcmp(buf, "anon2"))
1082                 er_flags |= QR_ANONOPT;
1083
1084         bump = 0;
1085         if (!strcmp(bstr("bump"), "yes"))
1086                 bump = 1;
1087
1088         er_floor = atoi(bstr("er_floor"));
1089
1090         sprintf(buf, "SETR %s|%s|%s|%u|%d|%d",
1091              er_name, er_password, er_dirname, er_flags, bump, er_floor);
1092         serv_puts(buf);
1093         serv_gets(buf);
1094         if (buf[0] != '2') {
1095                 display_error(&buf[4]);
1096                 return;
1097         }
1098         gotoroom(er_name, 0);
1099
1100         if (strlen(er_roomaide) > 0) {
1101                 sprintf(buf, "SETA %s", er_roomaide);
1102                 serv_puts(buf);
1103                 serv_gets(buf);
1104                 if (buf[0] != '2') {
1105                         display_error(&buf[4]);
1106                         return;
1107                 }
1108         }
1109         smart_goto(er_name);
1110 }
1111
1112 /*
1113  * Invite, Kick, and show Who Knows a room
1114  */
1115 void display_whok(void)
1116 {
1117         char buf[SIZ], room[SIZ], username[SIZ];
1118
1119         serv_puts("GETR");
1120         serv_gets(buf);
1121
1122         if (buf[0] != '2') {
1123                 display_error(&buf[4]);
1124                 return;
1125         }
1126         extract(room, &buf[4], 0);
1127
1128         strcpy(username, bstr("username"));
1129
1130         output_headers(1);
1131
1132         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
1133         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>Access control list for ");
1134         escputs(WC->wc_roomname);
1135         wprintf("</B></FONT></TD></TR></TABLE>\n");
1136
1137         if(!strcmp(bstr("sc"), "Kick")) {
1138                 sprintf(buf, "KICK %s", username);
1139                 serv_puts(buf);
1140                 serv_gets(buf);
1141
1142                 if (buf[0] != '2') {
1143                         display_error(&buf[4]);
1144                         return;
1145                 } else {
1146                         wprintf("<B><I>User %s kicked out of room %s.</I></B>\n", 
1147                                 username, room);
1148                 }
1149         } else if(!strcmp(bstr("sc"), "Invite")) {
1150                 sprintf(buf, "INVT %s", username);
1151                 serv_puts(buf);
1152                 serv_gets(buf);
1153
1154                 if (buf[0] != '2') {
1155                         display_error(&buf[4]);
1156                         return;
1157                 } else {
1158                         wprintf("<B><I>User %s invited to room %s.</I></B>\n", 
1159                                 username, room);
1160                 }
1161         }
1162         
1163
1164
1165         wprintf("<TABLE border=0 CELLSPACING=10><TR VALIGN=TOP>"
1166                 "<TD>The users listed below have access to this room.  "
1167                 "To remove a user from the access list, select the user "
1168                 "name from the list and click 'Kick'.<BR><BR>");
1169         
1170         wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1171         wprintf("<SELECT NAME=\"username\" SIZE=10>\n");
1172         serv_puts("WHOK");
1173         serv_gets(buf);
1174         if (buf[0] == '1') {
1175                 while (serv_gets(buf), strcmp(buf, "000")) {
1176                         extract(username, buf, 0);
1177                         wprintf("<OPTION>");
1178                         escputs(username);
1179                         wprintf("\n");
1180                 }
1181         }
1182         wprintf("</SELECT><BR>\n");
1183
1184         wprintf("<input type=submit name=sc value=\"Kick\">");
1185         wprintf("</FORM></CENTER>\n");
1186
1187         wprintf("</TD><TD>"
1188                 "To grant another user access to this room, enter the "
1189                 "user name in the box below and click 'Invite'.<BR><BR>");
1190
1191         wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1192         wprintf("Invite: ");
1193         wprintf("<input type=text name=username><BR>\n"
1194                 "<input type=hidden name=sc value=\"Invite\">"
1195                 "<input type=submit value=\"Invite\">"
1196                 "</FORM></CENTER>\n");
1197
1198         wprintf("</TD></TR></TABLE>\n");
1199         wDumpContent(1);
1200 }
1201
1202
1203
1204 /*
1205  * display the form for entering a new room
1206  */
1207 void display_entroom(void)
1208 {
1209         int i;
1210         char buf[SIZ];
1211
1212         serv_puts("CRE8 0");
1213         serv_gets(buf);
1214
1215         if (buf[0] != '2') {
1216                 display_error(&buf[4]);
1217                 return;
1218         }
1219         output_headers(1);
1220
1221         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>");
1222         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1223         wprintf("<B>Enter (create) a new room</B>\n");
1224         wprintf("</FONT></TD></TR></TABLE>\n");
1225
1226         wprintf("<FORM METHOD=\"POST\" ACTION=\"/entroom\">\n");
1227
1228         wprintf("<UL><LI>Name of room: ");
1229         wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" MAXLENGTH=\"19\">\n");
1230
1231         wprintf("<LI>Type of room:<UL>\n");
1232
1233         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
1234         wprintf("CHECKED > Public room\n");
1235
1236         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
1237         wprintf("> Private - guess name\n");
1238
1239         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
1240         wprintf("> Private - require password:\n");
1241         wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
1242
1243         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
1244         wprintf("> Private - invitation only\n");
1245         wprintf("</UL>\n");
1246
1247         wprintf("<LI>Resides on floor: ");
1248         load_floorlist(); 
1249         wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
1250         for (i = 0; i < 128; ++i)
1251                 if (strlen(floorlist[i]) > 0) {
1252                         wprintf("<OPTION ");
1253                         wprintf("VALUE=\"%d\">", i);
1254                         escputs(floorlist[i]);
1255                         wprintf("</OPTION>\n");
1256                 }
1257         wprintf("</SELECT>\n");                
1258         wprintf("</UL>\n");
1259
1260
1261         wprintf("<CENTER>\n");
1262         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1263         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1264         wprintf("</CENTER>\n");
1265         wprintf("</FORM>\n<HR>");
1266         serv_printf("MESG roomaccess");
1267         serv_gets(buf);
1268         if (buf[0] == '1') {
1269                 fmout(NULL);
1270         }
1271         wDumpContent(1);
1272 }
1273
1274
1275
1276 /*
1277  * enter a new room
1278  */
1279 void entroom(void)
1280 {
1281         char buf[SIZ];
1282         char er_name[20];
1283         char er_type[20];
1284         char er_password[10];
1285         int er_floor;
1286         int er_num_type;
1287
1288         if (strcmp(bstr("sc"), "OK")) {
1289                 display_error("Cancelled.  No new room was created.");
1290                 return;
1291         }
1292         strcpy(er_name, bstr("er_name"));
1293         strcpy(er_type, bstr("type"));
1294         strcpy(er_password, bstr("er_password"));
1295         er_floor = atoi(bstr("er_floor"));
1296
1297         er_num_type = 0;
1298         if (!strcmp(er_type, "guessname"))
1299                 er_num_type = 1;
1300         if (!strcmp(er_type, "passworded"))
1301                 er_num_type = 2;
1302         if (!strcmp(er_type, "invonly"))
1303                 er_num_type = 3;
1304
1305         sprintf(buf, "CRE8 1|%s|%d|%s|%d", 
1306                 er_name, er_num_type, er_password, er_floor);
1307         serv_puts(buf);
1308         serv_gets(buf);
1309         if (buf[0] != '2') {
1310                 display_error(&buf[4]);
1311                 return;
1312         }
1313         smart_goto(er_name);
1314 }
1315
1316
1317 /*
1318  * display the screen to enter a private room
1319  */
1320 void display_private(char *rname, int req_pass)
1321 {
1322
1323         output_headers(1);
1324
1325         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1326         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1327         wprintf("<B>Goto a private room</B>\n");
1328         wprintf("</FONT></TD></TR></TABLE>\n");
1329
1330         wprintf("<CENTER>\n");
1331         wprintf("If you know the name of a hidden (guess-name) or\n");
1332         wprintf("passworded room, you can enter that room by typing\n");
1333         wprintf("its name below.  Once you gain access to a private\n");
1334         wprintf("room, it will appear in your regular room listings\n");
1335         wprintf("so you don't have to keep returning here.\n");
1336         wprintf("<BR><BR>");
1337
1338         wprintf("<FORM METHOD=\"POST\" ACTION=\"/goto_private\">\n");
1339
1340         wprintf("<TABLE border><TR><TD>");
1341         wprintf("Enter room name:</TD><TD>");
1342         wprintf("<INPUT TYPE=\"text\" NAME=\"gr_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", rname);
1343
1344         if (req_pass) {
1345                 wprintf("</TD></TR><TR><TD>");
1346                 wprintf("Enter room password:</TD><TD>");
1347                 wprintf("<INPUT TYPE=\"password\" NAME=\"gr_pass\" MAXLENGTH=\"9\">\n");
1348         }
1349         wprintf("</TD></TR></TABLE>\n");
1350
1351         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1352         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1353         wprintf("</FORM>\n");
1354         wDumpContent(1);
1355 }
1356
1357 /* 
1358  * goto a private room
1359  */
1360 void goto_private(void)
1361 {
1362         char hold_rm[32];
1363         char buf[SIZ];
1364
1365         if (strcasecmp(bstr("sc"), "OK")) {
1366                 display_main_menu();
1367                 return;
1368         }
1369         strcpy(hold_rm, WC->wc_roomname);
1370         strcpy(buf, "GOTO ");
1371         strcat(buf, bstr("gr_name"));
1372         strcat(buf, "|");
1373         strcat(buf, bstr("gr_pass"));
1374         serv_puts(buf);
1375         serv_gets(buf);
1376
1377         if (buf[0] == '2') {
1378                 smart_goto(bstr("gr_name"));
1379                 return;
1380         }
1381         if (!strncmp(buf, "540", 3)) {
1382                 display_private(bstr("gr_name"), 1);
1383                 return;
1384         }
1385         output_headers(1);
1386         wprintf("%s\n", &buf[4]);
1387         wDumpContent(1);
1388         return;
1389 }
1390
1391
1392 /*
1393  * display the screen to zap a room
1394  */
1395 void display_zap(void)
1396 {
1397         output_headers(1);
1398
1399         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1400         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1401         wprintf("<B>Zap (forget) the current room</B>\n");
1402         wprintf("</FONT></TD></TR></TABLE>\n");
1403
1404         wprintf("If you select this option, <em>%s</em> will ", WC->wc_roomname);
1405         wprintf("disappear from your room list.  Is this what you wish ");
1406         wprintf("to do?<BR>\n");
1407
1408         wprintf("<FORM METHOD=\"POST\" ACTION=\"/zap\">\n");
1409         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1410         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1411         wprintf("</FORM>\n");
1412         wDumpContent(1);
1413 }
1414
1415
1416 /* 
1417  * zap a room
1418  */
1419 void zap(void)
1420 {
1421         char buf[SIZ];
1422         char final_destination[SIZ];
1423
1424         /* If the forget-room routine fails for any reason, we fall back
1425          * to the current room; otherwise, we go to the Lobby
1426          */
1427         strcpy(final_destination, WC->wc_roomname);
1428
1429         if (!strcasecmp(bstr("sc"), "OK")) {
1430                 serv_printf("GOTO %s", WC->wc_roomname);
1431                 serv_gets(buf);
1432                 if (buf[0] != '2') {
1433                         /* ExpressMessageCat(&buf[4]); */
1434                 } else {
1435                         serv_puts("FORG");
1436                         serv_gets(buf);
1437                         if (buf[0] != '2') {
1438                                 /* ExpressMessageCat(&buf[4]); */
1439                         } else {
1440                                 strcpy(final_destination, "_BASEROOM_");
1441                         }
1442                 }
1443         }
1444         smart_goto(final_destination);
1445 }
1446
1447
1448
1449
1450 /*
1451  * Confirm deletion of the current room
1452  */
1453 void confirm_delete_room(void)
1454 {
1455         char buf[SIZ];
1456
1457         serv_puts("KILL 0");
1458         serv_gets(buf);
1459         if (buf[0] != '2') {
1460                 display_error(&buf[4]);
1461                 return;
1462         }
1463         output_headers(1);
1464         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1465         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1466         wprintf("<B>Confirm deletion of room</B>\n");
1467         wprintf("</FONT></TD></TR></TABLE>\n");
1468
1469         wprintf("<CENTER>");
1470         wprintf("<FORM METHOD=\"POST\" ACTION=\"/delete_room\">\n");
1471
1472         wprintf("Are you sure you want to delete <FONT SIZE=+1>");
1473         escputs(WC->wc_roomname);
1474         wprintf("</FONT>?<BR>\n");
1475
1476         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">");
1477         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1478
1479         wprintf("</FORM></CENTER>\n");
1480         wDumpContent(1);
1481 }
1482
1483
1484 /*
1485  * Delete the current room
1486  */
1487 void delete_room(void)
1488 {
1489         char buf[SIZ];
1490         char sc[SIZ];
1491
1492         strcpy(sc, bstr("sc"));
1493
1494         if (strcasecmp(sc, "Delete")) {
1495                 display_error("Cancelled.  This room was not deleted.");
1496                 return;
1497         }
1498         serv_puts("KILL 1");
1499         serv_gets(buf);
1500         if (buf[0] != '2') {
1501                 display_error(&buf[4]);
1502         } else {
1503                 smart_goto("_BASEROOM_");
1504         }
1505 }
1506
1507
1508
1509 /*
1510  * Perform changes to a room's network configuration
1511  */
1512 void netedit(void) {
1513         FILE *fp;
1514         char buf[SIZ];
1515         char line[SIZ];
1516
1517         if (strlen(bstr("line"))==0) {
1518                 display_editroom();
1519                 return;
1520         }
1521
1522         strcpy(line, bstr("prefix"));
1523         strcat(line, bstr("line"));
1524         strcat(line, bstr("suffix"));
1525
1526         fp = tmpfile();
1527         if (fp == NULL) {
1528                 display_editroom();
1529                 return;
1530         }
1531
1532         serv_puts("GNET");
1533         serv_gets(buf);
1534         if (buf[0] != '1') {
1535                 fclose(fp);
1536                 display_editroom();
1537                 return;
1538         }
1539
1540         /* This loop works for add *or* remove.  Spiffy, eh? */
1541         while (serv_gets(buf), strcmp(buf, "000")) {
1542                 if (strcasecmp(buf, line)) {
1543                         fprintf(fp, "%s\n", buf);
1544                 }
1545         }
1546
1547         rewind(fp);
1548         serv_puts("SNET");
1549         serv_gets(buf);
1550         if (buf[0] != '4') {
1551                 fclose(fp);
1552                 display_editroom();
1553                 return;
1554         }
1555
1556         while (fgets(buf, sizeof buf, fp) != NULL) {
1557                 buf[strlen(buf)-1] = 0;
1558                 serv_puts(buf);
1559         }
1560
1561         if (!strcasecmp(bstr("cmd"), "add")) {
1562                 serv_puts(line);
1563         }
1564
1565         serv_puts("000");
1566         fclose(fp);
1567         display_editroom();
1568 }