15 #include "sysdep_decls.h"
19 #include "serv_chat.h"
20 #include "citserver.h"
24 * Generic routine for determining user access to rooms
26 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf) {
30 /* for internal programs, always do everything */
31 if (((CC->internal_pgm))&&(roombuf->QRflags & QR_INUSE)) {
32 return(UA_KNOWN | UA_GOTOALLOWED);
35 /* For mailbox rooms, only allow access to the owner */
36 if (roombuf->QRflags & QR_MAILBOX) {
37 if (userbuf->usernum != atol(roombuf->QRname)) {
42 /* Locate any applicable user/room relationships */
43 CtdlGetRelationship(&vbuf, userbuf, roombuf);
45 /* Force the properties of the Aide room */
46 if (!strcasecmp(roombuf->QRname, AIDEROOM)) {
47 if (userbuf->axlevel >= 6) {
48 retval = UA_KNOWN | UA_GOTOALLOWED;
56 /* For mailboxes, we skip all the access stuff (and we've
57 * already checked by this point that the mailbox belongs
60 if (roombuf->QRflags & QR_MAILBOX) {
61 retval = UA_KNOWN | UA_GOTOALLOWED;
65 /* If this is a public room, it's accessible... */
66 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
67 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
70 /* If this is a preferred users only room, check access level */
71 if (roombuf->QRflags & QR_PREFONLY) {
72 if (userbuf->axlevel < 5) {
73 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
77 /* For private rooms, check the generation number matchups */
78 if (roombuf->QRflags & QR_PRIVATE) {
80 /* An explicit match means the user belongs in this room */
81 if (vbuf.v_flags & V_ACCESS) {
82 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
84 /* Otherwise, check if this is a guess-name or passworded
85 * room. If it is, a goto may at least be attempted
87 else if ((roombuf->QRflags & QR_PRIVATE)
88 ||(roombuf->QRflags & QR_PASSWORDED)) {
89 retval = retval & ~UA_KNOWN;
90 retval = retval | UA_GOTOALLOWED;
94 /* Check to see if the user has forgotten this room */
95 if (vbuf.v_flags & V_FORGET) {
96 retval = retval & ~UA_KNOWN;
97 retval = retval | UA_ZAPPED;
100 /* If user is explicitly locked out of this room, deny everything */
101 if (vbuf.v_flags & V_LOCKOUT) {
102 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
105 /* Aides get access to everything */
106 if (userbuf->axlevel >= 6) {
107 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
108 retval = retval & ~UA_ZAPPED;
111 NEWMSG: /* By the way, we also check for the presence of new messages */
112 if ( (roombuf->QRhighest) > (vbuf.v_lastseen) ) {
113 retval = retval | UA_HASNEWMSGS;
120 * getroom() - retrieve room data from disk
122 int getroom(struct quickroom *qrbuf, char *room_name)
124 struct cdbdata *cdbqr;
125 char lowercase_name[ROOMNAMELEN];
128 for (a=0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
129 lowercase_name[a] = tolower(room_name[a]);
131 lowercase_name[a] = 0;
133 memset(qrbuf, 0, sizeof(struct quickroom));
134 cdbqr = cdb_fetch(CDB_QUICKROOM,
135 lowercase_name, strlen(lowercase_name));
137 memcpy(qrbuf, cdbqr->ptr,
138 ( (cdbqr->len > sizeof(struct quickroom)) ?
139 sizeof(struct quickroom) : cdbqr->len) );
142 /* Mailbox rooms are always on the lowest floor */
143 if (qrbuf->QRflags & QR_MAILBOX) {
155 * lgetroom() - same as getroom() but locks the record (if supported)
157 int lgetroom(struct quickroom *qrbuf, char *room_name)
159 begin_critical_section(S_QUICKROOM);
160 return(getroom(qrbuf, room_name));
165 * putroom() - store room data on disk
166 * (if the supplied buffer is NULL, delete the room record)
168 void putroom(struct quickroom *qrbuf, char *room_name)
170 char lowercase_name[ROOMNAMELEN];
173 for (a=0; a<=strlen(room_name); ++a) {
174 lowercase_name[a] = tolower(room_name[a]);
178 cdb_delete(CDB_QUICKROOM,
179 lowercase_name, strlen(lowercase_name));
182 time(&qrbuf->QRmtime);
183 cdb_store(CDB_QUICKROOM,
184 lowercase_name, strlen(lowercase_name),
185 qrbuf, sizeof(struct quickroom));
191 * lputroom() - same as putroom() but unlocks the record (if supported)
193 void lputroom(struct quickroom *qrbuf, char *room_name)
196 putroom(qrbuf, room_name);
197 end_critical_section(S_QUICKROOM);
201 /****************************************************************************/
204 * getfloor() - retrieve floor data from disk
206 void getfloor(struct floor *flbuf, int floor_num)
208 struct cdbdata *cdbfl;
210 memset(flbuf, 0, sizeof(struct floor));
211 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
213 memcpy(flbuf, cdbfl->ptr,
214 ( (cdbfl->len > sizeof(struct floor)) ?
215 sizeof(struct floor) : cdbfl->len) );
219 if (floor_num == 0) {
220 strcpy(flbuf->f_name, "Main Floor");
221 flbuf->f_flags = F_INUSE;
222 flbuf->f_ref_count = 3;
229 * lgetfloor() - same as getfloor() but locks the record (if supported)
231 void lgetfloor(struct floor *flbuf, int floor_num)
234 begin_critical_section(S_FLOORTAB);
235 getfloor(flbuf,floor_num);
240 * putfloor() - store floor data on disk
242 void putfloor(struct floor *flbuf, int floor_num)
244 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
245 flbuf, sizeof(struct floor));
250 * lputfloor() - same as putfloor() but unlocks the record (if supported)
252 void lputfloor(struct floor *flbuf, int floor_num)
255 putfloor(flbuf,floor_num);
256 end_critical_section(S_FLOORTAB);
262 * Traverse the room file...
264 void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) {
265 struct quickroom qrbuf;
266 struct cdbdata *cdbqr;
268 cdb_rewind(CDB_QUICKROOM);
270 while(cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
271 memset(&qrbuf, 0, sizeof(struct quickroom));
272 memcpy(&qrbuf, cdbqr->ptr,
273 ( (cdbqr->len > sizeof(struct quickroom)) ?
274 sizeof(struct quickroom) : cdbqr->len) );
276 if (qrbuf.QRflags & QR_INUSE) (*CallBack)(&qrbuf);
283 * get_msglist() - retrieve room message pointers
285 void get_msglist(struct quickroom *whichroom) {
286 struct cdbdata *cdbfr;
288 if (CC->msglist != NULL) {
294 cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
299 CC->msglist = malloc(cdbfr->len);
300 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
301 CC->num_msgs = cdbfr->len / sizeof(long);
307 * put_msglist() - retrieve room message pointers
309 void put_msglist(struct quickroom *whichroom) {
311 cdb_store(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long),
312 CC->msglist, CC->num_msgs * sizeof(long));
317 * delete_msglist() - delete room message pointers
318 * FIX - this really should check first to make sure there's actually a
319 * msglist to delete. As things stand now, calling this function on
320 * a room which has never been posted in will result in a message
321 * like "gdbm: illegal data" (no big deal, but could use fixing).
323 void delete_msglist(struct quickroom *whichroom) {
325 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
330 * Add a message number to a room's message list.
331 * So, why doesn't this function use the get_msglist() and put_msglist() stuff
332 * defined above? Because the room the message number is being written to
333 * may not be the current room (as is the case with cmd_move() for example).
335 void AddMessageToRoom(struct quickroom *whichroom, long newmsgid) {
336 struct cdbdata *cdbfr;
340 cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
346 msglist = malloc(cdbfr->len);
347 num_msgs = cdbfr->len / sizeof(long);
348 memcpy(msglist, cdbfr->ptr, cdbfr->len);
352 /* Now add the new message */
354 msglist = realloc(msglist,
355 (num_msgs * sizeof(long)) );
357 if (msglist == NULL) {
358 lprintf(3, "ERROR: can't realloc message list!\n");
361 msglist[num_msgs - 1] = newmsgid;
363 /* Write it back to disk. */
364 cdb_store(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long),
365 msglist, num_msgs * sizeof(long));
367 /* And finally, free up the memory we used. */
373 * MessageFromList() - get a message number from the list currently in memory
375 long MessageFromList(int whichpos) {
377 /* Return zero if the position is invalid */
378 if (whichpos >= CC->num_msgs) return 0L;
380 return(CC->msglist[whichpos]);
384 * SetMessageInList() - set a message number in the list currently in memory
386 void SetMessageInList(int whichpos, long newmsgnum) {
388 /* Return zero if the position is invalid */
389 if (whichpos >= CC->num_msgs) return;
391 CC->msglist[whichpos] = newmsgnum;
397 * sort message pointers
398 * (returns new msg count)
400 int sort_msglist(long listptrs[], int oldcount)
407 if (numitems < 2) return(oldcount);
410 for (a=numitems-2; a>=0; --a) {
411 for (b=0; b<=a; ++b) {
412 if (listptrs[b] > (listptrs[b+1])) {
414 hold2 = listptrs[b+1];
416 listptrs[b+1] = hold1;
421 /* and yank any nulls */
422 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
423 memcpy(&listptrs[0], &listptrs[1],
424 (sizeof(long) * (CC->num_msgs - 1)) );
433 * Determine whether a given room is non-editable.
435 int is_noneditable(struct quickroom *qrbuf) {
437 /* Lobby> and Aide> are non-editable */
438 if (!strcasecmp(qrbuf->QRname, BASEROOM)) return(1);
439 else if (!strcasecmp(qrbuf->QRname, AIDEROOM)) return(1);
441 /* Mailbox rooms are also non-editable */
442 else if (qrbuf->QRflags & QR_MAILBOX) return(1);
444 /* Everything else is editable */
451 * Back-back-end for all room listing commands
453 void list_roomname(struct quickroom *qrbuf) {
454 char truncated_roomname[ROOMNAMELEN];
456 /* For mailbox rooms, chop off the owner prefix */
457 if (qrbuf->QRflags & QR_MAILBOX) {
458 strcpy(truncated_roomname, qrbuf->QRname);
459 strcpy(truncated_roomname, &truncated_roomname[11]);
460 cprintf("%s", truncated_roomname);
462 /* For all other rooms, just display the name in its entirety */
464 cprintf("%s", qrbuf->QRname);
467 /* ...and now the other parameters */
469 qrbuf->QRflags,qrbuf->QRfloor);
474 * cmd_lrms() - List all accessible rooms, known or forgotten
476 void cmd_lrms_backend(struct quickroom *qrbuf) {
477 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
478 & (UA_KNOWN | UA_ZAPPED)))
479 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
480 ||((CC->FloorBeingSearched)<0)) )
481 list_roomname(qrbuf);
484 void cmd_lrms(char *argbuf)
486 CC->FloorBeingSearched = (-1);
487 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
489 if (!(CC->logged_in)) {
490 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
494 if (getuser(&CC->usersupp,CC->curr_user)) {
495 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
499 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
501 ForEachRoom(cmd_lrms_backend);
508 * cmd_lkra() - List all known rooms
510 void cmd_lkra_backend(struct quickroom *qrbuf) {
511 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
513 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
514 ||((CC->FloorBeingSearched)<0)) )
515 list_roomname(qrbuf);
518 void cmd_lkra(char *argbuf)
520 CC->FloorBeingSearched = (-1);
521 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
523 if (!(CC->logged_in)) {
524 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
528 if (getuser(&CC->usersupp,CC->curr_user)) {
529 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
533 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
535 ForEachRoom(cmd_lkra_backend);
542 * cmd_lkrn() - List all known rooms with new messages
544 void cmd_lkrn_backend(struct quickroom *qrbuf) {
547 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
549 && (ra & UA_HASNEWMSGS)
550 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
551 ||((CC->FloorBeingSearched)<0)) )
552 list_roomname(qrbuf);
555 void cmd_lkrn(char *argbuf)
557 CC->FloorBeingSearched = (-1);
558 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
560 if (!(CC->logged_in)) {
561 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
565 if (getuser(&CC->usersupp,CC->curr_user)) {
566 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
570 cprintf("%d Rooms w/ new msgs:\n",LISTING_FOLLOWS);
572 ForEachRoom(cmd_lkrn_backend);
579 * cmd_lkro() - List all known rooms
581 void cmd_lkro_backend(struct quickroom *qrbuf) {
584 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
586 && ((ra & UA_HASNEWMSGS)==0)
587 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
588 ||((CC->FloorBeingSearched)<0)) )
589 list_roomname(qrbuf);
592 void cmd_lkro(char *argbuf)
594 CC->FloorBeingSearched = (-1);
595 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
597 if (!(CC->logged_in)) {
598 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
602 if (getuser(&CC->usersupp,CC->curr_user)) {
603 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
607 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
609 ForEachRoom(cmd_lkro_backend);
616 * cmd_lzrm() - List all forgotten rooms
618 void cmd_lzrm_backend(struct quickroom *qrbuf) {
621 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
622 if ( (ra & UA_GOTOALLOWED)
624 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
625 ||((CC->FloorBeingSearched)<0)) )
626 list_roomname(qrbuf);
629 void cmd_lzrm(char *argbuf)
631 CC->FloorBeingSearched = (-1);
632 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
634 if (!(CC->logged_in)) {
635 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
639 if (getuser(&CC->usersupp,CC->curr_user)) {
640 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
644 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
646 ForEachRoom(cmd_lzrm_backend);
652 void usergoto(char *where, int display_result)
655 int new_messages = 0;
656 int total_messages = 0;
660 int newmailcount = 0;
662 char truncated_roomname[ROOMNAMELEN];
664 strcpy(CC->quickroom.QRname, where);
665 getroom(&CC->quickroom, where);
666 lgetuser(&CC->usersupp,CC->curr_user);
667 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
669 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
670 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
672 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
673 lputuser(&CC->usersupp,CC->curr_user);
675 /* check for new mail */
676 newmailcount = NewMailCount();
678 /* set info to 1 if the user needs to read the room's info file */
679 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
682 get_msglist(&CC->quickroom);
683 for (a=0; a<CC->num_msgs; ++a) {
684 if (MessageFromList(a)>0L) {
686 if (MessageFromList(a) > vbuf.v_lastseen) {
692 if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1;
695 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
696 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
699 strcpy(truncated_roomname, CC->quickroom.QRname);
700 if (CC->quickroom.QRflags & QR_MAILBOX) {
701 strcpy(truncated_roomname, &truncated_roomname[11]);
704 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
707 new_messages, total_messages,
708 info,CC->quickroom.QRflags,
709 CC->quickroom.QRhighest,
711 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
713 set_wtmpsupp_to_current_room();
718 * cmd_goto() - goto a new room
720 void cmd_goto(char *gargs)
722 struct quickroom QRscratch;
726 char augmented_roomname[256];
730 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
731 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
735 extract(towhere,gargs,0);
736 extract(password,gargs,1);
738 getuser(&CC->usersupp, CC->curr_user);
740 if (!strcasecmp(towhere, "_BASEROOM_"))
741 strcpy(towhere, BASEROOM);
743 if (!strcasecmp(towhere, "_MAIL_"))
744 strcpy(towhere, MAILROOM);
746 if (!strcasecmp(towhere, "_BITBUCKET_"))
747 strcpy(towhere, config.c_twitroom);
750 /* First try a regular match */
751 c = getroom(&QRscratch, towhere);
753 /* Then try a mailbox name match */
755 MailboxName(augmented_roomname, &CC->usersupp, towhere);
756 c = getroom(&QRscratch, augmented_roomname);
757 if (c == 0) strcpy(towhere, augmented_roomname);
760 /* And if the room was found... */
763 /* let internal programs go directly to any room */
764 if (CC->internal_pgm) {
765 usergoto(towhere, 1);
769 /* See if there is an existing user/room relationship */
770 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
772 /* normal clients have to pass through security */
773 if (ra & UA_GOTOALLOWED) ok = 1;
776 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
777 ((ra & UA_KNOWN) == 0) &&
778 (strcasecmp(QRscratch.QRpasswd,password))
780 cprintf("%d wrong or missing passwd\n",
781 ERROR+PASSWORD_REQUIRED);
785 usergoto(towhere, 1);
791 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
795 void cmd_whok(void) {
796 struct usersupp temp;
797 struct cdbdata *cdbus;
799 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
800 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
803 getuser(&CC->usersupp,CC->curr_user);
805 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
806 cprintf("%d Higher access required.\n",
807 ERROR+HIGHER_ACCESS_REQUIRED);
811 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
812 cdb_rewind(CDB_USERSUPP);
813 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
814 memset(&temp, 0, sizeof(struct usersupp));
815 memcpy(&temp, cdbus->ptr, cdbus->len);
818 if ( (CC->quickroom.QRflags & QR_INUSE)
819 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
820 ) cprintf("%s\n",temp.fullname);
827 * RDIR command for room directory
829 void cmd_rdir(void) {
836 if (!(CC->logged_in)) {
837 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
841 getroom(&CC->quickroom, CC->quickroom.QRname);
842 getuser(&CC->usersupp, CC->curr_user);
844 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
845 cprintf("%d not here.\n",ERROR+NOT_HERE);
849 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
850 && (CC->usersupp.axlevel<6)
851 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
852 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
856 cprintf("%d %s|%s/files/%s\n",
857 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
859 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
860 BBSDIR,CC->quickroom.QRdirname,CC->temp);
863 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
865 if (fd==NULL) fd=fopen("/dev/null","r");
867 ls = fopen(CC->temp,"r");
868 while (fgets(flnm,256,ls)!=NULL) {
869 flnm[strlen(flnm)-1]=0;
870 if (strcasecmp(flnm,"filedir")) {
871 sprintf(buf,"%s/files/%s/%s",
872 BBSDIR,CC->quickroom.QRdirname,flnm);
876 while ((fgets(buf,256,fd)!=NULL)
877 &&(strlen(comment)==0)) {
878 buf[strlen(buf)-1] = 0;
879 if ((!strncasecmp(buf,flnm,strlen(flnm)))
880 && (buf[strlen(flnm)]==' '))
882 &buf[strlen(flnm)+1],255);
884 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
895 * get room parameters (aide or room aide command)
897 void cmd_getr(void) {
898 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
899 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
903 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
904 cprintf("%d Higher access required.\n",
905 ERROR+HIGHER_ACCESS_REQUIRED);
909 if (is_noneditable(&CC->quickroom)) {
910 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
914 getroom(&CC->quickroom, CC->quickroom.QRname);
915 cprintf("%d%c%s|%s|%s|%d|%d\n",
917 CC->quickroom.QRname,
918 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
919 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
920 CC->quickroom.QRflags,
921 (int)CC->quickroom.QRfloor);
926 * set room parameters (aide or room aide command)
928 void cmd_setr(char *args) {
931 char old_name[ROOMNAMELEN];
934 if (!(CC->logged_in)) {
935 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
939 if (!is_room_aide()) {
940 cprintf("%d Higher access required.\n",
941 ERROR+HIGHER_ACCESS_REQUIRED);
945 if (is_noneditable(&CC->quickroom)) {
946 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
950 if (num_parms(args)>=6) {
951 getfloor(&flbuf,extract_int(args,5));
952 if ((flbuf.f_flags & F_INUSE) == 0) {
953 cprintf("%d Invalid floor number.\n",
954 ERROR+INVALID_FLOOR_OPERATION);
959 lgetroom(&CC->quickroom, CC->quickroom.QRname);
960 strcpy(old_name, CC->quickroom.QRname);
961 extract(buf,args,0); buf[ROOMNAMELEN]=0;
962 strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
963 extract(buf,args,1); buf[10]=0;
964 strncpy(CC->quickroom.QRpasswd,buf,9);
965 extract(buf,args,2); buf[15]=0;
966 strncpy(CC->quickroom.QRdirname,buf,19);
967 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
969 /* Clean up a client boo-boo: if the client set the room to
970 * guess-name or passworded, ensure that the private flag is
973 if ((CC->quickroom.QRflags & QR_GUESSNAME)
974 ||(CC->quickroom.QRflags & QR_PASSWORDED))
975 CC->quickroom.QRflags |= QR_PRIVATE;
977 /* Kick everyone out if the client requested it (by changing the
978 * room's generation number)
980 if (extract_int(args,4)) {
981 time(&CC->quickroom.QRgen);
984 old_floor = CC->quickroom.QRfloor;
985 if (num_parms(args)>=6) {
986 CC->quickroom.QRfloor = extract_int(args,5);
989 /* Write the room record back to disk */
990 lputroom(&CC->quickroom, CC->quickroom.QRname);
992 /* If the room name changed, then there are now two room records,
993 * so we have to delete the old one.
995 /* FIX - This causes everybody to think it's a new room, because the
996 * visit structs no longer match! Major problem! We have to
997 * assign each room a unique Object ID and index by that.
999 if (strcasecmp(CC->quickroom.QRname, old_name)) {
1000 putroom(NULL, old_name);
1003 /* adjust the floor reference counts */
1004 lgetfloor(&flbuf,old_floor);
1005 --flbuf.f_ref_count;
1006 lputfloor(&flbuf,old_floor);
1007 lgetfloor(&flbuf,CC->quickroom.QRfloor);
1008 ++flbuf.f_ref_count;
1009 lputfloor(&flbuf,CC->quickroom.QRfloor);
1011 /* create a room directory if necessary */
1012 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1014 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1015 CC->quickroom.QRdirname);
1019 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
1021 cprintf("%d Ok\n",OK);
1027 * get the name of the room aide for this room
1029 void cmd_geta(void) {
1030 struct usersupp usbuf;
1032 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
1033 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1037 if (is_noneditable(&CC->quickroom)) {
1038 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1042 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
1043 cprintf("%d %s\n",OK,usbuf.fullname);
1046 cprintf("%d \n",OK);
1052 * set the room aide for this room
1054 void cmd_seta(char *new_ra)
1056 struct usersupp usbuf;
1061 if (!(CC->logged_in)) {
1062 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1066 if (!is_room_aide()) {
1067 cprintf("%d Higher access required.\n",
1068 ERROR+HIGHER_ACCESS_REQUIRED);
1072 if (getuser(&usbuf,new_ra)!=0) {
1076 newu = usbuf.usernum;
1079 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1081 if (CC->quickroom.QRroomaide != newu) {
1084 CC->quickroom.QRroomaide = newu;
1085 lputroom(&CC->quickroom, CC->quickroom.QRname);
1088 * We have to post the change notice _after_ writing changes to
1089 * the room table, otherwise it would deadlock!
1091 if (post_notice == 1) {
1092 sprintf(buf,"%s is now room aide for %s>",
1093 usbuf.fullname,CC->quickroom.QRname);
1096 cprintf("%d Ok\n",OK);
1100 * Generate an associated file name for a room
1102 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
1105 sprintf(buf, "./prefix/%s.%ld", qrbuf->QRname, qrbuf->QRgen);
1106 for (a=0; a<strlen(buf); ++a) {
1107 if (buf[a]==32) buf[a]='.';
1112 * retrieve info file for this room
1114 void cmd_rinf(void) {
1119 assoc_file_name(filename, &CC->quickroom, "info");
1120 info_fp = fopen(filename,"r");
1122 if (info_fp==NULL) {
1123 cprintf("%d No info file.\n",ERROR);
1127 cprintf("%d Info:\n",LISTING_FOLLOWS);
1128 while (fgets(buf, 256, info_fp) != NULL) {
1129 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1130 cprintf("%s\n", buf);
1137 * Back end processing to delete a room and everything associated with it
1139 void delete_room(struct quickroom *qrbuf) {
1145 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1147 /* Delete the info file */
1148 assoc_file_name(aaa, qrbuf, "info");
1151 /* Delete the image file */
1152 assoc_file_name(aaa, qrbuf, "images");
1155 /* first flag the room record as not in use */
1156 lgetroom(qrbuf, qrbuf->QRname);
1159 /* then delete the messages in the room */
1161 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1162 MsgToDelete = MessageFromList(a);
1163 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1169 delete_msglist(qrbuf);
1170 lputroom(qrbuf, qrbuf->QRname);
1172 /* then decrement the reference count for the floor */
1173 lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
1174 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1175 lputfloor(&flbuf,(int)(qrbuf->QRfloor));
1177 /* Delete the room record from the database! */
1178 putroom(NULL, qrbuf->QRname);
1183 * aide command: kill the current room
1185 void cmd_kill(char *argbuf) {
1187 char deleted_room_name[ROOMNAMELEN];
1190 kill_ok = extract_int(argbuf,0);
1192 if (!(CC->logged_in)) {
1193 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1197 if (!is_room_aide()) {
1198 cprintf("%d Higher access required.\n",
1199 ERROR+HIGHER_ACCESS_REQUIRED);
1203 if (is_noneditable(&CC->quickroom)) {
1204 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1209 strcpy(deleted_room_name, CC->quickroom.QRname);
1210 delete_room(&CC->quickroom); /* Do the dirty work */
1211 usergoto(BASEROOM, 0); /* Return to the Lobby */
1213 /* tell the world what we did */
1214 sprintf(aaa,"%s> killed by %s",
1215 deleted_room_name, CC->curr_user);
1217 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1220 cprintf("%d ok to delete.\n",OK);
1226 * Internal code to create a new room (returns room flags)
1228 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1230 unsigned create_room(char *new_room_name,
1232 char *new_room_pass,
1233 int new_room_floor) {
1235 struct quickroom qrbuf;
1239 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1241 memset(&qrbuf, 0, sizeof(struct quickroom));
1242 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1243 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1244 qrbuf.QRflags = QR_INUSE;
1245 qrbuf.QRnumber = get_new_room_number();
1246 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1247 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1248 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1249 if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
1251 /* If the room is private, and the system administrator has elected
1252 * to automatically grant room aide privileges, do so now; otherwise,
1253 * set the room aide to undefined.
1255 if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) {
1256 qrbuf.QRroomaide=CC->usersupp.usernum;
1259 qrbuf.QRroomaide = (-1L);
1262 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1263 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1264 qrbuf.QRfloor = new_room_floor;
1266 /* save what we just did... */
1267 putroom(&qrbuf, qrbuf.QRname);
1269 /* bump the reference count on whatever floor the room is on */
1270 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1271 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1272 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1274 /* be sure not to kick the creator out of the room! */
1275 lgetuser(&CC->usersupp,CC->curr_user);
1276 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1277 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1278 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1279 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1280 lputuser(&CC->usersupp,CC->curr_user);
1282 /* resume our happy day */
1283 return(qrbuf.QRflags);
1290 void cmd_cre8(char *args)
1293 char new_room_name[256];
1295 char new_room_pass[256];
1299 struct quickroom qrbuf;
1302 cre8_ok = extract_int(args,0);
1303 extract(new_room_name,args,1);
1304 new_room_name[ROOMNAMELEN-1] = 0;
1305 new_room_type = extract_int(args,2);
1306 extract(new_room_pass,args,3);
1307 new_room_pass[9] = 0;
1310 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1311 cprintf("%d Invalid room name.\n",ERROR);
1315 if (num_parms(args)>=5) {
1316 getfloor(&flbuf,extract_int(args,4));
1317 if ((flbuf.f_flags & F_INUSE) == 0) {
1318 cprintf("%d Invalid floor number.\n",
1319 ERROR+INVALID_FLOOR_OPERATION);
1323 new_room_floor = extract_int(args,4);
1327 if (!(CC->logged_in)) {
1328 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1332 if (CC->usersupp.axlevel<3) {
1333 cprintf("%d You need higher access to create rooms.\n",
1334 ERROR+HIGHER_ACCESS_REQUIRED);
1338 if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
1339 cprintf("%d Ok to create rooms.\n", OK);
1343 /* Check to make sure the requested room name doesn't already exist */
1344 if (getroom(&qrbuf, new_room_name)==0) {
1345 cprintf("%d '%s' already exists.\n",
1346 ERROR,qrbuf.QRname);
1350 if ((new_room_type < 0) || (new_room_type > 3)) {
1351 cprintf("%d Invalid room type.\n",ERROR);
1356 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1360 newflags = create_room(new_room_name,
1361 new_room_type,new_room_pass,new_room_floor);
1363 /* post a message in Aide> describing the new room */
1364 strncpy(aaa,new_room_name,255);
1365 strcat(aaa,"> created by ");
1366 strcat(aaa,CC->usersupp.fullname);
1367 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1368 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1369 if (newflags&QR_PASSWORDED) {
1370 strcat(aaa,"\n Password: ");
1371 strcat(aaa,new_room_pass);
1375 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1380 void cmd_einf(char *ok)
1381 { /* enter info file for current room */
1383 char infofilename[64];
1386 if (!(CC->logged_in)) {
1387 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1391 if (!is_room_aide()) {
1392 cprintf("%d Higher access required.\n",
1393 ERROR+HIGHER_ACCESS_REQUIRED);
1398 cprintf("%d Ok.\n",OK);
1402 cprintf("%d Send info...\n",SEND_LISTING);
1404 assoc_file_name(infofilename, &CC->quickroom, "info");
1406 fp=fopen(infofilename,"w");
1409 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1410 } while(strcmp(buf,"000"));
1413 /* now update the room index so people will see our new info */
1414 lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */
1415 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1416 lputroom(&CC->quickroom,CC->quickroom.QRname);
1421 * cmd_lflr() - List all known floors
1423 void cmd_lflr(void) {
1427 if (!(CC->logged_in)) {
1428 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1432 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1433 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1438 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1440 for (a=0; a<MAXFLOORS; ++a) {
1442 if (flbuf.f_flags & F_INUSE) {
1443 cprintf("%d|%s|%d\n",
1455 * create a new floor
1457 void cmd_cflr(char *argbuf)
1459 char new_floor_name[256];
1462 int free_slot = (-1);
1465 extract(new_floor_name,argbuf,0);
1466 cflr_ok = extract_int(argbuf,1);
1469 if (!(CC->logged_in)) {
1470 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1474 if (CC->usersupp.axlevel<6) {
1475 cprintf("%d You need higher access to create rooms.\n",
1476 ERROR+HIGHER_ACCESS_REQUIRED);
1480 for (a=0; a<MAXFLOORS; ++a) {
1483 /* note any free slots while we're scanning... */
1484 if ( ((flbuf.f_flags & F_INUSE)==0)
1485 && (free_slot < 0) ) free_slot = a;
1487 /* check to see if it already exists */
1488 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1489 && (flbuf.f_flags & F_INUSE) ) {
1490 cprintf("%d Floor '%s' already exists.\n",
1491 ERROR+ALREADY_EXISTS,
1499 cprintf("%d There is no space available for a new floor.\n",
1500 ERROR+INVALID_FLOOR_OPERATION);
1505 cprintf("%d ok to create...\n",OK);
1509 lgetfloor(&flbuf,free_slot);
1510 flbuf.f_flags = F_INUSE;
1511 flbuf.f_ref_count = 0;
1512 strncpy(flbuf.f_name,new_floor_name,255);
1513 lputfloor(&flbuf,free_slot);
1514 cprintf("%d %d\n",OK,free_slot);
1522 void cmd_kflr(char *argbuf)
1525 int floor_to_delete;
1529 floor_to_delete = extract_int(argbuf,0);
1530 kflr_ok = extract_int(argbuf,1);
1533 if (!(CC->logged_in)) {
1534 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1538 if (CC->usersupp.axlevel<6) {
1539 cprintf("%d You need higher access to delete floors.\n",
1540 ERROR+HIGHER_ACCESS_REQUIRED);
1544 lgetfloor(&flbuf,floor_to_delete);
1547 if ((flbuf.f_flags & F_INUSE) == 0) {
1548 cprintf("%d Floor %d not in use.\n",
1549 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1554 if (flbuf.f_ref_count != 0) {
1555 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1556 ERROR+INVALID_FLOOR_OPERATION,
1563 cprintf("%d Ok\n",OK);
1566 cprintf("%d Ok to delete...\n",OK);
1573 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1574 lputfloor(&flbuf,floor_to_delete);
1580 void cmd_eflr(char *argbuf)
1586 np = num_parms(argbuf);
1588 cprintf("%d Usage error.\n",ERROR);
1592 if (!(CC->logged_in)) {
1593 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1597 if (CC->usersupp.axlevel<6) {
1598 cprintf("%d You need higher access to edit floors.\n",
1599 ERROR+HIGHER_ACCESS_REQUIRED);
1603 floor_num = extract_int(argbuf,0);
1604 lgetfloor(&flbuf,floor_num);
1605 if ( (flbuf.f_flags & F_INUSE) == 0) {
1606 lputfloor(&flbuf,floor_num);
1607 cprintf("%d Floor %d is not in use.\n",
1608 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1611 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1612 lputfloor(&flbuf,floor_num);
1614 cprintf("%d Ok\n",OK);