15 #include "sysdep_decls.h"
19 #include "serv_chat.h"
20 #include "citserver.h"
25 * Generic routine for determining user access to rooms
27 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf) {
31 /* for internal programs, always do everything */
32 if (((CC->internal_pgm))&&(roombuf->QRflags & QR_INUSE)) {
33 return(UA_KNOWN | UA_GOTOALLOWED);
36 /* For mailbox rooms, only allow access to the owner */
37 if (roombuf->QRflags & QR_MAILBOX) {
38 if (userbuf->usernum != atol(roombuf->QRname)) {
43 /* Locate any applicable user/room relationships */
44 CtdlGetRelationship(&vbuf, userbuf, roombuf);
46 /* Force the properties of the Aide room */
47 if (!strcasecmp(roombuf->QRname, AIDEROOM)) {
48 if (userbuf->axlevel >= 6) {
49 retval = UA_KNOWN | UA_GOTOALLOWED;
57 /* For mailboxes, we skip all the access stuff (and we've
58 * already checked by this point that the mailbox belongs
61 if (roombuf->QRflags & QR_MAILBOX) {
62 retval = UA_KNOWN | UA_GOTOALLOWED;
66 /* If this is a public room, it's accessible... */
67 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
68 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
71 /* If this is a preferred users only room, check access level */
72 if (roombuf->QRflags & QR_PREFONLY) {
73 if (userbuf->axlevel < 5) {
74 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
78 /* For private rooms, check the generation number matchups */
79 if (roombuf->QRflags & QR_PRIVATE) {
81 /* An explicit match means the user belongs in this room */
82 if (vbuf.v_flags & V_ACCESS) {
83 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
85 /* Otherwise, check if this is a guess-name or passworded
86 * room. If it is, a goto may at least be attempted
88 else if ((roombuf->QRflags & QR_PRIVATE)
89 ||(roombuf->QRflags & QR_PASSWORDED)) {
90 retval = retval & ~UA_KNOWN;
91 retval = retval | UA_GOTOALLOWED;
95 /* Check to see if the user has forgotten this room */
96 if (vbuf.v_flags & V_FORGET) {
97 retval = retval & ~UA_KNOWN;
98 retval = retval | UA_ZAPPED;
101 /* If user is explicitly locked out of this room, deny everything */
102 if (vbuf.v_flags & V_LOCKOUT) {
103 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
106 /* Aides get access to everything */
107 if (userbuf->axlevel >= 6) {
108 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
109 retval = retval & ~UA_ZAPPED;
112 NEWMSG: /* By the way, we also check for the presence of new messages */
113 if ( (roombuf->QRhighest) > (vbuf.v_lastseen) ) {
114 retval = retval | UA_HASNEWMSGS;
121 * getroom() - retrieve room data from disk
123 int getroom(struct quickroom *qrbuf, char *room_name)
125 struct cdbdata *cdbqr;
126 char lowercase_name[ROOMNAMELEN];
129 for (a=0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
130 lowercase_name[a] = tolower(room_name[a]);
132 lowercase_name[a] = 0;
134 memset(qrbuf, 0, sizeof(struct quickroom));
135 cdbqr = cdb_fetch(CDB_QUICKROOM,
136 lowercase_name, strlen(lowercase_name));
138 memcpy(qrbuf, cdbqr->ptr,
139 ( (cdbqr->len > sizeof(struct quickroom)) ?
140 sizeof(struct quickroom) : cdbqr->len) );
143 /* Mailbox rooms are always on the lowest floor */
144 if (qrbuf->QRflags & QR_MAILBOX) {
156 * lgetroom() - same as getroom() but locks the record (if supported)
158 int lgetroom(struct quickroom *qrbuf, char *room_name)
160 begin_critical_section(S_QUICKROOM);
161 return(getroom(qrbuf, room_name));
166 * putroom() - store room data on disk
167 * (if the supplied buffer is NULL, delete the room record)
169 void putroom(struct quickroom *qrbuf, char *room_name)
171 char lowercase_name[ROOMNAMELEN];
174 for (a=0; a<=strlen(room_name); ++a) {
175 lowercase_name[a] = tolower(room_name[a]);
179 cdb_delete(CDB_QUICKROOM,
180 lowercase_name, strlen(lowercase_name));
183 time(&qrbuf->QRmtime);
184 cdb_store(CDB_QUICKROOM,
185 lowercase_name, strlen(lowercase_name),
186 qrbuf, sizeof(struct quickroom));
192 * lputroom() - same as putroom() but unlocks the record (if supported)
194 void lputroom(struct quickroom *qrbuf, char *room_name)
197 putroom(qrbuf, room_name);
198 end_critical_section(S_QUICKROOM);
202 /****************************************************************************/
205 * getfloor() - retrieve floor data from disk
207 void getfloor(struct floor *flbuf, int floor_num)
209 struct cdbdata *cdbfl;
211 memset(flbuf, 0, sizeof(struct floor));
212 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
214 memcpy(flbuf, cdbfl->ptr,
215 ( (cdbfl->len > sizeof(struct floor)) ?
216 sizeof(struct floor) : cdbfl->len) );
220 if (floor_num == 0) {
221 strcpy(flbuf->f_name, "Main Floor");
222 flbuf->f_flags = F_INUSE;
223 flbuf->f_ref_count = 3;
230 * lgetfloor() - same as getfloor() but locks the record (if supported)
232 void lgetfloor(struct floor *flbuf, int floor_num)
235 begin_critical_section(S_FLOORTAB);
236 getfloor(flbuf,floor_num);
241 * putfloor() - store floor data on disk
243 void putfloor(struct floor *flbuf, int floor_num)
245 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
246 flbuf, sizeof(struct floor));
251 * lputfloor() - same as putfloor() but unlocks the record (if supported)
253 void lputfloor(struct floor *flbuf, int floor_num)
256 putfloor(flbuf,floor_num);
257 end_critical_section(S_FLOORTAB);
263 * Traverse the room file...
265 void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) {
266 struct quickroom qrbuf;
267 struct cdbdata *cdbqr;
269 cdb_rewind(CDB_QUICKROOM);
271 while(cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
272 memset(&qrbuf, 0, sizeof(struct quickroom));
273 memcpy(&qrbuf, cdbqr->ptr,
274 ( (cdbqr->len > sizeof(struct quickroom)) ?
275 sizeof(struct quickroom) : cdbqr->len) );
277 if (qrbuf.QRflags & QR_INUSE) (*CallBack)(&qrbuf);
284 * get_msglist() - retrieve room message pointers
286 void get_msglist(struct quickroom *whichroom) {
287 struct cdbdata *cdbfr;
289 if (CC->msglist != NULL) {
295 cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
300 CC->msglist = malloc(cdbfr->len);
301 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
302 CC->num_msgs = cdbfr->len / sizeof(long);
308 * put_msglist() - retrieve room message pointers
310 void put_msglist(struct quickroom *whichroom) {
312 cdb_store(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long),
313 CC->msglist, CC->num_msgs * sizeof(long));
318 * delete_msglist() - delete room message pointers
319 * FIX - this really should check first to make sure there's actually a
320 * msglist to delete. As things stand now, calling this function on
321 * a room which has never been posted in will result in a message
322 * like "gdbm: illegal data" (no big deal, but could use fixing).
324 void delete_msglist(struct quickroom *whichroom) {
326 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
331 * Add a message number to a room's message list.
332 * So, why doesn't this function use the get_msglist() and put_msglist() stuff
333 * defined above? Because the room the message number is being written to
334 * may not be the current room (as is the case with cmd_move() for example).
336 void AddMessageToRoom(struct quickroom *whichroom, long newmsgid) {
337 struct cdbdata *cdbfr;
341 cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
347 msglist = malloc(cdbfr->len);
348 num_msgs = cdbfr->len / sizeof(long);
349 memcpy(msglist, cdbfr->ptr, cdbfr->len);
353 /* Now add the new message */
355 msglist = realloc(msglist,
356 (num_msgs * sizeof(long)) );
358 if (msglist == NULL) {
359 lprintf(3, "ERROR: can't realloc message list!\n");
362 msglist[num_msgs - 1] = newmsgid;
364 /* Sort the message list, so all the msgid's are in order */
365 num_msgs = sort_msglist(msglist, num_msgs);
367 /* Write it back to disk. */
368 cdb_store(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long),
369 msglist, num_msgs * sizeof(long));
371 /* And finally, free up the memory we used. */
377 * MessageFromList() - get a message number from the list currently in memory
379 long MessageFromList(int whichpos) {
381 /* Return zero if the position is invalid */
382 if (whichpos >= CC->num_msgs) return 0L;
384 return(CC->msglist[whichpos]);
388 * SetMessageInList() - set a message number in the list currently in memory
390 void SetMessageInList(int whichpos, long newmsgnum) {
392 /* Return zero if the position is invalid */
393 if (whichpos >= CC->num_msgs) return;
395 CC->msglist[whichpos] = newmsgnum;
401 * sort message pointers
402 * (returns new msg count)
404 int sort_msglist(long listptrs[], int oldcount)
411 if (numitems < 2) return(oldcount);
414 for (a=numitems-2; a>=0; --a) {
415 for (b=0; b<=a; ++b) {
416 if (listptrs[b] > (listptrs[b+1])) {
418 hold2 = listptrs[b+1];
420 listptrs[b+1] = hold1;
425 /* and yank any nulls */
426 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
427 memcpy(&listptrs[0], &listptrs[1],
428 (sizeof(long) * (CC->num_msgs - 1)) );
437 * Determine whether a given room is non-editable.
439 int is_noneditable(struct quickroom *qrbuf) {
441 /* Lobby> and Aide> are non-editable */
442 if (!strcasecmp(qrbuf->QRname, BASEROOM)) return(1);
443 else if (!strcasecmp(qrbuf->QRname, AIDEROOM)) return(1);
445 /* Mailbox rooms are also non-editable */
446 else if (qrbuf->QRflags & QR_MAILBOX) return(1);
448 /* Everything else is editable */
455 * Back-back-end for all room listing commands
457 void list_roomname(struct quickroom *qrbuf) {
458 char truncated_roomname[ROOMNAMELEN];
460 /* For mailbox rooms, chop off the owner prefix */
461 if (qrbuf->QRflags & QR_MAILBOX) {
462 strcpy(truncated_roomname, qrbuf->QRname);
463 strcpy(truncated_roomname, &truncated_roomname[11]);
464 cprintf("%s", truncated_roomname);
466 /* For all other rooms, just display the name in its entirety */
468 cprintf("%s", qrbuf->QRname);
471 /* ...and now the other parameters */
473 qrbuf->QRflags,qrbuf->QRfloor);
478 * cmd_lrms() - List all accessible rooms, known or forgotten
480 void cmd_lrms_backend(struct quickroom *qrbuf) {
481 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
482 & (UA_KNOWN | UA_ZAPPED)))
483 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
484 ||((CC->FloorBeingSearched)<0)) )
485 list_roomname(qrbuf);
488 void cmd_lrms(char *argbuf)
490 CC->FloorBeingSearched = (-1);
491 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
493 if (!(CC->logged_in)) {
494 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
498 if (getuser(&CC->usersupp,CC->curr_user)) {
499 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
503 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
505 ForEachRoom(cmd_lrms_backend);
512 * cmd_lkra() - List all known rooms
514 void cmd_lkra_backend(struct quickroom *qrbuf) {
515 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
517 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
518 ||((CC->FloorBeingSearched)<0)) )
519 list_roomname(qrbuf);
522 void cmd_lkra(char *argbuf)
524 CC->FloorBeingSearched = (-1);
525 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
527 if (!(CC->logged_in)) {
528 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
532 if (getuser(&CC->usersupp,CC->curr_user)) {
533 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
537 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
539 ForEachRoom(cmd_lkra_backend);
546 * cmd_lkrn() - List all known rooms with new messages
548 void cmd_lkrn_backend(struct quickroom *qrbuf) {
551 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
553 && (ra & UA_HASNEWMSGS)
554 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
555 ||((CC->FloorBeingSearched)<0)) )
556 list_roomname(qrbuf);
559 void cmd_lkrn(char *argbuf)
561 CC->FloorBeingSearched = (-1);
562 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
564 if (!(CC->logged_in)) {
565 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
569 if (getuser(&CC->usersupp,CC->curr_user)) {
570 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
574 cprintf("%d Rooms w/ new msgs:\n",LISTING_FOLLOWS);
576 ForEachRoom(cmd_lkrn_backend);
583 * cmd_lkro() - List all known rooms
585 void cmd_lkro_backend(struct quickroom *qrbuf) {
588 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
590 && ((ra & UA_HASNEWMSGS)==0)
591 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
592 ||((CC->FloorBeingSearched)<0)) )
593 list_roomname(qrbuf);
596 void cmd_lkro(char *argbuf)
598 CC->FloorBeingSearched = (-1);
599 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
601 if (!(CC->logged_in)) {
602 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
606 if (getuser(&CC->usersupp,CC->curr_user)) {
607 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
611 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
613 ForEachRoom(cmd_lkro_backend);
620 * cmd_lzrm() - List all forgotten rooms
622 void cmd_lzrm_backend(struct quickroom *qrbuf) {
625 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
626 if ( (ra & UA_GOTOALLOWED)
628 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
629 ||((CC->FloorBeingSearched)<0)) )
630 list_roomname(qrbuf);
633 void cmd_lzrm(char *argbuf)
635 CC->FloorBeingSearched = (-1);
636 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
638 if (!(CC->logged_in)) {
639 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
643 if (getuser(&CC->usersupp,CC->curr_user)) {
644 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
648 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
650 ForEachRoom(cmd_lzrm_backend);
656 void usergoto(char *where, int display_result)
659 int new_messages = 0;
660 int total_messages = 0;
664 int newmailcount = 0;
666 char truncated_roomname[ROOMNAMELEN];
668 strcpy(CC->quickroom.QRname, where);
669 getroom(&CC->quickroom, where);
670 lgetuser(&CC->usersupp,CC->curr_user);
671 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
673 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
674 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
676 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
677 lputuser(&CC->usersupp,CC->curr_user);
679 /* check for new mail */
680 newmailcount = NewMailCount();
682 /* set info to 1 if the user needs to read the room's info file */
683 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
686 get_msglist(&CC->quickroom);
687 for (a=0; a<CC->num_msgs; ++a) {
688 if (MessageFromList(a)>0L) {
690 if (MessageFromList(a) > vbuf.v_lastseen) {
696 if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1;
699 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
700 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
703 strcpy(truncated_roomname, CC->quickroom.QRname);
704 if (CC->quickroom.QRflags & QR_MAILBOX) {
705 strcpy(truncated_roomname, &truncated_roomname[11]);
708 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
711 new_messages, total_messages,
712 info,CC->quickroom.QRflags,
713 CC->quickroom.QRhighest,
715 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
717 set_wtmpsupp_to_current_room();
722 * cmd_goto() - goto a new room
724 void cmd_goto(char *gargs)
726 struct quickroom QRscratch;
730 char augmented_roomname[256];
734 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
735 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
739 extract(towhere,gargs,0);
740 extract(password,gargs,1);
742 getuser(&CC->usersupp, CC->curr_user);
744 if (!strcasecmp(towhere, "_BASEROOM_"))
745 strcpy(towhere, BASEROOM);
747 if (!strcasecmp(towhere, "_MAIL_"))
748 strcpy(towhere, MAILROOM);
750 if (!strcasecmp(towhere, "_BITBUCKET_"))
751 strcpy(towhere, config.c_twitroom);
754 /* First try a regular match */
755 c = getroom(&QRscratch, towhere);
757 /* Then try a mailbox name match */
759 MailboxName(augmented_roomname, &CC->usersupp, towhere);
760 c = getroom(&QRscratch, augmented_roomname);
761 if (c == 0) strcpy(towhere, augmented_roomname);
764 /* And if the room was found... */
767 /* let internal programs go directly to any room */
768 if (CC->internal_pgm) {
769 usergoto(towhere, 1);
773 /* See if there is an existing user/room relationship */
774 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
776 /* normal clients have to pass through security */
777 if (ra & UA_GOTOALLOWED) ok = 1;
780 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
781 ((ra & UA_KNOWN) == 0) &&
782 (strcasecmp(QRscratch.QRpasswd,password))
784 cprintf("%d wrong or missing passwd\n",
785 ERROR+PASSWORD_REQUIRED);
789 usergoto(towhere, 1);
795 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
799 void cmd_whok(void) {
800 struct usersupp temp;
801 struct cdbdata *cdbus;
803 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
804 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
807 getuser(&CC->usersupp,CC->curr_user);
809 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
810 cprintf("%d Higher access required.\n",
811 ERROR+HIGHER_ACCESS_REQUIRED);
815 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
816 cdb_rewind(CDB_USERSUPP);
817 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
818 memset(&temp, 0, sizeof(struct usersupp));
819 memcpy(&temp, cdbus->ptr, cdbus->len);
822 if ( (CC->quickroom.QRflags & QR_INUSE)
823 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
824 ) cprintf("%s\n",temp.fullname);
831 * RDIR command for room directory
833 void cmd_rdir(void) {
840 if (!(CC->logged_in)) {
841 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
845 getroom(&CC->quickroom, CC->quickroom.QRname);
846 getuser(&CC->usersupp, CC->curr_user);
848 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
849 cprintf("%d not here.\n",ERROR+NOT_HERE);
853 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
854 && (CC->usersupp.axlevel<6)
855 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
856 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
860 cprintf("%d %s|%s/files/%s\n",
861 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
863 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
864 BBSDIR,CC->quickroom.QRdirname,CC->temp);
867 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
869 if (fd==NULL) fd=fopen("/dev/null","r");
871 ls = fopen(CC->temp,"r");
872 while (fgets(flnm,256,ls)!=NULL) {
873 flnm[strlen(flnm)-1]=0;
874 if (strcasecmp(flnm,"filedir")) {
875 sprintf(buf,"%s/files/%s/%s",
876 BBSDIR,CC->quickroom.QRdirname,flnm);
880 while ((fgets(buf,256,fd)!=NULL)
881 &&(strlen(comment)==0)) {
882 buf[strlen(buf)-1] = 0;
883 if ((!strncasecmp(buf,flnm,strlen(flnm)))
884 && (buf[strlen(flnm)]==' '))
886 &buf[strlen(flnm)+1],255);
888 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
899 * get room parameters (aide or room aide command)
901 void cmd_getr(void) {
902 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
903 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
907 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
908 cprintf("%d Higher access required.\n",
909 ERROR+HIGHER_ACCESS_REQUIRED);
913 if (is_noneditable(&CC->quickroom)) {
914 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
918 getroom(&CC->quickroom, CC->quickroom.QRname);
919 cprintf("%d%c%s|%s|%s|%d|%d\n",
921 CC->quickroom.QRname,
922 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
923 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
924 CC->quickroom.QRflags,
925 (int)CC->quickroom.QRfloor);
930 * set room parameters (aide or room aide command)
932 void cmd_setr(char *args) {
935 char old_name[ROOMNAMELEN];
938 if (!(CC->logged_in)) {
939 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
943 if (!is_room_aide()) {
944 cprintf("%d Higher access required.\n",
945 ERROR+HIGHER_ACCESS_REQUIRED);
949 if (is_noneditable(&CC->quickroom)) {
950 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
954 if (num_parms(args)>=6) {
955 getfloor(&flbuf,extract_int(args,5));
956 if ((flbuf.f_flags & F_INUSE) == 0) {
957 cprintf("%d Invalid floor number.\n",
958 ERROR+INVALID_FLOOR_OPERATION);
963 lgetroom(&CC->quickroom, CC->quickroom.QRname);
964 strcpy(old_name, CC->quickroom.QRname);
965 extract(buf,args,0); buf[ROOMNAMELEN]=0;
966 strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
967 extract(buf,args,1); buf[10]=0;
968 strncpy(CC->quickroom.QRpasswd,buf,9);
969 extract(buf,args,2); buf[15]=0;
970 strncpy(CC->quickroom.QRdirname,buf,19);
971 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
973 /* Clean up a client boo-boo: if the client set the room to
974 * guess-name or passworded, ensure that the private flag is
977 if ((CC->quickroom.QRflags & QR_GUESSNAME)
978 ||(CC->quickroom.QRflags & QR_PASSWORDED))
979 CC->quickroom.QRflags |= QR_PRIVATE;
981 /* Kick everyone out if the client requested it (by changing the
982 * room's generation number)
984 if (extract_int(args,4)) {
985 time(&CC->quickroom.QRgen);
988 old_floor = CC->quickroom.QRfloor;
989 if (num_parms(args)>=6) {
990 CC->quickroom.QRfloor = extract_int(args,5);
993 /* Write the room record back to disk */
994 lputroom(&CC->quickroom, CC->quickroom.QRname);
996 /* If the room name changed, then there are now two room records,
997 * so we have to delete the old one.
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) {
1103 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1107 * retrieve info file for this room
1109 void cmd_rinf(void) {
1114 assoc_file_name(filename, &CC->quickroom, "info");
1115 info_fp = fopen(filename,"r");
1117 if (info_fp==NULL) {
1118 cprintf("%d No info file.\n",ERROR);
1122 cprintf("%d Info:\n",LISTING_FOLLOWS);
1123 while (fgets(buf, 256, info_fp) != NULL) {
1124 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1125 cprintf("%s\n", buf);
1132 * Back end processing to delete a room and everything associated with it
1134 void delete_room(struct quickroom *qrbuf) {
1140 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1142 /* Delete the info file */
1143 assoc_file_name(aaa, qrbuf, "info");
1146 /* Delete the image file */
1147 assoc_file_name(aaa, qrbuf, "images");
1150 /* first flag the room record as not in use */
1151 lgetroom(qrbuf, qrbuf->QRname);
1154 /* then delete the messages in the room */
1156 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1157 MsgToDelete = MessageFromList(a);
1158 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1164 delete_msglist(qrbuf);
1165 lputroom(qrbuf, qrbuf->QRname);
1167 /* then decrement the reference count for the floor */
1168 lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
1169 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1170 lputfloor(&flbuf,(int)(qrbuf->QRfloor));
1172 /* Delete the room record from the database! */
1173 putroom(NULL, qrbuf->QRname);
1178 * aide command: kill the current room
1180 void cmd_kill(char *argbuf) {
1182 char deleted_room_name[ROOMNAMELEN];
1185 kill_ok = extract_int(argbuf,0);
1187 if (!(CC->logged_in)) {
1188 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1192 if (!is_room_aide()) {
1193 cprintf("%d Higher access required.\n",
1194 ERROR+HIGHER_ACCESS_REQUIRED);
1198 if (is_noneditable(&CC->quickroom)) {
1199 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1204 strcpy(deleted_room_name, CC->quickroom.QRname);
1205 delete_room(&CC->quickroom); /* Do the dirty work */
1206 usergoto(BASEROOM, 0); /* Return to the Lobby */
1208 /* tell the world what we did */
1209 sprintf(aaa,"%s> killed by %s",
1210 deleted_room_name, CC->curr_user);
1212 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1215 cprintf("%d ok to delete.\n",OK);
1221 * Internal code to create a new room (returns room flags)
1223 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1225 unsigned create_room(char *new_room_name,
1227 char *new_room_pass,
1228 int new_room_floor) {
1230 struct quickroom qrbuf;
1234 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1236 memset(&qrbuf, 0, sizeof(struct quickroom));
1237 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1238 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1239 qrbuf.QRflags = QR_INUSE;
1240 qrbuf.QRnumber = get_new_room_number();
1241 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1242 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1243 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1244 if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
1246 /* If the room is private, and the system administrator has elected
1247 * to automatically grant room aide privileges, do so now; otherwise,
1248 * set the room aide to undefined.
1250 if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) {
1251 qrbuf.QRroomaide=CC->usersupp.usernum;
1254 qrbuf.QRroomaide = (-1L);
1257 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1258 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1259 qrbuf.QRfloor = new_room_floor;
1261 /* save what we just did... */
1262 putroom(&qrbuf, qrbuf.QRname);
1264 /* bump the reference count on whatever floor the room is on */
1265 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1266 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1267 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1269 /* be sure not to kick the creator out of the room! */
1270 lgetuser(&CC->usersupp,CC->curr_user);
1271 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1272 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1273 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1274 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1275 lputuser(&CC->usersupp,CC->curr_user);
1277 /* resume our happy day */
1278 return(qrbuf.QRflags);
1285 void cmd_cre8(char *args)
1288 char new_room_name[256];
1290 char new_room_pass[256];
1294 struct quickroom qrbuf;
1297 cre8_ok = extract_int(args,0);
1298 extract(new_room_name,args,1);
1299 new_room_name[ROOMNAMELEN-1] = 0;
1300 new_room_type = extract_int(args,2);
1301 extract(new_room_pass,args,3);
1302 new_room_pass[9] = 0;
1305 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1306 cprintf("%d Invalid room name.\n",ERROR);
1310 if (num_parms(args)>=5) {
1311 getfloor(&flbuf,extract_int(args,4));
1312 if ((flbuf.f_flags & F_INUSE) == 0) {
1313 cprintf("%d Invalid floor number.\n",
1314 ERROR+INVALID_FLOOR_OPERATION);
1318 new_room_floor = extract_int(args,4);
1322 if (!(CC->logged_in)) {
1323 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1327 if (CC->usersupp.axlevel<3) {
1328 cprintf("%d You need higher access to create rooms.\n",
1329 ERROR+HIGHER_ACCESS_REQUIRED);
1333 if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
1334 cprintf("%d Ok to create rooms.\n", OK);
1338 /* Check to make sure the requested room name doesn't already exist */
1339 if (getroom(&qrbuf, new_room_name)==0) {
1340 cprintf("%d '%s' already exists.\n",
1341 ERROR,qrbuf.QRname);
1345 if ((new_room_type < 0) || (new_room_type > 3)) {
1346 cprintf("%d Invalid room type.\n",ERROR);
1351 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1355 newflags = create_room(new_room_name,
1356 new_room_type,new_room_pass,new_room_floor);
1358 /* post a message in Aide> describing the new room */
1359 strncpy(aaa,new_room_name,255);
1360 strcat(aaa,"> created by ");
1361 strcat(aaa,CC->usersupp.fullname);
1362 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1363 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1364 if (newflags&QR_PASSWORDED) {
1365 strcat(aaa,"\n Password: ");
1366 strcat(aaa,new_room_pass);
1370 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1375 void cmd_einf(char *ok)
1376 { /* enter info file for current room */
1378 char infofilename[256];
1381 if (!(CC->logged_in)) {
1382 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1386 if (!is_room_aide()) {
1387 cprintf("%d Higher access required.\n",
1388 ERROR+HIGHER_ACCESS_REQUIRED);
1393 cprintf("%d Ok.\n",OK);
1397 assoc_file_name(infofilename, &CC->quickroom, "info");
1398 lprintf(9, "opening\n");
1399 fp = fopen(infofilename, "w");
1400 lprintf(9, "checking\n");
1402 cprintf("%d Cannot open %s: %s\n",
1403 ERROR+INTERNAL_ERROR, infofilename, strerror(errno));
1407 cprintf("%d Send info...\n", SEND_LISTING);
1411 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1412 } while(strcmp(buf,"000"));
1415 /* now update the room index so people will see our new info */
1416 lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */
1417 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1418 lputroom(&CC->quickroom,CC->quickroom.QRname);
1423 * cmd_lflr() - List all known floors
1425 void cmd_lflr(void) {
1429 if (!(CC->logged_in)) {
1430 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1434 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1435 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1440 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1442 for (a=0; a<MAXFLOORS; ++a) {
1444 if (flbuf.f_flags & F_INUSE) {
1445 cprintf("%d|%s|%d\n",
1457 * create a new floor
1459 void cmd_cflr(char *argbuf)
1461 char new_floor_name[256];
1464 int free_slot = (-1);
1467 extract(new_floor_name,argbuf,0);
1468 cflr_ok = extract_int(argbuf,1);
1471 if (!(CC->logged_in)) {
1472 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1476 if (CC->usersupp.axlevel<6) {
1477 cprintf("%d You need higher access to create rooms.\n",
1478 ERROR+HIGHER_ACCESS_REQUIRED);
1482 for (a=0; a<MAXFLOORS; ++a) {
1485 /* note any free slots while we're scanning... */
1486 if ( ((flbuf.f_flags & F_INUSE)==0)
1487 && (free_slot < 0) ) free_slot = a;
1489 /* check to see if it already exists */
1490 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1491 && (flbuf.f_flags & F_INUSE) ) {
1492 cprintf("%d Floor '%s' already exists.\n",
1493 ERROR+ALREADY_EXISTS,
1501 cprintf("%d There is no space available for a new floor.\n",
1502 ERROR+INVALID_FLOOR_OPERATION);
1507 cprintf("%d ok to create...\n",OK);
1511 lgetfloor(&flbuf,free_slot);
1512 flbuf.f_flags = F_INUSE;
1513 flbuf.f_ref_count = 0;
1514 strncpy(flbuf.f_name,new_floor_name,255);
1515 lputfloor(&flbuf,free_slot);
1516 cprintf("%d %d\n",OK,free_slot);
1524 void cmd_kflr(char *argbuf)
1527 int floor_to_delete;
1531 floor_to_delete = extract_int(argbuf,0);
1532 kflr_ok = extract_int(argbuf,1);
1535 if (!(CC->logged_in)) {
1536 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1540 if (CC->usersupp.axlevel<6) {
1541 cprintf("%d You need higher access to delete floors.\n",
1542 ERROR+HIGHER_ACCESS_REQUIRED);
1546 lgetfloor(&flbuf,floor_to_delete);
1549 if ((flbuf.f_flags & F_INUSE) == 0) {
1550 cprintf("%d Floor %d not in use.\n",
1551 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1556 if (flbuf.f_ref_count != 0) {
1557 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1558 ERROR+INVALID_FLOOR_OPERATION,
1565 cprintf("%d Ok\n",OK);
1568 cprintf("%d Ok to delete...\n",OK);
1575 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1576 lputfloor(&flbuf,floor_to_delete);
1582 void cmd_eflr(char *argbuf)
1588 np = num_parms(argbuf);
1590 cprintf("%d Usage error.\n",ERROR);
1594 if (!(CC->logged_in)) {
1595 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1599 if (CC->usersupp.axlevel<6) {
1600 cprintf("%d You need higher access to edit floors.\n",
1601 ERROR+HIGHER_ACCESS_REQUIRED);
1605 floor_num = extract_int(argbuf,0);
1606 lgetfloor(&flbuf,floor_num);
1607 if ( (flbuf.f_flags & F_INUSE) == 0) {
1608 lputfloor(&flbuf,floor_num);
1609 cprintf("%d Floor %d is not in use.\n",
1610 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1613 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1614 lputfloor(&flbuf,floor_num);
1616 cprintf("%d Ok\n",OK);