15 #include "sysdep_decls.h"
19 #include "serv_chat.h"
20 #include "citserver.h"
23 * Generic routine for determining user access to rooms
25 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf) {
29 /* for internal programs, always do everything */
30 if (((CC->internal_pgm))&&(roombuf->QRflags & QR_INUSE)) {
31 return(UA_KNOWN | UA_GOTOALLOWED);
34 /* For mailbox rooms, only allow access to the owner */
35 if (roombuf->QRflags & QR_MAILBOX) {
36 if (userbuf->usernum != atol(roombuf->QRname)) {
41 /* Locate any applicable user/room relationships */
42 CtdlGetRelationship(&vbuf, userbuf, roombuf);
44 /* Force the properties of the Aide room */
45 if (!strcasecmp(roombuf->QRname, AIDEROOM)) {
46 lprintf(9, "Room <%s> is special!\n", roombuf->QRname);
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) );
149 * lgetroom() - same as getroom() but locks the record (if supported)
151 int lgetroom(struct quickroom *qrbuf, char *room_name)
153 begin_critical_section(S_QUICKROOM);
154 return(getroom(qrbuf, room_name));
159 * putroom() - store room data on disk
160 * (if the supplied buffer is NULL, delete the room record)
162 void putroom(struct quickroom *qrbuf, char *room_name)
164 char lowercase_name[ROOMNAMELEN];
167 for (a=0; a<=strlen(room_name); ++a) {
168 lowercase_name[a] = tolower(room_name[a]);
172 cdb_delete(CDB_QUICKROOM,
173 lowercase_name, strlen(lowercase_name));
176 time(&qrbuf->QRmtime);
177 cdb_store(CDB_QUICKROOM,
178 lowercase_name, strlen(lowercase_name),
179 qrbuf, sizeof(struct quickroom));
185 * lputroom() - same as putroom() but unlocks the record (if supported)
187 void lputroom(struct quickroom *qrbuf, char *room_name)
190 putroom(qrbuf, room_name);
191 end_critical_section(S_QUICKROOM);
195 /****************************************************************************/
198 * getfloor() - retrieve floor data from disk
200 void getfloor(struct floor *flbuf, int floor_num)
202 struct cdbdata *cdbfl;
204 memset(flbuf, 0, sizeof(struct floor));
205 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
207 memcpy(flbuf, cdbfl->ptr,
208 ( (cdbfl->len > sizeof(struct floor)) ?
209 sizeof(struct floor) : cdbfl->len) );
213 if (floor_num == 0) {
214 strcpy(flbuf->f_name, "Main Floor");
215 flbuf->f_flags = F_INUSE;
216 flbuf->f_ref_count = 3;
223 * lgetfloor() - same as getfloor() but locks the record (if supported)
225 void lgetfloor(struct floor *flbuf, int floor_num)
228 begin_critical_section(S_FLOORTAB);
229 getfloor(flbuf,floor_num);
234 * putfloor() - store floor data on disk
236 void putfloor(struct floor *flbuf, int floor_num)
238 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
239 flbuf, sizeof(struct floor));
244 * lputfloor() - same as putfloor() but unlocks the record (if supported)
246 void lputfloor(struct floor *flbuf, int floor_num)
249 putfloor(flbuf,floor_num);
250 end_critical_section(S_FLOORTAB);
256 * Traverse the room file...
258 void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) {
259 struct quickroom qrbuf;
260 struct cdbdata *cdbqr;
262 cdb_rewind(CDB_QUICKROOM);
264 while(cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
265 memset(&qrbuf, 0, sizeof(struct quickroom));
266 memcpy(&qrbuf, cdbqr->ptr,
267 ( (cdbqr->len > sizeof(struct quickroom)) ?
268 sizeof(struct quickroom) : cdbqr->len) );
270 if (qrbuf.QRflags & QR_INUSE) (*CallBack)(&qrbuf);
277 * Create a database key for storage of message lists
279 void msglist_key(char *dbkey, struct quickroom *whichroom) {
282 sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
283 for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
287 * get_msglist() - retrieve room message pointers
289 void get_msglist(struct quickroom *whichroom) {
290 struct cdbdata *cdbfr;
293 msglist_key(dbkey, whichroom);
295 if (CC->msglist != NULL) {
301 cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey));
306 CC->msglist = malloc(cdbfr->len);
307 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
308 CC->num_msgs = cdbfr->len / sizeof(long);
314 * put_msglist() - retrieve room message pointers
316 void put_msglist(struct quickroom *whichroom) {
319 msglist_key(dbkey, whichroom);
320 cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey),
321 CC->msglist, CC->num_msgs * sizeof(long));
326 * delete_msglist() - delete room message pointers
328 void delete_msglist(struct quickroom *whichroom) {
331 msglist_key(dbkey, whichroom);
332 cdb_delete(CDB_MSGLISTS, dbkey, strlen(dbkey));
337 * Add a message number to a room's message list.
338 * So, why doesn't this function use the get_msglist() and put_msglist() stuff
339 * defined above? Because the room the message number is being written to
340 * may not be the current room (as is the case with cmd_move() for example).
342 void AddMessageToRoom(struct quickroom *whichroom, long newmsgid) {
344 struct cdbdata *cdbfr;
348 msglist_key(dbkey, whichroom);
349 cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey));
355 msglist = malloc(cdbfr->len);
356 num_msgs = cdbfr->len / sizeof(long);
357 memcpy(msglist, cdbfr->ptr, cdbfr->len);
361 /* Now add the new message */
363 msglist = realloc(msglist,
364 (num_msgs * sizeof(long)) );
366 if (msglist == NULL) {
367 lprintf(3, "ERROR: can't realloc message list!\n");
370 msglist[num_msgs - 1] = newmsgid;
372 /* Write it back to disk. */
373 cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey),
374 msglist, num_msgs * sizeof(long));
376 /* And finally, free up the memory we used. */
382 * MessageFromList() - get a message number from the list currently in memory
384 long MessageFromList(int whichpos) {
386 /* Return zero if the position is invalid */
387 if (whichpos >= CC->num_msgs) return 0L;
389 return(CC->msglist[whichpos]);
393 * SetMessageInList() - set a message number in the list currently in memory
395 void SetMessageInList(int whichpos, long newmsgnum) {
397 /* Return zero if the position is invalid */
398 if (whichpos >= CC->num_msgs) return;
400 CC->msglist[whichpos] = newmsgnum;
406 * sort message pointers
407 * (returns new msg count)
409 int sort_msglist(long listptrs[], int oldcount)
416 if (numitems < 2) return(oldcount);
419 for (a=numitems-2; a>=0; --a) {
420 for (b=0; b<=a; ++b) {
421 if (listptrs[b] > (listptrs[b+1])) {
423 hold2 = listptrs[b+1];
425 listptrs[b+1] = hold1;
430 /* and yank any nulls */
431 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
432 memcpy(&listptrs[0], &listptrs[1],
433 (sizeof(long) * (CC->num_msgs - 1)) );
442 * Determine whether a given room is one of the base non-editable rooms
444 int is_noneditable(struct quickroom *qrbuf) {
445 if (!strcasecmp(qrbuf->QRname, BASEROOM)) return(1);
446 else if (!strcasecmp(qrbuf->QRname, AIDEROOM)) return(1);
453 * Back-back-end for all room listing commands
455 void list_roomname(struct quickroom *qrbuf) {
456 char truncated_roomname[ROOMNAMELEN];
458 /* For mailbox rooms, chop off the owner prefix */
459 if (qrbuf->QRflags & QR_MAILBOX) {
460 strcpy(truncated_roomname, qrbuf->QRname);
461 strcpy(truncated_roomname, &truncated_roomname[11]);
462 cprintf("%s", truncated_roomname);
464 /* For all other rooms, just display the name in its entirety */
466 cprintf("%s", qrbuf->QRname);
469 /* ...and now the other parameters */
471 qrbuf->QRflags,qrbuf->QRfloor);
476 * cmd_lrms() - List all accessible rooms, known or forgotten
478 void cmd_lrms_backend(struct quickroom *qrbuf) {
479 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
480 & (UA_KNOWN | UA_ZAPPED)))
481 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
482 ||((CC->FloorBeingSearched)<0)) )
483 list_roomname(qrbuf);
486 void cmd_lrms(char *argbuf)
488 CC->FloorBeingSearched = (-1);
489 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
491 if (!(CC->logged_in)) {
492 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
496 if (getuser(&CC->usersupp,CC->curr_user)) {
497 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
501 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
503 ForEachRoom(cmd_lrms_backend);
510 * cmd_lkra() - List all known rooms
512 void cmd_lkra_backend(struct quickroom *qrbuf) {
513 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
515 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
516 ||((CC->FloorBeingSearched)<0)) )
517 list_roomname(qrbuf);
520 void cmd_lkra(char *argbuf)
522 CC->FloorBeingSearched = (-1);
523 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
525 if (!(CC->logged_in)) {
526 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
530 if (getuser(&CC->usersupp,CC->curr_user)) {
531 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
535 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
537 ForEachRoom(cmd_lkra_backend);
544 * cmd_lkrn() - List all known rooms with new messages
546 void cmd_lkrn_backend(struct quickroom *qrbuf) {
549 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
551 && (ra & UA_HASNEWMSGS)
552 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
553 ||((CC->FloorBeingSearched)<0)) )
554 list_roomname(qrbuf);
557 void cmd_lkrn(char *argbuf)
559 CC->FloorBeingSearched = (-1);
560 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
562 if (!(CC->logged_in)) {
563 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
567 if (getuser(&CC->usersupp,CC->curr_user)) {
568 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
572 cprintf("%d Rooms w/ new msgs:\n",LISTING_FOLLOWS);
574 ForEachRoom(cmd_lkrn_backend);
581 * cmd_lkro() - List all known rooms
583 void cmd_lkro_backend(struct quickroom *qrbuf) {
586 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
588 && ((ra & UA_HASNEWMSGS)==0)
589 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
590 ||((CC->FloorBeingSearched)<0)) )
591 list_roomname(qrbuf);
594 void cmd_lkro(char *argbuf)
596 CC->FloorBeingSearched = (-1);
597 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
599 if (!(CC->logged_in)) {
600 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
604 if (getuser(&CC->usersupp,CC->curr_user)) {
605 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
609 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
611 ForEachRoom(cmd_lkro_backend);
618 * cmd_lzrm() - List all forgotten rooms
620 void cmd_lzrm_backend(struct quickroom *qrbuf) {
623 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
624 if ( (ra & UA_GOTOALLOWED)
626 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
627 ||((CC->FloorBeingSearched)<0)) )
628 list_roomname(qrbuf);
631 void cmd_lzrm(char *argbuf)
633 CC->FloorBeingSearched = (-1);
634 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
636 if (!(CC->logged_in)) {
637 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
641 if (getuser(&CC->usersupp,CC->curr_user)) {
642 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
646 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
648 ForEachRoom(cmd_lzrm_backend);
654 void usergoto(char *where, int display_result)
657 int new_messages = 0;
658 int total_messages = 0;
662 int newmailcount = 0;
664 char truncated_roomname[ROOMNAMELEN];
666 strcpy(CC->quickroom.QRname, where);
667 getroom(&CC->quickroom, where);
668 lgetuser(&CC->usersupp,CC->curr_user);
669 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
671 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
672 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
674 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
675 lputuser(&CC->usersupp,CC->curr_user);
677 /* check for new mail */
678 newmailcount = NewMailCount();
680 /* set info to 1 if the user needs to read the room's info file */
681 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
684 get_msglist(&CC->quickroom);
685 for (a=0; a<CC->num_msgs; ++a) {
686 if (MessageFromList(a)>0L) {
688 if (MessageFromList(a) > vbuf.v_lastseen) {
694 if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1;
697 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
698 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
701 strcpy(truncated_roomname, CC->quickroom.QRname);
702 if (CC->quickroom.QRflags & QR_MAILBOX) {
703 strcpy(truncated_roomname, &truncated_roomname[11]);
706 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
709 new_messages, total_messages,
710 info,CC->quickroom.QRflags,
711 CC->quickroom.QRhighest,
713 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
715 if (CC->quickroom.QRflags & QR_PRIVATE) {
716 set_wtmpsupp("<private room>");
719 set_wtmpsupp(CC->quickroom.QRname);
725 * cmd_goto() - goto a new room
727 void cmd_goto(char *gargs)
729 struct quickroom QRscratch;
733 char augmented_roomname[256];
737 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
738 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
742 extract(towhere,gargs,0);
743 extract(password,gargs,1);
745 getuser(&CC->usersupp, CC->curr_user);
747 if (!strcasecmp(towhere, "_BASEROOM_"))
748 strcpy(towhere, BASEROOM);
750 if (!strcasecmp(towhere, "_MAIL_"))
751 strcpy(towhere, MAILROOM);
753 if (!strcasecmp(towhere, "_BITBUCKET_"))
754 strcpy(towhere, config.c_twitroom);
757 /* First try a regular match */
758 c = getroom(&QRscratch, towhere);
760 /* Then try a mailbox name match */
762 MailboxName(augmented_roomname, &CC->usersupp, towhere);
763 c = getroom(&QRscratch, augmented_roomname);
764 if (c == 0) strcpy(towhere, augmented_roomname);
767 /* And if the room was found... */
770 /* let internal programs go directly to any room */
771 if (CC->internal_pgm) {
772 usergoto(towhere, 1);
776 /* See if there is an existing user/room relationship */
777 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
779 /* normal clients have to pass through security */
780 if (ra & UA_GOTOALLOWED) ok = 1;
783 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
784 ((ra & UA_KNOWN) == 0) &&
785 (strcasecmp(QRscratch.QRpasswd,password))
787 cprintf("%d wrong or missing passwd\n",
788 ERROR+PASSWORD_REQUIRED);
792 usergoto(towhere, 1);
798 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
802 void cmd_whok(void) {
803 struct usersupp temp;
804 struct cdbdata *cdbus;
806 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
807 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
810 getuser(&CC->usersupp,CC->curr_user);
812 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
813 cprintf("%d Higher access required.\n",
814 ERROR+HIGHER_ACCESS_REQUIRED);
818 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
819 cdb_rewind(CDB_USERSUPP);
820 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
821 memset(&temp, 0, sizeof(struct usersupp));
822 memcpy(&temp, cdbus->ptr, cdbus->len);
825 if ( (CC->quickroom.QRflags & QR_INUSE)
826 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
827 ) cprintf("%s\n",temp.fullname);
834 * RDIR command for room directory
836 void cmd_rdir(void) {
843 if (!(CC->logged_in)) {
844 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
848 getroom(&CC->quickroom, CC->quickroom.QRname);
849 getuser(&CC->usersupp, CC->curr_user);
851 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
852 cprintf("%d not here.\n",ERROR+NOT_HERE);
856 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
857 && (CC->usersupp.axlevel<6)
858 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
859 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
863 cprintf("%d %s|%s/files/%s\n",
864 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
866 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
867 BBSDIR,CC->quickroom.QRdirname,CC->temp);
870 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
872 if (fd==NULL) fd=fopen("/dev/null","r");
874 ls = fopen(CC->temp,"r");
875 while (fgets(flnm,256,ls)!=NULL) {
876 flnm[strlen(flnm)-1]=0;
877 if (strcasecmp(flnm,"filedir")) {
878 sprintf(buf,"%s/files/%s/%s",
879 BBSDIR,CC->quickroom.QRdirname,flnm);
883 while ((fgets(buf,256,fd)!=NULL)
884 &&(strlen(comment)==0)) {
885 buf[strlen(buf)-1] = 0;
886 if ((!strncasecmp(buf,flnm,strlen(flnm)))
887 && (buf[strlen(flnm)]==' '))
889 &buf[strlen(flnm)+1],255);
891 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
902 * get room parameters (aide or room aide command)
904 void cmd_getr(void) {
905 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
906 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
910 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
911 cprintf("%d Higher access required.\n",
912 ERROR+HIGHER_ACCESS_REQUIRED);
916 if (is_noneditable(&CC->quickroom)) {
917 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
921 getroom(&CC->quickroom, CC->quickroom.QRname);
922 cprintf("%d%c%s|%s|%s|%d|%d\n",
924 CC->quickroom.QRname,
925 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
926 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
927 CC->quickroom.QRflags,
928 (int)CC->quickroom.QRfloor);
933 * set room parameters (aide or room aide command)
935 void cmd_setr(char *args) {
940 if (!(CC->logged_in)) {
941 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
945 if (!is_room_aide()) {
946 cprintf("%d Higher access required.\n",
947 ERROR+HIGHER_ACCESS_REQUIRED);
951 if (is_noneditable(&CC->quickroom)) {
952 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
956 if (num_parms(args)>=6) {
957 getfloor(&flbuf,extract_int(args,5));
958 if ((flbuf.f_flags & F_INUSE) == 0) {
959 cprintf("%d Invalid floor number.\n",
960 ERROR+INVALID_FLOOR_OPERATION);
965 lgetroom(&CC->quickroom, CC->quickroom.QRname);
966 extract(buf,args,0); buf[ROOMNAMELEN]=0;
967 strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
968 extract(buf,args,1); buf[10]=0;
969 strncpy(CC->quickroom.QRpasswd,buf,9);
970 extract(buf,args,2); buf[15]=0;
971 strncpy(CC->quickroom.QRdirname,buf,19);
972 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
974 /* Clean up a client boo-boo: if the client set the room to
975 * guess-name or passworded, ensure that the private flag is
978 if ((CC->quickroom.QRflags & QR_GUESSNAME)
979 ||(CC->quickroom.QRflags & QR_PASSWORDED))
980 CC->quickroom.QRflags |= QR_PRIVATE;
982 /* Kick everyone out if the client requested it (by changing the
983 * room's generation number)
985 if (extract_int(args,4)) {
986 time(&CC->quickroom.QRgen);
989 old_floor = CC->quickroom.QRfloor;
990 if (num_parms(args)>=6) {
991 CC->quickroom.QRfloor = extract_int(args,5);
994 lputroom(&CC->quickroom, CC->quickroom.QRname);
996 /* adjust the floor reference counts */
997 lgetfloor(&flbuf,old_floor);
999 lputfloor(&flbuf,old_floor);
1000 lgetfloor(&flbuf,CC->quickroom.QRfloor);
1001 ++flbuf.f_ref_count;
1002 lputfloor(&flbuf,CC->quickroom.QRfloor);
1004 /* create a room directory if necessary */
1005 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1007 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1008 CC->quickroom.QRdirname);
1012 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
1014 cprintf("%d Ok\n",OK);
1020 * get the name of the room aide for this room
1022 void cmd_geta(void) {
1023 struct usersupp usbuf;
1025 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
1026 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1030 if (is_noneditable(&CC->quickroom)) {
1031 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1035 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
1036 cprintf("%d %s\n",OK,usbuf.fullname);
1039 cprintf("%d \n",OK);
1045 * set the room aide for this room
1047 void cmd_seta(char *new_ra)
1049 struct usersupp usbuf;
1054 if (!(CC->logged_in)) {
1055 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1059 if (!is_room_aide()) {
1060 cprintf("%d Higher access required.\n",
1061 ERROR+HIGHER_ACCESS_REQUIRED);
1065 if (getuser(&usbuf,new_ra)!=0) {
1069 newu = usbuf.usernum;
1072 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1074 if (CC->quickroom.QRroomaide != newu) {
1077 CC->quickroom.QRroomaide = newu;
1078 lputroom(&CC->quickroom, CC->quickroom.QRname);
1081 * We have to post the change notice _after_ writing changes to
1082 * the room table, otherwise it would deadlock!
1084 if (post_notice == 1) {
1085 sprintf(buf,"%s is now room aide for %s>",
1086 usbuf.fullname,CC->quickroom.QRname);
1089 cprintf("%d Ok\n",OK);
1093 * Generate an associated file name for a room
1095 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
1098 sprintf(buf, "./prefix/%s.%ld", qrbuf->QRname, qrbuf->QRgen);
1099 for (a=0; a<strlen(buf); ++a) {
1100 if (buf[a]==32) buf[a]='.';
1105 * retrieve info file for this room
1107 void cmd_rinf(void) {
1112 assoc_file_name(filename, &CC->quickroom, "info");
1113 info_fp = fopen(filename,"r");
1115 if (info_fp==NULL) {
1116 cprintf("%d No info file.\n",ERROR);
1120 cprintf("%d Info:\n",LISTING_FOLLOWS);
1121 while (fgets(buf, 256, info_fp) != NULL) {
1122 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1123 cprintf("%s\n", buf);
1130 * Back end processing to delete a room and everything associated with it
1132 void delete_room(struct quickroom *qrbuf) {
1138 /* Delete the info file */
1139 assoc_file_name(aaa, qrbuf, "info");
1142 /* Delete the image file */
1143 assoc_file_name(aaa, qrbuf, "images");
1146 /* first flag the room record as not in use */
1147 lgetroom(qrbuf, qrbuf->QRname);
1150 /* then delete the messages in the room */
1152 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1153 MsgToDelete = MessageFromList(a);
1154 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1160 delete_msglist(qrbuf);
1161 lputroom(qrbuf, qrbuf->QRname);
1163 /* then decrement the reference count for the floor */
1164 lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
1165 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1166 lputfloor(&flbuf,(int)(qrbuf->QRfloor));
1168 /* Delete the room record from the database! */
1169 putroom(NULL, qrbuf->QRname);
1174 * aide command: kill the current room
1176 void cmd_kill(char *argbuf) {
1178 char deleted_room_name[ROOMNAMELEN];
1181 kill_ok = extract_int(argbuf,0);
1183 if (!(CC->logged_in)) {
1184 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1188 if (!is_room_aide()) {
1189 cprintf("%d Higher access required.\n",
1190 ERROR+HIGHER_ACCESS_REQUIRED);
1194 if (is_noneditable(&CC->quickroom)) {
1195 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1200 strcpy(deleted_room_name, CC->quickroom.QRname);
1201 delete_room(&CC->quickroom); /* Do the dirty work */
1202 usergoto(BASEROOM, 0); /* Return to the Lobby */
1204 /* tell the world what we did */
1205 sprintf(aaa,"%s> killed by %s",
1206 deleted_room_name, CC->curr_user);
1208 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1211 cprintf("%d ok to delete.\n",OK);
1217 * Internal code to create a new room (returns room flags)
1219 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1221 unsigned create_room(char *new_room_name,
1223 char *new_room_pass,
1224 int new_room_floor) {
1226 struct quickroom qrbuf;
1230 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1232 memset(&qrbuf, 0, sizeof(struct quickroom));
1233 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1234 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1235 qrbuf.QRflags = QR_INUSE;
1236 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1237 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1238 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1239 if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
1241 /* If the room is private, and the system administrator has elected
1242 * to automatically grant room aide privileges, do so now; otherwise,
1243 * set the room aide to undefined.
1245 if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) {
1246 qrbuf.QRroomaide=CC->usersupp.usernum;
1249 qrbuf.QRroomaide = (-1L);
1252 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1253 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1254 qrbuf.QRfloor = new_room_floor;
1256 /* save what we just did... */
1257 putroom(&qrbuf, qrbuf.QRname);
1259 /* bump the reference count on whatever floor the room is on */
1260 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1261 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1262 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1264 /* be sure not to kick the creator out of the room! */
1265 lgetuser(&CC->usersupp,CC->curr_user);
1266 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1267 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1268 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1269 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1270 lputuser(&CC->usersupp,CC->curr_user);
1272 /* resume our happy day */
1273 return(qrbuf.QRflags);
1280 void cmd_cre8(char *args)
1283 char new_room_name[256];
1285 char new_room_pass[256];
1289 struct quickroom qrbuf;
1292 cre8_ok = extract_int(args,0);
1293 extract(new_room_name,args,1);
1294 new_room_name[ROOMNAMELEN-1] = 0;
1295 new_room_type = extract_int(args,2);
1296 extract(new_room_pass,args,3);
1297 new_room_pass[9] = 0;
1300 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1301 cprintf("%d Invalid room name.\n",ERROR);
1305 if (num_parms(args)>=5) {
1306 getfloor(&flbuf,extract_int(args,4));
1307 if ((flbuf.f_flags & F_INUSE) == 0) {
1308 cprintf("%d Invalid floor number.\n",
1309 ERROR+INVALID_FLOOR_OPERATION);
1313 new_room_floor = extract_int(args,4);
1317 if (!(CC->logged_in)) {
1318 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1322 if (CC->usersupp.axlevel<3) {
1323 cprintf("%d You need higher access to create rooms.\n",
1324 ERROR+HIGHER_ACCESS_REQUIRED);
1328 if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
1329 cprintf("%d Ok to create rooms.\n", OK);
1333 /* Check to make sure the requested room name doesn't already exist */
1334 if (getroom(&qrbuf, new_room_name)==0) {
1335 cprintf("%d '%s' already exists.\n",
1336 ERROR,qrbuf.QRname);
1340 if ((new_room_type < 0) || (new_room_type > 3)) {
1341 cprintf("%d Invalid room type.\n",ERROR);
1346 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1350 newflags = create_room(new_room_name,
1351 new_room_type,new_room_pass,new_room_floor);
1353 /* post a message in Aide> describing the new room */
1354 strncpy(aaa,new_room_name,255);
1355 strcat(aaa,"> created by ");
1356 strcat(aaa,CC->usersupp.fullname);
1357 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1358 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1359 if (newflags&QR_PASSWORDED) {
1360 strcat(aaa,"\n Password: ");
1361 strcat(aaa,new_room_pass);
1365 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1370 void cmd_einf(char *ok)
1371 { /* enter info file for current room */
1373 char infofilename[64];
1376 if (!(CC->logged_in)) {
1377 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1381 if (!is_room_aide()) {
1382 cprintf("%d Higher access required.\n",
1383 ERROR+HIGHER_ACCESS_REQUIRED);
1388 cprintf("%d Ok.\n",OK);
1392 cprintf("%d Send info...\n",SEND_LISTING);
1394 assoc_file_name(infofilename, &CC->quickroom, "info");
1396 fp=fopen(infofilename,"w");
1399 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1400 } while(strcmp(buf,"000"));
1403 /* now update the room index so people will see our new info */
1404 lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */
1405 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1406 lputroom(&CC->quickroom,CC->quickroom.QRname);
1411 * cmd_lflr() - List all known floors
1413 void cmd_lflr(void) {
1417 if (!(CC->logged_in)) {
1418 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1422 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1423 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1428 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1430 for (a=0; a<MAXFLOORS; ++a) {
1432 if (flbuf.f_flags & F_INUSE) {
1433 cprintf("%d|%s|%d\n",
1445 * create a new floor
1447 void cmd_cflr(char *argbuf)
1449 char new_floor_name[256];
1452 int free_slot = (-1);
1455 extract(new_floor_name,argbuf,0);
1456 cflr_ok = extract_int(argbuf,1);
1459 if (!(CC->logged_in)) {
1460 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1464 if (CC->usersupp.axlevel<6) {
1465 cprintf("%d You need higher access to create rooms.\n",
1466 ERROR+HIGHER_ACCESS_REQUIRED);
1470 for (a=0; a<MAXFLOORS; ++a) {
1473 /* note any free slots while we're scanning... */
1474 if ( ((flbuf.f_flags & F_INUSE)==0)
1475 && (free_slot < 0) ) free_slot = a;
1477 /* check to see if it already exists */
1478 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1479 && (flbuf.f_flags & F_INUSE) ) {
1480 cprintf("%d Floor '%s' already exists.\n",
1481 ERROR+ALREADY_EXISTS,
1489 cprintf("%d There is no space available for a new floor.\n",
1490 ERROR+INVALID_FLOOR_OPERATION);
1495 cprintf("%d ok to create...\n",OK);
1499 lgetfloor(&flbuf,free_slot);
1500 flbuf.f_flags = F_INUSE;
1501 flbuf.f_ref_count = 0;
1502 strncpy(flbuf.f_name,new_floor_name,255);
1503 lputfloor(&flbuf,free_slot);
1504 cprintf("%d %d\n",OK,free_slot);
1512 void cmd_kflr(char *argbuf)
1515 int floor_to_delete;
1519 floor_to_delete = extract_int(argbuf,0);
1520 kflr_ok = extract_int(argbuf,1);
1523 if (!(CC->logged_in)) {
1524 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1528 if (CC->usersupp.axlevel<6) {
1529 cprintf("%d You need higher access to delete floors.\n",
1530 ERROR+HIGHER_ACCESS_REQUIRED);
1534 lgetfloor(&flbuf,floor_to_delete);
1537 if ((flbuf.f_flags & F_INUSE) == 0) {
1538 cprintf("%d Floor %d not in use.\n",
1539 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1544 if (flbuf.f_ref_count != 0) {
1545 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1546 ERROR+INVALID_FLOOR_OPERATION,
1553 cprintf("%d Ok\n",OK);
1556 cprintf("%d Ok to delete...\n",OK);
1563 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1564 lputfloor(&flbuf,floor_to_delete);
1570 void cmd_eflr(char *argbuf)
1576 np = num_parms(argbuf);
1578 cprintf("%d Usage error.\n",ERROR);
1582 if (!(CC->logged_in)) {
1583 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1587 if (CC->usersupp.axlevel<6) {
1588 cprintf("%d You need higher access to edit floors.\n",
1589 ERROR+HIGHER_ACCESS_REQUIRED);
1593 floor_num = extract_int(argbuf,0);
1594 lgetfloor(&flbuf,floor_num);
1595 if ( (flbuf.f_flags & F_INUSE) == 0) {
1596 lputfloor(&flbuf,floor_num);
1597 cprintf("%d Floor %d is not in use.\n",
1598 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1601 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1602 lputfloor(&flbuf,floor_num);
1604 cprintf("%d Ok\n",OK);