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);
24 /* for regular rooms, check the permissions */
25 if ((roombuf->QRflags & QR_INUSE)
26 && ( (roomnum!=2) || (userbuf->axlevel>=6))
27 && (roombuf->QRgen != (userbuf->forget[roomnum]) )
29 && ( ((roombuf->QRflags&QR_PREFONLY)==0)
30 || ((userbuf->axlevel)>=5)
33 && ( ((roombuf->QRflags&QR_PRIVATE)==0)
34 || ((userbuf->axlevel)>=6)
35 || (roombuf->QRgen==(userbuf->generation[roomnum]))
44 * has_newmsgs() - returns nonzero if room has new messages
46 int has_newmsgs(struct quickroom *roombuf, int roomnum, struct usersupp *userbuf)
48 if (roombuf->QRhighest > (userbuf->lastseen[roomnum]) )
54 * is_zapped() - returns nonzero if room is on forgotten rooms list
56 int is_zapped(struct quickroom *roombuf, int roomnum, struct usersupp *userbuf)
58 if ((roombuf->QRflags & QR_INUSE)
59 && (roombuf->QRgen == (userbuf->forget[roomnum]) )
60 && ( (roomnum!=2) || ((userbuf->axlevel)>=6))
61 && ( ((roombuf->QRflags&QR_PRIVATE)==0)
62 || ((userbuf->axlevel)>=6)
63 || (roombuf->QRgen==(userbuf->generation[roomnum]))
70 * getroom() - retrieve room data from disk
72 void getroom(struct quickroom *qrbuf, int room_num)
74 struct cdbdata *cdbqr;
77 bzero(qrbuf, sizeof(struct quickroom));
78 cdbqr = cdb_fetch(CDB_QUICKROOM, &room_num, sizeof(int));
80 memcpy(qrbuf, cdbqr->ptr, cdbqr->len);
85 qrbuf->QRflags = QR_INUSE;
88 case 0: strcpy(qrbuf->QRname, "Lobby");
90 case 1: strcpy(qrbuf->QRname, "Mail");
92 case 2: strcpy(qrbuf->QRname, "Aide");
99 /** FIX ** VILE SLEAZY HACK ALERT!!
100 * This is a temporary fix until I can track down where room names
101 * are getting corrupted on some systems.
103 for (a=0; a<20; ++a) if (qrbuf->QRname[a] < 32) qrbuf->QRname[a] = 0;
104 qrbuf->QRname[19] = 0;
108 * lgetroom() - same as getroom() but locks the record (if supported)
110 void lgetroom(struct quickroom *qrbuf, int room_num)
112 begin_critical_section(S_QUICKROOM);
113 getroom(qrbuf,room_num);
118 * putroom() - store room data on disk
120 void putroom(struct quickroom *qrbuf, int room_num)
123 cdb_store(CDB_QUICKROOM, &room_num, sizeof(int),
124 qrbuf, sizeof(struct quickroom));
129 * lputroom() - same as putroom() but unlocks the record (if supported)
131 void lputroom(struct quickroom *qrbuf, int room_num)
134 putroom(qrbuf,room_num);
135 end_critical_section(S_QUICKROOM);
141 * getfloor() - retrieve floor data from disk
143 void getfloor(struct floor *flbuf, int floor_num)
145 struct cdbdata *cdbfl;
147 bzero(flbuf, sizeof(struct floor));
148 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
150 memcpy(flbuf, cdbfl->ptr, cdbfl->len);
154 if (floor_num == 0) {
155 strcpy(flbuf->f_name, "Main Floor");
156 flbuf->f_flags = F_INUSE;
157 flbuf->f_ref_count = 3;
164 * lgetfloor() - same as getfloor() but locks the record (if supported)
166 void lgetfloor(struct floor *flbuf, int floor_num)
169 begin_critical_section(S_FLOORTAB);
170 getfloor(flbuf,floor_num);
175 * putfloor() - store floor data on disk
177 void putfloor(struct floor *flbuf, int floor_num)
179 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
180 flbuf, sizeof(struct floor));
185 * lputfloor() - same as putfloor() but unlocks the record (if supported)
187 void lputfloor(struct floor *flbuf, int floor_num)
190 putfloor(flbuf,floor_num);
191 end_critical_section(S_FLOORTAB);
198 * get_msglist() - retrieve room message pointers
200 void get_msglist(int room_num)
202 struct cdbdata *cdbfr;
204 if (CC->msglist != NULL) {
211 cdbfr = cdb_fetch(CDB_MSGLISTS, &room_num, sizeof(int));
214 cdbfr = cdb_fetch(CDB_MAILBOXES, &CC->usersupp.usernum,
222 CC->msglist = malloc(cdbfr->len);
223 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
224 CC->num_msgs = cdbfr->len / sizeof(long);
230 * put_msglist() - retrieve room message pointers
232 void put_msglist(int room_num)
236 cdb_store(CDB_MSGLISTS, &room_num, sizeof(int),
237 CC->msglist, (CC->num_msgs * sizeof(long)) );
240 cdb_store(CDB_MAILBOXES, &CC->usersupp.usernum, sizeof(long),
241 CC->msglist, (CC->num_msgs * sizeof(long)) );
247 * MessageFromList() - get a message number from the list currently in memory
249 long MessageFromList(int whichpos) {
251 /* Return zero if the position is invalid */
252 if (whichpos >= CC->num_msgs) return 0L;
254 return(CC->msglist[whichpos]);
258 * SetMessageInList() - set a message number in the list currently in memory
260 void SetMessageInList(int whichpos, long newmsgnum) {
262 /* Return zero if the position is invalid */
263 if (whichpos >= CC->num_msgs) return;
265 CC->msglist[whichpos] = newmsgnum;
271 * sort message pointers
272 * (returns new msg count)
274 int sort_msglist(long listptrs[], int oldcount)
281 if (numitems < 2) return(oldcount);
284 for (a=numitems-2; a>=0; --a) {
285 for (b=0; b<=a; ++b) {
286 if (listptrs[b] > (listptrs[b+1])) {
288 hold2 = listptrs[b+1];
290 listptrs[b+1] = hold1;
295 /* and yank any nulls */
296 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
297 memcpy(&listptrs[0], &listptrs[1],
298 (sizeof(long) * (CC->num_msgs - 1)) );
309 * cmd_lrms() - List all accessible rooms, known or forgotten
311 void cmd_lrms(char *argbuf)
314 int target_floor = (-1);
315 struct quickroom qrbuf;
317 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
319 if (!(CC->logged_in)) {
320 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
324 if (getuser(&CC->usersupp,CC->curr_user)) {
325 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
329 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
331 for (a=0; a<MAXROOMS; ++a) {
333 if ( ( (is_known(&qrbuf,a,&CC->usersupp))
334 || (is_zapped(&qrbuf,a,&CC->usersupp)) )
335 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) )
336 cprintf("%s|%u|%d\n",
337 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
343 * cmd_lkra() - List all known rooms
345 void cmd_lkra(char *argbuf)
348 struct quickroom qrbuf;
349 int target_floor = (-1);
351 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
353 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
354 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
358 if (!(CC->internal_pgm)) if (getuser(&CC->usersupp,CC->curr_user)) {
359 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
363 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
365 for (a=0; a<MAXROOMS; ++a) {
367 if ((is_known(&qrbuf,a,&CC->usersupp))
368 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) )
369 cprintf("%s|%u|%d\n",
370 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
376 * cmd_lkrn() - List Known Rooms with New messages
378 void cmd_lkrn(char *argbuf)
381 struct quickroom qrbuf;
382 int target_floor = (-1);
384 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
386 if (!(CC->logged_in)) {
387 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
391 if (getuser(&CC->usersupp,CC->curr_user)) {
392 cprintf("%d can't locate user\n",ERROR+INTERNAL_ERROR);
396 cprintf("%d list of rms w/ new msgs\n",LISTING_FOLLOWS);
398 for (a=0; a<MAXROOMS; ++a) {
400 if ( ( (is_known(&qrbuf,a,&CC->usersupp))
401 && (has_newmsgs(&qrbuf,a,&CC->usersupp)) )
402 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) )
403 cprintf("%s|%u|%d\n",
404 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
410 * cmd_lkro() - List Known Rooms with Old (no new) messages
412 void cmd_lkro(char *argbuf)
415 struct quickroom qrbuf;
416 int target_floor = (-1);
418 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
420 if (!(CC->logged_in)) {
421 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
425 if (getuser(&CC->usersupp,CC->curr_user)) {
426 cprintf("%d can't locate user\n",ERROR+INTERNAL_ERROR);
430 cprintf("%d list of rms w/o new msgs\n",LISTING_FOLLOWS);
432 for (a=0; a<MAXROOMS; ++a) {
434 if ( ( (is_known(&qrbuf,a,&CC->usersupp))
435 && (!has_newmsgs(&qrbuf,a,&CC->usersupp)) )
436 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) ) {
437 if (!strcmp(qrbuf.QRname,"000")) cprintf(">");
438 cprintf("%s|%u|%d\n",
439 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
446 * cmd_lzrm() - List Zapped RooMs
448 void cmd_lzrm(char *argbuf)
451 struct quickroom qrbuf;
452 int target_floor = (-1);
454 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
456 if (!(CC->logged_in)) {
457 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
461 if (getuser(&CC->usersupp,CC->curr_user)) {
462 cprintf("%d can't locate user\n",ERROR+INTERNAL_ERROR);
466 cprintf("%d list of forgotten rms\n",LISTING_FOLLOWS);
468 for (a=0; a<MAXROOMS; ++a) {
470 if ( (is_zapped(&qrbuf,a,&CC->usersupp))
471 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) ) {
472 if (!strcmp(qrbuf.QRname,"000")) cprintf(">");
473 cprintf("%s|%u|%d\n",
474 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
482 void usergoto(int where, int display_result)
488 int newmailcount = 0;
489 struct cdbdata *cdbmb;
494 getroom(&CC->quickroom,CC->curr_rm);
495 lgetuser(&CC->usersupp,CC->curr_user);
496 CC->usersupp.forget[CC->curr_rm]=(-1);
497 CC->usersupp.generation[CC->curr_rm]=CC->quickroom.QRgen;
498 lputuser(&CC->usersupp,CC->curr_user);
500 /* check for new mail */
503 cdbmb = cdb_fetch(CDB_MAILBOXES, &CC->usersupp.usernum, sizeof(long));
505 num_mails = cdbmb->len / sizeof(long);
506 mailbox = (long *) cdbmb->ptr;
507 if (num_mails > 0) for (a=0; a<num_mails; ++a) {
508 if (mailbox[a] > (CC->usersupp.lastseen[1]))
514 /* set info to 1 if the user needs to read the room's info file */
515 if (CC->quickroom.QRinfo > CC->usersupp.lastseen[CC->curr_rm]) info = 1;
519 get_msglist(CC->curr_rm);
520 for (a=0; a<CC->num_msgs; ++a) {
521 if (MessageFromList(a)>0L) {
523 if (MessageFromList(a)
524 > CC->usersupp.lastseen[CC->curr_rm]) ++c;
529 if (CC->curr_rm == 1) rmailflag = 1;
532 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
533 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
536 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
538 CC->quickroom.QRname,c,b,info,CC->quickroom.QRflags,
539 CC->quickroom.QRhighest,CC->usersupp.lastseen[CC->curr_rm],
540 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
541 if (CC->quickroom.QRflags & QR_PRIVATE) {
542 set_wtmpsupp("<private room>");
545 set_wtmpsupp(CC->quickroom.QRname);
551 * cmd_goto() - goto a new room
553 void cmd_goto(char *gargs)
555 struct quickroom QRscratch;
558 char bbb[20],towhere[32],password[20];
560 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
561 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
565 extract(towhere,gargs,0);
566 extract(password,gargs,1);
569 getuser(&CC->usersupp,CC->curr_user);
570 for (a=0; a<MAXROOMS; ++a) {
571 getroom(&QRscratch,a);
572 if ((a==0)&&(!strcasecmp(towhere,"_BASEROOM_"))) {
573 strncpy(towhere,QRscratch.QRname,31);
575 if ((a==1)&&(!strcasecmp(towhere,"_MAIL_"))) {
576 strncpy(towhere,QRscratch.QRname,31);
578 if ((!strcasecmp(QRscratch.QRname,config.c_twitroom))
579 &&(!strcasecmp(towhere,"_BITBUCKET_"))) {
580 strncpy(towhere,QRscratch.QRname,31);
582 strcpy(bbb,QRscratch.QRname);
585 /* let internal programs go directly to any room */
586 if (((CC->internal_pgm))&&(!strcasecmp(bbb,towhere))) {
591 /* normal clients have to pass through security */
593 (strcasecmp(bbb,towhere)==0)
594 && ((QRscratch.QRflags&QR_INUSE)!=0)
596 && ( ((QRscratch.QRflags&QR_PREFONLY)==0)
597 || (CC->usersupp.axlevel>=5)
600 && ( (a!=2) || (CC->usersupp.axlevel>=6) )
602 && ( ((QRscratch.QRflags&QR_PRIVATE)==0)
603 || (QRscratch.QRflags&QR_GUESSNAME)
604 || (CC->usersupp.axlevel>=6)
605 || (QRscratch.QRflags&QR_PASSWORDED)
606 || (QRscratch.QRgen==CC->usersupp.generation[a])
614 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
615 (CC->usersupp.axlevel<6) &&
616 (QRscratch.QRgen!=CC->usersupp.generation[a]) &&
617 (strcasecmp(QRscratch.QRpasswd,password))
619 cprintf("%d wrong or missing passwd\n",
620 ERROR+PASSWORD_REQUIRED);
629 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
633 void cmd_whok(void) {
634 struct usersupp temp;
635 struct cdbdata *cdbus;
637 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
638 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
641 getuser(&CC->usersupp,CC->curr_user);
643 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
644 cprintf("%d Higher access required.\n",
645 ERROR+HIGHER_ACCESS_REQUIRED);
649 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
650 cdb_rewind(CDB_USERSUPP);
651 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
652 bzero(&temp, sizeof(struct usersupp));
653 memcpy(&temp, cdbus->ptr, cdbus->len);
655 if ((CC->quickroom.QRflags & QR_INUSE)
656 && ( (CC->curr_rm!=2) || (temp.axlevel>=6) )
657 && (CC->quickroom.QRgen != (temp.forget[CC->curr_rm]) )
659 && ( ((CC->quickroom.QRflags&QR_PREFONLY)==0)
663 && ( ((CC->quickroom.QRflags&QR_PRIVATE)==0)
665 || (CC->quickroom.QRgen==(temp.generation[CC->curr_rm]))
668 && (strncmp(temp.fullname,"000",3))
670 ) cprintf("%s\n",temp.fullname);
677 * RDIR command for room directory
679 void cmd_rdir(void) {
686 if (!(CC->logged_in)) {
687 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
691 getroom(&CC->quickroom,CC->curr_rm);
692 getuser(&CC->usersupp,CC->curr_user);
694 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
695 cprintf("%d not here.\n",ERROR+NOT_HERE);
699 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
700 && (CC->usersupp.axlevel<6)
701 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
702 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
706 cprintf("%d %s|%s/files/%s\n",
707 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
709 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
710 BBSDIR,CC->quickroom.QRdirname,CC->temp);
713 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
715 if (fd==NULL) fd=fopen("/dev/null","r");
717 ls = fopen(CC->temp,"r");
718 while (fgets(flnm,256,ls)!=NULL) {
719 flnm[strlen(flnm)-1]=0;
720 if (strcasecmp(flnm,"filedir")) {
721 sprintf(buf,"%s/files/%s/%s",
722 BBSDIR,CC->quickroom.QRdirname,flnm);
726 while ((fgets(buf,256,fd)!=NULL)
727 &&(strlen(comment)==0)) {
728 buf[strlen(buf)-1] = 0;
729 if ((!strncasecmp(buf,flnm,strlen(flnm)))
730 && (buf[strlen(flnm)]==' '))
732 &buf[strlen(flnm)+1],255);
734 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
745 * get room parameters (aide or room aide command)
747 void cmd_getr(void) {
748 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
749 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
753 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
754 cprintf("%d Higher access required.\n",
755 ERROR+HIGHER_ACCESS_REQUIRED);
759 if (CC->curr_rm < 3) {
760 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
764 getroom(&CC->quickroom,CC->curr_rm);
765 cprintf("%d%c%s|%s|%s|%d|%d\n",
767 CC->quickroom.QRname,
768 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
769 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
770 CC->quickroom.QRflags,
771 (int)CC->quickroom.QRfloor);
776 * set room parameters (aide or room aide command)
778 void cmd_setr(char *args) {
783 if (!(CC->logged_in)) {
784 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
788 if (!is_room_aide()) {
789 cprintf("%d Higher access required.\n",
790 ERROR+HIGHER_ACCESS_REQUIRED);
794 if (CC->curr_rm < 3) {
795 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
799 if (num_parms(args)>=6) {
800 getfloor(&flbuf,extract_int(args,5));
801 if ((flbuf.f_flags & F_INUSE) == 0) {
802 cprintf("%d Invalid floor number.\n",
803 ERROR+INVALID_FLOOR_OPERATION);
808 lgetroom(&CC->quickroom,CC->curr_rm);
809 extract(buf,args,0); buf[20]=0;
810 strncpy(CC->quickroom.QRname,buf,19);
811 extract(buf,args,1); buf[10]=0;
812 strncpy(CC->quickroom.QRpasswd,buf,9);
813 extract(buf,args,2); buf[15]=0;
814 strncpy(CC->quickroom.QRdirname,buf,19);
815 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
817 /* Clean up a client boo-boo: if the client set the room to
818 * guess-name or passworded, ensure that the private flag is
821 if ((CC->quickroom.QRflags & QR_GUESSNAME)
822 ||(CC->quickroom.QRflags & QR_PASSWORDED))
823 CC->quickroom.QRflags |= QR_PRIVATE;
825 /* Kick everyone out if the client requested it */
826 if (extract_int(args,4)) {
827 ++CC->quickroom.QRgen;
828 if (CC->quickroom.QRgen==100) CC->quickroom.QRgen=1;
831 old_floor = CC->quickroom.QRfloor;
832 if (num_parms(args)>=6) {
833 CC->quickroom.QRfloor = extract_int(args,5);
836 lputroom(&CC->quickroom,CC->curr_rm);
838 /* adjust the floor reference counts */
839 lgetfloor(&flbuf,old_floor);
841 lputfloor(&flbuf,old_floor);
842 lgetfloor(&flbuf,CC->quickroom.QRfloor);
844 lputfloor(&flbuf,CC->quickroom.QRfloor);
846 /* create a room directory if necessary */
847 if (CC->quickroom.QRflags & QR_DIRECTORY) {
849 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
850 CC->quickroom.QRdirname);
854 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
856 cprintf("%d Ok\n",OK);
862 * get the name of the room aide for this room
864 void cmd_geta(void) {
865 struct usersupp usbuf;
867 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
868 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
872 if (CC->curr_rm < 0) {
873 cprintf("%d No current room.\n",ERROR);
877 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
878 cprintf("%d %s\n",OK,usbuf.fullname);
887 * set the room aide for this room
889 void cmd_seta(char *new_ra)
891 struct usersupp usbuf;
896 if (!(CC->logged_in)) {
897 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
901 if (!is_room_aide()) {
902 cprintf("%d Higher access required.\n",
903 ERROR+HIGHER_ACCESS_REQUIRED);
907 if (CC->curr_rm < 3) {
908 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
912 if (getuser(&usbuf,new_ra)!=0) {
916 newu = usbuf.usernum;
919 lgetroom(&CC->quickroom,CC->curr_rm);
921 if (CC->quickroom.QRroomaide != newu) {
924 CC->quickroom.QRroomaide = newu;
925 lputroom(&CC->quickroom,CC->curr_rm);
928 * We have to post the change notice _after_ writing changes to
929 * the room table, otherwise it would deadlock!
931 if (post_notice == 1) {
932 sprintf(buf,"%s is now room aide for %s>",
933 usbuf.fullname,CC->quickroom.QRname);
936 cprintf("%d Ok\n",OK);
941 * retrieve info file for this room
943 void cmd_rinf(void) {
948 sprintf(filename,"./info/%d",CC->curr_rm);
949 info_fp = fopen(filename,"r");
952 cprintf("%d No info file.\n",ERROR);
956 cprintf("%d Info:\n",LISTING_FOLLOWS);
957 while (fgets(buf, 256, info_fp) != NULL) {
958 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
959 cprintf("%s\n", buf);
966 * aide command: kill the current room
968 void cmd_kill(char *argbuf)
976 kill_ok = extract_int(argbuf,0);
978 if (!(CC->logged_in)) {
979 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
983 if (!is_room_aide()) {
984 cprintf("%d Higher access required.\n",
985 ERROR+HIGHER_ACCESS_REQUIRED);
989 if (CC->curr_rm < 3) {
990 cprintf("%d Can't kill this room.\n",ERROR+NOT_HERE);
996 /* first flag the room record as not in use */
997 lgetroom(&CC->quickroom,CC->curr_rm);
998 CC->quickroom.QRflags=0;
1000 /* then delete the messages in the room */
1001 get_msglist(CC->curr_rm);
1002 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1003 MsgToDelete = MessageFromList(a);
1004 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1006 put_msglist(CC->curr_rm);
1009 cdb_delete(CDB_MSGLISTS, &CC->curr_rm, sizeof(int));
1011 lputroom(&CC->quickroom,CC->curr_rm);
1014 /* then decrement the reference count for the floor */
1015 lgetfloor(&flbuf,(int)CC->quickroom.QRfloor);
1016 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1017 lputfloor(&flbuf,(int)CC->quickroom.QRfloor);
1019 /* tell the world what we did */
1020 sprintf(aaa,"%s> killed by %s",CC->quickroom.QRname,CC->curr_user);
1023 cprintf("%d '%s' deleted.\n",OK,CC->quickroom.QRname);
1026 cprintf("%d ok to delete.\n",OK);
1032 * Find a free slot to create a new room in, or return -1 for error.
1033 * search_dir is the direction to search in. 1 causes this function to
1034 * return the first available slot, -1 gets the last available slot.
1036 int get_free_room_slot(int search_dir)
1039 struct quickroom qrbuf;
1041 st = ((search_dir>0) ? 3 : (MAXROOMS-1));
1043 for (a=st; ((a<MAXROOMS)&&(a>=3)); a=a+search_dir) {
1045 if ((qrbuf.QRflags & QR_INUSE)==0) return(a);
1052 * internal code to create a new room (returns room flags)
1054 unsigned create_room(int free_slot, char *new_room_name, int new_room_type, char *new_room_pass, int new_room_floor)
1056 struct quickroom qrbuf;
1059 lgetroom(&qrbuf,free_slot);
1060 strncpy(qrbuf.QRname,new_room_name,19);
1061 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1062 qrbuf.QRflags = QR_INUSE;
1063 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1064 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1065 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1066 qrbuf.QRroomaide = (-1L);
1067 if ((new_room_type > 0)&&(CREATAIDE==1))
1068 qrbuf.QRroomaide=CC->usersupp.usernum;
1069 qrbuf.QRhighest = 0L;
1070 ++qrbuf.QRgen; if (qrbuf.QRgen>=126) qrbuf.QRgen=10;
1071 qrbuf.QRfloor = new_room_floor;
1073 /* save what we just did... */
1074 lputroom(&qrbuf,free_slot);
1076 /* bump the reference count on whatever floor the room is on */
1077 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1078 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1079 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1081 /* be sure not to kick the creator out of the room! */
1082 lgetuser(&CC->usersupp,CC->curr_user);
1083 CC->usersupp.generation[free_slot] = qrbuf.QRgen;
1084 CC->usersupp.forget[free_slot] = (-1);
1085 lputuser(&CC->usersupp,CC->curr_user);
1087 /* resume our happy day */
1088 return(qrbuf.QRflags);
1095 void cmd_cre8(char *args)
1100 char new_room_name[256];
1102 char new_room_pass[256];
1106 struct quickroom qrbuf;
1109 cre8_ok = extract_int(args,0);
1110 extract(new_room_name,args,1);
1111 new_room_name[19] = 0;
1112 new_room_type = extract_int(args,2);
1113 extract(new_room_pass,args,3);
1114 new_room_pass[9] = 0;
1117 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1118 cprintf("%d Invalid room name.\n",ERROR);
1122 if (num_parms(args)>=5) {
1123 getfloor(&flbuf,extract_int(args,4));
1124 if ((flbuf.f_flags & F_INUSE) == 0) {
1125 cprintf("%d Invalid floor number.\n",
1126 ERROR+INVALID_FLOOR_OPERATION);
1130 new_room_floor = extract_int(args,4);
1134 if (!(CC->logged_in)) {
1135 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1139 if (CC->usersupp.axlevel<3) {
1140 cprintf("%d You need higher access to create rooms.\n",
1141 ERROR+HIGHER_ACCESS_REQUIRED);
1145 free_slot = get_free_room_slot(1);
1147 cprintf("%d There is no space available for a new room.\n",
1153 cprintf("%d ok to create...\n",OK);
1157 for (a=0; a<MAXROOMS; ++a) {
1159 if ( (!strcasecmp(qrbuf.QRname,new_room_name))
1160 && (qrbuf.QRflags & QR_INUSE) ) {
1161 cprintf("%d '%s' already exists.\n",
1162 ERROR,qrbuf.QRname);
1167 if ((new_room_type < 0) || (new_room_type > 3)) {
1168 cprintf("%d Invalid room type.\n",ERROR);
1172 newflags = create_room(free_slot,new_room_name,
1173 new_room_type,new_room_pass,new_room_floor);
1175 /* post a message in Aide> describing the new room */
1176 strncpy(aaa,new_room_name,255);
1177 strcat(aaa,"> created by ");
1178 strcat(aaa,CC->usersupp.fullname);
1179 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1180 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1181 if (newflags&QR_PASSWORDED) {
1182 strcat(aaa,"\n Password: ");
1183 strcat(aaa,new_room_pass);
1187 sprintf(aaa,"./info/%d",free_slot); /* delete old info file */
1189 sprintf(aaa,"./images/room.%d.gif",free_slot); /* and picture */
1192 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1197 void cmd_einf(char *ok)
1198 { /* enter info file for current room */
1200 char infofilename[32];
1203 if (!(CC->logged_in)) {
1204 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1208 if (!is_room_aide()) {
1209 cprintf("%d Higher access required.\n",
1210 ERROR+HIGHER_ACCESS_REQUIRED);
1215 cprintf("%d Ok.\n",OK);
1219 cprintf("%d Send info...\n",SEND_LISTING);
1221 sprintf(infofilename,"./info/%d",CC->curr_rm);
1223 fp=fopen(infofilename,"w");
1226 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1227 } while(strcmp(buf,"000"));
1230 /* now update the room index so people will see our new info */
1231 lgetroom(&CC->quickroom,CC->curr_rm); /* lock so no one steps on us */
1232 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1233 lputroom(&CC->quickroom,CC->curr_rm);
1238 * cmd_lflr() - List all known floors
1240 void cmd_lflr(void) {
1244 if (!(CC->logged_in)) {
1245 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1249 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1250 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1255 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1257 for (a=0; a<MAXFLOORS; ++a) {
1259 if (flbuf.f_flags & F_INUSE) {
1260 cprintf("%d|%s|%d\n",
1272 * create a new floor
1274 void cmd_cflr(char *argbuf)
1276 char new_floor_name[256];
1279 int free_slot = (-1);
1282 extract(new_floor_name,argbuf,0);
1283 cflr_ok = extract_int(argbuf,1);
1286 if (!(CC->logged_in)) {
1287 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1291 if (CC->usersupp.axlevel<6) {
1292 cprintf("%d You need higher access to create rooms.\n",
1293 ERROR+HIGHER_ACCESS_REQUIRED);
1297 for (a=0; a<MAXFLOORS; ++a) {
1300 /* note any free slots while we're scanning... */
1301 if ( ((flbuf.f_flags & F_INUSE)==0)
1302 && (free_slot < 0) ) free_slot = a;
1304 /* check to see if it already exists */
1305 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1306 && (flbuf.f_flags & F_INUSE) ) {
1307 cprintf("%d Floor '%s' already exists.\n",
1308 ERROR+ALREADY_EXISTS,
1316 cprintf("%d There is no space available for a new floor.\n",
1317 ERROR+INVALID_FLOOR_OPERATION);
1322 cprintf("%d ok to create...\n",OK);
1326 lgetfloor(&flbuf,free_slot);
1327 flbuf.f_flags = F_INUSE;
1328 flbuf.f_ref_count = 0;
1329 strncpy(flbuf.f_name,new_floor_name,255);
1330 lputfloor(&flbuf,free_slot);
1331 cprintf("%d %d\n",OK,free_slot);
1339 void cmd_kflr(char *argbuf)
1342 int floor_to_delete;
1346 floor_to_delete = extract_int(argbuf,0);
1347 kflr_ok = extract_int(argbuf,1);
1350 if (!(CC->logged_in)) {
1351 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1355 if (CC->usersupp.axlevel<6) {
1356 cprintf("%d You need higher access to delete floors.\n",
1357 ERROR+HIGHER_ACCESS_REQUIRED);
1361 lgetfloor(&flbuf,floor_to_delete);
1364 if ((flbuf.f_flags & F_INUSE) == 0) {
1365 cprintf("%d Floor %d not in use.\n",
1366 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1371 if (flbuf.f_ref_count != 0) {
1372 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1373 ERROR+INVALID_FLOOR_OPERATION,
1380 cprintf("%d Ok\n",OK);
1383 cprintf("%d Ok to delete...\n",OK);
1390 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1391 lputfloor(&flbuf,floor_to_delete);
1397 void cmd_eflr(char *argbuf)
1403 np = num_parms(argbuf);
1405 cprintf("%d Usage error.\n",ERROR);
1409 if (!(CC->logged_in)) {
1410 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1414 if (CC->usersupp.axlevel<6) {
1415 cprintf("%d You need higher access to edit floors.\n",
1416 ERROR+HIGHER_ACCESS_REQUIRED);
1420 floor_num = extract_int(argbuf,0);
1421 lgetfloor(&flbuf,floor_num);
1422 if ( (flbuf.f_flags & F_INUSE) == 0) {
1423 lputfloor(&flbuf,floor_num);
1424 cprintf("%d Floor %d is not in use.\n",
1425 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1428 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1429 lputfloor(&flbuf,floor_num);
1431 cprintf("%d Ok\n",OK);