16 #include "sysdep_decls.h"
20 #include "citserver.h"
25 * Generic routine for determining user access to rooms
27 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf)
32 /* for internal programs, always do everything */
33 if (((CC->internal_pgm)) && (roombuf->QRflags & QR_INUSE)) {
34 return (UA_KNOWN | UA_GOTOALLOWED);
36 /* For mailbox rooms, only allow access to the owner */
37 if (roombuf->QRflags & QR_MAILBOX) {
38 if (userbuf->usernum != atol(roombuf->QRname)) {
42 /* Locate any applicable user/room relationships */
43 CtdlGetRelationship(&vbuf, userbuf, roombuf);
45 /* Force the properties of the Aide room */
46 if (!strcasecmp(roombuf->QRname, AIDEROOM)) {
47 if (userbuf->axlevel >= 6) {
48 retval = UA_KNOWN | UA_GOTOALLOWED;
54 /* For mailboxes, we skip all the access stuff (and we've
55 * already checked by this point that the mailbox belongs
58 if (roombuf->QRflags & QR_MAILBOX) {
59 retval = UA_KNOWN | UA_GOTOALLOWED;
62 /* If this is a public room, it's accessible... */
63 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
64 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
66 /* If this is a preferred users only room, check access level */
67 if (roombuf->QRflags & QR_PREFONLY) {
68 if (userbuf->axlevel < 5) {
69 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
72 /* For private rooms, check the generation number matchups */
73 if (roombuf->QRflags & QR_PRIVATE) {
75 /* An explicit match means the user belongs in this room */
76 if (vbuf.v_flags & V_ACCESS) {
77 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
79 /* Otherwise, check if this is a guess-name or passworded
80 * room. If it is, a goto may at least be attempted
82 else if ((roombuf->QRflags & QR_PRIVATE)
83 || (roombuf->QRflags & QR_PASSWORDED)) {
84 retval = retval & ~UA_KNOWN;
85 retval = retval | UA_GOTOALLOWED;
88 /* Check to see if the user has forgotten this room */
89 if (vbuf.v_flags & V_FORGET) {
90 retval = retval & ~UA_KNOWN;
91 retval = retval | UA_ZAPPED;
93 /* If user is explicitly locked out of this room, deny everything */
94 if (vbuf.v_flags & V_LOCKOUT) {
95 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
97 /* Aides get access to everything */
98 if (userbuf->axlevel >= 6) {
99 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
100 retval = retval & ~UA_ZAPPED;
102 NEWMSG: /* By the way, we also check for the presence of new messages */
103 if ((roombuf->QRhighest) > (vbuf.v_lastseen)) {
104 retval = retval | UA_HASNEWMSGS;
110 * Self-checking stuff for a room record read into memory
112 void room_sanity_check(struct quickroom *qrbuf)
114 /* Mailbox rooms are always on the lowest floor */
115 if (qrbuf->QRflags & QR_MAILBOX) {
118 /* Listing order of 0 is illegal except for base rooms */
119 if (qrbuf->QRorder == 0)
120 if (!is_noneditable(qrbuf))
126 * getroom() - retrieve room data from disk
128 int getroom(struct quickroom *qrbuf, char *room_name)
130 struct cdbdata *cdbqr;
131 char lowercase_name[ROOMNAMELEN];
132 char personal_lowercase_name[ROOMNAMELEN];
135 for (a = 0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
136 lowercase_name[a] = tolower(room_name[a]);
138 lowercase_name[a] = 0;
140 memset(qrbuf, 0, sizeof(struct quickroom));
142 /* First, try the public namespace */
143 cdbqr = cdb_fetch(CDB_QUICKROOM,
144 lowercase_name, strlen(lowercase_name));
146 /* If that didn't work, try the user's personal namespace */
148 sprintf(personal_lowercase_name, "%010ld.%s",
149 CC->usersupp.usernum, lowercase_name);
150 cdbqr = cdb_fetch(CDB_QUICKROOM,
151 personal_lowercase_name,
152 strlen(personal_lowercase_name));
155 memcpy(qrbuf, cdbqr->ptr,
156 ((cdbqr->len > sizeof(struct quickroom)) ?
157 sizeof(struct quickroom) : cdbqr->len));
160 room_sanity_check(qrbuf);
169 * lgetroom() - same as getroom() but locks the record (if supported)
171 int lgetroom(struct quickroom *qrbuf, char *room_name)
174 retval = getroom(qrbuf, room_name);
175 if (retval == 0) begin_critical_section(S_QUICKROOM);
181 * b_putroom() - back end to putroom() and b_deleteroom()
182 * (if the supplied buffer is NULL, delete the room record)
184 void b_putroom(struct quickroom *qrbuf, char *room_name)
186 char lowercase_name[ROOMNAMELEN];
189 for (a = 0; a <= strlen(room_name); ++a) {
190 lowercase_name[a] = tolower(room_name[a]);
194 cdb_delete(CDB_QUICKROOM,
195 lowercase_name, strlen(lowercase_name));
197 time(&qrbuf->QRmtime);
198 cdb_store(CDB_QUICKROOM,
199 lowercase_name, strlen(lowercase_name),
200 qrbuf, sizeof(struct quickroom));
206 * putroom() - store room data to disk
208 void putroom(struct quickroom *qrbuf) {
209 b_putroom(qrbuf, qrbuf->QRname);
214 * b_deleteroom() - delete a room record from disk
216 void b_deleteroom(char *room_name) {
217 b_putroom(NULL, room_name);
223 * lputroom() - same as putroom() but unlocks the record (if supported)
225 void lputroom(struct quickroom *qrbuf)
229 end_critical_section(S_QUICKROOM);
233 /****************************************************************************/
236 * getfloor() - retrieve floor data from disk
238 void getfloor(struct floor *flbuf, int floor_num)
240 struct cdbdata *cdbfl;
242 memset(flbuf, 0, sizeof(struct floor));
243 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
245 memcpy(flbuf, cdbfl->ptr,
246 ((cdbfl->len > sizeof(struct floor)) ?
247 sizeof(struct floor) : cdbfl->len));
250 if (floor_num == 0) {
251 strcpy(flbuf->f_name, "Main Floor");
252 flbuf->f_flags = F_INUSE;
253 flbuf->f_ref_count = 3;
260 * lgetfloor() - same as getfloor() but locks the record (if supported)
262 void lgetfloor(struct floor *flbuf, int floor_num)
265 begin_critical_section(S_FLOORTAB);
266 getfloor(flbuf, floor_num);
271 * putfloor() - store floor data on disk
273 void putfloor(struct floor *flbuf, int floor_num)
275 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
276 flbuf, sizeof(struct floor));
281 * lputfloor() - same as putfloor() but unlocks the record (if supported)
283 void lputfloor(struct floor *flbuf, int floor_num)
286 putfloor(flbuf, floor_num);
287 end_critical_section(S_FLOORTAB);
293 * Traverse the room file...
295 void ForEachRoom(void (*CallBack) (struct quickroom *EachRoom, void *out_data),
298 struct quickroom qrbuf;
299 struct cdbdata *cdbqr;
301 cdb_rewind(CDB_QUICKROOM);
303 while (cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
304 memset(&qrbuf, 0, sizeof(struct quickroom));
305 memcpy(&qrbuf, cdbqr->ptr,
306 ((cdbqr->len > sizeof(struct quickroom)) ?
307 sizeof(struct quickroom) : cdbqr->len));
309 room_sanity_check(&qrbuf);
310 if (qrbuf.QRflags & QR_INUSE)
311 (*CallBack)(&qrbuf, in_data);
317 * delete_msglist() - delete room message pointers
319 void delete_msglist(struct quickroom *whichroom)
321 struct cdbdata *cdbml;
323 /* Make sure the msglist we're deleting actually exists, otherwise
324 * gdbm will complain when we try to delete an invalid record
326 cdbml = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
330 /* Go ahead and delete it */
331 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
339 * sort message pointers
340 * (returns new msg count)
342 int sort_msglist(long listptrs[], int oldcount)
353 for (a = numitems - 2; a >= 0; --a) {
354 for (b = 0; b <= a; ++b) {
355 if (listptrs[b] > (listptrs[b + 1])) {
357 hold2 = listptrs[b + 1];
359 listptrs[b + 1] = hold1;
364 /* and yank any nulls */
365 while ((numitems > 0) && (listptrs[0] == 0L)) {
366 memcpy(&listptrs[0], &listptrs[1],
367 (sizeof(long) * (numitems - 1)));
376 * Determine whether a given room is non-editable.
378 int is_noneditable(struct quickroom *qrbuf)
381 /* Lobby> and Aide> are non-editable */
382 if (!strcasecmp(qrbuf->QRname, BASEROOM))
384 else if (!strcasecmp(qrbuf->QRname, AIDEROOM))
387 /* Mail> rooms are also non-editable */
388 else if ( (qrbuf->QRflags & QR_MAILBOX)
389 && (!strcasecmp(&qrbuf->QRname[11], MAILROOM)) )
392 /* Everything else is editable */
400 * Back-back-end for all room listing commands
402 void list_roomname(struct quickroom *qrbuf)
404 char truncated_roomname[ROOMNAMELEN];
406 /* For mailbox rooms, chop off the owner prefix */
407 if (qrbuf->QRflags & QR_MAILBOX) {
408 strcpy(truncated_roomname, qrbuf->QRname);
409 strcpy(truncated_roomname, &truncated_roomname[11]);
410 cprintf("%s", truncated_roomname);
412 /* For all other rooms, just display the name in its entirety */
414 cprintf("%s", qrbuf->QRname);
417 /* ...and now the other parameters */
418 cprintf("|%u|%d|%d\n",
420 (int) qrbuf->QRfloor,
421 (int) qrbuf->QRorder);
426 * cmd_lrms() - List all accessible rooms, known or forgotten
428 void cmd_lrms_backend(struct quickroom *qrbuf, void *data)
430 int FloorBeingSearched = (-1);
431 FloorBeingSearched = *(int *)data;
433 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
434 & (UA_KNOWN | UA_ZAPPED)))
435 && ((qrbuf->QRfloor == (FloorBeingSearched))
436 || ((FloorBeingSearched) < 0)))
437 list_roomname(qrbuf);
440 void cmd_lrms(char *argbuf)
442 int FloorBeingSearched = (-1);
443 if (strlen(argbuf) > 0)
444 FloorBeingSearched = extract_int(argbuf, 0);
446 if (CtdlAccessCheck(ac_logged_in)) return;
448 if (getuser(&CC->usersupp, CC->curr_user)) {
449 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
452 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
454 ForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
461 * cmd_lkra() - List all known rooms
463 void cmd_lkra_backend(struct quickroom *qrbuf, void *data)
465 int FloorBeingSearched = (-1);
466 FloorBeingSearched = *(int *)data;
468 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
470 && ((qrbuf->QRfloor == (FloorBeingSearched))
471 || ((FloorBeingSearched) < 0)))
472 list_roomname(qrbuf);
475 void cmd_lkra(char *argbuf)
477 int FloorBeingSearched = (-1);
478 if (strlen(argbuf) > 0)
479 FloorBeingSearched = extract_int(argbuf, 0);
481 if (CtdlAccessCheck(ac_logged_in)) return;
483 if (getuser(&CC->usersupp, CC->curr_user)) {
484 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
487 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
489 ForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
496 * cmd_lkrn() - List all known rooms with new messages
498 void cmd_lkrn_backend(struct quickroom *qrbuf, void *data)
501 int FloorBeingSearched = (-1);
502 FloorBeingSearched = *(int *)data;
504 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
506 && (ra & UA_HASNEWMSGS)
507 && ((qrbuf->QRfloor == (FloorBeingSearched))
508 || ((FloorBeingSearched) < 0)))
509 list_roomname(qrbuf);
512 void cmd_lkrn(char *argbuf)
514 int FloorBeingSearched = (-1);
515 if (strlen(argbuf) > 0)
516 FloorBeingSearched = extract_int(argbuf, 0);
518 if (CtdlAccessCheck(ac_logged_in)) return;
520 if (getuser(&CC->usersupp, CC->curr_user)) {
521 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
524 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
526 ForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
533 * cmd_lkro() - List all known rooms
535 void cmd_lkro_backend(struct quickroom *qrbuf, void *data)
538 int FloorBeingSearched = (-1);
539 FloorBeingSearched = *(int *)data;
541 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
543 && ((ra & UA_HASNEWMSGS) == 0)
544 && ((qrbuf->QRfloor == (FloorBeingSearched))
545 || ((FloorBeingSearched) < 0)))
546 list_roomname(qrbuf);
549 void cmd_lkro(char *argbuf)
551 int FloorBeingSearched = (-1);
552 if (strlen(argbuf) > 0)
553 FloorBeingSearched = extract_int(argbuf, 0);
555 if (CtdlAccessCheck(ac_logged_in)) return;
557 if (getuser(&CC->usersupp, CC->curr_user)) {
558 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
561 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
563 ForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
570 * cmd_lzrm() - List all forgotten rooms
572 void cmd_lzrm_backend(struct quickroom *qrbuf, void *data)
575 int FloorBeingSearched = (-1);
576 FloorBeingSearched = *(int *)data;
578 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
579 if ((ra & UA_GOTOALLOWED)
581 && ((qrbuf->QRfloor == (FloorBeingSearched))
582 || ((FloorBeingSearched) < 0)))
583 list_roomname(qrbuf);
586 void cmd_lzrm(char *argbuf)
588 int FloorBeingSearched = (-1);
589 if (strlen(argbuf) > 0)
590 FloorBeingSearched = extract_int(argbuf, 0);
592 if (CtdlAccessCheck(ac_logged_in)) return;
594 if (getuser(&CC->usersupp, CC->curr_user)) {
595 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
598 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
600 ForEachRoom(cmd_lzrm_backend, &FloorBeingSearched);
606 void usergoto(char *where, int display_result)
609 int new_messages = 0;
610 int total_messages = 0;
614 int newmailcount = 0;
616 char truncated_roomname[ROOMNAMELEN];
617 struct cdbdata *cdbfr;
618 long *msglist = NULL;
621 strcpy(CC->quickroom.QRname, where);
622 getroom(&CC->quickroom, where);
624 lgetuser(&CC->usersupp, CC->curr_user);
625 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
627 /* Know the room ... but not if it's the page log room */
628 if (strcasecmp(where, config.c_logpages)) {
629 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
630 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
632 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
633 lputuser(&CC->usersupp);
635 /* check for new mail */
636 newmailcount = NewMailCount();
638 /* set info to 1 if the user needs to read the room's info file */
639 if (CC->quickroom.QRinfo > vbuf.v_lastseen)
643 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->quickroom.QRnumber, sizeof(long));
645 msglist = mallok(cdbfr->len);
646 memcpy(msglist, cdbfr->ptr, cdbfr->len);
647 num_msgs = cdbfr->len / sizeof(long);
651 if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
652 if (msglist[a] > 0L) {
654 if (msglist[a] > vbuf.v_lastseen) {
660 if (msglist != NULL) phree(msglist);
662 if (CC->quickroom.QRflags & QR_MAILBOX)
667 if ((CC->quickroom.QRroomaide == CC->usersupp.usernum)
668 || (CC->usersupp.axlevel >= 6))
673 strcpy(truncated_roomname, CC->quickroom.QRname);
674 if (CC->quickroom.QRflags & QR_MAILBOX) {
675 strcpy(truncated_roomname, &truncated_roomname[11]);
679 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
680 OK, CtdlCheckExpress(),
682 new_messages, total_messages,
683 info, CC->quickroom.QRflags,
684 CC->quickroom.QRhighest,
686 rmailflag, raideflag, newmailcount,
687 CC->quickroom.QRfloor);
693 * cmd_goto() - goto a new room
695 void cmd_goto(char *gargs)
697 struct quickroom QRscratch;
701 char augmented_roomname[256];
705 if (CtdlAccessCheck(ac_logged_in)) return;
707 extract(towhere, gargs, 0);
708 extract(password, gargs, 1);
710 getuser(&CC->usersupp, CC->curr_user);
712 if (!strcasecmp(towhere, "_BASEROOM_"))
713 strcpy(towhere, BASEROOM);
715 if (!strcasecmp(towhere, "_MAIL_"))
716 strcpy(towhere, MAILROOM);
718 if (!strcasecmp(towhere, "_BITBUCKET_"))
719 strcpy(towhere, config.c_twitroom);
722 /* First try a regular match */
723 c = getroom(&QRscratch, towhere);
725 /* Then try a mailbox name match */
727 MailboxName(augmented_roomname, &CC->usersupp, towhere);
728 c = getroom(&QRscratch, augmented_roomname);
730 strcpy(towhere, augmented_roomname);
733 /* And if the room was found... */
736 /* let internal programs go directly to any room */
737 if (CC->internal_pgm) {
738 usergoto(towhere, 1);
742 /* See if there is an existing user/room relationship */
743 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
745 /* normal clients have to pass through security */
746 if (ra & UA_GOTOALLOWED)
750 if ((QRscratch.QRflags & QR_PASSWORDED) &&
751 ((ra & UA_KNOWN) == 0) &&
752 (strcasecmp(QRscratch.QRpasswd, password))
754 cprintf("%d wrong or missing passwd\n",
755 ERROR + PASSWORD_REQUIRED);
757 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
758 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
759 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
760 ((ra & UA_KNOWN) == 0)) {
763 usergoto(towhere, 1);
769 NOPE: cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
775 struct usersupp temp;
776 struct cdbdata *cdbus;
778 getuser(&CC->usersupp, CC->curr_user);
779 if (CtdlAccessCheck(ac_room_aide)) return;
781 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
782 cdb_rewind(CDB_USERSUPP);
783 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
784 memset(&temp, 0, sizeof temp);
785 memcpy(&temp, cdbus->ptr, sizeof temp);
788 if ((CC->quickroom.QRflags & QR_INUSE)
789 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
791 cprintf("%s\n", temp.fullname);
798 * RDIR command for room directory
808 if (CtdlAccessCheck(ac_logged_in)) return;
810 getroom(&CC->quickroom, CC->quickroom.QRname);
811 getuser(&CC->usersupp, CC->curr_user);
813 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
814 cprintf("%d not here.\n", ERROR + NOT_HERE);
817 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
818 && (CC->usersupp.axlevel < 6)
819 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
820 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
823 cprintf("%d %s|%s/files/%s\n",
824 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->quickroom.QRdirname);
826 sprintf(buf, "ls %s/files/%s >%s 2> /dev/null",
827 BBSDIR, CC->quickroom.QRdirname, CC->temp);
830 sprintf(buf, "%s/files/%s/filedir", BBSDIR, CC->quickroom.QRdirname);
831 fd = fopen(buf, "r");
833 fd = fopen("/dev/null", "r");
835 ls = fopen(CC->temp, "r");
836 while (fgets(flnm, 256, ls) != NULL) {
837 flnm[strlen(flnm) - 1] = 0;
838 if (strcasecmp(flnm, "filedir")) {
839 sprintf(buf, "%s/files/%s/%s",
840 BBSDIR, CC->quickroom.QRdirname, flnm);
844 while ((fgets(buf, 256, fd) != NULL)
845 && (strlen(comment) == 0)) {
846 buf[strlen(buf) - 1] = 0;
847 if ((!strncasecmp(buf, flnm, strlen(flnm)))
848 && (buf[strlen(flnm)] == ' '))
850 &buf[strlen(flnm) + 1],
853 cprintf("%s|%ld|%s\n", flnm, statbuf.st_size, comment);
864 * get room parameters (aide or room aide command)
868 if (CtdlAccessCheck(ac_room_aide)) return;
871 if (is_noneditable(&CC->quickroom)) {
872 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
877 getroom(&CC->quickroom, CC->quickroom.QRname);
878 cprintf("%d%c%s|%s|%s|%d|%d|%d\n",
879 OK, CtdlCheckExpress(),
880 CC->quickroom.QRname,
881 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
882 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
883 CC->quickroom.QRflags,
884 (int) CC->quickroom.QRfloor,
885 (int) CC->quickroom.QRorder);
890 * set room parameters (aide or room aide command)
892 void cmd_setr(char *args)
896 char old_name[ROOMNAMELEN];
901 if (CtdlAccessCheck(ac_room_aide)) return;
903 if (is_noneditable(&CC->quickroom)) {
908 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
914 if (num_parms(args) >= 6) {
915 getfloor(&flbuf, extract_int(args, 5));
916 if ((flbuf.f_flags & F_INUSE) == 0) {
917 cprintf("%d Invalid floor number.\n",
918 ERROR + INVALID_FLOOR_OPERATION);
922 if (num_parms(args) >= 7) {
923 new_order = extract_int(args, 6);
929 lgetroom(&CC->quickroom, CC->quickroom.QRname);
931 /* Non-editable base rooms can't be renamed */
932 strcpy(old_name, CC->quickroom.QRname);
934 extract(buf, args, 0);
935 buf[ROOMNAMELEN] = 0;
936 safestrncpy(CC->quickroom.QRname, buf,
937 sizeof CC->quickroom.QRname);
940 extract(buf, args, 1);
942 safestrncpy(CC->quickroom.QRpasswd, buf, sizeof CC->quickroom.QRpasswd);
943 extract(buf, args, 2);
945 safestrncpy(CC->quickroom.QRdirname, buf,
946 sizeof CC->quickroom.QRdirname);
947 CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
948 if (num_parms(args) >= 7)
949 CC->quickroom.QRorder = (char) new_order;
951 /* Clean up a client boo-boo: if the client set the room to
952 * guess-name or passworded, ensure that the private flag is
955 if ((CC->quickroom.QRflags & QR_GUESSNAME)
956 || (CC->quickroom.QRflags & QR_PASSWORDED))
957 CC->quickroom.QRflags |= QR_PRIVATE;
959 /* Kick everyone out if the client requested it (by changing the
960 * room's generation number)
962 if (extract_int(args, 4)) {
963 time(&CC->quickroom.QRgen);
965 old_floor = CC->quickroom.QRfloor;
966 if (num_parms(args) >= 6) {
967 CC->quickroom.QRfloor = extract_int(args, 5);
969 /* Write the room record back to disk */
970 lputroom(&CC->quickroom);
972 /* If the room name changed, then there are now two room records,
973 * so we have to delete the old one.
975 if (strcasecmp(CC->quickroom.QRname, old_name)) {
976 b_deleteroom(old_name);
978 /* adjust the floor reference counts */
979 lgetfloor(&flbuf, old_floor);
981 lputfloor(&flbuf, old_floor);
982 lgetfloor(&flbuf, CC->quickroom.QRfloor);
984 lputfloor(&flbuf, CC->quickroom.QRfloor);
986 /* create a room directory if necessary */
987 if (CC->quickroom.QRflags & QR_DIRECTORY) {
989 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
990 CC->quickroom.QRdirname);
993 sprintf(buf, "%s> edited by %s\n", CC->quickroom.QRname, CC->curr_user);
995 cprintf("%d Ok\n", OK);
1001 * get the name of the room aide for this room
1005 struct usersupp usbuf;
1007 if (CtdlAccessCheck(ac_logged_in)) return;
1009 if (is_noneditable(&CC->quickroom)) {
1010 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1013 if (getuserbynumber(&usbuf, CC->quickroom.QRroomaide) == 0) {
1014 cprintf("%d %s\n", OK, usbuf.fullname);
1016 cprintf("%d \n", OK);
1022 * set the room aide for this room
1024 void cmd_seta(char *new_ra)
1026 struct usersupp usbuf;
1031 if (CtdlAccessCheck(ac_room_aide)) return;
1033 if (getuser(&usbuf, new_ra) != 0) {
1036 newu = usbuf.usernum;
1039 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1041 if (CC->quickroom.QRroomaide != newu) {
1044 CC->quickroom.QRroomaide = newu;
1045 lputroom(&CC->quickroom);
1048 * We have to post the change notice _after_ writing changes to
1049 * the room table, otherwise it would deadlock!
1051 if (post_notice == 1) {
1052 sprintf(buf, "%s is now room aide for %s>\n",
1053 usbuf.fullname, CC->quickroom.QRname);
1056 cprintf("%d Ok\n", OK);
1060 * Generate an associated file name for a room
1062 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix)
1064 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1068 * retrieve info file for this room
1076 assoc_file_name(filename, &CC->quickroom, "info");
1077 info_fp = fopen(filename, "r");
1079 if (info_fp == NULL) {
1080 cprintf("%d No info file.\n", ERROR);
1083 cprintf("%d Info:\n", LISTING_FOLLOWS);
1084 while (fgets(buf, 256, info_fp) != NULL) {
1085 if (strlen(buf) > 0)
1086 buf[strlen(buf) - 1] = 0;
1087 cprintf("%s\n", buf);
1094 * Back end processing to delete a room and everything associated with it
1096 void delete_room(struct quickroom *qrbuf)
1101 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1103 /* Delete the info file */
1104 assoc_file_name(filename, qrbuf, "info");
1107 /* Delete the image file */
1108 assoc_file_name(filename, qrbuf, "images");
1111 /* Delete the messages in the room
1112 * (Careful: this opens an S_QUICKROOM critical section!)
1114 CtdlDeleteMessages(qrbuf->QRname, 0L, "");
1116 /* Flag the room record as not in use */
1117 lgetroom(qrbuf, qrbuf->QRname);
1121 /* then decrement the reference count for the floor */
1122 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1123 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1124 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1126 /* Delete the room record from the database! */
1127 b_deleteroom(qrbuf->QRname);
1132 * aide command: kill the current room
1134 void cmd_kill(char *argbuf)
1137 char deleted_room_name[ROOMNAMELEN];
1140 kill_ok = extract_int(argbuf, 0);
1142 if (CtdlAccessCheck(ac_room_aide)) return;
1144 if (is_noneditable(&CC->quickroom)) {
1145 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1149 strcpy(deleted_room_name, CC->quickroom.QRname);
1150 delete_room(&CC->quickroom); /* Do the dirty work */
1151 usergoto(BASEROOM, 0); /* Return to the Lobby */
1153 /* tell the world what we did */
1154 sprintf(aaa, "%s> killed by %s\n",
1155 deleted_room_name, CC->curr_user);
1157 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1159 cprintf("%d ok to delete.\n", OK);
1165 * Internal code to create a new room (returns room flags)
1167 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1169 unsigned create_room(char *new_room_name,
1171 char *new_room_pass,
1175 struct quickroom qrbuf;
1179 if (getroom(&qrbuf, new_room_name) == 0)
1180 return (0); /* already exists */
1182 memset(&qrbuf, 0, sizeof(struct quickroom));
1183 safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
1184 safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
1185 qrbuf.QRflags = QR_INUSE;
1186 qrbuf.QRnumber = get_new_room_number();
1187 if (new_room_type > 0)
1188 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1189 if (new_room_type == 1)
1190 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1191 if (new_room_type == 2)
1192 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1193 if (new_room_type == 4)
1194 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1196 /* If the room is private, and the system administrator has elected
1197 * to automatically grant room aide privileges, do so now; otherwise,
1198 * set the room aide to undefined.
1200 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1201 qrbuf.QRroomaide = CC->usersupp.usernum;
1203 qrbuf.QRroomaide = (-1L);
1206 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1207 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1208 qrbuf.QRfloor = new_room_floor;
1210 /* save what we just did... */
1213 /* bump the reference count on whatever floor the room is on */
1214 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1215 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1216 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1218 /* be sure not to kick the creator out of the room! */
1219 lgetuser(&CC->usersupp, CC->curr_user);
1220 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1221 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1222 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1223 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1224 lputuser(&CC->usersupp);
1226 /* resume our happy day */
1227 return (qrbuf.QRflags);
1234 void cmd_cre8(char *args)
1237 char new_room_name[256];
1239 char new_room_pass[256];
1243 struct quickroom qrbuf;
1246 cre8_ok = extract_int(args, 0);
1247 extract(new_room_name, args, 1);
1248 new_room_name[ROOMNAMELEN - 1] = 0;
1249 new_room_type = extract_int(args, 2);
1250 extract(new_room_pass, args, 3);
1251 new_room_pass[9] = 0;
1254 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1255 cprintf("%d Invalid room name.\n", ERROR);
1259 if (!strcasecmp(new_room_name, MAILROOM)) {
1260 cprintf("%d '%s' already exists.\n",
1261 ERROR + ALREADY_EXISTS, new_room_name);
1265 if (num_parms(args) >= 5) {
1266 getfloor(&flbuf, extract_int(args, 4));
1267 if ((flbuf.f_flags & F_INUSE) == 0) {
1268 cprintf("%d Invalid floor number.\n",
1269 ERROR + INVALID_FLOOR_OPERATION);
1272 new_room_floor = extract_int(args, 4);
1276 if (CtdlAccessCheck(ac_logged_in)) return;
1278 if (CC->usersupp.axlevel < config.c_createax) {
1279 cprintf("%d You need higher access to create rooms.\n",
1280 ERROR + HIGHER_ACCESS_REQUIRED);
1284 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1285 cprintf("%d Ok to create rooms.\n", OK);
1289 if ((new_room_type < 0) || (new_room_type > 4)) {
1290 cprintf("%d Invalid room type.\n", ERROR);
1294 /* If the user is requesting a personal room, set up the room
1295 * name accordingly (prepend the user number)
1297 if (new_room_type == 4) {
1298 sprintf(aaa, "%010ld.%s",
1299 CC->usersupp.usernum, new_room_name);
1300 strcpy(new_room_name, aaa);
1303 /* Check to make sure the requested room name doesn't already exist */
1304 if (getroom(&qrbuf, new_room_name) == 0) {
1305 cprintf("%d '%s' already exists.\n",
1306 ERROR + ALREADY_EXISTS, qrbuf.QRname);
1311 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1315 newflags = create_room(new_room_name,
1316 new_room_type, new_room_pass, new_room_floor);
1318 /* post a message in Aide> describing the new room */
1319 safestrncpy(aaa, new_room_name, sizeof aaa);
1320 strcat(aaa, "> created by ");
1321 strcat(aaa, CC->usersupp.fullname);
1322 if (newflags & QR_MAILBOX)
1323 strcat(aaa, " [personal]");
1324 else if (newflags & QR_PRIVATE)
1325 strcat(aaa, " [private]");
1326 if (newflags & QR_GUESSNAME)
1327 strcat(aaa, "[guessname] ");
1328 if (newflags & QR_PASSWORDED) {
1329 strcat(aaa, "\n Password: ");
1330 strcat(aaa, new_room_pass);
1335 cprintf("%d '%s' has been created.\n", OK, qrbuf.QRname);
1340 void cmd_einf(char *ok)
1341 { /* enter info file for current room */
1343 char infofilename[256];
1346 if (CtdlAccessCheck(ac_room_aide)) return;
1348 if (atoi(ok) == 0) {
1349 cprintf("%d Ok.\n", OK);
1352 assoc_file_name(infofilename, &CC->quickroom, "info");
1353 lprintf(9, "opening\n");
1354 fp = fopen(infofilename, "w");
1355 lprintf(9, "checking\n");
1357 cprintf("%d Cannot open %s: %s\n",
1358 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1361 cprintf("%d Send info...\n", SEND_LISTING);
1365 if (strcmp(buf, "000"))
1366 fprintf(fp, "%s\n", buf);
1367 } while (strcmp(buf, "000"));
1370 /* now update the room index so people will see our new info */
1371 lgetroom(&CC->quickroom, CC->quickroom.QRname); /* lock so no one steps on us */
1372 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1373 lputroom(&CC->quickroom);
1378 * cmd_lflr() - List all known floors
1385 if (CtdlAccessCheck(ac_logged_in)) return;
1387 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1389 for (a = 0; a < MAXFLOORS; ++a) {
1390 getfloor(&flbuf, a);
1391 if (flbuf.f_flags & F_INUSE) {
1392 cprintf("%d|%s|%d\n",
1404 * create a new floor
1406 void cmd_cflr(char *argbuf)
1408 char new_floor_name[256];
1411 int free_slot = (-1);
1414 extract(new_floor_name, argbuf, 0);
1415 cflr_ok = extract_int(argbuf, 1);
1418 if (CtdlAccessCheck(ac_aide)) return;
1420 for (a = 0; a < MAXFLOORS; ++a) {
1421 getfloor(&flbuf, a);
1423 /* note any free slots while we're scanning... */
1424 if (((flbuf.f_flags & F_INUSE) == 0)
1428 /* check to see if it already exists */
1429 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1430 && (flbuf.f_flags & F_INUSE)) {
1431 cprintf("%d Floor '%s' already exists.\n",
1432 ERROR + ALREADY_EXISTS,
1438 if (free_slot < 0) {
1439 cprintf("%d There is no space available for a new floor.\n",
1440 ERROR + INVALID_FLOOR_OPERATION);
1444 cprintf("%d ok to create...\n", OK);
1447 lgetfloor(&flbuf, free_slot);
1448 flbuf.f_flags = F_INUSE;
1449 flbuf.f_ref_count = 0;
1450 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1451 lputfloor(&flbuf, free_slot);
1452 cprintf("%d %d\n", OK, free_slot);
1460 void cmd_kflr(char *argbuf)
1463 int floor_to_delete;
1467 floor_to_delete = extract_int(argbuf, 0);
1468 kflr_ok = extract_int(argbuf, 1);
1470 if (CtdlAccessCheck(ac_aide)) return;
1472 lgetfloor(&flbuf, floor_to_delete);
1475 if ((flbuf.f_flags & F_INUSE) == 0) {
1476 cprintf("%d Floor %d not in use.\n",
1477 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1480 if (flbuf.f_ref_count != 0) {
1481 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1482 ERROR + INVALID_FLOOR_OPERATION,
1487 cprintf("%d Ok\n", OK);
1489 cprintf("%d Ok to delete...\n", OK);
1496 if ((delete_ok == 1) && (kflr_ok == 1))
1498 lputfloor(&flbuf, floor_to_delete);
1504 void cmd_eflr(char *argbuf)
1510 np = num_parms(argbuf);
1512 cprintf("%d Usage error.\n", ERROR);
1516 if (CtdlAccessCheck(ac_aide)) return;
1518 floor_num = extract_int(argbuf, 0);
1519 lgetfloor(&flbuf, floor_num);
1520 if ((flbuf.f_flags & F_INUSE) == 0) {
1521 lputfloor(&flbuf, floor_num);
1522 cprintf("%d Floor %d is not in use.\n",
1523 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1527 extract(flbuf.f_name, argbuf, 1);
1528 lputfloor(&flbuf, floor_num);
1530 cprintf("%d Ok\n", OK);