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, 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 (!is_noneditable(qrbuf))
178 * getroom() - retrieve room data from disk
180 int getroom(struct quickroom *qrbuf, char *room_name)
182 struct cdbdata *cdbqr;
183 char lowercase_name[ROOMNAMELEN];
184 char personal_lowercase_name[ROOMNAMELEN];
187 for (a = 0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
188 lowercase_name[a] = tolower(room_name[a]);
190 lowercase_name[a] = 0;
192 memset(qrbuf, 0, sizeof(struct quickroom));
194 /* First, try the public namespace */
195 cdbqr = cdb_fetch(CDB_QUICKROOM,
196 lowercase_name, strlen(lowercase_name));
198 /* If that didn't work, try the user's personal namespace */
200 snprintf(personal_lowercase_name,
201 sizeof personal_lowercase_name, "%010ld.%s",
202 CC->usersupp.usernum, lowercase_name);
203 cdbqr = cdb_fetch(CDB_QUICKROOM,
204 personal_lowercase_name,
205 strlen(personal_lowercase_name));
208 memcpy(qrbuf, cdbqr->ptr,
209 ((cdbqr->len > sizeof(struct quickroom)) ?
210 sizeof(struct quickroom) : cdbqr->len));
213 room_sanity_check(qrbuf);
222 * lgetroom() - same as getroom() but locks the record (if supported)
224 int lgetroom(struct quickroom *qrbuf, char *room_name)
227 retval = getroom(qrbuf, room_name);
228 if (retval == 0) begin_critical_section(S_QUICKROOM);
234 * b_putroom() - back end to putroom() and b_deleteroom()
235 * (if the supplied buffer is NULL, delete the room record)
237 void b_putroom(struct quickroom *qrbuf, char *room_name)
239 char lowercase_name[ROOMNAMELEN];
242 for (a = 0; a <= strlen(room_name); ++a) {
243 lowercase_name[a] = tolower(room_name[a]);
247 cdb_delete(CDB_QUICKROOM,
248 lowercase_name, strlen(lowercase_name));
250 time(&qrbuf->QRmtime);
251 cdb_store(CDB_QUICKROOM,
252 lowercase_name, strlen(lowercase_name),
253 qrbuf, sizeof(struct quickroom));
259 * putroom() - store room data to disk
261 void putroom(struct quickroom *qrbuf) {
262 b_putroom(qrbuf, qrbuf->QRname);
267 * b_deleteroom() - delete a room record from disk
269 void b_deleteroom(char *room_name) {
270 b_putroom(NULL, room_name);
276 * lputroom() - same as putroom() but unlocks the record (if supported)
278 void lputroom(struct quickroom *qrbuf)
282 end_critical_section(S_QUICKROOM);
286 /****************************************************************************/
289 * getfloor() - retrieve floor data from disk
291 void getfloor(struct floor *flbuf, int floor_num)
293 struct cdbdata *cdbfl;
295 memset(flbuf, 0, sizeof(struct floor));
296 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
298 memcpy(flbuf, cdbfl->ptr,
299 ((cdbfl->len > sizeof(struct floor)) ?
300 sizeof(struct floor) : cdbfl->len));
303 if (floor_num == 0) {
304 strcpy(flbuf->f_name, "Main Floor");
305 flbuf->f_flags = F_INUSE;
306 flbuf->f_ref_count = 3;
313 * lgetfloor() - same as getfloor() but locks the record (if supported)
315 void lgetfloor(struct floor *flbuf, int floor_num)
318 begin_critical_section(S_FLOORTAB);
319 getfloor(flbuf, floor_num);
324 * cgetfloor() - Get floor record from *cache* (loads from disk if needed)
326 * This is strictly a performance hack.
328 struct floor *cgetfloor(int floor_num) {
329 static int initialized = 0;
332 if (initialized == 0) {
333 for (i=0; i<MAXFLOORS; ++i) {
334 floorcache[floor_num] = NULL;
339 if (floorcache[floor_num] == NULL) {
340 floorcache[floor_num] = mallok(sizeof(struct floor));
341 getfloor(floorcache[floor_num], floor_num);
344 return(floorcache[floor_num]);
350 * putfloor() - store floor data on disk
352 void putfloor(struct floor *flbuf, int floor_num)
354 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
355 flbuf, sizeof(struct floor));
357 /* If we've cached this, clear it out, 'cuz it's WRONG now! */
358 if (floorcache[floor_num] != NULL) {
359 phree(floorcache[floor_num]);
360 floorcache[floor_num] = NULL;
366 * lputfloor() - same as putfloor() but unlocks the record (if supported)
368 void lputfloor(struct floor *flbuf, int floor_num)
371 putfloor(flbuf, floor_num);
372 end_critical_section(S_FLOORTAB);
378 * Traverse the room file...
380 void ForEachRoom(void (*CallBack) (struct quickroom *EachRoom, void *out_data),
383 struct quickroom qrbuf;
384 struct cdbdata *cdbqr;
386 cdb_rewind(CDB_QUICKROOM);
388 while (cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
389 memset(&qrbuf, 0, sizeof(struct quickroom));
390 memcpy(&qrbuf, cdbqr->ptr,
391 ((cdbqr->len > sizeof(struct quickroom)) ?
392 sizeof(struct quickroom) : cdbqr->len));
394 room_sanity_check(&qrbuf);
395 if (qrbuf.QRflags & QR_INUSE)
396 (*CallBack)(&qrbuf, in_data);
402 * delete_msglist() - delete room message pointers
404 void delete_msglist(struct quickroom *whichroom)
406 struct cdbdata *cdbml;
408 /* Make sure the msglist we're deleting actually exists, otherwise
409 * gdbm will complain when we try to delete an invalid record
411 cdbml = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
415 /* Go ahead and delete it */
416 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
424 * sort message pointers
425 * (returns new msg count)
427 int sort_msglist(long listptrs[], int oldcount)
438 for (a = numitems - 2; a >= 0; --a) {
439 for (b = 0; b <= a; ++b) {
440 if (listptrs[b] > (listptrs[b + 1])) {
442 hold2 = listptrs[b + 1];
444 listptrs[b + 1] = hold1;
449 /* and yank any nulls */
450 while ((numitems > 0) && (listptrs[0] == 0L)) {
451 memcpy(&listptrs[0], &listptrs[1],
452 (sizeof(long) * (numitems - 1)));
461 * Determine whether a given room is non-editable.
463 int is_noneditable(struct quickroom *qrbuf)
466 /* Lobby> and Aide> are non-editable */
467 if (!strcasecmp(qrbuf->QRname, BASEROOM))
469 else if (!strcasecmp(qrbuf->QRname, AIDEROOM))
472 /* Mail> rooms are also non-editable */
473 else if ( (qrbuf->QRflags & QR_MAILBOX)
474 && (!strcasecmp(&qrbuf->QRname[11], MAILROOM)) )
477 /* Everything else is editable */
485 * Back-back-end for all room listing commands
487 void list_roomname(struct quickroom *qrbuf)
489 char truncated_roomname[ROOMNAMELEN];
491 /* For my own mailbox rooms, chop off the owner prefix */
492 if ( (qrbuf->QRflags & QR_MAILBOX)
493 && (atol(qrbuf->QRname) == CC->usersupp.usernum) ) {
494 strcpy(truncated_roomname, qrbuf->QRname);
495 strcpy(truncated_roomname, &truncated_roomname[11]);
496 cprintf("%s", truncated_roomname);
498 /* For all other rooms, just display the name in its entirety */
500 cprintf("%s", qrbuf->QRname);
503 /* ...and now the other parameters */
504 cprintf("|%u|%d|%d\n",
506 (int) qrbuf->QRfloor,
507 (int) qrbuf->QRorder);
512 * cmd_lrms() - List all accessible rooms, known or forgotten
514 void cmd_lrms_backend(struct quickroom *qrbuf, void *data)
516 int FloorBeingSearched = (-1);
517 FloorBeingSearched = *(int *)data;
519 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
520 & (UA_KNOWN | UA_ZAPPED)))
521 && ((qrbuf->QRfloor == (FloorBeingSearched))
522 || ((FloorBeingSearched) < 0)))
523 list_roomname(qrbuf);
526 void cmd_lrms(char *argbuf)
528 int FloorBeingSearched = (-1);
529 if (strlen(argbuf) > 0)
530 FloorBeingSearched = extract_int(argbuf, 0);
532 if (CtdlAccessCheck(ac_logged_in)) return;
534 if (getuser(&CC->usersupp, CC->curr_user)) {
535 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
538 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
540 ForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
547 * cmd_lkra() - List all known rooms
549 void cmd_lkra_backend(struct quickroom *qrbuf, void *data)
551 int FloorBeingSearched = (-1);
552 FloorBeingSearched = *(int *)data;
554 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
556 && ((qrbuf->QRfloor == (FloorBeingSearched))
557 || ((FloorBeingSearched) < 0)))
558 list_roomname(qrbuf);
561 void cmd_lkra(char *argbuf)
563 int FloorBeingSearched = (-1);
564 if (strlen(argbuf) > 0)
565 FloorBeingSearched = extract_int(argbuf, 0);
567 if (CtdlAccessCheck(ac_logged_in)) return;
569 if (getuser(&CC->usersupp, CC->curr_user)) {
570 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
573 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
575 ForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
582 * cmd_lkrn() - List all known rooms with new messages
584 void cmd_lkrn_backend(struct quickroom *qrbuf, void *data)
587 int FloorBeingSearched = (-1);
588 FloorBeingSearched = *(int *)data;
590 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
592 && (ra & UA_HASNEWMSGS)
593 && ((qrbuf->QRfloor == (FloorBeingSearched))
594 || ((FloorBeingSearched) < 0)))
595 list_roomname(qrbuf);
598 void cmd_lkrn(char *argbuf)
600 int FloorBeingSearched = (-1);
601 if (strlen(argbuf) > 0)
602 FloorBeingSearched = extract_int(argbuf, 0);
604 if (CtdlAccessCheck(ac_logged_in)) return;
606 if (getuser(&CC->usersupp, CC->curr_user)) {
607 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
610 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
612 ForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
619 * cmd_lkro() - List all known rooms
621 void cmd_lkro_backend(struct quickroom *qrbuf, void *data)
624 int FloorBeingSearched = (-1);
625 FloorBeingSearched = *(int *)data;
627 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
629 && ((ra & UA_HASNEWMSGS) == 0)
630 && ((qrbuf->QRfloor == (FloorBeingSearched))
631 || ((FloorBeingSearched) < 0)))
632 list_roomname(qrbuf);
635 void cmd_lkro(char *argbuf)
637 int FloorBeingSearched = (-1);
638 if (strlen(argbuf) > 0)
639 FloorBeingSearched = extract_int(argbuf, 0);
641 if (CtdlAccessCheck(ac_logged_in)) return;
643 if (getuser(&CC->usersupp, CC->curr_user)) {
644 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
647 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
649 ForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
656 * cmd_lzrm() - List all forgotten rooms
658 void cmd_lzrm_backend(struct quickroom *qrbuf, void *data)
661 int FloorBeingSearched = (-1);
662 FloorBeingSearched = *(int *)data;
664 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
665 if ((ra & UA_GOTOALLOWED)
667 && ((qrbuf->QRfloor == (FloorBeingSearched))
668 || ((FloorBeingSearched) < 0)))
669 list_roomname(qrbuf);
672 void cmd_lzrm(char *argbuf)
674 int FloorBeingSearched = (-1);
675 if (strlen(argbuf) > 0)
676 FloorBeingSearched = extract_int(argbuf, 0);
678 if (CtdlAccessCheck(ac_logged_in)) return;
680 if (getuser(&CC->usersupp, CC->curr_user)) {
681 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
684 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
686 ForEachRoom(cmd_lzrm_backend, &FloorBeingSearched);
692 * Make the specified room the current room for this session. No validation
693 * or access control is done here -- the caller should make sure that the
694 * specified room exists and is ok to access.
696 void usergoto(char *where, int display_result, int *retmsgs, int *retnew)
699 int new_messages = 0;
700 int total_messages = 0;
704 int newmailcount = 0;
706 char truncated_roomname[ROOMNAMELEN];
707 struct cdbdata *cdbfr;
708 long *msglist = NULL;
711 /* If the supplied room name is NULL, the caller wants us to know that
712 * it has already copied the quickroom record into CC->quickroom, so
713 * we can skip the extra database fetch.
716 strcpy(CC->quickroom.QRname, where);
717 getroom(&CC->quickroom, where);
720 /* Take care of all the formalities. */
722 begin_critical_section(S_USERSUPP);
723 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
725 /* Know the room ... but not if it's the page log room */
726 if (strcasecmp(CC->quickroom.QRname, config.c_logpages)) {
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];
810 if (CtdlAccessCheck(ac_logged_in)) return;
812 extract(towhere, gargs, 0);
813 extract(password, gargs, 1);
815 getuser(&CC->usersupp, CC->curr_user);
817 if (!strcasecmp(towhere, "_BASEROOM_"))
818 strcpy(towhere, BASEROOM);
820 if (!strcasecmp(towhere, "_MAIL_"))
821 strcpy(towhere, MAILROOM);
823 if (!strcasecmp(towhere, "_BITBUCKET_"))
824 strcpy(towhere, config.c_twitroom);
827 /* First try a regular match */
828 c = getroom(&QRscratch, towhere);
830 /* Then try a mailbox name match */
832 MailboxName(augmented_roomname, sizeof augmented_roomname,
833 &CC->usersupp, towhere);
834 c = getroom(&QRscratch, augmented_roomname);
836 strcpy(towhere, augmented_roomname);
839 /* And if the room was found... */
842 /* Let internal programs go directly to any room. */
843 if (CC->internal_pgm) {
844 memcpy(&CC->quickroom, &QRscratch,
845 sizeof(struct quickroom));
846 usergoto(NULL, 1, NULL, NULL);
850 /* See if there is an existing user/room relationship */
851 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
853 /* normal clients have to pass through security */
854 if (ra & UA_GOTOALLOWED) {
859 if ((QRscratch.QRflags & QR_MAILBOX) &&
860 ((ra & UA_GOTOALLOWED))) {
861 memcpy(&CC->quickroom, &QRscratch,
862 sizeof(struct quickroom));
863 usergoto(NULL, 1, NULL, NULL);
865 } else if ((QRscratch.QRflags & QR_PASSWORDED) &&
866 ((ra & UA_KNOWN) == 0) &&
867 (strcasecmp(QRscratch.QRpasswd, password)) &&
868 (CC->usersupp.axlevel < 6)
870 cprintf("%d wrong or missing passwd\n",
871 ERROR + PASSWORD_REQUIRED);
873 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
874 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
875 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
876 ((ra & UA_KNOWN) == 0) &&
877 (CC->usersupp.axlevel < 6)
879 lprintf(9, "Failed to acquire private room\n");
882 memcpy(&CC->quickroom, &QRscratch,
883 sizeof(struct quickroom));
884 usergoto(NULL, 1, NULL, NULL);
890 NOPE: cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
896 struct usersupp temp;
897 struct cdbdata *cdbus;
899 getuser(&CC->usersupp, CC->curr_user);
902 * This command is only allowed by aides, room aides,
903 * and room namespace owners
906 || (atol(CC->quickroom.QRname) == CC->usersupp.usernum) ) {
911 cprintf("%d Higher access or room ownership required.\n",
912 ERROR + HIGHER_ACCESS_REQUIRED);
916 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
917 cdb_rewind(CDB_USERSUPP);
918 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
919 memset(&temp, 0, sizeof temp);
920 memcpy(&temp, cdbus->ptr, sizeof temp);
923 if ((CC->quickroom.QRflags & QR_INUSE)
924 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
926 cprintf("%s\n", temp.fullname);
933 * RDIR command for room directory
943 if (CtdlAccessCheck(ac_logged_in)) return;
945 getroom(&CC->quickroom, CC->quickroom.QRname);
946 getuser(&CC->usersupp, CC->curr_user);
948 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
949 cprintf("%d not here.\n", ERROR + NOT_HERE);
952 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
953 && (CC->usersupp.axlevel < 6)
954 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
955 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
958 cprintf("%d %s|%s/files/%s\n",
959 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->quickroom.QRdirname);
961 snprintf(buf, sizeof buf, "ls %s/files/%s >%s 2> /dev/null",
962 BBSDIR, CC->quickroom.QRdirname, CC->temp);
965 snprintf(buf, sizeof buf, "%s/files/%s/filedir", BBSDIR, CC->quickroom.QRdirname);
966 fd = fopen(buf, "r");
968 fd = fopen("/dev/null", "r");
970 ls = fopen(CC->temp, "r");
971 while (fgets(flnm, sizeof flnm, ls) != NULL) {
972 flnm[strlen(flnm) - 1] = 0;
973 if (strcasecmp(flnm, "filedir")) {
974 snprintf(buf, sizeof buf, "%s/files/%s/%s",
975 BBSDIR, CC->quickroom.QRdirname, flnm);
979 while ((fgets(buf, sizeof buf, fd) != NULL)
980 && (strlen(comment) == 0)) {
981 buf[strlen(buf) - 1] = 0;
982 if ((!strncasecmp(buf, flnm, strlen(flnm)))
983 && (buf[strlen(flnm)] == ' '))
985 &buf[strlen(flnm) + 1],
988 cprintf("%s|%ld|%s\n", flnm, (long)statbuf.st_size, comment);
999 * get room parameters (aide or room aide command)
1003 if (CtdlAccessCheck(ac_room_aide)) return;
1005 getroom(&CC->quickroom, CC->quickroom.QRname);
1006 cprintf("%d%c%s|%s|%s|%d|%d|%d|%d\n",
1010 ((CC->quickroom.QRflags & QR_MAILBOX) ?
1011 &CC->quickroom.QRname[11] : CC->quickroom.QRname),
1013 ((CC->quickroom.QRflags & QR_PASSWORDED) ?
1014 CC->quickroom.QRpasswd : ""),
1016 ((CC->quickroom.QRflags & QR_DIRECTORY) ?
1017 CC->quickroom.QRdirname : ""),
1019 CC->quickroom.QRflags,
1020 (int) CC->quickroom.QRfloor,
1021 (int) CC->quickroom.QRorder,
1023 CC->quickroom.QRdefaultview);
1028 * Back end function to rename a room.
1029 * You can also specify which floor to move the room to, or specify -1 to
1030 * keep the room on the same floor it was on.
1032 * If you are renaming a mailbox room, you must supply the namespace prefix
1033 * in *at least* the old name!
1035 int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) {
1037 struct quickroom qrbuf;
1038 struct quickroom qrtmp;
1044 lprintf(9, "CtdlRenameRoom(%s, %s, %d)\n",
1045 old_name, new_name, new_floor);
1047 if (new_floor >= 0) {
1048 fl = cgetfloor(new_floor);
1049 if ((fl->f_flags & F_INUSE) == 0) {
1050 return(crr_invalid_floor);
1054 begin_critical_section(S_QUICKROOM);
1056 if ( (getroom(&qrtmp, new_name) == 0)
1057 && (strcasecmp(new_name, old_name)) ) {
1058 ret = crr_already_exists;
1061 else if (getroom(&qrbuf, old_name) != 0) {
1062 ret = crr_room_not_found;
1065 else if ( (CC->usersupp.axlevel < 6)
1066 && (CC->usersupp.usernum != qrbuf.QRroomaide)
1067 && ( (((qrbuf.QRflags & QR_MAILBOX) == 0) || (atol(qrbuf.QRname) != CC->usersupp.usernum))) ) {
1068 ret = crr_access_denied;
1071 else if (is_noneditable(&qrbuf)) {
1072 ret = crr_noneditable;
1077 if (qrbuf.QRflags & QR_MAILBOX) {
1078 owner = atol(qrbuf.QRname);
1080 if ( (owner > 0L) && (atol(new_name) == 0L) ) {
1081 snprintf(qrbuf.QRname, sizeof(qrbuf.QRname),
1082 "%010ld.%s", owner, new_name);
1085 safestrncpy(qrbuf.QRname, new_name,
1086 sizeof(qrbuf.QRname));
1089 /* Take care of floor stuff */
1090 old_floor = qrbuf.QRfloor;
1091 if (new_floor < 0) {
1092 new_floor = old_floor;
1094 qrbuf.QRfloor = new_floor;
1097 /* If the room name changed, then there are now two room
1098 * records, so we have to delete the old one.
1100 if (strcasecmp(new_name, old_name)) {
1101 b_deleteroom(old_name);
1107 end_critical_section(S_QUICKROOM);
1109 /* Adjust the floor reference counts if necessary */
1110 if (new_floor != old_floor) {
1111 lgetfloor(&flbuf, old_floor);
1112 --flbuf.f_ref_count;
1113 lputfloor(&flbuf, old_floor);
1114 lgetfloor(&flbuf, CC->quickroom.QRfloor);
1115 ++flbuf.f_ref_count;
1116 lputfloor(&flbuf, CC->quickroom.QRfloor);
1119 /* ...and everybody say "YATTA!" */
1125 * set room parameters (aide or room aide command)
1127 void cmd_setr(char *args)
1133 char new_name[ROOMNAMELEN];
1135 if (CtdlAccessCheck(ac_logged_in)) return;
1137 if (num_parms(args) >= 6) {
1138 new_floor = extract_int(args, 5);
1141 new_floor = (-1); /* don't change the floor */
1144 /* When is a new name more than just a new name? When the old name
1145 * has a namespace prefix.
1147 if (CC->quickroom.QRflags & QR_MAILBOX) {
1148 sprintf(new_name, "%010ld.", atol(CC->quickroom.QRname) );
1151 strcpy(new_name, "");
1153 extract(&new_name[strlen(new_name)], args, 0);
1155 r = CtdlRenameRoom(CC->quickroom.QRname, new_name, new_floor);
1157 if (r == crr_room_not_found) {
1158 cprintf("%d Internal error - room not found?\n", ERROR);
1160 else if (r == crr_already_exists) {
1161 cprintf("%d '%s' already exists.\n",
1162 ERROR + ALREADY_EXISTS, new_name);
1164 else if (r == crr_noneditable) {
1165 cprintf("%d Cannot edit this room.\n", ERROR);
1167 else if (r == crr_invalid_floor) {
1168 cprintf("%d Target floor does not exist.\n",
1169 ERROR + INVALID_FLOOR_OPERATION);
1171 else if (r == crr_access_denied) {
1172 cprintf("%d You do not have permission to edit '%s'\n",
1173 ERROR + HIGHER_ACCESS_REQUIRED,
1174 CC->quickroom.QRname);
1176 else if (r != crr_ok) {
1177 cprintf("%d Error: CtdlRenameRoom() returned %d\n",
1185 getroom(&CC->quickroom, new_name);
1187 /* Now we have to do a bunch of other stuff */
1189 if (num_parms(args) >= 7) {
1190 new_order = extract_int(args, 6);
1193 if (new_order > 127)
1196 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1198 extract(buf, args, 1);
1200 safestrncpy(CC->quickroom.QRpasswd, buf, sizeof CC->quickroom.QRpasswd);
1201 extract(buf, args, 2);
1203 safestrncpy(CC->quickroom.QRdirname, buf,
1204 sizeof CC->quickroom.QRdirname);
1205 CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
1206 if (num_parms(args) >= 7)
1207 CC->quickroom.QRorder = (char) new_order;
1209 /* Clean up a client boo-boo: if the client set the room to
1210 * guess-name or passworded, ensure that the private flag is
1213 if ((CC->quickroom.QRflags & QR_GUESSNAME)
1214 || (CC->quickroom.QRflags & QR_PASSWORDED))
1215 CC->quickroom.QRflags |= QR_PRIVATE;
1217 /* Kick everyone out if the client requested it (by changing the
1218 * room's generation number)
1220 if (extract_int(args, 4)) {
1221 time(&CC->quickroom.QRgen);
1224 if (num_parms(args) >= 8) {
1225 CC->quickroom.QRdefaultview = extract_int(args, 7);
1229 /* Write the room record back to disk */
1230 lputroom(&CC->quickroom);
1232 /* create a room directory if necessary */
1233 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1234 snprintf(buf, sizeof buf,
1235 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1236 CC->quickroom.QRdirname);
1239 snprintf(buf, sizeof buf, "%s> edited by %s\n", CC->quickroom.QRname, CC->curr_user);
1241 cprintf("%d Ok\n", CIT_OK);
1247 * get the name of the room aide for this room
1251 struct usersupp usbuf;
1253 if (CtdlAccessCheck(ac_logged_in)) return;
1255 if (is_noneditable(&CC->quickroom)) {
1256 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1259 if (getuserbynumber(&usbuf, CC->quickroom.QRroomaide) == 0) {
1260 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1262 cprintf("%d \n", CIT_OK);
1268 * set the room aide for this room
1270 void cmd_seta(char *new_ra)
1272 struct usersupp usbuf;
1277 if (CtdlAccessCheck(ac_room_aide)) return;
1279 if (getuser(&usbuf, new_ra) != 0) {
1282 newu = usbuf.usernum;
1285 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1287 if (CC->quickroom.QRroomaide != newu) {
1290 CC->quickroom.QRroomaide = newu;
1291 lputroom(&CC->quickroom);
1294 * We have to post the change notice _after_ writing changes to
1295 * the room table, otherwise it would deadlock!
1297 if (post_notice == 1) {
1298 if (strlen(usbuf.fullname) > 0)
1299 snprintf(buf, sizeof buf,
1300 "%s is now room aide for %s>\n",
1301 usbuf.fullname, CC->quickroom.QRname);
1303 snprintf(buf, sizeof buf,
1304 "There is now no room aide for %s>\n",
1305 CC->quickroom.QRname);
1308 cprintf("%d Ok\n", CIT_OK);
1312 * Generate an associated file name for a room
1314 void assoc_file_name(char *buf, size_t n,
1315 struct quickroom *qrbuf, const char *prefix)
1317 snprintf(buf, n, "./%s/%ld", prefix, qrbuf->QRnumber);
1321 * retrieve info file for this room
1329 assoc_file_name(filename, sizeof filename, &CC->quickroom, "info");
1330 info_fp = fopen(filename, "r");
1332 if (info_fp == NULL) {
1333 cprintf("%d No info file.\n", ERROR);
1336 cprintf("%d Info:\n", LISTING_FOLLOWS);
1337 while (fgets(buf, sizeof buf, info_fp) != NULL) {
1338 if (strlen(buf) > 0)
1339 buf[strlen(buf) - 1] = 0;
1340 cprintf("%s\n", buf);
1347 * Back end processing to delete a room and everything associated with it
1349 void delete_room(struct quickroom *qrbuf)
1354 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1356 /* Delete the info file */
1357 assoc_file_name(filename, sizeof filename, qrbuf, "info");
1360 /* Delete the image file */
1361 assoc_file_name(filename, sizeof filename, qrbuf, "images");
1364 /* Delete the room's network config file */
1365 assoc_file_name(filename, sizeof filename, qrbuf, "netconfigs");
1368 /* Delete the messages in the room
1369 * (Careful: this opens an S_QUICKROOM critical section!)
1371 CtdlDeleteMessages(qrbuf->QRname, 0L, "");
1373 /* Flag the room record as not in use */
1374 lgetroom(qrbuf, qrbuf->QRname);
1378 /* then decrement the reference count for the floor */
1379 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1380 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1381 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1383 /* Delete the room record from the database! */
1384 b_deleteroom(qrbuf->QRname);
1390 * Check access control for deleting a room
1392 int CtdlDoIHavePermissionToDeleteThisRoom(struct quickroom *qr) {
1394 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
1398 if (is_noneditable(qr)) {
1403 * For mailboxes, check stuff
1405 if (qr->QRflags & QR_MAILBOX) {
1407 if (strlen(qr->QRname) < 12) return(0); /* bad name */
1409 if (atol(qr->QRname) != CC->usersupp.usernum) {
1410 return(0); /* not my room */
1413 /* Can't delete your Mail> room */
1414 if (!strcasecmp(&qr->QRname[12], MAILROOM)) return(0);
1416 /* Otherwise it's ok */
1421 * For normal rooms, just check for aide or room aide status.
1424 return(is_room_aide());
1427 /* Should never get to this point, but to keep the compiler quiet... */
1432 * aide command: kill the current room
1434 void cmd_kill(char *argbuf)
1437 char deleted_room_name[ROOMNAMELEN];
1440 kill_ok = extract_int(argbuf, 0);
1442 if (CtdlDoIHavePermissionToDeleteThisRoom(&CC->quickroom) == 0) {
1443 cprintf("%d Can't delete this room.\n", ERROR + NOT_HERE);
1447 strcpy(deleted_room_name, CC->quickroom.QRname);
1448 delete_room(&CC->quickroom); /* Do the dirty work */
1449 usergoto(BASEROOM, 0, NULL, NULL); /* Return to the Lobby */
1451 /* tell the world what we did */
1452 snprintf(aaa, sizeof aaa, "%s> killed by %s\n",
1453 deleted_room_name, CC->curr_user);
1455 cprintf("%d '%s' deleted.\n", CIT_OK, deleted_room_name);
1457 cprintf("%d ok to delete.\n", CIT_OK);
1463 * Internal code to create a new room (returns room flags)
1465 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only,
1466 * 4=mailbox, 5=mailbox, but caller supplies namespace
1468 unsigned create_room(char *new_room_name,
1470 char *new_room_pass,
1476 struct quickroom qrbuf;
1480 lprintf(9, "create_room(%s)\n", new_room_name);
1481 if (getroom(&qrbuf, new_room_name) == 0) {
1482 lprintf(9, "%s already exists.\n", new_room_name);
1483 return (0); /* already exists */
1487 memset(&qrbuf, 0, sizeof(struct quickroom));
1488 safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
1489 qrbuf.QRflags = QR_INUSE;
1490 if (new_room_type > 0)
1491 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1492 if (new_room_type == 1)
1493 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1494 if (new_room_type == 2)
1495 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1496 if ( (new_room_type == 4) || (new_room_type == 5) )
1497 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1499 /* If the user is requesting a personal room, set up the room
1500 * name accordingly (prepend the user number)
1502 if (new_room_type == 4) {
1503 MailboxName(qrbuf.QRname, sizeof qrbuf.QRname, &CC->usersupp, new_room_name);
1506 safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
1509 /* If the room is private, and the system administrator has elected
1510 * to automatically grant room aide privileges, do so now; otherwise,
1511 * set the room aide to undefined.
1513 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1514 qrbuf.QRroomaide = CC->usersupp.usernum;
1516 qrbuf.QRroomaide = (-1L);
1520 * If the caller is only interested in testing whether this will work,
1521 * return now without creating the room.
1523 if (!really_create) return (qrbuf.QRflags);
1525 qrbuf.QRnumber = get_new_room_number();
1526 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1527 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1528 qrbuf.QRfloor = new_room_floor;
1530 /* save what we just did... */
1533 /* bump the reference count on whatever floor the room is on */
1534 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1535 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1536 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1538 /* Grant the creator access to the room unless the avoid_access
1539 * parameter was specified.
1541 if (avoid_access == 0) {
1542 lgetuser(&CC->usersupp, CC->curr_user);
1543 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1544 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1545 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1546 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1547 lputuser(&CC->usersupp);
1550 /* resume our happy day */
1551 return (qrbuf.QRflags);
1558 void cmd_cre8(char *args)
1561 char new_room_name[SIZ];
1563 char new_room_pass[SIZ];
1569 cre8_ok = extract_int(args, 0);
1570 extract(new_room_name, args, 1);
1571 new_room_name[ROOMNAMELEN - 1] = 0;
1572 new_room_type = extract_int(args, 2);
1573 extract(new_room_pass, args, 3);
1574 new_room_pass[9] = 0;
1577 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1578 cprintf("%d Invalid room name.\n", ERROR);
1582 if (!strcasecmp(new_room_name, MAILROOM)) {
1583 cprintf("%d '%s' already exists.\n",
1584 ERROR + ALREADY_EXISTS, new_room_name);
1588 if (num_parms(args) >= 5) {
1589 fl = cgetfloor(extract_int(args, 4));
1590 if ((fl->f_flags & F_INUSE) == 0) {
1591 cprintf("%d Invalid floor number.\n",
1592 ERROR + INVALID_FLOOR_OPERATION);
1595 new_room_floor = extract_int(args, 4);
1599 if (CtdlAccessCheck(ac_logged_in)) return;
1601 if (CC->usersupp.axlevel < config.c_createax) {
1602 cprintf("%d You need higher access to create rooms.\n",
1603 ERROR + HIGHER_ACCESS_REQUIRED);
1607 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1608 cprintf("%d Ok to create rooms.\n", CIT_OK);
1612 if ((new_room_type < 0) || (new_room_type > 4)) {
1613 cprintf("%d Invalid room type.\n", ERROR);
1617 /* Check to make sure the requested room name doesn't already exist */
1618 newflags = create_room(new_room_name,
1619 new_room_type, new_room_pass, new_room_floor, 0, 0);
1620 if (newflags == 0) {
1621 cprintf("%d '%s' already exists.\n",
1622 ERROR + ALREADY_EXISTS, new_room_name);
1627 cprintf("%d OK to create '%s'\n", CIT_OK, new_room_name);
1631 /* If we reach this point, the room needs to be created. */
1633 newflags = create_room(new_room_name,
1634 new_room_type, new_room_pass, new_room_floor, 1, 0);
1636 /* post a message in Aide> describing the new room */
1637 safestrncpy(aaa, new_room_name, sizeof aaa);
1638 strcat(aaa, "> created by ");
1639 strcat(aaa, CC->usersupp.fullname);
1640 if (newflags & QR_MAILBOX)
1641 strcat(aaa, " [personal]");
1642 else if (newflags & QR_PRIVATE)
1643 strcat(aaa, " [private]");
1644 if (newflags & QR_GUESSNAME)
1645 strcat(aaa, "[guessname] ");
1646 if (newflags & QR_PASSWORDED) {
1647 strcat(aaa, "\n Password: ");
1648 strcat(aaa, new_room_pass);
1653 cprintf("%d '%s' has been created.\n", CIT_OK, new_room_name);
1658 void cmd_einf(char *ok)
1659 { /* enter info file for current room */
1661 char infofilename[SIZ];
1664 if (CtdlAccessCheck(ac_room_aide)) return;
1666 if (atoi(ok) == 0) {
1667 cprintf("%d Ok.\n", CIT_OK);
1670 assoc_file_name(infofilename, sizeof infofilename, &CC->quickroom, "info");
1671 lprintf(9, "opening\n");
1672 fp = fopen(infofilename, "w");
1673 lprintf(9, "checking\n");
1675 cprintf("%d Cannot open %s: %s\n",
1676 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1679 cprintf("%d Send info...\n", SEND_LISTING);
1683 if (strcmp(buf, "000"))
1684 fprintf(fp, "%s\n", buf);
1685 } while (strcmp(buf, "000"));
1688 /* now update the room index so people will see our new info */
1689 lgetroom(&CC->quickroom, CC->quickroom.QRname); /* lock so no one steps on us */
1690 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1691 lputroom(&CC->quickroom);
1696 * cmd_lflr() - List all known floors
1703 if (CtdlAccessCheck(ac_logged_in)) return;
1705 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1707 for (a = 0; a < MAXFLOORS; ++a) {
1708 getfloor(&flbuf, a);
1709 if (flbuf.f_flags & F_INUSE) {
1710 cprintf("%d|%s|%d\n",
1722 * create a new floor
1724 void cmd_cflr(char *argbuf)
1726 char new_floor_name[SIZ];
1729 int free_slot = (-1);
1732 extract(new_floor_name, argbuf, 0);
1733 cflr_ok = extract_int(argbuf, 1);
1736 if (CtdlAccessCheck(ac_aide)) return;
1738 for (a = 0; a < MAXFLOORS; ++a) {
1739 getfloor(&flbuf, a);
1741 /* note any free slots while we're scanning... */
1742 if (((flbuf.f_flags & F_INUSE) == 0)
1746 /* check to see if it already exists */
1747 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1748 && (flbuf.f_flags & F_INUSE)) {
1749 cprintf("%d Floor '%s' already exists.\n",
1750 ERROR + ALREADY_EXISTS,
1756 if (free_slot < 0) {
1757 cprintf("%d There is no space available for a new floor.\n",
1758 ERROR + INVALID_FLOOR_OPERATION);
1762 cprintf("%d ok to create...\n", CIT_OK);
1765 lgetfloor(&flbuf, free_slot);
1766 flbuf.f_flags = F_INUSE;
1767 flbuf.f_ref_count = 0;
1768 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1769 lputfloor(&flbuf, free_slot);
1770 cprintf("%d %d\n", CIT_OK, free_slot);
1778 void cmd_kflr(char *argbuf)
1781 int floor_to_delete;
1785 floor_to_delete = extract_int(argbuf, 0);
1786 kflr_ok = extract_int(argbuf, 1);
1788 if (CtdlAccessCheck(ac_aide)) return;
1790 lgetfloor(&flbuf, floor_to_delete);
1793 if ((flbuf.f_flags & F_INUSE) == 0) {
1794 cprintf("%d Floor %d not in use.\n",
1795 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1798 if (flbuf.f_ref_count != 0) {
1799 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1800 ERROR + INVALID_FLOOR_OPERATION,
1805 cprintf("%d Ok\n", CIT_OK);
1807 cprintf("%d Ok to delete...\n", CIT_OK);
1814 if ((delete_ok == 1) && (kflr_ok == 1))
1816 lputfloor(&flbuf, floor_to_delete);
1822 void cmd_eflr(char *argbuf)
1828 np = num_parms(argbuf);
1830 cprintf("%d Usage error.\n", ERROR);
1834 if (CtdlAccessCheck(ac_aide)) return;
1836 floor_num = extract_int(argbuf, 0);
1837 lgetfloor(&flbuf, floor_num);
1838 if ((flbuf.f_flags & F_INUSE) == 0) {
1839 lputfloor(&flbuf, floor_num);
1840 cprintf("%d Floor %d is not in use.\n",
1841 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1845 extract(flbuf.f_name, argbuf, 1);
1846 lputfloor(&flbuf, floor_num);
1848 cprintf("%d Ok\n", CIT_OK);