4 * Server functions which perform operations on room objects.
21 #include "sysdep_decls.h"
25 #include "citserver.h"
29 struct floor *floorcache[MAXFLOORS];
32 * Generic routine for determining user access to rooms
34 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf)
39 /* for internal programs, always do everything */
40 if (((CC->internal_pgm)) && (roombuf->QRflags & QR_INUSE)) {
41 return (UA_KNOWN | UA_GOTOALLOWED);
43 /* For mailbox rooms, only allow access to the owner */
44 if (roombuf->QRflags & QR_MAILBOX) {
45 if (userbuf->usernum != atol(roombuf->QRname)) {
49 /* Locate any applicable user/room relationships */
50 CtdlGetRelationship(&vbuf, userbuf, roombuf);
52 /* Force the properties of the Aide room */
53 if (!strcasecmp(roombuf->QRname, AIDEROOM)) {
54 if (userbuf->axlevel >= 6) {
55 retval = UA_KNOWN | UA_GOTOALLOWED;
61 /* For mailboxes, we skip all the access stuff (and we've
62 * already checked by this point that the mailbox belongs
65 if (roombuf->QRflags & QR_MAILBOX) {
66 retval = UA_KNOWN | UA_GOTOALLOWED;
69 /* If this is a public room, it's accessible... */
70 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
71 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
73 /* If this is a preferred users only room, check access level */
74 if (roombuf->QRflags & QR_PREFONLY) {
75 if (userbuf->axlevel < 5) {
76 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;
95 /* Check to see if the user has forgotten this room */
96 if (vbuf.v_flags & V_FORGET) {
97 retval = retval & ~UA_KNOWN;
98 retval = retval | UA_ZAPPED;
100 /* If user is explicitly locked out of this room, deny everything */
101 if (vbuf.v_flags & V_LOCKOUT) {
102 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
105 /* Aides get access to everything */
106 if (userbuf->axlevel >= 6) {
107 if (vbuf.v_flags & V_FORGET) {
108 retval = retval | UA_GOTOALLOWED;
111 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
115 NEWMSG: /* By the way, we also check for the presence of new messages */
116 if ((roombuf->QRhighest) > (vbuf.v_lastseen)) {
117 retval = retval | UA_HASNEWMSGS;
123 * Self-checking stuff for a room record read into memory
125 void room_sanity_check(struct quickroom *qrbuf)
127 /* Mailbox rooms are always on the lowest floor */
128 if (qrbuf->QRflags & QR_MAILBOX) {
131 /* Listing order of 0 is illegal except for base rooms */
132 if (qrbuf->QRorder == 0)
133 if (!is_noneditable(qrbuf))
139 * getroom() - retrieve room data from disk
141 int getroom(struct quickroom *qrbuf, char *room_name)
143 struct cdbdata *cdbqr;
144 char lowercase_name[ROOMNAMELEN];
145 char personal_lowercase_name[ROOMNAMELEN];
148 for (a = 0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
149 lowercase_name[a] = tolower(room_name[a]);
151 lowercase_name[a] = 0;
153 memset(qrbuf, 0, sizeof(struct quickroom));
155 /* First, try the public namespace */
156 cdbqr = cdb_fetch(CDB_QUICKROOM,
157 lowercase_name, strlen(lowercase_name));
159 /* If that didn't work, try the user's personal namespace */
161 sprintf(personal_lowercase_name, "%010ld.%s",
162 CC->usersupp.usernum, lowercase_name);
163 cdbqr = cdb_fetch(CDB_QUICKROOM,
164 personal_lowercase_name,
165 strlen(personal_lowercase_name));
168 memcpy(qrbuf, cdbqr->ptr,
169 ((cdbqr->len > sizeof(struct quickroom)) ?
170 sizeof(struct quickroom) : cdbqr->len));
173 room_sanity_check(qrbuf);
182 * lgetroom() - same as getroom() but locks the record (if supported)
184 int lgetroom(struct quickroom *qrbuf, char *room_name)
187 retval = getroom(qrbuf, room_name);
188 if (retval == 0) begin_critical_section(S_QUICKROOM);
194 * b_putroom() - back end to putroom() and b_deleteroom()
195 * (if the supplied buffer is NULL, delete the room record)
197 void b_putroom(struct quickroom *qrbuf, char *room_name)
199 char lowercase_name[ROOMNAMELEN];
202 for (a = 0; a <= strlen(room_name); ++a) {
203 lowercase_name[a] = tolower(room_name[a]);
207 cdb_delete(CDB_QUICKROOM,
208 lowercase_name, strlen(lowercase_name));
210 time(&qrbuf->QRmtime);
211 cdb_store(CDB_QUICKROOM,
212 lowercase_name, strlen(lowercase_name),
213 qrbuf, sizeof(struct quickroom));
219 * putroom() - store room data to disk
221 void putroom(struct quickroom *qrbuf) {
222 b_putroom(qrbuf, qrbuf->QRname);
227 * b_deleteroom() - delete a room record from disk
229 void b_deleteroom(char *room_name) {
230 b_putroom(NULL, room_name);
236 * lputroom() - same as putroom() but unlocks the record (if supported)
238 void lputroom(struct quickroom *qrbuf)
242 end_critical_section(S_QUICKROOM);
246 /****************************************************************************/
249 * getfloor() - retrieve floor data from disk
251 void getfloor(struct floor *flbuf, int floor_num)
253 struct cdbdata *cdbfl;
255 memset(flbuf, 0, sizeof(struct floor));
256 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
258 memcpy(flbuf, cdbfl->ptr,
259 ((cdbfl->len > sizeof(struct floor)) ?
260 sizeof(struct floor) : cdbfl->len));
263 if (floor_num == 0) {
264 strcpy(flbuf->f_name, "Main Floor");
265 flbuf->f_flags = F_INUSE;
266 flbuf->f_ref_count = 3;
273 * lgetfloor() - same as getfloor() but locks the record (if supported)
275 void lgetfloor(struct floor *flbuf, int floor_num)
278 begin_critical_section(S_FLOORTAB);
279 getfloor(flbuf, floor_num);
284 * cgetfloor() - Get floor record from *cache* (loads from disk if needed)
286 * This is strictly a performance hack.
288 struct floor *cgetfloor(int floor_num) {
289 static int initialized = 0;
293 for (i=0; i<MAXFLOORS; ++i) {
294 floorcache[floor_num] = NULL;
299 if (floorcache[floor_num] == NULL) {
300 floorcache[floor_num] = mallok(sizeof(struct floor));
301 getfloor(floorcache[floor_num], floor_num);
304 return(floorcache[floor_num]);
310 * putfloor() - store floor data on disk
312 void putfloor(struct floor *flbuf, int floor_num)
314 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
315 flbuf, sizeof(struct floor));
317 /* If we've cached this, clear it out, 'cuz it's WRONG now! */
318 if (floorcache[floor_num] != NULL) {
319 phree(floorcache[floor_num]);
325 * lputfloor() - same as putfloor() but unlocks the record (if supported)
327 void lputfloor(struct floor *flbuf, int floor_num)
330 putfloor(flbuf, floor_num);
331 end_critical_section(S_FLOORTAB);
337 * Traverse the room file...
339 void ForEachRoom(void (*CallBack) (struct quickroom *EachRoom, void *out_data),
342 struct quickroom qrbuf;
343 struct cdbdata *cdbqr;
345 cdb_begin_transaction();
346 cdb_rewind(CDB_QUICKROOM);
348 while (cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
349 memset(&qrbuf, 0, sizeof(struct quickroom));
350 memcpy(&qrbuf, cdbqr->ptr,
351 ((cdbqr->len > sizeof(struct quickroom)) ?
352 sizeof(struct quickroom) : cdbqr->len));
354 room_sanity_check(&qrbuf);
355 if (qrbuf.QRflags & QR_INUSE)
356 (*CallBack)(&qrbuf, in_data);
358 cdb_end_transaction();
363 * delete_msglist() - delete room message pointers
365 void delete_msglist(struct quickroom *whichroom)
367 struct cdbdata *cdbml;
369 /* Make sure the msglist we're deleting actually exists, otherwise
370 * gdbm will complain when we try to delete an invalid record
372 cdbml = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
376 /* Go ahead and delete it */
377 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
385 * sort message pointers
386 * (returns new msg count)
388 int sort_msglist(long listptrs[], int oldcount)
399 for (a = numitems - 2; a >= 0; --a) {
400 for (b = 0; b <= a; ++b) {
401 if (listptrs[b] > (listptrs[b + 1])) {
403 hold2 = listptrs[b + 1];
405 listptrs[b + 1] = hold1;
410 /* and yank any nulls */
411 while ((numitems > 0) && (listptrs[0] == 0L)) {
412 memcpy(&listptrs[0], &listptrs[1],
413 (sizeof(long) * (numitems - 1)));
422 * Determine whether a given room is non-editable.
424 int is_noneditable(struct quickroom *qrbuf)
427 /* Lobby> and Aide> are non-editable */
428 if (!strcasecmp(qrbuf->QRname, BASEROOM))
430 else if (!strcasecmp(qrbuf->QRname, AIDEROOM))
433 /* Mail> rooms are also non-editable */
434 else if ( (qrbuf->QRflags & QR_MAILBOX)
435 && (!strcasecmp(&qrbuf->QRname[11], MAILROOM)) )
438 /* Everything else is editable */
446 * Back-back-end for all room listing commands
448 void list_roomname(struct quickroom *qrbuf)
450 char truncated_roomname[ROOMNAMELEN];
452 /* For mailbox rooms, chop off the owner prefix */
453 if (qrbuf->QRflags & QR_MAILBOX) {
454 strcpy(truncated_roomname, qrbuf->QRname);
455 strcpy(truncated_roomname, &truncated_roomname[11]);
456 cprintf("%s", truncated_roomname);
458 /* For all other rooms, just display the name in its entirety */
460 cprintf("%s", qrbuf->QRname);
463 /* ...and now the other parameters */
464 cprintf("|%u|%d|%d\n",
466 (int) qrbuf->QRfloor,
467 (int) qrbuf->QRorder);
472 * cmd_lrms() - List all accessible rooms, known or forgotten
474 void cmd_lrms_backend(struct quickroom *qrbuf, void *data)
476 int FloorBeingSearched = (-1);
477 FloorBeingSearched = *(int *)data;
479 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
480 & (UA_KNOWN | UA_ZAPPED)))
481 && ((qrbuf->QRfloor == (FloorBeingSearched))
482 || ((FloorBeingSearched) < 0)))
483 list_roomname(qrbuf);
486 void cmd_lrms(char *argbuf)
488 int FloorBeingSearched = (-1);
489 if (strlen(argbuf) > 0)
490 FloorBeingSearched = extract_int(argbuf, 0);
492 if (CtdlAccessCheck(ac_logged_in)) return;
494 if (getuser(&CC->usersupp, CC->curr_user)) {
495 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
498 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
500 ForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
507 * cmd_lkra() - List all known rooms
509 void cmd_lkra_backend(struct quickroom *qrbuf, void *data)
511 int FloorBeingSearched = (-1);
512 FloorBeingSearched = *(int *)data;
514 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
516 && ((qrbuf->QRfloor == (FloorBeingSearched))
517 || ((FloorBeingSearched) < 0)))
518 list_roomname(qrbuf);
521 void cmd_lkra(char *argbuf)
523 int FloorBeingSearched = (-1);
524 if (strlen(argbuf) > 0)
525 FloorBeingSearched = extract_int(argbuf, 0);
527 if (CtdlAccessCheck(ac_logged_in)) return;
529 if (getuser(&CC->usersupp, CC->curr_user)) {
530 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
533 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
535 ForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
542 * cmd_lkrn() - List all known rooms with new messages
544 void cmd_lkrn_backend(struct quickroom *qrbuf, void *data)
547 int FloorBeingSearched = (-1);
548 FloorBeingSearched = *(int *)data;
550 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
552 && (ra & UA_HASNEWMSGS)
553 && ((qrbuf->QRfloor == (FloorBeingSearched))
554 || ((FloorBeingSearched) < 0)))
555 list_roomname(qrbuf);
558 void cmd_lkrn(char *argbuf)
560 int FloorBeingSearched = (-1);
561 if (strlen(argbuf) > 0)
562 FloorBeingSearched = extract_int(argbuf, 0);
564 if (CtdlAccessCheck(ac_logged_in)) return;
566 if (getuser(&CC->usersupp, CC->curr_user)) {
567 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
570 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
572 ForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
579 * cmd_lkro() - List all known rooms
581 void cmd_lkro_backend(struct quickroom *qrbuf, void *data)
584 int FloorBeingSearched = (-1);
585 FloorBeingSearched = *(int *)data;
587 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
589 && ((ra & UA_HASNEWMSGS) == 0)
590 && ((qrbuf->QRfloor == (FloorBeingSearched))
591 || ((FloorBeingSearched) < 0)))
592 list_roomname(qrbuf);
595 void cmd_lkro(char *argbuf)
597 int FloorBeingSearched = (-1);
598 if (strlen(argbuf) > 0)
599 FloorBeingSearched = extract_int(argbuf, 0);
601 if (CtdlAccessCheck(ac_logged_in)) return;
603 if (getuser(&CC->usersupp, CC->curr_user)) {
604 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
607 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
609 ForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
616 * cmd_lzrm() - List all forgotten rooms
618 void cmd_lzrm_backend(struct quickroom *qrbuf, void *data)
621 int FloorBeingSearched = (-1);
622 FloorBeingSearched = *(int *)data;
624 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
625 if ((ra & UA_GOTOALLOWED)
627 && ((qrbuf->QRfloor == (FloorBeingSearched))
628 || ((FloorBeingSearched) < 0)))
629 list_roomname(qrbuf);
632 void cmd_lzrm(char *argbuf)
634 int FloorBeingSearched = (-1);
635 if (strlen(argbuf) > 0)
636 FloorBeingSearched = extract_int(argbuf, 0);
638 if (CtdlAccessCheck(ac_logged_in)) return;
640 if (getuser(&CC->usersupp, CC->curr_user)) {
641 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
644 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
646 ForEachRoom(cmd_lzrm_backend, &FloorBeingSearched);
652 void usergoto(char *where, int display_result, int *retmsgs, int *retnew)
655 int new_messages = 0;
656 int total_messages = 0;
660 int newmailcount = 0;
662 char truncated_roomname[ROOMNAMELEN];
663 struct cdbdata *cdbfr;
664 long *msglist = NULL;
667 strcpy(CC->quickroom.QRname, where);
668 getroom(&CC->quickroom, where);
670 lgetuser(&CC->usersupp, CC->curr_user);
671 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
673 /* Know the room ... but not if it's the page log room */
674 if (strcasecmp(where, config.c_logpages)) {
675 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
676 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
678 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
679 lputuser(&CC->usersupp);
681 /* check for new mail */
682 newmailcount = NewMailCount();
684 /* set info to 1 if the user needs to read the room's info file */
685 if (CC->quickroom.QRinfo > vbuf.v_lastseen)
689 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->quickroom.QRnumber, sizeof(long));
691 msglist = mallok(cdbfr->len);
692 memcpy(msglist, cdbfr->ptr, cdbfr->len);
693 num_msgs = cdbfr->len / sizeof(long);
697 if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
698 if (msglist[a] > 0L) {
700 if (msglist[a] > vbuf.v_lastseen) {
706 if (msglist != NULL) phree(msglist);
708 if (CC->quickroom.QRflags & QR_MAILBOX)
713 if ((CC->quickroom.QRroomaide == CC->usersupp.usernum)
714 || (CC->usersupp.axlevel >= 6))
719 strcpy(truncated_roomname, CC->quickroom.QRname);
720 if (CC->quickroom.QRflags & QR_MAILBOX) {
721 strcpy(truncated_roomname, &truncated_roomname[11]);
724 if (retmsgs != NULL) *retmsgs = total_messages;
725 if (retnew != NULL) *retnew = new_messages;
726 lprintf(9, "<%s> %d new of %d total messages\n",
727 CC->quickroom.QRname, new_messages, total_messages);
730 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
731 OK, CtdlCheckExpress(),
733 new_messages, total_messages,
734 info, CC->quickroom.QRflags,
735 CC->quickroom.QRhighest,
737 rmailflag, raideflag, newmailcount,
738 CC->quickroom.QRfloor);
744 * cmd_goto() - goto a new room
746 void cmd_goto(char *gargs)
748 struct quickroom QRscratch;
752 char augmented_roomname[SIZ];
756 if (CtdlAccessCheck(ac_logged_in)) return;
758 extract(towhere, gargs, 0);
759 extract(password, gargs, 1);
761 getuser(&CC->usersupp, CC->curr_user);
763 if (!strcasecmp(towhere, "_BASEROOM_"))
764 strcpy(towhere, BASEROOM);
766 if (!strcasecmp(towhere, "_MAIL_"))
767 strcpy(towhere, MAILROOM);
769 if (!strcasecmp(towhere, "_BITBUCKET_"))
770 strcpy(towhere, config.c_twitroom);
773 /* First try a regular match */
774 c = getroom(&QRscratch, towhere);
776 /* Then try a mailbox name match */
778 MailboxName(augmented_roomname, &CC->usersupp, towhere);
779 c = getroom(&QRscratch, augmented_roomname);
781 strcpy(towhere, augmented_roomname);
784 /* And if the room was found... */
787 /* let internal programs go directly to any room */
788 if (CC->internal_pgm) {
789 usergoto(towhere, 1, NULL, NULL);
793 /* See if there is an existing user/room relationship */
794 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
796 /* normal clients have to pass through security */
797 if (ra & UA_GOTOALLOWED)
801 if ((QRscratch.QRflags & QR_PASSWORDED) &&
802 ((ra & UA_KNOWN) == 0) &&
803 (strcasecmp(QRscratch.QRpasswd, password))
805 cprintf("%d wrong or missing passwd\n",
806 ERROR + PASSWORD_REQUIRED);
808 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
809 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
810 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
811 ((ra & UA_KNOWN) == 0)) {
814 usergoto(towhere, 1, NULL, NULL);
820 NOPE: cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
826 struct usersupp temp;
827 struct cdbdata *cdbus;
829 cdb_begin_transaction();
830 getuser(&CC->usersupp, CC->curr_user);
831 if (CtdlAccessCheck(ac_room_aide)) return;
833 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
834 cdb_rewind(CDB_USERSUPP);
835 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
836 memset(&temp, 0, sizeof temp);
837 memcpy(&temp, cdbus->ptr, sizeof temp);
840 if ((CC->quickroom.QRflags & QR_INUSE)
841 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
843 cprintf("%s\n", temp.fullname);
845 cdb_end_transaction();
851 * RDIR command for room directory
861 if (CtdlAccessCheck(ac_logged_in)) return;
863 getroom(&CC->quickroom, CC->quickroom.QRname);
864 getuser(&CC->usersupp, CC->curr_user);
866 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
867 cprintf("%d not here.\n", ERROR + NOT_HERE);
870 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
871 && (CC->usersupp.axlevel < 6)
872 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
873 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
876 cprintf("%d %s|%s/files/%s\n",
877 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->quickroom.QRdirname);
879 sprintf(buf, "ls %s/files/%s >%s 2> /dev/null",
880 BBSDIR, CC->quickroom.QRdirname, CC->temp);
883 sprintf(buf, "%s/files/%s/filedir", BBSDIR, CC->quickroom.QRdirname);
884 fd = fopen(buf, "r");
886 fd = fopen("/dev/null", "r");
888 ls = fopen(CC->temp, "r");
889 while (fgets(flnm, sizeof flnm, ls) != NULL) {
890 flnm[strlen(flnm) - 1] = 0;
891 if (strcasecmp(flnm, "filedir")) {
892 sprintf(buf, "%s/files/%s/%s",
893 BBSDIR, CC->quickroom.QRdirname, flnm);
897 while ((fgets(buf, sizeof buf, fd) != NULL)
898 && (strlen(comment) == 0)) {
899 buf[strlen(buf) - 1] = 0;
900 if ((!strncasecmp(buf, flnm, strlen(flnm)))
901 && (buf[strlen(flnm)] == ' '))
903 &buf[strlen(flnm) + 1],
906 cprintf("%s|%ld|%s\n", flnm, statbuf.st_size, comment);
917 * get room parameters (aide or room aide command)
921 if (CtdlAccessCheck(ac_room_aide)) return;
924 if (is_noneditable(&CC->quickroom)) {
925 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
930 getroom(&CC->quickroom, CC->quickroom.QRname);
931 cprintf("%d%c%s|%s|%s|%d|%d|%d\n",
932 OK, CtdlCheckExpress(),
933 CC->quickroom.QRname,
934 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
935 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
936 CC->quickroom.QRflags,
937 (int) CC->quickroom.QRfloor,
938 (int) CC->quickroom.QRorder);
943 * set room parameters (aide or room aide command)
945 void cmd_setr(char *args)
950 char old_name[ROOMNAMELEN];
955 if (CtdlAccessCheck(ac_room_aide)) return;
957 if (is_noneditable(&CC->quickroom)) {
962 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
968 if (num_parms(args) >= 6) {
969 fl = cgetfloor(extract_int(args, 5));
970 if ((fl->f_flags & F_INUSE) == 0) {
971 cprintf("%d Invalid floor number.\n",
972 ERROR + INVALID_FLOOR_OPERATION);
976 if (num_parms(args) >= 7) {
977 new_order = extract_int(args, 6);
983 lgetroom(&CC->quickroom, CC->quickroom.QRname);
985 /* Non-editable base rooms can't be renamed */
986 strcpy(old_name, CC->quickroom.QRname);
988 extract(buf, args, 0);
989 buf[ROOMNAMELEN] = 0;
990 safestrncpy(CC->quickroom.QRname, buf,
991 sizeof CC->quickroom.QRname);
994 extract(buf, args, 1);
996 safestrncpy(CC->quickroom.QRpasswd, buf, sizeof CC->quickroom.QRpasswd);
997 extract(buf, args, 2);
999 safestrncpy(CC->quickroom.QRdirname, buf,
1000 sizeof CC->quickroom.QRdirname);
1001 CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
1002 if (num_parms(args) >= 7)
1003 CC->quickroom.QRorder = (char) new_order;
1005 /* Clean up a client boo-boo: if the client set the room to
1006 * guess-name or passworded, ensure that the private flag is
1009 if ((CC->quickroom.QRflags & QR_GUESSNAME)
1010 || (CC->quickroom.QRflags & QR_PASSWORDED))
1011 CC->quickroom.QRflags |= QR_PRIVATE;
1013 /* Kick everyone out if the client requested it (by changing the
1014 * room's generation number)
1016 if (extract_int(args, 4)) {
1017 time(&CC->quickroom.QRgen);
1019 old_floor = CC->quickroom.QRfloor;
1020 if (num_parms(args) >= 6) {
1021 CC->quickroom.QRfloor = extract_int(args, 5);
1023 /* Write the room record back to disk */
1024 lputroom(&CC->quickroom);
1026 /* If the room name changed, then there are now two room records,
1027 * so we have to delete the old one.
1029 if (strcasecmp(CC->quickroom.QRname, old_name)) {
1030 b_deleteroom(old_name);
1032 /* adjust the floor reference counts */
1033 lgetfloor(&flbuf, old_floor);
1034 --flbuf.f_ref_count;
1035 lputfloor(&flbuf, old_floor);
1036 lgetfloor(&flbuf, CC->quickroom.QRfloor);
1037 ++flbuf.f_ref_count;
1038 lputfloor(&flbuf, CC->quickroom.QRfloor);
1040 /* create a room directory if necessary */
1041 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1043 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1044 CC->quickroom.QRdirname);
1047 sprintf(buf, "%s> edited by %s\n", CC->quickroom.QRname, CC->curr_user);
1049 cprintf("%d Ok\n", OK);
1055 * get the name of the room aide for this room
1059 struct usersupp usbuf;
1061 if (CtdlAccessCheck(ac_logged_in)) return;
1063 if (is_noneditable(&CC->quickroom)) {
1064 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1067 if (getuserbynumber(&usbuf, CC->quickroom.QRroomaide) == 0) {
1068 cprintf("%d %s\n", OK, usbuf.fullname);
1070 cprintf("%d \n", OK);
1076 * set the room aide for this room
1078 void cmd_seta(char *new_ra)
1080 struct usersupp usbuf;
1085 if (CtdlAccessCheck(ac_room_aide)) return;
1087 if (getuser(&usbuf, new_ra) != 0) {
1090 newu = usbuf.usernum;
1093 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1095 if (CC->quickroom.QRroomaide != newu) {
1098 CC->quickroom.QRroomaide = newu;
1099 lputroom(&CC->quickroom);
1102 * We have to post the change notice _after_ writing changes to
1103 * the room table, otherwise it would deadlock!
1105 if (post_notice == 1) {
1106 sprintf(buf, "%s is now room aide for %s>\n",
1107 usbuf.fullname, CC->quickroom.QRname);
1110 cprintf("%d Ok\n", OK);
1114 * Generate an associated file name for a room
1116 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix)
1118 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1122 * retrieve info file for this room
1130 assoc_file_name(filename, &CC->quickroom, "info");
1131 info_fp = fopen(filename, "r");
1133 if (info_fp == NULL) {
1134 cprintf("%d No info file.\n", ERROR);
1137 cprintf("%d Info:\n", LISTING_FOLLOWS);
1138 while (fgets(buf, sizeof buf, info_fp) != NULL) {
1139 if (strlen(buf) > 0)
1140 buf[strlen(buf) - 1] = 0;
1141 cprintf("%s\n", buf);
1148 * Back end processing to delete a room and everything associated with it
1150 void delete_room(struct quickroom *qrbuf)
1155 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1157 /* Delete the info file */
1158 assoc_file_name(filename, qrbuf, "info");
1161 /* Delete the image file */
1162 assoc_file_name(filename, qrbuf, "images");
1165 /* Delete the room's network config file */
1166 assoc_file_name(filename, qrbuf, "netconfigs");
1169 /* Delete the messages in the room
1170 * (Careful: this opens an S_QUICKROOM critical section!)
1172 CtdlDeleteMessages(qrbuf->QRname, 0L, "");
1174 /* Flag the room record as not in use */
1175 lgetroom(qrbuf, qrbuf->QRname);
1179 /* then decrement the reference count for the floor */
1180 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1181 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1182 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1184 /* Delete the room record from the database! */
1185 b_deleteroom(qrbuf->QRname);
1190 * aide command: kill the current room
1192 void cmd_kill(char *argbuf)
1195 char deleted_room_name[ROOMNAMELEN];
1198 kill_ok = extract_int(argbuf, 0);
1200 if (CtdlAccessCheck(ac_room_aide)) return;
1202 if (is_noneditable(&CC->quickroom)) {
1203 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1207 strcpy(deleted_room_name, CC->quickroom.QRname);
1208 delete_room(&CC->quickroom); /* Do the dirty work */
1209 usergoto(BASEROOM, 0, NULL, NULL); /* Return to the Lobby */
1211 /* tell the world what we did */
1212 sprintf(aaa, "%s> killed by %s\n",
1213 deleted_room_name, CC->curr_user);
1215 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1217 cprintf("%d ok to delete.\n", OK);
1223 * Internal code to create a new room (returns room flags)
1225 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1227 unsigned create_room(char *new_room_name,
1229 char *new_room_pass,
1233 struct quickroom qrbuf;
1237 lprintf(9, "create_room(%s)\n", new_room_name);
1238 if (getroom(&qrbuf, new_room_name) == 0) {
1239 lprintf(9, "%s already exists.\n", new_room_name);
1240 return (0); /* already exists */
1243 memset(&qrbuf, 0, sizeof(struct quickroom));
1244 safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
1245 safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
1246 qrbuf.QRflags = QR_INUSE;
1247 qrbuf.QRnumber = get_new_room_number();
1248 if (new_room_type > 0)
1249 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1250 if (new_room_type == 1)
1251 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1252 if (new_room_type == 2)
1253 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1254 if (new_room_type == 4)
1255 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1257 /* If the room is private, and the system administrator has elected
1258 * to automatically grant room aide privileges, do so now; otherwise,
1259 * set the room aide to undefined.
1261 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1262 qrbuf.QRroomaide = CC->usersupp.usernum;
1264 qrbuf.QRroomaide = (-1L);
1267 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1268 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1269 qrbuf.QRfloor = new_room_floor;
1271 /* save what we just did... */
1274 /* bump the reference count on whatever floor the room is on */
1275 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1276 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1277 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1279 /* be sure not to kick the creator out of the room! */
1280 lgetuser(&CC->usersupp, CC->curr_user);
1281 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1282 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1283 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1284 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1285 lputuser(&CC->usersupp);
1287 /* resume our happy day */
1288 return (qrbuf.QRflags);
1295 void cmd_cre8(char *args)
1298 char new_room_name[SIZ];
1300 char new_room_pass[SIZ];
1304 struct quickroom qrbuf;
1307 cre8_ok = extract_int(args, 0);
1308 extract(new_room_name, args, 1);
1309 new_room_name[ROOMNAMELEN - 1] = 0;
1310 new_room_type = extract_int(args, 2);
1311 extract(new_room_pass, args, 3);
1312 new_room_pass[9] = 0;
1315 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1316 cprintf("%d Invalid room name.\n", ERROR);
1320 if (!strcasecmp(new_room_name, MAILROOM)) {
1321 cprintf("%d '%s' already exists.\n",
1322 ERROR + ALREADY_EXISTS, new_room_name);
1326 if (num_parms(args) >= 5) {
1327 fl = cgetfloor(extract_int(args, 4));
1328 if ((fl->f_flags & F_INUSE) == 0) {
1329 cprintf("%d Invalid floor number.\n",
1330 ERROR + INVALID_FLOOR_OPERATION);
1333 new_room_floor = extract_int(args, 4);
1337 if (CtdlAccessCheck(ac_logged_in)) return;
1339 if (CC->usersupp.axlevel < config.c_createax) {
1340 cprintf("%d You need higher access to create rooms.\n",
1341 ERROR + HIGHER_ACCESS_REQUIRED);
1345 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1346 cprintf("%d Ok to create rooms.\n", OK);
1350 if ((new_room_type < 0) || (new_room_type > 4)) {
1351 cprintf("%d Invalid room type.\n", ERROR);
1355 /* If the user is requesting a personal room, set up the room
1356 * name accordingly (prepend the user number)
1358 if (new_room_type == 4) {
1359 sprintf(aaa, "%010ld.%s",
1360 CC->usersupp.usernum, new_room_name);
1361 strcpy(new_room_name, aaa);
1364 /* Check to make sure the requested room name doesn't already exist */
1365 if (getroom(&qrbuf, new_room_name) == 0) {
1366 cprintf("%d '%s' already exists.\n",
1367 ERROR + ALREADY_EXISTS, qrbuf.QRname);
1372 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1376 newflags = create_room(new_room_name,
1377 new_room_type, new_room_pass, new_room_floor);
1379 /* post a message in Aide> describing the new room */
1380 safestrncpy(aaa, new_room_name, sizeof aaa);
1381 strcat(aaa, "> created by ");
1382 strcat(aaa, CC->usersupp.fullname);
1383 if (newflags & QR_MAILBOX)
1384 strcat(aaa, " [personal]");
1385 else if (newflags & QR_PRIVATE)
1386 strcat(aaa, " [private]");
1387 if (newflags & QR_GUESSNAME)
1388 strcat(aaa, "[guessname] ");
1389 if (newflags & QR_PASSWORDED) {
1390 strcat(aaa, "\n Password: ");
1391 strcat(aaa, new_room_pass);
1396 cprintf("%d '%s' has been created.\n", OK, qrbuf.QRname);
1401 void cmd_einf(char *ok)
1402 { /* enter info file for current room */
1404 char infofilename[SIZ];
1407 if (CtdlAccessCheck(ac_room_aide)) return;
1409 if (atoi(ok) == 0) {
1410 cprintf("%d Ok.\n", OK);
1413 assoc_file_name(infofilename, &CC->quickroom, "info");
1414 lprintf(9, "opening\n");
1415 fp = fopen(infofilename, "w");
1416 lprintf(9, "checking\n");
1418 cprintf("%d Cannot open %s: %s\n",
1419 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1422 cprintf("%d Send info...\n", SEND_LISTING);
1426 if (strcmp(buf, "000"))
1427 fprintf(fp, "%s\n", buf);
1428 } while (strcmp(buf, "000"));
1431 /* now update the room index so people will see our new info */
1432 lgetroom(&CC->quickroom, CC->quickroom.QRname); /* lock so no one steps on us */
1433 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1434 lputroom(&CC->quickroom);
1439 * cmd_lflr() - List all known floors
1446 if (CtdlAccessCheck(ac_logged_in)) return;
1448 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1450 for (a = 0; a < MAXFLOORS; ++a) {
1451 getfloor(&flbuf, a);
1452 if (flbuf.f_flags & F_INUSE) {
1453 cprintf("%d|%s|%d\n",
1465 * create a new floor
1467 void cmd_cflr(char *argbuf)
1469 char new_floor_name[SIZ];
1472 int free_slot = (-1);
1475 extract(new_floor_name, argbuf, 0);
1476 cflr_ok = extract_int(argbuf, 1);
1479 if (CtdlAccessCheck(ac_aide)) return;
1481 for (a = 0; a < MAXFLOORS; ++a) {
1482 getfloor(&flbuf, a);
1484 /* note any free slots while we're scanning... */
1485 if (((flbuf.f_flags & F_INUSE) == 0)
1489 /* check to see if it already exists */
1490 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1491 && (flbuf.f_flags & F_INUSE)) {
1492 cprintf("%d Floor '%s' already exists.\n",
1493 ERROR + ALREADY_EXISTS,
1499 if (free_slot < 0) {
1500 cprintf("%d There is no space available for a new floor.\n",
1501 ERROR + INVALID_FLOOR_OPERATION);
1505 cprintf("%d ok to create...\n", OK);
1508 lgetfloor(&flbuf, free_slot);
1509 flbuf.f_flags = F_INUSE;
1510 flbuf.f_ref_count = 0;
1511 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1512 lputfloor(&flbuf, free_slot);
1513 cprintf("%d %d\n", OK, free_slot);
1521 void cmd_kflr(char *argbuf)
1524 int floor_to_delete;
1528 floor_to_delete = extract_int(argbuf, 0);
1529 kflr_ok = extract_int(argbuf, 1);
1531 if (CtdlAccessCheck(ac_aide)) return;
1533 lgetfloor(&flbuf, floor_to_delete);
1536 if ((flbuf.f_flags & F_INUSE) == 0) {
1537 cprintf("%d Floor %d not in use.\n",
1538 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1541 if (flbuf.f_ref_count != 0) {
1542 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1543 ERROR + INVALID_FLOOR_OPERATION,
1548 cprintf("%d Ok\n", OK);
1550 cprintf("%d Ok to delete...\n", OK);
1557 if ((delete_ok == 1) && (kflr_ok == 1))
1559 lputfloor(&flbuf, floor_to_delete);
1565 void cmd_eflr(char *argbuf)
1571 np = num_parms(argbuf);
1573 cprintf("%d Usage error.\n", ERROR);
1577 if (CtdlAccessCheck(ac_aide)) return;
1579 floor_num = extract_int(argbuf, 0);
1580 lgetfloor(&flbuf, floor_num);
1581 if ((flbuf.f_flags & F_INUSE) == 0) {
1582 lputfloor(&flbuf, floor_num);
1583 cprintf("%d Floor %d is not in use.\n",
1584 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1588 extract(flbuf.f_name, argbuf, 1);
1589 lputfloor(&flbuf, floor_num);
1591 cprintf("%d Ok\n", OK);