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 lprintf(9, "get_msglist() called for <%s>\n", whichroom->QRname);
270 sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
271 for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
272 lprintf(9, "database key is <%s>\n", dbkey);
274 lprintf(9, "Freeing existing message list\n");
275 if (CC->msglist != NULL) {
281 lprintf(9, "calling cdb_fetch\n");
282 cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey));
283 lprintf(9, "done\n");
289 CC->msglist = malloc(cdbfr->len);
290 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
291 CC->num_msgs = cdbfr->len / sizeof(long);
293 lprintf(9, "Leaving get_msglist()\n");
298 * put_msglist() - retrieve room message pointers
300 void put_msglist(struct quickroom *whichroom) {
304 sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
305 for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
307 cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey),
308 CC->msglist, CC->num_msgs * sizeof(long));
313 * delete_msglist() - delete room message pointers
315 void delete_msglist(struct quickroom *whichroom) {
319 sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
320 for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
322 cdb_delete(CDB_MSGLISTS, dbkey, strlen(dbkey));
327 * MessageFromList() - get a message number from the list currently in memory
329 long MessageFromList(int whichpos) {
331 /* Return zero if the position is invalid */
332 if (whichpos >= CC->num_msgs) return 0L;
334 return(CC->msglist[whichpos]);
338 * SetMessageInList() - set a message number in the list currently in memory
340 void SetMessageInList(int whichpos, long newmsgnum) {
342 /* Return zero if the position is invalid */
343 if (whichpos >= CC->num_msgs) return;
345 CC->msglist[whichpos] = newmsgnum;
351 * sort message pointers
352 * (returns new msg count)
354 int sort_msglist(long listptrs[], int oldcount)
361 if (numitems < 2) return(oldcount);
364 for (a=numitems-2; a>=0; --a) {
365 for (b=0; b<=a; ++b) {
366 if (listptrs[b] > (listptrs[b+1])) {
368 hold2 = listptrs[b+1];
370 listptrs[b+1] = hold1;
375 /* and yank any nulls */
376 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
377 memcpy(&listptrs[0], &listptrs[1],
378 (sizeof(long) * (CC->num_msgs - 1)) );
388 * Determine whether a given room is one of the base non-editable rooms
390 int is_noneditable(struct quickroom *qrbuf) {
391 if (!strcasecmp(qrbuf->QRname, BASEROOM)) return(1);
392 else if (!strcasecmp(qrbuf->QRname, AIDEROOM)) return(1);
397 * cmd_lrms() - List all accessible rooms, known or forgotten
399 void cmd_lrms_backend(struct quickroom *qrbuf) {
400 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
401 & (UA_KNOWN | UA_ZAPPED)))
402 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
403 ||((CC->FloorBeingSearched)<0)) )
404 cprintf("%s|%u|%d\n",
405 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
408 void cmd_lrms(char *argbuf)
410 CC->FloorBeingSearched = (-1);
411 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
413 if (!(CC->logged_in)) {
414 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
418 if (getuser(&CC->usersupp,CC->curr_user)) {
419 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
423 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
425 ForEachRoom(cmd_lrms_backend);
432 * cmd_lkra() - List all known rooms
434 void cmd_lkra_backend(struct quickroom *qrbuf) {
435 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
437 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
438 ||((CC->FloorBeingSearched)<0)) )
439 cprintf("%s|%u|%d\n",
440 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
443 void cmd_lkra(char *argbuf)
445 CC->FloorBeingSearched = (-1);
446 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
448 if (!(CC->logged_in)) {
449 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
453 if (getuser(&CC->usersupp,CC->curr_user)) {
454 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
458 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
460 ForEachRoom(cmd_lkra_backend);
467 * cmd_lkrn() - List all known rooms with new messages
469 void cmd_lkrn_backend(struct quickroom *qrbuf) {
472 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
474 && (ra & UA_HASNEWMSGS)
475 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
476 ||((CC->FloorBeingSearched)<0)) )
477 cprintf("%s|%u|%d\n",
478 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
481 void cmd_lkrn(char *argbuf)
483 CC->FloorBeingSearched = (-1);
484 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
486 if (!(CC->logged_in)) {
487 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
491 if (getuser(&CC->usersupp,CC->curr_user)) {
492 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
496 cprintf("%d Rooms w/ new msgs:\n",LISTING_FOLLOWS);
498 ForEachRoom(cmd_lkrn_backend);
505 * cmd_lkro() - List all known rooms
507 void cmd_lkro_backend(struct quickroom *qrbuf) {
510 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
512 && ((ra & UA_HASNEWMSGS)==0)
513 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
514 ||((CC->FloorBeingSearched)<0)) )
515 cprintf("%s|%u|%d\n",
516 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
519 void cmd_lkro(char *argbuf)
521 CC->FloorBeingSearched = (-1);
522 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
524 if (!(CC->logged_in)) {
525 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
529 if (getuser(&CC->usersupp,CC->curr_user)) {
530 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
534 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
536 ForEachRoom(cmd_lkro_backend);
543 * cmd_lzrm() - List all forgotten rooms
545 void cmd_lzrm_backend(struct quickroom *qrbuf) {
548 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
549 if ( (ra & UA_GOTOALLOWED)
551 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
552 ||((CC->FloorBeingSearched)<0)) )
553 cprintf("%s|%u|%d\n",
554 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
557 void cmd_lzrm(char *argbuf)
559 CC->FloorBeingSearched = (-1);
560 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
562 if (!(CC->logged_in)) {
563 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
567 if (getuser(&CC->usersupp,CC->curr_user)) {
568 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
572 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
574 ForEachRoom(cmd_lzrm_backend);
580 void usergoto(char *where, int display_result)
583 int new_messages = 0;
584 int total_messages = 0;
588 int newmailcount = 0;
591 strcpy(CC->quickroom.QRname, where);
592 lprintf(9, "usergoto() fetching room record\n");
593 getroom(&CC->quickroom, where);
594 lprintf(9, "usergoto() fetching user record\n");
595 lgetuser(&CC->usersupp,CC->curr_user);
596 lprintf(9, "usergoto() fetching relationships\n");
597 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
599 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
600 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
602 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
603 lputuser(&CC->usersupp,CC->curr_user);
605 lprintf(9, "usergoto() about to check for new mail\n");
606 /* check for new mail */
607 newmailcount = NewMailCount();
609 /* set info to 1 if the user needs to read the room's info file */
610 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
613 lprintf(9, "Fetching message list for counting...\n");
614 get_msglist(&CC->quickroom);
615 for (a=0; a<CC->num_msgs; ++a) {
616 if (MessageFromList(a)>0L) {
618 if (MessageFromList(a) > vbuf.v_lastseen) {
623 lprintf(9, "...done counting\n");
625 if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1;
628 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
629 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
632 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
634 CC->quickroom.QRname,
635 new_messages, total_messages,
636 info,CC->quickroom.QRflags,
637 CC->quickroom.QRhighest,
639 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
641 if (CC->quickroom.QRflags & QR_PRIVATE) {
642 set_wtmpsupp("<private room>");
645 set_wtmpsupp(CC->quickroom.QRname);
651 * cmd_goto() - goto a new room
653 void cmd_goto(char *gargs)
655 struct quickroom QRscratch;
659 char bbb[ROOMNAMELEN],towhere[32],password[20];
661 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
662 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
666 extract(towhere,gargs,0);
667 extract(password,gargs,1);
670 getuser(&CC->usersupp,CC->curr_user);
672 if (!strcasecmp(towhere, "_BASEROOM_"))
673 strcpy(towhere, BASEROOM);
675 if (!strcasecmp(towhere, "_MAIL_"))
676 strcpy(towhere, MAILROOM);
678 if (!strcasecmp(towhere, "_BITBUCKET_"))
679 strcpy(towhere, config.c_twitroom);
682 /* let internal programs go directly to any room */
683 if (((CC->internal_pgm))&&(!strcasecmp(bbb,towhere))) {
684 usergoto(towhere, 1);
688 if (getroom(&QRscratch, towhere) == 0) {
690 /* See if there is an existing user/room relationship */
691 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
693 /* normal clients have to pass through security */
694 if (ra & UA_GOTOALLOWED) ok = 1;
697 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
698 ((ra & UA_KNOWN) == 0) &&
699 (strcasecmp(QRscratch.QRpasswd,password))
701 cprintf("%d wrong or missing passwd\n",
702 ERROR+PASSWORD_REQUIRED);
706 usergoto(towhere, 1);
712 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
716 void cmd_whok(void) {
717 struct usersupp temp;
718 struct cdbdata *cdbus;
720 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
721 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
724 getuser(&CC->usersupp,CC->curr_user);
726 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
727 cprintf("%d Higher access required.\n",
728 ERROR+HIGHER_ACCESS_REQUIRED);
732 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
733 cdb_rewind(CDB_USERSUPP);
734 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
735 memset(&temp, 0, sizeof(struct usersupp));
736 memcpy(&temp, cdbus->ptr, cdbus->len);
739 if ( (CC->quickroom.QRflags & QR_INUSE)
740 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
741 ) cprintf("%s\n",temp.fullname);
748 * RDIR command for room directory
750 void cmd_rdir(void) {
757 if (!(CC->logged_in)) {
758 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
762 getroom(&CC->quickroom, CC->quickroom.QRname);
763 getuser(&CC->usersupp, CC->curr_user);
765 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
766 cprintf("%d not here.\n",ERROR+NOT_HERE);
770 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
771 && (CC->usersupp.axlevel<6)
772 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
773 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
777 cprintf("%d %s|%s/files/%s\n",
778 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
780 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
781 BBSDIR,CC->quickroom.QRdirname,CC->temp);
784 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
786 if (fd==NULL) fd=fopen("/dev/null","r");
788 ls = fopen(CC->temp,"r");
789 while (fgets(flnm,256,ls)!=NULL) {
790 flnm[strlen(flnm)-1]=0;
791 if (strcasecmp(flnm,"filedir")) {
792 sprintf(buf,"%s/files/%s/%s",
793 BBSDIR,CC->quickroom.QRdirname,flnm);
797 while ((fgets(buf,256,fd)!=NULL)
798 &&(strlen(comment)==0)) {
799 buf[strlen(buf)-1] = 0;
800 if ((!strncasecmp(buf,flnm,strlen(flnm)))
801 && (buf[strlen(flnm)]==' '))
803 &buf[strlen(flnm)+1],255);
805 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
816 * get room parameters (aide or room aide command)
818 void cmd_getr(void) {
819 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
820 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
824 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
825 cprintf("%d Higher access required.\n",
826 ERROR+HIGHER_ACCESS_REQUIRED);
830 if (is_noneditable(&CC->quickroom)) {
831 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
835 getroom(&CC->quickroom, CC->quickroom.QRname);
836 cprintf("%d%c%s|%s|%s|%d|%d\n",
838 CC->quickroom.QRname,
839 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
840 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
841 CC->quickroom.QRflags,
842 (int)CC->quickroom.QRfloor);
847 * set room parameters (aide or room aide command)
849 void cmd_setr(char *args) {
854 if (!(CC->logged_in)) {
855 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
859 if (!is_room_aide()) {
860 cprintf("%d Higher access required.\n",
861 ERROR+HIGHER_ACCESS_REQUIRED);
865 if (is_noneditable(&CC->quickroom)) {
866 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
870 if (num_parms(args)>=6) {
871 getfloor(&flbuf,extract_int(args,5));
872 if ((flbuf.f_flags & F_INUSE) == 0) {
873 cprintf("%d Invalid floor number.\n",
874 ERROR+INVALID_FLOOR_OPERATION);
879 lgetroom(&CC->quickroom, CC->quickroom.QRname);
880 extract(buf,args,0); buf[ROOMNAMELEN]=0;
881 strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
882 extract(buf,args,1); buf[10]=0;
883 strncpy(CC->quickroom.QRpasswd,buf,9);
884 extract(buf,args,2); buf[15]=0;
885 strncpy(CC->quickroom.QRdirname,buf,19);
886 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
888 /* Clean up a client boo-boo: if the client set the room to
889 * guess-name or passworded, ensure that the private flag is
892 if ((CC->quickroom.QRflags & QR_GUESSNAME)
893 ||(CC->quickroom.QRflags & QR_PASSWORDED))
894 CC->quickroom.QRflags |= QR_PRIVATE;
896 /* Kick everyone out if the client requested it (by changing the
897 * room's generation number)
899 if (extract_int(args,4)) {
900 time(&CC->quickroom.QRgen);
903 old_floor = CC->quickroom.QRfloor;
904 if (num_parms(args)>=6) {
905 CC->quickroom.QRfloor = extract_int(args,5);
908 lputroom(&CC->quickroom, CC->quickroom.QRname);
910 /* adjust the floor reference counts */
911 lgetfloor(&flbuf,old_floor);
913 lputfloor(&flbuf,old_floor);
914 lgetfloor(&flbuf,CC->quickroom.QRfloor);
916 lputfloor(&flbuf,CC->quickroom.QRfloor);
918 /* create a room directory if necessary */
919 if (CC->quickroom.QRflags & QR_DIRECTORY) {
921 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
922 CC->quickroom.QRdirname);
926 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
928 cprintf("%d Ok\n",OK);
934 * get the name of the room aide for this room
936 void cmd_geta(void) {
937 struct usersupp usbuf;
939 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
940 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
944 if (is_noneditable(&CC->quickroom)) {
945 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
949 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
950 cprintf("%d %s\n",OK,usbuf.fullname);
959 * set the room aide for this room
961 void cmd_seta(char *new_ra)
963 struct usersupp usbuf;
968 if (!(CC->logged_in)) {
969 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
973 if (!is_room_aide()) {
974 cprintf("%d Higher access required.\n",
975 ERROR+HIGHER_ACCESS_REQUIRED);
979 if (getuser(&usbuf,new_ra)!=0) {
983 newu = usbuf.usernum;
986 lgetroom(&CC->quickroom, CC->quickroom.QRname);
988 if (CC->quickroom.QRroomaide != newu) {
991 CC->quickroom.QRroomaide = newu;
992 lputroom(&CC->quickroom, CC->quickroom.QRname);
995 * We have to post the change notice _after_ writing changes to
996 * the room table, otherwise it would deadlock!
998 if (post_notice == 1) {
999 sprintf(buf,"%s is now room aide for %s>",
1000 usbuf.fullname,CC->quickroom.QRname);
1003 cprintf("%d Ok\n",OK);
1007 * Generate an associated file name for a room
1009 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
1012 sprintf(buf, "./prefix/%s.%ld", qrbuf->QRname, qrbuf->QRgen);
1013 for (a=0; a<strlen(buf); ++a) {
1014 if (buf[a]==32) buf[a]='.';
1019 * retrieve info file for this room
1021 void cmd_rinf(void) {
1026 assoc_file_name(filename, &CC->quickroom, "info");
1027 info_fp = fopen(filename,"r");
1029 if (info_fp==NULL) {
1030 cprintf("%d No info file.\n",ERROR);
1034 cprintf("%d Info:\n",LISTING_FOLLOWS);
1035 while (fgets(buf, 256, info_fp) != NULL) {
1036 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1037 cprintf("%s\n", buf);
1044 * Back end processing to delete a room and everything associated with it
1046 void delete_room(struct quickroom *qrbuf) {
1052 /* Delete the info file */
1053 assoc_file_name(aaa, qrbuf, "info");
1056 /* Delete the image file */
1057 assoc_file_name(aaa, qrbuf, "images");
1060 /* first flag the room record as not in use */
1061 lgetroom(qrbuf, qrbuf->QRname);
1064 /* then delete the messages in the room */
1065 lprintf(9, "calling get_msglist()\n");
1067 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1068 MsgToDelete = MessageFromList(a);
1069 lprintf(9, "Deleting message %ld\n", MsgToDelete);
1070 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1072 lprintf(9, "calling put_msglist()\n");
1077 lprintf(9, "calling delete_msglist()\n");
1078 delete_msglist(qrbuf);
1079 lputroom(qrbuf, qrbuf->QRname);
1081 /* then decrement the reference count for the floor */
1082 lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
1083 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1084 lputfloor(&flbuf,(int)(qrbuf->QRfloor));
1086 /* Delete the room record from the database! */
1087 putroom(NULL, qrbuf->QRname);
1088 lprintf(9, "finished with delete_room()\n");
1093 * aide command: kill the current room
1095 void cmd_kill(char *argbuf) {
1097 char deleted_room_name[ROOMNAMELEN];
1100 kill_ok = extract_int(argbuf,0);
1102 if (!(CC->logged_in)) {
1103 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1107 if (!is_room_aide()) {
1108 cprintf("%d Higher access required.\n",
1109 ERROR+HIGHER_ACCESS_REQUIRED);
1113 if (is_noneditable(&CC->quickroom)) {
1114 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1119 strcpy(deleted_room_name, CC->quickroom.QRname);
1120 delete_room(&CC->quickroom); /* Do the dirty work */
1121 lprintf(9, "Calling usergoto()\n");
1122 usergoto(BASEROOM, 0); /* Return to the Lobby */
1124 lprintf(9, "Composing notice\n");
1125 /* tell the world what we did */
1126 sprintf(aaa,"%s> killed by %s",
1127 deleted_room_name, CC->curr_user);
1128 lprintf(9, "Posting notice\n");
1130 lprintf(9, "done posting notice\n");
1131 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1134 cprintf("%d ok to delete.\n",OK);
1140 * Internal code to create a new room (returns room flags)
1142 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1144 unsigned create_room(char *new_room_name,
1146 char *new_room_pass,
1147 int new_room_floor) {
1149 struct quickroom qrbuf;
1153 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1155 memset(&qrbuf, 0, sizeof(struct quickroom));
1156 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1157 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1158 qrbuf.QRflags = QR_INUSE;
1159 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1160 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1161 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1162 if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
1164 /* If the room is private, and the system administrator has elected
1165 * to automatically grant room aide privileges, do so now; otherwise,
1166 * set the room aide to undefined.
1168 if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) {
1169 qrbuf.QRroomaide=CC->usersupp.usernum;
1172 qrbuf.QRroomaide = (-1L);
1175 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1176 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1177 qrbuf.QRfloor = new_room_floor;
1179 /* save what we just did... */
1180 putroom(&qrbuf, qrbuf.QRname);
1182 /* bump the reference count on whatever floor the room is on */
1183 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1184 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1185 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1187 /* be sure not to kick the creator out of the room! */
1188 lgetuser(&CC->usersupp,CC->curr_user);
1189 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1190 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1191 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1192 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1193 lputuser(&CC->usersupp,CC->curr_user);
1195 /* resume our happy day */
1196 return(qrbuf.QRflags);
1203 void cmd_cre8(char *args)
1206 char new_room_name[256];
1208 char new_room_pass[256];
1212 struct quickroom qrbuf;
1215 cre8_ok = extract_int(args,0);
1216 extract(new_room_name,args,1);
1217 new_room_name[ROOMNAMELEN-1] = 0;
1218 new_room_type = extract_int(args,2);
1219 extract(new_room_pass,args,3);
1220 new_room_pass[9] = 0;
1223 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1224 cprintf("%d Invalid room name.\n",ERROR);
1228 if (num_parms(args)>=5) {
1229 getfloor(&flbuf,extract_int(args,4));
1230 if ((flbuf.f_flags & F_INUSE) == 0) {
1231 cprintf("%d Invalid floor number.\n",
1232 ERROR+INVALID_FLOOR_OPERATION);
1236 new_room_floor = extract_int(args,4);
1240 if (!(CC->logged_in)) {
1241 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1245 if (CC->usersupp.axlevel<3) {
1246 cprintf("%d You need higher access to create rooms.\n",
1247 ERROR+HIGHER_ACCESS_REQUIRED);
1251 if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
1252 cprintf("%d Ok to create rooms.\n", OK);
1256 /* Check to make sure the requested room name doesn't already exist */
1257 if (getroom(&qrbuf, new_room_name)==0) {
1258 cprintf("%d '%s' already exists.\n",
1259 ERROR,qrbuf.QRname);
1263 if ((new_room_type < 0) || (new_room_type > 3)) {
1264 cprintf("%d Invalid room type.\n",ERROR);
1269 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1273 newflags = create_room(new_room_name,
1274 new_room_type,new_room_pass,new_room_floor);
1276 /* post a message in Aide> describing the new room */
1277 strncpy(aaa,new_room_name,255);
1278 strcat(aaa,"> created by ");
1279 strcat(aaa,CC->usersupp.fullname);
1280 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1281 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1282 if (newflags&QR_PASSWORDED) {
1283 strcat(aaa,"\n Password: ");
1284 strcat(aaa,new_room_pass);
1288 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1293 void cmd_einf(char *ok)
1294 { /* enter info file for current room */
1296 char infofilename[64];
1299 if (!(CC->logged_in)) {
1300 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1304 if (!is_room_aide()) {
1305 cprintf("%d Higher access required.\n",
1306 ERROR+HIGHER_ACCESS_REQUIRED);
1311 cprintf("%d Ok.\n",OK);
1315 cprintf("%d Send info...\n",SEND_LISTING);
1317 assoc_file_name(infofilename, &CC->quickroom, "info");
1319 fp=fopen(infofilename,"w");
1322 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1323 } while(strcmp(buf,"000"));
1326 /* now update the room index so people will see our new info */
1327 lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */
1328 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1329 lputroom(&CC->quickroom,CC->quickroom.QRname);
1334 * cmd_lflr() - List all known floors
1336 void cmd_lflr(void) {
1340 if (!(CC->logged_in)) {
1341 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1345 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1346 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1351 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1353 for (a=0; a<MAXFLOORS; ++a) {
1355 if (flbuf.f_flags & F_INUSE) {
1356 cprintf("%d|%s|%d\n",
1368 * create a new floor
1370 void cmd_cflr(char *argbuf)
1372 char new_floor_name[256];
1375 int free_slot = (-1);
1378 extract(new_floor_name,argbuf,0);
1379 cflr_ok = extract_int(argbuf,1);
1382 if (!(CC->logged_in)) {
1383 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1387 if (CC->usersupp.axlevel<6) {
1388 cprintf("%d You need higher access to create rooms.\n",
1389 ERROR+HIGHER_ACCESS_REQUIRED);
1393 for (a=0; a<MAXFLOORS; ++a) {
1396 /* note any free slots while we're scanning... */
1397 if ( ((flbuf.f_flags & F_INUSE)==0)
1398 && (free_slot < 0) ) free_slot = a;
1400 /* check to see if it already exists */
1401 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1402 && (flbuf.f_flags & F_INUSE) ) {
1403 cprintf("%d Floor '%s' already exists.\n",
1404 ERROR+ALREADY_EXISTS,
1412 cprintf("%d There is no space available for a new floor.\n",
1413 ERROR+INVALID_FLOOR_OPERATION);
1418 cprintf("%d ok to create...\n",OK);
1422 lgetfloor(&flbuf,free_slot);
1423 flbuf.f_flags = F_INUSE;
1424 flbuf.f_ref_count = 0;
1425 strncpy(flbuf.f_name,new_floor_name,255);
1426 lputfloor(&flbuf,free_slot);
1427 cprintf("%d %d\n",OK,free_slot);
1435 void cmd_kflr(char *argbuf)
1438 int floor_to_delete;
1442 floor_to_delete = extract_int(argbuf,0);
1443 kflr_ok = extract_int(argbuf,1);
1446 if (!(CC->logged_in)) {
1447 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1451 if (CC->usersupp.axlevel<6) {
1452 cprintf("%d You need higher access to delete floors.\n",
1453 ERROR+HIGHER_ACCESS_REQUIRED);
1457 lgetfloor(&flbuf,floor_to_delete);
1460 if ((flbuf.f_flags & F_INUSE) == 0) {
1461 cprintf("%d Floor %d not in use.\n",
1462 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1467 if (flbuf.f_ref_count != 0) {
1468 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1469 ERROR+INVALID_FLOOR_OPERATION,
1476 cprintf("%d Ok\n",OK);
1479 cprintf("%d Ok to delete...\n",OK);
1486 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1487 lputfloor(&flbuf,floor_to_delete);
1493 void cmd_eflr(char *argbuf)
1499 np = num_parms(argbuf);
1501 cprintf("%d Usage error.\n",ERROR);
1505 if (!(CC->logged_in)) {
1506 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1510 if (CC->usersupp.axlevel<6) {
1511 cprintf("%d You need higher access to edit floors.\n",
1512 ERROR+HIGHER_ACCESS_REQUIRED);
1516 floor_num = extract_int(argbuf,0);
1517 lgetfloor(&flbuf,floor_num);
1518 if ( (flbuf.f_flags & F_INUSE) == 0) {
1519 lputfloor(&flbuf,floor_num);
1520 cprintf("%d Floor %d is not in use.\n",
1521 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1524 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1525 lputfloor(&flbuf,floor_num);
1527 cprintf("%d Ok\n",OK);