19 #include "sysdep_decls.h"
23 #include "serv_chat.h"
24 #include "citserver.h"
29 * Generic routine for determining user access to rooms
31 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf)
36 /* for internal programs, always do everything */
37 if (((CC->internal_pgm)) && (roombuf->QRflags & QR_INUSE)) {
38 return (UA_KNOWN | UA_GOTOALLOWED);
40 /* For mailbox rooms, only allow access to the owner */
41 if (roombuf->QRflags & QR_MAILBOX) {
42 if (userbuf->usernum != atol(roombuf->QRname)) {
46 /* Locate any applicable user/room relationships */
47 CtdlGetRelationship(&vbuf, userbuf, roombuf);
49 /* Force the properties of the Aide room */
50 if (!strcasecmp(roombuf->QRname, AIDEROOM)) {
51 if (userbuf->axlevel >= 6) {
52 retval = UA_KNOWN | UA_GOTOALLOWED;
58 /* For mailboxes, we skip all the access stuff (and we've
59 * already checked by this point that the mailbox belongs
62 if (roombuf->QRflags & QR_MAILBOX) {
63 retval = UA_KNOWN | UA_GOTOALLOWED;
66 /* If this is a public room, it's accessible... */
67 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
68 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
70 /* If this is a preferred users only room, check access level */
71 if (roombuf->QRflags & QR_PREFONLY) {
72 if (userbuf->axlevel < 5) {
73 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
76 /* For private rooms, check the generation number matchups */
77 if (roombuf->QRflags & QR_PRIVATE) {
79 /* An explicit match means the user belongs in this room */
80 if (vbuf.v_flags & V_ACCESS) {
81 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
83 /* Otherwise, check if this is a guess-name or passworded
84 * room. If it is, a goto may at least be attempted
86 else if ((roombuf->QRflags & QR_PRIVATE)
87 || (roombuf->QRflags & QR_PASSWORDED)) {
88 retval = retval & ~UA_KNOWN;
89 retval = retval | UA_GOTOALLOWED;
92 /* Check to see if the user has forgotten this room */
93 if (vbuf.v_flags & V_FORGET) {
94 retval = retval & ~UA_KNOWN;
95 retval = retval | UA_ZAPPED;
97 /* If user is explicitly locked out of this room, deny everything */
98 if (vbuf.v_flags & V_LOCKOUT) {
99 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
101 /* Aides get access to everything */
102 if (userbuf->axlevel >= 6) {
103 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
104 retval = retval & ~UA_ZAPPED;
106 NEWMSG: /* By the way, we also check for the presence of new messages */
107 if ((roombuf->QRhighest) > (vbuf.v_lastseen)) {
108 retval = retval | UA_HASNEWMSGS;
114 * Self-checking stuff for a room record read into memory
116 void room_sanity_check(struct quickroom *qrbuf)
118 /* Mailbox rooms are always on the lowest floor */
119 if (qrbuf->QRflags & QR_MAILBOX) {
122 /* Listing order of 0 is illegal except for base rooms */
123 if (qrbuf->QRorder == 0)
124 if (!is_noneditable(qrbuf))
130 * getroom() - retrieve room data from disk
132 int getroom(struct quickroom *qrbuf, char *room_name)
134 struct cdbdata *cdbqr;
135 char lowercase_name[ROOMNAMELEN];
136 char personal_lowercase_name[ROOMNAMELEN];
139 for (a = 0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
140 lowercase_name[a] = tolower(room_name[a]);
142 lowercase_name[a] = 0;
144 memset(qrbuf, 0, sizeof(struct quickroom));
146 /* First, try the public namespace */
147 cdbqr = cdb_fetch(CDB_QUICKROOM,
148 lowercase_name, strlen(lowercase_name));
150 /* If that didn't work, try the user's personal namespace */
152 sprintf(personal_lowercase_name, "%010ld.%s",
153 CC->usersupp.usernum, lowercase_name);
154 cdbqr = cdb_fetch(CDB_QUICKROOM,
155 personal_lowercase_name,
156 strlen(personal_lowercase_name));
159 memcpy(qrbuf, cdbqr->ptr,
160 ((cdbqr->len > sizeof(struct quickroom)) ?
161 sizeof(struct quickroom) : cdbqr->len));
164 room_sanity_check(qrbuf);
173 * lgetroom() - same as getroom() but locks the record (if supported)
175 int lgetroom(struct quickroom *qrbuf, char *room_name)
177 begin_critical_section(S_QUICKROOM);
178 return (getroom(qrbuf, room_name));
183 * b_putroom() - back end to putroom() and b_deleteroom()
184 * (if the supplied buffer is NULL, delete the room record)
186 void b_putroom(struct quickroom *qrbuf, char *room_name)
188 char lowercase_name[ROOMNAMELEN];
191 for (a = 0; a <= strlen(room_name); ++a) {
192 lowercase_name[a] = tolower(room_name[a]);
196 cdb_delete(CDB_QUICKROOM,
197 lowercase_name, strlen(lowercase_name));
199 time(&qrbuf->QRmtime);
200 cdb_store(CDB_QUICKROOM,
201 lowercase_name, strlen(lowercase_name),
202 qrbuf, sizeof(struct quickroom));
208 * putroom() - store room data to disk
210 void putroom(struct quickroom *qrbuf) {
211 b_putroom(qrbuf, qrbuf->QRname);
216 * b_deleteroom() - delete a room record from disk
218 void b_deleteroom(char *room_name) {
219 b_putroom(NULL, room_name);
225 * lputroom() - same as putroom() but unlocks the record (if supported)
227 void lputroom(struct quickroom *qrbuf)
231 end_critical_section(S_QUICKROOM);
235 /****************************************************************************/
238 * getfloor() - retrieve floor data from disk
240 void getfloor(struct floor *flbuf, int floor_num)
242 struct cdbdata *cdbfl;
244 memset(flbuf, 0, sizeof(struct floor));
245 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
247 memcpy(flbuf, cdbfl->ptr,
248 ((cdbfl->len > sizeof(struct floor)) ?
249 sizeof(struct floor) : cdbfl->len));
252 if (floor_num == 0) {
253 strcpy(flbuf->f_name, "Main Floor");
254 flbuf->f_flags = F_INUSE;
255 flbuf->f_ref_count = 3;
262 * lgetfloor() - same as getfloor() but locks the record (if supported)
264 void lgetfloor(struct floor *flbuf, int floor_num)
267 begin_critical_section(S_FLOORTAB);
268 getfloor(flbuf, floor_num);
273 * putfloor() - store floor data on disk
275 void putfloor(struct floor *flbuf, int floor_num)
277 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
278 flbuf, sizeof(struct floor));
283 * lputfloor() - same as putfloor() but unlocks the record (if supported)
285 void lputfloor(struct floor *flbuf, int floor_num)
288 putfloor(flbuf, floor_num);
289 end_critical_section(S_FLOORTAB);
295 * Traverse the room file...
297 void ForEachRoom(void (*CallBack) (struct quickroom * EachRoom))
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);
318 * delete_msglist() - delete room message pointers
319 * FIX - 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)
425 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
426 & (UA_KNOWN | UA_ZAPPED)))
427 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
428 || ((CC->FloorBeingSearched) < 0)))
429 list_roomname(qrbuf);
432 void cmd_lrms(char *argbuf)
434 CC->FloorBeingSearched = (-1);
435 if (strlen(argbuf) > 0)
436 CC->FloorBeingSearched = extract_int(argbuf, 0);
438 if (!(CC->logged_in)) {
439 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
442 if (getuser(&CC->usersupp, CC->curr_user)) {
443 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
446 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
448 ForEachRoom(cmd_lrms_backend);
455 * cmd_lkra() - List all known rooms
457 void cmd_lkra_backend(struct quickroom *qrbuf)
459 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
461 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
462 || ((CC->FloorBeingSearched) < 0)))
463 list_roomname(qrbuf);
466 void cmd_lkra(char *argbuf)
468 CC->FloorBeingSearched = (-1);
469 if (strlen(argbuf) > 0)
470 CC->FloorBeingSearched = extract_int(argbuf, 0);
472 if (!(CC->logged_in)) {
473 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
476 if (getuser(&CC->usersupp, CC->curr_user)) {
477 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
480 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
482 ForEachRoom(cmd_lkra_backend);
489 * cmd_lkrn() - List all known rooms with new messages
491 void cmd_lkrn_backend(struct quickroom *qrbuf)
495 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
497 && (ra & UA_HASNEWMSGS)
498 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
499 || ((CC->FloorBeingSearched) < 0)))
500 list_roomname(qrbuf);
503 void cmd_lkrn(char *argbuf)
505 CC->FloorBeingSearched = (-1);
506 if (strlen(argbuf) > 0)
507 CC->FloorBeingSearched = extract_int(argbuf, 0);
509 if (!(CC->logged_in)) {
510 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
513 if (getuser(&CC->usersupp, CC->curr_user)) {
514 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
517 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
519 ForEachRoom(cmd_lkrn_backend);
526 * cmd_lkro() - List all known rooms
528 void cmd_lkro_backend(struct quickroom *qrbuf)
532 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
534 && ((ra & UA_HASNEWMSGS) == 0)
535 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
536 || ((CC->FloorBeingSearched) < 0)))
537 list_roomname(qrbuf);
540 void cmd_lkro(char *argbuf)
542 CC->FloorBeingSearched = (-1);
543 if (strlen(argbuf) > 0)
544 CC->FloorBeingSearched = extract_int(argbuf, 0);
546 if (!(CC->logged_in)) {
547 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
550 if (getuser(&CC->usersupp, CC->curr_user)) {
551 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
554 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
556 ForEachRoom(cmd_lkro_backend);
563 * cmd_lzrm() - List all forgotten rooms
565 void cmd_lzrm_backend(struct quickroom *qrbuf)
569 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
570 if ((ra & UA_GOTOALLOWED)
572 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
573 || ((CC->FloorBeingSearched) < 0)))
574 list_roomname(qrbuf);
577 void cmd_lzrm(char *argbuf)
579 CC->FloorBeingSearched = (-1);
580 if (strlen(argbuf) > 0)
581 CC->FloorBeingSearched = extract_int(argbuf, 0);
583 if (!(CC->logged_in)) {
584 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
587 if (getuser(&CC->usersupp, CC->curr_user)) {
588 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
591 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
593 ForEachRoom(cmd_lzrm_backend);
599 void usergoto(char *where, int display_result)
602 int new_messages = 0;
603 int total_messages = 0;
607 int newmailcount = 0;
609 char truncated_roomname[ROOMNAMELEN];
610 struct cdbdata *cdbfr;
611 long *msglist = NULL;
614 strcpy(CC->quickroom.QRname, where);
615 getroom(&CC->quickroom, where);
617 lgetuser(&CC->usersupp, CC->curr_user);
618 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
620 /* Know the room ... but not if it's the page log room */
621 if (strcasecmp(where, config.c_logpages)) {
622 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
623 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
625 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
626 lputuser(&CC->usersupp);
628 /* check for new mail */
629 newmailcount = NewMailCount();
631 /* set info to 1 if the user needs to read the room's info file */
632 if (CC->quickroom.QRinfo > vbuf.v_lastseen)
636 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->quickroom.QRnumber, sizeof(long));
638 msglist = mallok(cdbfr->len);
639 memcpy(msglist, cdbfr->ptr, cdbfr->len);
640 num_msgs = cdbfr->len / sizeof(long);
644 if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
645 if (msglist[a] > 0L) {
647 if (msglist[a] > vbuf.v_lastseen) {
653 if (msglist != NULL) phree(msglist);
655 if (CC->quickroom.QRflags & QR_MAILBOX)
660 if ((CC->quickroom.QRroomaide == CC->usersupp.usernum)
661 || (CC->usersupp.axlevel >= 6))
666 strcpy(truncated_roomname, CC->quickroom.QRname);
667 if (CC->quickroom.QRflags & QR_MAILBOX) {
668 strcpy(truncated_roomname, &truncated_roomname[11]);
672 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
675 new_messages, total_messages,
676 info, CC->quickroom.QRflags,
677 CC->quickroom.QRhighest,
679 rmailflag, raideflag, newmailcount,
680 CC->quickroom.QRfloor);
686 * cmd_goto() - goto a new room
688 void cmd_goto(char *gargs)
690 struct quickroom QRscratch;
694 char augmented_roomname[256];
698 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
699 cprintf("%d not logged in\n", ERROR + NOT_LOGGED_IN);
703 extract(towhere, gargs, 0);
704 extract(password, gargs, 1);
706 getuser(&CC->usersupp, CC->curr_user);
708 if (!strcasecmp(towhere, "_BASEROOM_"))
709 strcpy(towhere, BASEROOM);
711 if (!strcasecmp(towhere, "_MAIL_"))
712 strcpy(towhere, MAILROOM);
714 if (!strcasecmp(towhere, "_BITBUCKET_"))
715 strcpy(towhere, config.c_twitroom);
718 /* First try a regular match */
719 c = getroom(&QRscratch, towhere);
721 /* Then try a mailbox name match */
723 MailboxName(augmented_roomname, &CC->usersupp, towhere);
724 c = getroom(&QRscratch, augmented_roomname);
726 strcpy(towhere, augmented_roomname);
729 /* And if the room was found... */
732 /* let internal programs go directly to any room */
733 if (CC->internal_pgm) {
734 usergoto(towhere, 1);
738 /* See if there is an existing user/room relationship */
739 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
741 /* normal clients have to pass through security */
742 if (ra & UA_GOTOALLOWED)
746 if ((QRscratch.QRflags & QR_PASSWORDED) &&
747 ((ra & UA_KNOWN) == 0) &&
748 (strcasecmp(QRscratch.QRpasswd, password))
750 cprintf("%d wrong or missing passwd\n",
751 ERROR + PASSWORD_REQUIRED);
753 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
754 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
755 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
756 ((ra & UA_KNOWN) == 0)) {
759 usergoto(towhere, 1);
765 NOPE: cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
771 struct usersupp temp;
772 struct cdbdata *cdbus;
774 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
775 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
778 getuser(&CC->usersupp, CC->curr_user);
780 if ((!is_room_aide()) && (!(CC->internal_pgm))) {
781 cprintf("%d Higher access required.\n",
782 ERROR + HIGHER_ACCESS_REQUIRED);
785 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
786 cdb_rewind(CDB_USERSUPP);
787 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
788 memset(&temp, 0, sizeof temp);
789 memcpy(&temp, cdbus->ptr, sizeof temp);
792 if ((CC->quickroom.QRflags & QR_INUSE)
793 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
795 cprintf("%s\n", temp.fullname);
802 * RDIR command for room directory
812 if (!(CC->logged_in)) {
813 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
816 getroom(&CC->quickroom, CC->quickroom.QRname);
817 getuser(&CC->usersupp, CC->curr_user);
819 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
820 cprintf("%d not here.\n", ERROR + NOT_HERE);
823 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
824 && (CC->usersupp.axlevel < 6)
825 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
826 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
829 cprintf("%d %s|%s/files/%s\n",
830 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->quickroom.QRdirname);
832 sprintf(buf, "ls %s/files/%s >%s 2> /dev/null",
833 BBSDIR, CC->quickroom.QRdirname, CC->temp);
836 sprintf(buf, "%s/files/%s/filedir", BBSDIR, CC->quickroom.QRdirname);
837 fd = fopen(buf, "r");
839 fd = fopen("/dev/null", "r");
841 ls = fopen(CC->temp, "r");
842 while (fgets(flnm, 256, ls) != NULL) {
843 flnm[strlen(flnm) - 1] = 0;
844 if (strcasecmp(flnm, "filedir")) {
845 sprintf(buf, "%s/files/%s/%s",
846 BBSDIR, CC->quickroom.QRdirname, flnm);
850 while ((fgets(buf, 256, fd) != NULL)
851 && (strlen(comment) == 0)) {
852 buf[strlen(buf) - 1] = 0;
853 if ((!strncasecmp(buf, flnm, strlen(flnm)))
854 && (buf[strlen(flnm)] == ' '))
856 &buf[strlen(flnm) + 1], 255);
858 cprintf("%s|%ld|%s\n", flnm, statbuf.st_size, comment);
869 * get room parameters (aide or room aide command)
873 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
874 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
877 if ((!is_room_aide()) && (!(CC->internal_pgm))) {
878 cprintf("%d Higher access required.\n",
879 ERROR + HIGHER_ACCESS_REQUIRED);
882 if (is_noneditable(&CC->quickroom)) {
883 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
886 getroom(&CC->quickroom, CC->quickroom.QRname);
887 cprintf("%d%c%s|%s|%s|%d|%d|%d\n",
889 CC->quickroom.QRname,
890 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
891 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
892 CC->quickroom.QRflags,
893 (int) CC->quickroom.QRfloor,
894 (int) CC->quickroom.QRorder);
899 * set room parameters (aide or room aide command)
901 void cmd_setr(char *args)
905 char old_name[ROOMNAMELEN];
909 if (!(CC->logged_in)) {
910 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
913 if (!is_room_aide()) {
914 cprintf("%d Higher access required.\n",
915 ERROR + HIGHER_ACCESS_REQUIRED);
918 if (is_noneditable(&CC->quickroom)) {
919 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
922 if (num_parms(args) >= 6) {
923 getfloor(&flbuf, extract_int(args, 5));
924 if ((flbuf.f_flags & F_INUSE) == 0) {
925 cprintf("%d Invalid floor number.\n",
926 ERROR + INVALID_FLOOR_OPERATION);
930 if (num_parms(args) >= 7) {
931 new_order = extract_int(args, 6);
937 lgetroom(&CC->quickroom, CC->quickroom.QRname);
938 strcpy(old_name, CC->quickroom.QRname);
939 extract(buf, args, 0);
940 buf[ROOMNAMELEN] = 0;
941 strncpy(CC->quickroom.QRname, buf, ROOMNAMELEN - 1);
942 extract(buf, args, 1);
944 strncpy(CC->quickroom.QRpasswd, buf, 9);
945 extract(buf, args, 2);
947 strncpy(CC->quickroom.QRdirname, buf, 19);
948 CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
949 if (num_parms(args) >= 7)
950 CC->quickroom.QRorder = (char) new_order;
952 /* Clean up a client boo-boo: if the client set the room to
953 * guess-name or passworded, ensure that the private flag is
956 if ((CC->quickroom.QRflags & QR_GUESSNAME)
957 || (CC->quickroom.QRflags & QR_PASSWORDED))
958 CC->quickroom.QRflags |= QR_PRIVATE;
960 /* Kick everyone out if the client requested it (by changing the
961 * room's generation number)
963 if (extract_int(args, 4)) {
964 time(&CC->quickroom.QRgen);
966 old_floor = CC->quickroom.QRfloor;
967 if (num_parms(args) >= 6) {
968 CC->quickroom.QRfloor = extract_int(args, 5);
970 /* Write the room record back to disk */
971 lputroom(&CC->quickroom);
973 /* If the room name changed, then there are now two room records,
974 * so we have to delete the old one.
976 if (strcasecmp(CC->quickroom.QRname, old_name)) {
977 b_deleteroom(old_name);
979 /* adjust the floor reference counts */
980 lgetfloor(&flbuf, old_floor);
982 lputfloor(&flbuf, old_floor);
983 lgetfloor(&flbuf, CC->quickroom.QRfloor);
985 lputfloor(&flbuf, CC->quickroom.QRfloor);
987 /* create a room directory if necessary */
988 if (CC->quickroom.QRflags & QR_DIRECTORY) {
990 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
991 CC->quickroom.QRdirname);
994 sprintf(buf, "%s> edited by %s\n", CC->quickroom.QRname, CC->curr_user);
996 cprintf("%d Ok\n", OK);
1002 * get the name of the room aide for this room
1006 struct usersupp usbuf;
1008 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
1009 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1012 if (is_noneditable(&CC->quickroom)) {
1013 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1016 if (getuserbynumber(&usbuf, CC->quickroom.QRroomaide) == 0) {
1017 cprintf("%d %s\n", OK, usbuf.fullname);
1019 cprintf("%d \n", OK);
1025 * set the room aide for this room
1027 void cmd_seta(char *new_ra)
1029 struct usersupp usbuf;
1034 if (!(CC->logged_in)) {
1035 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1038 if (!is_room_aide()) {
1039 cprintf("%d Higher access required.\n",
1040 ERROR + HIGHER_ACCESS_REQUIRED);
1043 if (getuser(&usbuf, new_ra) != 0) {
1046 newu = usbuf.usernum;
1049 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1051 if (CC->quickroom.QRroomaide != newu) {
1054 CC->quickroom.QRroomaide = newu;
1055 lputroom(&CC->quickroom);
1058 * We have to post the change notice _after_ writing changes to
1059 * the room table, otherwise it would deadlock!
1061 if (post_notice == 1) {
1062 sprintf(buf, "%s is now room aide for %s>\n",
1063 usbuf.fullname, CC->quickroom.QRname);
1066 cprintf("%d Ok\n", OK);
1070 * Generate an associated file name for a room
1072 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix)
1074 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1078 * retrieve info file for this room
1086 assoc_file_name(filename, &CC->quickroom, "info");
1087 info_fp = fopen(filename, "r");
1089 if (info_fp == NULL) {
1090 cprintf("%d No info file.\n", ERROR);
1093 cprintf("%d Info:\n", LISTING_FOLLOWS);
1094 while (fgets(buf, 256, info_fp) != NULL) {
1095 if (strlen(buf) > 0)
1096 buf[strlen(buf) - 1] = 0;
1097 cprintf("%s\n", buf);
1104 * Back end processing to delete a room and everything associated with it
1106 void delete_room(struct quickroom *qrbuf)
1111 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1113 /* Delete the info file */
1114 assoc_file_name(filename, qrbuf, "info");
1117 /* Delete the image file */
1118 assoc_file_name(filename, qrbuf, "images");
1121 /* Delete the messages in the room
1122 * (Careful: this opens an S_QUICKROOM critical section!)
1124 CtdlDeleteMessages(qrbuf->QRname, 0L, NULL);
1126 /* Flag the room record as not in use */
1127 lgetroom(qrbuf, qrbuf->QRname);
1131 /* then decrement the reference count for the floor */
1132 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1133 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1134 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1136 /* Delete the room record from the database! */
1137 b_deleteroom(qrbuf->QRname);
1142 * aide command: kill the current room
1144 void cmd_kill(char *argbuf)
1147 char deleted_room_name[ROOMNAMELEN];
1150 kill_ok = extract_int(argbuf, 0);
1152 if (!(CC->logged_in)) {
1153 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1156 if (!is_room_aide()) {
1157 cprintf("%d Higher access required.\n",
1158 ERROR + HIGHER_ACCESS_REQUIRED);
1161 if (is_noneditable(&CC->quickroom)) {
1162 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1166 strcpy(deleted_room_name, CC->quickroom.QRname);
1167 delete_room(&CC->quickroom); /* Do the dirty work */
1168 usergoto(BASEROOM, 0); /* Return to the Lobby */
1170 /* tell the world what we did */
1171 sprintf(aaa, "%s> killed by %s\n",
1172 deleted_room_name, CC->curr_user);
1174 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1176 cprintf("%d ok to delete.\n", OK);
1182 * Internal code to create a new room (returns room flags)
1184 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1186 unsigned create_room(char *new_room_name,
1188 char *new_room_pass,
1192 struct quickroom qrbuf;
1196 if (getroom(&qrbuf, new_room_name) == 0)
1197 return (0); /* already exists */
1199 memset(&qrbuf, 0, sizeof(struct quickroom));
1200 strncpy(qrbuf.QRname, new_room_name, ROOMNAMELEN);
1201 strncpy(qrbuf.QRpasswd, new_room_pass, 9);
1202 qrbuf.QRflags = QR_INUSE;
1203 qrbuf.QRnumber = get_new_room_number();
1204 if (new_room_type > 0)
1205 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1206 if (new_room_type == 1)
1207 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1208 if (new_room_type == 2)
1209 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1210 if (new_room_type == 4)
1211 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1213 /* If the room is private, and the system administrator has elected
1214 * to automatically grant room aide privileges, do so now; otherwise,
1215 * set the room aide to undefined.
1217 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1218 qrbuf.QRroomaide = CC->usersupp.usernum;
1220 qrbuf.QRroomaide = (-1L);
1223 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1224 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1225 qrbuf.QRfloor = new_room_floor;
1227 /* save what we just did... */
1230 /* bump the reference count on whatever floor the room is on */
1231 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1232 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1233 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1235 /* be sure not to kick the creator out of the room! */
1236 lgetuser(&CC->usersupp, CC->curr_user);
1237 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1238 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1239 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1240 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1241 lputuser(&CC->usersupp);
1243 /* resume our happy day */
1244 return (qrbuf.QRflags);
1251 void cmd_cre8(char *args)
1254 char new_room_name[256];
1256 char new_room_pass[256];
1260 struct quickroom qrbuf;
1263 cre8_ok = extract_int(args, 0);
1264 extract(new_room_name, args, 1);
1265 new_room_name[ROOMNAMELEN - 1] = 0;
1266 new_room_type = extract_int(args, 2);
1267 extract(new_room_pass, args, 3);
1268 new_room_pass[9] = 0;
1271 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1272 cprintf("%d Invalid room name.\n", ERROR);
1276 if (!strcasecmp(new_room_name, MAILROOM)) {
1277 cprintf("%d '%s' already exists.\n",
1278 ERROR + ALREADY_EXISTS, new_room_name);
1282 if (num_parms(args) >= 5) {
1283 getfloor(&flbuf, extract_int(args, 4));
1284 if ((flbuf.f_flags & F_INUSE) == 0) {
1285 cprintf("%d Invalid floor number.\n",
1286 ERROR + INVALID_FLOOR_OPERATION);
1289 new_room_floor = extract_int(args, 4);
1293 if (!(CC->logged_in)) {
1294 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1298 if (CC->usersupp.axlevel < config.c_createax) {
1299 cprintf("%d You need higher access to create rooms.\n",
1300 ERROR + HIGHER_ACCESS_REQUIRED);
1304 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1305 cprintf("%d Ok to create rooms.\n", OK);
1309 if ((new_room_type < 0) || (new_room_type > 4)) {
1310 cprintf("%d Invalid room type.\n", ERROR);
1314 /* If the user is requesting a personal room, set up the room
1315 * name accordingly (prepend the user number)
1317 if (new_room_type == 4) {
1318 sprintf(aaa, "%010ld.%s",
1319 CC->usersupp.usernum, new_room_name);
1320 strcpy(new_room_name, aaa);
1323 /* Check to make sure the requested room name doesn't already exist */
1324 if (getroom(&qrbuf, new_room_name) == 0) {
1325 cprintf("%d '%s' already exists.\n",
1326 ERROR + ALREADY_EXISTS, qrbuf.QRname);
1331 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1335 newflags = create_room(new_room_name,
1336 new_room_type, new_room_pass, new_room_floor);
1338 /* post a message in Aide> describing the new room */
1339 strncpy(aaa, new_room_name, 255);
1340 strcat(aaa, "> created by ");
1341 strcat(aaa, CC->usersupp.fullname);
1342 if (newflags & QR_MAILBOX)
1343 strcat(aaa, " [personal]");
1344 else if (newflags & QR_PRIVATE)
1345 strcat(aaa, " [private]");
1346 if (newflags & QR_GUESSNAME)
1347 strcat(aaa, "[guessname] ");
1348 if (newflags & QR_PASSWORDED) {
1349 strcat(aaa, "\n Password: ");
1350 strcat(aaa, new_room_pass);
1355 cprintf("%d '%s' has been created.\n", OK, qrbuf.QRname);
1360 void cmd_einf(char *ok)
1361 { /* enter info file for current room */
1363 char infofilename[256];
1366 if (!(CC->logged_in)) {
1367 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1370 if (!is_room_aide()) {
1371 cprintf("%d Higher access required.\n",
1372 ERROR + HIGHER_ACCESS_REQUIRED);
1375 if (atoi(ok) == 0) {
1376 cprintf("%d Ok.\n", OK);
1379 assoc_file_name(infofilename, &CC->quickroom, "info");
1380 lprintf(9, "opening\n");
1381 fp = fopen(infofilename, "w");
1382 lprintf(9, "checking\n");
1384 cprintf("%d Cannot open %s: %s\n",
1385 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1388 cprintf("%d Send info...\n", SEND_LISTING);
1392 if (strcmp(buf, "000"))
1393 fprintf(fp, "%s\n", buf);
1394 } while (strcmp(buf, "000"));
1397 /* now update the room index so people will see our new info */
1398 lgetroom(&CC->quickroom, CC->quickroom.QRname); /* lock so no one steps on us */
1399 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1400 lputroom(&CC->quickroom);
1405 * cmd_lflr() - List all known floors
1412 if (!(CC->logged_in)) {
1413 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1416 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1417 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1422 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1424 for (a = 0; a < MAXFLOORS; ++a) {
1425 getfloor(&flbuf, a);
1426 if (flbuf.f_flags & F_INUSE) {
1427 cprintf("%d|%s|%d\n",
1439 * create a new floor
1441 void cmd_cflr(char *argbuf)
1443 char new_floor_name[256];
1446 int free_slot = (-1);
1449 extract(new_floor_name, argbuf, 0);
1450 cflr_ok = extract_int(argbuf, 1);
1453 if (!(CC->logged_in)) {
1454 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1457 if (CC->usersupp.axlevel < 6) {
1458 cprintf("%d You need higher access to create rooms.\n",
1459 ERROR + HIGHER_ACCESS_REQUIRED);
1462 for (a = 0; a < MAXFLOORS; ++a) {
1463 getfloor(&flbuf, a);
1465 /* note any free slots while we're scanning... */
1466 if (((flbuf.f_flags & F_INUSE) == 0)
1470 /* check to see if it already exists */
1471 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1472 && (flbuf.f_flags & F_INUSE)) {
1473 cprintf("%d Floor '%s' already exists.\n",
1474 ERROR + ALREADY_EXISTS,
1480 if (free_slot < 0) {
1481 cprintf("%d There is no space available for a new floor.\n",
1482 ERROR + INVALID_FLOOR_OPERATION);
1486 cprintf("%d ok to create...\n", OK);
1489 lgetfloor(&flbuf, free_slot);
1490 flbuf.f_flags = F_INUSE;
1491 flbuf.f_ref_count = 0;
1492 strncpy(flbuf.f_name, new_floor_name, 255);
1493 lputfloor(&flbuf, free_slot);
1494 cprintf("%d %d\n", OK, free_slot);
1502 void cmd_kflr(char *argbuf)
1505 int floor_to_delete;
1509 floor_to_delete = extract_int(argbuf, 0);
1510 kflr_ok = extract_int(argbuf, 1);
1513 if (!(CC->logged_in)) {
1514 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1517 if (CC->usersupp.axlevel < 6) {
1518 cprintf("%d You need higher access to delete floors.\n",
1519 ERROR + HIGHER_ACCESS_REQUIRED);
1522 lgetfloor(&flbuf, floor_to_delete);
1525 if ((flbuf.f_flags & F_INUSE) == 0) {
1526 cprintf("%d Floor %d not in use.\n",
1527 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1530 if (flbuf.f_ref_count != 0) {
1531 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1532 ERROR + INVALID_FLOOR_OPERATION,
1537 cprintf("%d Ok\n", OK);
1539 cprintf("%d Ok to delete...\n", OK);
1546 if ((delete_ok == 1) && (kflr_ok == 1))
1548 lputfloor(&flbuf, floor_to_delete);
1554 void cmd_eflr(char *argbuf)
1560 np = num_parms(argbuf);
1562 cprintf("%d Usage error.\n", ERROR);
1565 if (!(CC->logged_in)) {
1566 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1569 if (CC->usersupp.axlevel < 6) {
1570 cprintf("%d You need higher access to edit floors.\n",
1571 ERROR + HIGHER_ACCESS_REQUIRED);
1574 floor_num = extract_int(argbuf, 0);
1575 lgetfloor(&flbuf, floor_num);
1576 if ((flbuf.f_flags & F_INUSE) == 0) {
1577 lputfloor(&flbuf, floor_num);
1578 cprintf("%d Floor %d is not in use.\n",
1579 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1583 extract(flbuf.f_name, argbuf, 1);
1584 lputfloor(&flbuf, floor_num);
1586 cprintf("%d Ok\n", OK);