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);
319 * get_msglist() - retrieve room message pointers
321 void get_msglist(struct quickroom *whichroom)
323 struct cdbdata *cdbfr;
325 if (CC->msglist != NULL) {
331 cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
335 CC->msglist = mallok(cdbfr->len);
336 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
337 CC->num_msgs = cdbfr->len / sizeof(long);
343 * put_msglist() - retrieve room message pointers
345 void put_msglist(struct quickroom *whichroom)
348 if (CC->msglist != NULL)
349 cdb_store(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long),
350 CC->msglist, CC->num_msgs * sizeof(long));
355 * delete_msglist() - delete room message pointers
356 * FIX - this really should check first to make sure there's actually a
357 * msglist to delete. As things stand now, calling this function on
358 * a room which has never been posted in will result in a message
359 * like "gdbm: illegal data" (no big deal, but could use fixing).
361 void delete_msglist(struct quickroom *whichroom)
364 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
369 * Add a message number to a room's message list.
370 * So, why doesn't this function use the get_msglist() and put_msglist() stuff
371 * defined above? Because the room the message number is being written to
372 * may not be the current room (as is the case with cmd_move() for example).
374 * This function returns the highest message number present in the room after
375 * the add operation is performed - which is not necessarily the message
378 long AddMessageToRoom(struct quickroom *whichroom, long newmsgid)
380 struct cdbdata *cdbfr;
383 long highest_msg = 0L;
385 lprintf(9, "AddMessageToRoom(%s, %ld)\n", whichroom->QRname, newmsgid);
386 cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
391 msglist = mallok(cdbfr->len);
393 lprintf(3, "ERROR malloc msglist!\n");
394 num_msgs = cdbfr->len / sizeof(long);
395 memcpy(msglist, cdbfr->ptr, cdbfr->len);
399 /* Now add the new message */
401 msglist = reallok(msglist,
402 (num_msgs * sizeof(long)));
404 if (msglist == NULL) {
405 lprintf(3, "ERROR: can't realloc message list!\n");
407 msglist[num_msgs - 1] = newmsgid;
409 /* Sort the message list, so all the msgid's are in order */
410 num_msgs = sort_msglist(msglist, num_msgs);
412 /* Determine the highest message number */
413 highest_msg = msglist[num_msgs - 1];
415 /* Write it back to disk. */
416 cdb_store(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long),
417 msglist, num_msgs * sizeof(long));
419 /* And finally, free up the memory we used. */
421 return (highest_msg);
426 * MessageFromList() - get a message number from the list currently in memory
428 long MessageFromList(int whichpos)
431 /* Return zero if the position is invalid */
432 if (whichpos >= CC->num_msgs)
435 return (CC->msglist[whichpos]);
439 * SetMessageInList() - set a message number in the list currently in memory
441 void SetMessageInList(int whichpos, long newmsgnum)
444 /* Return zero if the position is invalid */
445 if (whichpos >= CC->num_msgs)
448 CC->msglist[whichpos] = newmsgnum;
454 * sort message pointers
455 * (returns new msg count)
457 int sort_msglist(long listptrs[], int oldcount)
468 for (a = numitems - 2; a >= 0; --a) {
469 for (b = 0; b <= a; ++b) {
470 if (listptrs[b] > (listptrs[b + 1])) {
472 hold2 = listptrs[b + 1];
474 listptrs[b + 1] = hold1;
479 /* and yank any nulls */
480 while ((numitems > 0) && (listptrs[0] == 0L)) {
481 memcpy(&listptrs[0], &listptrs[1],
482 (sizeof(long) * (CC->num_msgs - 1)));
491 * Determine whether a given room is non-editable.
493 int is_noneditable(struct quickroom *qrbuf)
496 /* Lobby> and Aide> are non-editable */
497 if (!strcasecmp(qrbuf->QRname, BASEROOM))
499 else if (!strcasecmp(qrbuf->QRname, AIDEROOM))
502 /* Mail> rooms are also non-editable */
503 else if ( (qrbuf->QRflags & QR_MAILBOX)
504 && (!strcasecmp(&qrbuf->QRname[11], MAILROOM)) )
507 /* Everything else is editable */
515 * Back-back-end for all room listing commands
517 void list_roomname(struct quickroom *qrbuf)
519 char truncated_roomname[ROOMNAMELEN];
521 /* For mailbox rooms, chop off the owner prefix */
522 if (qrbuf->QRflags & QR_MAILBOX) {
523 strcpy(truncated_roomname, qrbuf->QRname);
524 strcpy(truncated_roomname, &truncated_roomname[11]);
525 cprintf("%s", truncated_roomname);
527 /* For all other rooms, just display the name in its entirety */
529 cprintf("%s", qrbuf->QRname);
532 /* ...and now the other parameters */
533 cprintf("|%u|%d|%d\n",
535 (int) qrbuf->QRfloor,
536 (int) qrbuf->QRorder);
541 * cmd_lrms() - List all accessible rooms, known or forgotten
543 void cmd_lrms_backend(struct quickroom *qrbuf)
545 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
546 & (UA_KNOWN | UA_ZAPPED)))
547 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
548 || ((CC->FloorBeingSearched) < 0)))
549 list_roomname(qrbuf);
552 void cmd_lrms(char *argbuf)
554 CC->FloorBeingSearched = (-1);
555 if (strlen(argbuf) > 0)
556 CC->FloorBeingSearched = extract_int(argbuf, 0);
558 if (!(CC->logged_in)) {
559 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
562 if (getuser(&CC->usersupp, CC->curr_user)) {
563 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
566 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
568 ForEachRoom(cmd_lrms_backend);
575 * cmd_lkra() - List all known rooms
577 void cmd_lkra_backend(struct quickroom *qrbuf)
579 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
581 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
582 || ((CC->FloorBeingSearched) < 0)))
583 list_roomname(qrbuf);
586 void cmd_lkra(char *argbuf)
588 CC->FloorBeingSearched = (-1);
589 if (strlen(argbuf) > 0)
590 CC->FloorBeingSearched = extract_int(argbuf, 0);
592 if (!(CC->logged_in)) {
593 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
596 if (getuser(&CC->usersupp, CC->curr_user)) {
597 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
600 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
602 ForEachRoom(cmd_lkra_backend);
609 * cmd_lkrn() - List all known rooms with new messages
611 void cmd_lkrn_backend(struct quickroom *qrbuf)
615 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
617 && (ra & UA_HASNEWMSGS)
618 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
619 || ((CC->FloorBeingSearched) < 0)))
620 list_roomname(qrbuf);
623 void cmd_lkrn(char *argbuf)
625 CC->FloorBeingSearched = (-1);
626 if (strlen(argbuf) > 0)
627 CC->FloorBeingSearched = extract_int(argbuf, 0);
629 if (!(CC->logged_in)) {
630 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
633 if (getuser(&CC->usersupp, CC->curr_user)) {
634 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
637 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
639 ForEachRoom(cmd_lkrn_backend);
646 * cmd_lkro() - List all known rooms
648 void cmd_lkro_backend(struct quickroom *qrbuf)
652 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
654 && ((ra & UA_HASNEWMSGS) == 0)
655 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
656 || ((CC->FloorBeingSearched) < 0)))
657 list_roomname(qrbuf);
660 void cmd_lkro(char *argbuf)
662 CC->FloorBeingSearched = (-1);
663 if (strlen(argbuf) > 0)
664 CC->FloorBeingSearched = extract_int(argbuf, 0);
666 if (!(CC->logged_in)) {
667 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
670 if (getuser(&CC->usersupp, CC->curr_user)) {
671 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
674 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
676 ForEachRoom(cmd_lkro_backend);
683 * cmd_lzrm() - List all forgotten rooms
685 void cmd_lzrm_backend(struct quickroom *qrbuf)
689 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
690 if ((ra & UA_GOTOALLOWED)
692 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
693 || ((CC->FloorBeingSearched) < 0)))
694 list_roomname(qrbuf);
697 void cmd_lzrm(char *argbuf)
699 CC->FloorBeingSearched = (-1);
700 if (strlen(argbuf) > 0)
701 CC->FloorBeingSearched = extract_int(argbuf, 0);
703 if (!(CC->logged_in)) {
704 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
707 if (getuser(&CC->usersupp, CC->curr_user)) {
708 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
711 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
713 ForEachRoom(cmd_lzrm_backend);
719 void usergoto(char *where, int display_result)
722 int new_messages = 0;
723 int total_messages = 0;
727 int newmailcount = 0;
729 char truncated_roomname[ROOMNAMELEN];
731 strcpy(CC->quickroom.QRname, where);
732 getroom(&CC->quickroom, where);
734 lgetuser(&CC->usersupp, CC->curr_user);
735 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
737 /* Know the room ... but not if it's the page log room */
738 if (strcasecmp(where, config.c_logpages)) {
739 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
740 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
742 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
743 lputuser(&CC->usersupp, CC->curr_user);
745 /* check for new mail */
746 newmailcount = NewMailCount();
748 /* set info to 1 if the user needs to read the room's info file */
749 if (CC->quickroom.QRinfo > vbuf.v_lastseen)
753 get_msglist(&CC->quickroom);
754 for (a = 0; a < CC->num_msgs; ++a) {
755 if (MessageFromList(a) > 0L) {
757 if (MessageFromList(a) > vbuf.v_lastseen) {
763 if (CC->quickroom.QRflags & QR_MAILBOX)
768 if ((CC->quickroom.QRroomaide == CC->usersupp.usernum)
769 || (CC->usersupp.axlevel >= 6))
774 strcpy(truncated_roomname, CC->quickroom.QRname);
775 if (CC->quickroom.QRflags & QR_MAILBOX) {
776 strcpy(truncated_roomname, &truncated_roomname[11]);
779 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
782 new_messages, total_messages,
783 info, CC->quickroom.QRflags,
784 CC->quickroom.QRhighest,
786 rmailflag, raideflag, newmailcount, CC->quickroom.QRfloor);
788 set_wtmpsupp_to_current_room();
793 * cmd_goto() - goto a new room
795 void cmd_goto(char *gargs)
797 struct quickroom QRscratch;
801 char augmented_roomname[256];
805 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
806 cprintf("%d not logged in\n", ERROR + NOT_LOGGED_IN);
809 extract(towhere, gargs, 0);
810 extract(password, gargs, 1);
812 getuser(&CC->usersupp, CC->curr_user);
814 if (!strcasecmp(towhere, "_BASEROOM_"))
815 strcpy(towhere, BASEROOM);
817 if (!strcasecmp(towhere, "_MAIL_"))
818 strcpy(towhere, MAILROOM);
820 if (!strcasecmp(towhere, "_BITBUCKET_"))
821 strcpy(towhere, config.c_twitroom);
824 /* First try a regular match */
825 c = getroom(&QRscratch, towhere);
827 /* Then try a mailbox name match */
829 MailboxName(augmented_roomname, &CC->usersupp, towhere);
830 c = getroom(&QRscratch, augmented_roomname);
832 strcpy(towhere, augmented_roomname);
834 /* And if the room was found... */
837 /* let internal programs go directly to any room */
838 if (CC->internal_pgm) {
839 usergoto(towhere, 1);
842 /* See if there is an existing user/room relationship */
843 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
845 /* normal clients have to pass through security */
846 if (ra & UA_GOTOALLOWED)
850 if ((QRscratch.QRflags & QR_PASSWORDED) &&
851 ((ra & UA_KNOWN) == 0) &&
852 (strcasecmp(QRscratch.QRpasswd, password))
854 cprintf("%d wrong or missing passwd\n",
855 ERROR + PASSWORD_REQUIRED);
857 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
858 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
859 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
860 ((ra & UA_KNOWN) == 0)) {
863 usergoto(towhere, 1);
868 NOPE:cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
874 struct usersupp temp;
875 struct cdbdata *cdbus;
877 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
878 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
881 getuser(&CC->usersupp, CC->curr_user);
883 if ((!is_room_aide()) && (!(CC->internal_pgm))) {
884 cprintf("%d Higher access required.\n",
885 ERROR + HIGHER_ACCESS_REQUIRED);
888 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
889 cdb_rewind(CDB_USERSUPP);
890 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
891 memset(&temp, 0, sizeof(struct usersupp));
892 memcpy(&temp, cdbus->ptr, cdbus->len);
895 if ((CC->quickroom.QRflags & QR_INUSE)
896 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
898 cprintf("%s\n", temp.fullname);
905 * RDIR command for room directory
915 if (!(CC->logged_in)) {
916 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
919 getroom(&CC->quickroom, CC->quickroom.QRname);
920 getuser(&CC->usersupp, CC->curr_user);
922 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
923 cprintf("%d not here.\n", ERROR + NOT_HERE);
926 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
927 && (CC->usersupp.axlevel < 6)
928 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
929 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
932 cprintf("%d %s|%s/files/%s\n",
933 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->quickroom.QRdirname);
935 sprintf(buf, "cd %s/files/%s; ls >%s 2>/dev/null",
936 BBSDIR, CC->quickroom.QRdirname, CC->temp);
939 sprintf(buf, "%s/files/%s/filedir", BBSDIR, CC->quickroom.QRdirname);
940 fd = fopen(buf, "r");
942 fd = fopen("/dev/null", "r");
944 ls = fopen(CC->temp, "r");
945 while (fgets(flnm, 256, ls) != NULL) {
946 flnm[strlen(flnm) - 1] = 0;
947 if (strcasecmp(flnm, "filedir")) {
948 sprintf(buf, "%s/files/%s/%s",
949 BBSDIR, CC->quickroom.QRdirname, flnm);
953 while ((fgets(buf, 256, fd) != NULL)
954 && (strlen(comment) == 0)) {
955 buf[strlen(buf) - 1] = 0;
956 if ((!strncasecmp(buf, flnm, strlen(flnm)))
957 && (buf[strlen(flnm)] == ' '))
959 &buf[strlen(flnm) + 1], 255);
961 cprintf("%s|%ld|%s\n", flnm, statbuf.st_size, comment);
972 * get room parameters (aide or room aide command)
976 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
977 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
980 if ((!is_room_aide()) && (!(CC->internal_pgm))) {
981 cprintf("%d Higher access required.\n",
982 ERROR + HIGHER_ACCESS_REQUIRED);
985 if (is_noneditable(&CC->quickroom)) {
986 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
989 getroom(&CC->quickroom, CC->quickroom.QRname);
990 cprintf("%d%c%s|%s|%s|%d|%d|%d\n",
992 CC->quickroom.QRname,
993 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
994 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
995 CC->quickroom.QRflags,
996 (int) CC->quickroom.QRfloor,
997 (int) CC->quickroom.QRorder);
1002 * set room parameters (aide or room aide command)
1004 void cmd_setr(char *args)
1008 char old_name[ROOMNAMELEN];
1012 if (!(CC->logged_in)) {
1013 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1016 if (!is_room_aide()) {
1017 cprintf("%d Higher access required.\n",
1018 ERROR + HIGHER_ACCESS_REQUIRED);
1021 if (is_noneditable(&CC->quickroom)) {
1022 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1025 if (num_parms(args) >= 6) {
1026 getfloor(&flbuf, extract_int(args, 5));
1027 if ((flbuf.f_flags & F_INUSE) == 0) {
1028 cprintf("%d Invalid floor number.\n",
1029 ERROR + INVALID_FLOOR_OPERATION);
1033 if (num_parms(args) >= 7) {
1034 new_order = extract_int(args, 6);
1037 if (new_order > 127)
1040 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1041 strcpy(old_name, CC->quickroom.QRname);
1042 extract(buf, args, 0);
1043 buf[ROOMNAMELEN] = 0;
1044 strncpy(CC->quickroom.QRname, buf, ROOMNAMELEN - 1);
1045 extract(buf, args, 1);
1047 strncpy(CC->quickroom.QRpasswd, buf, 9);
1048 extract(buf, args, 2);
1050 strncpy(CC->quickroom.QRdirname, buf, 19);
1051 CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
1052 if (num_parms(args) >= 7)
1053 CC->quickroom.QRorder = (char) new_order;
1055 /* Clean up a client boo-boo: if the client set the room to
1056 * guess-name or passworded, ensure that the private flag is
1059 if ((CC->quickroom.QRflags & QR_GUESSNAME)
1060 || (CC->quickroom.QRflags & QR_PASSWORDED))
1061 CC->quickroom.QRflags |= QR_PRIVATE;
1063 /* Kick everyone out if the client requested it (by changing the
1064 * room's generation number)
1066 if (extract_int(args, 4)) {
1067 time(&CC->quickroom.QRgen);
1069 old_floor = CC->quickroom.QRfloor;
1070 if (num_parms(args) >= 6) {
1071 CC->quickroom.QRfloor = extract_int(args, 5);
1073 /* Write the room record back to disk */
1074 lputroom(&CC->quickroom);
1076 /* If the room name changed, then there are now two room records,
1077 * so we have to delete the old one.
1079 if (strcasecmp(CC->quickroom.QRname, old_name)) {
1080 b_deleteroom(old_name);
1082 /* adjust the floor reference counts */
1083 lgetfloor(&flbuf, old_floor);
1084 --flbuf.f_ref_count;
1085 lputfloor(&flbuf, old_floor);
1086 lgetfloor(&flbuf, CC->quickroom.QRfloor);
1087 ++flbuf.f_ref_count;
1088 lputfloor(&flbuf, CC->quickroom.QRfloor);
1090 /* create a room directory if necessary */
1091 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1093 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1094 CC->quickroom.QRdirname);
1097 sprintf(buf, "%s> edited by %s", CC->quickroom.QRname, CC->curr_user);
1099 cprintf("%d Ok\n", OK);
1105 * get the name of the room aide for this room
1109 struct usersupp usbuf;
1111 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
1112 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1115 if (is_noneditable(&CC->quickroom)) {
1116 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1119 if (getuserbynumber(&usbuf, CC->quickroom.QRroomaide) == 0) {
1120 cprintf("%d %s\n", OK, usbuf.fullname);
1122 cprintf("%d \n", OK);
1128 * set the room aide for this room
1130 void cmd_seta(char *new_ra)
1132 struct usersupp usbuf;
1137 if (!(CC->logged_in)) {
1138 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1141 if (!is_room_aide()) {
1142 cprintf("%d Higher access required.\n",
1143 ERROR + HIGHER_ACCESS_REQUIRED);
1146 if (getuser(&usbuf, new_ra) != 0) {
1149 newu = usbuf.usernum;
1152 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1154 if (CC->quickroom.QRroomaide != newu) {
1157 CC->quickroom.QRroomaide = newu;
1158 lputroom(&CC->quickroom);
1161 * We have to post the change notice _after_ writing changes to
1162 * the room table, otherwise it would deadlock!
1164 if (post_notice == 1) {
1165 sprintf(buf, "%s is now room aide for %s>",
1166 usbuf.fullname, CC->quickroom.QRname);
1169 cprintf("%d Ok\n", OK);
1173 * Generate an associated file name for a room
1175 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix)
1177 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1181 * retrieve info file for this room
1189 assoc_file_name(filename, &CC->quickroom, "info");
1190 info_fp = fopen(filename, "r");
1192 if (info_fp == NULL) {
1193 cprintf("%d No info file.\n", ERROR);
1196 cprintf("%d Info:\n", LISTING_FOLLOWS);
1197 while (fgets(buf, 256, info_fp) != NULL) {
1198 if (strlen(buf) > 0)
1199 buf[strlen(buf) - 1] = 0;
1200 cprintf("%s\n", buf);
1207 * Back end processing to delete a room and everything associated with it
1209 void delete_room(struct quickroom *qrbuf)
1216 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1218 /* Delete the info file */
1219 assoc_file_name(aaa, qrbuf, "info");
1222 /* Delete the image file */
1223 assoc_file_name(aaa, qrbuf, "images");
1226 /* first flag the room record as not in use */
1227 lgetroom(qrbuf, qrbuf->QRname);
1230 /* then delete the messages in the room */
1232 if (CC->num_msgs > 0)
1233 for (a = 0; a < CC->num_msgs; ++a) {
1234 MsgToDelete = MessageFromList(a);
1235 AdjRefCount(MsgToDelete, -1);
1241 delete_msglist(qrbuf);
1244 /* then decrement the reference count for the floor */
1245 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1246 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1247 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1249 /* Delete the room record from the database! */
1250 b_deleteroom(qrbuf->QRname);
1255 * aide command: kill the current room
1257 void cmd_kill(char *argbuf)
1260 char deleted_room_name[ROOMNAMELEN];
1263 kill_ok = extract_int(argbuf, 0);
1265 if (!(CC->logged_in)) {
1266 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1269 if (!is_room_aide()) {
1270 cprintf("%d Higher access required.\n",
1271 ERROR + HIGHER_ACCESS_REQUIRED);
1274 if (is_noneditable(&CC->quickroom)) {
1275 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1279 strcpy(deleted_room_name, CC->quickroom.QRname);
1280 delete_room(&CC->quickroom); /* Do the dirty work */
1281 usergoto(BASEROOM, 0); /* Return to the Lobby */
1283 /* tell the world what we did */
1284 sprintf(aaa, "%s> killed by %s",
1285 deleted_room_name, CC->curr_user);
1287 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1289 cprintf("%d ok to delete.\n", OK);
1295 * Internal code to create a new room (returns room flags)
1297 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1299 unsigned create_room(char *new_room_name,
1301 char *new_room_pass,
1305 struct quickroom qrbuf;
1309 if (getroom(&qrbuf, new_room_name) == 0)
1310 return (0); /* already exists */
1312 memset(&qrbuf, 0, sizeof(struct quickroom));
1313 strncpy(qrbuf.QRname, new_room_name, ROOMNAMELEN);
1314 strncpy(qrbuf.QRpasswd, new_room_pass, 9);
1315 qrbuf.QRflags = QR_INUSE;
1316 qrbuf.QRnumber = get_new_room_number();
1317 if (new_room_type > 0)
1318 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1319 if (new_room_type == 1)
1320 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1321 if (new_room_type == 2)
1322 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1323 if (new_room_type == 4)
1324 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1326 /* If the room is private, and the system administrator has elected
1327 * to automatically grant room aide privileges, do so now; otherwise,
1328 * set the room aide to undefined.
1330 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1331 qrbuf.QRroomaide = CC->usersupp.usernum;
1333 qrbuf.QRroomaide = (-1L);
1336 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1337 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1338 qrbuf.QRfloor = new_room_floor;
1340 /* save what we just did... */
1343 /* bump the reference count on whatever floor the room is on */
1344 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1345 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1346 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1348 /* be sure not to kick the creator out of the room! */
1349 lgetuser(&CC->usersupp, CC->curr_user);
1350 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1351 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1352 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1353 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1354 lputuser(&CC->usersupp, CC->curr_user);
1356 /* resume our happy day */
1357 return (qrbuf.QRflags);
1364 void cmd_cre8(char *args)
1367 char new_room_name[256];
1369 char new_room_pass[256];
1373 struct quickroom qrbuf;
1376 cre8_ok = extract_int(args, 0);
1377 extract(new_room_name, args, 1);
1378 new_room_name[ROOMNAMELEN - 1] = 0;
1379 new_room_type = extract_int(args, 2);
1380 extract(new_room_pass, args, 3);
1381 new_room_pass[9] = 0;
1384 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1385 cprintf("%d Invalid room name.\n", ERROR);
1389 if (!strcasecmp(new_room_name, MAILROOM)) {
1390 cprintf("%d '%s' already exists.\n",
1391 ERROR + ALREADY_EXISTS, new_room_name);
1395 if (num_parms(args) >= 5) {
1396 getfloor(&flbuf, extract_int(args, 4));
1397 if ((flbuf.f_flags & F_INUSE) == 0) {
1398 cprintf("%d Invalid floor number.\n",
1399 ERROR + INVALID_FLOOR_OPERATION);
1402 new_room_floor = extract_int(args, 4);
1406 if (!(CC->logged_in)) {
1407 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1411 if (CC->usersupp.axlevel < config.c_createax) {
1412 cprintf("%d You need higher access to create rooms.\n",
1413 ERROR + HIGHER_ACCESS_REQUIRED);
1417 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1418 cprintf("%d Ok to create rooms.\n", OK);
1422 if ((new_room_type < 0) || (new_room_type > 4)) {
1423 cprintf("%d Invalid room type.\n", ERROR);
1427 /* If the user is requesting a personal room, set up the room
1428 * name accordingly (prepend the user number)
1430 if (new_room_type == 4) {
1431 sprintf(aaa, "%010ld.%s",
1432 CC->usersupp.usernum, new_room_name);
1433 strcpy(new_room_name, aaa);
1436 /* Check to make sure the requested room name doesn't already exist */
1437 if (getroom(&qrbuf, new_room_name) == 0) {
1438 cprintf("%d '%s' already exists.\n",
1439 ERROR + ALREADY_EXISTS, qrbuf.QRname);
1444 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1448 newflags = create_room(new_room_name,
1449 new_room_type, new_room_pass, new_room_floor);
1451 /* post a message in Aide> describing the new room */
1452 strncpy(aaa, new_room_name, 255);
1453 strcat(aaa, "> created by ");
1454 strcat(aaa, CC->usersupp.fullname);
1455 if (newflags & QR_MAILBOX)
1456 strcat(aaa, " [personal]");
1457 else if (newflags & QR_PRIVATE)
1458 strcat(aaa, " [private]");
1459 if (newflags & QR_GUESSNAME)
1460 strcat(aaa, "[guessname] ");
1461 if (newflags & QR_PASSWORDED) {
1462 strcat(aaa, "\n Password: ");
1463 strcat(aaa, new_room_pass);
1467 cprintf("%d '%s' has been created.\n", OK, qrbuf.QRname);
1472 void cmd_einf(char *ok)
1473 { /* enter info file for current room */
1475 char infofilename[256];
1478 if (!(CC->logged_in)) {
1479 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1482 if (!is_room_aide()) {
1483 cprintf("%d Higher access required.\n",
1484 ERROR + HIGHER_ACCESS_REQUIRED);
1487 if (atoi(ok) == 0) {
1488 cprintf("%d Ok.\n", OK);
1491 assoc_file_name(infofilename, &CC->quickroom, "info");
1492 lprintf(9, "opening\n");
1493 fp = fopen(infofilename, "w");
1494 lprintf(9, "checking\n");
1496 cprintf("%d Cannot open %s: %s\n",
1497 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1500 cprintf("%d Send info...\n", SEND_LISTING);
1504 if (strcmp(buf, "000"))
1505 fprintf(fp, "%s\n", buf);
1506 } while (strcmp(buf, "000"));
1509 /* now update the room index so people will see our new info */
1510 lgetroom(&CC->quickroom, CC->quickroom.QRname); /* lock so no one steps on us */
1511 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1512 lputroom(&CC->quickroom);
1517 * cmd_lflr() - List all known floors
1524 if (!(CC->logged_in)) {
1525 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1528 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1529 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1534 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1536 for (a = 0; a < MAXFLOORS; ++a) {
1537 getfloor(&flbuf, a);
1538 if (flbuf.f_flags & F_INUSE) {
1539 cprintf("%d|%s|%d\n",
1551 * create a new floor
1553 void cmd_cflr(char *argbuf)
1555 char new_floor_name[256];
1558 int free_slot = (-1);
1561 extract(new_floor_name, argbuf, 0);
1562 cflr_ok = extract_int(argbuf, 1);
1565 if (!(CC->logged_in)) {
1566 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1569 if (CC->usersupp.axlevel < 6) {
1570 cprintf("%d You need higher access to create rooms.\n",
1571 ERROR + HIGHER_ACCESS_REQUIRED);
1574 for (a = 0; a < MAXFLOORS; ++a) {
1575 getfloor(&flbuf, a);
1577 /* note any free slots while we're scanning... */
1578 if (((flbuf.f_flags & F_INUSE) == 0)
1582 /* check to see if it already exists */
1583 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1584 && (flbuf.f_flags & F_INUSE)) {
1585 cprintf("%d Floor '%s' already exists.\n",
1586 ERROR + ALREADY_EXISTS,
1592 if (free_slot < 0) {
1593 cprintf("%d There is no space available for a new floor.\n",
1594 ERROR + INVALID_FLOOR_OPERATION);
1598 cprintf("%d ok to create...\n", OK);
1601 lgetfloor(&flbuf, free_slot);
1602 flbuf.f_flags = F_INUSE;
1603 flbuf.f_ref_count = 0;
1604 strncpy(flbuf.f_name, new_floor_name, 255);
1605 lputfloor(&flbuf, free_slot);
1606 cprintf("%d %d\n", OK, free_slot);
1614 void cmd_kflr(char *argbuf)
1617 int floor_to_delete;
1621 floor_to_delete = extract_int(argbuf, 0);
1622 kflr_ok = extract_int(argbuf, 1);
1625 if (!(CC->logged_in)) {
1626 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1629 if (CC->usersupp.axlevel < 6) {
1630 cprintf("%d You need higher access to delete floors.\n",
1631 ERROR + HIGHER_ACCESS_REQUIRED);
1634 lgetfloor(&flbuf, floor_to_delete);
1637 if ((flbuf.f_flags & F_INUSE) == 0) {
1638 cprintf("%d Floor %d not in use.\n",
1639 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1642 if (flbuf.f_ref_count != 0) {
1643 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1644 ERROR + INVALID_FLOOR_OPERATION,
1649 cprintf("%d Ok\n", OK);
1651 cprintf("%d Ok to delete...\n", OK);
1658 if ((delete_ok == 1) && (kflr_ok == 1))
1660 lputfloor(&flbuf, floor_to_delete);
1666 void cmd_eflr(char *argbuf)
1672 np = num_parms(argbuf);
1674 cprintf("%d Usage error.\n", ERROR);
1677 if (!(CC->logged_in)) {
1678 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1681 if (CC->usersupp.axlevel < 6) {
1682 cprintf("%d You need higher access to edit floors.\n",
1683 ERROR + HIGHER_ACCESS_REQUIRED);
1686 floor_num = extract_int(argbuf, 0);
1687 lgetfloor(&flbuf, floor_num);
1688 if ((flbuf.f_flags & F_INUSE) == 0) {
1689 lputfloor(&flbuf, floor_num);
1690 cprintf("%d Floor %d is not in use.\n",
1691 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1695 extract(flbuf.f_name, argbuf, 1);
1696 lputfloor(&flbuf, floor_num);
1698 cprintf("%d Ok\n", OK);