14 #include "sysdep_decls.h"
18 #include "serv_chat.h"
19 #include "citserver.h"
22 * Generic routine for determining user access to rooms
24 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf) {
28 /* Make sure we're dealing with a real, existing room */
29 if (roombuf->QRflags & QR_INUSE) {
30 retval = retval | UA_INUSE;
36 /* for internal programs, always do everything */
37 if (((CC->internal_pgm))&&(roombuf->QRflags & QR_INUSE)) {
38 return(UA_INUSE | UA_KNOWN | UA_GOTOALLOWED);
41 /* For mailbox rooms, only allow access to the owner */
42 if (roombuf->QRflags & QR_MAILBOX) {
43 if (userbuf->usernum != atol(roombuf->QRname)) {
48 /* Locate any applicable user/room relationships */
49 CtdlGetRelationship(&vbuf, userbuf, roombuf);
51 /* If this is a public room, it's accessible... */
52 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
53 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
56 /* If this is a preferred users only room, check access level */
57 if (roombuf->QRflags & QR_PREFONLY) {
58 if (userbuf->axlevel < 5) {
59 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
63 /* For private rooms, check the generation number matchups */
64 if (roombuf->QRflags & QR_PRIVATE) {
66 /* An explicit match means the user belongs in this room */
67 if (vbuf.v_flags & V_ACCESS) {
68 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
70 /* Otherwise, check if this is a guess-name or passworded
71 * room. If it is, a goto may at least be attempted
73 else if ((roombuf->QRflags & QR_PRIVATE)
74 ||(roombuf->QRflags & QR_PASSWORDED)) {
75 retval = retval & ~UA_KNOWN;
76 retval = retval | UA_GOTOALLOWED;
80 /* Check to see if the user has forgotten this room */
81 if (vbuf.v_flags & V_FORGET) {
82 retval = retval & ~UA_KNOWN;
83 retval = retval | UA_ZAPPED;
86 /* If user is explicitly locked out of this room, deny everything */
87 if (vbuf.v_flags & V_LOCKOUT) {
88 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
91 /* Aides get access to everything */
92 if (userbuf->axlevel >= 6) {
93 retval = retval | UA_INUSE | UA_KNOWN | UA_GOTOALLOWED;
94 retval = retval & ~UA_ZAPPED;
97 /* By the way, we also check for the presence of new messages */
98 if ( (roombuf->QRhighest) > (vbuf.v_lastseen) ) {
99 retval = retval | UA_HASNEWMSGS;
106 * getroom() - retrieve room data from disk
108 int getroom(struct quickroom *qrbuf, char *room_name)
110 struct cdbdata *cdbqr;
111 char lowercase_name[ROOMNAMELEN];
114 for (a=0; a<=strlen(room_name); ++a) {
115 lowercase_name[a] = tolower(room_name[a]);
118 memset(qrbuf, 0, sizeof(struct quickroom));
119 cdbqr = cdb_fetch(CDB_QUICKROOM,
120 lowercase_name, strlen(lowercase_name));
122 memcpy(qrbuf, cdbqr->ptr,
123 ( (cdbqr->len > sizeof(struct quickroom)) ?
124 sizeof(struct quickroom) : cdbqr->len) );
134 * lgetroom() - same as getroom() but locks the record (if supported)
136 int lgetroom(struct quickroom *qrbuf, char *room_name)
138 begin_critical_section(S_QUICKROOM);
139 return(getroom(qrbuf, room_name));
144 * putroom() - store room data on disk
145 * (if the supplied buffer is NULL, delete the room record)
147 void putroom(struct quickroom *qrbuf, char *room_name)
149 char lowercase_name[ROOMNAMELEN];
152 for (a=0; a<=strlen(room_name); ++a) {
153 lowercase_name[a] = tolower(room_name[a]);
157 cdb_delete(CDB_QUICKROOM,
158 lowercase_name, strlen(lowercase_name));
161 time(&qrbuf->QRmtime);
162 cdb_store(CDB_QUICKROOM,
163 lowercase_name, strlen(lowercase_name),
164 qrbuf, sizeof(struct quickroom));
170 * lputroom() - same as putroom() but unlocks the record (if supported)
172 void lputroom(struct quickroom *qrbuf, char *room_name)
175 putroom(qrbuf, room_name);
176 end_critical_section(S_QUICKROOM);
180 /****************************************************************************/
183 * getfloor() - retrieve floor data from disk
185 void getfloor(struct floor *flbuf, int floor_num)
187 struct cdbdata *cdbfl;
189 memset(flbuf, 0, sizeof(struct floor));
190 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
192 memcpy(flbuf, cdbfl->ptr,
193 ( (cdbfl->len > sizeof(struct floor)) ?
194 sizeof(struct floor) : cdbfl->len) );
198 if (floor_num == 0) {
199 strcpy(flbuf->f_name, "Main Floor");
200 flbuf->f_flags = F_INUSE;
201 flbuf->f_ref_count = 3;
208 * lgetfloor() - same as getfloor() but locks the record (if supported)
210 void lgetfloor(struct floor *flbuf, int floor_num)
213 begin_critical_section(S_FLOORTAB);
214 getfloor(flbuf,floor_num);
219 * putfloor() - store floor data on disk
221 void putfloor(struct floor *flbuf, int floor_num)
223 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
224 flbuf, sizeof(struct floor));
229 * lputfloor() - same as putfloor() but unlocks the record (if supported)
231 void lputfloor(struct floor *flbuf, int floor_num)
234 putfloor(flbuf,floor_num);
235 end_critical_section(S_FLOORTAB);
241 * Traverse the room file...
243 void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) {
244 struct quickroom qrbuf;
245 struct cdbdata *cdbqr;
247 cdb_rewind(CDB_QUICKROOM);
249 while(cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
250 memset(&qrbuf, 0, sizeof(struct quickroom));
251 memcpy(&qrbuf, cdbqr->ptr,
252 ( (cdbqr->len > sizeof(struct quickroom)) ?
253 sizeof(struct quickroom) : cdbqr->len) );
255 if (qrbuf.QRflags & QR_INUSE) (*CallBack)(&qrbuf);
262 * get_msglist() - retrieve room message pointers
264 void get_msglist(struct quickroom *whichroom) {
265 struct cdbdata *cdbfr;
269 sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
270 for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
272 if (CC->msglist != NULL) {
278 cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey));
284 CC->msglist = malloc(cdbfr->len);
285 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
286 CC->num_msgs = cdbfr->len / sizeof(long);
292 * put_msglist() - retrieve room message pointers
294 void put_msglist(struct quickroom *whichroom) {
298 sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
299 for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
301 cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey),
302 CC->msglist, CC->num_msgs * sizeof(long));
307 * delete_msglist() - delete room message pointers
309 void delete_msglist(struct quickroom *whichroom) {
313 sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
314 for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
316 cdb_delete(CDB_MSGLISTS, dbkey, strlen(dbkey));
321 * MessageFromList() - get a message number from the list currently in memory
323 long MessageFromList(int whichpos) {
325 /* Return zero if the position is invalid */
326 if (whichpos >= CC->num_msgs) return 0L;
328 return(CC->msglist[whichpos]);
332 * SetMessageInList() - set a message number in the list currently in memory
334 void SetMessageInList(int whichpos, long newmsgnum) {
336 /* Return zero if the position is invalid */
337 if (whichpos >= CC->num_msgs) return;
339 CC->msglist[whichpos] = newmsgnum;
345 * sort message pointers
346 * (returns new msg count)
348 int sort_msglist(long listptrs[], int oldcount)
355 if (numitems < 2) return(oldcount);
358 for (a=numitems-2; a>=0; --a) {
359 for (b=0; b<=a; ++b) {
360 if (listptrs[b] > (listptrs[b+1])) {
362 hold2 = listptrs[b+1];
364 listptrs[b+1] = hold1;
369 /* and yank any nulls */
370 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
371 memcpy(&listptrs[0], &listptrs[1],
372 (sizeof(long) * (CC->num_msgs - 1)) );
381 * Determine whether a given room is one of the base non-editable rooms
383 int is_noneditable(struct quickroom *qrbuf) {
384 if (!strcasecmp(qrbuf->QRname, BASEROOM)) return(1);
385 else if (!strcasecmp(qrbuf->QRname, AIDEROOM)) return(1);
392 * Retrieve the applicable room policy for a specific room
394 void GetExpirePolicy(struct ExpirePolicy *epbuf, struct quickroom *qrbuf) {
397 /* If the room has its own policy, return it */
398 if (qrbuf->QRep.expire_mode != 0) {
399 memcpy(epbuf, &qrbuf->QRep, sizeof(struct ExpirePolicy));
403 /* Otherwise, if the floor has its own policy, return it */
404 getfloor(&flbuf, qrbuf->QRfloor);
405 if (flbuf.f_ep.expire_mode != 0) {
406 memcpy(epbuf, &flbuf.f_ep, sizeof(struct ExpirePolicy));
410 /* Otherwise, fall back on the system default */
411 memcpy(epbuf, &config.c_ep, sizeof(struct ExpirePolicy));
417 * cmd_lrms() - List all accessible rooms, known or forgotten
419 void cmd_lrms_backend(struct quickroom *qrbuf) {
420 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
421 & (UA_KNOWN | UA_ZAPPED)))
422 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
423 ||((CC->FloorBeingSearched)<0)) )
424 cprintf("%s|%u|%d\n",
425 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
428 void cmd_lrms(char *argbuf)
430 CC->FloorBeingSearched = (-1);
431 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
433 if (!(CC->logged_in)) {
434 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
438 if (getuser(&CC->usersupp,CC->curr_user)) {
439 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
443 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
445 ForEachRoom(cmd_lrms_backend);
452 * cmd_lkra() - List all known rooms
454 void cmd_lkra_backend(struct quickroom *qrbuf) {
455 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
457 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
458 ||((CC->FloorBeingSearched)<0)) )
459 cprintf("%s|%u|%d\n",
460 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
463 void cmd_lkra(char *argbuf)
465 CC->FloorBeingSearched = (-1);
466 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
468 if (!(CC->logged_in)) {
469 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
473 if (getuser(&CC->usersupp,CC->curr_user)) {
474 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
478 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
480 ForEachRoom(cmd_lkra_backend);
487 * cmd_lkrn() - List all known rooms with new messages
489 void cmd_lkrn_backend(struct quickroom *qrbuf) {
492 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
494 && (ra & UA_HASNEWMSGS)
495 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
496 ||((CC->FloorBeingSearched)<0)) )
497 cprintf("%s|%u|%d\n",
498 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
501 void cmd_lkrn(char *argbuf)
503 CC->FloorBeingSearched = (-1);
504 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
506 if (!(CC->logged_in)) {
507 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
511 if (getuser(&CC->usersupp,CC->curr_user)) {
512 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
516 cprintf("%d Rooms w/ new msgs:\n",LISTING_FOLLOWS);
518 ForEachRoom(cmd_lkrn_backend);
525 * cmd_lkro() - List all known rooms
527 void cmd_lkro_backend(struct quickroom *qrbuf) {
530 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
532 && ((ra & UA_HASNEWMSGS)==0)
533 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
534 ||((CC->FloorBeingSearched)<0)) )
535 cprintf("%s|%u|%d\n",
536 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
539 void cmd_lkro(char *argbuf)
541 CC->FloorBeingSearched = (-1);
542 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
544 if (!(CC->logged_in)) {
545 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
549 if (getuser(&CC->usersupp,CC->curr_user)) {
550 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
554 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
556 ForEachRoom(cmd_lkro_backend);
563 * cmd_lzrm() - List all forgotten rooms
565 void cmd_lzrm_backend(struct quickroom *qrbuf) {
568 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
569 if ( (ra & UA_GOTOALLOWED)
571 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
572 ||((CC->FloorBeingSearched)<0)) )
573 cprintf("%s|%u|%d\n",
574 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
577 void cmd_lzrm(char *argbuf)
579 CC->FloorBeingSearched = (-1);
580 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
582 if (!(CC->logged_in)) {
583 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
587 if (getuser(&CC->usersupp,CC->curr_user)) {
588 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
592 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
594 ForEachRoom(cmd_lzrm_backend);
600 void usergoto(char *where, int display_result)
603 int new_messages = 0;
604 int total_messages = 0;
608 int newmailcount = 0;
611 strcpy(CC->quickroom.QRname, where);
612 getroom(&CC->quickroom, where);
613 lgetuser(&CC->usersupp,CC->curr_user);
614 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
616 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
617 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
619 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
620 lputuser(&CC->usersupp,CC->curr_user);
622 /* check for new mail */
623 newmailcount = NewMailCount();
625 /* set info to 1 if the user needs to read the room's info file */
626 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
629 get_msglist(&CC->quickroom);
630 for (a=0; a<CC->num_msgs; ++a) {
631 if (MessageFromList(a)>0L) {
633 if (MessageFromList(a) > vbuf.v_lastseen) {
639 if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1;
642 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
643 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
646 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
648 CC->quickroom.QRname,
649 new_messages, total_messages,
650 info,CC->quickroom.QRflags,
651 CC->quickroom.QRhighest,
653 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
655 if (CC->quickroom.QRflags & QR_PRIVATE) {
656 set_wtmpsupp("<private room>");
659 set_wtmpsupp(CC->quickroom.QRname);
665 * cmd_goto() - goto a new room
667 void cmd_goto(char *gargs)
669 struct quickroom QRscratch;
673 char bbb[ROOMNAMELEN],towhere[32],password[20];
675 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
676 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
680 extract(towhere,gargs,0);
681 extract(password,gargs,1);
684 getuser(&CC->usersupp,CC->curr_user);
686 if (!strcasecmp(towhere, "_BASEROOM_"))
687 strcpy(towhere, BASEROOM);
689 if (!strcasecmp(towhere, "_MAIL_"))
690 strcpy(towhere, MAILROOM);
692 if (!strcasecmp(towhere, "_BITBUCKET_"))
693 strcpy(towhere, config.c_twitroom);
696 /* let internal programs go directly to any room */
697 if (((CC->internal_pgm))&&(!strcasecmp(bbb,towhere))) {
698 usergoto(towhere, 1);
702 if (getroom(&QRscratch, towhere) == 0) {
704 /* See if there is an existing user/room relationship */
705 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
707 /* normal clients have to pass through security */
708 if (ra & UA_GOTOALLOWED) ok = 1;
711 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
712 ((ra & UA_KNOWN) == 0) &&
713 (strcasecmp(QRscratch.QRpasswd,password))
715 cprintf("%d wrong or missing passwd\n",
716 ERROR+PASSWORD_REQUIRED);
720 usergoto(towhere, 1);
726 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
730 void cmd_whok(void) {
731 struct usersupp temp;
732 struct cdbdata *cdbus;
734 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
735 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
738 getuser(&CC->usersupp,CC->curr_user);
740 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
741 cprintf("%d Higher access required.\n",
742 ERROR+HIGHER_ACCESS_REQUIRED);
746 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
747 cdb_rewind(CDB_USERSUPP);
748 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
749 memset(&temp, 0, sizeof(struct usersupp));
750 memcpy(&temp, cdbus->ptr, cdbus->len);
753 if ( (CC->quickroom.QRflags & QR_INUSE)
754 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
755 ) cprintf("%s\n",temp.fullname);
762 * RDIR command for room directory
764 void cmd_rdir(void) {
771 if (!(CC->logged_in)) {
772 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
776 getroom(&CC->quickroom, CC->quickroom.QRname);
777 getuser(&CC->usersupp, CC->curr_user);
779 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
780 cprintf("%d not here.\n",ERROR+NOT_HERE);
784 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
785 && (CC->usersupp.axlevel<6)
786 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
787 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
791 cprintf("%d %s|%s/files/%s\n",
792 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
794 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
795 BBSDIR,CC->quickroom.QRdirname,CC->temp);
798 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
800 if (fd==NULL) fd=fopen("/dev/null","r");
802 ls = fopen(CC->temp,"r");
803 while (fgets(flnm,256,ls)!=NULL) {
804 flnm[strlen(flnm)-1]=0;
805 if (strcasecmp(flnm,"filedir")) {
806 sprintf(buf,"%s/files/%s/%s",
807 BBSDIR,CC->quickroom.QRdirname,flnm);
811 while ((fgets(buf,256,fd)!=NULL)
812 &&(strlen(comment)==0)) {
813 buf[strlen(buf)-1] = 0;
814 if ((!strncasecmp(buf,flnm,strlen(flnm)))
815 && (buf[strlen(flnm)]==' '))
817 &buf[strlen(flnm)+1],255);
819 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
830 * get room parameters (aide or room aide command)
832 void cmd_getr(void) {
833 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
834 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
838 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
839 cprintf("%d Higher access required.\n",
840 ERROR+HIGHER_ACCESS_REQUIRED);
844 if (is_noneditable(&CC->quickroom)) {
845 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
849 getroom(&CC->quickroom, CC->quickroom.QRname);
850 cprintf("%d%c%s|%s|%s|%d|%d\n",
852 CC->quickroom.QRname,
853 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
854 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
855 CC->quickroom.QRflags,
856 (int)CC->quickroom.QRfloor);
861 * set room parameters (aide or room aide command)
863 void cmd_setr(char *args) {
868 if (!(CC->logged_in)) {
869 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
873 if (!is_room_aide()) {
874 cprintf("%d Higher access required.\n",
875 ERROR+HIGHER_ACCESS_REQUIRED);
879 if (is_noneditable(&CC->quickroom)) {
880 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
884 if (num_parms(args)>=6) {
885 getfloor(&flbuf,extract_int(args,5));
886 if ((flbuf.f_flags & F_INUSE) == 0) {
887 cprintf("%d Invalid floor number.\n",
888 ERROR+INVALID_FLOOR_OPERATION);
893 lgetroom(&CC->quickroom, CC->quickroom.QRname);
894 extract(buf,args,0); buf[ROOMNAMELEN]=0;
895 strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
896 extract(buf,args,1); buf[10]=0;
897 strncpy(CC->quickroom.QRpasswd,buf,9);
898 extract(buf,args,2); buf[15]=0;
899 strncpy(CC->quickroom.QRdirname,buf,19);
900 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
902 /* Clean up a client boo-boo: if the client set the room to
903 * guess-name or passworded, ensure that the private flag is
906 if ((CC->quickroom.QRflags & QR_GUESSNAME)
907 ||(CC->quickroom.QRflags & QR_PASSWORDED))
908 CC->quickroom.QRflags |= QR_PRIVATE;
910 /* Kick everyone out if the client requested it (by changing the
911 * room's generation number)
913 if (extract_int(args,4)) {
914 time(&CC->quickroom.QRgen);
917 old_floor = CC->quickroom.QRfloor;
918 if (num_parms(args)>=6) {
919 CC->quickroom.QRfloor = extract_int(args,5);
922 lputroom(&CC->quickroom, CC->quickroom.QRname);
924 /* adjust the floor reference counts */
925 lgetfloor(&flbuf,old_floor);
927 lputfloor(&flbuf,old_floor);
928 lgetfloor(&flbuf,CC->quickroom.QRfloor);
930 lputfloor(&flbuf,CC->quickroom.QRfloor);
932 /* create a room directory if necessary */
933 if (CC->quickroom.QRflags & QR_DIRECTORY) {
935 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
936 CC->quickroom.QRdirname);
940 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
942 cprintf("%d Ok\n",OK);
948 * get the name of the room aide for this room
950 void cmd_geta(void) {
951 struct usersupp usbuf;
953 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
954 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
958 if (is_noneditable(&CC->quickroom)) {
959 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
963 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
964 cprintf("%d %s\n",OK,usbuf.fullname);
973 * set the room aide for this room
975 void cmd_seta(char *new_ra)
977 struct usersupp usbuf;
982 if (!(CC->logged_in)) {
983 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
987 if (!is_room_aide()) {
988 cprintf("%d Higher access required.\n",
989 ERROR+HIGHER_ACCESS_REQUIRED);
993 if (getuser(&usbuf,new_ra)!=0) {
997 newu = usbuf.usernum;
1000 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1002 if (CC->quickroom.QRroomaide != newu) {
1005 CC->quickroom.QRroomaide = newu;
1006 lputroom(&CC->quickroom, CC->quickroom.QRname);
1009 * We have to post the change notice _after_ writing changes to
1010 * the room table, otherwise it would deadlock!
1012 if (post_notice == 1) {
1013 sprintf(buf,"%s is now room aide for %s>",
1014 usbuf.fullname,CC->quickroom.QRname);
1017 cprintf("%d Ok\n",OK);
1021 * Generate an associated file name for a room
1023 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
1026 sprintf(buf, "./prefix/%s.%ld", qrbuf->QRname, qrbuf->QRgen);
1027 for (a=0; a<strlen(buf); ++a) {
1028 if (buf[a]==32) buf[a]='.';
1033 * retrieve info file for this room
1035 void cmd_rinf(void) {
1040 assoc_file_name(filename, &CC->quickroom, "info");
1041 info_fp = fopen(filename,"r");
1043 if (info_fp==NULL) {
1044 cprintf("%d No info file.\n",ERROR);
1048 cprintf("%d Info:\n",LISTING_FOLLOWS);
1049 while (fgets(buf, 256, info_fp) != NULL) {
1050 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1051 cprintf("%s\n", buf);
1058 * Back end processing to delete a room and everything associated with it
1060 void delete_room(struct quickroom *qrbuf) {
1066 /* Delete the info file */
1067 assoc_file_name(aaa, qrbuf, "info");
1070 /* Delete the image file */
1071 assoc_file_name(aaa, qrbuf, "images");
1074 /* first flag the room record as not in use */
1075 lgetroom(qrbuf, qrbuf->QRname);
1078 /* then delete the messages in the room */
1080 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1081 MsgToDelete = MessageFromList(a);
1082 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1088 delete_msglist(qrbuf);
1089 lputroom(qrbuf, qrbuf->QRname);
1091 /* then decrement the reference count for the floor */
1092 lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
1093 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1094 lputfloor(&flbuf,(int)(qrbuf->QRfloor));
1096 /* Delete the room record from the database! */
1097 putroom(NULL, qrbuf->QRname);
1102 * aide command: kill the current room
1104 void cmd_kill(char *argbuf) {
1106 char deleted_room_name[ROOMNAMELEN];
1109 kill_ok = extract_int(argbuf,0);
1111 if (!(CC->logged_in)) {
1112 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1116 if (!is_room_aide()) {
1117 cprintf("%d Higher access required.\n",
1118 ERROR+HIGHER_ACCESS_REQUIRED);
1122 if (is_noneditable(&CC->quickroom)) {
1123 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1128 strcpy(deleted_room_name, CC->quickroom.QRname);
1129 delete_room(&CC->quickroom); /* Do the dirty work */
1130 usergoto(BASEROOM, 0); /* Return to the Lobby */
1132 /* tell the world what we did */
1133 sprintf(aaa,"%s> killed by %s",
1134 deleted_room_name, CC->curr_user);
1136 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1139 cprintf("%d ok to delete.\n",OK);
1145 * Internal code to create a new room (returns room flags)
1147 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1149 unsigned create_room(char *new_room_name,
1151 char *new_room_pass,
1152 int new_room_floor) {
1154 struct quickroom qrbuf;
1158 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1160 memset(&qrbuf, 0, sizeof(struct quickroom));
1161 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1162 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1163 qrbuf.QRflags = QR_INUSE;
1164 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1165 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1166 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1167 if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
1169 /* If the room is private, and the system administrator has elected
1170 * to automatically grant room aide privileges, do so now; otherwise,
1171 * set the room aide to undefined.
1173 if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) {
1174 qrbuf.QRroomaide=CC->usersupp.usernum;
1177 qrbuf.QRroomaide = (-1L);
1180 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1181 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1182 qrbuf.QRfloor = new_room_floor;
1184 /* save what we just did... */
1185 putroom(&qrbuf, qrbuf.QRname);
1187 /* bump the reference count on whatever floor the room is on */
1188 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1189 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1190 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1192 /* be sure not to kick the creator out of the room! */
1193 lgetuser(&CC->usersupp,CC->curr_user);
1194 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1195 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1196 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1197 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1198 lputuser(&CC->usersupp,CC->curr_user);
1200 /* resume our happy day */
1201 return(qrbuf.QRflags);
1208 void cmd_cre8(char *args)
1211 char new_room_name[256];
1213 char new_room_pass[256];
1217 struct quickroom qrbuf;
1220 cre8_ok = extract_int(args,0);
1221 extract(new_room_name,args,1);
1222 new_room_name[ROOMNAMELEN-1] = 0;
1223 new_room_type = extract_int(args,2);
1224 extract(new_room_pass,args,3);
1225 new_room_pass[9] = 0;
1228 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1229 cprintf("%d Invalid room name.\n",ERROR);
1233 if (num_parms(args)>=5) {
1234 getfloor(&flbuf,extract_int(args,4));
1235 if ((flbuf.f_flags & F_INUSE) == 0) {
1236 cprintf("%d Invalid floor number.\n",
1237 ERROR+INVALID_FLOOR_OPERATION);
1241 new_room_floor = extract_int(args,4);
1245 if (!(CC->logged_in)) {
1246 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1250 if (CC->usersupp.axlevel<3) {
1251 cprintf("%d You need higher access to create rooms.\n",
1252 ERROR+HIGHER_ACCESS_REQUIRED);
1256 if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
1257 cprintf("%d Ok to create rooms.\n", OK);
1261 /* Check to make sure the requested room name doesn't already exist */
1262 if (getroom(&qrbuf, new_room_name)==0) {
1263 cprintf("%d '%s' already exists.\n",
1264 ERROR,qrbuf.QRname);
1268 if ((new_room_type < 0) || (new_room_type > 3)) {
1269 cprintf("%d Invalid room type.\n",ERROR);
1274 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1278 newflags = create_room(new_room_name,
1279 new_room_type,new_room_pass,new_room_floor);
1281 /* post a message in Aide> describing the new room */
1282 strncpy(aaa,new_room_name,255);
1283 strcat(aaa,"> created by ");
1284 strcat(aaa,CC->usersupp.fullname);
1285 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1286 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1287 if (newflags&QR_PASSWORDED) {
1288 strcat(aaa,"\n Password: ");
1289 strcat(aaa,new_room_pass);
1293 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1298 void cmd_einf(char *ok)
1299 { /* enter info file for current room */
1301 char infofilename[64];
1304 if (!(CC->logged_in)) {
1305 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1309 if (!is_room_aide()) {
1310 cprintf("%d Higher access required.\n",
1311 ERROR+HIGHER_ACCESS_REQUIRED);
1316 cprintf("%d Ok.\n",OK);
1320 cprintf("%d Send info...\n",SEND_LISTING);
1322 assoc_file_name(infofilename, &CC->quickroom, "info");
1324 fp=fopen(infofilename,"w");
1327 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1328 } while(strcmp(buf,"000"));
1331 /* now update the room index so people will see our new info */
1332 lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */
1333 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1334 lputroom(&CC->quickroom,CC->quickroom.QRname);
1339 * cmd_lflr() - List all known floors
1341 void cmd_lflr(void) {
1345 if (!(CC->logged_in)) {
1346 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1350 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1351 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1356 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1358 for (a=0; a<MAXFLOORS; ++a) {
1360 if (flbuf.f_flags & F_INUSE) {
1361 cprintf("%d|%s|%d\n",
1373 * create a new floor
1375 void cmd_cflr(char *argbuf)
1377 char new_floor_name[256];
1380 int free_slot = (-1);
1383 extract(new_floor_name,argbuf,0);
1384 cflr_ok = extract_int(argbuf,1);
1387 if (!(CC->logged_in)) {
1388 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1392 if (CC->usersupp.axlevel<6) {
1393 cprintf("%d You need higher access to create rooms.\n",
1394 ERROR+HIGHER_ACCESS_REQUIRED);
1398 for (a=0; a<MAXFLOORS; ++a) {
1401 /* note any free slots while we're scanning... */
1402 if ( ((flbuf.f_flags & F_INUSE)==0)
1403 && (free_slot < 0) ) free_slot = a;
1405 /* check to see if it already exists */
1406 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1407 && (flbuf.f_flags & F_INUSE) ) {
1408 cprintf("%d Floor '%s' already exists.\n",
1409 ERROR+ALREADY_EXISTS,
1417 cprintf("%d There is no space available for a new floor.\n",
1418 ERROR+INVALID_FLOOR_OPERATION);
1423 cprintf("%d ok to create...\n",OK);
1427 lgetfloor(&flbuf,free_slot);
1428 flbuf.f_flags = F_INUSE;
1429 flbuf.f_ref_count = 0;
1430 strncpy(flbuf.f_name,new_floor_name,255);
1431 lputfloor(&flbuf,free_slot);
1432 cprintf("%d %d\n",OK,free_slot);
1440 void cmd_kflr(char *argbuf)
1443 int floor_to_delete;
1447 floor_to_delete = extract_int(argbuf,0);
1448 kflr_ok = extract_int(argbuf,1);
1451 if (!(CC->logged_in)) {
1452 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1456 if (CC->usersupp.axlevel<6) {
1457 cprintf("%d You need higher access to delete floors.\n",
1458 ERROR+HIGHER_ACCESS_REQUIRED);
1462 lgetfloor(&flbuf,floor_to_delete);
1465 if ((flbuf.f_flags & F_INUSE) == 0) {
1466 cprintf("%d Floor %d not in use.\n",
1467 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1472 if (flbuf.f_ref_count != 0) {
1473 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1474 ERROR+INVALID_FLOOR_OPERATION,
1481 cprintf("%d Ok\n",OK);
1484 cprintf("%d Ok to delete...\n",OK);
1491 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1492 lputfloor(&flbuf,floor_to_delete);
1498 void cmd_eflr(char *argbuf)
1504 np = num_parms(argbuf);
1506 cprintf("%d Usage error.\n",ERROR);
1510 if (!(CC->logged_in)) {
1511 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1515 if (CC->usersupp.axlevel<6) {
1516 cprintf("%d You need higher access to edit floors.\n",
1517 ERROR+HIGHER_ACCESS_REQUIRED);
1521 floor_num = extract_int(argbuf,0);
1522 lgetfloor(&flbuf,floor_num);
1523 if ( (flbuf.f_flags & F_INUSE) == 0) {
1524 lputfloor(&flbuf,floor_num);
1525 cprintf("%d Floor %d is not in use.\n",
1526 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1529 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1530 lputfloor(&flbuf,floor_num);
1532 cprintf("%d Ok\n",OK);