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 /* Aides can gain access to mailboxes as well, but they don't show
146 if ( (userbuf->axlevel >= 6)
147 && (roombuf->QRflags & QR_MAILBOX) ) {
148 retval = retval | UA_GOTOALLOWED;
151 NEWMSG: /* By the way, we also check for the presence of new messages */
152 if (is_msg_in_mset(vbuf.v_seen, roombuf->QRhighest) == 0) {
153 retval = retval | UA_HASNEWMSGS;
156 /* System rooms never show up in the list. */
157 if (roombuf->QRflags2 & QR2_SYSTEM) {
158 retval = retval & ~UA_KNOWN;
164 * Self-checking stuff for a room record read into memory
166 void room_sanity_check(struct ctdlroom *qrbuf)
168 /* Mailbox rooms are always on the lowest floor */
169 if (qrbuf->QRflags & QR_MAILBOX) {
172 /* Listing order of 0 is illegal except for base rooms */
173 if (qrbuf->QRorder == 0)
174 if (!(qrbuf->QRflags & QR_MAILBOX) &&
175 strncasecmp(qrbuf->QRname, config.c_baseroom, ROOMNAMELEN)
177 strncasecmp(qrbuf->QRname, config.c_aideroom, ROOMNAMELEN))
183 * getroom() - retrieve room data from disk
185 int getroom(struct ctdlroom *qrbuf, char *room_name)
187 struct cdbdata *cdbqr;
188 char lowercase_name[ROOMNAMELEN];
189 char personal_lowercase_name[ROOMNAMELEN];
192 for (a = 0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
193 lowercase_name[a] = tolower(room_name[a]);
195 lowercase_name[a] = 0;
197 memset(qrbuf, 0, sizeof(struct ctdlroom));
199 /* First, try the public namespace */
200 cdbqr = cdb_fetch(CDB_ROOMS,
201 lowercase_name, strlen(lowercase_name));
203 /* If that didn't work, try the user's personal namespace */
205 snprintf(personal_lowercase_name,
206 sizeof personal_lowercase_name, "%010ld.%s",
207 CC->user.usernum, lowercase_name);
208 cdbqr = cdb_fetch(CDB_ROOMS,
209 personal_lowercase_name,
210 strlen(personal_lowercase_name));
213 memcpy(qrbuf, cdbqr->ptr,
214 ((cdbqr->len > sizeof(struct ctdlroom)) ?
215 sizeof(struct ctdlroom) : cdbqr->len));
218 room_sanity_check(qrbuf);
227 * lgetroom() - same as getroom() but locks the record (if supported)
229 int lgetroom(struct ctdlroom *qrbuf, char *room_name)
232 retval = getroom(qrbuf, room_name);
233 if (retval == 0) begin_critical_section(S_ROOMS);
239 * b_putroom() - back end to putroom() and b_deleteroom()
240 * (if the supplied buffer is NULL, delete the room record)
242 void b_putroom(struct ctdlroom *qrbuf, char *room_name)
244 char lowercase_name[ROOMNAMELEN];
247 for (a = 0; a <= strlen(room_name); ++a) {
248 lowercase_name[a] = tolower(room_name[a]);
252 cdb_delete(CDB_ROOMS,
253 lowercase_name, strlen(lowercase_name));
255 time(&qrbuf->QRmtime);
257 lowercase_name, strlen(lowercase_name),
258 qrbuf, sizeof(struct ctdlroom));
264 * putroom() - store room data to disk
266 void putroom(struct ctdlroom *qrbuf) {
267 b_putroom(qrbuf, qrbuf->QRname);
272 * b_deleteroom() - delete a room record from disk
274 void b_deleteroom(char *room_name) {
275 b_putroom(NULL, room_name);
281 * lputroom() - same as putroom() but unlocks the record (if supported)
283 void lputroom(struct ctdlroom *qrbuf)
287 end_critical_section(S_ROOMS);
291 /****************************************************************************/
294 * getfloor() - retrieve floor data from disk
296 void getfloor(struct floor *flbuf, int floor_num)
298 struct cdbdata *cdbfl;
300 memset(flbuf, 0, sizeof(struct floor));
301 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
303 memcpy(flbuf, cdbfl->ptr,
304 ((cdbfl->len > sizeof(struct floor)) ?
305 sizeof(struct floor) : cdbfl->len));
308 if (floor_num == 0) {
309 safestrncpy(flbuf->f_name, "Main Floor",
310 sizeof flbuf->f_name);
311 flbuf->f_flags = F_INUSE;
312 flbuf->f_ref_count = 3;
319 * lgetfloor() - same as getfloor() but locks the record (if supported)
321 void lgetfloor(struct floor *flbuf, int floor_num)
324 begin_critical_section(S_FLOORTAB);
325 getfloor(flbuf, floor_num);
330 * cgetfloor() - Get floor record from *cache* (loads from disk if needed)
332 * This is strictly a performance hack.
334 struct floor *cgetfloor(int floor_num) {
335 static int initialized = 0;
338 struct floor *fl = NULL;
340 begin_critical_section(S_FLOORCACHE);
341 if (initialized == 0) {
342 for (i=0; i<MAXFLOORS; ++i) {
343 floorcache[floor_num] = NULL;
347 if (floorcache[floor_num] == NULL) {
350 end_critical_section(S_FLOORCACHE);
353 lprintf(CTDL_DEBUG, "fetch_new is active ... going to disk\n");
354 fl = malloc(sizeof(struct floor));
355 getfloor(fl, floor_num);
356 begin_critical_section(S_FLOORCACHE);
357 if (floorcache[floor_num] != NULL) {
358 free(floorcache[floor_num]);
360 floorcache[floor_num] = fl;
361 end_critical_section(S_FLOORCACHE);
364 return(floorcache[floor_num]);
370 * putfloor() - store floor data on disk
372 void putfloor(struct floor *flbuf, int floor_num)
374 /* If we've cached this, clear it out, 'cuz it's WRONG now! */
375 begin_critical_section(S_FLOORCACHE);
376 if (floorcache[floor_num] != NULL) {
377 free(floorcache[floor_num]);
378 floorcache[floor_num] = malloc(sizeof(struct floor));
379 memcpy(floorcache[floor_num], flbuf, sizeof(struct floor));
381 end_critical_section(S_FLOORCACHE);
383 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
384 flbuf, sizeof(struct floor));
389 * lputfloor() - same as putfloor() but unlocks the record (if supported)
391 void lputfloor(struct floor *flbuf, int floor_num)
394 putfloor(flbuf, floor_num);
395 end_critical_section(S_FLOORTAB);
401 * Traverse the room file...
403 void ForEachRoom(void (*CallBack) (struct ctdlroom *EachRoom, void *out_data),
406 struct ctdlroom qrbuf;
407 struct cdbdata *cdbqr;
409 cdb_rewind(CDB_ROOMS);
411 while (cdbqr = cdb_next_item(CDB_ROOMS), cdbqr != NULL) {
412 memset(&qrbuf, 0, sizeof(struct ctdlroom));
413 memcpy(&qrbuf, cdbqr->ptr,
414 ((cdbqr->len > sizeof(struct ctdlroom)) ?
415 sizeof(struct ctdlroom) : cdbqr->len));
417 room_sanity_check(&qrbuf);
418 if (qrbuf.QRflags & QR_INUSE)
419 (*CallBack)(&qrbuf, in_data);
425 * delete_msglist() - delete room message pointers
427 void delete_msglist(struct ctdlroom *whichroom)
429 struct cdbdata *cdbml;
431 /* Make sure the msglist we're deleting actually exists, otherwise
432 * gdbm will complain when we try to delete an invalid record
434 cdbml = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
438 /* Go ahead and delete it */
439 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
447 * sort message pointers
448 * (returns new msg count)
450 int sort_msglist(long listptrs[], int oldcount)
461 for (a = numitems - 2; a >= 0; --a) {
462 for (b = 0; b <= a; ++b) {
463 if (listptrs[b] > (listptrs[b + 1])) {
465 hold2 = listptrs[b + 1];
467 listptrs[b + 1] = hold1;
472 /* and yank any nulls */
473 while ((numitems > 0) && (listptrs[0] == 0L)) {
474 memcpy(&listptrs[0], &listptrs[1],
475 (sizeof(long) * (numitems - 1)));
484 * Determine whether a given room is non-editable.
486 int is_noneditable(struct ctdlroom *qrbuf)
489 /* Mail> rooms are non-editable */
490 if ( (qrbuf->QRflags & QR_MAILBOX)
491 && (!strcasecmp(&qrbuf->QRname[11], MAILROOM)) )
494 /* Everything else is editable */
501 * Back-back-end for all room listing commands
503 void list_roomname(struct ctdlroom *qrbuf, int ra)
505 char truncated_roomname[ROOMNAMELEN];
507 /* For my own mailbox rooms, chop off the owner prefix */
508 if ( (qrbuf->QRflags & QR_MAILBOX)
509 && (atol(qrbuf->QRname) == CC->user.usernum) ) {
510 strcpy(truncated_roomname, qrbuf->QRname);
511 strcpy(truncated_roomname, &truncated_roomname[11]);
512 cprintf("%s", truncated_roomname);
514 /* For all other rooms, just display the name in its entirety */
516 cprintf("%s", qrbuf->QRname);
519 /* ...and now the other parameters */
520 cprintf("|%u|%d|%d|%d|%d|\n",
522 (int) qrbuf->QRfloor,
523 (int) qrbuf->QRorder,
524 (int) qrbuf->QRflags2,
531 * cmd_lrms() - List all accessible rooms, known or forgotten
533 void cmd_lrms_backend(struct ctdlroom *qrbuf, void *data)
535 int FloorBeingSearched = (-1);
538 FloorBeingSearched = *(int *)data;
539 ra = CtdlRoomAccess(qrbuf, &CC->user);
541 if ((( ra & (UA_KNOWN | UA_ZAPPED)))
542 && ((qrbuf->QRfloor == (FloorBeingSearched))
543 || ((FloorBeingSearched) < 0)))
544 list_roomname(qrbuf, ra);
547 void cmd_lrms(char *argbuf)
549 int FloorBeingSearched = (-1);
550 if (strlen(argbuf) > 0)
551 FloorBeingSearched = extract_int(argbuf, 0);
553 if (CtdlAccessCheck(ac_logged_in)) return;
555 if (getuser(&CC->user, CC->curr_user)) {
556 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
559 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
561 ForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
568 * cmd_lkra() - List all known rooms
570 void cmd_lkra_backend(struct ctdlroom *qrbuf, void *data)
572 int FloorBeingSearched = (-1);
575 FloorBeingSearched = *(int *)data;
576 ra = CtdlRoomAccess(qrbuf, &CC->user);
578 if ((( ra & (UA_KNOWN)))
579 && ((qrbuf->QRfloor == (FloorBeingSearched))
580 || ((FloorBeingSearched) < 0)))
581 list_roomname(qrbuf, ra);
584 void cmd_lkra(char *argbuf)
586 int FloorBeingSearched = (-1);
587 if (strlen(argbuf) > 0)
588 FloorBeingSearched = extract_int(argbuf, 0);
590 if (CtdlAccessCheck(ac_logged_in)) return;
592 if (getuser(&CC->user, CC->curr_user)) {
593 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
596 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
598 ForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
604 void cmd_lprm_backend(struct ctdlroom *qrbuf, void *data)
606 int FloorBeingSearched = (-1);
609 FloorBeingSearched = *(int *)data;
610 ra = CtdlRoomAccess(qrbuf, &CC->user);
612 if ( ((qrbuf->QRflags & QR_PRIVATE) == 0)
613 && ((qrbuf->QRflags & QR_MAILBOX) == 0)
614 && ((qrbuf->QRfloor == (FloorBeingSearched))
615 || ((FloorBeingSearched) < 0)))
616 list_roomname(qrbuf, ra);
619 void cmd_lprm(char *argbuf)
621 int FloorBeingSearched = (-1);
622 if (strlen(argbuf) > 0)
623 FloorBeingSearched = extract_int(argbuf, 0);
625 cprintf("%d Publiic rooms:\n", LISTING_FOLLOWS);
627 ForEachRoom(cmd_lprm_backend, &FloorBeingSearched);
634 * cmd_lkrn() - List all known rooms with new messages
636 void cmd_lkrn_backend(struct ctdlroom *qrbuf, void *data)
638 int FloorBeingSearched = (-1);
641 FloorBeingSearched = *(int *)data;
642 ra = CtdlRoomAccess(qrbuf, &CC->user);
645 && (ra & UA_HASNEWMSGS)
646 && ((qrbuf->QRfloor == (FloorBeingSearched))
647 || ((FloorBeingSearched) < 0)))
648 list_roomname(qrbuf, ra);
651 void cmd_lkrn(char *argbuf)
653 int FloorBeingSearched = (-1);
654 if (strlen(argbuf) > 0)
655 FloorBeingSearched = extract_int(argbuf, 0);
657 if (CtdlAccessCheck(ac_logged_in)) return;
659 if (getuser(&CC->user, CC->curr_user)) {
660 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
663 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
665 ForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
672 * cmd_lkro() - List all known rooms
674 void cmd_lkro_backend(struct ctdlroom *qrbuf, void *data)
676 int FloorBeingSearched = (-1);
679 FloorBeingSearched = *(int *)data;
680 ra = CtdlRoomAccess(qrbuf, &CC->user);
683 && ((ra & UA_HASNEWMSGS) == 0)
684 && ((qrbuf->QRfloor == (FloorBeingSearched))
685 || ((FloorBeingSearched) < 0)))
686 list_roomname(qrbuf, ra);
689 void cmd_lkro(char *argbuf)
691 int FloorBeingSearched = (-1);
692 if (strlen(argbuf) > 0)
693 FloorBeingSearched = extract_int(argbuf, 0);
695 if (CtdlAccessCheck(ac_logged_in)) return;
697 if (getuser(&CC->user, CC->curr_user)) {
698 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
701 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
703 ForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
710 * cmd_lzrm() - List all forgotten rooms
712 void cmd_lzrm_backend(struct ctdlroom *qrbuf, void *data)
714 int FloorBeingSearched = (-1);
717 FloorBeingSearched = *(int *)data;
718 ra = CtdlRoomAccess(qrbuf, &CC->user);
720 if ((ra & UA_GOTOALLOWED)
722 && ((qrbuf->QRfloor == (FloorBeingSearched))
723 || ((FloorBeingSearched) < 0)))
724 list_roomname(qrbuf, ra);
727 void cmd_lzrm(char *argbuf)
729 int FloorBeingSearched = (-1);
730 if (strlen(argbuf) > 0)
731 FloorBeingSearched = extract_int(argbuf, 0);
733 if (CtdlAccessCheck(ac_logged_in)) return;
735 if (getuser(&CC->user, CC->curr_user)) {
736 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
739 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
741 ForEachRoom(cmd_lzrm_backend, &FloorBeingSearched);
747 * Make the specified room the current room for this session. No validation
748 * or access control is done here -- the caller should make sure that the
749 * specified room exists and is ok to access.
751 void usergoto(char *where, int display_result, int transiently,
752 int *retmsgs, int *retnew)
755 int new_messages = 0;
756 int total_messages = 0;
760 int newmailcount = 0;
762 char truncated_roomname[ROOMNAMELEN];
763 struct cdbdata *cdbfr;
764 long *msglist = NULL;
766 unsigned int original_v_flags;
768 /* If the supplied room name is NULL, the caller wants us to know that
769 * it has already copied the room record into CC->room, so
770 * we can skip the extra database fetch.
773 safestrncpy(CC->room.QRname, where, sizeof CC->room.QRname);
774 getroom(&CC->room, where);
777 /* Take care of all the formalities. */
779 begin_critical_section(S_USERS);
780 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
781 original_v_flags = vbuf.v_flags;
783 /* Know the room ... but not if it's the page log room, or if the
784 * caller specified that we're only entering this room transiently.
786 if ((strcasecmp(CC->room.QRname, config.c_logpages))
787 && (transiently == 0) ) {
788 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
789 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
792 /* Only rewrite the database record if we changed something */
793 if (vbuf.v_flags != original_v_flags) {
794 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
796 end_critical_section(S_USERS);
798 /* Check for new mail */
799 newmailcount = NewMailCount();
801 /* set info to 1 if the user needs to read the room's info file */
802 if (CC->room.QRinfo > vbuf.v_lastseen) {
807 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
809 msglist = malloc(cdbfr->len);
810 memcpy(msglist, cdbfr->ptr, cdbfr->len);
811 num_msgs = cdbfr->len / sizeof(long);
815 if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
816 if (msglist[a] > 0L) {
818 if (is_msg_in_mset(vbuf.v_seen, msglist[a]) == 0) {
824 if (msglist != NULL) free(msglist);
826 if (CC->room.QRflags & QR_MAILBOX)
831 if ((CC->room.QRroomaide == CC->user.usernum)
832 || (CC->user.axlevel >= 6))
837 strcpy(truncated_roomname, CC->room.QRname);
838 if ( (CC->room.QRflags & QR_MAILBOX)
839 && (atol(CC->room.QRname) == CC->user.usernum) ) {
840 strcpy(truncated_roomname, &truncated_roomname[11]);
843 if (retmsgs != NULL) *retmsgs = total_messages;
844 if (retnew != NULL) *retnew = new_messages;
845 lprintf(CTDL_DEBUG, "<%s> %d new of %d total messages\n",
847 new_messages, total_messages
850 CC->curr_view = (int)vbuf.v_view;
852 if (display_result) {
853 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d|%d|%d|\n",
854 CIT_OK, CtdlCheckExpress(),
859 (int)CC->room.QRflags,
860 (long)CC->room.QRhighest,
861 (long)vbuf.v_lastseen,
865 (int)CC->room.QRfloor,
867 (int)CC->room.QRdefaultview
874 * cmd_goto() - goto a new room
876 void cmd_goto(char *gargs)
878 struct ctdlroom QRscratch;
882 char augmented_roomname[SIZ];
887 if (CtdlAccessCheck(ac_logged_in)) return;
889 extract(towhere, gargs, 0);
890 extract(password, gargs, 1);
891 transiently = extract_int(gargs, 2);
893 getuser(&CC->user, CC->curr_user);
895 if (!strcasecmp(towhere, "_BASEROOM_"))
896 strcpy(towhere, config.c_baseroom);
898 if (!strcasecmp(towhere, "_MAIL_"))
899 strcpy(towhere, MAILROOM);
901 if (!strcasecmp(towhere, "_BITBUCKET_"))
902 strcpy(towhere, config.c_twitroom);
905 /* First try a regular match */
906 c = getroom(&QRscratch, towhere);
908 /* Then try a mailbox name match */
910 MailboxName(augmented_roomname, sizeof augmented_roomname,
912 c = getroom(&QRscratch, augmented_roomname);
914 strcpy(towhere, augmented_roomname);
917 /* And if the room was found... */
920 /* Let internal programs go directly to any room. */
921 if (CC->internal_pgm) {
922 memcpy(&CC->room, &QRscratch,
923 sizeof(struct ctdlroom));
924 usergoto(NULL, 1, transiently, NULL, NULL);
928 /* See if there is an existing user/room relationship */
929 ra = CtdlRoomAccess(&QRscratch, &CC->user);
931 /* normal clients have to pass through security */
932 if (ra & UA_GOTOALLOWED) {
937 if ((QRscratch.QRflags & QR_MAILBOX) &&
938 ((ra & UA_GOTOALLOWED))) {
939 memcpy(&CC->room, &QRscratch,
940 sizeof(struct ctdlroom));
941 usergoto(NULL, 1, transiently, NULL, NULL);
943 } else if ((QRscratch.QRflags & QR_PASSWORDED) &&
944 ((ra & UA_KNOWN) == 0) &&
945 (strcasecmp(QRscratch.QRpasswd, password)) &&
946 (CC->user.axlevel < 6)
948 cprintf("%d wrong or missing passwd\n",
949 ERROR + PASSWORD_REQUIRED);
951 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
952 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
953 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
954 ((ra & UA_KNOWN) == 0) &&
955 (CC->user.axlevel < 6)
957 lprintf(CTDL_DEBUG, "Failed to acquire private room\n");
959 memcpy(&CC->room, &QRscratch,
960 sizeof(struct ctdlroom));
961 usergoto(NULL, 1, transiently, NULL, NULL);
967 cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
973 struct ctdluser temp;
974 struct cdbdata *cdbus;
976 getuser(&CC->user, CC->curr_user);
979 * This command is only allowed by aides, room aides,
980 * and room namespace owners
983 || (atol(CC->room.QRname) == CC->user.usernum) ) {
988 cprintf("%d Higher access or room ownership required.\n",
989 ERROR + HIGHER_ACCESS_REQUIRED);
993 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
994 cdb_rewind(CDB_USERS);
995 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
996 memset(&temp, 0, sizeof temp);
997 memcpy(&temp, cdbus->ptr, sizeof temp);
1000 if ((CC->room.QRflags & QR_INUSE)
1001 && (CtdlRoomAccess(&CC->room, &temp) & UA_KNOWN)
1003 cprintf("%s\n", temp.fullname);
1010 * RDIR command for room directory
1018 struct stat statbuf;
1020 if (CtdlAccessCheck(ac_logged_in)) return;
1022 getroom(&CC->room, CC->room.QRname);
1023 getuser(&CC->user, CC->curr_user);
1025 if ((CC->room.QRflags & QR_DIRECTORY) == 0) {
1026 cprintf("%d not here.\n", ERROR + NOT_HERE);
1029 if (((CC->room.QRflags & QR_VISDIR) == 0)
1030 && (CC->user.axlevel < 6)
1031 && (CC->user.usernum != CC->room.QRroomaide)) {
1032 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
1035 cprintf("%d %s|%s/files/%s\n",
1036 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->room.QRdirname);
1038 snprintf(buf, sizeof buf, "ls %s/files/%s >%s 2> /dev/null",
1039 BBSDIR, CC->room.QRdirname, CC->temp);
1042 snprintf(buf, sizeof buf, "%s/files/%s/filedir", BBSDIR, CC->room.QRdirname);
1043 fd = fopen(buf, "r");
1045 fd = fopen("/dev/null", "r");
1047 ls = fopen(CC->temp, "r");
1048 while (fgets(flnm, sizeof flnm, ls) != NULL) {
1049 flnm[strlen(flnm) - 1] = 0;
1050 if (strcasecmp(flnm, "filedir")) {
1051 snprintf(buf, sizeof buf, "%s/files/%s/%s",
1052 BBSDIR, CC->room.QRdirname, flnm);
1053 stat(buf, &statbuf);
1054 strcpy(comment, "");
1056 while ((fgets(buf, sizeof buf, fd) != NULL)
1057 && (strlen(comment) == 0)) {
1058 buf[strlen(buf) - 1] = 0;
1059 if ((!strncasecmp(buf, flnm, strlen(flnm)))
1060 && (buf[strlen(flnm)] == ' '))
1061 safestrncpy(comment,
1062 &buf[strlen(flnm) + 1],
1065 cprintf("%s|%ld|%s\n", flnm, (long)statbuf.st_size, comment);
1076 * get room parameters (aide or room aide command)
1080 if (CtdlAccessCheck(ac_room_aide)) return;
1082 getroom(&CC->room, CC->room.QRname);
1083 cprintf("%d%c%s|%s|%s|%d|%d|%d|%d|%d|\n",
1087 ((CC->room.QRflags & QR_MAILBOX) ?
1088 &CC->room.QRname[11] : CC->room.QRname),
1090 ((CC->room.QRflags & QR_PASSWORDED) ?
1091 CC->room.QRpasswd : ""),
1093 ((CC->room.QRflags & QR_DIRECTORY) ?
1094 CC->room.QRdirname : ""),
1097 (int) CC->room.QRfloor,
1098 (int) CC->room.QRorder,
1100 CC->room.QRdefaultview,
1107 * Back end function to rename a room.
1108 * You can also specify which floor to move the room to, or specify -1 to
1109 * keep the room on the same floor it was on.
1111 * If you are renaming a mailbox room, you must supply the namespace prefix
1112 * in *at least* the old name!
1114 int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) {
1116 struct ctdlroom qrbuf;
1117 struct ctdlroom qrtmp;
1122 char actual_old_name[SIZ];
1124 lprintf(CTDL_DEBUG, "CtdlRenameRoom(%s, %s, %d)\n",
1125 old_name, new_name, new_floor);
1127 if (new_floor >= 0) {
1128 fl = cgetfloor(new_floor);
1129 if ((fl->f_flags & F_INUSE) == 0) {
1130 return(crr_invalid_floor);
1134 begin_critical_section(S_ROOMS);
1136 if ( (getroom(&qrtmp, new_name) == 0)
1137 && (strcasecmp(new_name, old_name)) ) {
1138 ret = crr_already_exists;
1141 else if (getroom(&qrbuf, old_name) != 0) {
1142 ret = crr_room_not_found;
1145 else if ( (CC->user.axlevel < 6)
1146 && (CC->user.usernum != qrbuf.QRroomaide)
1147 && ( (((qrbuf.QRflags & QR_MAILBOX) == 0) || (atol(qrbuf.QRname) != CC->user.usernum))) ) {
1148 ret = crr_access_denied;
1151 else if (is_noneditable(&qrbuf)) {
1152 ret = crr_noneditable;
1157 strcpy(actual_old_name, qrbuf.QRname);
1158 if (qrbuf.QRflags & QR_MAILBOX) {
1159 owner = atol(qrbuf.QRname);
1161 if ( (owner > 0L) && (atol(new_name) == 0L) ) {
1162 snprintf(qrbuf.QRname, sizeof(qrbuf.QRname),
1163 "%010ld.%s", owner, new_name);
1166 safestrncpy(qrbuf.QRname, new_name,
1167 sizeof(qrbuf.QRname));
1170 /* Reject change of floor for baseroom/aideroom */
1171 if (!strncasecmp(old_name, config.c_baseroom, ROOMNAMELEN) ||
1172 !strncasecmp(old_name, config.c_aideroom, ROOMNAMELEN)) {
1176 /* Take care of floor stuff */
1177 old_floor = qrbuf.QRfloor;
1178 if (new_floor < 0) {
1179 new_floor = old_floor;
1181 qrbuf.QRfloor = new_floor;
1184 begin_critical_section(S_CONFIG);
1186 /* If baseroom/aideroom name changes, update config */
1187 if (!strncasecmp(old_name, config.c_baseroom, ROOMNAMELEN)) {
1188 safestrncpy(config.c_baseroom, new_name, ROOMNAMELEN);
1191 if (!strncasecmp(old_name, config.c_aideroom, ROOMNAMELEN)) {
1192 safestrncpy(config.c_aideroom, new_name, ROOMNAMELEN);
1196 end_critical_section(S_CONFIG);
1198 /* If the room name changed, then there are now two room
1199 * records, so we have to delete the old one.
1201 if (strcasecmp(new_name, old_name)) {
1202 b_deleteroom(actual_old_name);
1208 end_critical_section(S_ROOMS);
1210 /* Adjust the floor reference counts if necessary */
1211 if (new_floor != old_floor) {
1212 lgetfloor(&flbuf, old_floor);
1213 --flbuf.f_ref_count;
1214 lputfloor(&flbuf, old_floor);
1215 lprintf(CTDL_DEBUG, "Reference count for floor %d is now %d\n", old_floor, flbuf.f_ref_count);
1216 lgetfloor(&flbuf, new_floor);
1217 ++flbuf.f_ref_count;
1218 lputfloor(&flbuf, new_floor);
1219 lprintf(CTDL_DEBUG, "Reference count for floor %d is now %d\n", new_floor, flbuf.f_ref_count);
1222 /* ...and everybody say "YATTA!" */
1228 * set room parameters (aide or room aide command)
1230 void cmd_setr(char *args)
1236 char new_name[ROOMNAMELEN];
1238 if (CtdlAccessCheck(ac_logged_in)) return;
1240 if (num_parms(args) >= 6) {
1241 new_floor = extract_int(args, 5);
1243 new_floor = (-1); /* don't change the floor */
1246 /* When is a new name more than just a new name? When the old name
1247 * has a namespace prefix.
1249 if (CC->room.QRflags & QR_MAILBOX) {
1250 sprintf(new_name, "%010ld.", atol(CC->room.QRname) );
1252 strcpy(new_name, "");
1254 extract(&new_name[strlen(new_name)], args, 0);
1256 r = CtdlRenameRoom(CC->room.QRname, new_name, new_floor);
1258 if (r == crr_room_not_found) {
1259 cprintf("%d Internal error - room not found?\n", ERROR + INTERNAL_ERROR);
1260 } else if (r == crr_already_exists) {
1261 cprintf("%d '%s' already exists.\n",
1262 ERROR + ALREADY_EXISTS, new_name);
1263 } else if (r == crr_noneditable) {
1264 cprintf("%d Cannot edit this room.\n", ERROR + NOT_HERE);
1265 } else if (r == crr_invalid_floor) {
1266 cprintf("%d Target floor does not exist.\n",
1267 ERROR + INVALID_FLOOR_OPERATION);
1268 } else if (r == crr_access_denied) {
1269 cprintf("%d You do not have permission to edit '%s'\n",
1270 ERROR + HIGHER_ACCESS_REQUIRED,
1272 } else if (r != crr_ok) {
1273 cprintf("%d Error: CtdlRenameRoom() returned %d\n",
1274 ERROR + INTERNAL_ERROR, r);
1281 getroom(&CC->room, new_name);
1283 /* Now we have to do a bunch of other stuff */
1285 if (num_parms(args) >= 7) {
1286 new_order = extract_int(args, 6);
1289 if (new_order > 127)
1293 lgetroom(&CC->room, CC->room.QRname);
1295 /* Directory room */
1296 extract(buf, args, 2);
1298 safestrncpy(CC->room.QRdirname, buf,
1299 sizeof CC->room.QRdirname);
1302 if (num_parms(args) >= 8) {
1303 CC->room.QRdefaultview = extract_int(args, 7);
1306 /* Second set of flags */
1307 if (num_parms(args) >= 9) {
1308 CC->room.QRflags2 = extract_int(args, 8);
1312 CC->room.QRflags = (extract_int(args, 3) | QR_INUSE);
1313 /* Clean up a client boo-boo: if the client set the room to
1314 * guess-name or passworded, ensure that the private flag is
1317 if ((CC->room.QRflags & QR_GUESSNAME)
1318 || (CC->room.QRflags & QR_PASSWORDED))
1319 CC->room.QRflags |= QR_PRIVATE;
1321 /* Some changes can't apply to BASEROOM */
1322 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1324 CC->room.QRorder = 0;
1325 CC->room.QRpasswd[0] = '\0';
1326 CC->room.QRflags &= ~(QR_PRIVATE & QR_PASSWORDED &
1327 QR_GUESSNAME & QR_PREFONLY & QR_MAILBOX);
1328 CC->room.QRflags |= QR_PERMANENT;
1330 /* March order (doesn't apply to AIDEROOM) */
1331 if (num_parms(args) >= 7)
1332 CC->room.QRorder = (char) new_order;
1334 extract(buf, args, 1);
1336 safestrncpy(CC->room.QRpasswd, buf,
1337 sizeof CC->room.QRpasswd);
1338 /* Kick everyone out if the client requested it
1339 * (by changing the room's generation number)
1341 if (extract_int(args, 4)) {
1342 time(&CC->room.QRgen);
1345 /* Some changes can't apply to AIDEROOM */
1346 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1348 CC->room.QRorder = 0;
1349 CC->room.QRflags &= ~QR_MAILBOX;
1350 CC->room.QRflags |= QR_PERMANENT;
1353 /* Write the room record back to disk */
1354 lputroom(&CC->room);
1356 /* Create a room directory if necessary */
1357 if (CC->room.QRflags & QR_DIRECTORY) {
1358 snprintf(buf, sizeof buf, "./files/%s",
1359 CC->room.QRdirname);
1362 snprintf(buf, sizeof buf, "%s> edited by %s\n", CC->room.QRname, CC->curr_user);
1364 cprintf("%d Ok\n", CIT_OK);
1370 * get the name of the room aide for this room
1374 struct ctdluser usbuf;
1376 if (CtdlAccessCheck(ac_logged_in)) return;
1378 if (getuserbynumber(&usbuf, CC->room.QRroomaide) == 0) {
1379 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1381 cprintf("%d \n", CIT_OK);
1387 * set the room aide for this room
1389 void cmd_seta(char *new_ra)
1391 struct ctdluser usbuf;
1396 if (CtdlAccessCheck(ac_room_aide)) return;
1398 if (getuser(&usbuf, new_ra) != 0) {
1401 newu = usbuf.usernum;
1404 lgetroom(&CC->room, CC->room.QRname);
1406 if (CC->room.QRroomaide != newu) {
1409 CC->room.QRroomaide = newu;
1410 lputroom(&CC->room);
1413 * We have to post the change notice _after_ writing changes to
1414 * the room table, otherwise it would deadlock!
1416 if (post_notice == 1) {
1417 if (strlen(usbuf.fullname) > 0)
1418 snprintf(buf, sizeof buf,
1419 "%s is now room aide for %s>\n",
1420 usbuf.fullname, CC->room.QRname);
1422 snprintf(buf, sizeof buf,
1423 "There is now no room aide for %s>\n",
1427 cprintf("%d Ok\n", CIT_OK);
1431 * Generate an associated file name for a room
1433 void assoc_file_name(char *buf, size_t n,
1434 struct ctdlroom *qrbuf, const char *prefix)
1436 snprintf(buf, n, "./%s/%ld", prefix, qrbuf->QRnumber);
1440 * retrieve info file for this room
1448 assoc_file_name(filename, sizeof filename, &CC->room, "info");
1449 info_fp = fopen(filename, "r");
1451 if (info_fp == NULL) {
1452 cprintf("%d No info file.\n", ERROR + FILE_NOT_FOUND);
1455 cprintf("%d Info:\n", LISTING_FOLLOWS);
1456 while (fgets(buf, sizeof buf, info_fp) != NULL) {
1457 if (strlen(buf) > 0)
1458 buf[strlen(buf) - 1] = 0;
1459 cprintf("%s\n", buf);
1466 * Back end processing to delete a room and everything associated with it
1468 void delete_room(struct ctdlroom *qrbuf)
1473 lprintf(CTDL_NOTICE, "Deleting room <%s>\n", qrbuf->QRname);
1475 /* Delete the info file */
1476 assoc_file_name(filename, sizeof filename, qrbuf, "info");
1479 /* Delete the image file */
1480 assoc_file_name(filename, sizeof filename, qrbuf, "images");
1483 /* Delete the room's network config file */
1484 assoc_file_name(filename, sizeof filename, qrbuf, "netconfigs");
1487 /* Delete the messages in the room
1488 * (Careful: this opens an S_ROOMS critical section!)
1490 CtdlDeleteMessages(qrbuf->QRname, 0L, "");
1492 /* Flag the room record as not in use */
1493 lgetroom(qrbuf, qrbuf->QRname);
1497 /* then decrement the reference count for the floor */
1498 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1499 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1500 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1502 /* Delete the room record from the database! */
1503 b_deleteroom(qrbuf->QRname);
1509 * Check access control for deleting a room
1511 int CtdlDoIHavePermissionToDeleteThisRoom(struct ctdlroom *qr) {
1513 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
1517 if (is_noneditable(qr)) {
1522 * For mailboxes, check stuff
1524 if (qr->QRflags & QR_MAILBOX) {
1526 if (strlen(qr->QRname) < 12) return(0); /* bad name */
1528 if (atol(qr->QRname) != CC->user.usernum) {
1529 return(0); /* not my room */
1532 /* Can't delete your Mail> room */
1533 if (!strcasecmp(&qr->QRname[12], MAILROOM)) return(0);
1535 /* Otherwise it's ok */
1540 * For normal rooms, just check for aide or room aide status.
1542 return(is_room_aide());
1546 * aide command: kill the current room
1548 void cmd_kill(char *argbuf)
1550 char deleted_room_name[ROOMNAMELEN];
1554 kill_ok = extract_int(argbuf, 0);
1556 if (CtdlDoIHavePermissionToDeleteThisRoom(&CC->room) == 0) {
1557 cprintf("%d Can't delete this room.\n", ERROR + NOT_HERE);
1561 if (CC->room.QRflags & QR_MAILBOX) {
1562 strcpy(deleted_room_name, &CC->room.QRname[11]);
1565 strcpy(deleted_room_name, CC->room.QRname);
1568 /* Do the dirty work */
1569 delete_room(&CC->room);
1571 /* Return to the Lobby */
1572 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
1574 /* tell the world what we did */
1575 snprintf(msg, sizeof msg, "%s> killed by %s\n",
1576 deleted_room_name, CC->curr_user);
1578 cprintf("%d '%s' deleted.\n", CIT_OK, deleted_room_name);
1580 cprintf("%d ok to delete.\n", CIT_OK);
1586 * Internal code to create a new room (returns room flags)
1588 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only,
1589 * 4=mailbox, 5=mailbox, but caller supplies namespace
1591 unsigned create_room(char *new_room_name,
1593 char *new_room_pass,
1600 struct ctdlroom qrbuf;
1604 lprintf(CTDL_DEBUG, "create_room(%s)\n", new_room_name);
1605 if (getroom(&qrbuf, new_room_name) == 0) {
1606 lprintf(CTDL_DEBUG, "%s already exists.\n", new_room_name);
1607 return (0); /* already exists */
1611 memset(&qrbuf, 0, sizeof(struct ctdlroom));
1612 safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
1613 qrbuf.QRflags = QR_INUSE;
1614 if (new_room_type > 0)
1615 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1616 if (new_room_type == 1)
1617 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1618 if (new_room_type == 2)
1619 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1620 if ( (new_room_type == 4) || (new_room_type == 5) )
1621 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1623 /* If the user is requesting a personal room, set up the room
1624 * name accordingly (prepend the user number)
1626 if (new_room_type == 4) {
1627 MailboxName(qrbuf.QRname, sizeof qrbuf.QRname, &CC->user, new_room_name);
1630 safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
1633 /* If the room is private, and the system administrator has elected
1634 * to automatically grant room aide privileges, do so now; otherwise,
1635 * set the room aide to undefined.
1637 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1638 qrbuf.QRroomaide = CC->user.usernum;
1640 qrbuf.QRroomaide = (-1L);
1644 * If the caller is only interested in testing whether this will work,
1645 * return now without creating the room.
1647 if (!really_create) return (qrbuf.QRflags);
1649 qrbuf.QRnumber = get_new_room_number();
1650 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1651 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1652 qrbuf.QRfloor = new_room_floor;
1653 qrbuf.QRdefaultview = new_room_view;
1655 /* save what we just did... */
1658 /* bump the reference count on whatever floor the room is on */
1659 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1660 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1661 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1663 /* Grant the creator access to the room unless the avoid_access
1664 * parameter was specified.
1666 if (avoid_access == 0) {
1667 lgetuser(&CC->user, CC->curr_user);
1668 CtdlGetRelationship(&vbuf, &CC->user, &qrbuf);
1669 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1670 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1671 CtdlSetRelationship(&vbuf, &CC->user, &qrbuf);
1672 lputuser(&CC->user);
1675 /* resume our happy day */
1676 return (qrbuf.QRflags);
1683 void cmd_cre8(char *args)
1686 char new_room_name[SIZ];
1688 char new_room_pass[SIZ];
1694 int avoid_access = 0;
1696 cre8_ok = extract_int(args, 0);
1697 extract(new_room_name, args, 1);
1698 new_room_name[ROOMNAMELEN - 1] = 0;
1699 new_room_type = extract_int(args, 2);
1700 extract(new_room_pass, args, 3);
1701 avoid_access = extract_int(args, 5);
1702 new_room_view = extract_int(args, 6);
1703 new_room_pass[9] = 0;
1706 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1707 cprintf("%d Invalid room name.\n", ERROR + ILLEGAL_VALUE);
1711 if (!strcasecmp(new_room_name, MAILROOM)) {
1712 cprintf("%d '%s' already exists.\n",
1713 ERROR + ALREADY_EXISTS, new_room_name);
1717 if (num_parms(args) >= 5) {
1718 fl = cgetfloor(extract_int(args, 4));
1720 cprintf("%d Invalid floor number.\n",
1721 ERROR + INVALID_FLOOR_OPERATION);
1724 else if ((fl->f_flags & F_INUSE) == 0) {
1725 cprintf("%d Invalid floor number.\n",
1726 ERROR + INVALID_FLOOR_OPERATION);
1729 new_room_floor = extract_int(args, 4);
1733 if (CtdlAccessCheck(ac_logged_in)) return;
1735 if (CC->user.axlevel < config.c_createax) {
1736 cprintf("%d You need higher access to create rooms.\n",
1737 ERROR + HIGHER_ACCESS_REQUIRED);
1741 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1742 cprintf("%d Ok to create rooms.\n", CIT_OK);
1746 if ((new_room_type < 0) || (new_room_type > 5)) {
1747 cprintf("%d Invalid room type.\n", ERROR + ILLEGAL_VALUE);
1751 if (new_room_type == 5) {
1752 if (CC->user.axlevel < 6) {
1753 cprintf("%d Higher access required\n",
1754 ERROR + HIGHER_ACCESS_REQUIRED);
1759 /* Check to make sure the requested room name doesn't already exist */
1760 newflags = create_room(new_room_name,
1761 new_room_type, new_room_pass, new_room_floor,
1762 0, avoid_access, new_room_view);
1763 if (newflags == 0) {
1764 cprintf("%d '%s' already exists.\n",
1765 ERROR + ALREADY_EXISTS, new_room_name);
1770 cprintf("%d OK to create '%s'\n", CIT_OK, new_room_name);
1774 /* If we reach this point, the room needs to be created. */
1776 newflags = create_room(new_room_name,
1777 new_room_type, new_room_pass, new_room_floor, 1, 0,
1780 /* post a message in Aide> describing the new room */
1781 safestrncpy(aaa, new_room_name, sizeof aaa);
1782 strcat(aaa, "> created by ");
1783 strcat(aaa, CC->user.fullname);
1784 if (newflags & QR_MAILBOX)
1785 strcat(aaa, " [personal]");
1786 else if (newflags & QR_PRIVATE)
1787 strcat(aaa, " [private]");
1788 if (newflags & QR_GUESSNAME)
1789 strcat(aaa, "[guessname] ");
1790 if (newflags & QR_PASSWORDED) {
1791 strcat(aaa, "\n Password: ");
1792 strcat(aaa, new_room_pass);
1797 cprintf("%d '%s' has been created.\n", CIT_OK, new_room_name);
1802 void cmd_einf(char *ok)
1803 { /* enter info file for current room */
1805 char infofilename[SIZ];
1810 if (CtdlAccessCheck(ac_room_aide)) return;
1812 if (atoi(ok) == 0) {
1813 cprintf("%d Ok.\n", CIT_OK);
1816 assoc_file_name(infofilename, sizeof infofilename, &CC->room, "info");
1817 lprintf(CTDL_DEBUG, "opening\n");
1818 fp = fopen(infofilename, "w");
1819 lprintf(CTDL_DEBUG, "checking\n");
1821 cprintf("%d Cannot open %s: %s\n",
1822 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1825 cprintf("%d Send info...\n", SEND_LISTING);
1829 if (strcmp(buf, "000"))
1830 fprintf(fp, "%s\n", buf);
1831 } while (strcmp(buf, "000"));
1834 /* now update the room index so people will see our new info */
1835 lgetroom(&CC->room, CC->room.QRname); /* lock so no one steps on us */
1836 CC->room.QRinfo = CC->room.QRhighest + 1L;
1837 lputroom(&CC->room);
1842 * cmd_lflr() - List all known floors
1849 if (CtdlAccessCheck(ac_logged_in)) return;
1851 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1853 for (a = 0; a < MAXFLOORS; ++a) {
1854 getfloor(&flbuf, a);
1855 if (flbuf.f_flags & F_INUSE) {
1856 cprintf("%d|%s|%d\n",
1868 * create a new floor
1870 void cmd_cflr(char *argbuf)
1872 char new_floor_name[SIZ];
1875 int free_slot = (-1);
1878 extract(new_floor_name, argbuf, 0);
1879 cflr_ok = extract_int(argbuf, 1);
1881 if (CtdlAccessCheck(ac_aide)) return;
1883 if (strlen(new_floor_name) == 0) {
1884 cprintf("%d Blank floor name not allowed.\n",
1885 ERROR + ILLEGAL_VALUE);
1889 for (a = 0; a < MAXFLOORS; ++a) {
1890 getfloor(&flbuf, a);
1892 /* note any free slots while we're scanning... */
1893 if (((flbuf.f_flags & F_INUSE) == 0)
1897 /* check to see if it already exists */
1898 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1899 && (flbuf.f_flags & F_INUSE)) {
1900 cprintf("%d Floor '%s' already exists.\n",
1901 ERROR + ALREADY_EXISTS,
1907 if (free_slot < 0) {
1908 cprintf("%d There is no space available for a new floor.\n",
1909 ERROR + INVALID_FLOOR_OPERATION);
1913 cprintf("%d ok to create...\n", CIT_OK);
1916 lgetfloor(&flbuf, free_slot);
1917 flbuf.f_flags = F_INUSE;
1918 flbuf.f_ref_count = 0;
1919 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1920 lputfloor(&flbuf, free_slot);
1921 cprintf("%d %d\n", CIT_OK, free_slot);
1929 void cmd_kflr(char *argbuf)
1932 int floor_to_delete;
1936 floor_to_delete = extract_int(argbuf, 0);
1937 kflr_ok = extract_int(argbuf, 1);
1939 if (CtdlAccessCheck(ac_aide)) return;
1941 lgetfloor(&flbuf, floor_to_delete);
1944 if ((flbuf.f_flags & F_INUSE) == 0) {
1945 cprintf("%d Floor %d not in use.\n",
1946 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1949 if (flbuf.f_ref_count != 0) {
1950 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1951 ERROR + INVALID_FLOOR_OPERATION,
1956 cprintf("%d Ok\n", CIT_OK);
1958 cprintf("%d Ok to delete...\n", CIT_OK);
1965 if ((delete_ok == 1) && (kflr_ok == 1))
1967 lputfloor(&flbuf, floor_to_delete);
1973 void cmd_eflr(char *argbuf)
1979 np = num_parms(argbuf);
1981 cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
1985 if (CtdlAccessCheck(ac_aide)) return;
1987 floor_num = extract_int(argbuf, 0);
1988 lgetfloor(&flbuf, floor_num);
1989 if ((flbuf.f_flags & F_INUSE) == 0) {
1990 lputfloor(&flbuf, floor_num);
1991 cprintf("%d Floor %d is not in use.\n",
1992 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1996 extract(flbuf.f_name, argbuf, 1);
1997 lputfloor(&flbuf, floor_num);
1999 cprintf("%d Ok\n", CIT_OK);