4 * Server functions which perform operations on room objects.
21 #include "sysdep_decls.h"
25 #include "citserver.h"
30 * Generic routine for determining user access to rooms
32 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf)
37 /* for internal programs, always do everything */
38 if (((CC->internal_pgm)) && (roombuf->QRflags & QR_INUSE)) {
39 return (UA_KNOWN | UA_GOTOALLOWED);
41 /* For mailbox rooms, only allow access to the owner */
42 if (roombuf->QRflags & QR_MAILBOX) {
43 if (userbuf->usernum != atol(roombuf->QRname)) {
47 /* Locate any applicable user/room relationships */
48 CtdlGetRelationship(&vbuf, userbuf, roombuf);
50 /* Force the properties of the Aide room */
51 if (!strcasecmp(roombuf->QRname, AIDEROOM)) {
52 if (userbuf->axlevel >= 6) {
53 retval = UA_KNOWN | UA_GOTOALLOWED;
59 /* For mailboxes, we skip all the access stuff (and we've
60 * already checked by this point that the mailbox belongs
63 if (roombuf->QRflags & QR_MAILBOX) {
64 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;
71 /* If this is a preferred users only room, check access level */
72 if (roombuf->QRflags & QR_PREFONLY) {
73 if (userbuf->axlevel < 5) {
74 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
77 /* For private rooms, check the generation number matchups */
78 if (roombuf->QRflags & QR_PRIVATE) {
80 /* An explicit match means the user belongs in this room */
81 if (vbuf.v_flags & V_ACCESS) {
82 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
84 /* Otherwise, check if this is a guess-name or passworded
85 * room. If it is, a goto may at least be attempted
87 else if ((roombuf->QRflags & QR_PRIVATE)
88 || (roombuf->QRflags & QR_PASSWORDED)) {
89 retval = retval & ~UA_KNOWN;
90 retval = retval | UA_GOTOALLOWED;
93 /* Check to see if the user has forgotten this room */
94 if (vbuf.v_flags & V_FORGET) {
95 retval = retval & ~UA_KNOWN;
96 retval = retval | UA_ZAPPED;
98 /* If user is explicitly locked out of this room, deny everything */
99 if (vbuf.v_flags & V_LOCKOUT) {
100 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
103 /* Aides get access to everything */
104 if (userbuf->axlevel >= 6) {
105 if (vbuf.v_flags & V_FORGET) {
106 retval = retval | UA_GOTOALLOWED;
109 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
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;
121 * Self-checking stuff for a room record read into memory
123 void room_sanity_check(struct quickroom *qrbuf)
125 /* Mailbox rooms are always on the lowest floor */
126 if (qrbuf->QRflags & QR_MAILBOX) {
129 /* Listing order of 0 is illegal except for base rooms */
130 if (qrbuf->QRorder == 0)
131 if (!is_noneditable(qrbuf))
137 * getroom() - retrieve room data from disk
139 int getroom(struct quickroom *qrbuf, char *room_name)
141 struct cdbdata *cdbqr;
142 char lowercase_name[ROOMNAMELEN];
143 char personal_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));
153 /* First, try the public namespace */
154 cdbqr = cdb_fetch(CDB_QUICKROOM,
155 lowercase_name, strlen(lowercase_name));
157 /* If that didn't work, try the user's personal namespace */
159 sprintf(personal_lowercase_name, "%010ld.%s",
160 CC->usersupp.usernum, lowercase_name);
161 cdbqr = cdb_fetch(CDB_QUICKROOM,
162 personal_lowercase_name,
163 strlen(personal_lowercase_name));
166 memcpy(qrbuf, cdbqr->ptr,
167 ((cdbqr->len > sizeof(struct quickroom)) ?
168 sizeof(struct quickroom) : cdbqr->len));
171 room_sanity_check(qrbuf);
180 * lgetroom() - same as getroom() but locks the record (if supported)
182 int lgetroom(struct quickroom *qrbuf, char *room_name)
185 retval = getroom(qrbuf, room_name);
186 if (retval == 0) begin_critical_section(S_QUICKROOM);
192 * b_putroom() - back end to putroom() and b_deleteroom()
193 * (if the supplied buffer is NULL, delete the room record)
195 void b_putroom(struct quickroom *qrbuf, char *room_name)
197 char lowercase_name[ROOMNAMELEN];
200 for (a = 0; a <= strlen(room_name); ++a) {
201 lowercase_name[a] = tolower(room_name[a]);
205 cdb_delete(CDB_QUICKROOM,
206 lowercase_name, strlen(lowercase_name));
208 time(&qrbuf->QRmtime);
209 cdb_store(CDB_QUICKROOM,
210 lowercase_name, strlen(lowercase_name),
211 qrbuf, sizeof(struct quickroom));
217 * putroom() - store room data to disk
219 void putroom(struct quickroom *qrbuf) {
220 b_putroom(qrbuf, qrbuf->QRname);
225 * b_deleteroom() - delete a room record from disk
227 void b_deleteroom(char *room_name) {
228 b_putroom(NULL, room_name);
234 * lputroom() - same as putroom() but unlocks the record (if supported)
236 void lputroom(struct quickroom *qrbuf)
240 end_critical_section(S_QUICKROOM);
244 /****************************************************************************/
247 * getfloor() - retrieve floor data from disk
249 void getfloor(struct floor *flbuf, int floor_num)
251 struct cdbdata *cdbfl;
253 memset(flbuf, 0, sizeof(struct floor));
254 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
256 memcpy(flbuf, cdbfl->ptr,
257 ((cdbfl->len > sizeof(struct floor)) ?
258 sizeof(struct floor) : cdbfl->len));
261 if (floor_num == 0) {
262 strcpy(flbuf->f_name, "Main Floor");
263 flbuf->f_flags = F_INUSE;
264 flbuf->f_ref_count = 3;
271 * lgetfloor() - same as getfloor() but locks the record (if supported)
273 void lgetfloor(struct floor *flbuf, int floor_num)
276 begin_critical_section(S_FLOORTAB);
277 getfloor(flbuf, floor_num);
282 * putfloor() - store floor data on disk
284 void putfloor(struct floor *flbuf, int floor_num)
286 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
287 flbuf, sizeof(struct floor));
292 * lputfloor() - same as putfloor() but unlocks the record (if supported)
294 void lputfloor(struct floor *flbuf, int floor_num)
297 putfloor(flbuf, floor_num);
298 end_critical_section(S_FLOORTAB);
304 * Traverse the room file...
306 void ForEachRoom(void (*CallBack) (struct quickroom *EachRoom, void *out_data),
309 struct quickroom qrbuf;
310 struct cdbdata *cdbqr;
312 cdb_rewind(CDB_QUICKROOM);
314 while (cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
315 memset(&qrbuf, 0, sizeof(struct quickroom));
316 memcpy(&qrbuf, cdbqr->ptr,
317 ((cdbqr->len > sizeof(struct quickroom)) ?
318 sizeof(struct quickroom) : cdbqr->len));
320 room_sanity_check(&qrbuf);
321 if (qrbuf.QRflags & QR_INUSE)
322 (*CallBack)(&qrbuf, in_data);
328 * delete_msglist() - delete room message pointers
330 void delete_msglist(struct quickroom *whichroom)
332 struct cdbdata *cdbml;
334 /* Make sure the msglist we're deleting actually exists, otherwise
335 * gdbm will complain when we try to delete an invalid record
337 cdbml = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
341 /* Go ahead and delete it */
342 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
350 * sort message pointers
351 * (returns new msg count)
353 int sort_msglist(long listptrs[], int oldcount)
364 for (a = numitems - 2; a >= 0; --a) {
365 for (b = 0; b <= a; ++b) {
366 if (listptrs[b] > (listptrs[b + 1])) {
368 hold2 = listptrs[b + 1];
370 listptrs[b + 1] = hold1;
375 /* and yank any nulls */
376 while ((numitems > 0) && (listptrs[0] == 0L)) {
377 memcpy(&listptrs[0], &listptrs[1],
378 (sizeof(long) * (numitems - 1)));
387 * Determine whether a given room is non-editable.
389 int is_noneditable(struct quickroom *qrbuf)
392 /* Lobby> and Aide> are non-editable */
393 if (!strcasecmp(qrbuf->QRname, BASEROOM))
395 else if (!strcasecmp(qrbuf->QRname, AIDEROOM))
398 /* Mail> rooms are also non-editable */
399 else if ( (qrbuf->QRflags & QR_MAILBOX)
400 && (!strcasecmp(&qrbuf->QRname[11], MAILROOM)) )
403 /* Everything else is editable */
411 * Back-back-end for all room listing commands
413 void list_roomname(struct quickroom *qrbuf)
415 char truncated_roomname[ROOMNAMELEN];
417 /* For mailbox rooms, chop off the owner prefix */
418 if (qrbuf->QRflags & QR_MAILBOX) {
419 strcpy(truncated_roomname, qrbuf->QRname);
420 strcpy(truncated_roomname, &truncated_roomname[11]);
421 cprintf("%s", truncated_roomname);
423 /* For all other rooms, just display the name in its entirety */
425 cprintf("%s", qrbuf->QRname);
428 /* ...and now the other parameters */
429 cprintf("|%u|%d|%d\n",
431 (int) qrbuf->QRfloor,
432 (int) qrbuf->QRorder);
437 * cmd_lrms() - List all accessible rooms, known or forgotten
439 void cmd_lrms_backend(struct quickroom *qrbuf, void *data)
441 int FloorBeingSearched = (-1);
442 FloorBeingSearched = *(int *)data;
444 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
445 & (UA_KNOWN | UA_ZAPPED)))
446 && ((qrbuf->QRfloor == (FloorBeingSearched))
447 || ((FloorBeingSearched) < 0)))
448 list_roomname(qrbuf);
451 void cmd_lrms(char *argbuf)
453 int FloorBeingSearched = (-1);
454 if (strlen(argbuf) > 0)
455 FloorBeingSearched = extract_int(argbuf, 0);
457 if (CtdlAccessCheck(ac_logged_in)) return;
459 if (getuser(&CC->usersupp, CC->curr_user)) {
460 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
463 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
465 ForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
472 * cmd_lkra() - List all known rooms
474 void cmd_lkra_backend(struct quickroom *qrbuf, void *data)
476 int FloorBeingSearched = (-1);
477 FloorBeingSearched = *(int *)data;
479 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
481 && ((qrbuf->QRfloor == (FloorBeingSearched))
482 || ((FloorBeingSearched) < 0)))
483 list_roomname(qrbuf);
486 void cmd_lkra(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 Known rooms:\n", LISTING_FOLLOWS);
500 ForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
507 * cmd_lkrn() - List all known rooms with new messages
509 void cmd_lkrn_backend(struct quickroom *qrbuf, void *data)
512 int FloorBeingSearched = (-1);
513 FloorBeingSearched = *(int *)data;
515 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
517 && (ra & UA_HASNEWMSGS)
518 && ((qrbuf->QRfloor == (FloorBeingSearched))
519 || ((FloorBeingSearched) < 0)))
520 list_roomname(qrbuf);
523 void cmd_lkrn(char *argbuf)
525 int FloorBeingSearched = (-1);
526 if (strlen(argbuf) > 0)
527 FloorBeingSearched = extract_int(argbuf, 0);
529 if (CtdlAccessCheck(ac_logged_in)) return;
531 if (getuser(&CC->usersupp, CC->curr_user)) {
532 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
535 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
537 ForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
544 * cmd_lkro() - List all known rooms
546 void cmd_lkro_backend(struct quickroom *qrbuf, void *data)
549 int FloorBeingSearched = (-1);
550 FloorBeingSearched = *(int *)data;
552 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
554 && ((ra & UA_HASNEWMSGS) == 0)
555 && ((qrbuf->QRfloor == (FloorBeingSearched))
556 || ((FloorBeingSearched) < 0)))
557 list_roomname(qrbuf);
560 void cmd_lkro(char *argbuf)
562 int FloorBeingSearched = (-1);
563 if (strlen(argbuf) > 0)
564 FloorBeingSearched = extract_int(argbuf, 0);
566 if (CtdlAccessCheck(ac_logged_in)) return;
568 if (getuser(&CC->usersupp, CC->curr_user)) {
569 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
572 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
574 ForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
581 * cmd_lzrm() - List all forgotten rooms
583 void cmd_lzrm_backend(struct quickroom *qrbuf, void *data)
586 int FloorBeingSearched = (-1);
587 FloorBeingSearched = *(int *)data;
589 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
590 if ((ra & UA_GOTOALLOWED)
592 && ((qrbuf->QRfloor == (FloorBeingSearched))
593 || ((FloorBeingSearched) < 0)))
594 list_roomname(qrbuf);
597 void cmd_lzrm(char *argbuf)
599 int FloorBeingSearched = (-1);
600 if (strlen(argbuf) > 0)
601 FloorBeingSearched = extract_int(argbuf, 0);
603 if (CtdlAccessCheck(ac_logged_in)) return;
605 if (getuser(&CC->usersupp, CC->curr_user)) {
606 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
609 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
611 ForEachRoom(cmd_lzrm_backend, &FloorBeingSearched);
617 void usergoto(char *where, int display_result, int *retmsgs, int *retnew)
620 int new_messages = 0;
621 int total_messages = 0;
625 int newmailcount = 0;
627 char truncated_roomname[ROOMNAMELEN];
628 struct cdbdata *cdbfr;
629 long *msglist = NULL;
632 strcpy(CC->quickroom.QRname, where);
633 getroom(&CC->quickroom, where);
635 lgetuser(&CC->usersupp, CC->curr_user);
636 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
638 /* Know the room ... but not if it's the page log room */
639 if (strcasecmp(where, config.c_logpages)) {
640 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
641 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
643 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
644 lputuser(&CC->usersupp);
646 /* check for new mail */
647 newmailcount = NewMailCount();
649 /* set info to 1 if the user needs to read the room's info file */
650 if (CC->quickroom.QRinfo > vbuf.v_lastseen)
654 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->quickroom.QRnumber, sizeof(long));
656 msglist = mallok(cdbfr->len);
657 memcpy(msglist, cdbfr->ptr, cdbfr->len);
658 num_msgs = cdbfr->len / sizeof(long);
662 if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
663 if (msglist[a] > 0L) {
665 if (msglist[a] > vbuf.v_lastseen) {
671 if (msglist != NULL) phree(msglist);
673 if (CC->quickroom.QRflags & QR_MAILBOX)
678 if ((CC->quickroom.QRroomaide == CC->usersupp.usernum)
679 || (CC->usersupp.axlevel >= 6))
684 strcpy(truncated_roomname, CC->quickroom.QRname);
685 if (CC->quickroom.QRflags & QR_MAILBOX) {
686 strcpy(truncated_roomname, &truncated_roomname[11]);
689 if (retmsgs != NULL) *retmsgs = total_messages;
690 if (retnew != NULL) *retnew = new_messages;
691 lprintf(9, "<%s> %d new of %d total messages\n",
692 CC->quickroom.QRname, new_messages, total_messages);
695 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
696 OK, CtdlCheckExpress(),
698 new_messages, total_messages,
699 info, CC->quickroom.QRflags,
700 CC->quickroom.QRhighest,
702 rmailflag, raideflag, newmailcount,
703 CC->quickroom.QRfloor);
709 * cmd_goto() - goto a new room
711 void cmd_goto(char *gargs)
713 struct quickroom QRscratch;
717 char augmented_roomname[256];
721 if (CtdlAccessCheck(ac_logged_in)) return;
723 extract(towhere, gargs, 0);
724 extract(password, gargs, 1);
726 getuser(&CC->usersupp, CC->curr_user);
728 if (!strcasecmp(towhere, "_BASEROOM_"))
729 strcpy(towhere, BASEROOM);
731 if (!strcasecmp(towhere, "_MAIL_"))
732 strcpy(towhere, MAILROOM);
734 if (!strcasecmp(towhere, "_BITBUCKET_"))
735 strcpy(towhere, config.c_twitroom);
738 /* First try a regular match */
739 c = getroom(&QRscratch, towhere);
741 /* Then try a mailbox name match */
743 MailboxName(augmented_roomname, &CC->usersupp, towhere);
744 c = getroom(&QRscratch, augmented_roomname);
746 strcpy(towhere, augmented_roomname);
749 /* And if the room was found... */
752 /* let internal programs go directly to any room */
753 if (CC->internal_pgm) {
754 usergoto(towhere, 1, NULL, NULL);
758 /* See if there is an existing user/room relationship */
759 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
761 /* normal clients have to pass through security */
762 if (ra & UA_GOTOALLOWED)
766 if ((QRscratch.QRflags & QR_PASSWORDED) &&
767 ((ra & UA_KNOWN) == 0) &&
768 (strcasecmp(QRscratch.QRpasswd, password))
770 cprintf("%d wrong or missing passwd\n",
771 ERROR + PASSWORD_REQUIRED);
773 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
774 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
775 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
776 ((ra & UA_KNOWN) == 0)) {
779 usergoto(towhere, 1, NULL, NULL);
785 NOPE: cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
791 struct usersupp temp;
792 struct cdbdata *cdbus;
794 getuser(&CC->usersupp, CC->curr_user);
795 if (CtdlAccessCheck(ac_room_aide)) return;
797 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
798 cdb_rewind(CDB_USERSUPP);
799 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
800 memset(&temp, 0, sizeof temp);
801 memcpy(&temp, cdbus->ptr, sizeof temp);
804 if ((CC->quickroom.QRflags & QR_INUSE)
805 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
807 cprintf("%s\n", temp.fullname);
814 * RDIR command for room directory
824 if (CtdlAccessCheck(ac_logged_in)) return;
826 getroom(&CC->quickroom, CC->quickroom.QRname);
827 getuser(&CC->usersupp, CC->curr_user);
829 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
830 cprintf("%d not here.\n", ERROR + NOT_HERE);
833 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
834 && (CC->usersupp.axlevel < 6)
835 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
836 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
839 cprintf("%d %s|%s/files/%s\n",
840 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->quickroom.QRdirname);
842 sprintf(buf, "ls %s/files/%s >%s 2> /dev/null",
843 BBSDIR, CC->quickroom.QRdirname, CC->temp);
846 sprintf(buf, "%s/files/%s/filedir", BBSDIR, CC->quickroom.QRdirname);
847 fd = fopen(buf, "r");
849 fd = fopen("/dev/null", "r");
851 ls = fopen(CC->temp, "r");
852 while (fgets(flnm, 256, ls) != NULL) {
853 flnm[strlen(flnm) - 1] = 0;
854 if (strcasecmp(flnm, "filedir")) {
855 sprintf(buf, "%s/files/%s/%s",
856 BBSDIR, CC->quickroom.QRdirname, flnm);
860 while ((fgets(buf, 256, fd) != NULL)
861 && (strlen(comment) == 0)) {
862 buf[strlen(buf) - 1] = 0;
863 if ((!strncasecmp(buf, flnm, strlen(flnm)))
864 && (buf[strlen(flnm)] == ' '))
866 &buf[strlen(flnm) + 1],
869 cprintf("%s|%ld|%s\n", flnm, statbuf.st_size, comment);
880 * get room parameters (aide or room aide command)
884 if (CtdlAccessCheck(ac_room_aide)) return;
887 if (is_noneditable(&CC->quickroom)) {
888 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
893 getroom(&CC->quickroom, CC->quickroom.QRname);
894 cprintf("%d%c%s|%s|%s|%d|%d|%d\n",
895 OK, CtdlCheckExpress(),
896 CC->quickroom.QRname,
897 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
898 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
899 CC->quickroom.QRflags,
900 (int) CC->quickroom.QRfloor,
901 (int) CC->quickroom.QRorder);
906 * set room parameters (aide or room aide command)
908 void cmd_setr(char *args)
912 char old_name[ROOMNAMELEN];
917 if (CtdlAccessCheck(ac_room_aide)) return;
919 if (is_noneditable(&CC->quickroom)) {
924 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
930 if (num_parms(args) >= 6) {
931 getfloor(&flbuf, extract_int(args, 5));
932 if ((flbuf.f_flags & F_INUSE) == 0) {
933 cprintf("%d Invalid floor number.\n",
934 ERROR + INVALID_FLOOR_OPERATION);
938 if (num_parms(args) >= 7) {
939 new_order = extract_int(args, 6);
945 lgetroom(&CC->quickroom, CC->quickroom.QRname);
947 /* Non-editable base rooms can't be renamed */
948 strcpy(old_name, CC->quickroom.QRname);
950 extract(buf, args, 0);
951 buf[ROOMNAMELEN] = 0;
952 safestrncpy(CC->quickroom.QRname, buf,
953 sizeof CC->quickroom.QRname);
956 extract(buf, args, 1);
958 safestrncpy(CC->quickroom.QRpasswd, buf, sizeof CC->quickroom.QRpasswd);
959 extract(buf, args, 2);
961 safestrncpy(CC->quickroom.QRdirname, buf,
962 sizeof CC->quickroom.QRdirname);
963 CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
964 if (num_parms(args) >= 7)
965 CC->quickroom.QRorder = (char) new_order;
967 /* Clean up a client boo-boo: if the client set the room to
968 * guess-name or passworded, ensure that the private flag is
971 if ((CC->quickroom.QRflags & QR_GUESSNAME)
972 || (CC->quickroom.QRflags & QR_PASSWORDED))
973 CC->quickroom.QRflags |= QR_PRIVATE;
975 /* Kick everyone out if the client requested it (by changing the
976 * room's generation number)
978 if (extract_int(args, 4)) {
979 time(&CC->quickroom.QRgen);
981 old_floor = CC->quickroom.QRfloor;
982 if (num_parms(args) >= 6) {
983 CC->quickroom.QRfloor = extract_int(args, 5);
985 /* Write the room record back to disk */
986 lputroom(&CC->quickroom);
988 /* If the room name changed, then there are now two room records,
989 * so we have to delete the old one.
991 if (strcasecmp(CC->quickroom.QRname, old_name)) {
992 b_deleteroom(old_name);
994 /* adjust the floor reference counts */
995 lgetfloor(&flbuf, old_floor);
997 lputfloor(&flbuf, old_floor);
998 lgetfloor(&flbuf, CC->quickroom.QRfloor);
1000 lputfloor(&flbuf, CC->quickroom.QRfloor);
1002 /* create a room directory if necessary */
1003 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1005 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1006 CC->quickroom.QRdirname);
1009 sprintf(buf, "%s> edited by %s\n", CC->quickroom.QRname, CC->curr_user);
1011 cprintf("%d Ok\n", OK);
1017 * get the name of the room aide for this room
1021 struct usersupp usbuf;
1023 if (CtdlAccessCheck(ac_logged_in)) return;
1025 if (is_noneditable(&CC->quickroom)) {
1026 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1029 if (getuserbynumber(&usbuf, CC->quickroom.QRroomaide) == 0) {
1030 cprintf("%d %s\n", OK, usbuf.fullname);
1032 cprintf("%d \n", OK);
1038 * set the room aide for this room
1040 void cmd_seta(char *new_ra)
1042 struct usersupp usbuf;
1047 if (CtdlAccessCheck(ac_room_aide)) return;
1049 if (getuser(&usbuf, new_ra) != 0) {
1052 newu = usbuf.usernum;
1055 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1057 if (CC->quickroom.QRroomaide != newu) {
1060 CC->quickroom.QRroomaide = newu;
1061 lputroom(&CC->quickroom);
1064 * We have to post the change notice _after_ writing changes to
1065 * the room table, otherwise it would deadlock!
1067 if (post_notice == 1) {
1068 sprintf(buf, "%s is now room aide for %s>\n",
1069 usbuf.fullname, CC->quickroom.QRname);
1072 cprintf("%d Ok\n", OK);
1076 * Generate an associated file name for a room
1078 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix)
1080 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1084 * retrieve info file for this room
1092 assoc_file_name(filename, &CC->quickroom, "info");
1093 info_fp = fopen(filename, "r");
1095 if (info_fp == NULL) {
1096 cprintf("%d No info file.\n", ERROR);
1099 cprintf("%d Info:\n", LISTING_FOLLOWS);
1100 while (fgets(buf, 256, info_fp) != NULL) {
1101 if (strlen(buf) > 0)
1102 buf[strlen(buf) - 1] = 0;
1103 cprintf("%s\n", buf);
1110 * Back end processing to delete a room and everything associated with it
1112 void delete_room(struct quickroom *qrbuf)
1117 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1119 /* Delete the info file */
1120 assoc_file_name(filename, qrbuf, "info");
1123 /* Delete the image file */
1124 assoc_file_name(filename, qrbuf, "images");
1127 /* Delete the room's network config file */
1128 assoc_file_name(filename, qrbuf, "netconfigs");
1131 /* Delete the messages in the room
1132 * (Careful: this opens an S_QUICKROOM critical section!)
1134 CtdlDeleteMessages(qrbuf->QRname, 0L, "");
1136 /* Flag the room record as not in use */
1137 lgetroom(qrbuf, qrbuf->QRname);
1141 /* then decrement the reference count for the floor */
1142 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1143 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1144 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1146 /* Delete the room record from the database! */
1147 b_deleteroom(qrbuf->QRname);
1152 * aide command: kill the current room
1154 void cmd_kill(char *argbuf)
1157 char deleted_room_name[ROOMNAMELEN];
1160 kill_ok = extract_int(argbuf, 0);
1162 if (CtdlAccessCheck(ac_room_aide)) return;
1164 if (is_noneditable(&CC->quickroom)) {
1165 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1169 strcpy(deleted_room_name, CC->quickroom.QRname);
1170 delete_room(&CC->quickroom); /* Do the dirty work */
1171 usergoto(BASEROOM, 0, NULL, NULL); /* Return to the Lobby */
1173 /* tell the world what we did */
1174 sprintf(aaa, "%s> killed by %s\n",
1175 deleted_room_name, CC->curr_user);
1177 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1179 cprintf("%d ok to delete.\n", OK);
1185 * Internal code to create a new room (returns room flags)
1187 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1189 unsigned create_room(char *new_room_name,
1191 char *new_room_pass,
1195 struct quickroom qrbuf;
1199 lprintf(9, "create_room(%s)\n", new_room_name);
1200 if (getroom(&qrbuf, new_room_name) == 0) {
1201 lprintf(9, "%s already exists.\n", new_room_name);
1202 return (0); /* already exists */
1205 memset(&qrbuf, 0, sizeof(struct quickroom));
1206 safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
1207 safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
1208 qrbuf.QRflags = QR_INUSE;
1209 qrbuf.QRnumber = get_new_room_number();
1210 if (new_room_type > 0)
1211 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1212 if (new_room_type == 1)
1213 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1214 if (new_room_type == 2)
1215 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1216 if (new_room_type == 4)
1217 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1219 /* If the room is private, and the system administrator has elected
1220 * to automatically grant room aide privileges, do so now; otherwise,
1221 * set the room aide to undefined.
1223 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1224 qrbuf.QRroomaide = CC->usersupp.usernum;
1226 qrbuf.QRroomaide = (-1L);
1229 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1230 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1231 qrbuf.QRfloor = new_room_floor;
1233 /* save what we just did... */
1236 /* bump the reference count on whatever floor the room is on */
1237 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1238 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1239 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1241 /* be sure not to kick the creator out of the room! */
1242 lgetuser(&CC->usersupp, CC->curr_user);
1243 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1244 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1245 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1246 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1247 lputuser(&CC->usersupp);
1249 /* resume our happy day */
1250 return (qrbuf.QRflags);
1257 void cmd_cre8(char *args)
1260 char new_room_name[256];
1262 char new_room_pass[256];
1266 struct quickroom qrbuf;
1269 cre8_ok = extract_int(args, 0);
1270 extract(new_room_name, args, 1);
1271 new_room_name[ROOMNAMELEN - 1] = 0;
1272 new_room_type = extract_int(args, 2);
1273 extract(new_room_pass, args, 3);
1274 new_room_pass[9] = 0;
1277 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1278 cprintf("%d Invalid room name.\n", ERROR);
1282 if (!strcasecmp(new_room_name, MAILROOM)) {
1283 cprintf("%d '%s' already exists.\n",
1284 ERROR + ALREADY_EXISTS, new_room_name);
1288 if (num_parms(args) >= 5) {
1289 getfloor(&flbuf, extract_int(args, 4));
1290 if ((flbuf.f_flags & F_INUSE) == 0) {
1291 cprintf("%d Invalid floor number.\n",
1292 ERROR + INVALID_FLOOR_OPERATION);
1295 new_room_floor = extract_int(args, 4);
1299 if (CtdlAccessCheck(ac_logged_in)) return;
1301 if (CC->usersupp.axlevel < config.c_createax) {
1302 cprintf("%d You need higher access to create rooms.\n",
1303 ERROR + HIGHER_ACCESS_REQUIRED);
1307 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1308 cprintf("%d Ok to create rooms.\n", OK);
1312 if ((new_room_type < 0) || (new_room_type > 4)) {
1313 cprintf("%d Invalid room type.\n", ERROR);
1317 /* If the user is requesting a personal room, set up the room
1318 * name accordingly (prepend the user number)
1320 if (new_room_type == 4) {
1321 sprintf(aaa, "%010ld.%s",
1322 CC->usersupp.usernum, new_room_name);
1323 strcpy(new_room_name, aaa);
1326 /* Check to make sure the requested room name doesn't already exist */
1327 if (getroom(&qrbuf, new_room_name) == 0) {
1328 cprintf("%d '%s' already exists.\n",
1329 ERROR + ALREADY_EXISTS, qrbuf.QRname);
1334 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1338 newflags = create_room(new_room_name,
1339 new_room_type, new_room_pass, new_room_floor);
1341 /* post a message in Aide> describing the new room */
1342 safestrncpy(aaa, new_room_name, sizeof aaa);
1343 strcat(aaa, "> created by ");
1344 strcat(aaa, CC->usersupp.fullname);
1345 if (newflags & QR_MAILBOX)
1346 strcat(aaa, " [personal]");
1347 else if (newflags & QR_PRIVATE)
1348 strcat(aaa, " [private]");
1349 if (newflags & QR_GUESSNAME)
1350 strcat(aaa, "[guessname] ");
1351 if (newflags & QR_PASSWORDED) {
1352 strcat(aaa, "\n Password: ");
1353 strcat(aaa, new_room_pass);
1358 cprintf("%d '%s' has been created.\n", OK, qrbuf.QRname);
1363 void cmd_einf(char *ok)
1364 { /* enter info file for current room */
1366 char infofilename[256];
1369 if (CtdlAccessCheck(ac_room_aide)) return;
1371 if (atoi(ok) == 0) {
1372 cprintf("%d Ok.\n", OK);
1375 assoc_file_name(infofilename, &CC->quickroom, "info");
1376 lprintf(9, "opening\n");
1377 fp = fopen(infofilename, "w");
1378 lprintf(9, "checking\n");
1380 cprintf("%d Cannot open %s: %s\n",
1381 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1384 cprintf("%d Send info...\n", SEND_LISTING);
1388 if (strcmp(buf, "000"))
1389 fprintf(fp, "%s\n", buf);
1390 } while (strcmp(buf, "000"));
1393 /* now update the room index so people will see our new info */
1394 lgetroom(&CC->quickroom, CC->quickroom.QRname); /* lock so no one steps on us */
1395 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1396 lputroom(&CC->quickroom);
1401 * cmd_lflr() - List all known floors
1408 if (CtdlAccessCheck(ac_logged_in)) return;
1410 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1412 for (a = 0; a < MAXFLOORS; ++a) {
1413 getfloor(&flbuf, a);
1414 if (flbuf.f_flags & F_INUSE) {
1415 cprintf("%d|%s|%d\n",
1427 * create a new floor
1429 void cmd_cflr(char *argbuf)
1431 char new_floor_name[256];
1434 int free_slot = (-1);
1437 extract(new_floor_name, argbuf, 0);
1438 cflr_ok = extract_int(argbuf, 1);
1441 if (CtdlAccessCheck(ac_aide)) return;
1443 for (a = 0; a < MAXFLOORS; ++a) {
1444 getfloor(&flbuf, a);
1446 /* note any free slots while we're scanning... */
1447 if (((flbuf.f_flags & F_INUSE) == 0)
1451 /* check to see if it already exists */
1452 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1453 && (flbuf.f_flags & F_INUSE)) {
1454 cprintf("%d Floor '%s' already exists.\n",
1455 ERROR + ALREADY_EXISTS,
1461 if (free_slot < 0) {
1462 cprintf("%d There is no space available for a new floor.\n",
1463 ERROR + INVALID_FLOOR_OPERATION);
1467 cprintf("%d ok to create...\n", OK);
1470 lgetfloor(&flbuf, free_slot);
1471 flbuf.f_flags = F_INUSE;
1472 flbuf.f_ref_count = 0;
1473 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1474 lputfloor(&flbuf, free_slot);
1475 cprintf("%d %d\n", OK, free_slot);
1483 void cmd_kflr(char *argbuf)
1486 int floor_to_delete;
1490 floor_to_delete = extract_int(argbuf, 0);
1491 kflr_ok = extract_int(argbuf, 1);
1493 if (CtdlAccessCheck(ac_aide)) return;
1495 lgetfloor(&flbuf, floor_to_delete);
1498 if ((flbuf.f_flags & F_INUSE) == 0) {
1499 cprintf("%d Floor %d not in use.\n",
1500 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1503 if (flbuf.f_ref_count != 0) {
1504 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1505 ERROR + INVALID_FLOOR_OPERATION,
1510 cprintf("%d Ok\n", OK);
1512 cprintf("%d Ok to delete...\n", OK);
1519 if ((delete_ok == 1) && (kflr_ok == 1))
1521 lputfloor(&flbuf, floor_to_delete);
1527 void cmd_eflr(char *argbuf)
1533 np = num_parms(argbuf);
1535 cprintf("%d Usage error.\n", ERROR);
1539 if (CtdlAccessCheck(ac_aide)) return;
1541 floor_num = extract_int(argbuf, 0);
1542 lgetfloor(&flbuf, floor_num);
1543 if ((flbuf.f_flags & F_INUSE) == 0) {
1544 lputfloor(&flbuf, floor_num);
1545 cprintf("%d Floor %d is not in use.\n",
1546 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1550 extract(flbuf.f_name, argbuf, 1);
1551 lputfloor(&flbuf, floor_num);
1553 cprintf("%d Ok\n", OK);