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;
97 /*************** START OF OLD ROOM DATABASE FUNCTIONS ***********************/
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);
171 /*************** START OF NEW ROOM DATABASE FUNCTIONS ***********************/
173 * ngetroom() - retrieve room data from disk
175 void ngetroom(struct quickroom *qrbuf, char *room_name)
177 struct cdbdata *cdbqr;
178 char lowercase_name[20];
181 for (a=0; a<=strlen(room_name); ++a) {
182 lowercase_name[a] = tolower(room_name[a]);
185 bzero(qrbuf, sizeof(struct quickroom));
186 cdbqr = cdb_fetch(CDB_QUICKROOM,
187 lowercase_name, strlen(lowercase_name));
189 memcpy(qrbuf, cdbqr->ptr,
190 ( (cdbqr->len > sizeof(struct quickroom)) ?
191 sizeof(struct quickroom) : cdbqr->len) );
195 /** FIX ** VILE SLEAZY HACK ALERT!!
196 * This is a temporary fix until we can track down where room names
197 * are getting corrupted on some systems.
199 for (a=0; a<20; ++a) if (qrbuf->QRname[a] < 32) qrbuf->QRname[a] = 0;
200 qrbuf->QRname[19] = 0;
204 * lngetroom() - same as ngetroom() but locks the record (if supported)
206 void lngetroom(struct quickroom *qrbuf, char *room_name)
208 begin_critical_section(S_QUICKROOM);
209 ngetroom(qrbuf, room_name);
214 * nputroom() - store room data on disk
216 void nputroom(struct quickroom *qrbuf, char *room_name)
218 char lowercase_name[20];
221 for (a=0; a<=strlen(room_name); ++a) {
222 lowercase_name[a] = tolower(room_name[a]);
225 time(&qrbuf->QRmtime);
226 cdb_store(CDB_QUICKROOM, lowercase_name, strlen(lowercase_name),
227 qrbuf, sizeof(struct quickroom));
232 * lnputroom() - same as nputroom() but unlocks the record (if supported)
234 void lnputroom(struct quickroom *qrbuf, char *room_name)
237 nputroom(qrbuf, room_name);
238 end_critical_section(S_QUICKROOM);
242 /****************************************************************************/
245 * getfloor() - retrieve floor data from disk
247 void getfloor(struct floor *flbuf, int floor_num)
249 struct cdbdata *cdbfl;
251 bzero(flbuf, sizeof(struct floor));
252 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
254 memcpy(flbuf, cdbfl->ptr,
255 ( (cdbfl->len > sizeof(struct floor)) ?
256 sizeof(struct floor) : cdbfl->len) );
260 if (floor_num == 0) {
261 strcpy(flbuf->f_name, "Main Floor");
262 flbuf->f_flags = F_INUSE;
263 flbuf->f_ref_count = 3;
270 * lgetfloor() - same as getfloor() but locks the record (if supported)
272 void lgetfloor(struct floor *flbuf, int floor_num)
275 begin_critical_section(S_FLOORTAB);
276 getfloor(flbuf,floor_num);
281 * putfloor() - store floor data on disk
283 void putfloor(struct floor *flbuf, int floor_num)
285 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
286 flbuf, sizeof(struct floor));
291 * lputfloor() - same as putfloor() but unlocks the record (if supported)
293 void lputfloor(struct floor *flbuf, int floor_num)
296 putfloor(flbuf,floor_num);
297 end_critical_section(S_FLOORTAB);
303 * Traverse the room file...
305 void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) {
306 struct quickroom qrbuf;
307 struct cdbdata *cdbqr;
309 cdb_rewind(CDB_QUICKROOM);
311 while(cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
312 bzero(&qrbuf, sizeof(struct quickroom));
313 memcpy(&qrbuf, cdbqr->ptr,
314 ( (cdbqr->len > sizeof(struct quickroom)) ?
315 sizeof(struct quickroom) : cdbqr->len) );
317 if (qrbuf.QRflags & QR_INUSE) (*CallBack)(&qrbuf);
324 * get_msglist() - retrieve room message pointers
326 void get_msglist(int room_num)
328 struct cdbdata *cdbfr;
330 if (CC->msglist != NULL) {
337 cdbfr = cdb_fetch(CDB_MSGLISTS, &room_num, sizeof(int));
340 cdbfr = cdb_fetch(CDB_MAILBOXES, &CC->usersupp.usernum,
348 CC->msglist = malloc(cdbfr->len);
349 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
350 CC->num_msgs = cdbfr->len / sizeof(long);
356 * put_msglist() - retrieve room message pointers
358 void put_msglist(int room_num)
362 cdb_store(CDB_MSGLISTS, &room_num, sizeof(int),
363 CC->msglist, (CC->num_msgs * sizeof(long)) );
366 cdb_store(CDB_MAILBOXES, &CC->usersupp.usernum, sizeof(long),
367 CC->msglist, (CC->num_msgs * sizeof(long)) );
373 * MessageFromList() - get a message number from the list currently in memory
375 long MessageFromList(int whichpos) {
377 /* Return zero if the position is invalid */
378 if (whichpos >= CC->num_msgs) return 0L;
380 return(CC->msglist[whichpos]);
384 * SetMessageInList() - set a message number in the list currently in memory
386 void SetMessageInList(int whichpos, long newmsgnum) {
388 /* Return zero if the position is invalid */
389 if (whichpos >= CC->num_msgs) return;
391 CC->msglist[whichpos] = newmsgnum;
397 * sort message pointers
398 * (returns new msg count)
400 int sort_msglist(long listptrs[], int oldcount)
407 if (numitems < 2) return(oldcount);
410 for (a=numitems-2; a>=0; --a) {
411 for (b=0; b<=a; ++b) {
412 if (listptrs[b] > (listptrs[b+1])) {
414 hold2 = listptrs[b+1];
416 listptrs[b+1] = hold1;
421 /* and yank any nulls */
422 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
423 memcpy(&listptrs[0], &listptrs[1],
424 (sizeof(long) * (CC->num_msgs - 1)) );
434 * cmd_lrms() - List all accessible rooms, known or forgotten
436 void cmd_lrms_backend(struct quickroom *qrbuf) {
437 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
438 & (UA_KNOWN | UA_ZAPPED)))
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_lrms(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 Accessible rooms:\n",LISTING_FOLLOWS);
462 ForEachRoom(cmd_lrms_backend);
469 * cmd_lkra() - List all known rooms
471 void cmd_lkra_backend(struct quickroom *qrbuf) {
472 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
474 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
475 ||((CC->FloorBeingSearched)<0)) )
476 cprintf("%s|%u|%d\n",
477 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
480 void cmd_lkra(char *argbuf)
482 CC->FloorBeingSearched = (-1);
483 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
485 if (!(CC->logged_in)) {
486 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
490 if (getuser(&CC->usersupp,CC->curr_user)) {
491 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
495 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
497 ForEachRoom(cmd_lkra_backend);
504 * cmd_lkrn() - List all known rooms with new messages
506 void cmd_lkrn_backend(struct quickroom *qrbuf) {
509 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
511 && (ra & UA_HASNEWMSGS)
512 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
513 ||((CC->FloorBeingSearched)<0)) )
514 cprintf("%s|%u|%d\n",
515 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
518 void cmd_lkrn(char *argbuf)
520 CC->FloorBeingSearched = (-1);
521 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
523 if (!(CC->logged_in)) {
524 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
528 if (getuser(&CC->usersupp,CC->curr_user)) {
529 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
533 cprintf("%d Rooms w/ new msgs:\n",LISTING_FOLLOWS);
535 ForEachRoom(cmd_lkrn_backend);
542 * cmd_lkro() - List all known rooms
544 void cmd_lkro_backend(struct quickroom *qrbuf) {
547 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
549 && ((ra & UA_HASNEWMSGS)==0)
550 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
551 ||((CC->FloorBeingSearched)<0)) )
552 cprintf("%s|%u|%d\n",
553 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
556 void cmd_lkro(char *argbuf)
558 CC->FloorBeingSearched = (-1);
559 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
561 if (!(CC->logged_in)) {
562 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
566 if (getuser(&CC->usersupp,CC->curr_user)) {
567 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
571 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
573 ForEachRoom(cmd_lkro_backend);
580 * cmd_lzrm() - List all forgotten rooms
582 void cmd_lzrm_backend(struct quickroom *qrbuf) {
585 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
586 if ( (ra & UA_GOTOALLOWED)
588 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
589 ||((CC->FloorBeingSearched)<0)) )
590 cprintf("%s|%u|%d\n",
591 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
594 void cmd_lzrm(char *argbuf)
596 CC->FloorBeingSearched = (-1);
597 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
599 if (!(CC->logged_in)) {
600 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
604 if (getuser(&CC->usersupp,CC->curr_user)) {
605 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
609 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
611 ForEachRoom(cmd_lzrm_backend);
617 void usergoto(int where, int display_result)
620 int new_messages = 0;
621 int total_messages = 0;
625 int newmailcount = 0;
629 getroom(&CC->quickroom,CC->curr_rm);
630 lgetuser(&CC->usersupp,CC->curr_user);
631 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
633 /* old method - remove when we're ready */
634 CC->usersupp.forget[CC->curr_rm]=(-1);
635 CC->usersupp.generation[CC->curr_rm]=CC->quickroom.QRgen;
638 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
639 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
641 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
642 lputuser(&CC->usersupp,CC->curr_user);
644 /* check for new mail */
645 newmailcount = NewMailCount();
647 /* set info to 1 if the user needs to read the room's info file */
648 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
651 get_msglist(CC->curr_rm);
652 for (a=0; a<CC->num_msgs; ++a) {
653 if (MessageFromList(a)>0L) {
655 if (MessageFromList(a) > vbuf.v_lastseen) {
662 if (CC->curr_rm == 1) rmailflag = 1;
665 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
666 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
669 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
671 CC->quickroom.QRname,
672 new_messages, total_messages,
673 info,CC->quickroom.QRflags,
674 CC->quickroom.QRhighest,
676 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
678 if (CC->quickroom.QRflags & QR_PRIVATE) {
679 set_wtmpsupp("<private room>");
682 set_wtmpsupp(CC->quickroom.QRname);
688 * cmd_goto() - goto a new room
690 void cmd_goto(char *gargs)
692 struct quickroom QRscratch;
695 char bbb[20],towhere[32],password[20];
697 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
698 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
702 extract(towhere,gargs,0);
703 extract(password,gargs,1);
706 getuser(&CC->usersupp,CC->curr_user);
708 /* FIX This is the primary bit of code that needs to be rewritten
709 * during the cutover. Search for rooms by name rather than by
710 * position in the file. A total rewrite may be necessary.
712 for (a=0; a<MAXROOMS; ++a) {
713 getroom(&QRscratch,a);
714 if ((a==0)&&(!strcasecmp(towhere,"_BASEROOM_"))) {
715 strncpy(towhere,QRscratch.QRname,31);
717 if ((a==1)&&(!strcasecmp(towhere,"_MAIL_"))) {
718 strncpy(towhere,QRscratch.QRname,31);
720 if ((!strcasecmp(QRscratch.QRname,config.c_twitroom))
721 &&(!strcasecmp(towhere,"_BITBUCKET_"))) {
722 strncpy(towhere,QRscratch.QRname,31);
724 strcpy(bbb,QRscratch.QRname);
727 /* let internal programs go directly to any room */
728 if (((CC->internal_pgm))&&(!strcasecmp(bbb,towhere))) {
733 /* normal clients have to pass through security */
735 (strcasecmp(bbb,towhere)==0)
736 && ((QRscratch.QRflags&QR_INUSE)!=0)
738 && ( ((QRscratch.QRflags&QR_PREFONLY)==0)
739 || (CC->usersupp.axlevel>=5)
742 && ( (a!=2) || (CC->usersupp.axlevel>=6) )
744 && ( ((QRscratch.QRflags&QR_PRIVATE)==0)
745 || (QRscratch.QRflags&QR_GUESSNAME)
746 || (CC->usersupp.axlevel>=6)
747 || (QRscratch.QRflags&QR_PASSWORDED)
748 || (QRscratch.QRgen==CC->usersupp.generation[a])
756 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
757 (CC->usersupp.axlevel<6) &&
758 (QRscratch.QRgen!=CC->usersupp.generation[a]) &&
759 (strcasecmp(QRscratch.QRpasswd,password))
761 cprintf("%d wrong or missing passwd\n",
762 ERROR+PASSWORD_REQUIRED);
771 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
775 void cmd_whok(void) {
776 struct usersupp temp;
777 struct cdbdata *cdbus;
779 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
780 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
783 getuser(&CC->usersupp,CC->curr_user);
785 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
786 cprintf("%d Higher access required.\n",
787 ERROR+HIGHER_ACCESS_REQUIRED);
791 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
792 cdb_rewind(CDB_USERSUPP);
793 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
794 bzero(&temp, sizeof(struct usersupp));
795 memcpy(&temp, cdbus->ptr, cdbus->len);
797 if ((CC->quickroom.QRflags & QR_INUSE)
798 && ( (CC->curr_rm!=2) || (temp.axlevel>=6) )
799 && (CC->quickroom.QRgen != (temp.forget[CC->curr_rm]) )
801 && ( ((CC->quickroom.QRflags&QR_PREFONLY)==0)
805 && ( ((CC->quickroom.QRflags&QR_PRIVATE)==0)
807 || (CC->quickroom.QRgen==(temp.generation[CC->curr_rm]))
810 && (strncmp(temp.fullname,"000",3))
812 ) cprintf("%s\n",temp.fullname);
819 * RDIR command for room directory
821 void cmd_rdir(void) {
828 if (!(CC->logged_in)) {
829 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
833 getroom(&CC->quickroom,CC->curr_rm);
834 getuser(&CC->usersupp,CC->curr_user);
836 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
837 cprintf("%d not here.\n",ERROR+NOT_HERE);
841 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
842 && (CC->usersupp.axlevel<6)
843 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
844 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
848 cprintf("%d %s|%s/files/%s\n",
849 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
851 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
852 BBSDIR,CC->quickroom.QRdirname,CC->temp);
855 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
857 if (fd==NULL) fd=fopen("/dev/null","r");
859 ls = fopen(CC->temp,"r");
860 while (fgets(flnm,256,ls)!=NULL) {
861 flnm[strlen(flnm)-1]=0;
862 if (strcasecmp(flnm,"filedir")) {
863 sprintf(buf,"%s/files/%s/%s",
864 BBSDIR,CC->quickroom.QRdirname,flnm);
868 while ((fgets(buf,256,fd)!=NULL)
869 &&(strlen(comment)==0)) {
870 buf[strlen(buf)-1] = 0;
871 if ((!strncasecmp(buf,flnm,strlen(flnm)))
872 && (buf[strlen(flnm)]==' '))
874 &buf[strlen(flnm)+1],255);
876 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
887 * get room parameters (aide or room aide command)
889 void cmd_getr(void) {
890 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
891 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
895 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
896 cprintf("%d Higher access required.\n",
897 ERROR+HIGHER_ACCESS_REQUIRED);
901 if (CC->curr_rm < 3) {
902 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
906 getroom(&CC->quickroom,CC->curr_rm);
907 cprintf("%d%c%s|%s|%s|%d|%d\n",
909 CC->quickroom.QRname,
910 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
911 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
912 CC->quickroom.QRflags,
913 (int)CC->quickroom.QRfloor);
918 * set room parameters (aide or room aide command)
920 void cmd_setr(char *args) {
925 if (!(CC->logged_in)) {
926 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
930 if (!is_room_aide()) {
931 cprintf("%d Higher access required.\n",
932 ERROR+HIGHER_ACCESS_REQUIRED);
936 if (CC->curr_rm < 3) {
937 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
941 if (num_parms(args)>=6) {
942 getfloor(&flbuf,extract_int(args,5));
943 if ((flbuf.f_flags & F_INUSE) == 0) {
944 cprintf("%d Invalid floor number.\n",
945 ERROR+INVALID_FLOOR_OPERATION);
950 lgetroom(&CC->quickroom,CC->curr_rm);
951 extract(buf,args,0); buf[20]=0;
952 strncpy(CC->quickroom.QRname,buf,19);
953 extract(buf,args,1); buf[10]=0;
954 strncpy(CC->quickroom.QRpasswd,buf,9);
955 extract(buf,args,2); buf[15]=0;
956 strncpy(CC->quickroom.QRdirname,buf,19);
957 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
959 /* Clean up a client boo-boo: if the client set the room to
960 * guess-name or passworded, ensure that the private flag is
963 if ((CC->quickroom.QRflags & QR_GUESSNAME)
964 ||(CC->quickroom.QRflags & QR_PASSWORDED))
965 CC->quickroom.QRflags |= QR_PRIVATE;
967 /* Kick everyone out if the client requested it (by changing the
968 * room's generation number)
970 if (extract_int(args,4)) {
971 time(&CC->quickroom.QRgen);
974 old_floor = CC->quickroom.QRfloor;
975 if (num_parms(args)>=6) {
976 CC->quickroom.QRfloor = extract_int(args,5);
979 lputroom(&CC->quickroom,CC->curr_rm);
981 /* adjust the floor reference counts */
982 lgetfloor(&flbuf,old_floor);
984 lputfloor(&flbuf,old_floor);
985 lgetfloor(&flbuf,CC->quickroom.QRfloor);
987 lputfloor(&flbuf,CC->quickroom.QRfloor);
989 /* create a room directory if necessary */
990 if (CC->quickroom.QRflags & QR_DIRECTORY) {
992 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
993 CC->quickroom.QRdirname);
997 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
999 cprintf("%d Ok\n",OK);
1005 * get the name of the room aide for this room
1007 void cmd_geta(void) {
1008 struct usersupp usbuf;
1010 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
1011 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1015 if (CC->curr_rm < 0) {
1016 cprintf("%d No current room.\n",ERROR);
1020 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
1021 cprintf("%d %s\n",OK,usbuf.fullname);
1024 cprintf("%d \n",OK);
1030 * set the room aide for this room
1032 void cmd_seta(char *new_ra)
1034 struct usersupp usbuf;
1039 if (!(CC->logged_in)) {
1040 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1044 if (!is_room_aide()) {
1045 cprintf("%d Higher access required.\n",
1046 ERROR+HIGHER_ACCESS_REQUIRED);
1050 if (CC->curr_rm < 3) {
1051 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1055 if (getuser(&usbuf,new_ra)!=0) {
1059 newu = usbuf.usernum;
1062 lgetroom(&CC->quickroom,CC->curr_rm);
1064 if (CC->quickroom.QRroomaide != newu) {
1067 CC->quickroom.QRroomaide = newu;
1068 lputroom(&CC->quickroom,CC->curr_rm);
1071 * We have to post the change notice _after_ writing changes to
1072 * the room table, otherwise it would deadlock!
1074 if (post_notice == 1) {
1075 sprintf(buf,"%s is now room aide for %s>",
1076 usbuf.fullname,CC->quickroom.QRname);
1079 cprintf("%d Ok\n",OK);
1084 * retrieve info file for this room
1086 void cmd_rinf(void) {
1091 sprintf(filename,"./info/%d",CC->curr_rm);
1092 info_fp = fopen(filename,"r");
1094 if (info_fp==NULL) {
1095 cprintf("%d No info file.\n",ERROR);
1099 cprintf("%d Info:\n",LISTING_FOLLOWS);
1100 while (fgets(buf, 256, info_fp) != NULL) {
1101 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1102 cprintf("%s\n", buf);
1109 * aide command: kill the current room
1111 void cmd_kill(char *argbuf)
1119 kill_ok = extract_int(argbuf,0);
1121 if (!(CC->logged_in)) {
1122 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1126 if (!is_room_aide()) {
1127 cprintf("%d Higher access required.\n",
1128 ERROR+HIGHER_ACCESS_REQUIRED);
1132 if (CC->curr_rm < 3) {
1133 cprintf("%d Can't kill this room.\n",ERROR+NOT_HERE);
1139 /* first flag the room record as not in use */
1140 lgetroom(&CC->quickroom,CC->curr_rm);
1141 CC->quickroom.QRflags=0;
1143 /* then delete the messages in the room */
1144 get_msglist(CC->curr_rm);
1145 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1146 MsgToDelete = MessageFromList(a);
1147 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1149 put_msglist(CC->curr_rm);
1152 cdb_delete(CDB_MSGLISTS, &CC->curr_rm, sizeof(int));
1154 lputroom(&CC->quickroom,CC->curr_rm);
1157 /* then decrement the reference count for the floor */
1158 lgetfloor(&flbuf,(int)CC->quickroom.QRfloor);
1159 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1160 lputfloor(&flbuf,(int)CC->quickroom.QRfloor);
1162 /* tell the world what we did */
1163 sprintf(aaa,"%s> killed by %s",CC->quickroom.QRname,CC->curr_user);
1166 cprintf("%d '%s' deleted.\n",OK,CC->quickroom.QRname);
1169 cprintf("%d ok to delete.\n",OK);
1175 * Find a free slot to create a new room in, or return -1 for error.
1176 * search_dir is the direction to search in. 1 causes this function to
1177 * return the first available slot, -1 gets the last available slot.
1179 * FIX This function can be eliminated during the cutover.
1181 int get_free_room_slot(int search_dir)
1184 struct quickroom qrbuf;
1186 st = ((search_dir>0) ? 3 : (MAXROOMS-1));
1188 for (a=st; ((a<MAXROOMS)&&(a>=3)); a=a+search_dir) {
1190 if ((qrbuf.QRflags & QR_INUSE)==0) return(a);
1197 * internal code to create a new room (returns room flags)
1199 unsigned create_room(int free_slot, char *new_room_name, int new_room_type, char *new_room_pass, int new_room_floor)
1201 struct quickroom qrbuf;
1205 lgetroom(&qrbuf,free_slot);
1206 strncpy(qrbuf.QRname,new_room_name,19);
1207 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1208 qrbuf.QRflags = QR_INUSE;
1209 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1210 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1211 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1212 qrbuf.QRroomaide = (-1L);
1213 if ((new_room_type > 0)&&(CREATAIDE==1))
1214 qrbuf.QRroomaide=CC->usersupp.usernum;
1215 qrbuf.QRhighest = 0L;
1217 qrbuf.QRfloor = new_room_floor;
1219 /* save what we just did... */
1220 lputroom(&qrbuf,free_slot);
1222 /* bump the reference count on whatever floor the room is on */
1223 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1224 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1225 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1227 /* be sure not to kick the creator out of the room! */
1228 lgetuser(&CC->usersupp,CC->curr_user);
1229 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1231 CC->usersupp.generation[free_slot] = qrbuf.QRgen;
1232 CC->usersupp.forget[free_slot] = (-1);
1234 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1235 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1236 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1237 lputuser(&CC->usersupp,CC->curr_user);
1239 /* resume our happy day */
1240 return(qrbuf.QRflags);
1245 * create a new room FIX Rework this to use name indexing
1247 void cmd_cre8(char *args)
1252 char new_room_name[256];
1254 char new_room_pass[256];
1258 struct quickroom qrbuf;
1261 cre8_ok = extract_int(args,0);
1262 extract(new_room_name,args,1);
1263 new_room_name[19] = 0;
1264 new_room_type = extract_int(args,2);
1265 extract(new_room_pass,args,3);
1266 new_room_pass[9] = 0;
1269 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1270 cprintf("%d Invalid room name.\n",ERROR);
1274 if (num_parms(args)>=5) {
1275 getfloor(&flbuf,extract_int(args,4));
1276 if ((flbuf.f_flags & F_INUSE) == 0) {
1277 cprintf("%d Invalid floor number.\n",
1278 ERROR+INVALID_FLOOR_OPERATION);
1282 new_room_floor = extract_int(args,4);
1286 if (!(CC->logged_in)) {
1287 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1291 if (CC->usersupp.axlevel<3) {
1292 cprintf("%d You need higher access to create rooms.\n",
1293 ERROR+HIGHER_ACCESS_REQUIRED);
1297 free_slot = get_free_room_slot(1);
1299 cprintf("%d There is no space available for a new room.\n",
1305 cprintf("%d ok to create...\n",OK);
1309 for (a=0; a<MAXROOMS; ++a) {
1311 if ( (!strcasecmp(qrbuf.QRname,new_room_name))
1312 && (qrbuf.QRflags & QR_INUSE) ) {
1313 cprintf("%d '%s' already exists.\n",
1314 ERROR,qrbuf.QRname);
1319 if ((new_room_type < 0) || (new_room_type > 3)) {
1320 cprintf("%d Invalid room type.\n",ERROR);
1324 newflags = create_room(free_slot,new_room_name,
1325 new_room_type,new_room_pass,new_room_floor);
1327 /* post a message in Aide> describing the new room */
1328 strncpy(aaa,new_room_name,255);
1329 strcat(aaa,"> created by ");
1330 strcat(aaa,CC->usersupp.fullname);
1331 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1332 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1333 if (newflags&QR_PASSWORDED) {
1334 strcat(aaa,"\n Password: ");
1335 strcat(aaa,new_room_pass);
1339 sprintf(aaa,"./info/%d",free_slot); /* delete old info file */
1341 sprintf(aaa,"./images/room.%d.gif",free_slot); /* and picture */
1344 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1349 void cmd_einf(char *ok)
1350 { /* enter info file for current room */
1352 char infofilename[32];
1355 if (!(CC->logged_in)) {
1356 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1360 if (!is_room_aide()) {
1361 cprintf("%d Higher access required.\n",
1362 ERROR+HIGHER_ACCESS_REQUIRED);
1367 cprintf("%d Ok.\n",OK);
1371 cprintf("%d Send info...\n",SEND_LISTING);
1373 sprintf(infofilename,"./info/%d",CC->curr_rm);
1375 fp=fopen(infofilename,"w");
1378 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1379 } while(strcmp(buf,"000"));
1382 /* now update the room index so people will see our new info */
1383 lgetroom(&CC->quickroom,CC->curr_rm); /* lock so no one steps on us */
1384 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1385 lputroom(&CC->quickroom,CC->curr_rm);
1390 * cmd_lflr() - List all known floors
1392 void cmd_lflr(void) {
1396 if (!(CC->logged_in)) {
1397 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1401 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1402 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1407 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1409 for (a=0; a<MAXFLOORS; ++a) {
1411 if (flbuf.f_flags & F_INUSE) {
1412 cprintf("%d|%s|%d\n",
1424 * create a new floor
1426 void cmd_cflr(char *argbuf)
1428 char new_floor_name[256];
1431 int free_slot = (-1);
1434 extract(new_floor_name,argbuf,0);
1435 cflr_ok = extract_int(argbuf,1);
1438 if (!(CC->logged_in)) {
1439 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1443 if (CC->usersupp.axlevel<6) {
1444 cprintf("%d You need higher access to create rooms.\n",
1445 ERROR+HIGHER_ACCESS_REQUIRED);
1449 for (a=0; a<MAXFLOORS; ++a) {
1452 /* note any free slots while we're scanning... */
1453 if ( ((flbuf.f_flags & F_INUSE)==0)
1454 && (free_slot < 0) ) free_slot = a;
1456 /* check to see if it already exists */
1457 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1458 && (flbuf.f_flags & F_INUSE) ) {
1459 cprintf("%d Floor '%s' already exists.\n",
1460 ERROR+ALREADY_EXISTS,
1468 cprintf("%d There is no space available for a new floor.\n",
1469 ERROR+INVALID_FLOOR_OPERATION);
1474 cprintf("%d ok to create...\n",OK);
1478 lgetfloor(&flbuf,free_slot);
1479 flbuf.f_flags = F_INUSE;
1480 flbuf.f_ref_count = 0;
1481 strncpy(flbuf.f_name,new_floor_name,255);
1482 lputfloor(&flbuf,free_slot);
1483 cprintf("%d %d\n",OK,free_slot);
1491 void cmd_kflr(char *argbuf)
1494 int floor_to_delete;
1498 floor_to_delete = extract_int(argbuf,0);
1499 kflr_ok = extract_int(argbuf,1);
1502 if (!(CC->logged_in)) {
1503 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1507 if (CC->usersupp.axlevel<6) {
1508 cprintf("%d You need higher access to delete floors.\n",
1509 ERROR+HIGHER_ACCESS_REQUIRED);
1513 lgetfloor(&flbuf,floor_to_delete);
1516 if ((flbuf.f_flags & F_INUSE) == 0) {
1517 cprintf("%d Floor %d not in use.\n",
1518 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1523 if (flbuf.f_ref_count != 0) {
1524 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1525 ERROR+INVALID_FLOOR_OPERATION,
1532 cprintf("%d Ok\n",OK);
1535 cprintf("%d Ok to delete...\n",OK);
1542 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1543 lputfloor(&flbuf,floor_to_delete);
1549 void cmd_eflr(char *argbuf)
1555 np = num_parms(argbuf);
1557 cprintf("%d Usage error.\n",ERROR);
1561 if (!(CC->logged_in)) {
1562 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1566 if (CC->usersupp.axlevel<6) {
1567 cprintf("%d You need higher access to edit floors.\n",
1568 ERROR+HIGHER_ACCESS_REQUIRED);
1572 floor_num = extract_int(argbuf,0);
1573 lgetfloor(&flbuf,floor_num);
1574 if ( (flbuf.f_flags & F_INUSE) == 0) {
1575 lputfloor(&flbuf,floor_num);
1576 cprintf("%d Floor %d is not in use.\n",
1577 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1580 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1581 lputfloor(&flbuf,floor_num);
1583 cprintf("%d Ok\n",OK);