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