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 struct floor *fl = NULL;
339 begin_critical_section(S_FLOORCACHE);
340 if (initialized == 0) {
341 for (i=0; i<MAXFLOORS; ++i) {
342 floorcache[floor_num] = NULL;
346 if (floorcache[floor_num] == NULL) {
349 end_critical_section(S_FLOORCACHE);
352 lprintf(9, "fetch_new is active ... going to disk\n");
353 fl = mallok(sizeof(struct floor));
354 getfloor(fl, floor_num);
355 begin_critical_section(S_FLOORCACHE);
356 if (floorcache[floor_num] != NULL) {
357 phree(floorcache[floor_num]);
359 floorcache[floor_num] = fl;
360 end_critical_section(S_FLOORCACHE);
363 return(floorcache[floor_num]);
369 * putfloor() - store floor data on disk
371 void putfloor(struct floor *flbuf, int floor_num)
373 /* If we've cached this, clear it out, 'cuz it's WRONG now! */
374 begin_critical_section(S_FLOORCACHE);
375 if (floorcache[floor_num] != NULL) {
376 phree(floorcache[floor_num]);
377 floorcache[floor_num] = mallok(sizeof(struct floor));
378 memcpy(floorcache[floor_num], flbuf, sizeof(struct floor));
380 end_critical_section(S_FLOORCACHE);
382 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
383 flbuf, sizeof(struct floor));
388 * lputfloor() - same as putfloor() but unlocks the record (if supported)
390 void lputfloor(struct floor *flbuf, int floor_num)
393 putfloor(flbuf, floor_num);
394 end_critical_section(S_FLOORTAB);
400 * Traverse the room file...
402 void ForEachRoom(void (*CallBack) (struct ctdlroom *EachRoom, void *out_data),
405 struct ctdlroom qrbuf;
406 struct cdbdata *cdbqr;
408 cdb_rewind(CDB_ROOMS);
410 while (cdbqr = cdb_next_item(CDB_ROOMS), cdbqr != NULL) {
411 memset(&qrbuf, 0, sizeof(struct ctdlroom));
412 memcpy(&qrbuf, cdbqr->ptr,
413 ((cdbqr->len > sizeof(struct ctdlroom)) ?
414 sizeof(struct ctdlroom) : cdbqr->len));
416 room_sanity_check(&qrbuf);
417 if (qrbuf.QRflags & QR_INUSE)
418 (*CallBack)(&qrbuf, in_data);
424 * delete_msglist() - delete room message pointers
426 void delete_msglist(struct ctdlroom *whichroom)
428 struct cdbdata *cdbml;
430 /* Make sure the msglist we're deleting actually exists, otherwise
431 * gdbm will complain when we try to delete an invalid record
433 cdbml = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
437 /* Go ahead and delete it */
438 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
446 * sort message pointers
447 * (returns new msg count)
449 int sort_msglist(long listptrs[], int oldcount)
460 for (a = numitems - 2; a >= 0; --a) {
461 for (b = 0; b <= a; ++b) {
462 if (listptrs[b] > (listptrs[b + 1])) {
464 hold2 = listptrs[b + 1];
466 listptrs[b + 1] = hold1;
471 /* and yank any nulls */
472 while ((numitems > 0) && (listptrs[0] == 0L)) {
473 memcpy(&listptrs[0], &listptrs[1],
474 (sizeof(long) * (numitems - 1)));
483 * Determine whether a given room is non-editable.
485 int is_noneditable(struct ctdlroom *qrbuf)
488 /* Mail> rooms are non-editable */
489 if ( (qrbuf->QRflags & QR_MAILBOX)
490 && (!strcasecmp(&qrbuf->QRname[11], MAILROOM)) )
493 /* Everything else is editable */
500 * Back-back-end for all room listing commands
502 void list_roomname(struct ctdlroom *qrbuf, int ra)
504 char truncated_roomname[ROOMNAMELEN];
506 /* For my own mailbox rooms, chop off the owner prefix */
507 if ( (qrbuf->QRflags & QR_MAILBOX)
508 && (atol(qrbuf->QRname) == CC->user.usernum) ) {
509 strcpy(truncated_roomname, qrbuf->QRname);
510 strcpy(truncated_roomname, &truncated_roomname[11]);
511 cprintf("%s", truncated_roomname);
513 /* For all other rooms, just display the name in its entirety */
515 cprintf("%s", qrbuf->QRname);
518 /* ...and now the other parameters */
519 cprintf("|%u|%d|%d|%d|%d|\n",
521 (int) qrbuf->QRfloor,
522 (int) qrbuf->QRorder,
523 (int) qrbuf->QRflags2,
530 * cmd_lrms() - List all accessible rooms, known or forgotten
532 void cmd_lrms_backend(struct ctdlroom *qrbuf, void *data)
534 int FloorBeingSearched = (-1);
537 FloorBeingSearched = *(int *)data;
538 ra = CtdlRoomAccess(qrbuf, &CC->user);
540 if ((( ra & (UA_KNOWN | UA_ZAPPED)))
541 && ((qrbuf->QRfloor == (FloorBeingSearched))
542 || ((FloorBeingSearched) < 0)))
543 list_roomname(qrbuf, ra);
546 void cmd_lrms(char *argbuf)
548 int FloorBeingSearched = (-1);
549 if (strlen(argbuf) > 0)
550 FloorBeingSearched = extract_int(argbuf, 0);
552 if (CtdlAccessCheck(ac_logged_in)) return;
554 if (getuser(&CC->user, CC->curr_user)) {
555 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
558 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
560 ForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
567 * cmd_lkra() - List all known rooms
569 void cmd_lkra_backend(struct ctdlroom *qrbuf, void *data)
571 int FloorBeingSearched = (-1);
574 FloorBeingSearched = *(int *)data;
575 ra = CtdlRoomAccess(qrbuf, &CC->user);
577 if ((( ra & (UA_KNOWN)))
578 && ((qrbuf->QRfloor == (FloorBeingSearched))
579 || ((FloorBeingSearched) < 0)))
580 list_roomname(qrbuf, ra);
583 void cmd_lkra(char *argbuf)
585 int FloorBeingSearched = (-1);
586 if (strlen(argbuf) > 0)
587 FloorBeingSearched = extract_int(argbuf, 0);
589 if (CtdlAccessCheck(ac_logged_in)) return;
591 if (getuser(&CC->user, CC->curr_user)) {
592 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
595 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
597 ForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
603 void cmd_lprm_backend(struct ctdlroom *qrbuf, void *data)
605 int FloorBeingSearched = (-1);
608 FloorBeingSearched = *(int *)data;
609 ra = CtdlRoomAccess(qrbuf, &CC->user);
611 if ( ((qrbuf->QRflags & QR_PRIVATE) == 0)
612 && ((qrbuf->QRflags & QR_MAILBOX) == 0)
613 && ((qrbuf->QRfloor == (FloorBeingSearched))
614 || ((FloorBeingSearched) < 0)))
615 list_roomname(qrbuf, ra);
618 void cmd_lprm(char *argbuf)
620 int FloorBeingSearched = (-1);
621 if (strlen(argbuf) > 0)
622 FloorBeingSearched = extract_int(argbuf, 0);
624 cprintf("%d Publiic rooms:\n", LISTING_FOLLOWS);
626 ForEachRoom(cmd_lprm_backend, &FloorBeingSearched);
633 * cmd_lkrn() - List all known rooms with new messages
635 void cmd_lkrn_backend(struct ctdlroom *qrbuf, void *data)
637 int FloorBeingSearched = (-1);
640 FloorBeingSearched = *(int *)data;
641 ra = CtdlRoomAccess(qrbuf, &CC->user);
644 && (ra & UA_HASNEWMSGS)
645 && ((qrbuf->QRfloor == (FloorBeingSearched))
646 || ((FloorBeingSearched) < 0)))
647 list_roomname(qrbuf, ra);
650 void cmd_lkrn(char *argbuf)
652 int FloorBeingSearched = (-1);
653 if (strlen(argbuf) > 0)
654 FloorBeingSearched = extract_int(argbuf, 0);
656 if (CtdlAccessCheck(ac_logged_in)) return;
658 if (getuser(&CC->user, CC->curr_user)) {
659 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
662 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
664 ForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
671 * cmd_lkro() - List all known rooms
673 void cmd_lkro_backend(struct ctdlroom *qrbuf, void *data)
675 int FloorBeingSearched = (-1);
678 FloorBeingSearched = *(int *)data;
679 ra = CtdlRoomAccess(qrbuf, &CC->user);
682 && ((ra & UA_HASNEWMSGS) == 0)
683 && ((qrbuf->QRfloor == (FloorBeingSearched))
684 || ((FloorBeingSearched) < 0)))
685 list_roomname(qrbuf, ra);
688 void cmd_lkro(char *argbuf)
690 int FloorBeingSearched = (-1);
691 if (strlen(argbuf) > 0)
692 FloorBeingSearched = extract_int(argbuf, 0);
694 if (CtdlAccessCheck(ac_logged_in)) return;
696 if (getuser(&CC->user, CC->curr_user)) {
697 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
700 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
702 ForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
709 * cmd_lzrm() - List all forgotten rooms
711 void cmd_lzrm_backend(struct ctdlroom *qrbuf, void *data)
713 int FloorBeingSearched = (-1);
716 FloorBeingSearched = *(int *)data;
717 ra = CtdlRoomAccess(qrbuf, &CC->user);
719 if ((ra & UA_GOTOALLOWED)
721 && ((qrbuf->QRfloor == (FloorBeingSearched))
722 || ((FloorBeingSearched) < 0)))
723 list_roomname(qrbuf, ra);
726 void cmd_lzrm(char *argbuf)
728 int FloorBeingSearched = (-1);
729 if (strlen(argbuf) > 0)
730 FloorBeingSearched = extract_int(argbuf, 0);
732 if (CtdlAccessCheck(ac_logged_in)) return;
734 if (getuser(&CC->user, CC->curr_user)) {
735 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
738 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
740 ForEachRoom(cmd_lzrm_backend, &FloorBeingSearched);
746 * Make the specified room the current room for this session. No validation
747 * or access control is done here -- the caller should make sure that the
748 * specified room exists and is ok to access.
750 void usergoto(char *where, int display_result, int transiently,
751 int *retmsgs, int *retnew)
754 int new_messages = 0;
755 int total_messages = 0;
759 int newmailcount = 0;
761 char truncated_roomname[ROOMNAMELEN];
762 struct cdbdata *cdbfr;
763 long *msglist = NULL;
765 unsigned int original_v_flags;
767 /* If the supplied room name is NULL, the caller wants us to know that
768 * it has already copied the room record into CC->room, so
769 * we can skip the extra database fetch.
772 safestrncpy(CC->room.QRname, where, sizeof CC->room.QRname);
773 getroom(&CC->room, where);
776 /* Take care of all the formalities. */
778 begin_critical_section(S_USERS);
779 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
780 original_v_flags = vbuf.v_flags;
782 /* Know the room ... but not if it's the page log room, or if the
783 * caller specified that we're only entering this room transiently.
785 if ((strcasecmp(CC->room.QRname, config.c_logpages))
786 && (transiently == 0) ) {
787 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
788 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
791 /* Only rewrite the database record if we changed something */
792 if (vbuf.v_flags != original_v_flags) {
793 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
795 end_critical_section(S_USERS);
797 /* Check for new mail */
798 newmailcount = NewMailCount();
800 /* set info to 1 if the user needs to read the room's info file */
801 if (CC->room.QRinfo > vbuf.v_lastseen) {
806 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
808 msglist = mallok(cdbfr->len);
809 memcpy(msglist, cdbfr->ptr, cdbfr->len);
810 num_msgs = cdbfr->len / sizeof(long);
814 if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
815 if (msglist[a] > 0L) {
817 if (is_msg_in_mset(vbuf.v_seen, msglist[a]) == 0) {
823 if (msglist != NULL) phree(msglist);
825 if (CC->room.QRflags & QR_MAILBOX)
830 if ((CC->room.QRroomaide == CC->user.usernum)
831 || (CC->user.axlevel >= 6))
836 strcpy(truncated_roomname, CC->room.QRname);
837 if ( (CC->room.QRflags & QR_MAILBOX)
838 && (atol(CC->room.QRname) == CC->user.usernum) ) {
839 strcpy(truncated_roomname, &truncated_roomname[11]);
842 if (retmsgs != NULL) *retmsgs = total_messages;
843 if (retnew != NULL) *retnew = new_messages;
844 lprintf(CTDL_DEBUG, "<%s> %d new of %d total messages\n",
846 new_messages, total_messages
849 if (display_result) {
850 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d|%d|%d|\n",
851 CIT_OK, CtdlCheckExpress(),
856 (int)CC->room.QRflags,
857 (long)CC->room.QRhighest,
858 (long)vbuf.v_lastseen,
862 (int)CC->room.QRfloor,
864 (int)CC->room.QRdefaultview
871 * cmd_goto() - goto a new room
873 void cmd_goto(char *gargs)
875 struct ctdlroom QRscratch;
879 char augmented_roomname[SIZ];
884 if (CtdlAccessCheck(ac_logged_in)) return;
886 extract(towhere, gargs, 0);
887 extract(password, gargs, 1);
888 transiently = extract_int(gargs, 2);
890 getuser(&CC->user, CC->curr_user);
892 if (!strcasecmp(towhere, "_BASEROOM_"))
893 strcpy(towhere, config.c_baseroom);
895 if (!strcasecmp(towhere, "_MAIL_"))
896 strcpy(towhere, MAILROOM);
898 if (!strcasecmp(towhere, "_BITBUCKET_"))
899 strcpy(towhere, config.c_twitroom);
902 /* First try a regular match */
903 c = getroom(&QRscratch, towhere);
905 /* Then try a mailbox name match */
907 MailboxName(augmented_roomname, sizeof augmented_roomname,
909 c = getroom(&QRscratch, augmented_roomname);
911 strcpy(towhere, augmented_roomname);
914 /* And if the room was found... */
917 /* Let internal programs go directly to any room. */
918 if (CC->internal_pgm) {
919 memcpy(&CC->room, &QRscratch,
920 sizeof(struct ctdlroom));
921 usergoto(NULL, 1, transiently, NULL, NULL);
925 /* See if there is an existing user/room relationship */
926 ra = CtdlRoomAccess(&QRscratch, &CC->user);
928 /* normal clients have to pass through security */
929 if (ra & UA_GOTOALLOWED) {
934 if ((QRscratch.QRflags & QR_MAILBOX) &&
935 ((ra & UA_GOTOALLOWED))) {
936 memcpy(&CC->room, &QRscratch,
937 sizeof(struct ctdlroom));
938 usergoto(NULL, 1, transiently, NULL, NULL);
940 } else if ((QRscratch.QRflags & QR_PASSWORDED) &&
941 ((ra & UA_KNOWN) == 0) &&
942 (strcasecmp(QRscratch.QRpasswd, password)) &&
943 (CC->user.axlevel < 6)
945 cprintf("%d wrong or missing passwd\n",
946 ERROR + PASSWORD_REQUIRED);
948 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
949 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
950 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
951 ((ra & UA_KNOWN) == 0) &&
952 (CC->user.axlevel < 6)
954 lprintf(CTDL_DEBUG, "Failed to acquire private room\n");
956 memcpy(&CC->room, &QRscratch,
957 sizeof(struct ctdlroom));
958 usergoto(NULL, 1, transiently, NULL, NULL);
964 cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
970 struct ctdluser temp;
971 struct cdbdata *cdbus;
973 getuser(&CC->user, CC->curr_user);
976 * This command is only allowed by aides, room aides,
977 * and room namespace owners
980 || (atol(CC->room.QRname) == CC->user.usernum) ) {
985 cprintf("%d Higher access or room ownership required.\n",
986 ERROR + HIGHER_ACCESS_REQUIRED);
990 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
991 cdb_rewind(CDB_USERS);
992 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
993 memset(&temp, 0, sizeof temp);
994 memcpy(&temp, cdbus->ptr, sizeof temp);
997 if ((CC->room.QRflags & QR_INUSE)
998 && (CtdlRoomAccess(&CC->room, &temp) & UA_KNOWN)
1000 cprintf("%s\n", temp.fullname);
1007 * RDIR command for room directory
1015 struct stat statbuf;
1017 if (CtdlAccessCheck(ac_logged_in)) return;
1019 getroom(&CC->room, CC->room.QRname);
1020 getuser(&CC->user, CC->curr_user);
1022 if ((CC->room.QRflags & QR_DIRECTORY) == 0) {
1023 cprintf("%d not here.\n", ERROR + NOT_HERE);
1026 if (((CC->room.QRflags & QR_VISDIR) == 0)
1027 && (CC->user.axlevel < 6)
1028 && (CC->user.usernum != CC->room.QRroomaide)) {
1029 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
1032 cprintf("%d %s|%s/files/%s\n",
1033 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->room.QRdirname);
1035 snprintf(buf, sizeof buf, "ls %s/files/%s >%s 2> /dev/null",
1036 BBSDIR, CC->room.QRdirname, CC->temp);
1039 snprintf(buf, sizeof buf, "%s/files/%s/filedir", BBSDIR, CC->room.QRdirname);
1040 fd = fopen(buf, "r");
1042 fd = fopen("/dev/null", "r");
1044 ls = fopen(CC->temp, "r");
1045 while (fgets(flnm, sizeof flnm, ls) != NULL) {
1046 flnm[strlen(flnm) - 1] = 0;
1047 if (strcasecmp(flnm, "filedir")) {
1048 snprintf(buf, sizeof buf, "%s/files/%s/%s",
1049 BBSDIR, CC->room.QRdirname, flnm);
1050 stat(buf, &statbuf);
1051 strcpy(comment, "");
1053 while ((fgets(buf, sizeof buf, fd) != NULL)
1054 && (strlen(comment) == 0)) {
1055 buf[strlen(buf) - 1] = 0;
1056 if ((!strncasecmp(buf, flnm, strlen(flnm)))
1057 && (buf[strlen(flnm)] == ' '))
1058 safestrncpy(comment,
1059 &buf[strlen(flnm) + 1],
1062 cprintf("%s|%ld|%s\n", flnm, (long)statbuf.st_size, comment);
1073 * get room parameters (aide or room aide command)
1077 if (CtdlAccessCheck(ac_room_aide)) return;
1079 getroom(&CC->room, CC->room.QRname);
1080 cprintf("%d%c%s|%s|%s|%d|%d|%d|%d|%d|\n",
1084 ((CC->room.QRflags & QR_MAILBOX) ?
1085 &CC->room.QRname[11] : CC->room.QRname),
1087 ((CC->room.QRflags & QR_PASSWORDED) ?
1088 CC->room.QRpasswd : ""),
1090 ((CC->room.QRflags & QR_DIRECTORY) ?
1091 CC->room.QRdirname : ""),
1094 (int) CC->room.QRfloor,
1095 (int) CC->room.QRorder,
1097 CC->room.QRdefaultview,
1104 * Back end function to rename a room.
1105 * You can also specify which floor to move the room to, or specify -1 to
1106 * keep the room on the same floor it was on.
1108 * If you are renaming a mailbox room, you must supply the namespace prefix
1109 * in *at least* the old name!
1111 int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) {
1113 struct ctdlroom qrbuf;
1114 struct ctdlroom qrtmp;
1119 char actual_old_name[SIZ];
1121 lprintf(CTDL_DEBUG, "CtdlRenameRoom(%s, %s, %d)\n",
1122 old_name, new_name, new_floor);
1124 if (new_floor >= 0) {
1125 fl = cgetfloor(new_floor);
1126 if ((fl->f_flags & F_INUSE) == 0) {
1127 return(crr_invalid_floor);
1131 begin_critical_section(S_ROOMS);
1133 if ( (getroom(&qrtmp, new_name) == 0)
1134 && (strcasecmp(new_name, old_name)) ) {
1135 ret = crr_already_exists;
1138 else if (getroom(&qrbuf, old_name) != 0) {
1139 ret = crr_room_not_found;
1142 else if ( (CC->user.axlevel < 6)
1143 && (CC->user.usernum != qrbuf.QRroomaide)
1144 && ( (((qrbuf.QRflags & QR_MAILBOX) == 0) || (atol(qrbuf.QRname) != CC->user.usernum))) ) {
1145 ret = crr_access_denied;
1148 else if (is_noneditable(&qrbuf)) {
1149 ret = crr_noneditable;
1154 strcpy(actual_old_name, qrbuf.QRname);
1155 if (qrbuf.QRflags & QR_MAILBOX) {
1156 owner = atol(qrbuf.QRname);
1158 if ( (owner > 0L) && (atol(new_name) == 0L) ) {
1159 snprintf(qrbuf.QRname, sizeof(qrbuf.QRname),
1160 "%010ld.%s", owner, new_name);
1163 safestrncpy(qrbuf.QRname, new_name,
1164 sizeof(qrbuf.QRname));
1167 /* Reject change of floor for baseroom/aideroom */
1168 if (!strncasecmp(old_name, config.c_baseroom, ROOMNAMELEN) ||
1169 !strncasecmp(old_name, config.c_aideroom, ROOMNAMELEN)) {
1173 /* Take care of floor stuff */
1174 old_floor = qrbuf.QRfloor;
1175 if (new_floor < 0) {
1176 new_floor = old_floor;
1178 qrbuf.QRfloor = new_floor;
1181 begin_critical_section(S_CONFIG);
1183 /* If baseroom/aideroom name changes, update config */
1184 if (!strncasecmp(old_name, config.c_baseroom, ROOMNAMELEN)) {
1185 safestrncpy(config.c_baseroom, new_name, ROOMNAMELEN);
1188 if (!strncasecmp(old_name, config.c_aideroom, ROOMNAMELEN)) {
1189 safestrncpy(config.c_aideroom, new_name, ROOMNAMELEN);
1193 end_critical_section(S_CONFIG);
1195 /* If the room name changed, then there are now two room
1196 * records, so we have to delete the old one.
1198 if (strcasecmp(new_name, old_name)) {
1199 b_deleteroom(actual_old_name);
1205 end_critical_section(S_ROOMS);
1207 /* Adjust the floor reference counts if necessary */
1208 if (new_floor != old_floor) {
1209 lgetfloor(&flbuf, old_floor);
1210 --flbuf.f_ref_count;
1211 lputfloor(&flbuf, old_floor);
1212 lprintf(CTDL_DEBUG, "Reference count for floor %d is now %d\n", old_floor, flbuf.f_ref_count);
1213 lgetfloor(&flbuf, new_floor);
1214 ++flbuf.f_ref_count;
1215 lputfloor(&flbuf, new_floor);
1216 lprintf(CTDL_DEBUG, "Reference count for floor %d is now %d\n", new_floor, flbuf.f_ref_count);
1219 /* ...and everybody say "YATTA!" */
1225 * set room parameters (aide or room aide command)
1227 void cmd_setr(char *args)
1233 char new_name[ROOMNAMELEN];
1235 if (CtdlAccessCheck(ac_logged_in)) return;
1237 if (num_parms(args) >= 6) {
1238 new_floor = extract_int(args, 5);
1240 new_floor = (-1); /* don't change the floor */
1243 /* When is a new name more than just a new name? When the old name
1244 * has a namespace prefix.
1246 if (CC->room.QRflags & QR_MAILBOX) {
1247 sprintf(new_name, "%010ld.", atol(CC->room.QRname) );
1249 strcpy(new_name, "");
1251 extract(&new_name[strlen(new_name)], args, 0);
1253 r = CtdlRenameRoom(CC->room.QRname, new_name, new_floor);
1255 if (r == crr_room_not_found) {
1256 cprintf("%d Internal error - room not found?\n", ERROR + INTERNAL_ERROR);
1257 } else if (r == crr_already_exists) {
1258 cprintf("%d '%s' already exists.\n",
1259 ERROR + ALREADY_EXISTS, new_name);
1260 } else if (r == crr_noneditable) {
1261 cprintf("%d Cannot edit this room.\n", ERROR + NOT_HERE);
1262 } else if (r == crr_invalid_floor) {
1263 cprintf("%d Target floor does not exist.\n",
1264 ERROR + INVALID_FLOOR_OPERATION);
1265 } else if (r == crr_access_denied) {
1266 cprintf("%d You do not have permission to edit '%s'\n",
1267 ERROR + HIGHER_ACCESS_REQUIRED,
1269 } else if (r != crr_ok) {
1270 cprintf("%d Error: CtdlRenameRoom() returned %d\n",
1271 ERROR + INTERNAL_ERROR, r);
1278 getroom(&CC->room, new_name);
1280 /* Now we have to do a bunch of other stuff */
1282 if (num_parms(args) >= 7) {
1283 new_order = extract_int(args, 6);
1286 if (new_order > 127)
1290 lgetroom(&CC->room, CC->room.QRname);
1292 /* Directory room */
1293 extract(buf, args, 2);
1295 safestrncpy(CC->room.QRdirname, buf,
1296 sizeof CC->room.QRdirname);
1299 if (num_parms(args) >= 8) {
1300 CC->room.QRdefaultview = extract_int(args, 7);
1303 /* Second set of flags */
1304 if (num_parms(args) >= 9) {
1305 CC->room.QRflags2 = extract_int(args, 8);
1309 CC->room.QRflags = (extract_int(args, 3) | QR_INUSE);
1310 /* Clean up a client boo-boo: if the client set the room to
1311 * guess-name or passworded, ensure that the private flag is
1314 if ((CC->room.QRflags & QR_GUESSNAME)
1315 || (CC->room.QRflags & QR_PASSWORDED))
1316 CC->room.QRflags |= QR_PRIVATE;
1318 /* Some changes can't apply to BASEROOM */
1319 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1321 CC->room.QRorder = 0;
1322 CC->room.QRpasswd[0] = '\0';
1323 CC->room.QRflags &= ~(QR_PRIVATE & QR_PASSWORDED &
1324 QR_GUESSNAME & QR_PREFONLY & QR_MAILBOX);
1325 CC->room.QRflags |= QR_PERMANENT;
1327 /* March order (doesn't apply to AIDEROOM) */
1328 if (num_parms(args) >= 7)
1329 CC->room.QRorder = (char) new_order;
1331 extract(buf, args, 1);
1333 safestrncpy(CC->room.QRpasswd, buf,
1334 sizeof CC->room.QRpasswd);
1335 /* Kick everyone out if the client requested it
1336 * (by changing the room's generation number)
1338 if (extract_int(args, 4)) {
1339 time(&CC->room.QRgen);
1342 /* Some changes can't apply to AIDEROOM */
1343 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1345 CC->room.QRorder = 0;
1346 CC->room.QRflags &= ~QR_MAILBOX;
1347 CC->room.QRflags |= QR_PERMANENT;
1350 /* Write the room record back to disk */
1351 lputroom(&CC->room);
1353 /* Create a room directory if necessary */
1354 if (CC->room.QRflags & QR_DIRECTORY) {
1355 snprintf(buf, sizeof buf, "./files/%s",
1356 CC->room.QRdirname);
1359 snprintf(buf, sizeof buf, "%s> edited by %s\n", CC->room.QRname, CC->curr_user);
1361 cprintf("%d Ok\n", CIT_OK);
1367 * get the name of the room aide for this room
1371 struct ctdluser usbuf;
1373 if (CtdlAccessCheck(ac_logged_in)) return;
1375 if (getuserbynumber(&usbuf, CC->room.QRroomaide) == 0) {
1376 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1378 cprintf("%d \n", CIT_OK);
1384 * set the room aide for this room
1386 void cmd_seta(char *new_ra)
1388 struct ctdluser usbuf;
1393 if (CtdlAccessCheck(ac_room_aide)) return;
1395 if (getuser(&usbuf, new_ra) != 0) {
1398 newu = usbuf.usernum;
1401 lgetroom(&CC->room, CC->room.QRname);
1403 if (CC->room.QRroomaide != newu) {
1406 CC->room.QRroomaide = newu;
1407 lputroom(&CC->room);
1410 * We have to post the change notice _after_ writing changes to
1411 * the room table, otherwise it would deadlock!
1413 if (post_notice == 1) {
1414 if (strlen(usbuf.fullname) > 0)
1415 snprintf(buf, sizeof buf,
1416 "%s is now room aide for %s>\n",
1417 usbuf.fullname, CC->room.QRname);
1419 snprintf(buf, sizeof buf,
1420 "There is now no room aide for %s>\n",
1424 cprintf("%d Ok\n", CIT_OK);
1428 * Generate an associated file name for a room
1430 void assoc_file_name(char *buf, size_t n,
1431 struct ctdlroom *qrbuf, const char *prefix)
1433 snprintf(buf, n, "./%s/%ld", prefix, qrbuf->QRnumber);
1437 * retrieve info file for this room
1445 assoc_file_name(filename, sizeof filename, &CC->room, "info");
1446 info_fp = fopen(filename, "r");
1448 if (info_fp == NULL) {
1449 cprintf("%d No info file.\n", ERROR + FILE_NOT_FOUND);
1452 cprintf("%d Info:\n", LISTING_FOLLOWS);
1453 while (fgets(buf, sizeof buf, info_fp) != NULL) {
1454 if (strlen(buf) > 0)
1455 buf[strlen(buf) - 1] = 0;
1456 cprintf("%s\n", buf);
1463 * Back end processing to delete a room and everything associated with it
1465 void delete_room(struct ctdlroom *qrbuf)
1470 lprintf(CTDL_NOTICE, "Deleting room <%s>\n", qrbuf->QRname);
1472 /* Delete the info file */
1473 assoc_file_name(filename, sizeof filename, qrbuf, "info");
1476 /* Delete the image file */
1477 assoc_file_name(filename, sizeof filename, qrbuf, "images");
1480 /* Delete the room's network config file */
1481 assoc_file_name(filename, sizeof filename, qrbuf, "netconfigs");
1484 /* Delete the messages in the room
1485 * (Careful: this opens an S_ROOMS critical section!)
1487 CtdlDeleteMessages(qrbuf->QRname, 0L, "");
1489 /* Flag the room record as not in use */
1490 lgetroom(qrbuf, qrbuf->QRname);
1494 /* then decrement the reference count for the floor */
1495 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1496 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1497 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1499 /* Delete the room record from the database! */
1500 b_deleteroom(qrbuf->QRname);
1506 * Check access control for deleting a room
1508 int CtdlDoIHavePermissionToDeleteThisRoom(struct ctdlroom *qr) {
1510 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
1514 if (is_noneditable(qr)) {
1519 * For mailboxes, check stuff
1521 if (qr->QRflags & QR_MAILBOX) {
1523 if (strlen(qr->QRname) < 12) return(0); /* bad name */
1525 if (atol(qr->QRname) != CC->user.usernum) {
1526 return(0); /* not my room */
1529 /* Can't delete your Mail> room */
1530 if (!strcasecmp(&qr->QRname[12], MAILROOM)) return(0);
1532 /* Otherwise it's ok */
1537 * For normal rooms, just check for aide or room aide status.
1539 return(is_room_aide());
1543 * aide command: kill the current room
1545 void cmd_kill(char *argbuf)
1547 char deleted_room_name[ROOMNAMELEN];
1551 kill_ok = extract_int(argbuf, 0);
1553 if (CtdlDoIHavePermissionToDeleteThisRoom(&CC->room) == 0) {
1554 cprintf("%d Can't delete this room.\n", ERROR + NOT_HERE);
1558 if (CC->room.QRflags & QR_MAILBOX) {
1559 strcpy(deleted_room_name, &CC->room.QRname[11]);
1562 strcpy(deleted_room_name, CC->room.QRname);
1565 /* Do the dirty work */
1566 delete_room(&CC->room);
1568 /* Return to the Lobby */
1569 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
1571 /* tell the world what we did */
1572 snprintf(msg, sizeof msg, "%s> killed by %s\n",
1573 deleted_room_name, CC->curr_user);
1575 cprintf("%d '%s' deleted.\n", CIT_OK, deleted_room_name);
1577 cprintf("%d ok to delete.\n", CIT_OK);
1583 * Internal code to create a new room (returns room flags)
1585 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only,
1586 * 4=mailbox, 5=mailbox, but caller supplies namespace
1588 unsigned create_room(char *new_room_name,
1590 char *new_room_pass,
1596 struct ctdlroom qrbuf;
1600 lprintf(CTDL_DEBUG, "create_room(%s)\n", new_room_name);
1601 if (getroom(&qrbuf, new_room_name) == 0) {
1602 lprintf(CTDL_DEBUG, "%s already exists.\n", new_room_name);
1603 return (0); /* already exists */
1607 memset(&qrbuf, 0, sizeof(struct ctdlroom));
1608 safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
1609 qrbuf.QRflags = QR_INUSE;
1610 if (new_room_type > 0)
1611 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1612 if (new_room_type == 1)
1613 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1614 if (new_room_type == 2)
1615 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1616 if ( (new_room_type == 4) || (new_room_type == 5) )
1617 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1619 /* If the user is requesting a personal room, set up the room
1620 * name accordingly (prepend the user number)
1622 if (new_room_type == 4) {
1623 MailboxName(qrbuf.QRname, sizeof qrbuf.QRname, &CC->user, new_room_name);
1626 safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
1629 /* If the room is private, and the system administrator has elected
1630 * to automatically grant room aide privileges, do so now; otherwise,
1631 * set the room aide to undefined.
1633 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1634 qrbuf.QRroomaide = CC->user.usernum;
1636 qrbuf.QRroomaide = (-1L);
1640 * If the caller is only interested in testing whether this will work,
1641 * return now without creating the room.
1643 if (!really_create) return (qrbuf.QRflags);
1645 qrbuf.QRnumber = get_new_room_number();
1646 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1647 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1648 qrbuf.QRfloor = new_room_floor;
1650 /* save what we just did... */
1653 /* bump the reference count on whatever floor the room is on */
1654 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1655 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1656 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1658 /* Grant the creator access to the room unless the avoid_access
1659 * parameter was specified.
1661 if (avoid_access == 0) {
1662 lgetuser(&CC->user, CC->curr_user);
1663 CtdlGetRelationship(&vbuf, &CC->user, &qrbuf);
1664 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1665 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1666 CtdlSetRelationship(&vbuf, &CC->user, &qrbuf);
1667 lputuser(&CC->user);
1670 /* resume our happy day */
1671 return (qrbuf.QRflags);
1678 void cmd_cre8(char *args)
1681 char new_room_name[SIZ];
1683 char new_room_pass[SIZ];
1688 int avoid_access = 0;
1690 cre8_ok = extract_int(args, 0);
1691 extract(new_room_name, args, 1);
1692 new_room_name[ROOMNAMELEN - 1] = 0;
1693 new_room_type = extract_int(args, 2);
1694 extract(new_room_pass, args, 3);
1695 avoid_access = extract_int(args, 5);
1696 new_room_pass[9] = 0;
1699 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1700 cprintf("%d Invalid room name.\n", ERROR + ILLEGAL_VALUE);
1704 if (!strcasecmp(new_room_name, MAILROOM)) {
1705 cprintf("%d '%s' already exists.\n",
1706 ERROR + ALREADY_EXISTS, new_room_name);
1710 if (num_parms(args) >= 5) {
1711 fl = cgetfloor(extract_int(args, 4));
1713 cprintf("%d Invalid floor number.\n",
1714 ERROR + INVALID_FLOOR_OPERATION);
1717 else if ((fl->f_flags & F_INUSE) == 0) {
1718 cprintf("%d Invalid floor number.\n",
1719 ERROR + INVALID_FLOOR_OPERATION);
1722 new_room_floor = extract_int(args, 4);
1726 if (CtdlAccessCheck(ac_logged_in)) return;
1728 if (CC->user.axlevel < config.c_createax) {
1729 cprintf("%d You need higher access to create rooms.\n",
1730 ERROR + HIGHER_ACCESS_REQUIRED);
1734 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1735 cprintf("%d Ok to create rooms.\n", CIT_OK);
1739 if ((new_room_type < 0) || (new_room_type > 5)) {
1740 cprintf("%d Invalid room type.\n", ERROR + ILLEGAL_VALUE);
1744 if (new_room_type == 5) {
1745 if ((config.c_aide_mailboxes == 0)
1746 || (CC->user.axlevel < 6)) {
1747 cprintf("%d Higher access required\n",
1748 ERROR + HIGHER_ACCESS_REQUIRED);
1753 /* Check to make sure the requested room name doesn't already exist */
1754 newflags = create_room(new_room_name,
1755 new_room_type, new_room_pass, new_room_floor,
1757 if (newflags == 0) {
1758 cprintf("%d '%s' already exists.\n",
1759 ERROR + ALREADY_EXISTS, new_room_name);
1764 cprintf("%d OK to create '%s'\n", CIT_OK, new_room_name);
1768 /* If we reach this point, the room needs to be created. */
1770 newflags = create_room(new_room_name,
1771 new_room_type, new_room_pass, new_room_floor, 1, 0);
1773 /* post a message in Aide> describing the new room */
1774 safestrncpy(aaa, new_room_name, sizeof aaa);
1775 strcat(aaa, "> created by ");
1776 strcat(aaa, CC->user.fullname);
1777 if (newflags & QR_MAILBOX)
1778 strcat(aaa, " [personal]");
1779 else if (newflags & QR_PRIVATE)
1780 strcat(aaa, " [private]");
1781 if (newflags & QR_GUESSNAME)
1782 strcat(aaa, "[guessname] ");
1783 if (newflags & QR_PASSWORDED) {
1784 strcat(aaa, "\n Password: ");
1785 strcat(aaa, new_room_pass);
1790 cprintf("%d '%s' has been created.\n", CIT_OK, new_room_name);
1795 void cmd_einf(char *ok)
1796 { /* enter info file for current room */
1798 char infofilename[SIZ];
1801 if (CtdlAccessCheck(ac_room_aide)) return;
1803 if (atoi(ok) == 0) {
1804 cprintf("%d Ok.\n", CIT_OK);
1807 assoc_file_name(infofilename, sizeof infofilename, &CC->room, "info");
1808 lprintf(CTDL_DEBUG, "opening\n");
1809 fp = fopen(infofilename, "w");
1810 lprintf(CTDL_DEBUG, "checking\n");
1812 cprintf("%d Cannot open %s: %s\n",
1813 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1816 cprintf("%d Send info...\n", SEND_LISTING);
1820 if (strcmp(buf, "000"))
1821 fprintf(fp, "%s\n", buf);
1822 } while (strcmp(buf, "000"));
1825 /* now update the room index so people will see our new info */
1826 lgetroom(&CC->room, CC->room.QRname); /* lock so no one steps on us */
1827 CC->room.QRinfo = CC->room.QRhighest + 1L;
1828 lputroom(&CC->room);
1833 * cmd_lflr() - List all known floors
1840 if (CtdlAccessCheck(ac_logged_in)) return;
1842 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1844 for (a = 0; a < MAXFLOORS; ++a) {
1845 getfloor(&flbuf, a);
1846 if (flbuf.f_flags & F_INUSE) {
1847 cprintf("%d|%s|%d\n",
1859 * create a new floor
1861 void cmd_cflr(char *argbuf)
1863 char new_floor_name[SIZ];
1866 int free_slot = (-1);
1869 extract(new_floor_name, argbuf, 0);
1870 cflr_ok = extract_int(argbuf, 1);
1872 if (CtdlAccessCheck(ac_aide)) return;
1874 if (strlen(new_floor_name) == 0) {
1875 cprintf("%d Blank floor name not allowed.\n",
1876 ERROR + ILLEGAL_VALUE);
1880 for (a = 0; a < MAXFLOORS; ++a) {
1881 getfloor(&flbuf, a);
1883 /* note any free slots while we're scanning... */
1884 if (((flbuf.f_flags & F_INUSE) == 0)
1888 /* check to see if it already exists */
1889 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1890 && (flbuf.f_flags & F_INUSE)) {
1891 cprintf("%d Floor '%s' already exists.\n",
1892 ERROR + ALREADY_EXISTS,
1898 if (free_slot < 0) {
1899 cprintf("%d There is no space available for a new floor.\n",
1900 ERROR + INVALID_FLOOR_OPERATION);
1904 cprintf("%d ok to create...\n", CIT_OK);
1907 lgetfloor(&flbuf, free_slot);
1908 flbuf.f_flags = F_INUSE;
1909 flbuf.f_ref_count = 0;
1910 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1911 lputfloor(&flbuf, free_slot);
1912 cprintf("%d %d\n", CIT_OK, free_slot);
1920 void cmd_kflr(char *argbuf)
1923 int floor_to_delete;
1927 floor_to_delete = extract_int(argbuf, 0);
1928 kflr_ok = extract_int(argbuf, 1);
1930 if (CtdlAccessCheck(ac_aide)) return;
1932 lgetfloor(&flbuf, floor_to_delete);
1935 if ((flbuf.f_flags & F_INUSE) == 0) {
1936 cprintf("%d Floor %d not in use.\n",
1937 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1940 if (flbuf.f_ref_count != 0) {
1941 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1942 ERROR + INVALID_FLOOR_OPERATION,
1947 cprintf("%d Ok\n", CIT_OK);
1949 cprintf("%d Ok to delete...\n", CIT_OK);
1956 if ((delete_ok == 1) && (kflr_ok == 1))
1958 lputfloor(&flbuf, floor_to_delete);
1964 void cmd_eflr(char *argbuf)
1970 np = num_parms(argbuf);
1972 cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
1976 if (CtdlAccessCheck(ac_aide)) return;
1978 floor_num = extract_int(argbuf, 0);
1979 lgetfloor(&flbuf, floor_num);
1980 if ((flbuf.f_flags & F_INUSE) == 0) {
1981 lputfloor(&flbuf, floor_num);
1982 cprintf("%d Floor %d is not in use.\n",
1983 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1987 extract(flbuf.f_name, argbuf, 1);
1988 lputfloor(&flbuf, floor_num);
1990 cprintf("%d Ok\n", CIT_OK);