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 if (strcasecmp(CC->quickroom.QRname, old_name)) {
996 putroom(NULL, old_name);
999 /* adjust the floor reference counts */
1000 lgetfloor(&flbuf,old_floor);
1001 --flbuf.f_ref_count;
1002 lputfloor(&flbuf,old_floor);
1003 lgetfloor(&flbuf,CC->quickroom.QRfloor);
1004 ++flbuf.f_ref_count;
1005 lputfloor(&flbuf,CC->quickroom.QRfloor);
1007 /* create a room directory if necessary */
1008 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1010 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1011 CC->quickroom.QRdirname);
1015 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
1017 cprintf("%d Ok\n",OK);
1023 * get the name of the room aide for this room
1025 void cmd_geta(void) {
1026 struct usersupp usbuf;
1028 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
1029 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1033 if (is_noneditable(&CC->quickroom)) {
1034 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1038 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
1039 cprintf("%d %s\n",OK,usbuf.fullname);
1042 cprintf("%d \n",OK);
1048 * set the room aide for this room
1050 void cmd_seta(char *new_ra)
1052 struct usersupp usbuf;
1057 if (!(CC->logged_in)) {
1058 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1062 if (!is_room_aide()) {
1063 cprintf("%d Higher access required.\n",
1064 ERROR+HIGHER_ACCESS_REQUIRED);
1068 if (getuser(&usbuf,new_ra)!=0) {
1072 newu = usbuf.usernum;
1075 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1077 if (CC->quickroom.QRroomaide != newu) {
1080 CC->quickroom.QRroomaide = newu;
1081 lputroom(&CC->quickroom, CC->quickroom.QRname);
1084 * We have to post the change notice _after_ writing changes to
1085 * the room table, otherwise it would deadlock!
1087 if (post_notice == 1) {
1088 sprintf(buf,"%s is now room aide for %s>",
1089 usbuf.fullname,CC->quickroom.QRname);
1092 cprintf("%d Ok\n",OK);
1096 * Generate an associated file name for a room
1098 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
1101 sprintf(buf, "./prefix/%s.%ld", qrbuf->QRname, qrbuf->QRgen);
1102 for (a=0; a<strlen(buf); ++a) {
1103 if (buf[a]==32) buf[a]='.';
1108 * retrieve info file for this room
1110 void cmd_rinf(void) {
1115 assoc_file_name(filename, &CC->quickroom, "info");
1116 info_fp = fopen(filename,"r");
1118 if (info_fp==NULL) {
1119 cprintf("%d No info file.\n",ERROR);
1123 cprintf("%d Info:\n",LISTING_FOLLOWS);
1124 while (fgets(buf, 256, info_fp) != NULL) {
1125 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1126 cprintf("%s\n", buf);
1133 * Back end processing to delete a room and everything associated with it
1135 void delete_room(struct quickroom *qrbuf) {
1141 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1143 /* Delete the info file */
1144 assoc_file_name(aaa, qrbuf, "info");
1147 /* Delete the image file */
1148 assoc_file_name(aaa, qrbuf, "images");
1151 /* first flag the room record as not in use */
1152 lgetroom(qrbuf, qrbuf->QRname);
1155 /* then delete the messages in the room */
1157 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1158 MsgToDelete = MessageFromList(a);
1159 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1165 delete_msglist(qrbuf);
1166 lputroom(qrbuf, qrbuf->QRname);
1168 /* then decrement the reference count for the floor */
1169 lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
1170 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1171 lputfloor(&flbuf,(int)(qrbuf->QRfloor));
1173 /* Delete the room record from the database! */
1174 putroom(NULL, qrbuf->QRname);
1179 * aide command: kill the current room
1181 void cmd_kill(char *argbuf) {
1183 char deleted_room_name[ROOMNAMELEN];
1186 kill_ok = extract_int(argbuf,0);
1188 if (!(CC->logged_in)) {
1189 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1193 if (!is_room_aide()) {
1194 cprintf("%d Higher access required.\n",
1195 ERROR+HIGHER_ACCESS_REQUIRED);
1199 if (is_noneditable(&CC->quickroom)) {
1200 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1205 strcpy(deleted_room_name, CC->quickroom.QRname);
1206 delete_room(&CC->quickroom); /* Do the dirty work */
1207 usergoto(BASEROOM, 0); /* Return to the Lobby */
1209 /* tell the world what we did */
1210 sprintf(aaa,"%s> killed by %s",
1211 deleted_room_name, CC->curr_user);
1213 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1216 cprintf("%d ok to delete.\n",OK);
1222 * Internal code to create a new room (returns room flags)
1224 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1226 unsigned create_room(char *new_room_name,
1228 char *new_room_pass,
1229 int new_room_floor) {
1231 struct quickroom qrbuf;
1235 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1237 memset(&qrbuf, 0, sizeof(struct quickroom));
1238 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1239 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1240 qrbuf.QRflags = QR_INUSE;
1241 qrbuf.QRnumber = get_new_room_number();
1242 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1243 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1244 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1245 if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
1247 /* If the room is private, and the system administrator has elected
1248 * to automatically grant room aide privileges, do so now; otherwise,
1249 * set the room aide to undefined.
1251 if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) {
1252 qrbuf.QRroomaide=CC->usersupp.usernum;
1255 qrbuf.QRroomaide = (-1L);
1258 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1259 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1260 qrbuf.QRfloor = new_room_floor;
1262 /* save what we just did... */
1263 putroom(&qrbuf, qrbuf.QRname);
1265 /* bump the reference count on whatever floor the room is on */
1266 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1267 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1268 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1270 /* be sure not to kick the creator out of the room! */
1271 lgetuser(&CC->usersupp,CC->curr_user);
1272 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1273 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1274 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1275 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1276 lputuser(&CC->usersupp,CC->curr_user);
1278 /* resume our happy day */
1279 return(qrbuf.QRflags);
1286 void cmd_cre8(char *args)
1289 char new_room_name[256];
1291 char new_room_pass[256];
1295 struct quickroom qrbuf;
1298 cre8_ok = extract_int(args,0);
1299 extract(new_room_name,args,1);
1300 new_room_name[ROOMNAMELEN-1] = 0;
1301 new_room_type = extract_int(args,2);
1302 extract(new_room_pass,args,3);
1303 new_room_pass[9] = 0;
1306 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1307 cprintf("%d Invalid room name.\n",ERROR);
1311 if (num_parms(args)>=5) {
1312 getfloor(&flbuf,extract_int(args,4));
1313 if ((flbuf.f_flags & F_INUSE) == 0) {
1314 cprintf("%d Invalid floor number.\n",
1315 ERROR+INVALID_FLOOR_OPERATION);
1319 new_room_floor = extract_int(args,4);
1323 if (!(CC->logged_in)) {
1324 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1328 if (CC->usersupp.axlevel<3) {
1329 cprintf("%d You need higher access to create rooms.\n",
1330 ERROR+HIGHER_ACCESS_REQUIRED);
1334 if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
1335 cprintf("%d Ok to create rooms.\n", OK);
1339 /* Check to make sure the requested room name doesn't already exist */
1340 if (getroom(&qrbuf, new_room_name)==0) {
1341 cprintf("%d '%s' already exists.\n",
1342 ERROR,qrbuf.QRname);
1346 if ((new_room_type < 0) || (new_room_type > 3)) {
1347 cprintf("%d Invalid room type.\n",ERROR);
1352 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1356 newflags = create_room(new_room_name,
1357 new_room_type,new_room_pass,new_room_floor);
1359 /* post a message in Aide> describing the new room */
1360 strncpy(aaa,new_room_name,255);
1361 strcat(aaa,"> created by ");
1362 strcat(aaa,CC->usersupp.fullname);
1363 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1364 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1365 if (newflags&QR_PASSWORDED) {
1366 strcat(aaa,"\n Password: ");
1367 strcat(aaa,new_room_pass);
1371 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1376 void cmd_einf(char *ok)
1377 { /* enter info file for current room */
1379 char infofilename[64];
1382 if (!(CC->logged_in)) {
1383 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1387 if (!is_room_aide()) {
1388 cprintf("%d Higher access required.\n",
1389 ERROR+HIGHER_ACCESS_REQUIRED);
1394 cprintf("%d Ok.\n",OK);
1398 cprintf("%d Send info...\n",SEND_LISTING);
1400 assoc_file_name(infofilename, &CC->quickroom, "info");
1402 fp=fopen(infofilename,"w");
1405 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1406 } while(strcmp(buf,"000"));
1409 /* now update the room index so people will see our new info */
1410 lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */
1411 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1412 lputroom(&CC->quickroom,CC->quickroom.QRname);
1417 * cmd_lflr() - List all known floors
1419 void cmd_lflr(void) {
1423 if (!(CC->logged_in)) {
1424 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1428 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1429 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1434 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1436 for (a=0; a<MAXFLOORS; ++a) {
1438 if (flbuf.f_flags & F_INUSE) {
1439 cprintf("%d|%s|%d\n",
1451 * create a new floor
1453 void cmd_cflr(char *argbuf)
1455 char new_floor_name[256];
1458 int free_slot = (-1);
1461 extract(new_floor_name,argbuf,0);
1462 cflr_ok = extract_int(argbuf,1);
1465 if (!(CC->logged_in)) {
1466 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1470 if (CC->usersupp.axlevel<6) {
1471 cprintf("%d You need higher access to create rooms.\n",
1472 ERROR+HIGHER_ACCESS_REQUIRED);
1476 for (a=0; a<MAXFLOORS; ++a) {
1479 /* note any free slots while we're scanning... */
1480 if ( ((flbuf.f_flags & F_INUSE)==0)
1481 && (free_slot < 0) ) free_slot = a;
1483 /* check to see if it already exists */
1484 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1485 && (flbuf.f_flags & F_INUSE) ) {
1486 cprintf("%d Floor '%s' already exists.\n",
1487 ERROR+ALREADY_EXISTS,
1495 cprintf("%d There is no space available for a new floor.\n",
1496 ERROR+INVALID_FLOOR_OPERATION);
1501 cprintf("%d ok to create...\n",OK);
1505 lgetfloor(&flbuf,free_slot);
1506 flbuf.f_flags = F_INUSE;
1507 flbuf.f_ref_count = 0;
1508 strncpy(flbuf.f_name,new_floor_name,255);
1509 lputfloor(&flbuf,free_slot);
1510 cprintf("%d %d\n",OK,free_slot);
1518 void cmd_kflr(char *argbuf)
1521 int floor_to_delete;
1525 floor_to_delete = extract_int(argbuf,0);
1526 kflr_ok = extract_int(argbuf,1);
1529 if (!(CC->logged_in)) {
1530 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1534 if (CC->usersupp.axlevel<6) {
1535 cprintf("%d You need higher access to delete floors.\n",
1536 ERROR+HIGHER_ACCESS_REQUIRED);
1540 lgetfloor(&flbuf,floor_to_delete);
1543 if ((flbuf.f_flags & F_INUSE) == 0) {
1544 cprintf("%d Floor %d not in use.\n",
1545 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1550 if (flbuf.f_ref_count != 0) {
1551 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1552 ERROR+INVALID_FLOOR_OPERATION,
1559 cprintf("%d Ok\n",OK);
1562 cprintf("%d Ok to delete...\n",OK);
1569 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1570 lputfloor(&flbuf,floor_to_delete);
1576 void cmd_eflr(char *argbuf)
1582 np = num_parms(argbuf);
1584 cprintf("%d Usage error.\n",ERROR);
1588 if (!(CC->logged_in)) {
1589 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1593 if (CC->usersupp.axlevel<6) {
1594 cprintf("%d You need higher access to edit floors.\n",
1595 ERROR+HIGHER_ACCESS_REQUIRED);
1599 floor_num = extract_int(argbuf,0);
1600 lgetfloor(&flbuf,floor_num);
1601 if ( (flbuf.f_flags & F_INUSE) == 0) {
1602 lputfloor(&flbuf,floor_num);
1603 cprintf("%d Floor %d is not in use.\n",
1604 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1607 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1608 lputfloor(&flbuf,floor_num);
1610 cprintf("%d Ok\n",OK);