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);
897 if (is_noneditable(&CC->quickroom)) {
898 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
903 getroom(&CC->quickroom, CC->quickroom.QRname);
904 cprintf("%d%c%s|%s|%s|%d|%d|%d\n",
905 OK, CtdlCheckExpress(),
906 CC->quickroom.QRname,
907 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
908 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
909 CC->quickroom.QRflags,
910 (int) CC->quickroom.QRfloor,
911 (int) CC->quickroom.QRorder);
916 * set room parameters (aide or room aide command)
918 void cmd_setr(char *args)
922 char old_name[ROOMNAMELEN];
927 if (!(CC->logged_in)) {
928 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
931 if (!is_room_aide()) {
932 cprintf("%d Higher access required.\n",
933 ERROR + HIGHER_ACCESS_REQUIRED);
938 if (is_noneditable(&CC->quickroom)) {
943 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
949 if (num_parms(args) >= 6) {
950 getfloor(&flbuf, extract_int(args, 5));
951 if ((flbuf.f_flags & F_INUSE) == 0) {
952 cprintf("%d Invalid floor number.\n",
953 ERROR + INVALID_FLOOR_OPERATION);
957 if (num_parms(args) >= 7) {
958 new_order = extract_int(args, 6);
964 lgetroom(&CC->quickroom, CC->quickroom.QRname);
966 /* Non-editable base rooms can't be renamed */
967 strcpy(old_name, CC->quickroom.QRname);
969 extract(buf, args, 0);
970 buf[ROOMNAMELEN] = 0;
971 safestrncpy(CC->quickroom.QRname, buf,
972 sizeof CC->quickroom.QRname);
975 extract(buf, args, 1);
977 safestrncpy(CC->quickroom.QRpasswd, buf, sizeof CC->quickroom.QRpasswd);
978 extract(buf, args, 2);
980 safestrncpy(CC->quickroom.QRdirname, buf,
981 sizeof CC->quickroom.QRdirname);
982 CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
983 if (num_parms(args) >= 7)
984 CC->quickroom.QRorder = (char) new_order;
986 /* Clean up a client boo-boo: if the client set the room to
987 * guess-name or passworded, ensure that the private flag is
990 if ((CC->quickroom.QRflags & QR_GUESSNAME)
991 || (CC->quickroom.QRflags & QR_PASSWORDED))
992 CC->quickroom.QRflags |= QR_PRIVATE;
994 /* Kick everyone out if the client requested it (by changing the
995 * room's generation number)
997 if (extract_int(args, 4)) {
998 time(&CC->quickroom.QRgen);
1000 old_floor = CC->quickroom.QRfloor;
1001 if (num_parms(args) >= 6) {
1002 CC->quickroom.QRfloor = extract_int(args, 5);
1004 /* Write the room record back to disk */
1005 lputroom(&CC->quickroom);
1007 /* If the room name changed, then there are now two room records,
1008 * so we have to delete the old one.
1010 if (strcasecmp(CC->quickroom.QRname, old_name)) {
1011 b_deleteroom(old_name);
1013 /* adjust the floor reference counts */
1014 lgetfloor(&flbuf, old_floor);
1015 --flbuf.f_ref_count;
1016 lputfloor(&flbuf, old_floor);
1017 lgetfloor(&flbuf, CC->quickroom.QRfloor);
1018 ++flbuf.f_ref_count;
1019 lputfloor(&flbuf, CC->quickroom.QRfloor);
1021 /* create a room directory if necessary */
1022 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1024 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1025 CC->quickroom.QRdirname);
1028 sprintf(buf, "%s> edited by %s\n", CC->quickroom.QRname, CC->curr_user);
1030 cprintf("%d Ok\n", OK);
1036 * get the name of the room aide for this room
1040 struct usersupp usbuf;
1042 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
1043 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1046 if (is_noneditable(&CC->quickroom)) {
1047 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1050 if (getuserbynumber(&usbuf, CC->quickroom.QRroomaide) == 0) {
1051 cprintf("%d %s\n", OK, usbuf.fullname);
1053 cprintf("%d \n", OK);
1059 * set the room aide for this room
1061 void cmd_seta(char *new_ra)
1063 struct usersupp usbuf;
1068 if (!(CC->logged_in)) {
1069 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1072 if (!is_room_aide()) {
1073 cprintf("%d Higher access required.\n",
1074 ERROR + HIGHER_ACCESS_REQUIRED);
1077 if (getuser(&usbuf, new_ra) != 0) {
1080 newu = usbuf.usernum;
1083 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1085 if (CC->quickroom.QRroomaide != newu) {
1088 CC->quickroom.QRroomaide = newu;
1089 lputroom(&CC->quickroom);
1092 * We have to post the change notice _after_ writing changes to
1093 * the room table, otherwise it would deadlock!
1095 if (post_notice == 1) {
1096 sprintf(buf, "%s is now room aide for %s>\n",
1097 usbuf.fullname, CC->quickroom.QRname);
1100 cprintf("%d Ok\n", OK);
1104 * Generate an associated file name for a room
1106 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix)
1108 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1112 * retrieve info file for this room
1120 assoc_file_name(filename, &CC->quickroom, "info");
1121 info_fp = fopen(filename, "r");
1123 if (info_fp == NULL) {
1124 cprintf("%d No info file.\n", ERROR);
1127 cprintf("%d Info:\n", LISTING_FOLLOWS);
1128 while (fgets(buf, 256, info_fp) != NULL) {
1129 if (strlen(buf) > 0)
1130 buf[strlen(buf) - 1] = 0;
1131 cprintf("%s\n", buf);
1138 * Back end processing to delete a room and everything associated with it
1140 void delete_room(struct quickroom *qrbuf)
1145 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1147 /* Delete the info file */
1148 assoc_file_name(filename, qrbuf, "info");
1151 /* Delete the image file */
1152 assoc_file_name(filename, qrbuf, "images");
1155 /* Delete the messages in the room
1156 * (Careful: this opens an S_QUICKROOM critical section!)
1158 CtdlDeleteMessages(qrbuf->QRname, 0L, NULL);
1160 /* Flag the room record as not in use */
1161 lgetroom(qrbuf, qrbuf->QRname);
1165 /* then decrement the reference count for the floor */
1166 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1167 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1168 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1170 /* Delete the room record from the database! */
1171 b_deleteroom(qrbuf->QRname);
1176 * aide command: kill the current room
1178 void cmd_kill(char *argbuf)
1181 char deleted_room_name[ROOMNAMELEN];
1184 kill_ok = extract_int(argbuf, 0);
1186 if (!(CC->logged_in)) {
1187 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1190 if (!is_room_aide()) {
1191 cprintf("%d Higher access required.\n",
1192 ERROR + HIGHER_ACCESS_REQUIRED);
1195 if (is_noneditable(&CC->quickroom)) {
1196 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1200 strcpy(deleted_room_name, CC->quickroom.QRname);
1201 delete_room(&CC->quickroom); /* Do the dirty work */
1202 usergoto(BASEROOM, 0); /* Return to the Lobby */
1204 /* tell the world what we did */
1205 sprintf(aaa, "%s> killed by %s\n",
1206 deleted_room_name, CC->curr_user);
1208 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1210 cprintf("%d ok to delete.\n", OK);
1216 * Internal code to create a new room (returns room flags)
1218 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1220 unsigned create_room(char *new_room_name,
1222 char *new_room_pass,
1226 struct quickroom qrbuf;
1230 if (getroom(&qrbuf, new_room_name) == 0)
1231 return (0); /* already exists */
1233 memset(&qrbuf, 0, sizeof(struct quickroom));
1234 safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
1235 safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
1236 qrbuf.QRflags = QR_INUSE;
1237 qrbuf.QRnumber = get_new_room_number();
1238 if (new_room_type > 0)
1239 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1240 if (new_room_type == 1)
1241 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1242 if (new_room_type == 2)
1243 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1244 if (new_room_type == 4)
1245 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1247 /* If the room is private, and the system administrator has elected
1248 * to automatically grant room aide privileges, do so now; otherwise,
1249 * set the room aide to undefined.
1251 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1252 qrbuf.QRroomaide = CC->usersupp.usernum;
1254 qrbuf.QRroomaide = (-1L);
1257 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1258 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1259 qrbuf.QRfloor = new_room_floor;
1261 /* save what we just did... */
1264 /* bump the reference count on whatever floor the room is on */
1265 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1266 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1267 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1269 /* be sure not to kick the creator out of the room! */
1270 lgetuser(&CC->usersupp, CC->curr_user);
1271 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1272 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1273 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1274 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1275 lputuser(&CC->usersupp);
1277 /* resume our happy day */
1278 return (qrbuf.QRflags);
1285 void cmd_cre8(char *args)
1288 char new_room_name[256];
1290 char new_room_pass[256];
1294 struct quickroom qrbuf;
1297 cre8_ok = extract_int(args, 0);
1298 extract(new_room_name, args, 1);
1299 new_room_name[ROOMNAMELEN - 1] = 0;
1300 new_room_type = extract_int(args, 2);
1301 extract(new_room_pass, args, 3);
1302 new_room_pass[9] = 0;
1305 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1306 cprintf("%d Invalid room name.\n", ERROR);
1310 if (!strcasecmp(new_room_name, MAILROOM)) {
1311 cprintf("%d '%s' already exists.\n",
1312 ERROR + ALREADY_EXISTS, new_room_name);
1316 if (num_parms(args) >= 5) {
1317 getfloor(&flbuf, extract_int(args, 4));
1318 if ((flbuf.f_flags & F_INUSE) == 0) {
1319 cprintf("%d Invalid floor number.\n",
1320 ERROR + INVALID_FLOOR_OPERATION);
1323 new_room_floor = extract_int(args, 4);
1327 if (!(CC->logged_in)) {
1328 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1332 if (CC->usersupp.axlevel < config.c_createax) {
1333 cprintf("%d You need higher access to create rooms.\n",
1334 ERROR + HIGHER_ACCESS_REQUIRED);
1338 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1339 cprintf("%d Ok to create rooms.\n", OK);
1343 if ((new_room_type < 0) || (new_room_type > 4)) {
1344 cprintf("%d Invalid room type.\n", ERROR);
1348 /* If the user is requesting a personal room, set up the room
1349 * name accordingly (prepend the user number)
1351 if (new_room_type == 4) {
1352 sprintf(aaa, "%010ld.%s",
1353 CC->usersupp.usernum, new_room_name);
1354 strcpy(new_room_name, aaa);
1357 /* Check to make sure the requested room name doesn't already exist */
1358 if (getroom(&qrbuf, new_room_name) == 0) {
1359 cprintf("%d '%s' already exists.\n",
1360 ERROR + ALREADY_EXISTS, qrbuf.QRname);
1365 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1369 newflags = create_room(new_room_name,
1370 new_room_type, new_room_pass, new_room_floor);
1372 /* post a message in Aide> describing the new room */
1373 safestrncpy(aaa, new_room_name, sizeof aaa);
1374 strcat(aaa, "> created by ");
1375 strcat(aaa, CC->usersupp.fullname);
1376 if (newflags & QR_MAILBOX)
1377 strcat(aaa, " [personal]");
1378 else if (newflags & QR_PRIVATE)
1379 strcat(aaa, " [private]");
1380 if (newflags & QR_GUESSNAME)
1381 strcat(aaa, "[guessname] ");
1382 if (newflags & QR_PASSWORDED) {
1383 strcat(aaa, "\n Password: ");
1384 strcat(aaa, new_room_pass);
1389 cprintf("%d '%s' has been created.\n", OK, qrbuf.QRname);
1394 void cmd_einf(char *ok)
1395 { /* enter info file for current room */
1397 char infofilename[256];
1400 if (!(CC->logged_in)) {
1401 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1404 if (!is_room_aide()) {
1405 cprintf("%d Higher access required.\n",
1406 ERROR + HIGHER_ACCESS_REQUIRED);
1409 if (atoi(ok) == 0) {
1410 cprintf("%d Ok.\n", OK);
1413 assoc_file_name(infofilename, &CC->quickroom, "info");
1414 lprintf(9, "opening\n");
1415 fp = fopen(infofilename, "w");
1416 lprintf(9, "checking\n");
1418 cprintf("%d Cannot open %s: %s\n",
1419 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1422 cprintf("%d Send info...\n", SEND_LISTING);
1426 if (strcmp(buf, "000"))
1427 fprintf(fp, "%s\n", buf);
1428 } while (strcmp(buf, "000"));
1431 /* now update the room index so people will see our new info */
1432 lgetroom(&CC->quickroom, CC->quickroom.QRname); /* lock so no one steps on us */
1433 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1434 lputroom(&CC->quickroom);
1439 * cmd_lflr() - List all known floors
1446 if (!(CC->logged_in)) {
1447 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1450 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1451 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1456 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1458 for (a = 0; a < MAXFLOORS; ++a) {
1459 getfloor(&flbuf, a);
1460 if (flbuf.f_flags & F_INUSE) {
1461 cprintf("%d|%s|%d\n",
1473 * create a new floor
1475 void cmd_cflr(char *argbuf)
1477 char new_floor_name[256];
1480 int free_slot = (-1);
1483 extract(new_floor_name, argbuf, 0);
1484 cflr_ok = extract_int(argbuf, 1);
1487 if (!(CC->logged_in)) {
1488 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1491 if (CC->usersupp.axlevel < 6) {
1492 cprintf("%d You need higher access to create rooms.\n",
1493 ERROR + HIGHER_ACCESS_REQUIRED);
1496 for (a = 0; a < MAXFLOORS; ++a) {
1497 getfloor(&flbuf, a);
1499 /* note any free slots while we're scanning... */
1500 if (((flbuf.f_flags & F_INUSE) == 0)
1504 /* check to see if it already exists */
1505 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1506 && (flbuf.f_flags & F_INUSE)) {
1507 cprintf("%d Floor '%s' already exists.\n",
1508 ERROR + ALREADY_EXISTS,
1514 if (free_slot < 0) {
1515 cprintf("%d There is no space available for a new floor.\n",
1516 ERROR + INVALID_FLOOR_OPERATION);
1520 cprintf("%d ok to create...\n", OK);
1523 lgetfloor(&flbuf, free_slot);
1524 flbuf.f_flags = F_INUSE;
1525 flbuf.f_ref_count = 0;
1526 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1527 lputfloor(&flbuf, free_slot);
1528 cprintf("%d %d\n", OK, free_slot);
1536 void cmd_kflr(char *argbuf)
1539 int floor_to_delete;
1543 floor_to_delete = extract_int(argbuf, 0);
1544 kflr_ok = extract_int(argbuf, 1);
1547 if (!(CC->logged_in)) {
1548 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1551 if (CC->usersupp.axlevel < 6) {
1552 cprintf("%d You need higher access to delete floors.\n",
1553 ERROR + HIGHER_ACCESS_REQUIRED);
1556 lgetfloor(&flbuf, floor_to_delete);
1559 if ((flbuf.f_flags & F_INUSE) == 0) {
1560 cprintf("%d Floor %d not in use.\n",
1561 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1564 if (flbuf.f_ref_count != 0) {
1565 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1566 ERROR + INVALID_FLOOR_OPERATION,
1571 cprintf("%d Ok\n", OK);
1573 cprintf("%d Ok to delete...\n", OK);
1580 if ((delete_ok == 1) && (kflr_ok == 1))
1582 lputfloor(&flbuf, floor_to_delete);
1588 void cmd_eflr(char *argbuf)
1594 np = num_parms(argbuf);
1596 cprintf("%d Usage error.\n", ERROR);
1599 if (!(CC->logged_in)) {
1600 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1603 if (CC->usersupp.axlevel < 6) {
1604 cprintf("%d You need higher access to edit floors.\n",
1605 ERROR + HIGHER_ACCESS_REQUIRED);
1608 floor_num = extract_int(argbuf, 0);
1609 lgetfloor(&flbuf, floor_num);
1610 if ((flbuf.f_flags & F_INUSE) == 0) {
1611 lputfloor(&flbuf, floor_num);
1612 cprintf("%d Floor %d is not in use.\n",
1613 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1617 extract(flbuf.f_name, argbuf, 1);
1618 lputfloor(&flbuf, floor_num);
1620 cprintf("%d Ok\n", OK);