4 * Server functions which perform operations on room objects.
20 #if TIME_WITH_SYS_TIME
21 # include <sys/time.h>
25 # include <sys/time.h>
35 #include "serv_extensions.h"
39 #include "sysdep_decls.h"
43 #include "citserver.h"
47 struct floor *floorcache[MAXFLOORS];
50 * Generic routine for determining user access to rooms
52 int CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf)
57 /* for internal programs, always do everything */
58 if (((CC->internal_pgm)) && (roombuf->QRflags & QR_INUSE)) {
59 return (UA_KNOWN | UA_GOTOALLOWED);
62 /* Locate any applicable user/room relationships */
63 CtdlGetRelationship(&vbuf, userbuf, roombuf);
65 /* Force the properties of the Aide room */
66 if (!strcasecmp(roombuf->QRname, config.c_aideroom)) {
67 if (userbuf->axlevel >= 6) {
68 retval = UA_KNOWN | UA_GOTOALLOWED;
75 /* If this is a public room, it's accessible... */
76 if ( ((roombuf->QRflags & QR_PRIVATE) == 0)
77 && ((roombuf->QRflags & QR_MAILBOX) == 0) ) {
78 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
81 /* If this is a preferred users only room, check access level */
82 if (roombuf->QRflags & QR_PREFONLY) {
83 if (userbuf->axlevel < 5) {
84 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
88 /* For private rooms, check the generation number matchups */
89 if ( (roombuf->QRflags & QR_PRIVATE)
90 && ((roombuf->QRflags & QR_MAILBOX) == 0) ) {
92 /* An explicit match means the user belongs in this room */
93 if (vbuf.v_flags & V_ACCESS) {
94 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
96 /* Otherwise, check if this is a guess-name or passworded
97 * room. If it is, a goto may at least be attempted
99 else if ((roombuf->QRflags & QR_PRIVATE)
100 || (roombuf->QRflags & QR_PASSWORDED)) {
101 retval = retval & ~UA_KNOWN;
102 retval = retval | UA_GOTOALLOWED;
106 /* For mailbox rooms, also check the generation number matchups */
107 if (roombuf->QRflags & QR_MAILBOX) {
108 if (userbuf->usernum == atol(roombuf->QRname)) {
109 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
111 /* An explicit match means the user belongs in this room */
112 if (vbuf.v_flags & V_ACCESS) {
113 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
117 /* Check to see if the user has forgotten this room */
118 if (vbuf.v_flags & V_FORGET) {
119 retval = retval & ~UA_KNOWN;
120 if ( ( ((roombuf->QRflags & QR_PRIVATE) == 0)
121 && ((roombuf->QRflags & QR_MAILBOX) == 0) )
122 || ( (roombuf->QRflags & QR_MAILBOX)
123 && (atol(roombuf->QRname) == CC->user.usernum))) {
124 retval = retval | UA_ZAPPED;
127 /* If user is explicitly locked out of this room, deny everything */
128 if (vbuf.v_flags & V_LOCKOUT) {
129 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
132 /* Aides get access to all private rooms */
133 if ( (userbuf->axlevel >= 6)
134 && ((roombuf->QRflags & QR_MAILBOX) == 0) ) {
135 if (vbuf.v_flags & V_FORGET) {
136 retval = retval | UA_GOTOALLOWED;
139 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
143 /* On some systems, Aides can gain access to mailboxes as well */
144 if ( (config.c_aide_mailboxes)
145 && (userbuf->axlevel >= 6)
146 && (roombuf->QRflags & QR_MAILBOX) ) {
147 retval = retval | UA_GOTOALLOWED;
150 NEWMSG: /* By the way, we also check for the presence of new messages */
151 if (is_msg_in_mset(vbuf.v_seen, roombuf->QRhighest) == 0) {
152 retval = retval | UA_HASNEWMSGS;
155 /* System rooms never show up in the list. */
156 if (roombuf->QRflags2 & QR2_SYSTEM) {
157 retval = retval & ~UA_KNOWN;
163 * Self-checking stuff for a room record read into memory
165 void room_sanity_check(struct ctdlroom *qrbuf)
167 /* Mailbox rooms are always on the lowest floor */
168 if (qrbuf->QRflags & QR_MAILBOX) {
171 /* Listing order of 0 is illegal except for base rooms */
172 if (qrbuf->QRorder == 0)
173 if (!(qrbuf->QRflags & QR_MAILBOX) &&
174 strncasecmp(qrbuf->QRname, config.c_baseroom, ROOMNAMELEN)
176 strncasecmp(qrbuf->QRname, config.c_aideroom, ROOMNAMELEN))
182 * getroom() - retrieve room data from disk
184 int getroom(struct ctdlroom *qrbuf, char *room_name)
186 struct cdbdata *cdbqr;
187 char lowercase_name[ROOMNAMELEN];
188 char personal_lowercase_name[ROOMNAMELEN];
191 for (a = 0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
192 lowercase_name[a] = tolower(room_name[a]);
194 lowercase_name[a] = 0;
196 memset(qrbuf, 0, sizeof(struct ctdlroom));
198 /* First, try the public namespace */
199 cdbqr = cdb_fetch(CDB_ROOMS,
200 lowercase_name, strlen(lowercase_name));
202 /* If that didn't work, try the user's personal namespace */
204 snprintf(personal_lowercase_name,
205 sizeof personal_lowercase_name, "%010ld.%s",
206 CC->user.usernum, lowercase_name);
207 cdbqr = cdb_fetch(CDB_ROOMS,
208 personal_lowercase_name,
209 strlen(personal_lowercase_name));
212 memcpy(qrbuf, cdbqr->ptr,
213 ((cdbqr->len > sizeof(struct ctdlroom)) ?
214 sizeof(struct ctdlroom) : cdbqr->len));
217 room_sanity_check(qrbuf);
226 * lgetroom() - same as getroom() but locks the record (if supported)
228 int lgetroom(struct ctdlroom *qrbuf, char *room_name)
231 retval = getroom(qrbuf, room_name);
232 if (retval == 0) begin_critical_section(S_ROOMS);
238 * b_putroom() - back end to putroom() and b_deleteroom()
239 * (if the supplied buffer is NULL, delete the room record)
241 void b_putroom(struct ctdlroom *qrbuf, char *room_name)
243 char lowercase_name[ROOMNAMELEN];
246 for (a = 0; a <= strlen(room_name); ++a) {
247 lowercase_name[a] = tolower(room_name[a]);
251 cdb_delete(CDB_ROOMS,
252 lowercase_name, strlen(lowercase_name));
254 time(&qrbuf->QRmtime);
256 lowercase_name, strlen(lowercase_name),
257 qrbuf, sizeof(struct ctdlroom));
263 * putroom() - store room data to disk
265 void putroom(struct ctdlroom *qrbuf) {
266 b_putroom(qrbuf, qrbuf->QRname);
271 * b_deleteroom() - delete a room record from disk
273 void b_deleteroom(char *room_name) {
274 b_putroom(NULL, room_name);
280 * lputroom() - same as putroom() but unlocks the record (if supported)
282 void lputroom(struct ctdlroom *qrbuf)
286 end_critical_section(S_ROOMS);
290 /****************************************************************************/
293 * getfloor() - retrieve floor data from disk
295 void getfloor(struct floor *flbuf, int floor_num)
297 struct cdbdata *cdbfl;
299 memset(flbuf, 0, sizeof(struct floor));
300 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
302 memcpy(flbuf, cdbfl->ptr,
303 ((cdbfl->len > sizeof(struct floor)) ?
304 sizeof(struct floor) : cdbfl->len));
307 if (floor_num == 0) {
308 safestrncpy(flbuf->f_name, "Main Floor",
309 sizeof flbuf->f_name);
310 flbuf->f_flags = F_INUSE;
311 flbuf->f_ref_count = 3;
318 * lgetfloor() - same as getfloor() but locks the record (if supported)
320 void lgetfloor(struct floor *flbuf, int floor_num)
323 begin_critical_section(S_FLOORTAB);
324 getfloor(flbuf, floor_num);
329 * cgetfloor() - Get floor record from *cache* (loads from disk if needed)
331 * This is strictly a performance hack.
333 struct floor *cgetfloor(int floor_num) {
334 static int initialized = 0;
337 if (initialized == 0) {
338 for (i=0; i<MAXFLOORS; ++i) {
339 floorcache[floor_num] = NULL;
344 if (floorcache[floor_num] == NULL) {
345 floorcache[floor_num] = mallok(sizeof(struct floor));
346 getfloor(floorcache[floor_num], floor_num);
349 return(floorcache[floor_num]);
355 * putfloor() - store floor data on disk
357 void putfloor(struct floor *flbuf, int floor_num)
359 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
360 flbuf, sizeof(struct floor));
362 /* If we've cached this, clear it out, 'cuz it's WRONG now! */
363 if (floorcache[floor_num] != NULL) {
364 phree(floorcache[floor_num]);
365 floorcache[floor_num] = NULL;
371 * lputfloor() - same as putfloor() but unlocks the record (if supported)
373 void lputfloor(struct floor *flbuf, int floor_num)
376 putfloor(flbuf, floor_num);
377 end_critical_section(S_FLOORTAB);
383 * Traverse the room file...
385 void ForEachRoom(void (*CallBack) (struct ctdlroom *EachRoom, void *out_data),
388 struct ctdlroom qrbuf;
389 struct cdbdata *cdbqr;
391 cdb_rewind(CDB_ROOMS);
393 while (cdbqr = cdb_next_item(CDB_ROOMS), cdbqr != NULL) {
394 memset(&qrbuf, 0, sizeof(struct ctdlroom));
395 memcpy(&qrbuf, cdbqr->ptr,
396 ((cdbqr->len > sizeof(struct ctdlroom)) ?
397 sizeof(struct ctdlroom) : cdbqr->len));
399 room_sanity_check(&qrbuf);
400 if (qrbuf.QRflags & QR_INUSE)
401 (*CallBack)(&qrbuf, in_data);
407 * delete_msglist() - delete room message pointers
409 void delete_msglist(struct ctdlroom *whichroom)
411 struct cdbdata *cdbml;
413 /* Make sure the msglist we're deleting actually exists, otherwise
414 * gdbm will complain when we try to delete an invalid record
416 cdbml = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
420 /* Go ahead and delete it */
421 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
429 * sort message pointers
430 * (returns new msg count)
432 int sort_msglist(long listptrs[], int oldcount)
443 for (a = numitems - 2; a >= 0; --a) {
444 for (b = 0; b <= a; ++b) {
445 if (listptrs[b] > (listptrs[b + 1])) {
447 hold2 = listptrs[b + 1];
449 listptrs[b + 1] = hold1;
454 /* and yank any nulls */
455 while ((numitems > 0) && (listptrs[0] == 0L)) {
456 memcpy(&listptrs[0], &listptrs[1],
457 (sizeof(long) * (numitems - 1)));
466 * Determine whether a given room is non-editable.
468 int is_noneditable(struct ctdlroom *qrbuf)
471 /* Mail> rooms are non-editable */
472 if ( (qrbuf->QRflags & QR_MAILBOX)
473 && (!strcasecmp(&qrbuf->QRname[11], MAILROOM)) )
476 /* Everything else is editable */
483 * Back-back-end for all room listing commands
485 void list_roomname(struct ctdlroom *qrbuf, int ra)
487 char truncated_roomname[ROOMNAMELEN];
489 /* For my own mailbox rooms, chop off the owner prefix */
490 if ( (qrbuf->QRflags & QR_MAILBOX)
491 && (atol(qrbuf->QRname) == CC->user.usernum) ) {
492 strcpy(truncated_roomname, qrbuf->QRname);
493 strcpy(truncated_roomname, &truncated_roomname[11]);
494 cprintf("%s", truncated_roomname);
496 /* For all other rooms, just display the name in its entirety */
498 cprintf("%s", qrbuf->QRname);
501 /* ...and now the other parameters */
502 cprintf("|%u|%d|%d|%d|%d|\n",
504 (int) qrbuf->QRfloor,
505 (int) qrbuf->QRorder,
506 (int) qrbuf->QRflags2,
513 * cmd_lrms() - List all accessible rooms, known or forgotten
515 void cmd_lrms_backend(struct ctdlroom *qrbuf, void *data)
517 int FloorBeingSearched = (-1);
520 FloorBeingSearched = *(int *)data;
521 ra = CtdlRoomAccess(qrbuf, &CC->user);
523 if ((( ra & (UA_KNOWN | UA_ZAPPED)))
524 && ((qrbuf->QRfloor == (FloorBeingSearched))
525 || ((FloorBeingSearched) < 0)))
526 list_roomname(qrbuf, ra);
529 void cmd_lrms(char *argbuf)
531 int FloorBeingSearched = (-1);
532 if (strlen(argbuf) > 0)
533 FloorBeingSearched = extract_int(argbuf, 0);
535 if (CtdlAccessCheck(ac_logged_in)) return;
537 if (getuser(&CC->user, CC->curr_user)) {
538 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
541 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
543 ForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
550 * cmd_lkra() - List all known rooms
552 void cmd_lkra_backend(struct ctdlroom *qrbuf, void *data)
554 int FloorBeingSearched = (-1);
557 FloorBeingSearched = *(int *)data;
558 ra = CtdlRoomAccess(qrbuf, &CC->user);
560 if ((( ra & (UA_KNOWN)))
561 && ((qrbuf->QRfloor == (FloorBeingSearched))
562 || ((FloorBeingSearched) < 0)))
563 list_roomname(qrbuf, ra);
566 void cmd_lkra(char *argbuf)
568 int FloorBeingSearched = (-1);
569 if (strlen(argbuf) > 0)
570 FloorBeingSearched = extract_int(argbuf, 0);
572 if (CtdlAccessCheck(ac_logged_in)) return;
574 if (getuser(&CC->user, CC->curr_user)) {
575 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
578 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
580 ForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
586 void cmd_lprm_backend(struct ctdlroom *qrbuf, void *data)
588 int FloorBeingSearched = (-1);
591 FloorBeingSearched = *(int *)data;
592 ra = CtdlRoomAccess(qrbuf, &CC->user);
594 if ( ((qrbuf->QRflags & QR_PRIVATE) == 0)
595 && ((qrbuf->QRflags & QR_MAILBOX) == 0)
596 && ((qrbuf->QRfloor == (FloorBeingSearched))
597 || ((FloorBeingSearched) < 0)))
598 list_roomname(qrbuf, ra);
601 void cmd_lprm(char *argbuf)
603 int FloorBeingSearched = (-1);
604 if (strlen(argbuf) > 0)
605 FloorBeingSearched = extract_int(argbuf, 0);
607 cprintf("%d Publiic rooms:\n", LISTING_FOLLOWS);
609 ForEachRoom(cmd_lprm_backend, &FloorBeingSearched);
616 * cmd_lkrn() - List all known rooms with new messages
618 void cmd_lkrn_backend(struct ctdlroom *qrbuf, void *data)
620 int FloorBeingSearched = (-1);
623 FloorBeingSearched = *(int *)data;
624 ra = CtdlRoomAccess(qrbuf, &CC->user);
627 && (ra & UA_HASNEWMSGS)
628 && ((qrbuf->QRfloor == (FloorBeingSearched))
629 || ((FloorBeingSearched) < 0)))
630 list_roomname(qrbuf, ra);
633 void cmd_lkrn(char *argbuf)
635 int FloorBeingSearched = (-1);
636 if (strlen(argbuf) > 0)
637 FloorBeingSearched = extract_int(argbuf, 0);
639 if (CtdlAccessCheck(ac_logged_in)) return;
641 if (getuser(&CC->user, CC->curr_user)) {
642 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
645 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
647 ForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
654 * cmd_lkro() - List all known rooms
656 void cmd_lkro_backend(struct ctdlroom *qrbuf, void *data)
658 int FloorBeingSearched = (-1);
661 FloorBeingSearched = *(int *)data;
662 ra = CtdlRoomAccess(qrbuf, &CC->user);
665 && ((ra & UA_HASNEWMSGS) == 0)
666 && ((qrbuf->QRfloor == (FloorBeingSearched))
667 || ((FloorBeingSearched) < 0)))
668 list_roomname(qrbuf, ra);
671 void cmd_lkro(char *argbuf)
673 int FloorBeingSearched = (-1);
674 if (strlen(argbuf) > 0)
675 FloorBeingSearched = extract_int(argbuf, 0);
677 if (CtdlAccessCheck(ac_logged_in)) return;
679 if (getuser(&CC->user, CC->curr_user)) {
680 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
683 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
685 ForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
692 * cmd_lzrm() - List all forgotten rooms
694 void cmd_lzrm_backend(struct ctdlroom *qrbuf, void *data)
696 int FloorBeingSearched = (-1);
699 FloorBeingSearched = *(int *)data;
700 ra = CtdlRoomAccess(qrbuf, &CC->user);
702 if ((ra & UA_GOTOALLOWED)
704 && ((qrbuf->QRfloor == (FloorBeingSearched))
705 || ((FloorBeingSearched) < 0)))
706 list_roomname(qrbuf, ra);
709 void cmd_lzrm(char *argbuf)
711 int FloorBeingSearched = (-1);
712 if (strlen(argbuf) > 0)
713 FloorBeingSearched = extract_int(argbuf, 0);
715 if (CtdlAccessCheck(ac_logged_in)) return;
717 if (getuser(&CC->user, CC->curr_user)) {
718 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
721 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
723 ForEachRoom(cmd_lzrm_backend, &FloorBeingSearched);
729 * Make the specified room the current room for this session. No validation
730 * or access control is done here -- the caller should make sure that the
731 * specified room exists and is ok to access.
733 void usergoto(char *where, int display_result, int transiently,
734 int *retmsgs, int *retnew)
737 int new_messages = 0;
738 int total_messages = 0;
742 int newmailcount = 0;
744 char truncated_roomname[ROOMNAMELEN];
745 struct cdbdata *cdbfr;
746 long *msglist = NULL;
748 unsigned int original_v_flags;
750 /* If the supplied room name is NULL, the caller wants us to know that
751 * it has already copied the room record into CC->room, so
752 * we can skip the extra database fetch.
755 safestrncpy(CC->room.QRname, where, sizeof CC->room.QRname);
756 getroom(&CC->room, where);
759 /* Take care of all the formalities. */
761 begin_critical_section(S_USERS);
762 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
763 original_v_flags = vbuf.v_flags;
765 /* Know the room ... but not if it's the page log room, or if the
766 * caller specified that we're only entering this room transiently.
768 if ((strcasecmp(CC->room.QRname, config.c_logpages))
769 && (transiently == 0) ) {
770 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
771 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
774 /* Only rewrite the database record if we changed something */
775 if (vbuf.v_flags != original_v_flags) {
776 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
778 end_critical_section(S_USERS);
780 /* Check for new mail */
781 newmailcount = NewMailCount();
783 /* set info to 1 if the user needs to read the room's info file */
784 if (CC->room.QRinfo > vbuf.v_lastseen) {
789 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
791 msglist = mallok(cdbfr->len);
792 memcpy(msglist, cdbfr->ptr, cdbfr->len);
793 num_msgs = cdbfr->len / sizeof(long);
797 if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
798 if (msglist[a] > 0L) {
800 if (is_msg_in_mset(vbuf.v_seen, msglist[a]) == 0) {
806 if (msglist != NULL) phree(msglist);
808 if (CC->room.QRflags & QR_MAILBOX)
813 if ((CC->room.QRroomaide == CC->user.usernum)
814 || (CC->user.axlevel >= 6))
819 strcpy(truncated_roomname, CC->room.QRname);
820 if ( (CC->room.QRflags & QR_MAILBOX)
821 && (atol(CC->room.QRname) == CC->user.usernum) ) {
822 strcpy(truncated_roomname, &truncated_roomname[11]);
825 if (retmsgs != NULL) *retmsgs = total_messages;
826 if (retnew != NULL) *retnew = new_messages;
827 lprintf(9, "<%s> %d new of %d total messages\n",
829 new_messages, total_messages
832 if (display_result) {
833 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d|%d|%d|\n",
834 CIT_OK, CtdlCheckExpress(),
839 (int)CC->room.QRflags,
840 (long)CC->room.QRhighest,
841 (long)vbuf.v_lastseen,
845 (int)CC->room.QRfloor,
847 (int)CC->room.QRdefaultview
854 * cmd_goto() - goto a new room
856 void cmd_goto(char *gargs)
858 struct ctdlroom QRscratch;
862 char augmented_roomname[SIZ];
867 if (CtdlAccessCheck(ac_logged_in)) return;
869 extract(towhere, gargs, 0);
870 extract(password, gargs, 1);
871 transiently = extract_int(gargs, 2);
873 getuser(&CC->user, CC->curr_user);
875 if (!strcasecmp(towhere, "_BASEROOM_"))
876 strcpy(towhere, config.c_baseroom);
878 if (!strcasecmp(towhere, "_MAIL_"))
879 strcpy(towhere, MAILROOM);
881 if (!strcasecmp(towhere, "_BITBUCKET_"))
882 strcpy(towhere, config.c_twitroom);
885 /* First try a regular match */
886 c = getroom(&QRscratch, towhere);
888 /* Then try a mailbox name match */
890 MailboxName(augmented_roomname, sizeof augmented_roomname,
892 c = getroom(&QRscratch, augmented_roomname);
894 strcpy(towhere, augmented_roomname);
897 /* And if the room was found... */
900 /* Let internal programs go directly to any room. */
901 if (CC->internal_pgm) {
902 memcpy(&CC->room, &QRscratch,
903 sizeof(struct ctdlroom));
904 usergoto(NULL, 1, transiently, NULL, NULL);
908 /* See if there is an existing user/room relationship */
909 ra = CtdlRoomAccess(&QRscratch, &CC->user);
911 /* normal clients have to pass through security */
912 if (ra & UA_GOTOALLOWED) {
917 if ((QRscratch.QRflags & QR_MAILBOX) &&
918 ((ra & UA_GOTOALLOWED))) {
919 memcpy(&CC->room, &QRscratch,
920 sizeof(struct ctdlroom));
921 usergoto(NULL, 1, transiently, NULL, NULL);
923 } else if ((QRscratch.QRflags & QR_PASSWORDED) &&
924 ((ra & UA_KNOWN) == 0) &&
925 (strcasecmp(QRscratch.QRpasswd, password)) &&
926 (CC->user.axlevel < 6)
928 cprintf("%d wrong or missing passwd\n",
929 ERROR + PASSWORD_REQUIRED);
931 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
932 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
933 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
934 ((ra & UA_KNOWN) == 0) &&
935 (CC->user.axlevel < 6)
937 lprintf(9, "Failed to acquire private room\n");
940 memcpy(&CC->room, &QRscratch,
941 sizeof(struct ctdlroom));
942 usergoto(NULL, 1, transiently, NULL, NULL);
948 NOPE: cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
954 struct ctdluser temp;
955 struct cdbdata *cdbus;
957 getuser(&CC->user, CC->curr_user);
960 * This command is only allowed by aides, room aides,
961 * and room namespace owners
964 || (atol(CC->room.QRname) == CC->user.usernum) ) {
969 cprintf("%d Higher access or room ownership required.\n",
970 ERROR + HIGHER_ACCESS_REQUIRED);
974 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
975 cdb_rewind(CDB_USERS);
976 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
977 memset(&temp, 0, sizeof temp);
978 memcpy(&temp, cdbus->ptr, sizeof temp);
981 if ((CC->room.QRflags & QR_INUSE)
982 && (CtdlRoomAccess(&CC->room, &temp) & UA_KNOWN)
984 cprintf("%s\n", temp.fullname);
991 * RDIR command for room directory
1001 if (CtdlAccessCheck(ac_logged_in)) return;
1003 getroom(&CC->room, CC->room.QRname);
1004 getuser(&CC->user, CC->curr_user);
1006 if ((CC->room.QRflags & QR_DIRECTORY) == 0) {
1007 cprintf("%d not here.\n", ERROR + NOT_HERE);
1010 if (((CC->room.QRflags & QR_VISDIR) == 0)
1011 && (CC->user.axlevel < 6)
1012 && (CC->user.usernum != CC->room.QRroomaide)) {
1013 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
1016 cprintf("%d %s|%s/files/%s\n",
1017 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->room.QRdirname);
1019 snprintf(buf, sizeof buf, "ls %s/files/%s >%s 2> /dev/null",
1020 BBSDIR, CC->room.QRdirname, CC->temp);
1023 snprintf(buf, sizeof buf, "%s/files/%s/filedir", BBSDIR, CC->room.QRdirname);
1024 fd = fopen(buf, "r");
1026 fd = fopen("/dev/null", "r");
1028 ls = fopen(CC->temp, "r");
1029 while (fgets(flnm, sizeof flnm, ls) != NULL) {
1030 flnm[strlen(flnm) - 1] = 0;
1031 if (strcasecmp(flnm, "filedir")) {
1032 snprintf(buf, sizeof buf, "%s/files/%s/%s",
1033 BBSDIR, CC->room.QRdirname, flnm);
1034 stat(buf, &statbuf);
1035 strcpy(comment, "");
1037 while ((fgets(buf, sizeof buf, fd) != NULL)
1038 && (strlen(comment) == 0)) {
1039 buf[strlen(buf) - 1] = 0;
1040 if ((!strncasecmp(buf, flnm, strlen(flnm)))
1041 && (buf[strlen(flnm)] == ' '))
1042 safestrncpy(comment,
1043 &buf[strlen(flnm) + 1],
1046 cprintf("%s|%ld|%s\n", flnm, (long)statbuf.st_size, comment);
1057 * get room parameters (aide or room aide command)
1061 if (CtdlAccessCheck(ac_room_aide)) return;
1063 getroom(&CC->room, CC->room.QRname);
1064 cprintf("%d%c%s|%s|%s|%d|%d|%d|%d|%d|\n",
1068 ((CC->room.QRflags & QR_MAILBOX) ?
1069 &CC->room.QRname[11] : CC->room.QRname),
1071 ((CC->room.QRflags & QR_PASSWORDED) ?
1072 CC->room.QRpasswd : ""),
1074 ((CC->room.QRflags & QR_DIRECTORY) ?
1075 CC->room.QRdirname : ""),
1078 (int) CC->room.QRfloor,
1079 (int) CC->room.QRorder,
1081 CC->room.QRdefaultview,
1088 * Back end function to rename a room.
1089 * You can also specify which floor to move the room to, or specify -1 to
1090 * keep the room on the same floor it was on.
1092 * If you are renaming a mailbox room, you must supply the namespace prefix
1093 * in *at least* the old name!
1095 int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) {
1097 struct ctdlroom qrbuf;
1098 struct ctdlroom qrtmp;
1103 char actual_old_name[SIZ];
1105 lprintf(9, "CtdlRenameRoom(%s, %s, %d)\n",
1106 old_name, new_name, new_floor);
1108 if (new_floor >= 0) {
1109 fl = cgetfloor(new_floor);
1110 if ((fl->f_flags & F_INUSE) == 0) {
1111 return(crr_invalid_floor);
1115 begin_critical_section(S_ROOMS);
1117 if ( (getroom(&qrtmp, new_name) == 0)
1118 && (strcasecmp(new_name, old_name)) ) {
1119 ret = crr_already_exists;
1122 else if (getroom(&qrbuf, old_name) != 0) {
1123 ret = crr_room_not_found;
1126 else if ( (CC->user.axlevel < 6)
1127 && (CC->user.usernum != qrbuf.QRroomaide)
1128 && ( (((qrbuf.QRflags & QR_MAILBOX) == 0) || (atol(qrbuf.QRname) != CC->user.usernum))) ) {
1129 ret = crr_access_denied;
1132 else if (is_noneditable(&qrbuf)) {
1133 ret = crr_noneditable;
1138 strcpy(actual_old_name, qrbuf.QRname);
1139 if (qrbuf.QRflags & QR_MAILBOX) {
1140 owner = atol(qrbuf.QRname);
1142 if ( (owner > 0L) && (atol(new_name) == 0L) ) {
1143 snprintf(qrbuf.QRname, sizeof(qrbuf.QRname),
1144 "%010ld.%s", owner, new_name);
1147 safestrncpy(qrbuf.QRname, new_name,
1148 sizeof(qrbuf.QRname));
1151 /* Reject change of floor for baseroom/aideroom */
1152 if (!strncasecmp(old_name, config.c_baseroom, ROOMNAMELEN) ||
1153 !strncasecmp(old_name, config.c_aideroom, ROOMNAMELEN)) {
1157 /* Take care of floor stuff */
1158 old_floor = qrbuf.QRfloor;
1159 if (new_floor < 0) {
1160 new_floor = old_floor;
1162 qrbuf.QRfloor = new_floor;
1165 begin_critical_section(S_CONFIG);
1167 /* If baseroom/aideroom name changes, update config */
1168 if (!strncasecmp(old_name, config.c_baseroom, ROOMNAMELEN)) {
1169 safestrncpy(config.c_baseroom, new_name, ROOMNAMELEN);
1172 if (!strncasecmp(old_name, config.c_aideroom, ROOMNAMELEN)) {
1173 safestrncpy(config.c_aideroom, new_name, ROOMNAMELEN);
1177 end_critical_section(S_CONFIG);
1179 /* If the room name changed, then there are now two room
1180 * records, so we have to delete the old one.
1182 if (strcasecmp(new_name, old_name)) {
1183 b_deleteroom(actual_old_name);
1189 end_critical_section(S_ROOMS);
1191 /* Adjust the floor reference counts if necessary */
1192 if (new_floor != old_floor) {
1193 lgetfloor(&flbuf, old_floor);
1194 --flbuf.f_ref_count;
1195 lputfloor(&flbuf, old_floor);
1196 lprintf(9, "Reference count for floor %d is now %d\n", old_floor, flbuf.f_ref_count);
1197 lgetfloor(&flbuf, new_floor);
1198 ++flbuf.f_ref_count;
1199 lputfloor(&flbuf, new_floor);
1200 lprintf(9, "Reference count for floor %d is now %d\n", new_floor, flbuf.f_ref_count);
1203 /* ...and everybody say "YATTA!" */
1209 * set room parameters (aide or room aide command)
1211 void cmd_setr(char *args)
1217 char new_name[ROOMNAMELEN];
1219 if (CtdlAccessCheck(ac_logged_in)) return;
1221 if (num_parms(args) >= 6) {
1222 new_floor = extract_int(args, 5);
1224 new_floor = (-1); /* don't change the floor */
1227 /* When is a new name more than just a new name? When the old name
1228 * has a namespace prefix.
1230 if (CC->room.QRflags & QR_MAILBOX) {
1231 sprintf(new_name, "%010ld.", atol(CC->room.QRname) );
1233 strcpy(new_name, "");
1235 extract(&new_name[strlen(new_name)], args, 0);
1237 r = CtdlRenameRoom(CC->room.QRname, new_name, new_floor);
1239 if (r == crr_room_not_found) {
1240 cprintf("%d Internal error - room not found?\n", ERROR);
1241 } else if (r == crr_already_exists) {
1242 cprintf("%d '%s' already exists.\n",
1243 ERROR + ALREADY_EXISTS, new_name);
1244 } else if (r == crr_noneditable) {
1245 cprintf("%d Cannot edit this room.\n", ERROR);
1246 } else if (r == crr_invalid_floor) {
1247 cprintf("%d Target floor does not exist.\n",
1248 ERROR + INVALID_FLOOR_OPERATION);
1249 } else if (r == crr_access_denied) {
1250 cprintf("%d You do not have permission to edit '%s'\n",
1251 ERROR + HIGHER_ACCESS_REQUIRED,
1253 } else if (r != crr_ok) {
1254 cprintf("%d Error: CtdlRenameRoom() returned %d\n",
1262 getroom(&CC->room, new_name);
1264 /* Now we have to do a bunch of other stuff */
1266 if (num_parms(args) >= 7) {
1267 new_order = extract_int(args, 6);
1270 if (new_order > 127)
1274 lgetroom(&CC->room, CC->room.QRname);
1276 /* Directory room */
1277 extract(buf, args, 2);
1279 safestrncpy(CC->room.QRdirname, buf,
1280 sizeof CC->room.QRdirname);
1283 if (num_parms(args) >= 8) {
1284 CC->room.QRdefaultview = extract_int(args, 7);
1287 /* Second set of flags */
1288 if (num_parms(args) >= 9) {
1289 CC->room.QRflags2 = extract_int(args, 8);
1293 CC->room.QRflags = (extract_int(args, 3) | QR_INUSE);
1294 /* Clean up a client boo-boo: if the client set the room to
1295 * guess-name or passworded, ensure that the private flag is
1298 if ((CC->room.QRflags & QR_GUESSNAME)
1299 || (CC->room.QRflags & QR_PASSWORDED))
1300 CC->room.QRflags |= QR_PRIVATE;
1302 /* Some changes can't apply to BASEROOM */
1303 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1305 CC->room.QRorder = 0;
1306 CC->room.QRpasswd[0] = '\0';
1307 CC->room.QRflags &= ~(QR_PRIVATE & QR_PASSWORDED &
1308 QR_GUESSNAME & QR_PREFONLY & QR_MAILBOX);
1309 CC->room.QRflags |= QR_PERMANENT;
1311 /* March order (doesn't apply to AIDEROOM) */
1312 if (num_parms(args) >= 7)
1313 CC->room.QRorder = (char) new_order;
1315 extract(buf, args, 1);
1317 safestrncpy(CC->room.QRpasswd, buf,
1318 sizeof CC->room.QRpasswd);
1319 /* Kick everyone out if the client requested it
1320 * (by changing the room's generation number)
1322 if (extract_int(args, 4)) {
1323 time(&CC->room.QRgen);
1326 /* Some changes can't apply to AIDEROOM */
1327 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1329 CC->room.QRorder = 0;
1330 CC->room.QRflags &= ~QR_MAILBOX;
1331 CC->room.QRflags |= QR_PERMANENT;
1334 /* Write the room record back to disk */
1335 lputroom(&CC->room);
1337 /* Create a room directory if necessary */
1338 if (CC->room.QRflags & QR_DIRECTORY) {
1339 snprintf(buf, sizeof buf, "./files/%s",
1340 CC->room.QRdirname);
1343 snprintf(buf, sizeof buf, "%s> edited by %s\n", CC->room.QRname, CC->curr_user);
1345 cprintf("%d Ok\n", CIT_OK);
1351 * get the name of the room aide for this room
1355 struct ctdluser usbuf;
1357 if (CtdlAccessCheck(ac_logged_in)) return;
1359 if (getuserbynumber(&usbuf, CC->room.QRroomaide) == 0) {
1360 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1362 cprintf("%d \n", CIT_OK);
1368 * set the room aide for this room
1370 void cmd_seta(char *new_ra)
1372 struct ctdluser usbuf;
1377 if (CtdlAccessCheck(ac_room_aide)) return;
1379 if (getuser(&usbuf, new_ra) != 0) {
1382 newu = usbuf.usernum;
1385 lgetroom(&CC->room, CC->room.QRname);
1387 if (CC->room.QRroomaide != newu) {
1390 CC->room.QRroomaide = newu;
1391 lputroom(&CC->room);
1394 * We have to post the change notice _after_ writing changes to
1395 * the room table, otherwise it would deadlock!
1397 if (post_notice == 1) {
1398 if (strlen(usbuf.fullname) > 0)
1399 snprintf(buf, sizeof buf,
1400 "%s is now room aide for %s>\n",
1401 usbuf.fullname, CC->room.QRname);
1403 snprintf(buf, sizeof buf,
1404 "There is now no room aide for %s>\n",
1408 cprintf("%d Ok\n", CIT_OK);
1412 * Generate an associated file name for a room
1414 void assoc_file_name(char *buf, size_t n,
1415 struct ctdlroom *qrbuf, const char *prefix)
1417 snprintf(buf, n, "./%s/%ld", prefix, qrbuf->QRnumber);
1421 * retrieve info file for this room
1429 assoc_file_name(filename, sizeof filename, &CC->room, "info");
1430 info_fp = fopen(filename, "r");
1432 if (info_fp == NULL) {
1433 cprintf("%d No info file.\n", ERROR);
1436 cprintf("%d Info:\n", LISTING_FOLLOWS);
1437 while (fgets(buf, sizeof buf, info_fp) != NULL) {
1438 if (strlen(buf) > 0)
1439 buf[strlen(buf) - 1] = 0;
1440 cprintf("%s\n", buf);
1447 * Back end processing to delete a room and everything associated with it
1449 void delete_room(struct ctdlroom *qrbuf)
1454 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1456 /* Delete the info file */
1457 assoc_file_name(filename, sizeof filename, qrbuf, "info");
1460 /* Delete the image file */
1461 assoc_file_name(filename, sizeof filename, qrbuf, "images");
1464 /* Delete the room's network config file */
1465 assoc_file_name(filename, sizeof filename, qrbuf, "netconfigs");
1468 /* Delete the messages in the room
1469 * (Careful: this opens an S_ROOMS critical section!)
1471 CtdlDeleteMessages(qrbuf->QRname, 0L, "");
1473 /* Flag the room record as not in use */
1474 lgetroom(qrbuf, qrbuf->QRname);
1478 /* then decrement the reference count for the floor */
1479 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1480 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1481 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1483 /* Delete the room record from the database! */
1484 b_deleteroom(qrbuf->QRname);
1490 * Check access control for deleting a room
1492 int CtdlDoIHavePermissionToDeleteThisRoom(struct ctdlroom *qr) {
1494 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
1498 if (is_noneditable(qr)) {
1503 * For mailboxes, check stuff
1505 if (qr->QRflags & QR_MAILBOX) {
1507 if (strlen(qr->QRname) < 12) return(0); /* bad name */
1509 if (atol(qr->QRname) != CC->user.usernum) {
1510 return(0); /* not my room */
1513 /* Can't delete your Mail> room */
1514 if (!strcasecmp(&qr->QRname[12], MAILROOM)) return(0);
1516 /* Otherwise it's ok */
1521 * For normal rooms, just check for aide or room aide status.
1523 return(is_room_aide());
1527 * aide command: kill the current room
1529 void cmd_kill(char *argbuf)
1531 char deleted_room_name[ROOMNAMELEN];
1535 kill_ok = extract_int(argbuf, 0);
1537 if (CtdlDoIHavePermissionToDeleteThisRoom(&CC->room) == 0) {
1538 cprintf("%d Can't delete this room.\n", ERROR + NOT_HERE);
1542 if (CC->room.QRflags & QR_MAILBOX) {
1543 strcpy(deleted_room_name, &CC->room.QRname[11]);
1546 strcpy(deleted_room_name, CC->room.QRname);
1549 /* Do the dirty work */
1550 delete_room(&CC->room);
1552 /* Return to the Lobby */
1553 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
1555 /* tell the world what we did */
1556 snprintf(msg, sizeof msg, "%s> killed by %s\n",
1557 deleted_room_name, CC->curr_user);
1559 cprintf("%d '%s' deleted.\n", CIT_OK, deleted_room_name);
1561 cprintf("%d ok to delete.\n", CIT_OK);
1567 * Internal code to create a new room (returns room flags)
1569 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only,
1570 * 4=mailbox, 5=mailbox, but caller supplies namespace
1572 unsigned create_room(char *new_room_name,
1574 char *new_room_pass,
1580 struct ctdlroom qrbuf;
1584 lprintf(9, "create_room(%s)\n", new_room_name);
1585 if (getroom(&qrbuf, new_room_name) == 0) {
1586 lprintf(9, "%s already exists.\n", new_room_name);
1587 return (0); /* already exists */
1591 memset(&qrbuf, 0, sizeof(struct ctdlroom));
1592 safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
1593 qrbuf.QRflags = QR_INUSE;
1594 if (new_room_type > 0)
1595 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1596 if (new_room_type == 1)
1597 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1598 if (new_room_type == 2)
1599 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1600 if ( (new_room_type == 4) || (new_room_type == 5) )
1601 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1603 /* If the user is requesting a personal room, set up the room
1604 * name accordingly (prepend the user number)
1606 if (new_room_type == 4) {
1607 MailboxName(qrbuf.QRname, sizeof qrbuf.QRname, &CC->user, new_room_name);
1610 safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
1613 /* If the room is private, and the system administrator has elected
1614 * to automatically grant room aide privileges, do so now; otherwise,
1615 * set the room aide to undefined.
1617 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1618 qrbuf.QRroomaide = CC->user.usernum;
1620 qrbuf.QRroomaide = (-1L);
1624 * If the caller is only interested in testing whether this will work,
1625 * return now without creating the room.
1627 if (!really_create) return (qrbuf.QRflags);
1629 qrbuf.QRnumber = get_new_room_number();
1630 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1631 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1632 qrbuf.QRfloor = new_room_floor;
1634 /* save what we just did... */
1637 /* bump the reference count on whatever floor the room is on */
1638 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1639 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1640 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1642 /* Grant the creator access to the room unless the avoid_access
1643 * parameter was specified.
1645 if (avoid_access == 0) {
1646 lgetuser(&CC->user, CC->curr_user);
1647 CtdlGetRelationship(&vbuf, &CC->user, &qrbuf);
1648 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1649 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1650 CtdlSetRelationship(&vbuf, &CC->user, &qrbuf);
1651 lputuser(&CC->user);
1654 /* resume our happy day */
1655 return (qrbuf.QRflags);
1662 void cmd_cre8(char *args)
1665 char new_room_name[SIZ];
1667 char new_room_pass[SIZ];
1672 int avoid_access = 0;
1674 cre8_ok = extract_int(args, 0);
1675 extract(new_room_name, args, 1);
1676 new_room_name[ROOMNAMELEN - 1] = 0;
1677 new_room_type = extract_int(args, 2);
1678 extract(new_room_pass, args, 3);
1679 avoid_access = extract_int(args, 5);
1680 new_room_pass[9] = 0;
1683 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1684 cprintf("%d Invalid room name.\n", ERROR);
1688 if (!strcasecmp(new_room_name, MAILROOM)) {
1689 cprintf("%d '%s' already exists.\n",
1690 ERROR + ALREADY_EXISTS, new_room_name);
1694 if (num_parms(args) >= 5) {
1695 fl = cgetfloor(extract_int(args, 4));
1696 if ((fl->f_flags & F_INUSE) == 0) {
1697 cprintf("%d Invalid floor number.\n",
1698 ERROR + INVALID_FLOOR_OPERATION);
1701 new_room_floor = extract_int(args, 4);
1705 if (CtdlAccessCheck(ac_logged_in)) return;
1707 if (CC->user.axlevel < config.c_createax) {
1708 cprintf("%d You need higher access to create rooms.\n",
1709 ERROR + HIGHER_ACCESS_REQUIRED);
1713 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1714 cprintf("%d Ok to create rooms.\n", CIT_OK);
1718 if ((new_room_type < 0) || (new_room_type > 5)) {
1719 cprintf("%d Invalid room type.\n", ERROR);
1723 if (new_room_type == 5) {
1724 if ((config.c_aide_mailboxes == 0)
1725 || (CC->user.axlevel < 6)) {
1726 cprintf("%d Higher access required\n",
1727 ERROR+HIGHER_ACCESS_REQUIRED);
1732 /* Check to make sure the requested room name doesn't already exist */
1733 newflags = create_room(new_room_name,
1734 new_room_type, new_room_pass, new_room_floor,
1736 if (newflags == 0) {
1737 cprintf("%d '%s' already exists.\n",
1738 ERROR + ALREADY_EXISTS, new_room_name);
1743 cprintf("%d OK to create '%s'\n", CIT_OK, new_room_name);
1747 /* If we reach this point, the room needs to be created. */
1749 newflags = create_room(new_room_name,
1750 new_room_type, new_room_pass, new_room_floor, 1, 0);
1752 /* post a message in Aide> describing the new room */
1753 safestrncpy(aaa, new_room_name, sizeof aaa);
1754 strcat(aaa, "> created by ");
1755 strcat(aaa, CC->user.fullname);
1756 if (newflags & QR_MAILBOX)
1757 strcat(aaa, " [personal]");
1758 else if (newflags & QR_PRIVATE)
1759 strcat(aaa, " [private]");
1760 if (newflags & QR_GUESSNAME)
1761 strcat(aaa, "[guessname] ");
1762 if (newflags & QR_PASSWORDED) {
1763 strcat(aaa, "\n Password: ");
1764 strcat(aaa, new_room_pass);
1769 cprintf("%d '%s' has been created.\n", CIT_OK, new_room_name);
1774 void cmd_einf(char *ok)
1775 { /* enter info file for current room */
1777 char infofilename[SIZ];
1780 if (CtdlAccessCheck(ac_room_aide)) return;
1782 if (atoi(ok) == 0) {
1783 cprintf("%d Ok.\n", CIT_OK);
1786 assoc_file_name(infofilename, sizeof infofilename, &CC->room, "info");
1787 lprintf(9, "opening\n");
1788 fp = fopen(infofilename, "w");
1789 lprintf(9, "checking\n");
1791 cprintf("%d Cannot open %s: %s\n",
1792 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1795 cprintf("%d Send info...\n", SEND_LISTING);
1799 if (strcmp(buf, "000"))
1800 fprintf(fp, "%s\n", buf);
1801 } while (strcmp(buf, "000"));
1804 /* now update the room index so people will see our new info */
1805 lgetroom(&CC->room, CC->room.QRname); /* lock so no one steps on us */
1806 CC->room.QRinfo = CC->room.QRhighest + 1L;
1807 lputroom(&CC->room);
1812 * cmd_lflr() - List all known floors
1819 if (CtdlAccessCheck(ac_logged_in)) return;
1821 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1823 for (a = 0; a < MAXFLOORS; ++a) {
1824 getfloor(&flbuf, a);
1825 if (flbuf.f_flags & F_INUSE) {
1826 cprintf("%d|%s|%d\n",
1838 * create a new floor
1840 void cmd_cflr(char *argbuf)
1842 char new_floor_name[SIZ];
1845 int free_slot = (-1);
1848 extract(new_floor_name, argbuf, 0);
1849 cflr_ok = extract_int(argbuf, 1);
1851 if (CtdlAccessCheck(ac_aide)) return;
1853 if (strlen(new_floor_name) == 0) {
1854 cprintf("%d Blank floor name not allowed.\n",
1855 ERROR+ILLEGAL_VALUE);
1859 for (a = 0; a < MAXFLOORS; ++a) {
1860 getfloor(&flbuf, a);
1862 /* note any free slots while we're scanning... */
1863 if (((flbuf.f_flags & F_INUSE) == 0)
1867 /* check to see if it already exists */
1868 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1869 && (flbuf.f_flags & F_INUSE)) {
1870 cprintf("%d Floor '%s' already exists.\n",
1871 ERROR + ALREADY_EXISTS,
1877 if (free_slot < 0) {
1878 cprintf("%d There is no space available for a new floor.\n",
1879 ERROR + INVALID_FLOOR_OPERATION);
1883 cprintf("%d ok to create...\n", CIT_OK);
1886 lgetfloor(&flbuf, free_slot);
1887 flbuf.f_flags = F_INUSE;
1888 flbuf.f_ref_count = 0;
1889 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1890 lputfloor(&flbuf, free_slot);
1891 cprintf("%d %d\n", CIT_OK, free_slot);
1899 void cmd_kflr(char *argbuf)
1902 int floor_to_delete;
1906 floor_to_delete = extract_int(argbuf, 0);
1907 kflr_ok = extract_int(argbuf, 1);
1909 if (CtdlAccessCheck(ac_aide)) return;
1911 lgetfloor(&flbuf, floor_to_delete);
1914 if ((flbuf.f_flags & F_INUSE) == 0) {
1915 cprintf("%d Floor %d not in use.\n",
1916 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1919 if (flbuf.f_ref_count != 0) {
1920 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1921 ERROR + INVALID_FLOOR_OPERATION,
1926 cprintf("%d Ok\n", CIT_OK);
1928 cprintf("%d Ok to delete...\n", CIT_OK);
1935 if ((delete_ok == 1) && (kflr_ok == 1))
1937 lputfloor(&flbuf, floor_to_delete);
1943 void cmd_eflr(char *argbuf)
1949 np = num_parms(argbuf);
1951 cprintf("%d Usage error.\n", ERROR);
1955 if (CtdlAccessCheck(ac_aide)) return;
1957 floor_num = extract_int(argbuf, 0);
1958 lgetfloor(&flbuf, floor_num);
1959 if ((flbuf.f_flags & F_INUSE) == 0) {
1960 lputfloor(&flbuf, floor_num);
1961 cprintf("%d Floor %d is not in use.\n",
1962 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1966 extract(flbuf.f_name, argbuf, 1);
1967 lputfloor(&flbuf, floor_num);
1969 cprintf("%d Ok\n", CIT_OK);