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 if (userbuf->axlevel >= 6) {
47 retval = UA_KNOWN | UA_GOTOALLOWED;
55 /* For mailboxes, we skip all the access stuff (and we've
56 * already checked by this point that the mailbox belongs
59 if (roombuf->QRflags & QR_MAILBOX) {
60 retval = UA_KNOWN | UA_GOTOALLOWED;
64 /* If this is a public room, it's accessible... */
65 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
66 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
69 /* If this is a preferred users only room, check access level */
70 if (roombuf->QRflags & QR_PREFONLY) {
71 if (userbuf->axlevel < 5) {
72 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
76 /* For private rooms, check the generation number matchups */
77 if (roombuf->QRflags & QR_PRIVATE) {
79 /* An explicit match means the user belongs in this room */
80 if (vbuf.v_flags & V_ACCESS) {
81 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
83 /* Otherwise, check if this is a guess-name or passworded
84 * room. If it is, a goto may at least be attempted
86 else if ((roombuf->QRflags & QR_PRIVATE)
87 ||(roombuf->QRflags & QR_PASSWORDED)) {
88 retval = retval & ~UA_KNOWN;
89 retval = retval | UA_GOTOALLOWED;
93 /* Check to see if the user has forgotten this room */
94 if (vbuf.v_flags & V_FORGET) {
95 retval = retval & ~UA_KNOWN;
96 retval = retval | UA_ZAPPED;
99 /* If user is explicitly locked out of this room, deny everything */
100 if (vbuf.v_flags & V_LOCKOUT) {
101 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
104 /* Aides get access to everything */
105 if (userbuf->axlevel >= 6) {
106 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
107 retval = retval & ~UA_ZAPPED;
110 NEWMSG: /* By the way, we also check for the presence of new messages */
111 if ( (roombuf->QRhighest) > (vbuf.v_lastseen) ) {
112 retval = retval | UA_HASNEWMSGS;
119 * getroom() - retrieve room data from disk
121 int getroom(struct quickroom *qrbuf, char *room_name)
123 struct cdbdata *cdbqr;
124 char lowercase_name[ROOMNAMELEN];
127 for (a=0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
128 lowercase_name[a] = tolower(room_name[a]);
130 lowercase_name[a] = 0;
132 memset(qrbuf, 0, sizeof(struct quickroom));
133 cdbqr = cdb_fetch(CDB_QUICKROOM,
134 lowercase_name, strlen(lowercase_name));
136 memcpy(qrbuf, cdbqr->ptr,
137 ( (cdbqr->len > sizeof(struct quickroom)) ?
138 sizeof(struct quickroom) : cdbqr->len) );
141 /* Mailbox rooms are always on the lowest floor */
142 if (qrbuf->QRflags & QR_MAILBOX) {
154 * lgetroom() - same as getroom() but locks the record (if supported)
156 int lgetroom(struct quickroom *qrbuf, char *room_name)
158 begin_critical_section(S_QUICKROOM);
159 return(getroom(qrbuf, room_name));
164 * putroom() - store room data on disk
165 * (if the supplied buffer is NULL, delete the room record)
167 void putroom(struct quickroom *qrbuf, char *room_name)
169 char lowercase_name[ROOMNAMELEN];
172 for (a=0; a<=strlen(room_name); ++a) {
173 lowercase_name[a] = tolower(room_name[a]);
177 cdb_delete(CDB_QUICKROOM,
178 lowercase_name, strlen(lowercase_name));
181 time(&qrbuf->QRmtime);
182 cdb_store(CDB_QUICKROOM,
183 lowercase_name, strlen(lowercase_name),
184 qrbuf, sizeof(struct quickroom));
190 * lputroom() - same as putroom() but unlocks the record (if supported)
192 void lputroom(struct quickroom *qrbuf, char *room_name)
195 putroom(qrbuf, room_name);
196 end_critical_section(S_QUICKROOM);
200 /****************************************************************************/
203 * getfloor() - retrieve floor data from disk
205 void getfloor(struct floor *flbuf, int floor_num)
207 struct cdbdata *cdbfl;
209 memset(flbuf, 0, sizeof(struct floor));
210 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
212 memcpy(flbuf, cdbfl->ptr,
213 ( (cdbfl->len > sizeof(struct floor)) ?
214 sizeof(struct floor) : cdbfl->len) );
218 if (floor_num == 0) {
219 strcpy(flbuf->f_name, "Main Floor");
220 flbuf->f_flags = F_INUSE;
221 flbuf->f_ref_count = 3;
228 * lgetfloor() - same as getfloor() but locks the record (if supported)
230 void lgetfloor(struct floor *flbuf, int floor_num)
233 begin_critical_section(S_FLOORTAB);
234 getfloor(flbuf,floor_num);
239 * putfloor() - store floor data on disk
241 void putfloor(struct floor *flbuf, int floor_num)
243 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
244 flbuf, sizeof(struct floor));
249 * lputfloor() - same as putfloor() but unlocks the record (if supported)
251 void lputfloor(struct floor *flbuf, int floor_num)
254 putfloor(flbuf,floor_num);
255 end_critical_section(S_FLOORTAB);
261 * Traverse the room file...
263 void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) {
264 struct quickroom qrbuf;
265 struct cdbdata *cdbqr;
267 cdb_rewind(CDB_QUICKROOM);
269 while(cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
270 memset(&qrbuf, 0, sizeof(struct quickroom));
271 memcpy(&qrbuf, cdbqr->ptr,
272 ( (cdbqr->len > sizeof(struct quickroom)) ?
273 sizeof(struct quickroom) : cdbqr->len) );
275 if (qrbuf.QRflags & QR_INUSE) (*CallBack)(&qrbuf);
282 * Create a database key for storage of message lists
284 void msglist_key(char *dbkey, struct quickroom *whichroom) {
287 sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
288 for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
292 * get_msglist() - retrieve room message pointers
294 void get_msglist(struct quickroom *whichroom) {
295 struct cdbdata *cdbfr;
298 msglist_key(dbkey, whichroom);
300 if (CC->msglist != NULL) {
306 cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey));
311 CC->msglist = malloc(cdbfr->len);
312 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
313 CC->num_msgs = cdbfr->len / sizeof(long);
319 * put_msglist() - retrieve room message pointers
321 void put_msglist(struct quickroom *whichroom) {
324 msglist_key(dbkey, whichroom);
325 cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey),
326 CC->msglist, CC->num_msgs * sizeof(long));
331 * delete_msglist() - delete room message pointers
332 * FIX - this really should check first to make sure there's actually a
333 * msglist to delete. As things stand now, calling this function on
334 * a room which has never been posted in will result in a message
335 * like "gdbm: illegal data" (no big deal, but could use fixing).
337 void delete_msglist(struct quickroom *whichroom) {
340 msglist_key(dbkey, whichroom);
341 cdb_delete(CDB_MSGLISTS, dbkey, strlen(dbkey));
346 * Add a message number to a room's message list.
347 * So, why doesn't this function use the get_msglist() and put_msglist() stuff
348 * defined above? Because the room the message number is being written to
349 * may not be the current room (as is the case with cmd_move() for example).
351 void AddMessageToRoom(struct quickroom *whichroom, long newmsgid) {
353 struct cdbdata *cdbfr;
357 msglist_key(dbkey, whichroom);
358 cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey));
364 msglist = malloc(cdbfr->len);
365 num_msgs = cdbfr->len / sizeof(long);
366 memcpy(msglist, cdbfr->ptr, cdbfr->len);
370 /* Now add the new message */
372 msglist = realloc(msglist,
373 (num_msgs * sizeof(long)) );
375 if (msglist == NULL) {
376 lprintf(3, "ERROR: can't realloc message list!\n");
379 msglist[num_msgs - 1] = newmsgid;
381 /* Write it back to disk. */
382 cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey),
383 msglist, num_msgs * sizeof(long));
385 /* And finally, free up the memory we used. */
391 * MessageFromList() - get a message number from the list currently in memory
393 long MessageFromList(int whichpos) {
395 /* Return zero if the position is invalid */
396 if (whichpos >= CC->num_msgs) return 0L;
398 return(CC->msglist[whichpos]);
402 * SetMessageInList() - set a message number in the list currently in memory
404 void SetMessageInList(int whichpos, long newmsgnum) {
406 /* Return zero if the position is invalid */
407 if (whichpos >= CC->num_msgs) return;
409 CC->msglist[whichpos] = newmsgnum;
415 * sort message pointers
416 * (returns new msg count)
418 int sort_msglist(long listptrs[], int oldcount)
425 if (numitems < 2) return(oldcount);
428 for (a=numitems-2; a>=0; --a) {
429 for (b=0; b<=a; ++b) {
430 if (listptrs[b] > (listptrs[b+1])) {
432 hold2 = listptrs[b+1];
434 listptrs[b+1] = hold1;
439 /* and yank any nulls */
440 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
441 memcpy(&listptrs[0], &listptrs[1],
442 (sizeof(long) * (CC->num_msgs - 1)) );
451 * Determine whether a given room is non-editable.
453 int is_noneditable(struct quickroom *qrbuf) {
455 /* Lobby> and Aide> are non-editable */
456 if (!strcasecmp(qrbuf->QRname, BASEROOM)) return(1);
457 else if (!strcasecmp(qrbuf->QRname, AIDEROOM)) return(1);
459 /* Mailbox rooms are also non-editable */
460 else if (qrbuf->QRflags & QR_MAILBOX) return(1);
462 /* Everything else is editable */
469 * Back-back-end for all room listing commands
471 void list_roomname(struct quickroom *qrbuf) {
472 char truncated_roomname[ROOMNAMELEN];
474 /* For mailbox rooms, chop off the owner prefix */
475 if (qrbuf->QRflags & QR_MAILBOX) {
476 strcpy(truncated_roomname, qrbuf->QRname);
477 strcpy(truncated_roomname, &truncated_roomname[11]);
478 cprintf("%s", truncated_roomname);
480 /* For all other rooms, just display the name in its entirety */
482 cprintf("%s", qrbuf->QRname);
485 /* ...and now the other parameters */
487 qrbuf->QRflags,qrbuf->QRfloor);
492 * cmd_lrms() - List all accessible rooms, known or forgotten
494 void cmd_lrms_backend(struct quickroom *qrbuf) {
495 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
496 & (UA_KNOWN | UA_ZAPPED)))
497 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
498 ||((CC->FloorBeingSearched)<0)) )
499 list_roomname(qrbuf);
502 void cmd_lrms(char *argbuf)
504 CC->FloorBeingSearched = (-1);
505 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
507 if (!(CC->logged_in)) {
508 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
512 if (getuser(&CC->usersupp,CC->curr_user)) {
513 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
517 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
519 ForEachRoom(cmd_lrms_backend);
526 * cmd_lkra() - List all known rooms
528 void cmd_lkra_backend(struct quickroom *qrbuf) {
529 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
531 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
532 ||((CC->FloorBeingSearched)<0)) )
533 list_roomname(qrbuf);
536 void cmd_lkra(char *argbuf)
538 CC->FloorBeingSearched = (-1);
539 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
541 if (!(CC->logged_in)) {
542 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
546 if (getuser(&CC->usersupp,CC->curr_user)) {
547 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
551 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
553 ForEachRoom(cmd_lkra_backend);
560 * cmd_lkrn() - List all known rooms with new messages
562 void cmd_lkrn_backend(struct quickroom *qrbuf) {
565 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
567 && (ra & UA_HASNEWMSGS)
568 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
569 ||((CC->FloorBeingSearched)<0)) )
570 list_roomname(qrbuf);
573 void cmd_lkrn(char *argbuf)
575 CC->FloorBeingSearched = (-1);
576 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
578 if (!(CC->logged_in)) {
579 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
583 if (getuser(&CC->usersupp,CC->curr_user)) {
584 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
588 cprintf("%d Rooms w/ new msgs:\n",LISTING_FOLLOWS);
590 ForEachRoom(cmd_lkrn_backend);
597 * cmd_lkro() - List all known rooms
599 void cmd_lkro_backend(struct quickroom *qrbuf) {
602 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
604 && ((ra & UA_HASNEWMSGS)==0)
605 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
606 ||((CC->FloorBeingSearched)<0)) )
607 list_roomname(qrbuf);
610 void cmd_lkro(char *argbuf)
612 CC->FloorBeingSearched = (-1);
613 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
615 if (!(CC->logged_in)) {
616 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
620 if (getuser(&CC->usersupp,CC->curr_user)) {
621 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
625 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
627 ForEachRoom(cmd_lkro_backend);
634 * cmd_lzrm() - List all forgotten rooms
636 void cmd_lzrm_backend(struct quickroom *qrbuf) {
639 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
640 if ( (ra & UA_GOTOALLOWED)
642 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
643 ||((CC->FloorBeingSearched)<0)) )
644 list_roomname(qrbuf);
647 void cmd_lzrm(char *argbuf)
649 CC->FloorBeingSearched = (-1);
650 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
652 if (!(CC->logged_in)) {
653 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
657 if (getuser(&CC->usersupp,CC->curr_user)) {
658 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
662 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
664 ForEachRoom(cmd_lzrm_backend);
670 void usergoto(char *where, int display_result)
673 int new_messages = 0;
674 int total_messages = 0;
678 int newmailcount = 0;
680 char truncated_roomname[ROOMNAMELEN];
682 strcpy(CC->quickroom.QRname, where);
683 getroom(&CC->quickroom, where);
684 lgetuser(&CC->usersupp,CC->curr_user);
685 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
687 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
688 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
690 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
691 lputuser(&CC->usersupp,CC->curr_user);
693 /* check for new mail */
694 newmailcount = NewMailCount();
696 /* set info to 1 if the user needs to read the room's info file */
697 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
700 get_msglist(&CC->quickroom);
701 for (a=0; a<CC->num_msgs; ++a) {
702 if (MessageFromList(a)>0L) {
704 if (MessageFromList(a) > vbuf.v_lastseen) {
710 if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1;
713 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
714 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
717 strcpy(truncated_roomname, CC->quickroom.QRname);
718 if (CC->quickroom.QRflags & QR_MAILBOX) {
719 strcpy(truncated_roomname, &truncated_roomname[11]);
722 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
725 new_messages, total_messages,
726 info,CC->quickroom.QRflags,
727 CC->quickroom.QRhighest,
729 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
731 set_wtmpsupp_to_current_room();
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) {
949 char old_name[ROOMNAMELEN];
952 if (!(CC->logged_in)) {
953 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
957 if (!is_room_aide()) {
958 cprintf("%d Higher access required.\n",
959 ERROR+HIGHER_ACCESS_REQUIRED);
963 if (is_noneditable(&CC->quickroom)) {
964 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
968 if (num_parms(args)>=6) {
969 getfloor(&flbuf,extract_int(args,5));
970 if ((flbuf.f_flags & F_INUSE) == 0) {
971 cprintf("%d Invalid floor number.\n",
972 ERROR+INVALID_FLOOR_OPERATION);
977 lgetroom(&CC->quickroom, CC->quickroom.QRname);
978 strcpy(old_name, CC->quickroom.QRname);
979 extract(buf,args,0); buf[ROOMNAMELEN]=0;
980 strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
981 extract(buf,args,1); buf[10]=0;
982 strncpy(CC->quickroom.QRpasswd,buf,9);
983 extract(buf,args,2); buf[15]=0;
984 strncpy(CC->quickroom.QRdirname,buf,19);
985 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
987 /* Clean up a client boo-boo: if the client set the room to
988 * guess-name or passworded, ensure that the private flag is
991 if ((CC->quickroom.QRflags & QR_GUESSNAME)
992 ||(CC->quickroom.QRflags & QR_PASSWORDED))
993 CC->quickroom.QRflags |= QR_PRIVATE;
995 /* Kick everyone out if the client requested it (by changing the
996 * room's generation number)
998 if (extract_int(args,4)) {
999 time(&CC->quickroom.QRgen);
1002 old_floor = CC->quickroom.QRfloor;
1003 if (num_parms(args)>=6) {
1004 CC->quickroom.QRfloor = extract_int(args,5);
1007 /* Write the room record back to disk */
1008 lputroom(&CC->quickroom, CC->quickroom.QRname);
1010 /* If the room name changed, then there are now two room records,
1011 * so we have to delete the old one.
1013 /* FIX - This causes everybody to think it's a new room, because the
1014 * visit structs no longer match! Major problem! We have to
1015 * assign each room a unique Object ID and index by that.
1017 if (strcasecmp(CC->quickroom.QRname, old_name)) {
1018 putroom(NULL, old_name);
1021 /* adjust the floor reference counts */
1022 lgetfloor(&flbuf,old_floor);
1023 --flbuf.f_ref_count;
1024 lputfloor(&flbuf,old_floor);
1025 lgetfloor(&flbuf,CC->quickroom.QRfloor);
1026 ++flbuf.f_ref_count;
1027 lputfloor(&flbuf,CC->quickroom.QRfloor);
1029 /* create a room directory if necessary */
1030 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1032 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1033 CC->quickroom.QRdirname);
1037 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
1039 cprintf("%d Ok\n",OK);
1045 * get the name of the room aide for this room
1047 void cmd_geta(void) {
1048 struct usersupp usbuf;
1050 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
1051 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1055 if (is_noneditable(&CC->quickroom)) {
1056 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1060 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
1061 cprintf("%d %s\n",OK,usbuf.fullname);
1064 cprintf("%d \n",OK);
1070 * set the room aide for this room
1072 void cmd_seta(char *new_ra)
1074 struct usersupp usbuf;
1079 if (!(CC->logged_in)) {
1080 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1084 if (!is_room_aide()) {
1085 cprintf("%d Higher access required.\n",
1086 ERROR+HIGHER_ACCESS_REQUIRED);
1090 if (getuser(&usbuf,new_ra)!=0) {
1094 newu = usbuf.usernum;
1097 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1099 if (CC->quickroom.QRroomaide != newu) {
1102 CC->quickroom.QRroomaide = newu;
1103 lputroom(&CC->quickroom, CC->quickroom.QRname);
1106 * We have to post the change notice _after_ writing changes to
1107 * the room table, otherwise it would deadlock!
1109 if (post_notice == 1) {
1110 sprintf(buf,"%s is now room aide for %s>",
1111 usbuf.fullname,CC->quickroom.QRname);
1114 cprintf("%d Ok\n",OK);
1118 * Generate an associated file name for a room
1120 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
1123 sprintf(buf, "./prefix/%s.%ld", qrbuf->QRname, qrbuf->QRgen);
1124 for (a=0; a<strlen(buf); ++a) {
1125 if (buf[a]==32) buf[a]='.';
1130 * retrieve info file for this room
1132 void cmd_rinf(void) {
1137 assoc_file_name(filename, &CC->quickroom, "info");
1138 info_fp = fopen(filename,"r");
1140 if (info_fp==NULL) {
1141 cprintf("%d No info file.\n",ERROR);
1145 cprintf("%d Info:\n",LISTING_FOLLOWS);
1146 while (fgets(buf, 256, info_fp) != NULL) {
1147 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1148 cprintf("%s\n", buf);
1155 * Back end processing to delete a room and everything associated with it
1157 void delete_room(struct quickroom *qrbuf) {
1163 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1165 /* Delete the info file */
1166 assoc_file_name(aaa, qrbuf, "info");
1169 /* Delete the image file */
1170 assoc_file_name(aaa, qrbuf, "images");
1173 /* first flag the room record as not in use */
1174 lgetroom(qrbuf, qrbuf->QRname);
1177 /* then delete the messages in the room */
1179 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1180 MsgToDelete = MessageFromList(a);
1181 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1187 delete_msglist(qrbuf);
1188 lputroom(qrbuf, qrbuf->QRname);
1190 /* then decrement the reference count for the floor */
1191 lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
1192 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1193 lputfloor(&flbuf,(int)(qrbuf->QRfloor));
1195 /* Delete the room record from the database! */
1196 putroom(NULL, qrbuf->QRname);
1201 * aide command: kill the current room
1203 void cmd_kill(char *argbuf) {
1205 char deleted_room_name[ROOMNAMELEN];
1208 kill_ok = extract_int(argbuf,0);
1210 if (!(CC->logged_in)) {
1211 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1215 if (!is_room_aide()) {
1216 cprintf("%d Higher access required.\n",
1217 ERROR+HIGHER_ACCESS_REQUIRED);
1221 if (is_noneditable(&CC->quickroom)) {
1222 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1227 strcpy(deleted_room_name, CC->quickroom.QRname);
1228 delete_room(&CC->quickroom); /* Do the dirty work */
1229 usergoto(BASEROOM, 0); /* Return to the Lobby */
1231 /* tell the world what we did */
1232 sprintf(aaa,"%s> killed by %s",
1233 deleted_room_name, CC->curr_user);
1235 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1238 cprintf("%d ok to delete.\n",OK);
1244 * Internal code to create a new room (returns room flags)
1246 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1248 unsigned create_room(char *new_room_name,
1250 char *new_room_pass,
1251 int new_room_floor) {
1253 struct quickroom qrbuf;
1257 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1259 memset(&qrbuf, 0, sizeof(struct quickroom));
1260 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1261 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1262 qrbuf.QRflags = QR_INUSE;
1263 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1264 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1265 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1266 if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
1268 /* If the room is private, and the system administrator has elected
1269 * to automatically grant room aide privileges, do so now; otherwise,
1270 * set the room aide to undefined.
1272 if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) {
1273 qrbuf.QRroomaide=CC->usersupp.usernum;
1276 qrbuf.QRroomaide = (-1L);
1279 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1280 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1281 qrbuf.QRfloor = new_room_floor;
1283 /* save what we just did... */
1284 putroom(&qrbuf, qrbuf.QRname);
1286 /* bump the reference count on whatever floor the room is on */
1287 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1288 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1289 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1291 /* be sure not to kick the creator out of the room! */
1292 lgetuser(&CC->usersupp,CC->curr_user);
1293 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1294 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1295 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1296 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1297 lputuser(&CC->usersupp,CC->curr_user);
1299 /* resume our happy day */
1300 return(qrbuf.QRflags);
1307 void cmd_cre8(char *args)
1310 char new_room_name[256];
1312 char new_room_pass[256];
1316 struct quickroom qrbuf;
1319 cre8_ok = extract_int(args,0);
1320 extract(new_room_name,args,1);
1321 new_room_name[ROOMNAMELEN-1] = 0;
1322 new_room_type = extract_int(args,2);
1323 extract(new_room_pass,args,3);
1324 new_room_pass[9] = 0;
1327 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1328 cprintf("%d Invalid room name.\n",ERROR);
1332 if (num_parms(args)>=5) {
1333 getfloor(&flbuf,extract_int(args,4));
1334 if ((flbuf.f_flags & F_INUSE) == 0) {
1335 cprintf("%d Invalid floor number.\n",
1336 ERROR+INVALID_FLOOR_OPERATION);
1340 new_room_floor = extract_int(args,4);
1344 if (!(CC->logged_in)) {
1345 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1349 if (CC->usersupp.axlevel<3) {
1350 cprintf("%d You need higher access to create rooms.\n",
1351 ERROR+HIGHER_ACCESS_REQUIRED);
1355 if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
1356 cprintf("%d Ok to create rooms.\n", OK);
1360 /* Check to make sure the requested room name doesn't already exist */
1361 if (getroom(&qrbuf, new_room_name)==0) {
1362 cprintf("%d '%s' already exists.\n",
1363 ERROR,qrbuf.QRname);
1367 if ((new_room_type < 0) || (new_room_type > 3)) {
1368 cprintf("%d Invalid room type.\n",ERROR);
1373 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1377 newflags = create_room(new_room_name,
1378 new_room_type,new_room_pass,new_room_floor);
1380 /* post a message in Aide> describing the new room */
1381 strncpy(aaa,new_room_name,255);
1382 strcat(aaa,"> created by ");
1383 strcat(aaa,CC->usersupp.fullname);
1384 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1385 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1386 if (newflags&QR_PASSWORDED) {
1387 strcat(aaa,"\n Password: ");
1388 strcat(aaa,new_room_pass);
1392 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1397 void cmd_einf(char *ok)
1398 { /* enter info file for current room */
1400 char infofilename[64];
1403 if (!(CC->logged_in)) {
1404 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1408 if (!is_room_aide()) {
1409 cprintf("%d Higher access required.\n",
1410 ERROR+HIGHER_ACCESS_REQUIRED);
1415 cprintf("%d Ok.\n",OK);
1419 cprintf("%d Send info...\n",SEND_LISTING);
1421 assoc_file_name(infofilename, &CC->quickroom, "info");
1423 fp=fopen(infofilename,"w");
1426 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1427 } while(strcmp(buf,"000"));
1430 /* now update the room index so people will see our new info */
1431 lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */
1432 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1433 lputroom(&CC->quickroom,CC->quickroom.QRname);
1438 * cmd_lflr() - List all known floors
1440 void cmd_lflr(void) {
1444 if (!(CC->logged_in)) {
1445 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1449 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1450 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1455 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1457 for (a=0; a<MAXFLOORS; ++a) {
1459 if (flbuf.f_flags & F_INUSE) {
1460 cprintf("%d|%s|%d\n",
1472 * create a new floor
1474 void cmd_cflr(char *argbuf)
1476 char new_floor_name[256];
1479 int free_slot = (-1);
1482 extract(new_floor_name,argbuf,0);
1483 cflr_ok = extract_int(argbuf,1);
1486 if (!(CC->logged_in)) {
1487 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1491 if (CC->usersupp.axlevel<6) {
1492 cprintf("%d You need higher access to create rooms.\n",
1493 ERROR+HIGHER_ACCESS_REQUIRED);
1497 for (a=0; a<MAXFLOORS; ++a) {
1500 /* note any free slots while we're scanning... */
1501 if ( ((flbuf.f_flags & F_INUSE)==0)
1502 && (free_slot < 0) ) free_slot = a;
1504 /* check to see if it already exists */
1505 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1506 && (flbuf.f_flags & F_INUSE) ) {
1507 cprintf("%d Floor '%s' already exists.\n",
1508 ERROR+ALREADY_EXISTS,
1516 cprintf("%d There is no space available for a new floor.\n",
1517 ERROR+INVALID_FLOOR_OPERATION);
1522 cprintf("%d ok to create...\n",OK);
1526 lgetfloor(&flbuf,free_slot);
1527 flbuf.f_flags = F_INUSE;
1528 flbuf.f_ref_count = 0;
1529 strncpy(flbuf.f_name,new_floor_name,255);
1530 lputfloor(&flbuf,free_slot);
1531 cprintf("%d %d\n",OK,free_slot);
1539 void cmd_kflr(char *argbuf)
1542 int floor_to_delete;
1546 floor_to_delete = extract_int(argbuf,0);
1547 kflr_ok = extract_int(argbuf,1);
1550 if (!(CC->logged_in)) {
1551 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1555 if (CC->usersupp.axlevel<6) {
1556 cprintf("%d You need higher access to delete floors.\n",
1557 ERROR+HIGHER_ACCESS_REQUIRED);
1561 lgetfloor(&flbuf,floor_to_delete);
1564 if ((flbuf.f_flags & F_INUSE) == 0) {
1565 cprintf("%d Floor %d not in use.\n",
1566 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1571 if (flbuf.f_ref_count != 0) {
1572 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1573 ERROR+INVALID_FLOOR_OPERATION,
1580 cprintf("%d Ok\n",OK);
1583 cprintf("%d Ok to delete...\n",OK);
1590 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1591 lputfloor(&flbuf,floor_to_delete);
1597 void cmd_eflr(char *argbuf)
1603 np = num_parms(argbuf);
1605 cprintf("%d Usage error.\n",ERROR);
1609 if (!(CC->logged_in)) {
1610 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1614 if (CC->usersupp.axlevel<6) {
1615 cprintf("%d You need higher access to edit floors.\n",
1616 ERROR+HIGHER_ACCESS_REQUIRED);
1620 floor_num = extract_int(argbuf,0);
1621 lgetfloor(&flbuf,floor_num);
1622 if ( (flbuf.f_flags & F_INUSE) == 0) {
1623 lputfloor(&flbuf,floor_num);
1624 cprintf("%d Floor %d is not in use.\n",
1625 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1628 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1629 lputfloor(&flbuf,floor_num);
1631 cprintf("%d Ok\n",OK);