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 = malloc(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 = malloc(cdbfr->len);
353 num_msgs = cdbfr->len / sizeof(long);
354 memcpy(msglist, cdbfr->ptr, cdbfr->len);
358 /* Now add the new message */
360 msglist = realloc(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);
679 lgetuser(&CC->usersupp,CC->curr_user);
680 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
682 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
683 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
685 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
686 lputuser(&CC->usersupp,CC->curr_user);
688 /* check for new mail */
689 newmailcount = NewMailCount();
691 /* set info to 1 if the user needs to read the room's info file */
692 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
695 get_msglist(&CC->quickroom);
696 for (a=0; a<CC->num_msgs; ++a) {
697 if (MessageFromList(a)>0L) {
699 if (MessageFromList(a) > vbuf.v_lastseen) {
705 if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1;
708 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
709 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
712 strcpy(truncated_roomname, CC->quickroom.QRname);
713 if (CC->quickroom.QRflags & QR_MAILBOX) {
714 strcpy(truncated_roomname, &truncated_roomname[11]);
717 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
720 new_messages, total_messages,
721 info,CC->quickroom.QRflags,
722 CC->quickroom.QRhighest,
724 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
726 set_wtmpsupp_to_current_room();
731 * cmd_goto() - goto a new room
733 void cmd_goto(char *gargs)
735 struct quickroom QRscratch;
739 char augmented_roomname[256];
743 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
744 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
748 extract(towhere,gargs,0);
749 extract(password,gargs,1);
751 getuser(&CC->usersupp, CC->curr_user);
753 if (!strcasecmp(towhere, "_BASEROOM_"))
754 strcpy(towhere, BASEROOM);
756 if (!strcasecmp(towhere, "_MAIL_"))
757 strcpy(towhere, MAILROOM);
759 if (!strcasecmp(towhere, "_BITBUCKET_"))
760 strcpy(towhere, config.c_twitroom);
763 /* First try a regular match */
764 c = getroom(&QRscratch, towhere);
766 /* Then try a mailbox name match */
768 MailboxName(augmented_roomname, &CC->usersupp, towhere);
769 c = getroom(&QRscratch, augmented_roomname);
770 if (c == 0) strcpy(towhere, augmented_roomname);
773 /* And if the room was found... */
776 /* let internal programs go directly to any room */
777 if (CC->internal_pgm) {
778 usergoto(towhere, 1);
782 /* See if there is an existing user/room relationship */
783 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
785 /* normal clients have to pass through security */
786 if (ra & UA_GOTOALLOWED) ok = 1;
789 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
790 ((ra & UA_KNOWN) == 0) &&
791 (strcasecmp(QRscratch.QRpasswd,password))
793 cprintf("%d wrong or missing passwd\n",
794 ERROR+PASSWORD_REQUIRED);
798 usergoto(towhere, 1);
804 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
808 void cmd_whok(void) {
809 struct usersupp temp;
810 struct cdbdata *cdbus;
812 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
813 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
816 getuser(&CC->usersupp,CC->curr_user);
818 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
819 cprintf("%d Higher access required.\n",
820 ERROR+HIGHER_ACCESS_REQUIRED);
824 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
825 cdb_rewind(CDB_USERSUPP);
826 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
827 memset(&temp, 0, sizeof(struct usersupp));
828 memcpy(&temp, cdbus->ptr, cdbus->len);
831 if ( (CC->quickroom.QRflags & QR_INUSE)
832 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
833 ) cprintf("%s\n",temp.fullname);
840 * RDIR command for room directory
842 void cmd_rdir(void) {
849 if (!(CC->logged_in)) {
850 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
854 getroom(&CC->quickroom, CC->quickroom.QRname);
855 getuser(&CC->usersupp, CC->curr_user);
857 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
858 cprintf("%d not here.\n",ERROR+NOT_HERE);
862 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
863 && (CC->usersupp.axlevel<6)
864 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
865 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
869 cprintf("%d %s|%s/files/%s\n",
870 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
872 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
873 BBSDIR,CC->quickroom.QRdirname,CC->temp);
876 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
878 if (fd==NULL) fd=fopen("/dev/null","r");
880 ls = fopen(CC->temp,"r");
881 while (fgets(flnm,256,ls)!=NULL) {
882 flnm[strlen(flnm)-1]=0;
883 if (strcasecmp(flnm,"filedir")) {
884 sprintf(buf,"%s/files/%s/%s",
885 BBSDIR,CC->quickroom.QRdirname,flnm);
889 while ((fgets(buf,256,fd)!=NULL)
890 &&(strlen(comment)==0)) {
891 buf[strlen(buf)-1] = 0;
892 if ((!strncasecmp(buf,flnm,strlen(flnm)))
893 && (buf[strlen(flnm)]==' '))
895 &buf[strlen(flnm)+1],255);
897 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
908 * get room parameters (aide or room aide command)
910 void cmd_getr(void) {
911 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
912 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
916 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
917 cprintf("%d Higher access required.\n",
918 ERROR+HIGHER_ACCESS_REQUIRED);
922 if (is_noneditable(&CC->quickroom)) {
923 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
927 getroom(&CC->quickroom, CC->quickroom.QRname);
928 cprintf("%d%c%s|%s|%s|%d|%d\n",
930 CC->quickroom.QRname,
931 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
932 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
933 CC->quickroom.QRflags,
934 (int)CC->quickroom.QRfloor);
939 * set room parameters (aide or room aide command)
941 void cmd_setr(char *args) {
944 char old_name[ROOMNAMELEN];
947 if (!(CC->logged_in)) {
948 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
952 if (!is_room_aide()) {
953 cprintf("%d Higher access required.\n",
954 ERROR+HIGHER_ACCESS_REQUIRED);
958 if (is_noneditable(&CC->quickroom)) {
959 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
963 if (num_parms(args)>=6) {
964 getfloor(&flbuf,extract_int(args,5));
965 if ((flbuf.f_flags & F_INUSE) == 0) {
966 cprintf("%d Invalid floor number.\n",
967 ERROR+INVALID_FLOOR_OPERATION);
972 lgetroom(&CC->quickroom, CC->quickroom.QRname);
973 strcpy(old_name, CC->quickroom.QRname);
974 extract(buf,args,0); buf[ROOMNAMELEN]=0;
975 strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
976 extract(buf,args,1); buf[10]=0;
977 strncpy(CC->quickroom.QRpasswd,buf,9);
978 extract(buf,args,2); buf[15]=0;
979 strncpy(CC->quickroom.QRdirname,buf,19);
980 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
982 /* Clean up a client boo-boo: if the client set the room to
983 * guess-name or passworded, ensure that the private flag is
986 if ((CC->quickroom.QRflags & QR_GUESSNAME)
987 ||(CC->quickroom.QRflags & QR_PASSWORDED))
988 CC->quickroom.QRflags |= QR_PRIVATE;
990 /* Kick everyone out if the client requested it (by changing the
991 * room's generation number)
993 if (extract_int(args,4)) {
994 time(&CC->quickroom.QRgen);
997 old_floor = CC->quickroom.QRfloor;
998 if (num_parms(args)>=6) {
999 CC->quickroom.QRfloor = extract_int(args,5);
1002 /* Write the room record back to disk */
1003 lputroom(&CC->quickroom, CC->quickroom.QRname);
1005 /* If the room name changed, then there are now two room records,
1006 * so we have to delete the old one.
1008 if (strcasecmp(CC->quickroom.QRname, old_name)) {
1009 putroom(NULL, old_name);
1012 /* adjust the floor reference counts */
1013 lgetfloor(&flbuf,old_floor);
1014 --flbuf.f_ref_count;
1015 lputfloor(&flbuf,old_floor);
1016 lgetfloor(&flbuf,CC->quickroom.QRfloor);
1017 ++flbuf.f_ref_count;
1018 lputfloor(&flbuf,CC->quickroom.QRfloor);
1020 /* create a room directory if necessary */
1021 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1023 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1024 CC->quickroom.QRdirname);
1028 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
1030 cprintf("%d Ok\n",OK);
1036 * get the name of the room aide for this room
1038 void cmd_geta(void) {
1039 struct usersupp usbuf;
1041 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
1042 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1046 if (is_noneditable(&CC->quickroom)) {
1047 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1051 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
1052 cprintf("%d %s\n",OK,usbuf.fullname);
1055 cprintf("%d \n",OK);
1061 * set the room aide for this room
1063 void cmd_seta(char *new_ra)
1065 struct usersupp usbuf;
1070 if (!(CC->logged_in)) {
1071 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1075 if (!is_room_aide()) {
1076 cprintf("%d Higher access required.\n",
1077 ERROR+HIGHER_ACCESS_REQUIRED);
1081 if (getuser(&usbuf,new_ra)!=0) {
1085 newu = usbuf.usernum;
1088 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1090 if (CC->quickroom.QRroomaide != newu) {
1093 CC->quickroom.QRroomaide = newu;
1094 lputroom(&CC->quickroom, CC->quickroom.QRname);
1097 * We have to post the change notice _after_ writing changes to
1098 * the room table, otherwise it would deadlock!
1100 if (post_notice == 1) {
1101 sprintf(buf,"%s is now room aide for %s>",
1102 usbuf.fullname,CC->quickroom.QRname);
1105 cprintf("%d Ok\n",OK);
1109 * Generate an associated file name for a room
1111 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
1112 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1116 * retrieve info file for this room
1118 void cmd_rinf(void) {
1123 assoc_file_name(filename, &CC->quickroom, "info");
1124 info_fp = fopen(filename,"r");
1126 if (info_fp==NULL) {
1127 cprintf("%d No info file.\n",ERROR);
1131 cprintf("%d Info:\n",LISTING_FOLLOWS);
1132 while (fgets(buf, 256, info_fp) != NULL) {
1133 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1134 cprintf("%s\n", buf);
1141 * Back end processing to delete a room and everything associated with it
1143 void delete_room(struct quickroom *qrbuf) {
1149 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1151 /* Delete the info file */
1152 assoc_file_name(aaa, qrbuf, "info");
1155 /* Delete the image file */
1156 assoc_file_name(aaa, qrbuf, "images");
1159 /* first flag the room record as not in use */
1160 lgetroom(qrbuf, qrbuf->QRname);
1163 /* then delete the messages in the room */
1165 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1166 MsgToDelete = MessageFromList(a);
1167 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1173 delete_msglist(qrbuf);
1174 lputroom(qrbuf, qrbuf->QRname);
1176 /* then decrement the reference count for the floor */
1177 lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
1178 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1179 lputfloor(&flbuf,(int)(qrbuf->QRfloor));
1181 /* Delete the room record from the database! */
1182 putroom(NULL, qrbuf->QRname);
1187 * aide command: kill the current room
1189 void cmd_kill(char *argbuf) {
1191 char deleted_room_name[ROOMNAMELEN];
1194 kill_ok = extract_int(argbuf,0);
1196 if (!(CC->logged_in)) {
1197 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1201 if (!is_room_aide()) {
1202 cprintf("%d Higher access required.\n",
1203 ERROR+HIGHER_ACCESS_REQUIRED);
1207 if (is_noneditable(&CC->quickroom)) {
1208 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1213 strcpy(deleted_room_name, CC->quickroom.QRname);
1214 delete_room(&CC->quickroom); /* Do the dirty work */
1215 usergoto(BASEROOM, 0); /* Return to the Lobby */
1217 /* tell the world what we did */
1218 sprintf(aaa,"%s> killed by %s",
1219 deleted_room_name, CC->curr_user);
1221 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1224 cprintf("%d ok to delete.\n",OK);
1230 * Internal code to create a new room (returns room flags)
1232 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1234 unsigned create_room(char *new_room_name,
1236 char *new_room_pass,
1237 int new_room_floor) {
1239 struct quickroom qrbuf;
1243 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1245 memset(&qrbuf, 0, sizeof(struct quickroom));
1246 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1247 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1248 qrbuf.QRflags = QR_INUSE;
1249 qrbuf.QRnumber = get_new_room_number();
1250 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1251 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1252 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1253 if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
1255 /* If the room is private, and the system administrator has elected
1256 * to automatically grant room aide privileges, do so now; otherwise,
1257 * set the room aide to undefined.
1259 if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) {
1260 qrbuf.QRroomaide=CC->usersupp.usernum;
1263 qrbuf.QRroomaide = (-1L);
1266 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1267 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1268 qrbuf.QRfloor = new_room_floor;
1270 /* save what we just did... */
1271 putroom(&qrbuf, qrbuf.QRname);
1273 /* bump the reference count on whatever floor the room is on */
1274 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1275 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1276 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1278 /* be sure not to kick the creator out of the room! */
1279 lgetuser(&CC->usersupp,CC->curr_user);
1280 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1281 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1282 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1283 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1284 lputuser(&CC->usersupp,CC->curr_user);
1286 /* resume our happy day */
1287 return(qrbuf.QRflags);
1294 void cmd_cre8(char *args)
1297 char new_room_name[256];
1299 char new_room_pass[256];
1303 struct quickroom qrbuf;
1306 cre8_ok = extract_int(args,0);
1307 extract(new_room_name,args,1);
1308 new_room_name[ROOMNAMELEN-1] = 0;
1309 new_room_type = extract_int(args,2);
1310 extract(new_room_pass,args,3);
1311 new_room_pass[9] = 0;
1314 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1315 cprintf("%d Invalid room name.\n",ERROR);
1319 if (!strcasecmp(new_room_name, MAILROOM)) {
1320 cprintf("%d '%s' already exists.\n",
1321 ERROR+ALREADY_EXISTS, new_room_name);
1325 if (num_parms(args)>=5) {
1326 getfloor(&flbuf,extract_int(args,4));
1327 if ((flbuf.f_flags & F_INUSE) == 0) {
1328 cprintf("%d Invalid floor number.\n",
1329 ERROR+INVALID_FLOOR_OPERATION);
1333 new_room_floor = extract_int(args,4);
1337 if (!(CC->logged_in)) {
1338 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1342 if (CC->usersupp.axlevel<3) {
1343 cprintf("%d You need higher access to create rooms.\n",
1344 ERROR+HIGHER_ACCESS_REQUIRED);
1348 if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
1349 cprintf("%d Ok to create rooms.\n", OK);
1353 /* Check to make sure the requested room name doesn't already exist */
1354 if (getroom(&qrbuf, new_room_name)==0) {
1355 cprintf("%d '%s' already exists.\n",
1356 ERROR+ALREADY_EXISTS, qrbuf.QRname);
1360 if ((new_room_type < 0) || (new_room_type > 3)) {
1361 cprintf("%d Invalid room type.\n",ERROR);
1366 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1370 newflags = create_room(new_room_name,
1371 new_room_type,new_room_pass,new_room_floor);
1373 /* post a message in Aide> describing the new room */
1374 strncpy(aaa,new_room_name,255);
1375 strcat(aaa,"> created by ");
1376 strcat(aaa,CC->usersupp.fullname);
1377 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1378 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1379 if (newflags&QR_PASSWORDED) {
1380 strcat(aaa,"\n Password: ");
1381 strcat(aaa,new_room_pass);
1385 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1390 void cmd_einf(char *ok)
1391 { /* enter info file for current room */
1393 char infofilename[256];
1396 if (!(CC->logged_in)) {
1397 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1401 if (!is_room_aide()) {
1402 cprintf("%d Higher access required.\n",
1403 ERROR+HIGHER_ACCESS_REQUIRED);
1408 cprintf("%d Ok.\n",OK);
1412 assoc_file_name(infofilename, &CC->quickroom, "info");
1413 lprintf(9, "opening\n");
1414 fp = fopen(infofilename, "w");
1415 lprintf(9, "checking\n");
1417 cprintf("%d Cannot open %s: %s\n",
1418 ERROR+INTERNAL_ERROR, infofilename, strerror(errno));
1422 cprintf("%d Send info...\n", SEND_LISTING);
1426 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1427 } while(strcmp(buf,"000"));
1430 /* now update the room index so people will see our new info */
1431 lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */
1432 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1433 lputroom(&CC->quickroom,CC->quickroom.QRname);
1438 * cmd_lflr() - List all known floors
1440 void cmd_lflr(void) {
1444 if (!(CC->logged_in)) {
1445 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1449 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1450 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1455 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1457 for (a=0; a<MAXFLOORS; ++a) {
1459 if (flbuf.f_flags & F_INUSE) {
1460 cprintf("%d|%s|%d\n",
1472 * create a new floor
1474 void cmd_cflr(char *argbuf)
1476 char new_floor_name[256];
1479 int free_slot = (-1);
1482 extract(new_floor_name,argbuf,0);
1483 cflr_ok = extract_int(argbuf,1);
1486 if (!(CC->logged_in)) {
1487 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1491 if (CC->usersupp.axlevel<6) {
1492 cprintf("%d You need higher access to create rooms.\n",
1493 ERROR+HIGHER_ACCESS_REQUIRED);
1497 for (a=0; a<MAXFLOORS; ++a) {
1500 /* note any free slots while we're scanning... */
1501 if ( ((flbuf.f_flags & F_INUSE)==0)
1502 && (free_slot < 0) ) free_slot = a;
1504 /* check to see if it already exists */
1505 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1506 && (flbuf.f_flags & F_INUSE) ) {
1507 cprintf("%d Floor '%s' already exists.\n",
1508 ERROR+ALREADY_EXISTS,
1516 cprintf("%d There is no space available for a new floor.\n",
1517 ERROR+INVALID_FLOOR_OPERATION);
1522 cprintf("%d ok to create...\n",OK);
1526 lgetfloor(&flbuf,free_slot);
1527 flbuf.f_flags = F_INUSE;
1528 flbuf.f_ref_count = 0;
1529 strncpy(flbuf.f_name,new_floor_name,255);
1530 lputfloor(&flbuf,free_slot);
1531 cprintf("%d %d\n",OK,free_slot);
1539 void cmd_kflr(char *argbuf)
1542 int floor_to_delete;
1546 floor_to_delete = extract_int(argbuf,0);
1547 kflr_ok = extract_int(argbuf,1);
1550 if (!(CC->logged_in)) {
1551 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1555 if (CC->usersupp.axlevel<6) {
1556 cprintf("%d You need higher access to delete floors.\n",
1557 ERROR+HIGHER_ACCESS_REQUIRED);
1561 lgetfloor(&flbuf,floor_to_delete);
1564 if ((flbuf.f_flags & F_INUSE) == 0) {
1565 cprintf("%d Floor %d not in use.\n",
1566 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1571 if (flbuf.f_ref_count != 0) {
1572 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1573 ERROR+INVALID_FLOOR_OPERATION,
1580 cprintf("%d Ok\n",OK);
1583 cprintf("%d Ok to delete...\n",OK);
1590 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1591 lputfloor(&flbuf,floor_to_delete);
1597 void cmd_eflr(char *argbuf)
1603 np = num_parms(argbuf);
1605 cprintf("%d Usage error.\n",ERROR);
1609 if (!(CC->logged_in)) {
1610 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1614 if (CC->usersupp.axlevel<6) {
1615 cprintf("%d You need higher access to edit floors.\n",
1616 ERROR+HIGHER_ACCESS_REQUIRED);
1620 floor_num = extract_int(argbuf,0);
1621 lgetfloor(&flbuf,floor_num);
1622 if ( (flbuf.f_flags & F_INUSE) == 0) {
1623 lputfloor(&flbuf,floor_num);
1624 cprintf("%d Floor %d is not in use.\n",
1625 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1628 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1629 lputfloor(&flbuf,floor_num);
1631 cprintf("%d Ok\n",OK);