4 * Server functions which perform operations on room objects.
19 #if TIME_WITH_SYS_TIME
20 # include <sys/time.h>
24 # include <sys/time.h>
34 #include "serv_extensions.h"
38 #include "sysdep_decls.h"
42 #include "citserver.h"
46 struct floor *floorcache[MAXFLOORS];
49 * Generic routine for determining user access to rooms
51 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf)
56 /* for internal programs, always do everything */
57 if (((CC->internal_pgm)) && (roombuf->QRflags & QR_INUSE)) {
58 return (UA_KNOWN | UA_GOTOALLOWED);
61 /* Locate any applicable user/room relationships */
62 CtdlGetRelationship(&vbuf, userbuf, roombuf);
64 /* Force the properties of the Aide room */
65 if (!strcasecmp(roombuf->QRname, config.c_aideroom)) {
66 if (userbuf->axlevel >= 6) {
67 retval = UA_KNOWN | UA_GOTOALLOWED;
74 /* If this is a public room, it's accessible... */
75 if ( ((roombuf->QRflags & QR_PRIVATE) == 0)
76 && ((roombuf->QRflags & QR_MAILBOX) == 0) ) {
77 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
80 /* If this is a preferred users only room, check access level */
81 if (roombuf->QRflags & QR_PREFONLY) {
82 if (userbuf->axlevel < 5) {
83 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
87 /* For private rooms, check the generation number matchups */
88 if ( (roombuf->QRflags & QR_PRIVATE)
89 && ((roombuf->QRflags & QR_MAILBOX) == 0) ) {
91 /* An explicit match means the user belongs in this room */
92 if (vbuf.v_flags & V_ACCESS) {
93 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
95 /* Otherwise, check if this is a guess-name or passworded
96 * room. If it is, a goto may at least be attempted
98 else if ((roombuf->QRflags & QR_PRIVATE)
99 || (roombuf->QRflags & QR_PASSWORDED)) {
100 retval = retval & ~UA_KNOWN;
101 retval = retval | UA_GOTOALLOWED;
105 /* For mailbox rooms, also check the generation number matchups */
106 if (roombuf->QRflags & QR_MAILBOX) {
107 if (userbuf->usernum == atol(roombuf->QRname)) {
108 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
110 /* An explicit match means the user belongs in this room */
111 if (vbuf.v_flags & V_ACCESS) {
112 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
116 /* Check to see if the user has forgotten this room */
117 if (vbuf.v_flags & V_FORGET) {
118 retval = retval & ~UA_KNOWN;
119 if ( ( ((roombuf->QRflags & QR_PRIVATE) == 0)
120 && ((roombuf->QRflags & QR_MAILBOX) == 0) )
121 || ( (roombuf->QRflags & QR_MAILBOX)
122 && (atol(roombuf->QRname) == CC->usersupp.usernum))) {
123 retval = retval | UA_ZAPPED;
126 /* If user is explicitly locked out of this room, deny everything */
127 if (vbuf.v_flags & V_LOCKOUT) {
128 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
131 /* Aides get access to all private rooms */
132 if ( (userbuf->axlevel >= 6)
133 && ((roombuf->QRflags & QR_MAILBOX) == 0) ) {
134 if (vbuf.v_flags & V_FORGET) {
135 retval = retval | UA_GOTOALLOWED;
138 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
142 /* On some systems, Aides can gain access to mailboxes as well */
143 if ( (config.c_aide_mailboxes)
144 && (userbuf->axlevel >= 6)
145 && (roombuf->QRflags & QR_MAILBOX) ) {
146 retval = retval | UA_GOTOALLOWED;
149 NEWMSG: /* By the way, we also check for the presence of new messages */
150 if (is_msg_in_mset(vbuf.v_seen, roombuf->QRhighest) == 0) {
151 retval = retval | UA_HASNEWMSGS;
154 /* System rooms never show up in the list. */
155 if (roombuf->QRflags2 & QR2_SYSTEM) {
156 retval = retval & ~UA_KNOWN;
162 * Self-checking stuff for a room record read into memory
164 void room_sanity_check(struct quickroom *qrbuf)
166 /* Mailbox rooms are always on the lowest floor */
167 if (qrbuf->QRflags & QR_MAILBOX) {
170 /* Listing order of 0 is illegal except for base rooms */
171 if (qrbuf->QRorder == 0)
172 if (!(qrbuf->QRflags & QR_MAILBOX) &&
173 strncasecmp(qrbuf->QRname, config.c_baseroom, ROOMNAMELEN)
175 strncasecmp(qrbuf->QRname, config.c_aideroom, ROOMNAMELEN))
181 * getroom() - retrieve room data from disk
183 int getroom(struct quickroom *qrbuf, char *room_name)
185 struct cdbdata *cdbqr;
186 char lowercase_name[ROOMNAMELEN];
187 char personal_lowercase_name[ROOMNAMELEN];
190 for (a = 0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
191 lowercase_name[a] = tolower(room_name[a]);
193 lowercase_name[a] = 0;
195 memset(qrbuf, 0, sizeof(struct quickroom));
197 /* First, try the public namespace */
198 cdbqr = cdb_fetch(CDB_QUICKROOM,
199 lowercase_name, strlen(lowercase_name));
201 /* If that didn't work, try the user's personal namespace */
203 snprintf(personal_lowercase_name,
204 sizeof personal_lowercase_name, "%010ld.%s",
205 CC->usersupp.usernum, lowercase_name);
206 cdbqr = cdb_fetch(CDB_QUICKROOM,
207 personal_lowercase_name,
208 strlen(personal_lowercase_name));
211 memcpy(qrbuf, cdbqr->ptr,
212 ((cdbqr->len > sizeof(struct quickroom)) ?
213 sizeof(struct quickroom) : cdbqr->len));
216 room_sanity_check(qrbuf);
225 * lgetroom() - same as getroom() but locks the record (if supported)
227 int lgetroom(struct quickroom *qrbuf, char *room_name)
230 retval = getroom(qrbuf, room_name);
231 if (retval == 0) begin_critical_section(S_QUICKROOM);
237 * b_putroom() - back end to putroom() and b_deleteroom()
238 * (if the supplied buffer is NULL, delete the room record)
240 void b_putroom(struct quickroom *qrbuf, char *room_name)
242 char lowercase_name[ROOMNAMELEN];
245 for (a = 0; a <= strlen(room_name); ++a) {
246 lowercase_name[a] = tolower(room_name[a]);
250 cdb_delete(CDB_QUICKROOM,
251 lowercase_name, strlen(lowercase_name));
253 time(&qrbuf->QRmtime);
254 cdb_store(CDB_QUICKROOM,
255 lowercase_name, strlen(lowercase_name),
256 qrbuf, sizeof(struct quickroom));
262 * putroom() - store room data to disk
264 void putroom(struct quickroom *qrbuf) {
265 b_putroom(qrbuf, qrbuf->QRname);
270 * b_deleteroom() - delete a room record from disk
272 void b_deleteroom(char *room_name) {
273 b_putroom(NULL, room_name);
279 * lputroom() - same as putroom() but unlocks the record (if supported)
281 void lputroom(struct quickroom *qrbuf)
285 end_critical_section(S_QUICKROOM);
289 /****************************************************************************/
292 * getfloor() - retrieve floor data from disk
294 void getfloor(struct floor *flbuf, int floor_num)
296 struct cdbdata *cdbfl;
298 memset(flbuf, 0, sizeof(struct floor));
299 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
301 memcpy(flbuf, cdbfl->ptr,
302 ((cdbfl->len > sizeof(struct floor)) ?
303 sizeof(struct floor) : cdbfl->len));
306 if (floor_num == 0) {
307 strcpy(flbuf->f_name, "Main Floor");
308 flbuf->f_flags = F_INUSE;
309 flbuf->f_ref_count = 3;
316 * lgetfloor() - same as getfloor() but locks the record (if supported)
318 void lgetfloor(struct floor *flbuf, int floor_num)
321 begin_critical_section(S_FLOORTAB);
322 getfloor(flbuf, floor_num);
327 * cgetfloor() - Get floor record from *cache* (loads from disk if needed)
329 * This is strictly a performance hack.
331 struct floor *cgetfloor(int floor_num) {
332 static int initialized = 0;
335 if (initialized == 0) {
336 for (i=0; i<MAXFLOORS; ++i) {
337 floorcache[floor_num] = NULL;
342 if (floorcache[floor_num] == NULL) {
343 floorcache[floor_num] = mallok(sizeof(struct floor));
344 getfloor(floorcache[floor_num], floor_num);
347 return(floorcache[floor_num]);
353 * putfloor() - store floor data on disk
355 void putfloor(struct floor *flbuf, int floor_num)
357 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
358 flbuf, sizeof(struct floor));
360 /* If we've cached this, clear it out, 'cuz it's WRONG now! */
361 if (floorcache[floor_num] != NULL) {
362 phree(floorcache[floor_num]);
363 floorcache[floor_num] = NULL;
369 * lputfloor() - same as putfloor() but unlocks the record (if supported)
371 void lputfloor(struct floor *flbuf, int floor_num)
374 putfloor(flbuf, floor_num);
375 end_critical_section(S_FLOORTAB);
381 * Traverse the room file...
383 void ForEachRoom(void (*CallBack) (struct quickroom *EachRoom, void *out_data),
386 struct quickroom qrbuf;
387 struct cdbdata *cdbqr;
389 cdb_rewind(CDB_QUICKROOM);
391 while (cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
392 memset(&qrbuf, 0, sizeof(struct quickroom));
393 memcpy(&qrbuf, cdbqr->ptr,
394 ((cdbqr->len > sizeof(struct quickroom)) ?
395 sizeof(struct quickroom) : cdbqr->len));
397 room_sanity_check(&qrbuf);
398 if (qrbuf.QRflags & QR_INUSE)
399 (*CallBack)(&qrbuf, in_data);
405 * delete_msglist() - delete room message pointers
407 void delete_msglist(struct quickroom *whichroom)
409 struct cdbdata *cdbml;
411 /* Make sure the msglist we're deleting actually exists, otherwise
412 * gdbm will complain when we try to delete an invalid record
414 cdbml = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
418 /* Go ahead and delete it */
419 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
427 * sort message pointers
428 * (returns new msg count)
430 int sort_msglist(long listptrs[], int oldcount)
441 for (a = numitems - 2; a >= 0; --a) {
442 for (b = 0; b <= a; ++b) {
443 if (listptrs[b] > (listptrs[b + 1])) {
445 hold2 = listptrs[b + 1];
447 listptrs[b + 1] = hold1;
452 /* and yank any nulls */
453 while ((numitems > 0) && (listptrs[0] == 0L)) {
454 memcpy(&listptrs[0], &listptrs[1],
455 (sizeof(long) * (numitems - 1)));
464 * Determine whether a given room is non-editable.
466 int is_noneditable(struct quickroom *qrbuf)
469 /* Mail> rooms are non-editable */
470 if ( (qrbuf->QRflags & QR_MAILBOX)
471 && (!strcasecmp(&qrbuf->QRname[11], MAILROOM)) )
474 /* Everything else is editable */
481 * Back-back-end for all room listing commands
483 void list_roomname(struct quickroom *qrbuf, int ra)
485 char truncated_roomname[ROOMNAMELEN];
487 /* For my own mailbox rooms, chop off the owner prefix */
488 if ( (qrbuf->QRflags & QR_MAILBOX)
489 && (atol(qrbuf->QRname) == CC->usersupp.usernum) ) {
490 strcpy(truncated_roomname, qrbuf->QRname);
491 strcpy(truncated_roomname, &truncated_roomname[11]);
492 cprintf("%s", truncated_roomname);
494 /* For all other rooms, just display the name in its entirety */
496 cprintf("%s", qrbuf->QRname);
499 /* ...and now the other parameters */
500 cprintf("|%u|%d|%d|%d|%d|\n",
502 (int) qrbuf->QRfloor,
503 (int) qrbuf->QRorder,
504 (int) qrbuf->QRflags2,
511 * cmd_lrms() - List all accessible rooms, known or forgotten
513 void cmd_lrms_backend(struct quickroom *qrbuf, void *data)
515 int FloorBeingSearched = (-1);
518 FloorBeingSearched = *(int *)data;
519 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
521 if ((( ra & (UA_KNOWN | UA_ZAPPED)))
522 && ((qrbuf->QRfloor == (FloorBeingSearched))
523 || ((FloorBeingSearched) < 0)))
524 list_roomname(qrbuf, ra);
527 void cmd_lrms(char *argbuf)
529 int FloorBeingSearched = (-1);
530 if (strlen(argbuf) > 0)
531 FloorBeingSearched = extract_int(argbuf, 0);
533 if (CtdlAccessCheck(ac_logged_in)) return;
535 if (getuser(&CC->usersupp, CC->curr_user)) {
536 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
539 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
541 ForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
548 * cmd_lkra() - List all known rooms
550 void cmd_lkra_backend(struct quickroom *qrbuf, void *data)
552 int FloorBeingSearched = (-1);
555 FloorBeingSearched = *(int *)data;
556 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
558 if ((( ra & (UA_KNOWN)))
559 && ((qrbuf->QRfloor == (FloorBeingSearched))
560 || ((FloorBeingSearched) < 0)))
561 list_roomname(qrbuf, ra);
564 void cmd_lkra(char *argbuf)
566 int FloorBeingSearched = (-1);
567 if (strlen(argbuf) > 0)
568 FloorBeingSearched = extract_int(argbuf, 0);
570 if (CtdlAccessCheck(ac_logged_in)) return;
572 if (getuser(&CC->usersupp, CC->curr_user)) {
573 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
576 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
578 ForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
584 void cmd_lprm_backend(struct quickroom *qrbuf, void *data)
586 int FloorBeingSearched = (-1);
589 FloorBeingSearched = *(int *)data;
590 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
592 if ( ((qrbuf->QRflags & QR_PRIVATE) == 0)
593 && ((qrbuf->QRflags & QR_MAILBOX) == 0)
594 && ((qrbuf->QRfloor == (FloorBeingSearched))
595 || ((FloorBeingSearched) < 0)))
596 list_roomname(qrbuf, ra);
599 void cmd_lprm(char *argbuf)
601 int FloorBeingSearched = (-1);
602 if (strlen(argbuf) > 0)
603 FloorBeingSearched = extract_int(argbuf, 0);
605 cprintf("%d Publiic rooms:\n", LISTING_FOLLOWS);
607 ForEachRoom(cmd_lprm_backend, &FloorBeingSearched);
614 * cmd_lkrn() - List all known rooms with new messages
616 void cmd_lkrn_backend(struct quickroom *qrbuf, void *data)
618 int FloorBeingSearched = (-1);
621 FloorBeingSearched = *(int *)data;
622 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
625 && (ra & UA_HASNEWMSGS)
626 && ((qrbuf->QRfloor == (FloorBeingSearched))
627 || ((FloorBeingSearched) < 0)))
628 list_roomname(qrbuf, ra);
631 void cmd_lkrn(char *argbuf)
633 int FloorBeingSearched = (-1);
634 if (strlen(argbuf) > 0)
635 FloorBeingSearched = extract_int(argbuf, 0);
637 if (CtdlAccessCheck(ac_logged_in)) return;
639 if (getuser(&CC->usersupp, CC->curr_user)) {
640 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
643 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
645 ForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
652 * cmd_lkro() - List all known rooms
654 void cmd_lkro_backend(struct quickroom *qrbuf, void *data)
656 int FloorBeingSearched = (-1);
659 FloorBeingSearched = *(int *)data;
660 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
663 && ((ra & UA_HASNEWMSGS) == 0)
664 && ((qrbuf->QRfloor == (FloorBeingSearched))
665 || ((FloorBeingSearched) < 0)))
666 list_roomname(qrbuf, ra);
669 void cmd_lkro(char *argbuf)
671 int FloorBeingSearched = (-1);
672 if (strlen(argbuf) > 0)
673 FloorBeingSearched = extract_int(argbuf, 0);
675 if (CtdlAccessCheck(ac_logged_in)) return;
677 if (getuser(&CC->usersupp, CC->curr_user)) {
678 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
681 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
683 ForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
690 * cmd_lzrm() - List all forgotten rooms
692 void cmd_lzrm_backend(struct quickroom *qrbuf, void *data)
694 int FloorBeingSearched = (-1);
697 FloorBeingSearched = *(int *)data;
698 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
700 if ((ra & UA_GOTOALLOWED)
702 && ((qrbuf->QRfloor == (FloorBeingSearched))
703 || ((FloorBeingSearched) < 0)))
704 list_roomname(qrbuf, ra);
707 void cmd_lzrm(char *argbuf)
709 int FloorBeingSearched = (-1);
710 if (strlen(argbuf) > 0)
711 FloorBeingSearched = extract_int(argbuf, 0);
713 if (CtdlAccessCheck(ac_logged_in)) return;
715 if (getuser(&CC->usersupp, CC->curr_user)) {
716 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
719 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
721 ForEachRoom(cmd_lzrm_backend, &FloorBeingSearched);
727 * Make the specified room the current room for this session. No validation
728 * or access control is done here -- the caller should make sure that the
729 * specified room exists and is ok to access.
731 void usergoto(char *where, int display_result, int transiently,
732 int *retmsgs, int *retnew)
735 int new_messages = 0;
736 int total_messages = 0;
740 int newmailcount = 0;
742 char truncated_roomname[ROOMNAMELEN];
743 struct cdbdata *cdbfr;
744 long *msglist = NULL;
747 /* If the supplied room name is NULL, the caller wants us to know that
748 * it has already copied the quickroom record into CC->quickroom, so
749 * we can skip the extra database fetch.
752 strcpy(CC->quickroom.QRname, where);
753 getroom(&CC->quickroom, where);
756 /* Take care of all the formalities. */
758 begin_critical_section(S_USERSUPP);
759 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
761 /* Know the room ... but not if it's the page log room, or if the
762 * caller specified that we're only entering this room transiently.
764 if ((strcasecmp(CC->quickroom.QRname, config.c_logpages))
765 && (transiently == 0) ) {
766 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
767 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
769 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
770 end_critical_section(S_USERSUPP);
772 /* Check for new mail */
773 newmailcount = NewMailCount();
775 /* set info to 1 if the user needs to read the room's info file */
776 if (CC->quickroom.QRinfo > vbuf.v_lastseen) {
781 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->quickroom.QRnumber, sizeof(long));
783 msglist = mallok(cdbfr->len);
784 memcpy(msglist, cdbfr->ptr, cdbfr->len);
785 num_msgs = cdbfr->len / sizeof(long);
789 if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
790 if (msglist[a] > 0L) {
792 if (is_msg_in_mset(vbuf.v_seen, msglist[a]) == 0) {
798 if (msglist != NULL) phree(msglist);
800 if (CC->quickroom.QRflags & QR_MAILBOX)
805 if ((CC->quickroom.QRroomaide == CC->usersupp.usernum)
806 || (CC->usersupp.axlevel >= 6))
811 strcpy(truncated_roomname, CC->quickroom.QRname);
812 if ( (CC->quickroom.QRflags & QR_MAILBOX)
813 && (atol(CC->quickroom.QRname) == CC->usersupp.usernum) ) {
814 strcpy(truncated_roomname, &truncated_roomname[11]);
817 if (retmsgs != NULL) *retmsgs = total_messages;
818 if (retnew != NULL) *retnew = new_messages;
819 lprintf(9, "<%s> %d new of %d total messages\n",
820 CC->quickroom.QRname,
821 new_messages, total_messages
824 if (display_result) {
825 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d|%d|%d|\n",
826 CIT_OK, CtdlCheckExpress(),
831 (int)CC->quickroom.QRflags,
832 (long)CC->quickroom.QRhighest,
833 (long)vbuf.v_lastseen,
837 (int)CC->quickroom.QRfloor,
839 (int)CC->quickroom.QRdefaultview
846 * cmd_goto() - goto a new room
848 void cmd_goto(char *gargs)
850 struct quickroom QRscratch;
854 char augmented_roomname[SIZ];
859 if (CtdlAccessCheck(ac_logged_in)) return;
861 extract(towhere, gargs, 0);
862 extract(password, gargs, 1);
863 transiently = extract_int(gargs, 2);
865 getuser(&CC->usersupp, CC->curr_user);
867 if (!strcasecmp(towhere, "_BASEROOM_"))
868 strcpy(towhere, config.c_baseroom);
870 if (!strcasecmp(towhere, "_MAIL_"))
871 strcpy(towhere, MAILROOM);
873 if (!strcasecmp(towhere, "_BITBUCKET_"))
874 strcpy(towhere, config.c_twitroom);
877 /* First try a regular match */
878 c = getroom(&QRscratch, towhere);
880 /* Then try a mailbox name match */
882 MailboxName(augmented_roomname, sizeof augmented_roomname,
883 &CC->usersupp, towhere);
884 c = getroom(&QRscratch, augmented_roomname);
886 strcpy(towhere, augmented_roomname);
889 /* And if the room was found... */
892 /* Let internal programs go directly to any room. */
893 if (CC->internal_pgm) {
894 memcpy(&CC->quickroom, &QRscratch,
895 sizeof(struct quickroom));
896 usergoto(NULL, 1, transiently, NULL, NULL);
900 /* See if there is an existing user/room relationship */
901 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
903 /* normal clients have to pass through security */
904 if (ra & UA_GOTOALLOWED) {
909 if ((QRscratch.QRflags & QR_MAILBOX) &&
910 ((ra & UA_GOTOALLOWED))) {
911 memcpy(&CC->quickroom, &QRscratch,
912 sizeof(struct quickroom));
913 usergoto(NULL, 1, transiently, NULL, NULL);
915 } else if ((QRscratch.QRflags & QR_PASSWORDED) &&
916 ((ra & UA_KNOWN) == 0) &&
917 (strcasecmp(QRscratch.QRpasswd, password)) &&
918 (CC->usersupp.axlevel < 6)
920 cprintf("%d wrong or missing passwd\n",
921 ERROR + PASSWORD_REQUIRED);
923 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
924 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
925 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
926 ((ra & UA_KNOWN) == 0) &&
927 (CC->usersupp.axlevel < 6)
929 lprintf(9, "Failed to acquire private room\n");
932 memcpy(&CC->quickroom, &QRscratch,
933 sizeof(struct quickroom));
934 usergoto(NULL, 1, transiently, NULL, NULL);
940 NOPE: cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
946 struct usersupp temp;
947 struct cdbdata *cdbus;
949 getuser(&CC->usersupp, CC->curr_user);
952 * This command is only allowed by aides, room aides,
953 * and room namespace owners
956 || (atol(CC->quickroom.QRname) == CC->usersupp.usernum) ) {
961 cprintf("%d Higher access or room ownership required.\n",
962 ERROR + HIGHER_ACCESS_REQUIRED);
966 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
967 cdb_rewind(CDB_USERSUPP);
968 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
969 memset(&temp, 0, sizeof temp);
970 memcpy(&temp, cdbus->ptr, sizeof temp);
973 if ((CC->quickroom.QRflags & QR_INUSE)
974 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
976 cprintf("%s\n", temp.fullname);
983 * RDIR command for room directory
993 if (CtdlAccessCheck(ac_logged_in)) return;
995 getroom(&CC->quickroom, CC->quickroom.QRname);
996 getuser(&CC->usersupp, CC->curr_user);
998 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
999 cprintf("%d not here.\n", ERROR + NOT_HERE);
1002 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
1003 && (CC->usersupp.axlevel < 6)
1004 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
1005 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
1008 cprintf("%d %s|%s/files/%s\n",
1009 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->quickroom.QRdirname);
1011 snprintf(buf, sizeof buf, "ls %s/files/%s >%s 2> /dev/null",
1012 BBSDIR, CC->quickroom.QRdirname, CC->temp);
1015 snprintf(buf, sizeof buf, "%s/files/%s/filedir", BBSDIR, CC->quickroom.QRdirname);
1016 fd = fopen(buf, "r");
1018 fd = fopen("/dev/null", "r");
1020 ls = fopen(CC->temp, "r");
1021 while (fgets(flnm, sizeof flnm, ls) != NULL) {
1022 flnm[strlen(flnm) - 1] = 0;
1023 if (strcasecmp(flnm, "filedir")) {
1024 snprintf(buf, sizeof buf, "%s/files/%s/%s",
1025 BBSDIR, CC->quickroom.QRdirname, flnm);
1026 stat(buf, &statbuf);
1027 strcpy(comment, "");
1029 while ((fgets(buf, sizeof buf, fd) != NULL)
1030 && (strlen(comment) == 0)) {
1031 buf[strlen(buf) - 1] = 0;
1032 if ((!strncasecmp(buf, flnm, strlen(flnm)))
1033 && (buf[strlen(flnm)] == ' '))
1034 safestrncpy(comment,
1035 &buf[strlen(flnm) + 1],
1038 cprintf("%s|%ld|%s\n", flnm, (long)statbuf.st_size, comment);
1049 * get room parameters (aide or room aide command)
1053 if (CtdlAccessCheck(ac_room_aide)) return;
1055 getroom(&CC->quickroom, CC->quickroom.QRname);
1056 cprintf("%d%c%s|%s|%s|%d|%d|%d|%d|%d|\n",
1060 ((CC->quickroom.QRflags & QR_MAILBOX) ?
1061 &CC->quickroom.QRname[11] : CC->quickroom.QRname),
1063 ((CC->quickroom.QRflags & QR_PASSWORDED) ?
1064 CC->quickroom.QRpasswd : ""),
1066 ((CC->quickroom.QRflags & QR_DIRECTORY) ?
1067 CC->quickroom.QRdirname : ""),
1069 CC->quickroom.QRflags,
1070 (int) CC->quickroom.QRfloor,
1071 (int) CC->quickroom.QRorder,
1073 CC->quickroom.QRdefaultview,
1074 CC->quickroom.QRflags2
1080 * Back end function to rename a room.
1081 * You can also specify which floor to move the room to, or specify -1 to
1082 * keep the room on the same floor it was on.
1084 * If you are renaming a mailbox room, you must supply the namespace prefix
1085 * in *at least* the old name!
1087 int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) {
1089 struct quickroom qrbuf;
1090 struct quickroom qrtmp;
1095 char actual_old_name[SIZ];
1097 lprintf(9, "CtdlRenameRoom(%s, %s, %d)\n",
1098 old_name, new_name, new_floor);
1100 if (new_floor >= 0) {
1101 fl = cgetfloor(new_floor);
1102 if ((fl->f_flags & F_INUSE) == 0) {
1103 return(crr_invalid_floor);
1107 begin_critical_section(S_QUICKROOM);
1109 if ( (getroom(&qrtmp, new_name) == 0)
1110 && (strcasecmp(new_name, old_name)) ) {
1111 ret = crr_already_exists;
1114 else if (getroom(&qrbuf, old_name) != 0) {
1115 ret = crr_room_not_found;
1118 else if ( (CC->usersupp.axlevel < 6)
1119 && (CC->usersupp.usernum != qrbuf.QRroomaide)
1120 && ( (((qrbuf.QRflags & QR_MAILBOX) == 0) || (atol(qrbuf.QRname) != CC->usersupp.usernum))) ) {
1121 ret = crr_access_denied;
1124 else if (is_noneditable(&qrbuf)) {
1125 ret = crr_noneditable;
1130 strcpy(actual_old_name, qrbuf.QRname);
1131 if (qrbuf.QRflags & QR_MAILBOX) {
1132 owner = atol(qrbuf.QRname);
1134 if ( (owner > 0L) && (atol(new_name) == 0L) ) {
1135 snprintf(qrbuf.QRname, sizeof(qrbuf.QRname),
1136 "%010ld.%s", owner, new_name);
1139 safestrncpy(qrbuf.QRname, new_name,
1140 sizeof(qrbuf.QRname));
1143 /* Reject change of floor for baseroom/aideroom */
1144 if (!strncasecmp(old_name, config.c_baseroom, ROOMNAMELEN) ||
1145 !strncasecmp(old_name, config.c_aideroom, ROOMNAMELEN)) {
1149 /* Take care of floor stuff */
1150 old_floor = qrbuf.QRfloor;
1151 if (new_floor < 0) {
1152 new_floor = old_floor;
1154 qrbuf.QRfloor = new_floor;
1157 begin_critical_section(S_CONFIG);
1159 /* If baseroom/aideroom name changes, update config */
1160 if (!strncasecmp(old_name, config.c_baseroom, ROOMNAMELEN)) {
1161 safestrncpy(config.c_baseroom, new_name, ROOMNAMELEN);
1164 if (!strncasecmp(old_name, config.c_aideroom, ROOMNAMELEN)) {
1165 safestrncpy(config.c_aideroom, new_name, ROOMNAMELEN);
1169 end_critical_section(S_CONFIG);
1171 /* If the room name changed, then there are now two room
1172 * records, so we have to delete the old one.
1174 if (strcasecmp(new_name, old_name)) {
1175 b_deleteroom(actual_old_name);
1181 end_critical_section(S_QUICKROOM);
1183 /* Adjust the floor reference counts if necessary */
1184 if (new_floor != old_floor) {
1185 lgetfloor(&flbuf, old_floor);
1186 --flbuf.f_ref_count;
1187 lputfloor(&flbuf, old_floor);
1188 lgetfloor(&flbuf, CC->quickroom.QRfloor);
1189 ++flbuf.f_ref_count;
1190 lputfloor(&flbuf, CC->quickroom.QRfloor);
1193 /* ...and everybody say "YATTA!" */
1199 * set room parameters (aide or room aide command)
1201 void cmd_setr(char *args)
1207 char new_name[ROOMNAMELEN];
1209 if (CtdlAccessCheck(ac_logged_in)) return;
1211 if (num_parms(args) >= 6) {
1212 new_floor = extract_int(args, 5);
1214 new_floor = (-1); /* don't change the floor */
1217 /* When is a new name more than just a new name? When the old name
1218 * has a namespace prefix.
1220 if (CC->quickroom.QRflags & QR_MAILBOX) {
1221 sprintf(new_name, "%010ld.", atol(CC->quickroom.QRname) );
1223 strcpy(new_name, "");
1225 extract(&new_name[strlen(new_name)], args, 0);
1227 r = CtdlRenameRoom(CC->quickroom.QRname, new_name, new_floor);
1229 if (r == crr_room_not_found) {
1230 cprintf("%d Internal error - room not found?\n", ERROR);
1231 } else if (r == crr_already_exists) {
1232 cprintf("%d '%s' already exists.\n",
1233 ERROR + ALREADY_EXISTS, new_name);
1234 } else if (r == crr_noneditable) {
1235 cprintf("%d Cannot edit this room.\n", ERROR);
1236 } else if (r == crr_invalid_floor) {
1237 cprintf("%d Target floor does not exist.\n",
1238 ERROR + INVALID_FLOOR_OPERATION);
1239 } else if (r == crr_access_denied) {
1240 cprintf("%d You do not have permission to edit '%s'\n",
1241 ERROR + HIGHER_ACCESS_REQUIRED,
1242 CC->quickroom.QRname);
1243 } else if (r != crr_ok) {
1244 cprintf("%d Error: CtdlRenameRoom() returned %d\n",
1252 getroom(&CC->quickroom, new_name);
1254 /* Now we have to do a bunch of other stuff */
1256 if (num_parms(args) >= 7) {
1257 new_order = extract_int(args, 6);
1260 if (new_order > 127)
1264 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1266 /* Directory room */
1267 extract(buf, args, 2);
1269 safestrncpy(CC->quickroom.QRdirname, buf,
1270 sizeof CC->quickroom.QRdirname);
1273 if (num_parms(args) >= 8) {
1274 CC->quickroom.QRdefaultview = extract_int(args, 7);
1277 /* Second set of flags */
1278 if (num_parms(args) >= 9) {
1279 CC->quickroom.QRflags2 = extract_int(args, 8);
1283 CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
1284 /* Clean up a client boo-boo: if the client set the room to
1285 * guess-name or passworded, ensure that the private flag is
1288 if ((CC->quickroom.QRflags & QR_GUESSNAME)
1289 || (CC->quickroom.QRflags & QR_PASSWORDED))
1290 CC->quickroom.QRflags |= QR_PRIVATE;
1292 /* Some changes can't apply to BASEROOM */
1293 if (!strncasecmp(CC->quickroom.QRname, config.c_baseroom,
1295 CC->quickroom.QRorder = 0;
1296 CC->quickroom.QRpasswd[0] = '\0';
1297 CC->quickroom.QRflags &= ~(QR_PRIVATE & QR_PASSWORDED &
1298 QR_GUESSNAME & QR_PREFONLY & QR_MAILBOX);
1299 CC->quickroom.QRflags |= QR_PERMANENT;
1301 /* March order (doesn't apply to AIDEROOM) */
1302 if (num_parms(args) >= 7)
1303 CC->quickroom.QRorder = (char) new_order;
1305 extract(buf, args, 1);
1307 safestrncpy(CC->quickroom.QRpasswd, buf,
1308 sizeof CC->quickroom.QRpasswd);
1309 /* Kick everyone out if the client requested it
1310 * (by changing the room's generation number)
1312 if (extract_int(args, 4)) {
1313 time(&CC->quickroom.QRgen);
1316 /* Some changes can't apply to AIDEROOM */
1317 if (!strncasecmp(CC->quickroom.QRname, config.c_baseroom,
1319 CC->quickroom.QRorder = 0;
1320 CC->quickroom.QRflags &= ~QR_MAILBOX;
1321 CC->quickroom.QRflags |= QR_PERMANENT;
1324 /* Write the room record back to disk */
1325 lputroom(&CC->quickroom);
1327 /* Create a room directory if necessary */
1328 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1329 snprintf(buf, sizeof buf, "./files/%s",
1330 CC->quickroom.QRdirname);
1333 snprintf(buf, sizeof buf, "%s> edited by %s\n", CC->quickroom.QRname, CC->curr_user);
1335 cprintf("%d Ok\n", CIT_OK);
1341 * get the name of the room aide for this room
1345 struct usersupp usbuf;
1347 if (CtdlAccessCheck(ac_logged_in)) return;
1349 if (getuserbynumber(&usbuf, CC->quickroom.QRroomaide) == 0) {
1350 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1352 cprintf("%d \n", CIT_OK);
1358 * set the room aide for this room
1360 void cmd_seta(char *new_ra)
1362 struct usersupp usbuf;
1367 if (CtdlAccessCheck(ac_room_aide)) return;
1369 if (getuser(&usbuf, new_ra) != 0) {
1372 newu = usbuf.usernum;
1375 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1377 if (CC->quickroom.QRroomaide != newu) {
1380 CC->quickroom.QRroomaide = newu;
1381 lputroom(&CC->quickroom);
1384 * We have to post the change notice _after_ writing changes to
1385 * the room table, otherwise it would deadlock!
1387 if (post_notice == 1) {
1388 if (strlen(usbuf.fullname) > 0)
1389 snprintf(buf, sizeof buf,
1390 "%s is now room aide for %s>\n",
1391 usbuf.fullname, CC->quickroom.QRname);
1393 snprintf(buf, sizeof buf,
1394 "There is now no room aide for %s>\n",
1395 CC->quickroom.QRname);
1398 cprintf("%d Ok\n", CIT_OK);
1402 * Generate an associated file name for a room
1404 void assoc_file_name(char *buf, size_t n,
1405 struct quickroom *qrbuf, const char *prefix)
1407 snprintf(buf, n, "./%s/%ld", prefix, qrbuf->QRnumber);
1411 * retrieve info file for this room
1419 assoc_file_name(filename, sizeof filename, &CC->quickroom, "info");
1420 info_fp = fopen(filename, "r");
1422 if (info_fp == NULL) {
1423 cprintf("%d No info file.\n", ERROR);
1426 cprintf("%d Info:\n", LISTING_FOLLOWS);
1427 while (fgets(buf, sizeof buf, info_fp) != NULL) {
1428 if (strlen(buf) > 0)
1429 buf[strlen(buf) - 1] = 0;
1430 cprintf("%s\n", buf);
1437 * Back end processing to delete a room and everything associated with it
1439 void delete_room(struct quickroom *qrbuf)
1444 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1446 /* Delete the info file */
1447 assoc_file_name(filename, sizeof filename, qrbuf, "info");
1450 /* Delete the image file */
1451 assoc_file_name(filename, sizeof filename, qrbuf, "images");
1454 /* Delete the room's network config file */
1455 assoc_file_name(filename, sizeof filename, qrbuf, "netconfigs");
1458 /* Delete the messages in the room
1459 * (Careful: this opens an S_QUICKROOM critical section!)
1461 CtdlDeleteMessages(qrbuf->QRname, 0L, "");
1463 /* Flag the room record as not in use */
1464 lgetroom(qrbuf, qrbuf->QRname);
1468 /* then decrement the reference count for the floor */
1469 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1470 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1471 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1473 /* Delete the room record from the database! */
1474 b_deleteroom(qrbuf->QRname);
1480 * Check access control for deleting a room
1482 int CtdlDoIHavePermissionToDeleteThisRoom(struct quickroom *qr) {
1484 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
1488 if (is_noneditable(qr)) {
1493 * For mailboxes, check stuff
1495 if (qr->QRflags & QR_MAILBOX) {
1497 if (strlen(qr->QRname) < 12) return(0); /* bad name */
1499 if (atol(qr->QRname) != CC->usersupp.usernum) {
1500 return(0); /* not my room */
1503 /* Can't delete your Mail> room */
1504 if (!strcasecmp(&qr->QRname[12], MAILROOM)) return(0);
1506 /* Otherwise it's ok */
1511 * For normal rooms, just check for aide or room aide status.
1513 return(is_room_aide());
1517 * aide command: kill the current room
1519 void cmd_kill(char *argbuf)
1521 char deleted_room_name[ROOMNAMELEN];
1525 kill_ok = extract_int(argbuf, 0);
1527 if (CtdlDoIHavePermissionToDeleteThisRoom(&CC->quickroom) == 0) {
1528 cprintf("%d Can't delete this room.\n", ERROR + NOT_HERE);
1532 if (CC->quickroom.QRflags & QR_MAILBOX) {
1533 strcpy(deleted_room_name, &CC->quickroom.QRname[11]);
1536 strcpy(deleted_room_name, CC->quickroom.QRname);
1539 /* Do the dirty work */
1540 delete_room(&CC->quickroom);
1542 /* Return to the Lobby */
1543 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
1545 /* tell the world what we did */
1546 snprintf(msg, sizeof msg, "%s> killed by %s\n",
1547 deleted_room_name, CC->curr_user);
1549 cprintf("%d '%s' deleted.\n", CIT_OK, deleted_room_name);
1551 cprintf("%d ok to delete.\n", CIT_OK);
1557 * Internal code to create a new room (returns room flags)
1559 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only,
1560 * 4=mailbox, 5=mailbox, but caller supplies namespace
1562 unsigned create_room(char *new_room_name,
1564 char *new_room_pass,
1570 struct quickroom qrbuf;
1574 lprintf(9, "create_room(%s)\n", new_room_name);
1575 if (getroom(&qrbuf, new_room_name) == 0) {
1576 lprintf(9, "%s already exists.\n", new_room_name);
1577 return (0); /* already exists */
1581 memset(&qrbuf, 0, sizeof(struct quickroom));
1582 safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
1583 qrbuf.QRflags = QR_INUSE;
1584 if (new_room_type > 0)
1585 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1586 if (new_room_type == 1)
1587 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1588 if (new_room_type == 2)
1589 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1590 if ( (new_room_type == 4) || (new_room_type == 5) )
1591 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1593 /* If the user is requesting a personal room, set up the room
1594 * name accordingly (prepend the user number)
1596 if (new_room_type == 4) {
1597 MailboxName(qrbuf.QRname, sizeof qrbuf.QRname, &CC->usersupp, new_room_name);
1600 safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
1603 /* If the room is private, and the system administrator has elected
1604 * to automatically grant room aide privileges, do so now; otherwise,
1605 * set the room aide to undefined.
1607 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1608 qrbuf.QRroomaide = CC->usersupp.usernum;
1610 qrbuf.QRroomaide = (-1L);
1614 * If the caller is only interested in testing whether this will work,
1615 * return now without creating the room.
1617 if (!really_create) return (qrbuf.QRflags);
1619 qrbuf.QRnumber = get_new_room_number();
1620 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1621 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1622 qrbuf.QRfloor = new_room_floor;
1624 /* save what we just did... */
1627 /* bump the reference count on whatever floor the room is on */
1628 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1629 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1630 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1632 /* Grant the creator access to the room unless the avoid_access
1633 * parameter was specified.
1635 if (avoid_access == 0) {
1636 lgetuser(&CC->usersupp, CC->curr_user);
1637 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1638 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1639 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1640 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1641 lputuser(&CC->usersupp);
1644 /* resume our happy day */
1645 return (qrbuf.QRflags);
1652 void cmd_cre8(char *args)
1655 char new_room_name[SIZ];
1657 char new_room_pass[SIZ];
1662 int avoid_access = 0;
1664 cre8_ok = extract_int(args, 0);
1665 extract(new_room_name, args, 1);
1666 new_room_name[ROOMNAMELEN - 1] = 0;
1667 new_room_type = extract_int(args, 2);
1668 extract(new_room_pass, args, 3);
1669 avoid_access = extract_int(args, 5);
1670 new_room_pass[9] = 0;
1673 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1674 cprintf("%d Invalid room name.\n", ERROR);
1678 if (!strcasecmp(new_room_name, MAILROOM)) {
1679 cprintf("%d '%s' already exists.\n",
1680 ERROR + ALREADY_EXISTS, new_room_name);
1684 if (num_parms(args) >= 5) {
1685 fl = cgetfloor(extract_int(args, 4));
1686 if ((fl->f_flags & F_INUSE) == 0) {
1687 cprintf("%d Invalid floor number.\n",
1688 ERROR + INVALID_FLOOR_OPERATION);
1691 new_room_floor = extract_int(args, 4);
1695 if (CtdlAccessCheck(ac_logged_in)) return;
1697 if (CC->usersupp.axlevel < config.c_createax) {
1698 cprintf("%d You need higher access to create rooms.\n",
1699 ERROR + HIGHER_ACCESS_REQUIRED);
1703 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1704 cprintf("%d Ok to create rooms.\n", CIT_OK);
1708 if ((new_room_type < 0) || (new_room_type > 5)) {
1709 cprintf("%d Invalid room type.\n", ERROR);
1713 if (new_room_type == 5) {
1714 if ((config.c_aide_mailboxes == 0)
1715 || (CC->usersupp.axlevel < 6)) {
1716 cprintf("%d Higher access required\n",
1717 ERROR+HIGHER_ACCESS_REQUIRED);
1722 /* Check to make sure the requested room name doesn't already exist */
1723 newflags = create_room(new_room_name,
1724 new_room_type, new_room_pass, new_room_floor,
1726 if (newflags == 0) {
1727 cprintf("%d '%s' already exists.\n",
1728 ERROR + ALREADY_EXISTS, new_room_name);
1733 cprintf("%d OK to create '%s'\n", CIT_OK, new_room_name);
1737 /* If we reach this point, the room needs to be created. */
1739 newflags = create_room(new_room_name,
1740 new_room_type, new_room_pass, new_room_floor, 1, 0);
1742 /* post a message in Aide> describing the new room */
1743 safestrncpy(aaa, new_room_name, sizeof aaa);
1744 strcat(aaa, "> created by ");
1745 strcat(aaa, CC->usersupp.fullname);
1746 if (newflags & QR_MAILBOX)
1747 strcat(aaa, " [personal]");
1748 else if (newflags & QR_PRIVATE)
1749 strcat(aaa, " [private]");
1750 if (newflags & QR_GUESSNAME)
1751 strcat(aaa, "[guessname] ");
1752 if (newflags & QR_PASSWORDED) {
1753 strcat(aaa, "\n Password: ");
1754 strcat(aaa, new_room_pass);
1759 cprintf("%d '%s' has been created.\n", CIT_OK, new_room_name);
1764 void cmd_einf(char *ok)
1765 { /* enter info file for current room */
1767 char infofilename[SIZ];
1770 if (CtdlAccessCheck(ac_room_aide)) return;
1772 if (atoi(ok) == 0) {
1773 cprintf("%d Ok.\n", CIT_OK);
1776 assoc_file_name(infofilename, sizeof infofilename, &CC->quickroom, "info");
1777 lprintf(9, "opening\n");
1778 fp = fopen(infofilename, "w");
1779 lprintf(9, "checking\n");
1781 cprintf("%d Cannot open %s: %s\n",
1782 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1785 cprintf("%d Send info...\n", SEND_LISTING);
1789 if (strcmp(buf, "000"))
1790 fprintf(fp, "%s\n", buf);
1791 } while (strcmp(buf, "000"));
1794 /* now update the room index so people will see our new info */
1795 lgetroom(&CC->quickroom, CC->quickroom.QRname); /* lock so no one steps on us */
1796 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1797 lputroom(&CC->quickroom);
1802 * cmd_lflr() - List all known floors
1809 if (CtdlAccessCheck(ac_logged_in)) return;
1811 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1813 for (a = 0; a < MAXFLOORS; ++a) {
1814 getfloor(&flbuf, a);
1815 if (flbuf.f_flags & F_INUSE) {
1816 cprintf("%d|%s|%d\n",
1828 * create a new floor
1830 void cmd_cflr(char *argbuf)
1832 char new_floor_name[SIZ];
1835 int free_slot = (-1);
1838 extract(new_floor_name, argbuf, 0);
1839 cflr_ok = extract_int(argbuf, 1);
1841 if (CtdlAccessCheck(ac_aide)) return;
1843 if (strlen(new_floor_name) == 0) {
1844 cprintf("%d Blank floor name not allowed.\n",
1845 ERROR+ILLEGAL_VALUE);
1849 for (a = 0; a < MAXFLOORS; ++a) {
1850 getfloor(&flbuf, a);
1852 /* note any free slots while we're scanning... */
1853 if (((flbuf.f_flags & F_INUSE) == 0)
1857 /* check to see if it already exists */
1858 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1859 && (flbuf.f_flags & F_INUSE)) {
1860 cprintf("%d Floor '%s' already exists.\n",
1861 ERROR + ALREADY_EXISTS,
1867 if (free_slot < 0) {
1868 cprintf("%d There is no space available for a new floor.\n",
1869 ERROR + INVALID_FLOOR_OPERATION);
1873 cprintf("%d ok to create...\n", CIT_OK);
1876 lgetfloor(&flbuf, free_slot);
1877 flbuf.f_flags = F_INUSE;
1878 flbuf.f_ref_count = 0;
1879 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1880 lputfloor(&flbuf, free_slot);
1881 cprintf("%d %d\n", CIT_OK, free_slot);
1889 void cmd_kflr(char *argbuf)
1892 int floor_to_delete;
1896 floor_to_delete = extract_int(argbuf, 0);
1897 kflr_ok = extract_int(argbuf, 1);
1899 if (CtdlAccessCheck(ac_aide)) return;
1901 lgetfloor(&flbuf, floor_to_delete);
1904 if ((flbuf.f_flags & F_INUSE) == 0) {
1905 cprintf("%d Floor %d not in use.\n",
1906 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1909 if (flbuf.f_ref_count != 0) {
1910 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1911 ERROR + INVALID_FLOOR_OPERATION,
1916 cprintf("%d Ok\n", CIT_OK);
1918 cprintf("%d Ok to delete...\n", CIT_OK);
1925 if ((delete_ok == 1) && (kflr_ok == 1))
1927 lputfloor(&flbuf, floor_to_delete);
1933 void cmd_eflr(char *argbuf)
1939 np = num_parms(argbuf);
1941 cprintf("%d Usage error.\n", ERROR);
1945 if (CtdlAccessCheck(ac_aide)) return;
1947 floor_num = extract_int(argbuf, 0);
1948 lgetfloor(&flbuf, floor_num);
1949 if ((flbuf.f_flags & F_INUSE) == 0) {
1950 lputfloor(&flbuf, floor_num);
1951 cprintf("%d Floor %d is not in use.\n",
1952 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1956 extract(flbuf.f_name, argbuf, 1);
1957 lputfloor(&flbuf, floor_num);
1959 cprintf("%d Ok\n", CIT_OK);