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);
628 for (a=0; a<MAXROOMS; ++a) {
629 getroom(&QRscratch,a);
630 if ((a==0)&&(!strcasecmp(towhere,"_BASEROOM_"))) {
631 strncpy(towhere,QRscratch.QRname,31);
633 if ((a==1)&&(!strcasecmp(towhere,"_MAIL_"))) {
634 strncpy(towhere,QRscratch.QRname,31);
636 if ((!strcasecmp(QRscratch.QRname,config.c_twitroom))
637 &&(!strcasecmp(towhere,"_BITBUCKET_"))) {
638 strncpy(towhere,QRscratch.QRname,31);
640 strcpy(bbb,QRscratch.QRname);
643 /* let internal programs go directly to any room */
644 if (((CC->internal_pgm))&&(!strcasecmp(bbb,towhere))) {
649 /* normal clients have to pass through security */
651 (strcasecmp(bbb,towhere)==0)
652 && ((QRscratch.QRflags&QR_INUSE)!=0)
654 && ( ((QRscratch.QRflags&QR_PREFONLY)==0)
655 || (CC->usersupp.axlevel>=5)
658 && ( (a!=2) || (CC->usersupp.axlevel>=6) )
660 && ( ((QRscratch.QRflags&QR_PRIVATE)==0)
661 || (QRscratch.QRflags&QR_GUESSNAME)
662 || (CC->usersupp.axlevel>=6)
663 || (QRscratch.QRflags&QR_PASSWORDED)
664 || (QRscratch.QRgen==CC->usersupp.generation[a])
672 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
673 (CC->usersupp.axlevel<6) &&
674 (QRscratch.QRgen!=CC->usersupp.generation[a]) &&
675 (strcasecmp(QRscratch.QRpasswd,password))
677 cprintf("%d wrong or missing passwd\n",
678 ERROR+PASSWORD_REQUIRED);
687 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
691 void cmd_whok(void) {
692 struct usersupp temp;
693 struct cdbdata *cdbus;
695 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
696 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
699 getuser(&CC->usersupp,CC->curr_user);
701 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
702 cprintf("%d Higher access required.\n",
703 ERROR+HIGHER_ACCESS_REQUIRED);
707 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
708 cdb_rewind(CDB_USERSUPP);
709 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
710 bzero(&temp, sizeof(struct usersupp));
711 memcpy(&temp, cdbus->ptr, cdbus->len);
713 if ((CC->quickroom.QRflags & QR_INUSE)
714 && ( (CC->curr_rm!=2) || (temp.axlevel>=6) )
715 && (CC->quickroom.QRgen != (temp.forget[CC->curr_rm]) )
717 && ( ((CC->quickroom.QRflags&QR_PREFONLY)==0)
721 && ( ((CC->quickroom.QRflags&QR_PRIVATE)==0)
723 || (CC->quickroom.QRgen==(temp.generation[CC->curr_rm]))
726 && (strncmp(temp.fullname,"000",3))
728 ) cprintf("%s\n",temp.fullname);
735 * RDIR command for room directory
737 void cmd_rdir(void) {
744 if (!(CC->logged_in)) {
745 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
749 getroom(&CC->quickroom,CC->curr_rm);
750 getuser(&CC->usersupp,CC->curr_user);
752 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
753 cprintf("%d not here.\n",ERROR+NOT_HERE);
757 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
758 && (CC->usersupp.axlevel<6)
759 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
760 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
764 cprintf("%d %s|%s/files/%s\n",
765 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
767 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
768 BBSDIR,CC->quickroom.QRdirname,CC->temp);
771 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
773 if (fd==NULL) fd=fopen("/dev/null","r");
775 ls = fopen(CC->temp,"r");
776 while (fgets(flnm,256,ls)!=NULL) {
777 flnm[strlen(flnm)-1]=0;
778 if (strcasecmp(flnm,"filedir")) {
779 sprintf(buf,"%s/files/%s/%s",
780 BBSDIR,CC->quickroom.QRdirname,flnm);
784 while ((fgets(buf,256,fd)!=NULL)
785 &&(strlen(comment)==0)) {
786 buf[strlen(buf)-1] = 0;
787 if ((!strncasecmp(buf,flnm,strlen(flnm)))
788 && (buf[strlen(flnm)]==' '))
790 &buf[strlen(flnm)+1],255);
792 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
803 * get room parameters (aide or room aide command)
805 void cmd_getr(void) {
806 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
807 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
811 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
812 cprintf("%d Higher access required.\n",
813 ERROR+HIGHER_ACCESS_REQUIRED);
817 if (CC->curr_rm < 3) {
818 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
822 getroom(&CC->quickroom,CC->curr_rm);
823 cprintf("%d%c%s|%s|%s|%d|%d\n",
825 CC->quickroom.QRname,
826 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
827 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
828 CC->quickroom.QRflags,
829 (int)CC->quickroom.QRfloor);
834 * set room parameters (aide or room aide command)
836 void cmd_setr(char *args) {
841 if (!(CC->logged_in)) {
842 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
846 if (!is_room_aide()) {
847 cprintf("%d Higher access required.\n",
848 ERROR+HIGHER_ACCESS_REQUIRED);
852 if (CC->curr_rm < 3) {
853 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
857 if (num_parms(args)>=6) {
858 getfloor(&flbuf,extract_int(args,5));
859 if ((flbuf.f_flags & F_INUSE) == 0) {
860 cprintf("%d Invalid floor number.\n",
861 ERROR+INVALID_FLOOR_OPERATION);
866 lgetroom(&CC->quickroom,CC->curr_rm);
867 extract(buf,args,0); buf[20]=0;
868 strncpy(CC->quickroom.QRname,buf,19);
869 extract(buf,args,1); buf[10]=0;
870 strncpy(CC->quickroom.QRpasswd,buf,9);
871 extract(buf,args,2); buf[15]=0;
872 strncpy(CC->quickroom.QRdirname,buf,19);
873 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
875 /* Clean up a client boo-boo: if the client set the room to
876 * guess-name or passworded, ensure that the private flag is
879 if ((CC->quickroom.QRflags & QR_GUESSNAME)
880 ||(CC->quickroom.QRflags & QR_PASSWORDED))
881 CC->quickroom.QRflags |= QR_PRIVATE;
883 /* Kick everyone out if the client requested it (by changing the
884 * room's generation number)
886 if (extract_int(args,4)) {
887 time(&CC->quickroom.QRgen);
890 old_floor = CC->quickroom.QRfloor;
891 if (num_parms(args)>=6) {
892 CC->quickroom.QRfloor = extract_int(args,5);
895 lputroom(&CC->quickroom,CC->curr_rm);
897 /* adjust the floor reference counts */
898 lgetfloor(&flbuf,old_floor);
900 lputfloor(&flbuf,old_floor);
901 lgetfloor(&flbuf,CC->quickroom.QRfloor);
903 lputfloor(&flbuf,CC->quickroom.QRfloor);
905 /* create a room directory if necessary */
906 if (CC->quickroom.QRflags & QR_DIRECTORY) {
908 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
909 CC->quickroom.QRdirname);
913 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
915 cprintf("%d Ok\n",OK);
921 * get the name of the room aide for this room
923 void cmd_geta(void) {
924 struct usersupp usbuf;
926 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
927 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
931 if (CC->curr_rm < 0) {
932 cprintf("%d No current room.\n",ERROR);
936 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
937 cprintf("%d %s\n",OK,usbuf.fullname);
946 * set the room aide for this room
948 void cmd_seta(char *new_ra)
950 struct usersupp usbuf;
955 if (!(CC->logged_in)) {
956 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
960 if (!is_room_aide()) {
961 cprintf("%d Higher access required.\n",
962 ERROR+HIGHER_ACCESS_REQUIRED);
966 if (CC->curr_rm < 3) {
967 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
971 if (getuser(&usbuf,new_ra)!=0) {
975 newu = usbuf.usernum;
978 lgetroom(&CC->quickroom,CC->curr_rm);
980 if (CC->quickroom.QRroomaide != newu) {
983 CC->quickroom.QRroomaide = newu;
984 lputroom(&CC->quickroom,CC->curr_rm);
987 * We have to post the change notice _after_ writing changes to
988 * the room table, otherwise it would deadlock!
990 if (post_notice == 1) {
991 sprintf(buf,"%s is now room aide for %s>",
992 usbuf.fullname,CC->quickroom.QRname);
995 cprintf("%d Ok\n",OK);
1000 * retrieve info file for this room
1002 void cmd_rinf(void) {
1007 sprintf(filename,"./info/%d",CC->curr_rm);
1008 info_fp = fopen(filename,"r");
1010 if (info_fp==NULL) {
1011 cprintf("%d No info file.\n",ERROR);
1015 cprintf("%d Info:\n",LISTING_FOLLOWS);
1016 while (fgets(buf, 256, info_fp) != NULL) {
1017 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1018 cprintf("%s\n", buf);
1025 * aide command: kill the current room
1027 void cmd_kill(char *argbuf)
1035 kill_ok = extract_int(argbuf,0);
1037 if (!(CC->logged_in)) {
1038 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1042 if (!is_room_aide()) {
1043 cprintf("%d Higher access required.\n",
1044 ERROR+HIGHER_ACCESS_REQUIRED);
1048 if (CC->curr_rm < 3) {
1049 cprintf("%d Can't kill this room.\n",ERROR+NOT_HERE);
1055 /* first flag the room record as not in use */
1056 lgetroom(&CC->quickroom,CC->curr_rm);
1057 CC->quickroom.QRflags=0;
1059 /* then delete the messages in the room */
1060 get_msglist(CC->curr_rm);
1061 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1062 MsgToDelete = MessageFromList(a);
1063 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1065 put_msglist(CC->curr_rm);
1068 cdb_delete(CDB_MSGLISTS, &CC->curr_rm, sizeof(int));
1070 lputroom(&CC->quickroom,CC->curr_rm);
1073 /* then decrement the reference count for the floor */
1074 lgetfloor(&flbuf,(int)CC->quickroom.QRfloor);
1075 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1076 lputfloor(&flbuf,(int)CC->quickroom.QRfloor);
1078 /* tell the world what we did */
1079 sprintf(aaa,"%s> killed by %s",CC->quickroom.QRname,CC->curr_user);
1082 cprintf("%d '%s' deleted.\n",OK,CC->quickroom.QRname);
1085 cprintf("%d ok to delete.\n",OK);
1091 * Find a free slot to create a new room in, or return -1 for error.
1092 * search_dir is the direction to search in. 1 causes this function to
1093 * return the first available slot, -1 gets the last available slot.
1095 int get_free_room_slot(int search_dir)
1098 struct quickroom qrbuf;
1100 st = ((search_dir>0) ? 3 : (MAXROOMS-1));
1102 for (a=st; ((a<MAXROOMS)&&(a>=3)); a=a+search_dir) {
1104 if ((qrbuf.QRflags & QR_INUSE)==0) return(a);
1111 * internal code to create a new room (returns room flags)
1113 unsigned create_room(int free_slot, char *new_room_name, int new_room_type, char *new_room_pass, int new_room_floor)
1115 struct quickroom qrbuf;
1119 lgetroom(&qrbuf,free_slot);
1120 strncpy(qrbuf.QRname,new_room_name,19);
1121 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1122 qrbuf.QRflags = QR_INUSE;
1123 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1124 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1125 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1126 qrbuf.QRroomaide = (-1L);
1127 if ((new_room_type > 0)&&(CREATAIDE==1))
1128 qrbuf.QRroomaide=CC->usersupp.usernum;
1129 qrbuf.QRhighest = 0L;
1131 qrbuf.QRfloor = new_room_floor;
1133 /* save what we just did... */
1134 lputroom(&qrbuf,free_slot);
1136 /* bump the reference count on whatever floor the room is on */
1137 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1138 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1139 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1141 /* be sure not to kick the creator out of the room! */
1142 lgetuser(&CC->usersupp,CC->curr_user);
1143 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1145 CC->usersupp.generation[free_slot] = qrbuf.QRgen;
1146 CC->usersupp.forget[free_slot] = (-1);
1148 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1149 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1150 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1151 lputuser(&CC->usersupp,CC->curr_user);
1153 /* resume our happy day */
1154 return(qrbuf.QRflags);
1161 void cmd_cre8(char *args)
1166 char new_room_name[256];
1168 char new_room_pass[256];
1172 struct quickroom qrbuf;
1175 cre8_ok = extract_int(args,0);
1176 extract(new_room_name,args,1);
1177 new_room_name[19] = 0;
1178 new_room_type = extract_int(args,2);
1179 extract(new_room_pass,args,3);
1180 new_room_pass[9] = 0;
1183 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1184 cprintf("%d Invalid room name.\n",ERROR);
1188 if (num_parms(args)>=5) {
1189 getfloor(&flbuf,extract_int(args,4));
1190 if ((flbuf.f_flags & F_INUSE) == 0) {
1191 cprintf("%d Invalid floor number.\n",
1192 ERROR+INVALID_FLOOR_OPERATION);
1196 new_room_floor = extract_int(args,4);
1200 if (!(CC->logged_in)) {
1201 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1205 if (CC->usersupp.axlevel<3) {
1206 cprintf("%d You need higher access to create rooms.\n",
1207 ERROR+HIGHER_ACCESS_REQUIRED);
1211 free_slot = get_free_room_slot(1);
1213 cprintf("%d There is no space available for a new room.\n",
1219 cprintf("%d ok to create...\n",OK);
1223 for (a=0; a<MAXROOMS; ++a) {
1225 if ( (!strcasecmp(qrbuf.QRname,new_room_name))
1226 && (qrbuf.QRflags & QR_INUSE) ) {
1227 cprintf("%d '%s' already exists.\n",
1228 ERROR,qrbuf.QRname);
1233 if ((new_room_type < 0) || (new_room_type > 3)) {
1234 cprintf("%d Invalid room type.\n",ERROR);
1238 newflags = create_room(free_slot,new_room_name,
1239 new_room_type,new_room_pass,new_room_floor);
1241 /* post a message in Aide> describing the new room */
1242 strncpy(aaa,new_room_name,255);
1243 strcat(aaa,"> created by ");
1244 strcat(aaa,CC->usersupp.fullname);
1245 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1246 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1247 if (newflags&QR_PASSWORDED) {
1248 strcat(aaa,"\n Password: ");
1249 strcat(aaa,new_room_pass);
1253 sprintf(aaa,"./info/%d",free_slot); /* delete old info file */
1255 sprintf(aaa,"./images/room.%d.gif",free_slot); /* and picture */
1258 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1263 void cmd_einf(char *ok)
1264 { /* enter info file for current room */
1266 char infofilename[32];
1269 if (!(CC->logged_in)) {
1270 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1274 if (!is_room_aide()) {
1275 cprintf("%d Higher access required.\n",
1276 ERROR+HIGHER_ACCESS_REQUIRED);
1281 cprintf("%d Ok.\n",OK);
1285 cprintf("%d Send info...\n",SEND_LISTING);
1287 sprintf(infofilename,"./info/%d",CC->curr_rm);
1289 fp=fopen(infofilename,"w");
1292 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1293 } while(strcmp(buf,"000"));
1296 /* now update the room index so people will see our new info */
1297 lgetroom(&CC->quickroom,CC->curr_rm); /* lock so no one steps on us */
1298 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1299 lputroom(&CC->quickroom,CC->curr_rm);
1304 * cmd_lflr() - List all known floors
1306 void cmd_lflr(void) {
1310 if (!(CC->logged_in)) {
1311 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1315 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1316 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1321 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1323 for (a=0; a<MAXFLOORS; ++a) {
1325 if (flbuf.f_flags & F_INUSE) {
1326 cprintf("%d|%s|%d\n",
1338 * create a new floor
1340 void cmd_cflr(char *argbuf)
1342 char new_floor_name[256];
1345 int free_slot = (-1);
1348 extract(new_floor_name,argbuf,0);
1349 cflr_ok = extract_int(argbuf,1);
1352 if (!(CC->logged_in)) {
1353 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1357 if (CC->usersupp.axlevel<6) {
1358 cprintf("%d You need higher access to create rooms.\n",
1359 ERROR+HIGHER_ACCESS_REQUIRED);
1363 for (a=0; a<MAXFLOORS; ++a) {
1366 /* note any free slots while we're scanning... */
1367 if ( ((flbuf.f_flags & F_INUSE)==0)
1368 && (free_slot < 0) ) free_slot = a;
1370 /* check to see if it already exists */
1371 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1372 && (flbuf.f_flags & F_INUSE) ) {
1373 cprintf("%d Floor '%s' already exists.\n",
1374 ERROR+ALREADY_EXISTS,
1382 cprintf("%d There is no space available for a new floor.\n",
1383 ERROR+INVALID_FLOOR_OPERATION);
1388 cprintf("%d ok to create...\n",OK);
1392 lgetfloor(&flbuf,free_slot);
1393 flbuf.f_flags = F_INUSE;
1394 flbuf.f_ref_count = 0;
1395 strncpy(flbuf.f_name,new_floor_name,255);
1396 lputfloor(&flbuf,free_slot);
1397 cprintf("%d %d\n",OK,free_slot);
1405 void cmd_kflr(char *argbuf)
1408 int floor_to_delete;
1412 floor_to_delete = extract_int(argbuf,0);
1413 kflr_ok = extract_int(argbuf,1);
1416 if (!(CC->logged_in)) {
1417 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1421 if (CC->usersupp.axlevel<6) {
1422 cprintf("%d You need higher access to delete floors.\n",
1423 ERROR+HIGHER_ACCESS_REQUIRED);
1427 lgetfloor(&flbuf,floor_to_delete);
1430 if ((flbuf.f_flags & F_INUSE) == 0) {
1431 cprintf("%d Floor %d not in use.\n",
1432 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1437 if (flbuf.f_ref_count != 0) {
1438 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1439 ERROR+INVALID_FLOOR_OPERATION,
1446 cprintf("%d Ok\n",OK);
1449 cprintf("%d Ok to delete...\n",OK);
1456 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1457 lputfloor(&flbuf,floor_to_delete);
1463 void cmd_eflr(char *argbuf)
1469 np = num_parms(argbuf);
1471 cprintf("%d Usage error.\n",ERROR);
1475 if (!(CC->logged_in)) {
1476 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1480 if (CC->usersupp.axlevel<6) {
1481 cprintf("%d You need higher access to edit floors.\n",
1482 ERROR+HIGHER_ACCESS_REQUIRED);
1486 floor_num = extract_int(argbuf,0);
1487 lgetfloor(&flbuf,floor_num);
1488 if ( (flbuf.f_flags & F_INUSE) == 0) {
1489 lputfloor(&flbuf,floor_num);
1490 cprintf("%d Floor %d is not in use.\n",
1491 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1494 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1495 lputfloor(&flbuf,floor_num);
1497 cprintf("%d Ok\n",OK);