16 #include "sysdep_decls.h"
20 #include "serv_chat.h"
21 #include "citserver.h"
26 * Generic routine for determining user access to rooms
28 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf) {
32 /* for internal programs, always do everything */
33 if (((CC->internal_pgm))&&(roombuf->QRflags & QR_INUSE)) {
34 return(UA_KNOWN | UA_GOTOALLOWED);
37 /* For mailbox rooms, only allow access to the owner */
38 if (roombuf->QRflags & QR_MAILBOX) {
39 if (userbuf->usernum != atol(roombuf->QRname)) {
44 /* Locate any applicable user/room relationships */
45 CtdlGetRelationship(&vbuf, userbuf, roombuf);
47 /* Force the properties of the Aide room */
48 if (!strcasecmp(roombuf->QRname, AIDEROOM)) {
49 if (userbuf->axlevel >= 6) {
50 retval = UA_KNOWN | UA_GOTOALLOWED;
58 /* For mailboxes, we skip all the access stuff (and we've
59 * already checked by this point that the mailbox belongs
62 if (roombuf->QRflags & QR_MAILBOX) {
63 retval = UA_KNOWN | UA_GOTOALLOWED;
67 /* If this is a public room, it's accessible... */
68 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
69 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
72 /* If this is a preferred users only room, check access level */
73 if (roombuf->QRflags & QR_PREFONLY) {
74 if (userbuf->axlevel < 5) {
75 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
79 /* For private rooms, check the generation number matchups */
80 if (roombuf->QRflags & QR_PRIVATE) {
82 /* An explicit match means the user belongs in this room */
83 if (vbuf.v_flags & V_ACCESS) {
84 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
86 /* Otherwise, check if this is a guess-name or passworded
87 * room. If it is, a goto may at least be attempted
89 else if ((roombuf->QRflags & QR_PRIVATE)
90 ||(roombuf->QRflags & QR_PASSWORDED)) {
91 retval = retval & ~UA_KNOWN;
92 retval = retval | UA_GOTOALLOWED;
96 /* Check to see if the user has forgotten this room */
97 if (vbuf.v_flags & V_FORGET) {
98 retval = retval & ~UA_KNOWN;
99 retval = retval | UA_ZAPPED;
102 /* If user is explicitly locked out of this room, deny everything */
103 if (vbuf.v_flags & V_LOCKOUT) {
104 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
107 /* Aides get access to everything */
108 if (userbuf->axlevel >= 6) {
109 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
110 retval = retval & ~UA_ZAPPED;
113 NEWMSG: /* By the way, we also check for the presence of new messages */
114 if ( (roombuf->QRhighest) > (vbuf.v_lastseen) ) {
115 retval = retval | UA_HASNEWMSGS;
122 * getroom() - retrieve room data from disk
124 int getroom(struct quickroom *qrbuf, char *room_name)
126 struct cdbdata *cdbqr;
127 char lowercase_name[ROOMNAMELEN];
130 for (a=0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
131 lowercase_name[a] = tolower(room_name[a]);
133 lowercase_name[a] = 0;
135 memset(qrbuf, 0, sizeof(struct quickroom));
136 cdbqr = cdb_fetch(CDB_QUICKROOM,
137 lowercase_name, strlen(lowercase_name));
139 memcpy(qrbuf, cdbqr->ptr,
140 ( (cdbqr->len > sizeof(struct quickroom)) ?
141 sizeof(struct quickroom) : cdbqr->len) );
144 /* Mailbox rooms are always on the lowest floor */
145 if (qrbuf->QRflags & QR_MAILBOX) {
157 * lgetroom() - same as getroom() but locks the record (if supported)
159 int lgetroom(struct quickroom *qrbuf, char *room_name)
161 begin_critical_section(S_QUICKROOM);
162 return(getroom(qrbuf, room_name));
167 * putroom() - store room data on disk
168 * (if the supplied buffer is NULL, delete the room record)
170 void putroom(struct quickroom *qrbuf, char *room_name)
172 char lowercase_name[ROOMNAMELEN];
175 for (a=0; a<=strlen(room_name); ++a) {
176 lowercase_name[a] = tolower(room_name[a]);
180 cdb_delete(CDB_QUICKROOM,
181 lowercase_name, strlen(lowercase_name));
184 time(&qrbuf->QRmtime);
185 cdb_store(CDB_QUICKROOM,
186 lowercase_name, strlen(lowercase_name),
187 qrbuf, sizeof(struct quickroom));
193 * lputroom() - same as putroom() but unlocks the record (if supported)
195 void lputroom(struct quickroom *qrbuf, char *room_name)
198 putroom(qrbuf, room_name);
199 end_critical_section(S_QUICKROOM);
203 /****************************************************************************/
206 * getfloor() - retrieve floor data from disk
208 void getfloor(struct floor *flbuf, int floor_num)
210 struct cdbdata *cdbfl;
212 memset(flbuf, 0, sizeof(struct floor));
213 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
215 memcpy(flbuf, cdbfl->ptr,
216 ( (cdbfl->len > sizeof(struct floor)) ?
217 sizeof(struct floor) : cdbfl->len) );
221 if (floor_num == 0) {
222 strcpy(flbuf->f_name, "Main Floor");
223 flbuf->f_flags = F_INUSE;
224 flbuf->f_ref_count = 3;
231 * lgetfloor() - same as getfloor() but locks the record (if supported)
233 void lgetfloor(struct floor *flbuf, int floor_num)
236 begin_critical_section(S_FLOORTAB);
237 getfloor(flbuf,floor_num);
242 * putfloor() - store floor data on disk
244 void putfloor(struct floor *flbuf, int floor_num)
246 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
247 flbuf, sizeof(struct floor));
252 * lputfloor() - same as putfloor() but unlocks the record (if supported)
254 void lputfloor(struct floor *flbuf, int floor_num)
257 putfloor(flbuf,floor_num);
258 end_critical_section(S_FLOORTAB);
264 * Traverse the room file...
266 void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) {
267 struct quickroom qrbuf;
268 struct cdbdata *cdbqr;
270 cdb_rewind(CDB_QUICKROOM);
272 while(cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
273 memset(&qrbuf, 0, sizeof(struct quickroom));
274 memcpy(&qrbuf, cdbqr->ptr,
275 ( (cdbqr->len > sizeof(struct quickroom)) ?
276 sizeof(struct quickroom) : cdbqr->len) );
278 if (qrbuf.QRflags & QR_INUSE) (*CallBack)(&qrbuf);
285 * get_msglist() - retrieve room message pointers
287 void get_msglist(struct quickroom *whichroom) {
288 struct cdbdata *cdbfr;
290 if (CC->msglist != NULL) {
296 cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
301 CC->msglist = mallok(cdbfr->len);
302 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
303 CC->num_msgs = cdbfr->len / sizeof(long);
309 * put_msglist() - retrieve room message pointers
311 void put_msglist(struct quickroom *whichroom) {
313 cdb_store(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long),
314 CC->msglist, CC->num_msgs * sizeof(long));
319 * delete_msglist() - delete room message pointers
320 * FIX - this really should check first to make sure there's actually a
321 * msglist to delete. As things stand now, calling this function on
322 * a room which has never been posted in will result in a message
323 * like "gdbm: illegal data" (no big deal, but could use fixing).
325 void delete_msglist(struct quickroom *whichroom) {
327 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
332 * Add a message number to a room's message list.
333 * So, why doesn't this function use the get_msglist() and put_msglist() stuff
334 * defined above? Because the room the message number is being written to
335 * may not be the current room (as is the case with cmd_move() for example).
337 * This function returns the highest message number present in the room after
338 * the add operation is performed - which is not necessarily the message
341 long AddMessageToRoom(struct quickroom *whichroom, long newmsgid) {
342 struct cdbdata *cdbfr;
345 long highest_msg = 0L;
347 cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
353 msglist = mallok(cdbfr->len);
354 num_msgs = cdbfr->len / sizeof(long);
355 memcpy(msglist, cdbfr->ptr, cdbfr->len);
359 /* Now add the new message */
361 msglist = reallok(msglist,
362 (num_msgs * sizeof(long)) );
364 if (msglist == NULL) {
365 lprintf(3, "ERROR: can't realloc message list!\n");
368 msglist[num_msgs - 1] = newmsgid;
370 /* Sort the message list, so all the msgid's are in order */
371 num_msgs = sort_msglist(msglist, num_msgs);
373 /* Determine the highest message number */
374 highest_msg = msglist[num_msgs - 1];
376 /* Write it back to disk. */
377 cdb_store(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long),
378 msglist, num_msgs * sizeof(long));
380 /* And finally, free up the memory we used. */
387 * MessageFromList() - get a message number from the list currently in memory
389 long MessageFromList(int whichpos) {
391 /* Return zero if the position is invalid */
392 if (whichpos >= CC->num_msgs) return 0L;
394 return(CC->msglist[whichpos]);
398 * SetMessageInList() - set a message number in the list currently in memory
400 void SetMessageInList(int whichpos, long newmsgnum) {
402 /* Return zero if the position is invalid */
403 if (whichpos >= CC->num_msgs) return;
405 CC->msglist[whichpos] = newmsgnum;
411 * sort message pointers
412 * (returns new msg count)
414 int sort_msglist(long listptrs[], int oldcount)
421 if (numitems < 2) return(oldcount);
424 for (a=numitems-2; a>=0; --a) {
425 for (b=0; b<=a; ++b) {
426 if (listptrs[b] > (listptrs[b+1])) {
428 hold2 = listptrs[b+1];
430 listptrs[b+1] = hold1;
435 /* and yank any nulls */
436 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
437 memcpy(&listptrs[0], &listptrs[1],
438 (sizeof(long) * (CC->num_msgs - 1)) );
447 * Determine whether a given room is non-editable.
449 int is_noneditable(struct quickroom *qrbuf) {
451 /* Lobby> and Aide> are non-editable */
452 if (!strcasecmp(qrbuf->QRname, BASEROOM)) return(1);
453 else if (!strcasecmp(qrbuf->QRname, AIDEROOM)) return(1);
455 /* Mailbox rooms are also non-editable */
456 else if (qrbuf->QRflags & QR_MAILBOX) return(1);
458 /* Everything else is editable */
465 * Back-back-end for all room listing commands
467 void list_roomname(struct quickroom *qrbuf) {
468 char truncated_roomname[ROOMNAMELEN];
470 /* For mailbox rooms, chop off the owner prefix */
471 if (qrbuf->QRflags & QR_MAILBOX) {
472 strcpy(truncated_roomname, qrbuf->QRname);
473 strcpy(truncated_roomname, &truncated_roomname[11]);
474 cprintf("%s", truncated_roomname);
476 /* For all other rooms, just display the name in its entirety */
478 cprintf("%s", qrbuf->QRname);
481 /* ...and now the other parameters */
483 qrbuf->QRflags,qrbuf->QRfloor);
488 * cmd_lrms() - List all accessible rooms, known or forgotten
490 void cmd_lrms_backend(struct quickroom *qrbuf) {
491 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
492 & (UA_KNOWN | UA_ZAPPED)))
493 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
494 ||((CC->FloorBeingSearched)<0)) )
495 list_roomname(qrbuf);
498 void cmd_lrms(char *argbuf)
500 CC->FloorBeingSearched = (-1);
501 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
503 if (!(CC->logged_in)) {
504 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
508 if (getuser(&CC->usersupp,CC->curr_user)) {
509 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
513 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
515 ForEachRoom(cmd_lrms_backend);
522 * cmd_lkra() - List all known rooms
524 void cmd_lkra_backend(struct quickroom *qrbuf) {
525 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
527 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
528 ||((CC->FloorBeingSearched)<0)) )
529 list_roomname(qrbuf);
532 void cmd_lkra(char *argbuf)
534 CC->FloorBeingSearched = (-1);
535 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
537 if (!(CC->logged_in)) {
538 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
542 if (getuser(&CC->usersupp,CC->curr_user)) {
543 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
547 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
549 ForEachRoom(cmd_lkra_backend);
556 * cmd_lkrn() - List all known rooms with new messages
558 void cmd_lkrn_backend(struct quickroom *qrbuf) {
561 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
563 && (ra & UA_HASNEWMSGS)
564 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
565 ||((CC->FloorBeingSearched)<0)) )
566 list_roomname(qrbuf);
569 void cmd_lkrn(char *argbuf)
571 CC->FloorBeingSearched = (-1);
572 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
574 if (!(CC->logged_in)) {
575 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
579 if (getuser(&CC->usersupp,CC->curr_user)) {
580 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
584 cprintf("%d Rooms w/ new msgs:\n",LISTING_FOLLOWS);
586 ForEachRoom(cmd_lkrn_backend);
593 * cmd_lkro() - List all known rooms
595 void cmd_lkro_backend(struct quickroom *qrbuf) {
598 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
600 && ((ra & UA_HASNEWMSGS)==0)
601 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
602 ||((CC->FloorBeingSearched)<0)) )
603 list_roomname(qrbuf);
606 void cmd_lkro(char *argbuf)
608 CC->FloorBeingSearched = (-1);
609 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
611 if (!(CC->logged_in)) {
612 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
616 if (getuser(&CC->usersupp,CC->curr_user)) {
617 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
621 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
623 ForEachRoom(cmd_lkro_backend);
630 * cmd_lzrm() - List all forgotten rooms
632 void cmd_lzrm_backend(struct quickroom *qrbuf) {
635 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
636 if ( (ra & UA_GOTOALLOWED)
638 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
639 ||((CC->FloorBeingSearched)<0)) )
640 list_roomname(qrbuf);
643 void cmd_lzrm(char *argbuf)
645 CC->FloorBeingSearched = (-1);
646 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
648 if (!(CC->logged_in)) {
649 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
653 if (getuser(&CC->usersupp,CC->curr_user)) {
654 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
658 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
660 ForEachRoom(cmd_lzrm_backend);
666 void usergoto(char *where, int display_result)
669 int new_messages = 0;
670 int total_messages = 0;
674 int newmailcount = 0;
676 char truncated_roomname[ROOMNAMELEN];
678 strcpy(CC->quickroom.QRname, where);
679 getroom(&CC->quickroom, where);
681 lgetuser(&CC->usersupp,CC->curr_user);
682 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
684 /* Know the room ... but not if it's the page log room */
685 if (strcasecmp(where, config.c_logpages)) {
686 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
687 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
690 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
691 lputuser(&CC->usersupp,CC->curr_user);
693 /* check for new mail */
694 newmailcount = NewMailCount();
696 /* set info to 1 if the user needs to read the room's info file */
697 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
700 get_msglist(&CC->quickroom);
701 for (a=0; a<CC->num_msgs; ++a) {
702 if (MessageFromList(a)>0L) {
704 if (MessageFromList(a) > vbuf.v_lastseen) {
710 if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1;
713 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
714 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
717 strcpy(truncated_roomname, CC->quickroom.QRname);
718 if (CC->quickroom.QRflags & QR_MAILBOX) {
719 strcpy(truncated_roomname, &truncated_roomname[11]);
722 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
725 new_messages, total_messages,
726 info,CC->quickroom.QRflags,
727 CC->quickroom.QRhighest,
729 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
731 set_wtmpsupp_to_current_room();
736 * cmd_goto() - goto a new room
738 void cmd_goto(char *gargs)
740 struct quickroom QRscratch;
744 char augmented_roomname[256];
748 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
749 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
753 extract(towhere,gargs,0);
754 extract(password,gargs,1);
756 getuser(&CC->usersupp, CC->curr_user);
758 if (!strcasecmp(towhere, "_BASEROOM_"))
759 strcpy(towhere, BASEROOM);
761 if (!strcasecmp(towhere, "_MAIL_"))
762 strcpy(towhere, MAILROOM);
764 if (!strcasecmp(towhere, "_BITBUCKET_"))
765 strcpy(towhere, config.c_twitroom);
768 /* First try a regular match */
769 c = getroom(&QRscratch, towhere);
771 /* Then try a mailbox name match */
773 MailboxName(augmented_roomname, &CC->usersupp, towhere);
774 c = getroom(&QRscratch, augmented_roomname);
775 if (c == 0) strcpy(towhere, augmented_roomname);
778 /* And if the room was found... */
781 /* let internal programs go directly to any room */
782 if (CC->internal_pgm) {
783 usergoto(towhere, 1);
787 /* See if there is an existing user/room relationship */
788 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
790 /* normal clients have to pass through security */
791 if (ra & UA_GOTOALLOWED) ok = 1;
794 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
795 ((ra & UA_KNOWN) == 0) &&
796 (strcasecmp(QRscratch.QRpasswd,password))
798 cprintf("%d wrong or missing passwd\n",
799 ERROR+PASSWORD_REQUIRED);
802 else if ( (QRscratch.QRflags&QR_PRIVATE) &&
803 ((QRscratch.QRflags&QR_PASSWORDED)==0) &&
804 ((QRscratch.QRflags&QR_GUESSNAME)==0) &&
805 ((ra & UA_KNOWN) == 0) ) {
809 usergoto(towhere, 1);
815 NOPE: cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
819 void cmd_whok(void) {
820 struct usersupp temp;
821 struct cdbdata *cdbus;
823 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
824 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
827 getuser(&CC->usersupp,CC->curr_user);
829 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
830 cprintf("%d Higher access required.\n",
831 ERROR+HIGHER_ACCESS_REQUIRED);
835 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
836 cdb_rewind(CDB_USERSUPP);
837 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
838 memset(&temp, 0, sizeof(struct usersupp));
839 memcpy(&temp, cdbus->ptr, cdbus->len);
842 if ( (CC->quickroom.QRflags & QR_INUSE)
843 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
844 ) cprintf("%s\n",temp.fullname);
851 * RDIR command for room directory
853 void cmd_rdir(void) {
860 if (!(CC->logged_in)) {
861 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
865 getroom(&CC->quickroom, CC->quickroom.QRname);
866 getuser(&CC->usersupp, CC->curr_user);
868 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
869 cprintf("%d not here.\n",ERROR+NOT_HERE);
873 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
874 && (CC->usersupp.axlevel<6)
875 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
876 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
880 cprintf("%d %s|%s/files/%s\n",
881 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
883 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
884 BBSDIR,CC->quickroom.QRdirname,CC->temp);
887 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
889 if (fd==NULL) fd=fopen("/dev/null","r");
891 ls = fopen(CC->temp,"r");
892 while (fgets(flnm,256,ls)!=NULL) {
893 flnm[strlen(flnm)-1]=0;
894 if (strcasecmp(flnm,"filedir")) {
895 sprintf(buf,"%s/files/%s/%s",
896 BBSDIR,CC->quickroom.QRdirname,flnm);
900 while ((fgets(buf,256,fd)!=NULL)
901 &&(strlen(comment)==0)) {
902 buf[strlen(buf)-1] = 0;
903 if ((!strncasecmp(buf,flnm,strlen(flnm)))
904 && (buf[strlen(flnm)]==' '))
906 &buf[strlen(flnm)+1],255);
908 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
919 * get room parameters (aide or room aide command)
921 void cmd_getr(void) {
922 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
923 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
927 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
928 cprintf("%d Higher access required.\n",
929 ERROR+HIGHER_ACCESS_REQUIRED);
933 if (is_noneditable(&CC->quickroom)) {
934 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
938 getroom(&CC->quickroom, CC->quickroom.QRname);
939 cprintf("%d%c%s|%s|%s|%d|%d\n",
941 CC->quickroom.QRname,
942 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
943 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
944 CC->quickroom.QRflags,
945 (int)CC->quickroom.QRfloor);
950 * set room parameters (aide or room aide command)
952 void cmd_setr(char *args) {
955 char old_name[ROOMNAMELEN];
958 if (!(CC->logged_in)) {
959 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
963 if (!is_room_aide()) {
964 cprintf("%d Higher access required.\n",
965 ERROR+HIGHER_ACCESS_REQUIRED);
969 if (is_noneditable(&CC->quickroom)) {
970 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
974 if (num_parms(args)>=6) {
975 getfloor(&flbuf,extract_int(args,5));
976 if ((flbuf.f_flags & F_INUSE) == 0) {
977 cprintf("%d Invalid floor number.\n",
978 ERROR+INVALID_FLOOR_OPERATION);
983 lgetroom(&CC->quickroom, CC->quickroom.QRname);
984 strcpy(old_name, CC->quickroom.QRname);
985 extract(buf,args,0); buf[ROOMNAMELEN]=0;
986 strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
987 extract(buf,args,1); buf[10]=0;
988 strncpy(CC->quickroom.QRpasswd,buf,9);
989 extract(buf,args,2); buf[15]=0;
990 strncpy(CC->quickroom.QRdirname,buf,19);
991 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
993 /* Clean up a client boo-boo: if the client set the room to
994 * guess-name or passworded, ensure that the private flag is
997 if ((CC->quickroom.QRflags & QR_GUESSNAME)
998 ||(CC->quickroom.QRflags & QR_PASSWORDED))
999 CC->quickroom.QRflags |= QR_PRIVATE;
1001 /* Kick everyone out if the client requested it (by changing the
1002 * room's generation number)
1004 if (extract_int(args,4)) {
1005 time(&CC->quickroom.QRgen);
1008 old_floor = CC->quickroom.QRfloor;
1009 if (num_parms(args)>=6) {
1010 CC->quickroom.QRfloor = extract_int(args,5);
1013 /* Write the room record back to disk */
1014 lputroom(&CC->quickroom, CC->quickroom.QRname);
1016 /* If the room name changed, then there are now two room records,
1017 * so we have to delete the old one.
1019 if (strcasecmp(CC->quickroom.QRname, old_name)) {
1020 putroom(NULL, old_name);
1023 /* adjust the floor reference counts */
1024 lgetfloor(&flbuf,old_floor);
1025 --flbuf.f_ref_count;
1026 lputfloor(&flbuf,old_floor);
1027 lgetfloor(&flbuf,CC->quickroom.QRfloor);
1028 ++flbuf.f_ref_count;
1029 lputfloor(&flbuf,CC->quickroom.QRfloor);
1031 /* create a room directory if necessary */
1032 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1034 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1035 CC->quickroom.QRdirname);
1039 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
1041 cprintf("%d Ok\n",OK);
1047 * get the name of the room aide for this room
1049 void cmd_geta(void) {
1050 struct usersupp usbuf;
1052 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
1053 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1057 if (is_noneditable(&CC->quickroom)) {
1058 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1062 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
1063 cprintf("%d %s\n",OK,usbuf.fullname);
1066 cprintf("%d \n",OK);
1072 * set the room aide for this room
1074 void cmd_seta(char *new_ra)
1076 struct usersupp usbuf;
1081 if (!(CC->logged_in)) {
1082 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1086 if (!is_room_aide()) {
1087 cprintf("%d Higher access required.\n",
1088 ERROR+HIGHER_ACCESS_REQUIRED);
1092 if (getuser(&usbuf,new_ra)!=0) {
1096 newu = usbuf.usernum;
1099 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1101 if (CC->quickroom.QRroomaide != newu) {
1104 CC->quickroom.QRroomaide = newu;
1105 lputroom(&CC->quickroom, CC->quickroom.QRname);
1108 * We have to post the change notice _after_ writing changes to
1109 * the room table, otherwise it would deadlock!
1111 if (post_notice == 1) {
1112 sprintf(buf,"%s is now room aide for %s>",
1113 usbuf.fullname,CC->quickroom.QRname);
1116 cprintf("%d Ok\n",OK);
1120 * Generate an associated file name for a room
1122 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
1123 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1127 * retrieve info file for this room
1129 void cmd_rinf(void) {
1134 assoc_file_name(filename, &CC->quickroom, "info");
1135 info_fp = fopen(filename,"r");
1137 if (info_fp==NULL) {
1138 cprintf("%d No info file.\n",ERROR);
1142 cprintf("%d Info:\n",LISTING_FOLLOWS);
1143 while (fgets(buf, 256, info_fp) != NULL) {
1144 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1145 cprintf("%s\n", buf);
1152 * Back end processing to delete a room and everything associated with it
1154 void delete_room(struct quickroom *qrbuf) {
1160 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1162 /* Delete the info file */
1163 assoc_file_name(aaa, qrbuf, "info");
1166 /* Delete the image file */
1167 assoc_file_name(aaa, qrbuf, "images");
1170 /* first flag the room record as not in use */
1171 lgetroom(qrbuf, qrbuf->QRname);
1174 /* then delete the messages in the room */
1176 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1177 MsgToDelete = MessageFromList(a);
1178 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1184 delete_msglist(qrbuf);
1185 lputroom(qrbuf, qrbuf->QRname);
1187 /* then decrement the reference count for the floor */
1188 lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
1189 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1190 lputfloor(&flbuf,(int)(qrbuf->QRfloor));
1192 /* Delete the room record from the database! */
1193 putroom(NULL, qrbuf->QRname);
1198 * aide command: kill the current room
1200 void cmd_kill(char *argbuf) {
1202 char deleted_room_name[ROOMNAMELEN];
1205 kill_ok = extract_int(argbuf,0);
1207 if (!(CC->logged_in)) {
1208 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1212 if (!is_room_aide()) {
1213 cprintf("%d Higher access required.\n",
1214 ERROR+HIGHER_ACCESS_REQUIRED);
1218 if (is_noneditable(&CC->quickroom)) {
1219 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1224 strcpy(deleted_room_name, CC->quickroom.QRname);
1225 delete_room(&CC->quickroom); /* Do the dirty work */
1226 usergoto(BASEROOM, 0); /* Return to the Lobby */
1228 /* tell the world what we did */
1229 sprintf(aaa,"%s> killed by %s",
1230 deleted_room_name, CC->curr_user);
1232 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1235 cprintf("%d ok to delete.\n",OK);
1241 * Internal code to create a new room (returns room flags)
1243 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1245 unsigned create_room(char *new_room_name,
1247 char *new_room_pass,
1248 int new_room_floor) {
1250 struct quickroom qrbuf;
1254 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1256 memset(&qrbuf, 0, sizeof(struct quickroom));
1257 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1258 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1259 qrbuf.QRflags = QR_INUSE;
1260 qrbuf.QRnumber = get_new_room_number();
1261 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1262 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1263 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1264 if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
1266 /* If the room is private, and the system administrator has elected
1267 * to automatically grant room aide privileges, do so now; otherwise,
1268 * set the room aide to undefined.
1270 if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) {
1271 qrbuf.QRroomaide=CC->usersupp.usernum;
1274 qrbuf.QRroomaide = (-1L);
1277 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1278 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1279 qrbuf.QRfloor = new_room_floor;
1281 /* save what we just did... */
1282 putroom(&qrbuf, qrbuf.QRname);
1284 /* bump the reference count on whatever floor the room is on */
1285 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1286 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1287 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1289 /* be sure not to kick the creator out of the room! */
1290 lgetuser(&CC->usersupp,CC->curr_user);
1291 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1292 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1293 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1294 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1295 lputuser(&CC->usersupp,CC->curr_user);
1297 /* resume our happy day */
1298 return(qrbuf.QRflags);
1305 void cmd_cre8(char *args)
1308 char new_room_name[256];
1310 char new_room_pass[256];
1314 struct quickroom qrbuf;
1317 cre8_ok = extract_int(args,0);
1318 extract(new_room_name,args,1);
1319 new_room_name[ROOMNAMELEN-1] = 0;
1320 new_room_type = extract_int(args,2);
1321 extract(new_room_pass,args,3);
1322 new_room_pass[9] = 0;
1325 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1326 cprintf("%d Invalid room name.\n",ERROR);
1330 if (!strcasecmp(new_room_name, MAILROOM)) {
1331 cprintf("%d '%s' already exists.\n",
1332 ERROR+ALREADY_EXISTS, new_room_name);
1336 if (num_parms(args)>=5) {
1337 getfloor(&flbuf,extract_int(args,4));
1338 if ((flbuf.f_flags & F_INUSE) == 0) {
1339 cprintf("%d Invalid floor number.\n",
1340 ERROR+INVALID_FLOOR_OPERATION);
1344 new_room_floor = extract_int(args,4);
1348 if (!(CC->logged_in)) {
1349 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1353 if (CC->usersupp.axlevel<3) {
1354 cprintf("%d You need higher access to create rooms.\n",
1355 ERROR+HIGHER_ACCESS_REQUIRED);
1359 if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
1360 cprintf("%d Ok to create rooms.\n", OK);
1364 /* Check to make sure the requested room name doesn't already exist */
1365 if (getroom(&qrbuf, new_room_name)==0) {
1366 cprintf("%d '%s' already exists.\n",
1367 ERROR+ALREADY_EXISTS, qrbuf.QRname);
1371 if ((new_room_type < 0) || (new_room_type > 3)) {
1372 cprintf("%d Invalid room type.\n",ERROR);
1377 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1381 newflags = create_room(new_room_name,
1382 new_room_type,new_room_pass,new_room_floor);
1384 /* post a message in Aide> describing the new room */
1385 strncpy(aaa,new_room_name,255);
1386 strcat(aaa,"> created by ");
1387 strcat(aaa,CC->usersupp.fullname);
1388 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1389 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1390 if (newflags&QR_PASSWORDED) {
1391 strcat(aaa,"\n Password: ");
1392 strcat(aaa,new_room_pass);
1396 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1401 void cmd_einf(char *ok)
1402 { /* enter info file for current room */
1404 char infofilename[256];
1407 if (!(CC->logged_in)) {
1408 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1412 if (!is_room_aide()) {
1413 cprintf("%d Higher access required.\n",
1414 ERROR+HIGHER_ACCESS_REQUIRED);
1419 cprintf("%d Ok.\n",OK);
1423 assoc_file_name(infofilename, &CC->quickroom, "info");
1424 lprintf(9, "opening\n");
1425 fp = fopen(infofilename, "w");
1426 lprintf(9, "checking\n");
1428 cprintf("%d Cannot open %s: %s\n",
1429 ERROR+INTERNAL_ERROR, infofilename, strerror(errno));
1433 cprintf("%d Send info...\n", SEND_LISTING);
1437 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1438 } while(strcmp(buf,"000"));
1441 /* now update the room index so people will see our new info */
1442 lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */
1443 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1444 lputroom(&CC->quickroom,CC->quickroom.QRname);
1449 * cmd_lflr() - List all known floors
1451 void cmd_lflr(void) {
1455 if (!(CC->logged_in)) {
1456 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1460 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1461 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1466 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1468 for (a=0; a<MAXFLOORS; ++a) {
1470 if (flbuf.f_flags & F_INUSE) {
1471 cprintf("%d|%s|%d\n",
1483 * create a new floor
1485 void cmd_cflr(char *argbuf)
1487 char new_floor_name[256];
1490 int free_slot = (-1);
1493 extract(new_floor_name,argbuf,0);
1494 cflr_ok = extract_int(argbuf,1);
1497 if (!(CC->logged_in)) {
1498 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1502 if (CC->usersupp.axlevel<6) {
1503 cprintf("%d You need higher access to create rooms.\n",
1504 ERROR+HIGHER_ACCESS_REQUIRED);
1508 for (a=0; a<MAXFLOORS; ++a) {
1511 /* note any free slots while we're scanning... */
1512 if ( ((flbuf.f_flags & F_INUSE)==0)
1513 && (free_slot < 0) ) free_slot = a;
1515 /* check to see if it already exists */
1516 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1517 && (flbuf.f_flags & F_INUSE) ) {
1518 cprintf("%d Floor '%s' already exists.\n",
1519 ERROR+ALREADY_EXISTS,
1527 cprintf("%d There is no space available for a new floor.\n",
1528 ERROR+INVALID_FLOOR_OPERATION);
1533 cprintf("%d ok to create...\n",OK);
1537 lgetfloor(&flbuf,free_slot);
1538 flbuf.f_flags = F_INUSE;
1539 flbuf.f_ref_count = 0;
1540 strncpy(flbuf.f_name,new_floor_name,255);
1541 lputfloor(&flbuf,free_slot);
1542 cprintf("%d %d\n",OK,free_slot);
1550 void cmd_kflr(char *argbuf)
1553 int floor_to_delete;
1557 floor_to_delete = extract_int(argbuf,0);
1558 kflr_ok = extract_int(argbuf,1);
1561 if (!(CC->logged_in)) {
1562 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1566 if (CC->usersupp.axlevel<6) {
1567 cprintf("%d You need higher access to delete floors.\n",
1568 ERROR+HIGHER_ACCESS_REQUIRED);
1572 lgetfloor(&flbuf,floor_to_delete);
1575 if ((flbuf.f_flags & F_INUSE) == 0) {
1576 cprintf("%d Floor %d not in use.\n",
1577 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1582 if (flbuf.f_ref_count != 0) {
1583 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1584 ERROR+INVALID_FLOOR_OPERATION,
1591 cprintf("%d Ok\n",OK);
1594 cprintf("%d Ok to delete...\n",OK);
1601 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1602 lputfloor(&flbuf,floor_to_delete);
1608 void cmd_eflr(char *argbuf)
1614 np = num_parms(argbuf);
1616 cprintf("%d Usage error.\n",ERROR);
1620 if (!(CC->logged_in)) {
1621 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1625 if (CC->usersupp.axlevel<6) {
1626 cprintf("%d You need higher access to edit floors.\n",
1627 ERROR+HIGHER_ACCESS_REQUIRED);
1631 floor_num = extract_int(argbuf,0);
1632 lgetfloor(&flbuf,floor_num);
1633 if ( (flbuf.f_flags & F_INUSE) == 0) {
1634 lputfloor(&flbuf,floor_num);
1635 cprintf("%d Floor %d is not in use.\n",
1636 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1639 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1640 lputfloor(&flbuf,floor_num);
1642 cprintf("%d Ok\n",OK);