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