14 #include "sysdep_decls.h"
18 #include "serv_chat.h"
19 #include "citserver.h"
22 * Generic routine for determining user access to rooms
24 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf) {
28 /* Make sure we're dealing with a real, existing room */
29 if (roombuf->QRflags & QR_INUSE) {
30 retval = retval | UA_INUSE;
36 /* for internal programs, always do everything */
37 if (((CC->internal_pgm))&&(roombuf->QRflags & QR_INUSE)) {
38 return(UA_INUSE | UA_KNOWN | UA_GOTOALLOWED);
41 /* Locate any applicable user/room relationships */
42 CtdlGetRelationship(&vbuf, userbuf, roombuf);
44 /* If this is a public room, it's accessible... */
45 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
46 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
49 /* If this is a preferred users only room, check access level */
50 if (roombuf->QRflags & QR_PREFONLY) {
51 if (userbuf->axlevel < 5) {
52 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
56 /* For private rooms, check the generation number matchups */
57 if (roombuf->QRflags & QR_PRIVATE) {
59 /* An explicit match means the user belongs in this room */
60 if (vbuf.v_flags & V_ACCESS) {
61 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
63 /* Otherwise, check if this is a guess-name or passworded
64 * room. If it is, a goto may at least be attempted
66 else if ((roombuf->QRflags & QR_PRIVATE)
67 ||(roombuf->QRflags & QR_PASSWORDED)) {
68 retval = retval & ~UA_KNOWN;
69 retval = retval | UA_GOTOALLOWED;
73 /* Check to see if the user has forgotten this room */
74 if (vbuf.v_flags & V_FORGET) {
75 retval = retval & ~UA_KNOWN;
76 retval = retval | UA_ZAPPED;
79 /* If user is explicitly locked out of this room, deny everything */
80 if (vbuf.v_flags & V_LOCKOUT) {
81 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
84 /* Aides get access to everything */
85 if (userbuf->axlevel >= 6) {
86 retval = retval | UA_INUSE | UA_KNOWN | UA_GOTOALLOWED;
87 retval = retval & ~UA_ZAPPED;
90 /* By the way, we also check for the presence of new messages */
91 if ( (roombuf->QRhighest) > (vbuf.v_lastseen) ) {
92 retval = retval | UA_HASNEWMSGS;
99 * getroom() - retrieve room data from disk
101 int getroom(struct quickroom *qrbuf, char *room_name)
103 struct cdbdata *cdbqr;
104 char lowercase_name[ROOMNAMELEN];
107 for (a=0; a<=strlen(room_name); ++a) {
108 lowercase_name[a] = tolower(room_name[a]);
111 bzero(qrbuf, sizeof(struct quickroom));
112 cdbqr = cdb_fetch(CDB_QUICKROOM,
113 lowercase_name, strlen(lowercase_name));
115 memcpy(qrbuf, cdbqr->ptr,
116 ( (cdbqr->len > sizeof(struct quickroom)) ?
117 sizeof(struct quickroom) : cdbqr->len) );
127 * lgetroom() - same as getroom() but locks the record (if supported)
129 int lgetroom(struct quickroom *qrbuf, char *room_name)
131 begin_critical_section(S_QUICKROOM);
132 return(getroom(qrbuf, room_name));
137 * putroom() - store room data on disk
139 void putroom(struct quickroom *qrbuf, char *room_name)
141 char lowercase_name[ROOMNAMELEN];
144 for (a=0; a<=strlen(room_name); ++a) {
145 lowercase_name[a] = tolower(room_name[a]);
148 time(&qrbuf->QRmtime);
149 cdb_store(CDB_QUICKROOM, lowercase_name, strlen(lowercase_name),
150 qrbuf, sizeof(struct quickroom));
155 * lputroom() - same as putroom() but unlocks the record (if supported)
157 void lputroom(struct quickroom *qrbuf, char *room_name)
160 putroom(qrbuf, room_name);
161 end_critical_section(S_QUICKROOM);
165 /****************************************************************************/
168 * getfloor() - retrieve floor data from disk
170 void getfloor(struct floor *flbuf, int floor_num)
172 struct cdbdata *cdbfl;
174 bzero(flbuf, sizeof(struct floor));
175 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
177 memcpy(flbuf, cdbfl->ptr,
178 ( (cdbfl->len > sizeof(struct floor)) ?
179 sizeof(struct floor) : cdbfl->len) );
183 if (floor_num == 0) {
184 strcpy(flbuf->f_name, "Main Floor");
185 flbuf->f_flags = F_INUSE;
186 flbuf->f_ref_count = 3;
193 * lgetfloor() - same as getfloor() but locks the record (if supported)
195 void lgetfloor(struct floor *flbuf, int floor_num)
198 begin_critical_section(S_FLOORTAB);
199 getfloor(flbuf,floor_num);
204 * putfloor() - store floor data on disk
206 void putfloor(struct floor *flbuf, int floor_num)
208 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
209 flbuf, sizeof(struct floor));
214 * lputfloor() - same as putfloor() but unlocks the record (if supported)
216 void lputfloor(struct floor *flbuf, int floor_num)
219 putfloor(flbuf,floor_num);
220 end_critical_section(S_FLOORTAB);
226 * Traverse the room file...
228 void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) {
229 struct quickroom qrbuf;
230 struct cdbdata *cdbqr;
232 cdb_rewind(CDB_QUICKROOM);
234 while(cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
235 bzero(&qrbuf, sizeof(struct quickroom));
236 memcpy(&qrbuf, cdbqr->ptr,
237 ( (cdbqr->len > sizeof(struct quickroom)) ?
238 sizeof(struct quickroom) : cdbqr->len) );
240 if (qrbuf.QRflags & QR_INUSE) (*CallBack)(&qrbuf);
247 * get_msglist() - retrieve room message pointers
249 void get_msglist(struct quickroom *whichroom) {
250 struct cdbdata *cdbfr;
254 sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
255 for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
257 if (CC->msglist != NULL) {
263 cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey));
269 CC->msglist = malloc(cdbfr->len);
270 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
271 CC->num_msgs = cdbfr->len / sizeof(long);
277 * put_msglist() - retrieve room message pointers
279 void put_msglist(struct quickroom *whichroom) {
283 sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
284 for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
286 cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey),
287 CC->msglist, CC->num_msgs * sizeof(long));
292 * delete_msglist() - delete room message pointers
294 void delete_msglist(struct quickroom *whichroom) {
298 sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
299 for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
301 cdb_delete(CDB_MSGLISTS, dbkey, strlen(dbkey));
306 * MessageFromList() - get a message number from the list currently in memory
308 long MessageFromList(int whichpos) {
310 /* Return zero if the position is invalid */
311 if (whichpos >= CC->num_msgs) return 0L;
313 return(CC->msglist[whichpos]);
317 * SetMessageInList() - set a message number in the list currently in memory
319 void SetMessageInList(int whichpos, long newmsgnum) {
321 /* Return zero if the position is invalid */
322 if (whichpos >= CC->num_msgs) return;
324 CC->msglist[whichpos] = newmsgnum;
330 * sort message pointers
331 * (returns new msg count)
333 int sort_msglist(long listptrs[], int oldcount)
340 if (numitems < 2) return(oldcount);
343 for (a=numitems-2; a>=0; --a) {
344 for (b=0; b<=a; ++b) {
345 if (listptrs[b] > (listptrs[b+1])) {
347 hold2 = listptrs[b+1];
349 listptrs[b+1] = hold1;
354 /* and yank any nulls */
355 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
356 memcpy(&listptrs[0], &listptrs[1],
357 (sizeof(long) * (CC->num_msgs - 1)) );
367 * cmd_lrms() - List all accessible rooms, known or forgotten
369 void cmd_lrms_backend(struct quickroom *qrbuf) {
370 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
371 & (UA_KNOWN | UA_ZAPPED)))
372 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
373 ||((CC->FloorBeingSearched)<0)) )
374 cprintf("%s|%u|%d\n",
375 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
378 void cmd_lrms(char *argbuf)
380 CC->FloorBeingSearched = (-1);
381 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
383 if (!(CC->logged_in)) {
384 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
388 if (getuser(&CC->usersupp,CC->curr_user)) {
389 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
393 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
395 ForEachRoom(cmd_lrms_backend);
402 * cmd_lkra() - List all known rooms
404 void cmd_lkra_backend(struct quickroom *qrbuf) {
405 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
407 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
408 ||((CC->FloorBeingSearched)<0)) )
409 cprintf("%s|%u|%d\n",
410 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
413 void cmd_lkra(char *argbuf)
415 CC->FloorBeingSearched = (-1);
416 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
418 if (!(CC->logged_in)) {
419 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
423 if (getuser(&CC->usersupp,CC->curr_user)) {
424 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
428 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
430 ForEachRoom(cmd_lkra_backend);
437 * cmd_lkrn() - List all known rooms with new messages
439 void cmd_lkrn_backend(struct quickroom *qrbuf) {
442 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
444 && (ra & UA_HASNEWMSGS)
445 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
446 ||((CC->FloorBeingSearched)<0)) )
447 cprintf("%s|%u|%d\n",
448 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
451 void cmd_lkrn(char *argbuf)
453 CC->FloorBeingSearched = (-1);
454 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
456 if (!(CC->logged_in)) {
457 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
461 if (getuser(&CC->usersupp,CC->curr_user)) {
462 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
466 cprintf("%d Rooms w/ new msgs:\n",LISTING_FOLLOWS);
468 ForEachRoom(cmd_lkrn_backend);
475 * cmd_lkro() - List all known rooms
477 void cmd_lkro_backend(struct quickroom *qrbuf) {
480 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
482 && ((ra & UA_HASNEWMSGS)==0)
483 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
484 ||((CC->FloorBeingSearched)<0)) )
485 cprintf("%s|%u|%d\n",
486 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
489 void cmd_lkro(char *argbuf)
491 CC->FloorBeingSearched = (-1);
492 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
494 if (!(CC->logged_in)) {
495 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
499 if (getuser(&CC->usersupp,CC->curr_user)) {
500 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
504 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
506 ForEachRoom(cmd_lkro_backend);
513 * cmd_lzrm() - List all forgotten rooms
515 void cmd_lzrm_backend(struct quickroom *qrbuf) {
518 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
519 if ( (ra & UA_GOTOALLOWED)
521 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
522 ||((CC->FloorBeingSearched)<0)) )
523 cprintf("%s|%u|%d\n",
524 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
527 void cmd_lzrm(char *argbuf)
529 CC->FloorBeingSearched = (-1);
530 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
532 if (!(CC->logged_in)) {
533 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
537 if (getuser(&CC->usersupp,CC->curr_user)) {
538 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
542 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
544 ForEachRoom(cmd_lzrm_backend);
550 void usergoto(char *where, int display_result)
553 int new_messages = 0;
554 int total_messages = 0;
558 int newmailcount = 0;
561 strcpy(CC->cs_room, where);
562 getroom(&CC->quickroom, CC->cs_room);
563 lgetuser(&CC->usersupp,CC->curr_user);
564 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
566 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
567 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
569 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
570 lputuser(&CC->usersupp,CC->curr_user);
572 /* check for new mail */
573 newmailcount = NewMailCount();
575 /* set info to 1 if the user needs to read the room's info file */
576 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
579 get_msglist(&CC->quickroom);
580 for (a=0; a<CC->num_msgs; ++a) {
581 if (MessageFromList(a)>0L) {
583 if (MessageFromList(a) > vbuf.v_lastseen) {
590 if (0) rmailflag = 1; /* FIX to handle mail rooms!!! */
593 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
594 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
597 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
599 CC->quickroom.QRname,
600 new_messages, total_messages,
601 info,CC->quickroom.QRflags,
602 CC->quickroom.QRhighest,
604 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
606 if (CC->quickroom.QRflags & QR_PRIVATE) {
607 set_wtmpsupp("<private room>");
610 set_wtmpsupp(CC->quickroom.QRname);
616 * cmd_goto() - goto a new room
618 void cmd_goto(char *gargs)
620 struct quickroom QRscratch;
624 char bbb[ROOMNAMELEN],towhere[32],password[20];
626 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
627 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
631 extract(towhere,gargs,0);
632 extract(password,gargs,1);
635 getuser(&CC->usersupp,CC->curr_user);
637 if (!strcasecmp(towhere, "_BASEROOM_"))
638 strcpy(towhere, BASEROOM);
640 if (!strcasecmp(towhere, "_MAIL_"))
641 strcpy(towhere, MAILROOM);
643 if (!strcasecmp(towhere, "_BITBUCKET_"))
644 strcpy(towhere, config.c_twitroom);
647 /* let internal programs go directly to any room */
648 if (((CC->internal_pgm))&&(!strcasecmp(bbb,towhere))) {
649 usergoto(towhere, 1);
653 if (getroom(&QRscratch, towhere) == 0) {
655 /* See if there is an existing user/room relationship */
656 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
658 /* normal clients have to pass through security */
659 if (ra & UA_GOTOALLOWED) ok = 1;
662 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
663 ((ra & UA_KNOWN) == 0) &&
664 (strcasecmp(QRscratch.QRpasswd,password))
666 cprintf("%d wrong or missing passwd\n",
667 ERROR+PASSWORD_REQUIRED);
671 usergoto(towhere, 1);
677 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
681 void cmd_whok(void) {
682 struct usersupp temp;
683 struct cdbdata *cdbus;
685 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
686 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
689 getuser(&CC->usersupp,CC->curr_user);
691 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
692 cprintf("%d Higher access required.\n",
693 ERROR+HIGHER_ACCESS_REQUIRED);
697 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
698 cdb_rewind(CDB_USERSUPP);
699 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
700 bzero(&temp, sizeof(struct usersupp));
701 memcpy(&temp, cdbus->ptr, cdbus->len);
704 if ( (CC->quickroom.QRflags & QR_INUSE)
705 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
706 ) cprintf("%s\n",temp.fullname);
713 * RDIR command for room directory
715 void cmd_rdir(void) {
722 if (!(CC->logged_in)) {
723 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
727 getroom(&CC->quickroom, CC->cs_room);
728 getuser(&CC->usersupp, CC->curr_user);
730 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
731 cprintf("%d not here.\n",ERROR+NOT_HERE);
735 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
736 && (CC->usersupp.axlevel<6)
737 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
738 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
742 cprintf("%d %s|%s/files/%s\n",
743 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
745 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
746 BBSDIR,CC->quickroom.QRdirname,CC->temp);
749 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
751 if (fd==NULL) fd=fopen("/dev/null","r");
753 ls = fopen(CC->temp,"r");
754 while (fgets(flnm,256,ls)!=NULL) {
755 flnm[strlen(flnm)-1]=0;
756 if (strcasecmp(flnm,"filedir")) {
757 sprintf(buf,"%s/files/%s/%s",
758 BBSDIR,CC->quickroom.QRdirname,flnm);
762 while ((fgets(buf,256,fd)!=NULL)
763 &&(strlen(comment)==0)) {
764 buf[strlen(buf)-1] = 0;
765 if ((!strncasecmp(buf,flnm,strlen(flnm)))
766 && (buf[strlen(flnm)]==' '))
768 &buf[strlen(flnm)+1],255);
770 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
781 * get room parameters (aide or room aide command)
783 void cmd_getr(void) {
784 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
785 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
789 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
790 cprintf("%d Higher access required.\n",
791 ERROR+HIGHER_ACCESS_REQUIRED);
795 if ( (!strcasecmp(CC->cs_room, BASEROOM))
796 || (!strcasecmp(CC->cs_room, AIDEROOM)) ) {
797 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
801 getroom(&CC->quickroom, CC->cs_room);
802 cprintf("%d%c%s|%s|%s|%d|%d\n",
804 CC->quickroom.QRname,
805 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
806 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
807 CC->quickroom.QRflags,
808 (int)CC->quickroom.QRfloor);
813 * set room parameters (aide or room aide command)
815 void cmd_setr(char *args) {
820 if (!(CC->logged_in)) {
821 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
825 if (!is_room_aide()) {
826 cprintf("%d Higher access required.\n",
827 ERROR+HIGHER_ACCESS_REQUIRED);
831 if ( (!strcasecmp(CC->cs_room, BASEROOM))
832 || (!strcasecmp(CC->cs_room, AIDEROOM)) ) {
833 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
837 if (num_parms(args)>=6) {
838 getfloor(&flbuf,extract_int(args,5));
839 if ((flbuf.f_flags & F_INUSE) == 0) {
840 cprintf("%d Invalid floor number.\n",
841 ERROR+INVALID_FLOOR_OPERATION);
846 lgetroom(&CC->quickroom, CC->cs_room);
847 extract(buf,args,0); buf[ROOMNAMELEN]=0;
848 strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
849 extract(buf,args,1); buf[10]=0;
850 strncpy(CC->quickroom.QRpasswd,buf,9);
851 extract(buf,args,2); buf[15]=0;
852 strncpy(CC->quickroom.QRdirname,buf,19);
853 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
855 /* Clean up a client boo-boo: if the client set the room to
856 * guess-name or passworded, ensure that the private flag is
859 if ((CC->quickroom.QRflags & QR_GUESSNAME)
860 ||(CC->quickroom.QRflags & QR_PASSWORDED))
861 CC->quickroom.QRflags |= QR_PRIVATE;
863 /* Kick everyone out if the client requested it (by changing the
864 * room's generation number)
866 if (extract_int(args,4)) {
867 time(&CC->quickroom.QRgen);
870 old_floor = CC->quickroom.QRfloor;
871 if (num_parms(args)>=6) {
872 CC->quickroom.QRfloor = extract_int(args,5);
875 lputroom(&CC->quickroom, CC->cs_room);
877 /* adjust the floor reference counts */
878 lgetfloor(&flbuf,old_floor);
880 lputfloor(&flbuf,old_floor);
881 lgetfloor(&flbuf,CC->quickroom.QRfloor);
883 lputfloor(&flbuf,CC->quickroom.QRfloor);
885 /* create a room directory if necessary */
886 if (CC->quickroom.QRflags & QR_DIRECTORY) {
888 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
889 CC->quickroom.QRdirname);
893 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
895 cprintf("%d Ok\n",OK);
901 * get the name of the room aide for this room
903 void cmd_geta(void) {
904 struct usersupp usbuf;
906 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
907 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
911 if ( (!strcasecmp(CC->cs_room, BASEROOM))
912 || (!strcasecmp(CC->cs_room, AIDEROOM)) ) {
913 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
917 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
918 cprintf("%d %s\n",OK,usbuf.fullname);
927 * set the room aide for this room
929 void cmd_seta(char *new_ra)
931 struct usersupp usbuf;
936 if (!(CC->logged_in)) {
937 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
941 if (!is_room_aide()) {
942 cprintf("%d Higher access required.\n",
943 ERROR+HIGHER_ACCESS_REQUIRED);
947 if (getuser(&usbuf,new_ra)!=0) {
951 newu = usbuf.usernum;
954 lgetroom(&CC->quickroom, CC->cs_room);
956 if (CC->quickroom.QRroomaide != newu) {
959 CC->quickroom.QRroomaide = newu;
960 lputroom(&CC->quickroom, CC->cs_room);
963 * We have to post the change notice _after_ writing changes to
964 * the room table, otherwise it would deadlock!
966 if (post_notice == 1) {
967 sprintf(buf,"%s is now room aide for %s>",
968 usbuf.fullname,CC->quickroom.QRname);
971 cprintf("%d Ok\n",OK);
975 * Generate an associated file name for a room
977 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
980 sprintf(buf, "./prefix/%s.%ld", qrbuf->QRname, qrbuf->QRgen);
981 for (a=0; a<strlen(buf); ++a) {
982 if (buf[a]==32) buf[a]='.';
987 * retrieve info file for this room
989 void cmd_rinf(void) {
994 assoc_file_name(filename, &CC->quickroom, "info");
995 info_fp = fopen(filename,"r");
998 cprintf("%d No info file.\n",ERROR);
1002 cprintf("%d Info:\n",LISTING_FOLLOWS);
1003 while (fgets(buf, 256, info_fp) != NULL) {
1004 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1005 cprintf("%s\n", buf);
1012 * aide command: kill the current room
1014 void cmd_kill(char *argbuf)
1022 kill_ok = extract_int(argbuf,0);
1024 if (!(CC->logged_in)) {
1025 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1029 if (!is_room_aide()) {
1030 cprintf("%d Higher access required.\n",
1031 ERROR+HIGHER_ACCESS_REQUIRED);
1035 if ( (!strcasecmp(CC->cs_room, BASEROOM))
1036 || (!strcasecmp(CC->cs_room, AIDEROOM)) ) {
1037 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1043 /* Delete the info file */
1044 assoc_file_name(aaa, &CC->quickroom, "info");
1047 /* first flag the room record as not in use */
1048 lgetroom(&CC->quickroom, CC->cs_room);
1049 CC->quickroom.QRflags=0;
1051 /* then delete the messages in the room */
1052 get_msglist(&CC->quickroom);
1053 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1054 MsgToDelete = MessageFromList(a);
1055 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1057 put_msglist(&CC->quickroom);
1060 delete_msglist(&CC->quickroom);
1061 lputroom(&CC->quickroom, CC->cs_room);
1064 * To do at this location in the code:
1065 * 1. Delete the associated files (info, image)
1066 * 2. Delete the room record from the database
1069 /* then decrement the reference count for the floor */
1070 lgetfloor(&flbuf,(int)CC->quickroom.QRfloor);
1071 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1072 lputfloor(&flbuf,(int)CC->quickroom.QRfloor);
1074 /* tell the world what we did */
1075 sprintf(aaa,"%s> killed by %s",CC->quickroom.QRname,CC->curr_user);
1077 usergoto(BASEROOM, 0);
1078 cprintf("%d '%s' deleted.\n",OK,CC->quickroom.QRname);
1081 cprintf("%d ok to delete.\n",OK);
1087 * Internal code to create a new room (returns room flags)
1089 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1091 unsigned create_room(char *new_room_name,
1093 char *new_room_pass,
1094 int new_room_floor) {
1096 struct quickroom qrbuf;
1100 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1102 bzero(&qrbuf, sizeof(struct quickroom));
1103 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1104 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1105 qrbuf.QRflags = QR_INUSE;
1106 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1107 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1108 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1109 if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
1110 qrbuf.QRroomaide = (-1L);
1111 if ((new_room_type > 0)&&(CREATAIDE==1))
1112 qrbuf.QRroomaide=CC->usersupp.usernum;
1113 qrbuf.QRhighest = 0L;
1115 qrbuf.QRfloor = new_room_floor;
1117 /* save what we just did... */
1118 putroom(&qrbuf, qrbuf.QRname);
1120 /* bump the reference count on whatever floor the room is on */
1121 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1122 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1123 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1125 /* be sure not to kick the creator out of the room! */
1126 lgetuser(&CC->usersupp,CC->curr_user);
1127 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1128 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1129 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1130 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1131 lputuser(&CC->usersupp,CC->curr_user);
1133 /* resume our happy day */
1134 return(qrbuf.QRflags);
1141 void cmd_cre8(char *args)
1144 char new_room_name[256];
1146 char new_room_pass[256];
1150 struct quickroom qrbuf;
1153 cre8_ok = extract_int(args,0);
1154 extract(new_room_name,args,1);
1155 new_room_name[ROOMNAMELEN-1] = 0;
1156 new_room_type = extract_int(args,2);
1157 extract(new_room_pass,args,3);
1158 new_room_pass[9] = 0;
1161 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1162 cprintf("%d Invalid room name.\n",ERROR);
1166 if (num_parms(args)>=5) {
1167 getfloor(&flbuf,extract_int(args,4));
1168 if ((flbuf.f_flags & F_INUSE) == 0) {
1169 cprintf("%d Invalid floor number.\n",
1170 ERROR+INVALID_FLOOR_OPERATION);
1174 new_room_floor = extract_int(args,4);
1178 if (!(CC->logged_in)) {
1179 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1183 if (CC->usersupp.axlevel<3) {
1184 cprintf("%d You need higher access to create rooms.\n",
1185 ERROR+HIGHER_ACCESS_REQUIRED);
1189 if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
1190 cprintf("%d Ok to create rooms.\n", OK);
1194 /* Check to make sure the requested room name doesn't already exist */
1195 if (getroom(&qrbuf, new_room_name)==0) {
1196 cprintf("%d '%s' already exists.\n",
1197 ERROR,qrbuf.QRname);
1201 if ((new_room_type < 0) || (new_room_type > 3)) {
1202 cprintf("%d Invalid room type.\n",ERROR);
1207 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1211 newflags = create_room(new_room_name,
1212 new_room_type,new_room_pass,new_room_floor);
1214 /* post a message in Aide> describing the new room */
1215 strncpy(aaa,new_room_name,255);
1216 strcat(aaa,"> created by ");
1217 strcat(aaa,CC->usersupp.fullname);
1218 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1219 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1220 if (newflags&QR_PASSWORDED) {
1221 strcat(aaa,"\n Password: ");
1222 strcat(aaa,new_room_pass);
1226 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1231 void cmd_einf(char *ok)
1232 { /* enter info file for current room */
1234 char infofilename[64];
1237 if (!(CC->logged_in)) {
1238 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1242 if (!is_room_aide()) {
1243 cprintf("%d Higher access required.\n",
1244 ERROR+HIGHER_ACCESS_REQUIRED);
1249 cprintf("%d Ok.\n",OK);
1253 cprintf("%d Send info...\n",SEND_LISTING);
1255 assoc_file_name(infofilename, &CC->quickroom, "info");
1257 fp=fopen(infofilename,"w");
1260 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1261 } while(strcmp(buf,"000"));
1264 /* now update the room index so people will see our new info */
1265 lgetroom(&CC->quickroom,CC->cs_room); /* lock so no one steps on us */
1266 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1267 lputroom(&CC->quickroom,CC->cs_room);
1272 * cmd_lflr() - List all known floors
1274 void cmd_lflr(void) {
1278 if (!(CC->logged_in)) {
1279 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1283 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1284 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1289 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1291 for (a=0; a<MAXFLOORS; ++a) {
1293 if (flbuf.f_flags & F_INUSE) {
1294 cprintf("%d|%s|%d\n",
1306 * create a new floor
1308 void cmd_cflr(char *argbuf)
1310 char new_floor_name[256];
1313 int free_slot = (-1);
1316 extract(new_floor_name,argbuf,0);
1317 cflr_ok = extract_int(argbuf,1);
1320 if (!(CC->logged_in)) {
1321 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1325 if (CC->usersupp.axlevel<6) {
1326 cprintf("%d You need higher access to create rooms.\n",
1327 ERROR+HIGHER_ACCESS_REQUIRED);
1331 for (a=0; a<MAXFLOORS; ++a) {
1334 /* note any free slots while we're scanning... */
1335 if ( ((flbuf.f_flags & F_INUSE)==0)
1336 && (free_slot < 0) ) free_slot = a;
1338 /* check to see if it already exists */
1339 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1340 && (flbuf.f_flags & F_INUSE) ) {
1341 cprintf("%d Floor '%s' already exists.\n",
1342 ERROR+ALREADY_EXISTS,
1350 cprintf("%d There is no space available for a new floor.\n",
1351 ERROR+INVALID_FLOOR_OPERATION);
1356 cprintf("%d ok to create...\n",OK);
1360 lgetfloor(&flbuf,free_slot);
1361 flbuf.f_flags = F_INUSE;
1362 flbuf.f_ref_count = 0;
1363 strncpy(flbuf.f_name,new_floor_name,255);
1364 lputfloor(&flbuf,free_slot);
1365 cprintf("%d %d\n",OK,free_slot);
1373 void cmd_kflr(char *argbuf)
1376 int floor_to_delete;
1380 floor_to_delete = extract_int(argbuf,0);
1381 kflr_ok = extract_int(argbuf,1);
1384 if (!(CC->logged_in)) {
1385 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1389 if (CC->usersupp.axlevel<6) {
1390 cprintf("%d You need higher access to delete floors.\n",
1391 ERROR+HIGHER_ACCESS_REQUIRED);
1395 lgetfloor(&flbuf,floor_to_delete);
1398 if ((flbuf.f_flags & F_INUSE) == 0) {
1399 cprintf("%d Floor %d not in use.\n",
1400 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1405 if (flbuf.f_ref_count != 0) {
1406 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1407 ERROR+INVALID_FLOOR_OPERATION,
1414 cprintf("%d Ok\n",OK);
1417 cprintf("%d Ok to delete...\n",OK);
1424 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1425 lputfloor(&flbuf,floor_to_delete);
1431 void cmd_eflr(char *argbuf)
1437 np = num_parms(argbuf);
1439 cprintf("%d Usage error.\n",ERROR);
1443 if (!(CC->logged_in)) {
1444 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1448 if (CC->usersupp.axlevel<6) {
1449 cprintf("%d You need higher access to edit floors.\n",
1450 ERROR+HIGHER_ACCESS_REQUIRED);
1454 floor_num = extract_int(argbuf,0);
1455 lgetfloor(&flbuf,floor_num);
1456 if ( (flbuf.f_flags & F_INUSE) == 0) {
1457 lputfloor(&flbuf,floor_num);
1458 cprintf("%d Floor %d is not in use.\n",
1459 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1462 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1463 lputfloor(&flbuf,floor_num);
1465 cprintf("%d Ok\n",OK);