4 * Server functions which perform operations on room objects.
21 #include "sysdep_decls.h"
25 #include "citserver.h"
30 * Generic routine for determining user access to rooms
32 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf)
37 /* for internal programs, always do everything */
38 if (((CC->internal_pgm)) && (roombuf->QRflags & QR_INUSE)) {
39 return (UA_KNOWN | UA_GOTOALLOWED);
41 /* For mailbox rooms, only allow access to the owner */
42 if (roombuf->QRflags & QR_MAILBOX) {
43 if (userbuf->usernum != atol(roombuf->QRname)) {
47 /* Locate any applicable user/room relationships */
48 CtdlGetRelationship(&vbuf, userbuf, roombuf);
50 /* Force the properties of the Aide room */
51 if (!strcasecmp(roombuf->QRname, AIDEROOM)) {
52 if (userbuf->axlevel >= 6) {
53 retval = UA_KNOWN | UA_GOTOALLOWED;
59 /* For mailboxes, we skip all the access stuff (and we've
60 * already checked by this point that the mailbox belongs
63 if (roombuf->QRflags & QR_MAILBOX) {
64 retval = UA_KNOWN | UA_GOTOALLOWED;
67 /* If this is a public room, it's accessible... */
68 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
69 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
71 /* If this is a preferred users only room, check access level */
72 if (roombuf->QRflags & QR_PREFONLY) {
73 if (userbuf->axlevel < 5) {
74 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
77 /* For private rooms, check the generation number matchups */
78 if (roombuf->QRflags & QR_PRIVATE) {
80 /* An explicit match means the user belongs in this room */
81 if (vbuf.v_flags & V_ACCESS) {
82 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
84 /* Otherwise, check if this is a guess-name or passworded
85 * room. If it is, a goto may at least be attempted
87 else if ((roombuf->QRflags & QR_PRIVATE)
88 || (roombuf->QRflags & QR_PASSWORDED)) {
89 retval = retval & ~UA_KNOWN;
90 retval = retval | UA_GOTOALLOWED;
93 /* Check to see if the user has forgotten this room */
94 if (vbuf.v_flags & V_FORGET) {
95 retval = retval & ~UA_KNOWN;
96 retval = retval | UA_ZAPPED;
98 /* If user is explicitly locked out of this room, deny everything */
99 if (vbuf.v_flags & V_LOCKOUT) {
100 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
102 /* Aides get access to everything */
103 if (userbuf->axlevel >= 6) {
104 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
105 retval = retval & ~UA_ZAPPED;
107 NEWMSG: /* By the way, we also check for the presence of new messages */
108 if ((roombuf->QRhighest) > (vbuf.v_lastseen)) {
109 retval = retval | UA_HASNEWMSGS;
115 * Self-checking stuff for a room record read into memory
117 void room_sanity_check(struct quickroom *qrbuf)
119 /* Mailbox rooms are always on the lowest floor */
120 if (qrbuf->QRflags & QR_MAILBOX) {
123 /* Listing order of 0 is illegal except for base rooms */
124 if (qrbuf->QRorder == 0)
125 if (!is_noneditable(qrbuf))
131 * getroom() - retrieve room data from disk
133 int getroom(struct quickroom *qrbuf, char *room_name)
135 struct cdbdata *cdbqr;
136 char lowercase_name[ROOMNAMELEN];
137 char personal_lowercase_name[ROOMNAMELEN];
140 for (a = 0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
141 lowercase_name[a] = tolower(room_name[a]);
143 lowercase_name[a] = 0;
145 memset(qrbuf, 0, sizeof(struct quickroom));
147 /* First, try the public namespace */
148 cdbqr = cdb_fetch(CDB_QUICKROOM,
149 lowercase_name, strlen(lowercase_name));
151 /* If that didn't work, try the user's personal namespace */
153 sprintf(personal_lowercase_name, "%010ld.%s",
154 CC->usersupp.usernum, lowercase_name);
155 cdbqr = cdb_fetch(CDB_QUICKROOM,
156 personal_lowercase_name,
157 strlen(personal_lowercase_name));
160 memcpy(qrbuf, cdbqr->ptr,
161 ((cdbqr->len > sizeof(struct quickroom)) ?
162 sizeof(struct quickroom) : cdbqr->len));
165 room_sanity_check(qrbuf);
174 * lgetroom() - same as getroom() but locks the record (if supported)
176 int lgetroom(struct quickroom *qrbuf, char *room_name)
179 retval = getroom(qrbuf, room_name);
180 if (retval == 0) begin_critical_section(S_QUICKROOM);
186 * b_putroom() - back end to putroom() and b_deleteroom()
187 * (if the supplied buffer is NULL, delete the room record)
189 void b_putroom(struct quickroom *qrbuf, char *room_name)
191 char lowercase_name[ROOMNAMELEN];
194 for (a = 0; a <= strlen(room_name); ++a) {
195 lowercase_name[a] = tolower(room_name[a]);
199 cdb_delete(CDB_QUICKROOM,
200 lowercase_name, strlen(lowercase_name));
202 time(&qrbuf->QRmtime);
203 cdb_store(CDB_QUICKROOM,
204 lowercase_name, strlen(lowercase_name),
205 qrbuf, sizeof(struct quickroom));
211 * putroom() - store room data to disk
213 void putroom(struct quickroom *qrbuf) {
214 b_putroom(qrbuf, qrbuf->QRname);
219 * b_deleteroom() - delete a room record from disk
221 void b_deleteroom(char *room_name) {
222 b_putroom(NULL, room_name);
228 * lputroom() - same as putroom() but unlocks the record (if supported)
230 void lputroom(struct quickroom *qrbuf)
234 end_critical_section(S_QUICKROOM);
238 /****************************************************************************/
241 * getfloor() - retrieve floor data from disk
243 void getfloor(struct floor *flbuf, int floor_num)
245 struct cdbdata *cdbfl;
247 memset(flbuf, 0, sizeof(struct floor));
248 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
250 memcpy(flbuf, cdbfl->ptr,
251 ((cdbfl->len > sizeof(struct floor)) ?
252 sizeof(struct floor) : cdbfl->len));
255 if (floor_num == 0) {
256 strcpy(flbuf->f_name, "Main Floor");
257 flbuf->f_flags = F_INUSE;
258 flbuf->f_ref_count = 3;
265 * lgetfloor() - same as getfloor() but locks the record (if supported)
267 void lgetfloor(struct floor *flbuf, int floor_num)
270 begin_critical_section(S_FLOORTAB);
271 getfloor(flbuf, floor_num);
276 * putfloor() - store floor data on disk
278 void putfloor(struct floor *flbuf, int floor_num)
280 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
281 flbuf, sizeof(struct floor));
286 * lputfloor() - same as putfloor() but unlocks the record (if supported)
288 void lputfloor(struct floor *flbuf, int floor_num)
291 putfloor(flbuf, floor_num);
292 end_critical_section(S_FLOORTAB);
298 * Traverse the room file...
300 void ForEachRoom(void (*CallBack) (struct quickroom *EachRoom, void *out_data),
303 struct quickroom qrbuf;
304 struct cdbdata *cdbqr;
306 cdb_rewind(CDB_QUICKROOM);
308 while (cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
309 memset(&qrbuf, 0, sizeof(struct quickroom));
310 memcpy(&qrbuf, cdbqr->ptr,
311 ((cdbqr->len > sizeof(struct quickroom)) ?
312 sizeof(struct quickroom) : cdbqr->len));
314 room_sanity_check(&qrbuf);
315 if (qrbuf.QRflags & QR_INUSE)
316 (*CallBack)(&qrbuf, in_data);
322 * delete_msglist() - delete room message pointers
324 void delete_msglist(struct quickroom *whichroom)
326 struct cdbdata *cdbml;
328 /* Make sure the msglist we're deleting actually exists, otherwise
329 * gdbm will complain when we try to delete an invalid record
331 cdbml = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
335 /* Go ahead and delete it */
336 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
344 * sort message pointers
345 * (returns new msg count)
347 int sort_msglist(long listptrs[], int oldcount)
358 for (a = numitems - 2; a >= 0; --a) {
359 for (b = 0; b <= a; ++b) {
360 if (listptrs[b] > (listptrs[b + 1])) {
362 hold2 = listptrs[b + 1];
364 listptrs[b + 1] = hold1;
369 /* and yank any nulls */
370 while ((numitems > 0) && (listptrs[0] == 0L)) {
371 memcpy(&listptrs[0], &listptrs[1],
372 (sizeof(long) * (numitems - 1)));
381 * Determine whether a given room is non-editable.
383 int is_noneditable(struct quickroom *qrbuf)
386 /* Lobby> and Aide> are non-editable */
387 if (!strcasecmp(qrbuf->QRname, BASEROOM))
389 else if (!strcasecmp(qrbuf->QRname, AIDEROOM))
392 /* Mail> rooms are also non-editable */
393 else if ( (qrbuf->QRflags & QR_MAILBOX)
394 && (!strcasecmp(&qrbuf->QRname[11], MAILROOM)) )
397 /* Everything else is editable */
405 * Back-back-end for all room listing commands
407 void list_roomname(struct quickroom *qrbuf)
409 char truncated_roomname[ROOMNAMELEN];
411 /* For mailbox rooms, chop off the owner prefix */
412 if (qrbuf->QRflags & QR_MAILBOX) {
413 strcpy(truncated_roomname, qrbuf->QRname);
414 strcpy(truncated_roomname, &truncated_roomname[11]);
415 cprintf("%s", truncated_roomname);
417 /* For all other rooms, just display the name in its entirety */
419 cprintf("%s", qrbuf->QRname);
422 /* ...and now the other parameters */
423 cprintf("|%u|%d|%d\n",
425 (int) qrbuf->QRfloor,
426 (int) qrbuf->QRorder);
431 * cmd_lrms() - List all accessible rooms, known or forgotten
433 void cmd_lrms_backend(struct quickroom *qrbuf, void *data)
435 int FloorBeingSearched = (-1);
436 FloorBeingSearched = *(int *)data;
438 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
439 & (UA_KNOWN | UA_ZAPPED)))
440 && ((qrbuf->QRfloor == (FloorBeingSearched))
441 || ((FloorBeingSearched) < 0)))
442 list_roomname(qrbuf);
445 void cmd_lrms(char *argbuf)
447 int FloorBeingSearched = (-1);
448 if (strlen(argbuf) > 0)
449 FloorBeingSearched = extract_int(argbuf, 0);
451 if (CtdlAccessCheck(ac_logged_in)) return;
453 if (getuser(&CC->usersupp, CC->curr_user)) {
454 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
457 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
459 ForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
466 * cmd_lkra() - List all known rooms
468 void cmd_lkra_backend(struct quickroom *qrbuf, void *data)
470 int FloorBeingSearched = (-1);
471 FloorBeingSearched = *(int *)data;
473 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
475 && ((qrbuf->QRfloor == (FloorBeingSearched))
476 || ((FloorBeingSearched) < 0)))
477 list_roomname(qrbuf);
480 void cmd_lkra(char *argbuf)
482 int FloorBeingSearched = (-1);
483 if (strlen(argbuf) > 0)
484 FloorBeingSearched = extract_int(argbuf, 0);
486 if (CtdlAccessCheck(ac_logged_in)) return;
488 if (getuser(&CC->usersupp, CC->curr_user)) {
489 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
492 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
494 ForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
501 * cmd_lkrn() - List all known rooms with new messages
503 void cmd_lkrn_backend(struct quickroom *qrbuf, void *data)
506 int FloorBeingSearched = (-1);
507 FloorBeingSearched = *(int *)data;
509 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
511 && (ra & UA_HASNEWMSGS)
512 && ((qrbuf->QRfloor == (FloorBeingSearched))
513 || ((FloorBeingSearched) < 0)))
514 list_roomname(qrbuf);
517 void cmd_lkrn(char *argbuf)
519 int FloorBeingSearched = (-1);
520 if (strlen(argbuf) > 0)
521 FloorBeingSearched = extract_int(argbuf, 0);
523 if (CtdlAccessCheck(ac_logged_in)) return;
525 if (getuser(&CC->usersupp, CC->curr_user)) {
526 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
529 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
531 ForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
538 * cmd_lkro() - List all known rooms
540 void cmd_lkro_backend(struct quickroom *qrbuf, void *data)
543 int FloorBeingSearched = (-1);
544 FloorBeingSearched = *(int *)data;
546 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
548 && ((ra & UA_HASNEWMSGS) == 0)
549 && ((qrbuf->QRfloor == (FloorBeingSearched))
550 || ((FloorBeingSearched) < 0)))
551 list_roomname(qrbuf);
554 void cmd_lkro(char *argbuf)
556 int FloorBeingSearched = (-1);
557 if (strlen(argbuf) > 0)
558 FloorBeingSearched = extract_int(argbuf, 0);
560 if (CtdlAccessCheck(ac_logged_in)) return;
562 if (getuser(&CC->usersupp, CC->curr_user)) {
563 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
566 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
568 ForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
575 * cmd_lzrm() - List all forgotten rooms
577 void cmd_lzrm_backend(struct quickroom *qrbuf, void *data)
580 int FloorBeingSearched = (-1);
581 FloorBeingSearched = *(int *)data;
583 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
584 if ((ra & UA_GOTOALLOWED)
586 && ((qrbuf->QRfloor == (FloorBeingSearched))
587 || ((FloorBeingSearched) < 0)))
588 list_roomname(qrbuf);
591 void cmd_lzrm(char *argbuf)
593 int FloorBeingSearched = (-1);
594 if (strlen(argbuf) > 0)
595 FloorBeingSearched = extract_int(argbuf, 0);
597 if (CtdlAccessCheck(ac_logged_in)) return;
599 if (getuser(&CC->usersupp, CC->curr_user)) {
600 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
603 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
605 ForEachRoom(cmd_lzrm_backend, &FloorBeingSearched);
611 void usergoto(char *where, int display_result, int *retmsgs, int *retnew)
614 int new_messages = 0;
615 int total_messages = 0;
619 int newmailcount = 0;
621 char truncated_roomname[ROOMNAMELEN];
622 struct cdbdata *cdbfr;
623 long *msglist = NULL;
626 strcpy(CC->quickroom.QRname, where);
627 getroom(&CC->quickroom, where);
629 lgetuser(&CC->usersupp, CC->curr_user);
630 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
632 /* Know the room ... but not if it's the page log room */
633 if (strcasecmp(where, config.c_logpages)) {
634 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
635 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
637 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
638 lputuser(&CC->usersupp);
640 /* check for new mail */
641 newmailcount = NewMailCount();
643 /* set info to 1 if the user needs to read the room's info file */
644 if (CC->quickroom.QRinfo > vbuf.v_lastseen)
648 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->quickroom.QRnumber, sizeof(long));
650 msglist = mallok(cdbfr->len);
651 memcpy(msglist, cdbfr->ptr, cdbfr->len);
652 num_msgs = cdbfr->len / sizeof(long);
656 if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
657 if (msglist[a] > 0L) {
659 if (msglist[a] > vbuf.v_lastseen) {
665 if (msglist != NULL) phree(msglist);
667 if (CC->quickroom.QRflags & QR_MAILBOX)
672 if ((CC->quickroom.QRroomaide == CC->usersupp.usernum)
673 || (CC->usersupp.axlevel >= 6))
678 strcpy(truncated_roomname, CC->quickroom.QRname);
679 if (CC->quickroom.QRflags & QR_MAILBOX) {
680 strcpy(truncated_roomname, &truncated_roomname[11]);
683 if (retmsgs != NULL) *retmsgs = total_messages;
684 if (retnew != NULL) *retnew = new_messages;
685 lprintf(9, "<%s> %d new of %d total messages\n",
686 CC->quickroom.QRname, new_messages, total_messages);
689 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
690 OK, CtdlCheckExpress(),
692 new_messages, total_messages,
693 info, CC->quickroom.QRflags,
694 CC->quickroom.QRhighest,
696 rmailflag, raideflag, newmailcount,
697 CC->quickroom.QRfloor);
703 * cmd_goto() - goto a new room
705 void cmd_goto(char *gargs)
707 struct quickroom QRscratch;
711 char augmented_roomname[256];
715 if (CtdlAccessCheck(ac_logged_in)) return;
717 extract(towhere, gargs, 0);
718 extract(password, gargs, 1);
720 getuser(&CC->usersupp, CC->curr_user);
722 if (!strcasecmp(towhere, "_BASEROOM_"))
723 strcpy(towhere, BASEROOM);
725 if (!strcasecmp(towhere, "_MAIL_"))
726 strcpy(towhere, MAILROOM);
728 if (!strcasecmp(towhere, "_BITBUCKET_"))
729 strcpy(towhere, config.c_twitroom);
732 /* First try a regular match */
733 c = getroom(&QRscratch, towhere);
735 /* Then try a mailbox name match */
737 MailboxName(augmented_roomname, &CC->usersupp, towhere);
738 c = getroom(&QRscratch, augmented_roomname);
740 strcpy(towhere, augmented_roomname);
743 /* And if the room was found... */
746 /* let internal programs go directly to any room */
747 if (CC->internal_pgm) {
748 usergoto(towhere, 1, NULL, NULL);
752 /* See if there is an existing user/room relationship */
753 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
755 /* normal clients have to pass through security */
756 if (ra & UA_GOTOALLOWED)
760 if ((QRscratch.QRflags & QR_PASSWORDED) &&
761 ((ra & UA_KNOWN) == 0) &&
762 (strcasecmp(QRscratch.QRpasswd, password))
764 cprintf("%d wrong or missing passwd\n",
765 ERROR + PASSWORD_REQUIRED);
767 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
768 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
769 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
770 ((ra & UA_KNOWN) == 0)) {
773 usergoto(towhere, 1, NULL, NULL);
779 NOPE: cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
785 struct usersupp temp;
786 struct cdbdata *cdbus;
788 getuser(&CC->usersupp, CC->curr_user);
789 if (CtdlAccessCheck(ac_room_aide)) return;
791 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
792 cdb_rewind(CDB_USERSUPP);
793 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
794 memset(&temp, 0, sizeof temp);
795 memcpy(&temp, cdbus->ptr, sizeof temp);
798 if ((CC->quickroom.QRflags & QR_INUSE)
799 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
801 cprintf("%s\n", temp.fullname);
808 * RDIR command for room directory
818 if (CtdlAccessCheck(ac_logged_in)) return;
820 getroom(&CC->quickroom, CC->quickroom.QRname);
821 getuser(&CC->usersupp, CC->curr_user);
823 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
824 cprintf("%d not here.\n", ERROR + NOT_HERE);
827 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
828 && (CC->usersupp.axlevel < 6)
829 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
830 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
833 cprintf("%d %s|%s/files/%s\n",
834 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->quickroom.QRdirname);
836 sprintf(buf, "ls %s/files/%s >%s 2> /dev/null",
837 BBSDIR, CC->quickroom.QRdirname, CC->temp);
840 sprintf(buf, "%s/files/%s/filedir", BBSDIR, CC->quickroom.QRdirname);
841 fd = fopen(buf, "r");
843 fd = fopen("/dev/null", "r");
845 ls = fopen(CC->temp, "r");
846 while (fgets(flnm, 256, ls) != NULL) {
847 flnm[strlen(flnm) - 1] = 0;
848 if (strcasecmp(flnm, "filedir")) {
849 sprintf(buf, "%s/files/%s/%s",
850 BBSDIR, CC->quickroom.QRdirname, flnm);
854 while ((fgets(buf, 256, fd) != NULL)
855 && (strlen(comment) == 0)) {
856 buf[strlen(buf) - 1] = 0;
857 if ((!strncasecmp(buf, flnm, strlen(flnm)))
858 && (buf[strlen(flnm)] == ' '))
860 &buf[strlen(flnm) + 1],
863 cprintf("%s|%ld|%s\n", flnm, statbuf.st_size, comment);
874 * get room parameters (aide or room aide command)
878 if (CtdlAccessCheck(ac_room_aide)) return;
881 if (is_noneditable(&CC->quickroom)) {
882 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
887 getroom(&CC->quickroom, CC->quickroom.QRname);
888 cprintf("%d%c%s|%s|%s|%d|%d|%d\n",
889 OK, CtdlCheckExpress(),
890 CC->quickroom.QRname,
891 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
892 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
893 CC->quickroom.QRflags,
894 (int) CC->quickroom.QRfloor,
895 (int) CC->quickroom.QRorder);
900 * set room parameters (aide or room aide command)
902 void cmd_setr(char *args)
906 char old_name[ROOMNAMELEN];
911 if (CtdlAccessCheck(ac_room_aide)) return;
913 if (is_noneditable(&CC->quickroom)) {
918 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
924 if (num_parms(args) >= 6) {
925 getfloor(&flbuf, extract_int(args, 5));
926 if ((flbuf.f_flags & F_INUSE) == 0) {
927 cprintf("%d Invalid floor number.\n",
928 ERROR + INVALID_FLOOR_OPERATION);
932 if (num_parms(args) >= 7) {
933 new_order = extract_int(args, 6);
939 lgetroom(&CC->quickroom, CC->quickroom.QRname);
941 /* Non-editable base rooms can't be renamed */
942 strcpy(old_name, CC->quickroom.QRname);
944 extract(buf, args, 0);
945 buf[ROOMNAMELEN] = 0;
946 safestrncpy(CC->quickroom.QRname, buf,
947 sizeof CC->quickroom.QRname);
950 extract(buf, args, 1);
952 safestrncpy(CC->quickroom.QRpasswd, buf, sizeof CC->quickroom.QRpasswd);
953 extract(buf, args, 2);
955 safestrncpy(CC->quickroom.QRdirname, buf,
956 sizeof CC->quickroom.QRdirname);
957 CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
958 if (num_parms(args) >= 7)
959 CC->quickroom.QRorder = (char) new_order;
961 /* Clean up a client boo-boo: if the client set the room to
962 * guess-name or passworded, ensure that the private flag is
965 if ((CC->quickroom.QRflags & QR_GUESSNAME)
966 || (CC->quickroom.QRflags & QR_PASSWORDED))
967 CC->quickroom.QRflags |= QR_PRIVATE;
969 /* Kick everyone out if the client requested it (by changing the
970 * room's generation number)
972 if (extract_int(args, 4)) {
973 time(&CC->quickroom.QRgen);
975 old_floor = CC->quickroom.QRfloor;
976 if (num_parms(args) >= 6) {
977 CC->quickroom.QRfloor = extract_int(args, 5);
979 /* Write the room record back to disk */
980 lputroom(&CC->quickroom);
982 /* If the room name changed, then there are now two room records,
983 * so we have to delete the old one.
985 if (strcasecmp(CC->quickroom.QRname, old_name)) {
986 b_deleteroom(old_name);
988 /* adjust the floor reference counts */
989 lgetfloor(&flbuf, old_floor);
991 lputfloor(&flbuf, old_floor);
992 lgetfloor(&flbuf, CC->quickroom.QRfloor);
994 lputfloor(&flbuf, CC->quickroom.QRfloor);
996 /* create a room directory if necessary */
997 if (CC->quickroom.QRflags & QR_DIRECTORY) {
999 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1000 CC->quickroom.QRdirname);
1003 sprintf(buf, "%s> edited by %s\n", CC->quickroom.QRname, CC->curr_user);
1005 cprintf("%d Ok\n", OK);
1011 * get the name of the room aide for this room
1015 struct usersupp usbuf;
1017 if (CtdlAccessCheck(ac_logged_in)) return;
1019 if (is_noneditable(&CC->quickroom)) {
1020 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1023 if (getuserbynumber(&usbuf, CC->quickroom.QRroomaide) == 0) {
1024 cprintf("%d %s\n", OK, usbuf.fullname);
1026 cprintf("%d \n", OK);
1032 * set the room aide for this room
1034 void cmd_seta(char *new_ra)
1036 struct usersupp usbuf;
1041 if (CtdlAccessCheck(ac_room_aide)) return;
1043 if (getuser(&usbuf, new_ra) != 0) {
1046 newu = usbuf.usernum;
1049 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1051 if (CC->quickroom.QRroomaide != newu) {
1054 CC->quickroom.QRroomaide = newu;
1055 lputroom(&CC->quickroom);
1058 * We have to post the change notice _after_ writing changes to
1059 * the room table, otherwise it would deadlock!
1061 if (post_notice == 1) {
1062 sprintf(buf, "%s is now room aide for %s>\n",
1063 usbuf.fullname, CC->quickroom.QRname);
1066 cprintf("%d Ok\n", OK);
1070 * Generate an associated file name for a room
1072 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix)
1074 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1078 * retrieve info file for this room
1086 assoc_file_name(filename, &CC->quickroom, "info");
1087 info_fp = fopen(filename, "r");
1089 if (info_fp == NULL) {
1090 cprintf("%d No info file.\n", ERROR);
1093 cprintf("%d Info:\n", LISTING_FOLLOWS);
1094 while (fgets(buf, 256, info_fp) != NULL) {
1095 if (strlen(buf) > 0)
1096 buf[strlen(buf) - 1] = 0;
1097 cprintf("%s\n", buf);
1104 * Back end processing to delete a room and everything associated with it
1106 void delete_room(struct quickroom *qrbuf)
1111 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1113 /* Delete the info file */
1114 assoc_file_name(filename, qrbuf, "info");
1117 /* Delete the image file */
1118 assoc_file_name(filename, qrbuf, "images");
1121 /* Delete the messages in the room
1122 * (Careful: this opens an S_QUICKROOM critical section!)
1124 CtdlDeleteMessages(qrbuf->QRname, 0L, "");
1126 /* Flag the room record as not in use */
1127 lgetroom(qrbuf, qrbuf->QRname);
1131 /* then decrement the reference count for the floor */
1132 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1133 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1134 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1136 /* Delete the room record from the database! */
1137 b_deleteroom(qrbuf->QRname);
1142 * aide command: kill the current room
1144 void cmd_kill(char *argbuf)
1147 char deleted_room_name[ROOMNAMELEN];
1150 kill_ok = extract_int(argbuf, 0);
1152 if (CtdlAccessCheck(ac_room_aide)) return;
1154 if (is_noneditable(&CC->quickroom)) {
1155 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1159 strcpy(deleted_room_name, CC->quickroom.QRname);
1160 delete_room(&CC->quickroom); /* Do the dirty work */
1161 usergoto(BASEROOM, 0, NULL, NULL); /* Return to the Lobby */
1163 /* tell the world what we did */
1164 sprintf(aaa, "%s> killed by %s\n",
1165 deleted_room_name, CC->curr_user);
1167 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1169 cprintf("%d ok to delete.\n", OK);
1175 * Internal code to create a new room (returns room flags)
1177 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1179 unsigned create_room(char *new_room_name,
1181 char *new_room_pass,
1185 struct quickroom qrbuf;
1189 if (getroom(&qrbuf, new_room_name) == 0)
1190 return (0); /* already exists */
1192 memset(&qrbuf, 0, sizeof(struct quickroom));
1193 safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
1194 safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
1195 qrbuf.QRflags = QR_INUSE;
1196 qrbuf.QRnumber = get_new_room_number();
1197 if (new_room_type > 0)
1198 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1199 if (new_room_type == 1)
1200 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1201 if (new_room_type == 2)
1202 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1203 if (new_room_type == 4)
1204 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1206 /* If the room is private, and the system administrator has elected
1207 * to automatically grant room aide privileges, do so now; otherwise,
1208 * set the room aide to undefined.
1210 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1211 qrbuf.QRroomaide = CC->usersupp.usernum;
1213 qrbuf.QRroomaide = (-1L);
1216 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1217 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1218 qrbuf.QRfloor = new_room_floor;
1220 /* save what we just did... */
1223 /* bump the reference count on whatever floor the room is on */
1224 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1225 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1226 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1228 /* be sure not to kick the creator out of the room! */
1229 lgetuser(&CC->usersupp, CC->curr_user);
1230 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1231 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1232 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1233 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1234 lputuser(&CC->usersupp);
1236 /* resume our happy day */
1237 return (qrbuf.QRflags);
1244 void cmd_cre8(char *args)
1247 char new_room_name[256];
1249 char new_room_pass[256];
1253 struct quickroom qrbuf;
1256 cre8_ok = extract_int(args, 0);
1257 extract(new_room_name, args, 1);
1258 new_room_name[ROOMNAMELEN - 1] = 0;
1259 new_room_type = extract_int(args, 2);
1260 extract(new_room_pass, args, 3);
1261 new_room_pass[9] = 0;
1264 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1265 cprintf("%d Invalid room name.\n", ERROR);
1269 if (!strcasecmp(new_room_name, MAILROOM)) {
1270 cprintf("%d '%s' already exists.\n",
1271 ERROR + ALREADY_EXISTS, new_room_name);
1275 if (num_parms(args) >= 5) {
1276 getfloor(&flbuf, extract_int(args, 4));
1277 if ((flbuf.f_flags & F_INUSE) == 0) {
1278 cprintf("%d Invalid floor number.\n",
1279 ERROR + INVALID_FLOOR_OPERATION);
1282 new_room_floor = extract_int(args, 4);
1286 if (CtdlAccessCheck(ac_logged_in)) return;
1288 if (CC->usersupp.axlevel < config.c_createax) {
1289 cprintf("%d You need higher access to create rooms.\n",
1290 ERROR + HIGHER_ACCESS_REQUIRED);
1294 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1295 cprintf("%d Ok to create rooms.\n", OK);
1299 if ((new_room_type < 0) || (new_room_type > 4)) {
1300 cprintf("%d Invalid room type.\n", ERROR);
1304 /* If the user is requesting a personal room, set up the room
1305 * name accordingly (prepend the user number)
1307 if (new_room_type == 4) {
1308 sprintf(aaa, "%010ld.%s",
1309 CC->usersupp.usernum, new_room_name);
1310 strcpy(new_room_name, aaa);
1313 /* Check to make sure the requested room name doesn't already exist */
1314 if (getroom(&qrbuf, new_room_name) == 0) {
1315 cprintf("%d '%s' already exists.\n",
1316 ERROR + ALREADY_EXISTS, qrbuf.QRname);
1321 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1325 newflags = create_room(new_room_name,
1326 new_room_type, new_room_pass, new_room_floor);
1328 /* post a message in Aide> describing the new room */
1329 safestrncpy(aaa, new_room_name, sizeof aaa);
1330 strcat(aaa, "> created by ");
1331 strcat(aaa, CC->usersupp.fullname);
1332 if (newflags & QR_MAILBOX)
1333 strcat(aaa, " [personal]");
1334 else if (newflags & QR_PRIVATE)
1335 strcat(aaa, " [private]");
1336 if (newflags & QR_GUESSNAME)
1337 strcat(aaa, "[guessname] ");
1338 if (newflags & QR_PASSWORDED) {
1339 strcat(aaa, "\n Password: ");
1340 strcat(aaa, new_room_pass);
1345 cprintf("%d '%s' has been created.\n", OK, qrbuf.QRname);
1350 void cmd_einf(char *ok)
1351 { /* enter info file for current room */
1353 char infofilename[256];
1356 if (CtdlAccessCheck(ac_room_aide)) return;
1358 if (atoi(ok) == 0) {
1359 cprintf("%d Ok.\n", OK);
1362 assoc_file_name(infofilename, &CC->quickroom, "info");
1363 lprintf(9, "opening\n");
1364 fp = fopen(infofilename, "w");
1365 lprintf(9, "checking\n");
1367 cprintf("%d Cannot open %s: %s\n",
1368 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1371 cprintf("%d Send info...\n", SEND_LISTING);
1375 if (strcmp(buf, "000"))
1376 fprintf(fp, "%s\n", buf);
1377 } while (strcmp(buf, "000"));
1380 /* now update the room index so people will see our new info */
1381 lgetroom(&CC->quickroom, CC->quickroom.QRname); /* lock so no one steps on us */
1382 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1383 lputroom(&CC->quickroom);
1388 * cmd_lflr() - List all known floors
1395 if (CtdlAccessCheck(ac_logged_in)) return;
1397 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1399 for (a = 0; a < MAXFLOORS; ++a) {
1400 getfloor(&flbuf, a);
1401 if (flbuf.f_flags & F_INUSE) {
1402 cprintf("%d|%s|%d\n",
1414 * create a new floor
1416 void cmd_cflr(char *argbuf)
1418 char new_floor_name[256];
1421 int free_slot = (-1);
1424 extract(new_floor_name, argbuf, 0);
1425 cflr_ok = extract_int(argbuf, 1);
1428 if (CtdlAccessCheck(ac_aide)) return;
1430 for (a = 0; a < MAXFLOORS; ++a) {
1431 getfloor(&flbuf, a);
1433 /* note any free slots while we're scanning... */
1434 if (((flbuf.f_flags & F_INUSE) == 0)
1438 /* check to see if it already exists */
1439 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1440 && (flbuf.f_flags & F_INUSE)) {
1441 cprintf("%d Floor '%s' already exists.\n",
1442 ERROR + ALREADY_EXISTS,
1448 if (free_slot < 0) {
1449 cprintf("%d There is no space available for a new floor.\n",
1450 ERROR + INVALID_FLOOR_OPERATION);
1454 cprintf("%d ok to create...\n", OK);
1457 lgetfloor(&flbuf, free_slot);
1458 flbuf.f_flags = F_INUSE;
1459 flbuf.f_ref_count = 0;
1460 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1461 lputfloor(&flbuf, free_slot);
1462 cprintf("%d %d\n", OK, free_slot);
1470 void cmd_kflr(char *argbuf)
1473 int floor_to_delete;
1477 floor_to_delete = extract_int(argbuf, 0);
1478 kflr_ok = extract_int(argbuf, 1);
1480 if (CtdlAccessCheck(ac_aide)) return;
1482 lgetfloor(&flbuf, floor_to_delete);
1485 if ((flbuf.f_flags & F_INUSE) == 0) {
1486 cprintf("%d Floor %d not in use.\n",
1487 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1490 if (flbuf.f_ref_count != 0) {
1491 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1492 ERROR + INVALID_FLOOR_OPERATION,
1497 cprintf("%d Ok\n", OK);
1499 cprintf("%d Ok to delete...\n", OK);
1506 if ((delete_ok == 1) && (kflr_ok == 1))
1508 lputfloor(&flbuf, floor_to_delete);
1514 void cmd_eflr(char *argbuf)
1520 np = num_parms(argbuf);
1522 cprintf("%d Usage error.\n", ERROR);
1526 if (CtdlAccessCheck(ac_aide)) return;
1528 floor_num = extract_int(argbuf, 0);
1529 lgetfloor(&flbuf, floor_num);
1530 if ((flbuf.f_flags & F_INUSE) == 0) {
1531 lputfloor(&flbuf, floor_num);
1532 cprintf("%d Floor %d is not in use.\n",
1533 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1537 extract(flbuf.f_name, argbuf, 1);
1538 lputfloor(&flbuf, floor_num);
1540 cprintf("%d Ok\n", OK);