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) );
244 if (qrbuf.QRflags & QR_INUSE) (*CallBack)(&qrbuf);
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)) );
361 * cmd_lrms() - List all accessible rooms, known or forgotten
363 void cmd_lrms_backend(struct quickroom *qrbuf) {
364 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
365 & (UA_KNOWN | UA_ZAPPED)))
366 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
367 ||((CC->FloorBeingSearched)<0)) )
368 cprintf("%s|%u|%d\n",
369 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
372 void cmd_lrms(char *argbuf)
374 CC->FloorBeingSearched = (-1);
375 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
377 if (!(CC->logged_in)) {
378 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
382 if (getuser(&CC->usersupp,CC->curr_user)) {
383 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
387 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
389 ForEachRoom(cmd_lrms_backend);
396 * cmd_lkra() - List all known rooms
398 void cmd_lkra_backend(struct quickroom *qrbuf) {
399 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
401 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
402 ||((CC->FloorBeingSearched)<0)) )
403 cprintf("%s|%u|%d\n",
404 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
407 void cmd_lkra(char *argbuf)
409 CC->FloorBeingSearched = (-1);
410 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
412 if (!(CC->logged_in)) {
413 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
417 if (getuser(&CC->usersupp,CC->curr_user)) {
418 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
422 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
424 ForEachRoom(cmd_lkra_backend);
431 * cmd_lkrn() - List all known rooms with new messages
433 void cmd_lkrn_backend(struct quickroom *qrbuf) {
436 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
438 && (ra & UA_HASNEWMSGS)
439 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
440 ||((CC->FloorBeingSearched)<0)) )
441 cprintf("%s|%u|%d\n",
442 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
445 void cmd_lkrn(char *argbuf)
447 CC->FloorBeingSearched = (-1);
448 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
450 if (!(CC->logged_in)) {
451 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
455 if (getuser(&CC->usersupp,CC->curr_user)) {
456 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
460 cprintf("%d Rooms w/ new msgs:\n",LISTING_FOLLOWS);
462 ForEachRoom(cmd_lkrn_backend);
469 * cmd_lkro() - List all known rooms
471 void cmd_lkro_backend(struct quickroom *qrbuf) {
474 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
476 && ((ra & UA_HASNEWMSGS)==0)
477 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
478 ||((CC->FloorBeingSearched)<0)) )
479 cprintf("%s|%u|%d\n",
480 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
483 void cmd_lkro(char *argbuf)
485 CC->FloorBeingSearched = (-1);
486 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
488 if (!(CC->logged_in)) {
489 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
493 if (getuser(&CC->usersupp,CC->curr_user)) {
494 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
498 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
500 ForEachRoom(cmd_lkro_backend);
507 * cmd_lzrm() - List all forgotten rooms
509 void cmd_lzrm_backend(struct quickroom *qrbuf) {
512 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
513 if ( (ra & UA_GOTOALLOWED)
515 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
516 ||((CC->FloorBeingSearched)<0)) )
517 cprintf("%s|%u|%d\n",
518 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
521 void cmd_lzrm(char *argbuf)
523 CC->FloorBeingSearched = (-1);
524 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
526 if (!(CC->logged_in)) {
527 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
531 if (getuser(&CC->usersupp,CC->curr_user)) {
532 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
536 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
538 ForEachRoom(cmd_lzrm_backend);
544 void usergoto(int where, int display_result)
550 int newmailcount = 0;
554 getroom(&CC->quickroom,CC->curr_rm);
555 lgetuser(&CC->usersupp,CC->curr_user);
556 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
558 /* old method - remove when we're ready */
559 CC->usersupp.forget[CC->curr_rm]=(-1);
560 CC->usersupp.generation[CC->curr_rm]=CC->quickroom.QRgen;
563 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
564 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
566 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
567 lputuser(&CC->usersupp,CC->curr_user);
569 /* check for new mail */
570 newmailcount = NewMailCount();
572 /* set info to 1 if the user needs to read the room's info file */
573 if (CC->quickroom.QRinfo > CC->usersupp.lastseen[CC->curr_rm]) info = 1;
577 get_msglist(CC->curr_rm);
578 for (a=0; a<CC->num_msgs; ++a) {
579 if (MessageFromList(a)>0L) {
581 if (MessageFromList(a)
582 > CC->usersupp.lastseen[CC->curr_rm]) ++c;
587 if (CC->curr_rm == 1) rmailflag = 1;
590 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
591 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
594 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
596 CC->quickroom.QRname,c,b,info,CC->quickroom.QRflags,
597 CC->quickroom.QRhighest,CC->usersupp.lastseen[CC->curr_rm],
598 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
599 if (CC->quickroom.QRflags & QR_PRIVATE) {
600 set_wtmpsupp("<private room>");
603 set_wtmpsupp(CC->quickroom.QRname);
609 * cmd_goto() - goto a new room
611 void cmd_goto(char *gargs)
613 struct quickroom QRscratch;
616 char bbb[20],towhere[32],password[20];
618 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
619 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
623 extract(towhere,gargs,0);
624 extract(password,gargs,1);
627 getuser(&CC->usersupp,CC->curr_user);
629 /* FIX This is the primary bit of code that needs to be rewritten
630 * during the cutover. Search for rooms by name rather than by
631 * position in the file. A total rewrite may be necessary.
633 for (a=0; a<MAXROOMS; ++a) {
634 getroom(&QRscratch,a);
635 if ((a==0)&&(!strcasecmp(towhere,"_BASEROOM_"))) {
636 strncpy(towhere,QRscratch.QRname,31);
638 if ((a==1)&&(!strcasecmp(towhere,"_MAIL_"))) {
639 strncpy(towhere,QRscratch.QRname,31);
641 if ((!strcasecmp(QRscratch.QRname,config.c_twitroom))
642 &&(!strcasecmp(towhere,"_BITBUCKET_"))) {
643 strncpy(towhere,QRscratch.QRname,31);
645 strcpy(bbb,QRscratch.QRname);
648 /* let internal programs go directly to any room */
649 if (((CC->internal_pgm))&&(!strcasecmp(bbb,towhere))) {
654 /* normal clients have to pass through security */
656 (strcasecmp(bbb,towhere)==0)
657 && ((QRscratch.QRflags&QR_INUSE)!=0)
659 && ( ((QRscratch.QRflags&QR_PREFONLY)==0)
660 || (CC->usersupp.axlevel>=5)
663 && ( (a!=2) || (CC->usersupp.axlevel>=6) )
665 && ( ((QRscratch.QRflags&QR_PRIVATE)==0)
666 || (QRscratch.QRflags&QR_GUESSNAME)
667 || (CC->usersupp.axlevel>=6)
668 || (QRscratch.QRflags&QR_PASSWORDED)
669 || (QRscratch.QRgen==CC->usersupp.generation[a])
677 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
678 (CC->usersupp.axlevel<6) &&
679 (QRscratch.QRgen!=CC->usersupp.generation[a]) &&
680 (strcasecmp(QRscratch.QRpasswd,password))
682 cprintf("%d wrong or missing passwd\n",
683 ERROR+PASSWORD_REQUIRED);
692 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
696 void cmd_whok(void) {
697 struct usersupp temp;
698 struct cdbdata *cdbus;
700 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
701 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
704 getuser(&CC->usersupp,CC->curr_user);
706 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
707 cprintf("%d Higher access required.\n",
708 ERROR+HIGHER_ACCESS_REQUIRED);
712 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
713 cdb_rewind(CDB_USERSUPP);
714 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
715 bzero(&temp, sizeof(struct usersupp));
716 memcpy(&temp, cdbus->ptr, cdbus->len);
718 if ((CC->quickroom.QRflags & QR_INUSE)
719 && ( (CC->curr_rm!=2) || (temp.axlevel>=6) )
720 && (CC->quickroom.QRgen != (temp.forget[CC->curr_rm]) )
722 && ( ((CC->quickroom.QRflags&QR_PREFONLY)==0)
726 && ( ((CC->quickroom.QRflags&QR_PRIVATE)==0)
728 || (CC->quickroom.QRgen==(temp.generation[CC->curr_rm]))
731 && (strncmp(temp.fullname,"000",3))
733 ) cprintf("%s\n",temp.fullname);
740 * RDIR command for room directory
742 void cmd_rdir(void) {
749 if (!(CC->logged_in)) {
750 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
754 getroom(&CC->quickroom,CC->curr_rm);
755 getuser(&CC->usersupp,CC->curr_user);
757 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
758 cprintf("%d not here.\n",ERROR+NOT_HERE);
762 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
763 && (CC->usersupp.axlevel<6)
764 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
765 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
769 cprintf("%d %s|%s/files/%s\n",
770 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
772 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
773 BBSDIR,CC->quickroom.QRdirname,CC->temp);
776 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
778 if (fd==NULL) fd=fopen("/dev/null","r");
780 ls = fopen(CC->temp,"r");
781 while (fgets(flnm,256,ls)!=NULL) {
782 flnm[strlen(flnm)-1]=0;
783 if (strcasecmp(flnm,"filedir")) {
784 sprintf(buf,"%s/files/%s/%s",
785 BBSDIR,CC->quickroom.QRdirname,flnm);
789 while ((fgets(buf,256,fd)!=NULL)
790 &&(strlen(comment)==0)) {
791 buf[strlen(buf)-1] = 0;
792 if ((!strncasecmp(buf,flnm,strlen(flnm)))
793 && (buf[strlen(flnm)]==' '))
795 &buf[strlen(flnm)+1],255);
797 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
808 * get room parameters (aide or room aide command)
810 void cmd_getr(void) {
811 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
812 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
816 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
817 cprintf("%d Higher access required.\n",
818 ERROR+HIGHER_ACCESS_REQUIRED);
822 if (CC->curr_rm < 3) {
823 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
827 getroom(&CC->quickroom,CC->curr_rm);
828 cprintf("%d%c%s|%s|%s|%d|%d\n",
830 CC->quickroom.QRname,
831 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
832 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
833 CC->quickroom.QRflags,
834 (int)CC->quickroom.QRfloor);
839 * set room parameters (aide or room aide command)
841 void cmd_setr(char *args) {
846 if (!(CC->logged_in)) {
847 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
851 if (!is_room_aide()) {
852 cprintf("%d Higher access required.\n",
853 ERROR+HIGHER_ACCESS_REQUIRED);
857 if (CC->curr_rm < 3) {
858 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
862 if (num_parms(args)>=6) {
863 getfloor(&flbuf,extract_int(args,5));
864 if ((flbuf.f_flags & F_INUSE) == 0) {
865 cprintf("%d Invalid floor number.\n",
866 ERROR+INVALID_FLOOR_OPERATION);
871 lgetroom(&CC->quickroom,CC->curr_rm);
872 extract(buf,args,0); buf[20]=0;
873 strncpy(CC->quickroom.QRname,buf,19);
874 extract(buf,args,1); buf[10]=0;
875 strncpy(CC->quickroom.QRpasswd,buf,9);
876 extract(buf,args,2); buf[15]=0;
877 strncpy(CC->quickroom.QRdirname,buf,19);
878 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
880 /* Clean up a client boo-boo: if the client set the room to
881 * guess-name or passworded, ensure that the private flag is
884 if ((CC->quickroom.QRflags & QR_GUESSNAME)
885 ||(CC->quickroom.QRflags & QR_PASSWORDED))
886 CC->quickroom.QRflags |= QR_PRIVATE;
888 /* Kick everyone out if the client requested it (by changing the
889 * room's generation number)
891 if (extract_int(args,4)) {
892 time(&CC->quickroom.QRgen);
895 old_floor = CC->quickroom.QRfloor;
896 if (num_parms(args)>=6) {
897 CC->quickroom.QRfloor = extract_int(args,5);
900 lputroom(&CC->quickroom,CC->curr_rm);
902 /* adjust the floor reference counts */
903 lgetfloor(&flbuf,old_floor);
905 lputfloor(&flbuf,old_floor);
906 lgetfloor(&flbuf,CC->quickroom.QRfloor);
908 lputfloor(&flbuf,CC->quickroom.QRfloor);
910 /* create a room directory if necessary */
911 if (CC->quickroom.QRflags & QR_DIRECTORY) {
913 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
914 CC->quickroom.QRdirname);
918 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
920 cprintf("%d Ok\n",OK);
926 * get the name of the room aide for this room
928 void cmd_geta(void) {
929 struct usersupp usbuf;
931 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
932 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
936 if (CC->curr_rm < 0) {
937 cprintf("%d No current room.\n",ERROR);
941 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
942 cprintf("%d %s\n",OK,usbuf.fullname);
951 * set the room aide for this room
953 void cmd_seta(char *new_ra)
955 struct usersupp usbuf;
960 if (!(CC->logged_in)) {
961 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
965 if (!is_room_aide()) {
966 cprintf("%d Higher access required.\n",
967 ERROR+HIGHER_ACCESS_REQUIRED);
971 if (CC->curr_rm < 3) {
972 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
976 if (getuser(&usbuf,new_ra)!=0) {
980 newu = usbuf.usernum;
983 lgetroom(&CC->quickroom,CC->curr_rm);
985 if (CC->quickroom.QRroomaide != newu) {
988 CC->quickroom.QRroomaide = newu;
989 lputroom(&CC->quickroom,CC->curr_rm);
992 * We have to post the change notice _after_ writing changes to
993 * the room table, otherwise it would deadlock!
995 if (post_notice == 1) {
996 sprintf(buf,"%s is now room aide for %s>",
997 usbuf.fullname,CC->quickroom.QRname);
1000 cprintf("%d Ok\n",OK);
1005 * retrieve info file for this room
1007 void cmd_rinf(void) {
1012 sprintf(filename,"./info/%d",CC->curr_rm);
1013 info_fp = fopen(filename,"r");
1015 if (info_fp==NULL) {
1016 cprintf("%d No info file.\n",ERROR);
1020 cprintf("%d Info:\n",LISTING_FOLLOWS);
1021 while (fgets(buf, 256, info_fp) != NULL) {
1022 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1023 cprintf("%s\n", buf);
1030 * aide command: kill the current room
1032 void cmd_kill(char *argbuf)
1040 kill_ok = extract_int(argbuf,0);
1042 if (!(CC->logged_in)) {
1043 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1047 if (!is_room_aide()) {
1048 cprintf("%d Higher access required.\n",
1049 ERROR+HIGHER_ACCESS_REQUIRED);
1053 if (CC->curr_rm < 3) {
1054 cprintf("%d Can't kill this room.\n",ERROR+NOT_HERE);
1060 /* first flag the room record as not in use */
1061 lgetroom(&CC->quickroom,CC->curr_rm);
1062 CC->quickroom.QRflags=0;
1064 /* then delete the messages in the room */
1065 get_msglist(CC->curr_rm);
1066 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1067 MsgToDelete = MessageFromList(a);
1068 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1070 put_msglist(CC->curr_rm);
1073 cdb_delete(CDB_MSGLISTS, &CC->curr_rm, sizeof(int));
1075 lputroom(&CC->quickroom,CC->curr_rm);
1078 /* then decrement the reference count for the floor */
1079 lgetfloor(&flbuf,(int)CC->quickroom.QRfloor);
1080 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1081 lputfloor(&flbuf,(int)CC->quickroom.QRfloor);
1083 /* tell the world what we did */
1084 sprintf(aaa,"%s> killed by %s",CC->quickroom.QRname,CC->curr_user);
1087 cprintf("%d '%s' deleted.\n",OK,CC->quickroom.QRname);
1090 cprintf("%d ok to delete.\n",OK);
1096 * Find a free slot to create a new room in, or return -1 for error.
1097 * search_dir is the direction to search in. 1 causes this function to
1098 * return the first available slot, -1 gets the last available slot.
1100 * FIX This function can be eliminated during the cutover.
1102 int get_free_room_slot(int search_dir)
1105 struct quickroom qrbuf;
1107 st = ((search_dir>0) ? 3 : (MAXROOMS-1));
1109 for (a=st; ((a<MAXROOMS)&&(a>=3)); a=a+search_dir) {
1111 if ((qrbuf.QRflags & QR_INUSE)==0) return(a);
1118 * internal code to create a new room (returns room flags)
1120 unsigned create_room(int free_slot, char *new_room_name, int new_room_type, char *new_room_pass, int new_room_floor)
1122 struct quickroom qrbuf;
1126 lgetroom(&qrbuf,free_slot);
1127 strncpy(qrbuf.QRname,new_room_name,19);
1128 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1129 qrbuf.QRflags = QR_INUSE;
1130 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1131 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1132 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1133 qrbuf.QRroomaide = (-1L);
1134 if ((new_room_type > 0)&&(CREATAIDE==1))
1135 qrbuf.QRroomaide=CC->usersupp.usernum;
1136 qrbuf.QRhighest = 0L;
1138 qrbuf.QRfloor = new_room_floor;
1140 /* save what we just did... */
1141 lputroom(&qrbuf,free_slot);
1143 /* bump the reference count on whatever floor the room is on */
1144 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1145 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1146 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1148 /* be sure not to kick the creator out of the room! */
1149 lgetuser(&CC->usersupp,CC->curr_user);
1150 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1152 CC->usersupp.generation[free_slot] = qrbuf.QRgen;
1153 CC->usersupp.forget[free_slot] = (-1);
1155 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1156 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1157 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1158 lputuser(&CC->usersupp,CC->curr_user);
1160 /* resume our happy day */
1161 return(qrbuf.QRflags);
1166 * create a new room FIX Rework this to use name indexing
1168 void cmd_cre8(char *args)
1173 char new_room_name[256];
1175 char new_room_pass[256];
1179 struct quickroom qrbuf;
1182 cre8_ok = extract_int(args,0);
1183 extract(new_room_name,args,1);
1184 new_room_name[19] = 0;
1185 new_room_type = extract_int(args,2);
1186 extract(new_room_pass,args,3);
1187 new_room_pass[9] = 0;
1190 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1191 cprintf("%d Invalid room name.\n",ERROR);
1195 if (num_parms(args)>=5) {
1196 getfloor(&flbuf,extract_int(args,4));
1197 if ((flbuf.f_flags & F_INUSE) == 0) {
1198 cprintf("%d Invalid floor number.\n",
1199 ERROR+INVALID_FLOOR_OPERATION);
1203 new_room_floor = extract_int(args,4);
1207 if (!(CC->logged_in)) {
1208 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1212 if (CC->usersupp.axlevel<3) {
1213 cprintf("%d You need higher access to create rooms.\n",
1214 ERROR+HIGHER_ACCESS_REQUIRED);
1218 free_slot = get_free_room_slot(1);
1220 cprintf("%d There is no space available for a new room.\n",
1226 cprintf("%d ok to create...\n",OK);
1230 for (a=0; a<MAXROOMS; ++a) {
1232 if ( (!strcasecmp(qrbuf.QRname,new_room_name))
1233 && (qrbuf.QRflags & QR_INUSE) ) {
1234 cprintf("%d '%s' already exists.\n",
1235 ERROR,qrbuf.QRname);
1240 if ((new_room_type < 0) || (new_room_type > 3)) {
1241 cprintf("%d Invalid room type.\n",ERROR);
1245 newflags = create_room(free_slot,new_room_name,
1246 new_room_type,new_room_pass,new_room_floor);
1248 /* post a message in Aide> describing the new room */
1249 strncpy(aaa,new_room_name,255);
1250 strcat(aaa,"> created by ");
1251 strcat(aaa,CC->usersupp.fullname);
1252 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1253 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1254 if (newflags&QR_PASSWORDED) {
1255 strcat(aaa,"\n Password: ");
1256 strcat(aaa,new_room_pass);
1260 sprintf(aaa,"./info/%d",free_slot); /* delete old info file */
1262 sprintf(aaa,"./images/room.%d.gif",free_slot); /* and picture */
1265 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1270 void cmd_einf(char *ok)
1271 { /* enter info file for current room */
1273 char infofilename[32];
1276 if (!(CC->logged_in)) {
1277 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1281 if (!is_room_aide()) {
1282 cprintf("%d Higher access required.\n",
1283 ERROR+HIGHER_ACCESS_REQUIRED);
1288 cprintf("%d Ok.\n",OK);
1292 cprintf("%d Send info...\n",SEND_LISTING);
1294 sprintf(infofilename,"./info/%d",CC->curr_rm);
1296 fp=fopen(infofilename,"w");
1299 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1300 } while(strcmp(buf,"000"));
1303 /* now update the room index so people will see our new info */
1304 lgetroom(&CC->quickroom,CC->curr_rm); /* lock so no one steps on us */
1305 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1306 lputroom(&CC->quickroom,CC->curr_rm);
1311 * cmd_lflr() - List all known floors
1313 void cmd_lflr(void) {
1317 if (!(CC->logged_in)) {
1318 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1322 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1323 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1328 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1330 for (a=0; a<MAXFLOORS; ++a) {
1332 if (flbuf.f_flags & F_INUSE) {
1333 cprintf("%d|%s|%d\n",
1345 * create a new floor
1347 void cmd_cflr(char *argbuf)
1349 char new_floor_name[256];
1352 int free_slot = (-1);
1355 extract(new_floor_name,argbuf,0);
1356 cflr_ok = extract_int(argbuf,1);
1359 if (!(CC->logged_in)) {
1360 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1364 if (CC->usersupp.axlevel<6) {
1365 cprintf("%d You need higher access to create rooms.\n",
1366 ERROR+HIGHER_ACCESS_REQUIRED);
1370 for (a=0; a<MAXFLOORS; ++a) {
1373 /* note any free slots while we're scanning... */
1374 if ( ((flbuf.f_flags & F_INUSE)==0)
1375 && (free_slot < 0) ) free_slot = a;
1377 /* check to see if it already exists */
1378 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1379 && (flbuf.f_flags & F_INUSE) ) {
1380 cprintf("%d Floor '%s' already exists.\n",
1381 ERROR+ALREADY_EXISTS,
1389 cprintf("%d There is no space available for a new floor.\n",
1390 ERROR+INVALID_FLOOR_OPERATION);
1395 cprintf("%d ok to create...\n",OK);
1399 lgetfloor(&flbuf,free_slot);
1400 flbuf.f_flags = F_INUSE;
1401 flbuf.f_ref_count = 0;
1402 strncpy(flbuf.f_name,new_floor_name,255);
1403 lputfloor(&flbuf,free_slot);
1404 cprintf("%d %d\n",OK,free_slot);
1412 void cmd_kflr(char *argbuf)
1415 int floor_to_delete;
1419 floor_to_delete = extract_int(argbuf,0);
1420 kflr_ok = extract_int(argbuf,1);
1423 if (!(CC->logged_in)) {
1424 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1428 if (CC->usersupp.axlevel<6) {
1429 cprintf("%d You need higher access to delete floors.\n",
1430 ERROR+HIGHER_ACCESS_REQUIRED);
1434 lgetfloor(&flbuf,floor_to_delete);
1437 if ((flbuf.f_flags & F_INUSE) == 0) {
1438 cprintf("%d Floor %d not in use.\n",
1439 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1444 if (flbuf.f_ref_count != 0) {
1445 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1446 ERROR+INVALID_FLOOR_OPERATION,
1453 cprintf("%d Ok\n",OK);
1456 cprintf("%d Ok to delete...\n",OK);
1463 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1464 lputfloor(&flbuf,floor_to_delete);
1470 void cmd_eflr(char *argbuf)
1476 np = num_parms(argbuf);
1478 cprintf("%d Usage error.\n",ERROR);
1482 if (!(CC->logged_in)) {
1483 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1487 if (CC->usersupp.axlevel<6) {
1488 cprintf("%d You need higher access to edit floors.\n",
1489 ERROR+HIGHER_ACCESS_REQUIRED);
1493 floor_num = extract_int(argbuf,0);
1494 lgetfloor(&flbuf,floor_num);
1495 if ( (flbuf.f_flags & F_INUSE) == 0) {
1496 lputfloor(&flbuf,floor_num);
1497 cprintf("%d Floor %d is not in use.\n",
1498 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1501 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1502 lputfloor(&flbuf,floor_num);
1504 cprintf("%d Ok\n",OK);