15 #include "sysdep_decls.h"
19 #include "serv_chat.h"
20 #include "citserver.h"
23 * Generic routine for determining user access to rooms
25 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf) {
29 /* for internal programs, always do everything */
30 if (((CC->internal_pgm))&&(roombuf->QRflags & QR_INUSE)) {
31 return(UA_KNOWN | UA_GOTOALLOWED);
34 /* For mailbox rooms, only allow access to the owner */
35 if (roombuf->QRflags & QR_MAILBOX) {
36 if (userbuf->usernum != atol(roombuf->QRname)) {
41 /* Locate any applicable user/room relationships */
42 CtdlGetRelationship(&vbuf, userbuf, roombuf);
44 /* For mailboxes, we skip all the access stuff (and we've
45 * already checked by this point that the mailbox belongs
48 if (roombuf->QRflags & QR_MAILBOX) {
49 retval = UA_KNOWN | UA_GOTOALLOWED;
53 /* If this is a public room, it's accessible... */
54 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
55 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
58 /* If this is a preferred users only room, check access level */
59 if (roombuf->QRflags & QR_PREFONLY) {
60 if (userbuf->axlevel < 5) {
61 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
65 /* For private rooms, check the generation number matchups */
66 if (roombuf->QRflags & QR_PRIVATE) {
68 /* An explicit match means the user belongs in this room */
69 if (vbuf.v_flags & V_ACCESS) {
70 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
72 /* Otherwise, check if this is a guess-name or passworded
73 * room. If it is, a goto may at least be attempted
75 else if ((roombuf->QRflags & QR_PRIVATE)
76 ||(roombuf->QRflags & QR_PASSWORDED)) {
77 retval = retval & ~UA_KNOWN;
78 retval = retval | UA_GOTOALLOWED;
82 /* Check to see if the user has forgotten this room */
83 if (vbuf.v_flags & V_FORGET) {
84 retval = retval & ~UA_KNOWN;
85 retval = retval | UA_ZAPPED;
88 /* If user is explicitly locked out of this room, deny everything */
89 if (vbuf.v_flags & V_LOCKOUT) {
90 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
93 /* Aides get access to everything */
94 if (userbuf->axlevel >= 6) {
95 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
96 retval = retval & ~UA_ZAPPED;
99 NEWMSG: /* By the way, we also check for the presence of new messages */
100 if ( (roombuf->QRhighest) > (vbuf.v_lastseen) ) {
101 retval = retval | UA_HASNEWMSGS;
108 * getroom() - retrieve room data from disk
110 int getroom(struct quickroom *qrbuf, char *room_name)
112 struct cdbdata *cdbqr;
113 char lowercase_name[ROOMNAMELEN];
116 for (a=0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
117 lowercase_name[a] = tolower(room_name[a]);
119 lowercase_name[a] = 0;
121 memset(qrbuf, 0, sizeof(struct quickroom));
122 cdbqr = cdb_fetch(CDB_QUICKROOM,
123 lowercase_name, strlen(lowercase_name));
125 memcpy(qrbuf, cdbqr->ptr,
126 ( (cdbqr->len > sizeof(struct quickroom)) ?
127 sizeof(struct quickroom) : cdbqr->len) );
137 * lgetroom() - same as getroom() but locks the record (if supported)
139 int lgetroom(struct quickroom *qrbuf, char *room_name)
141 begin_critical_section(S_QUICKROOM);
142 return(getroom(qrbuf, room_name));
147 * putroom() - store room data on disk
148 * (if the supplied buffer is NULL, delete the room record)
150 void putroom(struct quickroom *qrbuf, char *room_name)
152 char lowercase_name[ROOMNAMELEN];
155 for (a=0; a<=strlen(room_name); ++a) {
156 lowercase_name[a] = tolower(room_name[a]);
160 cdb_delete(CDB_QUICKROOM,
161 lowercase_name, strlen(lowercase_name));
164 time(&qrbuf->QRmtime);
165 cdb_store(CDB_QUICKROOM,
166 lowercase_name, strlen(lowercase_name),
167 qrbuf, sizeof(struct quickroom));
173 * lputroom() - same as putroom() but unlocks the record (if supported)
175 void lputroom(struct quickroom *qrbuf, char *room_name)
178 putroom(qrbuf, room_name);
179 end_critical_section(S_QUICKROOM);
183 /****************************************************************************/
186 * getfloor() - retrieve floor data from disk
188 void getfloor(struct floor *flbuf, int floor_num)
190 struct cdbdata *cdbfl;
192 memset(flbuf, 0, sizeof(struct floor));
193 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
195 memcpy(flbuf, cdbfl->ptr,
196 ( (cdbfl->len > sizeof(struct floor)) ?
197 sizeof(struct floor) : cdbfl->len) );
201 if (floor_num == 0) {
202 strcpy(flbuf->f_name, "Main Floor");
203 flbuf->f_flags = F_INUSE;
204 flbuf->f_ref_count = 3;
211 * lgetfloor() - same as getfloor() but locks the record (if supported)
213 void lgetfloor(struct floor *flbuf, int floor_num)
216 begin_critical_section(S_FLOORTAB);
217 getfloor(flbuf,floor_num);
222 * putfloor() - store floor data on disk
224 void putfloor(struct floor *flbuf, int floor_num)
226 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
227 flbuf, sizeof(struct floor));
232 * lputfloor() - same as putfloor() but unlocks the record (if supported)
234 void lputfloor(struct floor *flbuf, int floor_num)
237 putfloor(flbuf,floor_num);
238 end_critical_section(S_FLOORTAB);
244 * Traverse the room file...
246 void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) {
247 struct quickroom qrbuf;
248 struct cdbdata *cdbqr;
250 cdb_rewind(CDB_QUICKROOM);
252 while(cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
253 memset(&qrbuf, 0, sizeof(struct quickroom));
254 memcpy(&qrbuf, cdbqr->ptr,
255 ( (cdbqr->len > sizeof(struct quickroom)) ?
256 sizeof(struct quickroom) : cdbqr->len) );
258 if (qrbuf.QRflags & QR_INUSE) (*CallBack)(&qrbuf);
265 * Create a database key for storage of message lists
267 void msglist_key(char *dbkey, struct quickroom *whichroom) {
270 sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
271 for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
275 * get_msglist() - retrieve room message pointers
277 void get_msglist(struct quickroom *whichroom) {
278 struct cdbdata *cdbfr;
281 msglist_key(dbkey, whichroom);
283 if (CC->msglist != NULL) {
289 cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey));
294 CC->msglist = malloc(cdbfr->len);
295 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
296 CC->num_msgs = cdbfr->len / sizeof(long);
302 * put_msglist() - retrieve room message pointers
304 void put_msglist(struct quickroom *whichroom) {
307 msglist_key(dbkey, whichroom);
308 cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey),
309 CC->msglist, CC->num_msgs * sizeof(long));
314 * delete_msglist() - delete room message pointers
316 void delete_msglist(struct quickroom *whichroom) {
319 msglist_key(dbkey, whichroom);
320 cdb_delete(CDB_MSGLISTS, dbkey, strlen(dbkey));
325 * Add a message number to a room's message list.
326 * So, why doesn't this function use the get_msglist() and put_msglist() stuff
327 * defined above? Because the room the message number is being written to
328 * may not be the current room (as is the case with cmd_move() for example).
330 void AddMessageToRoom(struct quickroom *whichroom, long newmsgid) {
332 struct cdbdata *cdbfr;
336 msglist_key(dbkey, whichroom);
337 cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey));
343 msglist = malloc(cdbfr->len);
344 num_msgs = cdbfr->len / sizeof(long);
345 memcpy(msglist, cdbfr->ptr, cdbfr->len);
349 /* Now add the new message */
351 msglist = realloc(msglist,
352 (num_msgs * sizeof(long)) );
354 if (msglist == NULL) {
355 lprintf(3, "ERROR: can't realloc message list!\n");
358 msglist[num_msgs - 1] = newmsgid;
360 /* Write it back to disk. */
361 cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey),
362 msglist, num_msgs * sizeof(long));
364 /* And finally, free up the memory we used. */
370 * MessageFromList() - get a message number from the list currently in memory
372 long MessageFromList(int whichpos) {
374 /* Return zero if the position is invalid */
375 if (whichpos >= CC->num_msgs) return 0L;
377 return(CC->msglist[whichpos]);
381 * SetMessageInList() - set a message number in the list currently in memory
383 void SetMessageInList(int whichpos, long newmsgnum) {
385 /* Return zero if the position is invalid */
386 if (whichpos >= CC->num_msgs) return;
388 CC->msglist[whichpos] = newmsgnum;
394 * sort message pointers
395 * (returns new msg count)
397 int sort_msglist(long listptrs[], int oldcount)
404 if (numitems < 2) return(oldcount);
407 for (a=numitems-2; a>=0; --a) {
408 for (b=0; b<=a; ++b) {
409 if (listptrs[b] > (listptrs[b+1])) {
411 hold2 = listptrs[b+1];
413 listptrs[b+1] = hold1;
418 /* and yank any nulls */
419 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
420 memcpy(&listptrs[0], &listptrs[1],
421 (sizeof(long) * (CC->num_msgs - 1)) );
430 * Determine whether a given room is one of the base non-editable rooms
432 int is_noneditable(struct quickroom *qrbuf) {
433 if (!strcasecmp(qrbuf->QRname, BASEROOM)) return(1);
434 else if (!strcasecmp(qrbuf->QRname, AIDEROOM)) return(1);
441 * Back-back-end for all room listing commands
443 void list_roomname(struct quickroom *qrbuf) {
444 char truncated_roomname[ROOMNAMELEN];
446 /* For mailbox rooms, chop off the owner prefix */
447 if (qrbuf->QRflags & QR_MAILBOX) {
448 strcpy(truncated_roomname, qrbuf->QRname);
449 strcpy(truncated_roomname, &truncated_roomname[11]);
450 cprintf("%s", truncated_roomname);
452 /* For all other rooms, just display the name in its entirety */
454 cprintf("%s", qrbuf->QRname);
457 /* ...and now the other parameters */
459 qrbuf->QRflags,qrbuf->QRfloor);
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 list_roomname(qrbuf);
474 void cmd_lrms(char *argbuf)
476 CC->FloorBeingSearched = (-1);
477 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
479 if (!(CC->logged_in)) {
480 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
484 if (getuser(&CC->usersupp,CC->curr_user)) {
485 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
489 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
491 ForEachRoom(cmd_lrms_backend);
498 * cmd_lkra() - List all known rooms
500 void cmd_lkra_backend(struct quickroom *qrbuf) {
501 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
503 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
504 ||((CC->FloorBeingSearched)<0)) )
505 list_roomname(qrbuf);
508 void cmd_lkra(char *argbuf)
510 CC->FloorBeingSearched = (-1);
511 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
513 if (!(CC->logged_in)) {
514 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
518 if (getuser(&CC->usersupp,CC->curr_user)) {
519 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
523 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
525 ForEachRoom(cmd_lkra_backend);
532 * cmd_lkrn() - List all known rooms with new messages
534 void cmd_lkrn_backend(struct quickroom *qrbuf) {
537 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
539 && (ra & UA_HASNEWMSGS)
540 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
541 ||((CC->FloorBeingSearched)<0)) )
542 list_roomname(qrbuf);
545 void cmd_lkrn(char *argbuf)
547 CC->FloorBeingSearched = (-1);
548 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
550 if (!(CC->logged_in)) {
551 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
555 if (getuser(&CC->usersupp,CC->curr_user)) {
556 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
560 cprintf("%d Rooms w/ new msgs:\n",LISTING_FOLLOWS);
562 ForEachRoom(cmd_lkrn_backend);
569 * cmd_lkro() - List all known rooms
571 void cmd_lkro_backend(struct quickroom *qrbuf) {
574 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
576 && ((ra & UA_HASNEWMSGS)==0)
577 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
578 ||((CC->FloorBeingSearched)<0)) )
579 list_roomname(qrbuf);
582 void cmd_lkro(char *argbuf)
584 CC->FloorBeingSearched = (-1);
585 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
587 if (!(CC->logged_in)) {
588 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
592 if (getuser(&CC->usersupp,CC->curr_user)) {
593 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
597 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
599 ForEachRoom(cmd_lkro_backend);
606 * cmd_lzrm() - List all forgotten rooms
608 void cmd_lzrm_backend(struct quickroom *qrbuf) {
611 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
612 if ( (ra & UA_GOTOALLOWED)
614 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
615 ||((CC->FloorBeingSearched)<0)) )
616 list_roomname(qrbuf);
619 void cmd_lzrm(char *argbuf)
621 CC->FloorBeingSearched = (-1);
622 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
624 if (!(CC->logged_in)) {
625 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
629 if (getuser(&CC->usersupp,CC->curr_user)) {
630 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
634 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
636 ForEachRoom(cmd_lzrm_backend);
642 void usergoto(char *where, int display_result)
645 int new_messages = 0;
646 int total_messages = 0;
650 int newmailcount = 0;
652 char truncated_roomname[ROOMNAMELEN];
654 strcpy(CC->quickroom.QRname, where);
655 getroom(&CC->quickroom, where);
656 lgetuser(&CC->usersupp,CC->curr_user);
657 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
659 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
660 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
662 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
663 lputuser(&CC->usersupp,CC->curr_user);
665 /* check for new mail */
666 newmailcount = NewMailCount();
668 /* set info to 1 if the user needs to read the room's info file */
669 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
672 get_msglist(&CC->quickroom);
673 for (a=0; a<CC->num_msgs; ++a) {
674 if (MessageFromList(a)>0L) {
676 if (MessageFromList(a) > vbuf.v_lastseen) {
682 if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1;
685 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
686 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
689 strcpy(truncated_roomname, CC->quickroom.QRname);
690 if (CC->quickroom.QRflags & QR_MAILBOX) {
691 strcpy(truncated_roomname, &truncated_roomname[11]);
694 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
697 new_messages, total_messages,
698 info,CC->quickroom.QRflags,
699 CC->quickroom.QRhighest,
701 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
703 if (CC->quickroom.QRflags & QR_PRIVATE) {
704 set_wtmpsupp("<private room>");
707 set_wtmpsupp(CC->quickroom.QRname);
713 * cmd_goto() - goto a new room
715 void cmd_goto(char *gargs)
717 struct quickroom QRscratch;
721 char augmented_roomname[256];
725 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
726 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
730 extract(towhere,gargs,0);
731 extract(password,gargs,1);
733 getuser(&CC->usersupp, CC->curr_user);
735 if (!strcasecmp(towhere, "_BASEROOM_"))
736 strcpy(towhere, BASEROOM);
738 if (!strcasecmp(towhere, "_MAIL_"))
739 strcpy(towhere, MAILROOM);
741 if (!strcasecmp(towhere, "_BITBUCKET_"))
742 strcpy(towhere, config.c_twitroom);
745 /* First try a regular match */
746 c = getroom(&QRscratch, towhere);
748 /* Then try a mailbox name match */
750 MailboxName(augmented_roomname, &CC->usersupp, towhere);
751 c = getroom(&QRscratch, augmented_roomname);
752 if (c == 0) strcpy(towhere, augmented_roomname);
755 /* And if the room was found... */
758 /* let internal programs go directly to any room */
759 if (CC->internal_pgm) {
760 usergoto(towhere, 1);
764 /* See if there is an existing user/room relationship */
765 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
767 /* normal clients have to pass through security */
768 if (ra & UA_GOTOALLOWED) ok = 1;
771 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
772 ((ra & UA_KNOWN) == 0) &&
773 (strcasecmp(QRscratch.QRpasswd,password))
775 cprintf("%d wrong or missing passwd\n",
776 ERROR+PASSWORD_REQUIRED);
780 usergoto(towhere, 1);
786 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
790 void cmd_whok(void) {
791 struct usersupp temp;
792 struct cdbdata *cdbus;
794 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
795 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
798 getuser(&CC->usersupp,CC->curr_user);
800 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
801 cprintf("%d Higher access required.\n",
802 ERROR+HIGHER_ACCESS_REQUIRED);
806 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
807 cdb_rewind(CDB_USERSUPP);
808 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
809 memset(&temp, 0, sizeof(struct usersupp));
810 memcpy(&temp, cdbus->ptr, cdbus->len);
813 if ( (CC->quickroom.QRflags & QR_INUSE)
814 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
815 ) cprintf("%s\n",temp.fullname);
822 * RDIR command for room directory
824 void cmd_rdir(void) {
831 if (!(CC->logged_in)) {
832 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
836 getroom(&CC->quickroom, CC->quickroom.QRname);
837 getuser(&CC->usersupp, CC->curr_user);
839 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
840 cprintf("%d not here.\n",ERROR+NOT_HERE);
844 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
845 && (CC->usersupp.axlevel<6)
846 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
847 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
851 cprintf("%d %s|%s/files/%s\n",
852 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
854 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
855 BBSDIR,CC->quickroom.QRdirname,CC->temp);
858 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
860 if (fd==NULL) fd=fopen("/dev/null","r");
862 ls = fopen(CC->temp,"r");
863 while (fgets(flnm,256,ls)!=NULL) {
864 flnm[strlen(flnm)-1]=0;
865 if (strcasecmp(flnm,"filedir")) {
866 sprintf(buf,"%s/files/%s/%s",
867 BBSDIR,CC->quickroom.QRdirname,flnm);
871 while ((fgets(buf,256,fd)!=NULL)
872 &&(strlen(comment)==0)) {
873 buf[strlen(buf)-1] = 0;
874 if ((!strncasecmp(buf,flnm,strlen(flnm)))
875 && (buf[strlen(flnm)]==' '))
877 &buf[strlen(flnm)+1],255);
879 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
890 * get room parameters (aide or room aide command)
892 void cmd_getr(void) {
893 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
894 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
898 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
899 cprintf("%d Higher access required.\n",
900 ERROR+HIGHER_ACCESS_REQUIRED);
904 if (is_noneditable(&CC->quickroom)) {
905 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
909 getroom(&CC->quickroom, CC->quickroom.QRname);
910 cprintf("%d%c%s|%s|%s|%d|%d\n",
912 CC->quickroom.QRname,
913 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
914 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
915 CC->quickroom.QRflags,
916 (int)CC->quickroom.QRfloor);
921 * set room parameters (aide or room aide command)
923 void cmd_setr(char *args) {
928 if (!(CC->logged_in)) {
929 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
933 if (!is_room_aide()) {
934 cprintf("%d Higher access required.\n",
935 ERROR+HIGHER_ACCESS_REQUIRED);
939 if (is_noneditable(&CC->quickroom)) {
940 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
944 if (num_parms(args)>=6) {
945 getfloor(&flbuf,extract_int(args,5));
946 if ((flbuf.f_flags & F_INUSE) == 0) {
947 cprintf("%d Invalid floor number.\n",
948 ERROR+INVALID_FLOOR_OPERATION);
953 lgetroom(&CC->quickroom, CC->quickroom.QRname);
954 extract(buf,args,0); buf[ROOMNAMELEN]=0;
955 strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
956 extract(buf,args,1); buf[10]=0;
957 strncpy(CC->quickroom.QRpasswd,buf,9);
958 extract(buf,args,2); buf[15]=0;
959 strncpy(CC->quickroom.QRdirname,buf,19);
960 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
962 /* Clean up a client boo-boo: if the client set the room to
963 * guess-name or passworded, ensure that the private flag is
966 if ((CC->quickroom.QRflags & QR_GUESSNAME)
967 ||(CC->quickroom.QRflags & QR_PASSWORDED))
968 CC->quickroom.QRflags |= QR_PRIVATE;
970 /* Kick everyone out if the client requested it (by changing the
971 * room's generation number)
973 if (extract_int(args,4)) {
974 time(&CC->quickroom.QRgen);
977 old_floor = CC->quickroom.QRfloor;
978 if (num_parms(args)>=6) {
979 CC->quickroom.QRfloor = extract_int(args,5);
982 lputroom(&CC->quickroom, CC->quickroom.QRname);
984 /* adjust the floor reference counts */
985 lgetfloor(&flbuf,old_floor);
987 lputfloor(&flbuf,old_floor);
988 lgetfloor(&flbuf,CC->quickroom.QRfloor);
990 lputfloor(&flbuf,CC->quickroom.QRfloor);
992 /* create a room directory if necessary */
993 if (CC->quickroom.QRflags & QR_DIRECTORY) {
995 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
996 CC->quickroom.QRdirname);
1000 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
1002 cprintf("%d Ok\n",OK);
1008 * get the name of the room aide for this room
1010 void cmd_geta(void) {
1011 struct usersupp usbuf;
1013 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
1014 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1018 if (is_noneditable(&CC->quickroom)) {
1019 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1023 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
1024 cprintf("%d %s\n",OK,usbuf.fullname);
1027 cprintf("%d \n",OK);
1033 * set the room aide for this room
1035 void cmd_seta(char *new_ra)
1037 struct usersupp usbuf;
1042 if (!(CC->logged_in)) {
1043 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1047 if (!is_room_aide()) {
1048 cprintf("%d Higher access required.\n",
1049 ERROR+HIGHER_ACCESS_REQUIRED);
1053 if (getuser(&usbuf,new_ra)!=0) {
1057 newu = usbuf.usernum;
1060 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1062 if (CC->quickroom.QRroomaide != newu) {
1065 CC->quickroom.QRroomaide = newu;
1066 lputroom(&CC->quickroom, CC->quickroom.QRname);
1069 * We have to post the change notice _after_ writing changes to
1070 * the room table, otherwise it would deadlock!
1072 if (post_notice == 1) {
1073 sprintf(buf,"%s is now room aide for %s>",
1074 usbuf.fullname,CC->quickroom.QRname);
1077 cprintf("%d Ok\n",OK);
1081 * Generate an associated file name for a room
1083 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
1086 sprintf(buf, "./prefix/%s.%ld", qrbuf->QRname, qrbuf->QRgen);
1087 for (a=0; a<strlen(buf); ++a) {
1088 if (buf[a]==32) buf[a]='.';
1093 * retrieve info file for this room
1095 void cmd_rinf(void) {
1100 assoc_file_name(filename, &CC->quickroom, "info");
1101 info_fp = fopen(filename,"r");
1103 if (info_fp==NULL) {
1104 cprintf("%d No info file.\n",ERROR);
1108 cprintf("%d Info:\n",LISTING_FOLLOWS);
1109 while (fgets(buf, 256, info_fp) != NULL) {
1110 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1111 cprintf("%s\n", buf);
1118 * Back end processing to delete a room and everything associated with it
1120 void delete_room(struct quickroom *qrbuf) {
1126 /* Delete the info file */
1127 assoc_file_name(aaa, qrbuf, "info");
1130 /* Delete the image file */
1131 assoc_file_name(aaa, qrbuf, "images");
1134 /* first flag the room record as not in use */
1135 lgetroom(qrbuf, qrbuf->QRname);
1138 /* then delete the messages in the room */
1140 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1141 MsgToDelete = MessageFromList(a);
1142 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1148 delete_msglist(qrbuf);
1149 lputroom(qrbuf, qrbuf->QRname);
1151 /* then decrement the reference count for the floor */
1152 lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
1153 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1154 lputfloor(&flbuf,(int)(qrbuf->QRfloor));
1156 /* Delete the room record from the database! */
1157 putroom(NULL, qrbuf->QRname);
1162 * aide command: kill the current room
1164 void cmd_kill(char *argbuf) {
1166 char deleted_room_name[ROOMNAMELEN];
1169 kill_ok = extract_int(argbuf,0);
1171 if (!(CC->logged_in)) {
1172 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1176 if (!is_room_aide()) {
1177 cprintf("%d Higher access required.\n",
1178 ERROR+HIGHER_ACCESS_REQUIRED);
1182 if (is_noneditable(&CC->quickroom)) {
1183 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1188 strcpy(deleted_room_name, CC->quickroom.QRname);
1189 delete_room(&CC->quickroom); /* Do the dirty work */
1190 usergoto(BASEROOM, 0); /* Return to the Lobby */
1192 /* tell the world what we did */
1193 sprintf(aaa,"%s> killed by %s",
1194 deleted_room_name, CC->curr_user);
1196 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1199 cprintf("%d ok to delete.\n",OK);
1205 * Internal code to create a new room (returns room flags)
1207 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1209 unsigned create_room(char *new_room_name,
1211 char *new_room_pass,
1212 int new_room_floor) {
1214 struct quickroom qrbuf;
1218 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1220 memset(&qrbuf, 0, sizeof(struct quickroom));
1221 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1222 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1223 qrbuf.QRflags = QR_INUSE;
1224 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1225 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1226 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1227 if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
1229 /* If the room is private, and the system administrator has elected
1230 * to automatically grant room aide privileges, do so now; otherwise,
1231 * set the room aide to undefined.
1233 if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) {
1234 qrbuf.QRroomaide=CC->usersupp.usernum;
1237 qrbuf.QRroomaide = (-1L);
1240 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1241 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1242 qrbuf.QRfloor = new_room_floor;
1244 /* save what we just did... */
1245 putroom(&qrbuf, qrbuf.QRname);
1247 /* bump the reference count on whatever floor the room is on */
1248 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1249 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1250 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1252 /* be sure not to kick the creator out of the room! */
1253 lgetuser(&CC->usersupp,CC->curr_user);
1254 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1255 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1256 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1257 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1258 lputuser(&CC->usersupp,CC->curr_user);
1260 /* resume our happy day */
1261 return(qrbuf.QRflags);
1268 void cmd_cre8(char *args)
1271 char new_room_name[256];
1273 char new_room_pass[256];
1277 struct quickroom qrbuf;
1280 cre8_ok = extract_int(args,0);
1281 extract(new_room_name,args,1);
1282 new_room_name[ROOMNAMELEN-1] = 0;
1283 new_room_type = extract_int(args,2);
1284 extract(new_room_pass,args,3);
1285 new_room_pass[9] = 0;
1288 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1289 cprintf("%d Invalid room name.\n",ERROR);
1293 if (num_parms(args)>=5) {
1294 getfloor(&flbuf,extract_int(args,4));
1295 if ((flbuf.f_flags & F_INUSE) == 0) {
1296 cprintf("%d Invalid floor number.\n",
1297 ERROR+INVALID_FLOOR_OPERATION);
1301 new_room_floor = extract_int(args,4);
1305 if (!(CC->logged_in)) {
1306 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1310 if (CC->usersupp.axlevel<3) {
1311 cprintf("%d You need higher access to create rooms.\n",
1312 ERROR+HIGHER_ACCESS_REQUIRED);
1316 if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
1317 cprintf("%d Ok to create rooms.\n", OK);
1321 /* Check to make sure the requested room name doesn't already exist */
1322 if (getroom(&qrbuf, new_room_name)==0) {
1323 cprintf("%d '%s' already exists.\n",
1324 ERROR,qrbuf.QRname);
1328 if ((new_room_type < 0) || (new_room_type > 3)) {
1329 cprintf("%d Invalid room type.\n",ERROR);
1334 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1338 newflags = create_room(new_room_name,
1339 new_room_type,new_room_pass,new_room_floor);
1341 /* post a message in Aide> describing the new room */
1342 strncpy(aaa,new_room_name,255);
1343 strcat(aaa,"> created by ");
1344 strcat(aaa,CC->usersupp.fullname);
1345 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1346 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1347 if (newflags&QR_PASSWORDED) {
1348 strcat(aaa,"\n Password: ");
1349 strcat(aaa,new_room_pass);
1353 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1358 void cmd_einf(char *ok)
1359 { /* enter info file for current room */
1361 char infofilename[64];
1364 if (!(CC->logged_in)) {
1365 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1369 if (!is_room_aide()) {
1370 cprintf("%d Higher access required.\n",
1371 ERROR+HIGHER_ACCESS_REQUIRED);
1376 cprintf("%d Ok.\n",OK);
1380 cprintf("%d Send info...\n",SEND_LISTING);
1382 assoc_file_name(infofilename, &CC->quickroom, "info");
1384 fp=fopen(infofilename,"w");
1387 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1388 } while(strcmp(buf,"000"));
1391 /* now update the room index so people will see our new info */
1392 lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */
1393 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1394 lputroom(&CC->quickroom,CC->quickroom.QRname);
1399 * cmd_lflr() - List all known floors
1401 void cmd_lflr(void) {
1405 if (!(CC->logged_in)) {
1406 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1410 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1411 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1416 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1418 for (a=0; a<MAXFLOORS; ++a) {
1420 if (flbuf.f_flags & F_INUSE) {
1421 cprintf("%d|%s|%d\n",
1433 * create a new floor
1435 void cmd_cflr(char *argbuf)
1437 char new_floor_name[256];
1440 int free_slot = (-1);
1443 extract(new_floor_name,argbuf,0);
1444 cflr_ok = extract_int(argbuf,1);
1447 if (!(CC->logged_in)) {
1448 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1452 if (CC->usersupp.axlevel<6) {
1453 cprintf("%d You need higher access to create rooms.\n",
1454 ERROR+HIGHER_ACCESS_REQUIRED);
1458 for (a=0; a<MAXFLOORS; ++a) {
1461 /* note any free slots while we're scanning... */
1462 if ( ((flbuf.f_flags & F_INUSE)==0)
1463 && (free_slot < 0) ) free_slot = a;
1465 /* check to see if it already exists */
1466 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1467 && (flbuf.f_flags & F_INUSE) ) {
1468 cprintf("%d Floor '%s' already exists.\n",
1469 ERROR+ALREADY_EXISTS,
1477 cprintf("%d There is no space available for a new floor.\n",
1478 ERROR+INVALID_FLOOR_OPERATION);
1483 cprintf("%d ok to create...\n",OK);
1487 lgetfloor(&flbuf,free_slot);
1488 flbuf.f_flags = F_INUSE;
1489 flbuf.f_ref_count = 0;
1490 strncpy(flbuf.f_name,new_floor_name,255);
1491 lputfloor(&flbuf,free_slot);
1492 cprintf("%d %d\n",OK,free_slot);
1500 void cmd_kflr(char *argbuf)
1503 int floor_to_delete;
1507 floor_to_delete = extract_int(argbuf,0);
1508 kflr_ok = extract_int(argbuf,1);
1511 if (!(CC->logged_in)) {
1512 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1516 if (CC->usersupp.axlevel<6) {
1517 cprintf("%d You need higher access to delete floors.\n",
1518 ERROR+HIGHER_ACCESS_REQUIRED);
1522 lgetfloor(&flbuf,floor_to_delete);
1525 if ((flbuf.f_flags & F_INUSE) == 0) {
1526 cprintf("%d Floor %d not in use.\n",
1527 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1532 if (flbuf.f_ref_count != 0) {
1533 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1534 ERROR+INVALID_FLOOR_OPERATION,
1541 cprintf("%d Ok\n",OK);
1544 cprintf("%d Ok to delete...\n",OK);
1551 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1552 lputfloor(&flbuf,floor_to_delete);
1558 void cmd_eflr(char *argbuf)
1564 np = num_parms(argbuf);
1566 cprintf("%d Usage error.\n",ERROR);
1570 if (!(CC->logged_in)) {
1571 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1575 if (CC->usersupp.axlevel<6) {
1576 cprintf("%d You need higher access to edit floors.\n",
1577 ERROR+HIGHER_ACCESS_REQUIRED);
1581 floor_num = extract_int(argbuf,0);
1582 lgetfloor(&flbuf,floor_num);
1583 if ( (flbuf.f_flags & F_INUSE) == 0) {
1584 lputfloor(&flbuf,floor_num);
1585 cprintf("%d Floor %d is not in use.\n",
1586 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1589 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1590 lputfloor(&flbuf,floor_num);
1592 cprintf("%d Ok\n",OK);