11 extern struct config config;
13 FILE *popen(const char *, const char *);
16 * is_known() - returns nonzero if room is in user's known room list
18 int is_known(struct quickroom *roombuf, int roomnum, struct usersupp *userbuf)
21 /* for internal programs, always succeed */
22 if (((CC->internal_pgm))&&(roombuf->QRflags & QR_INUSE)) return(1);
25 if (roomnum==1) roombuf->QRhighest=userbuf->mailnum[MAILSLOTS-1];
27 /* for regular rooms, check the permissions */
28 if ((roombuf->QRflags & QR_INUSE)
29 && ( (roomnum!=2) || (userbuf->axlevel>=6))
30 && (roombuf->QRgen != (userbuf->forget[roomnum]) )
32 && ( ((roombuf->QRflags&QR_PREFONLY)==0)
33 || ((userbuf->axlevel)>=5)
36 && ( ((roombuf->QRflags&QR_PRIVATE)==0)
37 || ((userbuf->axlevel)>=6)
38 || (roombuf->QRgen==(userbuf->generation[roomnum]))
47 * has_newmsgs() - returns nonzero if room has new messages
49 int has_newmsgs(struct quickroom *roombuf, int roomnum, struct usersupp *userbuf)
51 if (roombuf->QRhighest > (userbuf->lastseen[roomnum]) )
57 * is_zapped() - returns nonzero if room is on forgotten rooms list
59 int is_zapped(struct quickroom *roombuf, int roomnum, struct usersupp *userbuf)
61 if (roomnum==1) roombuf->QRhighest=userbuf->mailnum[MAILSLOTS-1];
62 if ((roombuf->QRflags & QR_INUSE)
63 && (roombuf->QRgen == (userbuf->forget[roomnum]) )
64 && ( (roomnum!=2) || ((userbuf->axlevel)>=6))
65 && ( ((roombuf->QRflags&QR_PRIVATE)==0)
66 || ((userbuf->axlevel)>=6)
67 || (roombuf->QRgen==(userbuf->generation[roomnum]))
74 * getroom() - retrieve room data from disk
76 void getroom(struct quickroom *qrbuf, int room_num)
78 struct cdbdata *cdbqr;
81 bzero(qrbuf, sizeof(struct quickroom));
82 cdbqr = cdb_fetch(CDB_QUICKROOM, &room_num, sizeof(int));
84 memcpy(qrbuf, cdbqr->ptr, cdbqr->len);
89 qrbuf->QRflags = QR_INUSE;
92 case 0: strcpy(qrbuf->QRname, "Lobby");
94 case 1: strcpy(qrbuf->QRname, "Mail");
96 case 2: strcpy(qrbuf->QRname, "Aide");
103 /** FIX ** VILE SLEAZY HACK ALERT!!
104 * This is a temporary fix until I can track down where room names
105 * are getting corrupted on some systems.
107 for (a=0; a<20; ++a) if (qrbuf->QRname[a] < 32) qrbuf->QRname[a] = 0;
108 qrbuf->QRname[19] = 0;
112 * lgetroom() - same as getroom() but locks the record (if supported)
114 void lgetroom(struct quickroom *qrbuf, int room_num)
116 begin_critical_section(S_QUICKROOM);
117 getroom(qrbuf,room_num);
122 * putroom() - store room data on disk
124 void putroom(struct quickroom *qrbuf, int room_num)
127 cdb_store(CDB_QUICKROOM, &room_num, sizeof(int),
128 qrbuf, sizeof(struct quickroom));
133 * lputroom() - same as putroom() but unlocks the record (if supported)
135 void lputroom(struct quickroom *qrbuf, int room_num)
138 putroom(qrbuf,room_num);
139 end_critical_section(S_QUICKROOM);
145 * getfloor() - retrieve floor data from disk
147 void getfloor(struct floor *flbuf, int floor_num)
149 struct cdbdata *cdbfl;
151 bzero(flbuf, sizeof(struct floor));
152 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
154 memcpy(flbuf, cdbfl->ptr, cdbfl->len);
158 if (floor_num == 0) {
159 strcpy(flbuf->f_name, "Main Floor");
160 flbuf->f_flags = F_INUSE;
161 flbuf->f_ref_count = 3;
168 * lgetfloor() - same as getfloor() but locks the record (if supported)
170 void lgetfloor(struct floor *flbuf, int floor_num)
173 begin_critical_section(S_FLOORTAB);
174 getfloor(flbuf,floor_num);
179 * putfloor() - store floor data on disk
181 void putfloor(struct floor *flbuf, int floor_num)
183 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
184 flbuf, sizeof(struct floor));
189 * lputfloor() - same as putfloor() but unlocks the record (if supported)
191 void lputfloor(struct floor *flbuf, int floor_num)
194 putfloor(flbuf,floor_num);
195 end_critical_section(S_FLOORTAB);
201 void readmail(void) {
203 for (a=0; a<MSGSPERRM; ++a) {
204 CC->fullroom.FRnum[a]=0L;
206 for (a=0; a<MAILSLOTS; ++a) {
207 CC->fullroom.FRnum[a+(MSGSPERRM-MAILSLOTS)] =
208 CC->usersupp.mailnum[a];
210 CC->quickroom.QRhighest = CC->usersupp.mailnum[MAILSLOTS-1];
214 void writemail(void) {
216 lgetuser(&CC->usersupp,CC->curr_user);
217 for (a=0; a<MAILSLOTS; ++a) {
218 CC->usersupp.mailnum[a] =
219 CC->fullroom.FRnum[a+(MSGSPERRM-MAILSLOTS)];
221 lputuser(&CC->usersupp,CC->curr_user);
228 * get_fullroom() - retrieve room message pointers
230 void get_fullroom(struct fullroom *frbuf, int room_num)
232 struct cdbdata *cdbfr;
235 bzero(frbuf, sizeof(struct fullroom));
236 cdbfr = cdb_fetch(CDB_FULLROOM, &room_num, sizeof(int));
238 memcpy(frbuf, cdbfr->ptr, cdbfr->len);
250 * put_fullroom() - retrieve room message pointers
252 void put_fullroom(struct fullroom *frbuf, int room_num)
256 cdb_store(CDB_FULLROOM, &room_num, sizeof(int),
257 frbuf, sizeof(struct fullroom));
267 * cmd_lrms() - List all accessible rooms, known or forgotten
269 void cmd_lrms(char *argbuf)
272 int target_floor = (-1);
273 struct quickroom qrbuf;
275 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
277 if (!(CC->logged_in)) {
278 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
282 if (getuser(&CC->usersupp,CC->curr_user)) {
283 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
287 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
289 for (a=0; a<MAXROOMS; ++a) {
291 if ( ( (is_known(&qrbuf,a,&CC->usersupp))
292 || (is_zapped(&qrbuf,a,&CC->usersupp)) )
293 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) )
294 cprintf("%s|%u|%d\n",
295 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
301 * cmd_lkra() - List all known rooms
303 void cmd_lkra(char *argbuf)
306 struct quickroom qrbuf;
307 int target_floor = (-1);
309 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
311 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
312 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
316 if (!(CC->internal_pgm)) if (getuser(&CC->usersupp,CC->curr_user)) {
317 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
321 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
323 for (a=0; a<MAXROOMS; ++a) {
325 if ((is_known(&qrbuf,a,&CC->usersupp))
326 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) )
327 cprintf("%s|%u|%d\n",
328 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
334 * cmd_lkrn() - List Known Rooms with New messages
336 void cmd_lkrn(char *argbuf)
339 struct quickroom qrbuf;
340 int target_floor = (-1);
342 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
344 if (!(CC->logged_in)) {
345 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
349 if (getuser(&CC->usersupp,CC->curr_user)) {
350 cprintf("%d can't locate user\n",ERROR+INTERNAL_ERROR);
354 cprintf("%d list of rms w/ new msgs\n",LISTING_FOLLOWS);
356 for (a=0; a<MAXROOMS; ++a) {
358 if ( ( (is_known(&qrbuf,a,&CC->usersupp))
359 && (has_newmsgs(&qrbuf,a,&CC->usersupp)) )
360 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) )
361 cprintf("%s|%u|%d\n",
362 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
368 * cmd_lkro() - List Known Rooms with Old (no new) messages
370 void cmd_lkro(char *argbuf)
373 struct quickroom qrbuf;
374 int target_floor = (-1);
376 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
378 if (!(CC->logged_in)) {
379 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
383 if (getuser(&CC->usersupp,CC->curr_user)) {
384 cprintf("%d can't locate user\n",ERROR+INTERNAL_ERROR);
388 cprintf("%d list of rms w/o new msgs\n",LISTING_FOLLOWS);
390 for (a=0; a<MAXROOMS; ++a) {
392 if ( ( (is_known(&qrbuf,a,&CC->usersupp))
393 && (!has_newmsgs(&qrbuf,a,&CC->usersupp)) )
394 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) ) {
395 if (!strcmp(qrbuf.QRname,"000")) cprintf(">");
396 cprintf("%s|%u|%d\n",
397 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
404 * cmd_lzrm() - List Zapped RooMs
406 void cmd_lzrm(char *argbuf)
409 struct quickroom qrbuf;
410 int target_floor = (-1);
412 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
414 if (!(CC->logged_in)) {
415 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
419 if (getuser(&CC->usersupp,CC->curr_user)) {
420 cprintf("%d can't locate user\n",ERROR+INTERNAL_ERROR);
424 cprintf("%d list of forgotten rms\n",LISTING_FOLLOWS);
426 for (a=0; a<MAXROOMS; ++a) {
428 if ( (is_zapped(&qrbuf,a,&CC->usersupp))
429 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) ) {
430 if (!strcmp(qrbuf.QRname,"000")) cprintf(">");
431 cprintf("%s|%u|%d\n",
432 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
440 void usergoto(int where, int display_result)
446 int newmailcount = 0;
449 getroom(&CC->quickroom,CC->curr_rm);
450 lgetuser(&CC->usersupp,CC->curr_user);
451 CC->usersupp.forget[CC->curr_rm]=(-1);
452 CC->usersupp.generation[CC->curr_rm]=CC->quickroom.QRgen;
453 lputuser(&CC->usersupp,CC->curr_user);
455 for (a=0; a<MAILSLOTS; ++a)
456 if (CC->usersupp.mailnum[a] > CC->usersupp.lastseen[1]) ++newmailcount;
458 /* set info to 1 if the user needs to read the room's info file */
459 if (CC->quickroom.QRinfo > CC->usersupp.lastseen[CC->curr_rm]) info = 1;
463 get_fullroom(&CC->fullroom,CC->curr_rm);
464 for (a=0; a<MSGSPERRM; ++a) {
465 if (CC->fullroom.FRnum[a]>0L) {
467 if (CC->fullroom.FRnum[a]>CC->usersupp.lastseen[CC->curr_rm]) ++c;
472 if (CC->curr_rm == 1) rmailflag = 1;
475 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
476 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
479 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
481 CC->quickroom.QRname,c,b,info,CC->quickroom.QRflags,
482 CC->quickroom.QRhighest,CC->usersupp.lastseen[CC->curr_rm],
483 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
484 if (CC->quickroom.QRflags & QR_PRIVATE) {
485 set_wtmpsupp("<private room>");
488 set_wtmpsupp(CC->quickroom.QRname);
494 * cmd_goto() - goto a new room
496 void cmd_goto(char *gargs)
498 struct quickroom QRscratch;
501 char bbb[20],towhere[32],password[20];
503 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
504 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
508 extract(towhere,gargs,0);
509 extract(password,gargs,1);
512 getuser(&CC->usersupp,CC->curr_user);
513 for (a=0; a<MAXROOMS; ++a) {
514 getroom(&QRscratch,a);
515 if ((a==0)&&(!strucmp(towhere,"_BASEROOM_"))) {
516 strncpy(towhere,QRscratch.QRname,31);
518 if ((a==1)&&(!strucmp(towhere,"_MAIL_"))) {
519 strncpy(towhere,QRscratch.QRname,31);
521 if ((!strucmp(QRscratch.QRname,config.c_twitroom))
522 &&(!strucmp(towhere,"_BITBUCKET_"))) {
523 strncpy(towhere,QRscratch.QRname,31);
525 strcpy(bbb,QRscratch.QRname);
528 /* let internal programs go directly to any room */
529 if (((CC->internal_pgm))&&(!strucmp(bbb,towhere))) {
534 /* normal clients have to pass through security */
536 (strucmp(bbb,towhere)==0)
537 && ((QRscratch.QRflags&QR_INUSE)!=0)
539 && ( ((QRscratch.QRflags&QR_PREFONLY)==0)
540 || (CC->usersupp.axlevel>=5)
543 && ( (a!=2) || (CC->usersupp.axlevel>=6) )
545 && ( ((QRscratch.QRflags&QR_PRIVATE)==0)
546 || (QRscratch.QRflags&QR_GUESSNAME)
547 || (CC->usersupp.axlevel>=6)
548 || (QRscratch.QRflags&QR_PASSWORDED)
549 || (QRscratch.QRgen==CC->usersupp.generation[a])
557 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
558 (CC->usersupp.axlevel<6) &&
559 (QRscratch.QRgen!=CC->usersupp.generation[a]) &&
560 (strucmp(QRscratch.QRpasswd,password))
562 cprintf("%d wrong or missing passwd\n",
563 ERROR+PASSWORD_REQUIRED);
572 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
576 void cmd_whok(void) {
577 struct usersupp temp;
578 struct cdbdata *cdbus;
580 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
581 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
584 getuser(&CC->usersupp,CC->curr_user);
586 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
587 cprintf("%d Higher access required.\n",
588 ERROR+HIGHER_ACCESS_REQUIRED);
592 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
593 cdb_rewind(CDB_USERSUPP);
594 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
595 bzero(&temp, sizeof(struct usersupp));
596 memcpy(&temp, cdbus->ptr, cdbus->len);
598 if ((CC->quickroom.QRflags & QR_INUSE)
599 && ( (CC->curr_rm!=2) || (temp.axlevel>=6) )
600 && (CC->quickroom.QRgen != (temp.forget[CC->curr_rm]) )
602 && ( ((CC->quickroom.QRflags&QR_PREFONLY)==0)
606 && ( ((CC->quickroom.QRflags&QR_PRIVATE)==0)
608 || (CC->quickroom.QRgen==(temp.generation[CC->curr_rm]))
611 && (strncmp(temp.fullname,"000",3))
613 ) cprintf("%s\n",temp.fullname);
620 * RDIR command for room directory
622 void cmd_rdir(void) {
629 if (!(CC->logged_in)) {
630 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
634 getroom(&CC->quickroom,CC->curr_rm);
635 getuser(&CC->usersupp,CC->curr_user);
637 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
638 cprintf("%d not here.\n",ERROR+NOT_HERE);
642 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
643 && (CC->usersupp.axlevel<6)
644 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
645 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
649 cprintf("%d %s|%s/files/%s\n",
650 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
652 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
653 BBSDIR,CC->quickroom.QRdirname,CC->temp);
656 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
658 if (fd==NULL) fd=fopen("/dev/null","r");
660 ls = fopen(CC->temp,"r");
661 while (fgets(flnm,256,ls)!=NULL) {
662 flnm[strlen(flnm)-1]=0;
663 if (strucmp(flnm,"filedir")) {
664 sprintf(buf,"%s/files/%s/%s",
665 BBSDIR,CC->quickroom.QRdirname,flnm);
669 while ((fgets(buf,256,fd)!=NULL)
670 &&(strlen(comment)==0)) {
671 buf[strlen(buf)-1] = 0;
672 if ((!struncmp(buf,flnm,strlen(flnm)))
673 && (buf[strlen(flnm)]==' '))
675 &buf[strlen(flnm)+1],255);
677 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
688 * get room parameters (aide or room aide command)
690 void cmd_getr(void) {
691 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
692 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
696 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
697 cprintf("%d Higher access required.\n",
698 ERROR+HIGHER_ACCESS_REQUIRED);
702 if (CC->curr_rm < 3) {
703 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
707 getroom(&CC->quickroom,CC->curr_rm);
708 cprintf("%d%c%s|%s|%s|%d|%d\n",
710 CC->quickroom.QRname,
711 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
712 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
713 CC->quickroom.QRflags,
714 (int)CC->quickroom.QRfloor);
719 * set room parameters (aide or room aide command)
721 void cmd_setr(char *args) {
726 if (!(CC->logged_in)) {
727 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
731 if (!is_room_aide()) {
732 cprintf("%d Higher access required.\n",
733 ERROR+HIGHER_ACCESS_REQUIRED);
737 if (CC->curr_rm < 3) {
738 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
742 if (num_parms(args)>=6) {
743 getfloor(&flbuf,extract_int(args,5));
744 if ((flbuf.f_flags & F_INUSE) == 0) {
745 cprintf("%d Invalid floor number.\n",
746 ERROR+INVALID_FLOOR_OPERATION);
751 lgetroom(&CC->quickroom,CC->curr_rm);
752 extract(buf,args,0); buf[20]=0;
753 strncpy(CC->quickroom.QRname,buf,19);
754 extract(buf,args,1); buf[10]=0;
755 strncpy(CC->quickroom.QRpasswd,buf,9);
756 extract(buf,args,2); buf[15]=0;
757 strncpy(CC->quickroom.QRdirname,buf,19);
758 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
760 /* Clean up a client boo-boo: if the client set the room to
761 * guess-name or passworded, ensure that the private flag is
764 if ((CC->quickroom.QRflags & QR_GUESSNAME)
765 ||(CC->quickroom.QRflags & QR_PASSWORDED))
766 CC->quickroom.QRflags |= QR_PRIVATE;
768 /* Kick everyone out if the client requested it */
769 if (extract_int(args,4)) {
770 ++CC->quickroom.QRgen;
771 if (CC->quickroom.QRgen==100) CC->quickroom.QRgen=1;
774 old_floor = CC->quickroom.QRfloor;
775 if (num_parms(args)>=6) {
776 CC->quickroom.QRfloor = extract_int(args,5);
779 lputroom(&CC->quickroom,CC->curr_rm);
781 /* adjust the floor reference counts */
782 lgetfloor(&flbuf,old_floor);
784 lputfloor(&flbuf,old_floor);
785 lgetfloor(&flbuf,CC->quickroom.QRfloor);
787 lputfloor(&flbuf,CC->quickroom.QRfloor);
789 /* create a room directory if necessary */
790 if (CC->quickroom.QRflags & QR_DIRECTORY) {
792 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
793 CC->quickroom.QRdirname);
797 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
799 cprintf("%d Ok\n",OK);
805 * get the name of the room aide for this room
807 void cmd_geta(void) {
808 struct usersupp usbuf;
810 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
811 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
815 if (CC->curr_rm < 0) {
816 cprintf("%d No current room.\n",ERROR);
820 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
821 cprintf("%d %s\n",OK,usbuf.fullname);
830 * set the room aide for this room
832 void cmd_seta(char *new_ra)
834 struct usersupp usbuf;
839 if (!(CC->logged_in)) {
840 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
844 if (!is_room_aide()) {
845 cprintf("%d Higher access required.\n",
846 ERROR+HIGHER_ACCESS_REQUIRED);
850 if (CC->curr_rm < 3) {
851 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
855 if (getuser(&usbuf,new_ra)!=0) {
859 newu = usbuf.usernum;
862 lgetroom(&CC->quickroom,CC->curr_rm);
864 if (CC->quickroom.QRroomaide != newu) {
867 CC->quickroom.QRroomaide = newu;
868 lputroom(&CC->quickroom,CC->curr_rm);
871 * We have to post the change notice _after_ writing changes to
872 * the room table, otherwise it would deadlock!
874 if (post_notice == 1) {
875 sprintf(buf,"%s is now room aide for %s>",
876 usbuf.fullname,CC->quickroom.QRname);
879 cprintf("%d Ok\n",OK);
884 * retrieve info file for this room
886 void cmd_rinf(void) {
891 sprintf(filename,"./info/%d",CC->curr_rm);
892 info_fp = fopen(filename,"r");
895 cprintf("%d No info file.\n",ERROR);
899 cprintf("%d Info:\n",LISTING_FOLLOWS);
900 while (fgets(buf, 256, info_fp) != NULL) {
901 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
902 cprintf("%s\n", buf);
909 * aide command: kill the current room
911 void cmd_kill(char *argbuf)
917 struct fullroom frbuf;
919 kill_ok = extract_int(argbuf,0);
921 if (!(CC->logged_in)) {
922 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
926 if (!is_room_aide()) {
927 cprintf("%d Higher access required.\n",
928 ERROR+HIGHER_ACCESS_REQUIRED);
932 if (CC->curr_rm < 3) {
933 cprintf("%d Can't kill this room.\n",ERROR+NOT_HERE);
939 /* first flag the room record as not in use */
940 lgetroom(&CC->quickroom,CC->curr_rm);
941 CC->quickroom.QRflags=0;
943 /* then delete the messages in the room */
944 get_fullroom(&frbuf, CC->curr_rm);
945 for (a=0; a<MSGSPERRM; ++a) {
946 cdb_delete(CDB_MSGMAIN, &frbuf.FRnum[a], sizeof(long));
948 put_fullroom(&frbuf, CC->curr_rm);
950 lputroom(&CC->quickroom,CC->curr_rm);
953 /* then decrement the reference count for the floor */
954 lgetfloor(&flbuf,(int)CC->quickroom.QRfloor);
955 flbuf.f_ref_count = flbuf.f_ref_count - 1;
956 lputfloor(&flbuf,(int)CC->quickroom.QRfloor);
958 /* tell the world what we did */
959 sprintf(aaa,"%s> killed by %s",CC->quickroom.QRname,CC->curr_user);
962 cprintf("%d '%s' deleted.\n",OK,CC->quickroom.QRname);
965 cprintf("%d ok to delete.\n",OK);
971 * Find a free slot to create a new room in, or return -1 for error.
972 * search_dir is the direction to search in. 1 causes this function to
973 * return the first available slot, -1 gets the last available slot.
975 int get_free_room_slot(int search_dir)
978 struct quickroom qrbuf;
980 st = ((search_dir>0) ? 3 : (MAXROOMS-1));
982 for (a=st; ((a<MAXROOMS)&&(a>=3)); a=a+search_dir) {
984 if ((qrbuf.QRflags & QR_INUSE)==0) return(a);
991 * internal code to create a new room (returns room flags)
993 unsigned create_room(int free_slot, char *new_room_name, int new_room_type, char *new_room_pass, int new_room_floor)
995 struct quickroom qrbuf;
996 struct fullroom frbuf;
1000 lgetroom(&qrbuf,free_slot);
1001 strncpy(qrbuf.QRname,new_room_name,19);
1002 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1003 qrbuf.QRflags = QR_INUSE;
1004 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1005 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1006 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1007 qrbuf.QRroomaide = (-1L);
1008 if ((new_room_type > 0)&&(CREATAIDE==1))
1009 qrbuf.QRroomaide=CC->usersupp.usernum;
1010 qrbuf.QRhighest = 0L;
1011 ++qrbuf.QRgen; if (qrbuf.QRgen>=126) qrbuf.QRgen=10;
1012 qrbuf.QRfloor = new_room_floor;
1014 /* Initialize a blank fullroom structure */
1015 get_fullroom(&frbuf,free_slot);
1016 for (a=0; a<MSGSPERRM; ++a) {
1019 put_fullroom(&frbuf,free_slot);
1021 /* save what we just did... */
1022 lputroom(&qrbuf,free_slot);
1024 /* bump the reference count on whatever floor the room is on */
1025 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1026 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1027 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1029 /* be sure not to kick the creator out of the room! */
1030 lgetuser(&CC->usersupp,CC->curr_user);
1031 CC->usersupp.generation[free_slot] = qrbuf.QRgen;
1032 CC->usersupp.forget[free_slot] = (-1);
1033 lputuser(&CC->usersupp,CC->curr_user);
1035 /* resume our happy day */
1036 return(qrbuf.QRflags);
1043 void cmd_cre8(char *args)
1048 char new_room_name[256];
1050 char new_room_pass[256];
1054 struct quickroom qrbuf;
1057 cre8_ok = extract_int(args,0);
1058 extract(new_room_name,args,1);
1059 new_room_name[19] = 0;
1060 new_room_type = extract_int(args,2);
1061 extract(new_room_pass,args,3);
1062 new_room_pass[9] = 0;
1065 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1066 cprintf("%d Invalid room name.\n",ERROR);
1070 if (num_parms(args)>=5) {
1071 getfloor(&flbuf,extract_int(args,4));
1072 if ((flbuf.f_flags & F_INUSE) == 0) {
1073 cprintf("%d Invalid floor number.\n",
1074 ERROR+INVALID_FLOOR_OPERATION);
1078 new_room_floor = extract_int(args,4);
1082 if (!(CC->logged_in)) {
1083 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1087 if (CC->usersupp.axlevel<3) {
1088 cprintf("%d You need higher access to create rooms.\n",
1089 ERROR+HIGHER_ACCESS_REQUIRED);
1093 free_slot = get_free_room_slot(1);
1095 cprintf("%d There is no space available for a new room.\n",
1101 cprintf("%d ok to create...\n",OK);
1105 for (a=0; a<MAXROOMS; ++a) {
1107 if ( (!strucmp(qrbuf.QRname,new_room_name))
1108 && (qrbuf.QRflags & QR_INUSE) ) {
1109 cprintf("%d '%s' already exists.\n",
1110 ERROR,qrbuf.QRname);
1115 if ((new_room_type < 0) || (new_room_type > 3)) {
1116 cprintf("%d Invalid room type.\n",ERROR);
1120 newflags = create_room(free_slot,new_room_name,
1121 new_room_type,new_room_pass,new_room_floor);
1123 /* post a message in Aide> describing the new room */
1124 strncpy(aaa,new_room_name,255);
1125 strcat(aaa,"> created by ");
1126 strcat(aaa,CC->usersupp.fullname);
1127 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1128 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1129 if (newflags&QR_PASSWORDED) {
1130 strcat(aaa,"\n Password: ");
1131 strcat(aaa,new_room_pass);
1135 sprintf(aaa,"./info/%d",free_slot); /* delete old info file */
1137 sprintf(aaa,"./images/room.%d.gif",free_slot); /* and picture */
1140 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1145 void cmd_einf(char *ok)
1146 { /* enter info file for current room */
1148 char infofilename[32];
1151 if (!(CC->logged_in)) {
1152 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1156 if (!is_room_aide()) {
1157 cprintf("%d Higher access required.\n",
1158 ERROR+HIGHER_ACCESS_REQUIRED);
1163 cprintf("%d Ok.\n",OK);
1167 cprintf("%d Send info...\n",SEND_LISTING);
1169 sprintf(infofilename,"./info/%d",CC->curr_rm);
1171 fp=fopen(infofilename,"w");
1174 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1175 } while(strcmp(buf,"000"));
1178 /* now update the room index so people will see our new info */
1179 lgetroom(&CC->quickroom,CC->curr_rm); /* lock so no one steps on us */
1180 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1181 lputroom(&CC->quickroom,CC->curr_rm);
1186 * cmd_lflr() - List all known floors
1188 void cmd_lflr(void) {
1192 if (!(CC->logged_in)) {
1193 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1197 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1198 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1203 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1205 for (a=0; a<MAXFLOORS; ++a) {
1207 if (flbuf.f_flags & F_INUSE) {
1208 cprintf("%d|%s|%d\n",
1220 * create a new floor
1222 void cmd_cflr(char *argbuf)
1224 char new_floor_name[256];
1227 int free_slot = (-1);
1230 extract(new_floor_name,argbuf,0);
1231 cflr_ok = extract_int(argbuf,1);
1234 if (!(CC->logged_in)) {
1235 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1239 if (CC->usersupp.axlevel<6) {
1240 cprintf("%d You need higher access to create rooms.\n",
1241 ERROR+HIGHER_ACCESS_REQUIRED);
1245 for (a=0; a<MAXFLOORS; ++a) {
1248 /* note any free slots while we're scanning... */
1249 if ( ((flbuf.f_flags & F_INUSE)==0)
1250 && (free_slot < 0) ) free_slot = a;
1252 /* check to see if it already exists */
1253 if ( (!strucmp(flbuf.f_name,new_floor_name))
1254 && (flbuf.f_flags & F_INUSE) ) {
1255 cprintf("%d Floor '%s' already exists.\n",
1256 ERROR+ALREADY_EXISTS,
1264 cprintf("%d There is no space available for a new floor.\n",
1265 ERROR+INVALID_FLOOR_OPERATION);
1270 cprintf("%d ok to create...\n",OK);
1274 lgetfloor(&flbuf,free_slot);
1275 flbuf.f_flags = F_INUSE;
1276 flbuf.f_ref_count = 0;
1277 strncpy(flbuf.f_name,new_floor_name,255);
1278 lputfloor(&flbuf,free_slot);
1279 cprintf("%d %d\n",OK,free_slot);
1287 void cmd_kflr(char *argbuf)
1290 int floor_to_delete;
1294 floor_to_delete = extract_int(argbuf,0);
1295 kflr_ok = extract_int(argbuf,1);
1298 if (!(CC->logged_in)) {
1299 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1303 if (CC->usersupp.axlevel<6) {
1304 cprintf("%d You need higher access to delete floors.\n",
1305 ERROR+HIGHER_ACCESS_REQUIRED);
1309 lgetfloor(&flbuf,floor_to_delete);
1312 if ((flbuf.f_flags & F_INUSE) == 0) {
1313 cprintf("%d Floor %d not in use.\n",
1314 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1319 if (flbuf.f_ref_count != 0) {
1320 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1321 ERROR+INVALID_FLOOR_OPERATION,
1328 cprintf("%d Ok\n",OK);
1331 cprintf("%d Ok to delete...\n",OK);
1338 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1339 lputfloor(&flbuf,floor_to_delete);
1345 void cmd_eflr(char *argbuf)
1351 np = num_parms(argbuf);
1353 cprintf("%d Usage error.\n",ERROR);
1357 if (!(CC->logged_in)) {
1358 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1362 if (CC->usersupp.axlevel<6) {
1363 cprintf("%d You need higher access to edit floors.\n",
1364 ERROR+HIGHER_ACCESS_REQUIRED);
1368 floor_num = extract_int(argbuf,0);
1369 lgetfloor(&flbuf,floor_num);
1370 if ( (flbuf.f_flags & F_INUSE) == 0) {
1371 lputfloor(&flbuf,floor_num);
1372 cprintf("%d Floor %d is not in use.\n",
1373 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1376 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1377 lputfloor(&flbuf,floor_num);
1379 cprintf("%d Ok\n",OK);