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 * Retrieve the applicable room policy for a specific room
441 void GetExpirePolicy(struct ExpirePolicy *epbuf, struct quickroom *qrbuf) {
444 /* If the room has its own policy, return it */
445 if (qrbuf->QRep.expire_mode != 0) {
446 memcpy(epbuf, &qrbuf->QRep, sizeof(struct ExpirePolicy));
450 /* Otherwise, if the floor has its own policy, return it */
451 getfloor(&flbuf, qrbuf->QRfloor);
452 if (flbuf.f_ep.expire_mode != 0) {
453 memcpy(epbuf, &flbuf.f_ep, sizeof(struct ExpirePolicy));
457 /* Otherwise, fall back on the system default */
458 memcpy(epbuf, &config.c_ep, sizeof(struct ExpirePolicy));
463 * Back-back-end for all room listing commands
465 void list_roomname(struct quickroom *qrbuf) {
466 char truncated_roomname[ROOMNAMELEN];
468 /* For mailbox rooms, chop off the owner prefix */
469 if (qrbuf->QRflags & QR_MAILBOX) {
470 strcpy(truncated_roomname, qrbuf->QRname);
471 strcpy(truncated_roomname, &truncated_roomname[11]);
472 cprintf("%s", truncated_roomname);
475 /* For all other rooms, just display the name in its entirety */
477 cprintf("%s", qrbuf->QRname);
480 /* ...and now the other parameters */
482 qrbuf->QRflags,qrbuf->QRfloor);
487 * cmd_lrms() - List all accessible rooms, known or forgotten
489 void cmd_lrms_backend(struct quickroom *qrbuf) {
490 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
491 & (UA_KNOWN | UA_ZAPPED)))
492 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
493 ||((CC->FloorBeingSearched)<0)) )
494 list_roomname(qrbuf);
497 void cmd_lrms(char *argbuf)
499 CC->FloorBeingSearched = (-1);
500 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
502 if (!(CC->logged_in)) {
503 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
507 if (getuser(&CC->usersupp,CC->curr_user)) {
508 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
512 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
514 ForEachRoom(cmd_lrms_backend);
521 * cmd_lkra() - List all known rooms
523 void cmd_lkra_backend(struct quickroom *qrbuf) {
524 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
526 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
527 ||((CC->FloorBeingSearched)<0)) )
528 list_roomname(qrbuf);
531 void cmd_lkra(char *argbuf)
533 CC->FloorBeingSearched = (-1);
534 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
536 if (!(CC->logged_in)) {
537 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
541 if (getuser(&CC->usersupp,CC->curr_user)) {
542 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
546 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
548 ForEachRoom(cmd_lkra_backend);
555 * cmd_lkrn() - List all known rooms with new messages
557 void cmd_lkrn_backend(struct quickroom *qrbuf) {
560 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
562 && (ra & UA_HASNEWMSGS)
563 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
564 ||((CC->FloorBeingSearched)<0)) )
565 list_roomname(qrbuf);
568 void cmd_lkrn(char *argbuf)
570 CC->FloorBeingSearched = (-1);
571 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
573 if (!(CC->logged_in)) {
574 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
578 if (getuser(&CC->usersupp,CC->curr_user)) {
579 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
583 cprintf("%d Rooms w/ new msgs:\n",LISTING_FOLLOWS);
585 ForEachRoom(cmd_lkrn_backend);
592 * cmd_lkro() - List all known rooms
594 void cmd_lkro_backend(struct quickroom *qrbuf) {
597 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
599 && ((ra & UA_HASNEWMSGS)==0)
600 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
601 ||((CC->FloorBeingSearched)<0)) )
602 list_roomname(qrbuf);
605 void cmd_lkro(char *argbuf)
607 CC->FloorBeingSearched = (-1);
608 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
610 if (!(CC->logged_in)) {
611 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
615 if (getuser(&CC->usersupp,CC->curr_user)) {
616 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
620 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
622 ForEachRoom(cmd_lkro_backend);
629 * cmd_lzrm() - List all forgotten rooms
631 void cmd_lzrm_backend(struct quickroom *qrbuf) {
634 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
635 if ( (ra & UA_GOTOALLOWED)
637 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
638 ||((CC->FloorBeingSearched)<0)) )
639 list_roomname(qrbuf);
642 void cmd_lzrm(char *argbuf)
644 CC->FloorBeingSearched = (-1);
645 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
647 if (!(CC->logged_in)) {
648 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
652 if (getuser(&CC->usersupp,CC->curr_user)) {
653 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
657 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
659 ForEachRoom(cmd_lzrm_backend);
665 void usergoto(char *where, int display_result)
668 int new_messages = 0;
669 int total_messages = 0;
673 int newmailcount = 0;
675 char truncated_roomname[ROOMNAMELEN];
677 strcpy(CC->quickroom.QRname, where);
678 getroom(&CC->quickroom, where);
679 lgetuser(&CC->usersupp,CC->curr_user);
680 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
682 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
683 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
685 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
686 lputuser(&CC->usersupp,CC->curr_user);
688 /* check for new mail */
689 newmailcount = NewMailCount();
691 /* set info to 1 if the user needs to read the room's info file */
692 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
695 get_msglist(&CC->quickroom);
696 for (a=0; a<CC->num_msgs; ++a) {
697 if (MessageFromList(a)>0L) {
699 if (MessageFromList(a) > vbuf.v_lastseen) {
705 if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1;
708 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
709 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
712 strcpy(truncated_roomname, CC->quickroom.QRname);
713 if (CC->quickroom.QRflags & QR_MAILBOX) {
714 strcpy(truncated_roomname, &truncated_roomname[11]);
717 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
720 new_messages, total_messages,
721 info,CC->quickroom.QRflags,
722 CC->quickroom.QRhighest,
724 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
726 if (CC->quickroom.QRflags & QR_PRIVATE) {
727 set_wtmpsupp("<private room>");
730 set_wtmpsupp(CC->quickroom.QRname);
736 * cmd_goto() - goto a new room
738 void cmd_goto(char *gargs)
740 struct quickroom QRscratch;
744 char augmented_roomname[256];
748 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
749 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
753 extract(towhere,gargs,0);
754 extract(password,gargs,1);
756 getuser(&CC->usersupp, CC->curr_user);
758 if (!strcasecmp(towhere, "_BASEROOM_"))
759 strcpy(towhere, BASEROOM);
761 if (!strcasecmp(towhere, "_MAIL_"))
762 strcpy(towhere, MAILROOM);
764 if (!strcasecmp(towhere, "_BITBUCKET_"))
765 strcpy(towhere, config.c_twitroom);
768 /* First try a regular match */
769 c = getroom(&QRscratch, towhere);
771 /* Then try a mailbox name match */
773 MailboxName(augmented_roomname, &CC->usersupp, towhere);
774 c = getroom(&QRscratch, augmented_roomname);
775 if (c == 0) strcpy(towhere, augmented_roomname);
778 /* And if the room was found... */
781 /* let internal programs go directly to any room */
782 if (CC->internal_pgm) {
783 usergoto(towhere, 1);
787 /* See if there is an existing user/room relationship */
788 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
790 /* normal clients have to pass through security */
791 if (ra & UA_GOTOALLOWED) ok = 1;
794 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
795 ((ra & UA_KNOWN) == 0) &&
796 (strcasecmp(QRscratch.QRpasswd,password))
798 cprintf("%d wrong or missing passwd\n",
799 ERROR+PASSWORD_REQUIRED);
803 usergoto(towhere, 1);
809 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
813 void cmd_whok(void) {
814 struct usersupp temp;
815 struct cdbdata *cdbus;
817 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
818 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
821 getuser(&CC->usersupp,CC->curr_user);
823 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
824 cprintf("%d Higher access required.\n",
825 ERROR+HIGHER_ACCESS_REQUIRED);
829 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
830 cdb_rewind(CDB_USERSUPP);
831 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
832 memset(&temp, 0, sizeof(struct usersupp));
833 memcpy(&temp, cdbus->ptr, cdbus->len);
836 if ( (CC->quickroom.QRflags & QR_INUSE)
837 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
838 ) cprintf("%s\n",temp.fullname);
845 * RDIR command for room directory
847 void cmd_rdir(void) {
854 if (!(CC->logged_in)) {
855 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
859 getroom(&CC->quickroom, CC->quickroom.QRname);
860 getuser(&CC->usersupp, CC->curr_user);
862 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
863 cprintf("%d not here.\n",ERROR+NOT_HERE);
867 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
868 && (CC->usersupp.axlevel<6)
869 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
870 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
874 cprintf("%d %s|%s/files/%s\n",
875 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
877 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
878 BBSDIR,CC->quickroom.QRdirname,CC->temp);
881 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
883 if (fd==NULL) fd=fopen("/dev/null","r");
885 ls = fopen(CC->temp,"r");
886 while (fgets(flnm,256,ls)!=NULL) {
887 flnm[strlen(flnm)-1]=0;
888 if (strcasecmp(flnm,"filedir")) {
889 sprintf(buf,"%s/files/%s/%s",
890 BBSDIR,CC->quickroom.QRdirname,flnm);
894 while ((fgets(buf,256,fd)!=NULL)
895 &&(strlen(comment)==0)) {
896 buf[strlen(buf)-1] = 0;
897 if ((!strncasecmp(buf,flnm,strlen(flnm)))
898 && (buf[strlen(flnm)]==' '))
900 &buf[strlen(flnm)+1],255);
902 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
913 * get room parameters (aide or room aide command)
915 void cmd_getr(void) {
916 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
917 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
921 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
922 cprintf("%d Higher access required.\n",
923 ERROR+HIGHER_ACCESS_REQUIRED);
927 if (is_noneditable(&CC->quickroom)) {
928 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
932 getroom(&CC->quickroom, CC->quickroom.QRname);
933 cprintf("%d%c%s|%s|%s|%d|%d\n",
935 CC->quickroom.QRname,
936 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
937 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
938 CC->quickroom.QRflags,
939 (int)CC->quickroom.QRfloor);
944 * set room parameters (aide or room aide command)
946 void cmd_setr(char *args) {
951 if (!(CC->logged_in)) {
952 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
956 if (!is_room_aide()) {
957 cprintf("%d Higher access required.\n",
958 ERROR+HIGHER_ACCESS_REQUIRED);
962 if (is_noneditable(&CC->quickroom)) {
963 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
967 if (num_parms(args)>=6) {
968 getfloor(&flbuf,extract_int(args,5));
969 if ((flbuf.f_flags & F_INUSE) == 0) {
970 cprintf("%d Invalid floor number.\n",
971 ERROR+INVALID_FLOOR_OPERATION);
976 lgetroom(&CC->quickroom, CC->quickroom.QRname);
977 extract(buf,args,0); buf[ROOMNAMELEN]=0;
978 strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
979 extract(buf,args,1); buf[10]=0;
980 strncpy(CC->quickroom.QRpasswd,buf,9);
981 extract(buf,args,2); buf[15]=0;
982 strncpy(CC->quickroom.QRdirname,buf,19);
983 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
985 /* Clean up a client boo-boo: if the client set the room to
986 * guess-name or passworded, ensure that the private flag is
989 if ((CC->quickroom.QRflags & QR_GUESSNAME)
990 ||(CC->quickroom.QRflags & QR_PASSWORDED))
991 CC->quickroom.QRflags |= QR_PRIVATE;
993 /* Kick everyone out if the client requested it (by changing the
994 * room's generation number)
996 if (extract_int(args,4)) {
997 time(&CC->quickroom.QRgen);
1000 old_floor = CC->quickroom.QRfloor;
1001 if (num_parms(args)>=6) {
1002 CC->quickroom.QRfloor = extract_int(args,5);
1005 lputroom(&CC->quickroom, CC->quickroom.QRname);
1007 /* adjust the floor reference counts */
1008 lgetfloor(&flbuf,old_floor);
1009 --flbuf.f_ref_count;
1010 lputfloor(&flbuf,old_floor);
1011 lgetfloor(&flbuf,CC->quickroom.QRfloor);
1012 ++flbuf.f_ref_count;
1013 lputfloor(&flbuf,CC->quickroom.QRfloor);
1015 /* create a room directory if necessary */
1016 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1018 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1019 CC->quickroom.QRdirname);
1023 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
1025 cprintf("%d Ok\n",OK);
1031 * get the name of the room aide for this room
1033 void cmd_geta(void) {
1034 struct usersupp usbuf;
1036 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
1037 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1041 if (is_noneditable(&CC->quickroom)) {
1042 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1046 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
1047 cprintf("%d %s\n",OK,usbuf.fullname);
1050 cprintf("%d \n",OK);
1056 * set the room aide for this room
1058 void cmd_seta(char *new_ra)
1060 struct usersupp usbuf;
1065 if (!(CC->logged_in)) {
1066 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1070 if (!is_room_aide()) {
1071 cprintf("%d Higher access required.\n",
1072 ERROR+HIGHER_ACCESS_REQUIRED);
1076 if (getuser(&usbuf,new_ra)!=0) {
1080 newu = usbuf.usernum;
1083 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1085 if (CC->quickroom.QRroomaide != newu) {
1088 CC->quickroom.QRroomaide = newu;
1089 lputroom(&CC->quickroom, CC->quickroom.QRname);
1092 * We have to post the change notice _after_ writing changes to
1093 * the room table, otherwise it would deadlock!
1095 if (post_notice == 1) {
1096 sprintf(buf,"%s is now room aide for %s>",
1097 usbuf.fullname,CC->quickroom.QRname);
1100 cprintf("%d Ok\n",OK);
1104 * Generate an associated file name for a room
1106 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
1109 sprintf(buf, "./prefix/%s.%ld", qrbuf->QRname, qrbuf->QRgen);
1110 for (a=0; a<strlen(buf); ++a) {
1111 if (buf[a]==32) buf[a]='.';
1116 * retrieve info file for this room
1118 void cmd_rinf(void) {
1123 assoc_file_name(filename, &CC->quickroom, "info");
1124 info_fp = fopen(filename,"r");
1126 if (info_fp==NULL) {
1127 cprintf("%d No info file.\n",ERROR);
1131 cprintf("%d Info:\n",LISTING_FOLLOWS);
1132 while (fgets(buf, 256, info_fp) != NULL) {
1133 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1134 cprintf("%s\n", buf);
1141 * Back end processing to delete a room and everything associated with it
1143 void delete_room(struct quickroom *qrbuf) {
1149 /* Delete the info file */
1150 assoc_file_name(aaa, qrbuf, "info");
1153 /* Delete the image file */
1154 assoc_file_name(aaa, qrbuf, "images");
1157 /* first flag the room record as not in use */
1158 lgetroom(qrbuf, qrbuf->QRname);
1161 /* then delete the messages in the room */
1163 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1164 MsgToDelete = MessageFromList(a);
1165 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1171 delete_msglist(qrbuf);
1172 lputroom(qrbuf, qrbuf->QRname);
1174 /* then decrement the reference count for the floor */
1175 lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
1176 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1177 lputfloor(&flbuf,(int)(qrbuf->QRfloor));
1179 /* Delete the room record from the database! */
1180 putroom(NULL, qrbuf->QRname);
1185 * aide command: kill the current room
1187 void cmd_kill(char *argbuf) {
1189 char deleted_room_name[ROOMNAMELEN];
1192 kill_ok = extract_int(argbuf,0);
1194 if (!(CC->logged_in)) {
1195 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1199 if (!is_room_aide()) {
1200 cprintf("%d Higher access required.\n",
1201 ERROR+HIGHER_ACCESS_REQUIRED);
1205 if (is_noneditable(&CC->quickroom)) {
1206 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1211 strcpy(deleted_room_name, CC->quickroom.QRname);
1212 delete_room(&CC->quickroom); /* Do the dirty work */
1213 usergoto(BASEROOM, 0); /* Return to the Lobby */
1215 /* tell the world what we did */
1216 sprintf(aaa,"%s> killed by %s",
1217 deleted_room_name, CC->curr_user);
1219 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1222 cprintf("%d ok to delete.\n",OK);
1228 * Internal code to create a new room (returns room flags)
1230 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1232 unsigned create_room(char *new_room_name,
1234 char *new_room_pass,
1235 int new_room_floor) {
1237 struct quickroom qrbuf;
1241 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1243 memset(&qrbuf, 0, sizeof(struct quickroom));
1244 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1245 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1246 qrbuf.QRflags = QR_INUSE;
1247 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1248 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1249 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1250 if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
1252 /* If the room is private, and the system administrator has elected
1253 * to automatically grant room aide privileges, do so now; otherwise,
1254 * set the room aide to undefined.
1256 if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) {
1257 qrbuf.QRroomaide=CC->usersupp.usernum;
1260 qrbuf.QRroomaide = (-1L);
1263 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1264 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1265 qrbuf.QRfloor = new_room_floor;
1267 /* save what we just did... */
1268 putroom(&qrbuf, qrbuf.QRname);
1270 /* bump the reference count on whatever floor the room is on */
1271 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1272 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1273 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1275 /* be sure not to kick the creator out of the room! */
1276 lgetuser(&CC->usersupp,CC->curr_user);
1277 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1278 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1279 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1280 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1281 lputuser(&CC->usersupp,CC->curr_user);
1283 /* resume our happy day */
1284 return(qrbuf.QRflags);
1291 void cmd_cre8(char *args)
1294 char new_room_name[256];
1296 char new_room_pass[256];
1300 struct quickroom qrbuf;
1303 cre8_ok = extract_int(args,0);
1304 extract(new_room_name,args,1);
1305 new_room_name[ROOMNAMELEN-1] = 0;
1306 new_room_type = extract_int(args,2);
1307 extract(new_room_pass,args,3);
1308 new_room_pass[9] = 0;
1311 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1312 cprintf("%d Invalid room name.\n",ERROR);
1316 if (num_parms(args)>=5) {
1317 getfloor(&flbuf,extract_int(args,4));
1318 if ((flbuf.f_flags & F_INUSE) == 0) {
1319 cprintf("%d Invalid floor number.\n",
1320 ERROR+INVALID_FLOOR_OPERATION);
1324 new_room_floor = extract_int(args,4);
1328 if (!(CC->logged_in)) {
1329 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1333 if (CC->usersupp.axlevel<3) {
1334 cprintf("%d You need higher access to create rooms.\n",
1335 ERROR+HIGHER_ACCESS_REQUIRED);
1339 if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
1340 cprintf("%d Ok to create rooms.\n", OK);
1344 /* Check to make sure the requested room name doesn't already exist */
1345 if (getroom(&qrbuf, new_room_name)==0) {
1346 cprintf("%d '%s' already exists.\n",
1347 ERROR,qrbuf.QRname);
1351 if ((new_room_type < 0) || (new_room_type > 3)) {
1352 cprintf("%d Invalid room type.\n",ERROR);
1357 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1361 newflags = create_room(new_room_name,
1362 new_room_type,new_room_pass,new_room_floor);
1364 /* post a message in Aide> describing the new room */
1365 strncpy(aaa,new_room_name,255);
1366 strcat(aaa,"> created by ");
1367 strcat(aaa,CC->usersupp.fullname);
1368 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1369 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1370 if (newflags&QR_PASSWORDED) {
1371 strcat(aaa,"\n Password: ");
1372 strcat(aaa,new_room_pass);
1376 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1381 void cmd_einf(char *ok)
1382 { /* enter info file for current room */
1384 char infofilename[64];
1387 if (!(CC->logged_in)) {
1388 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1392 if (!is_room_aide()) {
1393 cprintf("%d Higher access required.\n",
1394 ERROR+HIGHER_ACCESS_REQUIRED);
1399 cprintf("%d Ok.\n",OK);
1403 cprintf("%d Send info...\n",SEND_LISTING);
1405 assoc_file_name(infofilename, &CC->quickroom, "info");
1407 fp=fopen(infofilename,"w");
1410 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1411 } while(strcmp(buf,"000"));
1414 /* now update the room index so people will see our new info */
1415 lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */
1416 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1417 lputroom(&CC->quickroom,CC->quickroom.QRname);
1422 * cmd_lflr() - List all known floors
1424 void cmd_lflr(void) {
1428 if (!(CC->logged_in)) {
1429 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1433 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1434 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1439 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1441 for (a=0; a<MAXFLOORS; ++a) {
1443 if (flbuf.f_flags & F_INUSE) {
1444 cprintf("%d|%s|%d\n",
1456 * create a new floor
1458 void cmd_cflr(char *argbuf)
1460 char new_floor_name[256];
1463 int free_slot = (-1);
1466 extract(new_floor_name,argbuf,0);
1467 cflr_ok = extract_int(argbuf,1);
1470 if (!(CC->logged_in)) {
1471 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1475 if (CC->usersupp.axlevel<6) {
1476 cprintf("%d You need higher access to create rooms.\n",
1477 ERROR+HIGHER_ACCESS_REQUIRED);
1481 for (a=0; a<MAXFLOORS; ++a) {
1484 /* note any free slots while we're scanning... */
1485 if ( ((flbuf.f_flags & F_INUSE)==0)
1486 && (free_slot < 0) ) free_slot = a;
1488 /* check to see if it already exists */
1489 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1490 && (flbuf.f_flags & F_INUSE) ) {
1491 cprintf("%d Floor '%s' already exists.\n",
1492 ERROR+ALREADY_EXISTS,
1500 cprintf("%d There is no space available for a new floor.\n",
1501 ERROR+INVALID_FLOOR_OPERATION);
1506 cprintf("%d ok to create...\n",OK);
1510 lgetfloor(&flbuf,free_slot);
1511 flbuf.f_flags = F_INUSE;
1512 flbuf.f_ref_count = 0;
1513 strncpy(flbuf.f_name,new_floor_name,255);
1514 lputfloor(&flbuf,free_slot);
1515 cprintf("%d %d\n",OK,free_slot);
1523 void cmd_kflr(char *argbuf)
1526 int floor_to_delete;
1530 floor_to_delete = extract_int(argbuf,0);
1531 kflr_ok = extract_int(argbuf,1);
1534 if (!(CC->logged_in)) {
1535 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1539 if (CC->usersupp.axlevel<6) {
1540 cprintf("%d You need higher access to delete floors.\n",
1541 ERROR+HIGHER_ACCESS_REQUIRED);
1545 lgetfloor(&flbuf,floor_to_delete);
1548 if ((flbuf.f_flags & F_INUSE) == 0) {
1549 cprintf("%d Floor %d not in use.\n",
1550 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1555 if (flbuf.f_ref_count != 0) {
1556 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1557 ERROR+INVALID_FLOOR_OPERATION,
1564 cprintf("%d Ok\n",OK);
1567 cprintf("%d Ok to delete...\n",OK);
1574 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1575 lputfloor(&flbuf,floor_to_delete);
1581 void cmd_eflr(char *argbuf)
1587 np = num_parms(argbuf);
1589 cprintf("%d Usage error.\n",ERROR);
1593 if (!(CC->logged_in)) {
1594 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1598 if (CC->usersupp.axlevel<6) {
1599 cprintf("%d You need higher access to edit floors.\n",
1600 ERROR+HIGHER_ACCESS_REQUIRED);
1604 floor_num = extract_int(argbuf,0);
1605 lgetfloor(&flbuf,floor_num);
1606 if ( (flbuf.f_flags & F_INUSE) == 0) {
1607 lputfloor(&flbuf,floor_num);
1608 cprintf("%d Floor %d is not in use.\n",
1609 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1612 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1613 lputfloor(&flbuf,floor_num);
1615 cprintf("%d Ok\n",OK);