4 * Server functions which perform operations on room objects.
21 #include "sysdep_decls.h"
25 #include "citserver.h"
30 * Generic routine for determining user access to rooms
32 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf)
37 /* for internal programs, always do everything */
38 if (((CC->internal_pgm)) && (roombuf->QRflags & QR_INUSE)) {
39 return (UA_KNOWN | UA_GOTOALLOWED);
41 /* For mailbox rooms, only allow access to the owner */
42 if (roombuf->QRflags & QR_MAILBOX) {
43 if (userbuf->usernum != atol(roombuf->QRname)) {
47 /* Locate any applicable user/room relationships */
48 CtdlGetRelationship(&vbuf, userbuf, roombuf);
50 /* Force the properties of the Aide room */
51 if (!strcasecmp(roombuf->QRname, AIDEROOM)) {
52 if (userbuf->axlevel >= 6) {
53 retval = UA_KNOWN | UA_GOTOALLOWED;
59 /* For mailboxes, we skip all the access stuff (and we've
60 * already checked by this point that the mailbox belongs
63 if (roombuf->QRflags & QR_MAILBOX) {
64 retval = UA_KNOWN | UA_GOTOALLOWED;
67 /* If this is a public room, it's accessible... */
68 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
69 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
71 /* If this is a preferred users only room, check access level */
72 if (roombuf->QRflags & QR_PREFONLY) {
73 if (userbuf->axlevel < 5) {
74 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
77 /* For private rooms, check the generation number matchups */
78 if (roombuf->QRflags & QR_PRIVATE) {
80 /* An explicit match means the user belongs in this room */
81 if (vbuf.v_flags & V_ACCESS) {
82 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
84 /* Otherwise, check if this is a guess-name or passworded
85 * room. If it is, a goto may at least be attempted
87 else if ((roombuf->QRflags & QR_PRIVATE)
88 || (roombuf->QRflags & QR_PASSWORDED)) {
89 retval = retval & ~UA_KNOWN;
90 retval = retval | UA_GOTOALLOWED;
93 /* Check to see if the user has forgotten this room */
94 if (vbuf.v_flags & V_FORGET) {
95 retval = retval & ~UA_KNOWN;
96 retval = retval | UA_ZAPPED;
98 /* If user is explicitly locked out of this room, deny everything */
99 if (vbuf.v_flags & V_LOCKOUT) {
100 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
103 /* Aides get access to everything */
104 if (userbuf->axlevel >= 6) {
105 if (vbuf.v_flags & V_FORGET) {
106 retval = retval | UA_GOTOALLOWED;
109 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
113 NEWMSG: /* By the way, we also check for the presence of new messages */
114 if ((roombuf->QRhighest) > (vbuf.v_lastseen)) {
115 retval = retval | UA_HASNEWMSGS;
121 * Self-checking stuff for a room record read into memory
123 void room_sanity_check(struct quickroom *qrbuf)
125 /* Mailbox rooms are always on the lowest floor */
126 if (qrbuf->QRflags & QR_MAILBOX) {
129 /* Listing order of 0 is illegal except for base rooms */
130 if (qrbuf->QRorder == 0)
131 if (!is_noneditable(qrbuf))
137 * getroom() - retrieve room data from disk
139 int getroom(struct quickroom *qrbuf, char *room_name)
141 struct cdbdata *cdbqr;
142 char lowercase_name[ROOMNAMELEN];
143 char personal_lowercase_name[ROOMNAMELEN];
146 for (a = 0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
147 lowercase_name[a] = tolower(room_name[a]);
149 lowercase_name[a] = 0;
151 memset(qrbuf, 0, sizeof(struct quickroom));
153 /* First, try the public namespace */
154 cdbqr = cdb_fetch(CDB_QUICKROOM,
155 lowercase_name, strlen(lowercase_name));
157 /* If that didn't work, try the user's personal namespace */
159 sprintf(personal_lowercase_name, "%010ld.%s",
160 CC->usersupp.usernum, lowercase_name);
161 cdbqr = cdb_fetch(CDB_QUICKROOM,
162 personal_lowercase_name,
163 strlen(personal_lowercase_name));
166 memcpy(qrbuf, cdbqr->ptr,
167 ((cdbqr->len > sizeof(struct quickroom)) ?
168 sizeof(struct quickroom) : cdbqr->len));
171 room_sanity_check(qrbuf);
180 * lgetroom() - same as getroom() but locks the record (if supported)
182 int lgetroom(struct quickroom *qrbuf, char *room_name)
185 retval = getroom(qrbuf, room_name);
186 if (retval == 0) begin_critical_section(S_QUICKROOM);
192 * b_putroom() - back end to putroom() and b_deleteroom()
193 * (if the supplied buffer is NULL, delete the room record)
195 void b_putroom(struct quickroom *qrbuf, char *room_name)
197 char lowercase_name[ROOMNAMELEN];
200 for (a = 0; a <= strlen(room_name); ++a) {
201 lowercase_name[a] = tolower(room_name[a]);
205 cdb_delete(CDB_QUICKROOM,
206 lowercase_name, strlen(lowercase_name));
208 time(&qrbuf->QRmtime);
209 cdb_store(CDB_QUICKROOM,
210 lowercase_name, strlen(lowercase_name),
211 qrbuf, sizeof(struct quickroom));
217 * putroom() - store room data to disk
219 void putroom(struct quickroom *qrbuf) {
220 b_putroom(qrbuf, qrbuf->QRname);
225 * b_deleteroom() - delete a room record from disk
227 void b_deleteroom(char *room_name) {
228 b_putroom(NULL, room_name);
234 * lputroom() - same as putroom() but unlocks the record (if supported)
236 void lputroom(struct quickroom *qrbuf)
240 end_critical_section(S_QUICKROOM);
244 /****************************************************************************/
247 * getfloor() - retrieve floor data from disk
249 void getfloor(struct floor *flbuf, int floor_num)
251 struct cdbdata *cdbfl;
253 memset(flbuf, 0, sizeof(struct floor));
254 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
256 memcpy(flbuf, cdbfl->ptr,
257 ((cdbfl->len > sizeof(struct floor)) ?
258 sizeof(struct floor) : cdbfl->len));
261 if (floor_num == 0) {
262 strcpy(flbuf->f_name, "Main Floor");
263 flbuf->f_flags = F_INUSE;
264 flbuf->f_ref_count = 3;
271 * lgetfloor() - same as getfloor() but locks the record (if supported)
273 void lgetfloor(struct floor *flbuf, int floor_num)
276 begin_critical_section(S_FLOORTAB);
277 getfloor(flbuf, floor_num);
282 * putfloor() - store floor data on disk
284 void putfloor(struct floor *flbuf, int floor_num)
286 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
287 flbuf, sizeof(struct floor));
292 * lputfloor() - same as putfloor() but unlocks the record (if supported)
294 void lputfloor(struct floor *flbuf, int floor_num)
297 putfloor(flbuf, floor_num);
298 end_critical_section(S_FLOORTAB);
304 * Traverse the room file...
306 void ForEachRoom(void (*CallBack) (struct quickroom *EachRoom, void *out_data),
309 struct quickroom qrbuf;
310 struct cdbdata *cdbqr;
312 cdb_begin_transaction();
313 cdb_rewind(CDB_QUICKROOM);
315 while (cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
316 memset(&qrbuf, 0, sizeof(struct quickroom));
317 memcpy(&qrbuf, cdbqr->ptr,
318 ((cdbqr->len > sizeof(struct quickroom)) ?
319 sizeof(struct quickroom) : cdbqr->len));
321 room_sanity_check(&qrbuf);
322 if (qrbuf.QRflags & QR_INUSE)
323 (*CallBack)(&qrbuf, in_data);
325 cdb_end_transaction();
330 * delete_msglist() - delete room message pointers
332 void delete_msglist(struct quickroom *whichroom)
334 struct cdbdata *cdbml;
336 /* Make sure the msglist we're deleting actually exists, otherwise
337 * gdbm will complain when we try to delete an invalid record
339 cdbml = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
343 /* Go ahead and delete it */
344 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
352 * sort message pointers
353 * (returns new msg count)
355 int sort_msglist(long listptrs[], int oldcount)
366 for (a = numitems - 2; a >= 0; --a) {
367 for (b = 0; b <= a; ++b) {
368 if (listptrs[b] > (listptrs[b + 1])) {
370 hold2 = listptrs[b + 1];
372 listptrs[b + 1] = hold1;
377 /* and yank any nulls */
378 while ((numitems > 0) && (listptrs[0] == 0L)) {
379 memcpy(&listptrs[0], &listptrs[1],
380 (sizeof(long) * (numitems - 1)));
389 * Determine whether a given room is non-editable.
391 int is_noneditable(struct quickroom *qrbuf)
394 /* Lobby> and Aide> are non-editable */
395 if (!strcasecmp(qrbuf->QRname, BASEROOM))
397 else if (!strcasecmp(qrbuf->QRname, AIDEROOM))
400 /* Mail> rooms are also non-editable */
401 else if ( (qrbuf->QRflags & QR_MAILBOX)
402 && (!strcasecmp(&qrbuf->QRname[11], MAILROOM)) )
405 /* Everything else is editable */
413 * Back-back-end for all room listing commands
415 void list_roomname(struct quickroom *qrbuf)
417 char truncated_roomname[ROOMNAMELEN];
419 /* For mailbox rooms, chop off the owner prefix */
420 if (qrbuf->QRflags & QR_MAILBOX) {
421 strcpy(truncated_roomname, qrbuf->QRname);
422 strcpy(truncated_roomname, &truncated_roomname[11]);
423 cprintf("%s", truncated_roomname);
425 /* For all other rooms, just display the name in its entirety */
427 cprintf("%s", qrbuf->QRname);
430 /* ...and now the other parameters */
431 cprintf("|%u|%d|%d\n",
433 (int) qrbuf->QRfloor,
434 (int) qrbuf->QRorder);
439 * cmd_lrms() - List all accessible rooms, known or forgotten
441 void cmd_lrms_backend(struct quickroom *qrbuf, void *data)
443 int FloorBeingSearched = (-1);
444 FloorBeingSearched = *(int *)data;
446 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
447 & (UA_KNOWN | UA_ZAPPED)))
448 && ((qrbuf->QRfloor == (FloorBeingSearched))
449 || ((FloorBeingSearched) < 0)))
450 list_roomname(qrbuf);
453 void cmd_lrms(char *argbuf)
455 int FloorBeingSearched = (-1);
456 if (strlen(argbuf) > 0)
457 FloorBeingSearched = extract_int(argbuf, 0);
459 if (CtdlAccessCheck(ac_logged_in)) return;
461 if (getuser(&CC->usersupp, CC->curr_user)) {
462 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
465 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
467 ForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
474 * cmd_lkra() - List all known rooms
476 void cmd_lkra_backend(struct quickroom *qrbuf, void *data)
478 int FloorBeingSearched = (-1);
479 FloorBeingSearched = *(int *)data;
481 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
483 && ((qrbuf->QRfloor == (FloorBeingSearched))
484 || ((FloorBeingSearched) < 0)))
485 list_roomname(qrbuf);
488 void cmd_lkra(char *argbuf)
490 int FloorBeingSearched = (-1);
491 if (strlen(argbuf) > 0)
492 FloorBeingSearched = extract_int(argbuf, 0);
494 if (CtdlAccessCheck(ac_logged_in)) return;
496 if (getuser(&CC->usersupp, CC->curr_user)) {
497 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
500 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
502 ForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
509 * cmd_lkrn() - List all known rooms with new messages
511 void cmd_lkrn_backend(struct quickroom *qrbuf, void *data)
514 int FloorBeingSearched = (-1);
515 FloorBeingSearched = *(int *)data;
517 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
519 && (ra & UA_HASNEWMSGS)
520 && ((qrbuf->QRfloor == (FloorBeingSearched))
521 || ((FloorBeingSearched) < 0)))
522 list_roomname(qrbuf);
525 void cmd_lkrn(char *argbuf)
527 int FloorBeingSearched = (-1);
528 if (strlen(argbuf) > 0)
529 FloorBeingSearched = extract_int(argbuf, 0);
531 if (CtdlAccessCheck(ac_logged_in)) return;
533 if (getuser(&CC->usersupp, CC->curr_user)) {
534 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
537 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
539 ForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
546 * cmd_lkro() - List all known rooms
548 void cmd_lkro_backend(struct quickroom *qrbuf, void *data)
551 int FloorBeingSearched = (-1);
552 FloorBeingSearched = *(int *)data;
554 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
556 && ((ra & UA_HASNEWMSGS) == 0)
557 && ((qrbuf->QRfloor == (FloorBeingSearched))
558 || ((FloorBeingSearched) < 0)))
559 list_roomname(qrbuf);
562 void cmd_lkro(char *argbuf)
564 int FloorBeingSearched = (-1);
565 if (strlen(argbuf) > 0)
566 FloorBeingSearched = extract_int(argbuf, 0);
568 if (CtdlAccessCheck(ac_logged_in)) return;
570 if (getuser(&CC->usersupp, CC->curr_user)) {
571 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
574 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
576 ForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
583 * cmd_lzrm() - List all forgotten rooms
585 void cmd_lzrm_backend(struct quickroom *qrbuf, void *data)
588 int FloorBeingSearched = (-1);
589 FloorBeingSearched = *(int *)data;
591 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
592 if ((ra & UA_GOTOALLOWED)
594 && ((qrbuf->QRfloor == (FloorBeingSearched))
595 || ((FloorBeingSearched) < 0)))
596 list_roomname(qrbuf);
599 void cmd_lzrm(char *argbuf)
601 int FloorBeingSearched = (-1);
602 if (strlen(argbuf) > 0)
603 FloorBeingSearched = extract_int(argbuf, 0);
605 if (CtdlAccessCheck(ac_logged_in)) return;
607 if (getuser(&CC->usersupp, CC->curr_user)) {
608 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
611 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
613 ForEachRoom(cmd_lzrm_backend, &FloorBeingSearched);
619 void usergoto(char *where, int display_result, int *retmsgs, int *retnew)
622 int new_messages = 0;
623 int total_messages = 0;
627 int newmailcount = 0;
629 char truncated_roomname[ROOMNAMELEN];
630 struct cdbdata *cdbfr;
631 long *msglist = NULL;
634 strcpy(CC->quickroom.QRname, where);
635 getroom(&CC->quickroom, where);
637 lgetuser(&CC->usersupp, CC->curr_user);
638 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
640 /* Know the room ... but not if it's the page log room */
641 if (strcasecmp(where, config.c_logpages)) {
642 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
643 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
645 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
646 lputuser(&CC->usersupp);
648 /* check for new mail */
649 newmailcount = NewMailCount();
651 /* set info to 1 if the user needs to read the room's info file */
652 if (CC->quickroom.QRinfo > vbuf.v_lastseen)
656 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->quickroom.QRnumber, sizeof(long));
658 msglist = mallok(cdbfr->len);
659 memcpy(msglist, cdbfr->ptr, cdbfr->len);
660 num_msgs = cdbfr->len / sizeof(long);
664 if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
665 if (msglist[a] > 0L) {
667 if (msglist[a] > vbuf.v_lastseen) {
673 if (msglist != NULL) phree(msglist);
675 if (CC->quickroom.QRflags & QR_MAILBOX)
680 if ((CC->quickroom.QRroomaide == CC->usersupp.usernum)
681 || (CC->usersupp.axlevel >= 6))
686 strcpy(truncated_roomname, CC->quickroom.QRname);
687 if (CC->quickroom.QRflags & QR_MAILBOX) {
688 strcpy(truncated_roomname, &truncated_roomname[11]);
691 if (retmsgs != NULL) *retmsgs = total_messages;
692 if (retnew != NULL) *retnew = new_messages;
693 lprintf(9, "<%s> %d new of %d total messages\n",
694 CC->quickroom.QRname, new_messages, total_messages);
697 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
698 OK, CtdlCheckExpress(),
700 new_messages, total_messages,
701 info, CC->quickroom.QRflags,
702 CC->quickroom.QRhighest,
704 rmailflag, raideflag, newmailcount,
705 CC->quickroom.QRfloor);
711 * cmd_goto() - goto a new room
713 void cmd_goto(char *gargs)
715 struct quickroom QRscratch;
719 char augmented_roomname[SIZ];
723 if (CtdlAccessCheck(ac_logged_in)) return;
725 extract(towhere, gargs, 0);
726 extract(password, gargs, 1);
728 getuser(&CC->usersupp, CC->curr_user);
730 if (!strcasecmp(towhere, "_BASEROOM_"))
731 strcpy(towhere, BASEROOM);
733 if (!strcasecmp(towhere, "_MAIL_"))
734 strcpy(towhere, MAILROOM);
736 if (!strcasecmp(towhere, "_BITBUCKET_"))
737 strcpy(towhere, config.c_twitroom);
740 /* First try a regular match */
741 c = getroom(&QRscratch, towhere);
743 /* Then try a mailbox name match */
745 MailboxName(augmented_roomname, &CC->usersupp, towhere);
746 c = getroom(&QRscratch, augmented_roomname);
748 strcpy(towhere, augmented_roomname);
751 /* And if the room was found... */
754 /* let internal programs go directly to any room */
755 if (CC->internal_pgm) {
756 usergoto(towhere, 1, NULL, NULL);
760 /* See if there is an existing user/room relationship */
761 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
763 /* normal clients have to pass through security */
764 if (ra & UA_GOTOALLOWED)
768 if ((QRscratch.QRflags & QR_PASSWORDED) &&
769 ((ra & UA_KNOWN) == 0) &&
770 (strcasecmp(QRscratch.QRpasswd, password))
772 cprintf("%d wrong or missing passwd\n",
773 ERROR + PASSWORD_REQUIRED);
775 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
776 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
777 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
778 ((ra & UA_KNOWN) == 0)) {
781 usergoto(towhere, 1, NULL, NULL);
787 NOPE: cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
793 struct usersupp temp;
794 struct cdbdata *cdbus;
796 cdb_begin_transaction();
797 getuser(&CC->usersupp, CC->curr_user);
798 if (CtdlAccessCheck(ac_room_aide)) return;
800 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
801 cdb_rewind(CDB_USERSUPP);
802 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
803 memset(&temp, 0, sizeof temp);
804 memcpy(&temp, cdbus->ptr, sizeof temp);
807 if ((CC->quickroom.QRflags & QR_INUSE)
808 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
810 cprintf("%s\n", temp.fullname);
812 cdb_end_transaction();
818 * RDIR command for room directory
828 if (CtdlAccessCheck(ac_logged_in)) return;
830 getroom(&CC->quickroom, CC->quickroom.QRname);
831 getuser(&CC->usersupp, CC->curr_user);
833 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
834 cprintf("%d not here.\n", ERROR + NOT_HERE);
837 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
838 && (CC->usersupp.axlevel < 6)
839 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
840 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
843 cprintf("%d %s|%s/files/%s\n",
844 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->quickroom.QRdirname);
846 sprintf(buf, "ls %s/files/%s >%s 2> /dev/null",
847 BBSDIR, CC->quickroom.QRdirname, CC->temp);
850 sprintf(buf, "%s/files/%s/filedir", BBSDIR, CC->quickroom.QRdirname);
851 fd = fopen(buf, "r");
853 fd = fopen("/dev/null", "r");
855 ls = fopen(CC->temp, "r");
856 while (fgets(flnm, sizeof flnm, ls) != NULL) {
857 flnm[strlen(flnm) - 1] = 0;
858 if (strcasecmp(flnm, "filedir")) {
859 sprintf(buf, "%s/files/%s/%s",
860 BBSDIR, CC->quickroom.QRdirname, flnm);
864 while ((fgets(buf, sizeof buf, fd) != NULL)
865 && (strlen(comment) == 0)) {
866 buf[strlen(buf) - 1] = 0;
867 if ((!strncasecmp(buf, flnm, strlen(flnm)))
868 && (buf[strlen(flnm)] == ' '))
870 &buf[strlen(flnm) + 1],
873 cprintf("%s|%ld|%s\n", flnm, statbuf.st_size, comment);
884 * get room parameters (aide or room aide command)
888 if (CtdlAccessCheck(ac_room_aide)) return;
891 if (is_noneditable(&CC->quickroom)) {
892 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",
899 OK, CtdlCheckExpress(),
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];
921 if (CtdlAccessCheck(ac_room_aide)) return;
923 if (is_noneditable(&CC->quickroom)) {
928 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
934 if (num_parms(args) >= 6) {
935 getfloor(&flbuf, extract_int(args, 5));
936 if ((flbuf.f_flags & F_INUSE) == 0) {
937 cprintf("%d Invalid floor number.\n",
938 ERROR + INVALID_FLOOR_OPERATION);
942 if (num_parms(args) >= 7) {
943 new_order = extract_int(args, 6);
949 lgetroom(&CC->quickroom, CC->quickroom.QRname);
951 /* Non-editable base rooms can't be renamed */
952 strcpy(old_name, CC->quickroom.QRname);
954 extract(buf, args, 0);
955 buf[ROOMNAMELEN] = 0;
956 safestrncpy(CC->quickroom.QRname, buf,
957 sizeof CC->quickroom.QRname);
960 extract(buf, args, 1);
962 safestrncpy(CC->quickroom.QRpasswd, buf, sizeof CC->quickroom.QRpasswd);
963 extract(buf, args, 2);
965 safestrncpy(CC->quickroom.QRdirname, buf,
966 sizeof CC->quickroom.QRdirname);
967 CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
968 if (num_parms(args) >= 7)
969 CC->quickroom.QRorder = (char) new_order;
971 /* Clean up a client boo-boo: if the client set the room to
972 * guess-name or passworded, ensure that the private flag is
975 if ((CC->quickroom.QRflags & QR_GUESSNAME)
976 || (CC->quickroom.QRflags & QR_PASSWORDED))
977 CC->quickroom.QRflags |= QR_PRIVATE;
979 /* Kick everyone out if the client requested it (by changing the
980 * room's generation number)
982 if (extract_int(args, 4)) {
983 time(&CC->quickroom.QRgen);
985 old_floor = CC->quickroom.QRfloor;
986 if (num_parms(args) >= 6) {
987 CC->quickroom.QRfloor = extract_int(args, 5);
989 /* Write the room record back to disk */
990 lputroom(&CC->quickroom);
992 /* If the room name changed, then there are now two room records,
993 * so we have to delete the old one.
995 if (strcasecmp(CC->quickroom.QRname, old_name)) {
996 b_deleteroom(old_name);
998 /* adjust the floor reference counts */
999 lgetfloor(&flbuf, old_floor);
1000 --flbuf.f_ref_count;
1001 lputfloor(&flbuf, old_floor);
1002 lgetfloor(&flbuf, CC->quickroom.QRfloor);
1003 ++flbuf.f_ref_count;
1004 lputfloor(&flbuf, CC->quickroom.QRfloor);
1006 /* create a room directory if necessary */
1007 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1009 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1010 CC->quickroom.QRdirname);
1013 sprintf(buf, "%s> edited by %s\n", CC->quickroom.QRname, CC->curr_user);
1015 cprintf("%d Ok\n", OK);
1021 * get the name of the room aide for this room
1025 struct usersupp usbuf;
1027 if (CtdlAccessCheck(ac_logged_in)) return;
1029 if (is_noneditable(&CC->quickroom)) {
1030 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1033 if (getuserbynumber(&usbuf, CC->quickroom.QRroomaide) == 0) {
1034 cprintf("%d %s\n", OK, usbuf.fullname);
1036 cprintf("%d \n", OK);
1042 * set the room aide for this room
1044 void cmd_seta(char *new_ra)
1046 struct usersupp usbuf;
1051 if (CtdlAccessCheck(ac_room_aide)) return;
1053 if (getuser(&usbuf, new_ra) != 0) {
1056 newu = usbuf.usernum;
1059 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1061 if (CC->quickroom.QRroomaide != newu) {
1064 CC->quickroom.QRroomaide = newu;
1065 lputroom(&CC->quickroom);
1068 * We have to post the change notice _after_ writing changes to
1069 * the room table, otherwise it would deadlock!
1071 if (post_notice == 1) {
1072 sprintf(buf, "%s is now room aide for %s>\n",
1073 usbuf.fullname, CC->quickroom.QRname);
1076 cprintf("%d Ok\n", OK);
1080 * Generate an associated file name for a room
1082 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix)
1084 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1088 * retrieve info file for this room
1096 assoc_file_name(filename, &CC->quickroom, "info");
1097 info_fp = fopen(filename, "r");
1099 if (info_fp == NULL) {
1100 cprintf("%d No info file.\n", ERROR);
1103 cprintf("%d Info:\n", LISTING_FOLLOWS);
1104 while (fgets(buf, sizeof buf, info_fp) != NULL) {
1105 if (strlen(buf) > 0)
1106 buf[strlen(buf) - 1] = 0;
1107 cprintf("%s\n", buf);
1114 * Back end processing to delete a room and everything associated with it
1116 void delete_room(struct quickroom *qrbuf)
1121 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1123 /* Delete the info file */
1124 assoc_file_name(filename, qrbuf, "info");
1127 /* Delete the image file */
1128 assoc_file_name(filename, qrbuf, "images");
1131 /* Delete the room's network config file */
1132 assoc_file_name(filename, qrbuf, "netconfigs");
1135 /* Delete the messages in the room
1136 * (Careful: this opens an S_QUICKROOM critical section!)
1138 CtdlDeleteMessages(qrbuf->QRname, 0L, "");
1140 /* Flag the room record as not in use */
1141 lgetroom(qrbuf, qrbuf->QRname);
1145 /* then decrement the reference count for the floor */
1146 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1147 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1148 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1150 /* Delete the room record from the database! */
1151 b_deleteroom(qrbuf->QRname);
1156 * aide command: kill the current room
1158 void cmd_kill(char *argbuf)
1161 char deleted_room_name[ROOMNAMELEN];
1164 kill_ok = extract_int(argbuf, 0);
1166 if (CtdlAccessCheck(ac_room_aide)) return;
1168 if (is_noneditable(&CC->quickroom)) {
1169 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1173 strcpy(deleted_room_name, CC->quickroom.QRname);
1174 delete_room(&CC->quickroom); /* Do the dirty work */
1175 usergoto(BASEROOM, 0, NULL, NULL); /* Return to the Lobby */
1177 /* tell the world what we did */
1178 sprintf(aaa, "%s> killed by %s\n",
1179 deleted_room_name, CC->curr_user);
1181 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1183 cprintf("%d ok to delete.\n", OK);
1189 * Internal code to create a new room (returns room flags)
1191 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1193 unsigned create_room(char *new_room_name,
1195 char *new_room_pass,
1199 struct quickroom qrbuf;
1203 lprintf(9, "create_room(%s)\n", new_room_name);
1204 if (getroom(&qrbuf, new_room_name) == 0) {
1205 lprintf(9, "%s already exists.\n", new_room_name);
1206 return (0); /* already exists */
1209 memset(&qrbuf, 0, sizeof(struct quickroom));
1210 safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
1211 safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
1212 qrbuf.QRflags = QR_INUSE;
1213 qrbuf.QRnumber = get_new_room_number();
1214 if (new_room_type > 0)
1215 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1216 if (new_room_type == 1)
1217 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1218 if (new_room_type == 2)
1219 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1220 if (new_room_type == 4)
1221 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1223 /* If the room is private, and the system administrator has elected
1224 * to automatically grant room aide privileges, do so now; otherwise,
1225 * set the room aide to undefined.
1227 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1228 qrbuf.QRroomaide = CC->usersupp.usernum;
1230 qrbuf.QRroomaide = (-1L);
1233 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1234 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1235 qrbuf.QRfloor = new_room_floor;
1237 /* save what we just did... */
1240 /* bump the reference count on whatever floor the room is on */
1241 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1242 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1243 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1245 /* be sure not to kick the creator out of the room! */
1246 lgetuser(&CC->usersupp, CC->curr_user);
1247 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1248 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1249 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1250 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1251 lputuser(&CC->usersupp);
1253 /* resume our happy day */
1254 return (qrbuf.QRflags);
1261 void cmd_cre8(char *args)
1264 char new_room_name[SIZ];
1266 char new_room_pass[SIZ];
1270 struct quickroom qrbuf;
1273 cre8_ok = extract_int(args, 0);
1274 extract(new_room_name, args, 1);
1275 new_room_name[ROOMNAMELEN - 1] = 0;
1276 new_room_type = extract_int(args, 2);
1277 extract(new_room_pass, args, 3);
1278 new_room_pass[9] = 0;
1281 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1282 cprintf("%d Invalid room name.\n", ERROR);
1286 if (!strcasecmp(new_room_name, MAILROOM)) {
1287 cprintf("%d '%s' already exists.\n",
1288 ERROR + ALREADY_EXISTS, new_room_name);
1292 if (num_parms(args) >= 5) {
1293 getfloor(&flbuf, extract_int(args, 4));
1294 if ((flbuf.f_flags & F_INUSE) == 0) {
1295 cprintf("%d Invalid floor number.\n",
1296 ERROR + INVALID_FLOOR_OPERATION);
1299 new_room_floor = extract_int(args, 4);
1303 if (CtdlAccessCheck(ac_logged_in)) return;
1305 if (CC->usersupp.axlevel < config.c_createax) {
1306 cprintf("%d You need higher access to create rooms.\n",
1307 ERROR + HIGHER_ACCESS_REQUIRED);
1311 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1312 cprintf("%d Ok to create rooms.\n", OK);
1316 if ((new_room_type < 0) || (new_room_type > 4)) {
1317 cprintf("%d Invalid room type.\n", ERROR);
1321 /* If the user is requesting a personal room, set up the room
1322 * name accordingly (prepend the user number)
1324 if (new_room_type == 4) {
1325 sprintf(aaa, "%010ld.%s",
1326 CC->usersupp.usernum, new_room_name);
1327 strcpy(new_room_name, aaa);
1330 /* Check to make sure the requested room name doesn't already exist */
1331 if (getroom(&qrbuf, new_room_name) == 0) {
1332 cprintf("%d '%s' already exists.\n",
1333 ERROR + ALREADY_EXISTS, qrbuf.QRname);
1338 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1342 newflags = create_room(new_room_name,
1343 new_room_type, new_room_pass, new_room_floor);
1345 /* post a message in Aide> describing the new room */
1346 safestrncpy(aaa, new_room_name, sizeof aaa);
1347 strcat(aaa, "> created by ");
1348 strcat(aaa, CC->usersupp.fullname);
1349 if (newflags & QR_MAILBOX)
1350 strcat(aaa, " [personal]");
1351 else if (newflags & QR_PRIVATE)
1352 strcat(aaa, " [private]");
1353 if (newflags & QR_GUESSNAME)
1354 strcat(aaa, "[guessname] ");
1355 if (newflags & QR_PASSWORDED) {
1356 strcat(aaa, "\n Password: ");
1357 strcat(aaa, new_room_pass);
1362 cprintf("%d '%s' has been created.\n", OK, qrbuf.QRname);
1367 void cmd_einf(char *ok)
1368 { /* enter info file for current room */
1370 char infofilename[SIZ];
1373 if (CtdlAccessCheck(ac_room_aide)) return;
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 (CtdlAccessCheck(ac_logged_in)) return;
1414 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1416 for (a = 0; a < MAXFLOORS; ++a) {
1417 getfloor(&flbuf, a);
1418 if (flbuf.f_flags & F_INUSE) {
1419 cprintf("%d|%s|%d\n",
1431 * create a new floor
1433 void cmd_cflr(char *argbuf)
1435 char new_floor_name[SIZ];
1438 int free_slot = (-1);
1441 extract(new_floor_name, argbuf, 0);
1442 cflr_ok = extract_int(argbuf, 1);
1445 if (CtdlAccessCheck(ac_aide)) return;
1447 for (a = 0; a < MAXFLOORS; ++a) {
1448 getfloor(&flbuf, a);
1450 /* note any free slots while we're scanning... */
1451 if (((flbuf.f_flags & F_INUSE) == 0)
1455 /* check to see if it already exists */
1456 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1457 && (flbuf.f_flags & F_INUSE)) {
1458 cprintf("%d Floor '%s' already exists.\n",
1459 ERROR + ALREADY_EXISTS,
1465 if (free_slot < 0) {
1466 cprintf("%d There is no space available for a new floor.\n",
1467 ERROR + INVALID_FLOOR_OPERATION);
1471 cprintf("%d ok to create...\n", OK);
1474 lgetfloor(&flbuf, free_slot);
1475 flbuf.f_flags = F_INUSE;
1476 flbuf.f_ref_count = 0;
1477 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1478 lputfloor(&flbuf, free_slot);
1479 cprintf("%d %d\n", OK, free_slot);
1487 void cmd_kflr(char *argbuf)
1490 int floor_to_delete;
1494 floor_to_delete = extract_int(argbuf, 0);
1495 kflr_ok = extract_int(argbuf, 1);
1497 if (CtdlAccessCheck(ac_aide)) return;
1499 lgetfloor(&flbuf, floor_to_delete);
1502 if ((flbuf.f_flags & F_INUSE) == 0) {
1503 cprintf("%d Floor %d not in use.\n",
1504 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1507 if (flbuf.f_ref_count != 0) {
1508 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1509 ERROR + INVALID_FLOOR_OPERATION,
1514 cprintf("%d Ok\n", OK);
1516 cprintf("%d Ok to delete...\n", OK);
1523 if ((delete_ok == 1) && (kflr_ok == 1))
1525 lputfloor(&flbuf, floor_to_delete);
1531 void cmd_eflr(char *argbuf)
1537 np = num_parms(argbuf);
1539 cprintf("%d Usage error.\n", ERROR);
1543 if (CtdlAccessCheck(ac_aide)) return;
1545 floor_num = extract_int(argbuf, 0);
1546 lgetfloor(&flbuf, floor_num);
1547 if ((flbuf.f_flags & F_INUSE) == 0) {
1548 lputfloor(&flbuf, floor_num);
1549 cprintf("%d Floor %d is not in use.\n",
1550 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1554 extract(flbuf.f_name, argbuf, 1);
1555 lputfloor(&flbuf, floor_num);
1557 cprintf("%d Ok\n", OK);