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)
547 int new_messages = 0;
548 int total_messages = 0;
552 int newmailcount = 0;
556 getroom(&CC->quickroom,CC->curr_rm);
557 lgetuser(&CC->usersupp,CC->curr_user);
558 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
560 /* old method - remove when we're ready */
561 CC->usersupp.forget[CC->curr_rm]=(-1);
562 CC->usersupp.generation[CC->curr_rm]=CC->quickroom.QRgen;
565 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
566 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
568 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
569 lputuser(&CC->usersupp,CC->curr_user);
571 /* check for new mail */
572 newmailcount = NewMailCount();
574 /* set info to 1 if the user needs to read the room's info file */
575 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
578 get_msglist(CC->curr_rm);
579 for (a=0; a<CC->num_msgs; ++a) {
580 if (MessageFromList(a)>0L) {
582 if (MessageFromList(a) > vbuf.v_lastseen) {
589 if (CC->curr_rm == 1) rmailflag = 1;
592 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
593 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
596 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
598 CC->quickroom.QRname,
599 new_messages, total_messages,
600 info,CC->quickroom.QRflags,
601 CC->quickroom.QRhighest,
603 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
605 if (CC->quickroom.QRflags & QR_PRIVATE) {
606 set_wtmpsupp("<private room>");
609 set_wtmpsupp(CC->quickroom.QRname);
615 * cmd_goto() - goto a new room
617 void cmd_goto(char *gargs)
619 struct quickroom QRscratch;
622 char bbb[20],towhere[32],password[20];
624 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
625 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
629 extract(towhere,gargs,0);
630 extract(password,gargs,1);
633 getuser(&CC->usersupp,CC->curr_user);
635 /* FIX This is the primary bit of code that needs to be rewritten
636 * during the cutover. Search for rooms by name rather than by
637 * position in the file. A total rewrite may be necessary.
639 for (a=0; a<MAXROOMS; ++a) {
640 getroom(&QRscratch,a);
641 if ((a==0)&&(!strcasecmp(towhere,"_BASEROOM_"))) {
642 strncpy(towhere,QRscratch.QRname,31);
644 if ((a==1)&&(!strcasecmp(towhere,"_MAIL_"))) {
645 strncpy(towhere,QRscratch.QRname,31);
647 if ((!strcasecmp(QRscratch.QRname,config.c_twitroom))
648 &&(!strcasecmp(towhere,"_BITBUCKET_"))) {
649 strncpy(towhere,QRscratch.QRname,31);
651 strcpy(bbb,QRscratch.QRname);
654 /* let internal programs go directly to any room */
655 if (((CC->internal_pgm))&&(!strcasecmp(bbb,towhere))) {
660 /* normal clients have to pass through security */
662 (strcasecmp(bbb,towhere)==0)
663 && ((QRscratch.QRflags&QR_INUSE)!=0)
665 && ( ((QRscratch.QRflags&QR_PREFONLY)==0)
666 || (CC->usersupp.axlevel>=5)
669 && ( (a!=2) || (CC->usersupp.axlevel>=6) )
671 && ( ((QRscratch.QRflags&QR_PRIVATE)==0)
672 || (QRscratch.QRflags&QR_GUESSNAME)
673 || (CC->usersupp.axlevel>=6)
674 || (QRscratch.QRflags&QR_PASSWORDED)
675 || (QRscratch.QRgen==CC->usersupp.generation[a])
683 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
684 (CC->usersupp.axlevel<6) &&
685 (QRscratch.QRgen!=CC->usersupp.generation[a]) &&
686 (strcasecmp(QRscratch.QRpasswd,password))
688 cprintf("%d wrong or missing passwd\n",
689 ERROR+PASSWORD_REQUIRED);
698 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
702 void cmd_whok(void) {
703 struct usersupp temp;
704 struct cdbdata *cdbus;
706 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
707 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
710 getuser(&CC->usersupp,CC->curr_user);
712 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
713 cprintf("%d Higher access required.\n",
714 ERROR+HIGHER_ACCESS_REQUIRED);
718 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
719 cdb_rewind(CDB_USERSUPP);
720 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
721 bzero(&temp, sizeof(struct usersupp));
722 memcpy(&temp, cdbus->ptr, cdbus->len);
724 if ((CC->quickroom.QRflags & QR_INUSE)
725 && ( (CC->curr_rm!=2) || (temp.axlevel>=6) )
726 && (CC->quickroom.QRgen != (temp.forget[CC->curr_rm]) )
728 && ( ((CC->quickroom.QRflags&QR_PREFONLY)==0)
732 && ( ((CC->quickroom.QRflags&QR_PRIVATE)==0)
734 || (CC->quickroom.QRgen==(temp.generation[CC->curr_rm]))
737 && (strncmp(temp.fullname,"000",3))
739 ) cprintf("%s\n",temp.fullname);
746 * RDIR command for room directory
748 void cmd_rdir(void) {
755 if (!(CC->logged_in)) {
756 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
760 getroom(&CC->quickroom,CC->curr_rm);
761 getuser(&CC->usersupp,CC->curr_user);
763 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
764 cprintf("%d not here.\n",ERROR+NOT_HERE);
768 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
769 && (CC->usersupp.axlevel<6)
770 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
771 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
775 cprintf("%d %s|%s/files/%s\n",
776 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
778 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
779 BBSDIR,CC->quickroom.QRdirname,CC->temp);
782 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
784 if (fd==NULL) fd=fopen("/dev/null","r");
786 ls = fopen(CC->temp,"r");
787 while (fgets(flnm,256,ls)!=NULL) {
788 flnm[strlen(flnm)-1]=0;
789 if (strcasecmp(flnm,"filedir")) {
790 sprintf(buf,"%s/files/%s/%s",
791 BBSDIR,CC->quickroom.QRdirname,flnm);
795 while ((fgets(buf,256,fd)!=NULL)
796 &&(strlen(comment)==0)) {
797 buf[strlen(buf)-1] = 0;
798 if ((!strncasecmp(buf,flnm,strlen(flnm)))
799 && (buf[strlen(flnm)]==' '))
801 &buf[strlen(flnm)+1],255);
803 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
814 * get room parameters (aide or room aide command)
816 void cmd_getr(void) {
817 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
818 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
822 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
823 cprintf("%d Higher access required.\n",
824 ERROR+HIGHER_ACCESS_REQUIRED);
828 if (CC->curr_rm < 3) {
829 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
833 getroom(&CC->quickroom,CC->curr_rm);
834 cprintf("%d%c%s|%s|%s|%d|%d\n",
836 CC->quickroom.QRname,
837 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
838 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
839 CC->quickroom.QRflags,
840 (int)CC->quickroom.QRfloor);
845 * set room parameters (aide or room aide command)
847 void cmd_setr(char *args) {
852 if (!(CC->logged_in)) {
853 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
857 if (!is_room_aide()) {
858 cprintf("%d Higher access required.\n",
859 ERROR+HIGHER_ACCESS_REQUIRED);
863 if (CC->curr_rm < 3) {
864 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
868 if (num_parms(args)>=6) {
869 getfloor(&flbuf,extract_int(args,5));
870 if ((flbuf.f_flags & F_INUSE) == 0) {
871 cprintf("%d Invalid floor number.\n",
872 ERROR+INVALID_FLOOR_OPERATION);
877 lgetroom(&CC->quickroom,CC->curr_rm);
878 extract(buf,args,0); buf[20]=0;
879 strncpy(CC->quickroom.QRname,buf,19);
880 extract(buf,args,1); buf[10]=0;
881 strncpy(CC->quickroom.QRpasswd,buf,9);
882 extract(buf,args,2); buf[15]=0;
883 strncpy(CC->quickroom.QRdirname,buf,19);
884 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
886 /* Clean up a client boo-boo: if the client set the room to
887 * guess-name or passworded, ensure that the private flag is
890 if ((CC->quickroom.QRflags & QR_GUESSNAME)
891 ||(CC->quickroom.QRflags & QR_PASSWORDED))
892 CC->quickroom.QRflags |= QR_PRIVATE;
894 /* Kick everyone out if the client requested it (by changing the
895 * room's generation number)
897 if (extract_int(args,4)) {
898 time(&CC->quickroom.QRgen);
901 old_floor = CC->quickroom.QRfloor;
902 if (num_parms(args)>=6) {
903 CC->quickroom.QRfloor = extract_int(args,5);
906 lputroom(&CC->quickroom,CC->curr_rm);
908 /* adjust the floor reference counts */
909 lgetfloor(&flbuf,old_floor);
911 lputfloor(&flbuf,old_floor);
912 lgetfloor(&flbuf,CC->quickroom.QRfloor);
914 lputfloor(&flbuf,CC->quickroom.QRfloor);
916 /* create a room directory if necessary */
917 if (CC->quickroom.QRflags & QR_DIRECTORY) {
919 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
920 CC->quickroom.QRdirname);
924 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
926 cprintf("%d Ok\n",OK);
932 * get the name of the room aide for this room
934 void cmd_geta(void) {
935 struct usersupp usbuf;
937 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
938 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
942 if (CC->curr_rm < 0) {
943 cprintf("%d No current room.\n",ERROR);
947 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
948 cprintf("%d %s\n",OK,usbuf.fullname);
957 * set the room aide for this room
959 void cmd_seta(char *new_ra)
961 struct usersupp usbuf;
966 if (!(CC->logged_in)) {
967 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
971 if (!is_room_aide()) {
972 cprintf("%d Higher access required.\n",
973 ERROR+HIGHER_ACCESS_REQUIRED);
977 if (CC->curr_rm < 3) {
978 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
982 if (getuser(&usbuf,new_ra)!=0) {
986 newu = usbuf.usernum;
989 lgetroom(&CC->quickroom,CC->curr_rm);
991 if (CC->quickroom.QRroomaide != newu) {
994 CC->quickroom.QRroomaide = newu;
995 lputroom(&CC->quickroom,CC->curr_rm);
998 * We have to post the change notice _after_ writing changes to
999 * the room table, otherwise it would deadlock!
1001 if (post_notice == 1) {
1002 sprintf(buf,"%s is now room aide for %s>",
1003 usbuf.fullname,CC->quickroom.QRname);
1006 cprintf("%d Ok\n",OK);
1011 * retrieve info file for this room
1013 void cmd_rinf(void) {
1018 sprintf(filename,"./info/%d",CC->curr_rm);
1019 info_fp = fopen(filename,"r");
1021 if (info_fp==NULL) {
1022 cprintf("%d No info file.\n",ERROR);
1026 cprintf("%d Info:\n",LISTING_FOLLOWS);
1027 while (fgets(buf, 256, info_fp) != NULL) {
1028 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1029 cprintf("%s\n", buf);
1036 * aide command: kill the current room
1038 void cmd_kill(char *argbuf)
1046 kill_ok = extract_int(argbuf,0);
1048 if (!(CC->logged_in)) {
1049 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1053 if (!is_room_aide()) {
1054 cprintf("%d Higher access required.\n",
1055 ERROR+HIGHER_ACCESS_REQUIRED);
1059 if (CC->curr_rm < 3) {
1060 cprintf("%d Can't kill this room.\n",ERROR+NOT_HERE);
1066 /* first flag the room record as not in use */
1067 lgetroom(&CC->quickroom,CC->curr_rm);
1068 CC->quickroom.QRflags=0;
1070 /* then delete the messages in the room */
1071 get_msglist(CC->curr_rm);
1072 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1073 MsgToDelete = MessageFromList(a);
1074 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1076 put_msglist(CC->curr_rm);
1079 cdb_delete(CDB_MSGLISTS, &CC->curr_rm, sizeof(int));
1081 lputroom(&CC->quickroom,CC->curr_rm);
1084 /* then decrement the reference count for the floor */
1085 lgetfloor(&flbuf,(int)CC->quickroom.QRfloor);
1086 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1087 lputfloor(&flbuf,(int)CC->quickroom.QRfloor);
1089 /* tell the world what we did */
1090 sprintf(aaa,"%s> killed by %s",CC->quickroom.QRname,CC->curr_user);
1093 cprintf("%d '%s' deleted.\n",OK,CC->quickroom.QRname);
1096 cprintf("%d ok to delete.\n",OK);
1102 * Find a free slot to create a new room in, or return -1 for error.
1103 * search_dir is the direction to search in. 1 causes this function to
1104 * return the first available slot, -1 gets the last available slot.
1106 * FIX This function can be eliminated during the cutover.
1108 int get_free_room_slot(int search_dir)
1111 struct quickroom qrbuf;
1113 st = ((search_dir>0) ? 3 : (MAXROOMS-1));
1115 for (a=st; ((a<MAXROOMS)&&(a>=3)); a=a+search_dir) {
1117 if ((qrbuf.QRflags & QR_INUSE)==0) return(a);
1124 * internal code to create a new room (returns room flags)
1126 unsigned create_room(int free_slot, char *new_room_name, int new_room_type, char *new_room_pass, int new_room_floor)
1128 struct quickroom qrbuf;
1132 lgetroom(&qrbuf,free_slot);
1133 strncpy(qrbuf.QRname,new_room_name,19);
1134 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1135 qrbuf.QRflags = QR_INUSE;
1136 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1137 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1138 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1139 qrbuf.QRroomaide = (-1L);
1140 if ((new_room_type > 0)&&(CREATAIDE==1))
1141 qrbuf.QRroomaide=CC->usersupp.usernum;
1142 qrbuf.QRhighest = 0L;
1144 qrbuf.QRfloor = new_room_floor;
1146 /* save what we just did... */
1147 lputroom(&qrbuf,free_slot);
1149 /* bump the reference count on whatever floor the room is on */
1150 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1151 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1152 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1154 /* be sure not to kick the creator out of the room! */
1155 lgetuser(&CC->usersupp,CC->curr_user);
1156 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1158 CC->usersupp.generation[free_slot] = qrbuf.QRgen;
1159 CC->usersupp.forget[free_slot] = (-1);
1161 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1162 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1163 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1164 lputuser(&CC->usersupp,CC->curr_user);
1166 /* resume our happy day */
1167 return(qrbuf.QRflags);
1172 * create a new room FIX Rework this to use name indexing
1174 void cmd_cre8(char *args)
1179 char new_room_name[256];
1181 char new_room_pass[256];
1185 struct quickroom qrbuf;
1188 cre8_ok = extract_int(args,0);
1189 extract(new_room_name,args,1);
1190 new_room_name[19] = 0;
1191 new_room_type = extract_int(args,2);
1192 extract(new_room_pass,args,3);
1193 new_room_pass[9] = 0;
1196 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1197 cprintf("%d Invalid room name.\n",ERROR);
1201 if (num_parms(args)>=5) {
1202 getfloor(&flbuf,extract_int(args,4));
1203 if ((flbuf.f_flags & F_INUSE) == 0) {
1204 cprintf("%d Invalid floor number.\n",
1205 ERROR+INVALID_FLOOR_OPERATION);
1209 new_room_floor = extract_int(args,4);
1213 if (!(CC->logged_in)) {
1214 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1218 if (CC->usersupp.axlevel<3) {
1219 cprintf("%d You need higher access to create rooms.\n",
1220 ERROR+HIGHER_ACCESS_REQUIRED);
1224 free_slot = get_free_room_slot(1);
1226 cprintf("%d There is no space available for a new room.\n",
1232 cprintf("%d ok to create...\n",OK);
1236 for (a=0; a<MAXROOMS; ++a) {
1238 if ( (!strcasecmp(qrbuf.QRname,new_room_name))
1239 && (qrbuf.QRflags & QR_INUSE) ) {
1240 cprintf("%d '%s' already exists.\n",
1241 ERROR,qrbuf.QRname);
1246 if ((new_room_type < 0) || (new_room_type > 3)) {
1247 cprintf("%d Invalid room type.\n",ERROR);
1251 newflags = create_room(free_slot,new_room_name,
1252 new_room_type,new_room_pass,new_room_floor);
1254 /* post a message in Aide> describing the new room */
1255 strncpy(aaa,new_room_name,255);
1256 strcat(aaa,"> created by ");
1257 strcat(aaa,CC->usersupp.fullname);
1258 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1259 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1260 if (newflags&QR_PASSWORDED) {
1261 strcat(aaa,"\n Password: ");
1262 strcat(aaa,new_room_pass);
1266 sprintf(aaa,"./info/%d",free_slot); /* delete old info file */
1268 sprintf(aaa,"./images/room.%d.gif",free_slot); /* and picture */
1271 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1276 void cmd_einf(char *ok)
1277 { /* enter info file for current room */
1279 char infofilename[32];
1282 if (!(CC->logged_in)) {
1283 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1287 if (!is_room_aide()) {
1288 cprintf("%d Higher access required.\n",
1289 ERROR+HIGHER_ACCESS_REQUIRED);
1294 cprintf("%d Ok.\n",OK);
1298 cprintf("%d Send info...\n",SEND_LISTING);
1300 sprintf(infofilename,"./info/%d",CC->curr_rm);
1302 fp=fopen(infofilename,"w");
1305 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1306 } while(strcmp(buf,"000"));
1309 /* now update the room index so people will see our new info */
1310 lgetroom(&CC->quickroom,CC->curr_rm); /* lock so no one steps on us */
1311 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1312 lputroom(&CC->quickroom,CC->curr_rm);
1317 * cmd_lflr() - List all known floors
1319 void cmd_lflr(void) {
1323 if (!(CC->logged_in)) {
1324 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1328 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1329 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1334 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1336 for (a=0; a<MAXFLOORS; ++a) {
1338 if (flbuf.f_flags & F_INUSE) {
1339 cprintf("%d|%s|%d\n",
1351 * create a new floor
1353 void cmd_cflr(char *argbuf)
1355 char new_floor_name[256];
1358 int free_slot = (-1);
1361 extract(new_floor_name,argbuf,0);
1362 cflr_ok = extract_int(argbuf,1);
1365 if (!(CC->logged_in)) {
1366 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1370 if (CC->usersupp.axlevel<6) {
1371 cprintf("%d You need higher access to create rooms.\n",
1372 ERROR+HIGHER_ACCESS_REQUIRED);
1376 for (a=0; a<MAXFLOORS; ++a) {
1379 /* note any free slots while we're scanning... */
1380 if ( ((flbuf.f_flags & F_INUSE)==0)
1381 && (free_slot < 0) ) free_slot = a;
1383 /* check to see if it already exists */
1384 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1385 && (flbuf.f_flags & F_INUSE) ) {
1386 cprintf("%d Floor '%s' already exists.\n",
1387 ERROR+ALREADY_EXISTS,
1395 cprintf("%d There is no space available for a new floor.\n",
1396 ERROR+INVALID_FLOOR_OPERATION);
1401 cprintf("%d ok to create...\n",OK);
1405 lgetfloor(&flbuf,free_slot);
1406 flbuf.f_flags = F_INUSE;
1407 flbuf.f_ref_count = 0;
1408 strncpy(flbuf.f_name,new_floor_name,255);
1409 lputfloor(&flbuf,free_slot);
1410 cprintf("%d %d\n",OK,free_slot);
1418 void cmd_kflr(char *argbuf)
1421 int floor_to_delete;
1425 floor_to_delete = extract_int(argbuf,0);
1426 kflr_ok = extract_int(argbuf,1);
1429 if (!(CC->logged_in)) {
1430 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1434 if (CC->usersupp.axlevel<6) {
1435 cprintf("%d You need higher access to delete floors.\n",
1436 ERROR+HIGHER_ACCESS_REQUIRED);
1440 lgetfloor(&flbuf,floor_to_delete);
1443 if ((flbuf.f_flags & F_INUSE) == 0) {
1444 cprintf("%d Floor %d not in use.\n",
1445 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1450 if (flbuf.f_ref_count != 0) {
1451 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1452 ERROR+INVALID_FLOOR_OPERATION,
1459 cprintf("%d Ok\n",OK);
1462 cprintf("%d Ok to delete...\n",OK);
1469 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1470 lputfloor(&flbuf,floor_to_delete);
1476 void cmd_eflr(char *argbuf)
1482 np = num_parms(argbuf);
1484 cprintf("%d Usage error.\n",ERROR);
1488 if (!(CC->logged_in)) {
1489 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1493 if (CC->usersupp.axlevel<6) {
1494 cprintf("%d You need higher access to edit floors.\n",
1495 ERROR+HIGHER_ACCESS_REQUIRED);
1499 floor_num = extract_int(argbuf,0);
1500 lgetfloor(&flbuf,floor_num);
1501 if ( (flbuf.f_flags & F_INUSE) == 0) {
1502 lputfloor(&flbuf,floor_num);
1503 cprintf("%d Floor %d is not in use.\n",
1504 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1507 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1508 lputfloor(&flbuf,floor_num);
1510 cprintf("%d Ok\n",OK);