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) {
35 /* for internal programs, always do everything */
36 if (((CC->internal_pgm))&&(roombuf->QRflags & QR_INUSE)) {
37 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)) {
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;
61 /* For mailboxes, we skip all the access stuff (and we've
62 * already checked by this point that the mailbox belongs
65 if (roombuf->QRflags & QR_MAILBOX) {
66 retval = UA_KNOWN | UA_GOTOALLOWED;
70 /* If this is a public room, it's accessible... */
71 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
72 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
75 /* If this is a preferred users only room, check access level */
76 if (roombuf->QRflags & QR_PREFONLY) {
77 if (userbuf->axlevel < 5) {
78 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
82 /* For private rooms, check the generation number matchups */
83 if (roombuf->QRflags & QR_PRIVATE) {
85 /* An explicit match means the user belongs in this room */
86 if (vbuf.v_flags & V_ACCESS) {
87 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
89 /* Otherwise, check if this is a guess-name or passworded
90 * room. If it is, a goto may at least be attempted
92 else if ((roombuf->QRflags & QR_PRIVATE)
93 ||(roombuf->QRflags & QR_PASSWORDED)) {
94 retval = retval & ~UA_KNOWN;
95 retval = retval | UA_GOTOALLOWED;
99 /* Check to see if the user has forgotten this room */
100 if (vbuf.v_flags & V_FORGET) {
101 retval = retval & ~UA_KNOWN;
102 retval = retval | UA_ZAPPED;
105 /* If user is explicitly locked out of this room, deny everything */
106 if (vbuf.v_flags & V_LOCKOUT) {
107 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
110 /* Aides get access to everything */
111 if (userbuf->axlevel >= 6) {
112 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
113 retval = retval & ~UA_ZAPPED;
116 NEWMSG: /* By the way, we also check for the presence of new messages */
117 if ( (roombuf->QRhighest) > (vbuf.v_lastseen) ) {
118 retval = retval | UA_HASNEWMSGS;
125 * Self-checking stuff for a room record read into memory
127 void room_sanity_check(struct quickroom *qrbuf) {
128 /* Mailbox rooms are always on the lowest floor */
129 if (qrbuf->QRflags & QR_MAILBOX) {
133 /* Listing order of 0 is illegal except for base rooms */
134 if (qrbuf->QRorder == 0)
135 if (!is_noneditable(qrbuf))
141 * getroom() - retrieve room data from disk
143 int getroom(struct quickroom *qrbuf, char *room_name)
145 struct cdbdata *cdbqr;
146 char lowercase_name[ROOMNAMELEN];
149 for (a=0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
150 lowercase_name[a] = tolower(room_name[a]);
152 lowercase_name[a] = 0;
154 memset(qrbuf, 0, sizeof(struct quickroom));
155 cdbqr = cdb_fetch(CDB_QUICKROOM,
156 lowercase_name, strlen(lowercase_name));
158 memcpy(qrbuf, cdbqr->ptr,
159 ( (cdbqr->len > sizeof(struct quickroom)) ?
160 sizeof(struct quickroom) : cdbqr->len) );
163 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 * putroom() - store room data on disk
184 * (if the supplied buffer is NULL, delete the room record)
186 void 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));
200 time(&qrbuf->QRmtime);
201 cdb_store(CDB_QUICKROOM,
202 lowercase_name, strlen(lowercase_name),
203 qrbuf, sizeof(struct quickroom));
209 * lputroom() - same as putroom() but unlocks the record (if supported)
211 void lputroom(struct quickroom *qrbuf, char *room_name)
214 putroom(qrbuf, room_name);
215 end_critical_section(S_QUICKROOM);
219 /****************************************************************************/
222 * getfloor() - retrieve floor data from disk
224 void getfloor(struct floor *flbuf, int floor_num)
226 struct cdbdata *cdbfl;
228 memset(flbuf, 0, sizeof(struct floor));
229 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
231 memcpy(flbuf, cdbfl->ptr,
232 ( (cdbfl->len > sizeof(struct floor)) ?
233 sizeof(struct floor) : cdbfl->len) );
237 if (floor_num == 0) {
238 strcpy(flbuf->f_name, "Main Floor");
239 flbuf->f_flags = F_INUSE;
240 flbuf->f_ref_count = 3;
247 * lgetfloor() - same as getfloor() but locks the record (if supported)
249 void lgetfloor(struct floor *flbuf, int floor_num)
252 begin_critical_section(S_FLOORTAB);
253 getfloor(flbuf,floor_num);
258 * putfloor() - store floor data on disk
260 void putfloor(struct floor *flbuf, int floor_num)
262 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
263 flbuf, sizeof(struct floor));
268 * lputfloor() - same as putfloor() but unlocks the record (if supported)
270 void lputfloor(struct floor *flbuf, int floor_num)
273 putfloor(flbuf,floor_num);
274 end_critical_section(S_FLOORTAB);
280 * Traverse the room file...
282 void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) {
283 struct quickroom qrbuf;
284 struct cdbdata *cdbqr;
286 cdb_rewind(CDB_QUICKROOM);
288 while(cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
289 memset(&qrbuf, 0, sizeof(struct quickroom));
290 memcpy(&qrbuf, cdbqr->ptr,
291 ( (cdbqr->len > sizeof(struct quickroom)) ?
292 sizeof(struct quickroom) : cdbqr->len) );
294 room_sanity_check(&qrbuf);
295 if (qrbuf.QRflags & QR_INUSE) (*CallBack)(&qrbuf);
302 * get_msglist() - retrieve room message pointers
304 void get_msglist(struct quickroom *whichroom) {
305 struct cdbdata *cdbfr;
307 if (CC->msglist != NULL) {
313 cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
318 CC->msglist = mallok(cdbfr->len);
319 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
320 CC->num_msgs = cdbfr->len / sizeof(long);
326 * put_msglist() - retrieve room message pointers
328 void put_msglist(struct quickroom *whichroom) {
330 if (CC->msglist != NULL)
331 cdb_store(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long),
332 CC->msglist, CC->num_msgs * sizeof(long));
337 * delete_msglist() - delete room message pointers
338 * FIX - this really should check first to make sure there's actually a
339 * msglist to delete. As things stand now, calling this function on
340 * a room which has never been posted in will result in a message
341 * like "gdbm: illegal data" (no big deal, but could use fixing).
343 void delete_msglist(struct quickroom *whichroom) {
345 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
350 * Add a message number to a room's message list.
351 * So, why doesn't this function use the get_msglist() and put_msglist() stuff
352 * defined above? Because the room the message number is being written to
353 * may not be the current room (as is the case with cmd_move() for example).
355 * This function returns the highest message number present in the room after
356 * the add operation is performed - which is not necessarily the message
359 long AddMessageToRoom(struct quickroom *whichroom, long newmsgid) {
360 struct cdbdata *cdbfr;
363 long highest_msg = 0L;
365 cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
371 msglist = mallok(cdbfr->len);
372 num_msgs = cdbfr->len / sizeof(long);
373 memcpy(msglist, cdbfr->ptr, cdbfr->len);
377 /* Now add the new message */
379 msglist = reallok(msglist,
380 (num_msgs * sizeof(long)) );
382 if (msglist == NULL) {
383 lprintf(3, "ERROR: can't realloc message list!\n");
386 msglist[num_msgs - 1] = newmsgid;
388 /* Sort the message list, so all the msgid's are in order */
389 num_msgs = sort_msglist(msglist, num_msgs);
391 /* Determine the highest message number */
392 highest_msg = msglist[num_msgs - 1];
394 /* Write it back to disk. */
395 cdb_store(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long),
396 msglist, num_msgs * sizeof(long));
398 /* And finally, free up the memory we used. */
405 * MessageFromList() - get a message number from the list currently in memory
407 long MessageFromList(int whichpos) {
409 /* Return zero if the position is invalid */
410 if (whichpos >= CC->num_msgs) return 0L;
412 return(CC->msglist[whichpos]);
416 * SetMessageInList() - set a message number in the list currently in memory
418 void SetMessageInList(int whichpos, long newmsgnum) {
420 /* Return zero if the position is invalid */
421 if (whichpos >= CC->num_msgs) return;
423 CC->msglist[whichpos] = newmsgnum;
429 * sort message pointers
430 * (returns new msg count)
432 int sort_msglist(long listptrs[], int oldcount)
439 if (numitems < 2) return(oldcount);
442 for (a=numitems-2; a>=0; --a) {
443 for (b=0; b<=a; ++b) {
444 if (listptrs[b] > (listptrs[b+1])) {
446 hold2 = listptrs[b+1];
448 listptrs[b+1] = hold1;
453 /* and yank any nulls */
454 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
455 memcpy(&listptrs[0], &listptrs[1],
456 (sizeof(long) * (CC->num_msgs - 1)) );
465 * Determine whether a given room is non-editable.
467 int is_noneditable(struct quickroom *qrbuf) {
469 /* Lobby> and Aide> are non-editable */
470 if (!strcasecmp(qrbuf->QRname, BASEROOM)) return(1);
471 else if (!strcasecmp(qrbuf->QRname, AIDEROOM)) return(1);
473 /* Mailbox rooms are also non-editable */
474 else if (qrbuf->QRflags & QR_MAILBOX) return(1);
476 /* Everything else is editable */
483 * Back-back-end for all room listing commands
485 void list_roomname(struct quickroom *qrbuf) {
486 char truncated_roomname[ROOMNAMELEN];
488 /* For mailbox rooms, chop off the owner prefix */
489 if (qrbuf->QRflags & QR_MAILBOX) {
490 strcpy(truncated_roomname, qrbuf->QRname);
491 strcpy(truncated_roomname, &truncated_roomname[11]);
492 cprintf("%s", truncated_roomname);
494 /* For all other rooms, just display the name in its entirety */
496 cprintf("%s", qrbuf->QRname);
499 /* ...and now the other parameters */
500 cprintf("|%u|%d|%d\n",
503 (int)qrbuf->QRorder);
508 * cmd_lrms() - List all accessible rooms, known or forgotten
510 void cmd_lrms_backend(struct quickroom *qrbuf) {
511 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
512 & (UA_KNOWN | UA_ZAPPED)))
513 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
514 ||((CC->FloorBeingSearched)<0)) )
515 list_roomname(qrbuf);
518 void cmd_lrms(char *argbuf)
520 CC->FloorBeingSearched = (-1);
521 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
523 if (!(CC->logged_in)) {
524 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
528 if (getuser(&CC->usersupp,CC->curr_user)) {
529 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
533 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
535 ForEachRoom(cmd_lrms_backend);
542 * cmd_lkra() - List all known rooms
544 void cmd_lkra_backend(struct quickroom *qrbuf) {
545 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
547 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
548 ||((CC->FloorBeingSearched)<0)) )
549 list_roomname(qrbuf);
552 void cmd_lkra(char *argbuf)
554 CC->FloorBeingSearched = (-1);
555 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
557 if (!(CC->logged_in)) {
558 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);
567 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
569 ForEachRoom(cmd_lkra_backend);
576 * cmd_lkrn() - List all known rooms with new messages
578 void cmd_lkrn_backend(struct quickroom *qrbuf) {
581 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
583 && (ra & UA_HASNEWMSGS)
584 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
585 ||((CC->FloorBeingSearched)<0)) )
586 list_roomname(qrbuf);
589 void cmd_lkrn(char *argbuf)
591 CC->FloorBeingSearched = (-1);
592 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
594 if (!(CC->logged_in)) {
595 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
599 if (getuser(&CC->usersupp,CC->curr_user)) {
600 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
604 cprintf("%d Rooms w/ new msgs:\n",LISTING_FOLLOWS);
606 ForEachRoom(cmd_lkrn_backend);
613 * cmd_lkro() - List all known rooms
615 void cmd_lkro_backend(struct quickroom *qrbuf) {
618 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
620 && ((ra & UA_HASNEWMSGS)==0)
621 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
622 ||((CC->FloorBeingSearched)<0)) )
623 list_roomname(qrbuf);
626 void cmd_lkro(char *argbuf)
628 CC->FloorBeingSearched = (-1);
629 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
631 if (!(CC->logged_in)) {
632 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
636 if (getuser(&CC->usersupp,CC->curr_user)) {
637 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
641 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
643 ForEachRoom(cmd_lkro_backend);
650 * cmd_lzrm() - List all forgotten rooms
652 void cmd_lzrm_backend(struct quickroom *qrbuf) {
655 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
656 if ( (ra & UA_GOTOALLOWED)
658 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
659 ||((CC->FloorBeingSearched)<0)) )
660 list_roomname(qrbuf);
663 void cmd_lzrm(char *argbuf)
665 CC->FloorBeingSearched = (-1);
666 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
668 if (!(CC->logged_in)) {
669 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
673 if (getuser(&CC->usersupp,CC->curr_user)) {
674 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
678 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
680 ForEachRoom(cmd_lzrm_backend);
686 void usergoto(char *where, int display_result)
689 int new_messages = 0;
690 int total_messages = 0;
694 int newmailcount = 0;
696 char truncated_roomname[ROOMNAMELEN];
698 strcpy(CC->quickroom.QRname, where);
699 getroom(&CC->quickroom, where);
701 lgetuser(&CC->usersupp,CC->curr_user);
702 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
704 /* Know the room ... but not if it's the page log room */
705 if (strcasecmp(where, config.c_logpages)) {
706 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
707 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
710 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
711 lputuser(&CC->usersupp,CC->curr_user);
713 /* check for new mail */
714 newmailcount = NewMailCount();
716 /* set info to 1 if the user needs to read the room's info file */
717 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
720 get_msglist(&CC->quickroom);
721 for (a=0; a<CC->num_msgs; ++a) {
722 if (MessageFromList(a)>0L) {
724 if (MessageFromList(a) > vbuf.v_lastseen) {
730 if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1;
733 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
734 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
737 strcpy(truncated_roomname, CC->quickroom.QRname);
738 if (CC->quickroom.QRflags & QR_MAILBOX) {
739 strcpy(truncated_roomname, &truncated_roomname[11]);
742 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
745 new_messages, total_messages,
746 info,CC->quickroom.QRflags,
747 CC->quickroom.QRhighest,
749 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
751 set_wtmpsupp_to_current_room();
756 * cmd_goto() - goto a new room
758 void cmd_goto(char *gargs)
760 struct quickroom QRscratch;
764 char augmented_roomname[256];
768 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
769 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
773 extract(towhere,gargs,0);
774 extract(password,gargs,1);
776 getuser(&CC->usersupp, CC->curr_user);
778 if (!strcasecmp(towhere, "_BASEROOM_"))
779 strcpy(towhere, BASEROOM);
781 if (!strcasecmp(towhere, "_MAIL_"))
782 strcpy(towhere, MAILROOM);
784 if (!strcasecmp(towhere, "_BITBUCKET_"))
785 strcpy(towhere, config.c_twitroom);
788 /* First try a regular match */
789 c = getroom(&QRscratch, towhere);
791 /* Then try a mailbox name match */
793 MailboxName(augmented_roomname, &CC->usersupp, towhere);
794 c = getroom(&QRscratch, augmented_roomname);
795 if (c == 0) strcpy(towhere, augmented_roomname);
798 /* And if the room was found... */
801 /* let internal programs go directly to any room */
802 if (CC->internal_pgm) {
803 usergoto(towhere, 1);
807 /* See if there is an existing user/room relationship */
808 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
810 /* normal clients have to pass through security */
811 if (ra & UA_GOTOALLOWED) ok = 1;
814 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
815 ((ra & UA_KNOWN) == 0) &&
816 (strcasecmp(QRscratch.QRpasswd,password))
818 cprintf("%d wrong or missing passwd\n",
819 ERROR+PASSWORD_REQUIRED);
822 else if ( (QRscratch.QRflags&QR_PRIVATE) &&
823 ((QRscratch.QRflags&QR_PASSWORDED)==0) &&
824 ((QRscratch.QRflags&QR_GUESSNAME)==0) &&
825 ((ra & UA_KNOWN) == 0) ) {
829 usergoto(towhere, 1);
835 NOPE: cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
839 void cmd_whok(void) {
840 struct usersupp temp;
841 struct cdbdata *cdbus;
843 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
844 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
847 getuser(&CC->usersupp,CC->curr_user);
849 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
850 cprintf("%d Higher access required.\n",
851 ERROR+HIGHER_ACCESS_REQUIRED);
855 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
856 cdb_rewind(CDB_USERSUPP);
857 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
858 memset(&temp, 0, sizeof(struct usersupp));
859 memcpy(&temp, cdbus->ptr, cdbus->len);
862 if ( (CC->quickroom.QRflags & QR_INUSE)
863 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
864 ) cprintf("%s\n",temp.fullname);
871 * RDIR command for room directory
873 void cmd_rdir(void) {
880 if (!(CC->logged_in)) {
881 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
885 getroom(&CC->quickroom, CC->quickroom.QRname);
886 getuser(&CC->usersupp, CC->curr_user);
888 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
889 cprintf("%d not here.\n",ERROR+NOT_HERE);
893 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
894 && (CC->usersupp.axlevel<6)
895 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
896 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
900 cprintf("%d %s|%s/files/%s\n",
901 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
903 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
904 BBSDIR,CC->quickroom.QRdirname,CC->temp);
907 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
909 if (fd==NULL) fd=fopen("/dev/null","r");
911 ls = fopen(CC->temp,"r");
912 while (fgets(flnm,256,ls)!=NULL) {
913 flnm[strlen(flnm)-1]=0;
914 if (strcasecmp(flnm,"filedir")) {
915 sprintf(buf,"%s/files/%s/%s",
916 BBSDIR,CC->quickroom.QRdirname,flnm);
920 while ((fgets(buf,256,fd)!=NULL)
921 &&(strlen(comment)==0)) {
922 buf[strlen(buf)-1] = 0;
923 if ((!strncasecmp(buf,flnm,strlen(flnm)))
924 && (buf[strlen(flnm)]==' '))
926 &buf[strlen(flnm)+1],255);
928 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
939 * get room parameters (aide or room aide command)
941 void cmd_getr(void) {
942 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
943 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
947 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
948 cprintf("%d Higher access required.\n",
949 ERROR+HIGHER_ACCESS_REQUIRED);
953 if (is_noneditable(&CC->quickroom)) {
954 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
958 getroom(&CC->quickroom, CC->quickroom.QRname);
959 cprintf("%d%c%s|%s|%s|%d|%d|%d\n",
961 CC->quickroom.QRname,
962 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
963 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
964 CC->quickroom.QRflags,
965 (int)CC->quickroom.QRfloor,
966 (int)CC->quickroom.QRorder);
971 * set room parameters (aide or room aide command)
973 void cmd_setr(char *args) {
976 char old_name[ROOMNAMELEN];
980 if (!(CC->logged_in)) {
981 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
985 if (!is_room_aide()) {
986 cprintf("%d Higher access required.\n",
987 ERROR+HIGHER_ACCESS_REQUIRED);
991 if (is_noneditable(&CC->quickroom)) {
992 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
996 if (num_parms(args)>=6) {
997 getfloor(&flbuf,extract_int(args,5));
998 if ((flbuf.f_flags & F_INUSE) == 0) {
999 cprintf("%d Invalid floor number.\n",
1000 ERROR+INVALID_FLOOR_OPERATION);
1005 if (num_parms(args)>=7) {
1006 new_order = extract_int(args, 6);
1007 if (new_order < 1) new_order = 1;
1008 if (new_order > 127) new_order = 127;
1011 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1012 strcpy(old_name, CC->quickroom.QRname);
1013 extract(buf,args,0); buf[ROOMNAMELEN]=0;
1014 strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
1015 extract(buf,args,1); buf[10]=0;
1016 strncpy(CC->quickroom.QRpasswd,buf,9);
1017 extract(buf,args,2); buf[15]=0;
1018 strncpy(CC->quickroom.QRdirname,buf,19);
1019 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
1020 if (num_parms(args)>=7)
1021 CC->quickroom.QRorder = (char)new_order;
1023 /* Clean up a client boo-boo: if the client set the room to
1024 * guess-name or passworded, ensure that the private flag is
1027 if ((CC->quickroom.QRflags & QR_GUESSNAME)
1028 ||(CC->quickroom.QRflags & QR_PASSWORDED))
1029 CC->quickroom.QRflags |= QR_PRIVATE;
1031 /* Kick everyone out if the client requested it (by changing the
1032 * room's generation number)
1034 if (extract_int(args,4)) {
1035 time(&CC->quickroom.QRgen);
1038 old_floor = CC->quickroom.QRfloor;
1039 if (num_parms(args)>=6) {
1040 CC->quickroom.QRfloor = extract_int(args,5);
1043 /* Write the room record back to disk */
1044 lputroom(&CC->quickroom, CC->quickroom.QRname);
1046 /* If the room name changed, then there are now two room records,
1047 * so we have to delete the old one.
1049 if (strcasecmp(CC->quickroom.QRname, old_name)) {
1050 putroom(NULL, old_name);
1053 /* adjust the floor reference counts */
1054 lgetfloor(&flbuf,old_floor);
1055 --flbuf.f_ref_count;
1056 lputfloor(&flbuf,old_floor);
1057 lgetfloor(&flbuf,CC->quickroom.QRfloor);
1058 ++flbuf.f_ref_count;
1059 lputfloor(&flbuf,CC->quickroom.QRfloor);
1061 /* create a room directory if necessary */
1062 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1064 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1065 CC->quickroom.QRdirname);
1069 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
1071 cprintf("%d Ok\n",OK);
1077 * get the name of the room aide for this room
1079 void cmd_geta(void) {
1080 struct usersupp usbuf;
1082 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
1083 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1087 if (is_noneditable(&CC->quickroom)) {
1088 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1092 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
1093 cprintf("%d %s\n",OK,usbuf.fullname);
1096 cprintf("%d \n",OK);
1102 * set the room aide for this room
1104 void cmd_seta(char *new_ra)
1106 struct usersupp usbuf;
1111 if (!(CC->logged_in)) {
1112 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1116 if (!is_room_aide()) {
1117 cprintf("%d Higher access required.\n",
1118 ERROR+HIGHER_ACCESS_REQUIRED);
1122 if (getuser(&usbuf,new_ra)!=0) {
1126 newu = usbuf.usernum;
1129 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1131 if (CC->quickroom.QRroomaide != newu) {
1134 CC->quickroom.QRroomaide = newu;
1135 lputroom(&CC->quickroom, CC->quickroom.QRname);
1138 * We have to post the change notice _after_ writing changes to
1139 * the room table, otherwise it would deadlock!
1141 if (post_notice == 1) {
1142 sprintf(buf,"%s is now room aide for %s>",
1143 usbuf.fullname,CC->quickroom.QRname);
1146 cprintf("%d Ok\n",OK);
1150 * Generate an associated file name for a room
1152 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
1153 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1157 * retrieve info file for this room
1159 void cmd_rinf(void) {
1164 assoc_file_name(filename, &CC->quickroom, "info");
1165 info_fp = fopen(filename,"r");
1167 if (info_fp==NULL) {
1168 cprintf("%d No info file.\n",ERROR);
1172 cprintf("%d Info:\n",LISTING_FOLLOWS);
1173 while (fgets(buf, 256, info_fp) != NULL) {
1174 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1175 cprintf("%s\n", buf);
1182 * Back end processing to delete a room and everything associated with it
1184 void delete_room(struct quickroom *qrbuf) {
1190 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1192 /* Delete the info file */
1193 assoc_file_name(aaa, qrbuf, "info");
1196 /* Delete the image file */
1197 assoc_file_name(aaa, qrbuf, "images");
1200 /* first flag the room record as not in use */
1201 lgetroom(qrbuf, qrbuf->QRname);
1204 /* then delete the messages in the room */
1206 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1207 MsgToDelete = MessageFromList(a);
1208 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1214 delete_msglist(qrbuf);
1215 lputroom(qrbuf, qrbuf->QRname);
1217 /* then decrement the reference count for the floor */
1218 lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
1219 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1220 lputfloor(&flbuf,(int)(qrbuf->QRfloor));
1222 /* Delete the room record from the database! */
1223 putroom(NULL, qrbuf->QRname);
1228 * aide command: kill the current room
1230 void cmd_kill(char *argbuf) {
1232 char deleted_room_name[ROOMNAMELEN];
1235 kill_ok = extract_int(argbuf,0);
1237 if (!(CC->logged_in)) {
1238 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1242 if (!is_room_aide()) {
1243 cprintf("%d Higher access required.\n",
1244 ERROR+HIGHER_ACCESS_REQUIRED);
1248 if (is_noneditable(&CC->quickroom)) {
1249 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1254 strcpy(deleted_room_name, CC->quickroom.QRname);
1255 delete_room(&CC->quickroom); /* Do the dirty work */
1256 usergoto(BASEROOM, 0); /* Return to the Lobby */
1258 /* tell the world what we did */
1259 sprintf(aaa,"%s> killed by %s",
1260 deleted_room_name, CC->curr_user);
1262 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1265 cprintf("%d ok to delete.\n",OK);
1271 * Internal code to create a new room (returns room flags)
1273 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1275 unsigned create_room(char *new_room_name,
1277 char *new_room_pass,
1278 int new_room_floor) {
1280 struct quickroom qrbuf;
1284 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1286 memset(&qrbuf, 0, sizeof(struct quickroom));
1287 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1288 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1289 qrbuf.QRflags = QR_INUSE;
1290 qrbuf.QRnumber = get_new_room_number();
1291 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1292 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1293 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1294 if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
1296 /* If the room is private, and the system administrator has elected
1297 * to automatically grant room aide privileges, do so now; otherwise,
1298 * set the room aide to undefined.
1300 if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) {
1301 qrbuf.QRroomaide=CC->usersupp.usernum;
1304 qrbuf.QRroomaide = (-1L);
1307 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1308 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1309 qrbuf.QRfloor = new_room_floor;
1311 /* save what we just did... */
1312 putroom(&qrbuf, qrbuf.QRname);
1314 /* bump the reference count on whatever floor the room is on */
1315 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1316 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1317 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1319 /* be sure not to kick the creator out of the room! */
1320 lgetuser(&CC->usersupp,CC->curr_user);
1321 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1322 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1323 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1324 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1325 lputuser(&CC->usersupp,CC->curr_user);
1327 /* resume our happy day */
1328 return(qrbuf.QRflags);
1335 void cmd_cre8(char *args)
1338 char new_room_name[256];
1340 char new_room_pass[256];
1344 struct quickroom qrbuf;
1347 cre8_ok = extract_int(args,0);
1348 extract(new_room_name,args,1);
1349 new_room_name[ROOMNAMELEN-1] = 0;
1350 new_room_type = extract_int(args,2);
1351 extract(new_room_pass,args,3);
1352 new_room_pass[9] = 0;
1355 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1356 cprintf("%d Invalid room name.\n",ERROR);
1360 if (!strcasecmp(new_room_name, MAILROOM)) {
1361 cprintf("%d '%s' already exists.\n",
1362 ERROR+ALREADY_EXISTS, new_room_name);
1366 if (num_parms(args)>=5) {
1367 getfloor(&flbuf,extract_int(args,4));
1368 if ((flbuf.f_flags & F_INUSE) == 0) {
1369 cprintf("%d Invalid floor number.\n",
1370 ERROR+INVALID_FLOOR_OPERATION);
1374 new_room_floor = extract_int(args,4);
1378 if (!(CC->logged_in)) {
1379 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1383 if (CC->usersupp.axlevel < config.c_createax) {
1384 cprintf("%d You need higher access to create rooms.\n",
1385 ERROR+HIGHER_ACCESS_REQUIRED);
1389 if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
1390 cprintf("%d Ok to create rooms.\n", OK);
1394 /* Check to make sure the requested room name doesn't already exist */
1395 if (getroom(&qrbuf, new_room_name)==0) {
1396 cprintf("%d '%s' already exists.\n",
1397 ERROR+ALREADY_EXISTS, qrbuf.QRname);
1401 if ((new_room_type < 0) || (new_room_type > 3)) {
1402 cprintf("%d Invalid room type.\n",ERROR);
1407 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1411 newflags = create_room(new_room_name,
1412 new_room_type,new_room_pass,new_room_floor);
1414 /* post a message in Aide> describing the new room */
1415 strncpy(aaa,new_room_name,255);
1416 strcat(aaa,"> created by ");
1417 strcat(aaa,CC->usersupp.fullname);
1418 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1419 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1420 if (newflags&QR_PASSWORDED) {
1421 strcat(aaa,"\n Password: ");
1422 strcat(aaa,new_room_pass);
1426 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1431 void cmd_einf(char *ok)
1432 { /* enter info file for current room */
1434 char infofilename[256];
1437 if (!(CC->logged_in)) {
1438 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1442 if (!is_room_aide()) {
1443 cprintf("%d Higher access required.\n",
1444 ERROR+HIGHER_ACCESS_REQUIRED);
1449 cprintf("%d Ok.\n",OK);
1453 assoc_file_name(infofilename, &CC->quickroom, "info");
1454 lprintf(9, "opening\n");
1455 fp = fopen(infofilename, "w");
1456 lprintf(9, "checking\n");
1458 cprintf("%d Cannot open %s: %s\n",
1459 ERROR+INTERNAL_ERROR, infofilename, strerror(errno));
1463 cprintf("%d Send info...\n", SEND_LISTING);
1467 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1468 } while(strcmp(buf,"000"));
1471 /* now update the room index so people will see our new info */
1472 lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */
1473 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1474 lputroom(&CC->quickroom,CC->quickroom.QRname);
1479 * cmd_lflr() - List all known floors
1481 void cmd_lflr(void) {
1485 if (!(CC->logged_in)) {
1486 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1490 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1491 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1496 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1498 for (a=0; a<MAXFLOORS; ++a) {
1500 if (flbuf.f_flags & F_INUSE) {
1501 cprintf("%d|%s|%d\n",
1513 * create a new floor
1515 void cmd_cflr(char *argbuf)
1517 char new_floor_name[256];
1520 int free_slot = (-1);
1523 extract(new_floor_name,argbuf,0);
1524 cflr_ok = extract_int(argbuf,1);
1527 if (!(CC->logged_in)) {
1528 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1532 if (CC->usersupp.axlevel<6) {
1533 cprintf("%d You need higher access to create rooms.\n",
1534 ERROR+HIGHER_ACCESS_REQUIRED);
1538 for (a=0; a<MAXFLOORS; ++a) {
1541 /* note any free slots while we're scanning... */
1542 if ( ((flbuf.f_flags & F_INUSE)==0)
1543 && (free_slot < 0) ) free_slot = a;
1545 /* check to see if it already exists */
1546 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1547 && (flbuf.f_flags & F_INUSE) ) {
1548 cprintf("%d Floor '%s' already exists.\n",
1549 ERROR+ALREADY_EXISTS,
1557 cprintf("%d There is no space available for a new floor.\n",
1558 ERROR+INVALID_FLOOR_OPERATION);
1563 cprintf("%d ok to create...\n",OK);
1567 lgetfloor(&flbuf,free_slot);
1568 flbuf.f_flags = F_INUSE;
1569 flbuf.f_ref_count = 0;
1570 strncpy(flbuf.f_name,new_floor_name,255);
1571 lputfloor(&flbuf,free_slot);
1572 cprintf("%d %d\n",OK,free_slot);
1580 void cmd_kflr(char *argbuf)
1583 int floor_to_delete;
1587 floor_to_delete = extract_int(argbuf,0);
1588 kflr_ok = extract_int(argbuf,1);
1591 if (!(CC->logged_in)) {
1592 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1596 if (CC->usersupp.axlevel<6) {
1597 cprintf("%d You need higher access to delete floors.\n",
1598 ERROR+HIGHER_ACCESS_REQUIRED);
1602 lgetfloor(&flbuf,floor_to_delete);
1605 if ((flbuf.f_flags & F_INUSE) == 0) {
1606 cprintf("%d Floor %d not in use.\n",
1607 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1612 if (flbuf.f_ref_count != 0) {
1613 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1614 ERROR+INVALID_FLOOR_OPERATION,
1621 cprintf("%d Ok\n",OK);
1624 cprintf("%d Ok to delete...\n",OK);
1631 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1632 lputfloor(&flbuf,floor_to_delete);
1638 void cmd_eflr(char *argbuf)
1644 np = num_parms(argbuf);
1646 cprintf("%d Usage error.\n",ERROR);
1650 if (!(CC->logged_in)) {
1651 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1655 if (CC->usersupp.axlevel<6) {
1656 cprintf("%d You need higher access to edit floors.\n",
1657 ERROR+HIGHER_ACCESS_REQUIRED);
1661 floor_num = extract_int(argbuf,0);
1662 lgetfloor(&flbuf,floor_num);
1663 if ( (flbuf.f_flags & F_INUSE) == 0) {
1664 lputfloor(&flbuf,floor_num);
1665 cprintf("%d Floor %d is not in use.\n",
1666 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1669 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1670 lputfloor(&flbuf,floor_num);
1672 cprintf("%d Ok\n",OK);