]> code.citadel.org Git - citadel.git/blob - webcit/roomops.c
* Changed the "auto read new" functionality from a meta refresh tag
[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></HEAD><BODY \n");
207
208         /* automatically fire up a read-new-msgs in the bottom frame */
209         if (display_name) wprintf("onload=location=\"/readnew\" ");
210
211         wprintf("BACKGROUND=\"/image&name=background\" TEXT=\"#000000\" LINK=\"#004400\">\n");
212
213         if (display_name != 2) {
214                 /* store ungoto information */
215                 strcpy(ugname, wc_roomname);
216                 uglsn = ls;
217                 fprintf(stderr, "setting ugname to %s and uglsn to %ld\n",
218                         ugname, uglsn);
219                 }
220
221         /* move to the new room */
222         sprintf(buf,"GOTO %s",gname);
223         serv_puts(buf);
224         serv_gets(buf);
225         if (buf[0]!='2') {
226                 serv_puts("GOTO _BASEROOM_");
227                 serv_gets(buf);
228                 }
229         if (buf[0]!='2') {
230                 wprintf("<EM>%s</EM><BR>\n",&buf[4]);
231                 wDumpContent();
232                 return;
233                 }
234
235         extract(wc_roomname,&buf[4],0);
236         room_flags = extract_int(&buf[4],4);
237         /* highest_msg_read = extract_int(&buf[4],6);
238         maxmsgnum = extract_int(&buf[4],5);
239         is_mail = (char) extract_int(&buf[4],7); */
240         ls = extract_long(&buf[4], 6);
241
242         if (is_aide) is_room_aide = is_aide;
243         else is_room_aide = (char) extract_int(&buf[4],8);
244
245         remove_march(wc_roomname);
246         if (!strcasecmp(gname,"_BASEROOM_")) remove_march(gname);
247
248         /* Display the room banner */
249
250         if (display_name) {
251                 wprintf("<CENTER><TABLE border=0><TR>");
252
253                 if ( (strlen(ugname)>0) && (strcasecmp(ugname,wc_roomname)) ) {
254                         wprintf("<TD><A HREF=\"/ungoto\">");
255                         wprintf("<IMG SRC=\"/static/back.gif\" border=0></A></TD>");
256                         }
257
258                 wprintf("<TD><H1>%s</H1>",wc_roomname);
259                 wprintf("<FONT SIZE=-1>%d new of %d messages</FONT></TD>\n",
260                         extract_int(&buf[4],1),
261                         extract_int(&buf[4],2));
262
263                 /* Display room graphic.  The server doesn't actually need the
264                  * room name, but we supply it in order to keep the browser
265                  * from using a cached graphic from another room.
266                  */
267                 serv_puts("OIMG _roompic_");
268                 serv_gets(buf);
269                 if (buf[0]=='2') {
270                         wprintf("<TD>");
271                         wprintf("<IMG SRC=\"/image&name=_roompic_&room=");
272                         escputs(wc_roomname);
273                         wprintf("\"></TD>");
274                         serv_puts("CLOS");
275                         serv_gets(buf);
276                         }
277
278                 wprintf("<TD>");
279                 readinfo(0);
280                 wprintf("</TD>");
281
282                 wprintf("<TD><A HREF=\"/gotonext\">");
283                 wprintf("<IMG SRC=\"/static/forward.gif\" border=0></A></TD>");
284
285                 wprintf("</TR></TABLE></CENTER>\n");
286                 }
287
288         strcpy(wc_roomname, wc_roomname);
289         wDumpContent();
290         }
291
292
293 /*
294  * operation to goto a room
295  */
296 void dotgoto(void) {
297         fprintf(stderr, "DOTGOTO: <%s>\n", bstr("room"));
298         gotoroom(bstr("room"),1);
299         }
300
301
302 /* Goto next room having unread messages.
303  * We want to skip over rooms that the user has already been to, and take the
304  * user back to the lobby when done.  The room we end up in is placed in
305  * newroom - which is set to 0 (the lobby) initially.
306  * We start the search in the current room rather than the beginning to prevent
307  * two or more concurrent users from dragging each other back to the same room.
308  */
309 void gotonext(void) {
310         char buf[256];
311         struct march *mptr,*mptr2;
312         char next_room[32];
313
314         /* First check to see if the march-mode list is already allocated.
315          * If it is, pop the first room off the list and go there.
316          */
317
318         if (march==NULL) {
319                 serv_puts("LKRN");
320                 serv_gets(buf);
321                 if (buf[0]=='1')
322                     while (serv_gets(buf), strcmp(buf,"000")) {
323                         mptr = (struct march *) malloc(sizeof(struct march));
324                         mptr->next = NULL;
325                         extract(mptr->march_name,buf,0);
326                         if (march==NULL) {
327                                 march = mptr;
328                                 }
329                         else {
330                                 mptr2 = march;
331                                 while (mptr2->next != NULL)
332                                         mptr2 = mptr2->next;
333                                 mptr2->next = mptr;
334                                 }
335                         }
336
337 /* add _BASEROOM_ to the end of the march list, so the user will end up
338  * in the system base room (usually the Lobby>) at the end of the loop
339  */
340                 mptr = (struct march *) malloc(sizeof(struct march));
341                 mptr->next = NULL;
342                 strcpy(mptr->march_name,"_BASEROOM_");
343                 if (march==NULL) {
344                         march = mptr;
345                         }
346                 else {
347                         mptr2 = march;
348                         while (mptr2->next != NULL)
349                                 mptr2 = mptr2->next;
350                         mptr2->next = mptr;
351                         }
352 /*
353  * ...and remove the room we're currently in, so a <G>oto doesn't make us
354  * walk around in circles
355  */
356                 remove_march(wc_roomname);
357                 }
358
359
360         if (march!=NULL) {
361                 strcpy(next_room,march->march_name);
362                 }
363         else {
364                 strcpy(next_room,"_BASEROOM_");
365                 }
366         gotoroom(next_room,1);
367    }
368
369
370
371 /*
372  * mark all messages in current room as having been read
373  */
374 void slrp_highest(void) {
375         char buf[256];
376
377         /* set pointer */
378         serv_puts("SLRP HIGHEST");
379         serv_gets(buf);
380         if (buf[0]!='2') {
381                 wprintf("<EM>%s</EM><BR>\n",&buf[4]);
382                 return;
383                 }
384         }
385
386
387 /*
388  * un-goto the previous room
389  */
390 void ungoto(void) { 
391         char buf[256];
392         
393         if (!strcmp(ugname, "")) {
394                 gotoroom(wc_roomname, 1);
395                 return;
396                 }
397         serv_printf("GOTO %s", ugname);
398         serv_gets(buf);
399         if (buf[0]!='2') {
400                 gotoroom(wc_roomname, 1);
401                 return;
402                 }
403         if (uglsn >= 0L) {
404                 serv_printf("SLRP %ld",uglsn);
405                 serv_gets(buf);
406                 }
407         strcpy(buf,ugname);
408         strcpy(ugname, "");
409         gotoroom(buf,1);
410         }
411
412 /*
413  * display the form for editing a room
414  */
415 int display_editroom(void) {
416         char buf[256];
417         char er_name[20];
418         char er_password[10];
419         char er_dirname[15];
420         char er_roomaide[26];
421         unsigned er_flags;
422
423         serv_puts("GETR");
424         serv_gets(buf);
425
426         if (buf[0]!='2') {
427                 wprintf("<EM>%s</EM><BR>\n",&buf[4]);
428                 return(0);
429                 }
430
431         extract(er_name,&buf[4],0);
432         extract(er_password,&buf[4],1);
433         extract(er_dirname,&buf[4],2);
434         er_flags=extract_int(&buf[4],3);
435
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>\n");
546         return(1);
547         }
548
549
550 /*
551  * save new parameters for a room
552  */
553 int 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                 wprintf("<EM>Changes have <STRONG>not</STRONG> been saved.</EM><BR>");
565                 return(0);
566                 }
567         
568         serv_puts("GETR");
569         serv_gets(buf);
570
571         if (buf[0]!='2') {
572                 wprintf("<EM>%s</EM><BR>\n",&buf[4]);
573                 return(0);
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                 wprintf("<EM>%s</EM><HR>\n",&buf[4]);
679                 return(display_editroom());
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                         wprintf("<EM>%s</EM><HR>\n",&buf[4]);
689                         return(display_editroom());
690                         }
691                 }
692
693         wprintf("<EM>Changes have been saved.</EM><BR>");
694         return(0);
695         }
696
697
698
699 /*
700  * display the form for entering a new room
701  */
702 int display_entroom(void) {
703         char buf[256];
704
705         serv_puts("CRE8 0");
706         serv_gets(buf);
707         
708         if (buf[0]!='2') {
709                 wprintf("<EM>%s</EM><HR>\n",&buf[4]);
710                 return(0);
711                 }
712
713         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
714         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
715         wprintf("<B>Enter (create) a new room</B>\n");
716         wprintf("</FONT></TD></TR></TABLE>\n");
717
718         wprintf("<FORM METHOD=\"POST\" ACTION=\"/entroom\">\n");
719
720         wprintf("<UL><LI>Name of room: ");      
721         wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" MAXLENGTH=\"19\">\n");
722
723         wprintf("<LI>Type of room:<UL>\n");
724
725         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
726         wprintf("CHECKED > Public room\n");
727
728         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
729         wprintf("> Private - guess name\n");
730
731         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
732         wprintf("> Private - require password:\n");
733         wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
734
735         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
736         wprintf("> Private - invitation only\n");
737
738         wprintf("<CENTER>\n");
739         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
740         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
741         wprintf("</CENTER>\n");
742         wprintf("</FORM>\n");
743         return(1);
744         }
745
746
747
748 /*
749  * enter a new room
750  */
751 int entroom(void) {
752         char buf[256];
753         char er_name[20];
754         char er_type[20];
755         char er_password[10];
756         int er_num_type;
757
758         if (strcmp(bstr("sc"),"OK")) {
759                 wprintf("<EM>Changes have <STRONG>not</STRONG> been saved.</EM><BR>");
760                 return(0);
761                 }
762         
763         strcpy(er_name,bstr("er_name"));
764         strcpy(er_type,bstr("type"));
765         strcpy(er_password,bstr("er_password"));
766
767         er_num_type = 0;
768         if (!strcmp(er_type,"guessname")) er_num_type = 1;
769         if (!strcmp(er_type,"passworded")) er_num_type = 2;
770         if (!strcmp(er_type,"invonly")) er_num_type = 3;
771
772         sprintf(buf,"CRE8 1|%s|%d|%s",er_name,er_num_type,er_password);
773         serv_puts(buf);
774         serv_gets(buf);
775         if (buf[0]!='2') {
776                 wprintf("<EM>%s</EM><HR>\n",&buf[4]);
777                 return(display_editroom());
778                 }
779         gotoroom(er_name,0);
780         return(0);
781         }
782
783
784 /*
785  * display the screen to enter a private room
786  */
787 void display_private(char *rname, int req_pass)
788 {
789
790         printf("HTTP/1.0 200 OK\n");
791         output_headers(1);
792
793         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
794         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
795         wprintf("<B>Goto a private room</B>\n");
796         wprintf("</FONT></TD></TR></TABLE>\n");
797
798         wprintf("<CENTER>\n");
799         wprintf("If you know the name of a hidden (guess-name) or\n");
800         wprintf("passworded room, you can enter that room by typing\n");
801         wprintf("its name below.  Once you gain access to a private\n");
802         wprintf("room, it will appear in your regular room listings\n");
803         wprintf("so you don't have to keep returning here.\n");
804         wprintf("<BR><BR>");
805         
806         wprintf("<FORM METHOD=\"POST\" ACTION=\"/goto_private\">\n");
807
808         wprintf("<TABLE border><TR><TD>");
809         wprintf("Enter room name:</TD><TD>");
810         wprintf("<INPUT TYPE=\"text\" NAME=\"gr_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n",rname);
811
812         if (req_pass) {
813                 wprintf("</TD></TR><TR><TD>");
814                 wprintf("Enter room password:</TD><TD>");
815                 wprintf("<INPUT TYPE=\"password\" NAME=\"gr_pass\" MAXLENGTH=\"9\">\n");
816                 }
817
818         wprintf("</TD></TR></TABLE>\n");
819         
820         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
821         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
822         wprintf("</FORM></HTML>\n");
823         wDumpContent();
824         }
825
826 /* 
827  * goto a private room
828  */
829 void goto_private(void) {
830         char hold_rm[32];
831         char buf[256];
832         
833         if (strcasecmp(bstr("sc"),"OK")) {
834                 display_main_menu();
835                 return;
836                 }
837
838         strcpy(hold_rm,wc_roomname);
839         strcpy(buf,"GOTO ");
840         strcat(buf,bstr("gr_name"));
841         strcat(buf,"|");
842         strcat(buf,bstr("gr_pass"));
843         serv_puts(buf);
844         serv_gets(buf);
845
846         if (buf[0]=='2') {
847                 gotoroom(bstr("gr_name"),1);
848                 return;
849                 }
850
851         if (!strncmp(buf,"540",3)) {
852                 display_private(bstr("gr_name"),1);
853                 return;
854                 }
855
856         printf("HTTP/1.0 200 OK\n");
857         output_headers(1);
858         wprintf("%s\n",&buf[4]);
859         wDumpContent();
860         return;
861         }
862
863
864 /*
865  * display the screen to zap a room
866  */
867 void display_zap(void) {
868         printf("HTTP/1.0 200 OK\n");
869         output_headers(1);
870         
871         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
872         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
873         wprintf("<B>Zap (forget) the current room</B>\n");
874         wprintf("</FONT></TD></TR></TABLE>\n");
875
876         wprintf("If you select this option, <em>%s</em> will ", wc_roomname);
877         wprintf("disappear from your room list.  Is this what you wish ");
878         wprintf("to do?<BR>\n");
879
880         wprintf("<FORM METHOD=\"POST\" ACTION=\"/zap\">\n");
881         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
882         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
883         wprintf("</FORM></HTML>\n");
884         wDumpContent();
885         }
886
887
888 /* 
889  * zap a room
890  */
891 void zap(void) {
892         char buf[256];
893
894         if (strcmp(bstr("sc"),"OK")) {
895                 display_main_menu();
896                 return;
897                 }
898
899         serv_printf("GOTO %s", wc_roomname);
900         serv_gets(buf);
901         if (buf[0] != '2') {
902                 display_error(&buf[4]);
903                 return;
904                 }
905
906         serv_puts("FORG");
907         serv_gets(buf);
908         if (buf[0] != '2') {
909                 display_error(&buf[4]);
910                 return;
911                 }
912
913         gotoroom(bstr("_BASEROOM_"),1);
914         }