13 #include "sysdep_decls.h"
17 #include "serv_chat.h"
18 #include "citserver.h"
21 * is_known() - returns nonzero if room is in user's known room list
23 int is_known(struct quickroom *roombuf, int roomnum, struct usersupp *userbuf)
26 /* for internal programs, always succeed */
27 if (((CC->internal_pgm))&&(roombuf->QRflags & QR_INUSE)) return(1);
29 /* for regular rooms, check the permissions */
30 if ((roombuf->QRflags & QR_INUSE)
31 && ( (roomnum!=2) || (userbuf->axlevel>=6))
32 && (roombuf->QRgen != (userbuf->forget[roomnum]) )
34 && ( ((roombuf->QRflags&QR_PREFONLY)==0)
35 || ((userbuf->axlevel)>=5)
38 && ( ((roombuf->QRflags&QR_PRIVATE)==0)
39 || ((userbuf->axlevel)>=6)
40 || (roombuf->QRgen==(userbuf->generation[roomnum]))
49 * has_newmsgs() - returns nonzero if room has new messages
51 int has_newmsgs(struct quickroom *roombuf, int roomnum, struct usersupp *userbuf)
54 return ( (NewMailCount() > 0) ? 1 : 0 );
57 if (roombuf->QRhighest > (userbuf->lastseen[roomnum]) ) {
68 * is_zapped() - returns nonzero if room is on forgotten rooms list
70 int is_zapped(struct quickroom *roombuf, int roomnum, struct usersupp *userbuf)
72 if ((roombuf->QRflags & QR_INUSE)
73 && (roombuf->QRgen == (userbuf->forget[roomnum]) )
74 && ( (roomnum!=2) || ((userbuf->axlevel)>=6))
75 && ( ((roombuf->QRflags&QR_PRIVATE)==0)
76 || ((userbuf->axlevel)>=6)
77 || (roombuf->QRgen==(userbuf->generation[roomnum]))
84 * getroom() - retrieve room data from disk
86 void getroom(struct quickroom *qrbuf, int room_num)
88 struct cdbdata *cdbqr;
91 bzero(qrbuf, sizeof(struct quickroom));
92 cdbqr = cdb_fetch(CDB_QUICKROOM, &room_num, sizeof(int));
94 memcpy(qrbuf, cdbqr->ptr,
95 ( (cdbqr->len > sizeof(struct quickroom)) ?
96 sizeof(struct quickroom) : cdbqr->len) );
101 qrbuf->QRflags = QR_INUSE;
104 case 0: strcpy(qrbuf->QRname, "Lobby");
106 case 1: strcpy(qrbuf->QRname, "Mail");
108 case 2: strcpy(qrbuf->QRname, "Aide");
115 /** FIX ** VILE SLEAZY HACK ALERT!!
116 * This is a temporary fix until we can track down where room names
117 * are getting corrupted on some systems.
119 for (a=0; a<20; ++a) if (qrbuf->QRname[a] < 32) qrbuf->QRname[a] = 0;
120 qrbuf->QRname[19] = 0;
124 * lgetroom() - same as getroom() but locks the record (if supported)
126 void lgetroom(struct quickroom *qrbuf, int room_num)
128 begin_critical_section(S_QUICKROOM);
129 getroom(qrbuf,room_num);
134 * putroom() - store room data on disk
136 void putroom(struct quickroom *qrbuf, int room_num)
138 time(&qrbuf->QRmtime);
139 cdb_store(CDB_QUICKROOM, &room_num, sizeof(int),
140 qrbuf, sizeof(struct quickroom));
145 * lputroom() - same as putroom() but unlocks the record (if supported)
147 void lputroom(struct quickroom *qrbuf, int room_num)
150 putroom(qrbuf,room_num);
151 end_critical_section(S_QUICKROOM);
157 * getfloor() - retrieve floor data from disk
159 void getfloor(struct floor *flbuf, int floor_num)
161 struct cdbdata *cdbfl;
163 bzero(flbuf, sizeof(struct floor));
164 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
166 memcpy(flbuf, cdbfl->ptr,
167 ( (cdbfl->len > sizeof(struct floor)) ?
168 sizeof(struct floor) : cdbfl->len) );
172 if (floor_num == 0) {
173 strcpy(flbuf->f_name, "Main Floor");
174 flbuf->f_flags = F_INUSE;
175 flbuf->f_ref_count = 3;
182 * lgetfloor() - same as getfloor() but locks the record (if supported)
184 void lgetfloor(struct floor *flbuf, int floor_num)
187 begin_critical_section(S_FLOORTAB);
188 getfloor(flbuf,floor_num);
193 * putfloor() - store floor data on disk
195 void putfloor(struct floor *flbuf, int floor_num)
197 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
198 flbuf, sizeof(struct floor));
203 * lputfloor() - same as putfloor() but unlocks the record (if supported)
205 void lputfloor(struct floor *flbuf, int floor_num)
208 putfloor(flbuf,floor_num);
209 end_critical_section(S_FLOORTAB);
216 * get_msglist() - retrieve room message pointers
218 void get_msglist(int room_num)
220 struct cdbdata *cdbfr;
222 if (CC->msglist != NULL) {
229 cdbfr = cdb_fetch(CDB_MSGLISTS, &room_num, sizeof(int));
232 cdbfr = cdb_fetch(CDB_MAILBOXES, &CC->usersupp.usernum,
240 CC->msglist = malloc(cdbfr->len);
241 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
242 CC->num_msgs = cdbfr->len / sizeof(long);
248 * put_msglist() - retrieve room message pointers
250 void put_msglist(int room_num)
254 cdb_store(CDB_MSGLISTS, &room_num, sizeof(int),
255 CC->msglist, (CC->num_msgs * sizeof(long)) );
258 cdb_store(CDB_MAILBOXES, &CC->usersupp.usernum, sizeof(long),
259 CC->msglist, (CC->num_msgs * sizeof(long)) );
265 * MessageFromList() - get a message number from the list currently in memory
267 long MessageFromList(int whichpos) {
269 /* Return zero if the position is invalid */
270 if (whichpos >= CC->num_msgs) return 0L;
272 return(CC->msglist[whichpos]);
276 * SetMessageInList() - set a message number in the list currently in memory
278 void SetMessageInList(int whichpos, long newmsgnum) {
280 /* Return zero if the position is invalid */
281 if (whichpos >= CC->num_msgs) return;
283 CC->msglist[whichpos] = newmsgnum;
289 * sort message pointers
290 * (returns new msg count)
292 int sort_msglist(long listptrs[], int oldcount)
299 if (numitems < 2) return(oldcount);
302 for (a=numitems-2; a>=0; --a) {
303 for (b=0; b<=a; ++b) {
304 if (listptrs[b] > (listptrs[b+1])) {
306 hold2 = listptrs[b+1];
308 listptrs[b+1] = hold1;
313 /* and yank any nulls */
314 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
315 memcpy(&listptrs[0], &listptrs[1],
316 (sizeof(long) * (CC->num_msgs - 1)) );
327 * cmd_lrms() - List all accessible rooms, known or forgotten
329 void cmd_lrms(char *argbuf)
332 int target_floor = (-1);
333 struct quickroom qrbuf;
335 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
337 if (!(CC->logged_in)) {
338 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
342 if (getuser(&CC->usersupp,CC->curr_user)) {
343 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
347 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
349 for (a=0; a<MAXROOMS; ++a) {
351 if ( ( (is_known(&qrbuf,a,&CC->usersupp))
352 || (is_zapped(&qrbuf,a,&CC->usersupp)) )
353 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) )
354 cprintf("%s|%u|%d\n",
355 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
361 * cmd_lkra() - List all known rooms
363 void cmd_lkra(char *argbuf)
366 struct quickroom qrbuf;
367 int target_floor = (-1);
369 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
371 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
372 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
376 if (!(CC->internal_pgm)) if (getuser(&CC->usersupp,CC->curr_user)) {
377 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
381 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
383 for (a=0; a<MAXROOMS; ++a) {
385 if ((is_known(&qrbuf,a,&CC->usersupp))
386 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) )
387 cprintf("%s|%u|%d\n",
388 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
394 * cmd_lkrn() - List Known Rooms with New messages
396 void cmd_lkrn(char *argbuf)
399 struct quickroom qrbuf;
400 int target_floor = (-1);
402 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
404 if (!(CC->logged_in)) {
405 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
409 if (getuser(&CC->usersupp,CC->curr_user)) {
410 cprintf("%d can't locate user\n",ERROR+INTERNAL_ERROR);
414 cprintf("%d list of rms w/ new msgs\n",LISTING_FOLLOWS);
416 for (a=0; a<MAXROOMS; ++a) {
418 if ( ( (is_known(&qrbuf,a,&CC->usersupp))
419 && (has_newmsgs(&qrbuf,a,&CC->usersupp)) )
420 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) )
421 cprintf("%s|%u|%d\n",
422 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
428 * cmd_lkro() - List Known Rooms with Old (no new) messages
430 void cmd_lkro(char *argbuf)
433 struct quickroom qrbuf;
434 int target_floor = (-1);
436 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
438 if (!(CC->logged_in)) {
439 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
443 if (getuser(&CC->usersupp,CC->curr_user)) {
444 cprintf("%d can't locate user\n",ERROR+INTERNAL_ERROR);
448 cprintf("%d list of rms w/o new msgs\n",LISTING_FOLLOWS);
450 for (a=0; a<MAXROOMS; ++a) {
452 if ( ( (is_known(&qrbuf,a,&CC->usersupp))
453 && (!has_newmsgs(&qrbuf,a,&CC->usersupp)) )
454 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) ) {
455 if (!strcmp(qrbuf.QRname,"000")) cprintf(">");
456 cprintf("%s|%u|%d\n",
457 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
464 * cmd_lzrm() - List Zapped RooMs
466 void cmd_lzrm(char *argbuf)
469 struct quickroom qrbuf;
470 int target_floor = (-1);
472 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
474 if (!(CC->logged_in)) {
475 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
479 if (getuser(&CC->usersupp,CC->curr_user)) {
480 cprintf("%d can't locate user\n",ERROR+INTERNAL_ERROR);
484 cprintf("%d list of forgotten rms\n",LISTING_FOLLOWS);
486 for (a=0; a<MAXROOMS; ++a) {
488 if ( (is_zapped(&qrbuf,a,&CC->usersupp))
489 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) ) {
490 if (!strcmp(qrbuf.QRname,"000")) cprintf(">");
491 cprintf("%s|%u|%d\n",
492 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
500 void usergoto(int where, int display_result)
506 int newmailcount = 0;
509 getroom(&CC->quickroom,CC->curr_rm);
510 lgetuser(&CC->usersupp,CC->curr_user);
511 CC->usersupp.forget[CC->curr_rm]=(-1);
512 CC->usersupp.generation[CC->curr_rm]=CC->quickroom.QRgen;
513 lputuser(&CC->usersupp,CC->curr_user);
515 /* check for new mail */
516 newmailcount = NewMailCount();
518 /* set info to 1 if the user needs to read the room's info file */
519 if (CC->quickroom.QRinfo > CC->usersupp.lastseen[CC->curr_rm]) info = 1;
523 get_msglist(CC->curr_rm);
524 for (a=0; a<CC->num_msgs; ++a) {
525 if (MessageFromList(a)>0L) {
527 if (MessageFromList(a)
528 > CC->usersupp.lastseen[CC->curr_rm]) ++c;
533 if (CC->curr_rm == 1) rmailflag = 1;
536 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
537 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
540 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
542 CC->quickroom.QRname,c,b,info,CC->quickroom.QRflags,
543 CC->quickroom.QRhighest,CC->usersupp.lastseen[CC->curr_rm],
544 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
545 if (CC->quickroom.QRflags & QR_PRIVATE) {
546 set_wtmpsupp("<private room>");
549 set_wtmpsupp(CC->quickroom.QRname);
555 * cmd_goto() - goto a new room
557 void cmd_goto(char *gargs)
559 struct quickroom QRscratch;
562 char bbb[20],towhere[32],password[20];
564 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
565 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
569 extract(towhere,gargs,0);
570 extract(password,gargs,1);
573 getuser(&CC->usersupp,CC->curr_user);
574 for (a=0; a<MAXROOMS; ++a) {
575 getroom(&QRscratch,a);
576 if ((a==0)&&(!strcasecmp(towhere,"_BASEROOM_"))) {
577 strncpy(towhere,QRscratch.QRname,31);
579 if ((a==1)&&(!strcasecmp(towhere,"_MAIL_"))) {
580 strncpy(towhere,QRscratch.QRname,31);
582 if ((!strcasecmp(QRscratch.QRname,config.c_twitroom))
583 &&(!strcasecmp(towhere,"_BITBUCKET_"))) {
584 strncpy(towhere,QRscratch.QRname,31);
586 strcpy(bbb,QRscratch.QRname);
589 /* let internal programs go directly to any room */
590 if (((CC->internal_pgm))&&(!strcasecmp(bbb,towhere))) {
595 /* normal clients have to pass through security */
597 (strcasecmp(bbb,towhere)==0)
598 && ((QRscratch.QRflags&QR_INUSE)!=0)
600 && ( ((QRscratch.QRflags&QR_PREFONLY)==0)
601 || (CC->usersupp.axlevel>=5)
604 && ( (a!=2) || (CC->usersupp.axlevel>=6) )
606 && ( ((QRscratch.QRflags&QR_PRIVATE)==0)
607 || (QRscratch.QRflags&QR_GUESSNAME)
608 || (CC->usersupp.axlevel>=6)
609 || (QRscratch.QRflags&QR_PASSWORDED)
610 || (QRscratch.QRgen==CC->usersupp.generation[a])
618 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
619 (CC->usersupp.axlevel<6) &&
620 (QRscratch.QRgen!=CC->usersupp.generation[a]) &&
621 (strcasecmp(QRscratch.QRpasswd,password))
623 cprintf("%d wrong or missing passwd\n",
624 ERROR+PASSWORD_REQUIRED);
633 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
637 void cmd_whok(void) {
638 struct usersupp temp;
639 struct cdbdata *cdbus;
641 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
642 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
645 getuser(&CC->usersupp,CC->curr_user);
647 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
648 cprintf("%d Higher access required.\n",
649 ERROR+HIGHER_ACCESS_REQUIRED);
653 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
654 cdb_rewind(CDB_USERSUPP);
655 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
656 bzero(&temp, sizeof(struct usersupp));
657 memcpy(&temp, cdbus->ptr, cdbus->len);
659 if ((CC->quickroom.QRflags & QR_INUSE)
660 && ( (CC->curr_rm!=2) || (temp.axlevel>=6) )
661 && (CC->quickroom.QRgen != (temp.forget[CC->curr_rm]) )
663 && ( ((CC->quickroom.QRflags&QR_PREFONLY)==0)
667 && ( ((CC->quickroom.QRflags&QR_PRIVATE)==0)
669 || (CC->quickroom.QRgen==(temp.generation[CC->curr_rm]))
672 && (strncmp(temp.fullname,"000",3))
674 ) cprintf("%s\n",temp.fullname);
681 * RDIR command for room directory
683 void cmd_rdir(void) {
690 if (!(CC->logged_in)) {
691 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
695 getroom(&CC->quickroom,CC->curr_rm);
696 getuser(&CC->usersupp,CC->curr_user);
698 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
699 cprintf("%d not here.\n",ERROR+NOT_HERE);
703 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
704 && (CC->usersupp.axlevel<6)
705 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
706 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
710 cprintf("%d %s|%s/files/%s\n",
711 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
713 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
714 BBSDIR,CC->quickroom.QRdirname,CC->temp);
717 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
719 if (fd==NULL) fd=fopen("/dev/null","r");
721 ls = fopen(CC->temp,"r");
722 while (fgets(flnm,256,ls)!=NULL) {
723 flnm[strlen(flnm)-1]=0;
724 if (strcasecmp(flnm,"filedir")) {
725 sprintf(buf,"%s/files/%s/%s",
726 BBSDIR,CC->quickroom.QRdirname,flnm);
730 while ((fgets(buf,256,fd)!=NULL)
731 &&(strlen(comment)==0)) {
732 buf[strlen(buf)-1] = 0;
733 if ((!strncasecmp(buf,flnm,strlen(flnm)))
734 && (buf[strlen(flnm)]==' '))
736 &buf[strlen(flnm)+1],255);
738 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
749 * get room parameters (aide or room aide command)
751 void cmd_getr(void) {
752 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
753 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
757 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
758 cprintf("%d Higher access required.\n",
759 ERROR+HIGHER_ACCESS_REQUIRED);
763 if (CC->curr_rm < 3) {
764 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
768 getroom(&CC->quickroom,CC->curr_rm);
769 cprintf("%d%c%s|%s|%s|%d|%d\n",
771 CC->quickroom.QRname,
772 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
773 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
774 CC->quickroom.QRflags,
775 (int)CC->quickroom.QRfloor);
780 * set room parameters (aide or room aide command)
782 void cmd_setr(char *args) {
787 if (!(CC->logged_in)) {
788 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
792 if (!is_room_aide()) {
793 cprintf("%d Higher access required.\n",
794 ERROR+HIGHER_ACCESS_REQUIRED);
798 if (CC->curr_rm < 3) {
799 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
803 if (num_parms(args)>=6) {
804 getfloor(&flbuf,extract_int(args,5));
805 if ((flbuf.f_flags & F_INUSE) == 0) {
806 cprintf("%d Invalid floor number.\n",
807 ERROR+INVALID_FLOOR_OPERATION);
812 lgetroom(&CC->quickroom,CC->curr_rm);
813 extract(buf,args,0); buf[20]=0;
814 strncpy(CC->quickroom.QRname,buf,19);
815 extract(buf,args,1); buf[10]=0;
816 strncpy(CC->quickroom.QRpasswd,buf,9);
817 extract(buf,args,2); buf[15]=0;
818 strncpy(CC->quickroom.QRdirname,buf,19);
819 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
821 /* Clean up a client boo-boo: if the client set the room to
822 * guess-name or passworded, ensure that the private flag is
825 if ((CC->quickroom.QRflags & QR_GUESSNAME)
826 ||(CC->quickroom.QRflags & QR_PASSWORDED))
827 CC->quickroom.QRflags |= QR_PRIVATE;
829 /* Kick everyone out if the client requested it */
830 if (extract_int(args,4)) {
831 ++CC->quickroom.QRgen;
832 if (CC->quickroom.QRgen==100) CC->quickroom.QRgen=1;
835 old_floor = CC->quickroom.QRfloor;
836 if (num_parms(args)>=6) {
837 CC->quickroom.QRfloor = extract_int(args,5);
840 lputroom(&CC->quickroom,CC->curr_rm);
842 /* adjust the floor reference counts */
843 lgetfloor(&flbuf,old_floor);
845 lputfloor(&flbuf,old_floor);
846 lgetfloor(&flbuf,CC->quickroom.QRfloor);
848 lputfloor(&flbuf,CC->quickroom.QRfloor);
850 /* create a room directory if necessary */
851 if (CC->quickroom.QRflags & QR_DIRECTORY) {
853 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
854 CC->quickroom.QRdirname);
858 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
860 cprintf("%d Ok\n",OK);
866 * get the name of the room aide for this room
868 void cmd_geta(void) {
869 struct usersupp usbuf;
871 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
872 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
876 if (CC->curr_rm < 0) {
877 cprintf("%d No current room.\n",ERROR);
881 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
882 cprintf("%d %s\n",OK,usbuf.fullname);
891 * set the room aide for this room
893 void cmd_seta(char *new_ra)
895 struct usersupp usbuf;
900 if (!(CC->logged_in)) {
901 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
905 if (!is_room_aide()) {
906 cprintf("%d Higher access required.\n",
907 ERROR+HIGHER_ACCESS_REQUIRED);
911 if (CC->curr_rm < 3) {
912 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
916 if (getuser(&usbuf,new_ra)!=0) {
920 newu = usbuf.usernum;
923 lgetroom(&CC->quickroom,CC->curr_rm);
925 if (CC->quickroom.QRroomaide != newu) {
928 CC->quickroom.QRroomaide = newu;
929 lputroom(&CC->quickroom,CC->curr_rm);
932 * We have to post the change notice _after_ writing changes to
933 * the room table, otherwise it would deadlock!
935 if (post_notice == 1) {
936 sprintf(buf,"%s is now room aide for %s>",
937 usbuf.fullname,CC->quickroom.QRname);
940 cprintf("%d Ok\n",OK);
945 * retrieve info file for this room
947 void cmd_rinf(void) {
952 sprintf(filename,"./info/%d",CC->curr_rm);
953 info_fp = fopen(filename,"r");
956 cprintf("%d No info file.\n",ERROR);
960 cprintf("%d Info:\n",LISTING_FOLLOWS);
961 while (fgets(buf, 256, info_fp) != NULL) {
962 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
963 cprintf("%s\n", buf);
970 * aide command: kill the current room
972 void cmd_kill(char *argbuf)
980 kill_ok = extract_int(argbuf,0);
982 if (!(CC->logged_in)) {
983 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
987 if (!is_room_aide()) {
988 cprintf("%d Higher access required.\n",
989 ERROR+HIGHER_ACCESS_REQUIRED);
993 if (CC->curr_rm < 3) {
994 cprintf("%d Can't kill this room.\n",ERROR+NOT_HERE);
1000 /* first flag the room record as not in use */
1001 lgetroom(&CC->quickroom,CC->curr_rm);
1002 CC->quickroom.QRflags=0;
1004 /* then delete the messages in the room */
1005 get_msglist(CC->curr_rm);
1006 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1007 MsgToDelete = MessageFromList(a);
1008 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1010 put_msglist(CC->curr_rm);
1013 cdb_delete(CDB_MSGLISTS, &CC->curr_rm, sizeof(int));
1015 lputroom(&CC->quickroom,CC->curr_rm);
1018 /* then decrement the reference count for the floor */
1019 lgetfloor(&flbuf,(int)CC->quickroom.QRfloor);
1020 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1021 lputfloor(&flbuf,(int)CC->quickroom.QRfloor);
1023 /* tell the world what we did */
1024 sprintf(aaa,"%s> killed by %s",CC->quickroom.QRname,CC->curr_user);
1027 cprintf("%d '%s' deleted.\n",OK,CC->quickroom.QRname);
1030 cprintf("%d ok to delete.\n",OK);
1036 * Find a free slot to create a new room in, or return -1 for error.
1037 * search_dir is the direction to search in. 1 causes this function to
1038 * return the first available slot, -1 gets the last available slot.
1040 int get_free_room_slot(int search_dir)
1043 struct quickroom qrbuf;
1045 st = ((search_dir>0) ? 3 : (MAXROOMS-1));
1047 for (a=st; ((a<MAXROOMS)&&(a>=3)); a=a+search_dir) {
1049 if ((qrbuf.QRflags & QR_INUSE)==0) return(a);
1056 * internal code to create a new room (returns room flags)
1058 unsigned create_room(int free_slot, char *new_room_name, int new_room_type, char *new_room_pass, int new_room_floor)
1060 struct quickroom qrbuf;
1063 lgetroom(&qrbuf,free_slot);
1064 strncpy(qrbuf.QRname,new_room_name,19);
1065 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1066 qrbuf.QRflags = QR_INUSE;
1067 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1068 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1069 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1070 qrbuf.QRroomaide = (-1L);
1071 if ((new_room_type > 0)&&(CREATAIDE==1))
1072 qrbuf.QRroomaide=CC->usersupp.usernum;
1073 qrbuf.QRhighest = 0L;
1074 ++qrbuf.QRgen; if (qrbuf.QRgen>=126) qrbuf.QRgen=10;
1075 qrbuf.QRfloor = new_room_floor;
1077 /* save what we just did... */
1078 lputroom(&qrbuf,free_slot);
1080 /* bump the reference count on whatever floor the room is on */
1081 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1082 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1083 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1085 /* be sure not to kick the creator out of the room! */
1086 lgetuser(&CC->usersupp,CC->curr_user);
1087 CC->usersupp.generation[free_slot] = qrbuf.QRgen;
1088 CC->usersupp.forget[free_slot] = (-1);
1089 lputuser(&CC->usersupp,CC->curr_user);
1091 /* resume our happy day */
1092 return(qrbuf.QRflags);
1099 void cmd_cre8(char *args)
1104 char new_room_name[256];
1106 char new_room_pass[256];
1110 struct quickroom qrbuf;
1113 cre8_ok = extract_int(args,0);
1114 extract(new_room_name,args,1);
1115 new_room_name[19] = 0;
1116 new_room_type = extract_int(args,2);
1117 extract(new_room_pass,args,3);
1118 new_room_pass[9] = 0;
1121 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1122 cprintf("%d Invalid room name.\n",ERROR);
1126 if (num_parms(args)>=5) {
1127 getfloor(&flbuf,extract_int(args,4));
1128 if ((flbuf.f_flags & F_INUSE) == 0) {
1129 cprintf("%d Invalid floor number.\n",
1130 ERROR+INVALID_FLOOR_OPERATION);
1134 new_room_floor = extract_int(args,4);
1138 if (!(CC->logged_in)) {
1139 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1143 if (CC->usersupp.axlevel<3) {
1144 cprintf("%d You need higher access to create rooms.\n",
1145 ERROR+HIGHER_ACCESS_REQUIRED);
1149 free_slot = get_free_room_slot(1);
1151 cprintf("%d There is no space available for a new room.\n",
1157 cprintf("%d ok to create...\n",OK);
1161 for (a=0; a<MAXROOMS; ++a) {
1163 if ( (!strcasecmp(qrbuf.QRname,new_room_name))
1164 && (qrbuf.QRflags & QR_INUSE) ) {
1165 cprintf("%d '%s' already exists.\n",
1166 ERROR,qrbuf.QRname);
1171 if ((new_room_type < 0) || (new_room_type > 3)) {
1172 cprintf("%d Invalid room type.\n",ERROR);
1176 newflags = create_room(free_slot,new_room_name,
1177 new_room_type,new_room_pass,new_room_floor);
1179 /* post a message in Aide> describing the new room */
1180 strncpy(aaa,new_room_name,255);
1181 strcat(aaa,"> created by ");
1182 strcat(aaa,CC->usersupp.fullname);
1183 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1184 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1185 if (newflags&QR_PASSWORDED) {
1186 strcat(aaa,"\n Password: ");
1187 strcat(aaa,new_room_pass);
1191 sprintf(aaa,"./info/%d",free_slot); /* delete old info file */
1193 sprintf(aaa,"./images/room.%d.gif",free_slot); /* and picture */
1196 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1201 void cmd_einf(char *ok)
1202 { /* enter info file for current room */
1204 char infofilename[32];
1207 if (!(CC->logged_in)) {
1208 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1212 if (!is_room_aide()) {
1213 cprintf("%d Higher access required.\n",
1214 ERROR+HIGHER_ACCESS_REQUIRED);
1219 cprintf("%d Ok.\n",OK);
1223 cprintf("%d Send info...\n",SEND_LISTING);
1225 sprintf(infofilename,"./info/%d",CC->curr_rm);
1227 fp=fopen(infofilename,"w");
1230 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1231 } while(strcmp(buf,"000"));
1234 /* now update the room index so people will see our new info */
1235 lgetroom(&CC->quickroom,CC->curr_rm); /* lock so no one steps on us */
1236 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1237 lputroom(&CC->quickroom,CC->curr_rm);
1242 * cmd_lflr() - List all known floors
1244 void cmd_lflr(void) {
1248 if (!(CC->logged_in)) {
1249 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1253 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1254 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1259 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1261 for (a=0; a<MAXFLOORS; ++a) {
1263 if (flbuf.f_flags & F_INUSE) {
1264 cprintf("%d|%s|%d\n",
1276 * create a new floor
1278 void cmd_cflr(char *argbuf)
1280 char new_floor_name[256];
1283 int free_slot = (-1);
1286 extract(new_floor_name,argbuf,0);
1287 cflr_ok = extract_int(argbuf,1);
1290 if (!(CC->logged_in)) {
1291 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1295 if (CC->usersupp.axlevel<6) {
1296 cprintf("%d You need higher access to create rooms.\n",
1297 ERROR+HIGHER_ACCESS_REQUIRED);
1301 for (a=0; a<MAXFLOORS; ++a) {
1304 /* note any free slots while we're scanning... */
1305 if ( ((flbuf.f_flags & F_INUSE)==0)
1306 && (free_slot < 0) ) free_slot = a;
1308 /* check to see if it already exists */
1309 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1310 && (flbuf.f_flags & F_INUSE) ) {
1311 cprintf("%d Floor '%s' already exists.\n",
1312 ERROR+ALREADY_EXISTS,
1320 cprintf("%d There is no space available for a new floor.\n",
1321 ERROR+INVALID_FLOOR_OPERATION);
1326 cprintf("%d ok to create...\n",OK);
1330 lgetfloor(&flbuf,free_slot);
1331 flbuf.f_flags = F_INUSE;
1332 flbuf.f_ref_count = 0;
1333 strncpy(flbuf.f_name,new_floor_name,255);
1334 lputfloor(&flbuf,free_slot);
1335 cprintf("%d %d\n",OK,free_slot);
1343 void cmd_kflr(char *argbuf)
1346 int floor_to_delete;
1350 floor_to_delete = extract_int(argbuf,0);
1351 kflr_ok = extract_int(argbuf,1);
1354 if (!(CC->logged_in)) {
1355 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1359 if (CC->usersupp.axlevel<6) {
1360 cprintf("%d You need higher access to delete floors.\n",
1361 ERROR+HIGHER_ACCESS_REQUIRED);
1365 lgetfloor(&flbuf,floor_to_delete);
1368 if ((flbuf.f_flags & F_INUSE) == 0) {
1369 cprintf("%d Floor %d not in use.\n",
1370 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1375 if (flbuf.f_ref_count != 0) {
1376 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1377 ERROR+INVALID_FLOOR_OPERATION,
1384 cprintf("%d Ok\n",OK);
1387 cprintf("%d Ok to delete...\n",OK);
1394 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1395 lputfloor(&flbuf,floor_to_delete);
1401 void cmd_eflr(char *argbuf)
1407 np = num_parms(argbuf);
1409 cprintf("%d Usage error.\n",ERROR);
1413 if (!(CC->logged_in)) {
1414 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1418 if (CC->usersupp.axlevel<6) {
1419 cprintf("%d You need higher access to edit floors.\n",
1420 ERROR+HIGHER_ACCESS_REQUIRED);
1424 floor_num = extract_int(argbuf,0);
1425 lgetfloor(&flbuf,floor_num);
1426 if ( (flbuf.f_flags & F_INUSE) == 0) {
1427 lputfloor(&flbuf,floor_num);
1428 cprintf("%d Floor %d is not in use.\n",
1429 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1432 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1433 lputfloor(&flbuf,floor_num);
1435 cprintf("%d Ok\n",OK);