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);
682 set_wtmpsupp_to_current_room();
687 * cmd_goto() - goto a new room
689 void cmd_goto(char *gargs)
691 struct quickroom QRscratch;
695 char augmented_roomname[256];
699 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
700 cprintf("%d not logged in\n", ERROR + NOT_LOGGED_IN);
704 extract(towhere, gargs, 0);
705 extract(password, gargs, 1);
707 getuser(&CC->usersupp, CC->curr_user);
709 if (!strcasecmp(towhere, "_BASEROOM_"))
710 strcpy(towhere, BASEROOM);
712 if (!strcasecmp(towhere, "_MAIL_"))
713 strcpy(towhere, MAILROOM);
715 if (!strcasecmp(towhere, "_BITBUCKET_"))
716 strcpy(towhere, config.c_twitroom);
719 /* First try a regular match */
720 c = getroom(&QRscratch, towhere);
722 /* Then try a mailbox name match */
724 MailboxName(augmented_roomname, &CC->usersupp, towhere);
725 c = getroom(&QRscratch, augmented_roomname);
727 strcpy(towhere, augmented_roomname);
730 /* And if the room was found... */
733 /* let internal programs go directly to any room */
734 if (CC->internal_pgm) {
735 usergoto(towhere, 1);
739 /* See if there is an existing user/room relationship */
740 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
742 /* normal clients have to pass through security */
743 if (ra & UA_GOTOALLOWED)
747 if ((QRscratch.QRflags & QR_PASSWORDED) &&
748 ((ra & UA_KNOWN) == 0) &&
749 (strcasecmp(QRscratch.QRpasswd, password))
751 cprintf("%d wrong or missing passwd\n",
752 ERROR + PASSWORD_REQUIRED);
754 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
755 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
756 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
757 ((ra & UA_KNOWN) == 0)) {
760 usergoto(towhere, 1);
766 NOPE: cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
772 struct usersupp temp;
773 struct cdbdata *cdbus;
775 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
776 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
779 getuser(&CC->usersupp, CC->curr_user);
781 if ((!is_room_aide()) && (!(CC->internal_pgm))) {
782 cprintf("%d Higher access required.\n",
783 ERROR + HIGHER_ACCESS_REQUIRED);
786 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
787 cdb_rewind(CDB_USERSUPP);
788 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
789 memset(&temp, 0, sizeof temp);
790 memcpy(&temp, cdbus->ptr, sizeof temp);
793 if ((CC->quickroom.QRflags & QR_INUSE)
794 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
796 cprintf("%s\n", temp.fullname);
803 * RDIR command for room directory
813 if (!(CC->logged_in)) {
814 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
817 getroom(&CC->quickroom, CC->quickroom.QRname);
818 getuser(&CC->usersupp, CC->curr_user);
820 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
821 cprintf("%d not here.\n", ERROR + NOT_HERE);
824 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
825 && (CC->usersupp.axlevel < 6)
826 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
827 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
830 cprintf("%d %s|%s/files/%s\n",
831 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->quickroom.QRdirname);
833 sprintf(buf, "ls %s/files/%s >%s 2> /dev/null",
834 BBSDIR, CC->quickroom.QRdirname, CC->temp);
837 sprintf(buf, "%s/files/%s/filedir", BBSDIR, CC->quickroom.QRdirname);
838 fd = fopen(buf, "r");
840 fd = fopen("/dev/null", "r");
842 ls = fopen(CC->temp, "r");
843 while (fgets(flnm, 256, ls) != NULL) {
844 flnm[strlen(flnm) - 1] = 0;
845 if (strcasecmp(flnm, "filedir")) {
846 sprintf(buf, "%s/files/%s/%s",
847 BBSDIR, CC->quickroom.QRdirname, flnm);
851 while ((fgets(buf, 256, fd) != NULL)
852 && (strlen(comment) == 0)) {
853 buf[strlen(buf) - 1] = 0;
854 if ((!strncasecmp(buf, flnm, strlen(flnm)))
855 && (buf[strlen(flnm)] == ' '))
857 &buf[strlen(flnm) + 1], 255);
859 cprintf("%s|%ld|%s\n", flnm, statbuf.st_size, comment);
870 * get room parameters (aide or room aide command)
874 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
875 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
878 if ((!is_room_aide()) && (!(CC->internal_pgm))) {
879 cprintf("%d Higher access required.\n",
880 ERROR + HIGHER_ACCESS_REQUIRED);
883 if (is_noneditable(&CC->quickroom)) {
884 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
887 getroom(&CC->quickroom, CC->quickroom.QRname);
888 cprintf("%d%c%s|%s|%s|%d|%d|%d\n",
890 CC->quickroom.QRname,
891 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
892 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
893 CC->quickroom.QRflags,
894 (int) CC->quickroom.QRfloor,
895 (int) CC->quickroom.QRorder);
900 * set room parameters (aide or room aide command)
902 void cmd_setr(char *args)
906 char old_name[ROOMNAMELEN];
910 if (!(CC->logged_in)) {
911 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
914 if (!is_room_aide()) {
915 cprintf("%d Higher access required.\n",
916 ERROR + HIGHER_ACCESS_REQUIRED);
919 if (is_noneditable(&CC->quickroom)) {
920 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
923 if (num_parms(args) >= 6) {
924 getfloor(&flbuf, extract_int(args, 5));
925 if ((flbuf.f_flags & F_INUSE) == 0) {
926 cprintf("%d Invalid floor number.\n",
927 ERROR + INVALID_FLOOR_OPERATION);
931 if (num_parms(args) >= 7) {
932 new_order = extract_int(args, 6);
938 lgetroom(&CC->quickroom, CC->quickroom.QRname);
939 strcpy(old_name, CC->quickroom.QRname);
940 extract(buf, args, 0);
941 buf[ROOMNAMELEN] = 0;
942 strncpy(CC->quickroom.QRname, buf, ROOMNAMELEN - 1);
943 extract(buf, args, 1);
945 strncpy(CC->quickroom.QRpasswd, buf, 9);
946 extract(buf, args, 2);
948 strncpy(CC->quickroom.QRdirname, buf, 19);
949 CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
950 if (num_parms(args) >= 7)
951 CC->quickroom.QRorder = (char) new_order;
953 /* Clean up a client boo-boo: if the client set the room to
954 * guess-name or passworded, ensure that the private flag is
957 if ((CC->quickroom.QRflags & QR_GUESSNAME)
958 || (CC->quickroom.QRflags & QR_PASSWORDED))
959 CC->quickroom.QRflags |= QR_PRIVATE;
961 /* Kick everyone out if the client requested it (by changing the
962 * room's generation number)
964 if (extract_int(args, 4)) {
965 time(&CC->quickroom.QRgen);
967 old_floor = CC->quickroom.QRfloor;
968 if (num_parms(args) >= 6) {
969 CC->quickroom.QRfloor = extract_int(args, 5);
971 /* Write the room record back to disk */
972 lputroom(&CC->quickroom);
974 /* If the room name changed, then there are now two room records,
975 * so we have to delete the old one.
977 if (strcasecmp(CC->quickroom.QRname, old_name)) {
978 b_deleteroom(old_name);
980 /* adjust the floor reference counts */
981 lgetfloor(&flbuf, old_floor);
983 lputfloor(&flbuf, old_floor);
984 lgetfloor(&flbuf, CC->quickroom.QRfloor);
986 lputfloor(&flbuf, CC->quickroom.QRfloor);
988 /* create a room directory if necessary */
989 if (CC->quickroom.QRflags & QR_DIRECTORY) {
991 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
992 CC->quickroom.QRdirname);
995 sprintf(buf, "%s> edited by %s\n", CC->quickroom.QRname, CC->curr_user);
997 cprintf("%d Ok\n", OK);
1003 * get the name of the room aide for this room
1007 struct usersupp usbuf;
1009 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
1010 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1013 if (is_noneditable(&CC->quickroom)) {
1014 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1017 if (getuserbynumber(&usbuf, CC->quickroom.QRroomaide) == 0) {
1018 cprintf("%d %s\n", OK, usbuf.fullname);
1020 cprintf("%d \n", OK);
1026 * set the room aide for this room
1028 void cmd_seta(char *new_ra)
1030 struct usersupp usbuf;
1035 if (!(CC->logged_in)) {
1036 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1039 if (!is_room_aide()) {
1040 cprintf("%d Higher access required.\n",
1041 ERROR + HIGHER_ACCESS_REQUIRED);
1044 if (getuser(&usbuf, new_ra) != 0) {
1047 newu = usbuf.usernum;
1050 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1052 if (CC->quickroom.QRroomaide != newu) {
1055 CC->quickroom.QRroomaide = newu;
1056 lputroom(&CC->quickroom);
1059 * We have to post the change notice _after_ writing changes to
1060 * the room table, otherwise it would deadlock!
1062 if (post_notice == 1) {
1063 sprintf(buf, "%s is now room aide for %s>\n",
1064 usbuf.fullname, CC->quickroom.QRname);
1067 cprintf("%d Ok\n", OK);
1071 * Generate an associated file name for a room
1073 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix)
1075 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1079 * retrieve info file for this room
1087 assoc_file_name(filename, &CC->quickroom, "info");
1088 info_fp = fopen(filename, "r");
1090 if (info_fp == NULL) {
1091 cprintf("%d No info file.\n", ERROR);
1094 cprintf("%d Info:\n", LISTING_FOLLOWS);
1095 while (fgets(buf, 256, info_fp) != NULL) {
1096 if (strlen(buf) > 0)
1097 buf[strlen(buf) - 1] = 0;
1098 cprintf("%s\n", buf);
1105 * Back end processing to delete a room and everything associated with it
1107 void delete_room(struct quickroom *qrbuf)
1112 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1114 /* Delete the info file */
1115 assoc_file_name(filename, qrbuf, "info");
1118 /* Delete the image file */
1119 assoc_file_name(filename, qrbuf, "images");
1122 /* Delete the messages in the room
1123 * (Careful: this opens an S_QUICKROOM critical section!)
1125 CtdlDeleteMessages(qrbuf->QRname, 0L, NULL);
1127 /* Flag the room record as not in use */
1128 lgetroom(qrbuf, qrbuf->QRname);
1132 /* then decrement the reference count for the floor */
1133 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1134 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1135 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1137 /* Delete the room record from the database! */
1138 b_deleteroom(qrbuf->QRname);
1143 * aide command: kill the current room
1145 void cmd_kill(char *argbuf)
1148 char deleted_room_name[ROOMNAMELEN];
1151 kill_ok = extract_int(argbuf, 0);
1153 if (!(CC->logged_in)) {
1154 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1157 if (!is_room_aide()) {
1158 cprintf("%d Higher access required.\n",
1159 ERROR + HIGHER_ACCESS_REQUIRED);
1162 if (is_noneditable(&CC->quickroom)) {
1163 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1167 strcpy(deleted_room_name, CC->quickroom.QRname);
1168 delete_room(&CC->quickroom); /* Do the dirty work */
1169 usergoto(BASEROOM, 0); /* Return to the Lobby */
1171 /* tell the world what we did */
1172 sprintf(aaa, "%s> killed by %s\n",
1173 deleted_room_name, CC->curr_user);
1175 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1177 cprintf("%d ok to delete.\n", OK);
1183 * Internal code to create a new room (returns room flags)
1185 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1187 unsigned create_room(char *new_room_name,
1189 char *new_room_pass,
1193 struct quickroom qrbuf;
1197 if (getroom(&qrbuf, new_room_name) == 0)
1198 return (0); /* already exists */
1200 memset(&qrbuf, 0, sizeof(struct quickroom));
1201 strncpy(qrbuf.QRname, new_room_name, ROOMNAMELEN);
1202 strncpy(qrbuf.QRpasswd, new_room_pass, 9);
1203 qrbuf.QRflags = QR_INUSE;
1204 qrbuf.QRnumber = get_new_room_number();
1205 if (new_room_type > 0)
1206 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1207 if (new_room_type == 1)
1208 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1209 if (new_room_type == 2)
1210 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1211 if (new_room_type == 4)
1212 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1214 /* If the room is private, and the system administrator has elected
1215 * to automatically grant room aide privileges, do so now; otherwise,
1216 * set the room aide to undefined.
1218 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1219 qrbuf.QRroomaide = CC->usersupp.usernum;
1221 qrbuf.QRroomaide = (-1L);
1224 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1225 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1226 qrbuf.QRfloor = new_room_floor;
1228 /* save what we just did... */
1231 /* bump the reference count on whatever floor the room is on */
1232 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1233 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1234 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1236 /* be sure not to kick the creator out of the room! */
1237 lgetuser(&CC->usersupp, CC->curr_user);
1238 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1239 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1240 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1241 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1242 lputuser(&CC->usersupp);
1244 /* resume our happy day */
1245 return (qrbuf.QRflags);
1252 void cmd_cre8(char *args)
1255 char new_room_name[256];
1257 char new_room_pass[256];
1261 struct quickroom qrbuf;
1264 cre8_ok = extract_int(args, 0);
1265 extract(new_room_name, args, 1);
1266 new_room_name[ROOMNAMELEN - 1] = 0;
1267 new_room_type = extract_int(args, 2);
1268 extract(new_room_pass, args, 3);
1269 new_room_pass[9] = 0;
1272 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1273 cprintf("%d Invalid room name.\n", ERROR);
1277 if (!strcasecmp(new_room_name, MAILROOM)) {
1278 cprintf("%d '%s' already exists.\n",
1279 ERROR + ALREADY_EXISTS, new_room_name);
1283 if (num_parms(args) >= 5) {
1284 getfloor(&flbuf, extract_int(args, 4));
1285 if ((flbuf.f_flags & F_INUSE) == 0) {
1286 cprintf("%d Invalid floor number.\n",
1287 ERROR + INVALID_FLOOR_OPERATION);
1290 new_room_floor = extract_int(args, 4);
1294 if (!(CC->logged_in)) {
1295 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1299 if (CC->usersupp.axlevel < config.c_createax) {
1300 cprintf("%d You need higher access to create rooms.\n",
1301 ERROR + HIGHER_ACCESS_REQUIRED);
1305 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1306 cprintf("%d Ok to create rooms.\n", OK);
1310 if ((new_room_type < 0) || (new_room_type > 4)) {
1311 cprintf("%d Invalid room type.\n", ERROR);
1315 /* If the user is requesting a personal room, set up the room
1316 * name accordingly (prepend the user number)
1318 if (new_room_type == 4) {
1319 sprintf(aaa, "%010ld.%s",
1320 CC->usersupp.usernum, new_room_name);
1321 strcpy(new_room_name, aaa);
1324 /* Check to make sure the requested room name doesn't already exist */
1325 if (getroom(&qrbuf, new_room_name) == 0) {
1326 cprintf("%d '%s' already exists.\n",
1327 ERROR + ALREADY_EXISTS, qrbuf.QRname);
1332 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1336 newflags = create_room(new_room_name,
1337 new_room_type, new_room_pass, new_room_floor);
1339 /* post a message in Aide> describing the new room */
1340 strncpy(aaa, new_room_name, 255);
1341 strcat(aaa, "> created by ");
1342 strcat(aaa, CC->usersupp.fullname);
1343 if (newflags & QR_MAILBOX)
1344 strcat(aaa, " [personal]");
1345 else if (newflags & QR_PRIVATE)
1346 strcat(aaa, " [private]");
1347 if (newflags & QR_GUESSNAME)
1348 strcat(aaa, "[guessname] ");
1349 if (newflags & QR_PASSWORDED) {
1350 strcat(aaa, "\n Password: ");
1351 strcat(aaa, new_room_pass);
1356 cprintf("%d '%s' has been created.\n", OK, qrbuf.QRname);
1361 void cmd_einf(char *ok)
1362 { /* enter info file for current room */
1364 char infofilename[256];
1367 if (!(CC->logged_in)) {
1368 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1371 if (!is_room_aide()) {
1372 cprintf("%d Higher access required.\n",
1373 ERROR + HIGHER_ACCESS_REQUIRED);
1376 if (atoi(ok) == 0) {
1377 cprintf("%d Ok.\n", OK);
1380 assoc_file_name(infofilename, &CC->quickroom, "info");
1381 lprintf(9, "opening\n");
1382 fp = fopen(infofilename, "w");
1383 lprintf(9, "checking\n");
1385 cprintf("%d Cannot open %s: %s\n",
1386 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1389 cprintf("%d Send info...\n", SEND_LISTING);
1393 if (strcmp(buf, "000"))
1394 fprintf(fp, "%s\n", buf);
1395 } while (strcmp(buf, "000"));
1398 /* now update the room index so people will see our new info */
1399 lgetroom(&CC->quickroom, CC->quickroom.QRname); /* lock so no one steps on us */
1400 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1401 lputroom(&CC->quickroom);
1406 * cmd_lflr() - List all known floors
1413 if (!(CC->logged_in)) {
1414 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1417 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1418 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1423 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1425 for (a = 0; a < MAXFLOORS; ++a) {
1426 getfloor(&flbuf, a);
1427 if (flbuf.f_flags & F_INUSE) {
1428 cprintf("%d|%s|%d\n",
1440 * create a new floor
1442 void cmd_cflr(char *argbuf)
1444 char new_floor_name[256];
1447 int free_slot = (-1);
1450 extract(new_floor_name, argbuf, 0);
1451 cflr_ok = extract_int(argbuf, 1);
1454 if (!(CC->logged_in)) {
1455 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1458 if (CC->usersupp.axlevel < 6) {
1459 cprintf("%d You need higher access to create rooms.\n",
1460 ERROR + HIGHER_ACCESS_REQUIRED);
1463 for (a = 0; a < MAXFLOORS; ++a) {
1464 getfloor(&flbuf, a);
1466 /* note any free slots while we're scanning... */
1467 if (((flbuf.f_flags & F_INUSE) == 0)
1471 /* check to see if it already exists */
1472 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1473 && (flbuf.f_flags & F_INUSE)) {
1474 cprintf("%d Floor '%s' already exists.\n",
1475 ERROR + ALREADY_EXISTS,
1481 if (free_slot < 0) {
1482 cprintf("%d There is no space available for a new floor.\n",
1483 ERROR + INVALID_FLOOR_OPERATION);
1487 cprintf("%d ok to create...\n", OK);
1490 lgetfloor(&flbuf, free_slot);
1491 flbuf.f_flags = F_INUSE;
1492 flbuf.f_ref_count = 0;
1493 strncpy(flbuf.f_name, new_floor_name, 255);
1494 lputfloor(&flbuf, free_slot);
1495 cprintf("%d %d\n", OK, free_slot);
1503 void cmd_kflr(char *argbuf)
1506 int floor_to_delete;
1510 floor_to_delete = extract_int(argbuf, 0);
1511 kflr_ok = extract_int(argbuf, 1);
1514 if (!(CC->logged_in)) {
1515 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1518 if (CC->usersupp.axlevel < 6) {
1519 cprintf("%d You need higher access to delete floors.\n",
1520 ERROR + HIGHER_ACCESS_REQUIRED);
1523 lgetfloor(&flbuf, floor_to_delete);
1526 if ((flbuf.f_flags & F_INUSE) == 0) {
1527 cprintf("%d Floor %d not in use.\n",
1528 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1531 if (flbuf.f_ref_count != 0) {
1532 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1533 ERROR + INVALID_FLOOR_OPERATION,
1538 cprintf("%d Ok\n", OK);
1540 cprintf("%d Ok to delete...\n", OK);
1547 if ((delete_ok == 1) && (kflr_ok == 1))
1549 lputfloor(&flbuf, floor_to_delete);
1555 void cmd_eflr(char *argbuf)
1561 np = num_parms(argbuf);
1563 cprintf("%d Usage error.\n", ERROR);
1566 if (!(CC->logged_in)) {
1567 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1570 if (CC->usersupp.axlevel < 6) {
1571 cprintf("%d You need higher access to edit floors.\n",
1572 ERROR + HIGHER_ACCESS_REQUIRED);
1575 floor_num = extract_int(argbuf, 0);
1576 lgetfloor(&flbuf, floor_num);
1577 if ((flbuf.f_flags & F_INUSE) == 0) {
1578 lputfloor(&flbuf, floor_num);
1579 cprintf("%d Floor %d is not in use.\n",
1580 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1584 extract(flbuf.f_name, argbuf, 1);
1585 lputfloor(&flbuf, floor_num);
1587 cprintf("%d Ok\n", OK);