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
320 void delete_msglist(struct quickroom *whichroom)
322 struct cdbdata *cdbml;
324 /* Make sure the msglist we're deleting actually exists, otherwise
325 * gdbm will complain when we try to delete an invalid record
327 cdbml = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
331 /* Go ahead and delete it */
332 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
340 * sort message pointers
341 * (returns new msg count)
343 int sort_msglist(long listptrs[], int oldcount)
354 for (a = numitems - 2; a >= 0; --a) {
355 for (b = 0; b <= a; ++b) {
356 if (listptrs[b] > (listptrs[b + 1])) {
358 hold2 = listptrs[b + 1];
360 listptrs[b + 1] = hold1;
365 /* and yank any nulls */
366 while ((numitems > 0) && (listptrs[0] == 0L)) {
367 memcpy(&listptrs[0], &listptrs[1],
368 (sizeof(long) * (numitems - 1)));
377 * Determine whether a given room is non-editable.
379 int is_noneditable(struct quickroom *qrbuf)
382 /* Lobby> and Aide> are non-editable */
383 if (!strcasecmp(qrbuf->QRname, BASEROOM))
385 else if (!strcasecmp(qrbuf->QRname, AIDEROOM))
388 /* Mail> rooms are also non-editable */
389 else if ( (qrbuf->QRflags & QR_MAILBOX)
390 && (!strcasecmp(&qrbuf->QRname[11], MAILROOM)) )
393 /* Everything else is editable */
401 * Back-back-end for all room listing commands
403 void list_roomname(struct quickroom *qrbuf)
405 char truncated_roomname[ROOMNAMELEN];
407 /* For mailbox rooms, chop off the owner prefix */
408 if (qrbuf->QRflags & QR_MAILBOX) {
409 strcpy(truncated_roomname, qrbuf->QRname);
410 strcpy(truncated_roomname, &truncated_roomname[11]);
411 cprintf("%s", truncated_roomname);
413 /* For all other rooms, just display the name in its entirety */
415 cprintf("%s", qrbuf->QRname);
418 /* ...and now the other parameters */
419 cprintf("|%u|%d|%d\n",
421 (int) qrbuf->QRfloor,
422 (int) qrbuf->QRorder);
427 * cmd_lrms() - List all accessible rooms, known or forgotten
429 void cmd_lrms_backend(struct quickroom *qrbuf, void *data)
431 int FloorBeingSearched = (-1);
432 FloorBeingSearched = *(int *)data;
434 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
435 & (UA_KNOWN | UA_ZAPPED)))
436 && ((qrbuf->QRfloor == (FloorBeingSearched))
437 || ((FloorBeingSearched) < 0)))
438 list_roomname(qrbuf);
441 void cmd_lrms(char *argbuf)
443 int FloorBeingSearched = (-1);
444 if (strlen(argbuf) > 0)
445 FloorBeingSearched = extract_int(argbuf, 0);
447 if (!(CC->logged_in)) {
448 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
451 if (getuser(&CC->usersupp, CC->curr_user)) {
452 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
455 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
457 ForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
464 * cmd_lkra() - List all known rooms
466 void cmd_lkra_backend(struct quickroom *qrbuf, void *data)
468 int FloorBeingSearched = (-1);
469 FloorBeingSearched = *(int *)data;
471 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
473 && ((qrbuf->QRfloor == (FloorBeingSearched))
474 || ((FloorBeingSearched) < 0)))
475 list_roomname(qrbuf);
478 void cmd_lkra(char *argbuf)
480 int FloorBeingSearched = (-1);
481 if (strlen(argbuf) > 0)
482 FloorBeingSearched = extract_int(argbuf, 0);
484 if (!(CC->logged_in)) {
485 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
488 if (getuser(&CC->usersupp, CC->curr_user)) {
489 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
492 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
494 ForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
501 * cmd_lkrn() - List all known rooms with new messages
503 void cmd_lkrn_backend(struct quickroom *qrbuf, void *data)
506 int FloorBeingSearched = (-1);
507 FloorBeingSearched = *(int *)data;
509 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
511 && (ra & UA_HASNEWMSGS)
512 && ((qrbuf->QRfloor == (FloorBeingSearched))
513 || ((FloorBeingSearched) < 0)))
514 list_roomname(qrbuf);
517 void cmd_lkrn(char *argbuf)
519 int FloorBeingSearched = (-1);
520 if (strlen(argbuf) > 0)
521 FloorBeingSearched = extract_int(argbuf, 0);
523 if (!(CC->logged_in)) {
524 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
527 if (getuser(&CC->usersupp, CC->curr_user)) {
528 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
531 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
533 ForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
540 * cmd_lkro() - List all known rooms
542 void cmd_lkro_backend(struct quickroom *qrbuf, void *data)
545 int FloorBeingSearched = (-1);
546 FloorBeingSearched = *(int *)data;
548 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
550 && ((ra & UA_HASNEWMSGS) == 0)
551 && ((qrbuf->QRfloor == (FloorBeingSearched))
552 || ((FloorBeingSearched) < 0)))
553 list_roomname(qrbuf);
556 void cmd_lkro(char *argbuf)
558 int FloorBeingSearched = (-1);
559 if (strlen(argbuf) > 0)
560 FloorBeingSearched = extract_int(argbuf, 0);
562 if (!(CC->logged_in)) {
563 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
566 if (getuser(&CC->usersupp, CC->curr_user)) {
567 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
570 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
572 ForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
579 * cmd_lzrm() - List all forgotten rooms
581 void cmd_lzrm_backend(struct quickroom *qrbuf, void *data)
584 int FloorBeingSearched = (-1);
585 FloorBeingSearched = *(int *)data;
587 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
588 if ((ra & UA_GOTOALLOWED)
590 && ((qrbuf->QRfloor == (FloorBeingSearched))
591 || ((FloorBeingSearched) < 0)))
592 list_roomname(qrbuf);
595 void cmd_lzrm(char *argbuf)
597 int FloorBeingSearched = (-1);
598 if (strlen(argbuf) > 0)
599 FloorBeingSearched = extract_int(argbuf, 0);
601 if (!(CC->logged_in)) {
602 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
605 if (getuser(&CC->usersupp, CC->curr_user)) {
606 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
609 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
611 ForEachRoom(cmd_lzrm_backend, &FloorBeingSearched);
617 void usergoto(char *where, int display_result)
620 int new_messages = 0;
621 int total_messages = 0;
625 int newmailcount = 0;
627 char truncated_roomname[ROOMNAMELEN];
628 struct cdbdata *cdbfr;
629 long *msglist = NULL;
632 strcpy(CC->quickroom.QRname, where);
633 getroom(&CC->quickroom, where);
635 lgetuser(&CC->usersupp, CC->curr_user);
636 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
638 /* Know the room ... but not if it's the page log room */
639 if (strcasecmp(where, config.c_logpages)) {
640 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
641 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
643 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
644 lputuser(&CC->usersupp);
646 /* check for new mail */
647 newmailcount = NewMailCount();
649 /* set info to 1 if the user needs to read the room's info file */
650 if (CC->quickroom.QRinfo > vbuf.v_lastseen)
654 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->quickroom.QRnumber, sizeof(long));
656 msglist = mallok(cdbfr->len);
657 memcpy(msglist, cdbfr->ptr, cdbfr->len);
658 num_msgs = cdbfr->len / sizeof(long);
662 if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
663 if (msglist[a] > 0L) {
665 if (msglist[a] > vbuf.v_lastseen) {
671 if (msglist != NULL) phree(msglist);
673 if (CC->quickroom.QRflags & QR_MAILBOX)
678 if ((CC->quickroom.QRroomaide == CC->usersupp.usernum)
679 || (CC->usersupp.axlevel >= 6))
684 strcpy(truncated_roomname, CC->quickroom.QRname);
685 if (CC->quickroom.QRflags & QR_MAILBOX) {
686 strcpy(truncated_roomname, &truncated_roomname[11]);
690 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
691 OK, CtdlCheckExpress(),
693 new_messages, total_messages,
694 info, CC->quickroom.QRflags,
695 CC->quickroom.QRhighest,
697 rmailflag, raideflag, newmailcount,
698 CC->quickroom.QRfloor);
704 * cmd_goto() - goto a new room
706 void cmd_goto(char *gargs)
708 struct quickroom QRscratch;
712 char augmented_roomname[256];
716 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
717 cprintf("%d not logged in\n", ERROR + NOT_LOGGED_IN);
721 extract(towhere, gargs, 0);
722 extract(password, gargs, 1);
724 getuser(&CC->usersupp, CC->curr_user);
726 if (!strcasecmp(towhere, "_BASEROOM_"))
727 strcpy(towhere, BASEROOM);
729 if (!strcasecmp(towhere, "_MAIL_"))
730 strcpy(towhere, MAILROOM);
732 if (!strcasecmp(towhere, "_BITBUCKET_"))
733 strcpy(towhere, config.c_twitroom);
736 /* First try a regular match */
737 c = getroom(&QRscratch, towhere);
739 /* Then try a mailbox name match */
741 MailboxName(augmented_roomname, &CC->usersupp, towhere);
742 c = getroom(&QRscratch, augmented_roomname);
744 strcpy(towhere, augmented_roomname);
747 /* And if the room was found... */
750 /* let internal programs go directly to any room */
751 if (CC->internal_pgm) {
752 usergoto(towhere, 1);
756 /* See if there is an existing user/room relationship */
757 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
759 /* normal clients have to pass through security */
760 if (ra & UA_GOTOALLOWED)
764 if ((QRscratch.QRflags & QR_PASSWORDED) &&
765 ((ra & UA_KNOWN) == 0) &&
766 (strcasecmp(QRscratch.QRpasswd, password))
768 cprintf("%d wrong or missing passwd\n",
769 ERROR + PASSWORD_REQUIRED);
771 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
772 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
773 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
774 ((ra & UA_KNOWN) == 0)) {
777 usergoto(towhere, 1);
783 NOPE: cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
789 struct usersupp temp;
790 struct cdbdata *cdbus;
792 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
793 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
796 getuser(&CC->usersupp, CC->curr_user);
798 if ((!is_room_aide()) && (!(CC->internal_pgm))) {
799 cprintf("%d Higher access required.\n",
800 ERROR + HIGHER_ACCESS_REQUIRED);
803 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
804 cdb_rewind(CDB_USERSUPP);
805 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
806 memset(&temp, 0, sizeof temp);
807 memcpy(&temp, cdbus->ptr, sizeof temp);
810 if ((CC->quickroom.QRflags & QR_INUSE)
811 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
813 cprintf("%s\n", temp.fullname);
820 * RDIR command for room directory
830 if (!(CC->logged_in)) {
831 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
834 getroom(&CC->quickroom, CC->quickroom.QRname);
835 getuser(&CC->usersupp, CC->curr_user);
837 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
838 cprintf("%d not here.\n", ERROR + NOT_HERE);
841 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
842 && (CC->usersupp.axlevel < 6)
843 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
844 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
847 cprintf("%d %s|%s/files/%s\n",
848 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->quickroom.QRdirname);
850 sprintf(buf, "ls %s/files/%s >%s 2> /dev/null",
851 BBSDIR, CC->quickroom.QRdirname, CC->temp);
854 sprintf(buf, "%s/files/%s/filedir", BBSDIR, CC->quickroom.QRdirname);
855 fd = fopen(buf, "r");
857 fd = fopen("/dev/null", "r");
859 ls = fopen(CC->temp, "r");
860 while (fgets(flnm, 256, ls) != NULL) {
861 flnm[strlen(flnm) - 1] = 0;
862 if (strcasecmp(flnm, "filedir")) {
863 sprintf(buf, "%s/files/%s/%s",
864 BBSDIR, CC->quickroom.QRdirname, flnm);
868 while ((fgets(buf, 256, fd) != NULL)
869 && (strlen(comment) == 0)) {
870 buf[strlen(buf) - 1] = 0;
871 if ((!strncasecmp(buf, flnm, strlen(flnm)))
872 && (buf[strlen(flnm)] == ' '))
874 &buf[strlen(flnm) + 1],
877 cprintf("%s|%ld|%s\n", flnm, statbuf.st_size, comment);
888 * get room parameters (aide or room aide command)
892 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
893 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
896 if ((!is_room_aide()) && (!(CC->internal_pgm))) {
897 cprintf("%d Higher access required.\n",
898 ERROR + HIGHER_ACCESS_REQUIRED);
903 if (is_noneditable(&CC->quickroom)) {
904 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
909 getroom(&CC->quickroom, CC->quickroom.QRname);
910 cprintf("%d%c%s|%s|%s|%d|%d|%d\n",
911 OK, CtdlCheckExpress(),
912 CC->quickroom.QRname,
913 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
914 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
915 CC->quickroom.QRflags,
916 (int) CC->quickroom.QRfloor,
917 (int) CC->quickroom.QRorder);
922 * set room parameters (aide or room aide command)
924 void cmd_setr(char *args)
928 char old_name[ROOMNAMELEN];
933 if (!(CC->logged_in)) {
934 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
937 if (!is_room_aide()) {
938 cprintf("%d Higher access required.\n",
939 ERROR + HIGHER_ACCESS_REQUIRED);
944 if (is_noneditable(&CC->quickroom)) {
949 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
955 if (num_parms(args) >= 6) {
956 getfloor(&flbuf, extract_int(args, 5));
957 if ((flbuf.f_flags & F_INUSE) == 0) {
958 cprintf("%d Invalid floor number.\n",
959 ERROR + INVALID_FLOOR_OPERATION);
963 if (num_parms(args) >= 7) {
964 new_order = extract_int(args, 6);
970 lgetroom(&CC->quickroom, CC->quickroom.QRname);
972 /* Non-editable base rooms can't be renamed */
973 strcpy(old_name, CC->quickroom.QRname);
975 extract(buf, args, 0);
976 buf[ROOMNAMELEN] = 0;
977 safestrncpy(CC->quickroom.QRname, buf,
978 sizeof CC->quickroom.QRname);
981 extract(buf, args, 1);
983 safestrncpy(CC->quickroom.QRpasswd, buf, sizeof CC->quickroom.QRpasswd);
984 extract(buf, args, 2);
986 safestrncpy(CC->quickroom.QRdirname, buf,
987 sizeof CC->quickroom.QRdirname);
988 CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
989 if (num_parms(args) >= 7)
990 CC->quickroom.QRorder = (char) new_order;
992 /* Clean up a client boo-boo: if the client set the room to
993 * guess-name or passworded, ensure that the private flag is
996 if ((CC->quickroom.QRflags & QR_GUESSNAME)
997 || (CC->quickroom.QRflags & QR_PASSWORDED))
998 CC->quickroom.QRflags |= QR_PRIVATE;
1000 /* Kick everyone out if the client requested it (by changing the
1001 * room's generation number)
1003 if (extract_int(args, 4)) {
1004 time(&CC->quickroom.QRgen);
1006 old_floor = CC->quickroom.QRfloor;
1007 if (num_parms(args) >= 6) {
1008 CC->quickroom.QRfloor = extract_int(args, 5);
1010 /* Write the room record back to disk */
1011 lputroom(&CC->quickroom);
1013 /* If the room name changed, then there are now two room records,
1014 * so we have to delete the old one.
1016 if (strcasecmp(CC->quickroom.QRname, old_name)) {
1017 b_deleteroom(old_name);
1019 /* adjust the floor reference counts */
1020 lgetfloor(&flbuf, old_floor);
1021 --flbuf.f_ref_count;
1022 lputfloor(&flbuf, old_floor);
1023 lgetfloor(&flbuf, CC->quickroom.QRfloor);
1024 ++flbuf.f_ref_count;
1025 lputfloor(&flbuf, CC->quickroom.QRfloor);
1027 /* create a room directory if necessary */
1028 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1030 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1031 CC->quickroom.QRdirname);
1034 sprintf(buf, "%s> edited by %s\n", CC->quickroom.QRname, CC->curr_user);
1036 cprintf("%d Ok\n", OK);
1042 * get the name of the room aide for this room
1046 struct usersupp usbuf;
1048 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
1049 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1052 if (is_noneditable(&CC->quickroom)) {
1053 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1056 if (getuserbynumber(&usbuf, CC->quickroom.QRroomaide) == 0) {
1057 cprintf("%d %s\n", OK, usbuf.fullname);
1059 cprintf("%d \n", OK);
1065 * set the room aide for this room
1067 void cmd_seta(char *new_ra)
1069 struct usersupp usbuf;
1074 if (!(CC->logged_in)) {
1075 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1078 if (!is_room_aide()) {
1079 cprintf("%d Higher access required.\n",
1080 ERROR + HIGHER_ACCESS_REQUIRED);
1083 if (getuser(&usbuf, new_ra) != 0) {
1086 newu = usbuf.usernum;
1089 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1091 if (CC->quickroom.QRroomaide != newu) {
1094 CC->quickroom.QRroomaide = newu;
1095 lputroom(&CC->quickroom);
1098 * We have to post the change notice _after_ writing changes to
1099 * the room table, otherwise it would deadlock!
1101 if (post_notice == 1) {
1102 sprintf(buf, "%s is now room aide for %s>\n",
1103 usbuf.fullname, CC->quickroom.QRname);
1106 cprintf("%d Ok\n", OK);
1110 * Generate an associated file name for a room
1112 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix)
1114 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1118 * retrieve info file for this room
1126 assoc_file_name(filename, &CC->quickroom, "info");
1127 info_fp = fopen(filename, "r");
1129 if (info_fp == NULL) {
1130 cprintf("%d No info file.\n", ERROR);
1133 cprintf("%d Info:\n", LISTING_FOLLOWS);
1134 while (fgets(buf, 256, info_fp) != NULL) {
1135 if (strlen(buf) > 0)
1136 buf[strlen(buf) - 1] = 0;
1137 cprintf("%s\n", buf);
1144 * Back end processing to delete a room and everything associated with it
1146 void delete_room(struct quickroom *qrbuf)
1151 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1153 /* Delete the info file */
1154 assoc_file_name(filename, qrbuf, "info");
1157 /* Delete the image file */
1158 assoc_file_name(filename, qrbuf, "images");
1161 /* Delete the messages in the room
1162 * (Careful: this opens an S_QUICKROOM critical section!)
1164 CtdlDeleteMessages(qrbuf->QRname, 0L, NULL);
1166 /* Flag the room record as not in use */
1167 lgetroom(qrbuf, qrbuf->QRname);
1171 /* then decrement the reference count for the floor */
1172 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1173 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1174 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1176 /* Delete the room record from the database! */
1177 b_deleteroom(qrbuf->QRname);
1182 * aide command: kill the current room
1184 void cmd_kill(char *argbuf)
1187 char deleted_room_name[ROOMNAMELEN];
1190 kill_ok = extract_int(argbuf, 0);
1192 if (!(CC->logged_in)) {
1193 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1196 if (!is_room_aide()) {
1197 cprintf("%d Higher access required.\n",
1198 ERROR + HIGHER_ACCESS_REQUIRED);
1201 if (is_noneditable(&CC->quickroom)) {
1202 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1206 strcpy(deleted_room_name, CC->quickroom.QRname);
1207 delete_room(&CC->quickroom); /* Do the dirty work */
1208 usergoto(BASEROOM, 0); /* Return to the Lobby */
1210 /* tell the world what we did */
1211 sprintf(aaa, "%s> killed by %s\n",
1212 deleted_room_name, CC->curr_user);
1214 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1216 cprintf("%d ok to delete.\n", OK);
1222 * Internal code to create a new room (returns room flags)
1224 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1226 unsigned create_room(char *new_room_name,
1228 char *new_room_pass,
1232 struct quickroom qrbuf;
1236 if (getroom(&qrbuf, new_room_name) == 0)
1237 return (0); /* already exists */
1239 memset(&qrbuf, 0, sizeof(struct quickroom));
1240 safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
1241 safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
1242 qrbuf.QRflags = QR_INUSE;
1243 qrbuf.QRnumber = get_new_room_number();
1244 if (new_room_type > 0)
1245 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1246 if (new_room_type == 1)
1247 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1248 if (new_room_type == 2)
1249 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1250 if (new_room_type == 4)
1251 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1253 /* If the room is private, and the system administrator has elected
1254 * to automatically grant room aide privileges, do so now; otherwise,
1255 * set the room aide to undefined.
1257 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1258 qrbuf.QRroomaide = CC->usersupp.usernum;
1260 qrbuf.QRroomaide = (-1L);
1263 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1264 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1265 qrbuf.QRfloor = new_room_floor;
1267 /* save what we just did... */
1270 /* bump the reference count on whatever floor the room is on */
1271 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1272 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1273 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1275 /* be sure not to kick the creator out of the room! */
1276 lgetuser(&CC->usersupp, CC->curr_user);
1277 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1278 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1279 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1280 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1281 lputuser(&CC->usersupp);
1283 /* resume our happy day */
1284 return (qrbuf.QRflags);
1291 void cmd_cre8(char *args)
1294 char new_room_name[256];
1296 char new_room_pass[256];
1300 struct quickroom qrbuf;
1303 cre8_ok = extract_int(args, 0);
1304 extract(new_room_name, args, 1);
1305 new_room_name[ROOMNAMELEN - 1] = 0;
1306 new_room_type = extract_int(args, 2);
1307 extract(new_room_pass, args, 3);
1308 new_room_pass[9] = 0;
1311 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1312 cprintf("%d Invalid room name.\n", ERROR);
1316 if (!strcasecmp(new_room_name, MAILROOM)) {
1317 cprintf("%d '%s' already exists.\n",
1318 ERROR + ALREADY_EXISTS, new_room_name);
1322 if (num_parms(args) >= 5) {
1323 getfloor(&flbuf, extract_int(args, 4));
1324 if ((flbuf.f_flags & F_INUSE) == 0) {
1325 cprintf("%d Invalid floor number.\n",
1326 ERROR + INVALID_FLOOR_OPERATION);
1329 new_room_floor = extract_int(args, 4);
1333 if (!(CC->logged_in)) {
1334 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1338 if (CC->usersupp.axlevel < config.c_createax) {
1339 cprintf("%d You need higher access to create rooms.\n",
1340 ERROR + HIGHER_ACCESS_REQUIRED);
1344 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1345 cprintf("%d Ok to create rooms.\n", OK);
1349 if ((new_room_type < 0) || (new_room_type > 4)) {
1350 cprintf("%d Invalid room type.\n", ERROR);
1354 /* If the user is requesting a personal room, set up the room
1355 * name accordingly (prepend the user number)
1357 if (new_room_type == 4) {
1358 sprintf(aaa, "%010ld.%s",
1359 CC->usersupp.usernum, new_room_name);
1360 strcpy(new_room_name, aaa);
1363 /* Check to make sure the requested room name doesn't already exist */
1364 if (getroom(&qrbuf, new_room_name) == 0) {
1365 cprintf("%d '%s' already exists.\n",
1366 ERROR + ALREADY_EXISTS, qrbuf.QRname);
1371 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1375 newflags = create_room(new_room_name,
1376 new_room_type, new_room_pass, new_room_floor);
1378 /* post a message in Aide> describing the new room */
1379 safestrncpy(aaa, new_room_name, sizeof aaa);
1380 strcat(aaa, "> created by ");
1381 strcat(aaa, CC->usersupp.fullname);
1382 if (newflags & QR_MAILBOX)
1383 strcat(aaa, " [personal]");
1384 else if (newflags & QR_PRIVATE)
1385 strcat(aaa, " [private]");
1386 if (newflags & QR_GUESSNAME)
1387 strcat(aaa, "[guessname] ");
1388 if (newflags & QR_PASSWORDED) {
1389 strcat(aaa, "\n Password: ");
1390 strcat(aaa, new_room_pass);
1395 cprintf("%d '%s' has been created.\n", OK, qrbuf.QRname);
1400 void cmd_einf(char *ok)
1401 { /* enter info file for current room */
1403 char infofilename[256];
1406 if (!(CC->logged_in)) {
1407 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1410 if (!is_room_aide()) {
1411 cprintf("%d Higher access required.\n",
1412 ERROR + HIGHER_ACCESS_REQUIRED);
1415 if (atoi(ok) == 0) {
1416 cprintf("%d Ok.\n", OK);
1419 assoc_file_name(infofilename, &CC->quickroom, "info");
1420 lprintf(9, "opening\n");
1421 fp = fopen(infofilename, "w");
1422 lprintf(9, "checking\n");
1424 cprintf("%d Cannot open %s: %s\n",
1425 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1428 cprintf("%d Send info...\n", SEND_LISTING);
1432 if (strcmp(buf, "000"))
1433 fprintf(fp, "%s\n", buf);
1434 } while (strcmp(buf, "000"));
1437 /* now update the room index so people will see our new info */
1438 lgetroom(&CC->quickroom, CC->quickroom.QRname); /* lock so no one steps on us */
1439 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1440 lputroom(&CC->quickroom);
1445 * cmd_lflr() - List all known floors
1452 if (!(CC->logged_in)) {
1453 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1456 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1457 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1462 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1464 for (a = 0; a < MAXFLOORS; ++a) {
1465 getfloor(&flbuf, a);
1466 if (flbuf.f_flags & F_INUSE) {
1467 cprintf("%d|%s|%d\n",
1479 * create a new floor
1481 void cmd_cflr(char *argbuf)
1483 char new_floor_name[256];
1486 int free_slot = (-1);
1489 extract(new_floor_name, argbuf, 0);
1490 cflr_ok = extract_int(argbuf, 1);
1493 if (!(CC->logged_in)) {
1494 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1497 if (CC->usersupp.axlevel < 6) {
1498 cprintf("%d You need higher access to create rooms.\n",
1499 ERROR + HIGHER_ACCESS_REQUIRED);
1502 for (a = 0; a < MAXFLOORS; ++a) {
1503 getfloor(&flbuf, a);
1505 /* note any free slots while we're scanning... */
1506 if (((flbuf.f_flags & F_INUSE) == 0)
1510 /* check to see if it already exists */
1511 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1512 && (flbuf.f_flags & F_INUSE)) {
1513 cprintf("%d Floor '%s' already exists.\n",
1514 ERROR + ALREADY_EXISTS,
1520 if (free_slot < 0) {
1521 cprintf("%d There is no space available for a new floor.\n",
1522 ERROR + INVALID_FLOOR_OPERATION);
1526 cprintf("%d ok to create...\n", OK);
1529 lgetfloor(&flbuf, free_slot);
1530 flbuf.f_flags = F_INUSE;
1531 flbuf.f_ref_count = 0;
1532 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1533 lputfloor(&flbuf, free_slot);
1534 cprintf("%d %d\n", OK, free_slot);
1542 void cmd_kflr(char *argbuf)
1545 int floor_to_delete;
1549 floor_to_delete = extract_int(argbuf, 0);
1550 kflr_ok = extract_int(argbuf, 1);
1553 if (!(CC->logged_in)) {
1554 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1557 if (CC->usersupp.axlevel < 6) {
1558 cprintf("%d You need higher access to delete floors.\n",
1559 ERROR + HIGHER_ACCESS_REQUIRED);
1562 lgetfloor(&flbuf, floor_to_delete);
1565 if ((flbuf.f_flags & F_INUSE) == 0) {
1566 cprintf("%d Floor %d not in use.\n",
1567 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1570 if (flbuf.f_ref_count != 0) {
1571 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1572 ERROR + INVALID_FLOOR_OPERATION,
1577 cprintf("%d Ok\n", OK);
1579 cprintf("%d Ok to delete...\n", OK);
1586 if ((delete_ok == 1) && (kflr_ok == 1))
1588 lputfloor(&flbuf, floor_to_delete);
1594 void cmd_eflr(char *argbuf)
1600 np = num_parms(argbuf);
1602 cprintf("%d Usage error.\n", ERROR);
1605 if (!(CC->logged_in)) {
1606 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1609 if (CC->usersupp.axlevel < 6) {
1610 cprintf("%d You need higher access to edit floors.\n",
1611 ERROR + HIGHER_ACCESS_REQUIRED);
1614 floor_num = extract_int(argbuf, 0);
1615 lgetfloor(&flbuf, floor_num);
1616 if ((flbuf.f_flags & F_INUSE) == 0) {
1617 lputfloor(&flbuf, floor_num);
1618 cprintf("%d Floor %d is not in use.\n",
1619 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1623 extract(flbuf.f_name, argbuf, 1);
1624 lputfloor(&flbuf, floor_num);
1626 cprintf("%d Ok\n", OK);