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_sequence_set(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 fl = malloc(sizeof(struct floor));
361 getfloor(fl, floor_num);
362 begin_critical_section(S_FLOORCACHE);
363 if (floorcache[floor_num] != NULL) {
364 free(floorcache[floor_num]);
366 floorcache[floor_num] = fl;
367 end_critical_section(S_FLOORCACHE);
370 return(floorcache[floor_num]);
376 * putfloor() - store floor data on disk
378 void putfloor(struct floor *flbuf, int floor_num)
380 /* If we've cached this, clear it out, 'cuz it's WRONG now! */
381 begin_critical_section(S_FLOORCACHE);
382 if (floorcache[floor_num] != NULL) {
383 free(floorcache[floor_num]);
384 floorcache[floor_num] = malloc(sizeof(struct floor));
385 memcpy(floorcache[floor_num], flbuf, sizeof(struct floor));
387 end_critical_section(S_FLOORCACHE);
389 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
390 flbuf, sizeof(struct floor));
395 * lputfloor() - same as putfloor() but unlocks the record (if supported)
397 void lputfloor(struct floor *flbuf, int floor_num)
400 putfloor(flbuf, floor_num);
401 end_critical_section(S_FLOORTAB);
407 * Traverse the room file...
409 void ForEachRoom(void (*CallBack) (struct ctdlroom *EachRoom, void *out_data),
412 struct ctdlroom qrbuf;
413 struct cdbdata *cdbqr;
415 cdb_rewind(CDB_ROOMS);
417 while (cdbqr = cdb_next_item(CDB_ROOMS), cdbqr != NULL) {
418 memset(&qrbuf, 0, sizeof(struct ctdlroom));
419 memcpy(&qrbuf, cdbqr->ptr,
420 ((cdbqr->len > sizeof(struct ctdlroom)) ?
421 sizeof(struct ctdlroom) : cdbqr->len));
423 room_sanity_check(&qrbuf);
424 if (qrbuf.QRflags & QR_INUSE)
425 (*CallBack)(&qrbuf, in_data);
431 * delete_msglist() - delete room message pointers
433 void delete_msglist(struct ctdlroom *whichroom)
435 struct cdbdata *cdbml;
437 /* Make sure the msglist we're deleting actually exists, otherwise
438 * gdbm will complain when we try to delete an invalid record
440 cdbml = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
444 /* Go ahead and delete it */
445 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
453 * sort message pointers
454 * (returns new msg count)
456 int sort_msglist(long listptrs[], int oldcount)
467 for (a = numitems - 2; a >= 0; --a) {
468 for (b = 0; b <= a; ++b) {
469 if (listptrs[b] > (listptrs[b + 1])) {
471 hold2 = listptrs[b + 1];
473 listptrs[b + 1] = hold1;
478 /* and yank any nulls */
479 while ((numitems > 0) && (listptrs[0] == 0L)) {
480 memcpy(&listptrs[0], &listptrs[1],
481 (sizeof(long) * (numitems - 1)));
490 * Determine whether a given room is non-editable.
492 int is_noneditable(struct ctdlroom *qrbuf)
495 /* Mail> rooms are non-editable */
496 if ( (qrbuf->QRflags & QR_MAILBOX)
497 && (!strcasecmp(&qrbuf->QRname[11], MAILROOM)) )
500 /* Everything else is editable */
507 * Back-back-end for all room listing commands
509 void list_roomname(struct ctdlroom *qrbuf, int ra, int view)
511 char truncated_roomname[ROOMNAMELEN];
513 /* For my own mailbox rooms, chop off the owner prefix */
514 if ( (qrbuf->QRflags & QR_MAILBOX)
515 && (atol(qrbuf->QRname) == CC->user.usernum) ) {
516 safestrncpy(truncated_roomname, qrbuf->QRname, sizeof truncated_roomname);
517 safestrncpy(truncated_roomname, &truncated_roomname[11], sizeof truncated_roomname);
518 cprintf("%s", truncated_roomname);
520 /* For all other rooms, just display the name in its entirety */
522 cprintf("%s", qrbuf->QRname);
525 /* ...and now the other parameters */
526 cprintf("|%u|%d|%d|%d|%d|%d|\n",
528 (int) qrbuf->QRfloor,
529 (int) qrbuf->QRorder,
530 (int) qrbuf->QRflags2,
538 * cmd_lrms() - List all accessible rooms, known or forgotten
540 void cmd_lrms_backend(struct ctdlroom *qrbuf, void *data)
542 int FloorBeingSearched = (-1);
546 FloorBeingSearched = *(int *)data;
547 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
549 if ((( ra & (UA_KNOWN | UA_ZAPPED)))
550 && ((qrbuf->QRfloor == (FloorBeingSearched))
551 || ((FloorBeingSearched) < 0)))
552 list_roomname(qrbuf, ra, view);
555 void cmd_lrms(char *argbuf)
557 int FloorBeingSearched = (-1);
558 if (strlen(argbuf) > 0)
559 FloorBeingSearched = extract_int(argbuf, 0);
561 if (CtdlAccessCheck(ac_logged_in)) return;
563 if (getuser(&CC->user, CC->curr_user)) {
564 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
567 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
569 ForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
576 * cmd_lkra() - List all known rooms
578 void cmd_lkra_backend(struct ctdlroom *qrbuf, void *data)
580 int FloorBeingSearched = (-1);
584 FloorBeingSearched = *(int *)data;
585 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
587 if ((( ra & (UA_KNOWN)))
588 && ((qrbuf->QRfloor == (FloorBeingSearched))
589 || ((FloorBeingSearched) < 0)))
590 list_roomname(qrbuf, ra, view);
593 void cmd_lkra(char *argbuf)
595 int FloorBeingSearched = (-1);
596 if (strlen(argbuf) > 0)
597 FloorBeingSearched = extract_int(argbuf, 0);
599 if (CtdlAccessCheck(ac_logged_in)) return;
601 if (getuser(&CC->user, CC->curr_user)) {
602 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
605 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
607 ForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
613 void cmd_lprm_backend(struct ctdlroom *qrbuf, void *data)
615 int FloorBeingSearched = (-1);
619 FloorBeingSearched = *(int *)data;
620 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
622 if ( ((qrbuf->QRflags & QR_PRIVATE) == 0)
623 && ((qrbuf->QRflags & QR_MAILBOX) == 0)
624 && ((qrbuf->QRfloor == (FloorBeingSearched))
625 || ((FloorBeingSearched) < 0)))
626 list_roomname(qrbuf, ra, view);
629 void cmd_lprm(char *argbuf)
631 int FloorBeingSearched = (-1);
632 if (strlen(argbuf) > 0)
633 FloorBeingSearched = extract_int(argbuf, 0);
635 cprintf("%d Publiic rooms:\n", LISTING_FOLLOWS);
637 ForEachRoom(cmd_lprm_backend, &FloorBeingSearched);
644 * cmd_lkrn() - List all known rooms with new messages
646 void cmd_lkrn_backend(struct ctdlroom *qrbuf, void *data)
648 int FloorBeingSearched = (-1);
652 FloorBeingSearched = *(int *)data;
653 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
656 && (ra & UA_HASNEWMSGS)
657 && ((qrbuf->QRfloor == (FloorBeingSearched))
658 || ((FloorBeingSearched) < 0)))
659 list_roomname(qrbuf, ra, view);
662 void cmd_lkrn(char *argbuf)
664 int FloorBeingSearched = (-1);
665 if (strlen(argbuf) > 0)
666 FloorBeingSearched = extract_int(argbuf, 0);
668 if (CtdlAccessCheck(ac_logged_in)) return;
670 if (getuser(&CC->user, CC->curr_user)) {
671 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
674 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
676 ForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
683 * cmd_lkro() - List all known rooms
685 void cmd_lkro_backend(struct ctdlroom *qrbuf, void *data)
687 int FloorBeingSearched = (-1);
691 FloorBeingSearched = *(int *)data;
692 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
695 && ((ra & UA_HASNEWMSGS) == 0)
696 && ((qrbuf->QRfloor == (FloorBeingSearched))
697 || ((FloorBeingSearched) < 0)))
698 list_roomname(qrbuf, ra, view);
701 void cmd_lkro(char *argbuf)
703 int FloorBeingSearched = (-1);
704 if (strlen(argbuf) > 0)
705 FloorBeingSearched = extract_int(argbuf, 0);
707 if (CtdlAccessCheck(ac_logged_in)) return;
709 if (getuser(&CC->user, CC->curr_user)) {
710 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
713 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
715 ForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
722 * cmd_lzrm() - List all forgotten rooms
724 void cmd_lzrm_backend(struct ctdlroom *qrbuf, void *data)
726 int FloorBeingSearched = (-1);
730 FloorBeingSearched = *(int *)data;
731 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
733 if ((ra & UA_GOTOALLOWED)
735 && ((qrbuf->QRfloor == (FloorBeingSearched))
736 || ((FloorBeingSearched) < 0)))
737 list_roomname(qrbuf, ra, view);
740 void cmd_lzrm(char *argbuf)
742 int FloorBeingSearched = (-1);
743 if (strlen(argbuf) > 0)
744 FloorBeingSearched = extract_int(argbuf, 0);
746 if (CtdlAccessCheck(ac_logged_in)) return;
748 if (getuser(&CC->user, CC->curr_user)) {
749 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
752 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
754 ForEachRoom(cmd_lzrm_backend, &FloorBeingSearched);
760 * Make the specified room the current room for this session. No validation
761 * or access control is done here -- the caller should make sure that the
762 * specified room exists and is ok to access.
764 void usergoto(char *where, int display_result, int transiently,
765 int *retmsgs, int *retnew)
768 int new_messages = 0;
769 int total_messages = 0;
773 int newmailcount = 0;
775 char truncated_roomname[ROOMNAMELEN];
776 struct cdbdata *cdbfr;
777 long *msglist = NULL;
779 unsigned int original_v_flags;
781 /* If the supplied room name is NULL, the caller wants us to know that
782 * it has already copied the room record into CC->room, so
783 * we can skip the extra database fetch.
786 safestrncpy(CC->room.QRname, where, sizeof CC->room.QRname);
787 getroom(&CC->room, where);
790 /* Take care of all the formalities. */
792 begin_critical_section(S_USERS);
793 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
794 original_v_flags = vbuf.v_flags;
796 /* Know the room ... but not if it's the page log room, or if the
797 * caller specified that we're only entering this room transiently.
799 if ((strcasecmp(CC->room.QRname, config.c_logpages))
800 && (transiently == 0) ) {
801 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
802 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
805 /* Only rewrite the database record if we changed something */
806 if (vbuf.v_flags != original_v_flags) {
807 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
809 end_critical_section(S_USERS);
811 /* Check for new mail */
812 newmailcount = NewMailCount();
814 /* set info to 1 if the user needs to read the room's info file */
815 if (CC->room.QRinfo > vbuf.v_lastseen) {
820 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
822 msglist = malloc(cdbfr->len);
823 memcpy(msglist, cdbfr->ptr, cdbfr->len);
824 num_msgs = cdbfr->len / sizeof(long);
828 if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
829 if (msglist[a] > 0L) {
831 if (is_msg_in_sequence_set(vbuf.v_seen, msglist[a]) == 0) {
837 if (msglist != NULL) free(msglist);
839 if (CC->room.QRflags & QR_MAILBOX)
844 if ((CC->room.QRroomaide == CC->user.usernum)
845 || (CC->user.axlevel >= 6))
850 safestrncpy(truncated_roomname, CC->room.QRname, sizeof truncated_roomname);
851 if ( (CC->room.QRflags & QR_MAILBOX)
852 && (atol(CC->room.QRname) == CC->user.usernum) ) {
853 safestrncpy(truncated_roomname, &truncated_roomname[11], sizeof truncated_roomname);
856 if (retmsgs != NULL) *retmsgs = total_messages;
857 if (retnew != NULL) *retnew = new_messages;
858 lprintf(CTDL_DEBUG, "<%s> %d new of %d total messages\n",
860 new_messages, total_messages
863 CC->curr_view = (int)vbuf.v_view;
865 if (display_result) {
866 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d|%d|%d|\n",
867 CIT_OK, CtdlCheckExpress(),
872 (int)CC->room.QRflags,
873 (long)CC->room.QRhighest,
874 (long)vbuf.v_lastseen,
878 (int)CC->room.QRfloor,
880 (int)CC->room.QRdefaultview
887 * cmd_goto() - goto a new room
889 void cmd_goto(char *gargs)
891 struct ctdlroom QRscratch;
895 char augmented_roomname[ROOMNAMELEN];
896 char towhere[ROOMNAMELEN];
900 if (CtdlAccessCheck(ac_logged_in)) return;
902 extract_token(towhere, gargs, 0, '|', sizeof towhere);
903 extract_token(password, gargs, 1, '|', sizeof password);
904 transiently = extract_int(gargs, 2);
906 getuser(&CC->user, CC->curr_user);
908 if (!strcasecmp(towhere, "_BASEROOM_"))
909 safestrncpy(towhere, config.c_baseroom, sizeof towhere);
911 if (!strcasecmp(towhere, "_MAIL_"))
912 safestrncpy(towhere, MAILROOM, sizeof towhere);
914 if (!strcasecmp(towhere, "_BITBUCKET_"))
915 safestrncpy(towhere, config.c_twitroom, sizeof towhere);
918 /* First try a regular match */
919 c = getroom(&QRscratch, towhere);
921 /* Then try a mailbox name match */
923 MailboxName(augmented_roomname, sizeof augmented_roomname,
925 c = getroom(&QRscratch, augmented_roomname);
927 safestrncpy(towhere, augmented_roomname, sizeof towhere);
930 /* And if the room was found... */
933 /* Let internal programs go directly to any room. */
934 if (CC->internal_pgm) {
935 memcpy(&CC->room, &QRscratch,
936 sizeof(struct ctdlroom));
937 usergoto(NULL, 1, transiently, NULL, NULL);
941 /* See if there is an existing user/room relationship */
942 CtdlRoomAccess(&QRscratch, &CC->user, &ra, NULL);
944 /* normal clients have to pass through security */
945 if (ra & UA_GOTOALLOWED) {
950 if ((QRscratch.QRflags & QR_MAILBOX) &&
951 ((ra & UA_GOTOALLOWED))) {
952 memcpy(&CC->room, &QRscratch,
953 sizeof(struct ctdlroom));
954 usergoto(NULL, 1, transiently, NULL, NULL);
956 } else if ((QRscratch.QRflags & QR_PASSWORDED) &&
957 ((ra & UA_KNOWN) == 0) &&
958 (strcasecmp(QRscratch.QRpasswd, password)) &&
959 (CC->user.axlevel < 6)
961 cprintf("%d wrong or missing passwd\n",
962 ERROR + PASSWORD_REQUIRED);
964 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
965 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
966 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
967 ((ra & UA_KNOWN) == 0) &&
968 (CC->user.axlevel < 6)
970 lprintf(CTDL_DEBUG, "Failed to acquire private room\n");
972 memcpy(&CC->room, &QRscratch,
973 sizeof(struct ctdlroom));
974 usergoto(NULL, 1, transiently, NULL, NULL);
980 cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
986 struct ctdluser temp;
987 struct cdbdata *cdbus;
990 getuser(&CC->user, CC->curr_user);
993 * This command is only allowed by aides, room aides,
994 * and room namespace owners
997 || (atol(CC->room.QRname) == CC->user.usernum) ) {
1002 cprintf("%d Higher access or room ownership required.\n",
1003 ERROR + HIGHER_ACCESS_REQUIRED);
1007 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
1008 cdb_rewind(CDB_USERS);
1009 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1010 memset(&temp, 0, sizeof temp);
1011 memcpy(&temp, cdbus->ptr, sizeof temp);
1014 CtdlRoomAccess(&CC->room, &temp, &ra, NULL);
1015 if ((CC->room.QRflags & QR_INUSE)
1018 cprintf("%s\n", temp.fullname);
1025 * RDIR command for room directory
1033 struct stat statbuf;
1034 char tempfilename[PATH_MAX];
1036 if (CtdlAccessCheck(ac_logged_in)) return;
1037 tmpnam(tempfilename);
1039 getroom(&CC->room, CC->room.QRname);
1040 getuser(&CC->user, CC->curr_user);
1042 if ((CC->room.QRflags & QR_DIRECTORY) == 0) {
1043 cprintf("%d not here.\n", ERROR + NOT_HERE);
1046 if (((CC->room.QRflags & QR_VISDIR) == 0)
1047 && (CC->user.axlevel < 6)
1048 && (CC->user.usernum != CC->room.QRroomaide)) {
1049 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
1052 cprintf("%d %s|%s/files/%s\n",
1053 LISTING_FOLLOWS, config.c_fqdn, CTDLDIR, CC->room.QRdirname);
1055 snprintf(buf, sizeof buf, "ls %s/files/%s >%s 2> /dev/null",
1056 CTDLDIR, CC->room.QRdirname, tempfilename);
1059 snprintf(buf, sizeof buf, "%s/files/%s/filedir", CTDLDIR, CC->room.QRdirname);
1060 fd = fopen(buf, "r");
1062 fd = fopen("/dev/null", "r");
1064 ls = fopen(tempfilename, "r");
1065 while (fgets(flnm, sizeof flnm, ls) != NULL) {
1066 flnm[strlen(flnm) - 1] = 0;
1067 if (strcasecmp(flnm, "filedir")) {
1068 snprintf(buf, sizeof buf, "%s/files/%s/%s",
1069 CTDLDIR, CC->room.QRdirname, flnm);
1070 stat(buf, &statbuf);
1071 safestrncpy(comment, "", sizeof comment);
1073 while ((fgets(buf, sizeof buf, fd) != NULL)
1074 && (strlen(comment) == 0)) {
1075 buf[strlen(buf) - 1] = 0;
1076 if ((!strncasecmp(buf, flnm, strlen(flnm)))
1077 && (buf[strlen(flnm)] == ' '))
1078 safestrncpy(comment,
1079 &buf[strlen(flnm) + 1],
1082 cprintf("%s|%ld|%s\n", flnm, (long)statbuf.st_size, comment);
1087 unlink(tempfilename);
1093 * get room parameters (aide or room aide command)
1097 if (CtdlAccessCheck(ac_room_aide)) return;
1099 getroom(&CC->room, CC->room.QRname);
1100 cprintf("%d%c%s|%s|%s|%d|%d|%d|%d|%d|\n",
1104 ((CC->room.QRflags & QR_MAILBOX) ?
1105 &CC->room.QRname[11] : CC->room.QRname),
1107 ((CC->room.QRflags & QR_PASSWORDED) ?
1108 CC->room.QRpasswd : ""),
1110 ((CC->room.QRflags & QR_DIRECTORY) ?
1111 CC->room.QRdirname : ""),
1114 (int) CC->room.QRfloor,
1115 (int) CC->room.QRorder,
1117 CC->room.QRdefaultview,
1124 * Back end function to rename a room.
1125 * You can also specify which floor to move the room to, or specify -1 to
1126 * keep the room on the same floor it was on.
1128 * If you are renaming a mailbox room, you must supply the namespace prefix
1129 * in *at least* the old name!
1131 int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) {
1133 struct ctdlroom qrbuf;
1134 struct ctdlroom qrtmp;
1139 char actual_old_name[ROOMNAMELEN];
1141 lprintf(CTDL_DEBUG, "CtdlRenameRoom(%s, %s, %d)\n",
1142 old_name, new_name, new_floor);
1144 if (new_floor >= 0) {
1145 fl = cgetfloor(new_floor);
1146 if ((fl->f_flags & F_INUSE) == 0) {
1147 return(crr_invalid_floor);
1151 begin_critical_section(S_ROOMS);
1153 if ( (getroom(&qrtmp, new_name) == 0)
1154 && (strcasecmp(new_name, old_name)) ) {
1155 ret = crr_already_exists;
1158 else if (getroom(&qrbuf, old_name) != 0) {
1159 ret = crr_room_not_found;
1162 else if ( (CC->user.axlevel < 6)
1163 && (CC->user.usernum != qrbuf.QRroomaide)
1164 && ( (((qrbuf.QRflags & QR_MAILBOX) == 0) || (atol(qrbuf.QRname) != CC->user.usernum))) ) {
1165 ret = crr_access_denied;
1168 else if (is_noneditable(&qrbuf)) {
1169 ret = crr_noneditable;
1174 safestrncpy(actual_old_name, qrbuf.QRname, sizeof actual_old_name);
1175 if (qrbuf.QRflags & QR_MAILBOX) {
1176 owner = atol(qrbuf.QRname);
1178 if ( (owner > 0L) && (atol(new_name) == 0L) ) {
1179 snprintf(qrbuf.QRname, sizeof(qrbuf.QRname),
1180 "%010ld.%s", owner, new_name);
1183 safestrncpy(qrbuf.QRname, new_name,
1184 sizeof(qrbuf.QRname));
1187 /* Reject change of floor for baseroom/aideroom */
1188 if (!strncasecmp(old_name, config.c_baseroom, ROOMNAMELEN) ||
1189 !strncasecmp(old_name, config.c_aideroom, ROOMNAMELEN)) {
1193 /* Take care of floor stuff */
1194 old_floor = qrbuf.QRfloor;
1195 if (new_floor < 0) {
1196 new_floor = old_floor;
1198 qrbuf.QRfloor = new_floor;
1201 begin_critical_section(S_CONFIG);
1203 /* If baseroom/aideroom name changes, update config */
1204 if (!strncasecmp(old_name, config.c_baseroom, ROOMNAMELEN)) {
1205 safestrncpy(config.c_baseroom, new_name, ROOMNAMELEN);
1208 if (!strncasecmp(old_name, config.c_aideroom, ROOMNAMELEN)) {
1209 safestrncpy(config.c_aideroom, new_name, ROOMNAMELEN);
1213 end_critical_section(S_CONFIG);
1215 /* If the room name changed, then there are now two room
1216 * records, so we have to delete the old one.
1218 if (strcasecmp(new_name, old_name)) {
1219 b_deleteroom(actual_old_name);
1225 end_critical_section(S_ROOMS);
1227 /* Adjust the floor reference counts if necessary */
1228 if (new_floor != old_floor) {
1229 lgetfloor(&flbuf, old_floor);
1230 --flbuf.f_ref_count;
1231 lputfloor(&flbuf, old_floor);
1232 lprintf(CTDL_DEBUG, "Reference count for floor %d is now %d\n", old_floor, flbuf.f_ref_count);
1233 lgetfloor(&flbuf, new_floor);
1234 ++flbuf.f_ref_count;
1235 lputfloor(&flbuf, new_floor);
1236 lprintf(CTDL_DEBUG, "Reference count for floor %d is now %d\n", new_floor, flbuf.f_ref_count);
1239 /* ...and everybody say "YATTA!" */
1245 * set room parameters (aide or room aide command)
1247 void cmd_setr(char *args)
1253 char new_name[ROOMNAMELEN];
1255 if (CtdlAccessCheck(ac_logged_in)) return;
1257 if (num_parms(args) >= 6) {
1258 new_floor = extract_int(args, 5);
1260 new_floor = (-1); /* don't change the floor */
1263 /* When is a new name more than just a new name? When the old name
1264 * has a namespace prefix.
1266 if (CC->room.QRflags & QR_MAILBOX) {
1267 sprintf(new_name, "%010ld.", atol(CC->room.QRname) );
1269 safestrncpy(new_name, "", sizeof new_name);
1271 extract_token(&new_name[strlen(new_name)], args, 0, '|', (sizeof new_name - strlen(new_name)));
1273 r = CtdlRenameRoom(CC->room.QRname, new_name, new_floor);
1275 if (r == crr_room_not_found) {
1276 cprintf("%d Internal error - room not found?\n", ERROR + INTERNAL_ERROR);
1277 } else if (r == crr_already_exists) {
1278 cprintf("%d '%s' already exists.\n",
1279 ERROR + ALREADY_EXISTS, new_name);
1280 } else if (r == crr_noneditable) {
1281 cprintf("%d Cannot edit this room.\n", ERROR + NOT_HERE);
1282 } else if (r == crr_invalid_floor) {
1283 cprintf("%d Target floor does not exist.\n",
1284 ERROR + INVALID_FLOOR_OPERATION);
1285 } else if (r == crr_access_denied) {
1286 cprintf("%d You do not have permission to edit '%s'\n",
1287 ERROR + HIGHER_ACCESS_REQUIRED,
1289 } else if (r != crr_ok) {
1290 cprintf("%d Error: CtdlRenameRoom() returned %d\n",
1291 ERROR + INTERNAL_ERROR, r);
1298 getroom(&CC->room, new_name);
1300 /* Now we have to do a bunch of other stuff */
1302 if (num_parms(args) >= 7) {
1303 new_order = extract_int(args, 6);
1306 if (new_order > 127)
1310 lgetroom(&CC->room, CC->room.QRname);
1312 /* Directory room */
1313 extract_token(buf, args, 2, '|', sizeof buf);
1315 safestrncpy(CC->room.QRdirname, buf,
1316 sizeof CC->room.QRdirname);
1319 if (num_parms(args) >= 8) {
1320 CC->room.QRdefaultview = extract_int(args, 7);
1323 /* Second set of flags */
1324 if (num_parms(args) >= 9) {
1325 CC->room.QRflags2 = extract_int(args, 8);
1329 CC->room.QRflags = (extract_int(args, 3) | QR_INUSE);
1330 /* Clean up a client boo-boo: if the client set the room to
1331 * guess-name or passworded, ensure that the private flag is
1334 if ((CC->room.QRflags & QR_GUESSNAME)
1335 || (CC->room.QRflags & QR_PASSWORDED))
1336 CC->room.QRflags |= QR_PRIVATE;
1338 /* Some changes can't apply to BASEROOM */
1339 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1341 CC->room.QRorder = 0;
1342 CC->room.QRpasswd[0] = '\0';
1343 CC->room.QRflags &= ~(QR_PRIVATE & QR_PASSWORDED &
1344 QR_GUESSNAME & QR_PREFONLY & QR_MAILBOX);
1345 CC->room.QRflags |= QR_PERMANENT;
1347 /* March order (doesn't apply to AIDEROOM) */
1348 if (num_parms(args) >= 7)
1349 CC->room.QRorder = (char) new_order;
1351 extract_token(buf, args, 1, '|', sizeof buf);
1353 safestrncpy(CC->room.QRpasswd, buf,
1354 sizeof CC->room.QRpasswd);
1355 /* Kick everyone out if the client requested it
1356 * (by changing the room's generation number)
1358 if (extract_int(args, 4)) {
1359 time(&CC->room.QRgen);
1362 /* Some changes can't apply to AIDEROOM */
1363 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1365 CC->room.QRorder = 0;
1366 CC->room.QRflags &= ~QR_MAILBOX;
1367 CC->room.QRflags |= QR_PERMANENT;
1370 /* Write the room record back to disk */
1371 lputroom(&CC->room);
1373 /* Create a room directory if necessary */
1374 if (CC->room.QRflags & QR_DIRECTORY) {
1375 snprintf(buf, sizeof buf, "./files/%s", 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 * Asynchronously schedule a room for deletion. The room will appear
1483 * deleted to the user(s), but it won't actually get purged from the
1484 * database until THE DREADED AUTO-PURGER makes its next run.
1486 void schedule_room_for_deletion(struct ctdlroom *qrbuf)
1488 char old_name[ROOMNAMELEN];
1491 lprintf(CTDL_NOTICE, "Scheduling room <%s> for deletion\n",
1494 safestrncpy(old_name, qrbuf->QRname, sizeof old_name);
1496 getroom(qrbuf, qrbuf->QRname);
1498 /* Turn the room into a private mailbox owned by a user who doesn't
1499 * exist. This will immediately make the room invisible to everyone,
1500 * and qualify the room for purging.
1502 snprintf(qrbuf->QRname, sizeof qrbuf->QRname, "9999999999.%08lx.%04d.%s",
1507 qrbuf->QRflags |= QR_MAILBOX;
1508 time(&qrbuf->QRgen); /* Use a timestamp as the new generation number */
1512 b_deleteroom(old_name);
1518 * Back end processing to delete a room and everything associated with it
1519 * (This one is synchronous and should only get called by THE DREADED
1520 * AUTO-PURGER in serv_expire.c. All user-facing code should call
1521 * the asynchronous schedule_room_for_deletion() instead.)
1523 void delete_room(struct ctdlroom *qrbuf)
1528 lprintf(CTDL_NOTICE, "Deleting room <%s>\n", qrbuf->QRname);
1530 /* Delete the info file */
1531 assoc_file_name(filename, sizeof filename, qrbuf, "info");
1534 /* Delete the image file */
1535 assoc_file_name(filename, sizeof filename, qrbuf, "images");
1538 /* Delete the room's network config file */
1539 assoc_file_name(filename, sizeof filename, qrbuf, "netconfigs");
1542 /* Delete the messages in the room
1543 * (Careful: this opens an S_ROOMS critical section!)
1545 CtdlDeleteMessages(qrbuf->QRname, 0L, "");
1547 /* Flag the room record as not in use */
1548 lgetroom(qrbuf, qrbuf->QRname);
1552 /* then decrement the reference count for the floor */
1553 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1554 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1555 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1557 /* Delete the room record from the database! */
1558 b_deleteroom(qrbuf->QRname);
1564 * Check access control for deleting a room
1566 int CtdlDoIHavePermissionToDeleteThisRoom(struct ctdlroom *qr) {
1568 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
1572 if (is_noneditable(qr)) {
1577 * For mailboxes, check stuff
1579 if (qr->QRflags & QR_MAILBOX) {
1581 if (strlen(qr->QRname) < 12) return(0); /* bad name */
1583 if (atol(qr->QRname) != CC->user.usernum) {
1584 return(0); /* not my room */
1587 /* Can't delete your Mail> room */
1588 if (!strcasecmp(&qr->QRname[12], MAILROOM)) return(0);
1590 /* Otherwise it's ok */
1595 * For normal rooms, just check for aide or room aide status.
1597 return(is_room_aide());
1601 * aide command: kill the current room
1603 void cmd_kill(char *argbuf)
1605 char deleted_room_name[ROOMNAMELEN];
1609 kill_ok = extract_int(argbuf, 0);
1611 if (CtdlDoIHavePermissionToDeleteThisRoom(&CC->room) == 0) {
1612 cprintf("%d Can't delete this room.\n", ERROR + NOT_HERE);
1616 if (CC->room.QRflags & QR_MAILBOX) {
1617 safestrncpy(deleted_room_name, &CC->room.QRname[11], sizeof deleted_room_name);
1620 safestrncpy(deleted_room_name, CC->room.QRname, sizeof deleted_room_name);
1623 /* Do the dirty work */
1624 schedule_room_for_deletion(&CC->room);
1626 /* Return to the Lobby */
1627 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
1629 /* tell the world what we did */
1630 snprintf(msg, sizeof msg, "%s> killed by %s\n",
1631 deleted_room_name, CC->curr_user);
1633 cprintf("%d '%s' deleted.\n", CIT_OK, deleted_room_name);
1635 cprintf("%d ok to delete.\n", CIT_OK);
1641 * Internal code to create a new room (returns room flags)
1643 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only,
1644 * 4=mailbox, 5=mailbox, but caller supplies namespace
1646 unsigned create_room(char *new_room_name,
1648 char *new_room_pass,
1655 struct ctdlroom qrbuf;
1659 lprintf(CTDL_DEBUG, "create_room(name=%s, type=%d, view=%d)\n",
1660 new_room_name, new_room_type, new_room_view);
1662 if (getroom(&qrbuf, new_room_name) == 0) {
1663 lprintf(CTDL_DEBUG, "%s already exists.\n", new_room_name);
1667 memset(&qrbuf, 0, sizeof(struct ctdlroom));
1668 safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
1669 qrbuf.QRflags = QR_INUSE;
1670 if (new_room_type > 0)
1671 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1672 if (new_room_type == 1)
1673 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1674 if (new_room_type == 2)
1675 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1676 if ( (new_room_type == 4) || (new_room_type == 5) )
1677 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1679 /* If the user is requesting a personal room, set up the room
1680 * name accordingly (prepend the user number)
1682 if (new_room_type == 4) {
1683 MailboxName(qrbuf.QRname, sizeof qrbuf.QRname, &CC->user, new_room_name);
1686 safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
1689 /* If the room is private, and the system administrator has elected
1690 * to automatically grant room aide privileges, do so now; otherwise,
1691 * set the room aide to undefined.
1693 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1694 qrbuf.QRroomaide = CC->user.usernum;
1696 qrbuf.QRroomaide = (-1L);
1700 * If the caller is only interested in testing whether this will work,
1701 * return now without creating the room.
1703 if (!really_create) return (qrbuf.QRflags);
1705 qrbuf.QRnumber = get_new_room_number();
1706 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1707 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1708 qrbuf.QRfloor = new_room_floor;
1709 qrbuf.QRdefaultview = new_room_view;
1711 /* save what we just did... */
1714 /* bump the reference count on whatever floor the room is on */
1715 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1716 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1717 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1719 /* Grant the creator access to the room unless the avoid_access
1720 * parameter was specified.
1722 if (avoid_access == 0) {
1723 lgetuser(&CC->user, CC->curr_user);
1724 CtdlGetRelationship(&vbuf, &CC->user, &qrbuf);
1725 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1726 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1727 CtdlSetRelationship(&vbuf, &CC->user, &qrbuf);
1728 lputuser(&CC->user);
1731 /* resume our happy day */
1732 return (qrbuf.QRflags);
1739 void cmd_cre8(char *args)
1742 char new_room_name[ROOMNAMELEN];
1744 char new_room_pass[32];
1747 char *notification_message = NULL;
1750 int avoid_access = 0;
1752 cre8_ok = extract_int(args, 0);
1753 extract_token(new_room_name, args, 1, '|', sizeof new_room_name);
1754 new_room_name[ROOMNAMELEN - 1] = 0;
1755 new_room_type = extract_int(args, 2);
1756 extract_token(new_room_pass, args, 3, '|', sizeof new_room_pass);
1757 avoid_access = extract_int(args, 5);
1758 new_room_view = extract_int(args, 6);
1759 new_room_pass[9] = 0;
1762 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1763 cprintf("%d Invalid room name.\n", ERROR + ILLEGAL_VALUE);
1767 if (!strcasecmp(new_room_name, MAILROOM)) {
1768 cprintf("%d '%s' already exists.\n",
1769 ERROR + ALREADY_EXISTS, new_room_name);
1773 if (num_parms(args) >= 5) {
1774 fl = cgetfloor(extract_int(args, 4));
1776 cprintf("%d Invalid floor number.\n",
1777 ERROR + INVALID_FLOOR_OPERATION);
1780 else if ((fl->f_flags & F_INUSE) == 0) {
1781 cprintf("%d Invalid floor number.\n",
1782 ERROR + INVALID_FLOOR_OPERATION);
1785 new_room_floor = extract_int(args, 4);
1789 if (CtdlAccessCheck(ac_logged_in)) return;
1791 if (CC->user.axlevel < config.c_createax) {
1792 cprintf("%d You need higher access to create rooms.\n",
1793 ERROR + HIGHER_ACCESS_REQUIRED);
1797 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1798 cprintf("%d Ok to create rooms.\n", CIT_OK);
1802 if ((new_room_type < 0) || (new_room_type > 5)) {
1803 cprintf("%d Invalid room type.\n", ERROR + ILLEGAL_VALUE);
1807 if (new_room_type == 5) {
1808 if (CC->user.axlevel < 6) {
1809 cprintf("%d Higher access required\n",
1810 ERROR + HIGHER_ACCESS_REQUIRED);
1815 /* Check to make sure the requested room name doesn't already exist */
1816 newflags = create_room(new_room_name,
1817 new_room_type, new_room_pass, new_room_floor,
1818 0, avoid_access, new_room_view);
1819 if (newflags == 0) {
1820 cprintf("%d '%s' already exists.\n",
1821 ERROR + ALREADY_EXISTS, new_room_name);
1826 cprintf("%d OK to create '%s'\n", CIT_OK, new_room_name);
1830 /* If we reach this point, the room needs to be created. */
1832 newflags = create_room(new_room_name,
1833 new_room_type, new_room_pass, new_room_floor, 1, 0,
1836 /* post a message in Aide> describing the new room */
1837 notification_message = malloc(1024);
1838 snprintf(notification_message, 1024,
1839 "%s> created by %s%s%s%s%s%s\n",
1842 ((newflags & QR_MAILBOX) ? " [personal]" : ""),
1843 ((newflags & QR_PRIVATE) ? " [private]" : ""),
1844 ((newflags & QR_GUESSNAME) ? " [hidden]" : ""),
1845 ((newflags & QR_PASSWORDED) ? " Password: " : ""),
1846 ((newflags & QR_PASSWORDED) ? new_room_pass : "")
1848 aide_message(notification_message);
1849 free(notification_message);
1851 cprintf("%d '%s' has been created.\n", CIT_OK, new_room_name);
1856 void cmd_einf(char *ok)
1857 { /* enter info file for current room */
1859 char infofilename[SIZ];
1864 if (CtdlAccessCheck(ac_room_aide)) return;
1866 if (atoi(ok) == 0) {
1867 cprintf("%d Ok.\n", CIT_OK);
1870 assoc_file_name(infofilename, sizeof infofilename, &CC->room, "info");
1871 lprintf(CTDL_DEBUG, "opening\n");
1872 fp = fopen(infofilename, "w");
1873 lprintf(CTDL_DEBUG, "checking\n");
1875 cprintf("%d Cannot open %s: %s\n",
1876 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1879 cprintf("%d Send info...\n", SEND_LISTING);
1882 client_getln(buf, sizeof buf);
1883 if (strcmp(buf, "000"))
1884 fprintf(fp, "%s\n", buf);
1885 } while (strcmp(buf, "000"));
1888 /* now update the room index so people will see our new info */
1889 lgetroom(&CC->room, CC->room.QRname); /* lock so no one steps on us */
1890 CC->room.QRinfo = CC->room.QRhighest + 1L;
1891 lputroom(&CC->room);
1896 * cmd_lflr() - List all known floors
1903 if (CtdlAccessCheck(ac_logged_in)) return;
1905 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1907 for (a = 0; a < MAXFLOORS; ++a) {
1908 getfloor(&flbuf, a);
1909 if (flbuf.f_flags & F_INUSE) {
1910 cprintf("%d|%s|%d\n",
1922 * create a new floor
1924 void cmd_cflr(char *argbuf)
1926 char new_floor_name[256];
1929 int free_slot = (-1);
1932 extract_token(new_floor_name, argbuf, 0, '|', sizeof new_floor_name);
1933 cflr_ok = extract_int(argbuf, 1);
1935 if (CtdlAccessCheck(ac_aide)) return;
1937 if (strlen(new_floor_name) == 0) {
1938 cprintf("%d Blank floor name not allowed.\n",
1939 ERROR + ILLEGAL_VALUE);
1943 for (a = 0; a < MAXFLOORS; ++a) {
1944 getfloor(&flbuf, a);
1946 /* note any free slots while we're scanning... */
1947 if (((flbuf.f_flags & F_INUSE) == 0)
1951 /* check to see if it already exists */
1952 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1953 && (flbuf.f_flags & F_INUSE)) {
1954 cprintf("%d Floor '%s' already exists.\n",
1955 ERROR + ALREADY_EXISTS,
1961 if (free_slot < 0) {
1962 cprintf("%d There is no space available for a new floor.\n",
1963 ERROR + INVALID_FLOOR_OPERATION);
1967 cprintf("%d ok to create...\n", CIT_OK);
1970 lgetfloor(&flbuf, free_slot);
1971 flbuf.f_flags = F_INUSE;
1972 flbuf.f_ref_count = 0;
1973 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1974 lputfloor(&flbuf, free_slot);
1975 cprintf("%d %d\n", CIT_OK, free_slot);
1983 void cmd_kflr(char *argbuf)
1986 int floor_to_delete;
1990 floor_to_delete = extract_int(argbuf, 0);
1991 kflr_ok = extract_int(argbuf, 1);
1993 if (CtdlAccessCheck(ac_aide)) return;
1995 lgetfloor(&flbuf, floor_to_delete);
1998 if ((flbuf.f_flags & F_INUSE) == 0) {
1999 cprintf("%d Floor %d not in use.\n",
2000 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
2003 if (flbuf.f_ref_count != 0) {
2004 cprintf("%d Cannot delete; floor contains %d rooms.\n",
2005 ERROR + INVALID_FLOOR_OPERATION,
2010 cprintf("%d Ok\n", CIT_OK);
2012 cprintf("%d Ok to delete...\n", CIT_OK);
2019 if ((delete_ok == 1) && (kflr_ok == 1))
2021 lputfloor(&flbuf, floor_to_delete);
2027 void cmd_eflr(char *argbuf)
2033 np = num_parms(argbuf);
2035 cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
2039 if (CtdlAccessCheck(ac_aide)) return;
2041 floor_num = extract_int(argbuf, 0);
2042 lgetfloor(&flbuf, floor_num);
2043 if ((flbuf.f_flags & F_INUSE) == 0) {
2044 lputfloor(&flbuf, floor_num);
2045 cprintf("%d Floor %d is not in use.\n",
2046 ERROR + INVALID_FLOOR_OPERATION, floor_num);
2050 extract_token(flbuf.f_name, argbuf, 1, '|', sizeof flbuf.f_name);
2051 lputfloor(&flbuf, floor_num);
2053 cprintf("%d Ok\n", CIT_OK);