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\n",
502 (int) qrbuf->QRfloor,
503 (int) qrbuf->QRorder);
508 * cmd_lrms() - List all accessible rooms, known or forgotten
510 void cmd_lrms_backend(struct quickroom *qrbuf, void *data)
512 int FloorBeingSearched = (-1);
513 FloorBeingSearched = *(int *)data;
515 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
516 & (UA_KNOWN | UA_ZAPPED)))
517 && ((qrbuf->QRfloor == (FloorBeingSearched))
518 || ((FloorBeingSearched) < 0)))
519 list_roomname(qrbuf);
522 void cmd_lrms(char *argbuf)
524 int FloorBeingSearched = (-1);
525 if (strlen(argbuf) > 0)
526 FloorBeingSearched = extract_int(argbuf, 0);
528 if (CtdlAccessCheck(ac_logged_in)) return;
530 if (getuser(&CC->usersupp, CC->curr_user)) {
531 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
534 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
536 ForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
543 * cmd_lkra() - List all known rooms
545 void cmd_lkra_backend(struct quickroom *qrbuf, void *data)
547 int FloorBeingSearched = (-1);
548 FloorBeingSearched = *(int *)data;
550 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
552 && ((qrbuf->QRfloor == (FloorBeingSearched))
553 || ((FloorBeingSearched) < 0)))
554 list_roomname(qrbuf);
557 void cmd_lkra(char *argbuf)
559 int FloorBeingSearched = (-1);
560 if (strlen(argbuf) > 0)
561 FloorBeingSearched = extract_int(argbuf, 0);
563 if (CtdlAccessCheck(ac_logged_in)) return;
565 if (getuser(&CC->usersupp, CC->curr_user)) {
566 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
569 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
571 ForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
578 * cmd_lkrn() - List all known rooms with new messages
580 void cmd_lkrn_backend(struct quickroom *qrbuf, void *data)
583 int FloorBeingSearched = (-1);
584 FloorBeingSearched = *(int *)data;
586 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
588 && (ra & UA_HASNEWMSGS)
589 && ((qrbuf->QRfloor == (FloorBeingSearched))
590 || ((FloorBeingSearched) < 0)))
591 list_roomname(qrbuf);
594 void cmd_lkrn(char *argbuf)
596 int FloorBeingSearched = (-1);
597 if (strlen(argbuf) > 0)
598 FloorBeingSearched = extract_int(argbuf, 0);
600 if (CtdlAccessCheck(ac_logged_in)) return;
602 if (getuser(&CC->usersupp, CC->curr_user)) {
603 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
606 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
608 ForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
615 * cmd_lkro() - List all known rooms
617 void cmd_lkro_backend(struct quickroom *qrbuf, void *data)
620 int FloorBeingSearched = (-1);
621 FloorBeingSearched = *(int *)data;
623 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
625 && ((ra & UA_HASNEWMSGS) == 0)
626 && ((qrbuf->QRfloor == (FloorBeingSearched))
627 || ((FloorBeingSearched) < 0)))
628 list_roomname(qrbuf);
631 void cmd_lkro(char *argbuf)
633 int FloorBeingSearched = (-1);
634 if (strlen(argbuf) > 0)
635 FloorBeingSearched = extract_int(argbuf, 0);
637 if (CtdlAccessCheck(ac_logged_in)) return;
639 if (getuser(&CC->usersupp, CC->curr_user)) {
640 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
643 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
645 ForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
652 * cmd_lzrm() - List all forgotten rooms
654 void cmd_lzrm_backend(struct quickroom *qrbuf, void *data)
657 int FloorBeingSearched = (-1);
658 FloorBeingSearched = *(int *)data;
660 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
661 if ((ra & UA_GOTOALLOWED)
663 && ((qrbuf->QRfloor == (FloorBeingSearched))
664 || ((FloorBeingSearched) < 0)))
665 list_roomname(qrbuf);
668 void cmd_lzrm(char *argbuf)
670 int FloorBeingSearched = (-1);
671 if (strlen(argbuf) > 0)
672 FloorBeingSearched = extract_int(argbuf, 0);
674 if (CtdlAccessCheck(ac_logged_in)) return;
676 if (getuser(&CC->usersupp, CC->curr_user)) {
677 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
680 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
682 ForEachRoom(cmd_lzrm_backend, &FloorBeingSearched);
688 * Make the specified room the current room for this session. No validation
689 * or access control is done here -- the caller should make sure that the
690 * specified room exists and is ok to access.
692 void usergoto(char *where, int display_result, int transiently,
693 int *retmsgs, int *retnew)
696 int new_messages = 0;
697 int total_messages = 0;
701 int newmailcount = 0;
703 char truncated_roomname[ROOMNAMELEN];
704 struct cdbdata *cdbfr;
705 long *msglist = NULL;
708 /* If the supplied room name is NULL, the caller wants us to know that
709 * it has already copied the quickroom record into CC->quickroom, so
710 * we can skip the extra database fetch.
713 strcpy(CC->quickroom.QRname, where);
714 getroom(&CC->quickroom, where);
717 /* Take care of all the formalities. */
719 begin_critical_section(S_USERSUPP);
720 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
722 /* Know the room ... but not if it's the page log room, or if the
723 * caller specified that we're only entering this room transiently.
725 if ((strcasecmp(CC->quickroom.QRname, config.c_logpages))
726 && (transiently == 0) ) {
727 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
728 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
730 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
731 end_critical_section(S_USERSUPP);
733 /* Check for new mail */
734 newmailcount = NewMailCount();
736 /* set info to 1 if the user needs to read the room's info file */
737 if (CC->quickroom.QRinfo > vbuf.v_lastseen) {
742 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->quickroom.QRnumber, sizeof(long));
744 msglist = mallok(cdbfr->len);
745 memcpy(msglist, cdbfr->ptr, cdbfr->len);
746 num_msgs = cdbfr->len / sizeof(long);
750 if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
751 if (msglist[a] > 0L) {
753 if (is_msg_in_mset(vbuf.v_seen, msglist[a]) == 0) {
759 if (msglist != NULL) phree(msglist);
761 if (CC->quickroom.QRflags & QR_MAILBOX)
766 if ((CC->quickroom.QRroomaide == CC->usersupp.usernum)
767 || (CC->usersupp.axlevel >= 6))
772 strcpy(truncated_roomname, CC->quickroom.QRname);
773 if ( (CC->quickroom.QRflags & QR_MAILBOX)
774 && (atol(CC->quickroom.QRname) == CC->usersupp.usernum) ) {
775 strcpy(truncated_roomname, &truncated_roomname[11]);
778 if (retmsgs != NULL) *retmsgs = total_messages;
779 if (retnew != NULL) *retnew = new_messages;
780 lprintf(9, "<%s> %d new of %d total messages\n",
781 CC->quickroom.QRname, new_messages, total_messages);
784 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d|%d\n",
785 CIT_OK, CtdlCheckExpress(),
787 new_messages, total_messages,
788 info, CC->quickroom.QRflags,
789 CC->quickroom.QRhighest,
791 rmailflag, raideflag, newmailcount,
792 CC->quickroom.QRfloor,
798 * cmd_goto() - goto a new room
800 void cmd_goto(char *gargs)
802 struct quickroom QRscratch;
806 char augmented_roomname[SIZ];
811 if (CtdlAccessCheck(ac_logged_in)) return;
813 extract(towhere, gargs, 0);
814 extract(password, gargs, 1);
815 transiently = extract_int(gargs, 2);
817 getuser(&CC->usersupp, CC->curr_user);
819 if (!strcasecmp(towhere, "_BASEROOM_"))
820 strcpy(towhere, config.c_baseroom);
822 if (!strcasecmp(towhere, "_MAIL_"))
823 strcpy(towhere, MAILROOM);
825 if (!strcasecmp(towhere, "_BITBUCKET_"))
826 strcpy(towhere, config.c_twitroom);
829 /* First try a regular match */
830 c = getroom(&QRscratch, towhere);
832 /* Then try a mailbox name match */
834 MailboxName(augmented_roomname, sizeof augmented_roomname,
835 &CC->usersupp, towhere);
836 c = getroom(&QRscratch, augmented_roomname);
838 strcpy(towhere, augmented_roomname);
841 /* And if the room was found... */
844 /* Let internal programs go directly to any room. */
845 if (CC->internal_pgm) {
846 memcpy(&CC->quickroom, &QRscratch,
847 sizeof(struct quickroom));
848 usergoto(NULL, 1, transiently, NULL, NULL);
852 /* See if there is an existing user/room relationship */
853 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
855 /* normal clients have to pass through security */
856 if (ra & UA_GOTOALLOWED) {
861 if ((QRscratch.QRflags & QR_MAILBOX) &&
862 ((ra & UA_GOTOALLOWED))) {
863 memcpy(&CC->quickroom, &QRscratch,
864 sizeof(struct quickroom));
865 usergoto(NULL, 1, transiently, NULL, NULL);
867 } else if ((QRscratch.QRflags & QR_PASSWORDED) &&
868 ((ra & UA_KNOWN) == 0) &&
869 (strcasecmp(QRscratch.QRpasswd, password)) &&
870 (CC->usersupp.axlevel < 6)
872 cprintf("%d wrong or missing passwd\n",
873 ERROR + PASSWORD_REQUIRED);
875 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
876 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
877 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
878 ((ra & UA_KNOWN) == 0) &&
879 (CC->usersupp.axlevel < 6)
881 lprintf(9, "Failed to acquire private room\n");
884 memcpy(&CC->quickroom, &QRscratch,
885 sizeof(struct quickroom));
886 usergoto(NULL, 1, transiently, NULL, NULL);
892 NOPE: cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
898 struct usersupp temp;
899 struct cdbdata *cdbus;
901 getuser(&CC->usersupp, CC->curr_user);
904 * This command is only allowed by aides, room aides,
905 * and room namespace owners
908 || (atol(CC->quickroom.QRname) == CC->usersupp.usernum) ) {
913 cprintf("%d Higher access or room ownership required.\n",
914 ERROR + HIGHER_ACCESS_REQUIRED);
918 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
919 cdb_rewind(CDB_USERSUPP);
920 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
921 memset(&temp, 0, sizeof temp);
922 memcpy(&temp, cdbus->ptr, sizeof temp);
925 if ((CC->quickroom.QRflags & QR_INUSE)
926 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
928 cprintf("%s\n", temp.fullname);
935 * RDIR command for room directory
945 if (CtdlAccessCheck(ac_logged_in)) return;
947 getroom(&CC->quickroom, CC->quickroom.QRname);
948 getuser(&CC->usersupp, CC->curr_user);
950 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
951 cprintf("%d not here.\n", ERROR + NOT_HERE);
954 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
955 && (CC->usersupp.axlevel < 6)
956 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
957 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
960 cprintf("%d %s|%s/files/%s\n",
961 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->quickroom.QRdirname);
963 snprintf(buf, sizeof buf, "ls %s/files/%s >%s 2> /dev/null",
964 BBSDIR, CC->quickroom.QRdirname, CC->temp);
967 snprintf(buf, sizeof buf, "%s/files/%s/filedir", BBSDIR, CC->quickroom.QRdirname);
968 fd = fopen(buf, "r");
970 fd = fopen("/dev/null", "r");
972 ls = fopen(CC->temp, "r");
973 while (fgets(flnm, sizeof flnm, ls) != NULL) {
974 flnm[strlen(flnm) - 1] = 0;
975 if (strcasecmp(flnm, "filedir")) {
976 snprintf(buf, sizeof buf, "%s/files/%s/%s",
977 BBSDIR, CC->quickroom.QRdirname, flnm);
981 while ((fgets(buf, sizeof buf, fd) != NULL)
982 && (strlen(comment) == 0)) {
983 buf[strlen(buf) - 1] = 0;
984 if ((!strncasecmp(buf, flnm, strlen(flnm)))
985 && (buf[strlen(flnm)] == ' '))
987 &buf[strlen(flnm) + 1],
990 cprintf("%s|%ld|%s\n", flnm, (long)statbuf.st_size, comment);
1001 * get room parameters (aide or room aide command)
1005 if (CtdlAccessCheck(ac_room_aide)) return;
1007 getroom(&CC->quickroom, CC->quickroom.QRname);
1008 cprintf("%d%c%s|%s|%s|%d|%d|%d|%d\n",
1012 ((CC->quickroom.QRflags & QR_MAILBOX) ?
1013 &CC->quickroom.QRname[11] : CC->quickroom.QRname),
1015 ((CC->quickroom.QRflags & QR_PASSWORDED) ?
1016 CC->quickroom.QRpasswd : ""),
1018 ((CC->quickroom.QRflags & QR_DIRECTORY) ?
1019 CC->quickroom.QRdirname : ""),
1021 CC->quickroom.QRflags,
1022 (int) CC->quickroom.QRfloor,
1023 (int) CC->quickroom.QRorder,
1025 CC->quickroom.QRdefaultview);
1030 * Back end function to rename a room.
1031 * You can also specify which floor to move the room to, or specify -1 to
1032 * keep the room on the same floor it was on.
1034 * If you are renaming a mailbox room, you must supply the namespace prefix
1035 * in *at least* the old name!
1037 int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) {
1039 struct quickroom qrbuf;
1040 struct quickroom qrtmp;
1046 lprintf(9, "CtdlRenameRoom(%s, %s, %d)\n",
1047 old_name, new_name, new_floor);
1049 if (new_floor >= 0) {
1050 fl = cgetfloor(new_floor);
1051 if ((fl->f_flags & F_INUSE) == 0) {
1052 return(crr_invalid_floor);
1056 begin_critical_section(S_QUICKROOM);
1058 if ( (getroom(&qrtmp, new_name) == 0)
1059 && (strcasecmp(new_name, old_name)) ) {
1060 ret = crr_already_exists;
1063 else if (getroom(&qrbuf, old_name) != 0) {
1064 ret = crr_room_not_found;
1067 else if ( (CC->usersupp.axlevel < 6)
1068 && (CC->usersupp.usernum != qrbuf.QRroomaide)
1069 && ( (((qrbuf.QRflags & QR_MAILBOX) == 0) || (atol(qrbuf.QRname) != CC->usersupp.usernum))) ) {
1070 ret = crr_access_denied;
1073 else if (is_noneditable(&qrbuf)) {
1074 ret = crr_noneditable;
1079 if (qrbuf.QRflags & QR_MAILBOX) {
1080 owner = atol(qrbuf.QRname);
1082 if ( (owner > 0L) && (atol(new_name) == 0L) ) {
1083 snprintf(qrbuf.QRname, sizeof(qrbuf.QRname),
1084 "%010ld.%s", owner, new_name);
1087 safestrncpy(qrbuf.QRname, new_name,
1088 sizeof(qrbuf.QRname));
1091 /* Reject change of floor for baseroom/aideroom */
1092 if (!strncasecmp(old_name, config.c_baseroom, ROOMNAMELEN) ||
1093 !strncasecmp(old_name, config.c_aideroom, ROOMNAMELEN)) {
1097 /* Take care of floor stuff */
1098 old_floor = qrbuf.QRfloor;
1099 if (new_floor < 0) {
1100 new_floor = old_floor;
1102 qrbuf.QRfloor = new_floor;
1105 begin_critical_section(S_CONFIG);
1107 /* If baseroom/aideroom name changes, update config */
1108 if (!strncasecmp(old_name, config.c_baseroom, ROOMNAMELEN)) {
1109 safestrncpy(config.c_baseroom, new_name, ROOMNAMELEN);
1112 if (!strncasecmp(old_name, config.c_aideroom, ROOMNAMELEN)) {
1113 safestrncpy(config.c_aideroom, new_name, ROOMNAMELEN);
1117 end_critical_section(S_CONFIG);
1119 /* If the room name changed, then there are now two room
1120 * records, so we have to delete the old one.
1122 if (strcasecmp(new_name, old_name)) {
1123 b_deleteroom(old_name);
1129 end_critical_section(S_QUICKROOM);
1131 /* Adjust the floor reference counts if necessary */
1132 if (new_floor != old_floor) {
1133 lgetfloor(&flbuf, old_floor);
1134 --flbuf.f_ref_count;
1135 lputfloor(&flbuf, old_floor);
1136 lgetfloor(&flbuf, CC->quickroom.QRfloor);
1137 ++flbuf.f_ref_count;
1138 lputfloor(&flbuf, CC->quickroom.QRfloor);
1141 /* ...and everybody say "YATTA!" */
1147 * set room parameters (aide or room aide command)
1149 void cmd_setr(char *args)
1155 char new_name[ROOMNAMELEN];
1157 if (CtdlAccessCheck(ac_logged_in)) return;
1159 if (num_parms(args) >= 6) {
1160 new_floor = extract_int(args, 5);
1162 new_floor = (-1); /* don't change the floor */
1165 /* When is a new name more than just a new name? When the old name
1166 * has a namespace prefix.
1168 if (CC->quickroom.QRflags & QR_MAILBOX) {
1169 sprintf(new_name, "%010ld.", atol(CC->quickroom.QRname) );
1171 strcpy(new_name, "");
1173 extract(&new_name[strlen(new_name)], args, 0);
1175 r = CtdlRenameRoom(CC->quickroom.QRname, new_name, new_floor);
1177 if (r == crr_room_not_found) {
1178 cprintf("%d Internal error - room not found?\n", ERROR);
1179 } else if (r == crr_already_exists) {
1180 cprintf("%d '%s' already exists.\n",
1181 ERROR + ALREADY_EXISTS, new_name);
1182 } else if (r == crr_noneditable) {
1183 cprintf("%d Cannot edit this room.\n", ERROR);
1184 } else if (r == crr_invalid_floor) {
1185 cprintf("%d Target floor does not exist.\n",
1186 ERROR + INVALID_FLOOR_OPERATION);
1187 } else if (r == crr_access_denied) {
1188 cprintf("%d You do not have permission to edit '%s'\n",
1189 ERROR + HIGHER_ACCESS_REQUIRED,
1190 CC->quickroom.QRname);
1191 } else if (r != crr_ok) {
1192 cprintf("%d Error: CtdlRenameRoom() returned %d\n",
1200 getroom(&CC->quickroom, new_name);
1202 /* Now we have to do a bunch of other stuff */
1204 if (num_parms(args) >= 7) {
1205 new_order = extract_int(args, 6);
1208 if (new_order > 127)
1212 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1214 /* Directory room */
1215 extract(buf, args, 2);
1217 safestrncpy(CC->quickroom.QRdirname, buf,
1218 sizeof CC->quickroom.QRdirname);
1221 if (num_parms(args) >= 8) {
1222 CC->quickroom.QRdefaultview = extract_int(args, 7);
1226 CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
1227 /* Clean up a client boo-boo: if the client set the room to
1228 * guess-name or passworded, ensure that the private flag is
1231 if ((CC->quickroom.QRflags & QR_GUESSNAME)
1232 || (CC->quickroom.QRflags & QR_PASSWORDED))
1233 CC->quickroom.QRflags |= QR_PRIVATE;
1235 /* Some changes can't apply to BASEROOM */
1236 if (!strncasecmp(CC->quickroom.QRname, config.c_baseroom,
1238 CC->quickroom.QRorder = 0;
1239 CC->quickroom.QRpasswd[0] = '\0';
1240 CC->quickroom.QRflags &= ~(QR_PRIVATE & QR_PASSWORDED &
1241 QR_GUESSNAME & QR_PREFONLY & QR_MAILBOX);
1242 CC->quickroom.QRflags |= QR_PERMANENT;
1244 /* March order (doesn't apply to AIDEROOM) */
1245 if (num_parms(args) >= 7)
1246 CC->quickroom.QRorder = (char) new_order;
1248 extract(buf, args, 1);
1250 safestrncpy(CC->quickroom.QRpasswd, buf,
1251 sizeof CC->quickroom.QRpasswd);
1252 /* Kick everyone out if the client requested it
1253 * (by changing the room's generation number)
1255 if (extract_int(args, 4)) {
1256 time(&CC->quickroom.QRgen);
1259 /* Some changes can't apply to AIDEROOM */
1260 if (!strncasecmp(CC->quickroom.QRname, config.c_baseroom,
1262 CC->quickroom.QRorder = 0;
1263 CC->quickroom.QRflags &= ~QR_MAILBOX;
1264 CC->quickroom.QRflags |= QR_PERMANENT;
1267 /* Write the room record back to disk */
1268 lputroom(&CC->quickroom);
1270 /* Create a room directory if necessary */
1271 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1272 snprintf(buf, sizeof buf,
1273 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1274 CC->quickroom.QRdirname);
1277 snprintf(buf, sizeof buf, "%s> edited by %s\n", CC->quickroom.QRname, CC->curr_user);
1279 cprintf("%d Ok\n", CIT_OK);
1285 * get the name of the room aide for this room
1289 struct usersupp usbuf;
1291 if (CtdlAccessCheck(ac_logged_in)) return;
1293 if (getuserbynumber(&usbuf, CC->quickroom.QRroomaide) == 0) {
1294 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1296 cprintf("%d \n", CIT_OK);
1302 * set the room aide for this room
1304 void cmd_seta(char *new_ra)
1306 struct usersupp usbuf;
1311 if (CtdlAccessCheck(ac_room_aide)) return;
1313 if (getuser(&usbuf, new_ra) != 0) {
1316 newu = usbuf.usernum;
1319 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1321 if (CC->quickroom.QRroomaide != newu) {
1324 CC->quickroom.QRroomaide = newu;
1325 lputroom(&CC->quickroom);
1328 * We have to post the change notice _after_ writing changes to
1329 * the room table, otherwise it would deadlock!
1331 if (post_notice == 1) {
1332 if (strlen(usbuf.fullname) > 0)
1333 snprintf(buf, sizeof buf,
1334 "%s is now room aide for %s>\n",
1335 usbuf.fullname, CC->quickroom.QRname);
1337 snprintf(buf, sizeof buf,
1338 "There is now no room aide for %s>\n",
1339 CC->quickroom.QRname);
1342 cprintf("%d Ok\n", CIT_OK);
1346 * Generate an associated file name for a room
1348 void assoc_file_name(char *buf, size_t n,
1349 struct quickroom *qrbuf, const char *prefix)
1351 snprintf(buf, n, "./%s/%ld", prefix, qrbuf->QRnumber);
1355 * retrieve info file for this room
1363 assoc_file_name(filename, sizeof filename, &CC->quickroom, "info");
1364 info_fp = fopen(filename, "r");
1366 if (info_fp == NULL) {
1367 cprintf("%d No info file.\n", ERROR);
1370 cprintf("%d Info:\n", LISTING_FOLLOWS);
1371 while (fgets(buf, sizeof buf, info_fp) != NULL) {
1372 if (strlen(buf) > 0)
1373 buf[strlen(buf) - 1] = 0;
1374 cprintf("%s\n", buf);
1381 * Back end processing to delete a room and everything associated with it
1383 void delete_room(struct quickroom *qrbuf)
1388 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1390 /* Delete the info file */
1391 assoc_file_name(filename, sizeof filename, qrbuf, "info");
1394 /* Delete the image file */
1395 assoc_file_name(filename, sizeof filename, qrbuf, "images");
1398 /* Delete the room's network config file */
1399 assoc_file_name(filename, sizeof filename, qrbuf, "netconfigs");
1402 /* Delete the messages in the room
1403 * (Careful: this opens an S_QUICKROOM critical section!)
1405 CtdlDeleteMessages(qrbuf->QRname, 0L, "");
1407 /* Flag the room record as not in use */
1408 lgetroom(qrbuf, qrbuf->QRname);
1412 /* then decrement the reference count for the floor */
1413 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1414 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1415 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1417 /* Delete the room record from the database! */
1418 b_deleteroom(qrbuf->QRname);
1424 * Check access control for deleting a room
1426 int CtdlDoIHavePermissionToDeleteThisRoom(struct quickroom *qr) {
1428 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
1432 if (is_noneditable(qr)) {
1437 * For mailboxes, check stuff
1439 if (qr->QRflags & QR_MAILBOX) {
1441 if (strlen(qr->QRname) < 12) return(0); /* bad name */
1443 if (atol(qr->QRname) != CC->usersupp.usernum) {
1444 return(0); /* not my room */
1447 /* Can't delete your Mail> room */
1448 if (!strcasecmp(&qr->QRname[12], MAILROOM)) return(0);
1450 /* Otherwise it's ok */
1455 * For normal rooms, just check for aide or room aide status.
1457 return(is_room_aide());
1461 * aide command: kill the current room
1463 void cmd_kill(char *argbuf)
1466 char deleted_room_name[ROOMNAMELEN];
1469 kill_ok = extract_int(argbuf, 0);
1471 if (CtdlDoIHavePermissionToDeleteThisRoom(&CC->quickroom) == 0) {
1472 cprintf("%d Can't delete this room.\n", ERROR + NOT_HERE);
1476 strcpy(deleted_room_name, CC->quickroom.QRname);
1477 delete_room(&CC->quickroom); /* Do the dirty work */
1478 usergoto(config.c_baseroom, 0, 0, NULL, NULL); /* Return to the Lobby */
1480 /* tell the world what we did */
1481 snprintf(aaa, sizeof aaa, "%s> killed by %s\n",
1482 deleted_room_name, CC->curr_user);
1484 cprintf("%d '%s' deleted.\n", CIT_OK, deleted_room_name);
1486 cprintf("%d ok to delete.\n", CIT_OK);
1492 * Internal code to create a new room (returns room flags)
1494 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only,
1495 * 4=mailbox, 5=mailbox, but caller supplies namespace
1497 unsigned create_room(char *new_room_name,
1499 char *new_room_pass,
1505 struct quickroom qrbuf;
1509 lprintf(9, "create_room(%s)\n", new_room_name);
1510 if (getroom(&qrbuf, new_room_name) == 0) {
1511 lprintf(9, "%s already exists.\n", new_room_name);
1512 return (0); /* already exists */
1516 memset(&qrbuf, 0, sizeof(struct quickroom));
1517 safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
1518 qrbuf.QRflags = QR_INUSE;
1519 if (new_room_type > 0)
1520 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1521 if (new_room_type == 1)
1522 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1523 if (new_room_type == 2)
1524 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1525 if ( (new_room_type == 4) || (new_room_type == 5) )
1526 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1528 /* If the user is requesting a personal room, set up the room
1529 * name accordingly (prepend the user number)
1531 if (new_room_type == 4) {
1532 MailboxName(qrbuf.QRname, sizeof qrbuf.QRname, &CC->usersupp, new_room_name);
1535 safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
1538 /* If the room is private, and the system administrator has elected
1539 * to automatically grant room aide privileges, do so now; otherwise,
1540 * set the room aide to undefined.
1542 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1543 qrbuf.QRroomaide = CC->usersupp.usernum;
1545 qrbuf.QRroomaide = (-1L);
1549 * If the caller is only interested in testing whether this will work,
1550 * return now without creating the room.
1552 if (!really_create) return (qrbuf.QRflags);
1554 qrbuf.QRnumber = get_new_room_number();
1555 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1556 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1557 qrbuf.QRfloor = new_room_floor;
1559 /* save what we just did... */
1562 /* bump the reference count on whatever floor the room is on */
1563 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1564 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1565 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1567 /* Grant the creator access to the room unless the avoid_access
1568 * parameter was specified.
1570 if (avoid_access == 0) {
1571 lgetuser(&CC->usersupp, CC->curr_user);
1572 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1573 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1574 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1575 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1576 lputuser(&CC->usersupp);
1579 /* resume our happy day */
1580 return (qrbuf.QRflags);
1587 void cmd_cre8(char *args)
1590 char new_room_name[SIZ];
1592 char new_room_pass[SIZ];
1598 cre8_ok = extract_int(args, 0);
1599 extract(new_room_name, args, 1);
1600 new_room_name[ROOMNAMELEN - 1] = 0;
1601 new_room_type = extract_int(args, 2);
1602 extract(new_room_pass, args, 3);
1603 new_room_pass[9] = 0;
1606 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1607 cprintf("%d Invalid room name.\n", ERROR);
1611 if (!strcasecmp(new_room_name, MAILROOM)) {
1612 cprintf("%d '%s' already exists.\n",
1613 ERROR + ALREADY_EXISTS, new_room_name);
1617 if (num_parms(args) >= 5) {
1618 fl = cgetfloor(extract_int(args, 4));
1619 if ((fl->f_flags & F_INUSE) == 0) {
1620 cprintf("%d Invalid floor number.\n",
1621 ERROR + INVALID_FLOOR_OPERATION);
1624 new_room_floor = extract_int(args, 4);
1628 if (CtdlAccessCheck(ac_logged_in)) return;
1630 if (CC->usersupp.axlevel < config.c_createax) {
1631 cprintf("%d You need higher access to create rooms.\n",
1632 ERROR + HIGHER_ACCESS_REQUIRED);
1636 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1637 cprintf("%d Ok to create rooms.\n", CIT_OK);
1641 if ((new_room_type < 0) || (new_room_type > 5)) {
1642 cprintf("%d Invalid room type.\n", ERROR);
1646 if (new_room_type == 5) {
1647 if ((config.c_aide_mailboxes == 0)
1648 || (CC->usersupp.axlevel < 6)) {
1649 cprintf("%d Higher access required\n",
1650 ERROR+HIGHER_ACCESS_REQUIRED);
1655 /* Check to make sure the requested room name doesn't already exist */
1656 newflags = create_room(new_room_name,
1657 new_room_type, new_room_pass, new_room_floor, 0, 0);
1658 if (newflags == 0) {
1659 cprintf("%d '%s' already exists.\n",
1660 ERROR + ALREADY_EXISTS, new_room_name);
1665 cprintf("%d OK to create '%s'\n", CIT_OK, new_room_name);
1669 /* If we reach this point, the room needs to be created. */
1671 newflags = create_room(new_room_name,
1672 new_room_type, new_room_pass, new_room_floor, 1, 0);
1674 /* post a message in Aide> describing the new room */
1675 safestrncpy(aaa, new_room_name, sizeof aaa);
1676 strcat(aaa, "> created by ");
1677 strcat(aaa, CC->usersupp.fullname);
1678 if (newflags & QR_MAILBOX)
1679 strcat(aaa, " [personal]");
1680 else if (newflags & QR_PRIVATE)
1681 strcat(aaa, " [private]");
1682 if (newflags & QR_GUESSNAME)
1683 strcat(aaa, "[guessname] ");
1684 if (newflags & QR_PASSWORDED) {
1685 strcat(aaa, "\n Password: ");
1686 strcat(aaa, new_room_pass);
1691 cprintf("%d '%s' has been created.\n", CIT_OK, new_room_name);
1696 void cmd_einf(char *ok)
1697 { /* enter info file for current room */
1699 char infofilename[SIZ];
1702 if (CtdlAccessCheck(ac_room_aide)) return;
1704 if (atoi(ok) == 0) {
1705 cprintf("%d Ok.\n", CIT_OK);
1708 assoc_file_name(infofilename, sizeof infofilename, &CC->quickroom, "info");
1709 lprintf(9, "opening\n");
1710 fp = fopen(infofilename, "w");
1711 lprintf(9, "checking\n");
1713 cprintf("%d Cannot open %s: %s\n",
1714 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1717 cprintf("%d Send info...\n", SEND_LISTING);
1721 if (strcmp(buf, "000"))
1722 fprintf(fp, "%s\n", buf);
1723 } while (strcmp(buf, "000"));
1726 /* now update the room index so people will see our new info */
1727 lgetroom(&CC->quickroom, CC->quickroom.QRname); /* lock so no one steps on us */
1728 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1729 lputroom(&CC->quickroom);
1734 * cmd_lflr() - List all known floors
1741 if (CtdlAccessCheck(ac_logged_in)) return;
1743 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1745 for (a = 0; a < MAXFLOORS; ++a) {
1746 getfloor(&flbuf, a);
1747 if (flbuf.f_flags & F_INUSE) {
1748 cprintf("%d|%s|%d\n",
1760 * create a new floor
1762 void cmd_cflr(char *argbuf)
1764 char new_floor_name[SIZ];
1767 int free_slot = (-1);
1770 extract(new_floor_name, argbuf, 0);
1771 cflr_ok = extract_int(argbuf, 1);
1774 if (CtdlAccessCheck(ac_aide)) return;
1776 for (a = 0; a < MAXFLOORS; ++a) {
1777 getfloor(&flbuf, a);
1779 /* note any free slots while we're scanning... */
1780 if (((flbuf.f_flags & F_INUSE) == 0)
1784 /* check to see if it already exists */
1785 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1786 && (flbuf.f_flags & F_INUSE)) {
1787 cprintf("%d Floor '%s' already exists.\n",
1788 ERROR + ALREADY_EXISTS,
1794 if (free_slot < 0) {
1795 cprintf("%d There is no space available for a new floor.\n",
1796 ERROR + INVALID_FLOOR_OPERATION);
1800 cprintf("%d ok to create...\n", CIT_OK);
1803 lgetfloor(&flbuf, free_slot);
1804 flbuf.f_flags = F_INUSE;
1805 flbuf.f_ref_count = 0;
1806 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1807 lputfloor(&flbuf, free_slot);
1808 cprintf("%d %d\n", CIT_OK, free_slot);
1816 void cmd_kflr(char *argbuf)
1819 int floor_to_delete;
1823 floor_to_delete = extract_int(argbuf, 0);
1824 kflr_ok = extract_int(argbuf, 1);
1826 if (CtdlAccessCheck(ac_aide)) return;
1828 lgetfloor(&flbuf, floor_to_delete);
1831 if ((flbuf.f_flags & F_INUSE) == 0) {
1832 cprintf("%d Floor %d not in use.\n",
1833 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1836 if (flbuf.f_ref_count != 0) {
1837 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1838 ERROR + INVALID_FLOOR_OPERATION,
1843 cprintf("%d Ok\n", CIT_OK);
1845 cprintf("%d Ok to delete...\n", CIT_OK);
1852 if ((delete_ok == 1) && (kflr_ok == 1))
1854 lputfloor(&flbuf, floor_to_delete);
1860 void cmd_eflr(char *argbuf)
1866 np = num_parms(argbuf);
1868 cprintf("%d Usage error.\n", ERROR);
1872 if (CtdlAccessCheck(ac_aide)) return;
1874 floor_num = extract_int(argbuf, 0);
1875 lgetfloor(&flbuf, floor_num);
1876 if ((flbuf.f_flags & F_INUSE) == 0) {
1877 lputfloor(&flbuf, floor_num);
1878 cprintf("%d Floor %d is not in use.\n",
1879 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1883 extract(flbuf.f_name, argbuf, 1);
1884 lputfloor(&flbuf, floor_num);
1886 cprintf("%d Ok\n", CIT_OK);