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);
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]);
780 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
783 new_messages, total_messages,
784 info, CC->quickroom.QRflags,
785 CC->quickroom.QRhighest,
787 rmailflag, raideflag, newmailcount,
788 CC->quickroom.QRfloor);
790 set_wtmpsupp_to_current_room();
795 * cmd_goto() - goto a new room
797 void cmd_goto(char *gargs)
799 struct quickroom QRscratch;
803 char augmented_roomname[256];
807 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
808 cprintf("%d not logged in\n", ERROR + NOT_LOGGED_IN);
812 extract(towhere, gargs, 0);
813 extract(password, gargs, 1);
815 getuser(&CC->usersupp, CC->curr_user);
817 if (!strcasecmp(towhere, "_BASEROOM_"))
818 strcpy(towhere, BASEROOM);
820 if (!strcasecmp(towhere, "_MAIL_"))
821 strcpy(towhere, MAILROOM);
823 if (!strcasecmp(towhere, "_BITBUCKET_"))
824 strcpy(towhere, config.c_twitroom);
827 /* First try a regular match */
828 c = getroom(&QRscratch, towhere);
830 /* Then try a mailbox name match */
832 MailboxName(augmented_roomname, &CC->usersupp, towhere);
833 c = getroom(&QRscratch, augmented_roomname);
835 strcpy(towhere, augmented_roomname);
838 /* And if the room was found... */
841 /* let internal programs go directly to any room */
842 if (CC->internal_pgm) {
843 usergoto(towhere, 1);
847 /* See if there is an existing user/room relationship */
848 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
850 /* normal clients have to pass through security */
851 if (ra & UA_GOTOALLOWED)
855 if ((QRscratch.QRflags & QR_PASSWORDED) &&
856 ((ra & UA_KNOWN) == 0) &&
857 (strcasecmp(QRscratch.QRpasswd, password))
859 cprintf("%d wrong or missing passwd\n",
860 ERROR + PASSWORD_REQUIRED);
862 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
863 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
864 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
865 ((ra & UA_KNOWN) == 0)) {
868 usergoto(towhere, 1);
874 NOPE: cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
880 struct usersupp temp;
881 struct cdbdata *cdbus;
883 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
884 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
887 getuser(&CC->usersupp, CC->curr_user);
889 if ((!is_room_aide()) && (!(CC->internal_pgm))) {
890 cprintf("%d Higher access required.\n",
891 ERROR + HIGHER_ACCESS_REQUIRED);
894 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
895 cdb_rewind(CDB_USERSUPP);
896 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
897 memset(&temp, 0, sizeof(struct usersupp));
898 memcpy(&temp, cdbus->ptr, cdbus->len);
901 if ((CC->quickroom.QRflags & QR_INUSE)
902 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
904 cprintf("%s\n", temp.fullname);
911 * RDIR command for room directory
921 if (!(CC->logged_in)) {
922 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
925 getroom(&CC->quickroom, CC->quickroom.QRname);
926 getuser(&CC->usersupp, CC->curr_user);
928 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
929 cprintf("%d not here.\n", ERROR + NOT_HERE);
932 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
933 && (CC->usersupp.axlevel < 6)
934 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
935 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
938 cprintf("%d %s|%s/files/%s\n",
939 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->quickroom.QRdirname);
941 sprintf(buf, "cd %s/files/%s; ls >%s 2>/dev/null",
942 BBSDIR, CC->quickroom.QRdirname, CC->temp);
945 sprintf(buf, "%s/files/%s/filedir", BBSDIR, CC->quickroom.QRdirname);
946 fd = fopen(buf, "r");
948 fd = fopen("/dev/null", "r");
950 ls = fopen(CC->temp, "r");
951 while (fgets(flnm, 256, ls) != NULL) {
952 flnm[strlen(flnm) - 1] = 0;
953 if (strcasecmp(flnm, "filedir")) {
954 sprintf(buf, "%s/files/%s/%s",
955 BBSDIR, CC->quickroom.QRdirname, flnm);
959 while ((fgets(buf, 256, fd) != NULL)
960 && (strlen(comment) == 0)) {
961 buf[strlen(buf) - 1] = 0;
962 if ((!strncasecmp(buf, flnm, strlen(flnm)))
963 && (buf[strlen(flnm)] == ' '))
965 &buf[strlen(flnm) + 1], 255);
967 cprintf("%s|%ld|%s\n", flnm, statbuf.st_size, comment);
978 * get room parameters (aide or room aide command)
982 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
983 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
986 if ((!is_room_aide()) && (!(CC->internal_pgm))) {
987 cprintf("%d Higher access required.\n",
988 ERROR + HIGHER_ACCESS_REQUIRED);
991 if (is_noneditable(&CC->quickroom)) {
992 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
995 getroom(&CC->quickroom, CC->quickroom.QRname);
996 cprintf("%d%c%s|%s|%s|%d|%d|%d\n",
998 CC->quickroom.QRname,
999 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
1000 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
1001 CC->quickroom.QRflags,
1002 (int) CC->quickroom.QRfloor,
1003 (int) CC->quickroom.QRorder);
1008 * set room parameters (aide or room aide command)
1010 void cmd_setr(char *args)
1014 char old_name[ROOMNAMELEN];
1018 if (!(CC->logged_in)) {
1019 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1022 if (!is_room_aide()) {
1023 cprintf("%d Higher access required.\n",
1024 ERROR + HIGHER_ACCESS_REQUIRED);
1027 if (is_noneditable(&CC->quickroom)) {
1028 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1031 if (num_parms(args) >= 6) {
1032 getfloor(&flbuf, extract_int(args, 5));
1033 if ((flbuf.f_flags & F_INUSE) == 0) {
1034 cprintf("%d Invalid floor number.\n",
1035 ERROR + INVALID_FLOOR_OPERATION);
1039 if (num_parms(args) >= 7) {
1040 new_order = extract_int(args, 6);
1043 if (new_order > 127)
1046 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1047 strcpy(old_name, CC->quickroom.QRname);
1048 extract(buf, args, 0);
1049 buf[ROOMNAMELEN] = 0;
1050 strncpy(CC->quickroom.QRname, buf, ROOMNAMELEN - 1);
1051 extract(buf, args, 1);
1053 strncpy(CC->quickroom.QRpasswd, buf, 9);
1054 extract(buf, args, 2);
1056 strncpy(CC->quickroom.QRdirname, buf, 19);
1057 CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
1058 if (num_parms(args) >= 7)
1059 CC->quickroom.QRorder = (char) new_order;
1061 /* Clean up a client boo-boo: if the client set the room to
1062 * guess-name or passworded, ensure that the private flag is
1065 if ((CC->quickroom.QRflags & QR_GUESSNAME)
1066 || (CC->quickroom.QRflags & QR_PASSWORDED))
1067 CC->quickroom.QRflags |= QR_PRIVATE;
1069 /* Kick everyone out if the client requested it (by changing the
1070 * room's generation number)
1072 if (extract_int(args, 4)) {
1073 time(&CC->quickroom.QRgen);
1075 old_floor = CC->quickroom.QRfloor;
1076 if (num_parms(args) >= 6) {
1077 CC->quickroom.QRfloor = extract_int(args, 5);
1079 /* Write the room record back to disk */
1080 lputroom(&CC->quickroom);
1082 /* If the room name changed, then there are now two room records,
1083 * so we have to delete the old one.
1085 if (strcasecmp(CC->quickroom.QRname, old_name)) {
1086 b_deleteroom(old_name);
1088 /* adjust the floor reference counts */
1089 lgetfloor(&flbuf, old_floor);
1090 --flbuf.f_ref_count;
1091 lputfloor(&flbuf, old_floor);
1092 lgetfloor(&flbuf, CC->quickroom.QRfloor);
1093 ++flbuf.f_ref_count;
1094 lputfloor(&flbuf, CC->quickroom.QRfloor);
1096 /* create a room directory if necessary */
1097 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1099 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1100 CC->quickroom.QRdirname);
1103 sprintf(buf, "%s> edited by %s", CC->quickroom.QRname, CC->curr_user);
1105 cprintf("%d Ok\n", OK);
1111 * get the name of the room aide for this room
1115 struct usersupp usbuf;
1117 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
1118 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1121 if (is_noneditable(&CC->quickroom)) {
1122 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1125 if (getuserbynumber(&usbuf, CC->quickroom.QRroomaide) == 0) {
1126 cprintf("%d %s\n", OK, usbuf.fullname);
1128 cprintf("%d \n", OK);
1134 * set the room aide for this room
1136 void cmd_seta(char *new_ra)
1138 struct usersupp usbuf;
1143 if (!(CC->logged_in)) {
1144 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1147 if (!is_room_aide()) {
1148 cprintf("%d Higher access required.\n",
1149 ERROR + HIGHER_ACCESS_REQUIRED);
1152 if (getuser(&usbuf, new_ra) != 0) {
1155 newu = usbuf.usernum;
1158 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1160 if (CC->quickroom.QRroomaide != newu) {
1163 CC->quickroom.QRroomaide = newu;
1164 lputroom(&CC->quickroom);
1167 * We have to post the change notice _after_ writing changes to
1168 * the room table, otherwise it would deadlock!
1170 if (post_notice == 1) {
1171 sprintf(buf, "%s is now room aide for %s>",
1172 usbuf.fullname, CC->quickroom.QRname);
1175 cprintf("%d Ok\n", OK);
1179 * Generate an associated file name for a room
1181 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix)
1183 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1187 * retrieve info file for this room
1195 assoc_file_name(filename, &CC->quickroom, "info");
1196 info_fp = fopen(filename, "r");
1198 if (info_fp == NULL) {
1199 cprintf("%d No info file.\n", ERROR);
1202 cprintf("%d Info:\n", LISTING_FOLLOWS);
1203 while (fgets(buf, 256, info_fp) != NULL) {
1204 if (strlen(buf) > 0)
1205 buf[strlen(buf) - 1] = 0;
1206 cprintf("%s\n", buf);
1213 * Back end processing to delete a room and everything associated with it
1215 void delete_room(struct quickroom *qrbuf)
1222 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1224 /* Delete the info file */
1225 assoc_file_name(aaa, qrbuf, "info");
1228 /* Delete the image file */
1229 assoc_file_name(aaa, qrbuf, "images");
1232 /* first flag the room record as not in use */
1233 lgetroom(qrbuf, qrbuf->QRname);
1236 /* then delete the messages in the room */
1238 if (CC->num_msgs > 0)
1239 for (a = 0; a < CC->num_msgs; ++a) {
1240 MsgToDelete = MessageFromList(a);
1241 AdjRefCount(MsgToDelete, -1);
1247 delete_msglist(qrbuf);
1250 /* then decrement the reference count for the floor */
1251 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1252 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1253 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1255 /* Delete the room record from the database! */
1256 b_deleteroom(qrbuf->QRname);
1261 * aide command: kill the current room
1263 void cmd_kill(char *argbuf)
1266 char deleted_room_name[ROOMNAMELEN];
1269 kill_ok = extract_int(argbuf, 0);
1271 if (!(CC->logged_in)) {
1272 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1275 if (!is_room_aide()) {
1276 cprintf("%d Higher access required.\n",
1277 ERROR + HIGHER_ACCESS_REQUIRED);
1280 if (is_noneditable(&CC->quickroom)) {
1281 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1285 strcpy(deleted_room_name, CC->quickroom.QRname);
1286 delete_room(&CC->quickroom); /* Do the dirty work */
1287 usergoto(BASEROOM, 0); /* Return to the Lobby */
1289 /* tell the world what we did */
1290 sprintf(aaa, "%s> killed by %s",
1291 deleted_room_name, CC->curr_user);
1293 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1295 cprintf("%d ok to delete.\n", OK);
1301 * Internal code to create a new room (returns room flags)
1303 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1305 unsigned create_room(char *new_room_name,
1307 char *new_room_pass,
1311 struct quickroom qrbuf;
1315 if (getroom(&qrbuf, new_room_name) == 0)
1316 return (0); /* already exists */
1318 memset(&qrbuf, 0, sizeof(struct quickroom));
1319 strncpy(qrbuf.QRname, new_room_name, ROOMNAMELEN);
1320 strncpy(qrbuf.QRpasswd, new_room_pass, 9);
1321 qrbuf.QRflags = QR_INUSE;
1322 qrbuf.QRnumber = get_new_room_number();
1323 if (new_room_type > 0)
1324 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1325 if (new_room_type == 1)
1326 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1327 if (new_room_type == 2)
1328 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1329 if (new_room_type == 4)
1330 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1332 /* If the room is private, and the system administrator has elected
1333 * to automatically grant room aide privileges, do so now; otherwise,
1334 * set the room aide to undefined.
1336 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1337 qrbuf.QRroomaide = CC->usersupp.usernum;
1339 qrbuf.QRroomaide = (-1L);
1342 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1343 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1344 qrbuf.QRfloor = new_room_floor;
1346 /* save what we just did... */
1349 /* bump the reference count on whatever floor the room is on */
1350 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1351 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1352 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1354 /* be sure not to kick the creator out of the room! */
1355 lgetuser(&CC->usersupp, CC->curr_user);
1356 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1357 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1358 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1359 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1360 lputuser(&CC->usersupp);
1362 /* resume our happy day */
1363 return (qrbuf.QRflags);
1370 void cmd_cre8(char *args)
1373 char new_room_name[256];
1375 char new_room_pass[256];
1379 struct quickroom qrbuf;
1382 cre8_ok = extract_int(args, 0);
1383 extract(new_room_name, args, 1);
1384 new_room_name[ROOMNAMELEN - 1] = 0;
1385 new_room_type = extract_int(args, 2);
1386 extract(new_room_pass, args, 3);
1387 new_room_pass[9] = 0;
1390 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1391 cprintf("%d Invalid room name.\n", ERROR);
1395 if (!strcasecmp(new_room_name, MAILROOM)) {
1396 cprintf("%d '%s' already exists.\n",
1397 ERROR + ALREADY_EXISTS, new_room_name);
1401 if (num_parms(args) >= 5) {
1402 getfloor(&flbuf, extract_int(args, 4));
1403 if ((flbuf.f_flags & F_INUSE) == 0) {
1404 cprintf("%d Invalid floor number.\n",
1405 ERROR + INVALID_FLOOR_OPERATION);
1408 new_room_floor = extract_int(args, 4);
1412 if (!(CC->logged_in)) {
1413 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1417 if (CC->usersupp.axlevel < config.c_createax) {
1418 cprintf("%d You need higher access to create rooms.\n",
1419 ERROR + HIGHER_ACCESS_REQUIRED);
1423 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1424 cprintf("%d Ok to create rooms.\n", OK);
1428 if ((new_room_type < 0) || (new_room_type > 4)) {
1429 cprintf("%d Invalid room type.\n", ERROR);
1433 /* If the user is requesting a personal room, set up the room
1434 * name accordingly (prepend the user number)
1436 if (new_room_type == 4) {
1437 sprintf(aaa, "%010ld.%s",
1438 CC->usersupp.usernum, new_room_name);
1439 strcpy(new_room_name, aaa);
1442 /* Check to make sure the requested room name doesn't already exist */
1443 if (getroom(&qrbuf, new_room_name) == 0) {
1444 cprintf("%d '%s' already exists.\n",
1445 ERROR + ALREADY_EXISTS, qrbuf.QRname);
1450 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1454 newflags = create_room(new_room_name,
1455 new_room_type, new_room_pass, new_room_floor);
1457 /* post a message in Aide> describing the new room */
1458 strncpy(aaa, new_room_name, 255);
1459 strcat(aaa, "> created by ");
1460 strcat(aaa, CC->usersupp.fullname);
1461 if (newflags & QR_MAILBOX)
1462 strcat(aaa, " [personal]");
1463 else if (newflags & QR_PRIVATE)
1464 strcat(aaa, " [private]");
1465 if (newflags & QR_GUESSNAME)
1466 strcat(aaa, "[guessname] ");
1467 if (newflags & QR_PASSWORDED) {
1468 strcat(aaa, "\n Password: ");
1469 strcat(aaa, new_room_pass);
1473 cprintf("%d '%s' has been created.\n", OK, qrbuf.QRname);
1478 void cmd_einf(char *ok)
1479 { /* enter info file for current room */
1481 char infofilename[256];
1484 if (!(CC->logged_in)) {
1485 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1488 if (!is_room_aide()) {
1489 cprintf("%d Higher access required.\n",
1490 ERROR + HIGHER_ACCESS_REQUIRED);
1493 if (atoi(ok) == 0) {
1494 cprintf("%d Ok.\n", OK);
1497 assoc_file_name(infofilename, &CC->quickroom, "info");
1498 lprintf(9, "opening\n");
1499 fp = fopen(infofilename, "w");
1500 lprintf(9, "checking\n");
1502 cprintf("%d Cannot open %s: %s\n",
1503 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1506 cprintf("%d Send info...\n", SEND_LISTING);
1510 if (strcmp(buf, "000"))
1511 fprintf(fp, "%s\n", buf);
1512 } while (strcmp(buf, "000"));
1515 /* now update the room index so people will see our new info */
1516 lgetroom(&CC->quickroom, CC->quickroom.QRname); /* lock so no one steps on us */
1517 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1518 lputroom(&CC->quickroom);
1523 * cmd_lflr() - List all known floors
1530 if (!(CC->logged_in)) {
1531 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1534 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1535 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1540 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1542 for (a = 0; a < MAXFLOORS; ++a) {
1543 getfloor(&flbuf, a);
1544 if (flbuf.f_flags & F_INUSE) {
1545 cprintf("%d|%s|%d\n",
1557 * create a new floor
1559 void cmd_cflr(char *argbuf)
1561 char new_floor_name[256];
1564 int free_slot = (-1);
1567 extract(new_floor_name, argbuf, 0);
1568 cflr_ok = extract_int(argbuf, 1);
1571 if (!(CC->logged_in)) {
1572 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1575 if (CC->usersupp.axlevel < 6) {
1576 cprintf("%d You need higher access to create rooms.\n",
1577 ERROR + HIGHER_ACCESS_REQUIRED);
1580 for (a = 0; a < MAXFLOORS; ++a) {
1581 getfloor(&flbuf, a);
1583 /* note any free slots while we're scanning... */
1584 if (((flbuf.f_flags & F_INUSE) == 0)
1588 /* check to see if it already exists */
1589 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1590 && (flbuf.f_flags & F_INUSE)) {
1591 cprintf("%d Floor '%s' already exists.\n",
1592 ERROR + ALREADY_EXISTS,
1598 if (free_slot < 0) {
1599 cprintf("%d There is no space available for a new floor.\n",
1600 ERROR + INVALID_FLOOR_OPERATION);
1604 cprintf("%d ok to create...\n", OK);
1607 lgetfloor(&flbuf, free_slot);
1608 flbuf.f_flags = F_INUSE;
1609 flbuf.f_ref_count = 0;
1610 strncpy(flbuf.f_name, new_floor_name, 255);
1611 lputfloor(&flbuf, free_slot);
1612 cprintf("%d %d\n", OK, free_slot);
1620 void cmd_kflr(char *argbuf)
1623 int floor_to_delete;
1627 floor_to_delete = extract_int(argbuf, 0);
1628 kflr_ok = extract_int(argbuf, 1);
1631 if (!(CC->logged_in)) {
1632 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1635 if (CC->usersupp.axlevel < 6) {
1636 cprintf("%d You need higher access to delete floors.\n",
1637 ERROR + HIGHER_ACCESS_REQUIRED);
1640 lgetfloor(&flbuf, floor_to_delete);
1643 if ((flbuf.f_flags & F_INUSE) == 0) {
1644 cprintf("%d Floor %d not in use.\n",
1645 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1648 if (flbuf.f_ref_count != 0) {
1649 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1650 ERROR + INVALID_FLOOR_OPERATION,
1655 cprintf("%d Ok\n", OK);
1657 cprintf("%d Ok to delete...\n", OK);
1664 if ((delete_ok == 1) && (kflr_ok == 1))
1666 lputfloor(&flbuf, floor_to_delete);
1672 void cmd_eflr(char *argbuf)
1678 np = num_parms(argbuf);
1680 cprintf("%d Usage error.\n", ERROR);
1683 if (!(CC->logged_in)) {
1684 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1687 if (CC->usersupp.axlevel < 6) {
1688 cprintf("%d You need higher access to edit floors.\n",
1689 ERROR + HIGHER_ACCESS_REQUIRED);
1692 floor_num = extract_int(argbuf, 0);
1693 lgetfloor(&flbuf, floor_num);
1694 if ((flbuf.f_flags & F_INUSE) == 0) {
1695 lputfloor(&flbuf, floor_num);
1696 cprintf("%d Floor %d is not in use.\n",
1697 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1701 extract(flbuf.f_name, argbuf, 1);
1702 lputfloor(&flbuf, floor_num);
1704 cprintf("%d Ok\n", OK);