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
327 * FIX - this really should check first to make sure there's actually a
328 * msglist to delete. As things stand now, calling this function on
329 * a room which has never been posted in will result in a message
330 * like "gdbm: illegal data" (no big deal, but could use fixing).
332 void delete_msglist(struct quickroom *whichroom) {
335 msglist_key(dbkey, whichroom);
336 cdb_delete(CDB_MSGLISTS, dbkey, strlen(dbkey));
341 * Add a message number to a room's message list.
342 * So, why doesn't this function use the get_msglist() and put_msglist() stuff
343 * defined above? Because the room the message number is being written to
344 * may not be the current room (as is the case with cmd_move() for example).
346 void AddMessageToRoom(struct quickroom *whichroom, long newmsgid) {
348 struct cdbdata *cdbfr;
352 msglist_key(dbkey, whichroom);
353 cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey));
359 msglist = malloc(cdbfr->len);
360 num_msgs = cdbfr->len / sizeof(long);
361 memcpy(msglist, cdbfr->ptr, cdbfr->len);
365 /* Now add the new message */
367 msglist = realloc(msglist,
368 (num_msgs * sizeof(long)) );
370 if (msglist == NULL) {
371 lprintf(3, "ERROR: can't realloc message list!\n");
374 msglist[num_msgs - 1] = newmsgid;
376 /* Write it back to disk. */
377 cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey),
378 msglist, num_msgs * sizeof(long));
380 /* And finally, free up the memory we used. */
386 * MessageFromList() - get a message number from the list currently in memory
388 long MessageFromList(int whichpos) {
390 /* Return zero if the position is invalid */
391 if (whichpos >= CC->num_msgs) return 0L;
393 return(CC->msglist[whichpos]);
397 * SetMessageInList() - set a message number in the list currently in memory
399 void SetMessageInList(int whichpos, long newmsgnum) {
401 /* Return zero if the position is invalid */
402 if (whichpos >= CC->num_msgs) return;
404 CC->msglist[whichpos] = newmsgnum;
410 * sort message pointers
411 * (returns new msg count)
413 int sort_msglist(long listptrs[], int oldcount)
420 if (numitems < 2) return(oldcount);
423 for (a=numitems-2; a>=0; --a) {
424 for (b=0; b<=a; ++b) {
425 if (listptrs[b] > (listptrs[b+1])) {
427 hold2 = listptrs[b+1];
429 listptrs[b+1] = hold1;
434 /* and yank any nulls */
435 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
436 memcpy(&listptrs[0], &listptrs[1],
437 (sizeof(long) * (CC->num_msgs - 1)) );
446 * Determine whether a given room is one of the base non-editable rooms
448 int is_noneditable(struct quickroom *qrbuf) {
449 if (!strcasecmp(qrbuf->QRname, BASEROOM)) return(1);
450 else if (!strcasecmp(qrbuf->QRname, AIDEROOM)) return(1);
457 * Back-back-end for all room listing commands
459 void list_roomname(struct quickroom *qrbuf) {
460 char truncated_roomname[ROOMNAMELEN];
462 /* For mailbox rooms, chop off the owner prefix */
463 if (qrbuf->QRflags & QR_MAILBOX) {
464 strcpy(truncated_roomname, qrbuf->QRname);
465 strcpy(truncated_roomname, &truncated_roomname[11]);
466 cprintf("%s", truncated_roomname);
468 /* For all other rooms, just display the name in its entirety */
470 cprintf("%s", qrbuf->QRname);
473 /* ...and now the other parameters */
475 qrbuf->QRflags,qrbuf->QRfloor);
480 * cmd_lrms() - List all accessible rooms, known or forgotten
482 void cmd_lrms_backend(struct quickroom *qrbuf) {
483 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
484 & (UA_KNOWN | UA_ZAPPED)))
485 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
486 ||((CC->FloorBeingSearched)<0)) )
487 list_roomname(qrbuf);
490 void cmd_lrms(char *argbuf)
492 CC->FloorBeingSearched = (-1);
493 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
495 if (!(CC->logged_in)) {
496 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
500 if (getuser(&CC->usersupp,CC->curr_user)) {
501 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
505 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
507 ForEachRoom(cmd_lrms_backend);
514 * cmd_lkra() - List all known rooms
516 void cmd_lkra_backend(struct quickroom *qrbuf) {
517 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
519 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
520 ||((CC->FloorBeingSearched)<0)) )
521 list_roomname(qrbuf);
524 void cmd_lkra(char *argbuf)
526 CC->FloorBeingSearched = (-1);
527 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
529 if (!(CC->logged_in)) {
530 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
534 if (getuser(&CC->usersupp,CC->curr_user)) {
535 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
539 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
541 ForEachRoom(cmd_lkra_backend);
548 * cmd_lkrn() - List all known rooms with new messages
550 void cmd_lkrn_backend(struct quickroom *qrbuf) {
553 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
555 && (ra & UA_HASNEWMSGS)
556 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
557 ||((CC->FloorBeingSearched)<0)) )
558 list_roomname(qrbuf);
561 void cmd_lkrn(char *argbuf)
563 CC->FloorBeingSearched = (-1);
564 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
566 if (!(CC->logged_in)) {
567 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
571 if (getuser(&CC->usersupp,CC->curr_user)) {
572 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
576 cprintf("%d Rooms w/ new msgs:\n",LISTING_FOLLOWS);
578 ForEachRoom(cmd_lkrn_backend);
585 * cmd_lkro() - List all known rooms
587 void cmd_lkro_backend(struct quickroom *qrbuf) {
590 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
592 && ((ra & UA_HASNEWMSGS)==0)
593 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
594 ||((CC->FloorBeingSearched)<0)) )
595 list_roomname(qrbuf);
598 void cmd_lkro(char *argbuf)
600 CC->FloorBeingSearched = (-1);
601 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
603 if (!(CC->logged_in)) {
604 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
608 if (getuser(&CC->usersupp,CC->curr_user)) {
609 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
613 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
615 ForEachRoom(cmd_lkro_backend);
622 * cmd_lzrm() - List all forgotten rooms
624 void cmd_lzrm_backend(struct quickroom *qrbuf) {
627 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
628 if ( (ra & UA_GOTOALLOWED)
630 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
631 ||((CC->FloorBeingSearched)<0)) )
632 list_roomname(qrbuf);
635 void cmd_lzrm(char *argbuf)
637 CC->FloorBeingSearched = (-1);
638 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
640 if (!(CC->logged_in)) {
641 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
645 if (getuser(&CC->usersupp,CC->curr_user)) {
646 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
650 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
652 ForEachRoom(cmd_lzrm_backend);
658 void usergoto(char *where, int display_result)
661 int new_messages = 0;
662 int total_messages = 0;
666 int newmailcount = 0;
668 char truncated_roomname[ROOMNAMELEN];
670 strcpy(CC->quickroom.QRname, where);
671 getroom(&CC->quickroom, where);
672 lgetuser(&CC->usersupp,CC->curr_user);
673 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
675 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
676 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
678 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
679 lputuser(&CC->usersupp,CC->curr_user);
681 /* check for new mail */
682 newmailcount = NewMailCount();
684 /* set info to 1 if the user needs to read the room's info file */
685 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
688 get_msglist(&CC->quickroom);
689 for (a=0; a<CC->num_msgs; ++a) {
690 if (MessageFromList(a)>0L) {
692 if (MessageFromList(a) > vbuf.v_lastseen) {
698 if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1;
701 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
702 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
705 strcpy(truncated_roomname, CC->quickroom.QRname);
706 if (CC->quickroom.QRflags & QR_MAILBOX) {
707 strcpy(truncated_roomname, &truncated_roomname[11]);
710 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
713 new_messages, total_messages,
714 info,CC->quickroom.QRflags,
715 CC->quickroom.QRhighest,
717 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
719 if (CC->quickroom.QRflags & QR_PRIVATE) {
720 set_wtmpsupp("<private room>");
723 set_wtmpsupp(CC->quickroom.QRname);
729 * cmd_goto() - goto a new room
731 void cmd_goto(char *gargs)
733 struct quickroom QRscratch;
737 char augmented_roomname[256];
741 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
742 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
746 extract(towhere,gargs,0);
747 extract(password,gargs,1);
749 getuser(&CC->usersupp, CC->curr_user);
751 if (!strcasecmp(towhere, "_BASEROOM_"))
752 strcpy(towhere, BASEROOM);
754 if (!strcasecmp(towhere, "_MAIL_"))
755 strcpy(towhere, MAILROOM);
757 if (!strcasecmp(towhere, "_BITBUCKET_"))
758 strcpy(towhere, config.c_twitroom);
761 /* First try a regular match */
762 c = getroom(&QRscratch, towhere);
764 /* Then try a mailbox name match */
766 MailboxName(augmented_roomname, &CC->usersupp, towhere);
767 c = getroom(&QRscratch, augmented_roomname);
768 if (c == 0) strcpy(towhere, augmented_roomname);
771 /* And if the room was found... */
774 /* let internal programs go directly to any room */
775 if (CC->internal_pgm) {
776 usergoto(towhere, 1);
780 /* See if there is an existing user/room relationship */
781 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
783 /* normal clients have to pass through security */
784 if (ra & UA_GOTOALLOWED) ok = 1;
787 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
788 ((ra & UA_KNOWN) == 0) &&
789 (strcasecmp(QRscratch.QRpasswd,password))
791 cprintf("%d wrong or missing passwd\n",
792 ERROR+PASSWORD_REQUIRED);
796 usergoto(towhere, 1);
802 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
806 void cmd_whok(void) {
807 struct usersupp temp;
808 struct cdbdata *cdbus;
810 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
811 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
814 getuser(&CC->usersupp,CC->curr_user);
816 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
817 cprintf("%d Higher access required.\n",
818 ERROR+HIGHER_ACCESS_REQUIRED);
822 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
823 cdb_rewind(CDB_USERSUPP);
824 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
825 memset(&temp, 0, sizeof(struct usersupp));
826 memcpy(&temp, cdbus->ptr, cdbus->len);
829 if ( (CC->quickroom.QRflags & QR_INUSE)
830 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
831 ) cprintf("%s\n",temp.fullname);
838 * RDIR command for room directory
840 void cmd_rdir(void) {
847 if (!(CC->logged_in)) {
848 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
852 getroom(&CC->quickroom, CC->quickroom.QRname);
853 getuser(&CC->usersupp, CC->curr_user);
855 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
856 cprintf("%d not here.\n",ERROR+NOT_HERE);
860 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
861 && (CC->usersupp.axlevel<6)
862 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
863 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
867 cprintf("%d %s|%s/files/%s\n",
868 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
870 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
871 BBSDIR,CC->quickroom.QRdirname,CC->temp);
874 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
876 if (fd==NULL) fd=fopen("/dev/null","r");
878 ls = fopen(CC->temp,"r");
879 while (fgets(flnm,256,ls)!=NULL) {
880 flnm[strlen(flnm)-1]=0;
881 if (strcasecmp(flnm,"filedir")) {
882 sprintf(buf,"%s/files/%s/%s",
883 BBSDIR,CC->quickroom.QRdirname,flnm);
887 while ((fgets(buf,256,fd)!=NULL)
888 &&(strlen(comment)==0)) {
889 buf[strlen(buf)-1] = 0;
890 if ((!strncasecmp(buf,flnm,strlen(flnm)))
891 && (buf[strlen(flnm)]==' '))
893 &buf[strlen(flnm)+1],255);
895 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
906 * get room parameters (aide or room aide command)
908 void cmd_getr(void) {
909 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
910 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
914 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
915 cprintf("%d Higher access required.\n",
916 ERROR+HIGHER_ACCESS_REQUIRED);
920 if (is_noneditable(&CC->quickroom)) {
921 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
925 getroom(&CC->quickroom, CC->quickroom.QRname);
926 cprintf("%d%c%s|%s|%s|%d|%d\n",
928 CC->quickroom.QRname,
929 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
930 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
931 CC->quickroom.QRflags,
932 (int)CC->quickroom.QRfloor);
937 * set room parameters (aide or room aide command)
939 void cmd_setr(char *args) {
944 if (!(CC->logged_in)) {
945 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
949 if (!is_room_aide()) {
950 cprintf("%d Higher access required.\n",
951 ERROR+HIGHER_ACCESS_REQUIRED);
955 if (is_noneditable(&CC->quickroom)) {
956 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
960 if (num_parms(args)>=6) {
961 getfloor(&flbuf,extract_int(args,5));
962 if ((flbuf.f_flags & F_INUSE) == 0) {
963 cprintf("%d Invalid floor number.\n",
964 ERROR+INVALID_FLOOR_OPERATION);
969 lgetroom(&CC->quickroom, CC->quickroom.QRname);
970 extract(buf,args,0); buf[ROOMNAMELEN]=0;
971 strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
972 extract(buf,args,1); buf[10]=0;
973 strncpy(CC->quickroom.QRpasswd,buf,9);
974 extract(buf,args,2); buf[15]=0;
975 strncpy(CC->quickroom.QRdirname,buf,19);
976 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
978 /* Clean up a client boo-boo: if the client set the room to
979 * guess-name or passworded, ensure that the private flag is
982 if ((CC->quickroom.QRflags & QR_GUESSNAME)
983 ||(CC->quickroom.QRflags & QR_PASSWORDED))
984 CC->quickroom.QRflags |= QR_PRIVATE;
986 /* Kick everyone out if the client requested it (by changing the
987 * room's generation number)
989 if (extract_int(args,4)) {
990 time(&CC->quickroom.QRgen);
993 old_floor = CC->quickroom.QRfloor;
994 if (num_parms(args)>=6) {
995 CC->quickroom.QRfloor = extract_int(args,5);
998 lputroom(&CC->quickroom, CC->quickroom.QRname);
1000 /* adjust the floor reference counts */
1001 lgetfloor(&flbuf,old_floor);
1002 --flbuf.f_ref_count;
1003 lputfloor(&flbuf,old_floor);
1004 lgetfloor(&flbuf,CC->quickroom.QRfloor);
1005 ++flbuf.f_ref_count;
1006 lputfloor(&flbuf,CC->quickroom.QRfloor);
1008 /* create a room directory if necessary */
1009 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1011 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1012 CC->quickroom.QRdirname);
1016 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
1018 cprintf("%d Ok\n",OK);
1024 * get the name of the room aide for this room
1026 void cmd_geta(void) {
1027 struct usersupp usbuf;
1029 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
1030 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1034 if (is_noneditable(&CC->quickroom)) {
1035 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1039 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
1040 cprintf("%d %s\n",OK,usbuf.fullname);
1043 cprintf("%d \n",OK);
1049 * set the room aide for this room
1051 void cmd_seta(char *new_ra)
1053 struct usersupp usbuf;
1058 if (!(CC->logged_in)) {
1059 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1063 if (!is_room_aide()) {
1064 cprintf("%d Higher access required.\n",
1065 ERROR+HIGHER_ACCESS_REQUIRED);
1069 if (getuser(&usbuf,new_ra)!=0) {
1073 newu = usbuf.usernum;
1076 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1078 if (CC->quickroom.QRroomaide != newu) {
1081 CC->quickroom.QRroomaide = newu;
1082 lputroom(&CC->quickroom, CC->quickroom.QRname);
1085 * We have to post the change notice _after_ writing changes to
1086 * the room table, otherwise it would deadlock!
1088 if (post_notice == 1) {
1089 sprintf(buf,"%s is now room aide for %s>",
1090 usbuf.fullname,CC->quickroom.QRname);
1093 cprintf("%d Ok\n",OK);
1097 * Generate an associated file name for a room
1099 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
1102 sprintf(buf, "./prefix/%s.%ld", qrbuf->QRname, qrbuf->QRgen);
1103 for (a=0; a<strlen(buf); ++a) {
1104 if (buf[a]==32) buf[a]='.';
1109 * retrieve info file for this room
1111 void cmd_rinf(void) {
1116 assoc_file_name(filename, &CC->quickroom, "info");
1117 info_fp = fopen(filename,"r");
1119 if (info_fp==NULL) {
1120 cprintf("%d No info file.\n",ERROR);
1124 cprintf("%d Info:\n",LISTING_FOLLOWS);
1125 while (fgets(buf, 256, info_fp) != NULL) {
1126 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1127 cprintf("%s\n", buf);
1134 * Back end processing to delete a room and everything associated with it
1136 void delete_room(struct quickroom *qrbuf) {
1142 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1144 /* Delete the info file */
1145 assoc_file_name(aaa, qrbuf, "info");
1148 /* Delete the image file */
1149 assoc_file_name(aaa, qrbuf, "images");
1152 /* first flag the room record as not in use */
1153 lgetroom(qrbuf, qrbuf->QRname);
1156 /* then delete the messages in the room */
1158 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1159 MsgToDelete = MessageFromList(a);
1160 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1166 delete_msglist(qrbuf);
1167 lputroom(qrbuf, qrbuf->QRname);
1169 /* then decrement the reference count for the floor */
1170 lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
1171 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1172 lputfloor(&flbuf,(int)(qrbuf->QRfloor));
1174 /* Delete the room record from the database! */
1175 putroom(NULL, qrbuf->QRname);
1180 * aide command: kill the current room
1182 void cmd_kill(char *argbuf) {
1184 char deleted_room_name[ROOMNAMELEN];
1187 kill_ok = extract_int(argbuf,0);
1189 if (!(CC->logged_in)) {
1190 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1194 if (!is_room_aide()) {
1195 cprintf("%d Higher access required.\n",
1196 ERROR+HIGHER_ACCESS_REQUIRED);
1200 if (is_noneditable(&CC->quickroom)) {
1201 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1206 strcpy(deleted_room_name, CC->quickroom.QRname);
1207 delete_room(&CC->quickroom); /* Do the dirty work */
1208 usergoto(BASEROOM, 0); /* Return to the Lobby */
1210 /* tell the world what we did */
1211 sprintf(aaa,"%s> killed by %s",
1212 deleted_room_name, CC->curr_user);
1214 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1217 cprintf("%d ok to delete.\n",OK);
1223 * Internal code to create a new room (returns room flags)
1225 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1227 unsigned create_room(char *new_room_name,
1229 char *new_room_pass,
1230 int new_room_floor) {
1232 struct quickroom qrbuf;
1236 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1238 memset(&qrbuf, 0, sizeof(struct quickroom));
1239 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1240 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1241 qrbuf.QRflags = QR_INUSE;
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);