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 /* Locate any applicable user/room relationships */
42 CtdlGetRelationship(&vbuf, userbuf, roombuf);
44 /* If this is a public room, it's accessible... */
45 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
46 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
49 /* If this is a preferred users only room, check access level */
50 if (roombuf->QRflags & QR_PREFONLY) {
51 if (userbuf->axlevel < 5) {
52 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
56 /* For private rooms, check the generation number matchups */
57 if (roombuf->QRflags & QR_PRIVATE) {
59 /* An explicit match means the user belongs in this room */
60 if (vbuf.v_flags & V_ACCESS) {
61 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
63 /* Otherwise, check if this is a guess-name or passworded
64 * room. If it is, a goto may at least be attempted
66 else if ((roombuf->QRflags & QR_PRIVATE)
67 ||(roombuf->QRflags & QR_PASSWORDED)) {
68 retval = retval & ~UA_KNOWN;
69 retval = retval | UA_GOTOALLOWED;
73 /* Check to see if the user has forgotten this room */
74 if (vbuf.v_flags & V_FORGET) {
75 retval = retval & ~UA_KNOWN;
76 retval = retval | UA_ZAPPED;
79 /* If user is explicitly locked out of this room, deny everything */
80 if (vbuf.v_flags & V_LOCKOUT) {
81 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
84 /* Aides get access to everything */
85 if (userbuf->axlevel >= 6) {
86 retval = retval | UA_INUSE | UA_KNOWN | UA_GOTOALLOWED;
87 retval = retval & ~UA_ZAPPED;
90 /* By the way, we also check for the presence of new messages */
91 if ( (roombuf->QRhighest) > (vbuf.v_lastseen) ) {
92 retval = retval | UA_HASNEWMSGS;
99 * getroom() - retrieve room data from disk
101 int getroom(struct quickroom *qrbuf, char *room_name)
103 struct cdbdata *cdbqr;
104 char lowercase_name[ROOMNAMELEN];
107 for (a=0; a<=strlen(room_name); ++a) {
108 lowercase_name[a] = tolower(room_name[a]);
111 bzero(qrbuf, sizeof(struct quickroom));
112 cdbqr = cdb_fetch(CDB_QUICKROOM,
113 lowercase_name, strlen(lowercase_name));
115 memcpy(qrbuf, cdbqr->ptr,
116 ( (cdbqr->len > sizeof(struct quickroom)) ?
117 sizeof(struct quickroom) : cdbqr->len) );
127 * lgetroom() - same as getroom() but locks the record (if supported)
129 int lgetroom(struct quickroom *qrbuf, char *room_name)
131 begin_critical_section(S_QUICKROOM);
132 return(getroom(qrbuf, room_name));
137 * putroom() - store room data on disk
138 * (if the supplied buffer is NULL, delete the room record)
140 void putroom(struct quickroom *qrbuf, char *room_name)
142 char lowercase_name[ROOMNAMELEN];
145 for (a=0; a<=strlen(room_name); ++a) {
146 lowercase_name[a] = tolower(room_name[a]);
150 cdb_delete(CDB_QUICKROOM,
151 lowercase_name, strlen(lowercase_name));
154 time(&qrbuf->QRmtime);
155 cdb_store(CDB_QUICKROOM,
156 lowercase_name, strlen(lowercase_name),
157 qrbuf, sizeof(struct quickroom));
163 * lputroom() - same as putroom() but unlocks the record (if supported)
165 void lputroom(struct quickroom *qrbuf, char *room_name)
168 putroom(qrbuf, room_name);
169 end_critical_section(S_QUICKROOM);
173 /****************************************************************************/
176 * getfloor() - retrieve floor data from disk
178 void getfloor(struct floor *flbuf, int floor_num)
180 struct cdbdata *cdbfl;
182 bzero(flbuf, sizeof(struct floor));
183 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
185 memcpy(flbuf, cdbfl->ptr,
186 ( (cdbfl->len > sizeof(struct floor)) ?
187 sizeof(struct floor) : cdbfl->len) );
191 if (floor_num == 0) {
192 strcpy(flbuf->f_name, "Main Floor");
193 flbuf->f_flags = F_INUSE;
194 flbuf->f_ref_count = 3;
201 * lgetfloor() - same as getfloor() but locks the record (if supported)
203 void lgetfloor(struct floor *flbuf, int floor_num)
206 begin_critical_section(S_FLOORTAB);
207 getfloor(flbuf,floor_num);
212 * putfloor() - store floor data on disk
214 void putfloor(struct floor *flbuf, int floor_num)
216 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
217 flbuf, sizeof(struct floor));
222 * lputfloor() - same as putfloor() but unlocks the record (if supported)
224 void lputfloor(struct floor *flbuf, int floor_num)
227 putfloor(flbuf,floor_num);
228 end_critical_section(S_FLOORTAB);
234 * Traverse the room file...
236 void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) {
237 struct quickroom qrbuf;
238 struct cdbdata *cdbqr;
240 cdb_rewind(CDB_QUICKROOM);
242 while(cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
243 bzero(&qrbuf, sizeof(struct quickroom));
244 memcpy(&qrbuf, cdbqr->ptr,
245 ( (cdbqr->len > sizeof(struct quickroom)) ?
246 sizeof(struct quickroom) : cdbqr->len) );
248 if (qrbuf.QRflags & QR_INUSE) (*CallBack)(&qrbuf);
255 * get_msglist() - retrieve room message pointers
257 void get_msglist(struct quickroom *whichroom) {
258 struct cdbdata *cdbfr;
262 lprintf(9, "get_msglist() called for <%s>\n", whichroom->QRname);
263 sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
264 for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
265 lprintf(9, "database key is <%s>\n", dbkey);
267 lprintf(9, "Freeing existing message list\n");
268 if (CC->msglist != NULL) {
274 lprintf(9, "calling cdb_fetch\n");
275 cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey));
276 lprintf(9, "done\n");
282 CC->msglist = malloc(cdbfr->len);
283 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
284 CC->num_msgs = cdbfr->len / sizeof(long);
286 lprintf(9, "Leaving get_msglist()\n");
291 * put_msglist() - retrieve room message pointers
293 void put_msglist(struct quickroom *whichroom) {
297 sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
298 for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
300 cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey),
301 CC->msglist, CC->num_msgs * sizeof(long));
306 * delete_msglist() - delete room message pointers
308 void delete_msglist(struct quickroom *whichroom) {
312 sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
313 for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
315 cdb_delete(CDB_MSGLISTS, dbkey, strlen(dbkey));
320 * MessageFromList() - get a message number from the list currently in memory
322 long MessageFromList(int whichpos) {
324 /* Return zero if the position is invalid */
325 if (whichpos >= CC->num_msgs) return 0L;
327 return(CC->msglist[whichpos]);
331 * SetMessageInList() - set a message number in the list currently in memory
333 void SetMessageInList(int whichpos, long newmsgnum) {
335 /* Return zero if the position is invalid */
336 if (whichpos >= CC->num_msgs) return;
338 CC->msglist[whichpos] = newmsgnum;
344 * sort message pointers
345 * (returns new msg count)
347 int sort_msglist(long listptrs[], int oldcount)
354 if (numitems < 2) return(oldcount);
357 for (a=numitems-2; a>=0; --a) {
358 for (b=0; b<=a; ++b) {
359 if (listptrs[b] > (listptrs[b+1])) {
361 hold2 = listptrs[b+1];
363 listptrs[b+1] = hold1;
368 /* and yank any nulls */
369 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
370 memcpy(&listptrs[0], &listptrs[1],
371 (sizeof(long) * (CC->num_msgs - 1)) );
381 * cmd_lrms() - List all accessible rooms, known or forgotten
383 void cmd_lrms_backend(struct quickroom *qrbuf) {
384 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
385 & (UA_KNOWN | UA_ZAPPED)))
386 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
387 ||((CC->FloorBeingSearched)<0)) )
388 cprintf("%s|%u|%d\n",
389 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
392 void cmd_lrms(char *argbuf)
394 CC->FloorBeingSearched = (-1);
395 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
397 if (!(CC->logged_in)) {
398 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
402 if (getuser(&CC->usersupp,CC->curr_user)) {
403 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
407 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
409 ForEachRoom(cmd_lrms_backend);
416 * cmd_lkra() - List all known rooms
418 void cmd_lkra_backend(struct quickroom *qrbuf) {
419 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
421 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
422 ||((CC->FloorBeingSearched)<0)) )
423 cprintf("%s|%u|%d\n",
424 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
427 void cmd_lkra(char *argbuf)
429 CC->FloorBeingSearched = (-1);
430 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
432 if (!(CC->logged_in)) {
433 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
437 if (getuser(&CC->usersupp,CC->curr_user)) {
438 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
442 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
444 ForEachRoom(cmd_lkra_backend);
451 * cmd_lkrn() - List all known rooms with new messages
453 void cmd_lkrn_backend(struct quickroom *qrbuf) {
456 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
458 && (ra & UA_HASNEWMSGS)
459 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
460 ||((CC->FloorBeingSearched)<0)) )
461 cprintf("%s|%u|%d\n",
462 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
465 void cmd_lkrn(char *argbuf)
467 CC->FloorBeingSearched = (-1);
468 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
470 if (!(CC->logged_in)) {
471 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
475 if (getuser(&CC->usersupp,CC->curr_user)) {
476 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
480 cprintf("%d Rooms w/ new msgs:\n",LISTING_FOLLOWS);
482 ForEachRoom(cmd_lkrn_backend);
489 * cmd_lkro() - List all known rooms
491 void cmd_lkro_backend(struct quickroom *qrbuf) {
494 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
496 && ((ra & UA_HASNEWMSGS)==0)
497 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
498 ||((CC->FloorBeingSearched)<0)) )
499 cprintf("%s|%u|%d\n",
500 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
503 void cmd_lkro(char *argbuf)
505 CC->FloorBeingSearched = (-1);
506 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
508 if (!(CC->logged_in)) {
509 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
513 if (getuser(&CC->usersupp,CC->curr_user)) {
514 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
518 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
520 ForEachRoom(cmd_lkro_backend);
527 * cmd_lzrm() - List all forgotten rooms
529 void cmd_lzrm_backend(struct quickroom *qrbuf) {
532 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
533 if ( (ra & UA_GOTOALLOWED)
535 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
536 ||((CC->FloorBeingSearched)<0)) )
537 cprintf("%s|%u|%d\n",
538 qrbuf->QRname,qrbuf->QRflags,qrbuf->QRfloor);
541 void cmd_lzrm(char *argbuf)
543 CC->FloorBeingSearched = (-1);
544 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
546 if (!(CC->logged_in)) {
547 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
551 if (getuser(&CC->usersupp,CC->curr_user)) {
552 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
556 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
558 ForEachRoom(cmd_lzrm_backend);
564 void usergoto(char *where, int display_result)
567 int new_messages = 0;
568 int total_messages = 0;
572 int newmailcount = 0;
575 strcpy(CC->quickroom.QRname, where);
576 lprintf(9, "usergoto() fetching room record\n");
577 getroom(&CC->quickroom, where);
578 lprintf(9, "usergoto() fetching user record\n");
579 lgetuser(&CC->usersupp,CC->curr_user);
580 lprintf(9, "usergoto() fetching relationships\n");
581 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
583 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
584 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
586 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
587 lputuser(&CC->usersupp,CC->curr_user);
589 lprintf(9, "usergoto() about to check for new mail\n");
590 /* check for new mail */
591 newmailcount = NewMailCount();
593 /* set info to 1 if the user needs to read the room's info file */
594 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
597 lprintf(9, "Fetching message list for counting...\n");
598 get_msglist(&CC->quickroom);
599 for (a=0; a<CC->num_msgs; ++a) {
600 if (MessageFromList(a)>0L) {
602 if (MessageFromList(a) > vbuf.v_lastseen) {
607 lprintf(9, "...done counting\n");
609 if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1;
612 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
613 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
616 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
618 CC->quickroom.QRname,
619 new_messages, total_messages,
620 info,CC->quickroom.QRflags,
621 CC->quickroom.QRhighest,
623 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
625 if (CC->quickroom.QRflags & QR_PRIVATE) {
626 set_wtmpsupp("<private room>");
629 set_wtmpsupp(CC->quickroom.QRname);
635 * cmd_goto() - goto a new room
637 void cmd_goto(char *gargs)
639 struct quickroom QRscratch;
643 char bbb[ROOMNAMELEN],towhere[32],password[20];
645 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
646 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
650 extract(towhere,gargs,0);
651 extract(password,gargs,1);
654 getuser(&CC->usersupp,CC->curr_user);
656 if (!strcasecmp(towhere, "_BASEROOM_"))
657 strcpy(towhere, BASEROOM);
659 if (!strcasecmp(towhere, "_MAIL_"))
660 strcpy(towhere, MAILROOM);
662 if (!strcasecmp(towhere, "_BITBUCKET_"))
663 strcpy(towhere, config.c_twitroom);
666 /* let internal programs go directly to any room */
667 if (((CC->internal_pgm))&&(!strcasecmp(bbb,towhere))) {
668 usergoto(towhere, 1);
672 if (getroom(&QRscratch, towhere) == 0) {
674 /* See if there is an existing user/room relationship */
675 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
677 /* normal clients have to pass through security */
678 if (ra & UA_GOTOALLOWED) ok = 1;
681 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
682 ((ra & UA_KNOWN) == 0) &&
683 (strcasecmp(QRscratch.QRpasswd,password))
685 cprintf("%d wrong or missing passwd\n",
686 ERROR+PASSWORD_REQUIRED);
690 usergoto(towhere, 1);
696 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
700 void cmd_whok(void) {
701 struct usersupp temp;
702 struct cdbdata *cdbus;
704 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
705 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
708 getuser(&CC->usersupp,CC->curr_user);
710 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
711 cprintf("%d Higher access required.\n",
712 ERROR+HIGHER_ACCESS_REQUIRED);
716 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
717 cdb_rewind(CDB_USERSUPP);
718 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
719 bzero(&temp, sizeof(struct usersupp));
720 memcpy(&temp, cdbus->ptr, cdbus->len);
723 if ( (CC->quickroom.QRflags & QR_INUSE)
724 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
725 ) cprintf("%s\n",temp.fullname);
732 * RDIR command for room directory
734 void cmd_rdir(void) {
741 if (!(CC->logged_in)) {
742 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
746 getroom(&CC->quickroom, CC->quickroom.QRname);
747 getuser(&CC->usersupp, CC->curr_user);
749 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
750 cprintf("%d not here.\n",ERROR+NOT_HERE);
754 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
755 && (CC->usersupp.axlevel<6)
756 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
757 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
761 cprintf("%d %s|%s/files/%s\n",
762 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
764 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
765 BBSDIR,CC->quickroom.QRdirname,CC->temp);
768 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
770 if (fd==NULL) fd=fopen("/dev/null","r");
772 ls = fopen(CC->temp,"r");
773 while (fgets(flnm,256,ls)!=NULL) {
774 flnm[strlen(flnm)-1]=0;
775 if (strcasecmp(flnm,"filedir")) {
776 sprintf(buf,"%s/files/%s/%s",
777 BBSDIR,CC->quickroom.QRdirname,flnm);
781 while ((fgets(buf,256,fd)!=NULL)
782 &&(strlen(comment)==0)) {
783 buf[strlen(buf)-1] = 0;
784 if ((!strncasecmp(buf,flnm,strlen(flnm)))
785 && (buf[strlen(flnm)]==' '))
787 &buf[strlen(flnm)+1],255);
789 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
800 * get room parameters (aide or room aide command)
802 void cmd_getr(void) {
803 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
804 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
808 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
809 cprintf("%d Higher access required.\n",
810 ERROR+HIGHER_ACCESS_REQUIRED);
814 if ( (!strcasecmp(CC->quickroom.QRname, BASEROOM))
815 || (!strcasecmp(CC->quickroom.QRname, AIDEROOM)) ) {
816 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
820 getroom(&CC->quickroom, CC->quickroom.QRname);
821 cprintf("%d%c%s|%s|%s|%d|%d\n",
823 CC->quickroom.QRname,
824 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
825 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
826 CC->quickroom.QRflags,
827 (int)CC->quickroom.QRfloor);
832 * set room parameters (aide or room aide command)
834 void cmd_setr(char *args) {
839 if (!(CC->logged_in)) {
840 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
844 if (!is_room_aide()) {
845 cprintf("%d Higher access required.\n",
846 ERROR+HIGHER_ACCESS_REQUIRED);
850 if ( (!strcasecmp(CC->quickroom.QRname, BASEROOM))
851 || (!strcasecmp(CC->quickroom.QRname, AIDEROOM)) ) {
852 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
856 if (num_parms(args)>=6) {
857 getfloor(&flbuf,extract_int(args,5));
858 if ((flbuf.f_flags & F_INUSE) == 0) {
859 cprintf("%d Invalid floor number.\n",
860 ERROR+INVALID_FLOOR_OPERATION);
865 lgetroom(&CC->quickroom, CC->quickroom.QRname);
866 extract(buf,args,0); buf[ROOMNAMELEN]=0;
867 strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
868 extract(buf,args,1); buf[10]=0;
869 strncpy(CC->quickroom.QRpasswd,buf,9);
870 extract(buf,args,2); buf[15]=0;
871 strncpy(CC->quickroom.QRdirname,buf,19);
872 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
874 /* Clean up a client boo-boo: if the client set the room to
875 * guess-name or passworded, ensure that the private flag is
878 if ((CC->quickroom.QRflags & QR_GUESSNAME)
879 ||(CC->quickroom.QRflags & QR_PASSWORDED))
880 CC->quickroom.QRflags |= QR_PRIVATE;
882 /* Kick everyone out if the client requested it (by changing the
883 * room's generation number)
885 if (extract_int(args,4)) {
886 time(&CC->quickroom.QRgen);
889 old_floor = CC->quickroom.QRfloor;
890 if (num_parms(args)>=6) {
891 CC->quickroom.QRfloor = extract_int(args,5);
894 lputroom(&CC->quickroom, CC->quickroom.QRname);
896 /* adjust the floor reference counts */
897 lgetfloor(&flbuf,old_floor);
899 lputfloor(&flbuf,old_floor);
900 lgetfloor(&flbuf,CC->quickroom.QRfloor);
902 lputfloor(&flbuf,CC->quickroom.QRfloor);
904 /* create a room directory if necessary */
905 if (CC->quickroom.QRflags & QR_DIRECTORY) {
907 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
908 CC->quickroom.QRdirname);
912 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
914 cprintf("%d Ok\n",OK);
920 * get the name of the room aide for this room
922 void cmd_geta(void) {
923 struct usersupp usbuf;
925 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
926 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
930 if ( (!strcasecmp(CC->quickroom.QRname, BASEROOM))
931 || (!strcasecmp(CC->quickroom.QRname, AIDEROOM)) ) {
932 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
936 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
937 cprintf("%d %s\n",OK,usbuf.fullname);
946 * set the room aide for this room
948 void cmd_seta(char *new_ra)
950 struct usersupp usbuf;
955 if (!(CC->logged_in)) {
956 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
960 if (!is_room_aide()) {
961 cprintf("%d Higher access required.\n",
962 ERROR+HIGHER_ACCESS_REQUIRED);
966 if (getuser(&usbuf,new_ra)!=0) {
970 newu = usbuf.usernum;
973 lgetroom(&CC->quickroom, CC->quickroom.QRname);
975 if (CC->quickroom.QRroomaide != newu) {
978 CC->quickroom.QRroomaide = newu;
979 lputroom(&CC->quickroom, CC->quickroom.QRname);
982 * We have to post the change notice _after_ writing changes to
983 * the room table, otherwise it would deadlock!
985 if (post_notice == 1) {
986 sprintf(buf,"%s is now room aide for %s>",
987 usbuf.fullname,CC->quickroom.QRname);
990 cprintf("%d Ok\n",OK);
994 * Generate an associated file name for a room
996 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
999 sprintf(buf, "./prefix/%s.%ld", qrbuf->QRname, qrbuf->QRgen);
1000 for (a=0; a<strlen(buf); ++a) {
1001 if (buf[a]==32) buf[a]='.';
1006 * retrieve info file for this room
1008 void cmd_rinf(void) {
1013 assoc_file_name(filename, &CC->quickroom, "info");
1014 info_fp = fopen(filename,"r");
1016 if (info_fp==NULL) {
1017 cprintf("%d No info file.\n",ERROR);
1021 cprintf("%d Info:\n",LISTING_FOLLOWS);
1022 while (fgets(buf, 256, info_fp) != NULL) {
1023 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1024 cprintf("%s\n", buf);
1031 * Back end processing to delete a room and everything associated with it
1033 void delete_room(struct quickroom *qrbuf) {
1039 /* Delete the info file */
1040 assoc_file_name(aaa, qrbuf, "info");
1043 /* Delete the image file */
1044 assoc_file_name(aaa, qrbuf, "images");
1047 /* first flag the room record as not in use */
1048 lgetroom(qrbuf, qrbuf->QRname);
1051 /* then delete the messages in the room */
1052 lprintf(9, "calling get_msglist()\n");
1054 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1055 MsgToDelete = MessageFromList(a);
1056 lprintf(9, "Deleting message %ld\n", MsgToDelete);
1057 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1059 lprintf(9, "calling put_msglist()\n");
1064 lprintf(9, "calling delete_msglist()\n");
1065 delete_msglist(qrbuf);
1066 lputroom(qrbuf, qrbuf->QRname);
1068 /* then decrement the reference count for the floor */
1069 lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
1070 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1071 lputfloor(&flbuf,(int)(qrbuf->QRfloor));
1073 /* Delete the room record from the database! */
1074 putroom(NULL, qrbuf->QRname);
1075 lprintf(9, "finished with delete_room()\n");
1080 * aide command: kill the current room
1082 void cmd_kill(char *argbuf) {
1084 char deleted_room_name[ROOMNAMELEN];
1087 kill_ok = extract_int(argbuf,0);
1089 if (!(CC->logged_in)) {
1090 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1094 if (!is_room_aide()) {
1095 cprintf("%d Higher access required.\n",
1096 ERROR+HIGHER_ACCESS_REQUIRED);
1100 if ( (!strcasecmp(CC->quickroom.QRname, BASEROOM))
1101 || (!strcasecmp(CC->quickroom.QRname, AIDEROOM)) ) {
1102 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1107 strcpy(deleted_room_name, CC->quickroom.QRname);
1108 delete_room(&CC->quickroom); /* Do the dirty work */
1109 lprintf(9, "Calling usergoto()\n");
1110 usergoto(BASEROOM, 0); /* Return to the Lobby */
1112 lprintf(9, "Composing notice\n");
1113 /* tell the world what we did */
1114 sprintf(aaa,"%s> killed by %s",
1115 deleted_room_name, CC->curr_user);
1116 lprintf(9, "Posting notice\n");
1118 lprintf(9, "done posting notice\n");
1119 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1122 cprintf("%d ok to delete.\n",OK);
1128 * Internal code to create a new room (returns room flags)
1130 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1132 unsigned create_room(char *new_room_name,
1134 char *new_room_pass,
1135 int new_room_floor) {
1137 struct quickroom qrbuf;
1141 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1143 bzero(&qrbuf, sizeof(struct quickroom));
1144 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1145 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1146 qrbuf.QRflags = QR_INUSE;
1147 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1148 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1149 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1150 if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
1152 /* If the room is private, and the system administrator has elected
1153 * to automatically grant room aide privileges, do so now; otherwise,
1154 * set the room aide to undefined.
1156 if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) {
1157 qrbuf.QRroomaide=CC->usersupp.usernum;
1160 qrbuf.QRroomaide = (-1L);
1163 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1164 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1165 qrbuf.QRfloor = new_room_floor;
1167 /* save what we just did... */
1168 putroom(&qrbuf, qrbuf.QRname);
1170 /* bump the reference count on whatever floor the room is on */
1171 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1172 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1173 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1175 /* be sure not to kick the creator out of the room! */
1176 lgetuser(&CC->usersupp,CC->curr_user);
1177 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1178 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1179 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1180 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1181 lputuser(&CC->usersupp,CC->curr_user);
1183 /* resume our happy day */
1184 return(qrbuf.QRflags);
1191 void cmd_cre8(char *args)
1194 char new_room_name[256];
1196 char new_room_pass[256];
1200 struct quickroom qrbuf;
1203 cre8_ok = extract_int(args,0);
1204 extract(new_room_name,args,1);
1205 new_room_name[ROOMNAMELEN-1] = 0;
1206 new_room_type = extract_int(args,2);
1207 extract(new_room_pass,args,3);
1208 new_room_pass[9] = 0;
1211 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1212 cprintf("%d Invalid room name.\n",ERROR);
1216 if (num_parms(args)>=5) {
1217 getfloor(&flbuf,extract_int(args,4));
1218 if ((flbuf.f_flags & F_INUSE) == 0) {
1219 cprintf("%d Invalid floor number.\n",
1220 ERROR+INVALID_FLOOR_OPERATION);
1224 new_room_floor = extract_int(args,4);
1228 if (!(CC->logged_in)) {
1229 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1233 if (CC->usersupp.axlevel<3) {
1234 cprintf("%d You need higher access to create rooms.\n",
1235 ERROR+HIGHER_ACCESS_REQUIRED);
1239 if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
1240 cprintf("%d Ok to create rooms.\n", OK);
1244 /* Check to make sure the requested room name doesn't already exist */
1245 if (getroom(&qrbuf, new_room_name)==0) {
1246 cprintf("%d '%s' already exists.\n",
1247 ERROR,qrbuf.QRname);
1251 if ((new_room_type < 0) || (new_room_type > 3)) {
1252 cprintf("%d Invalid room type.\n",ERROR);
1257 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1261 newflags = create_room(new_room_name,
1262 new_room_type,new_room_pass,new_room_floor);
1264 /* post a message in Aide> describing the new room */
1265 strncpy(aaa,new_room_name,255);
1266 strcat(aaa,"> created by ");
1267 strcat(aaa,CC->usersupp.fullname);
1268 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1269 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1270 if (newflags&QR_PASSWORDED) {
1271 strcat(aaa,"\n Password: ");
1272 strcat(aaa,new_room_pass);
1276 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1281 void cmd_einf(char *ok)
1282 { /* enter info file for current room */
1284 char infofilename[64];
1287 if (!(CC->logged_in)) {
1288 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1292 if (!is_room_aide()) {
1293 cprintf("%d Higher access required.\n",
1294 ERROR+HIGHER_ACCESS_REQUIRED);
1299 cprintf("%d Ok.\n",OK);
1303 cprintf("%d Send info...\n",SEND_LISTING);
1305 assoc_file_name(infofilename, &CC->quickroom, "info");
1307 fp=fopen(infofilename,"w");
1310 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1311 } while(strcmp(buf,"000"));
1314 /* now update the room index so people will see our new info */
1315 lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */
1316 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1317 lputroom(&CC->quickroom,CC->quickroom.QRname);
1322 * cmd_lflr() - List all known floors
1324 void cmd_lflr(void) {
1328 if (!(CC->logged_in)) {
1329 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1333 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1334 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1339 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1341 for (a=0; a<MAXFLOORS; ++a) {
1343 if (flbuf.f_flags & F_INUSE) {
1344 cprintf("%d|%s|%d\n",
1356 * create a new floor
1358 void cmd_cflr(char *argbuf)
1360 char new_floor_name[256];
1363 int free_slot = (-1);
1366 extract(new_floor_name,argbuf,0);
1367 cflr_ok = extract_int(argbuf,1);
1370 if (!(CC->logged_in)) {
1371 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1375 if (CC->usersupp.axlevel<6) {
1376 cprintf("%d You need higher access to create rooms.\n",
1377 ERROR+HIGHER_ACCESS_REQUIRED);
1381 for (a=0; a<MAXFLOORS; ++a) {
1384 /* note any free slots while we're scanning... */
1385 if ( ((flbuf.f_flags & F_INUSE)==0)
1386 && (free_slot < 0) ) free_slot = a;
1388 /* check to see if it already exists */
1389 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1390 && (flbuf.f_flags & F_INUSE) ) {
1391 cprintf("%d Floor '%s' already exists.\n",
1392 ERROR+ALREADY_EXISTS,
1400 cprintf("%d There is no space available for a new floor.\n",
1401 ERROR+INVALID_FLOOR_OPERATION);
1406 cprintf("%d ok to create...\n",OK);
1410 lgetfloor(&flbuf,free_slot);
1411 flbuf.f_flags = F_INUSE;
1412 flbuf.f_ref_count = 0;
1413 strncpy(flbuf.f_name,new_floor_name,255);
1414 lputfloor(&flbuf,free_slot);
1415 cprintf("%d %d\n",OK,free_slot);
1423 void cmd_kflr(char *argbuf)
1426 int floor_to_delete;
1430 floor_to_delete = extract_int(argbuf,0);
1431 kflr_ok = extract_int(argbuf,1);
1434 if (!(CC->logged_in)) {
1435 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1439 if (CC->usersupp.axlevel<6) {
1440 cprintf("%d You need higher access to delete floors.\n",
1441 ERROR+HIGHER_ACCESS_REQUIRED);
1445 lgetfloor(&flbuf,floor_to_delete);
1448 if ((flbuf.f_flags & F_INUSE) == 0) {
1449 cprintf("%d Floor %d not in use.\n",
1450 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1455 if (flbuf.f_ref_count != 0) {
1456 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1457 ERROR+INVALID_FLOOR_OPERATION,
1464 cprintf("%d Ok\n",OK);
1467 cprintf("%d Ok to delete...\n",OK);
1474 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1475 lputfloor(&flbuf,floor_to_delete);
1481 void cmd_eflr(char *argbuf)
1487 np = num_parms(argbuf);
1489 cprintf("%d Usage error.\n",ERROR);
1493 if (!(CC->logged_in)) {
1494 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1498 if (CC->usersupp.axlevel<6) {
1499 cprintf("%d You need higher access to edit floors.\n",
1500 ERROR+HIGHER_ACCESS_REQUIRED);
1504 floor_num = extract_int(argbuf,0);
1505 lgetfloor(&flbuf,floor_num);
1506 if ( (flbuf.f_flags & F_INUSE) == 0) {
1507 lputfloor(&flbuf,floor_num);
1508 cprintf("%d Floor %d is not in use.\n",
1509 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1512 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1513 lputfloor(&flbuf,floor_num);
1515 cprintf("%d Ok\n",OK);