14 #include "sysdep_decls.h"
18 #include "serv_chat.h"
19 #include "citserver.h"
22 * Generic routine for determining user access to rooms
24 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf) {
28 /* Make sure we're dealing with a real, existing room */
29 if (roombuf->QRflags & QR_INUSE) {
30 retval = retval | UA_INUSE;
36 /* for internal programs, always do everything */
37 if (((CC->internal_pgm))&&(roombuf->QRflags & QR_INUSE)) {
38 return(UA_INUSE | UA_KNOWN | UA_GOTOALLOWED);
41 /* For mailbox rooms, only allow access to the owner */
42 if (roombuf->QRflags & QR_MAILBOX) {
43 if (userbuf->usernum != atol(roombuf->QRname)) {
48 /* Locate any applicable user/room relationships */
49 CtdlGetRelationship(&vbuf, userbuf, roombuf);
51 /* If this is a public room, it's accessible... */
52 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
53 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
56 /* If this is a preferred users only room, check access level */
57 if (roombuf->QRflags & QR_PREFONLY) {
58 if (userbuf->axlevel < 5) {
59 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
63 /* For private rooms, check the generation number matchups */
64 if (roombuf->QRflags & QR_PRIVATE) {
66 /* An explicit match means the user belongs in this room */
67 if (vbuf.v_flags & V_ACCESS) {
68 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
70 /* Otherwise, check if this is a guess-name or passworded
71 * room. If it is, a goto may at least be attempted
73 else if ((roombuf->QRflags & QR_PRIVATE)
74 ||(roombuf->QRflags & QR_PASSWORDED)) {
75 retval = retval & ~UA_KNOWN;
76 retval = retval | UA_GOTOALLOWED;
80 /* Check to see if the user has forgotten this room */
81 if (vbuf.v_flags & V_FORGET) {
82 retval = retval & ~UA_KNOWN;
83 retval = retval | UA_ZAPPED;
86 /* If user is explicitly locked out of this room, deny everything */
87 if (vbuf.v_flags & V_LOCKOUT) {
88 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
91 /* Aides get access to everything */
92 if (userbuf->axlevel >= 6) {
93 retval = retval | UA_INUSE | UA_KNOWN | UA_GOTOALLOWED;
94 retval = retval & ~UA_ZAPPED;
97 /* By the way, we also check for the presence of new messages */
98 if ( (roombuf->QRhighest) > (vbuf.v_lastseen) ) {
99 retval = retval | UA_HASNEWMSGS;
106 * getroom() - retrieve room data from disk
108 int getroom(struct quickroom *qrbuf, char *room_name)
110 struct cdbdata *cdbqr;
111 char lowercase_name[ROOMNAMELEN];
114 for (a=0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
115 lowercase_name[a] = tolower(room_name[a]);
117 lowercase_name[a] = 0;
119 memset(qrbuf, 0, sizeof(struct quickroom));
120 cdbqr = cdb_fetch(CDB_QUICKROOM,
121 lowercase_name, strlen(lowercase_name));
123 memcpy(qrbuf, cdbqr->ptr,
124 ( (cdbqr->len > sizeof(struct quickroom)) ?
125 sizeof(struct quickroom) : cdbqr->len) );
135 * lgetroom() - same as getroom() but locks the record (if supported)
137 int lgetroom(struct quickroom *qrbuf, char *room_name)
139 begin_critical_section(S_QUICKROOM);
140 return(getroom(qrbuf, room_name));
145 * putroom() - store room data on disk
146 * (if the supplied buffer is NULL, delete the room record)
148 void putroom(struct quickroom *qrbuf, char *room_name)
150 char lowercase_name[ROOMNAMELEN];
153 for (a=0; a<=strlen(room_name); ++a) {
154 lowercase_name[a] = tolower(room_name[a]);
158 cdb_delete(CDB_QUICKROOM,
159 lowercase_name, strlen(lowercase_name));
162 time(&qrbuf->QRmtime);
163 cdb_store(CDB_QUICKROOM,
164 lowercase_name, strlen(lowercase_name),
165 qrbuf, sizeof(struct quickroom));
171 * lputroom() - same as putroom() but unlocks the record (if supported)
173 void lputroom(struct quickroom *qrbuf, char *room_name)
176 putroom(qrbuf, room_name);
177 end_critical_section(S_QUICKROOM);
181 /****************************************************************************/
184 * getfloor() - retrieve floor data from disk
186 void getfloor(struct floor *flbuf, int floor_num)
188 struct cdbdata *cdbfl;
190 memset(flbuf, 0, sizeof(struct floor));
191 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
193 memcpy(flbuf, cdbfl->ptr,
194 ( (cdbfl->len > sizeof(struct floor)) ?
195 sizeof(struct floor) : cdbfl->len) );
199 if (floor_num == 0) {
200 strcpy(flbuf->f_name, "Main Floor");
201 flbuf->f_flags = F_INUSE;
202 flbuf->f_ref_count = 3;
209 * lgetfloor() - same as getfloor() but locks the record (if supported)
211 void lgetfloor(struct floor *flbuf, int floor_num)
214 begin_critical_section(S_FLOORTAB);
215 getfloor(flbuf,floor_num);
220 * putfloor() - store floor data on disk
222 void putfloor(struct floor *flbuf, int floor_num)
224 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
225 flbuf, sizeof(struct floor));
230 * lputfloor() - same as putfloor() but unlocks the record (if supported)
232 void lputfloor(struct floor *flbuf, int floor_num)
235 putfloor(flbuf,floor_num);
236 end_critical_section(S_FLOORTAB);
242 * Traverse the room file...
244 void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) {
245 struct quickroom qrbuf;
246 struct cdbdata *cdbqr;
248 cdb_rewind(CDB_QUICKROOM);
250 while(cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
251 memset(&qrbuf, 0, sizeof(struct quickroom));
252 memcpy(&qrbuf, cdbqr->ptr,
253 ( (cdbqr->len > sizeof(struct quickroom)) ?
254 sizeof(struct quickroom) : cdbqr->len) );
256 if (qrbuf.QRflags & QR_INUSE) (*CallBack)(&qrbuf);
263 * Create a database key for storage of message lists
265 void msglist_key(char *dbkey, struct quickroom *whichroom) {
268 sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
269 for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
273 * get_msglist() - retrieve room message pointers
275 void get_msglist(struct quickroom *whichroom) {
276 struct cdbdata *cdbfr;
279 msglist_key(dbkey, whichroom);
281 if (CC->msglist != NULL) {
287 cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey));
292 CC->msglist = malloc(cdbfr->len);
293 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
294 CC->num_msgs = cdbfr->len / sizeof(long);
300 * put_msglist() - retrieve room message pointers
302 void put_msglist(struct quickroom *whichroom) {
305 msglist_key(dbkey, whichroom);
306 cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey),
307 CC->msglist, CC->num_msgs * sizeof(long));
312 * delete_msglist() - delete room message pointers
314 void delete_msglist(struct quickroom *whichroom) {
317 msglist_key(dbkey, whichroom);
318 cdb_delete(CDB_MSGLISTS, dbkey, strlen(dbkey));
323 * Add a message number to a room's message list.
324 * So, why doesn't this function use the get_msglist() and put_msglist() stuff
325 * defined above? Because the room the message number is being written to
326 * may not be the current room (as is the case with cmd_move() for example).
328 void AddMessageToRoom(struct quickroom *whichroom, long newmsgid) {
330 struct cdbdata *cdbfr;
334 msglist_key(dbkey, whichroom);
335 cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey));
341 msglist = malloc(cdbfr->len);
342 num_msgs = cdbfr->len / sizeof(long);
343 memcpy(msglist, cdbfr->ptr, cdbfr->len);
347 /* Now add the new message */
349 msglist = realloc(msglist,
350 (num_msgs * sizeof(long)) );
352 if (msglist == NULL) {
353 lprintf(3, "ERROR: can't realloc message list!\n");
356 msglist[num_msgs - 1] = newmsgid;
358 /* Write it back to disk. */
359 cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey),
360 msglist, num_msgs * sizeof(long));
362 /* And finally, free up the memory we used. */
368 * MessageFromList() - get a message number from the list currently in memory
370 long MessageFromList(int whichpos) {
372 /* Return zero if the position is invalid */
373 if (whichpos >= CC->num_msgs) return 0L;
375 return(CC->msglist[whichpos]);
379 * SetMessageInList() - set a message number in the list currently in memory
381 void SetMessageInList(int whichpos, long newmsgnum) {
383 /* Return zero if the position is invalid */
384 if (whichpos >= CC->num_msgs) return;
386 CC->msglist[whichpos] = newmsgnum;
392 * sort message pointers
393 * (returns new msg count)
395 int sort_msglist(long listptrs[], int oldcount)
402 if (numitems < 2) return(oldcount);
405 for (a=numitems-2; a>=0; --a) {
406 for (b=0; b<=a; ++b) {
407 if (listptrs[b] > (listptrs[b+1])) {
409 hold2 = listptrs[b+1];
411 listptrs[b+1] = hold1;
416 /* and yank any nulls */
417 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
418 memcpy(&listptrs[0], &listptrs[1],
419 (sizeof(long) * (CC->num_msgs - 1)) );
428 * Determine whether a given room is one of the base non-editable rooms
430 int is_noneditable(struct quickroom *qrbuf) {
431 if (!strcasecmp(qrbuf->QRname, BASEROOM)) return(1);
432 else if (!strcasecmp(qrbuf->QRname, AIDEROOM)) return(1);
439 * Back-back-end for all room listing commands
441 void list_roomname(struct quickroom *qrbuf) {
442 char truncated_roomname[ROOMNAMELEN];
444 /* For mailbox rooms, chop off the owner prefix */
445 if (qrbuf->QRflags & QR_MAILBOX) {
446 strcpy(truncated_roomname, qrbuf->QRname);
447 strcpy(truncated_roomname, &truncated_roomname[11]);
448 cprintf("%s", truncated_roomname);
451 /* For all other rooms, just display the name in its entirety */
453 cprintf("%s", qrbuf->QRname);
456 /* ...and now the other parameters */
458 qrbuf->QRflags,qrbuf->QRfloor);
463 * cmd_lrms() - List all accessible rooms, known or forgotten
465 void cmd_lrms_backend(struct quickroom *qrbuf) {
466 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
467 & (UA_KNOWN | UA_ZAPPED)))
468 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
469 ||((CC->FloorBeingSearched)<0)) )
470 list_roomname(qrbuf);
473 void cmd_lrms(char *argbuf)
475 CC->FloorBeingSearched = (-1);
476 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
478 if (!(CC->logged_in)) {
479 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
483 if (getuser(&CC->usersupp,CC->curr_user)) {
484 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
488 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
490 ForEachRoom(cmd_lrms_backend);
497 * cmd_lkra() - List all known rooms
499 void cmd_lkra_backend(struct quickroom *qrbuf) {
500 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
502 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
503 ||((CC->FloorBeingSearched)<0)) )
504 list_roomname(qrbuf);
507 void cmd_lkra(char *argbuf)
509 CC->FloorBeingSearched = (-1);
510 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
512 if (!(CC->logged_in)) {
513 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
517 if (getuser(&CC->usersupp,CC->curr_user)) {
518 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
522 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
524 ForEachRoom(cmd_lkra_backend);
531 * cmd_lkrn() - List all known rooms with new messages
533 void cmd_lkrn_backend(struct quickroom *qrbuf) {
536 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
538 && (ra & UA_HASNEWMSGS)
539 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
540 ||((CC->FloorBeingSearched)<0)) )
541 list_roomname(qrbuf);
544 void cmd_lkrn(char *argbuf)
546 CC->FloorBeingSearched = (-1);
547 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
549 if (!(CC->logged_in)) {
550 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
554 if (getuser(&CC->usersupp,CC->curr_user)) {
555 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
559 cprintf("%d Rooms w/ new msgs:\n",LISTING_FOLLOWS);
561 ForEachRoom(cmd_lkrn_backend);
568 * cmd_lkro() - List all known rooms
570 void cmd_lkro_backend(struct quickroom *qrbuf) {
573 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
575 && ((ra & UA_HASNEWMSGS)==0)
576 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
577 ||((CC->FloorBeingSearched)<0)) )
578 list_roomname(qrbuf);
581 void cmd_lkro(char *argbuf)
583 CC->FloorBeingSearched = (-1);
584 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
586 if (!(CC->logged_in)) {
587 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
591 if (getuser(&CC->usersupp,CC->curr_user)) {
592 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
596 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
598 ForEachRoom(cmd_lkro_backend);
605 * cmd_lzrm() - List all forgotten rooms
607 void cmd_lzrm_backend(struct quickroom *qrbuf) {
610 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
611 if ( (ra & UA_GOTOALLOWED)
613 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
614 ||((CC->FloorBeingSearched)<0)) )
615 list_roomname(qrbuf);
618 void cmd_lzrm(char *argbuf)
620 CC->FloorBeingSearched = (-1);
621 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
623 if (!(CC->logged_in)) {
624 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
628 if (getuser(&CC->usersupp,CC->curr_user)) {
629 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
633 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
635 ForEachRoom(cmd_lzrm_backend);
641 void usergoto(char *where, int display_result)
644 int new_messages = 0;
645 int total_messages = 0;
649 int newmailcount = 0;
651 char truncated_roomname[ROOMNAMELEN];
653 strcpy(CC->quickroom.QRname, where);
654 getroom(&CC->quickroom, where);
655 lgetuser(&CC->usersupp,CC->curr_user);
656 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
658 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
659 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
661 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
662 lputuser(&CC->usersupp,CC->curr_user);
664 /* check for new mail */
665 newmailcount = NewMailCount();
667 /* set info to 1 if the user needs to read the room's info file */
668 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
671 get_msglist(&CC->quickroom);
672 for (a=0; a<CC->num_msgs; ++a) {
673 if (MessageFromList(a)>0L) {
675 if (MessageFromList(a) > vbuf.v_lastseen) {
681 if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1;
684 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
685 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
688 strcpy(truncated_roomname, CC->quickroom.QRname);
689 if (CC->quickroom.QRflags & QR_MAILBOX) {
690 strcpy(truncated_roomname, &truncated_roomname[11]);
693 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
696 new_messages, total_messages,
697 info,CC->quickroom.QRflags,
698 CC->quickroom.QRhighest,
700 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
702 if (CC->quickroom.QRflags & QR_PRIVATE) {
703 set_wtmpsupp("<private room>");
706 set_wtmpsupp(CC->quickroom.QRname);
712 * cmd_goto() - goto a new room
714 void cmd_goto(char *gargs)
716 struct quickroom QRscratch;
720 char augmented_roomname[256];
724 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
725 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
729 extract(towhere,gargs,0);
730 extract(password,gargs,1);
732 getuser(&CC->usersupp, CC->curr_user);
734 if (!strcasecmp(towhere, "_BASEROOM_"))
735 strcpy(towhere, BASEROOM);
737 if (!strcasecmp(towhere, "_MAIL_"))
738 strcpy(towhere, MAILROOM);
740 if (!strcasecmp(towhere, "_BITBUCKET_"))
741 strcpy(towhere, config.c_twitroom);
744 /* First try a regular match */
745 c = getroom(&QRscratch, towhere);
747 /* Then try a mailbox name match */
749 MailboxName(augmented_roomname, &CC->usersupp, towhere);
750 c = getroom(&QRscratch, augmented_roomname);
751 if (c == 0) strcpy(towhere, augmented_roomname);
754 /* And if the room was found... */
757 /* let internal programs go directly to any room */
758 if (CC->internal_pgm) {
759 usergoto(towhere, 1);
763 /* See if there is an existing user/room relationship */
764 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
766 /* normal clients have to pass through security */
767 if (ra & UA_GOTOALLOWED) ok = 1;
770 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
771 ((ra & UA_KNOWN) == 0) &&
772 (strcasecmp(QRscratch.QRpasswd,password))
774 cprintf("%d wrong or missing passwd\n",
775 ERROR+PASSWORD_REQUIRED);
779 usergoto(towhere, 1);
785 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
789 void cmd_whok(void) {
790 struct usersupp temp;
791 struct cdbdata *cdbus;
793 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
794 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
797 getuser(&CC->usersupp,CC->curr_user);
799 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
800 cprintf("%d Higher access required.\n",
801 ERROR+HIGHER_ACCESS_REQUIRED);
805 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
806 cdb_rewind(CDB_USERSUPP);
807 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
808 memset(&temp, 0, sizeof(struct usersupp));
809 memcpy(&temp, cdbus->ptr, cdbus->len);
812 if ( (CC->quickroom.QRflags & QR_INUSE)
813 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
814 ) cprintf("%s\n",temp.fullname);
821 * RDIR command for room directory
823 void cmd_rdir(void) {
830 if (!(CC->logged_in)) {
831 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
835 getroom(&CC->quickroom, CC->quickroom.QRname);
836 getuser(&CC->usersupp, CC->curr_user);
838 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
839 cprintf("%d not here.\n",ERROR+NOT_HERE);
843 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
844 && (CC->usersupp.axlevel<6)
845 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
846 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
850 cprintf("%d %s|%s/files/%s\n",
851 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
853 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
854 BBSDIR,CC->quickroom.QRdirname,CC->temp);
857 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
859 if (fd==NULL) fd=fopen("/dev/null","r");
861 ls = fopen(CC->temp,"r");
862 while (fgets(flnm,256,ls)!=NULL) {
863 flnm[strlen(flnm)-1]=0;
864 if (strcasecmp(flnm,"filedir")) {
865 sprintf(buf,"%s/files/%s/%s",
866 BBSDIR,CC->quickroom.QRdirname,flnm);
870 while ((fgets(buf,256,fd)!=NULL)
871 &&(strlen(comment)==0)) {
872 buf[strlen(buf)-1] = 0;
873 if ((!strncasecmp(buf,flnm,strlen(flnm)))
874 && (buf[strlen(flnm)]==' '))
876 &buf[strlen(flnm)+1],255);
878 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
889 * get room parameters (aide or room aide command)
891 void cmd_getr(void) {
892 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
893 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
897 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
898 cprintf("%d Higher access required.\n",
899 ERROR+HIGHER_ACCESS_REQUIRED);
903 if (is_noneditable(&CC->quickroom)) {
904 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
908 getroom(&CC->quickroom, CC->quickroom.QRname);
909 cprintf("%d%c%s|%s|%s|%d|%d\n",
911 CC->quickroom.QRname,
912 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
913 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
914 CC->quickroom.QRflags,
915 (int)CC->quickroom.QRfloor);
920 * set room parameters (aide or room aide command)
922 void cmd_setr(char *args) {
927 if (!(CC->logged_in)) {
928 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
932 if (!is_room_aide()) {
933 cprintf("%d Higher access required.\n",
934 ERROR+HIGHER_ACCESS_REQUIRED);
938 if (is_noneditable(&CC->quickroom)) {
939 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
943 if (num_parms(args)>=6) {
944 getfloor(&flbuf,extract_int(args,5));
945 if ((flbuf.f_flags & F_INUSE) == 0) {
946 cprintf("%d Invalid floor number.\n",
947 ERROR+INVALID_FLOOR_OPERATION);
952 lgetroom(&CC->quickroom, CC->quickroom.QRname);
953 extract(buf,args,0); buf[ROOMNAMELEN]=0;
954 strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
955 extract(buf,args,1); buf[10]=0;
956 strncpy(CC->quickroom.QRpasswd,buf,9);
957 extract(buf,args,2); buf[15]=0;
958 strncpy(CC->quickroom.QRdirname,buf,19);
959 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
961 /* Clean up a client boo-boo: if the client set the room to
962 * guess-name or passworded, ensure that the private flag is
965 if ((CC->quickroom.QRflags & QR_GUESSNAME)
966 ||(CC->quickroom.QRflags & QR_PASSWORDED))
967 CC->quickroom.QRflags |= QR_PRIVATE;
969 /* Kick everyone out if the client requested it (by changing the
970 * room's generation number)
972 if (extract_int(args,4)) {
973 time(&CC->quickroom.QRgen);
976 old_floor = CC->quickroom.QRfloor;
977 if (num_parms(args)>=6) {
978 CC->quickroom.QRfloor = extract_int(args,5);
981 lputroom(&CC->quickroom, CC->quickroom.QRname);
983 /* adjust the floor reference counts */
984 lgetfloor(&flbuf,old_floor);
986 lputfloor(&flbuf,old_floor);
987 lgetfloor(&flbuf,CC->quickroom.QRfloor);
989 lputfloor(&flbuf,CC->quickroom.QRfloor);
991 /* create a room directory if necessary */
992 if (CC->quickroom.QRflags & QR_DIRECTORY) {
994 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
995 CC->quickroom.QRdirname);
999 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
1001 cprintf("%d Ok\n",OK);
1007 * get the name of the room aide for this room
1009 void cmd_geta(void) {
1010 struct usersupp usbuf;
1012 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
1013 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1017 if (is_noneditable(&CC->quickroom)) {
1018 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1022 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
1023 cprintf("%d %s\n",OK,usbuf.fullname);
1026 cprintf("%d \n",OK);
1032 * set the room aide for this room
1034 void cmd_seta(char *new_ra)
1036 struct usersupp usbuf;
1041 if (!(CC->logged_in)) {
1042 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1046 if (!is_room_aide()) {
1047 cprintf("%d Higher access required.\n",
1048 ERROR+HIGHER_ACCESS_REQUIRED);
1052 if (getuser(&usbuf,new_ra)!=0) {
1056 newu = usbuf.usernum;
1059 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1061 if (CC->quickroom.QRroomaide != newu) {
1064 CC->quickroom.QRroomaide = newu;
1065 lputroom(&CC->quickroom, CC->quickroom.QRname);
1068 * We have to post the change notice _after_ writing changes to
1069 * the room table, otherwise it would deadlock!
1071 if (post_notice == 1) {
1072 sprintf(buf,"%s is now room aide for %s>",
1073 usbuf.fullname,CC->quickroom.QRname);
1076 cprintf("%d Ok\n",OK);
1080 * Generate an associated file name for a room
1082 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
1085 sprintf(buf, "./prefix/%s.%ld", qrbuf->QRname, qrbuf->QRgen);
1086 for (a=0; a<strlen(buf); ++a) {
1087 if (buf[a]==32) buf[a]='.';
1092 * retrieve info file for this room
1094 void cmd_rinf(void) {
1099 assoc_file_name(filename, &CC->quickroom, "info");
1100 info_fp = fopen(filename,"r");
1102 if (info_fp==NULL) {
1103 cprintf("%d No info file.\n",ERROR);
1107 cprintf("%d Info:\n",LISTING_FOLLOWS);
1108 while (fgets(buf, 256, info_fp) != NULL) {
1109 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1110 cprintf("%s\n", buf);
1117 * Back end processing to delete a room and everything associated with it
1119 void delete_room(struct quickroom *qrbuf) {
1125 /* Delete the info file */
1126 assoc_file_name(aaa, qrbuf, "info");
1129 /* Delete the image file */
1130 assoc_file_name(aaa, qrbuf, "images");
1133 /* first flag the room record as not in use */
1134 lgetroom(qrbuf, qrbuf->QRname);
1137 /* then delete the messages in the room */
1139 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1140 MsgToDelete = MessageFromList(a);
1141 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1147 delete_msglist(qrbuf);
1148 lputroom(qrbuf, qrbuf->QRname);
1150 /* then decrement the reference count for the floor */
1151 lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
1152 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1153 lputfloor(&flbuf,(int)(qrbuf->QRfloor));
1155 /* Delete the room record from the database! */
1156 putroom(NULL, qrbuf->QRname);
1161 * aide command: kill the current room
1163 void cmd_kill(char *argbuf) {
1165 char deleted_room_name[ROOMNAMELEN];
1168 kill_ok = extract_int(argbuf,0);
1170 if (!(CC->logged_in)) {
1171 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1175 if (!is_room_aide()) {
1176 cprintf("%d Higher access required.\n",
1177 ERROR+HIGHER_ACCESS_REQUIRED);
1181 if (is_noneditable(&CC->quickroom)) {
1182 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1187 strcpy(deleted_room_name, CC->quickroom.QRname);
1188 delete_room(&CC->quickroom); /* Do the dirty work */
1189 usergoto(BASEROOM, 0); /* Return to the Lobby */
1191 /* tell the world what we did */
1192 sprintf(aaa,"%s> killed by %s",
1193 deleted_room_name, CC->curr_user);
1195 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1198 cprintf("%d ok to delete.\n",OK);
1204 * Internal code to create a new room (returns room flags)
1206 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1208 unsigned create_room(char *new_room_name,
1210 char *new_room_pass,
1211 int new_room_floor) {
1213 struct quickroom qrbuf;
1217 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1219 memset(&qrbuf, 0, sizeof(struct quickroom));
1220 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1221 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1222 qrbuf.QRflags = QR_INUSE;
1223 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1224 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1225 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1226 if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
1228 /* If the room is private, and the system administrator has elected
1229 * to automatically grant room aide privileges, do so now; otherwise,
1230 * set the room aide to undefined.
1232 if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) {
1233 qrbuf.QRroomaide=CC->usersupp.usernum;
1236 qrbuf.QRroomaide = (-1L);
1239 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1240 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1241 qrbuf.QRfloor = new_room_floor;
1243 /* save what we just did... */
1244 putroom(&qrbuf, qrbuf.QRname);
1246 /* bump the reference count on whatever floor the room is on */
1247 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1248 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1249 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1251 /* be sure not to kick the creator out of the room! */
1252 lgetuser(&CC->usersupp,CC->curr_user);
1253 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1254 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1255 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1256 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1257 lputuser(&CC->usersupp,CC->curr_user);
1259 /* resume our happy day */
1260 return(qrbuf.QRflags);
1267 void cmd_cre8(char *args)
1270 char new_room_name[256];
1272 char new_room_pass[256];
1276 struct quickroom qrbuf;
1279 cre8_ok = extract_int(args,0);
1280 extract(new_room_name,args,1);
1281 new_room_name[ROOMNAMELEN-1] = 0;
1282 new_room_type = extract_int(args,2);
1283 extract(new_room_pass,args,3);
1284 new_room_pass[9] = 0;
1287 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1288 cprintf("%d Invalid room name.\n",ERROR);
1292 if (num_parms(args)>=5) {
1293 getfloor(&flbuf,extract_int(args,4));
1294 if ((flbuf.f_flags & F_INUSE) == 0) {
1295 cprintf("%d Invalid floor number.\n",
1296 ERROR+INVALID_FLOOR_OPERATION);
1300 new_room_floor = extract_int(args,4);
1304 if (!(CC->logged_in)) {
1305 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1309 if (CC->usersupp.axlevel<3) {
1310 cprintf("%d You need higher access to create rooms.\n",
1311 ERROR+HIGHER_ACCESS_REQUIRED);
1315 if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
1316 cprintf("%d Ok to create rooms.\n", OK);
1320 /* Check to make sure the requested room name doesn't already exist */
1321 if (getroom(&qrbuf, new_room_name)==0) {
1322 cprintf("%d '%s' already exists.\n",
1323 ERROR,qrbuf.QRname);
1327 if ((new_room_type < 0) || (new_room_type > 3)) {
1328 cprintf("%d Invalid room type.\n",ERROR);
1333 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1337 newflags = create_room(new_room_name,
1338 new_room_type,new_room_pass,new_room_floor);
1340 /* post a message in Aide> describing the new room */
1341 strncpy(aaa,new_room_name,255);
1342 strcat(aaa,"> created by ");
1343 strcat(aaa,CC->usersupp.fullname);
1344 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1345 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1346 if (newflags&QR_PASSWORDED) {
1347 strcat(aaa,"\n Password: ");
1348 strcat(aaa,new_room_pass);
1352 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1357 void cmd_einf(char *ok)
1358 { /* enter info file for current room */
1360 char infofilename[64];
1363 if (!(CC->logged_in)) {
1364 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1368 if (!is_room_aide()) {
1369 cprintf("%d Higher access required.\n",
1370 ERROR+HIGHER_ACCESS_REQUIRED);
1375 cprintf("%d Ok.\n",OK);
1379 cprintf("%d Send info...\n",SEND_LISTING);
1381 assoc_file_name(infofilename, &CC->quickroom, "info");
1383 fp=fopen(infofilename,"w");
1386 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1387 } while(strcmp(buf,"000"));
1390 /* now update the room index so people will see our new info */
1391 lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */
1392 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1393 lputroom(&CC->quickroom,CC->quickroom.QRname);
1398 * cmd_lflr() - List all known floors
1400 void cmd_lflr(void) {
1404 if (!(CC->logged_in)) {
1405 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1409 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1410 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1415 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1417 for (a=0; a<MAXFLOORS; ++a) {
1419 if (flbuf.f_flags & F_INUSE) {
1420 cprintf("%d|%s|%d\n",
1432 * create a new floor
1434 void cmd_cflr(char *argbuf)
1436 char new_floor_name[256];
1439 int free_slot = (-1);
1442 extract(new_floor_name,argbuf,0);
1443 cflr_ok = extract_int(argbuf,1);
1446 if (!(CC->logged_in)) {
1447 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1451 if (CC->usersupp.axlevel<6) {
1452 cprintf("%d You need higher access to create rooms.\n",
1453 ERROR+HIGHER_ACCESS_REQUIRED);
1457 for (a=0; a<MAXFLOORS; ++a) {
1460 /* note any free slots while we're scanning... */
1461 if ( ((flbuf.f_flags & F_INUSE)==0)
1462 && (free_slot < 0) ) free_slot = a;
1464 /* check to see if it already exists */
1465 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1466 && (flbuf.f_flags & F_INUSE) ) {
1467 cprintf("%d Floor '%s' already exists.\n",
1468 ERROR+ALREADY_EXISTS,
1476 cprintf("%d There is no space available for a new floor.\n",
1477 ERROR+INVALID_FLOOR_OPERATION);
1482 cprintf("%d ok to create...\n",OK);
1486 lgetfloor(&flbuf,free_slot);
1487 flbuf.f_flags = F_INUSE;
1488 flbuf.f_ref_count = 0;
1489 strncpy(flbuf.f_name,new_floor_name,255);
1490 lputfloor(&flbuf,free_slot);
1491 cprintf("%d %d\n",OK,free_slot);
1499 void cmd_kflr(char *argbuf)
1502 int floor_to_delete;
1506 floor_to_delete = extract_int(argbuf,0);
1507 kflr_ok = extract_int(argbuf,1);
1510 if (!(CC->logged_in)) {
1511 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1515 if (CC->usersupp.axlevel<6) {
1516 cprintf("%d You need higher access to delete floors.\n",
1517 ERROR+HIGHER_ACCESS_REQUIRED);
1521 lgetfloor(&flbuf,floor_to_delete);
1524 if ((flbuf.f_flags & F_INUSE) == 0) {
1525 cprintf("%d Floor %d not in use.\n",
1526 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1531 if (flbuf.f_ref_count != 0) {
1532 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1533 ERROR+INVALID_FLOOR_OPERATION,
1540 cprintf("%d Ok\n",OK);
1543 cprintf("%d Ok to delete...\n",OK);
1550 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1551 lputfloor(&flbuf,floor_to_delete);
1557 void cmd_eflr(char *argbuf)
1563 np = num_parms(argbuf);
1565 cprintf("%d Usage error.\n",ERROR);
1569 if (!(CC->logged_in)) {
1570 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1574 if (CC->usersupp.axlevel<6) {
1575 cprintf("%d You need higher access to edit floors.\n",
1576 ERROR+HIGHER_ACCESS_REQUIRED);
1580 floor_num = extract_int(argbuf,0);
1581 lgetfloor(&flbuf,floor_num);
1582 if ( (flbuf.f_flags & F_INUSE) == 0) {
1583 lputfloor(&flbuf,floor_num);
1584 cprintf("%d Floor %d is not in use.\n",
1585 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1588 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1589 lputfloor(&flbuf,floor_num);
1591 cprintf("%d Ok\n",OK);