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