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