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)
174 begin_critical_section(S_QUICKROOM);
175 return (getroom(qrbuf, room_name));
180 * b_putroom() - back end to putroom() and b_deleteroom()
181 * (if the supplied buffer is NULL, delete the room record)
183 void b_putroom(struct quickroom *qrbuf, char *room_name)
185 char lowercase_name[ROOMNAMELEN];
188 for (a = 0; a <= strlen(room_name); ++a) {
189 lowercase_name[a] = tolower(room_name[a]);
193 cdb_delete(CDB_QUICKROOM,
194 lowercase_name, strlen(lowercase_name));
196 time(&qrbuf->QRmtime);
197 cdb_store(CDB_QUICKROOM,
198 lowercase_name, strlen(lowercase_name),
199 qrbuf, sizeof(struct quickroom));
205 * putroom() - store room data to disk
207 void putroom(struct quickroom *qrbuf) {
208 b_putroom(qrbuf, qrbuf->QRname);
213 * b_deleteroom() - delete a room record from disk
215 void b_deleteroom(char *room_name) {
216 b_putroom(NULL, room_name);
222 * lputroom() - same as putroom() but unlocks the record (if supported)
224 void lputroom(struct quickroom *qrbuf)
228 end_critical_section(S_QUICKROOM);
232 /****************************************************************************/
235 * getfloor() - retrieve floor data from disk
237 void getfloor(struct floor *flbuf, int floor_num)
239 struct cdbdata *cdbfl;
241 memset(flbuf, 0, sizeof(struct floor));
242 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
244 memcpy(flbuf, cdbfl->ptr,
245 ((cdbfl->len > sizeof(struct floor)) ?
246 sizeof(struct floor) : cdbfl->len));
249 if (floor_num == 0) {
250 strcpy(flbuf->f_name, "Main Floor");
251 flbuf->f_flags = F_INUSE;
252 flbuf->f_ref_count = 3;
259 * lgetfloor() - same as getfloor() but locks the record (if supported)
261 void lgetfloor(struct floor *flbuf, int floor_num)
264 begin_critical_section(S_FLOORTAB);
265 getfloor(flbuf, floor_num);
270 * putfloor() - store floor data on disk
272 void putfloor(struct floor *flbuf, int floor_num)
274 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
275 flbuf, sizeof(struct floor));
280 * lputfloor() - same as putfloor() but unlocks the record (if supported)
282 void lputfloor(struct floor *flbuf, int floor_num)
285 putfloor(flbuf, floor_num);
286 end_critical_section(S_FLOORTAB);
292 * Traverse the room file...
294 void ForEachRoom(void (*CallBack) (struct quickroom *EachRoom, void *out_data),
297 struct quickroom qrbuf;
298 struct cdbdata *cdbqr;
300 cdb_rewind(CDB_QUICKROOM);
302 while (cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
303 memset(&qrbuf, 0, sizeof(struct quickroom));
304 memcpy(&qrbuf, cdbqr->ptr,
305 ((cdbqr->len > sizeof(struct quickroom)) ?
306 sizeof(struct quickroom) : cdbqr->len));
308 room_sanity_check(&qrbuf);
309 if (qrbuf.QRflags & QR_INUSE)
310 (*CallBack)(&qrbuf, in_data);
316 * delete_msglist() - delete room message pointers
317 * FIX - this really should check first to make sure there's actually a
318 * msglist to delete. As things stand now, calling this function on
319 * a room which has never been posted in will result in a message
320 * like "gdbm: illegal data" (no big deal, but could use fixing).
322 void delete_msglist(struct quickroom *whichroom)
325 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
332 * sort message pointers
333 * (returns new msg count)
335 int sort_msglist(long listptrs[], int oldcount)
346 for (a = numitems - 2; a >= 0; --a) {
347 for (b = 0; b <= a; ++b) {
348 if (listptrs[b] > (listptrs[b + 1])) {
350 hold2 = listptrs[b + 1];
352 listptrs[b + 1] = hold1;
357 /* and yank any nulls */
358 while ((numitems > 0) && (listptrs[0] == 0L)) {
359 memcpy(&listptrs[0], &listptrs[1],
360 (sizeof(long) * (numitems - 1)));
369 * Determine whether a given room is non-editable.
371 int is_noneditable(struct quickroom *qrbuf)
374 /* Lobby> and Aide> are non-editable */
375 if (!strcasecmp(qrbuf->QRname, BASEROOM))
377 else if (!strcasecmp(qrbuf->QRname, AIDEROOM))
380 /* Mail> rooms are also non-editable */
381 else if ( (qrbuf->QRflags & QR_MAILBOX)
382 && (!strcasecmp(&qrbuf->QRname[11], MAILROOM)) )
385 /* Everything else is editable */
393 * Back-back-end for all room listing commands
395 void list_roomname(struct quickroom *qrbuf)
397 char truncated_roomname[ROOMNAMELEN];
399 /* For mailbox rooms, chop off the owner prefix */
400 if (qrbuf->QRflags & QR_MAILBOX) {
401 strcpy(truncated_roomname, qrbuf->QRname);
402 strcpy(truncated_roomname, &truncated_roomname[11]);
403 cprintf("%s", truncated_roomname);
405 /* For all other rooms, just display the name in its entirety */
407 cprintf("%s", qrbuf->QRname);
410 /* ...and now the other parameters */
411 cprintf("|%u|%d|%d\n",
413 (int) qrbuf->QRfloor,
414 (int) qrbuf->QRorder);
419 * cmd_lrms() - List all accessible rooms, known or forgotten
421 void cmd_lrms_backend(struct quickroom *qrbuf, void *data)
423 int FloorBeingSearched = (-1);
424 FloorBeingSearched = *(int *)data;
426 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
427 & (UA_KNOWN | UA_ZAPPED)))
428 && ((qrbuf->QRfloor == (FloorBeingSearched))
429 || ((FloorBeingSearched) < 0)))
430 list_roomname(qrbuf);
433 void cmd_lrms(char *argbuf)
435 int FloorBeingSearched = (-1);
436 if (strlen(argbuf) > 0)
437 FloorBeingSearched = extract_int(argbuf, 0);
439 if (!(CC->logged_in)) {
440 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
443 if (getuser(&CC->usersupp, CC->curr_user)) {
444 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
447 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
449 ForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
456 * cmd_lkra() - List all known rooms
458 void cmd_lkra_backend(struct quickroom *qrbuf, void *data)
460 int FloorBeingSearched = (-1);
461 FloorBeingSearched = *(int *)data;
463 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
465 && ((qrbuf->QRfloor == (FloorBeingSearched))
466 || ((FloorBeingSearched) < 0)))
467 list_roomname(qrbuf);
470 void cmd_lkra(char *argbuf)
472 int FloorBeingSearched = (-1);
473 if (strlen(argbuf) > 0)
474 FloorBeingSearched = extract_int(argbuf, 0);
476 if (!(CC->logged_in)) {
477 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
480 if (getuser(&CC->usersupp, CC->curr_user)) {
481 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
484 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
486 ForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
493 * cmd_lkrn() - List all known rooms with new messages
495 void cmd_lkrn_backend(struct quickroom *qrbuf, void *data)
498 int FloorBeingSearched = (-1);
499 FloorBeingSearched = *(int *)data;
501 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
503 && (ra & UA_HASNEWMSGS)
504 && ((qrbuf->QRfloor == (FloorBeingSearched))
505 || ((FloorBeingSearched) < 0)))
506 list_roomname(qrbuf);
509 void cmd_lkrn(char *argbuf)
511 int FloorBeingSearched = (-1);
512 if (strlen(argbuf) > 0)
513 FloorBeingSearched = extract_int(argbuf, 0);
515 if (!(CC->logged_in)) {
516 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
519 if (getuser(&CC->usersupp, CC->curr_user)) {
520 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
523 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
525 ForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
532 * cmd_lkro() - List all known rooms
534 void cmd_lkro_backend(struct quickroom *qrbuf, void *data)
537 int FloorBeingSearched = (-1);
538 FloorBeingSearched = *(int *)data;
540 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
542 && ((ra & UA_HASNEWMSGS) == 0)
543 && ((qrbuf->QRfloor == (FloorBeingSearched))
544 || ((FloorBeingSearched) < 0)))
545 list_roomname(qrbuf);
548 void cmd_lkro(char *argbuf)
550 int FloorBeingSearched = (-1);
551 if (strlen(argbuf) > 0)
552 FloorBeingSearched = extract_int(argbuf, 0);
554 if (!(CC->logged_in)) {
555 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
558 if (getuser(&CC->usersupp, CC->curr_user)) {
559 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
562 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
564 ForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
571 * cmd_lzrm() - List all forgotten rooms
573 void cmd_lzrm_backend(struct quickroom *qrbuf, void *data)
576 int FloorBeingSearched = (-1);
577 FloorBeingSearched = *(int *)data;
579 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
580 if ((ra & UA_GOTOALLOWED)
582 && ((qrbuf->QRfloor == (FloorBeingSearched))
583 || ((FloorBeingSearched) < 0)))
584 list_roomname(qrbuf);
587 void cmd_lzrm(char *argbuf)
589 int FloorBeingSearched = (-1);
590 if (strlen(argbuf) > 0)
591 FloorBeingSearched = extract_int(argbuf, 0);
593 if (!(CC->logged_in)) {
594 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
597 if (getuser(&CC->usersupp, CC->curr_user)) {
598 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
601 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
603 ForEachRoom(cmd_lzrm_backend, &FloorBeingSearched);
609 void usergoto(char *where, int display_result)
612 int new_messages = 0;
613 int total_messages = 0;
617 int newmailcount = 0;
619 char truncated_roomname[ROOMNAMELEN];
620 struct cdbdata *cdbfr;
621 long *msglist = NULL;
624 strcpy(CC->quickroom.QRname, where);
625 getroom(&CC->quickroom, where);
627 lgetuser(&CC->usersupp, CC->curr_user);
628 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
630 /* Know the room ... but not if it's the page log room */
631 if (strcasecmp(where, config.c_logpages)) {
632 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
633 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
635 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
636 lputuser(&CC->usersupp);
638 /* check for new mail */
639 newmailcount = NewMailCount();
641 /* set info to 1 if the user needs to read the room's info file */
642 if (CC->quickroom.QRinfo > vbuf.v_lastseen)
646 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->quickroom.QRnumber, sizeof(long));
648 msglist = mallok(cdbfr->len);
649 memcpy(msglist, cdbfr->ptr, cdbfr->len);
650 num_msgs = cdbfr->len / sizeof(long);
654 if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
655 if (msglist[a] > 0L) {
657 if (msglist[a] > vbuf.v_lastseen) {
663 if (msglist != NULL) phree(msglist);
665 if (CC->quickroom.QRflags & QR_MAILBOX)
670 if ((CC->quickroom.QRroomaide == CC->usersupp.usernum)
671 || (CC->usersupp.axlevel >= 6))
676 strcpy(truncated_roomname, CC->quickroom.QRname);
677 if (CC->quickroom.QRflags & QR_MAILBOX) {
678 strcpy(truncated_roomname, &truncated_roomname[11]);
682 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
685 new_messages, total_messages,
686 info, CC->quickroom.QRflags,
687 CC->quickroom.QRhighest,
689 rmailflag, raideflag, newmailcount,
690 CC->quickroom.QRfloor);
696 * cmd_goto() - goto a new room
698 void cmd_goto(char *gargs)
700 struct quickroom QRscratch;
704 char augmented_roomname[256];
708 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
709 cprintf("%d not logged in\n", ERROR + NOT_LOGGED_IN);
713 extract(towhere, gargs, 0);
714 extract(password, gargs, 1);
716 getuser(&CC->usersupp, CC->curr_user);
718 if (!strcasecmp(towhere, "_BASEROOM_"))
719 strcpy(towhere, BASEROOM);
721 if (!strcasecmp(towhere, "_MAIL_"))
722 strcpy(towhere, MAILROOM);
724 if (!strcasecmp(towhere, "_BITBUCKET_"))
725 strcpy(towhere, config.c_twitroom);
728 /* First try a regular match */
729 c = getroom(&QRscratch, towhere);
731 /* Then try a mailbox name match */
733 MailboxName(augmented_roomname, &CC->usersupp, towhere);
734 c = getroom(&QRscratch, augmented_roomname);
736 strcpy(towhere, augmented_roomname);
739 /* And if the room was found... */
742 /* let internal programs go directly to any room */
743 if (CC->internal_pgm) {
744 usergoto(towhere, 1);
748 /* See if there is an existing user/room relationship */
749 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
751 /* normal clients have to pass through security */
752 if (ra & UA_GOTOALLOWED)
756 if ((QRscratch.QRflags & QR_PASSWORDED) &&
757 ((ra & UA_KNOWN) == 0) &&
758 (strcasecmp(QRscratch.QRpasswd, password))
760 cprintf("%d wrong or missing passwd\n",
761 ERROR + PASSWORD_REQUIRED);
763 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
764 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
765 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
766 ((ra & UA_KNOWN) == 0)) {
769 usergoto(towhere, 1);
775 NOPE: cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
781 struct usersupp temp;
782 struct cdbdata *cdbus;
784 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
785 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
788 getuser(&CC->usersupp, CC->curr_user);
790 if ((!is_room_aide()) && (!(CC->internal_pgm))) {
791 cprintf("%d Higher access required.\n",
792 ERROR + HIGHER_ACCESS_REQUIRED);
795 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
796 cdb_rewind(CDB_USERSUPP);
797 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
798 memset(&temp, 0, sizeof temp);
799 memcpy(&temp, cdbus->ptr, sizeof temp);
802 if ((CC->quickroom.QRflags & QR_INUSE)
803 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
805 cprintf("%s\n", temp.fullname);
812 * RDIR command for room directory
822 if (!(CC->logged_in)) {
823 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
826 getroom(&CC->quickroom, CC->quickroom.QRname);
827 getuser(&CC->usersupp, CC->curr_user);
829 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
830 cprintf("%d not here.\n", ERROR + NOT_HERE);
833 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
834 && (CC->usersupp.axlevel < 6)
835 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
836 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
839 cprintf("%d %s|%s/files/%s\n",
840 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->quickroom.QRdirname);
842 sprintf(buf, "ls %s/files/%s >%s 2> /dev/null",
843 BBSDIR, CC->quickroom.QRdirname, CC->temp);
846 sprintf(buf, "%s/files/%s/filedir", BBSDIR, CC->quickroom.QRdirname);
847 fd = fopen(buf, "r");
849 fd = fopen("/dev/null", "r");
851 ls = fopen(CC->temp, "r");
852 while (fgets(flnm, 256, ls) != NULL) {
853 flnm[strlen(flnm) - 1] = 0;
854 if (strcasecmp(flnm, "filedir")) {
855 sprintf(buf, "%s/files/%s/%s",
856 BBSDIR, CC->quickroom.QRdirname, flnm);
860 while ((fgets(buf, 256, fd) != NULL)
861 && (strlen(comment) == 0)) {
862 buf[strlen(buf) - 1] = 0;
863 if ((!strncasecmp(buf, flnm, strlen(flnm)))
864 && (buf[strlen(flnm)] == ' '))
866 &buf[strlen(flnm) + 1],
869 cprintf("%s|%ld|%s\n", flnm, statbuf.st_size, comment);
880 * get room parameters (aide or room aide command)
884 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
885 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
888 if ((!is_room_aide()) && (!(CC->internal_pgm))) {
889 cprintf("%d Higher access required.\n",
890 ERROR + HIGHER_ACCESS_REQUIRED);
893 if (is_noneditable(&CC->quickroom)) {
894 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
897 getroom(&CC->quickroom, CC->quickroom.QRname);
898 cprintf("%d%c%s|%s|%s|%d|%d|%d\n",
900 CC->quickroom.QRname,
901 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
902 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
903 CC->quickroom.QRflags,
904 (int) CC->quickroom.QRfloor,
905 (int) CC->quickroom.QRorder);
910 * set room parameters (aide or room aide command)
912 void cmd_setr(char *args)
916 char old_name[ROOMNAMELEN];
920 if (!(CC->logged_in)) {
921 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
924 if (!is_room_aide()) {
925 cprintf("%d Higher access required.\n",
926 ERROR + HIGHER_ACCESS_REQUIRED);
929 if (is_noneditable(&CC->quickroom)) {
930 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
933 if (num_parms(args) >= 6) {
934 getfloor(&flbuf, extract_int(args, 5));
935 if ((flbuf.f_flags & F_INUSE) == 0) {
936 cprintf("%d Invalid floor number.\n",
937 ERROR + INVALID_FLOOR_OPERATION);
941 if (num_parms(args) >= 7) {
942 new_order = extract_int(args, 6);
948 lgetroom(&CC->quickroom, CC->quickroom.QRname);
949 strcpy(old_name, CC->quickroom.QRname);
950 extract(buf, args, 0);
951 buf[ROOMNAMELEN] = 0;
952 safestrncpy(CC->quickroom.QRname, buf, sizeof CC->quickroom.QRname);
953 extract(buf, args, 1);
955 safestrncpy(CC->quickroom.QRpasswd, buf, sizeof CC->quickroom.QRpasswd);
956 extract(buf, args, 2);
958 safestrncpy(CC->quickroom.QRdirname, buf,
959 sizeof CC->quickroom.QRdirname);
960 CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
961 if (num_parms(args) >= 7)
962 CC->quickroom.QRorder = (char) new_order;
964 /* Clean up a client boo-boo: if the client set the room to
965 * guess-name or passworded, ensure that the private flag is
968 if ((CC->quickroom.QRflags & QR_GUESSNAME)
969 || (CC->quickroom.QRflags & QR_PASSWORDED))
970 CC->quickroom.QRflags |= QR_PRIVATE;
972 /* Kick everyone out if the client requested it (by changing the
973 * room's generation number)
975 if (extract_int(args, 4)) {
976 time(&CC->quickroom.QRgen);
978 old_floor = CC->quickroom.QRfloor;
979 if (num_parms(args) >= 6) {
980 CC->quickroom.QRfloor = extract_int(args, 5);
982 /* Write the room record back to disk */
983 lputroom(&CC->quickroom);
985 /* If the room name changed, then there are now two room records,
986 * so we have to delete the old one.
988 if (strcasecmp(CC->quickroom.QRname, old_name)) {
989 b_deleteroom(old_name);
991 /* adjust the floor reference counts */
992 lgetfloor(&flbuf, old_floor);
994 lputfloor(&flbuf, old_floor);
995 lgetfloor(&flbuf, CC->quickroom.QRfloor);
997 lputfloor(&flbuf, CC->quickroom.QRfloor);
999 /* create a room directory if necessary */
1000 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1002 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1003 CC->quickroom.QRdirname);
1006 sprintf(buf, "%s> edited by %s\n", CC->quickroom.QRname, CC->curr_user);
1008 cprintf("%d Ok\n", OK);
1014 * get the name of the room aide for this room
1018 struct usersupp usbuf;
1020 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
1021 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1024 if (is_noneditable(&CC->quickroom)) {
1025 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1028 if (getuserbynumber(&usbuf, CC->quickroom.QRroomaide) == 0) {
1029 cprintf("%d %s\n", OK, usbuf.fullname);
1031 cprintf("%d \n", OK);
1037 * set the room aide for this room
1039 void cmd_seta(char *new_ra)
1041 struct usersupp usbuf;
1046 if (!(CC->logged_in)) {
1047 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1050 if (!is_room_aide()) {
1051 cprintf("%d Higher access required.\n",
1052 ERROR + HIGHER_ACCESS_REQUIRED);
1055 if (getuser(&usbuf, new_ra) != 0) {
1058 newu = usbuf.usernum;
1061 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1063 if (CC->quickroom.QRroomaide != newu) {
1066 CC->quickroom.QRroomaide = newu;
1067 lputroom(&CC->quickroom);
1070 * We have to post the change notice _after_ writing changes to
1071 * the room table, otherwise it would deadlock!
1073 if (post_notice == 1) {
1074 sprintf(buf, "%s is now room aide for %s>\n",
1075 usbuf.fullname, CC->quickroom.QRname);
1078 cprintf("%d Ok\n", OK);
1082 * Generate an associated file name for a room
1084 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix)
1086 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1090 * retrieve info file for this room
1098 assoc_file_name(filename, &CC->quickroom, "info");
1099 info_fp = fopen(filename, "r");
1101 if (info_fp == NULL) {
1102 cprintf("%d No info file.\n", ERROR);
1105 cprintf("%d Info:\n", LISTING_FOLLOWS);
1106 while (fgets(buf, 256, info_fp) != NULL) {
1107 if (strlen(buf) > 0)
1108 buf[strlen(buf) - 1] = 0;
1109 cprintf("%s\n", buf);
1116 * Back end processing to delete a room and everything associated with it
1118 void delete_room(struct quickroom *qrbuf)
1123 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1125 /* Delete the info file */
1126 assoc_file_name(filename, qrbuf, "info");
1129 /* Delete the image file */
1130 assoc_file_name(filename, qrbuf, "images");
1133 /* Delete the messages in the room
1134 * (Careful: this opens an S_QUICKROOM critical section!)
1136 CtdlDeleteMessages(qrbuf->QRname, 0L, NULL);
1138 /* Flag the room record as not in use */
1139 lgetroom(qrbuf, qrbuf->QRname);
1143 /* then decrement the reference count for the floor */
1144 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1145 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1146 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1148 /* Delete the room record from the database! */
1149 b_deleteroom(qrbuf->QRname);
1154 * aide command: kill the current room
1156 void cmd_kill(char *argbuf)
1159 char deleted_room_name[ROOMNAMELEN];
1162 kill_ok = extract_int(argbuf, 0);
1164 if (!(CC->logged_in)) {
1165 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1168 if (!is_room_aide()) {
1169 cprintf("%d Higher access required.\n",
1170 ERROR + HIGHER_ACCESS_REQUIRED);
1173 if (is_noneditable(&CC->quickroom)) {
1174 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1178 strcpy(deleted_room_name, CC->quickroom.QRname);
1179 delete_room(&CC->quickroom); /* Do the dirty work */
1180 usergoto(BASEROOM, 0); /* Return to the Lobby */
1182 /* tell the world what we did */
1183 sprintf(aaa, "%s> killed by %s\n",
1184 deleted_room_name, CC->curr_user);
1186 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1188 cprintf("%d ok to delete.\n", OK);
1194 * Internal code to create a new room (returns room flags)
1196 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1198 unsigned create_room(char *new_room_name,
1200 char *new_room_pass,
1204 struct quickroom qrbuf;
1208 if (getroom(&qrbuf, new_room_name) == 0)
1209 return (0); /* already exists */
1211 memset(&qrbuf, 0, sizeof(struct quickroom));
1212 safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
1213 safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
1214 qrbuf.QRflags = QR_INUSE;
1215 qrbuf.QRnumber = get_new_room_number();
1216 if (new_room_type > 0)
1217 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1218 if (new_room_type == 1)
1219 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1220 if (new_room_type == 2)
1221 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1222 if (new_room_type == 4)
1223 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1225 /* If the room is private, and the system administrator has elected
1226 * to automatically grant room aide privileges, do so now; otherwise,
1227 * set the room aide to undefined.
1229 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1230 qrbuf.QRroomaide = CC->usersupp.usernum;
1232 qrbuf.QRroomaide = (-1L);
1235 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1236 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1237 qrbuf.QRfloor = new_room_floor;
1239 /* save what we just did... */
1242 /* bump the reference count on whatever floor the room is on */
1243 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1244 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1245 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1247 /* be sure not to kick the creator out of the room! */
1248 lgetuser(&CC->usersupp, CC->curr_user);
1249 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1250 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1251 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1252 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1253 lputuser(&CC->usersupp);
1255 /* resume our happy day */
1256 return (qrbuf.QRflags);
1263 void cmd_cre8(char *args)
1266 char new_room_name[256];
1268 char new_room_pass[256];
1272 struct quickroom qrbuf;
1275 cre8_ok = extract_int(args, 0);
1276 extract(new_room_name, args, 1);
1277 new_room_name[ROOMNAMELEN - 1] = 0;
1278 new_room_type = extract_int(args, 2);
1279 extract(new_room_pass, args, 3);
1280 new_room_pass[9] = 0;
1283 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1284 cprintf("%d Invalid room name.\n", ERROR);
1288 if (!strcasecmp(new_room_name, MAILROOM)) {
1289 cprintf("%d '%s' already exists.\n",
1290 ERROR + ALREADY_EXISTS, new_room_name);
1294 if (num_parms(args) >= 5) {
1295 getfloor(&flbuf, extract_int(args, 4));
1296 if ((flbuf.f_flags & F_INUSE) == 0) {
1297 cprintf("%d Invalid floor number.\n",
1298 ERROR + INVALID_FLOOR_OPERATION);
1301 new_room_floor = extract_int(args, 4);
1305 if (!(CC->logged_in)) {
1306 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1310 if (CC->usersupp.axlevel < config.c_createax) {
1311 cprintf("%d You need higher access to create rooms.\n",
1312 ERROR + HIGHER_ACCESS_REQUIRED);
1316 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1317 cprintf("%d Ok to create rooms.\n", OK);
1321 if ((new_room_type < 0) || (new_room_type > 4)) {
1322 cprintf("%d Invalid room type.\n", ERROR);
1326 /* If the user is requesting a personal room, set up the room
1327 * name accordingly (prepend the user number)
1329 if (new_room_type == 4) {
1330 sprintf(aaa, "%010ld.%s",
1331 CC->usersupp.usernum, new_room_name);
1332 strcpy(new_room_name, aaa);
1335 /* Check to make sure the requested room name doesn't already exist */
1336 if (getroom(&qrbuf, new_room_name) == 0) {
1337 cprintf("%d '%s' already exists.\n",
1338 ERROR + ALREADY_EXISTS, qrbuf.QRname);
1343 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1347 newflags = create_room(new_room_name,
1348 new_room_type, new_room_pass, new_room_floor);
1350 /* post a message in Aide> describing the new room */
1351 safestrncpy(aaa, new_room_name, sizeof aaa);
1352 strcat(aaa, "> created by ");
1353 strcat(aaa, CC->usersupp.fullname);
1354 if (newflags & QR_MAILBOX)
1355 strcat(aaa, " [personal]");
1356 else if (newflags & QR_PRIVATE)
1357 strcat(aaa, " [private]");
1358 if (newflags & QR_GUESSNAME)
1359 strcat(aaa, "[guessname] ");
1360 if (newflags & QR_PASSWORDED) {
1361 strcat(aaa, "\n Password: ");
1362 strcat(aaa, new_room_pass);
1367 cprintf("%d '%s' has been created.\n", OK, qrbuf.QRname);
1372 void cmd_einf(char *ok)
1373 { /* enter info file for current room */
1375 char infofilename[256];
1378 if (!(CC->logged_in)) {
1379 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1382 if (!is_room_aide()) {
1383 cprintf("%d Higher access required.\n",
1384 ERROR + HIGHER_ACCESS_REQUIRED);
1387 if (atoi(ok) == 0) {
1388 cprintf("%d Ok.\n", OK);
1391 assoc_file_name(infofilename, &CC->quickroom, "info");
1392 lprintf(9, "opening\n");
1393 fp = fopen(infofilename, "w");
1394 lprintf(9, "checking\n");
1396 cprintf("%d Cannot open %s: %s\n",
1397 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1400 cprintf("%d Send info...\n", SEND_LISTING);
1404 if (strcmp(buf, "000"))
1405 fprintf(fp, "%s\n", buf);
1406 } while (strcmp(buf, "000"));
1409 /* now update the room index so people will see our new info */
1410 lgetroom(&CC->quickroom, CC->quickroom.QRname); /* lock so no one steps on us */
1411 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1412 lputroom(&CC->quickroom);
1417 * cmd_lflr() - List all known floors
1424 if (!(CC->logged_in)) {
1425 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1428 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1429 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1434 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1436 for (a = 0; a < MAXFLOORS; ++a) {
1437 getfloor(&flbuf, a);
1438 if (flbuf.f_flags & F_INUSE) {
1439 cprintf("%d|%s|%d\n",
1451 * create a new floor
1453 void cmd_cflr(char *argbuf)
1455 char new_floor_name[256];
1458 int free_slot = (-1);
1461 extract(new_floor_name, argbuf, 0);
1462 cflr_ok = extract_int(argbuf, 1);
1465 if (!(CC->logged_in)) {
1466 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1469 if (CC->usersupp.axlevel < 6) {
1470 cprintf("%d You need higher access to create rooms.\n",
1471 ERROR + HIGHER_ACCESS_REQUIRED);
1474 for (a = 0; a < MAXFLOORS; ++a) {
1475 getfloor(&flbuf, a);
1477 /* note any free slots while we're scanning... */
1478 if (((flbuf.f_flags & F_INUSE) == 0)
1482 /* check to see if it already exists */
1483 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1484 && (flbuf.f_flags & F_INUSE)) {
1485 cprintf("%d Floor '%s' already exists.\n",
1486 ERROR + ALREADY_EXISTS,
1492 if (free_slot < 0) {
1493 cprintf("%d There is no space available for a new floor.\n",
1494 ERROR + INVALID_FLOOR_OPERATION);
1498 cprintf("%d ok to create...\n", OK);
1501 lgetfloor(&flbuf, free_slot);
1502 flbuf.f_flags = F_INUSE;
1503 flbuf.f_ref_count = 0;
1504 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1505 lputfloor(&flbuf, free_slot);
1506 cprintf("%d %d\n", OK, free_slot);
1514 void cmd_kflr(char *argbuf)
1517 int floor_to_delete;
1521 floor_to_delete = extract_int(argbuf, 0);
1522 kflr_ok = extract_int(argbuf, 1);
1525 if (!(CC->logged_in)) {
1526 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1529 if (CC->usersupp.axlevel < 6) {
1530 cprintf("%d You need higher access to delete floors.\n",
1531 ERROR + HIGHER_ACCESS_REQUIRED);
1534 lgetfloor(&flbuf, floor_to_delete);
1537 if ((flbuf.f_flags & F_INUSE) == 0) {
1538 cprintf("%d Floor %d not in use.\n",
1539 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1542 if (flbuf.f_ref_count != 0) {
1543 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1544 ERROR + INVALID_FLOOR_OPERATION,
1549 cprintf("%d Ok\n", OK);
1551 cprintf("%d Ok to delete...\n", OK);
1558 if ((delete_ok == 1) && (kflr_ok == 1))
1560 lputfloor(&flbuf, floor_to_delete);
1566 void cmd_eflr(char *argbuf)
1572 np = num_parms(argbuf);
1574 cprintf("%d Usage error.\n", ERROR);
1577 if (!(CC->logged_in)) {
1578 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1581 if (CC->usersupp.axlevel < 6) {
1582 cprintf("%d You need higher access to edit floors.\n",
1583 ERROR + HIGHER_ACCESS_REQUIRED);
1586 floor_num = extract_int(argbuf, 0);
1587 lgetfloor(&flbuf, floor_num);
1588 if ((flbuf.f_flags & F_INUSE) == 0) {
1589 lputfloor(&flbuf, floor_num);
1590 cprintf("%d Floor %d is not in use.\n",
1591 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1595 extract(flbuf.f_name, argbuf, 1);
1596 lputfloor(&flbuf, floor_num);
1598 cprintf("%d Ok\n", OK);