13 #include "sysdep_decls.h"
17 #include "serv_chat.h"
18 #include "citserver.h"
21 * Generic routine for determining user access to rooms
23 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf) {
27 /* Make sure we're dealing with a real, existing room */
28 if (roombuf->QRflags & QR_INUSE) {
29 retval = retval | UA_INUSE;
35 /* for internal programs, always do everything */
36 if (((CC->internal_pgm))&&(roombuf->QRflags & QR_INUSE)) {
37 return(UA_INUSE | UA_KNOWN | UA_GOTOALLOWED);
40 /* Locate any applicable user/room relationships */
41 CtdlGetRelationship(&vbuf, userbuf, roombuf);
43 /* If this is a public room, it's accessible... */
44 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
45 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
48 /* If this is a preferred users only room, check access level */
49 if (roombuf->QRflags & QR_PREFONLY) {
50 if (userbuf->axlevel < 5) {
51 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
55 /* For private rooms, check the generation number matchups */
56 if (roombuf->QRflags & QR_PRIVATE) {
58 /* An explicit match means the user belongs in this room */
59 if (vbuf.v_flags & V_ACCESS) {
60 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
62 /* Otherwise, check if this is a guess-name or passworded
63 * room. If it is, a goto may at least be attempted
65 else if ((roombuf->QRflags & QR_PRIVATE)
66 ||(roombuf->QRflags & QR_PASSWORDED)) {
67 retval = retval & ~UA_KNOWN;
68 retval = retval | UA_GOTOALLOWED;
72 /* Check to see if the user has forgotten this room */
73 if (vbuf.v_flags & V_FORGET) {
74 retval = retval & ~UA_KNOWN;
75 retval = retval | UA_ZAPPED;
78 /* If user is explicitly locked out of this room, deny everything */
79 if (vbuf.v_flags & V_LOCKOUT) {
80 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
83 /* Aides get access to everything */
84 if (userbuf->axlevel >= 6) {
85 retval = retval | UA_INUSE | UA_KNOWN | UA_GOTOALLOWED;
86 retval = retval & ~UA_ZAPPED;
89 /* By the way, we also check for the presence of new messages */
90 if ( (roombuf->QRhighest) > (vbuf.v_lastseen) ) {
91 retval = retval | UA_HASNEWMSGS;
99 * getroom() - retrieve room data from disk
101 void getroom(struct quickroom *qrbuf, int room_num)
103 struct cdbdata *cdbqr;
106 bzero(qrbuf, sizeof(struct quickroom));
107 cdbqr = cdb_fetch(CDB_QUICKROOM, &room_num, sizeof(int));
109 memcpy(qrbuf, cdbqr->ptr,
110 ( (cdbqr->len > sizeof(struct quickroom)) ?
111 sizeof(struct quickroom) : cdbqr->len) );
116 qrbuf->QRflags = QR_INUSE;
119 case 0: strcpy(qrbuf->QRname, "Lobby");
121 case 1: strcpy(qrbuf->QRname, "Mail");
123 case 2: strcpy(qrbuf->QRname, "Aide");
130 /** FIX ** VILE SLEAZY HACK ALERT!!
131 * This is a temporary fix until we can track down where room names
132 * are getting corrupted on some systems.
134 for (a=0; a<20; ++a) if (qrbuf->QRname[a] < 32) qrbuf->QRname[a] = 0;
135 qrbuf->QRname[19] = 0;
139 * lgetroom() - same as getroom() but locks the record (if supported)
141 void lgetroom(struct quickroom *qrbuf, int room_num)
143 begin_critical_section(S_QUICKROOM);
144 getroom(qrbuf,room_num);
149 * putroom() - store room data on disk
151 void putroom(struct quickroom *qrbuf, int room_num)
153 time(&qrbuf->QRmtime);
154 cdb_store(CDB_QUICKROOM, &room_num, sizeof(int),
155 qrbuf, sizeof(struct quickroom));
160 * lputroom() - same as putroom() but unlocks the record (if supported)
162 void lputroom(struct quickroom *qrbuf, int room_num)
165 putroom(qrbuf,room_num);
166 end_critical_section(S_QUICKROOM);
172 * getfloor() - retrieve floor data from disk
174 void getfloor(struct floor *flbuf, int floor_num)
176 struct cdbdata *cdbfl;
178 bzero(flbuf, sizeof(struct floor));
179 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
181 memcpy(flbuf, cdbfl->ptr,
182 ( (cdbfl->len > sizeof(struct floor)) ?
183 sizeof(struct floor) : cdbfl->len) );
187 if (floor_num == 0) {
188 strcpy(flbuf->f_name, "Main Floor");
189 flbuf->f_flags = F_INUSE;
190 flbuf->f_ref_count = 3;
197 * lgetfloor() - same as getfloor() but locks the record (if supported)
199 void lgetfloor(struct floor *flbuf, int floor_num)
202 begin_critical_section(S_FLOORTAB);
203 getfloor(flbuf,floor_num);
208 * putfloor() - store floor data on disk
210 void putfloor(struct floor *flbuf, int floor_num)
212 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
213 flbuf, sizeof(struct floor));
218 * lputfloor() - same as putfloor() but unlocks the record (if supported)
220 void lputfloor(struct floor *flbuf, int floor_num)
223 putfloor(flbuf,floor_num);
224 end_critical_section(S_FLOORTAB);
230 * Traverse the room file...
232 void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) {
233 struct quickroom qrbuf;
234 struct cdbdata *cdbqr;
236 cdb_rewind(CDB_QUICKROOM);
238 while(cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
239 bzero(&qrbuf, sizeof(struct quickroom));
240 memcpy(&qrbuf, cdbqr->ptr,
241 ( (cdbqr->len > sizeof(struct quickroom)) ?
242 sizeof(struct quickroom) : cdbqr->len) );
251 * get_msglist() - retrieve room message pointers
253 void get_msglist(int room_num)
255 struct cdbdata *cdbfr;
257 if (CC->msglist != NULL) {
264 cdbfr = cdb_fetch(CDB_MSGLISTS, &room_num, sizeof(int));
267 cdbfr = cdb_fetch(CDB_MAILBOXES, &CC->usersupp.usernum,
275 CC->msglist = malloc(cdbfr->len);
276 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
277 CC->num_msgs = cdbfr->len / sizeof(long);
283 * put_msglist() - retrieve room message pointers
285 void put_msglist(int room_num)
289 cdb_store(CDB_MSGLISTS, &room_num, sizeof(int),
290 CC->msglist, (CC->num_msgs * sizeof(long)) );
293 cdb_store(CDB_MAILBOXES, &CC->usersupp.usernum, sizeof(long),
294 CC->msglist, (CC->num_msgs * sizeof(long)) );
300 * MessageFromList() - get a message number from the list currently in memory
302 long MessageFromList(int whichpos) {
304 /* Return zero if the position is invalid */
305 if (whichpos >= CC->num_msgs) return 0L;
307 return(CC->msglist[whichpos]);
311 * SetMessageInList() - set a message number in the list currently in memory
313 void SetMessageInList(int whichpos, long newmsgnum) {
315 /* Return zero if the position is invalid */
316 if (whichpos >= CC->num_msgs) return;
318 CC->msglist[whichpos] = newmsgnum;
324 * sort message pointers
325 * (returns new msg count)
327 int sort_msglist(long listptrs[], int oldcount)
334 if (numitems < 2) return(oldcount);
337 for (a=numitems-2; a>=0; --a) {
338 for (b=0; b<=a; ++b) {
339 if (listptrs[b] > (listptrs[b+1])) {
341 hold2 = listptrs[b+1];
343 listptrs[b+1] = hold1;
348 /* and yank any nulls */
349 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
350 memcpy(&listptrs[0], &listptrs[1],
351 (sizeof(long) * (CC->num_msgs - 1)) );
362 * cmd_lrms() - List all accessible rooms, known or forgotten
364 void cmd_lrms(char *argbuf)
367 int target_floor = (-1);
368 struct quickroom qrbuf;
370 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
372 if (!(CC->logged_in)) {
373 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
377 if (getuser(&CC->usersupp,CC->curr_user)) {
378 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
382 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
384 for (a=0; a<MAXROOMS; ++a) {
386 if ( ((CtdlRoomAccess(&qrbuf, &CC->usersupp)
387 & (UA_KNOWN | UA_ZAPPED)))
388 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) )
389 cprintf("%s|%u|%d\n",
390 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
396 * cmd_lkra() - List all known rooms
398 void cmd_lkra(char *argbuf)
401 struct quickroom qrbuf;
402 int target_floor = (-1);
404 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
406 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
407 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
411 if (!(CC->internal_pgm)) if (getuser(&CC->usersupp,CC->curr_user)) {
412 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
416 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
418 for (a=0; a<MAXROOMS; ++a) {
420 ra = CtdlRoomAccess(&qrbuf, &CC->usersupp);
422 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) )
423 cprintf("%s|%u|%d\n",
424 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
430 * cmd_lkrn() - List Known Rooms with New messages
432 void cmd_lkrn(char *argbuf)
435 struct quickroom qrbuf;
436 int target_floor = (-1);
438 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
440 if (!(CC->logged_in)) {
441 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
445 if (getuser(&CC->usersupp,CC->curr_user)) {
446 cprintf("%d can't locate user\n",ERROR+INTERNAL_ERROR);
450 cprintf("%d list of rms w/ new msgs\n",LISTING_FOLLOWS);
452 for (a=0; a<MAXROOMS; ++a) {
454 ra = CtdlRoomAccess(&qrbuf, &CC->usersupp);
456 && (ra & UA_HASNEWMSGS)
457 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) )
458 cprintf("%s|%u|%d\n",
459 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
465 * cmd_lkro() - List Known Rooms with Old (no new) messages
467 void cmd_lkro(char *argbuf)
470 struct quickroom qrbuf;
471 int target_floor = (-1);
473 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
475 if (!(CC->logged_in)) {
476 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
480 if (getuser(&CC->usersupp,CC->curr_user)) {
481 cprintf("%d can't locate user\n",ERROR+INTERNAL_ERROR);
485 cprintf("%d list of rms w/o new msgs\n",LISTING_FOLLOWS);
487 for (a=0; a<MAXROOMS; ++a) {
489 ra = CtdlRoomAccess(&qrbuf, &CC->usersupp);
491 && ((ra & UA_HASNEWMSGS) == 0)
492 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) ) {
493 if (!strcmp(qrbuf.QRname,"000")) cprintf(">");
494 cprintf("%s|%u|%d\n",
495 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
502 * cmd_lzrm() - List Zapped RooMs
504 void cmd_lzrm(char *argbuf)
507 struct quickroom qrbuf;
508 int target_floor = (-1);
510 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
512 if (!(CC->logged_in)) {
513 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
517 if (getuser(&CC->usersupp,CC->curr_user)) {
518 cprintf("%d can't locate user\n",ERROR+INTERNAL_ERROR);
522 cprintf("%d list of forgotten rms\n",LISTING_FOLLOWS);
524 for (a=0; a<MAXROOMS; ++a) {
526 ra = CtdlRoomAccess(&qrbuf, &CC->usersupp);
527 if ( (ra & UA_GOTOALLOWED)
529 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) ) {
530 if (!strcmp(qrbuf.QRname,"000")) cprintf(">");
531 cprintf("%s|%u|%d\n",
532 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
540 void usergoto(int where, int display_result)
546 int newmailcount = 0;
550 getroom(&CC->quickroom,CC->curr_rm);
551 lgetuser(&CC->usersupp,CC->curr_user);
552 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
554 /* old method - remove when we're ready */
555 CC->usersupp.forget[CC->curr_rm]=(-1);
556 CC->usersupp.generation[CC->curr_rm]=CC->quickroom.QRgen;
559 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
560 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
562 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
563 lputuser(&CC->usersupp,CC->curr_user);
565 /* check for new mail */
566 newmailcount = NewMailCount();
568 /* set info to 1 if the user needs to read the room's info file */
569 if (CC->quickroom.QRinfo > CC->usersupp.lastseen[CC->curr_rm]) info = 1;
573 get_msglist(CC->curr_rm);
574 for (a=0; a<CC->num_msgs; ++a) {
575 if (MessageFromList(a)>0L) {
577 if (MessageFromList(a)
578 > CC->usersupp.lastseen[CC->curr_rm]) ++c;
583 if (CC->curr_rm == 1) rmailflag = 1;
586 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
587 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
590 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
592 CC->quickroom.QRname,c,b,info,CC->quickroom.QRflags,
593 CC->quickroom.QRhighest,CC->usersupp.lastseen[CC->curr_rm],
594 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
595 if (CC->quickroom.QRflags & QR_PRIVATE) {
596 set_wtmpsupp("<private room>");
599 set_wtmpsupp(CC->quickroom.QRname);
605 * cmd_goto() - goto a new room
607 void cmd_goto(char *gargs)
609 struct quickroom QRscratch;
612 char bbb[20],towhere[32],password[20];
614 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
615 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
619 extract(towhere,gargs,0);
620 extract(password,gargs,1);
623 getuser(&CC->usersupp,CC->curr_user);
624 for (a=0; a<MAXROOMS; ++a) {
625 getroom(&QRscratch,a);
626 if ((a==0)&&(!strcasecmp(towhere,"_BASEROOM_"))) {
627 strncpy(towhere,QRscratch.QRname,31);
629 if ((a==1)&&(!strcasecmp(towhere,"_MAIL_"))) {
630 strncpy(towhere,QRscratch.QRname,31);
632 if ((!strcasecmp(QRscratch.QRname,config.c_twitroom))
633 &&(!strcasecmp(towhere,"_BITBUCKET_"))) {
634 strncpy(towhere,QRscratch.QRname,31);
636 strcpy(bbb,QRscratch.QRname);
639 /* let internal programs go directly to any room */
640 if (((CC->internal_pgm))&&(!strcasecmp(bbb,towhere))) {
645 /* normal clients have to pass through security */
647 (strcasecmp(bbb,towhere)==0)
648 && ((QRscratch.QRflags&QR_INUSE)!=0)
650 && ( ((QRscratch.QRflags&QR_PREFONLY)==0)
651 || (CC->usersupp.axlevel>=5)
654 && ( (a!=2) || (CC->usersupp.axlevel>=6) )
656 && ( ((QRscratch.QRflags&QR_PRIVATE)==0)
657 || (QRscratch.QRflags&QR_GUESSNAME)
658 || (CC->usersupp.axlevel>=6)
659 || (QRscratch.QRflags&QR_PASSWORDED)
660 || (QRscratch.QRgen==CC->usersupp.generation[a])
668 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
669 (CC->usersupp.axlevel<6) &&
670 (QRscratch.QRgen!=CC->usersupp.generation[a]) &&
671 (strcasecmp(QRscratch.QRpasswd,password))
673 cprintf("%d wrong or missing passwd\n",
674 ERROR+PASSWORD_REQUIRED);
683 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
687 void cmd_whok(void) {
688 struct usersupp temp;
689 struct cdbdata *cdbus;
691 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
692 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
695 getuser(&CC->usersupp,CC->curr_user);
697 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
698 cprintf("%d Higher access required.\n",
699 ERROR+HIGHER_ACCESS_REQUIRED);
703 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
704 cdb_rewind(CDB_USERSUPP);
705 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
706 bzero(&temp, sizeof(struct usersupp));
707 memcpy(&temp, cdbus->ptr, cdbus->len);
709 if ((CC->quickroom.QRflags & QR_INUSE)
710 && ( (CC->curr_rm!=2) || (temp.axlevel>=6) )
711 && (CC->quickroom.QRgen != (temp.forget[CC->curr_rm]) )
713 && ( ((CC->quickroom.QRflags&QR_PREFONLY)==0)
717 && ( ((CC->quickroom.QRflags&QR_PRIVATE)==0)
719 || (CC->quickroom.QRgen==(temp.generation[CC->curr_rm]))
722 && (strncmp(temp.fullname,"000",3))
724 ) cprintf("%s\n",temp.fullname);
731 * RDIR command for room directory
733 void cmd_rdir(void) {
740 if (!(CC->logged_in)) {
741 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
745 getroom(&CC->quickroom,CC->curr_rm);
746 getuser(&CC->usersupp,CC->curr_user);
748 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
749 cprintf("%d not here.\n",ERROR+NOT_HERE);
753 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
754 && (CC->usersupp.axlevel<6)
755 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
756 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
760 cprintf("%d %s|%s/files/%s\n",
761 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
763 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
764 BBSDIR,CC->quickroom.QRdirname,CC->temp);
767 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
769 if (fd==NULL) fd=fopen("/dev/null","r");
771 ls = fopen(CC->temp,"r");
772 while (fgets(flnm,256,ls)!=NULL) {
773 flnm[strlen(flnm)-1]=0;
774 if (strcasecmp(flnm,"filedir")) {
775 sprintf(buf,"%s/files/%s/%s",
776 BBSDIR,CC->quickroom.QRdirname,flnm);
780 while ((fgets(buf,256,fd)!=NULL)
781 &&(strlen(comment)==0)) {
782 buf[strlen(buf)-1] = 0;
783 if ((!strncasecmp(buf,flnm,strlen(flnm)))
784 && (buf[strlen(flnm)]==' '))
786 &buf[strlen(flnm)+1],255);
788 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
799 * get room parameters (aide or room aide command)
801 void cmd_getr(void) {
802 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
803 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
807 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
808 cprintf("%d Higher access required.\n",
809 ERROR+HIGHER_ACCESS_REQUIRED);
813 if (CC->curr_rm < 3) {
814 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
818 getroom(&CC->quickroom,CC->curr_rm);
819 cprintf("%d%c%s|%s|%s|%d|%d\n",
821 CC->quickroom.QRname,
822 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
823 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
824 CC->quickroom.QRflags,
825 (int)CC->quickroom.QRfloor);
830 * set room parameters (aide or room aide command)
832 void cmd_setr(char *args) {
837 if (!(CC->logged_in)) {
838 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
842 if (!is_room_aide()) {
843 cprintf("%d Higher access required.\n",
844 ERROR+HIGHER_ACCESS_REQUIRED);
848 if (CC->curr_rm < 3) {
849 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
853 if (num_parms(args)>=6) {
854 getfloor(&flbuf,extract_int(args,5));
855 if ((flbuf.f_flags & F_INUSE) == 0) {
856 cprintf("%d Invalid floor number.\n",
857 ERROR+INVALID_FLOOR_OPERATION);
862 lgetroom(&CC->quickroom,CC->curr_rm);
863 extract(buf,args,0); buf[20]=0;
864 strncpy(CC->quickroom.QRname,buf,19);
865 extract(buf,args,1); buf[10]=0;
866 strncpy(CC->quickroom.QRpasswd,buf,9);
867 extract(buf,args,2); buf[15]=0;
868 strncpy(CC->quickroom.QRdirname,buf,19);
869 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
871 /* Clean up a client boo-boo: if the client set the room to
872 * guess-name or passworded, ensure that the private flag is
875 if ((CC->quickroom.QRflags & QR_GUESSNAME)
876 ||(CC->quickroom.QRflags & QR_PASSWORDED))
877 CC->quickroom.QRflags |= QR_PRIVATE;
879 /* Kick everyone out if the client requested it (by changing the
880 * room's generation number)
882 if (extract_int(args,4)) {
883 time(&CC->quickroom.QRgen);
886 old_floor = CC->quickroom.QRfloor;
887 if (num_parms(args)>=6) {
888 CC->quickroom.QRfloor = extract_int(args,5);
891 lputroom(&CC->quickroom,CC->curr_rm);
893 /* adjust the floor reference counts */
894 lgetfloor(&flbuf,old_floor);
896 lputfloor(&flbuf,old_floor);
897 lgetfloor(&flbuf,CC->quickroom.QRfloor);
899 lputfloor(&flbuf,CC->quickroom.QRfloor);
901 /* create a room directory if necessary */
902 if (CC->quickroom.QRflags & QR_DIRECTORY) {
904 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
905 CC->quickroom.QRdirname);
909 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
911 cprintf("%d Ok\n",OK);
917 * get the name of the room aide for this room
919 void cmd_geta(void) {
920 struct usersupp usbuf;
922 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
923 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
927 if (CC->curr_rm < 0) {
928 cprintf("%d No current room.\n",ERROR);
932 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
933 cprintf("%d %s\n",OK,usbuf.fullname);
942 * set the room aide for this room
944 void cmd_seta(char *new_ra)
946 struct usersupp usbuf;
951 if (!(CC->logged_in)) {
952 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
956 if (!is_room_aide()) {
957 cprintf("%d Higher access required.\n",
958 ERROR+HIGHER_ACCESS_REQUIRED);
962 if (CC->curr_rm < 3) {
963 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
967 if (getuser(&usbuf,new_ra)!=0) {
971 newu = usbuf.usernum;
974 lgetroom(&CC->quickroom,CC->curr_rm);
976 if (CC->quickroom.QRroomaide != newu) {
979 CC->quickroom.QRroomaide = newu;
980 lputroom(&CC->quickroom,CC->curr_rm);
983 * We have to post the change notice _after_ writing changes to
984 * the room table, otherwise it would deadlock!
986 if (post_notice == 1) {
987 sprintf(buf,"%s is now room aide for %s>",
988 usbuf.fullname,CC->quickroom.QRname);
991 cprintf("%d Ok\n",OK);
996 * retrieve info file for this room
998 void cmd_rinf(void) {
1003 sprintf(filename,"./info/%d",CC->curr_rm);
1004 info_fp = fopen(filename,"r");
1006 if (info_fp==NULL) {
1007 cprintf("%d No info file.\n",ERROR);
1011 cprintf("%d Info:\n",LISTING_FOLLOWS);
1012 while (fgets(buf, 256, info_fp) != NULL) {
1013 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1014 cprintf("%s\n", buf);
1021 * aide command: kill the current room
1023 void cmd_kill(char *argbuf)
1031 kill_ok = extract_int(argbuf,0);
1033 if (!(CC->logged_in)) {
1034 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1038 if (!is_room_aide()) {
1039 cprintf("%d Higher access required.\n",
1040 ERROR+HIGHER_ACCESS_REQUIRED);
1044 if (CC->curr_rm < 3) {
1045 cprintf("%d Can't kill this room.\n",ERROR+NOT_HERE);
1051 /* first flag the room record as not in use */
1052 lgetroom(&CC->quickroom,CC->curr_rm);
1053 CC->quickroom.QRflags=0;
1055 /* then delete the messages in the room */
1056 get_msglist(CC->curr_rm);
1057 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1058 MsgToDelete = MessageFromList(a);
1059 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1061 put_msglist(CC->curr_rm);
1064 cdb_delete(CDB_MSGLISTS, &CC->curr_rm, sizeof(int));
1066 lputroom(&CC->quickroom,CC->curr_rm);
1069 /* then decrement the reference count for the floor */
1070 lgetfloor(&flbuf,(int)CC->quickroom.QRfloor);
1071 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1072 lputfloor(&flbuf,(int)CC->quickroom.QRfloor);
1074 /* tell the world what we did */
1075 sprintf(aaa,"%s> killed by %s",CC->quickroom.QRname,CC->curr_user);
1078 cprintf("%d '%s' deleted.\n",OK,CC->quickroom.QRname);
1081 cprintf("%d ok to delete.\n",OK);
1087 * Find a free slot to create a new room in, or return -1 for error.
1088 * search_dir is the direction to search in. 1 causes this function to
1089 * return the first available slot, -1 gets the last available slot.
1091 int get_free_room_slot(int search_dir)
1094 struct quickroom qrbuf;
1096 st = ((search_dir>0) ? 3 : (MAXROOMS-1));
1098 for (a=st; ((a<MAXROOMS)&&(a>=3)); a=a+search_dir) {
1100 if ((qrbuf.QRflags & QR_INUSE)==0) return(a);
1107 * internal code to create a new room (returns room flags)
1109 unsigned create_room(int free_slot, char *new_room_name, int new_room_type, char *new_room_pass, int new_room_floor)
1111 struct quickroom qrbuf;
1115 lgetroom(&qrbuf,free_slot);
1116 strncpy(qrbuf.QRname,new_room_name,19);
1117 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1118 qrbuf.QRflags = QR_INUSE;
1119 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1120 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1121 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1122 qrbuf.QRroomaide = (-1L);
1123 if ((new_room_type > 0)&&(CREATAIDE==1))
1124 qrbuf.QRroomaide=CC->usersupp.usernum;
1125 qrbuf.QRhighest = 0L;
1127 qrbuf.QRfloor = new_room_floor;
1129 /* save what we just did... */
1130 lputroom(&qrbuf,free_slot);
1132 /* bump the reference count on whatever floor the room is on */
1133 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1134 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1135 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1137 /* be sure not to kick the creator out of the room! */
1138 lgetuser(&CC->usersupp,CC->curr_user);
1139 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1141 CC->usersupp.generation[free_slot] = qrbuf.QRgen;
1142 CC->usersupp.forget[free_slot] = (-1);
1144 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1145 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1146 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1147 lputuser(&CC->usersupp,CC->curr_user);
1149 /* resume our happy day */
1150 return(qrbuf.QRflags);
1157 void cmd_cre8(char *args)
1162 char new_room_name[256];
1164 char new_room_pass[256];
1168 struct quickroom qrbuf;
1171 cre8_ok = extract_int(args,0);
1172 extract(new_room_name,args,1);
1173 new_room_name[19] = 0;
1174 new_room_type = extract_int(args,2);
1175 extract(new_room_pass,args,3);
1176 new_room_pass[9] = 0;
1179 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1180 cprintf("%d Invalid room name.\n",ERROR);
1184 if (num_parms(args)>=5) {
1185 getfloor(&flbuf,extract_int(args,4));
1186 if ((flbuf.f_flags & F_INUSE) == 0) {
1187 cprintf("%d Invalid floor number.\n",
1188 ERROR+INVALID_FLOOR_OPERATION);
1192 new_room_floor = extract_int(args,4);
1196 if (!(CC->logged_in)) {
1197 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1201 if (CC->usersupp.axlevel<3) {
1202 cprintf("%d You need higher access to create rooms.\n",
1203 ERROR+HIGHER_ACCESS_REQUIRED);
1207 free_slot = get_free_room_slot(1);
1209 cprintf("%d There is no space available for a new room.\n",
1215 cprintf("%d ok to create...\n",OK);
1219 for (a=0; a<MAXROOMS; ++a) {
1221 if ( (!strcasecmp(qrbuf.QRname,new_room_name))
1222 && (qrbuf.QRflags & QR_INUSE) ) {
1223 cprintf("%d '%s' already exists.\n",
1224 ERROR,qrbuf.QRname);
1229 if ((new_room_type < 0) || (new_room_type > 3)) {
1230 cprintf("%d Invalid room type.\n",ERROR);
1234 newflags = create_room(free_slot,new_room_name,
1235 new_room_type,new_room_pass,new_room_floor);
1237 /* post a message in Aide> describing the new room */
1238 strncpy(aaa,new_room_name,255);
1239 strcat(aaa,"> created by ");
1240 strcat(aaa,CC->usersupp.fullname);
1241 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1242 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1243 if (newflags&QR_PASSWORDED) {
1244 strcat(aaa,"\n Password: ");
1245 strcat(aaa,new_room_pass);
1249 sprintf(aaa,"./info/%d",free_slot); /* delete old info file */
1251 sprintf(aaa,"./images/room.%d.gif",free_slot); /* and picture */
1254 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1259 void cmd_einf(char *ok)
1260 { /* enter info file for current room */
1262 char infofilename[32];
1265 if (!(CC->logged_in)) {
1266 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1270 if (!is_room_aide()) {
1271 cprintf("%d Higher access required.\n",
1272 ERROR+HIGHER_ACCESS_REQUIRED);
1277 cprintf("%d Ok.\n",OK);
1281 cprintf("%d Send info...\n",SEND_LISTING);
1283 sprintf(infofilename,"./info/%d",CC->curr_rm);
1285 fp=fopen(infofilename,"w");
1288 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1289 } while(strcmp(buf,"000"));
1292 /* now update the room index so people will see our new info */
1293 lgetroom(&CC->quickroom,CC->curr_rm); /* lock so no one steps on us */
1294 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1295 lputroom(&CC->quickroom,CC->curr_rm);
1300 * cmd_lflr() - List all known floors
1302 void cmd_lflr(void) {
1306 if (!(CC->logged_in)) {
1307 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1311 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1312 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1317 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1319 for (a=0; a<MAXFLOORS; ++a) {
1321 if (flbuf.f_flags & F_INUSE) {
1322 cprintf("%d|%s|%d\n",
1334 * create a new floor
1336 void cmd_cflr(char *argbuf)
1338 char new_floor_name[256];
1341 int free_slot = (-1);
1344 extract(new_floor_name,argbuf,0);
1345 cflr_ok = extract_int(argbuf,1);
1348 if (!(CC->logged_in)) {
1349 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1353 if (CC->usersupp.axlevel<6) {
1354 cprintf("%d You need higher access to create rooms.\n",
1355 ERROR+HIGHER_ACCESS_REQUIRED);
1359 for (a=0; a<MAXFLOORS; ++a) {
1362 /* note any free slots while we're scanning... */
1363 if ( ((flbuf.f_flags & F_INUSE)==0)
1364 && (free_slot < 0) ) free_slot = a;
1366 /* check to see if it already exists */
1367 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1368 && (flbuf.f_flags & F_INUSE) ) {
1369 cprintf("%d Floor '%s' already exists.\n",
1370 ERROR+ALREADY_EXISTS,
1378 cprintf("%d There is no space available for a new floor.\n",
1379 ERROR+INVALID_FLOOR_OPERATION);
1384 cprintf("%d ok to create...\n",OK);
1388 lgetfloor(&flbuf,free_slot);
1389 flbuf.f_flags = F_INUSE;
1390 flbuf.f_ref_count = 0;
1391 strncpy(flbuf.f_name,new_floor_name,255);
1392 lputfloor(&flbuf,free_slot);
1393 cprintf("%d %d\n",OK,free_slot);
1401 void cmd_kflr(char *argbuf)
1404 int floor_to_delete;
1408 floor_to_delete = extract_int(argbuf,0);
1409 kflr_ok = extract_int(argbuf,1);
1412 if (!(CC->logged_in)) {
1413 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1417 if (CC->usersupp.axlevel<6) {
1418 cprintf("%d You need higher access to delete floors.\n",
1419 ERROR+HIGHER_ACCESS_REQUIRED);
1423 lgetfloor(&flbuf,floor_to_delete);
1426 if ((flbuf.f_flags & F_INUSE) == 0) {
1427 cprintf("%d Floor %d not in use.\n",
1428 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1433 if (flbuf.f_ref_count != 0) {
1434 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1435 ERROR+INVALID_FLOOR_OPERATION,
1442 cprintf("%d Ok\n",OK);
1445 cprintf("%d Ok to delete...\n",OK);
1452 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1453 lputfloor(&flbuf,floor_to_delete);
1459 void cmd_eflr(char *argbuf)
1465 np = num_parms(argbuf);
1467 cprintf("%d Usage error.\n",ERROR);
1471 if (!(CC->logged_in)) {
1472 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1476 if (CC->usersupp.axlevel<6) {
1477 cprintf("%d You need higher access to edit floors.\n",
1478 ERROR+HIGHER_ACCESS_REQUIRED);
1482 floor_num = extract_int(argbuf,0);
1483 lgetfloor(&flbuf,floor_num);
1484 if ( (flbuf.f_flags & F_INUSE) == 0) {
1485 lputfloor(&flbuf,floor_num);
1486 cprintf("%d Floor %d is not in use.\n",
1487 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1490 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1491 lputfloor(&flbuf,floor_num);
1493 cprintf("%d Ok\n",OK);