]> code.citadel.org Git - citadel.git/blob - webcit/roomops.c
* Got the Zap and List-Zapped commands working
[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 /*
51  * remove a room from the march list
52  */
53 void remove_march(char *aaa)
54 {
55         struct march *mptr,*mptr2;
56
57         if (march==NULL) return;
58
59         if (!strcasecmp(march->march_name,aaa)) {
60                 mptr = march->next;
61                 free(march);
62                 march = mptr;
63                 return;
64                 }
65
66         mptr2 = march;
67         for (mptr=march; mptr!=NULL; mptr=mptr->next) {
68                 if (!strcasecmp(mptr->march_name,aaa)) {
69                         mptr2->next = mptr->next;
70                         free(mptr);
71                         mptr=mptr2;
72                         }
73                 else {
74                         mptr2=mptr;
75                         }
76                 }
77         }
78
79
80 void listrms(char *variety)
81 {
82         char buf[256];
83         char rmname[32];
84         int f;
85
86         fprintf(stderr, "doing listrms(%s)\n", variety);
87         serv_puts(variety);
88         serv_gets(buf);
89         if (buf[0]!='1') return;
90         while (serv_gets(buf), strcmp(buf,"000")) {
91                 extract(rmname,buf,0);
92                 wprintf("<A HREF=\"/dotgoto&room=");
93                 urlescputs(rmname);
94                 wprintf("\" TARGET=\"top\">");
95                 escputs1(rmname,1);
96                 f = extract_int(buf,1);
97                 if ((f & QR_DIRECTORY) && (f & QR_NETWORK)) wprintf("}");
98                 else if (f & QR_DIRECTORY) wprintf("]");
99                 else if (f & QR_NETWORK) wprintf(")");
100                 else wprintf("&gt;");
101
102                 wprintf("</A><TT> </TT>\n");
103                 };
104         wprintf("<BR>\n");
105         }
106
107
108
109 /*
110  * list all rooms by floor
111  */
112 void list_all_rooms_by_floor(void) {
113         int a;
114         char buf[256];
115
116         load_floorlist();
117
118         printf("HTTP/1.0 200 OK\n");
119         output_headers(1);
120
121         wprintf("<TABLE width=100% border><TR><TH>Floor</TH>");
122         wprintf("<TH>Rooms with new messages</TH>");
123         wprintf("<TH>Rooms with no new messages</TH></TR>\n");
124
125         for (a=0; a<128; ++a) if (floorlist[a][0]!=0) {
126
127                 /* Floor name column */
128                 wprintf("<TR><TD>");
129         
130 /* FIX ... don't link to a floor pic that doesn't exist
131                 wprintf("<IMG SRC=\"/dynamic/_floorpic_/%d\" ALT=\"%s\">",
132                         &floorlist[a][0]);
133  */
134                 escputs(&floorlist[a][0]);
135
136                 wprintf("</TD>");
137
138                 /* Rooms with new messages column */
139                 wprintf("<TD>");
140                 sprintf(buf,"LKRN %d",a);
141                 listrms(buf);
142                 wprintf("</TD><TD>\n");
143
144                 /* Rooms with old messages column */
145                 sprintf(buf,"LKRO %d",a);
146                 listrms(buf);
147                 wprintf("</TD></TR>\n");
148                 }
149         wprintf("</TABLE>\n");
150         wprintf("</BODY></HTML>\n");
151         wDumpContent();
152         }
153
154
155 /*
156  * list all forgotten rooms
157  */
158 void zapped_list(void) {
159         printf("HTTP/1.0 200 OK\n");
160         output_headers(1);
161         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
162         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
163         wprintf("<B>Zapped (forgotten) rooms</B>\n");
164         wprintf("</FONT></TD></TR></TABLE><BR>\n");
165         listrms("LZRM -1");
166         wprintf("<BR><BR>\n");
167         wprintf("Click on any room to un-zap it and goto that room.\n");
168         wprintf("</BODY></HTML>\n");
169         wDumpContent();
170         }
171         
172
173 /*
174  * read this room's info file (set v to 1 for verbose mode)
175  */
176 void readinfo(int v)
177 {
178         char buf[256];
179
180         serv_puts("RINF");
181         serv_gets(buf);
182         if (buf[0]=='1') fmout(NULL);
183         else {
184                 if (v==1) wprintf("<EM>%s</EM><BR>\n",&buf[4]);
185                 }
186         }
187
188
189 /*
190  * generic routine to take the session to a new room
191  *
192  * display_name values:  0 = goto only
193  *                       1 = goto and display
194  *                       2 = display only
195  */
196 void gotoroom(char *gname, int display_name)
197 {
198         char buf[256];
199         static long ls = (-1L);
200
201
202         printf("HTTP/1.0 200 OK\n");
203         printf("Window-target: top\n");
204         output_headers(0);
205
206         wprintf("<HTML><HEAD>\n");
207
208         /* automatically fire up a read-new-msgs in the bottom frame */
209         wprintf("<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0;URL=/readnew\">\n");
210
211         wprintf("</HEAD><BODY ");
212         wprintf("BACKGROUND=\"/image&name=background\" TEXT=\"#000000\" LINK=\"#004400\">\n");
213
214         if (display_name != 2) {
215                 /* store ungoto information */
216                 strcpy(ugname, wc_roomname);
217                 uglsn = ls;
218                 fprintf(stderr, "setting ugname to %s and uglsn to %ld\n",
219                         ugname, uglsn);
220                 }
221
222         /* move to the new room */
223         sprintf(buf,"GOTO %s",gname);
224         serv_puts(buf);
225         serv_gets(buf);
226         if (buf[0]!='2') {
227                 serv_puts("GOTO _BASEROOM_");
228                 serv_gets(buf);
229                 }
230         if (buf[0]!='2') {
231                 wprintf("<EM>%s</EM><BR>\n",&buf[4]);
232                 wDumpContent();
233                 return;
234                 }
235
236         extract(wc_roomname,&buf[4],0);
237         room_flags = extract_int(&buf[4],4);
238         /* highest_msg_read = extract_int(&buf[4],6);
239         maxmsgnum = extract_int(&buf[4],5);
240         is_mail = (char) extract_int(&buf[4],7); */
241         ls = extract_long(&buf[4], 6);
242
243         if (is_aide) is_room_aide = is_aide;
244         else is_room_aide = (char) extract_int(&buf[4],8);
245
246         remove_march(wc_roomname);
247         if (!strcasecmp(gname,"_BASEROOM_")) remove_march(gname);
248
249         /* Display the room banner */
250
251         if (display_name) {
252                 wprintf("<CENTER><TABLE border=0><TR>");
253
254                 if ( (strlen(ugname)>0) && (strcasecmp(ugname,wc_roomname)) ) {
255                         wprintf("<TD><A HREF=\"/ungoto\">");
256                         wprintf("<IMG SRC=\"/static/back.gif\" border=0></A></TD>");
257                         }
258
259                 wprintf("<TD><H1>%s</H1>",wc_roomname);
260                 wprintf("<FONT SIZE=-1>%d new of %d messages</FONT></TD>\n",
261                         extract_int(&buf[4],1),
262                         extract_int(&buf[4],2));
263
264                 /* Display room graphic.  The server doesn't actually need the
265                  * room name, but we supply it in order to keep the browser
266                  * from using a cached graphic from another room.
267                  */
268                 serv_puts("OIMG _roompic_");
269                 serv_gets(buf);
270                 if (buf[0]=='2') {
271                         wprintf("<TD>");
272                         wprintf("<IMG SRC=\"/image&name=_roompic_&room=");
273                         escputs(wc_roomname);
274                         wprintf("\"></TD>");
275                         serv_puts("CLOS");
276                         serv_gets(buf);
277                         }
278
279                 wprintf("<TD>");
280                 readinfo(0);
281                 wprintf("</TD>");
282
283                 wprintf("<TD><A HREF=\"/gotonext\">");
284                 wprintf("<IMG SRC=\"/static/forward.gif\" border=0></A></TD>");
285
286                 wprintf("</TR></TABLE></CENTER>\n");
287                 }
288
289         strcpy(wc_roomname, wc_roomname);
290         wDumpContent();
291         }
292
293
294 /*
295  * operation to goto a room
296  */
297 void dotgoto(void) {
298         fprintf(stderr, "DOTGOTO: <%s>\n", bstr("room"));
299         gotoroom(bstr("room"),1);
300         }
301
302
303 /* Goto next room having unread messages.
304  * We want to skip over rooms that the user has already been to, and take the
305  * user back to the lobby when done.  The room we end up in is placed in
306  * newroom - which is set to 0 (the lobby) initially.
307  * We start the search in the current room rather than the beginning to prevent
308  * two or more concurrent users from dragging each other back to the same room.
309  */
310 void gotonext(void) {
311         char buf[256];
312         struct march *mptr,*mptr2;
313         char next_room[32];
314
315         /* First check to see if the march-mode list is already allocated.
316          * If it is, pop the first room off the list and go there.
317          */
318
319         if (march==NULL) {
320                 serv_puts("LKRN");
321                 serv_gets(buf);
322                 if (buf[0]=='1')
323                     while (serv_gets(buf), strcmp(buf,"000")) {
324                         mptr = (struct march *) malloc(sizeof(struct march));
325                         mptr->next = NULL;
326                         extract(mptr->march_name,buf,0);
327                         if (march==NULL) {
328                                 march = mptr;
329                                 }
330                         else {
331                                 mptr2 = march;
332                                 while (mptr2->next != NULL)
333                                         mptr2 = mptr2->next;
334                                 mptr2->next = mptr;
335                                 }
336                         }
337
338 /* add _BASEROOM_ to the end of the march list, so the user will end up
339  * in the system base room (usually the Lobby>) at the end of the loop
340  */
341                 mptr = (struct march *) malloc(sizeof(struct march));
342                 mptr->next = NULL;
343                 strcpy(mptr->march_name,"_BASEROOM_");
344                 if (march==NULL) {
345                         march = mptr;
346                         }
347                 else {
348                         mptr2 = march;
349                         while (mptr2->next != NULL)
350                                 mptr2 = mptr2->next;
351                         mptr2->next = mptr;
352                         }
353 /*
354  * ...and remove the room we're currently in, so a <G>oto doesn't make us
355  * walk around in circles
356  */
357                 remove_march(wc_roomname);
358                 }
359
360
361         if (march!=NULL) {
362                 strcpy(next_room,march->march_name);
363                 }
364         else {
365                 strcpy(next_room,"_BASEROOM_");
366                 }
367         gotoroom(next_room,1);
368    }
369
370
371
372 /*
373  * mark all messages in current room as having been read
374  */
375 void slrp_highest(void) {
376         char buf[256];
377
378         /* set pointer */
379         serv_puts("SLRP HIGHEST");
380         serv_gets(buf);
381         if (buf[0]!='2') {
382                 wprintf("<EM>%s</EM><BR>\n",&buf[4]);
383                 return;
384                 }
385         }
386
387
388 /*
389  * un-goto the previous room
390  */
391 void ungoto(void) { 
392         char buf[256];
393         
394         if (!strcmp(ugname, "")) {
395                 gotoroom(wc_roomname, 1);
396                 return;
397                 }
398         serv_printf("GOTO %s", ugname);
399         serv_gets(buf);
400         if (buf[0]!='2') {
401                 gotoroom(wc_roomname, 1);
402                 return;
403                 }
404         if (uglsn >= 0L) {
405                 serv_printf("SLRP %ld",uglsn);
406                 serv_gets(buf);
407                 }
408         strcpy(buf,ugname);
409         strcpy(ugname, "");
410         gotoroom(buf,1);
411         }
412
413 /*
414  * display the form for editing a room
415  */
416 int display_editroom(void) {
417         char buf[256];
418         char er_name[20];
419         char er_password[10];
420         char er_dirname[15];
421         char er_roomaide[26];
422         unsigned er_flags;
423
424         serv_puts("GETR");
425         serv_gets(buf);
426
427         if (buf[0]!='2') {
428                 wprintf("<EM>%s</EM><BR>\n",&buf[4]);
429                 return(0);
430                 }
431
432         extract(er_name,&buf[4],0);
433         extract(er_password,&buf[4],1);
434         extract(er_dirname,&buf[4],2);
435         er_flags=extract_int(&buf[4],3);
436
437
438         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
439         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
440         wprintf("<B>Edit this room</B>\n");
441         wprintf("</FONT></TD></TR></TABLE>\n");
442
443         wprintf("<FORM METHOD=\"POST\" ACTION=\"/editroom\">\n");
444
445         wprintf("<UL><LI>Name of room: ");      
446         wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n",er_name);
447
448         wprintf("<LI>Type of room:<UL>\n");
449
450         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
451         if ((er_flags & QR_PRIVATE) == 0) wprintf("CHECKED ");
452         wprintf("> Public room\n");
453
454         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
455         if ((er_flags & QR_PRIVATE)&&
456            (er_flags & QR_GUESSNAME)) wprintf("CHECKED ");
457         wprintf("> Private - guess name\n");
458
459         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
460         if ((er_flags & QR_PRIVATE)&&
461            (er_flags & QR_PASSWORDED)) wprintf("CHECKED ");
462         wprintf("> Private - require password:\n");
463         wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n",er_password);
464
465         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
466         if ( (er_flags & QR_PRIVATE)
467            && ((er_flags & QR_GUESSNAME) == 0)
468            && ((er_flags & QR_PASSWORDED) == 0) )
469                 wprintf("CHECKED ");
470         wprintf("> Private - invitation only\n");
471
472         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"bump\" VALUE=\"yes\" ");
473         wprintf("> If private, cause current users to forget room\n");
474
475         wprintf("</UL>\n");
476
477         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"prefonly\" VALUE=\"yes\" ");
478         if (er_flags & QR_PREFONLY) wprintf("CHECKED ");
479         wprintf("> Preferred users only\n");
480
481         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"readonly\" VALUE=\"yes\" ");
482         if (er_flags & QR_READONLY) wprintf("CHECKED ");
483         wprintf("> Read-only room\n");
484
485 /* directory stuff */
486         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"directory\" VALUE=\"yes\" ");
487         if (er_flags & QR_DIRECTORY) wprintf("CHECKED ");
488         wprintf("> File directory room\n");
489
490         wprintf("<UL><LI>Directory name: ");
491         wprintf("<INPUT TYPE=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n",er_dirname);
492
493         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"ulallowed\" VALUE=\"yes\" ");
494         if (er_flags & QR_UPLOAD) wprintf("CHECKED ");
495         wprintf("> Uploading allowed\n");
496
497         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"dlallowed\" VALUE=\"yes\" ");
498         if (er_flags & QR_DOWNLOAD) wprintf("CHECKED ");
499         wprintf("> Downloading allowed\n");
500
501         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"visdir\" VALUE=\"yes\" ");
502         if (er_flags & QR_VISDIR) wprintf("CHECKED ");
503         wprintf("> Visible directory</UL>\n");
504
505 /* end of directory stuff */
506         
507         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"network\" VALUE=\"yes\" ");
508         if (er_flags & QR_NETWORK) wprintf("CHECKED ");
509         wprintf("> Network shared room\n");
510
511 /* start of anon options */
512
513         wprintf("<LI>Anonymous messages<UL>\n");
514         
515         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"no\" ");
516         if ( ((er_flags & QR_ANONONLY)==0)
517            && ((er_flags & QR_ANONOPT)==0)) wprintf("CHECKED ");
518         wprintf("> No anonymous messages\n");
519
520         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anononly\" ");
521         if (er_flags & QR_ANONONLY) wprintf("CHECKED ");
522         wprintf("> All messages are anonymous\n");
523
524         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anon2\" ");
525         if (er_flags & QR_ANONOPT) wprintf("CHECKED ");
526         wprintf("> Prompt user when entering messages</UL>\n");
527
528 /* end of anon options */
529
530         wprintf("<LI>Room aide: \n");
531         serv_puts("GETA");
532         serv_gets(buf);
533         if (buf[0]!='2') {
534                 wprintf("<EM>%s</EM>\n",&buf[4]);
535                 }
536         else {
537                 extract(er_roomaide,&buf[4],0);
538                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n",er_roomaide);
539                 }
540                 
541         wprintf("</UL><CENTER>\n");
542         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
543         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
544         wprintf("</CENTER>\n");
545
546         wprintf("</FORM>\n");
547         return(1);
548         }
549
550
551 /*
552  * save new parameters for a room
553  */
554 int editroom(void) {
555         char buf[256];
556         char er_name[20];
557         char er_password[10];
558         char er_dirname[15];
559         char er_roomaide[26];
560         unsigned er_flags;
561         int bump;
562
563
564         if (strcmp(bstr("sc"),"OK")) {
565                 wprintf("<EM>Changes have <STRONG>not</STRONG> been saved.</EM><BR>");
566                 return(0);
567                 }
568         
569         serv_puts("GETR");
570         serv_gets(buf);
571
572         if (buf[0]!='2') {
573                 wprintf("<EM>%s</EM><BR>\n",&buf[4]);
574                 return(0);
575                 }
576
577         extract(er_name,&buf[4],0);
578         extract(er_password,&buf[4],1);
579         extract(er_dirname,&buf[4],2);
580         er_flags=extract_int(&buf[4],3);
581
582         strcpy(er_roomaide,bstr("er_roomaide"));
583         if (strlen(er_roomaide)==0) {
584                 serv_puts("GETA");
585                 serv_gets(buf);
586                 if (buf[0]!='2') {
587                         strcpy(er_roomaide,"");
588                         }
589                 else {
590                         extract(er_roomaide,&buf[4],0);
591                         }
592                 }
593
594         strcpy(buf,bstr("er_name"));            buf[20] = 0;
595         if (strlen(buf)>0) strcpy(er_name,buf);
596
597         strcpy(buf,bstr("er_password"));        buf[10] = 0;
598         if (strlen(buf)>0) strcpy(er_password,buf);
599
600         strcpy(buf,bstr("er_dirname"));         buf[15] = 0;
601         if (strlen(buf)>0) strcpy(er_dirname,buf);
602
603         strcpy(buf,bstr("type"));
604         er_flags &= !(QR_PRIVATE|QR_PASSWORDED|QR_GUESSNAME);
605
606         if (!strcmp(buf,"invonly")) {
607                 er_flags |= (QR_PRIVATE);
608                 }
609         if (!strcmp(buf,"guessname")) {
610                 er_flags |= (QR_PRIVATE | QR_GUESSNAME);
611                 }
612         if (!strcmp(buf,"passworded")) {
613                 er_flags |= (QR_PRIVATE | QR_PASSWORDED);
614                 }
615
616         if (!strcmp(bstr("prefonly"),"yes")) {
617                 er_flags |= QR_PREFONLY;
618                 }
619         else {
620                 er_flags &= ~QR_PREFONLY;
621                 }
622
623         if (!strcmp(bstr("readonly"),"yes")) {
624                 er_flags |= QR_READONLY;
625                 }
626         else {
627                 er_flags &= ~QR_READONLY;
628                 }
629
630         if (!strcmp(bstr("network"),"yes")) {
631                 er_flags |= QR_NETWORK;
632                 }
633         else {
634                 er_flags &= ~QR_NETWORK;
635                 }
636
637         if (!strcmp(bstr("directory"),"yes")) {
638                 er_flags |= QR_DIRECTORY;
639                 }
640         else {
641                 er_flags &= ~QR_DIRECTORY;
642                 }
643
644         if (!strcmp(bstr("ulallowed"),"yes")) {
645                 er_flags |= QR_UPLOAD;
646                 }
647         else {
648                 er_flags &= ~QR_UPLOAD;
649                 }
650
651         if (!strcmp(bstr("dlallowed"),"yes")) {
652                 er_flags |= QR_DOWNLOAD;
653                 }
654         else {
655                 er_flags &= ~QR_DOWNLOAD;
656                 }
657
658         if (!strcmp(bstr("visdir"),"yes")) {
659                 er_flags |= QR_VISDIR;
660                 }
661         else {
662                 er_flags &= ~QR_VISDIR;
663                 }
664
665         strcpy(buf,bstr("anon"));
666
667         er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
668         if (!strcmp(buf,"anononly")) er_flags |= QR_ANONONLY;
669         if (!strcmp(buf,"anon2")) er_flags |= QR_ANONOPT;
670
671         bump = 0;
672         if (!strcmp(bstr("bump"),"yes")) bump = 1;
673
674         sprintf(buf,"SETR %s|%s|%s|%u|%d",
675                 er_name,er_password,er_dirname,er_flags,bump);
676         serv_puts(buf);
677         serv_gets(buf);
678         if (buf[0]!='2') {
679                 wprintf("<EM>%s</EM><HR>\n",&buf[4]);
680                 return(display_editroom());
681                 }
682         gotoroom(er_name,0);
683
684         if (strlen(er_roomaide)>0) {
685                 sprintf(buf,"SETA %s",er_roomaide);
686                 serv_puts(buf);
687                 serv_gets(buf);
688                 if (buf[0]!='2') {
689                         wprintf("<EM>%s</EM><HR>\n",&buf[4]);
690                         return(display_editroom());
691                         }
692                 }
693
694         wprintf("<EM>Changes have been saved.</EM><BR>");
695         return(0);
696         }
697
698
699
700 /*
701  * display the form for entering a new room
702  */
703 int display_entroom(void) {
704         char buf[256];
705
706         serv_puts("CRE8 0");
707         serv_gets(buf);
708         
709         if (buf[0]!='2') {
710                 wprintf("<EM>%s</EM><HR>\n",&buf[4]);
711                 return(0);
712                 }
713
714         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
715         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
716         wprintf("<B>Enter (create) a new room</B>\n");
717         wprintf("</FONT></TD></TR></TABLE>\n");
718
719         wprintf("<FORM METHOD=\"POST\" ACTION=\"/entroom\">\n");
720
721         wprintf("<UL><LI>Name of room: ");      
722         wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" MAXLENGTH=\"19\">\n");
723
724         wprintf("<LI>Type of room:<UL>\n");
725
726         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
727         wprintf("CHECKED > Public room\n");
728
729         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
730         wprintf("> Private - guess name\n");
731
732         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
733         wprintf("> Private - require password:\n");
734         wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
735
736         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
737         wprintf("> Private - invitation only\n");
738
739         wprintf("<CENTER>\n");
740         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
741         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
742         wprintf("</CENTER>\n");
743         wprintf("</FORM>\n");
744         return(1);
745         }
746
747
748
749 /*
750  * enter a new room
751  */
752 int entroom(void) {
753         char buf[256];
754         char er_name[20];
755         char er_type[20];
756         char er_password[10];
757         int er_num_type;
758
759         if (strcmp(bstr("sc"),"OK")) {
760                 wprintf("<EM>Changes have <STRONG>not</STRONG> been saved.</EM><BR>");
761                 return(0);
762                 }
763         
764         strcpy(er_name,bstr("er_name"));
765         strcpy(er_type,bstr("type"));
766         strcpy(er_password,bstr("er_password"));
767
768         er_num_type = 0;
769         if (!strcmp(er_type,"guessname")) er_num_type = 1;
770         if (!strcmp(er_type,"passworded")) er_num_type = 2;
771         if (!strcmp(er_type,"invonly")) er_num_type = 3;
772
773         sprintf(buf,"CRE8 1|%s|%d|%s",er_name,er_num_type,er_password);
774         serv_puts(buf);
775         serv_gets(buf);
776         if (buf[0]!='2') {
777                 wprintf("<EM>%s</EM><HR>\n",&buf[4]);
778                 return(display_editroom());
779                 }
780         gotoroom(er_name,0);
781         return(0);
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         }