15 #include "sysdep_decls.h"
19 #include "serv_chat.h"
20 #include "citserver.h"
25 * Generic routine for determining user access to rooms
27 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf) {
31 /* for internal programs, always do everything */
32 if (((CC->internal_pgm))&&(roombuf->QRflags & QR_INUSE)) {
33 return(UA_KNOWN | UA_GOTOALLOWED);
36 /* For mailbox rooms, only allow access to the owner */
37 if (roombuf->QRflags & QR_MAILBOX) {
38 if (userbuf->usernum != atol(roombuf->QRname)) {
43 /* Locate any applicable user/room relationships */
44 CtdlGetRelationship(&vbuf, userbuf, roombuf);
46 /* Force the properties of the Aide room */
47 if (!strcasecmp(roombuf->QRname, AIDEROOM)) {
48 if (userbuf->axlevel >= 6) {
49 retval = UA_KNOWN | UA_GOTOALLOWED;
57 /* For mailboxes, we skip all the access stuff (and we've
58 * already checked by this point that the mailbox belongs
61 if (roombuf->QRflags & QR_MAILBOX) {
62 retval = UA_KNOWN | UA_GOTOALLOWED;
66 /* If this is a public room, it's accessible... */
67 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
68 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
71 /* If this is a preferred users only room, check access level */
72 if (roombuf->QRflags & QR_PREFONLY) {
73 if (userbuf->axlevel < 5) {
74 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
78 /* For private rooms, check the generation number matchups */
79 if (roombuf->QRflags & QR_PRIVATE) {
81 /* An explicit match means the user belongs in this room */
82 if (vbuf.v_flags & V_ACCESS) {
83 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
85 /* Otherwise, check if this is a guess-name or passworded
86 * room. If it is, a goto may at least be attempted
88 else if ((roombuf->QRflags & QR_PRIVATE)
89 ||(roombuf->QRflags & QR_PASSWORDED)) {
90 retval = retval & ~UA_KNOWN;
91 retval = retval | UA_GOTOALLOWED;
95 /* Check to see if the user has forgotten this room */
96 if (vbuf.v_flags & V_FORGET) {
97 retval = retval & ~UA_KNOWN;
98 retval = retval | UA_ZAPPED;
101 /* If user is explicitly locked out of this room, deny everything */
102 if (vbuf.v_flags & V_LOCKOUT) {
103 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
106 /* Aides get access to everything */
107 if (userbuf->axlevel >= 6) {
108 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
109 retval = retval & ~UA_ZAPPED;
112 NEWMSG: /* By the way, we also check for the presence of new messages */
113 if ( (roombuf->QRhighest) > (vbuf.v_lastseen) ) {
114 retval = retval | UA_HASNEWMSGS;
121 * getroom() - retrieve room data from disk
123 int getroom(struct quickroom *qrbuf, char *room_name)
125 struct cdbdata *cdbqr;
126 char lowercase_name[ROOMNAMELEN];
129 for (a=0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
130 lowercase_name[a] = tolower(room_name[a]);
132 lowercase_name[a] = 0;
134 memset(qrbuf, 0, sizeof(struct quickroom));
135 cdbqr = cdb_fetch(CDB_QUICKROOM,
136 lowercase_name, strlen(lowercase_name));
138 memcpy(qrbuf, cdbqr->ptr,
139 ( (cdbqr->len > sizeof(struct quickroom)) ?
140 sizeof(struct quickroom) : cdbqr->len) );
143 /* Mailbox rooms are always on the lowest floor */
144 if (qrbuf->QRflags & QR_MAILBOX) {
156 * lgetroom() - same as getroom() but locks the record (if supported)
158 int lgetroom(struct quickroom *qrbuf, char *room_name)
160 begin_critical_section(S_QUICKROOM);
161 return(getroom(qrbuf, room_name));
166 * putroom() - store room data on disk
167 * (if the supplied buffer is NULL, delete the room record)
169 void putroom(struct quickroom *qrbuf, char *room_name)
171 char lowercase_name[ROOMNAMELEN];
174 for (a=0; a<=strlen(room_name); ++a) {
175 lowercase_name[a] = tolower(room_name[a]);
179 cdb_delete(CDB_QUICKROOM,
180 lowercase_name, strlen(lowercase_name));
183 time(&qrbuf->QRmtime);
184 cdb_store(CDB_QUICKROOM,
185 lowercase_name, strlen(lowercase_name),
186 qrbuf, sizeof(struct quickroom));
192 * lputroom() - same as putroom() but unlocks the record (if supported)
194 void lputroom(struct quickroom *qrbuf, char *room_name)
197 putroom(qrbuf, room_name);
198 end_critical_section(S_QUICKROOM);
202 /****************************************************************************/
205 * getfloor() - retrieve floor data from disk
207 void getfloor(struct floor *flbuf, int floor_num)
209 struct cdbdata *cdbfl;
211 memset(flbuf, 0, sizeof(struct floor));
212 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
214 memcpy(flbuf, cdbfl->ptr,
215 ( (cdbfl->len > sizeof(struct floor)) ?
216 sizeof(struct floor) : cdbfl->len) );
220 if (floor_num == 0) {
221 strcpy(flbuf->f_name, "Main Floor");
222 flbuf->f_flags = F_INUSE;
223 flbuf->f_ref_count = 3;
230 * lgetfloor() - same as getfloor() but locks the record (if supported)
232 void lgetfloor(struct floor *flbuf, int floor_num)
235 begin_critical_section(S_FLOORTAB);
236 getfloor(flbuf,floor_num);
241 * putfloor() - store floor data on disk
243 void putfloor(struct floor *flbuf, int floor_num)
245 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
246 flbuf, sizeof(struct floor));
251 * lputfloor() - same as putfloor() but unlocks the record (if supported)
253 void lputfloor(struct floor *flbuf, int floor_num)
256 putfloor(flbuf,floor_num);
257 end_critical_section(S_FLOORTAB);
263 * Traverse the room file...
265 void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) {
266 struct quickroom qrbuf;
267 struct cdbdata *cdbqr;
269 cdb_rewind(CDB_QUICKROOM);
271 while(cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
272 memset(&qrbuf, 0, sizeof(struct quickroom));
273 memcpy(&qrbuf, cdbqr->ptr,
274 ( (cdbqr->len > sizeof(struct quickroom)) ?
275 sizeof(struct quickroom) : cdbqr->len) );
277 if (qrbuf.QRflags & QR_INUSE) (*CallBack)(&qrbuf);
284 * get_msglist() - retrieve room message pointers
286 void get_msglist(struct quickroom *whichroom) {
287 struct cdbdata *cdbfr;
289 if (CC->msglist != NULL) {
295 cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
300 CC->msglist = malloc(cdbfr->len);
301 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
302 CC->num_msgs = cdbfr->len / sizeof(long);
308 * put_msglist() - retrieve room message pointers
310 void put_msglist(struct quickroom *whichroom) {
312 cdb_store(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long),
313 CC->msglist, CC->num_msgs * sizeof(long));
318 * delete_msglist() - delete room message pointers
319 * FIX - this really should check first to make sure there's actually a
320 * msglist to delete. As things stand now, calling this function on
321 * a room which has never been posted in will result in a message
322 * like "gdbm: illegal data" (no big deal, but could use fixing).
324 void delete_msglist(struct quickroom *whichroom) {
326 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
331 * Add a message number to a room's message list.
332 * So, why doesn't this function use the get_msglist() and put_msglist() stuff
333 * defined above? Because the room the message number is being written to
334 * may not be the current room (as is the case with cmd_move() for example).
336 void AddMessageToRoom(struct quickroom *whichroom, long newmsgid) {
337 struct cdbdata *cdbfr;
341 cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
347 msglist = malloc(cdbfr->len);
348 num_msgs = cdbfr->len / sizeof(long);
349 memcpy(msglist, cdbfr->ptr, cdbfr->len);
353 /* Now add the new message */
355 msglist = realloc(msglist,
356 (num_msgs * sizeof(long)) );
358 if (msglist == NULL) {
359 lprintf(3, "ERROR: can't realloc message list!\n");
362 msglist[num_msgs - 1] = newmsgid;
364 /* Write it back to disk. */
365 cdb_store(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long),
366 msglist, num_msgs * sizeof(long));
368 /* And finally, free up the memory we used. */
374 * MessageFromList() - get a message number from the list currently in memory
376 long MessageFromList(int whichpos) {
378 /* Return zero if the position is invalid */
379 if (whichpos >= CC->num_msgs) return 0L;
381 return(CC->msglist[whichpos]);
385 * SetMessageInList() - set a message number in the list currently in memory
387 void SetMessageInList(int whichpos, long newmsgnum) {
389 /* Return zero if the position is invalid */
390 if (whichpos >= CC->num_msgs) return;
392 CC->msglist[whichpos] = newmsgnum;
398 * sort message pointers
399 * (returns new msg count)
401 int sort_msglist(long listptrs[], int oldcount)
408 if (numitems < 2) return(oldcount);
411 for (a=numitems-2; a>=0; --a) {
412 for (b=0; b<=a; ++b) {
413 if (listptrs[b] > (listptrs[b+1])) {
415 hold2 = listptrs[b+1];
417 listptrs[b+1] = hold1;
422 /* and yank any nulls */
423 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
424 memcpy(&listptrs[0], &listptrs[1],
425 (sizeof(long) * (CC->num_msgs - 1)) );
434 * Determine whether a given room is non-editable.
436 int is_noneditable(struct quickroom *qrbuf) {
438 /* Lobby> and Aide> are non-editable */
439 if (!strcasecmp(qrbuf->QRname, BASEROOM)) return(1);
440 else if (!strcasecmp(qrbuf->QRname, AIDEROOM)) return(1);
442 /* Mailbox rooms are also non-editable */
443 else if (qrbuf->QRflags & QR_MAILBOX) return(1);
445 /* Everything else is editable */
452 * Back-back-end for all room listing commands
454 void list_roomname(struct quickroom *qrbuf) {
455 char truncated_roomname[ROOMNAMELEN];
457 /* For mailbox rooms, chop off the owner prefix */
458 if (qrbuf->QRflags & QR_MAILBOX) {
459 strcpy(truncated_roomname, qrbuf->QRname);
460 strcpy(truncated_roomname, &truncated_roomname[11]);
461 cprintf("%s", truncated_roomname);
463 /* For all other rooms, just display the name in its entirety */
465 cprintf("%s", qrbuf->QRname);
468 /* ...and now the other parameters */
470 qrbuf->QRflags,qrbuf->QRfloor);
475 * cmd_lrms() - List all accessible rooms, known or forgotten
477 void cmd_lrms_backend(struct quickroom *qrbuf) {
478 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
479 & (UA_KNOWN | UA_ZAPPED)))
480 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
481 ||((CC->FloorBeingSearched)<0)) )
482 list_roomname(qrbuf);
485 void cmd_lrms(char *argbuf)
487 CC->FloorBeingSearched = (-1);
488 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
490 if (!(CC->logged_in)) {
491 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
495 if (getuser(&CC->usersupp,CC->curr_user)) {
496 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
500 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
502 ForEachRoom(cmd_lrms_backend);
509 * cmd_lkra() - List all known rooms
511 void cmd_lkra_backend(struct quickroom *qrbuf) {
512 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
514 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
515 ||((CC->FloorBeingSearched)<0)) )
516 list_roomname(qrbuf);
519 void cmd_lkra(char *argbuf)
521 CC->FloorBeingSearched = (-1);
522 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
524 if (!(CC->logged_in)) {
525 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
529 if (getuser(&CC->usersupp,CC->curr_user)) {
530 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
534 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
536 ForEachRoom(cmd_lkra_backend);
543 * cmd_lkrn() - List all known rooms with new messages
545 void cmd_lkrn_backend(struct quickroom *qrbuf) {
548 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
550 && (ra & UA_HASNEWMSGS)
551 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
552 ||((CC->FloorBeingSearched)<0)) )
553 list_roomname(qrbuf);
556 void cmd_lkrn(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/ new msgs:\n",LISTING_FOLLOWS);
573 ForEachRoom(cmd_lkrn_backend);
580 * cmd_lkro() - List all known rooms
582 void cmd_lkro_backend(struct quickroom *qrbuf) {
585 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
587 && ((ra & UA_HASNEWMSGS)==0)
588 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
589 ||((CC->FloorBeingSearched)<0)) )
590 list_roomname(qrbuf);
593 void cmd_lkro(char *argbuf)
595 CC->FloorBeingSearched = (-1);
596 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
598 if (!(CC->logged_in)) {
599 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
603 if (getuser(&CC->usersupp,CC->curr_user)) {
604 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
608 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
610 ForEachRoom(cmd_lkro_backend);
617 * cmd_lzrm() - List all forgotten rooms
619 void cmd_lzrm_backend(struct quickroom *qrbuf) {
622 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
623 if ( (ra & UA_GOTOALLOWED)
625 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
626 ||((CC->FloorBeingSearched)<0)) )
627 list_roomname(qrbuf);
630 void cmd_lzrm(char *argbuf)
632 CC->FloorBeingSearched = (-1);
633 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
635 if (!(CC->logged_in)) {
636 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
640 if (getuser(&CC->usersupp,CC->curr_user)) {
641 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
645 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
647 ForEachRoom(cmd_lzrm_backend);
653 void usergoto(char *where, int display_result)
656 int new_messages = 0;
657 int total_messages = 0;
661 int newmailcount = 0;
663 char truncated_roomname[ROOMNAMELEN];
665 strcpy(CC->quickroom.QRname, where);
666 getroom(&CC->quickroom, where);
667 lgetuser(&CC->usersupp,CC->curr_user);
668 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
670 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
671 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
673 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
674 lputuser(&CC->usersupp,CC->curr_user);
676 /* check for new mail */
677 newmailcount = NewMailCount();
679 /* set info to 1 if the user needs to read the room's info file */
680 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
683 get_msglist(&CC->quickroom);
684 for (a=0; a<CC->num_msgs; ++a) {
685 if (MessageFromList(a)>0L) {
687 if (MessageFromList(a) > vbuf.v_lastseen) {
693 if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1;
696 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
697 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
700 strcpy(truncated_roomname, CC->quickroom.QRname);
701 if (CC->quickroom.QRflags & QR_MAILBOX) {
702 strcpy(truncated_roomname, &truncated_roomname[11]);
705 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
708 new_messages, total_messages,
709 info,CC->quickroom.QRflags,
710 CC->quickroom.QRhighest,
712 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
714 set_wtmpsupp_to_current_room();
719 * cmd_goto() - goto a new room
721 void cmd_goto(char *gargs)
723 struct quickroom QRscratch;
727 char augmented_roomname[256];
731 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
732 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
736 extract(towhere,gargs,0);
737 extract(password,gargs,1);
739 getuser(&CC->usersupp, CC->curr_user);
741 if (!strcasecmp(towhere, "_BASEROOM_"))
742 strcpy(towhere, BASEROOM);
744 if (!strcasecmp(towhere, "_MAIL_"))
745 strcpy(towhere, MAILROOM);
747 if (!strcasecmp(towhere, "_BITBUCKET_"))
748 strcpy(towhere, config.c_twitroom);
751 /* First try a regular match */
752 c = getroom(&QRscratch, towhere);
754 /* Then try a mailbox name match */
756 MailboxName(augmented_roomname, &CC->usersupp, towhere);
757 c = getroom(&QRscratch, augmented_roomname);
758 if (c == 0) strcpy(towhere, augmented_roomname);
761 /* And if the room was found... */
764 /* let internal programs go directly to any room */
765 if (CC->internal_pgm) {
766 usergoto(towhere, 1);
770 /* See if there is an existing user/room relationship */
771 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
773 /* normal clients have to pass through security */
774 if (ra & UA_GOTOALLOWED) ok = 1;
777 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
778 ((ra & UA_KNOWN) == 0) &&
779 (strcasecmp(QRscratch.QRpasswd,password))
781 cprintf("%d wrong or missing passwd\n",
782 ERROR+PASSWORD_REQUIRED);
786 usergoto(towhere, 1);
792 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
796 void cmd_whok(void) {
797 struct usersupp temp;
798 struct cdbdata *cdbus;
800 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
801 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
804 getuser(&CC->usersupp,CC->curr_user);
806 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
807 cprintf("%d Higher access required.\n",
808 ERROR+HIGHER_ACCESS_REQUIRED);
812 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
813 cdb_rewind(CDB_USERSUPP);
814 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
815 memset(&temp, 0, sizeof(struct usersupp));
816 memcpy(&temp, cdbus->ptr, cdbus->len);
819 if ( (CC->quickroom.QRflags & QR_INUSE)
820 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
821 ) cprintf("%s\n",temp.fullname);
828 * RDIR command for room directory
830 void cmd_rdir(void) {
837 if (!(CC->logged_in)) {
838 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
842 getroom(&CC->quickroom, CC->quickroom.QRname);
843 getuser(&CC->usersupp, CC->curr_user);
845 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
846 cprintf("%d not here.\n",ERROR+NOT_HERE);
850 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
851 && (CC->usersupp.axlevel<6)
852 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
853 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
857 cprintf("%d %s|%s/files/%s\n",
858 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
860 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
861 BBSDIR,CC->quickroom.QRdirname,CC->temp);
864 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
866 if (fd==NULL) fd=fopen("/dev/null","r");
868 ls = fopen(CC->temp,"r");
869 while (fgets(flnm,256,ls)!=NULL) {
870 flnm[strlen(flnm)-1]=0;
871 if (strcasecmp(flnm,"filedir")) {
872 sprintf(buf,"%s/files/%s/%s",
873 BBSDIR,CC->quickroom.QRdirname,flnm);
877 while ((fgets(buf,256,fd)!=NULL)
878 &&(strlen(comment)==0)) {
879 buf[strlen(buf)-1] = 0;
880 if ((!strncasecmp(buf,flnm,strlen(flnm)))
881 && (buf[strlen(flnm)]==' '))
883 &buf[strlen(flnm)+1],255);
885 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
896 * get room parameters (aide or room aide command)
898 void cmd_getr(void) {
899 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
900 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
904 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
905 cprintf("%d Higher access required.\n",
906 ERROR+HIGHER_ACCESS_REQUIRED);
910 if (is_noneditable(&CC->quickroom)) {
911 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
915 getroom(&CC->quickroom, CC->quickroom.QRname);
916 cprintf("%d%c%s|%s|%s|%d|%d\n",
918 CC->quickroom.QRname,
919 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
920 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
921 CC->quickroom.QRflags,
922 (int)CC->quickroom.QRfloor);
927 * set room parameters (aide or room aide command)
929 void cmd_setr(char *args) {
932 char old_name[ROOMNAMELEN];
935 if (!(CC->logged_in)) {
936 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
940 if (!is_room_aide()) {
941 cprintf("%d Higher access required.\n",
942 ERROR+HIGHER_ACCESS_REQUIRED);
946 if (is_noneditable(&CC->quickroom)) {
947 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
951 if (num_parms(args)>=6) {
952 getfloor(&flbuf,extract_int(args,5));
953 if ((flbuf.f_flags & F_INUSE) == 0) {
954 cprintf("%d Invalid floor number.\n",
955 ERROR+INVALID_FLOOR_OPERATION);
960 lgetroom(&CC->quickroom, CC->quickroom.QRname);
961 strcpy(old_name, CC->quickroom.QRname);
962 extract(buf,args,0); buf[ROOMNAMELEN]=0;
963 strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
964 extract(buf,args,1); buf[10]=0;
965 strncpy(CC->quickroom.QRpasswd,buf,9);
966 extract(buf,args,2); buf[15]=0;
967 strncpy(CC->quickroom.QRdirname,buf,19);
968 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
970 /* Clean up a client boo-boo: if the client set the room to
971 * guess-name or passworded, ensure that the private flag is
974 if ((CC->quickroom.QRflags & QR_GUESSNAME)
975 ||(CC->quickroom.QRflags & QR_PASSWORDED))
976 CC->quickroom.QRflags |= QR_PRIVATE;
978 /* Kick everyone out if the client requested it (by changing the
979 * room's generation number)
981 if (extract_int(args,4)) {
982 time(&CC->quickroom.QRgen);
985 old_floor = CC->quickroom.QRfloor;
986 if (num_parms(args)>=6) {
987 CC->quickroom.QRfloor = extract_int(args,5);
990 /* Write the room record back to disk */
991 lputroom(&CC->quickroom, CC->quickroom.QRname);
993 /* If the room name changed, then there are now two room records,
994 * so we have to delete the old one.
996 if (strcasecmp(CC->quickroom.QRname, old_name)) {
997 putroom(NULL, old_name);
1000 /* adjust the floor reference counts */
1001 lgetfloor(&flbuf,old_floor);
1002 --flbuf.f_ref_count;
1003 lputfloor(&flbuf,old_floor);
1004 lgetfloor(&flbuf,CC->quickroom.QRfloor);
1005 ++flbuf.f_ref_count;
1006 lputfloor(&flbuf,CC->quickroom.QRfloor);
1008 /* create a room directory if necessary */
1009 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1011 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1012 CC->quickroom.QRdirname);
1016 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
1018 cprintf("%d Ok\n",OK);
1024 * get the name of the room aide for this room
1026 void cmd_geta(void) {
1027 struct usersupp usbuf;
1029 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
1030 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1034 if (is_noneditable(&CC->quickroom)) {
1035 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1039 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
1040 cprintf("%d %s\n",OK,usbuf.fullname);
1043 cprintf("%d \n",OK);
1049 * set the room aide for this room
1051 void cmd_seta(char *new_ra)
1053 struct usersupp usbuf;
1058 if (!(CC->logged_in)) {
1059 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1063 if (!is_room_aide()) {
1064 cprintf("%d Higher access required.\n",
1065 ERROR+HIGHER_ACCESS_REQUIRED);
1069 if (getuser(&usbuf,new_ra)!=0) {
1073 newu = usbuf.usernum;
1076 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1078 if (CC->quickroom.QRroomaide != newu) {
1081 CC->quickroom.QRroomaide = newu;
1082 lputroom(&CC->quickroom, CC->quickroom.QRname);
1085 * We have to post the change notice _after_ writing changes to
1086 * the room table, otherwise it would deadlock!
1088 if (post_notice == 1) {
1089 sprintf(buf,"%s is now room aide for %s>",
1090 usbuf.fullname,CC->quickroom.QRname);
1093 cprintf("%d Ok\n",OK);
1097 * Generate an associated file name for a room
1099 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
1100 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1104 * retrieve info file for this room
1106 void cmd_rinf(void) {
1111 assoc_file_name(filename, &CC->quickroom, "info");
1112 info_fp = fopen(filename,"r");
1114 if (info_fp==NULL) {
1115 cprintf("%d No info file.\n",ERROR);
1119 cprintf("%d Info:\n",LISTING_FOLLOWS);
1120 while (fgets(buf, 256, info_fp) != NULL) {
1121 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1122 cprintf("%s\n", buf);
1129 * Back end processing to delete a room and everything associated with it
1131 void delete_room(struct quickroom *qrbuf) {
1137 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1139 /* Delete the info file */
1140 assoc_file_name(aaa, qrbuf, "info");
1143 /* Delete the image file */
1144 assoc_file_name(aaa, qrbuf, "images");
1147 /* first flag the room record as not in use */
1148 lgetroom(qrbuf, qrbuf->QRname);
1151 /* then delete the messages in the room */
1153 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1154 MsgToDelete = MessageFromList(a);
1155 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1161 delete_msglist(qrbuf);
1162 lputroom(qrbuf, qrbuf->QRname);
1164 /* then decrement the reference count for the floor */
1165 lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
1166 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1167 lputfloor(&flbuf,(int)(qrbuf->QRfloor));
1169 /* Delete the room record from the database! */
1170 putroom(NULL, qrbuf->QRname);
1175 * aide command: kill the current room
1177 void cmd_kill(char *argbuf) {
1179 char deleted_room_name[ROOMNAMELEN];
1182 kill_ok = extract_int(argbuf,0);
1184 if (!(CC->logged_in)) {
1185 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1189 if (!is_room_aide()) {
1190 cprintf("%d Higher access required.\n",
1191 ERROR+HIGHER_ACCESS_REQUIRED);
1195 if (is_noneditable(&CC->quickroom)) {
1196 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1201 strcpy(deleted_room_name, CC->quickroom.QRname);
1202 delete_room(&CC->quickroom); /* Do the dirty work */
1203 usergoto(BASEROOM, 0); /* Return to the Lobby */
1205 /* tell the world what we did */
1206 sprintf(aaa,"%s> killed by %s",
1207 deleted_room_name, CC->curr_user);
1209 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1212 cprintf("%d ok to delete.\n",OK);
1218 * Internal code to create a new room (returns room flags)
1220 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1222 unsigned create_room(char *new_room_name,
1224 char *new_room_pass,
1225 int new_room_floor) {
1227 struct quickroom qrbuf;
1231 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1233 memset(&qrbuf, 0, sizeof(struct quickroom));
1234 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1235 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1236 qrbuf.QRflags = QR_INUSE;
1237 qrbuf.QRnumber = get_new_room_number();
1238 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1239 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1240 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1241 if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
1243 /* If the room is private, and the system administrator has elected
1244 * to automatically grant room aide privileges, do so now; otherwise,
1245 * set the room aide to undefined.
1247 if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) {
1248 qrbuf.QRroomaide=CC->usersupp.usernum;
1251 qrbuf.QRroomaide = (-1L);
1254 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1255 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1256 qrbuf.QRfloor = new_room_floor;
1258 /* save what we just did... */
1259 putroom(&qrbuf, qrbuf.QRname);
1261 /* bump the reference count on whatever floor the room is on */
1262 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1263 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1264 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1266 /* be sure not to kick the creator out of the room! */
1267 lgetuser(&CC->usersupp,CC->curr_user);
1268 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1269 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1270 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1271 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1272 lputuser(&CC->usersupp,CC->curr_user);
1274 /* resume our happy day */
1275 return(qrbuf.QRflags);
1282 void cmd_cre8(char *args)
1285 char new_room_name[256];
1287 char new_room_pass[256];
1291 struct quickroom qrbuf;
1294 cre8_ok = extract_int(args,0);
1295 extract(new_room_name,args,1);
1296 new_room_name[ROOMNAMELEN-1] = 0;
1297 new_room_type = extract_int(args,2);
1298 extract(new_room_pass,args,3);
1299 new_room_pass[9] = 0;
1302 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1303 cprintf("%d Invalid room name.\n",ERROR);
1307 if (num_parms(args)>=5) {
1308 getfloor(&flbuf,extract_int(args,4));
1309 if ((flbuf.f_flags & F_INUSE) == 0) {
1310 cprintf("%d Invalid floor number.\n",
1311 ERROR+INVALID_FLOOR_OPERATION);
1315 new_room_floor = extract_int(args,4);
1319 if (!(CC->logged_in)) {
1320 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1324 if (CC->usersupp.axlevel<3) {
1325 cprintf("%d You need higher access to create rooms.\n",
1326 ERROR+HIGHER_ACCESS_REQUIRED);
1330 if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
1331 cprintf("%d Ok to create rooms.\n", OK);
1335 /* Check to make sure the requested room name doesn't already exist */
1336 if (getroom(&qrbuf, new_room_name)==0) {
1337 cprintf("%d '%s' already exists.\n",
1338 ERROR,qrbuf.QRname);
1342 if ((new_room_type < 0) || (new_room_type > 3)) {
1343 cprintf("%d Invalid room type.\n",ERROR);
1348 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1352 newflags = create_room(new_room_name,
1353 new_room_type,new_room_pass,new_room_floor);
1355 /* post a message in Aide> describing the new room */
1356 strncpy(aaa,new_room_name,255);
1357 strcat(aaa,"> created by ");
1358 strcat(aaa,CC->usersupp.fullname);
1359 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1360 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1361 if (newflags&QR_PASSWORDED) {
1362 strcat(aaa,"\n Password: ");
1363 strcat(aaa,new_room_pass);
1367 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1372 void cmd_einf(char *ok)
1373 { /* enter info file for current room */
1375 char infofilename[256];
1378 if (!(CC->logged_in)) {
1379 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1383 if (!is_room_aide()) {
1384 cprintf("%d Higher access required.\n",
1385 ERROR+HIGHER_ACCESS_REQUIRED);
1390 cprintf("%d Ok.\n",OK);
1394 assoc_file_name(infofilename, &CC->quickroom, "info");
1395 lprintf(9, "opening\n");
1396 fp = fopen(infofilename, "w");
1397 lprintf(9, "checking\n");
1399 cprintf("%d Cannot open %s: %s\n",
1400 ERROR+INTERNAL_ERROR, infofilename, strerror(errno));
1404 cprintf("%d Send info...\n", SEND_LISTING);
1408 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1409 } while(strcmp(buf,"000"));
1412 /* now update the room index so people will see our new info */
1413 lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */
1414 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1415 lputroom(&CC->quickroom,CC->quickroom.QRname);
1420 * cmd_lflr() - List all known floors
1422 void cmd_lflr(void) {
1426 if (!(CC->logged_in)) {
1427 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1431 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1432 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1437 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1439 for (a=0; a<MAXFLOORS; ++a) {
1441 if (flbuf.f_flags & F_INUSE) {
1442 cprintf("%d|%s|%d\n",
1454 * create a new floor
1456 void cmd_cflr(char *argbuf)
1458 char new_floor_name[256];
1461 int free_slot = (-1);
1464 extract(new_floor_name,argbuf,0);
1465 cflr_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 create rooms.\n",
1475 ERROR+HIGHER_ACCESS_REQUIRED);
1479 for (a=0; a<MAXFLOORS; ++a) {
1482 /* note any free slots while we're scanning... */
1483 if ( ((flbuf.f_flags & F_INUSE)==0)
1484 && (free_slot < 0) ) free_slot = a;
1486 /* check to see if it already exists */
1487 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1488 && (flbuf.f_flags & F_INUSE) ) {
1489 cprintf("%d Floor '%s' already exists.\n",
1490 ERROR+ALREADY_EXISTS,
1498 cprintf("%d There is no space available for a new floor.\n",
1499 ERROR+INVALID_FLOOR_OPERATION);
1504 cprintf("%d ok to create...\n",OK);
1508 lgetfloor(&flbuf,free_slot);
1509 flbuf.f_flags = F_INUSE;
1510 flbuf.f_ref_count = 0;
1511 strncpy(flbuf.f_name,new_floor_name,255);
1512 lputfloor(&flbuf,free_slot);
1513 cprintf("%d %d\n",OK,free_slot);
1521 void cmd_kflr(char *argbuf)
1524 int floor_to_delete;
1528 floor_to_delete = extract_int(argbuf,0);
1529 kflr_ok = extract_int(argbuf,1);
1532 if (!(CC->logged_in)) {
1533 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1537 if (CC->usersupp.axlevel<6) {
1538 cprintf("%d You need higher access to delete floors.\n",
1539 ERROR+HIGHER_ACCESS_REQUIRED);
1543 lgetfloor(&flbuf,floor_to_delete);
1546 if ((flbuf.f_flags & F_INUSE) == 0) {
1547 cprintf("%d Floor %d not in use.\n",
1548 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1553 if (flbuf.f_ref_count != 0) {
1554 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1555 ERROR+INVALID_FLOOR_OPERATION,
1562 cprintf("%d Ok\n",OK);
1565 cprintf("%d Ok to delete...\n",OK);
1572 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1573 lputfloor(&flbuf,floor_to_delete);
1579 void cmd_eflr(char *argbuf)
1585 np = num_parms(argbuf);
1587 cprintf("%d Usage error.\n",ERROR);
1591 if (!(CC->logged_in)) {
1592 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1596 if (CC->usersupp.axlevel<6) {
1597 cprintf("%d You need higher access to edit floors.\n",
1598 ERROR+HIGHER_ACCESS_REQUIRED);
1602 floor_num = extract_int(argbuf,0);
1603 lgetfloor(&flbuf,floor_num);
1604 if ( (flbuf.f_flags & F_INUSE) == 0) {
1605 lputfloor(&flbuf,floor_num);
1606 cprintf("%d Floor %d is not in use.\n",
1607 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1610 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1611 lputfloor(&flbuf,floor_num);
1613 cprintf("%d Ok\n",OK);