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 /* For mailbox rooms, only allow access to the owner */
42 if (roombuf->QRflags & QR_MAILBOX) {
43 if (userbuf->usernum != atol(roombuf->QRname)) {
48 /* Locate any applicable user/room relationships */
49 CtdlGetRelationship(&vbuf, userbuf, roombuf);
51 /* If this is a public room, it's accessible... */
52 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
53 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
56 /* If this is a preferred users only room, check access level */
57 if (roombuf->QRflags & QR_PREFONLY) {
58 if (userbuf->axlevel < 5) {
59 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
63 /* For private rooms, check the generation number matchups */
64 if (roombuf->QRflags & QR_PRIVATE) {
66 /* An explicit match means the user belongs in this room */
67 if (vbuf.v_flags & V_ACCESS) {
68 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
70 /* Otherwise, check if this is a guess-name or passworded
71 * room. If it is, a goto may at least be attempted
73 else if ((roombuf->QRflags & QR_PRIVATE)
74 ||(roombuf->QRflags & QR_PASSWORDED)) {
75 retval = retval & ~UA_KNOWN;
76 retval = retval | UA_GOTOALLOWED;
80 /* Check to see if the user has forgotten this room */
81 if (vbuf.v_flags & V_FORGET) {
82 retval = retval & ~UA_KNOWN;
83 retval = retval | UA_ZAPPED;
86 /* If user is explicitly locked out of this room, deny everything */
87 if (vbuf.v_flags & V_LOCKOUT) {
88 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
91 /* Aides get access to everything */
92 if (userbuf->axlevel >= 6) {
93 retval = retval | UA_INUSE | UA_KNOWN | UA_GOTOALLOWED;
94 retval = retval & ~UA_ZAPPED;
97 /* By the way, we also check for the presence of new messages */
98 if ( (roombuf->QRhighest) > (vbuf.v_lastseen) ) {
99 retval = retval | UA_HASNEWMSGS;
106 * getroom() - retrieve room data from disk
108 int getroom(struct quickroom *qrbuf, char *room_name)
110 struct cdbdata *cdbqr;
111 char lowercase_name[ROOMNAMELEN];
114 for (a=0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
115 lowercase_name[a] = tolower(room_name[a]);
117 lowercase_name[a] = 0;
119 memset(qrbuf, 0, sizeof(struct quickroom));
120 cdbqr = cdb_fetch(CDB_QUICKROOM,
121 lowercase_name, strlen(lowercase_name));
123 memcpy(qrbuf, cdbqr->ptr,
124 ( (cdbqr->len > sizeof(struct quickroom)) ?
125 sizeof(struct quickroom) : cdbqr->len) );
135 * lgetroom() - same as getroom() but locks the record (if supported)
137 int lgetroom(struct quickroom *qrbuf, char *room_name)
139 begin_critical_section(S_QUICKROOM);
140 return(getroom(qrbuf, room_name));
145 * putroom() - store room data on disk
146 * (if the supplied buffer is NULL, delete the room record)
148 void putroom(struct quickroom *qrbuf, char *room_name)
150 char lowercase_name[ROOMNAMELEN];
153 for (a=0; a<=strlen(room_name); ++a) {
154 lowercase_name[a] = tolower(room_name[a]);
158 cdb_delete(CDB_QUICKROOM,
159 lowercase_name, strlen(lowercase_name));
162 time(&qrbuf->QRmtime);
163 cdb_store(CDB_QUICKROOM,
164 lowercase_name, strlen(lowercase_name),
165 qrbuf, sizeof(struct quickroom));
171 * lputroom() - same as putroom() but unlocks the record (if supported)
173 void lputroom(struct quickroom *qrbuf, char *room_name)
176 putroom(qrbuf, room_name);
177 end_critical_section(S_QUICKROOM);
181 /****************************************************************************/
184 * getfloor() - retrieve floor data from disk
186 void getfloor(struct floor *flbuf, int floor_num)
188 struct cdbdata *cdbfl;
190 memset(flbuf, 0, sizeof(struct floor));
191 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
193 memcpy(flbuf, cdbfl->ptr,
194 ( (cdbfl->len > sizeof(struct floor)) ?
195 sizeof(struct floor) : cdbfl->len) );
199 if (floor_num == 0) {
200 strcpy(flbuf->f_name, "Main Floor");
201 flbuf->f_flags = F_INUSE;
202 flbuf->f_ref_count = 3;
209 * lgetfloor() - same as getfloor() but locks the record (if supported)
211 void lgetfloor(struct floor *flbuf, int floor_num)
214 begin_critical_section(S_FLOORTAB);
215 getfloor(flbuf,floor_num);
220 * putfloor() - store floor data on disk
222 void putfloor(struct floor *flbuf, int floor_num)
224 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
225 flbuf, sizeof(struct floor));
230 * lputfloor() - same as putfloor() but unlocks the record (if supported)
232 void lputfloor(struct floor *flbuf, int floor_num)
235 putfloor(flbuf,floor_num);
236 end_critical_section(S_FLOORTAB);
242 * Traverse the room file...
244 void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) {
245 struct quickroom qrbuf;
246 struct cdbdata *cdbqr;
248 cdb_rewind(CDB_QUICKROOM);
250 while(cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
251 memset(&qrbuf, 0, sizeof(struct quickroom));
252 memcpy(&qrbuf, cdbqr->ptr,
253 ( (cdbqr->len > sizeof(struct quickroom)) ?
254 sizeof(struct quickroom) : cdbqr->len) );
256 if (qrbuf.QRflags & QR_INUSE) (*CallBack)(&qrbuf);
263 * Create a database key for storage of message lists
265 void msglist_key(char *dbkey, struct quickroom *whichroom) {
268 sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
269 for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
273 * get_msglist() - retrieve room message pointers
275 void get_msglist(struct quickroom *whichroom) {
276 struct cdbdata *cdbfr;
279 msglist_key(dbkey, whichroom);
281 if (CC->msglist != NULL) {
287 cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey));
292 CC->msglist = malloc(cdbfr->len);
293 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
294 CC->num_msgs = cdbfr->len / sizeof(long);
300 * put_msglist() - retrieve room message pointers
302 void put_msglist(struct quickroom *whichroom) {
305 msglist_key(dbkey, whichroom);
306 cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey),
307 CC->msglist, CC->num_msgs * sizeof(long));
312 * delete_msglist() - delete room message pointers
314 void delete_msglist(struct quickroom *whichroom) {
317 msglist_key(dbkey, whichroom);
318 cdb_delete(CDB_MSGLISTS, dbkey, strlen(dbkey));
323 * Add a message number to a room's message list.
324 * So, why doesn't this function use the get_msglist() and put_msglist() stuff
325 * defined above? Because the room the message number is being written to
326 * may not be the current room (as is the case with cmd_move() for example).
328 void AddMessageToRoom(struct quickroom *whichroom, long newmsgid) {
330 struct cdbdata *cdbfr;
334 msglist_key(dbkey, whichroom);
335 cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey));
341 msglist = malloc(cdbfr->len);
342 num_msgs = cdbfr->len / sizeof(long);
343 memcpy(msglist, cdbfr->ptr, cdbfr->len);
347 /* Now add the new message */
349 msglist = realloc(msglist,
350 (num_msgs * sizeof(long)) );
352 if (msglist == NULL) {
353 lprintf(3, "ERROR: can't realloc message list!\n");
356 msglist[num_msgs - 1] = newmsgid;
358 /* Write it back to disk. */
359 cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey),
360 msglist, num_msgs * sizeof(long));
362 /* And finally, free up the memory we used. */
368 * MessageFromList() - get a message number from the list currently in memory
370 long MessageFromList(int whichpos) {
372 /* Return zero if the position is invalid */
373 if (whichpos >= CC->num_msgs) return 0L;
375 return(CC->msglist[whichpos]);
379 * SetMessageInList() - set a message number in the list currently in memory
381 void SetMessageInList(int whichpos, long newmsgnum) {
383 /* Return zero if the position is invalid */
384 if (whichpos >= CC->num_msgs) return;
386 CC->msglist[whichpos] = newmsgnum;
392 * sort message pointers
393 * (returns new msg count)
395 int sort_msglist(long listptrs[], int oldcount)
402 if (numitems < 2) return(oldcount);
405 for (a=numitems-2; a>=0; --a) {
406 for (b=0; b<=a; ++b) {
407 if (listptrs[b] > (listptrs[b+1])) {
409 hold2 = listptrs[b+1];
411 listptrs[b+1] = hold1;
416 /* and yank any nulls */
417 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
418 memcpy(&listptrs[0], &listptrs[1],
419 (sizeof(long) * (CC->num_msgs - 1)) );
428 * Determine whether a given room is one of the base non-editable rooms
430 int is_noneditable(struct quickroom *qrbuf) {
431 if (!strcasecmp(qrbuf->QRname, BASEROOM)) return(1);
432 else if (!strcasecmp(qrbuf->QRname, AIDEROOM)) return(1);
439 * Retrieve the applicable room policy for a specific room
441 void GetExpirePolicy(struct ExpirePolicy *epbuf, struct quickroom *qrbuf) {
444 /* If the room has its own policy, return it */
445 if (qrbuf->QRep.expire_mode != 0) {
446 memcpy(epbuf, &qrbuf->QRep, sizeof(struct ExpirePolicy));
450 /* Otherwise, if the floor has its own policy, return it */
451 getfloor(&flbuf, qrbuf->QRfloor);
452 if (flbuf.f_ep.expire_mode != 0) {
453 memcpy(epbuf, &flbuf.f_ep, sizeof(struct ExpirePolicy));
457 /* Otherwise, fall back on the system default */
458 memcpy(epbuf, &config.c_ep, sizeof(struct ExpirePolicy));
464 * cmd_lrms() - List all accessible rooms, known or forgotten
466 void cmd_lrms_backend(struct quickroom *qrbuf) {
467 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
468 & (UA_KNOWN | UA_ZAPPED)))
469 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
470 ||((CC->FloorBeingSearched)<0)) )
471 cprintf("%s|%u|%d\n",
472 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
475 void cmd_lrms(char *argbuf)
477 CC->FloorBeingSearched = (-1);
478 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
480 if (!(CC->logged_in)) {
481 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
485 if (getuser(&CC->usersupp,CC->curr_user)) {
486 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
490 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
492 ForEachRoom(cmd_lrms_backend);
499 * cmd_lkra() - List all known rooms
501 void cmd_lkra_backend(struct quickroom *qrbuf) {
502 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
504 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
505 ||((CC->FloorBeingSearched)<0)) )
506 cprintf("%s|%u|%d\n",
507 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
510 void cmd_lkra(char *argbuf)
512 CC->FloorBeingSearched = (-1);
513 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
515 if (!(CC->logged_in)) {
516 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
520 if (getuser(&CC->usersupp,CC->curr_user)) {
521 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
525 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
527 ForEachRoom(cmd_lkra_backend);
534 * cmd_lkrn() - List all known rooms with new messages
536 void cmd_lkrn_backend(struct quickroom *qrbuf) {
539 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
541 && (ra & UA_HASNEWMSGS)
542 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
543 ||((CC->FloorBeingSearched)<0)) )
544 cprintf("%s|%u|%d\n",
545 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
548 void cmd_lkrn(char *argbuf)
550 CC->FloorBeingSearched = (-1);
551 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
553 if (!(CC->logged_in)) {
554 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
558 if (getuser(&CC->usersupp,CC->curr_user)) {
559 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
563 cprintf("%d Rooms w/ new msgs:\n",LISTING_FOLLOWS);
565 ForEachRoom(cmd_lkrn_backend);
572 * cmd_lkro() - List all known rooms
574 void cmd_lkro_backend(struct quickroom *qrbuf) {
577 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
579 && ((ra & UA_HASNEWMSGS)==0)
580 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
581 ||((CC->FloorBeingSearched)<0)) )
582 cprintf("%s|%u|%d\n",
583 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
586 void cmd_lkro(char *argbuf)
588 CC->FloorBeingSearched = (-1);
589 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
591 if (!(CC->logged_in)) {
592 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
596 if (getuser(&CC->usersupp,CC->curr_user)) {
597 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
601 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
603 ForEachRoom(cmd_lkro_backend);
610 * cmd_lzrm() - List all forgotten rooms
612 void cmd_lzrm_backend(struct quickroom *qrbuf) {
615 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
616 if ( (ra & UA_GOTOALLOWED)
618 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
619 ||((CC->FloorBeingSearched)<0)) )
620 cprintf("%s|%u|%d\n",
621 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
624 void cmd_lzrm(char *argbuf)
626 CC->FloorBeingSearched = (-1);
627 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
629 if (!(CC->logged_in)) {
630 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
634 if (getuser(&CC->usersupp,CC->curr_user)) {
635 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
639 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
641 ForEachRoom(cmd_lzrm_backend);
647 void usergoto(char *where, int display_result)
650 int new_messages = 0;
651 int total_messages = 0;
655 int newmailcount = 0;
658 strcpy(CC->quickroom.QRname, where);
659 getroom(&CC->quickroom, where);
660 lgetuser(&CC->usersupp,CC->curr_user);
661 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
663 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
664 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
666 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
667 lputuser(&CC->usersupp,CC->curr_user);
669 /* check for new mail */
670 newmailcount = NewMailCount();
672 /* set info to 1 if the user needs to read the room's info file */
673 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
676 get_msglist(&CC->quickroom);
677 for (a=0; a<CC->num_msgs; ++a) {
678 if (MessageFromList(a)>0L) {
680 if (MessageFromList(a) > vbuf.v_lastseen) {
686 if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1;
689 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
690 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
693 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
695 CC->quickroom.QRname,
696 new_messages, total_messages,
697 info,CC->quickroom.QRflags,
698 CC->quickroom.QRhighest,
700 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
702 if (CC->quickroom.QRflags & QR_PRIVATE) {
703 set_wtmpsupp("<private room>");
706 set_wtmpsupp(CC->quickroom.QRname);
712 * cmd_goto() - goto a new room
714 void cmd_goto(char *gargs)
716 struct quickroom QRscratch;
720 char bbb[ROOMNAMELEN],towhere[256],password[256];
722 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
723 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
727 extract(towhere,gargs,0);
728 extract(password,gargs,1);
731 getuser(&CC->usersupp, CC->curr_user);
733 if (!strcasecmp(towhere, "_BASEROOM_"))
734 strcpy(towhere, BASEROOM);
736 if (!strcasecmp(towhere, "_MAIL_"))
737 strcpy(towhere, MAILROOM);
739 if (!strcasecmp(towhere, "_BITBUCKET_"))
740 strcpy(towhere, config.c_twitroom);
743 /* let internal programs go directly to any room */
744 if (((CC->internal_pgm))&&(!strcasecmp(bbb,towhere))) {
745 usergoto(towhere, 1);
749 if (getroom(&QRscratch, towhere) == 0) {
751 /* See if there is an existing user/room relationship */
752 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
754 /* normal clients have to pass through security */
755 if (ra & UA_GOTOALLOWED) ok = 1;
758 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
759 ((ra & UA_KNOWN) == 0) &&
760 (strcasecmp(QRscratch.QRpasswd,password))
762 cprintf("%d wrong or missing passwd\n",
763 ERROR+PASSWORD_REQUIRED);
767 usergoto(towhere, 1);
773 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
777 void cmd_whok(void) {
778 struct usersupp temp;
779 struct cdbdata *cdbus;
781 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
782 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
785 getuser(&CC->usersupp,CC->curr_user);
787 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
788 cprintf("%d Higher access required.\n",
789 ERROR+HIGHER_ACCESS_REQUIRED);
793 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
794 cdb_rewind(CDB_USERSUPP);
795 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
796 memset(&temp, 0, sizeof(struct usersupp));
797 memcpy(&temp, cdbus->ptr, cdbus->len);
800 if ( (CC->quickroom.QRflags & QR_INUSE)
801 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
802 ) cprintf("%s\n",temp.fullname);
809 * RDIR command for room directory
811 void cmd_rdir(void) {
818 if (!(CC->logged_in)) {
819 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
823 getroom(&CC->quickroom, CC->quickroom.QRname);
824 getuser(&CC->usersupp, CC->curr_user);
826 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
827 cprintf("%d not here.\n",ERROR+NOT_HERE);
831 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
832 && (CC->usersupp.axlevel<6)
833 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
834 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
838 cprintf("%d %s|%s/files/%s\n",
839 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
841 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
842 BBSDIR,CC->quickroom.QRdirname,CC->temp);
845 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
847 if (fd==NULL) fd=fopen("/dev/null","r");
849 ls = fopen(CC->temp,"r");
850 while (fgets(flnm,256,ls)!=NULL) {
851 flnm[strlen(flnm)-1]=0;
852 if (strcasecmp(flnm,"filedir")) {
853 sprintf(buf,"%s/files/%s/%s",
854 BBSDIR,CC->quickroom.QRdirname,flnm);
858 while ((fgets(buf,256,fd)!=NULL)
859 &&(strlen(comment)==0)) {
860 buf[strlen(buf)-1] = 0;
861 if ((!strncasecmp(buf,flnm,strlen(flnm)))
862 && (buf[strlen(flnm)]==' '))
864 &buf[strlen(flnm)+1],255);
866 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
877 * get room parameters (aide or room aide command)
879 void cmd_getr(void) {
880 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
881 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
885 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
886 cprintf("%d Higher access required.\n",
887 ERROR+HIGHER_ACCESS_REQUIRED);
891 if (is_noneditable(&CC->quickroom)) {
892 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
896 getroom(&CC->quickroom, CC->quickroom.QRname);
897 cprintf("%d%c%s|%s|%s|%d|%d\n",
899 CC->quickroom.QRname,
900 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
901 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
902 CC->quickroom.QRflags,
903 (int)CC->quickroom.QRfloor);
908 * set room parameters (aide or room aide command)
910 void cmd_setr(char *args) {
915 if (!(CC->logged_in)) {
916 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
920 if (!is_room_aide()) {
921 cprintf("%d Higher access required.\n",
922 ERROR+HIGHER_ACCESS_REQUIRED);
926 if (is_noneditable(&CC->quickroom)) {
927 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
931 if (num_parms(args)>=6) {
932 getfloor(&flbuf,extract_int(args,5));
933 if ((flbuf.f_flags & F_INUSE) == 0) {
934 cprintf("%d Invalid floor number.\n",
935 ERROR+INVALID_FLOOR_OPERATION);
940 lgetroom(&CC->quickroom, CC->quickroom.QRname);
941 extract(buf,args,0); buf[ROOMNAMELEN]=0;
942 strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
943 extract(buf,args,1); buf[10]=0;
944 strncpy(CC->quickroom.QRpasswd,buf,9);
945 extract(buf,args,2); buf[15]=0;
946 strncpy(CC->quickroom.QRdirname,buf,19);
947 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
949 /* Clean up a client boo-boo: if the client set the room to
950 * guess-name or passworded, ensure that the private flag is
953 if ((CC->quickroom.QRflags & QR_GUESSNAME)
954 ||(CC->quickroom.QRflags & QR_PASSWORDED))
955 CC->quickroom.QRflags |= QR_PRIVATE;
957 /* Kick everyone out if the client requested it (by changing the
958 * room's generation number)
960 if (extract_int(args,4)) {
961 time(&CC->quickroom.QRgen);
964 old_floor = CC->quickroom.QRfloor;
965 if (num_parms(args)>=6) {
966 CC->quickroom.QRfloor = extract_int(args,5);
969 lputroom(&CC->quickroom, CC->quickroom.QRname);
971 /* adjust the floor reference counts */
972 lgetfloor(&flbuf,old_floor);
974 lputfloor(&flbuf,old_floor);
975 lgetfloor(&flbuf,CC->quickroom.QRfloor);
977 lputfloor(&flbuf,CC->quickroom.QRfloor);
979 /* create a room directory if necessary */
980 if (CC->quickroom.QRflags & QR_DIRECTORY) {
982 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
983 CC->quickroom.QRdirname);
987 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
989 cprintf("%d Ok\n",OK);
995 * get the name of the room aide for this room
997 void cmd_geta(void) {
998 struct usersupp usbuf;
1000 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
1001 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1005 if (is_noneditable(&CC->quickroom)) {
1006 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1010 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
1011 cprintf("%d %s\n",OK,usbuf.fullname);
1014 cprintf("%d \n",OK);
1020 * set the room aide for this room
1022 void cmd_seta(char *new_ra)
1024 struct usersupp usbuf;
1029 if (!(CC->logged_in)) {
1030 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1034 if (!is_room_aide()) {
1035 cprintf("%d Higher access required.\n",
1036 ERROR+HIGHER_ACCESS_REQUIRED);
1040 if (getuser(&usbuf,new_ra)!=0) {
1044 newu = usbuf.usernum;
1047 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1049 if (CC->quickroom.QRroomaide != newu) {
1052 CC->quickroom.QRroomaide = newu;
1053 lputroom(&CC->quickroom, CC->quickroom.QRname);
1056 * We have to post the change notice _after_ writing changes to
1057 * the room table, otherwise it would deadlock!
1059 if (post_notice == 1) {
1060 sprintf(buf,"%s is now room aide for %s>",
1061 usbuf.fullname,CC->quickroom.QRname);
1064 cprintf("%d Ok\n",OK);
1068 * Generate an associated file name for a room
1070 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
1073 sprintf(buf, "./prefix/%s.%ld", qrbuf->QRname, qrbuf->QRgen);
1074 for (a=0; a<strlen(buf); ++a) {
1075 if (buf[a]==32) buf[a]='.';
1080 * retrieve info file for this room
1082 void cmd_rinf(void) {
1087 assoc_file_name(filename, &CC->quickroom, "info");
1088 info_fp = fopen(filename,"r");
1090 if (info_fp==NULL) {
1091 cprintf("%d No info file.\n",ERROR);
1095 cprintf("%d Info:\n",LISTING_FOLLOWS);
1096 while (fgets(buf, 256, info_fp) != NULL) {
1097 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1098 cprintf("%s\n", buf);
1105 * Back end processing to delete a room and everything associated with it
1107 void delete_room(struct quickroom *qrbuf) {
1113 /* Delete the info file */
1114 assoc_file_name(aaa, qrbuf, "info");
1117 /* Delete the image file */
1118 assoc_file_name(aaa, qrbuf, "images");
1121 /* first flag the room record as not in use */
1122 lgetroom(qrbuf, qrbuf->QRname);
1125 /* then delete the messages in the room */
1127 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1128 MsgToDelete = MessageFromList(a);
1129 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1135 delete_msglist(qrbuf);
1136 lputroom(qrbuf, qrbuf->QRname);
1138 /* then decrement the reference count for the floor */
1139 lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
1140 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1141 lputfloor(&flbuf,(int)(qrbuf->QRfloor));
1143 /* Delete the room record from the database! */
1144 putroom(NULL, qrbuf->QRname);
1149 * aide command: kill the current room
1151 void cmd_kill(char *argbuf) {
1153 char deleted_room_name[ROOMNAMELEN];
1156 kill_ok = extract_int(argbuf,0);
1158 if (!(CC->logged_in)) {
1159 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1163 if (!is_room_aide()) {
1164 cprintf("%d Higher access required.\n",
1165 ERROR+HIGHER_ACCESS_REQUIRED);
1169 if (is_noneditable(&CC->quickroom)) {
1170 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1175 strcpy(deleted_room_name, CC->quickroom.QRname);
1176 delete_room(&CC->quickroom); /* Do the dirty work */
1177 usergoto(BASEROOM, 0); /* Return to the Lobby */
1179 /* tell the world what we did */
1180 sprintf(aaa,"%s> killed by %s",
1181 deleted_room_name, CC->curr_user);
1183 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1186 cprintf("%d ok to delete.\n",OK);
1192 * Internal code to create a new room (returns room flags)
1194 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1196 unsigned create_room(char *new_room_name,
1198 char *new_room_pass,
1199 int new_room_floor) {
1201 struct quickroom qrbuf;
1205 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1207 memset(&qrbuf, 0, sizeof(struct quickroom));
1208 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1209 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1210 qrbuf.QRflags = QR_INUSE;
1211 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1212 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1213 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1214 if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
1216 /* If the room is private, and the system administrator has elected
1217 * to automatically grant room aide privileges, do so now; otherwise,
1218 * set the room aide to undefined.
1220 if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) {
1221 qrbuf.QRroomaide=CC->usersupp.usernum;
1224 qrbuf.QRroomaide = (-1L);
1227 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1228 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1229 qrbuf.QRfloor = new_room_floor;
1231 /* save what we just did... */
1232 putroom(&qrbuf, qrbuf.QRname);
1234 /* bump the reference count on whatever floor the room is on */
1235 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1236 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1237 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1239 /* be sure not to kick the creator out of the room! */
1240 lgetuser(&CC->usersupp,CC->curr_user);
1241 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1242 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1243 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1244 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1245 lputuser(&CC->usersupp,CC->curr_user);
1247 /* resume our happy day */
1248 return(qrbuf.QRflags);
1255 void cmd_cre8(char *args)
1258 char new_room_name[256];
1260 char new_room_pass[256];
1264 struct quickroom qrbuf;
1267 cre8_ok = extract_int(args,0);
1268 extract(new_room_name,args,1);
1269 new_room_name[ROOMNAMELEN-1] = 0;
1270 new_room_type = extract_int(args,2);
1271 extract(new_room_pass,args,3);
1272 new_room_pass[9] = 0;
1275 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1276 cprintf("%d Invalid room name.\n",ERROR);
1280 if (num_parms(args)>=5) {
1281 getfloor(&flbuf,extract_int(args,4));
1282 if ((flbuf.f_flags & F_INUSE) == 0) {
1283 cprintf("%d Invalid floor number.\n",
1284 ERROR+INVALID_FLOOR_OPERATION);
1288 new_room_floor = extract_int(args,4);
1292 if (!(CC->logged_in)) {
1293 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1297 if (CC->usersupp.axlevel<3) {
1298 cprintf("%d You need higher access to create rooms.\n",
1299 ERROR+HIGHER_ACCESS_REQUIRED);
1303 if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
1304 cprintf("%d Ok to create rooms.\n", OK);
1308 /* Check to make sure the requested room name doesn't already exist */
1309 if (getroom(&qrbuf, new_room_name)==0) {
1310 cprintf("%d '%s' already exists.\n",
1311 ERROR,qrbuf.QRname);
1315 if ((new_room_type < 0) || (new_room_type > 3)) {
1316 cprintf("%d Invalid room type.\n",ERROR);
1321 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1325 newflags = create_room(new_room_name,
1326 new_room_type,new_room_pass,new_room_floor);
1328 /* post a message in Aide> describing the new room */
1329 strncpy(aaa,new_room_name,255);
1330 strcat(aaa,"> created by ");
1331 strcat(aaa,CC->usersupp.fullname);
1332 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1333 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1334 if (newflags&QR_PASSWORDED) {
1335 strcat(aaa,"\n Password: ");
1336 strcat(aaa,new_room_pass);
1340 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1345 void cmd_einf(char *ok)
1346 { /* enter info file for current room */
1348 char infofilename[64];
1351 if (!(CC->logged_in)) {
1352 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1356 if (!is_room_aide()) {
1357 cprintf("%d Higher access required.\n",
1358 ERROR+HIGHER_ACCESS_REQUIRED);
1363 cprintf("%d Ok.\n",OK);
1367 cprintf("%d Send info...\n",SEND_LISTING);
1369 assoc_file_name(infofilename, &CC->quickroom, "info");
1371 fp=fopen(infofilename,"w");
1374 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1375 } while(strcmp(buf,"000"));
1378 /* now update the room index so people will see our new info */
1379 lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */
1380 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1381 lputroom(&CC->quickroom,CC->quickroom.QRname);
1386 * cmd_lflr() - List all known floors
1388 void cmd_lflr(void) {
1392 if (!(CC->logged_in)) {
1393 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1397 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1398 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1403 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1405 for (a=0; a<MAXFLOORS; ++a) {
1407 if (flbuf.f_flags & F_INUSE) {
1408 cprintf("%d|%s|%d\n",
1420 * create a new floor
1422 void cmd_cflr(char *argbuf)
1424 char new_floor_name[256];
1427 int free_slot = (-1);
1430 extract(new_floor_name,argbuf,0);
1431 cflr_ok = extract_int(argbuf,1);
1434 if (!(CC->logged_in)) {
1435 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1439 if (CC->usersupp.axlevel<6) {
1440 cprintf("%d You need higher access to create rooms.\n",
1441 ERROR+HIGHER_ACCESS_REQUIRED);
1445 for (a=0; a<MAXFLOORS; ++a) {
1448 /* note any free slots while we're scanning... */
1449 if ( ((flbuf.f_flags & F_INUSE)==0)
1450 && (free_slot < 0) ) free_slot = a;
1452 /* check to see if it already exists */
1453 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1454 && (flbuf.f_flags & F_INUSE) ) {
1455 cprintf("%d Floor '%s' already exists.\n",
1456 ERROR+ALREADY_EXISTS,
1464 cprintf("%d There is no space available for a new floor.\n",
1465 ERROR+INVALID_FLOOR_OPERATION);
1470 cprintf("%d ok to create...\n",OK);
1474 lgetfloor(&flbuf,free_slot);
1475 flbuf.f_flags = F_INUSE;
1476 flbuf.f_ref_count = 0;
1477 strncpy(flbuf.f_name,new_floor_name,255);
1478 lputfloor(&flbuf,free_slot);
1479 cprintf("%d %d\n",OK,free_slot);
1487 void cmd_kflr(char *argbuf)
1490 int floor_to_delete;
1494 floor_to_delete = extract_int(argbuf,0);
1495 kflr_ok = extract_int(argbuf,1);
1498 if (!(CC->logged_in)) {
1499 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1503 if (CC->usersupp.axlevel<6) {
1504 cprintf("%d You need higher access to delete floors.\n",
1505 ERROR+HIGHER_ACCESS_REQUIRED);
1509 lgetfloor(&flbuf,floor_to_delete);
1512 if ((flbuf.f_flags & F_INUSE) == 0) {
1513 cprintf("%d Floor %d not in use.\n",
1514 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1519 if (flbuf.f_ref_count != 0) {
1520 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1521 ERROR+INVALID_FLOOR_OPERATION,
1528 cprintf("%d Ok\n",OK);
1531 cprintf("%d Ok to delete...\n",OK);
1538 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1539 lputfloor(&flbuf,floor_to_delete);
1545 void cmd_eflr(char *argbuf)
1551 np = num_parms(argbuf);
1553 cprintf("%d Usage error.\n",ERROR);
1557 if (!(CC->logged_in)) {
1558 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1562 if (CC->usersupp.axlevel<6) {
1563 cprintf("%d You need higher access to edit floors.\n",
1564 ERROR+HIGHER_ACCESS_REQUIRED);
1568 floor_num = extract_int(argbuf,0);
1569 lgetfloor(&flbuf,floor_num);
1570 if ( (flbuf.f_flags & F_INUSE) == 0) {
1571 lputfloor(&flbuf,floor_num);
1572 cprintf("%d Floor %d is not in use.\n",
1573 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1576 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1577 lputfloor(&flbuf,floor_num);
1579 cprintf("%d Ok\n",OK);