4 * Server functions which perform operations on room objects.
19 #if TIME_WITH_SYS_TIME
20 # include <sys/time.h>
24 # include <sys/time.h>
34 #include "dynloader.h"
38 #include "sysdep_decls.h"
42 #include "citserver.h"
46 struct floor *floorcache[MAXFLOORS];
49 * Generic routine for determining user access to rooms
51 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf)
56 /* for internal programs, always do everything */
57 if (((CC->internal_pgm)) && (roombuf->QRflags & QR_INUSE)) {
58 return (UA_KNOWN | UA_GOTOALLOWED);
61 /* Locate any applicable user/room relationships */
62 CtdlGetRelationship(&vbuf, userbuf, roombuf);
64 /* Force the properties of the Aide room */
65 if (!strcasecmp(roombuf->QRname, config.c_aideroom)) {
66 if (userbuf->axlevel >= 6) {
67 retval = UA_KNOWN | UA_GOTOALLOWED;
74 /* If this is a public room, it's accessible... */
75 if ( ((roombuf->QRflags & QR_PRIVATE) == 0)
76 && ((roombuf->QRflags & QR_MAILBOX) == 0) ) {
77 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
80 /* If this is a preferred users only room, check access level */
81 if (roombuf->QRflags & QR_PREFONLY) {
82 if (userbuf->axlevel < 5) {
83 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
87 /* For private rooms, check the generation number matchups */
88 if ( (roombuf->QRflags & QR_PRIVATE)
89 && ((roombuf->QRflags & QR_MAILBOX) == 0) ) {
91 /* An explicit match means the user belongs in this room */
92 if (vbuf.v_flags & V_ACCESS) {
93 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
95 /* Otherwise, check if this is a guess-name or passworded
96 * room. If it is, a goto may at least be attempted
98 else if ((roombuf->QRflags & QR_PRIVATE)
99 || (roombuf->QRflags & QR_PASSWORDED)) {
100 retval = retval & ~UA_KNOWN;
101 retval = retval | UA_GOTOALLOWED;
105 /* For mailbox rooms, also check the generation number matchups */
106 if (roombuf->QRflags & QR_MAILBOX) {
107 if (userbuf->usernum == atol(roombuf->QRname)) {
108 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
110 /* An explicit match means the user belongs in this room */
111 if (vbuf.v_flags & V_ACCESS) {
112 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
116 /* Check to see if the user has forgotten this room */
117 if (vbuf.v_flags & V_FORGET) {
118 retval = retval & ~UA_KNOWN;
119 if ( ( ((roombuf->QRflags & QR_PRIVATE) == 0)
120 && ((roombuf->QRflags & QR_MAILBOX) == 0) )
121 || ( (roombuf->QRflags & QR_MAILBOX)
122 && (atol(roombuf->QRname) == CC->usersupp.usernum))) {
123 retval = retval | UA_ZAPPED;
126 /* If user is explicitly locked out of this room, deny everything */
127 if (vbuf.v_flags & V_LOCKOUT) {
128 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
131 /* Aides get access to all private rooms */
132 if ( (userbuf->axlevel >= 6)
133 && ((roombuf->QRflags & QR_MAILBOX) == 0) ) {
134 if (vbuf.v_flags & V_FORGET) {
135 retval = retval | UA_GOTOALLOWED;
138 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
142 /* On some systems, Aides can gain access to mailboxes as well */
143 if ( (config.c_aide_mailboxes)
144 && (userbuf->axlevel >= 6)
145 && (roombuf->QRflags & QR_MAILBOX) ) {
146 retval = retval | UA_GOTOALLOWED;
149 NEWMSG: /* By the way, we also check for the presence of new messages */
150 if (is_msg_in_mset(vbuf.v_seen, roombuf->QRhighest) == 0) {
151 retval = retval | UA_HASNEWMSGS;
154 /* System rooms never show up in the list. */
155 if (roombuf->QRflags2 & QR2_SYSTEM) {
156 retval = retval & ~UA_KNOWN;
162 * Self-checking stuff for a room record read into memory
164 void room_sanity_check(struct quickroom *qrbuf)
166 /* Mailbox rooms are always on the lowest floor */
167 if (qrbuf->QRflags & QR_MAILBOX) {
170 /* Listing order of 0 is illegal except for base rooms */
171 if (qrbuf->QRorder == 0)
172 if (!(qrbuf->QRflags & QR_MAILBOX) &&
173 strncasecmp(qrbuf->QRname, config.c_baseroom, ROOMNAMELEN)
175 strncasecmp(qrbuf->QRname, config.c_aideroom, ROOMNAMELEN))
181 * getroom() - retrieve room data from disk
183 int getroom(struct quickroom *qrbuf, char *room_name)
185 struct cdbdata *cdbqr;
186 char lowercase_name[ROOMNAMELEN];
187 char personal_lowercase_name[ROOMNAMELEN];
190 for (a = 0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
191 lowercase_name[a] = tolower(room_name[a]);
193 lowercase_name[a] = 0;
195 memset(qrbuf, 0, sizeof(struct quickroom));
197 /* First, try the public namespace */
198 cdbqr = cdb_fetch(CDB_QUICKROOM,
199 lowercase_name, strlen(lowercase_name));
201 /* If that didn't work, try the user's personal namespace */
203 snprintf(personal_lowercase_name,
204 sizeof personal_lowercase_name, "%010ld.%s",
205 CC->usersupp.usernum, lowercase_name);
206 cdbqr = cdb_fetch(CDB_QUICKROOM,
207 personal_lowercase_name,
208 strlen(personal_lowercase_name));
211 memcpy(qrbuf, cdbqr->ptr,
212 ((cdbqr->len > sizeof(struct quickroom)) ?
213 sizeof(struct quickroom) : cdbqr->len));
216 room_sanity_check(qrbuf);
225 * lgetroom() - same as getroom() but locks the record (if supported)
227 int lgetroom(struct quickroom *qrbuf, char *room_name)
230 retval = getroom(qrbuf, room_name);
231 if (retval == 0) begin_critical_section(S_QUICKROOM);
237 * b_putroom() - back end to putroom() and b_deleteroom()
238 * (if the supplied buffer is NULL, delete the room record)
240 void b_putroom(struct quickroom *qrbuf, char *room_name)
242 char lowercase_name[ROOMNAMELEN];
245 for (a = 0; a <= strlen(room_name); ++a) {
246 lowercase_name[a] = tolower(room_name[a]);
250 cdb_delete(CDB_QUICKROOM,
251 lowercase_name, strlen(lowercase_name));
253 time(&qrbuf->QRmtime);
254 cdb_store(CDB_QUICKROOM,
255 lowercase_name, strlen(lowercase_name),
256 qrbuf, sizeof(struct quickroom));
262 * putroom() - store room data to disk
264 void putroom(struct quickroom *qrbuf) {
265 b_putroom(qrbuf, qrbuf->QRname);
270 * b_deleteroom() - delete a room record from disk
272 void b_deleteroom(char *room_name) {
273 b_putroom(NULL, room_name);
279 * lputroom() - same as putroom() but unlocks the record (if supported)
281 void lputroom(struct quickroom *qrbuf)
285 end_critical_section(S_QUICKROOM);
289 /****************************************************************************/
292 * getfloor() - retrieve floor data from disk
294 void getfloor(struct floor *flbuf, int floor_num)
296 struct cdbdata *cdbfl;
298 memset(flbuf, 0, sizeof(struct floor));
299 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
301 memcpy(flbuf, cdbfl->ptr,
302 ((cdbfl->len > sizeof(struct floor)) ?
303 sizeof(struct floor) : cdbfl->len));
306 if (floor_num == 0) {
307 strcpy(flbuf->f_name, "Main Floor");
308 flbuf->f_flags = F_INUSE;
309 flbuf->f_ref_count = 3;
316 * lgetfloor() - same as getfloor() but locks the record (if supported)
318 void lgetfloor(struct floor *flbuf, int floor_num)
321 begin_critical_section(S_FLOORTAB);
322 getfloor(flbuf, floor_num);
327 * cgetfloor() - Get floor record from *cache* (loads from disk if needed)
329 * This is strictly a performance hack.
331 struct floor *cgetfloor(int floor_num) {
332 static int initialized = 0;
335 if (initialized == 0) {
336 for (i=0; i<MAXFLOORS; ++i) {
337 floorcache[floor_num] = NULL;
342 if (floorcache[floor_num] == NULL) {
343 floorcache[floor_num] = mallok(sizeof(struct floor));
344 getfloor(floorcache[floor_num], floor_num);
347 return(floorcache[floor_num]);
353 * putfloor() - store floor data on disk
355 void putfloor(struct floor *flbuf, int floor_num)
357 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
358 flbuf, sizeof(struct floor));
360 /* If we've cached this, clear it out, 'cuz it's WRONG now! */
361 if (floorcache[floor_num] != NULL) {
362 phree(floorcache[floor_num]);
363 floorcache[floor_num] = NULL;
369 * lputfloor() - same as putfloor() but unlocks the record (if supported)
371 void lputfloor(struct floor *flbuf, int floor_num)
374 putfloor(flbuf, floor_num);
375 end_critical_section(S_FLOORTAB);
381 * Traverse the room file...
383 void ForEachRoom(void (*CallBack) (struct quickroom *EachRoom, void *out_data),
386 struct quickroom qrbuf;
387 struct cdbdata *cdbqr;
389 cdb_rewind(CDB_QUICKROOM);
391 while (cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
392 memset(&qrbuf, 0, sizeof(struct quickroom));
393 memcpy(&qrbuf, cdbqr->ptr,
394 ((cdbqr->len > sizeof(struct quickroom)) ?
395 sizeof(struct quickroom) : cdbqr->len));
397 room_sanity_check(&qrbuf);
398 if (qrbuf.QRflags & QR_INUSE)
399 (*CallBack)(&qrbuf, in_data);
405 * delete_msglist() - delete room message pointers
407 void delete_msglist(struct quickroom *whichroom)
409 struct cdbdata *cdbml;
411 /* Make sure the msglist we're deleting actually exists, otherwise
412 * gdbm will complain when we try to delete an invalid record
414 cdbml = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
418 /* Go ahead and delete it */
419 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
427 * sort message pointers
428 * (returns new msg count)
430 int sort_msglist(long listptrs[], int oldcount)
441 for (a = numitems - 2; a >= 0; --a) {
442 for (b = 0; b <= a; ++b) {
443 if (listptrs[b] > (listptrs[b + 1])) {
445 hold2 = listptrs[b + 1];
447 listptrs[b + 1] = hold1;
452 /* and yank any nulls */
453 while ((numitems > 0) && (listptrs[0] == 0L)) {
454 memcpy(&listptrs[0], &listptrs[1],
455 (sizeof(long) * (numitems - 1)));
464 * Determine whether a given room is non-editable.
466 int is_noneditable(struct quickroom *qrbuf)
469 /* Mail> rooms are non-editable */
470 if ( (qrbuf->QRflags & QR_MAILBOX)
471 && (!strcasecmp(&qrbuf->QRname[11], MAILROOM)) )
474 /* Everything else is editable */
481 * Back-back-end for all room listing commands
483 void list_roomname(struct quickroom *qrbuf)
485 char truncated_roomname[ROOMNAMELEN];
487 /* For my own mailbox rooms, chop off the owner prefix */
488 if ( (qrbuf->QRflags & QR_MAILBOX)
489 && (atol(qrbuf->QRname) == CC->usersupp.usernum) ) {
490 strcpy(truncated_roomname, qrbuf->QRname);
491 strcpy(truncated_roomname, &truncated_roomname[11]);
492 cprintf("%s", truncated_roomname);
494 /* For all other rooms, just display the name in its entirety */
496 cprintf("%s", qrbuf->QRname);
499 /* ...and now the other parameters */
500 cprintf("|%u|%d|%d|%d\n",
502 (int) qrbuf->QRfloor,
503 (int) qrbuf->QRorder,
504 (int) qrbuf->QRflags2
510 * cmd_lrms() - List all accessible rooms, known or forgotten
512 void cmd_lrms_backend(struct quickroom *qrbuf, void *data)
514 int FloorBeingSearched = (-1);
515 FloorBeingSearched = *(int *)data;
517 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
518 & (UA_KNOWN | UA_ZAPPED)))
519 && ((qrbuf->QRfloor == (FloorBeingSearched))
520 || ((FloorBeingSearched) < 0)))
521 list_roomname(qrbuf);
524 void cmd_lrms(char *argbuf)
526 int FloorBeingSearched = (-1);
527 if (strlen(argbuf) > 0)
528 FloorBeingSearched = extract_int(argbuf, 0);
530 if (CtdlAccessCheck(ac_logged_in)) return;
532 if (getuser(&CC->usersupp, CC->curr_user)) {
533 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
536 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
538 ForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
545 * cmd_lkra() - List all known rooms
547 void cmd_lkra_backend(struct quickroom *qrbuf, void *data)
549 int FloorBeingSearched = (-1);
550 FloorBeingSearched = *(int *)data;
552 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
554 && ((qrbuf->QRfloor == (FloorBeingSearched))
555 || ((FloorBeingSearched) < 0)))
556 list_roomname(qrbuf);
559 void cmd_lkra(char *argbuf)
561 int FloorBeingSearched = (-1);
562 if (strlen(argbuf) > 0)
563 FloorBeingSearched = extract_int(argbuf, 0);
565 if (CtdlAccessCheck(ac_logged_in)) return;
567 if (getuser(&CC->usersupp, CC->curr_user)) {
568 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
571 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
573 ForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
579 void cmd_lprm_backend(struct quickroom *qrbuf, void *data)
581 int FloorBeingSearched = (-1);
582 FloorBeingSearched = *(int *)data;
584 if ( ((qrbuf->QRflags & QR_PRIVATE) == 0)
585 && ((qrbuf->QRflags & QR_MAILBOX) == 0)
586 && ((qrbuf->QRfloor == (FloorBeingSearched))
587 || ((FloorBeingSearched) < 0)))
588 list_roomname(qrbuf);
591 void cmd_lprm(char *argbuf)
593 int FloorBeingSearched = (-1);
594 if (strlen(argbuf) > 0)
595 FloorBeingSearched = extract_int(argbuf, 0);
597 cprintf("%d Publiic rooms:\n", LISTING_FOLLOWS);
599 ForEachRoom(cmd_lprm_backend, &FloorBeingSearched);
606 * cmd_lkrn() - List all known rooms with new messages
608 void cmd_lkrn_backend(struct quickroom *qrbuf, void *data)
611 int FloorBeingSearched = (-1);
612 FloorBeingSearched = *(int *)data;
614 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
616 && (ra & UA_HASNEWMSGS)
617 && ((qrbuf->QRfloor == (FloorBeingSearched))
618 || ((FloorBeingSearched) < 0)))
619 list_roomname(qrbuf);
622 void cmd_lkrn(char *argbuf)
624 int FloorBeingSearched = (-1);
625 if (strlen(argbuf) > 0)
626 FloorBeingSearched = extract_int(argbuf, 0);
628 if (CtdlAccessCheck(ac_logged_in)) return;
630 if (getuser(&CC->usersupp, CC->curr_user)) {
631 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
634 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
636 ForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
643 * cmd_lkro() - List all known rooms
645 void cmd_lkro_backend(struct quickroom *qrbuf, void *data)
648 int FloorBeingSearched = (-1);
649 FloorBeingSearched = *(int *)data;
651 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
653 && ((ra & UA_HASNEWMSGS) == 0)
654 && ((qrbuf->QRfloor == (FloorBeingSearched))
655 || ((FloorBeingSearched) < 0)))
656 list_roomname(qrbuf);
659 void cmd_lkro(char *argbuf)
661 int FloorBeingSearched = (-1);
662 if (strlen(argbuf) > 0)
663 FloorBeingSearched = extract_int(argbuf, 0);
665 if (CtdlAccessCheck(ac_logged_in)) return;
667 if (getuser(&CC->usersupp, CC->curr_user)) {
668 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
671 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
673 ForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
680 * cmd_lzrm() - List all forgotten rooms
682 void cmd_lzrm_backend(struct quickroom *qrbuf, void *data)
685 int FloorBeingSearched = (-1);
686 FloorBeingSearched = *(int *)data;
688 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
689 if ((ra & UA_GOTOALLOWED)
691 && ((qrbuf->QRfloor == (FloorBeingSearched))
692 || ((FloorBeingSearched) < 0)))
693 list_roomname(qrbuf);
696 void cmd_lzrm(char *argbuf)
698 int FloorBeingSearched = (-1);
699 if (strlen(argbuf) > 0)
700 FloorBeingSearched = extract_int(argbuf, 0);
702 if (CtdlAccessCheck(ac_logged_in)) return;
704 if (getuser(&CC->usersupp, CC->curr_user)) {
705 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
708 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
710 ForEachRoom(cmd_lzrm_backend, &FloorBeingSearched);
716 * Make the specified room the current room for this session. No validation
717 * or access control is done here -- the caller should make sure that the
718 * specified room exists and is ok to access.
720 void usergoto(char *where, int display_result, int transiently,
721 int *retmsgs, int *retnew)
724 int new_messages = 0;
725 int total_messages = 0;
729 int newmailcount = 0;
731 char truncated_roomname[ROOMNAMELEN];
732 struct cdbdata *cdbfr;
733 long *msglist = NULL;
736 /* If the supplied room name is NULL, the caller wants us to know that
737 * it has already copied the quickroom record into CC->quickroom, so
738 * we can skip the extra database fetch.
741 strcpy(CC->quickroom.QRname, where);
742 getroom(&CC->quickroom, where);
745 /* Take care of all the formalities. */
747 begin_critical_section(S_USERSUPP);
748 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
750 /* Know the room ... but not if it's the page log room, or if the
751 * caller specified that we're only entering this room transiently.
753 if ((strcasecmp(CC->quickroom.QRname, config.c_logpages))
754 && (transiently == 0) ) {
755 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
756 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
758 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
759 end_critical_section(S_USERSUPP);
761 /* Check for new mail */
762 newmailcount = NewMailCount();
764 /* set info to 1 if the user needs to read the room's info file */
765 if (CC->quickroom.QRinfo > vbuf.v_lastseen) {
770 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->quickroom.QRnumber, sizeof(long));
772 msglist = mallok(cdbfr->len);
773 memcpy(msglist, cdbfr->ptr, cdbfr->len);
774 num_msgs = cdbfr->len / sizeof(long);
778 if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
779 if (msglist[a] > 0L) {
781 if (is_msg_in_mset(vbuf.v_seen, msglist[a]) == 0) {
787 if (msglist != NULL) phree(msglist);
789 if (CC->quickroom.QRflags & QR_MAILBOX)
794 if ((CC->quickroom.QRroomaide == CC->usersupp.usernum)
795 || (CC->usersupp.axlevel >= 6))
800 strcpy(truncated_roomname, CC->quickroom.QRname);
801 if ( (CC->quickroom.QRflags & QR_MAILBOX)
802 && (atol(CC->quickroom.QRname) == CC->usersupp.usernum) ) {
803 strcpy(truncated_roomname, &truncated_roomname[11]);
806 if (retmsgs != NULL) *retmsgs = total_messages;
807 if (retnew != NULL) *retnew = new_messages;
808 lprintf(9, "<%s> %d new of %d total messages\n",
809 CC->quickroom.QRname,
810 new_messages, total_messages
813 if (display_result) {
814 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d|%d|%d|\n",
815 CIT_OK, CtdlCheckExpress(),
820 (int)CC->quickroom.QRflags,
821 (long)CC->quickroom.QRhighest,
822 (long)vbuf.v_lastseen,
826 (int)CC->quickroom.QRfloor,
828 (int)CC->quickroom.QRdefaultview
835 * cmd_goto() - goto a new room
837 void cmd_goto(char *gargs)
839 struct quickroom QRscratch;
843 char augmented_roomname[SIZ];
848 if (CtdlAccessCheck(ac_logged_in)) return;
850 extract(towhere, gargs, 0);
851 extract(password, gargs, 1);
852 transiently = extract_int(gargs, 2);
854 getuser(&CC->usersupp, CC->curr_user);
856 if (!strcasecmp(towhere, "_BASEROOM_"))
857 strcpy(towhere, config.c_baseroom);
859 if (!strcasecmp(towhere, "_MAIL_"))
860 strcpy(towhere, MAILROOM);
862 if (!strcasecmp(towhere, "_BITBUCKET_"))
863 strcpy(towhere, config.c_twitroom);
866 /* First try a regular match */
867 c = getroom(&QRscratch, towhere);
869 /* Then try a mailbox name match */
871 MailboxName(augmented_roomname, sizeof augmented_roomname,
872 &CC->usersupp, towhere);
873 c = getroom(&QRscratch, augmented_roomname);
875 strcpy(towhere, augmented_roomname);
878 /* And if the room was found... */
881 /* Let internal programs go directly to any room. */
882 if (CC->internal_pgm) {
883 memcpy(&CC->quickroom, &QRscratch,
884 sizeof(struct quickroom));
885 usergoto(NULL, 1, transiently, NULL, NULL);
889 /* See if there is an existing user/room relationship */
890 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
892 /* normal clients have to pass through security */
893 if (ra & UA_GOTOALLOWED) {
898 if ((QRscratch.QRflags & QR_MAILBOX) &&
899 ((ra & UA_GOTOALLOWED))) {
900 memcpy(&CC->quickroom, &QRscratch,
901 sizeof(struct quickroom));
902 usergoto(NULL, 1, transiently, NULL, NULL);
904 } else if ((QRscratch.QRflags & QR_PASSWORDED) &&
905 ((ra & UA_KNOWN) == 0) &&
906 (strcasecmp(QRscratch.QRpasswd, password)) &&
907 (CC->usersupp.axlevel < 6)
909 cprintf("%d wrong or missing passwd\n",
910 ERROR + PASSWORD_REQUIRED);
912 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
913 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
914 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
915 ((ra & UA_KNOWN) == 0) &&
916 (CC->usersupp.axlevel < 6)
918 lprintf(9, "Failed to acquire private room\n");
921 memcpy(&CC->quickroom, &QRscratch,
922 sizeof(struct quickroom));
923 usergoto(NULL, 1, transiently, NULL, NULL);
929 NOPE: cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
935 struct usersupp temp;
936 struct cdbdata *cdbus;
938 getuser(&CC->usersupp, CC->curr_user);
941 * This command is only allowed by aides, room aides,
942 * and room namespace owners
945 || (atol(CC->quickroom.QRname) == CC->usersupp.usernum) ) {
950 cprintf("%d Higher access or room ownership required.\n",
951 ERROR + HIGHER_ACCESS_REQUIRED);
955 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
956 cdb_rewind(CDB_USERSUPP);
957 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
958 memset(&temp, 0, sizeof temp);
959 memcpy(&temp, cdbus->ptr, sizeof temp);
962 if ((CC->quickroom.QRflags & QR_INUSE)
963 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
965 cprintf("%s\n", temp.fullname);
972 * RDIR command for room directory
982 if (CtdlAccessCheck(ac_logged_in)) return;
984 getroom(&CC->quickroom, CC->quickroom.QRname);
985 getuser(&CC->usersupp, CC->curr_user);
987 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
988 cprintf("%d not here.\n", ERROR + NOT_HERE);
991 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
992 && (CC->usersupp.axlevel < 6)
993 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
994 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
997 cprintf("%d %s|%s/files/%s\n",
998 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->quickroom.QRdirname);
1000 snprintf(buf, sizeof buf, "ls %s/files/%s >%s 2> /dev/null",
1001 BBSDIR, CC->quickroom.QRdirname, CC->temp);
1004 snprintf(buf, sizeof buf, "%s/files/%s/filedir", BBSDIR, CC->quickroom.QRdirname);
1005 fd = fopen(buf, "r");
1007 fd = fopen("/dev/null", "r");
1009 ls = fopen(CC->temp, "r");
1010 while (fgets(flnm, sizeof flnm, ls) != NULL) {
1011 flnm[strlen(flnm) - 1] = 0;
1012 if (strcasecmp(flnm, "filedir")) {
1013 snprintf(buf, sizeof buf, "%s/files/%s/%s",
1014 BBSDIR, CC->quickroom.QRdirname, flnm);
1015 stat(buf, &statbuf);
1016 strcpy(comment, "");
1018 while ((fgets(buf, sizeof buf, fd) != NULL)
1019 && (strlen(comment) == 0)) {
1020 buf[strlen(buf) - 1] = 0;
1021 if ((!strncasecmp(buf, flnm, strlen(flnm)))
1022 && (buf[strlen(flnm)] == ' '))
1023 safestrncpy(comment,
1024 &buf[strlen(flnm) + 1],
1027 cprintf("%s|%ld|%s\n", flnm, (long)statbuf.st_size, comment);
1038 * get room parameters (aide or room aide command)
1042 if (CtdlAccessCheck(ac_room_aide)) return;
1044 getroom(&CC->quickroom, CC->quickroom.QRname);
1045 cprintf("%d%c%s|%s|%s|%d|%d|%d|%d|%d|\n",
1049 ((CC->quickroom.QRflags & QR_MAILBOX) ?
1050 &CC->quickroom.QRname[11] : CC->quickroom.QRname),
1052 ((CC->quickroom.QRflags & QR_PASSWORDED) ?
1053 CC->quickroom.QRpasswd : ""),
1055 ((CC->quickroom.QRflags & QR_DIRECTORY) ?
1056 CC->quickroom.QRdirname : ""),
1058 CC->quickroom.QRflags,
1059 (int) CC->quickroom.QRfloor,
1060 (int) CC->quickroom.QRorder,
1062 CC->quickroom.QRdefaultview,
1063 CC->quickroom.QRflags2
1069 * Back end function to rename a room.
1070 * You can also specify which floor to move the room to, or specify -1 to
1071 * keep the room on the same floor it was on.
1073 * If you are renaming a mailbox room, you must supply the namespace prefix
1074 * in *at least* the old name!
1076 int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) {
1078 struct quickroom qrbuf;
1079 struct quickroom qrtmp;
1084 char actual_old_name[SIZ];
1086 lprintf(9, "CtdlRenameRoom(%s, %s, %d)\n",
1087 old_name, new_name, new_floor);
1089 if (new_floor >= 0) {
1090 fl = cgetfloor(new_floor);
1091 if ((fl->f_flags & F_INUSE) == 0) {
1092 return(crr_invalid_floor);
1096 begin_critical_section(S_QUICKROOM);
1098 if ( (getroom(&qrtmp, new_name) == 0)
1099 && (strcasecmp(new_name, old_name)) ) {
1100 ret = crr_already_exists;
1103 else if (getroom(&qrbuf, old_name) != 0) {
1104 ret = crr_room_not_found;
1107 else if ( (CC->usersupp.axlevel < 6)
1108 && (CC->usersupp.usernum != qrbuf.QRroomaide)
1109 && ( (((qrbuf.QRflags & QR_MAILBOX) == 0) || (atol(qrbuf.QRname) != CC->usersupp.usernum))) ) {
1110 ret = crr_access_denied;
1113 else if (is_noneditable(&qrbuf)) {
1114 ret = crr_noneditable;
1119 strcpy(actual_old_name, qrbuf.QRname);
1120 if (qrbuf.QRflags & QR_MAILBOX) {
1121 owner = atol(qrbuf.QRname);
1123 if ( (owner > 0L) && (atol(new_name) == 0L) ) {
1124 snprintf(qrbuf.QRname, sizeof(qrbuf.QRname),
1125 "%010ld.%s", owner, new_name);
1128 safestrncpy(qrbuf.QRname, new_name,
1129 sizeof(qrbuf.QRname));
1132 /* Reject change of floor for baseroom/aideroom */
1133 if (!strncasecmp(old_name, config.c_baseroom, ROOMNAMELEN) ||
1134 !strncasecmp(old_name, config.c_aideroom, ROOMNAMELEN)) {
1138 /* Take care of floor stuff */
1139 old_floor = qrbuf.QRfloor;
1140 if (new_floor < 0) {
1141 new_floor = old_floor;
1143 qrbuf.QRfloor = new_floor;
1146 begin_critical_section(S_CONFIG);
1148 /* If baseroom/aideroom name changes, update config */
1149 if (!strncasecmp(old_name, config.c_baseroom, ROOMNAMELEN)) {
1150 safestrncpy(config.c_baseroom, new_name, ROOMNAMELEN);
1153 if (!strncasecmp(old_name, config.c_aideroom, ROOMNAMELEN)) {
1154 safestrncpy(config.c_aideroom, new_name, ROOMNAMELEN);
1158 end_critical_section(S_CONFIG);
1160 /* If the room name changed, then there are now two room
1161 * records, so we have to delete the old one.
1163 if (strcasecmp(new_name, old_name)) {
1164 b_deleteroom(actual_old_name);
1170 end_critical_section(S_QUICKROOM);
1172 /* Adjust the floor reference counts if necessary */
1173 if (new_floor != old_floor) {
1174 lgetfloor(&flbuf, old_floor);
1175 --flbuf.f_ref_count;
1176 lputfloor(&flbuf, old_floor);
1177 lgetfloor(&flbuf, CC->quickroom.QRfloor);
1178 ++flbuf.f_ref_count;
1179 lputfloor(&flbuf, CC->quickroom.QRfloor);
1182 /* ...and everybody say "YATTA!" */
1188 * set room parameters (aide or room aide command)
1190 void cmd_setr(char *args)
1196 char new_name[ROOMNAMELEN];
1198 if (CtdlAccessCheck(ac_logged_in)) return;
1200 if (num_parms(args) >= 6) {
1201 new_floor = extract_int(args, 5);
1203 new_floor = (-1); /* don't change the floor */
1206 /* When is a new name more than just a new name? When the old name
1207 * has a namespace prefix.
1209 if (CC->quickroom.QRflags & QR_MAILBOX) {
1210 sprintf(new_name, "%010ld.", atol(CC->quickroom.QRname) );
1212 strcpy(new_name, "");
1214 extract(&new_name[strlen(new_name)], args, 0);
1216 r = CtdlRenameRoom(CC->quickroom.QRname, new_name, new_floor);
1218 if (r == crr_room_not_found) {
1219 cprintf("%d Internal error - room not found?\n", ERROR);
1220 } else if (r == crr_already_exists) {
1221 cprintf("%d '%s' already exists.\n",
1222 ERROR + ALREADY_EXISTS, new_name);
1223 } else if (r == crr_noneditable) {
1224 cprintf("%d Cannot edit this room.\n", ERROR);
1225 } else if (r == crr_invalid_floor) {
1226 cprintf("%d Target floor does not exist.\n",
1227 ERROR + INVALID_FLOOR_OPERATION);
1228 } else if (r == crr_access_denied) {
1229 cprintf("%d You do not have permission to edit '%s'\n",
1230 ERROR + HIGHER_ACCESS_REQUIRED,
1231 CC->quickroom.QRname);
1232 } else if (r != crr_ok) {
1233 cprintf("%d Error: CtdlRenameRoom() returned %d\n",
1241 getroom(&CC->quickroom, new_name);
1243 /* Now we have to do a bunch of other stuff */
1245 if (num_parms(args) >= 7) {
1246 new_order = extract_int(args, 6);
1249 if (new_order > 127)
1253 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1255 /* Directory room */
1256 extract(buf, args, 2);
1258 safestrncpy(CC->quickroom.QRdirname, buf,
1259 sizeof CC->quickroom.QRdirname);
1262 if (num_parms(args) >= 8) {
1263 CC->quickroom.QRdefaultview = extract_int(args, 7);
1266 /* Second set of flags */
1267 if (num_parms(args) >= 9) {
1268 CC->quickroom.QRflags2 = extract_int(args, 8);
1272 CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
1273 /* Clean up a client boo-boo: if the client set the room to
1274 * guess-name or passworded, ensure that the private flag is
1277 if ((CC->quickroom.QRflags & QR_GUESSNAME)
1278 || (CC->quickroom.QRflags & QR_PASSWORDED))
1279 CC->quickroom.QRflags |= QR_PRIVATE;
1281 /* Some changes can't apply to BASEROOM */
1282 if (!strncasecmp(CC->quickroom.QRname, config.c_baseroom,
1284 CC->quickroom.QRorder = 0;
1285 CC->quickroom.QRpasswd[0] = '\0';
1286 CC->quickroom.QRflags &= ~(QR_PRIVATE & QR_PASSWORDED &
1287 QR_GUESSNAME & QR_PREFONLY & QR_MAILBOX);
1288 CC->quickroom.QRflags |= QR_PERMANENT;
1290 /* March order (doesn't apply to AIDEROOM) */
1291 if (num_parms(args) >= 7)
1292 CC->quickroom.QRorder = (char) new_order;
1294 extract(buf, args, 1);
1296 safestrncpy(CC->quickroom.QRpasswd, buf,
1297 sizeof CC->quickroom.QRpasswd);
1298 /* Kick everyone out if the client requested it
1299 * (by changing the room's generation number)
1301 if (extract_int(args, 4)) {
1302 time(&CC->quickroom.QRgen);
1305 /* Some changes can't apply to AIDEROOM */
1306 if (!strncasecmp(CC->quickroom.QRname, config.c_baseroom,
1308 CC->quickroom.QRorder = 0;
1309 CC->quickroom.QRflags &= ~QR_MAILBOX;
1310 CC->quickroom.QRflags |= QR_PERMANENT;
1313 /* Write the room record back to disk */
1314 lputroom(&CC->quickroom);
1316 /* Create a room directory if necessary */
1317 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1318 snprintf(buf, sizeof buf,
1319 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1320 CC->quickroom.QRdirname);
1323 snprintf(buf, sizeof buf, "%s> edited by %s\n", CC->quickroom.QRname, CC->curr_user);
1325 cprintf("%d Ok\n", CIT_OK);
1331 * get the name of the room aide for this room
1335 struct usersupp usbuf;
1337 if (CtdlAccessCheck(ac_logged_in)) return;
1339 if (getuserbynumber(&usbuf, CC->quickroom.QRroomaide) == 0) {
1340 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1342 cprintf("%d \n", CIT_OK);
1348 * set the room aide for this room
1350 void cmd_seta(char *new_ra)
1352 struct usersupp usbuf;
1357 if (CtdlAccessCheck(ac_room_aide)) return;
1359 if (getuser(&usbuf, new_ra) != 0) {
1362 newu = usbuf.usernum;
1365 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1367 if (CC->quickroom.QRroomaide != newu) {
1370 CC->quickroom.QRroomaide = newu;
1371 lputroom(&CC->quickroom);
1374 * We have to post the change notice _after_ writing changes to
1375 * the room table, otherwise it would deadlock!
1377 if (post_notice == 1) {
1378 if (strlen(usbuf.fullname) > 0)
1379 snprintf(buf, sizeof buf,
1380 "%s is now room aide for %s>\n",
1381 usbuf.fullname, CC->quickroom.QRname);
1383 snprintf(buf, sizeof buf,
1384 "There is now no room aide for %s>\n",
1385 CC->quickroom.QRname);
1388 cprintf("%d Ok\n", CIT_OK);
1392 * Generate an associated file name for a room
1394 void assoc_file_name(char *buf, size_t n,
1395 struct quickroom *qrbuf, const char *prefix)
1397 snprintf(buf, n, "./%s/%ld", prefix, qrbuf->QRnumber);
1401 * retrieve info file for this room
1409 assoc_file_name(filename, sizeof filename, &CC->quickroom, "info");
1410 info_fp = fopen(filename, "r");
1412 if (info_fp == NULL) {
1413 cprintf("%d No info file.\n", ERROR);
1416 cprintf("%d Info:\n", LISTING_FOLLOWS);
1417 while (fgets(buf, sizeof buf, info_fp) != NULL) {
1418 if (strlen(buf) > 0)
1419 buf[strlen(buf) - 1] = 0;
1420 cprintf("%s\n", buf);
1427 * Back end processing to delete a room and everything associated with it
1429 void delete_room(struct quickroom *qrbuf)
1434 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1436 /* Delete the info file */
1437 assoc_file_name(filename, sizeof filename, qrbuf, "info");
1440 /* Delete the image file */
1441 assoc_file_name(filename, sizeof filename, qrbuf, "images");
1444 /* Delete the room's network config file */
1445 assoc_file_name(filename, sizeof filename, qrbuf, "netconfigs");
1448 /* Delete the messages in the room
1449 * (Careful: this opens an S_QUICKROOM critical section!)
1451 CtdlDeleteMessages(qrbuf->QRname, 0L, "");
1453 /* Flag the room record as not in use */
1454 lgetroom(qrbuf, qrbuf->QRname);
1458 /* then decrement the reference count for the floor */
1459 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1460 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1461 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1463 /* Delete the room record from the database! */
1464 b_deleteroom(qrbuf->QRname);
1470 * Check access control for deleting a room
1472 int CtdlDoIHavePermissionToDeleteThisRoom(struct quickroom *qr) {
1474 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
1478 if (is_noneditable(qr)) {
1483 * For mailboxes, check stuff
1485 if (qr->QRflags & QR_MAILBOX) {
1487 if (strlen(qr->QRname) < 12) return(0); /* bad name */
1489 if (atol(qr->QRname) != CC->usersupp.usernum) {
1490 return(0); /* not my room */
1493 /* Can't delete your Mail> room */
1494 if (!strcasecmp(&qr->QRname[12], MAILROOM)) return(0);
1496 /* Otherwise it's ok */
1501 * For normal rooms, just check for aide or room aide status.
1503 return(is_room_aide());
1507 * aide command: kill the current room
1509 void cmd_kill(char *argbuf)
1512 char deleted_room_name[ROOMNAMELEN];
1515 kill_ok = extract_int(argbuf, 0);
1517 if (CtdlDoIHavePermissionToDeleteThisRoom(&CC->quickroom) == 0) {
1518 cprintf("%d Can't delete this room.\n", ERROR + NOT_HERE);
1522 strcpy(deleted_room_name, CC->quickroom.QRname);
1523 delete_room(&CC->quickroom); /* Do the dirty work */
1524 usergoto(config.c_baseroom, 0, 0, NULL, NULL); /* Return to the Lobby */
1526 /* tell the world what we did */
1527 snprintf(aaa, sizeof aaa, "%s> killed by %s\n",
1528 deleted_room_name, CC->curr_user);
1530 cprintf("%d '%s' deleted.\n", CIT_OK, deleted_room_name);
1532 cprintf("%d ok to delete.\n", CIT_OK);
1538 * Internal code to create a new room (returns room flags)
1540 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only,
1541 * 4=mailbox, 5=mailbox, but caller supplies namespace
1543 unsigned create_room(char *new_room_name,
1545 char *new_room_pass,
1551 struct quickroom qrbuf;
1555 lprintf(9, "create_room(%s)\n", new_room_name);
1556 if (getroom(&qrbuf, new_room_name) == 0) {
1557 lprintf(9, "%s already exists.\n", new_room_name);
1558 return (0); /* already exists */
1562 memset(&qrbuf, 0, sizeof(struct quickroom));
1563 safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
1564 qrbuf.QRflags = QR_INUSE;
1565 if (new_room_type > 0)
1566 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1567 if (new_room_type == 1)
1568 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1569 if (new_room_type == 2)
1570 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1571 if ( (new_room_type == 4) || (new_room_type == 5) )
1572 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1574 /* If the user is requesting a personal room, set up the room
1575 * name accordingly (prepend the user number)
1577 if (new_room_type == 4) {
1578 MailboxName(qrbuf.QRname, sizeof qrbuf.QRname, &CC->usersupp, new_room_name);
1581 safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
1584 /* If the room is private, and the system administrator has elected
1585 * to automatically grant room aide privileges, do so now; otherwise,
1586 * set the room aide to undefined.
1588 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1589 qrbuf.QRroomaide = CC->usersupp.usernum;
1591 qrbuf.QRroomaide = (-1L);
1595 * If the caller is only interested in testing whether this will work,
1596 * return now without creating the room.
1598 if (!really_create) return (qrbuf.QRflags);
1600 qrbuf.QRnumber = get_new_room_number();
1601 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1602 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1603 qrbuf.QRfloor = new_room_floor;
1605 /* save what we just did... */
1608 /* bump the reference count on whatever floor the room is on */
1609 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1610 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1611 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1613 /* Grant the creator access to the room unless the avoid_access
1614 * parameter was specified.
1616 if (avoid_access == 0) {
1617 lgetuser(&CC->usersupp, CC->curr_user);
1618 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1619 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1620 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1621 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1622 lputuser(&CC->usersupp);
1625 /* resume our happy day */
1626 return (qrbuf.QRflags);
1633 void cmd_cre8(char *args)
1636 char new_room_name[SIZ];
1638 char new_room_pass[SIZ];
1643 int avoid_access = 0;
1645 cre8_ok = extract_int(args, 0);
1646 extract(new_room_name, args, 1);
1647 new_room_name[ROOMNAMELEN - 1] = 0;
1648 new_room_type = extract_int(args, 2);
1649 extract(new_room_pass, args, 3);
1650 avoid_access = extract_int(args, 5);
1651 new_room_pass[9] = 0;
1654 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1655 cprintf("%d Invalid room name.\n", ERROR);
1659 if (!strcasecmp(new_room_name, MAILROOM)) {
1660 cprintf("%d '%s' already exists.\n",
1661 ERROR + ALREADY_EXISTS, new_room_name);
1665 if (num_parms(args) >= 5) {
1666 fl = cgetfloor(extract_int(args, 4));
1667 if ((fl->f_flags & F_INUSE) == 0) {
1668 cprintf("%d Invalid floor number.\n",
1669 ERROR + INVALID_FLOOR_OPERATION);
1672 new_room_floor = extract_int(args, 4);
1676 if (CtdlAccessCheck(ac_logged_in)) return;
1678 if (CC->usersupp.axlevel < config.c_createax) {
1679 cprintf("%d You need higher access to create rooms.\n",
1680 ERROR + HIGHER_ACCESS_REQUIRED);
1684 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1685 cprintf("%d Ok to create rooms.\n", CIT_OK);
1689 if ((new_room_type < 0) || (new_room_type > 5)) {
1690 cprintf("%d Invalid room type.\n", ERROR);
1694 if (new_room_type == 5) {
1695 if ((config.c_aide_mailboxes == 0)
1696 || (CC->usersupp.axlevel < 6)) {
1697 cprintf("%d Higher access required\n",
1698 ERROR+HIGHER_ACCESS_REQUIRED);
1703 /* Check to make sure the requested room name doesn't already exist */
1704 newflags = create_room(new_room_name,
1705 new_room_type, new_room_pass, new_room_floor,
1707 if (newflags == 0) {
1708 cprintf("%d '%s' already exists.\n",
1709 ERROR + ALREADY_EXISTS, new_room_name);
1714 cprintf("%d OK to create '%s'\n", CIT_OK, new_room_name);
1718 /* If we reach this point, the room needs to be created. */
1720 newflags = create_room(new_room_name,
1721 new_room_type, new_room_pass, new_room_floor, 1, 0);
1723 /* post a message in Aide> describing the new room */
1724 safestrncpy(aaa, new_room_name, sizeof aaa);
1725 strcat(aaa, "> created by ");
1726 strcat(aaa, CC->usersupp.fullname);
1727 if (newflags & QR_MAILBOX)
1728 strcat(aaa, " [personal]");
1729 else if (newflags & QR_PRIVATE)
1730 strcat(aaa, " [private]");
1731 if (newflags & QR_GUESSNAME)
1732 strcat(aaa, "[guessname] ");
1733 if (newflags & QR_PASSWORDED) {
1734 strcat(aaa, "\n Password: ");
1735 strcat(aaa, new_room_pass);
1740 cprintf("%d '%s' has been created.\n", CIT_OK, new_room_name);
1745 void cmd_einf(char *ok)
1746 { /* enter info file for current room */
1748 char infofilename[SIZ];
1751 if (CtdlAccessCheck(ac_room_aide)) return;
1753 if (atoi(ok) == 0) {
1754 cprintf("%d Ok.\n", CIT_OK);
1757 assoc_file_name(infofilename, sizeof infofilename, &CC->quickroom, "info");
1758 lprintf(9, "opening\n");
1759 fp = fopen(infofilename, "w");
1760 lprintf(9, "checking\n");
1762 cprintf("%d Cannot open %s: %s\n",
1763 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1766 cprintf("%d Send info...\n", SEND_LISTING);
1770 if (strcmp(buf, "000"))
1771 fprintf(fp, "%s\n", buf);
1772 } while (strcmp(buf, "000"));
1775 /* now update the room index so people will see our new info */
1776 lgetroom(&CC->quickroom, CC->quickroom.QRname); /* lock so no one steps on us */
1777 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1778 lputroom(&CC->quickroom);
1783 * cmd_lflr() - List all known floors
1790 if (CtdlAccessCheck(ac_logged_in)) return;
1792 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1794 for (a = 0; a < MAXFLOORS; ++a) {
1795 getfloor(&flbuf, a);
1796 if (flbuf.f_flags & F_INUSE) {
1797 cprintf("%d|%s|%d\n",
1809 * create a new floor
1811 void cmd_cflr(char *argbuf)
1813 char new_floor_name[SIZ];
1816 int free_slot = (-1);
1819 extract(new_floor_name, argbuf, 0);
1820 cflr_ok = extract_int(argbuf, 1);
1822 if (CtdlAccessCheck(ac_aide)) return;
1824 if (strlen(new_floor_name) == 0) {
1825 cprintf("%d Blank floor name not allowed.\n",
1826 ERROR+ILLEGAL_VALUE);
1830 for (a = 0; a < MAXFLOORS; ++a) {
1831 getfloor(&flbuf, a);
1833 /* note any free slots while we're scanning... */
1834 if (((flbuf.f_flags & F_INUSE) == 0)
1838 /* check to see if it already exists */
1839 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1840 && (flbuf.f_flags & F_INUSE)) {
1841 cprintf("%d Floor '%s' already exists.\n",
1842 ERROR + ALREADY_EXISTS,
1848 if (free_slot < 0) {
1849 cprintf("%d There is no space available for a new floor.\n",
1850 ERROR + INVALID_FLOOR_OPERATION);
1854 cprintf("%d ok to create...\n", CIT_OK);
1857 lgetfloor(&flbuf, free_slot);
1858 flbuf.f_flags = F_INUSE;
1859 flbuf.f_ref_count = 0;
1860 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1861 lputfloor(&flbuf, free_slot);
1862 cprintf("%d %d\n", CIT_OK, free_slot);
1870 void cmd_kflr(char *argbuf)
1873 int floor_to_delete;
1877 floor_to_delete = extract_int(argbuf, 0);
1878 kflr_ok = extract_int(argbuf, 1);
1880 if (CtdlAccessCheck(ac_aide)) return;
1882 lgetfloor(&flbuf, floor_to_delete);
1885 if ((flbuf.f_flags & F_INUSE) == 0) {
1886 cprintf("%d Floor %d not in use.\n",
1887 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1890 if (flbuf.f_ref_count != 0) {
1891 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1892 ERROR + INVALID_FLOOR_OPERATION,
1897 cprintf("%d Ok\n", CIT_OK);
1899 cprintf("%d Ok to delete...\n", CIT_OK);
1906 if ((delete_ok == 1) && (kflr_ok == 1))
1908 lputfloor(&flbuf, floor_to_delete);
1914 void cmd_eflr(char *argbuf)
1920 np = num_parms(argbuf);
1922 cprintf("%d Usage error.\n", ERROR);
1926 if (CtdlAccessCheck(ac_aide)) return;
1928 floor_num = extract_int(argbuf, 0);
1929 lgetfloor(&flbuf, floor_num);
1930 if ((flbuf.f_flags & F_INUSE) == 0) {
1931 lputfloor(&flbuf, floor_num);
1932 cprintf("%d Floor %d is not in use.\n",
1933 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1937 extract(flbuf.f_name, argbuf, 1);
1938 lputfloor(&flbuf, floor_num);
1940 cprintf("%d Ok\n", CIT_OK);