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) {
290 if (floorcache[floor_num] == NULL) {
291 floorcache[floor_num] = mallok(sizeof(struct floor));
292 getfloor(floorcache[floor_num], floor_num);
295 return(floorcache[floor_num]);
301 * putfloor() - store floor data on disk
303 void putfloor(struct floor *flbuf, int floor_num)
305 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
306 flbuf, sizeof(struct floor));
308 /* If we've cached this, clear it out, 'cuz it's WRONG now! */
309 if (floorcache[floor_num] != NULL) {
310 phree(floorcache[floor_num]);
316 * lputfloor() - same as putfloor() but unlocks the record (if supported)
318 void lputfloor(struct floor *flbuf, int floor_num)
321 putfloor(flbuf, floor_num);
322 end_critical_section(S_FLOORTAB);
328 * Traverse the room file...
330 void ForEachRoom(void (*CallBack) (struct quickroom *EachRoom, void *out_data),
333 struct quickroom qrbuf;
334 struct cdbdata *cdbqr;
336 cdb_begin_transaction();
337 cdb_rewind(CDB_QUICKROOM);
339 while (cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
340 memset(&qrbuf, 0, sizeof(struct quickroom));
341 memcpy(&qrbuf, cdbqr->ptr,
342 ((cdbqr->len > sizeof(struct quickroom)) ?
343 sizeof(struct quickroom) : cdbqr->len));
345 room_sanity_check(&qrbuf);
346 if (qrbuf.QRflags & QR_INUSE)
347 (*CallBack)(&qrbuf, in_data);
349 cdb_end_transaction();
354 * delete_msglist() - delete room message pointers
356 void delete_msglist(struct quickroom *whichroom)
358 struct cdbdata *cdbml;
360 /* Make sure the msglist we're deleting actually exists, otherwise
361 * gdbm will complain when we try to delete an invalid record
363 cdbml = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
367 /* Go ahead and delete it */
368 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
376 * sort message pointers
377 * (returns new msg count)
379 int sort_msglist(long listptrs[], int oldcount)
390 for (a = numitems - 2; a >= 0; --a) {
391 for (b = 0; b <= a; ++b) {
392 if (listptrs[b] > (listptrs[b + 1])) {
394 hold2 = listptrs[b + 1];
396 listptrs[b + 1] = hold1;
401 /* and yank any nulls */
402 while ((numitems > 0) && (listptrs[0] == 0L)) {
403 memcpy(&listptrs[0], &listptrs[1],
404 (sizeof(long) * (numitems - 1)));
413 * Determine whether a given room is non-editable.
415 int is_noneditable(struct quickroom *qrbuf)
418 /* Lobby> and Aide> are non-editable */
419 if (!strcasecmp(qrbuf->QRname, BASEROOM))
421 else if (!strcasecmp(qrbuf->QRname, AIDEROOM))
424 /* Mail> rooms are also non-editable */
425 else if ( (qrbuf->QRflags & QR_MAILBOX)
426 && (!strcasecmp(&qrbuf->QRname[11], MAILROOM)) )
429 /* Everything else is editable */
437 * Back-back-end for all room listing commands
439 void list_roomname(struct quickroom *qrbuf)
441 char truncated_roomname[ROOMNAMELEN];
443 /* For mailbox rooms, chop off the owner prefix */
444 if (qrbuf->QRflags & QR_MAILBOX) {
445 strcpy(truncated_roomname, qrbuf->QRname);
446 strcpy(truncated_roomname, &truncated_roomname[11]);
447 cprintf("%s", truncated_roomname);
449 /* For all other rooms, just display the name in its entirety */
451 cprintf("%s", qrbuf->QRname);
454 /* ...and now the other parameters */
455 cprintf("|%u|%d|%d\n",
457 (int) qrbuf->QRfloor,
458 (int) qrbuf->QRorder);
463 * cmd_lrms() - List all accessible rooms, known or forgotten
465 void cmd_lrms_backend(struct quickroom *qrbuf, void *data)
467 int FloorBeingSearched = (-1);
468 FloorBeingSearched = *(int *)data;
470 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
471 & (UA_KNOWN | UA_ZAPPED)))
472 && ((qrbuf->QRfloor == (FloorBeingSearched))
473 || ((FloorBeingSearched) < 0)))
474 list_roomname(qrbuf);
477 void cmd_lrms(char *argbuf)
479 int FloorBeingSearched = (-1);
480 if (strlen(argbuf) > 0)
481 FloorBeingSearched = extract_int(argbuf, 0);
483 if (CtdlAccessCheck(ac_logged_in)) return;
485 if (getuser(&CC->usersupp, CC->curr_user)) {
486 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
489 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
491 ForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
498 * cmd_lkra() - List all known rooms
500 void cmd_lkra_backend(struct quickroom *qrbuf, void *data)
502 int FloorBeingSearched = (-1);
503 FloorBeingSearched = *(int *)data;
505 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
507 && ((qrbuf->QRfloor == (FloorBeingSearched))
508 || ((FloorBeingSearched) < 0)))
509 list_roomname(qrbuf);
512 void cmd_lkra(char *argbuf)
514 int FloorBeingSearched = (-1);
515 if (strlen(argbuf) > 0)
516 FloorBeingSearched = extract_int(argbuf, 0);
518 if (CtdlAccessCheck(ac_logged_in)) return;
520 if (getuser(&CC->usersupp, CC->curr_user)) {
521 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
524 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
526 ForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
533 * cmd_lkrn() - List all known rooms with new messages
535 void cmd_lkrn_backend(struct quickroom *qrbuf, void *data)
538 int FloorBeingSearched = (-1);
539 FloorBeingSearched = *(int *)data;
541 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
543 && (ra & UA_HASNEWMSGS)
544 && ((qrbuf->QRfloor == (FloorBeingSearched))
545 || ((FloorBeingSearched) < 0)))
546 list_roomname(qrbuf);
549 void cmd_lkrn(char *argbuf)
551 int FloorBeingSearched = (-1);
552 if (strlen(argbuf) > 0)
553 FloorBeingSearched = extract_int(argbuf, 0);
555 if (CtdlAccessCheck(ac_logged_in)) return;
557 if (getuser(&CC->usersupp, CC->curr_user)) {
558 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
561 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
563 ForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
570 * cmd_lkro() - List all known rooms
572 void cmd_lkro_backend(struct quickroom *qrbuf, void *data)
575 int FloorBeingSearched = (-1);
576 FloorBeingSearched = *(int *)data;
578 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
580 && ((ra & UA_HASNEWMSGS) == 0)
581 && ((qrbuf->QRfloor == (FloorBeingSearched))
582 || ((FloorBeingSearched) < 0)))
583 list_roomname(qrbuf);
586 void cmd_lkro(char *argbuf)
588 int FloorBeingSearched = (-1);
589 if (strlen(argbuf) > 0)
590 FloorBeingSearched = extract_int(argbuf, 0);
592 if (CtdlAccessCheck(ac_logged_in)) return;
594 if (getuser(&CC->usersupp, CC->curr_user)) {
595 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
598 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
600 ForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
607 * cmd_lzrm() - List all forgotten rooms
609 void cmd_lzrm_backend(struct quickroom *qrbuf, void *data)
612 int FloorBeingSearched = (-1);
613 FloorBeingSearched = *(int *)data;
615 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
616 if ((ra & UA_GOTOALLOWED)
618 && ((qrbuf->QRfloor == (FloorBeingSearched))
619 || ((FloorBeingSearched) < 0)))
620 list_roomname(qrbuf);
623 void cmd_lzrm(char *argbuf)
625 int FloorBeingSearched = (-1);
626 if (strlen(argbuf) > 0)
627 FloorBeingSearched = extract_int(argbuf, 0);
629 if (CtdlAccessCheck(ac_logged_in)) return;
631 if (getuser(&CC->usersupp, CC->curr_user)) {
632 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
635 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
637 ForEachRoom(cmd_lzrm_backend, &FloorBeingSearched);
643 void usergoto(char *where, int display_result, int *retmsgs, int *retnew)
646 int new_messages = 0;
647 int total_messages = 0;
651 int newmailcount = 0;
653 char truncated_roomname[ROOMNAMELEN];
654 struct cdbdata *cdbfr;
655 long *msglist = NULL;
658 strcpy(CC->quickroom.QRname, where);
659 getroom(&CC->quickroom, where);
661 lgetuser(&CC->usersupp, CC->curr_user);
662 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
664 /* Know the room ... but not if it's the page log room */
665 if (strcasecmp(where, config.c_logpages)) {
666 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
667 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
669 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
670 lputuser(&CC->usersupp);
672 /* check for new mail */
673 newmailcount = NewMailCount();
675 /* set info to 1 if the user needs to read the room's info file */
676 if (CC->quickroom.QRinfo > vbuf.v_lastseen)
680 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->quickroom.QRnumber, sizeof(long));
682 msglist = mallok(cdbfr->len);
683 memcpy(msglist, cdbfr->ptr, cdbfr->len);
684 num_msgs = cdbfr->len / sizeof(long);
688 if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
689 if (msglist[a] > 0L) {
691 if (msglist[a] > vbuf.v_lastseen) {
697 if (msglist != NULL) phree(msglist);
699 if (CC->quickroom.QRflags & QR_MAILBOX)
704 if ((CC->quickroom.QRroomaide == CC->usersupp.usernum)
705 || (CC->usersupp.axlevel >= 6))
710 strcpy(truncated_roomname, CC->quickroom.QRname);
711 if (CC->quickroom.QRflags & QR_MAILBOX) {
712 strcpy(truncated_roomname, &truncated_roomname[11]);
715 if (retmsgs != NULL) *retmsgs = total_messages;
716 if (retnew != NULL) *retnew = new_messages;
717 lprintf(9, "<%s> %d new of %d total messages\n",
718 CC->quickroom.QRname, new_messages, total_messages);
721 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
722 OK, CtdlCheckExpress(),
724 new_messages, total_messages,
725 info, CC->quickroom.QRflags,
726 CC->quickroom.QRhighest,
728 rmailflag, raideflag, newmailcount,
729 CC->quickroom.QRfloor);
735 * cmd_goto() - goto a new room
737 void cmd_goto(char *gargs)
739 struct quickroom QRscratch;
743 char augmented_roomname[SIZ];
747 if (CtdlAccessCheck(ac_logged_in)) return;
749 extract(towhere, gargs, 0);
750 extract(password, gargs, 1);
752 getuser(&CC->usersupp, CC->curr_user);
754 if (!strcasecmp(towhere, "_BASEROOM_"))
755 strcpy(towhere, BASEROOM);
757 if (!strcasecmp(towhere, "_MAIL_"))
758 strcpy(towhere, MAILROOM);
760 if (!strcasecmp(towhere, "_BITBUCKET_"))
761 strcpy(towhere, config.c_twitroom);
764 /* First try a regular match */
765 c = getroom(&QRscratch, towhere);
767 /* Then try a mailbox name match */
769 MailboxName(augmented_roomname, &CC->usersupp, towhere);
770 c = getroom(&QRscratch, augmented_roomname);
772 strcpy(towhere, augmented_roomname);
775 /* And if the room was found... */
778 /* let internal programs go directly to any room */
779 if (CC->internal_pgm) {
780 usergoto(towhere, 1, NULL, NULL);
784 /* See if there is an existing user/room relationship */
785 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
787 /* normal clients have to pass through security */
788 if (ra & UA_GOTOALLOWED)
792 if ((QRscratch.QRflags & QR_PASSWORDED) &&
793 ((ra & UA_KNOWN) == 0) &&
794 (strcasecmp(QRscratch.QRpasswd, password))
796 cprintf("%d wrong or missing passwd\n",
797 ERROR + PASSWORD_REQUIRED);
799 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
800 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
801 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
802 ((ra & UA_KNOWN) == 0)) {
805 usergoto(towhere, 1, NULL, NULL);
811 NOPE: cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
817 struct usersupp temp;
818 struct cdbdata *cdbus;
820 cdb_begin_transaction();
821 getuser(&CC->usersupp, CC->curr_user);
822 if (CtdlAccessCheck(ac_room_aide)) return;
824 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
825 cdb_rewind(CDB_USERSUPP);
826 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
827 memset(&temp, 0, sizeof temp);
828 memcpy(&temp, cdbus->ptr, sizeof temp);
831 if ((CC->quickroom.QRflags & QR_INUSE)
832 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
834 cprintf("%s\n", temp.fullname);
836 cdb_end_transaction();
842 * RDIR command for room directory
852 if (CtdlAccessCheck(ac_logged_in)) return;
854 getroom(&CC->quickroom, CC->quickroom.QRname);
855 getuser(&CC->usersupp, CC->curr_user);
857 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
858 cprintf("%d not here.\n", ERROR + NOT_HERE);
861 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
862 && (CC->usersupp.axlevel < 6)
863 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
864 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
867 cprintf("%d %s|%s/files/%s\n",
868 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->quickroom.QRdirname);
870 sprintf(buf, "ls %s/files/%s >%s 2> /dev/null",
871 BBSDIR, CC->quickroom.QRdirname, CC->temp);
874 sprintf(buf, "%s/files/%s/filedir", BBSDIR, CC->quickroom.QRdirname);
875 fd = fopen(buf, "r");
877 fd = fopen("/dev/null", "r");
879 ls = fopen(CC->temp, "r");
880 while (fgets(flnm, sizeof flnm, ls) != NULL) {
881 flnm[strlen(flnm) - 1] = 0;
882 if (strcasecmp(flnm, "filedir")) {
883 sprintf(buf, "%s/files/%s/%s",
884 BBSDIR, CC->quickroom.QRdirname, flnm);
888 while ((fgets(buf, sizeof buf, fd) != NULL)
889 && (strlen(comment) == 0)) {
890 buf[strlen(buf) - 1] = 0;
891 if ((!strncasecmp(buf, flnm, strlen(flnm)))
892 && (buf[strlen(flnm)] == ' '))
894 &buf[strlen(flnm) + 1],
897 cprintf("%s|%ld|%s\n", flnm, statbuf.st_size, comment);
908 * get room parameters (aide or room aide command)
912 if (CtdlAccessCheck(ac_room_aide)) return;
915 if (is_noneditable(&CC->quickroom)) {
916 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
921 getroom(&CC->quickroom, CC->quickroom.QRname);
922 cprintf("%d%c%s|%s|%s|%d|%d|%d\n",
923 OK, CtdlCheckExpress(),
924 CC->quickroom.QRname,
925 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
926 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
927 CC->quickroom.QRflags,
928 (int) CC->quickroom.QRfloor,
929 (int) CC->quickroom.QRorder);
934 * set room parameters (aide or room aide command)
936 void cmd_setr(char *args)
941 char old_name[ROOMNAMELEN];
946 if (CtdlAccessCheck(ac_room_aide)) return;
948 if (is_noneditable(&CC->quickroom)) {
953 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
959 if (num_parms(args) >= 6) {
960 fl = cgetfloor(extract_int(args, 5));
961 if ((fl->f_flags & F_INUSE) == 0) {
962 cprintf("%d Invalid floor number.\n",
963 ERROR + INVALID_FLOOR_OPERATION);
967 if (num_parms(args) >= 7) {
968 new_order = extract_int(args, 6);
974 lgetroom(&CC->quickroom, CC->quickroom.QRname);
976 /* Non-editable base rooms can't be renamed */
977 strcpy(old_name, CC->quickroom.QRname);
979 extract(buf, args, 0);
980 buf[ROOMNAMELEN] = 0;
981 safestrncpy(CC->quickroom.QRname, buf,
982 sizeof CC->quickroom.QRname);
985 extract(buf, args, 1);
987 safestrncpy(CC->quickroom.QRpasswd, buf, sizeof CC->quickroom.QRpasswd);
988 extract(buf, args, 2);
990 safestrncpy(CC->quickroom.QRdirname, buf,
991 sizeof CC->quickroom.QRdirname);
992 CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
993 if (num_parms(args) >= 7)
994 CC->quickroom.QRorder = (char) new_order;
996 /* Clean up a client boo-boo: if the client set the room to
997 * guess-name or passworded, ensure that the private flag is
1000 if ((CC->quickroom.QRflags & QR_GUESSNAME)
1001 || (CC->quickroom.QRflags & QR_PASSWORDED))
1002 CC->quickroom.QRflags |= QR_PRIVATE;
1004 /* Kick everyone out if the client requested it (by changing the
1005 * room's generation number)
1007 if (extract_int(args, 4)) {
1008 time(&CC->quickroom.QRgen);
1010 old_floor = CC->quickroom.QRfloor;
1011 if (num_parms(args) >= 6) {
1012 CC->quickroom.QRfloor = extract_int(args, 5);
1014 /* Write the room record back to disk */
1015 lputroom(&CC->quickroom);
1017 /* If the room name changed, then there are now two room records,
1018 * so we have to delete the old one.
1020 if (strcasecmp(CC->quickroom.QRname, old_name)) {
1021 b_deleteroom(old_name);
1023 /* adjust the floor reference counts */
1024 lgetfloor(&flbuf, old_floor);
1025 --flbuf.f_ref_count;
1026 lputfloor(&flbuf, old_floor);
1027 lgetfloor(&flbuf, CC->quickroom.QRfloor);
1028 ++flbuf.f_ref_count;
1029 lputfloor(&flbuf, CC->quickroom.QRfloor);
1031 /* create a room directory if necessary */
1032 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1034 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1035 CC->quickroom.QRdirname);
1038 sprintf(buf, "%s> edited by %s\n", CC->quickroom.QRname, CC->curr_user);
1040 cprintf("%d Ok\n", OK);
1046 * get the name of the room aide for this room
1050 struct usersupp usbuf;
1052 if (CtdlAccessCheck(ac_logged_in)) return;
1054 if (is_noneditable(&CC->quickroom)) {
1055 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1058 if (getuserbynumber(&usbuf, CC->quickroom.QRroomaide) == 0) {
1059 cprintf("%d %s\n", OK, usbuf.fullname);
1061 cprintf("%d \n", OK);
1067 * set the room aide for this room
1069 void cmd_seta(char *new_ra)
1071 struct usersupp usbuf;
1076 if (CtdlAccessCheck(ac_room_aide)) return;
1078 if (getuser(&usbuf, new_ra) != 0) {
1081 newu = usbuf.usernum;
1084 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1086 if (CC->quickroom.QRroomaide != newu) {
1089 CC->quickroom.QRroomaide = newu;
1090 lputroom(&CC->quickroom);
1093 * We have to post the change notice _after_ writing changes to
1094 * the room table, otherwise it would deadlock!
1096 if (post_notice == 1) {
1097 sprintf(buf, "%s is now room aide for %s>\n",
1098 usbuf.fullname, CC->quickroom.QRname);
1101 cprintf("%d Ok\n", OK);
1105 * Generate an associated file name for a room
1107 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix)
1109 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1113 * retrieve info file for this room
1121 assoc_file_name(filename, &CC->quickroom, "info");
1122 info_fp = fopen(filename, "r");
1124 if (info_fp == NULL) {
1125 cprintf("%d No info file.\n", ERROR);
1128 cprintf("%d Info:\n", LISTING_FOLLOWS);
1129 while (fgets(buf, sizeof buf, info_fp) != NULL) {
1130 if (strlen(buf) > 0)
1131 buf[strlen(buf) - 1] = 0;
1132 cprintf("%s\n", buf);
1139 * Back end processing to delete a room and everything associated with it
1141 void delete_room(struct quickroom *qrbuf)
1146 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1148 /* Delete the info file */
1149 assoc_file_name(filename, qrbuf, "info");
1152 /* Delete the image file */
1153 assoc_file_name(filename, qrbuf, "images");
1156 /* Delete the room's network config file */
1157 assoc_file_name(filename, qrbuf, "netconfigs");
1160 /* Delete the messages in the room
1161 * (Careful: this opens an S_QUICKROOM critical section!)
1163 CtdlDeleteMessages(qrbuf->QRname, 0L, "");
1165 /* Flag the room record as not in use */
1166 lgetroom(qrbuf, qrbuf->QRname);
1170 /* then decrement the reference count for the floor */
1171 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1172 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1173 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1175 /* Delete the room record from the database! */
1176 b_deleteroom(qrbuf->QRname);
1181 * aide command: kill the current room
1183 void cmd_kill(char *argbuf)
1186 char deleted_room_name[ROOMNAMELEN];
1189 kill_ok = extract_int(argbuf, 0);
1191 if (CtdlAccessCheck(ac_room_aide)) return;
1193 if (is_noneditable(&CC->quickroom)) {
1194 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1198 strcpy(deleted_room_name, CC->quickroom.QRname);
1199 delete_room(&CC->quickroom); /* Do the dirty work */
1200 usergoto(BASEROOM, 0, NULL, NULL); /* Return to the Lobby */
1202 /* tell the world what we did */
1203 sprintf(aaa, "%s> killed by %s\n",
1204 deleted_room_name, CC->curr_user);
1206 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1208 cprintf("%d ok to delete.\n", OK);
1214 * Internal code to create a new room (returns room flags)
1216 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1218 unsigned create_room(char *new_room_name,
1220 char *new_room_pass,
1224 struct quickroom qrbuf;
1228 lprintf(9, "create_room(%s)\n", new_room_name);
1229 if (getroom(&qrbuf, new_room_name) == 0) {
1230 lprintf(9, "%s already exists.\n", new_room_name);
1231 return (0); /* already exists */
1234 memset(&qrbuf, 0, sizeof(struct quickroom));
1235 safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
1236 safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
1237 qrbuf.QRflags = QR_INUSE;
1238 qrbuf.QRnumber = get_new_room_number();
1239 if (new_room_type > 0)
1240 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1241 if (new_room_type == 1)
1242 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1243 if (new_room_type == 2)
1244 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1245 if (new_room_type == 4)
1246 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1248 /* If the room is private, and the system administrator has elected
1249 * to automatically grant room aide privileges, do so now; otherwise,
1250 * set the room aide to undefined.
1252 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1253 qrbuf.QRroomaide = CC->usersupp.usernum;
1255 qrbuf.QRroomaide = (-1L);
1258 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1259 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1260 qrbuf.QRfloor = new_room_floor;
1262 /* save what we just did... */
1265 /* bump the reference count on whatever floor the room is on */
1266 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1267 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1268 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1270 /* be sure not to kick the creator out of the room! */
1271 lgetuser(&CC->usersupp, CC->curr_user);
1272 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1273 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1274 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1275 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1276 lputuser(&CC->usersupp);
1278 /* resume our happy day */
1279 return (qrbuf.QRflags);
1286 void cmd_cre8(char *args)
1289 char new_room_name[SIZ];
1291 char new_room_pass[SIZ];
1295 struct quickroom qrbuf;
1298 cre8_ok = extract_int(args, 0);
1299 extract(new_room_name, args, 1);
1300 new_room_name[ROOMNAMELEN - 1] = 0;
1301 new_room_type = extract_int(args, 2);
1302 extract(new_room_pass, args, 3);
1303 new_room_pass[9] = 0;
1306 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1307 cprintf("%d Invalid room name.\n", ERROR);
1311 if (!strcasecmp(new_room_name, MAILROOM)) {
1312 cprintf("%d '%s' already exists.\n",
1313 ERROR + ALREADY_EXISTS, new_room_name);
1317 if (num_parms(args) >= 5) {
1318 fl = cgetfloor(extract_int(args, 4));
1319 if ((fl->f_flags & F_INUSE) == 0) {
1320 cprintf("%d Invalid floor number.\n",
1321 ERROR + INVALID_FLOOR_OPERATION);
1324 new_room_floor = extract_int(args, 4);
1328 if (CtdlAccessCheck(ac_logged_in)) return;
1330 if (CC->usersupp.axlevel < config.c_createax) {
1331 cprintf("%d You need higher access to create rooms.\n",
1332 ERROR + HIGHER_ACCESS_REQUIRED);
1336 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1337 cprintf("%d Ok to create rooms.\n", OK);
1341 if ((new_room_type < 0) || (new_room_type > 4)) {
1342 cprintf("%d Invalid room type.\n", ERROR);
1346 /* If the user is requesting a personal room, set up the room
1347 * name accordingly (prepend the user number)
1349 if (new_room_type == 4) {
1350 sprintf(aaa, "%010ld.%s",
1351 CC->usersupp.usernum, new_room_name);
1352 strcpy(new_room_name, aaa);
1355 /* Check to make sure the requested room name doesn't already exist */
1356 if (getroom(&qrbuf, new_room_name) == 0) {
1357 cprintf("%d '%s' already exists.\n",
1358 ERROR + ALREADY_EXISTS, qrbuf.QRname);
1363 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1367 newflags = create_room(new_room_name,
1368 new_room_type, new_room_pass, new_room_floor);
1370 /* post a message in Aide> describing the new room */
1371 safestrncpy(aaa, new_room_name, sizeof aaa);
1372 strcat(aaa, "> created by ");
1373 strcat(aaa, CC->usersupp.fullname);
1374 if (newflags & QR_MAILBOX)
1375 strcat(aaa, " [personal]");
1376 else if (newflags & QR_PRIVATE)
1377 strcat(aaa, " [private]");
1378 if (newflags & QR_GUESSNAME)
1379 strcat(aaa, "[guessname] ");
1380 if (newflags & QR_PASSWORDED) {
1381 strcat(aaa, "\n Password: ");
1382 strcat(aaa, new_room_pass);
1387 cprintf("%d '%s' has been created.\n", OK, qrbuf.QRname);
1392 void cmd_einf(char *ok)
1393 { /* enter info file for current room */
1395 char infofilename[SIZ];
1398 if (CtdlAccessCheck(ac_room_aide)) return;
1400 if (atoi(ok) == 0) {
1401 cprintf("%d Ok.\n", OK);
1404 assoc_file_name(infofilename, &CC->quickroom, "info");
1405 lprintf(9, "opening\n");
1406 fp = fopen(infofilename, "w");
1407 lprintf(9, "checking\n");
1409 cprintf("%d Cannot open %s: %s\n",
1410 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1413 cprintf("%d Send info...\n", SEND_LISTING);
1417 if (strcmp(buf, "000"))
1418 fprintf(fp, "%s\n", buf);
1419 } while (strcmp(buf, "000"));
1422 /* now update the room index so people will see our new info */
1423 lgetroom(&CC->quickroom, CC->quickroom.QRname); /* lock so no one steps on us */
1424 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1425 lputroom(&CC->quickroom);
1430 * cmd_lflr() - List all known floors
1437 if (CtdlAccessCheck(ac_logged_in)) return;
1439 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1441 for (a = 0; a < MAXFLOORS; ++a) {
1442 getfloor(&flbuf, a);
1443 if (flbuf.f_flags & F_INUSE) {
1444 cprintf("%d|%s|%d\n",
1456 * create a new floor
1458 void cmd_cflr(char *argbuf)
1460 char new_floor_name[SIZ];
1463 int free_slot = (-1);
1466 extract(new_floor_name, argbuf, 0);
1467 cflr_ok = extract_int(argbuf, 1);
1470 if (CtdlAccessCheck(ac_aide)) return;
1472 for (a = 0; a < MAXFLOORS; ++a) {
1473 getfloor(&flbuf, a);
1475 /* note any free slots while we're scanning... */
1476 if (((flbuf.f_flags & F_INUSE) == 0)
1480 /* check to see if it already exists */
1481 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1482 && (flbuf.f_flags & F_INUSE)) {
1483 cprintf("%d Floor '%s' already exists.\n",
1484 ERROR + ALREADY_EXISTS,
1490 if (free_slot < 0) {
1491 cprintf("%d There is no space available for a new floor.\n",
1492 ERROR + INVALID_FLOOR_OPERATION);
1496 cprintf("%d ok to create...\n", OK);
1499 lgetfloor(&flbuf, free_slot);
1500 flbuf.f_flags = F_INUSE;
1501 flbuf.f_ref_count = 0;
1502 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1503 lputfloor(&flbuf, free_slot);
1504 cprintf("%d %d\n", OK, free_slot);
1512 void cmd_kflr(char *argbuf)
1515 int floor_to_delete;
1519 floor_to_delete = extract_int(argbuf, 0);
1520 kflr_ok = extract_int(argbuf, 1);
1522 if (CtdlAccessCheck(ac_aide)) return;
1524 lgetfloor(&flbuf, floor_to_delete);
1527 if ((flbuf.f_flags & F_INUSE) == 0) {
1528 cprintf("%d Floor %d not in use.\n",
1529 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,
1539 cprintf("%d Ok\n", OK);
1541 cprintf("%d Ok to delete...\n", OK);
1548 if ((delete_ok == 1) && (kflr_ok == 1))
1550 lputfloor(&flbuf, floor_to_delete);
1556 void cmd_eflr(char *argbuf)
1562 np = num_parms(argbuf);
1564 cprintf("%d Usage error.\n", ERROR);
1568 if (CtdlAccessCheck(ac_aide)) return;
1570 floor_num = extract_int(argbuf, 0);
1571 lgetfloor(&flbuf, floor_num);
1572 if ((flbuf.f_flags & F_INUSE) == 0) {
1573 lputfloor(&flbuf, floor_num);
1574 cprintf("%d Floor %d is not in use.\n",
1575 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1579 extract(flbuf.f_name, argbuf, 1);
1580 lputfloor(&flbuf, floor_num);
1582 cprintf("%d Ok\n", OK);