16 #include "sysdep_decls.h"
20 #include "serv_chat.h"
21 #include "citserver.h"
26 * Generic routine for determining user access to rooms
28 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf)
33 /* for internal programs, always do everything */
34 if (((CC->internal_pgm)) && (roombuf->QRflags & QR_INUSE)) {
35 return (UA_KNOWN | UA_GOTOALLOWED);
37 /* For mailbox rooms, only allow access to the owner */
38 if (roombuf->QRflags & QR_MAILBOX) {
39 if (userbuf->usernum != atol(roombuf->QRname)) {
43 /* Locate any applicable user/room relationships */
44 CtdlGetRelationship(&vbuf, userbuf, roombuf);
46 /* Force the properties of the Aide room */
47 if (!strcasecmp(roombuf->QRname, AIDEROOM)) {
48 if (userbuf->axlevel >= 6) {
49 retval = UA_KNOWN | UA_GOTOALLOWED;
55 /* For mailboxes, we skip all the access stuff (and we've
56 * already checked by this point that the mailbox belongs
59 if (roombuf->QRflags & QR_MAILBOX) {
60 retval = UA_KNOWN | UA_GOTOALLOWED;
63 /* If this is a public room, it's accessible... */
64 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
65 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
67 /* If this is a preferred users only room, check access level */
68 if (roombuf->QRflags & QR_PREFONLY) {
69 if (userbuf->axlevel < 5) {
70 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
73 /* For private rooms, check the generation number matchups */
74 if (roombuf->QRflags & QR_PRIVATE) {
76 /* An explicit match means the user belongs in this room */
77 if (vbuf.v_flags & V_ACCESS) {
78 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
80 /* Otherwise, check if this is a guess-name or passworded
81 * room. If it is, a goto may at least be attempted
83 else if ((roombuf->QRflags & QR_PRIVATE)
84 || (roombuf->QRflags & QR_PASSWORDED)) {
85 retval = retval & ~UA_KNOWN;
86 retval = retval | UA_GOTOALLOWED;
89 /* Check to see if the user has forgotten this room */
90 if (vbuf.v_flags & V_FORGET) {
91 retval = retval & ~UA_KNOWN;
92 retval = retval | UA_ZAPPED;
94 /* If user is explicitly locked out of this room, deny everything */
95 if (vbuf.v_flags & V_LOCKOUT) {
96 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
98 /* Aides get access to everything */
99 if (userbuf->axlevel >= 6) {
100 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
101 retval = retval & ~UA_ZAPPED;
103 NEWMSG: /* By the way, we also check for the presence of new messages */
104 if ((roombuf->QRhighest) > (vbuf.v_lastseen)) {
105 retval = retval | UA_HASNEWMSGS;
111 * Self-checking stuff for a room record read into memory
113 void room_sanity_check(struct quickroom *qrbuf)
115 /* Mailbox rooms are always on the lowest floor */
116 if (qrbuf->QRflags & QR_MAILBOX) {
119 /* Listing order of 0 is illegal except for base rooms */
120 if (qrbuf->QRorder == 0)
121 if (!is_noneditable(qrbuf))
127 * getroom() - retrieve room data from disk
129 int getroom(struct quickroom *qrbuf, char *room_name)
131 struct cdbdata *cdbqr;
132 char lowercase_name[ROOMNAMELEN];
133 char personal_lowercase_name[ROOMNAMELEN];
136 for (a = 0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
137 lowercase_name[a] = tolower(room_name[a]);
139 lowercase_name[a] = 0;
141 memset(qrbuf, 0, sizeof(struct quickroom));
143 /* First, try the public namespace */
144 cdbqr = cdb_fetch(CDB_QUICKROOM,
145 lowercase_name, strlen(lowercase_name));
147 /* If that didn't work, try the user's personal namespace */
149 sprintf(personal_lowercase_name, "%010ld.%s",
150 CC->usersupp.usernum, lowercase_name);
151 cdbqr = cdb_fetch(CDB_QUICKROOM,
152 personal_lowercase_name,
153 strlen(personal_lowercase_name));
156 memcpy(qrbuf, cdbqr->ptr,
157 ((cdbqr->len > sizeof(struct quickroom)) ?
158 sizeof(struct quickroom) : cdbqr->len));
161 room_sanity_check(qrbuf);
170 * lgetroom() - same as getroom() but locks the record (if supported)
172 int lgetroom(struct quickroom *qrbuf, char *room_name)
175 retval = getroom(qrbuf, room_name);
176 if (retval == 0) begin_critical_section(S_QUICKROOM);
182 * b_putroom() - back end to putroom() and b_deleteroom()
183 * (if the supplied buffer is NULL, delete the room record)
185 void b_putroom(struct quickroom *qrbuf, char *room_name)
187 char lowercase_name[ROOMNAMELEN];
190 for (a = 0; a <= strlen(room_name); ++a) {
191 lowercase_name[a] = tolower(room_name[a]);
195 cdb_delete(CDB_QUICKROOM,
196 lowercase_name, strlen(lowercase_name));
198 time(&qrbuf->QRmtime);
199 cdb_store(CDB_QUICKROOM,
200 lowercase_name, strlen(lowercase_name),
201 qrbuf, sizeof(struct quickroom));
207 * putroom() - store room data to disk
209 void putroom(struct quickroom *qrbuf) {
210 b_putroom(qrbuf, qrbuf->QRname);
215 * b_deleteroom() - delete a room record from disk
217 void b_deleteroom(char *room_name) {
218 b_putroom(NULL, room_name);
224 * lputroom() - same as putroom() but unlocks the record (if supported)
226 void lputroom(struct quickroom *qrbuf)
230 end_critical_section(S_QUICKROOM);
234 /****************************************************************************/
237 * getfloor() - retrieve floor data from disk
239 void getfloor(struct floor *flbuf, int floor_num)
241 struct cdbdata *cdbfl;
243 memset(flbuf, 0, sizeof(struct floor));
244 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
246 memcpy(flbuf, cdbfl->ptr,
247 ((cdbfl->len > sizeof(struct floor)) ?
248 sizeof(struct floor) : cdbfl->len));
251 if (floor_num == 0) {
252 strcpy(flbuf->f_name, "Main Floor");
253 flbuf->f_flags = F_INUSE;
254 flbuf->f_ref_count = 3;
261 * lgetfloor() - same as getfloor() but locks the record (if supported)
263 void lgetfloor(struct floor *flbuf, int floor_num)
266 begin_critical_section(S_FLOORTAB);
267 getfloor(flbuf, floor_num);
272 * putfloor() - store floor data on disk
274 void putfloor(struct floor *flbuf, int floor_num)
276 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
277 flbuf, sizeof(struct floor));
282 * lputfloor() - same as putfloor() but unlocks the record (if supported)
284 void lputfloor(struct floor *flbuf, int floor_num)
287 putfloor(flbuf, floor_num);
288 end_critical_section(S_FLOORTAB);
294 * Traverse the room file...
296 void ForEachRoom(void (*CallBack) (struct quickroom *EachRoom, void *out_data),
299 struct quickroom qrbuf;
300 struct cdbdata *cdbqr;
302 cdb_rewind(CDB_QUICKROOM);
304 while (cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
305 memset(&qrbuf, 0, sizeof(struct quickroom));
306 memcpy(&qrbuf, cdbqr->ptr,
307 ((cdbqr->len > sizeof(struct quickroom)) ?
308 sizeof(struct quickroom) : cdbqr->len));
310 room_sanity_check(&qrbuf);
311 if (qrbuf.QRflags & QR_INUSE)
312 (*CallBack)(&qrbuf, in_data);
318 * delete_msglist() - delete room message pointers
319 * FIXME - this really should check first to make sure there's actually a
320 * msglist to delete. As things stand now, calling this function on
321 * a room which has never been posted in will result in a message
322 * like "gdbm: illegal data" (no big deal, but could use fixing).
324 void delete_msglist(struct quickroom *whichroom)
327 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
334 * sort message pointers
335 * (returns new msg count)
337 int sort_msglist(long listptrs[], int oldcount)
348 for (a = numitems - 2; a >= 0; --a) {
349 for (b = 0; b <= a; ++b) {
350 if (listptrs[b] > (listptrs[b + 1])) {
352 hold2 = listptrs[b + 1];
354 listptrs[b + 1] = hold1;
359 /* and yank any nulls */
360 while ((numitems > 0) && (listptrs[0] == 0L)) {
361 memcpy(&listptrs[0], &listptrs[1],
362 (sizeof(long) * (numitems - 1)));
371 * Determine whether a given room is non-editable.
373 int is_noneditable(struct quickroom *qrbuf)
376 /* Lobby> and Aide> are non-editable */
377 if (!strcasecmp(qrbuf->QRname, BASEROOM))
379 else if (!strcasecmp(qrbuf->QRname, AIDEROOM))
382 /* Mail> rooms are also non-editable */
383 else if ( (qrbuf->QRflags & QR_MAILBOX)
384 && (!strcasecmp(&qrbuf->QRname[11], MAILROOM)) )
387 /* Everything else is editable */
395 * Back-back-end for all room listing commands
397 void list_roomname(struct quickroom *qrbuf)
399 char truncated_roomname[ROOMNAMELEN];
401 /* For mailbox rooms, chop off the owner prefix */
402 if (qrbuf->QRflags & QR_MAILBOX) {
403 strcpy(truncated_roomname, qrbuf->QRname);
404 strcpy(truncated_roomname, &truncated_roomname[11]);
405 cprintf("%s", truncated_roomname);
407 /* For all other rooms, just display the name in its entirety */
409 cprintf("%s", qrbuf->QRname);
412 /* ...and now the other parameters */
413 cprintf("|%u|%d|%d\n",
415 (int) qrbuf->QRfloor,
416 (int) qrbuf->QRorder);
421 * cmd_lrms() - List all accessible rooms, known or forgotten
423 void cmd_lrms_backend(struct quickroom *qrbuf, void *data)
425 int FloorBeingSearched = (-1);
426 FloorBeingSearched = *(int *)data;
428 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
429 & (UA_KNOWN | UA_ZAPPED)))
430 && ((qrbuf->QRfloor == (FloorBeingSearched))
431 || ((FloorBeingSearched) < 0)))
432 list_roomname(qrbuf);
435 void cmd_lrms(char *argbuf)
437 int FloorBeingSearched = (-1);
438 if (strlen(argbuf) > 0)
439 FloorBeingSearched = extract_int(argbuf, 0);
441 if (!(CC->logged_in)) {
442 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
445 if (getuser(&CC->usersupp, CC->curr_user)) {
446 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
449 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
451 ForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
458 * cmd_lkra() - List all known rooms
460 void cmd_lkra_backend(struct quickroom *qrbuf, void *data)
462 int FloorBeingSearched = (-1);
463 FloorBeingSearched = *(int *)data;
465 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
467 && ((qrbuf->QRfloor == (FloorBeingSearched))
468 || ((FloorBeingSearched) < 0)))
469 list_roomname(qrbuf);
472 void cmd_lkra(char *argbuf)
474 int FloorBeingSearched = (-1);
475 if (strlen(argbuf) > 0)
476 FloorBeingSearched = extract_int(argbuf, 0);
478 if (!(CC->logged_in)) {
479 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
482 if (getuser(&CC->usersupp, CC->curr_user)) {
483 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
486 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
488 ForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
495 * cmd_lkrn() - List all known rooms with new messages
497 void cmd_lkrn_backend(struct quickroom *qrbuf, void *data)
500 int FloorBeingSearched = (-1);
501 FloorBeingSearched = *(int *)data;
503 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
505 && (ra & UA_HASNEWMSGS)
506 && ((qrbuf->QRfloor == (FloorBeingSearched))
507 || ((FloorBeingSearched) < 0)))
508 list_roomname(qrbuf);
511 void cmd_lkrn(char *argbuf)
513 int FloorBeingSearched = (-1);
514 if (strlen(argbuf) > 0)
515 FloorBeingSearched = extract_int(argbuf, 0);
517 if (!(CC->logged_in)) {
518 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
521 if (getuser(&CC->usersupp, CC->curr_user)) {
522 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
525 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
527 ForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
534 * cmd_lkro() - List all known rooms
536 void cmd_lkro_backend(struct quickroom *qrbuf, void *data)
539 int FloorBeingSearched = (-1);
540 FloorBeingSearched = *(int *)data;
542 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
544 && ((ra & UA_HASNEWMSGS) == 0)
545 && ((qrbuf->QRfloor == (FloorBeingSearched))
546 || ((FloorBeingSearched) < 0)))
547 list_roomname(qrbuf);
550 void cmd_lkro(char *argbuf)
552 int FloorBeingSearched = (-1);
553 if (strlen(argbuf) > 0)
554 FloorBeingSearched = extract_int(argbuf, 0);
556 if (!(CC->logged_in)) {
557 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
560 if (getuser(&CC->usersupp, CC->curr_user)) {
561 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
564 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
566 ForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
573 * cmd_lzrm() - List all forgotten rooms
575 void cmd_lzrm_backend(struct quickroom *qrbuf, void *data)
578 int FloorBeingSearched = (-1);
579 FloorBeingSearched = *(int *)data;
581 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
582 if ((ra & UA_GOTOALLOWED)
584 && ((qrbuf->QRfloor == (FloorBeingSearched))
585 || ((FloorBeingSearched) < 0)))
586 list_roomname(qrbuf);
589 void cmd_lzrm(char *argbuf)
591 int FloorBeingSearched = (-1);
592 if (strlen(argbuf) > 0)
593 FloorBeingSearched = extract_int(argbuf, 0);
595 if (!(CC->logged_in)) {
596 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
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)
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]);
684 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
685 OK, CtdlCheckExpress(),
687 new_messages, total_messages,
688 info, CC->quickroom.QRflags,
689 CC->quickroom.QRhighest,
691 rmailflag, raideflag, newmailcount,
692 CC->quickroom.QRfloor);
698 * cmd_goto() - goto a new room
700 void cmd_goto(char *gargs)
702 struct quickroom QRscratch;
706 char augmented_roomname[256];
710 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
711 cprintf("%d not logged in\n", ERROR + NOT_LOGGED_IN);
715 extract(towhere, gargs, 0);
716 extract(password, gargs, 1);
718 getuser(&CC->usersupp, CC->curr_user);
720 if (!strcasecmp(towhere, "_BASEROOM_"))
721 strcpy(towhere, BASEROOM);
723 if (!strcasecmp(towhere, "_MAIL_"))
724 strcpy(towhere, MAILROOM);
726 if (!strcasecmp(towhere, "_BITBUCKET_"))
727 strcpy(towhere, config.c_twitroom);
730 /* First try a regular match */
731 c = getroom(&QRscratch, towhere);
733 /* Then try a mailbox name match */
735 MailboxName(augmented_roomname, &CC->usersupp, towhere);
736 c = getroom(&QRscratch, augmented_roomname);
738 strcpy(towhere, augmented_roomname);
741 /* And if the room was found... */
744 /* let internal programs go directly to any room */
745 if (CC->internal_pgm) {
746 usergoto(towhere, 1);
750 /* See if there is an existing user/room relationship */
751 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
753 /* normal clients have to pass through security */
754 if (ra & UA_GOTOALLOWED)
758 if ((QRscratch.QRflags & QR_PASSWORDED) &&
759 ((ra & UA_KNOWN) == 0) &&
760 (strcasecmp(QRscratch.QRpasswd, password))
762 cprintf("%d wrong or missing passwd\n",
763 ERROR + PASSWORD_REQUIRED);
765 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
766 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
767 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
768 ((ra & UA_KNOWN) == 0)) {
771 usergoto(towhere, 1);
777 NOPE: cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
783 struct usersupp temp;
784 struct cdbdata *cdbus;
786 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
787 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
790 getuser(&CC->usersupp, CC->curr_user);
792 if ((!is_room_aide()) && (!(CC->internal_pgm))) {
793 cprintf("%d Higher access required.\n",
794 ERROR + HIGHER_ACCESS_REQUIRED);
797 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
798 cdb_rewind(CDB_USERSUPP);
799 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
800 memset(&temp, 0, sizeof temp);
801 memcpy(&temp, cdbus->ptr, sizeof temp);
804 if ((CC->quickroom.QRflags & QR_INUSE)
805 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
807 cprintf("%s\n", temp.fullname);
814 * RDIR command for room directory
824 if (!(CC->logged_in)) {
825 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
828 getroom(&CC->quickroom, CC->quickroom.QRname);
829 getuser(&CC->usersupp, CC->curr_user);
831 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
832 cprintf("%d not here.\n", ERROR + NOT_HERE);
835 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
836 && (CC->usersupp.axlevel < 6)
837 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
838 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
841 cprintf("%d %s|%s/files/%s\n",
842 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->quickroom.QRdirname);
844 sprintf(buf, "ls %s/files/%s >%s 2> /dev/null",
845 BBSDIR, CC->quickroom.QRdirname, CC->temp);
848 sprintf(buf, "%s/files/%s/filedir", BBSDIR, CC->quickroom.QRdirname);
849 fd = fopen(buf, "r");
851 fd = fopen("/dev/null", "r");
853 ls = fopen(CC->temp, "r");
854 while (fgets(flnm, 256, ls) != NULL) {
855 flnm[strlen(flnm) - 1] = 0;
856 if (strcasecmp(flnm, "filedir")) {
857 sprintf(buf, "%s/files/%s/%s",
858 BBSDIR, CC->quickroom.QRdirname, flnm);
862 while ((fgets(buf, 256, fd) != NULL)
863 && (strlen(comment) == 0)) {
864 buf[strlen(buf) - 1] = 0;
865 if ((!strncasecmp(buf, flnm, strlen(flnm)))
866 && (buf[strlen(flnm)] == ' '))
868 &buf[strlen(flnm) + 1],
871 cprintf("%s|%ld|%s\n", flnm, statbuf.st_size, comment);
882 * get room parameters (aide or room aide command)
886 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
887 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
890 if ((!is_room_aide()) && (!(CC->internal_pgm))) {
891 cprintf("%d Higher access required.\n",
892 ERROR + HIGHER_ACCESS_REQUIRED);
895 if (is_noneditable(&CC->quickroom)) {
896 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
899 getroom(&CC->quickroom, CC->quickroom.QRname);
900 cprintf("%d%c%s|%s|%s|%d|%d|%d\n",
901 OK, CtdlCheckExpress(),
902 CC->quickroom.QRname,
903 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
904 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
905 CC->quickroom.QRflags,
906 (int) CC->quickroom.QRfloor,
907 (int) CC->quickroom.QRorder);
912 * set room parameters (aide or room aide command)
914 void cmd_setr(char *args)
918 char old_name[ROOMNAMELEN];
922 if (!(CC->logged_in)) {
923 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
926 if (!is_room_aide()) {
927 cprintf("%d Higher access required.\n",
928 ERROR + HIGHER_ACCESS_REQUIRED);
931 if (is_noneditable(&CC->quickroom)) {
932 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
935 if (num_parms(args) >= 6) {
936 getfloor(&flbuf, extract_int(args, 5));
937 if ((flbuf.f_flags & F_INUSE) == 0) {
938 cprintf("%d Invalid floor number.\n",
939 ERROR + INVALID_FLOOR_OPERATION);
943 if (num_parms(args) >= 7) {
944 new_order = extract_int(args, 6);
950 lgetroom(&CC->quickroom, CC->quickroom.QRname);
951 strcpy(old_name, CC->quickroom.QRname);
952 extract(buf, args, 0);
953 buf[ROOMNAMELEN] = 0;
954 safestrncpy(CC->quickroom.QRname, buf, sizeof CC->quickroom.QRname);
955 extract(buf, args, 1);
957 safestrncpy(CC->quickroom.QRpasswd, buf, sizeof CC->quickroom.QRpasswd);
958 extract(buf, args, 2);
960 safestrncpy(CC->quickroom.QRdirname, buf,
961 sizeof CC->quickroom.QRdirname);
962 CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
963 if (num_parms(args) >= 7)
964 CC->quickroom.QRorder = (char) new_order;
966 /* Clean up a client boo-boo: if the client set the room to
967 * guess-name or passworded, ensure that the private flag is
970 if ((CC->quickroom.QRflags & QR_GUESSNAME)
971 || (CC->quickroom.QRflags & QR_PASSWORDED))
972 CC->quickroom.QRflags |= QR_PRIVATE;
974 /* Kick everyone out if the client requested it (by changing the
975 * room's generation number)
977 if (extract_int(args, 4)) {
978 time(&CC->quickroom.QRgen);
980 old_floor = CC->quickroom.QRfloor;
981 if (num_parms(args) >= 6) {
982 CC->quickroom.QRfloor = extract_int(args, 5);
984 /* Write the room record back to disk */
985 lputroom(&CC->quickroom);
987 /* If the room name changed, then there are now two room records,
988 * so we have to delete the old one.
990 if (strcasecmp(CC->quickroom.QRname, old_name)) {
991 b_deleteroom(old_name);
993 /* adjust the floor reference counts */
994 lgetfloor(&flbuf, old_floor);
996 lputfloor(&flbuf, old_floor);
997 lgetfloor(&flbuf, CC->quickroom.QRfloor);
999 lputfloor(&flbuf, CC->quickroom.QRfloor);
1001 /* create a room directory if necessary */
1002 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1004 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1005 CC->quickroom.QRdirname);
1008 sprintf(buf, "%s> edited by %s\n", CC->quickroom.QRname, CC->curr_user);
1010 cprintf("%d Ok\n", OK);
1016 * get the name of the room aide for this room
1020 struct usersupp usbuf;
1022 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
1023 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1026 if (is_noneditable(&CC->quickroom)) {
1027 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1030 if (getuserbynumber(&usbuf, CC->quickroom.QRroomaide) == 0) {
1031 cprintf("%d %s\n", OK, usbuf.fullname);
1033 cprintf("%d \n", OK);
1039 * set the room aide for this room
1041 void cmd_seta(char *new_ra)
1043 struct usersupp usbuf;
1048 if (!(CC->logged_in)) {
1049 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1052 if (!is_room_aide()) {
1053 cprintf("%d Higher access required.\n",
1054 ERROR + HIGHER_ACCESS_REQUIRED);
1057 if (getuser(&usbuf, new_ra) != 0) {
1060 newu = usbuf.usernum;
1063 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1065 if (CC->quickroom.QRroomaide != newu) {
1068 CC->quickroom.QRroomaide = newu;
1069 lputroom(&CC->quickroom);
1072 * We have to post the change notice _after_ writing changes to
1073 * the room table, otherwise it would deadlock!
1075 if (post_notice == 1) {
1076 sprintf(buf, "%s is now room aide for %s>\n",
1077 usbuf.fullname, CC->quickroom.QRname);
1080 cprintf("%d Ok\n", OK);
1084 * Generate an associated file name for a room
1086 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix)
1088 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1092 * retrieve info file for this room
1100 assoc_file_name(filename, &CC->quickroom, "info");
1101 info_fp = fopen(filename, "r");
1103 if (info_fp == NULL) {
1104 cprintf("%d No info file.\n", ERROR);
1107 cprintf("%d Info:\n", LISTING_FOLLOWS);
1108 while (fgets(buf, 256, info_fp) != NULL) {
1109 if (strlen(buf) > 0)
1110 buf[strlen(buf) - 1] = 0;
1111 cprintf("%s\n", buf);
1118 * Back end processing to delete a room and everything associated with it
1120 void delete_room(struct quickroom *qrbuf)
1125 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1127 /* Delete the info file */
1128 assoc_file_name(filename, qrbuf, "info");
1131 /* Delete the image file */
1132 assoc_file_name(filename, qrbuf, "images");
1135 /* Delete the messages in the room
1136 * (Careful: this opens an S_QUICKROOM critical section!)
1138 CtdlDeleteMessages(qrbuf->QRname, 0L, NULL);
1140 /* Flag the room record as not in use */
1141 lgetroom(qrbuf, qrbuf->QRname);
1145 /* then decrement the reference count for the floor */
1146 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1147 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1148 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1150 /* Delete the room record from the database! */
1151 b_deleteroom(qrbuf->QRname);
1156 * aide command: kill the current room
1158 void cmd_kill(char *argbuf)
1161 char deleted_room_name[ROOMNAMELEN];
1164 kill_ok = extract_int(argbuf, 0);
1166 if (!(CC->logged_in)) {
1167 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1170 if (!is_room_aide()) {
1171 cprintf("%d Higher access required.\n",
1172 ERROR + HIGHER_ACCESS_REQUIRED);
1175 if (is_noneditable(&CC->quickroom)) {
1176 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1180 strcpy(deleted_room_name, CC->quickroom.QRname);
1181 delete_room(&CC->quickroom); /* Do the dirty work */
1182 usergoto(BASEROOM, 0); /* Return to the Lobby */
1184 /* tell the world what we did */
1185 sprintf(aaa, "%s> killed by %s\n",
1186 deleted_room_name, CC->curr_user);
1188 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1190 cprintf("%d ok to delete.\n", OK);
1196 * Internal code to create a new room (returns room flags)
1198 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1200 unsigned create_room(char *new_room_name,
1202 char *new_room_pass,
1206 struct quickroom qrbuf;
1210 if (getroom(&qrbuf, new_room_name) == 0)
1211 return (0); /* already exists */
1213 memset(&qrbuf, 0, sizeof(struct quickroom));
1214 safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
1215 safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
1216 qrbuf.QRflags = QR_INUSE;
1217 qrbuf.QRnumber = get_new_room_number();
1218 if (new_room_type > 0)
1219 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1220 if (new_room_type == 1)
1221 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1222 if (new_room_type == 2)
1223 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1224 if (new_room_type == 4)
1225 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1227 /* If the room is private, and the system administrator has elected
1228 * to automatically grant room aide privileges, do so now; otherwise,
1229 * set the room aide to undefined.
1231 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1232 qrbuf.QRroomaide = CC->usersupp.usernum;
1234 qrbuf.QRroomaide = (-1L);
1237 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1238 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1239 qrbuf.QRfloor = new_room_floor;
1241 /* save what we just did... */
1244 /* bump the reference count on whatever floor the room is on */
1245 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1246 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1247 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1249 /* be sure not to kick the creator out of the room! */
1250 lgetuser(&CC->usersupp, CC->curr_user);
1251 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1252 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1253 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1254 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1255 lputuser(&CC->usersupp);
1257 /* resume our happy day */
1258 return (qrbuf.QRflags);
1265 void cmd_cre8(char *args)
1268 char new_room_name[256];
1270 char new_room_pass[256];
1274 struct quickroom qrbuf;
1277 cre8_ok = extract_int(args, 0);
1278 extract(new_room_name, args, 1);
1279 new_room_name[ROOMNAMELEN - 1] = 0;
1280 new_room_type = extract_int(args, 2);
1281 extract(new_room_pass, args, 3);
1282 new_room_pass[9] = 0;
1285 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1286 cprintf("%d Invalid room name.\n", ERROR);
1290 if (!strcasecmp(new_room_name, MAILROOM)) {
1291 cprintf("%d '%s' already exists.\n",
1292 ERROR + ALREADY_EXISTS, new_room_name);
1296 if (num_parms(args) >= 5) {
1297 getfloor(&flbuf, extract_int(args, 4));
1298 if ((flbuf.f_flags & F_INUSE) == 0) {
1299 cprintf("%d Invalid floor number.\n",
1300 ERROR + INVALID_FLOOR_OPERATION);
1303 new_room_floor = extract_int(args, 4);
1307 if (!(CC->logged_in)) {
1308 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1312 if (CC->usersupp.axlevel < config.c_createax) {
1313 cprintf("%d You need higher access to create rooms.\n",
1314 ERROR + HIGHER_ACCESS_REQUIRED);
1318 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1319 cprintf("%d Ok to create rooms.\n", OK);
1323 if ((new_room_type < 0) || (new_room_type > 4)) {
1324 cprintf("%d Invalid room type.\n", ERROR);
1328 /* If the user is requesting a personal room, set up the room
1329 * name accordingly (prepend the user number)
1331 if (new_room_type == 4) {
1332 sprintf(aaa, "%010ld.%s",
1333 CC->usersupp.usernum, new_room_name);
1334 strcpy(new_room_name, aaa);
1337 /* Check to make sure the requested room name doesn't already exist */
1338 if (getroom(&qrbuf, new_room_name) == 0) {
1339 cprintf("%d '%s' already exists.\n",
1340 ERROR + ALREADY_EXISTS, qrbuf.QRname);
1345 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1349 newflags = create_room(new_room_name,
1350 new_room_type, new_room_pass, new_room_floor);
1352 /* post a message in Aide> describing the new room */
1353 safestrncpy(aaa, new_room_name, sizeof aaa);
1354 strcat(aaa, "> created by ");
1355 strcat(aaa, CC->usersupp.fullname);
1356 if (newflags & QR_MAILBOX)
1357 strcat(aaa, " [personal]");
1358 else if (newflags & QR_PRIVATE)
1359 strcat(aaa, " [private]");
1360 if (newflags & QR_GUESSNAME)
1361 strcat(aaa, "[guessname] ");
1362 if (newflags & QR_PASSWORDED) {
1363 strcat(aaa, "\n Password: ");
1364 strcat(aaa, new_room_pass);
1369 cprintf("%d '%s' has been created.\n", OK, qrbuf.QRname);
1374 void cmd_einf(char *ok)
1375 { /* enter info file for current room */
1377 char infofilename[256];
1380 if (!(CC->logged_in)) {
1381 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1384 if (!is_room_aide()) {
1385 cprintf("%d Higher access required.\n",
1386 ERROR + HIGHER_ACCESS_REQUIRED);
1389 if (atoi(ok) == 0) {
1390 cprintf("%d Ok.\n", OK);
1393 assoc_file_name(infofilename, &CC->quickroom, "info");
1394 lprintf(9, "opening\n");
1395 fp = fopen(infofilename, "w");
1396 lprintf(9, "checking\n");
1398 cprintf("%d Cannot open %s: %s\n",
1399 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1402 cprintf("%d Send info...\n", SEND_LISTING);
1406 if (strcmp(buf, "000"))
1407 fprintf(fp, "%s\n", buf);
1408 } while (strcmp(buf, "000"));
1411 /* now update the room index so people will see our new info */
1412 lgetroom(&CC->quickroom, CC->quickroom.QRname); /* lock so no one steps on us */
1413 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1414 lputroom(&CC->quickroom);
1419 * cmd_lflr() - List all known floors
1426 if (!(CC->logged_in)) {
1427 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1430 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1431 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1436 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1438 for (a = 0; a < MAXFLOORS; ++a) {
1439 getfloor(&flbuf, a);
1440 if (flbuf.f_flags & F_INUSE) {
1441 cprintf("%d|%s|%d\n",
1453 * create a new floor
1455 void cmd_cflr(char *argbuf)
1457 char new_floor_name[256];
1460 int free_slot = (-1);
1463 extract(new_floor_name, argbuf, 0);
1464 cflr_ok = extract_int(argbuf, 1);
1467 if (!(CC->logged_in)) {
1468 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1471 if (CC->usersupp.axlevel < 6) {
1472 cprintf("%d You need higher access to create rooms.\n",
1473 ERROR + HIGHER_ACCESS_REQUIRED);
1476 for (a = 0; a < MAXFLOORS; ++a) {
1477 getfloor(&flbuf, a);
1479 /* note any free slots while we're scanning... */
1480 if (((flbuf.f_flags & F_INUSE) == 0)
1484 /* check to see if it already exists */
1485 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1486 && (flbuf.f_flags & F_INUSE)) {
1487 cprintf("%d Floor '%s' already exists.\n",
1488 ERROR + ALREADY_EXISTS,
1494 if (free_slot < 0) {
1495 cprintf("%d There is no space available for a new floor.\n",
1496 ERROR + INVALID_FLOOR_OPERATION);
1500 cprintf("%d ok to create...\n", OK);
1503 lgetfloor(&flbuf, free_slot);
1504 flbuf.f_flags = F_INUSE;
1505 flbuf.f_ref_count = 0;
1506 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1507 lputfloor(&flbuf, free_slot);
1508 cprintf("%d %d\n", OK, free_slot);
1516 void cmd_kflr(char *argbuf)
1519 int floor_to_delete;
1523 floor_to_delete = extract_int(argbuf, 0);
1524 kflr_ok = extract_int(argbuf, 1);
1527 if (!(CC->logged_in)) {
1528 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1531 if (CC->usersupp.axlevel < 6) {
1532 cprintf("%d You need higher access to delete floors.\n",
1533 ERROR + HIGHER_ACCESS_REQUIRED);
1536 lgetfloor(&flbuf, floor_to_delete);
1539 if ((flbuf.f_flags & F_INUSE) == 0) {
1540 cprintf("%d Floor %d not in use.\n",
1541 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1544 if (flbuf.f_ref_count != 0) {
1545 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1546 ERROR + INVALID_FLOOR_OPERATION,
1551 cprintf("%d Ok\n", OK);
1553 cprintf("%d Ok to delete...\n", OK);
1560 if ((delete_ok == 1) && (kflr_ok == 1))
1562 lputfloor(&flbuf, floor_to_delete);
1568 void cmd_eflr(char *argbuf)
1574 np = num_parms(argbuf);
1576 cprintf("%d Usage error.\n", ERROR);
1579 if (!(CC->logged_in)) {
1580 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1583 if (CC->usersupp.axlevel < 6) {
1584 cprintf("%d You need higher access to edit floors.\n",
1585 ERROR + HIGHER_ACCESS_REQUIRED);
1588 floor_num = extract_int(argbuf, 0);
1589 lgetfloor(&flbuf, floor_num);
1590 if ((flbuf.f_flags & F_INUSE) == 0) {
1591 lputfloor(&flbuf, floor_num);
1592 cprintf("%d Floor %d is not in use.\n",
1593 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1597 extract(flbuf.f_name, argbuf, 1);
1598 lputfloor(&flbuf, floor_num);
1600 cprintf("%d Ok\n", OK);