15 #include "sysdep_decls.h"
19 #include "serv_chat.h"
20 #include "citserver.h"
25 * Generic routine for determining user access to rooms
27 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf) {
31 /* for internal programs, always do everything */
32 if (((CC->internal_pgm))&&(roombuf->QRflags & QR_INUSE)) {
33 return(UA_KNOWN | UA_GOTOALLOWED);
36 /* For mailbox rooms, only allow access to the owner */
37 if (roombuf->QRflags & QR_MAILBOX) {
38 if (userbuf->usernum != atol(roombuf->QRname)) {
43 /* Locate any applicable user/room relationships */
44 CtdlGetRelationship(&vbuf, userbuf, roombuf);
46 /* Force the properties of the Aide room */
47 if (!strcasecmp(roombuf->QRname, AIDEROOM)) {
48 if (userbuf->axlevel >= 6) {
49 retval = UA_KNOWN | UA_GOTOALLOWED;
57 /* For mailboxes, we skip all the access stuff (and we've
58 * already checked by this point that the mailbox belongs
61 if (roombuf->QRflags & QR_MAILBOX) {
62 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;
71 /* If this is a preferred users only room, check access level */
72 if (roombuf->QRflags & QR_PREFONLY) {
73 if (userbuf->axlevel < 5) {
74 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
78 /* For private rooms, check the generation number matchups */
79 if (roombuf->QRflags & QR_PRIVATE) {
81 /* An explicit match means the user belongs in this room */
82 if (vbuf.v_flags & V_ACCESS) {
83 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
85 /* Otherwise, check if this is a guess-name or passworded
86 * room. If it is, a goto may at least be attempted
88 else if ((roombuf->QRflags & QR_PRIVATE)
89 ||(roombuf->QRflags & QR_PASSWORDED)) {
90 retval = retval & ~UA_KNOWN;
91 retval = retval | UA_GOTOALLOWED;
95 /* Check to see if the user has forgotten this room */
96 if (vbuf.v_flags & V_FORGET) {
97 retval = retval & ~UA_KNOWN;
98 retval = retval | UA_ZAPPED;
101 /* If user is explicitly locked out of this room, deny everything */
102 if (vbuf.v_flags & V_LOCKOUT) {
103 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
106 /* Aides get access to everything */
107 if (userbuf->axlevel >= 6) {
108 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
109 retval = retval & ~UA_ZAPPED;
112 NEWMSG: /* By the way, we also check for the presence of new messages */
113 if ( (roombuf->QRhighest) > (vbuf.v_lastseen) ) {
114 retval = retval | UA_HASNEWMSGS;
121 * getroom() - retrieve room data from disk
123 int getroom(struct quickroom *qrbuf, char *room_name)
125 struct cdbdata *cdbqr;
126 char lowercase_name[ROOMNAMELEN];
129 for (a=0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
130 lowercase_name[a] = tolower(room_name[a]);
132 lowercase_name[a] = 0;
134 memset(qrbuf, 0, sizeof(struct quickroom));
135 cdbqr = cdb_fetch(CDB_QUICKROOM,
136 lowercase_name, strlen(lowercase_name));
138 memcpy(qrbuf, cdbqr->ptr,
139 ( (cdbqr->len > sizeof(struct quickroom)) ?
140 sizeof(struct quickroom) : cdbqr->len) );
143 /* Mailbox rooms are always on the lowest floor */
144 if (qrbuf->QRflags & QR_MAILBOX) {
156 * lgetroom() - same as getroom() but locks the record (if supported)
158 int lgetroom(struct quickroom *qrbuf, char *room_name)
160 begin_critical_section(S_QUICKROOM);
161 return(getroom(qrbuf, room_name));
166 * putroom() - store room data on disk
167 * (if the supplied buffer is NULL, delete the room record)
169 void putroom(struct quickroom *qrbuf, char *room_name)
171 char lowercase_name[ROOMNAMELEN];
174 for (a=0; a<=strlen(room_name); ++a) {
175 lowercase_name[a] = tolower(room_name[a]);
179 cdb_delete(CDB_QUICKROOM,
180 lowercase_name, strlen(lowercase_name));
183 time(&qrbuf->QRmtime);
184 cdb_store(CDB_QUICKROOM,
185 lowercase_name, strlen(lowercase_name),
186 qrbuf, sizeof(struct quickroom));
192 * lputroom() - same as putroom() but unlocks the record (if supported)
194 void lputroom(struct quickroom *qrbuf, char *room_name)
197 putroom(qrbuf, room_name);
198 end_critical_section(S_QUICKROOM);
202 /****************************************************************************/
205 * getfloor() - retrieve floor data from disk
207 void getfloor(struct floor *flbuf, int floor_num)
209 struct cdbdata *cdbfl;
211 memset(flbuf, 0, sizeof(struct floor));
212 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
214 memcpy(flbuf, cdbfl->ptr,
215 ( (cdbfl->len > sizeof(struct floor)) ?
216 sizeof(struct floor) : cdbfl->len) );
220 if (floor_num == 0) {
221 strcpy(flbuf->f_name, "Main Floor");
222 flbuf->f_flags = F_INUSE;
223 flbuf->f_ref_count = 3;
230 * lgetfloor() - same as getfloor() but locks the record (if supported)
232 void lgetfloor(struct floor *flbuf, int floor_num)
235 begin_critical_section(S_FLOORTAB);
236 getfloor(flbuf,floor_num);
241 * putfloor() - store floor data on disk
243 void putfloor(struct floor *flbuf, int floor_num)
245 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
246 flbuf, sizeof(struct floor));
251 * lputfloor() - same as putfloor() but unlocks the record (if supported)
253 void lputfloor(struct floor *flbuf, int floor_num)
256 putfloor(flbuf,floor_num);
257 end_critical_section(S_FLOORTAB);
263 * Traverse the room file...
265 void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) {
266 struct quickroom qrbuf;
267 struct cdbdata *cdbqr;
269 cdb_rewind(CDB_QUICKROOM);
271 while(cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
272 memset(&qrbuf, 0, sizeof(struct quickroom));
273 memcpy(&qrbuf, cdbqr->ptr,
274 ( (cdbqr->len > sizeof(struct quickroom)) ?
275 sizeof(struct quickroom) : cdbqr->len) );
277 if (qrbuf.QRflags & QR_INUSE) (*CallBack)(&qrbuf);
284 * get_msglist() - retrieve room message pointers
286 void get_msglist(struct quickroom *whichroom) {
287 struct cdbdata *cdbfr;
289 if (CC->msglist != NULL) {
295 cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
300 CC->msglist = mallok(cdbfr->len);
301 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
302 CC->num_msgs = cdbfr->len / sizeof(long);
308 * put_msglist() - retrieve room message pointers
310 void put_msglist(struct quickroom *whichroom) {
312 cdb_store(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long),
313 CC->msglist, CC->num_msgs * sizeof(long));
318 * delete_msglist() - delete room message pointers
319 * FIX - this really should check first to make sure there's actually a
320 * msglist to delete. As things stand now, calling this function on
321 * a room which has never been posted in will result in a message
322 * like "gdbm: illegal data" (no big deal, but could use fixing).
324 void delete_msglist(struct quickroom *whichroom) {
326 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
331 * Add a message number to a room's message list.
332 * So, why doesn't this function use the get_msglist() and put_msglist() stuff
333 * defined above? Because the room the message number is being written to
334 * may not be the current room (as is the case with cmd_move() for example).
336 * This function returns the highest message number present in the room after
337 * the add operation is performed - which is not necessarily the message
340 long AddMessageToRoom(struct quickroom *whichroom, long newmsgid) {
341 struct cdbdata *cdbfr;
344 long highest_msg = 0L;
346 cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
352 msglist = mallok(cdbfr->len);
353 num_msgs = cdbfr->len / sizeof(long);
354 memcpy(msglist, cdbfr->ptr, cdbfr->len);
358 /* Now add the new message */
360 msglist = reallok(msglist,
361 (num_msgs * sizeof(long)) );
363 if (msglist == NULL) {
364 lprintf(3, "ERROR: can't realloc message list!\n");
367 msglist[num_msgs - 1] = newmsgid;
369 /* Sort the message list, so all the msgid's are in order */
370 num_msgs = sort_msglist(msglist, num_msgs);
372 /* Determine the highest message number */
373 highest_msg = msglist[num_msgs - 1];
375 /* Write it back to disk. */
376 cdb_store(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long),
377 msglist, num_msgs * sizeof(long));
379 /* And finally, free up the memory we used. */
386 * MessageFromList() - get a message number from the list currently in memory
388 long MessageFromList(int whichpos) {
390 /* Return zero if the position is invalid */
391 if (whichpos >= CC->num_msgs) return 0L;
393 return(CC->msglist[whichpos]);
397 * SetMessageInList() - set a message number in the list currently in memory
399 void SetMessageInList(int whichpos, long newmsgnum) {
401 /* Return zero if the position is invalid */
402 if (whichpos >= CC->num_msgs) return;
404 CC->msglist[whichpos] = newmsgnum;
410 * sort message pointers
411 * (returns new msg count)
413 int sort_msglist(long listptrs[], int oldcount)
420 if (numitems < 2) return(oldcount);
423 for (a=numitems-2; a>=0; --a) {
424 for (b=0; b<=a; ++b) {
425 if (listptrs[b] > (listptrs[b+1])) {
427 hold2 = listptrs[b+1];
429 listptrs[b+1] = hold1;
434 /* and yank any nulls */
435 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
436 memcpy(&listptrs[0], &listptrs[1],
437 (sizeof(long) * (CC->num_msgs - 1)) );
446 * Determine whether a given room is non-editable.
448 int is_noneditable(struct quickroom *qrbuf) {
450 /* Lobby> and Aide> are non-editable */
451 if (!strcasecmp(qrbuf->QRname, BASEROOM)) return(1);
452 else if (!strcasecmp(qrbuf->QRname, AIDEROOM)) return(1);
454 /* Mailbox rooms are also non-editable */
455 else if (qrbuf->QRflags & QR_MAILBOX) return(1);
457 /* Everything else is editable */
464 * Back-back-end for all room listing commands
466 void list_roomname(struct quickroom *qrbuf) {
467 char truncated_roomname[ROOMNAMELEN];
469 /* For mailbox rooms, chop off the owner prefix */
470 if (qrbuf->QRflags & QR_MAILBOX) {
471 strcpy(truncated_roomname, qrbuf->QRname);
472 strcpy(truncated_roomname, &truncated_roomname[11]);
473 cprintf("%s", truncated_roomname);
475 /* For all other rooms, just display the name in its entirety */
477 cprintf("%s", qrbuf->QRname);
480 /* ...and now the other parameters */
482 qrbuf->QRflags,qrbuf->QRfloor);
487 * cmd_lrms() - List all accessible rooms, known or forgotten
489 void cmd_lrms_backend(struct quickroom *qrbuf) {
490 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
491 & (UA_KNOWN | UA_ZAPPED)))
492 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
493 ||((CC->FloorBeingSearched)<0)) )
494 list_roomname(qrbuf);
497 void cmd_lrms(char *argbuf)
499 CC->FloorBeingSearched = (-1);
500 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
502 if (!(CC->logged_in)) {
503 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
507 if (getuser(&CC->usersupp,CC->curr_user)) {
508 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
512 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
514 ForEachRoom(cmd_lrms_backend);
521 * cmd_lkra() - List all known rooms
523 void cmd_lkra_backend(struct quickroom *qrbuf) {
524 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
526 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
527 ||((CC->FloorBeingSearched)<0)) )
528 list_roomname(qrbuf);
531 void cmd_lkra(char *argbuf)
533 CC->FloorBeingSearched = (-1);
534 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
536 if (!(CC->logged_in)) {
537 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
541 if (getuser(&CC->usersupp,CC->curr_user)) {
542 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
546 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
548 ForEachRoom(cmd_lkra_backend);
555 * cmd_lkrn() - List all known rooms with new messages
557 void cmd_lkrn_backend(struct quickroom *qrbuf) {
560 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
562 && (ra & UA_HASNEWMSGS)
563 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
564 ||((CC->FloorBeingSearched)<0)) )
565 list_roomname(qrbuf);
568 void cmd_lkrn(char *argbuf)
570 CC->FloorBeingSearched = (-1);
571 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
573 if (!(CC->logged_in)) {
574 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
578 if (getuser(&CC->usersupp,CC->curr_user)) {
579 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
583 cprintf("%d Rooms w/ new msgs:\n",LISTING_FOLLOWS);
585 ForEachRoom(cmd_lkrn_backend);
592 * cmd_lkro() - List all known rooms
594 void cmd_lkro_backend(struct quickroom *qrbuf) {
597 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
599 && ((ra & UA_HASNEWMSGS)==0)
600 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
601 ||((CC->FloorBeingSearched)<0)) )
602 list_roomname(qrbuf);
605 void cmd_lkro(char *argbuf)
607 CC->FloorBeingSearched = (-1);
608 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
610 if (!(CC->logged_in)) {
611 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
615 if (getuser(&CC->usersupp,CC->curr_user)) {
616 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
620 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
622 ForEachRoom(cmd_lkro_backend);
629 * cmd_lzrm() - List all forgotten rooms
631 void cmd_lzrm_backend(struct quickroom *qrbuf) {
634 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
635 if ( (ra & UA_GOTOALLOWED)
637 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
638 ||((CC->FloorBeingSearched)<0)) )
639 list_roomname(qrbuf);
642 void cmd_lzrm(char *argbuf)
644 CC->FloorBeingSearched = (-1);
645 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
647 if (!(CC->logged_in)) {
648 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
652 if (getuser(&CC->usersupp,CC->curr_user)) {
653 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
657 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
659 ForEachRoom(cmd_lzrm_backend);
665 void usergoto(char *where, int display_result)
668 int new_messages = 0;
669 int total_messages = 0;
673 int newmailcount = 0;
675 char truncated_roomname[ROOMNAMELEN];
677 strcpy(CC->quickroom.QRname, where);
678 getroom(&CC->quickroom, where);
680 lgetuser(&CC->usersupp,CC->curr_user);
681 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
683 /* Know the room ... but not if it's the page log room */
684 if (strcasecmp(where, config.c_logpages)) {
685 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
686 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
689 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
690 lputuser(&CC->usersupp,CC->curr_user);
692 /* check for new mail */
693 newmailcount = NewMailCount();
695 /* set info to 1 if the user needs to read the room's info file */
696 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
699 get_msglist(&CC->quickroom);
700 for (a=0; a<CC->num_msgs; ++a) {
701 if (MessageFromList(a)>0L) {
703 if (MessageFromList(a) > vbuf.v_lastseen) {
709 if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1;
712 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
713 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
716 strcpy(truncated_roomname, CC->quickroom.QRname);
717 if (CC->quickroom.QRflags & QR_MAILBOX) {
718 strcpy(truncated_roomname, &truncated_roomname[11]);
721 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
724 new_messages, total_messages,
725 info,CC->quickroom.QRflags,
726 CC->quickroom.QRhighest,
728 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
730 set_wtmpsupp_to_current_room();
735 * cmd_goto() - goto a new room
737 void cmd_goto(char *gargs)
739 struct quickroom QRscratch;
743 char augmented_roomname[256];
747 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
748 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
752 extract(towhere,gargs,0);
753 extract(password,gargs,1);
755 getuser(&CC->usersupp, CC->curr_user);
757 if (!strcasecmp(towhere, "_BASEROOM_"))
758 strcpy(towhere, BASEROOM);
760 if (!strcasecmp(towhere, "_MAIL_"))
761 strcpy(towhere, MAILROOM);
763 if (!strcasecmp(towhere, "_BITBUCKET_"))
764 strcpy(towhere, config.c_twitroom);
767 /* First try a regular match */
768 c = getroom(&QRscratch, towhere);
770 /* Then try a mailbox name match */
772 MailboxName(augmented_roomname, &CC->usersupp, towhere);
773 c = getroom(&QRscratch, augmented_roomname);
774 if (c == 0) strcpy(towhere, augmented_roomname);
777 /* And if the room was found... */
780 /* let internal programs go directly to any room */
781 if (CC->internal_pgm) {
782 usergoto(towhere, 1);
786 /* See if there is an existing user/room relationship */
787 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
789 /* normal clients have to pass through security */
790 if (ra & UA_GOTOALLOWED) ok = 1;
793 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
794 ((ra & UA_KNOWN) == 0) &&
795 (strcasecmp(QRscratch.QRpasswd,password))
797 cprintf("%d wrong or missing passwd\n",
798 ERROR+PASSWORD_REQUIRED);
801 else if ( (QRscratch.QRflags&QR_PRIVATE) &&
802 ((QRscratch.QRflags&QR_PASSWORDED)==0) &&
803 ((QRscratch.QRflags&QR_GUESSNAME)==0) &&
804 ((ra & UA_KNOWN) == 0) ) {
808 usergoto(towhere, 1);
814 NOPE: cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
818 void cmd_whok(void) {
819 struct usersupp temp;
820 struct cdbdata *cdbus;
822 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
823 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
826 getuser(&CC->usersupp,CC->curr_user);
828 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
829 cprintf("%d Higher access required.\n",
830 ERROR+HIGHER_ACCESS_REQUIRED);
834 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
835 cdb_rewind(CDB_USERSUPP);
836 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
837 memset(&temp, 0, sizeof(struct usersupp));
838 memcpy(&temp, cdbus->ptr, cdbus->len);
841 if ( (CC->quickroom.QRflags & QR_INUSE)
842 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
843 ) cprintf("%s\n",temp.fullname);
850 * RDIR command for room directory
852 void cmd_rdir(void) {
859 if (!(CC->logged_in)) {
860 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
864 getroom(&CC->quickroom, CC->quickroom.QRname);
865 getuser(&CC->usersupp, CC->curr_user);
867 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
868 cprintf("%d not here.\n",ERROR+NOT_HERE);
872 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
873 && (CC->usersupp.axlevel<6)
874 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
875 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
879 cprintf("%d %s|%s/files/%s\n",
880 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
882 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
883 BBSDIR,CC->quickroom.QRdirname,CC->temp);
886 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
888 if (fd==NULL) fd=fopen("/dev/null","r");
890 ls = fopen(CC->temp,"r");
891 while (fgets(flnm,256,ls)!=NULL) {
892 flnm[strlen(flnm)-1]=0;
893 if (strcasecmp(flnm,"filedir")) {
894 sprintf(buf,"%s/files/%s/%s",
895 BBSDIR,CC->quickroom.QRdirname,flnm);
899 while ((fgets(buf,256,fd)!=NULL)
900 &&(strlen(comment)==0)) {
901 buf[strlen(buf)-1] = 0;
902 if ((!strncasecmp(buf,flnm,strlen(flnm)))
903 && (buf[strlen(flnm)]==' '))
905 &buf[strlen(flnm)+1],255);
907 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
918 * get room parameters (aide or room aide command)
920 void cmd_getr(void) {
921 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
922 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
926 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
927 cprintf("%d Higher access required.\n",
928 ERROR+HIGHER_ACCESS_REQUIRED);
932 if (is_noneditable(&CC->quickroom)) {
933 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
937 getroom(&CC->quickroom, CC->quickroom.QRname);
938 cprintf("%d%c%s|%s|%s|%d|%d\n",
940 CC->quickroom.QRname,
941 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
942 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
943 CC->quickroom.QRflags,
944 (int)CC->quickroom.QRfloor);
949 * set room parameters (aide or room aide command)
951 void cmd_setr(char *args) {
954 char old_name[ROOMNAMELEN];
957 if (!(CC->logged_in)) {
958 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
962 if (!is_room_aide()) {
963 cprintf("%d Higher access required.\n",
964 ERROR+HIGHER_ACCESS_REQUIRED);
968 if (is_noneditable(&CC->quickroom)) {
969 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
973 if (num_parms(args)>=6) {
974 getfloor(&flbuf,extract_int(args,5));
975 if ((flbuf.f_flags & F_INUSE) == 0) {
976 cprintf("%d Invalid floor number.\n",
977 ERROR+INVALID_FLOOR_OPERATION);
982 lgetroom(&CC->quickroom, CC->quickroom.QRname);
983 strcpy(old_name, CC->quickroom.QRname);
984 extract(buf,args,0); buf[ROOMNAMELEN]=0;
985 strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
986 extract(buf,args,1); buf[10]=0;
987 strncpy(CC->quickroom.QRpasswd,buf,9);
988 extract(buf,args,2); buf[15]=0;
989 strncpy(CC->quickroom.QRdirname,buf,19);
990 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
992 /* Clean up a client boo-boo: if the client set the room to
993 * guess-name or passworded, ensure that the private flag is
996 if ((CC->quickroom.QRflags & QR_GUESSNAME)
997 ||(CC->quickroom.QRflags & QR_PASSWORDED))
998 CC->quickroom.QRflags |= QR_PRIVATE;
1000 /* Kick everyone out if the client requested it (by changing the
1001 * room's generation number)
1003 if (extract_int(args,4)) {
1004 time(&CC->quickroom.QRgen);
1007 old_floor = CC->quickroom.QRfloor;
1008 if (num_parms(args)>=6) {
1009 CC->quickroom.QRfloor = extract_int(args,5);
1012 /* Write the room record back to disk */
1013 lputroom(&CC->quickroom, CC->quickroom.QRname);
1015 /* If the room name changed, then there are now two room records,
1016 * so we have to delete the old one.
1018 if (strcasecmp(CC->quickroom.QRname, old_name)) {
1019 putroom(NULL, old_name);
1022 /* adjust the floor reference counts */
1023 lgetfloor(&flbuf,old_floor);
1024 --flbuf.f_ref_count;
1025 lputfloor(&flbuf,old_floor);
1026 lgetfloor(&flbuf,CC->quickroom.QRfloor);
1027 ++flbuf.f_ref_count;
1028 lputfloor(&flbuf,CC->quickroom.QRfloor);
1030 /* create a room directory if necessary */
1031 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1033 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1034 CC->quickroom.QRdirname);
1038 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
1040 cprintf("%d Ok\n",OK);
1046 * get the name of the room aide for this room
1048 void cmd_geta(void) {
1049 struct usersupp usbuf;
1051 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
1052 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1056 if (is_noneditable(&CC->quickroom)) {
1057 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1061 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
1062 cprintf("%d %s\n",OK,usbuf.fullname);
1065 cprintf("%d \n",OK);
1071 * set the room aide for this room
1073 void cmd_seta(char *new_ra)
1075 struct usersupp usbuf;
1080 if (!(CC->logged_in)) {
1081 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1085 if (!is_room_aide()) {
1086 cprintf("%d Higher access required.\n",
1087 ERROR+HIGHER_ACCESS_REQUIRED);
1091 if (getuser(&usbuf,new_ra)!=0) {
1095 newu = usbuf.usernum;
1098 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1100 if (CC->quickroom.QRroomaide != newu) {
1103 CC->quickroom.QRroomaide = newu;
1104 lputroom(&CC->quickroom, CC->quickroom.QRname);
1107 * We have to post the change notice _after_ writing changes to
1108 * the room table, otherwise it would deadlock!
1110 if (post_notice == 1) {
1111 sprintf(buf,"%s is now room aide for %s>",
1112 usbuf.fullname,CC->quickroom.QRname);
1115 cprintf("%d Ok\n",OK);
1119 * Generate an associated file name for a room
1121 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
1122 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1126 * retrieve info file for this room
1128 void cmd_rinf(void) {
1133 assoc_file_name(filename, &CC->quickroom, "info");
1134 info_fp = fopen(filename,"r");
1136 if (info_fp==NULL) {
1137 cprintf("%d No info file.\n",ERROR);
1141 cprintf("%d Info:\n",LISTING_FOLLOWS);
1142 while (fgets(buf, 256, info_fp) != NULL) {
1143 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1144 cprintf("%s\n", buf);
1151 * Back end processing to delete a room and everything associated with it
1153 void delete_room(struct quickroom *qrbuf) {
1159 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1161 /* Delete the info file */
1162 assoc_file_name(aaa, qrbuf, "info");
1165 /* Delete the image file */
1166 assoc_file_name(aaa, qrbuf, "images");
1169 /* first flag the room record as not in use */
1170 lgetroom(qrbuf, qrbuf->QRname);
1173 /* then delete the messages in the room */
1175 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1176 MsgToDelete = MessageFromList(a);
1177 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1183 delete_msglist(qrbuf);
1184 lputroom(qrbuf, qrbuf->QRname);
1186 /* then decrement the reference count for the floor */
1187 lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
1188 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1189 lputfloor(&flbuf,(int)(qrbuf->QRfloor));
1191 /* Delete the room record from the database! */
1192 putroom(NULL, qrbuf->QRname);
1197 * aide command: kill the current room
1199 void cmd_kill(char *argbuf) {
1201 char deleted_room_name[ROOMNAMELEN];
1204 kill_ok = extract_int(argbuf,0);
1206 if (!(CC->logged_in)) {
1207 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1211 if (!is_room_aide()) {
1212 cprintf("%d Higher access required.\n",
1213 ERROR+HIGHER_ACCESS_REQUIRED);
1217 if (is_noneditable(&CC->quickroom)) {
1218 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1223 strcpy(deleted_room_name, CC->quickroom.QRname);
1224 delete_room(&CC->quickroom); /* Do the dirty work */
1225 usergoto(BASEROOM, 0); /* Return to the Lobby */
1227 /* tell the world what we did */
1228 sprintf(aaa,"%s> killed by %s",
1229 deleted_room_name, CC->curr_user);
1231 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1234 cprintf("%d ok to delete.\n",OK);
1240 * Internal code to create a new room (returns room flags)
1242 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1244 unsigned create_room(char *new_room_name,
1246 char *new_room_pass,
1247 int new_room_floor) {
1249 struct quickroom qrbuf;
1253 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1255 memset(&qrbuf, 0, sizeof(struct quickroom));
1256 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1257 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1258 qrbuf.QRflags = QR_INUSE;
1259 qrbuf.QRnumber = get_new_room_number();
1260 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1261 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1262 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1263 if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
1265 /* If the room is private, and the system administrator has elected
1266 * to automatically grant room aide privileges, do so now; otherwise,
1267 * set the room aide to undefined.
1269 if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) {
1270 qrbuf.QRroomaide=CC->usersupp.usernum;
1273 qrbuf.QRroomaide = (-1L);
1276 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1277 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1278 qrbuf.QRfloor = new_room_floor;
1280 /* save what we just did... */
1281 putroom(&qrbuf, qrbuf.QRname);
1283 /* bump the reference count on whatever floor the room is on */
1284 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1285 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1286 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1288 /* be sure not to kick the creator out of the room! */
1289 lgetuser(&CC->usersupp,CC->curr_user);
1290 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1291 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1292 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1293 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1294 lputuser(&CC->usersupp,CC->curr_user);
1296 /* resume our happy day */
1297 return(qrbuf.QRflags);
1304 void cmd_cre8(char *args)
1307 char new_room_name[256];
1309 char new_room_pass[256];
1313 struct quickroom qrbuf;
1316 cre8_ok = extract_int(args,0);
1317 extract(new_room_name,args,1);
1318 new_room_name[ROOMNAMELEN-1] = 0;
1319 new_room_type = extract_int(args,2);
1320 extract(new_room_pass,args,3);
1321 new_room_pass[9] = 0;
1324 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1325 cprintf("%d Invalid room name.\n",ERROR);
1329 if (!strcasecmp(new_room_name, MAILROOM)) {
1330 cprintf("%d '%s' already exists.\n",
1331 ERROR+ALREADY_EXISTS, new_room_name);
1335 if (num_parms(args)>=5) {
1336 getfloor(&flbuf,extract_int(args,4));
1337 if ((flbuf.f_flags & F_INUSE) == 0) {
1338 cprintf("%d Invalid floor number.\n",
1339 ERROR+INVALID_FLOOR_OPERATION);
1343 new_room_floor = extract_int(args,4);
1347 if (!(CC->logged_in)) {
1348 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1352 if (CC->usersupp.axlevel<3) {
1353 cprintf("%d You need higher access to create rooms.\n",
1354 ERROR+HIGHER_ACCESS_REQUIRED);
1358 if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
1359 cprintf("%d Ok to create rooms.\n", OK);
1363 /* Check to make sure the requested room name doesn't already exist */
1364 if (getroom(&qrbuf, new_room_name)==0) {
1365 cprintf("%d '%s' already exists.\n",
1366 ERROR+ALREADY_EXISTS, qrbuf.QRname);
1370 if ((new_room_type < 0) || (new_room_type > 3)) {
1371 cprintf("%d Invalid room type.\n",ERROR);
1376 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1380 newflags = create_room(new_room_name,
1381 new_room_type,new_room_pass,new_room_floor);
1383 /* post a message in Aide> describing the new room */
1384 strncpy(aaa,new_room_name,255);
1385 strcat(aaa,"> created by ");
1386 strcat(aaa,CC->usersupp.fullname);
1387 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1388 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1389 if (newflags&QR_PASSWORDED) {
1390 strcat(aaa,"\n Password: ");
1391 strcat(aaa,new_room_pass);
1395 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1400 void cmd_einf(char *ok)
1401 { /* enter info file for current room */
1403 char infofilename[256];
1406 if (!(CC->logged_in)) {
1407 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1411 if (!is_room_aide()) {
1412 cprintf("%d Higher access required.\n",
1413 ERROR+HIGHER_ACCESS_REQUIRED);
1418 cprintf("%d Ok.\n",OK);
1422 assoc_file_name(infofilename, &CC->quickroom, "info");
1423 lprintf(9, "opening\n");
1424 fp = fopen(infofilename, "w");
1425 lprintf(9, "checking\n");
1427 cprintf("%d Cannot open %s: %s\n",
1428 ERROR+INTERNAL_ERROR, infofilename, strerror(errno));
1432 cprintf("%d Send info...\n", SEND_LISTING);
1436 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1437 } while(strcmp(buf,"000"));
1440 /* now update the room index so people will see our new info */
1441 lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */
1442 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1443 lputroom(&CC->quickroom,CC->quickroom.QRname);
1448 * cmd_lflr() - List all known floors
1450 void cmd_lflr(void) {
1454 if (!(CC->logged_in)) {
1455 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1459 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1460 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1465 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1467 for (a=0; a<MAXFLOORS; ++a) {
1469 if (flbuf.f_flags & F_INUSE) {
1470 cprintf("%d|%s|%d\n",
1482 * create a new floor
1484 void cmd_cflr(char *argbuf)
1486 char new_floor_name[256];
1489 int free_slot = (-1);
1492 extract(new_floor_name,argbuf,0);
1493 cflr_ok = extract_int(argbuf,1);
1496 if (!(CC->logged_in)) {
1497 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1501 if (CC->usersupp.axlevel<6) {
1502 cprintf("%d You need higher access to create rooms.\n",
1503 ERROR+HIGHER_ACCESS_REQUIRED);
1507 for (a=0; a<MAXFLOORS; ++a) {
1510 /* note any free slots while we're scanning... */
1511 if ( ((flbuf.f_flags & F_INUSE)==0)
1512 && (free_slot < 0) ) free_slot = a;
1514 /* check to see if it already exists */
1515 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1516 && (flbuf.f_flags & F_INUSE) ) {
1517 cprintf("%d Floor '%s' already exists.\n",
1518 ERROR+ALREADY_EXISTS,
1526 cprintf("%d There is no space available for a new floor.\n",
1527 ERROR+INVALID_FLOOR_OPERATION);
1532 cprintf("%d ok to create...\n",OK);
1536 lgetfloor(&flbuf,free_slot);
1537 flbuf.f_flags = F_INUSE;
1538 flbuf.f_ref_count = 0;
1539 strncpy(flbuf.f_name,new_floor_name,255);
1540 lputfloor(&flbuf,free_slot);
1541 cprintf("%d %d\n",OK,free_slot);
1549 void cmd_kflr(char *argbuf)
1552 int floor_to_delete;
1556 floor_to_delete = extract_int(argbuf,0);
1557 kflr_ok = extract_int(argbuf,1);
1560 if (!(CC->logged_in)) {
1561 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1565 if (CC->usersupp.axlevel<6) {
1566 cprintf("%d You need higher access to delete floors.\n",
1567 ERROR+HIGHER_ACCESS_REQUIRED);
1571 lgetfloor(&flbuf,floor_to_delete);
1574 if ((flbuf.f_flags & F_INUSE) == 0) {
1575 cprintf("%d Floor %d not in use.\n",
1576 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1581 if (flbuf.f_ref_count != 0) {
1582 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1583 ERROR+INVALID_FLOOR_OPERATION,
1590 cprintf("%d Ok\n",OK);
1593 cprintf("%d Ok to delete...\n",OK);
1600 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1601 lputfloor(&flbuf,floor_to_delete);
1607 void cmd_eflr(char *argbuf)
1613 np = num_parms(argbuf);
1615 cprintf("%d Usage error.\n",ERROR);
1619 if (!(CC->logged_in)) {
1620 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1624 if (CC->usersupp.axlevel<6) {
1625 cprintf("%d You need higher access to edit floors.\n",
1626 ERROR+HIGHER_ACCESS_REQUIRED);
1630 floor_num = extract_int(argbuf,0);
1631 lgetfloor(&flbuf,floor_num);
1632 if ( (flbuf.f_flags & F_INUSE) == 0) {
1633 lputfloor(&flbuf,floor_num);
1634 cprintf("%d Floor %d is not in use.\n",
1635 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1638 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1639 lputfloor(&flbuf,floor_num);
1641 cprintf("%d Ok\n",OK);