16 #include "sysdep_decls.h"
20 #include "serv_chat.h"
21 #include "citserver.h"
26 * Generic routine for determining user access to rooms
28 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf) {
32 /* for internal programs, always do everything */
33 if (((CC->internal_pgm))&&(roombuf->QRflags & QR_INUSE)) {
34 return(UA_KNOWN | UA_GOTOALLOWED);
37 /* For mailbox rooms, only allow access to the owner */
38 if (roombuf->QRflags & QR_MAILBOX) {
39 if (userbuf->usernum != atol(roombuf->QRname)) {
44 /* Locate any applicable user/room relationships */
45 CtdlGetRelationship(&vbuf, userbuf, roombuf);
47 /* Force the properties of the Aide room */
48 if (!strcasecmp(roombuf->QRname, AIDEROOM)) {
49 if (userbuf->axlevel >= 6) {
50 retval = UA_KNOWN | UA_GOTOALLOWED;
58 /* For mailboxes, we skip all the access stuff (and we've
59 * already checked by this point that the mailbox belongs
62 if (roombuf->QRflags & QR_MAILBOX) {
63 retval = UA_KNOWN | UA_GOTOALLOWED;
67 /* If this is a public room, it's accessible... */
68 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
69 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
72 /* If this is a preferred users only room, check access level */
73 if (roombuf->QRflags & QR_PREFONLY) {
74 if (userbuf->axlevel < 5) {
75 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
79 /* For private rooms, check the generation number matchups */
80 if (roombuf->QRflags & QR_PRIVATE) {
82 /* An explicit match means the user belongs in this room */
83 if (vbuf.v_flags & V_ACCESS) {
84 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
86 /* Otherwise, check if this is a guess-name or passworded
87 * room. If it is, a goto may at least be attempted
89 else if ((roombuf->QRflags & QR_PRIVATE)
90 ||(roombuf->QRflags & QR_PASSWORDED)) {
91 retval = retval & ~UA_KNOWN;
92 retval = retval | UA_GOTOALLOWED;
96 /* Check to see if the user has forgotten this room */
97 if (vbuf.v_flags & V_FORGET) {
98 retval = retval & ~UA_KNOWN;
99 retval = retval | UA_ZAPPED;
102 /* If user is explicitly locked out of this room, deny everything */
103 if (vbuf.v_flags & V_LOCKOUT) {
104 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
107 /* Aides get access to everything */
108 if (userbuf->axlevel >= 6) {
109 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
110 retval = retval & ~UA_ZAPPED;
113 NEWMSG: /* By the way, we also check for the presence of new messages */
114 if ( (roombuf->QRhighest) > (vbuf.v_lastseen) ) {
115 retval = retval | UA_HASNEWMSGS;
122 * Self-checking stuff for a room record read into memory
124 void room_sanity_check(struct quickroom *qrbuf) {
125 /* Mailbox rooms are always on the lowest floor */
126 if (qrbuf->QRflags & QR_MAILBOX) {
130 /* Listing order of 0 is illegal except for base rooms */
131 if (qrbuf->QRorder == 0)
132 if (!is_noneditable(qrbuf))
138 * getroom() - retrieve room data from disk
140 int getroom(struct quickroom *qrbuf, char *room_name)
142 struct cdbdata *cdbqr;
143 char lowercase_name[ROOMNAMELEN];
146 for (a=0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
147 lowercase_name[a] = tolower(room_name[a]);
149 lowercase_name[a] = 0;
151 memset(qrbuf, 0, sizeof(struct quickroom));
152 cdbqr = cdb_fetch(CDB_QUICKROOM,
153 lowercase_name, strlen(lowercase_name));
155 memcpy(qrbuf, cdbqr->ptr,
156 ( (cdbqr->len > sizeof(struct quickroom)) ?
157 sizeof(struct quickroom) : cdbqr->len) );
160 room_sanity_check(qrbuf);
170 * lgetroom() - same as getroom() but locks the record (if supported)
172 int lgetroom(struct quickroom *qrbuf, char *room_name)
174 begin_critical_section(S_QUICKROOM);
175 return(getroom(qrbuf, room_name));
180 * putroom() - store room data on disk
181 * (if the supplied buffer is NULL, delete the room record)
183 void putroom(struct quickroom *qrbuf, char *room_name)
185 char lowercase_name[ROOMNAMELEN];
188 for (a=0; a<=strlen(room_name); ++a) {
189 lowercase_name[a] = tolower(room_name[a]);
193 cdb_delete(CDB_QUICKROOM,
194 lowercase_name, strlen(lowercase_name));
197 time(&qrbuf->QRmtime);
198 cdb_store(CDB_QUICKROOM,
199 lowercase_name, strlen(lowercase_name),
200 qrbuf, sizeof(struct quickroom));
206 * lputroom() - same as putroom() but unlocks the record (if supported)
208 void lputroom(struct quickroom *qrbuf, char *room_name)
211 putroom(qrbuf, room_name);
212 end_critical_section(S_QUICKROOM);
216 /****************************************************************************/
219 * getfloor() - retrieve floor data from disk
221 void getfloor(struct floor *flbuf, int floor_num)
223 struct cdbdata *cdbfl;
225 memset(flbuf, 0, sizeof(struct floor));
226 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
228 memcpy(flbuf, cdbfl->ptr,
229 ( (cdbfl->len > sizeof(struct floor)) ?
230 sizeof(struct floor) : cdbfl->len) );
234 if (floor_num == 0) {
235 strcpy(flbuf->f_name, "Main Floor");
236 flbuf->f_flags = F_INUSE;
237 flbuf->f_ref_count = 3;
244 * lgetfloor() - same as getfloor() but locks the record (if supported)
246 void lgetfloor(struct floor *flbuf, int floor_num)
249 begin_critical_section(S_FLOORTAB);
250 getfloor(flbuf,floor_num);
255 * putfloor() - store floor data on disk
257 void putfloor(struct floor *flbuf, int floor_num)
259 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
260 flbuf, sizeof(struct floor));
265 * lputfloor() - same as putfloor() but unlocks the record (if supported)
267 void lputfloor(struct floor *flbuf, int floor_num)
270 putfloor(flbuf,floor_num);
271 end_critical_section(S_FLOORTAB);
277 * Traverse the room file...
279 void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) {
280 struct quickroom qrbuf;
281 struct cdbdata *cdbqr;
283 cdb_rewind(CDB_QUICKROOM);
285 while(cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
286 memset(&qrbuf, 0, sizeof(struct quickroom));
287 memcpy(&qrbuf, cdbqr->ptr,
288 ( (cdbqr->len > sizeof(struct quickroom)) ?
289 sizeof(struct quickroom) : cdbqr->len) );
291 room_sanity_check(&qrbuf);
292 if (qrbuf.QRflags & QR_INUSE) (*CallBack)(&qrbuf);
299 * get_msglist() - retrieve room message pointers
301 void get_msglist(struct quickroom *whichroom) {
302 struct cdbdata *cdbfr;
304 if (CC->msglist != NULL) {
310 cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
315 CC->msglist = mallok(cdbfr->len);
316 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
317 CC->num_msgs = cdbfr->len / sizeof(long);
323 * put_msglist() - retrieve room message pointers
325 void put_msglist(struct quickroom *whichroom) {
327 cdb_store(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long),
328 CC->msglist, CC->num_msgs * sizeof(long));
333 * delete_msglist() - delete room message pointers
334 * FIX - this really should check first to make sure there's actually a
335 * msglist to delete. As things stand now, calling this function on
336 * a room which has never been posted in will result in a message
337 * like "gdbm: illegal data" (no big deal, but could use fixing).
339 void delete_msglist(struct quickroom *whichroom) {
341 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
346 * Add a message number to a room's message list.
347 * So, why doesn't this function use the get_msglist() and put_msglist() stuff
348 * defined above? Because the room the message number is being written to
349 * may not be the current room (as is the case with cmd_move() for example).
351 * This function returns the highest message number present in the room after
352 * the add operation is performed - which is not necessarily the message
355 long AddMessageToRoom(struct quickroom *whichroom, long newmsgid) {
356 struct cdbdata *cdbfr;
359 long highest_msg = 0L;
361 cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
367 msglist = mallok(cdbfr->len);
368 num_msgs = cdbfr->len / sizeof(long);
369 memcpy(msglist, cdbfr->ptr, cdbfr->len);
373 /* Now add the new message */
375 msglist = reallok(msglist,
376 (num_msgs * sizeof(long)) );
378 if (msglist == NULL) {
379 lprintf(3, "ERROR: can't realloc message list!\n");
382 msglist[num_msgs - 1] = newmsgid;
384 /* Sort the message list, so all the msgid's are in order */
385 num_msgs = sort_msglist(msglist, num_msgs);
387 /* Determine the highest message number */
388 highest_msg = msglist[num_msgs - 1];
390 /* Write it back to disk. */
391 cdb_store(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long),
392 msglist, num_msgs * sizeof(long));
394 /* And finally, free up the memory we used. */
401 * MessageFromList() - get a message number from the list currently in memory
403 long MessageFromList(int whichpos) {
405 /* Return zero if the position is invalid */
406 if (whichpos >= CC->num_msgs) return 0L;
408 return(CC->msglist[whichpos]);
412 * SetMessageInList() - set a message number in the list currently in memory
414 void SetMessageInList(int whichpos, long newmsgnum) {
416 /* Return zero if the position is invalid */
417 if (whichpos >= CC->num_msgs) return;
419 CC->msglist[whichpos] = newmsgnum;
425 * sort message pointers
426 * (returns new msg count)
428 int sort_msglist(long listptrs[], int oldcount)
435 if (numitems < 2) return(oldcount);
438 for (a=numitems-2; a>=0; --a) {
439 for (b=0; b<=a; ++b) {
440 if (listptrs[b] > (listptrs[b+1])) {
442 hold2 = listptrs[b+1];
444 listptrs[b+1] = hold1;
449 /* and yank any nulls */
450 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
451 memcpy(&listptrs[0], &listptrs[1],
452 (sizeof(long) * (CC->num_msgs - 1)) );
461 * Determine whether a given room is non-editable.
463 int is_noneditable(struct quickroom *qrbuf) {
465 /* Lobby> and Aide> are non-editable */
466 if (!strcasecmp(qrbuf->QRname, BASEROOM)) return(1);
467 else if (!strcasecmp(qrbuf->QRname, AIDEROOM)) return(1);
469 /* Mailbox rooms are also non-editable */
470 else if (qrbuf->QRflags & QR_MAILBOX) return(1);
472 /* Everything else is editable */
479 * Back-back-end for all room listing commands
481 void list_roomname(struct quickroom *qrbuf) {
482 char truncated_roomname[ROOMNAMELEN];
484 /* For mailbox rooms, chop off the owner prefix */
485 if (qrbuf->QRflags & QR_MAILBOX) {
486 strcpy(truncated_roomname, qrbuf->QRname);
487 strcpy(truncated_roomname, &truncated_roomname[11]);
488 cprintf("%s", truncated_roomname);
490 /* For all other rooms, just display the name in its entirety */
492 cprintf("%s", qrbuf->QRname);
495 /* ...and now the other parameters */
496 cprintf("|%u|%d|%d\n",
499 (int)qrbuf->QRorder);
504 * cmd_lrms() - List all accessible rooms, known or forgotten
506 void cmd_lrms_backend(struct quickroom *qrbuf) {
507 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
508 & (UA_KNOWN | UA_ZAPPED)))
509 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
510 ||((CC->FloorBeingSearched)<0)) )
511 list_roomname(qrbuf);
514 void cmd_lrms(char *argbuf)
516 CC->FloorBeingSearched = (-1);
517 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
519 if (!(CC->logged_in)) {
520 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
524 if (getuser(&CC->usersupp,CC->curr_user)) {
525 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
529 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
531 ForEachRoom(cmd_lrms_backend);
538 * cmd_lkra() - List all known rooms
540 void cmd_lkra_backend(struct quickroom *qrbuf) {
541 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
543 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
544 ||((CC->FloorBeingSearched)<0)) )
545 list_roomname(qrbuf);
548 void cmd_lkra(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 Known rooms:\n",LISTING_FOLLOWS);
565 ForEachRoom(cmd_lkra_backend);
572 * cmd_lkrn() - List all known rooms with new messages
574 void cmd_lkrn_backend(struct quickroom *qrbuf) {
577 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
579 && (ra & UA_HASNEWMSGS)
580 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
581 ||((CC->FloorBeingSearched)<0)) )
582 list_roomname(qrbuf);
585 void cmd_lkrn(char *argbuf)
587 CC->FloorBeingSearched = (-1);
588 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
590 if (!(CC->logged_in)) {
591 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
595 if (getuser(&CC->usersupp,CC->curr_user)) {
596 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
600 cprintf("%d Rooms w/ new msgs:\n",LISTING_FOLLOWS);
602 ForEachRoom(cmd_lkrn_backend);
609 * cmd_lkro() - List all known rooms
611 void cmd_lkro_backend(struct quickroom *qrbuf) {
614 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
616 && ((ra & UA_HASNEWMSGS)==0)
617 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
618 ||((CC->FloorBeingSearched)<0)) )
619 list_roomname(qrbuf);
622 void cmd_lkro(char *argbuf)
624 CC->FloorBeingSearched = (-1);
625 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
627 if (!(CC->logged_in)) {
628 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
632 if (getuser(&CC->usersupp,CC->curr_user)) {
633 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
637 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
639 ForEachRoom(cmd_lkro_backend);
646 * cmd_lzrm() - List all forgotten rooms
648 void cmd_lzrm_backend(struct quickroom *qrbuf) {
651 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
652 if ( (ra & UA_GOTOALLOWED)
654 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
655 ||((CC->FloorBeingSearched)<0)) )
656 list_roomname(qrbuf);
659 void cmd_lzrm(char *argbuf)
661 CC->FloorBeingSearched = (-1);
662 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
664 if (!(CC->logged_in)) {
665 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
669 if (getuser(&CC->usersupp,CC->curr_user)) {
670 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
674 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
676 ForEachRoom(cmd_lzrm_backend);
682 void usergoto(char *where, int display_result)
685 int new_messages = 0;
686 int total_messages = 0;
690 int newmailcount = 0;
692 char truncated_roomname[ROOMNAMELEN];
694 strcpy(CC->quickroom.QRname, where);
695 getroom(&CC->quickroom, where);
697 lgetuser(&CC->usersupp,CC->curr_user);
698 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
700 /* Know the room ... but not if it's the page log room */
701 if (strcasecmp(where, config.c_logpages)) {
702 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
703 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
706 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
707 lputuser(&CC->usersupp,CC->curr_user);
709 /* check for new mail */
710 newmailcount = NewMailCount();
712 /* set info to 1 if the user needs to read the room's info file */
713 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
716 get_msglist(&CC->quickroom);
717 for (a=0; a<CC->num_msgs; ++a) {
718 if (MessageFromList(a)>0L) {
720 if (MessageFromList(a) > vbuf.v_lastseen) {
726 if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1;
729 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
730 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
733 strcpy(truncated_roomname, CC->quickroom.QRname);
734 if (CC->quickroom.QRflags & QR_MAILBOX) {
735 strcpy(truncated_roomname, &truncated_roomname[11]);
738 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
741 new_messages, total_messages,
742 info,CC->quickroom.QRflags,
743 CC->quickroom.QRhighest,
745 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
747 set_wtmpsupp_to_current_room();
752 * cmd_goto() - goto a new room
754 void cmd_goto(char *gargs)
756 struct quickroom QRscratch;
760 char augmented_roomname[256];
764 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
765 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
769 extract(towhere,gargs,0);
770 extract(password,gargs,1);
772 getuser(&CC->usersupp, CC->curr_user);
774 if (!strcasecmp(towhere, "_BASEROOM_"))
775 strcpy(towhere, BASEROOM);
777 if (!strcasecmp(towhere, "_MAIL_"))
778 strcpy(towhere, MAILROOM);
780 if (!strcasecmp(towhere, "_BITBUCKET_"))
781 strcpy(towhere, config.c_twitroom);
784 /* First try a regular match */
785 c = getroom(&QRscratch, towhere);
787 /* Then try a mailbox name match */
789 MailboxName(augmented_roomname, &CC->usersupp, towhere);
790 c = getroom(&QRscratch, augmented_roomname);
791 if (c == 0) strcpy(towhere, augmented_roomname);
794 /* And if the room was found... */
797 /* let internal programs go directly to any room */
798 if (CC->internal_pgm) {
799 usergoto(towhere, 1);
803 /* See if there is an existing user/room relationship */
804 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
806 /* normal clients have to pass through security */
807 if (ra & UA_GOTOALLOWED) ok = 1;
810 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
811 ((ra & UA_KNOWN) == 0) &&
812 (strcasecmp(QRscratch.QRpasswd,password))
814 cprintf("%d wrong or missing passwd\n",
815 ERROR+PASSWORD_REQUIRED);
818 else if ( (QRscratch.QRflags&QR_PRIVATE) &&
819 ((QRscratch.QRflags&QR_PASSWORDED)==0) &&
820 ((QRscratch.QRflags&QR_GUESSNAME)==0) &&
821 ((ra & UA_KNOWN) == 0) ) {
825 usergoto(towhere, 1);
831 NOPE: cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
835 void cmd_whok(void) {
836 struct usersupp temp;
837 struct cdbdata *cdbus;
839 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
840 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
843 getuser(&CC->usersupp,CC->curr_user);
845 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
846 cprintf("%d Higher access required.\n",
847 ERROR+HIGHER_ACCESS_REQUIRED);
851 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
852 cdb_rewind(CDB_USERSUPP);
853 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
854 memset(&temp, 0, sizeof(struct usersupp));
855 memcpy(&temp, cdbus->ptr, cdbus->len);
858 if ( (CC->quickroom.QRflags & QR_INUSE)
859 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
860 ) cprintf("%s\n",temp.fullname);
867 * RDIR command for room directory
869 void cmd_rdir(void) {
876 if (!(CC->logged_in)) {
877 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
881 getroom(&CC->quickroom, CC->quickroom.QRname);
882 getuser(&CC->usersupp, CC->curr_user);
884 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
885 cprintf("%d not here.\n",ERROR+NOT_HERE);
889 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
890 && (CC->usersupp.axlevel<6)
891 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
892 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
896 cprintf("%d %s|%s/files/%s\n",
897 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
899 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
900 BBSDIR,CC->quickroom.QRdirname,CC->temp);
903 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
905 if (fd==NULL) fd=fopen("/dev/null","r");
907 ls = fopen(CC->temp,"r");
908 while (fgets(flnm,256,ls)!=NULL) {
909 flnm[strlen(flnm)-1]=0;
910 if (strcasecmp(flnm,"filedir")) {
911 sprintf(buf,"%s/files/%s/%s",
912 BBSDIR,CC->quickroom.QRdirname,flnm);
916 while ((fgets(buf,256,fd)!=NULL)
917 &&(strlen(comment)==0)) {
918 buf[strlen(buf)-1] = 0;
919 if ((!strncasecmp(buf,flnm,strlen(flnm)))
920 && (buf[strlen(flnm)]==' '))
922 &buf[strlen(flnm)+1],255);
924 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
935 * get room parameters (aide or room aide command)
937 void cmd_getr(void) {
938 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
939 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
943 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
944 cprintf("%d Higher access required.\n",
945 ERROR+HIGHER_ACCESS_REQUIRED);
949 if (is_noneditable(&CC->quickroom)) {
950 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
954 getroom(&CC->quickroom, CC->quickroom.QRname);
955 cprintf("%d%c%s|%s|%s|%d|%d|%d\n",
957 CC->quickroom.QRname,
958 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
959 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
960 CC->quickroom.QRflags,
961 (int)CC->quickroom.QRfloor,
962 (int)CC->quickroom.QRorder);
967 * set room parameters (aide or room aide command)
969 void cmd_setr(char *args) {
972 char old_name[ROOMNAMELEN];
976 if (!(CC->logged_in)) {
977 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
981 if (!is_room_aide()) {
982 cprintf("%d Higher access required.\n",
983 ERROR+HIGHER_ACCESS_REQUIRED);
987 if (is_noneditable(&CC->quickroom)) {
988 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
992 if (num_parms(args)>=6) {
993 getfloor(&flbuf,extract_int(args,5));
994 if ((flbuf.f_flags & F_INUSE) == 0) {
995 cprintf("%d Invalid floor number.\n",
996 ERROR+INVALID_FLOOR_OPERATION);
1001 if (num_parms(args)>=7) {
1002 new_order = extract_int(args, 6);
1003 if (new_order < 1) new_order = 1;
1004 if (new_order > 127) new_order = 127;
1007 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1008 strcpy(old_name, CC->quickroom.QRname);
1009 extract(buf,args,0); buf[ROOMNAMELEN]=0;
1010 strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
1011 extract(buf,args,1); buf[10]=0;
1012 strncpy(CC->quickroom.QRpasswd,buf,9);
1013 extract(buf,args,2); buf[15]=0;
1014 strncpy(CC->quickroom.QRdirname,buf,19);
1015 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
1016 if (num_parms(args)>=7)
1017 CC->quickroom.QRorder = (char)new_order;
1019 /* Clean up a client boo-boo: if the client set the room to
1020 * guess-name or passworded, ensure that the private flag is
1023 if ((CC->quickroom.QRflags & QR_GUESSNAME)
1024 ||(CC->quickroom.QRflags & QR_PASSWORDED))
1025 CC->quickroom.QRflags |= QR_PRIVATE;
1027 /* Kick everyone out if the client requested it (by changing the
1028 * room's generation number)
1030 if (extract_int(args,4)) {
1031 time(&CC->quickroom.QRgen);
1034 old_floor = CC->quickroom.QRfloor;
1035 if (num_parms(args)>=6) {
1036 CC->quickroom.QRfloor = extract_int(args,5);
1039 /* Write the room record back to disk */
1040 lputroom(&CC->quickroom, CC->quickroom.QRname);
1042 /* If the room name changed, then there are now two room records,
1043 * so we have to delete the old one.
1045 if (strcasecmp(CC->quickroom.QRname, old_name)) {
1046 putroom(NULL, old_name);
1049 /* adjust the floor reference counts */
1050 lgetfloor(&flbuf,old_floor);
1051 --flbuf.f_ref_count;
1052 lputfloor(&flbuf,old_floor);
1053 lgetfloor(&flbuf,CC->quickroom.QRfloor);
1054 ++flbuf.f_ref_count;
1055 lputfloor(&flbuf,CC->quickroom.QRfloor);
1057 /* create a room directory if necessary */
1058 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1060 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1061 CC->quickroom.QRdirname);
1065 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
1067 cprintf("%d Ok\n",OK);
1073 * get the name of the room aide for this room
1075 void cmd_geta(void) {
1076 struct usersupp usbuf;
1078 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
1079 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1083 if (is_noneditable(&CC->quickroom)) {
1084 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1088 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
1089 cprintf("%d %s\n",OK,usbuf.fullname);
1092 cprintf("%d \n",OK);
1098 * set the room aide for this room
1100 void cmd_seta(char *new_ra)
1102 struct usersupp usbuf;
1107 if (!(CC->logged_in)) {
1108 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1112 if (!is_room_aide()) {
1113 cprintf("%d Higher access required.\n",
1114 ERROR+HIGHER_ACCESS_REQUIRED);
1118 if (getuser(&usbuf,new_ra)!=0) {
1122 newu = usbuf.usernum;
1125 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1127 if (CC->quickroom.QRroomaide != newu) {
1130 CC->quickroom.QRroomaide = newu;
1131 lputroom(&CC->quickroom, CC->quickroom.QRname);
1134 * We have to post the change notice _after_ writing changes to
1135 * the room table, otherwise it would deadlock!
1137 if (post_notice == 1) {
1138 sprintf(buf,"%s is now room aide for %s>",
1139 usbuf.fullname,CC->quickroom.QRname);
1142 cprintf("%d Ok\n",OK);
1146 * Generate an associated file name for a room
1148 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
1149 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1153 * retrieve info file for this room
1155 void cmd_rinf(void) {
1160 assoc_file_name(filename, &CC->quickroom, "info");
1161 info_fp = fopen(filename,"r");
1163 if (info_fp==NULL) {
1164 cprintf("%d No info file.\n",ERROR);
1168 cprintf("%d Info:\n",LISTING_FOLLOWS);
1169 while (fgets(buf, 256, info_fp) != NULL) {
1170 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1171 cprintf("%s\n", buf);
1178 * Back end processing to delete a room and everything associated with it
1180 void delete_room(struct quickroom *qrbuf) {
1186 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1188 /* Delete the info file */
1189 assoc_file_name(aaa, qrbuf, "info");
1192 /* Delete the image file */
1193 assoc_file_name(aaa, qrbuf, "images");
1196 /* first flag the room record as not in use */
1197 lgetroom(qrbuf, qrbuf->QRname);
1200 /* then delete the messages in the room */
1202 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1203 MsgToDelete = MessageFromList(a);
1204 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1210 delete_msglist(qrbuf);
1211 lputroom(qrbuf, qrbuf->QRname);
1213 /* then decrement the reference count for the floor */
1214 lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
1215 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1216 lputfloor(&flbuf,(int)(qrbuf->QRfloor));
1218 /* Delete the room record from the database! */
1219 putroom(NULL, qrbuf->QRname);
1224 * aide command: kill the current room
1226 void cmd_kill(char *argbuf) {
1228 char deleted_room_name[ROOMNAMELEN];
1231 kill_ok = extract_int(argbuf,0);
1233 if (!(CC->logged_in)) {
1234 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1238 if (!is_room_aide()) {
1239 cprintf("%d Higher access required.\n",
1240 ERROR+HIGHER_ACCESS_REQUIRED);
1244 if (is_noneditable(&CC->quickroom)) {
1245 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1250 strcpy(deleted_room_name, CC->quickroom.QRname);
1251 delete_room(&CC->quickroom); /* Do the dirty work */
1252 usergoto(BASEROOM, 0); /* Return to the Lobby */
1254 /* tell the world what we did */
1255 sprintf(aaa,"%s> killed by %s",
1256 deleted_room_name, CC->curr_user);
1258 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1261 cprintf("%d ok to delete.\n",OK);
1267 * Internal code to create a new room (returns room flags)
1269 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1271 unsigned create_room(char *new_room_name,
1273 char *new_room_pass,
1274 int new_room_floor) {
1276 struct quickroom qrbuf;
1280 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1282 memset(&qrbuf, 0, sizeof(struct quickroom));
1283 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1284 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1285 qrbuf.QRflags = QR_INUSE;
1286 qrbuf.QRnumber = get_new_room_number();
1287 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1288 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1289 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1290 if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
1292 /* If the room is private, and the system administrator has elected
1293 * to automatically grant room aide privileges, do so now; otherwise,
1294 * set the room aide to undefined.
1296 if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) {
1297 qrbuf.QRroomaide=CC->usersupp.usernum;
1300 qrbuf.QRroomaide = (-1L);
1303 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1304 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1305 qrbuf.QRfloor = new_room_floor;
1307 /* save what we just did... */
1308 putroom(&qrbuf, qrbuf.QRname);
1310 /* bump the reference count on whatever floor the room is on */
1311 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1312 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1313 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1315 /* be sure not to kick the creator out of the room! */
1316 lgetuser(&CC->usersupp,CC->curr_user);
1317 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1318 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1319 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1320 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1321 lputuser(&CC->usersupp,CC->curr_user);
1323 /* resume our happy day */
1324 return(qrbuf.QRflags);
1331 void cmd_cre8(char *args)
1334 char new_room_name[256];
1336 char new_room_pass[256];
1340 struct quickroom qrbuf;
1343 cre8_ok = extract_int(args,0);
1344 extract(new_room_name,args,1);
1345 new_room_name[ROOMNAMELEN-1] = 0;
1346 new_room_type = extract_int(args,2);
1347 extract(new_room_pass,args,3);
1348 new_room_pass[9] = 0;
1351 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1352 cprintf("%d Invalid room name.\n",ERROR);
1356 if (!strcasecmp(new_room_name, MAILROOM)) {
1357 cprintf("%d '%s' already exists.\n",
1358 ERROR+ALREADY_EXISTS, new_room_name);
1362 if (num_parms(args)>=5) {
1363 getfloor(&flbuf,extract_int(args,4));
1364 if ((flbuf.f_flags & F_INUSE) == 0) {
1365 cprintf("%d Invalid floor number.\n",
1366 ERROR+INVALID_FLOOR_OPERATION);
1370 new_room_floor = extract_int(args,4);
1374 if (!(CC->logged_in)) {
1375 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1379 if (CC->usersupp.axlevel<3) {
1380 cprintf("%d You need higher access to create rooms.\n",
1381 ERROR+HIGHER_ACCESS_REQUIRED);
1385 if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
1386 cprintf("%d Ok to create rooms.\n", OK);
1390 /* Check to make sure the requested room name doesn't already exist */
1391 if (getroom(&qrbuf, new_room_name)==0) {
1392 cprintf("%d '%s' already exists.\n",
1393 ERROR+ALREADY_EXISTS, qrbuf.QRname);
1397 if ((new_room_type < 0) || (new_room_type > 3)) {
1398 cprintf("%d Invalid room type.\n",ERROR);
1403 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1407 newflags = create_room(new_room_name,
1408 new_room_type,new_room_pass,new_room_floor);
1410 /* post a message in Aide> describing the new room */
1411 strncpy(aaa,new_room_name,255);
1412 strcat(aaa,"> created by ");
1413 strcat(aaa,CC->usersupp.fullname);
1414 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1415 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1416 if (newflags&QR_PASSWORDED) {
1417 strcat(aaa,"\n Password: ");
1418 strcat(aaa,new_room_pass);
1422 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1427 void cmd_einf(char *ok)
1428 { /* enter info file for current room */
1430 char infofilename[256];
1433 if (!(CC->logged_in)) {
1434 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1438 if (!is_room_aide()) {
1439 cprintf("%d Higher access required.\n",
1440 ERROR+HIGHER_ACCESS_REQUIRED);
1445 cprintf("%d Ok.\n",OK);
1449 assoc_file_name(infofilename, &CC->quickroom, "info");
1450 lprintf(9, "opening\n");
1451 fp = fopen(infofilename, "w");
1452 lprintf(9, "checking\n");
1454 cprintf("%d Cannot open %s: %s\n",
1455 ERROR+INTERNAL_ERROR, infofilename, strerror(errno));
1459 cprintf("%d Send info...\n", SEND_LISTING);
1463 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1464 } while(strcmp(buf,"000"));
1467 /* now update the room index so people will see our new info */
1468 lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */
1469 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1470 lputroom(&CC->quickroom,CC->quickroom.QRname);
1475 * cmd_lflr() - List all known floors
1477 void cmd_lflr(void) {
1481 if (!(CC->logged_in)) {
1482 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1486 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1487 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1492 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1494 for (a=0; a<MAXFLOORS; ++a) {
1496 if (flbuf.f_flags & F_INUSE) {
1497 cprintf("%d|%s|%d\n",
1509 * create a new floor
1511 void cmd_cflr(char *argbuf)
1513 char new_floor_name[256];
1516 int free_slot = (-1);
1519 extract(new_floor_name,argbuf,0);
1520 cflr_ok = extract_int(argbuf,1);
1523 if (!(CC->logged_in)) {
1524 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1528 if (CC->usersupp.axlevel<6) {
1529 cprintf("%d You need higher access to create rooms.\n",
1530 ERROR+HIGHER_ACCESS_REQUIRED);
1534 for (a=0; a<MAXFLOORS; ++a) {
1537 /* note any free slots while we're scanning... */
1538 if ( ((flbuf.f_flags & F_INUSE)==0)
1539 && (free_slot < 0) ) free_slot = a;
1541 /* check to see if it already exists */
1542 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1543 && (flbuf.f_flags & F_INUSE) ) {
1544 cprintf("%d Floor '%s' already exists.\n",
1545 ERROR+ALREADY_EXISTS,
1553 cprintf("%d There is no space available for a new floor.\n",
1554 ERROR+INVALID_FLOOR_OPERATION);
1559 cprintf("%d ok to create...\n",OK);
1563 lgetfloor(&flbuf,free_slot);
1564 flbuf.f_flags = F_INUSE;
1565 flbuf.f_ref_count = 0;
1566 strncpy(flbuf.f_name,new_floor_name,255);
1567 lputfloor(&flbuf,free_slot);
1568 cprintf("%d %d\n",OK,free_slot);
1576 void cmd_kflr(char *argbuf)
1579 int floor_to_delete;
1583 floor_to_delete = extract_int(argbuf,0);
1584 kflr_ok = extract_int(argbuf,1);
1587 if (!(CC->logged_in)) {
1588 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1592 if (CC->usersupp.axlevel<6) {
1593 cprintf("%d You need higher access to delete floors.\n",
1594 ERROR+HIGHER_ACCESS_REQUIRED);
1598 lgetfloor(&flbuf,floor_to_delete);
1601 if ((flbuf.f_flags & F_INUSE) == 0) {
1602 cprintf("%d Floor %d not in use.\n",
1603 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1608 if (flbuf.f_ref_count != 0) {
1609 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1610 ERROR+INVALID_FLOOR_OPERATION,
1617 cprintf("%d Ok\n",OK);
1620 cprintf("%d Ok to delete...\n",OK);
1627 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1628 lputfloor(&flbuf,floor_to_delete);
1634 void cmd_eflr(char *argbuf)
1640 np = num_parms(argbuf);
1642 cprintf("%d Usage error.\n",ERROR);
1646 if (!(CC->logged_in)) {
1647 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1651 if (CC->usersupp.axlevel<6) {
1652 cprintf("%d You need higher access to edit floors.\n",
1653 ERROR+HIGHER_ACCESS_REQUIRED);
1657 floor_num = extract_int(argbuf,0);
1658 lgetfloor(&flbuf,floor_num);
1659 if ( (flbuf.f_flags & F_INUSE) == 0) {
1660 lputfloor(&flbuf,floor_num);
1661 cprintf("%d Floor %d is not in use.\n",
1662 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1665 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1666 lputfloor(&flbuf,floor_num);
1668 cprintf("%d Ok\n",OK);