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 void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf,
53 int *result, int *view)
58 /* for internal programs, always do everything */
59 if (((CC->internal_pgm)) && (roombuf->QRflags & QR_INUSE)) {
60 retval = (UA_KNOWN | UA_GOTOALLOWED);
65 /* Locate any applicable user/room relationships */
66 CtdlGetRelationship(&vbuf, userbuf, roombuf);
68 /* Force the properties of the Aide room */
69 if (!strcasecmp(roombuf->QRname, config.c_aideroom)) {
70 if (userbuf->axlevel >= 6) {
71 retval = UA_KNOWN | UA_GOTOALLOWED;
78 /* If this is a public room, it's accessible... */
79 if ( ((roombuf->QRflags & QR_PRIVATE) == 0)
80 && ((roombuf->QRflags & QR_MAILBOX) == 0) ) {
81 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
84 /* If this is a preferred users only room, check access level */
85 if (roombuf->QRflags & QR_PREFONLY) {
86 if (userbuf->axlevel < 5) {
87 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
91 /* For private rooms, check the generation number matchups */
92 if ( (roombuf->QRflags & QR_PRIVATE)
93 && ((roombuf->QRflags & QR_MAILBOX) == 0) ) {
95 /* An explicit match means the user belongs in this room */
96 if (vbuf.v_flags & V_ACCESS) {
97 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
99 /* Otherwise, check if this is a guess-name or passworded
100 * room. If it is, a goto may at least be attempted
102 else if ((roombuf->QRflags & QR_PRIVATE)
103 || (roombuf->QRflags & QR_PASSWORDED)) {
104 retval = retval & ~UA_KNOWN;
105 retval = retval | UA_GOTOALLOWED;
109 /* For mailbox rooms, also check the generation number matchups */
110 if (roombuf->QRflags & QR_MAILBOX) {
111 if (userbuf->usernum == atol(roombuf->QRname)) {
112 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
114 /* An explicit match means the user belongs in this room */
115 if (vbuf.v_flags & V_ACCESS) {
116 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
120 /* Check to see if the user has forgotten this room */
121 if (vbuf.v_flags & V_FORGET) {
122 retval = retval & ~UA_KNOWN;
123 if ( ( ((roombuf->QRflags & QR_PRIVATE) == 0)
124 && ((roombuf->QRflags & QR_MAILBOX) == 0) )
125 || ( (roombuf->QRflags & QR_MAILBOX)
126 && (atol(roombuf->QRname) == CC->user.usernum))) {
127 retval = retval | UA_ZAPPED;
130 /* If user is explicitly locked out of this room, deny everything */
131 if (vbuf.v_flags & V_LOCKOUT) {
132 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
135 /* Aides get access to all private rooms */
136 if ( (userbuf->axlevel >= 6)
137 && ((roombuf->QRflags & QR_MAILBOX) == 0) ) {
138 if (vbuf.v_flags & V_FORGET) {
139 retval = retval | UA_GOTOALLOWED;
142 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
146 /* Aides can gain access to mailboxes as well, but they don't show
149 if ( (userbuf->axlevel >= 6)
150 && (roombuf->QRflags & QR_MAILBOX) ) {
151 retval = retval | UA_GOTOALLOWED;
154 NEWMSG: /* By the way, we also check for the presence of new messages */
155 if (is_msg_in_mset(vbuf.v_seen, roombuf->QRhighest) == 0) {
156 retval = retval | UA_HASNEWMSGS;
159 /* System rooms never show up in the list. */
160 if (roombuf->QRflags2 & QR2_SYSTEM) {
161 retval = retval & ~UA_KNOWN;
165 /* Now give the caller the information it wants. */
166 if (result != NULL) *result = retval;
167 if (view != NULL) *view = vbuf.v_view;
171 * Self-checking stuff for a room record read into memory
173 void room_sanity_check(struct ctdlroom *qrbuf)
175 /* Mailbox rooms are always on the lowest floor */
176 if (qrbuf->QRflags & QR_MAILBOX) {
179 /* Listing order of 0 is illegal except for base rooms */
180 if (qrbuf->QRorder == 0)
181 if (!(qrbuf->QRflags & QR_MAILBOX) &&
182 strncasecmp(qrbuf->QRname, config.c_baseroom, ROOMNAMELEN)
184 strncasecmp(qrbuf->QRname, config.c_aideroom, ROOMNAMELEN))
190 * getroom() - retrieve room data from disk
192 int getroom(struct ctdlroom *qrbuf, char *room_name)
194 struct cdbdata *cdbqr;
195 char lowercase_name[ROOMNAMELEN];
196 char personal_lowercase_name[ROOMNAMELEN];
199 for (a = 0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
200 lowercase_name[a] = tolower(room_name[a]);
202 lowercase_name[a] = 0;
204 memset(qrbuf, 0, sizeof(struct ctdlroom));
206 /* First, try the public namespace */
207 cdbqr = cdb_fetch(CDB_ROOMS,
208 lowercase_name, strlen(lowercase_name));
210 /* If that didn't work, try the user's personal namespace */
212 snprintf(personal_lowercase_name,
213 sizeof personal_lowercase_name, "%010ld.%s",
214 CC->user.usernum, lowercase_name);
215 cdbqr = cdb_fetch(CDB_ROOMS,
216 personal_lowercase_name,
217 strlen(personal_lowercase_name));
220 memcpy(qrbuf, cdbqr->ptr,
221 ((cdbqr->len > sizeof(struct ctdlroom)) ?
222 sizeof(struct ctdlroom) : cdbqr->len));
225 room_sanity_check(qrbuf);
234 * lgetroom() - same as getroom() but locks the record (if supported)
236 int lgetroom(struct ctdlroom *qrbuf, char *room_name)
239 retval = getroom(qrbuf, room_name);
240 if (retval == 0) begin_critical_section(S_ROOMS);
246 * b_putroom() - back end to putroom() and b_deleteroom()
247 * (if the supplied buffer is NULL, delete the room record)
249 void b_putroom(struct ctdlroom *qrbuf, char *room_name)
251 char lowercase_name[ROOMNAMELEN];
254 for (a = 0; a <= strlen(room_name); ++a) {
255 lowercase_name[a] = tolower(room_name[a]);
259 cdb_delete(CDB_ROOMS,
260 lowercase_name, strlen(lowercase_name));
262 time(&qrbuf->QRmtime);
264 lowercase_name, strlen(lowercase_name),
265 qrbuf, sizeof(struct ctdlroom));
271 * putroom() - store room data to disk
273 void putroom(struct ctdlroom *qrbuf) {
274 b_putroom(qrbuf, qrbuf->QRname);
279 * b_deleteroom() - delete a room record from disk
281 void b_deleteroom(char *room_name) {
282 b_putroom(NULL, room_name);
288 * lputroom() - same as putroom() but unlocks the record (if supported)
290 void lputroom(struct ctdlroom *qrbuf)
294 end_critical_section(S_ROOMS);
298 /****************************************************************************/
301 * getfloor() - retrieve floor data from disk
303 void getfloor(struct floor *flbuf, int floor_num)
305 struct cdbdata *cdbfl;
307 memset(flbuf, 0, sizeof(struct floor));
308 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
310 memcpy(flbuf, cdbfl->ptr,
311 ((cdbfl->len > sizeof(struct floor)) ?
312 sizeof(struct floor) : cdbfl->len));
315 if (floor_num == 0) {
316 safestrncpy(flbuf->f_name, "Main Floor",
317 sizeof flbuf->f_name);
318 flbuf->f_flags = F_INUSE;
319 flbuf->f_ref_count = 3;
326 * lgetfloor() - same as getfloor() but locks the record (if supported)
328 void lgetfloor(struct floor *flbuf, int floor_num)
331 begin_critical_section(S_FLOORTAB);
332 getfloor(flbuf, floor_num);
337 * cgetfloor() - Get floor record from *cache* (loads from disk if needed)
339 * This is strictly a performance hack.
341 struct floor *cgetfloor(int floor_num) {
342 static int initialized = 0;
345 struct floor *fl = NULL;
347 begin_critical_section(S_FLOORCACHE);
348 if (initialized == 0) {
349 for (i=0; i<MAXFLOORS; ++i) {
350 floorcache[floor_num] = NULL;
354 if (floorcache[floor_num] == NULL) {
357 end_critical_section(S_FLOORCACHE);
360 lprintf(CTDL_DEBUG, "fetch_new is active ... going to disk\n");
361 fl = malloc(sizeof(struct floor));
362 getfloor(fl, floor_num);
363 begin_critical_section(S_FLOORCACHE);
364 if (floorcache[floor_num] != NULL) {
365 free(floorcache[floor_num]);
367 floorcache[floor_num] = fl;
368 end_critical_section(S_FLOORCACHE);
371 return(floorcache[floor_num]);
377 * putfloor() - store floor data on disk
379 void putfloor(struct floor *flbuf, int floor_num)
381 /* If we've cached this, clear it out, 'cuz it's WRONG now! */
382 begin_critical_section(S_FLOORCACHE);
383 if (floorcache[floor_num] != NULL) {
384 free(floorcache[floor_num]);
385 floorcache[floor_num] = malloc(sizeof(struct floor));
386 memcpy(floorcache[floor_num], flbuf, sizeof(struct floor));
388 end_critical_section(S_FLOORCACHE);
390 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
391 flbuf, sizeof(struct floor));
396 * lputfloor() - same as putfloor() but unlocks the record (if supported)
398 void lputfloor(struct floor *flbuf, int floor_num)
401 putfloor(flbuf, floor_num);
402 end_critical_section(S_FLOORTAB);
408 * Traverse the room file...
410 void ForEachRoom(void (*CallBack) (struct ctdlroom *EachRoom, void *out_data),
413 struct ctdlroom qrbuf;
414 struct cdbdata *cdbqr;
416 cdb_rewind(CDB_ROOMS);
418 while (cdbqr = cdb_next_item(CDB_ROOMS), cdbqr != NULL) {
419 memset(&qrbuf, 0, sizeof(struct ctdlroom));
420 memcpy(&qrbuf, cdbqr->ptr,
421 ((cdbqr->len > sizeof(struct ctdlroom)) ?
422 sizeof(struct ctdlroom) : cdbqr->len));
424 room_sanity_check(&qrbuf);
425 if (qrbuf.QRflags & QR_INUSE)
426 (*CallBack)(&qrbuf, in_data);
432 * delete_msglist() - delete room message pointers
434 void delete_msglist(struct ctdlroom *whichroom)
436 struct cdbdata *cdbml;
438 /* Make sure the msglist we're deleting actually exists, otherwise
439 * gdbm will complain when we try to delete an invalid record
441 cdbml = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
445 /* Go ahead and delete it */
446 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
454 * sort message pointers
455 * (returns new msg count)
457 int sort_msglist(long listptrs[], int oldcount)
468 for (a = numitems - 2; a >= 0; --a) {
469 for (b = 0; b <= a; ++b) {
470 if (listptrs[b] > (listptrs[b + 1])) {
472 hold2 = listptrs[b + 1];
474 listptrs[b + 1] = hold1;
479 /* and yank any nulls */
480 while ((numitems > 0) && (listptrs[0] == 0L)) {
481 memcpy(&listptrs[0], &listptrs[1],
482 (sizeof(long) * (numitems - 1)));
491 * Determine whether a given room is non-editable.
493 int is_noneditable(struct ctdlroom *qrbuf)
496 /* Mail> rooms are non-editable */
497 if ( (qrbuf->QRflags & QR_MAILBOX)
498 && (!strcasecmp(&qrbuf->QRname[11], MAILROOM)) )
501 /* Everything else is editable */
508 * Back-back-end for all room listing commands
510 void list_roomname(struct ctdlroom *qrbuf, int ra, int view)
512 char truncated_roomname[ROOMNAMELEN];
514 /* For my own mailbox rooms, chop off the owner prefix */
515 if ( (qrbuf->QRflags & QR_MAILBOX)
516 && (atol(qrbuf->QRname) == CC->user.usernum) ) {
517 strcpy(truncated_roomname, qrbuf->QRname);
518 strcpy(truncated_roomname, &truncated_roomname[11]);
519 cprintf("%s", truncated_roomname);
521 /* For all other rooms, just display the name in its entirety */
523 cprintf("%s", qrbuf->QRname);
526 /* ...and now the other parameters */
527 cprintf("|%u|%d|%d|%d|%d|%d|\n",
529 (int) qrbuf->QRfloor,
530 (int) qrbuf->QRorder,
531 (int) qrbuf->QRflags2,
539 * cmd_lrms() - List all accessible rooms, known or forgotten
541 void cmd_lrms_backend(struct ctdlroom *qrbuf, void *data)
543 int FloorBeingSearched = (-1);
547 FloorBeingSearched = *(int *)data;
548 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
550 if ((( ra & (UA_KNOWN | UA_ZAPPED)))
551 && ((qrbuf->QRfloor == (FloorBeingSearched))
552 || ((FloorBeingSearched) < 0)))
553 list_roomname(qrbuf, ra, view);
556 void cmd_lrms(char *argbuf)
558 int FloorBeingSearched = (-1);
559 if (strlen(argbuf) > 0)
560 FloorBeingSearched = extract_int(argbuf, 0);
562 if (CtdlAccessCheck(ac_logged_in)) return;
564 if (getuser(&CC->user, CC->curr_user)) {
565 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
568 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
570 ForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
577 * cmd_lkra() - List all known rooms
579 void cmd_lkra_backend(struct ctdlroom *qrbuf, void *data)
581 int FloorBeingSearched = (-1);
585 FloorBeingSearched = *(int *)data;
586 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
588 if ((( ra & (UA_KNOWN)))
589 && ((qrbuf->QRfloor == (FloorBeingSearched))
590 || ((FloorBeingSearched) < 0)))
591 list_roomname(qrbuf, ra, view);
594 void cmd_lkra(char *argbuf)
596 int FloorBeingSearched = (-1);
597 if (strlen(argbuf) > 0)
598 FloorBeingSearched = extract_int(argbuf, 0);
600 if (CtdlAccessCheck(ac_logged_in)) return;
602 if (getuser(&CC->user, CC->curr_user)) {
603 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
606 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
608 ForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
614 void cmd_lprm_backend(struct ctdlroom *qrbuf, void *data)
616 int FloorBeingSearched = (-1);
620 FloorBeingSearched = *(int *)data;
621 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
623 if ( ((qrbuf->QRflags & QR_PRIVATE) == 0)
624 && ((qrbuf->QRflags & QR_MAILBOX) == 0)
625 && ((qrbuf->QRfloor == (FloorBeingSearched))
626 || ((FloorBeingSearched) < 0)))
627 list_roomname(qrbuf, ra, view);
630 void cmd_lprm(char *argbuf)
632 int FloorBeingSearched = (-1);
633 if (strlen(argbuf) > 0)
634 FloorBeingSearched = extract_int(argbuf, 0);
636 cprintf("%d Publiic rooms:\n", LISTING_FOLLOWS);
638 ForEachRoom(cmd_lprm_backend, &FloorBeingSearched);
645 * cmd_lkrn() - List all known rooms with new messages
647 void cmd_lkrn_backend(struct ctdlroom *qrbuf, void *data)
649 int FloorBeingSearched = (-1);
653 FloorBeingSearched = *(int *)data;
654 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
657 && (ra & UA_HASNEWMSGS)
658 && ((qrbuf->QRfloor == (FloorBeingSearched))
659 || ((FloorBeingSearched) < 0)))
660 list_roomname(qrbuf, ra, view);
663 void cmd_lkrn(char *argbuf)
665 int FloorBeingSearched = (-1);
666 if (strlen(argbuf) > 0)
667 FloorBeingSearched = extract_int(argbuf, 0);
669 if (CtdlAccessCheck(ac_logged_in)) return;
671 if (getuser(&CC->user, CC->curr_user)) {
672 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
675 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
677 ForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
684 * cmd_lkro() - List all known rooms
686 void cmd_lkro_backend(struct ctdlroom *qrbuf, void *data)
688 int FloorBeingSearched = (-1);
692 FloorBeingSearched = *(int *)data;
693 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
696 && ((ra & UA_HASNEWMSGS) == 0)
697 && ((qrbuf->QRfloor == (FloorBeingSearched))
698 || ((FloorBeingSearched) < 0)))
699 list_roomname(qrbuf, ra, view);
702 void cmd_lkro(char *argbuf)
704 int FloorBeingSearched = (-1);
705 if (strlen(argbuf) > 0)
706 FloorBeingSearched = extract_int(argbuf, 0);
708 if (CtdlAccessCheck(ac_logged_in)) return;
710 if (getuser(&CC->user, CC->curr_user)) {
711 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
714 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
716 ForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
723 * cmd_lzrm() - List all forgotten rooms
725 void cmd_lzrm_backend(struct ctdlroom *qrbuf, void *data)
727 int FloorBeingSearched = (-1);
731 FloorBeingSearched = *(int *)data;
732 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
734 if ((ra & UA_GOTOALLOWED)
736 && ((qrbuf->QRfloor == (FloorBeingSearched))
737 || ((FloorBeingSearched) < 0)))
738 list_roomname(qrbuf, ra, view);
741 void cmd_lzrm(char *argbuf)
743 int FloorBeingSearched = (-1);
744 if (strlen(argbuf) > 0)
745 FloorBeingSearched = extract_int(argbuf, 0);
747 if (CtdlAccessCheck(ac_logged_in)) return;
749 if (getuser(&CC->user, CC->curr_user)) {
750 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
753 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
755 ForEachRoom(cmd_lzrm_backend, &FloorBeingSearched);
761 * Make the specified room the current room for this session. No validation
762 * or access control is done here -- the caller should make sure that the
763 * specified room exists and is ok to access.
765 void usergoto(char *where, int display_result, int transiently,
766 int *retmsgs, int *retnew)
769 int new_messages = 0;
770 int total_messages = 0;
774 int newmailcount = 0;
776 char truncated_roomname[ROOMNAMELEN];
777 struct cdbdata *cdbfr;
778 long *msglist = NULL;
780 unsigned int original_v_flags;
782 /* If the supplied room name is NULL, the caller wants us to know that
783 * it has already copied the room record into CC->room, so
784 * we can skip the extra database fetch.
787 safestrncpy(CC->room.QRname, where, sizeof CC->room.QRname);
788 getroom(&CC->room, where);
791 /* Take care of all the formalities. */
793 begin_critical_section(S_USERS);
794 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
795 original_v_flags = vbuf.v_flags;
797 /* Know the room ... but not if it's the page log room, or if the
798 * caller specified that we're only entering this room transiently.
800 if ((strcasecmp(CC->room.QRname, config.c_logpages))
801 && (transiently == 0) ) {
802 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
803 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
806 /* Only rewrite the database record if we changed something */
807 if (vbuf.v_flags != original_v_flags) {
808 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
810 end_critical_section(S_USERS);
812 /* Check for new mail */
813 newmailcount = NewMailCount();
815 /* set info to 1 if the user needs to read the room's info file */
816 if (CC->room.QRinfo > vbuf.v_lastseen) {
821 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
823 msglist = malloc(cdbfr->len);
824 memcpy(msglist, cdbfr->ptr, cdbfr->len);
825 num_msgs = cdbfr->len / sizeof(long);
829 if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
830 if (msglist[a] > 0L) {
832 if (is_msg_in_mset(vbuf.v_seen, msglist[a]) == 0) {
838 if (msglist != NULL) free(msglist);
840 if (CC->room.QRflags & QR_MAILBOX)
845 if ((CC->room.QRroomaide == CC->user.usernum)
846 || (CC->user.axlevel >= 6))
851 strcpy(truncated_roomname, CC->room.QRname);
852 if ( (CC->room.QRflags & QR_MAILBOX)
853 && (atol(CC->room.QRname) == CC->user.usernum) ) {
854 strcpy(truncated_roomname, &truncated_roomname[11]);
857 if (retmsgs != NULL) *retmsgs = total_messages;
858 if (retnew != NULL) *retnew = new_messages;
859 lprintf(CTDL_DEBUG, "<%s> %d new of %d total messages\n",
861 new_messages, total_messages
864 CC->curr_view = (int)vbuf.v_view;
866 if (display_result) {
867 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d|%d|%d|\n",
868 CIT_OK, CtdlCheckExpress(),
873 (int)CC->room.QRflags,
874 (long)CC->room.QRhighest,
875 (long)vbuf.v_lastseen,
879 (int)CC->room.QRfloor,
881 (int)CC->room.QRdefaultview
888 * cmd_goto() - goto a new room
890 void cmd_goto(char *gargs)
892 struct ctdlroom QRscratch;
896 char augmented_roomname[SIZ];
901 if (CtdlAccessCheck(ac_logged_in)) return;
903 extract(towhere, gargs, 0);
904 extract(password, gargs, 1);
905 transiently = extract_int(gargs, 2);
907 getuser(&CC->user, CC->curr_user);
909 if (!strcasecmp(towhere, "_BASEROOM_"))
910 strcpy(towhere, config.c_baseroom);
912 if (!strcasecmp(towhere, "_MAIL_"))
913 strcpy(towhere, MAILROOM);
915 if (!strcasecmp(towhere, "_BITBUCKET_"))
916 strcpy(towhere, config.c_twitroom);
919 /* First try a regular match */
920 c = getroom(&QRscratch, towhere);
922 /* Then try a mailbox name match */
924 MailboxName(augmented_roomname, sizeof augmented_roomname,
926 c = getroom(&QRscratch, augmented_roomname);
928 strcpy(towhere, augmented_roomname);
931 /* And if the room was found... */
934 /* Let internal programs go directly to any room. */
935 if (CC->internal_pgm) {
936 memcpy(&CC->room, &QRscratch,
937 sizeof(struct ctdlroom));
938 usergoto(NULL, 1, transiently, NULL, NULL);
942 /* See if there is an existing user/room relationship */
943 CtdlRoomAccess(&QRscratch, &CC->user, &ra, NULL);
945 /* normal clients have to pass through security */
946 if (ra & UA_GOTOALLOWED) {
951 if ((QRscratch.QRflags & QR_MAILBOX) &&
952 ((ra & UA_GOTOALLOWED))) {
953 memcpy(&CC->room, &QRscratch,
954 sizeof(struct ctdlroom));
955 usergoto(NULL, 1, transiently, NULL, NULL);
957 } else if ((QRscratch.QRflags & QR_PASSWORDED) &&
958 ((ra & UA_KNOWN) == 0) &&
959 (strcasecmp(QRscratch.QRpasswd, password)) &&
960 (CC->user.axlevel < 6)
962 cprintf("%d wrong or missing passwd\n",
963 ERROR + PASSWORD_REQUIRED);
965 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
966 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
967 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
968 ((ra & UA_KNOWN) == 0) &&
969 (CC->user.axlevel < 6)
971 lprintf(CTDL_DEBUG, "Failed to acquire private room\n");
973 memcpy(&CC->room, &QRscratch,
974 sizeof(struct ctdlroom));
975 usergoto(NULL, 1, transiently, NULL, NULL);
981 cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
987 struct ctdluser temp;
988 struct cdbdata *cdbus;
991 getuser(&CC->user, CC->curr_user);
994 * This command is only allowed by aides, room aides,
995 * and room namespace owners
998 || (atol(CC->room.QRname) == CC->user.usernum) ) {
1003 cprintf("%d Higher access or room ownership required.\n",
1004 ERROR + HIGHER_ACCESS_REQUIRED);
1008 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
1009 cdb_rewind(CDB_USERS);
1010 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1011 memset(&temp, 0, sizeof temp);
1012 memcpy(&temp, cdbus->ptr, sizeof temp);
1015 CtdlRoomAccess(&CC->room, &temp, &ra, NULL);
1016 if ((CC->room.QRflags & QR_INUSE)
1019 cprintf("%s\n", temp.fullname);
1026 * RDIR command for room directory
1034 struct stat statbuf;
1036 if (CtdlAccessCheck(ac_logged_in)) return;
1038 getroom(&CC->room, CC->room.QRname);
1039 getuser(&CC->user, CC->curr_user);
1041 if ((CC->room.QRflags & QR_DIRECTORY) == 0) {
1042 cprintf("%d not here.\n", ERROR + NOT_HERE);
1045 if (((CC->room.QRflags & QR_VISDIR) == 0)
1046 && (CC->user.axlevel < 6)
1047 && (CC->user.usernum != CC->room.QRroomaide)) {
1048 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
1051 cprintf("%d %s|%s/files/%s\n",
1052 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->room.QRdirname);
1054 snprintf(buf, sizeof buf, "ls %s/files/%s >%s 2> /dev/null",
1055 BBSDIR, CC->room.QRdirname, CC->temp);
1058 snprintf(buf, sizeof buf, "%s/files/%s/filedir", BBSDIR, CC->room.QRdirname);
1059 fd = fopen(buf, "r");
1061 fd = fopen("/dev/null", "r");
1063 ls = fopen(CC->temp, "r");
1064 while (fgets(flnm, sizeof flnm, ls) != NULL) {
1065 flnm[strlen(flnm) - 1] = 0;
1066 if (strcasecmp(flnm, "filedir")) {
1067 snprintf(buf, sizeof buf, "%s/files/%s/%s",
1068 BBSDIR, CC->room.QRdirname, flnm);
1069 stat(buf, &statbuf);
1070 strcpy(comment, "");
1072 while ((fgets(buf, sizeof buf, fd) != NULL)
1073 && (strlen(comment) == 0)) {
1074 buf[strlen(buf) - 1] = 0;
1075 if ((!strncasecmp(buf, flnm, strlen(flnm)))
1076 && (buf[strlen(flnm)] == ' '))
1077 safestrncpy(comment,
1078 &buf[strlen(flnm) + 1],
1081 cprintf("%s|%ld|%s\n", flnm, (long)statbuf.st_size, comment);
1092 * get room parameters (aide or room aide command)
1096 if (CtdlAccessCheck(ac_room_aide)) return;
1098 getroom(&CC->room, CC->room.QRname);
1099 cprintf("%d%c%s|%s|%s|%d|%d|%d|%d|%d|\n",
1103 ((CC->room.QRflags & QR_MAILBOX) ?
1104 &CC->room.QRname[11] : CC->room.QRname),
1106 ((CC->room.QRflags & QR_PASSWORDED) ?
1107 CC->room.QRpasswd : ""),
1109 ((CC->room.QRflags & QR_DIRECTORY) ?
1110 CC->room.QRdirname : ""),
1113 (int) CC->room.QRfloor,
1114 (int) CC->room.QRorder,
1116 CC->room.QRdefaultview,
1123 * Back end function to rename a room.
1124 * You can also specify which floor to move the room to, or specify -1 to
1125 * keep the room on the same floor it was on.
1127 * If you are renaming a mailbox room, you must supply the namespace prefix
1128 * in *at least* the old name!
1130 int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) {
1132 struct ctdlroom qrbuf;
1133 struct ctdlroom qrtmp;
1138 char actual_old_name[SIZ];
1140 lprintf(CTDL_DEBUG, "CtdlRenameRoom(%s, %s, %d)\n",
1141 old_name, new_name, new_floor);
1143 if (new_floor >= 0) {
1144 fl = cgetfloor(new_floor);
1145 if ((fl->f_flags & F_INUSE) == 0) {
1146 return(crr_invalid_floor);
1150 begin_critical_section(S_ROOMS);
1152 if ( (getroom(&qrtmp, new_name) == 0)
1153 && (strcasecmp(new_name, old_name)) ) {
1154 ret = crr_already_exists;
1157 else if (getroom(&qrbuf, old_name) != 0) {
1158 ret = crr_room_not_found;
1161 else if ( (CC->user.axlevel < 6)
1162 && (CC->user.usernum != qrbuf.QRroomaide)
1163 && ( (((qrbuf.QRflags & QR_MAILBOX) == 0) || (atol(qrbuf.QRname) != CC->user.usernum))) ) {
1164 ret = crr_access_denied;
1167 else if (is_noneditable(&qrbuf)) {
1168 ret = crr_noneditable;
1173 strcpy(actual_old_name, qrbuf.QRname);
1174 if (qrbuf.QRflags & QR_MAILBOX) {
1175 owner = atol(qrbuf.QRname);
1177 if ( (owner > 0L) && (atol(new_name) == 0L) ) {
1178 snprintf(qrbuf.QRname, sizeof(qrbuf.QRname),
1179 "%010ld.%s", owner, new_name);
1182 safestrncpy(qrbuf.QRname, new_name,
1183 sizeof(qrbuf.QRname));
1186 /* Reject change of floor for baseroom/aideroom */
1187 if (!strncasecmp(old_name, config.c_baseroom, ROOMNAMELEN) ||
1188 !strncasecmp(old_name, config.c_aideroom, ROOMNAMELEN)) {
1192 /* Take care of floor stuff */
1193 old_floor = qrbuf.QRfloor;
1194 if (new_floor < 0) {
1195 new_floor = old_floor;
1197 qrbuf.QRfloor = new_floor;
1200 begin_critical_section(S_CONFIG);
1202 /* If baseroom/aideroom name changes, update config */
1203 if (!strncasecmp(old_name, config.c_baseroom, ROOMNAMELEN)) {
1204 safestrncpy(config.c_baseroom, new_name, ROOMNAMELEN);
1207 if (!strncasecmp(old_name, config.c_aideroom, ROOMNAMELEN)) {
1208 safestrncpy(config.c_aideroom, new_name, ROOMNAMELEN);
1212 end_critical_section(S_CONFIG);
1214 /* If the room name changed, then there are now two room
1215 * records, so we have to delete the old one.
1217 if (strcasecmp(new_name, old_name)) {
1218 b_deleteroom(actual_old_name);
1224 end_critical_section(S_ROOMS);
1226 /* Adjust the floor reference counts if necessary */
1227 if (new_floor != old_floor) {
1228 lgetfloor(&flbuf, old_floor);
1229 --flbuf.f_ref_count;
1230 lputfloor(&flbuf, old_floor);
1231 lprintf(CTDL_DEBUG, "Reference count for floor %d is now %d\n", old_floor, flbuf.f_ref_count);
1232 lgetfloor(&flbuf, new_floor);
1233 ++flbuf.f_ref_count;
1234 lputfloor(&flbuf, new_floor);
1235 lprintf(CTDL_DEBUG, "Reference count for floor %d is now %d\n", new_floor, flbuf.f_ref_count);
1238 /* ...and everybody say "YATTA!" */
1244 * set room parameters (aide or room aide command)
1246 void cmd_setr(char *args)
1252 char new_name[ROOMNAMELEN];
1254 if (CtdlAccessCheck(ac_logged_in)) return;
1256 if (num_parms(args) >= 6) {
1257 new_floor = extract_int(args, 5);
1259 new_floor = (-1); /* don't change the floor */
1262 /* When is a new name more than just a new name? When the old name
1263 * has a namespace prefix.
1265 if (CC->room.QRflags & QR_MAILBOX) {
1266 sprintf(new_name, "%010ld.", atol(CC->room.QRname) );
1268 strcpy(new_name, "");
1270 extract(&new_name[strlen(new_name)], args, 0);
1272 r = CtdlRenameRoom(CC->room.QRname, new_name, new_floor);
1274 if (r == crr_room_not_found) {
1275 cprintf("%d Internal error - room not found?\n", ERROR + INTERNAL_ERROR);
1276 } else if (r == crr_already_exists) {
1277 cprintf("%d '%s' already exists.\n",
1278 ERROR + ALREADY_EXISTS, new_name);
1279 } else if (r == crr_noneditable) {
1280 cprintf("%d Cannot edit this room.\n", ERROR + NOT_HERE);
1281 } else if (r == crr_invalid_floor) {
1282 cprintf("%d Target floor does not exist.\n",
1283 ERROR + INVALID_FLOOR_OPERATION);
1284 } else if (r == crr_access_denied) {
1285 cprintf("%d You do not have permission to edit '%s'\n",
1286 ERROR + HIGHER_ACCESS_REQUIRED,
1288 } else if (r != crr_ok) {
1289 cprintf("%d Error: CtdlRenameRoom() returned %d\n",
1290 ERROR + INTERNAL_ERROR, r);
1297 getroom(&CC->room, new_name);
1299 /* Now we have to do a bunch of other stuff */
1301 if (num_parms(args) >= 7) {
1302 new_order = extract_int(args, 6);
1305 if (new_order > 127)
1309 lgetroom(&CC->room, CC->room.QRname);
1311 /* Directory room */
1312 extract(buf, args, 2);
1314 safestrncpy(CC->room.QRdirname, buf,
1315 sizeof CC->room.QRdirname);
1318 if (num_parms(args) >= 8) {
1319 CC->room.QRdefaultview = extract_int(args, 7);
1322 /* Second set of flags */
1323 if (num_parms(args) >= 9) {
1324 CC->room.QRflags2 = extract_int(args, 8);
1328 CC->room.QRflags = (extract_int(args, 3) | QR_INUSE);
1329 /* Clean up a client boo-boo: if the client set the room to
1330 * guess-name or passworded, ensure that the private flag is
1333 if ((CC->room.QRflags & QR_GUESSNAME)
1334 || (CC->room.QRflags & QR_PASSWORDED))
1335 CC->room.QRflags |= QR_PRIVATE;
1337 /* Some changes can't apply to BASEROOM */
1338 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1340 CC->room.QRorder = 0;
1341 CC->room.QRpasswd[0] = '\0';
1342 CC->room.QRflags &= ~(QR_PRIVATE & QR_PASSWORDED &
1343 QR_GUESSNAME & QR_PREFONLY & QR_MAILBOX);
1344 CC->room.QRflags |= QR_PERMANENT;
1346 /* March order (doesn't apply to AIDEROOM) */
1347 if (num_parms(args) >= 7)
1348 CC->room.QRorder = (char) new_order;
1350 extract(buf, args, 1);
1352 safestrncpy(CC->room.QRpasswd, buf,
1353 sizeof CC->room.QRpasswd);
1354 /* Kick everyone out if the client requested it
1355 * (by changing the room's generation number)
1357 if (extract_int(args, 4)) {
1358 time(&CC->room.QRgen);
1361 /* Some changes can't apply to AIDEROOM */
1362 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1364 CC->room.QRorder = 0;
1365 CC->room.QRflags &= ~QR_MAILBOX;
1366 CC->room.QRflags |= QR_PERMANENT;
1369 /* Write the room record back to disk */
1370 lputroom(&CC->room);
1372 /* Create a room directory if necessary */
1373 if (CC->room.QRflags & QR_DIRECTORY) {
1374 snprintf(buf, sizeof buf, "./files/%s",
1375 CC->room.QRdirname);
1378 snprintf(buf, sizeof buf, "%s> edited by %s\n", CC->room.QRname, CC->curr_user);
1380 cprintf("%d Ok\n", CIT_OK);
1386 * get the name of the room aide for this room
1390 struct ctdluser usbuf;
1392 if (CtdlAccessCheck(ac_logged_in)) return;
1394 if (getuserbynumber(&usbuf, CC->room.QRroomaide) == 0) {
1395 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1397 cprintf("%d \n", CIT_OK);
1403 * set the room aide for this room
1405 void cmd_seta(char *new_ra)
1407 struct ctdluser usbuf;
1412 if (CtdlAccessCheck(ac_room_aide)) return;
1414 if (getuser(&usbuf, new_ra) != 0) {
1417 newu = usbuf.usernum;
1420 lgetroom(&CC->room, CC->room.QRname);
1422 if (CC->room.QRroomaide != newu) {
1425 CC->room.QRroomaide = newu;
1426 lputroom(&CC->room);
1429 * We have to post the change notice _after_ writing changes to
1430 * the room table, otherwise it would deadlock!
1432 if (post_notice == 1) {
1433 if (strlen(usbuf.fullname) > 0)
1434 snprintf(buf, sizeof buf,
1435 "%s is now room aide for %s>\n",
1436 usbuf.fullname, CC->room.QRname);
1438 snprintf(buf, sizeof buf,
1439 "There is now no room aide for %s>\n",
1443 cprintf("%d Ok\n", CIT_OK);
1447 * Generate an associated file name for a room
1449 void assoc_file_name(char *buf, size_t n,
1450 struct ctdlroom *qrbuf, const char *prefix)
1452 snprintf(buf, n, "./%s/%ld", prefix, qrbuf->QRnumber);
1456 * retrieve info file for this room
1464 assoc_file_name(filename, sizeof filename, &CC->room, "info");
1465 info_fp = fopen(filename, "r");
1467 if (info_fp == NULL) {
1468 cprintf("%d No info file.\n", ERROR + FILE_NOT_FOUND);
1471 cprintf("%d Info:\n", LISTING_FOLLOWS);
1472 while (fgets(buf, sizeof buf, info_fp) != NULL) {
1473 if (strlen(buf) > 0)
1474 buf[strlen(buf) - 1] = 0;
1475 cprintf("%s\n", buf);
1482 * Back end processing to delete a room and everything associated with it
1484 void delete_room(struct ctdlroom *qrbuf)
1489 lprintf(CTDL_NOTICE, "Deleting room <%s>\n", qrbuf->QRname);
1491 /* Delete the info file */
1492 assoc_file_name(filename, sizeof filename, qrbuf, "info");
1495 /* Delete the image file */
1496 assoc_file_name(filename, sizeof filename, qrbuf, "images");
1499 /* Delete the room's network config file */
1500 assoc_file_name(filename, sizeof filename, qrbuf, "netconfigs");
1503 /* Delete the messages in the room
1504 * (Careful: this opens an S_ROOMS critical section!)
1506 CtdlDeleteMessages(qrbuf->QRname, 0L, "");
1508 /* Flag the room record as not in use */
1509 lgetroom(qrbuf, qrbuf->QRname);
1513 /* then decrement the reference count for the floor */
1514 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1515 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1516 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1518 /* Delete the room record from the database! */
1519 b_deleteroom(qrbuf->QRname);
1525 * Check access control for deleting a room
1527 int CtdlDoIHavePermissionToDeleteThisRoom(struct ctdlroom *qr) {
1529 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
1533 if (is_noneditable(qr)) {
1538 * For mailboxes, check stuff
1540 if (qr->QRflags & QR_MAILBOX) {
1542 if (strlen(qr->QRname) < 12) return(0); /* bad name */
1544 if (atol(qr->QRname) != CC->user.usernum) {
1545 return(0); /* not my room */
1548 /* Can't delete your Mail> room */
1549 if (!strcasecmp(&qr->QRname[12], MAILROOM)) return(0);
1551 /* Otherwise it's ok */
1556 * For normal rooms, just check for aide or room aide status.
1558 return(is_room_aide());
1562 * aide command: kill the current room
1564 void cmd_kill(char *argbuf)
1566 char deleted_room_name[ROOMNAMELEN];
1570 kill_ok = extract_int(argbuf, 0);
1572 if (CtdlDoIHavePermissionToDeleteThisRoom(&CC->room) == 0) {
1573 cprintf("%d Can't delete this room.\n", ERROR + NOT_HERE);
1577 if (CC->room.QRflags & QR_MAILBOX) {
1578 strcpy(deleted_room_name, &CC->room.QRname[11]);
1581 strcpy(deleted_room_name, CC->room.QRname);
1584 /* Do the dirty work */
1585 delete_room(&CC->room);
1587 /* Return to the Lobby */
1588 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
1590 /* tell the world what we did */
1591 snprintf(msg, sizeof msg, "%s> killed by %s\n",
1592 deleted_room_name, CC->curr_user);
1594 cprintf("%d '%s' deleted.\n", CIT_OK, deleted_room_name);
1596 cprintf("%d ok to delete.\n", CIT_OK);
1602 * Internal code to create a new room (returns room flags)
1604 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only,
1605 * 4=mailbox, 5=mailbox, but caller supplies namespace
1607 unsigned create_room(char *new_room_name,
1609 char *new_room_pass,
1616 struct ctdlroom qrbuf;
1620 lprintf(CTDL_DEBUG, "create_room(%s)\n", new_room_name);
1621 if (getroom(&qrbuf, new_room_name) == 0) {
1622 lprintf(CTDL_DEBUG, "%s already exists.\n", new_room_name);
1623 return (0); /* already exists */
1627 memset(&qrbuf, 0, sizeof(struct ctdlroom));
1628 safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
1629 qrbuf.QRflags = QR_INUSE;
1630 if (new_room_type > 0)
1631 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1632 if (new_room_type == 1)
1633 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1634 if (new_room_type == 2)
1635 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1636 if ( (new_room_type == 4) || (new_room_type == 5) )
1637 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1639 /* If the user is requesting a personal room, set up the room
1640 * name accordingly (prepend the user number)
1642 if (new_room_type == 4) {
1643 MailboxName(qrbuf.QRname, sizeof qrbuf.QRname, &CC->user, new_room_name);
1646 safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
1649 /* If the room is private, and the system administrator has elected
1650 * to automatically grant room aide privileges, do so now; otherwise,
1651 * set the room aide to undefined.
1653 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1654 qrbuf.QRroomaide = CC->user.usernum;
1656 qrbuf.QRroomaide = (-1L);
1660 * If the caller is only interested in testing whether this will work,
1661 * return now without creating the room.
1663 if (!really_create) return (qrbuf.QRflags);
1665 qrbuf.QRnumber = get_new_room_number();
1666 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1667 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1668 qrbuf.QRfloor = new_room_floor;
1669 qrbuf.QRdefaultview = new_room_view;
1671 /* save what we just did... */
1674 /* bump the reference count on whatever floor the room is on */
1675 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1676 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1677 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1679 /* Grant the creator access to the room unless the avoid_access
1680 * parameter was specified.
1682 if (avoid_access == 0) {
1683 lgetuser(&CC->user, CC->curr_user);
1684 CtdlGetRelationship(&vbuf, &CC->user, &qrbuf);
1685 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1686 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1687 CtdlSetRelationship(&vbuf, &CC->user, &qrbuf);
1688 lputuser(&CC->user);
1691 /* resume our happy day */
1692 return (qrbuf.QRflags);
1699 void cmd_cre8(char *args)
1702 char new_room_name[SIZ];
1704 char new_room_pass[SIZ];
1710 int avoid_access = 0;
1712 cre8_ok = extract_int(args, 0);
1713 extract(new_room_name, args, 1);
1714 new_room_name[ROOMNAMELEN - 1] = 0;
1715 new_room_type = extract_int(args, 2);
1716 extract(new_room_pass, args, 3);
1717 avoid_access = extract_int(args, 5);
1718 new_room_view = extract_int(args, 6);
1719 new_room_pass[9] = 0;
1722 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1723 cprintf("%d Invalid room name.\n", ERROR + ILLEGAL_VALUE);
1727 if (!strcasecmp(new_room_name, MAILROOM)) {
1728 cprintf("%d '%s' already exists.\n",
1729 ERROR + ALREADY_EXISTS, new_room_name);
1733 if (num_parms(args) >= 5) {
1734 fl = cgetfloor(extract_int(args, 4));
1736 cprintf("%d Invalid floor number.\n",
1737 ERROR + INVALID_FLOOR_OPERATION);
1740 else if ((fl->f_flags & F_INUSE) == 0) {
1741 cprintf("%d Invalid floor number.\n",
1742 ERROR + INVALID_FLOOR_OPERATION);
1745 new_room_floor = extract_int(args, 4);
1749 if (CtdlAccessCheck(ac_logged_in)) return;
1751 if (CC->user.axlevel < config.c_createax) {
1752 cprintf("%d You need higher access to create rooms.\n",
1753 ERROR + HIGHER_ACCESS_REQUIRED);
1757 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1758 cprintf("%d Ok to create rooms.\n", CIT_OK);
1762 if ((new_room_type < 0) || (new_room_type > 5)) {
1763 cprintf("%d Invalid room type.\n", ERROR + ILLEGAL_VALUE);
1767 if (new_room_type == 5) {
1768 if (CC->user.axlevel < 6) {
1769 cprintf("%d Higher access required\n",
1770 ERROR + HIGHER_ACCESS_REQUIRED);
1775 /* Check to make sure the requested room name doesn't already exist */
1776 newflags = create_room(new_room_name,
1777 new_room_type, new_room_pass, new_room_floor,
1778 0, avoid_access, new_room_view);
1779 if (newflags == 0) {
1780 cprintf("%d '%s' already exists.\n",
1781 ERROR + ALREADY_EXISTS, new_room_name);
1786 cprintf("%d OK to create '%s'\n", CIT_OK, new_room_name);
1790 /* If we reach this point, the room needs to be created. */
1792 newflags = create_room(new_room_name,
1793 new_room_type, new_room_pass, new_room_floor, 1, 0,
1796 /* post a message in Aide> describing the new room */
1797 safestrncpy(aaa, new_room_name, sizeof aaa);
1798 strcat(aaa, "> created by ");
1799 strcat(aaa, CC->user.fullname);
1800 if (newflags & QR_MAILBOX)
1801 strcat(aaa, " [personal]");
1802 else if (newflags & QR_PRIVATE)
1803 strcat(aaa, " [private]");
1804 if (newflags & QR_GUESSNAME)
1805 strcat(aaa, "[guessname] ");
1806 if (newflags & QR_PASSWORDED) {
1807 strcat(aaa, "\n Password: ");
1808 strcat(aaa, new_room_pass);
1813 cprintf("%d '%s' has been created.\n", CIT_OK, new_room_name);
1818 void cmd_einf(char *ok)
1819 { /* enter info file for current room */
1821 char infofilename[SIZ];
1826 if (CtdlAccessCheck(ac_room_aide)) return;
1828 if (atoi(ok) == 0) {
1829 cprintf("%d Ok.\n", CIT_OK);
1832 assoc_file_name(infofilename, sizeof infofilename, &CC->room, "info");
1833 lprintf(CTDL_DEBUG, "opening\n");
1834 fp = fopen(infofilename, "w");
1835 lprintf(CTDL_DEBUG, "checking\n");
1837 cprintf("%d Cannot open %s: %s\n",
1838 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1841 cprintf("%d Send info...\n", SEND_LISTING);
1845 if (strcmp(buf, "000"))
1846 fprintf(fp, "%s\n", buf);
1847 } while (strcmp(buf, "000"));
1850 /* now update the room index so people will see our new info */
1851 lgetroom(&CC->room, CC->room.QRname); /* lock so no one steps on us */
1852 CC->room.QRinfo = CC->room.QRhighest + 1L;
1853 lputroom(&CC->room);
1858 * cmd_lflr() - List all known floors
1865 if (CtdlAccessCheck(ac_logged_in)) return;
1867 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1869 for (a = 0; a < MAXFLOORS; ++a) {
1870 getfloor(&flbuf, a);
1871 if (flbuf.f_flags & F_INUSE) {
1872 cprintf("%d|%s|%d\n",
1884 * create a new floor
1886 void cmd_cflr(char *argbuf)
1888 char new_floor_name[SIZ];
1891 int free_slot = (-1);
1894 extract(new_floor_name, argbuf, 0);
1895 cflr_ok = extract_int(argbuf, 1);
1897 if (CtdlAccessCheck(ac_aide)) return;
1899 if (strlen(new_floor_name) == 0) {
1900 cprintf("%d Blank floor name not allowed.\n",
1901 ERROR + ILLEGAL_VALUE);
1905 for (a = 0; a < MAXFLOORS; ++a) {
1906 getfloor(&flbuf, a);
1908 /* note any free slots while we're scanning... */
1909 if (((flbuf.f_flags & F_INUSE) == 0)
1913 /* check to see if it already exists */
1914 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1915 && (flbuf.f_flags & F_INUSE)) {
1916 cprintf("%d Floor '%s' already exists.\n",
1917 ERROR + ALREADY_EXISTS,
1923 if (free_slot < 0) {
1924 cprintf("%d There is no space available for a new floor.\n",
1925 ERROR + INVALID_FLOOR_OPERATION);
1929 cprintf("%d ok to create...\n", CIT_OK);
1932 lgetfloor(&flbuf, free_slot);
1933 flbuf.f_flags = F_INUSE;
1934 flbuf.f_ref_count = 0;
1935 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1936 lputfloor(&flbuf, free_slot);
1937 cprintf("%d %d\n", CIT_OK, free_slot);
1945 void cmd_kflr(char *argbuf)
1948 int floor_to_delete;
1952 floor_to_delete = extract_int(argbuf, 0);
1953 kflr_ok = extract_int(argbuf, 1);
1955 if (CtdlAccessCheck(ac_aide)) return;
1957 lgetfloor(&flbuf, floor_to_delete);
1960 if ((flbuf.f_flags & F_INUSE) == 0) {
1961 cprintf("%d Floor %d not in use.\n",
1962 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1965 if (flbuf.f_ref_count != 0) {
1966 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1967 ERROR + INVALID_FLOOR_OPERATION,
1972 cprintf("%d Ok\n", CIT_OK);
1974 cprintf("%d Ok to delete...\n", CIT_OK);
1981 if ((delete_ok == 1) && (kflr_ok == 1))
1983 lputfloor(&flbuf, floor_to_delete);
1989 void cmd_eflr(char *argbuf)
1995 np = num_parms(argbuf);
1997 cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
2001 if (CtdlAccessCheck(ac_aide)) return;
2003 floor_num = extract_int(argbuf, 0);
2004 lgetfloor(&flbuf, floor_num);
2005 if ((flbuf.f_flags & F_INUSE) == 0) {
2006 lputfloor(&flbuf, floor_num);
2007 cprintf("%d Floor %d is not in use.\n",
2008 ERROR + INVALID_FLOOR_OPERATION, floor_num);
2012 extract(flbuf.f_name, argbuf, 1);
2013 lputfloor(&flbuf, floor_num);
2015 cprintf("%d Ok\n", CIT_OK);