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 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
634 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
636 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
637 lputuser(&CC->usersupp,CC->curr_user);
639 /* check for new mail */
640 newmailcount = NewMailCount();
642 /* set info to 1 if the user needs to read the room's info file */
643 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
646 get_msglist(CC->curr_rm);
647 for (a=0; a<CC->num_msgs; ++a) {
648 if (MessageFromList(a)>0L) {
650 if (MessageFromList(a) > vbuf.v_lastseen) {
657 if (CC->curr_rm == 1) rmailflag = 1;
660 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
661 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
664 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
666 CC->quickroom.QRname,
667 new_messages, total_messages,
668 info,CC->quickroom.QRflags,
669 CC->quickroom.QRhighest,
671 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
673 if (CC->quickroom.QRflags & QR_PRIVATE) {
674 set_wtmpsupp("<private room>");
677 set_wtmpsupp(CC->quickroom.QRname);
683 * cmd_goto() - goto a new room
685 void cmd_goto(char *gargs)
687 struct quickroom QRscratch;
690 char bbb[20],towhere[32],password[20];
692 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
693 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
697 extract(towhere,gargs,0);
698 extract(password,gargs,1);
701 getuser(&CC->usersupp,CC->curr_user);
703 /* FIX This is the primary bit of code that needs to be rewritten
704 * during the cutover. Search for rooms by name rather than by
705 * position in the file. A total rewrite may be necessary.
707 for (a=0; a<MAXROOMS; ++a) {
708 getroom(&QRscratch,a);
709 if ((a==0)&&(!strcasecmp(towhere,"_BASEROOM_"))) {
710 strncpy(towhere,QRscratch.QRname,31);
712 if ((a==1)&&(!strcasecmp(towhere,"_MAIL_"))) {
713 strncpy(towhere,QRscratch.QRname,31);
715 if ((!strcasecmp(QRscratch.QRname,config.c_twitroom))
716 &&(!strcasecmp(towhere,"_BITBUCKET_"))) {
717 strncpy(towhere,QRscratch.QRname,31);
719 strcpy(bbb,QRscratch.QRname);
722 /* let internal programs go directly to any room */
723 if (((CC->internal_pgm))&&(!strcasecmp(bbb,towhere))) {
728 if (!strcasecmp(bbb, towhere)) {
730 /* See if there is an existing user/room relationship */
731 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
733 /* normal clients have to pass through security */
734 if (ra & UA_GOTOALLOWED) ok = 1;
737 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
738 ((ra & UA_KNOWN) == 0) &&
739 (strcasecmp(QRscratch.QRpasswd,password))
741 cprintf("%d wrong or missing passwd\n",
742 ERROR+PASSWORD_REQUIRED);
753 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
757 void cmd_whok(void) {
758 struct usersupp temp;
759 struct cdbdata *cdbus;
761 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
762 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
765 getuser(&CC->usersupp,CC->curr_user);
767 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
768 cprintf("%d Higher access required.\n",
769 ERROR+HIGHER_ACCESS_REQUIRED);
773 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
774 cdb_rewind(CDB_USERSUPP);
775 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
776 bzero(&temp, sizeof(struct usersupp));
777 memcpy(&temp, cdbus->ptr, cdbus->len);
780 if ( (CC->quickroom.QRflags & QR_INUSE)
781 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
782 ) cprintf("%s\n",temp.fullname);
789 * RDIR command for room directory
791 void cmd_rdir(void) {
798 if (!(CC->logged_in)) {
799 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
803 getroom(&CC->quickroom,CC->curr_rm);
804 getuser(&CC->usersupp,CC->curr_user);
806 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
807 cprintf("%d not here.\n",ERROR+NOT_HERE);
811 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
812 && (CC->usersupp.axlevel<6)
813 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
814 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
818 cprintf("%d %s|%s/files/%s\n",
819 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
821 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
822 BBSDIR,CC->quickroom.QRdirname,CC->temp);
825 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
827 if (fd==NULL) fd=fopen("/dev/null","r");
829 ls = fopen(CC->temp,"r");
830 while (fgets(flnm,256,ls)!=NULL) {
831 flnm[strlen(flnm)-1]=0;
832 if (strcasecmp(flnm,"filedir")) {
833 sprintf(buf,"%s/files/%s/%s",
834 BBSDIR,CC->quickroom.QRdirname,flnm);
838 while ((fgets(buf,256,fd)!=NULL)
839 &&(strlen(comment)==0)) {
840 buf[strlen(buf)-1] = 0;
841 if ((!strncasecmp(buf,flnm,strlen(flnm)))
842 && (buf[strlen(flnm)]==' '))
844 &buf[strlen(flnm)+1],255);
846 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
857 * get room parameters (aide or room aide command)
859 void cmd_getr(void) {
860 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
861 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
865 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
866 cprintf("%d Higher access required.\n",
867 ERROR+HIGHER_ACCESS_REQUIRED);
871 if (CC->curr_rm < 3) {
872 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
876 getroom(&CC->quickroom,CC->curr_rm);
877 cprintf("%d%c%s|%s|%s|%d|%d\n",
879 CC->quickroom.QRname,
880 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
881 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
882 CC->quickroom.QRflags,
883 (int)CC->quickroom.QRfloor);
888 * set room parameters (aide or room aide command)
890 void cmd_setr(char *args) {
895 if (!(CC->logged_in)) {
896 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
900 if (!is_room_aide()) {
901 cprintf("%d Higher access required.\n",
902 ERROR+HIGHER_ACCESS_REQUIRED);
906 if (CC->curr_rm < 3) {
907 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
911 if (num_parms(args)>=6) {
912 getfloor(&flbuf,extract_int(args,5));
913 if ((flbuf.f_flags & F_INUSE) == 0) {
914 cprintf("%d Invalid floor number.\n",
915 ERROR+INVALID_FLOOR_OPERATION);
920 lgetroom(&CC->quickroom,CC->curr_rm);
921 extract(buf,args,0); buf[20]=0;
922 strncpy(CC->quickroom.QRname,buf,19);
923 extract(buf,args,1); buf[10]=0;
924 strncpy(CC->quickroom.QRpasswd,buf,9);
925 extract(buf,args,2); buf[15]=0;
926 strncpy(CC->quickroom.QRdirname,buf,19);
927 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
929 /* Clean up a client boo-boo: if the client set the room to
930 * guess-name or passworded, ensure that the private flag is
933 if ((CC->quickroom.QRflags & QR_GUESSNAME)
934 ||(CC->quickroom.QRflags & QR_PASSWORDED))
935 CC->quickroom.QRflags |= QR_PRIVATE;
937 /* Kick everyone out if the client requested it (by changing the
938 * room's generation number)
940 if (extract_int(args,4)) {
941 time(&CC->quickroom.QRgen);
944 old_floor = CC->quickroom.QRfloor;
945 if (num_parms(args)>=6) {
946 CC->quickroom.QRfloor = extract_int(args,5);
949 lputroom(&CC->quickroom,CC->curr_rm);
951 /* adjust the floor reference counts */
952 lgetfloor(&flbuf,old_floor);
954 lputfloor(&flbuf,old_floor);
955 lgetfloor(&flbuf,CC->quickroom.QRfloor);
957 lputfloor(&flbuf,CC->quickroom.QRfloor);
959 /* create a room directory if necessary */
960 if (CC->quickroom.QRflags & QR_DIRECTORY) {
962 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
963 CC->quickroom.QRdirname);
967 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
969 cprintf("%d Ok\n",OK);
975 * get the name of the room aide for this room
977 void cmd_geta(void) {
978 struct usersupp usbuf;
980 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
981 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
985 if (CC->curr_rm < 0) {
986 cprintf("%d No current room.\n",ERROR);
990 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
991 cprintf("%d %s\n",OK,usbuf.fullname);
1000 * set the room aide for this room
1002 void cmd_seta(char *new_ra)
1004 struct usersupp usbuf;
1009 if (!(CC->logged_in)) {
1010 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1014 if (!is_room_aide()) {
1015 cprintf("%d Higher access required.\n",
1016 ERROR+HIGHER_ACCESS_REQUIRED);
1020 if (CC->curr_rm < 3) {
1021 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1025 if (getuser(&usbuf,new_ra)!=0) {
1029 newu = usbuf.usernum;
1032 lgetroom(&CC->quickroom,CC->curr_rm);
1034 if (CC->quickroom.QRroomaide != newu) {
1037 CC->quickroom.QRroomaide = newu;
1038 lputroom(&CC->quickroom,CC->curr_rm);
1041 * We have to post the change notice _after_ writing changes to
1042 * the room table, otherwise it would deadlock!
1044 if (post_notice == 1) {
1045 sprintf(buf,"%s is now room aide for %s>",
1046 usbuf.fullname,CC->quickroom.QRname);
1049 cprintf("%d Ok\n",OK);
1054 * retrieve info file for this room
1056 void cmd_rinf(void) {
1061 sprintf(filename,"./info/%d",CC->curr_rm);
1062 info_fp = fopen(filename,"r");
1064 if (info_fp==NULL) {
1065 cprintf("%d No info file.\n",ERROR);
1069 cprintf("%d Info:\n",LISTING_FOLLOWS);
1070 while (fgets(buf, 256, info_fp) != NULL) {
1071 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1072 cprintf("%s\n", buf);
1079 * aide command: kill the current room
1081 void cmd_kill(char *argbuf)
1089 kill_ok = extract_int(argbuf,0);
1091 if (!(CC->logged_in)) {
1092 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1096 if (!is_room_aide()) {
1097 cprintf("%d Higher access required.\n",
1098 ERROR+HIGHER_ACCESS_REQUIRED);
1102 if (CC->curr_rm < 3) {
1103 cprintf("%d Can't kill this room.\n",ERROR+NOT_HERE);
1109 /* first flag the room record as not in use */
1110 lgetroom(&CC->quickroom,CC->curr_rm);
1111 CC->quickroom.QRflags=0;
1113 /* then delete the messages in the room */
1114 get_msglist(CC->curr_rm);
1115 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1116 MsgToDelete = MessageFromList(a);
1117 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1119 put_msglist(CC->curr_rm);
1122 cdb_delete(CDB_MSGLISTS, &CC->curr_rm, sizeof(int));
1124 lputroom(&CC->quickroom,CC->curr_rm);
1127 /* then decrement the reference count for the floor */
1128 lgetfloor(&flbuf,(int)CC->quickroom.QRfloor);
1129 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1130 lputfloor(&flbuf,(int)CC->quickroom.QRfloor);
1132 /* tell the world what we did */
1133 sprintf(aaa,"%s> killed by %s",CC->quickroom.QRname,CC->curr_user);
1136 cprintf("%d '%s' deleted.\n",OK,CC->quickroom.QRname);
1139 cprintf("%d ok to delete.\n",OK);
1145 * Find a free slot to create a new room in, or return -1 for error.
1146 * search_dir is the direction to search in. 1 causes this function to
1147 * return the first available slot, -1 gets the last available slot.
1149 * FIX This function can be eliminated during the cutover.
1151 int get_free_room_slot(int search_dir)
1154 struct quickroom qrbuf;
1156 st = ((search_dir>0) ? 3 : (MAXROOMS-1));
1158 for (a=st; ((a<MAXROOMS)&&(a>=3)); a=a+search_dir) {
1160 if ((qrbuf.QRflags & QR_INUSE)==0) return(a);
1167 * internal code to create a new room (returns room flags)
1169 unsigned create_room(int free_slot, char *new_room_name, int new_room_type, char *new_room_pass, int new_room_floor)
1171 struct quickroom qrbuf;
1175 lgetroom(&qrbuf,free_slot);
1176 strncpy(qrbuf.QRname,new_room_name,19);
1177 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1178 qrbuf.QRflags = QR_INUSE;
1179 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1180 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1181 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1182 qrbuf.QRroomaide = (-1L);
1183 if ((new_room_type > 0)&&(CREATAIDE==1))
1184 qrbuf.QRroomaide=CC->usersupp.usernum;
1185 qrbuf.QRhighest = 0L;
1187 qrbuf.QRfloor = new_room_floor;
1189 /* save what we just did... */
1190 lputroom(&qrbuf,free_slot);
1192 /* bump the reference count on whatever floor the room is on */
1193 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1194 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1195 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1197 /* be sure not to kick the creator out of the room! */
1198 lgetuser(&CC->usersupp,CC->curr_user);
1199 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1200 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1201 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1202 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1203 lputuser(&CC->usersupp,CC->curr_user);
1205 /* resume our happy day */
1206 return(qrbuf.QRflags);
1211 * create a new room FIX Rework this to use name indexing
1213 void cmd_cre8(char *args)
1218 char new_room_name[256];
1220 char new_room_pass[256];
1224 struct quickroom qrbuf;
1227 cre8_ok = extract_int(args,0);
1228 extract(new_room_name,args,1);
1229 new_room_name[19] = 0;
1230 new_room_type = extract_int(args,2);
1231 extract(new_room_pass,args,3);
1232 new_room_pass[9] = 0;
1235 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1236 cprintf("%d Invalid room name.\n",ERROR);
1240 if (num_parms(args)>=5) {
1241 getfloor(&flbuf,extract_int(args,4));
1242 if ((flbuf.f_flags & F_INUSE) == 0) {
1243 cprintf("%d Invalid floor number.\n",
1244 ERROR+INVALID_FLOOR_OPERATION);
1248 new_room_floor = extract_int(args,4);
1252 if (!(CC->logged_in)) {
1253 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1257 if (CC->usersupp.axlevel<3) {
1258 cprintf("%d You need higher access to create rooms.\n",
1259 ERROR+HIGHER_ACCESS_REQUIRED);
1263 free_slot = get_free_room_slot(1);
1265 cprintf("%d There is no space available for a new room.\n",
1271 cprintf("%d ok to create...\n",OK);
1275 for (a=0; a<MAXROOMS; ++a) {
1277 if ( (!strcasecmp(qrbuf.QRname,new_room_name))
1278 && (qrbuf.QRflags & QR_INUSE) ) {
1279 cprintf("%d '%s' already exists.\n",
1280 ERROR,qrbuf.QRname);
1285 if ((new_room_type < 0) || (new_room_type > 3)) {
1286 cprintf("%d Invalid room type.\n",ERROR);
1290 newflags = create_room(free_slot,new_room_name,
1291 new_room_type,new_room_pass,new_room_floor);
1293 /* post a message in Aide> describing the new room */
1294 strncpy(aaa,new_room_name,255);
1295 strcat(aaa,"> created by ");
1296 strcat(aaa,CC->usersupp.fullname);
1297 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1298 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1299 if (newflags&QR_PASSWORDED) {
1300 strcat(aaa,"\n Password: ");
1301 strcat(aaa,new_room_pass);
1305 sprintf(aaa,"./info/%d",free_slot); /* delete old info file */
1307 sprintf(aaa,"./images/room.%d.gif",free_slot); /* and picture */
1310 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1315 void cmd_einf(char *ok)
1316 { /* enter info file for current room */
1318 char infofilename[32];
1321 if (!(CC->logged_in)) {
1322 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1326 if (!is_room_aide()) {
1327 cprintf("%d Higher access required.\n",
1328 ERROR+HIGHER_ACCESS_REQUIRED);
1333 cprintf("%d Ok.\n",OK);
1337 cprintf("%d Send info...\n",SEND_LISTING);
1339 sprintf(infofilename,"./info/%d",CC->curr_rm);
1341 fp=fopen(infofilename,"w");
1344 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1345 } while(strcmp(buf,"000"));
1348 /* now update the room index so people will see our new info */
1349 lgetroom(&CC->quickroom,CC->curr_rm); /* lock so no one steps on us */
1350 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1351 lputroom(&CC->quickroom,CC->curr_rm);
1356 * cmd_lflr() - List all known floors
1358 void cmd_lflr(void) {
1362 if (!(CC->logged_in)) {
1363 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1367 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1368 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1373 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1375 for (a=0; a<MAXFLOORS; ++a) {
1377 if (flbuf.f_flags & F_INUSE) {
1378 cprintf("%d|%s|%d\n",
1390 * create a new floor
1392 void cmd_cflr(char *argbuf)
1394 char new_floor_name[256];
1397 int free_slot = (-1);
1400 extract(new_floor_name,argbuf,0);
1401 cflr_ok = extract_int(argbuf,1);
1404 if (!(CC->logged_in)) {
1405 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1409 if (CC->usersupp.axlevel<6) {
1410 cprintf("%d You need higher access to create rooms.\n",
1411 ERROR+HIGHER_ACCESS_REQUIRED);
1415 for (a=0; a<MAXFLOORS; ++a) {
1418 /* note any free slots while we're scanning... */
1419 if ( ((flbuf.f_flags & F_INUSE)==0)
1420 && (free_slot < 0) ) free_slot = a;
1422 /* check to see if it already exists */
1423 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1424 && (flbuf.f_flags & F_INUSE) ) {
1425 cprintf("%d Floor '%s' already exists.\n",
1426 ERROR+ALREADY_EXISTS,
1434 cprintf("%d There is no space available for a new floor.\n",
1435 ERROR+INVALID_FLOOR_OPERATION);
1440 cprintf("%d ok to create...\n",OK);
1444 lgetfloor(&flbuf,free_slot);
1445 flbuf.f_flags = F_INUSE;
1446 flbuf.f_ref_count = 0;
1447 strncpy(flbuf.f_name,new_floor_name,255);
1448 lputfloor(&flbuf,free_slot);
1449 cprintf("%d %d\n",OK,free_slot);
1457 void cmd_kflr(char *argbuf)
1460 int floor_to_delete;
1464 floor_to_delete = extract_int(argbuf,0);
1465 kflr_ok = extract_int(argbuf,1);
1468 if (!(CC->logged_in)) {
1469 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1473 if (CC->usersupp.axlevel<6) {
1474 cprintf("%d You need higher access to delete floors.\n",
1475 ERROR+HIGHER_ACCESS_REQUIRED);
1479 lgetfloor(&flbuf,floor_to_delete);
1482 if ((flbuf.f_flags & F_INUSE) == 0) {
1483 cprintf("%d Floor %d not in use.\n",
1484 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1489 if (flbuf.f_ref_count != 0) {
1490 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1491 ERROR+INVALID_FLOOR_OPERATION,
1498 cprintf("%d Ok\n",OK);
1501 cprintf("%d Ok to delete...\n",OK);
1508 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1509 lputfloor(&flbuf,floor_to_delete);
1515 void cmd_eflr(char *argbuf)
1521 np = num_parms(argbuf);
1523 cprintf("%d Usage error.\n",ERROR);
1527 if (!(CC->logged_in)) {
1528 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1532 if (CC->usersupp.axlevel<6) {
1533 cprintf("%d You need higher access to edit floors.\n",
1534 ERROR+HIGHER_ACCESS_REQUIRED);
1538 floor_num = extract_int(argbuf,0);
1539 lgetfloor(&flbuf,floor_num);
1540 if ( (flbuf.f_flags & F_INUSE) == 0) {
1541 lputfloor(&flbuf,floor_num);
1542 cprintf("%d Floor %d is not in use.\n",
1543 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1546 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1547 lputfloor(&flbuf,floor_num);
1549 cprintf("%d Ok\n",OK);