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 cdb_store(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long),
331 CC->msglist, CC->num_msgs * sizeof(long));
336 * delete_msglist() - delete room message pointers
337 * FIX - this really should check first to make sure there's actually a
338 * msglist to delete. As things stand now, calling this function on
339 * a room which has never been posted in will result in a message
340 * like "gdbm: illegal data" (no big deal, but could use fixing).
342 void delete_msglist(struct quickroom *whichroom) {
344 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
349 * Add a message number to a room's message list.
350 * So, why doesn't this function use the get_msglist() and put_msglist() stuff
351 * defined above? Because the room the message number is being written to
352 * may not be the current room (as is the case with cmd_move() for example).
354 * This function returns the highest message number present in the room after
355 * the add operation is performed - which is not necessarily the message
358 long AddMessageToRoom(struct quickroom *whichroom, long newmsgid) {
359 struct cdbdata *cdbfr;
362 long highest_msg = 0L;
364 cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
370 msglist = mallok(cdbfr->len);
371 num_msgs = cdbfr->len / sizeof(long);
372 memcpy(msglist, cdbfr->ptr, cdbfr->len);
376 /* Now add the new message */
378 msglist = reallok(msglist,
379 (num_msgs * sizeof(long)) );
381 if (msglist == NULL) {
382 lprintf(3, "ERROR: can't realloc message list!\n");
385 msglist[num_msgs - 1] = newmsgid;
387 /* Sort the message list, so all the msgid's are in order */
388 num_msgs = sort_msglist(msglist, num_msgs);
390 /* Determine the highest message number */
391 highest_msg = msglist[num_msgs - 1];
393 /* Write it back to disk. */
394 cdb_store(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long),
395 msglist, num_msgs * sizeof(long));
397 /* And finally, free up the memory we used. */
404 * MessageFromList() - get a message number from the list currently in memory
406 long MessageFromList(int whichpos) {
408 /* Return zero if the position is invalid */
409 if (whichpos >= CC->num_msgs) return 0L;
411 return(CC->msglist[whichpos]);
415 * SetMessageInList() - set a message number in the list currently in memory
417 void SetMessageInList(int whichpos, long newmsgnum) {
419 /* Return zero if the position is invalid */
420 if (whichpos >= CC->num_msgs) return;
422 CC->msglist[whichpos] = newmsgnum;
428 * sort message pointers
429 * (returns new msg count)
431 int sort_msglist(long listptrs[], int oldcount)
438 if (numitems < 2) return(oldcount);
441 for (a=numitems-2; a>=0; --a) {
442 for (b=0; b<=a; ++b) {
443 if (listptrs[b] > (listptrs[b+1])) {
445 hold2 = listptrs[b+1];
447 listptrs[b+1] = hold1;
452 /* and yank any nulls */
453 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
454 memcpy(&listptrs[0], &listptrs[1],
455 (sizeof(long) * (CC->num_msgs - 1)) );
464 * Determine whether a given room is non-editable.
466 int is_noneditable(struct quickroom *qrbuf) {
468 /* Lobby> and Aide> are non-editable */
469 if (!strcasecmp(qrbuf->QRname, BASEROOM)) return(1);
470 else if (!strcasecmp(qrbuf->QRname, AIDEROOM)) return(1);
472 /* Mailbox rooms are also non-editable */
473 else if (qrbuf->QRflags & QR_MAILBOX) return(1);
475 /* Everything else is editable */
482 * Back-back-end for all room listing commands
484 void list_roomname(struct quickroom *qrbuf) {
485 char truncated_roomname[ROOMNAMELEN];
487 /* For mailbox rooms, chop off the owner prefix */
488 if (qrbuf->QRflags & QR_MAILBOX) {
489 strcpy(truncated_roomname, qrbuf->QRname);
490 strcpy(truncated_roomname, &truncated_roomname[11]);
491 cprintf("%s", truncated_roomname);
493 /* For all other rooms, just display the name in its entirety */
495 cprintf("%s", qrbuf->QRname);
498 /* ...and now the other parameters */
499 cprintf("|%u|%d|%d\n",
502 (int)qrbuf->QRorder);
507 * cmd_lrms() - List all accessible rooms, known or forgotten
509 void cmd_lrms_backend(struct quickroom *qrbuf) {
510 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
511 & (UA_KNOWN | UA_ZAPPED)))
512 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
513 ||((CC->FloorBeingSearched)<0)) )
514 list_roomname(qrbuf);
517 void cmd_lrms(char *argbuf)
519 CC->FloorBeingSearched = (-1);
520 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
522 if (!(CC->logged_in)) {
523 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
527 if (getuser(&CC->usersupp,CC->curr_user)) {
528 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
532 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
534 ForEachRoom(cmd_lrms_backend);
541 * cmd_lkra() - List all known rooms
543 void cmd_lkra_backend(struct quickroom *qrbuf) {
544 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
546 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
547 ||((CC->FloorBeingSearched)<0)) )
548 list_roomname(qrbuf);
551 void cmd_lkra(char *argbuf)
553 CC->FloorBeingSearched = (-1);
554 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
556 if (!(CC->logged_in)) {
557 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
561 if (getuser(&CC->usersupp,CC->curr_user)) {
562 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
566 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
568 ForEachRoom(cmd_lkra_backend);
575 * cmd_lkrn() - List all known rooms with new messages
577 void cmd_lkrn_backend(struct quickroom *qrbuf) {
580 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
582 && (ra & UA_HASNEWMSGS)
583 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
584 ||((CC->FloorBeingSearched)<0)) )
585 list_roomname(qrbuf);
588 void cmd_lkrn(char *argbuf)
590 CC->FloorBeingSearched = (-1);
591 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
593 if (!(CC->logged_in)) {
594 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
598 if (getuser(&CC->usersupp,CC->curr_user)) {
599 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
603 cprintf("%d Rooms w/ new msgs:\n",LISTING_FOLLOWS);
605 ForEachRoom(cmd_lkrn_backend);
612 * cmd_lkro() - List all known rooms
614 void cmd_lkro_backend(struct quickroom *qrbuf) {
617 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
619 && ((ra & UA_HASNEWMSGS)==0)
620 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
621 ||((CC->FloorBeingSearched)<0)) )
622 list_roomname(qrbuf);
625 void cmd_lkro(char *argbuf)
627 CC->FloorBeingSearched = (-1);
628 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
630 if (!(CC->logged_in)) {
631 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
635 if (getuser(&CC->usersupp,CC->curr_user)) {
636 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
640 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
642 ForEachRoom(cmd_lkro_backend);
649 * cmd_lzrm() - List all forgotten rooms
651 void cmd_lzrm_backend(struct quickroom *qrbuf) {
654 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
655 if ( (ra & UA_GOTOALLOWED)
657 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
658 ||((CC->FloorBeingSearched)<0)) )
659 list_roomname(qrbuf);
662 void cmd_lzrm(char *argbuf)
664 CC->FloorBeingSearched = (-1);
665 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
667 if (!(CC->logged_in)) {
668 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
672 if (getuser(&CC->usersupp,CC->curr_user)) {
673 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
677 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
679 ForEachRoom(cmd_lzrm_backend);
685 void usergoto(char *where, int display_result)
688 int new_messages = 0;
689 int total_messages = 0;
693 int newmailcount = 0;
695 char truncated_roomname[ROOMNAMELEN];
697 strcpy(CC->quickroom.QRname, where);
698 getroom(&CC->quickroom, where);
700 lgetuser(&CC->usersupp,CC->curr_user);
701 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
703 /* Know the room ... but not if it's the page log room */
704 if (strcasecmp(where, config.c_logpages)) {
705 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
706 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
709 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
710 lputuser(&CC->usersupp,CC->curr_user);
712 /* check for new mail */
713 newmailcount = NewMailCount();
715 /* set info to 1 if the user needs to read the room's info file */
716 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
719 get_msglist(&CC->quickroom);
720 for (a=0; a<CC->num_msgs; ++a) {
721 if (MessageFromList(a)>0L) {
723 if (MessageFromList(a) > vbuf.v_lastseen) {
729 if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1;
732 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
733 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
736 strcpy(truncated_roomname, CC->quickroom.QRname);
737 if (CC->quickroom.QRflags & QR_MAILBOX) {
738 strcpy(truncated_roomname, &truncated_roomname[11]);
741 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
744 new_messages, total_messages,
745 info,CC->quickroom.QRflags,
746 CC->quickroom.QRhighest,
748 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
750 set_wtmpsupp_to_current_room();
755 * cmd_goto() - goto a new room
757 void cmd_goto(char *gargs)
759 struct quickroom QRscratch;
763 char augmented_roomname[256];
767 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
768 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
772 extract(towhere,gargs,0);
773 extract(password,gargs,1);
775 getuser(&CC->usersupp, CC->curr_user);
777 if (!strcasecmp(towhere, "_BASEROOM_"))
778 strcpy(towhere, BASEROOM);
780 if (!strcasecmp(towhere, "_MAIL_"))
781 strcpy(towhere, MAILROOM);
783 if (!strcasecmp(towhere, "_BITBUCKET_"))
784 strcpy(towhere, config.c_twitroom);
787 /* First try a regular match */
788 c = getroom(&QRscratch, towhere);
790 /* Then try a mailbox name match */
792 MailboxName(augmented_roomname, &CC->usersupp, towhere);
793 c = getroom(&QRscratch, augmented_roomname);
794 if (c == 0) strcpy(towhere, augmented_roomname);
797 /* And if the room was found... */
800 /* let internal programs go directly to any room */
801 if (CC->internal_pgm) {
802 usergoto(towhere, 1);
806 /* See if there is an existing user/room relationship */
807 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
809 /* normal clients have to pass through security */
810 if (ra & UA_GOTOALLOWED) ok = 1;
813 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
814 ((ra & UA_KNOWN) == 0) &&
815 (strcasecmp(QRscratch.QRpasswd,password))
817 cprintf("%d wrong or missing passwd\n",
818 ERROR+PASSWORD_REQUIRED);
821 else if ( (QRscratch.QRflags&QR_PRIVATE) &&
822 ((QRscratch.QRflags&QR_PASSWORDED)==0) &&
823 ((QRscratch.QRflags&QR_GUESSNAME)==0) &&
824 ((ra & UA_KNOWN) == 0) ) {
828 usergoto(towhere, 1);
834 NOPE: cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
838 void cmd_whok(void) {
839 struct usersupp temp;
840 struct cdbdata *cdbus;
842 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
843 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
846 getuser(&CC->usersupp,CC->curr_user);
848 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
849 cprintf("%d Higher access required.\n",
850 ERROR+HIGHER_ACCESS_REQUIRED);
854 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
855 cdb_rewind(CDB_USERSUPP);
856 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
857 memset(&temp, 0, sizeof(struct usersupp));
858 memcpy(&temp, cdbus->ptr, cdbus->len);
861 if ( (CC->quickroom.QRflags & QR_INUSE)
862 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
863 ) cprintf("%s\n",temp.fullname);
870 * RDIR command for room directory
872 void cmd_rdir(void) {
879 if (!(CC->logged_in)) {
880 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
884 getroom(&CC->quickroom, CC->quickroom.QRname);
885 getuser(&CC->usersupp, CC->curr_user);
887 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
888 cprintf("%d not here.\n",ERROR+NOT_HERE);
892 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
893 && (CC->usersupp.axlevel<6)
894 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
895 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
899 cprintf("%d %s|%s/files/%s\n",
900 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
902 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
903 BBSDIR,CC->quickroom.QRdirname,CC->temp);
906 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
908 if (fd==NULL) fd=fopen("/dev/null","r");
910 ls = fopen(CC->temp,"r");
911 while (fgets(flnm,256,ls)!=NULL) {
912 flnm[strlen(flnm)-1]=0;
913 if (strcasecmp(flnm,"filedir")) {
914 sprintf(buf,"%s/files/%s/%s",
915 BBSDIR,CC->quickroom.QRdirname,flnm);
919 while ((fgets(buf,256,fd)!=NULL)
920 &&(strlen(comment)==0)) {
921 buf[strlen(buf)-1] = 0;
922 if ((!strncasecmp(buf,flnm,strlen(flnm)))
923 && (buf[strlen(flnm)]==' '))
925 &buf[strlen(flnm)+1],255);
927 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
938 * get room parameters (aide or room aide command)
940 void cmd_getr(void) {
941 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
942 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
946 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
947 cprintf("%d Higher access required.\n",
948 ERROR+HIGHER_ACCESS_REQUIRED);
952 if (is_noneditable(&CC->quickroom)) {
953 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
957 getroom(&CC->quickroom, CC->quickroom.QRname);
958 cprintf("%d%c%s|%s|%s|%d|%d|%d\n",
960 CC->quickroom.QRname,
961 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
962 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
963 CC->quickroom.QRflags,
964 (int)CC->quickroom.QRfloor,
965 (int)CC->quickroom.QRorder);
970 * set room parameters (aide or room aide command)
972 void cmd_setr(char *args) {
975 char old_name[ROOMNAMELEN];
979 if (!(CC->logged_in)) {
980 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
984 if (!is_room_aide()) {
985 cprintf("%d Higher access required.\n",
986 ERROR+HIGHER_ACCESS_REQUIRED);
990 if (is_noneditable(&CC->quickroom)) {
991 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
995 if (num_parms(args)>=6) {
996 getfloor(&flbuf,extract_int(args,5));
997 if ((flbuf.f_flags & F_INUSE) == 0) {
998 cprintf("%d Invalid floor number.\n",
999 ERROR+INVALID_FLOOR_OPERATION);
1004 if (num_parms(args)>=7) {
1005 new_order = extract_int(args, 6);
1006 if (new_order < 1) new_order = 1;
1007 if (new_order > 127) new_order = 127;
1010 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1011 strcpy(old_name, CC->quickroom.QRname);
1012 extract(buf,args,0); buf[ROOMNAMELEN]=0;
1013 strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
1014 extract(buf,args,1); buf[10]=0;
1015 strncpy(CC->quickroom.QRpasswd,buf,9);
1016 extract(buf,args,2); buf[15]=0;
1017 strncpy(CC->quickroom.QRdirname,buf,19);
1018 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
1019 if (num_parms(args)>=7)
1020 CC->quickroom.QRorder = (char)new_order;
1022 /* Clean up a client boo-boo: if the client set the room to
1023 * guess-name or passworded, ensure that the private flag is
1026 if ((CC->quickroom.QRflags & QR_GUESSNAME)
1027 ||(CC->quickroom.QRflags & QR_PASSWORDED))
1028 CC->quickroom.QRflags |= QR_PRIVATE;
1030 /* Kick everyone out if the client requested it (by changing the
1031 * room's generation number)
1033 if (extract_int(args,4)) {
1034 time(&CC->quickroom.QRgen);
1037 old_floor = CC->quickroom.QRfloor;
1038 if (num_parms(args)>=6) {
1039 CC->quickroom.QRfloor = extract_int(args,5);
1042 /* Write the room record back to disk */
1043 lputroom(&CC->quickroom, CC->quickroom.QRname);
1045 /* If the room name changed, then there are now two room records,
1046 * so we have to delete the old one.
1048 if (strcasecmp(CC->quickroom.QRname, old_name)) {
1049 putroom(NULL, old_name);
1052 /* adjust the floor reference counts */
1053 lgetfloor(&flbuf,old_floor);
1054 --flbuf.f_ref_count;
1055 lputfloor(&flbuf,old_floor);
1056 lgetfloor(&flbuf,CC->quickroom.QRfloor);
1057 ++flbuf.f_ref_count;
1058 lputfloor(&flbuf,CC->quickroom.QRfloor);
1060 /* create a room directory if necessary */
1061 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1063 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1064 CC->quickroom.QRdirname);
1068 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
1070 cprintf("%d Ok\n",OK);
1076 * get the name of the room aide for this room
1078 void cmd_geta(void) {
1079 struct usersupp usbuf;
1081 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
1082 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1086 if (is_noneditable(&CC->quickroom)) {
1087 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1091 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
1092 cprintf("%d %s\n",OK,usbuf.fullname);
1095 cprintf("%d \n",OK);
1101 * set the room aide for this room
1103 void cmd_seta(char *new_ra)
1105 struct usersupp usbuf;
1110 if (!(CC->logged_in)) {
1111 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1115 if (!is_room_aide()) {
1116 cprintf("%d Higher access required.\n",
1117 ERROR+HIGHER_ACCESS_REQUIRED);
1121 if (getuser(&usbuf,new_ra)!=0) {
1125 newu = usbuf.usernum;
1128 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1130 if (CC->quickroom.QRroomaide != newu) {
1133 CC->quickroom.QRroomaide = newu;
1134 lputroom(&CC->quickroom, CC->quickroom.QRname);
1137 * We have to post the change notice _after_ writing changes to
1138 * the room table, otherwise it would deadlock!
1140 if (post_notice == 1) {
1141 sprintf(buf,"%s is now room aide for %s>",
1142 usbuf.fullname,CC->quickroom.QRname);
1145 cprintf("%d Ok\n",OK);
1149 * Generate an associated file name for a room
1151 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
1152 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1156 * retrieve info file for this room
1158 void cmd_rinf(void) {
1163 assoc_file_name(filename, &CC->quickroom, "info");
1164 info_fp = fopen(filename,"r");
1166 if (info_fp==NULL) {
1167 cprintf("%d No info file.\n",ERROR);
1171 cprintf("%d Info:\n",LISTING_FOLLOWS);
1172 while (fgets(buf, 256, info_fp) != NULL) {
1173 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1174 cprintf("%s\n", buf);
1181 * Back end processing to delete a room and everything associated with it
1183 void delete_room(struct quickroom *qrbuf) {
1189 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1191 /* Delete the info file */
1192 assoc_file_name(aaa, qrbuf, "info");
1195 /* Delete the image file */
1196 assoc_file_name(aaa, qrbuf, "images");
1199 /* first flag the room record as not in use */
1200 lgetroom(qrbuf, qrbuf->QRname);
1203 /* then delete the messages in the room */
1205 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1206 MsgToDelete = MessageFromList(a);
1207 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1213 delete_msglist(qrbuf);
1214 lputroom(qrbuf, qrbuf->QRname);
1216 /* then decrement the reference count for the floor */
1217 lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
1218 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1219 lputfloor(&flbuf,(int)(qrbuf->QRfloor));
1221 /* Delete the room record from the database! */
1222 putroom(NULL, qrbuf->QRname);
1227 * aide command: kill the current room
1229 void cmd_kill(char *argbuf) {
1231 char deleted_room_name[ROOMNAMELEN];
1234 kill_ok = extract_int(argbuf,0);
1236 if (!(CC->logged_in)) {
1237 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1241 if (!is_room_aide()) {
1242 cprintf("%d Higher access required.\n",
1243 ERROR+HIGHER_ACCESS_REQUIRED);
1247 if (is_noneditable(&CC->quickroom)) {
1248 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1253 strcpy(deleted_room_name, CC->quickroom.QRname);
1254 delete_room(&CC->quickroom); /* Do the dirty work */
1255 usergoto(BASEROOM, 0); /* Return to the Lobby */
1257 /* tell the world what we did */
1258 sprintf(aaa,"%s> killed by %s",
1259 deleted_room_name, CC->curr_user);
1261 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1264 cprintf("%d ok to delete.\n",OK);
1270 * Internal code to create a new room (returns room flags)
1272 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1274 unsigned create_room(char *new_room_name,
1276 char *new_room_pass,
1277 int new_room_floor) {
1279 struct quickroom qrbuf;
1283 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1285 memset(&qrbuf, 0, sizeof(struct quickroom));
1286 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1287 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1288 qrbuf.QRflags = QR_INUSE;
1289 qrbuf.QRnumber = get_new_room_number();
1290 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1291 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1292 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1293 if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
1295 /* If the room is private, and the system administrator has elected
1296 * to automatically grant room aide privileges, do so now; otherwise,
1297 * set the room aide to undefined.
1299 if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) {
1300 qrbuf.QRroomaide=CC->usersupp.usernum;
1303 qrbuf.QRroomaide = (-1L);
1306 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1307 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1308 qrbuf.QRfloor = new_room_floor;
1310 /* save what we just did... */
1311 putroom(&qrbuf, qrbuf.QRname);
1313 /* bump the reference count on whatever floor the room is on */
1314 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1315 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1316 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1318 /* be sure not to kick the creator out of the room! */
1319 lgetuser(&CC->usersupp,CC->curr_user);
1320 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1321 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1322 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1323 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1324 lputuser(&CC->usersupp,CC->curr_user);
1326 /* resume our happy day */
1327 return(qrbuf.QRflags);
1334 void cmd_cre8(char *args)
1337 char new_room_name[256];
1339 char new_room_pass[256];
1343 struct quickroom qrbuf;
1346 cre8_ok = extract_int(args,0);
1347 extract(new_room_name,args,1);
1348 new_room_name[ROOMNAMELEN-1] = 0;
1349 new_room_type = extract_int(args,2);
1350 extract(new_room_pass,args,3);
1351 new_room_pass[9] = 0;
1354 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1355 cprintf("%d Invalid room name.\n",ERROR);
1359 if (!strcasecmp(new_room_name, MAILROOM)) {
1360 cprintf("%d '%s' already exists.\n",
1361 ERROR+ALREADY_EXISTS, new_room_name);
1365 if (num_parms(args)>=5) {
1366 getfloor(&flbuf,extract_int(args,4));
1367 if ((flbuf.f_flags & F_INUSE) == 0) {
1368 cprintf("%d Invalid floor number.\n",
1369 ERROR+INVALID_FLOOR_OPERATION);
1373 new_room_floor = extract_int(args,4);
1377 if (!(CC->logged_in)) {
1378 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1382 if (CC->usersupp.axlevel<3) {
1383 cprintf("%d You need higher access to create rooms.\n",
1384 ERROR+HIGHER_ACCESS_REQUIRED);
1388 if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
1389 cprintf("%d Ok to create rooms.\n", OK);
1393 /* Check to make sure the requested room name doesn't already exist */
1394 if (getroom(&qrbuf, new_room_name)==0) {
1395 cprintf("%d '%s' already exists.\n",
1396 ERROR+ALREADY_EXISTS, qrbuf.QRname);
1400 if ((new_room_type < 0) || (new_room_type > 3)) {
1401 cprintf("%d Invalid room type.\n",ERROR);
1406 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1410 newflags = create_room(new_room_name,
1411 new_room_type,new_room_pass,new_room_floor);
1413 /* post a message in Aide> describing the new room */
1414 strncpy(aaa,new_room_name,255);
1415 strcat(aaa,"> created by ");
1416 strcat(aaa,CC->usersupp.fullname);
1417 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1418 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1419 if (newflags&QR_PASSWORDED) {
1420 strcat(aaa,"\n Password: ");
1421 strcat(aaa,new_room_pass);
1425 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1430 void cmd_einf(char *ok)
1431 { /* enter info file for current room */
1433 char infofilename[256];
1436 if (!(CC->logged_in)) {
1437 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1441 if (!is_room_aide()) {
1442 cprintf("%d Higher access required.\n",
1443 ERROR+HIGHER_ACCESS_REQUIRED);
1448 cprintf("%d Ok.\n",OK);
1452 assoc_file_name(infofilename, &CC->quickroom, "info");
1453 lprintf(9, "opening\n");
1454 fp = fopen(infofilename, "w");
1455 lprintf(9, "checking\n");
1457 cprintf("%d Cannot open %s: %s\n",
1458 ERROR+INTERNAL_ERROR, infofilename, strerror(errno));
1462 cprintf("%d Send info...\n", SEND_LISTING);
1466 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1467 } while(strcmp(buf,"000"));
1470 /* now update the room index so people will see our new info */
1471 lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */
1472 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1473 lputroom(&CC->quickroom,CC->quickroom.QRname);
1478 * cmd_lflr() - List all known floors
1480 void cmd_lflr(void) {
1484 if (!(CC->logged_in)) {
1485 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1489 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1490 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1495 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1497 for (a=0; a<MAXFLOORS; ++a) {
1499 if (flbuf.f_flags & F_INUSE) {
1500 cprintf("%d|%s|%d\n",
1512 * create a new floor
1514 void cmd_cflr(char *argbuf)
1516 char new_floor_name[256];
1519 int free_slot = (-1);
1522 extract(new_floor_name,argbuf,0);
1523 cflr_ok = extract_int(argbuf,1);
1526 if (!(CC->logged_in)) {
1527 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1531 if (CC->usersupp.axlevel<6) {
1532 cprintf("%d You need higher access to create rooms.\n",
1533 ERROR+HIGHER_ACCESS_REQUIRED);
1537 for (a=0; a<MAXFLOORS; ++a) {
1540 /* note any free slots while we're scanning... */
1541 if ( ((flbuf.f_flags & F_INUSE)==0)
1542 && (free_slot < 0) ) free_slot = a;
1544 /* check to see if it already exists */
1545 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1546 && (flbuf.f_flags & F_INUSE) ) {
1547 cprintf("%d Floor '%s' already exists.\n",
1548 ERROR+ALREADY_EXISTS,
1556 cprintf("%d There is no space available for a new floor.\n",
1557 ERROR+INVALID_FLOOR_OPERATION);
1562 cprintf("%d ok to create...\n",OK);
1566 lgetfloor(&flbuf,free_slot);
1567 flbuf.f_flags = F_INUSE;
1568 flbuf.f_ref_count = 0;
1569 strncpy(flbuf.f_name,new_floor_name,255);
1570 lputfloor(&flbuf,free_slot);
1571 cprintf("%d %d\n",OK,free_slot);
1579 void cmd_kflr(char *argbuf)
1582 int floor_to_delete;
1586 floor_to_delete = extract_int(argbuf,0);
1587 kflr_ok = extract_int(argbuf,1);
1590 if (!(CC->logged_in)) {
1591 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1595 if (CC->usersupp.axlevel<6) {
1596 cprintf("%d You need higher access to delete floors.\n",
1597 ERROR+HIGHER_ACCESS_REQUIRED);
1601 lgetfloor(&flbuf,floor_to_delete);
1604 if ((flbuf.f_flags & F_INUSE) == 0) {
1605 cprintf("%d Floor %d not in use.\n",
1606 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1611 if (flbuf.f_ref_count != 0) {
1612 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1613 ERROR+INVALID_FLOOR_OPERATION,
1620 cprintf("%d Ok\n",OK);
1623 cprintf("%d Ok to delete...\n",OK);
1630 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1631 lputfloor(&flbuf,floor_to_delete);
1637 void cmd_eflr(char *argbuf)
1643 np = num_parms(argbuf);
1645 cprintf("%d Usage error.\n",ERROR);
1649 if (!(CC->logged_in)) {
1650 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1654 if (CC->usersupp.axlevel<6) {
1655 cprintf("%d You need higher access to edit floors.\n",
1656 ERROR+HIGHER_ACCESS_REQUIRED);
1660 floor_num = extract_int(argbuf,0);
1661 lgetfloor(&flbuf,floor_num);
1662 if ( (flbuf.f_flags & F_INUSE) == 0) {
1663 lputfloor(&flbuf,floor_num);
1664 cprintf("%d Floor %d is not in use.\n",
1665 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1668 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1669 lputfloor(&flbuf,floor_num);
1671 cprintf("%d Ok\n",OK);