15 #include "sysdep_decls.h"
19 #include "serv_chat.h"
20 #include "citserver.h"
23 * Generic routine for determining user access to rooms
25 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf) {
29 /* for internal programs, always do everything */
30 if (((CC->internal_pgm))&&(roombuf->QRflags & QR_INUSE)) {
31 return(UA_KNOWN | UA_GOTOALLOWED);
34 /* For mailbox rooms, only allow access to the owner */
35 if (roombuf->QRflags & QR_MAILBOX) {
36 if (userbuf->usernum != atol(roombuf->QRname)) {
41 /* Locate any applicable user/room relationships */
42 CtdlGetRelationship(&vbuf, userbuf, roombuf);
44 /* Force the properties of the Aide room */
45 if (!strcasecmp(roombuf->QRname, AIDEROOM)) {
46 lprintf(9, "Room <%s> is special!\n", roombuf->QRname);
47 if (userbuf->axlevel >= 6) {
48 retval = UA_KNOWN | UA_GOTOALLOWED;
56 /* For mailboxes, we skip all the access stuff (and we've
57 * already checked by this point that the mailbox belongs
60 if (roombuf->QRflags & QR_MAILBOX) {
61 retval = UA_KNOWN | UA_GOTOALLOWED;
65 /* If this is a public room, it's accessible... */
66 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
67 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
70 /* If this is a preferred users only room, check access level */
71 if (roombuf->QRflags & QR_PREFONLY) {
72 if (userbuf->axlevel < 5) {
73 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
77 /* For private rooms, check the generation number matchups */
78 if (roombuf->QRflags & QR_PRIVATE) {
80 /* An explicit match means the user belongs in this room */
81 if (vbuf.v_flags & V_ACCESS) {
82 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
84 /* Otherwise, check if this is a guess-name or passworded
85 * room. If it is, a goto may at least be attempted
87 else if ((roombuf->QRflags & QR_PRIVATE)
88 ||(roombuf->QRflags & QR_PASSWORDED)) {
89 retval = retval & ~UA_KNOWN;
90 retval = retval | UA_GOTOALLOWED;
94 /* Check to see if the user has forgotten this room */
95 if (vbuf.v_flags & V_FORGET) {
96 retval = retval & ~UA_KNOWN;
97 retval = retval | UA_ZAPPED;
100 /* If user is explicitly locked out of this room, deny everything */
101 if (vbuf.v_flags & V_LOCKOUT) {
102 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
105 /* Aides get access to everything */
106 if (userbuf->axlevel >= 6) {
107 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
108 retval = retval & ~UA_ZAPPED;
111 NEWMSG: /* By the way, we also check for the presence of new messages */
112 if ( (roombuf->QRhighest) > (vbuf.v_lastseen) ) {
113 retval = retval | UA_HASNEWMSGS;
120 * getroom() - retrieve room data from disk
122 int getroom(struct quickroom *qrbuf, char *room_name)
124 struct cdbdata *cdbqr;
125 char lowercase_name[ROOMNAMELEN];
128 for (a=0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
129 lowercase_name[a] = tolower(room_name[a]);
131 lowercase_name[a] = 0;
133 memset(qrbuf, 0, sizeof(struct quickroom));
134 cdbqr = cdb_fetch(CDB_QUICKROOM,
135 lowercase_name, strlen(lowercase_name));
137 memcpy(qrbuf, cdbqr->ptr,
138 ( (cdbqr->len > sizeof(struct quickroom)) ?
139 sizeof(struct quickroom) : cdbqr->len) );
142 /*** FIX FIX FIX REMOVE THIS!!!! IT'S ONLY TO FIX A PROBLEM SPECIFIC TO UNCENSORED ***/
143 if (!strcasecmp(qrbuf->QRname, "Linux")) {
144 qrbuf->QRflags = qrbuf->QRflags & ~QR_MAILBOX;
157 * lgetroom() - same as getroom() but locks the record (if supported)
159 int lgetroom(struct quickroom *qrbuf, char *room_name)
161 begin_critical_section(S_QUICKROOM);
162 return(getroom(qrbuf, room_name));
167 * putroom() - store room data on disk
168 * (if the supplied buffer is NULL, delete the room record)
170 void putroom(struct quickroom *qrbuf, char *room_name)
172 char lowercase_name[ROOMNAMELEN];
175 for (a=0; a<=strlen(room_name); ++a) {
176 lowercase_name[a] = tolower(room_name[a]);
180 cdb_delete(CDB_QUICKROOM,
181 lowercase_name, strlen(lowercase_name));
184 time(&qrbuf->QRmtime);
185 cdb_store(CDB_QUICKROOM,
186 lowercase_name, strlen(lowercase_name),
187 qrbuf, sizeof(struct quickroom));
193 * lputroom() - same as putroom() but unlocks the record (if supported)
195 void lputroom(struct quickroom *qrbuf, char *room_name)
198 putroom(qrbuf, room_name);
199 end_critical_section(S_QUICKROOM);
203 /****************************************************************************/
206 * getfloor() - retrieve floor data from disk
208 void getfloor(struct floor *flbuf, int floor_num)
210 struct cdbdata *cdbfl;
212 memset(flbuf, 0, sizeof(struct floor));
213 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
215 memcpy(flbuf, cdbfl->ptr,
216 ( (cdbfl->len > sizeof(struct floor)) ?
217 sizeof(struct floor) : cdbfl->len) );
221 if (floor_num == 0) {
222 strcpy(flbuf->f_name, "Main Floor");
223 flbuf->f_flags = F_INUSE;
224 flbuf->f_ref_count = 3;
231 * lgetfloor() - same as getfloor() but locks the record (if supported)
233 void lgetfloor(struct floor *flbuf, int floor_num)
236 begin_critical_section(S_FLOORTAB);
237 getfloor(flbuf,floor_num);
242 * putfloor() - store floor data on disk
244 void putfloor(struct floor *flbuf, int floor_num)
246 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
247 flbuf, sizeof(struct floor));
252 * lputfloor() - same as putfloor() but unlocks the record (if supported)
254 void lputfloor(struct floor *flbuf, int floor_num)
257 putfloor(flbuf,floor_num);
258 end_critical_section(S_FLOORTAB);
264 * Traverse the room file...
266 void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) {
267 struct quickroom qrbuf;
268 struct cdbdata *cdbqr;
270 cdb_rewind(CDB_QUICKROOM);
272 while(cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
273 memset(&qrbuf, 0, sizeof(struct quickroom));
274 memcpy(&qrbuf, cdbqr->ptr,
275 ( (cdbqr->len > sizeof(struct quickroom)) ?
276 sizeof(struct quickroom) : cdbqr->len) );
278 if (qrbuf.QRflags & QR_INUSE) (*CallBack)(&qrbuf);
285 * Create a database key for storage of message lists
287 void msglist_key(char *dbkey, struct quickroom *whichroom) {
290 sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
291 for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
295 * get_msglist() - retrieve room message pointers
297 void get_msglist(struct quickroom *whichroom) {
298 struct cdbdata *cdbfr;
301 msglist_key(dbkey, whichroom);
303 if (CC->msglist != NULL) {
309 cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey));
314 CC->msglist = malloc(cdbfr->len);
315 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
316 CC->num_msgs = cdbfr->len / sizeof(long);
322 * put_msglist() - retrieve room message pointers
324 void put_msglist(struct quickroom *whichroom) {
327 msglist_key(dbkey, whichroom);
328 cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey),
329 CC->msglist, CC->num_msgs * sizeof(long));
334 * delete_msglist() - delete room message pointers
335 * FIX - this really should check first to make sure there's actually a
336 * msglist to delete. As things stand now, calling this function on
337 * a room which has never been posted in will result in a message
338 * like "gdbm: illegal data" (no big deal, but could use fixing).
340 void delete_msglist(struct quickroom *whichroom) {
343 msglist_key(dbkey, whichroom);
344 cdb_delete(CDB_MSGLISTS, dbkey, strlen(dbkey));
349 * Add a message number to a room's message list.
350 * So, why doesn't this function use the get_msglist() and put_msglist() stuff
351 * defined above? Because the room the message number is being written to
352 * may not be the current room (as is the case with cmd_move() for example).
354 void AddMessageToRoom(struct quickroom *whichroom, long newmsgid) {
356 struct cdbdata *cdbfr;
360 msglist_key(dbkey, whichroom);
361 cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey));
367 msglist = malloc(cdbfr->len);
368 num_msgs = cdbfr->len / sizeof(long);
369 memcpy(msglist, cdbfr->ptr, cdbfr->len);
373 /* Now add the new message */
375 msglist = realloc(msglist,
376 (num_msgs * sizeof(long)) );
378 if (msglist == NULL) {
379 lprintf(3, "ERROR: can't realloc message list!\n");
382 msglist[num_msgs - 1] = newmsgid;
384 /* Write it back to disk. */
385 cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey),
386 msglist, num_msgs * sizeof(long));
388 /* And finally, free up the memory we used. */
394 * MessageFromList() - get a message number from the list currently in memory
396 long MessageFromList(int whichpos) {
398 /* Return zero if the position is invalid */
399 if (whichpos >= CC->num_msgs) return 0L;
401 return(CC->msglist[whichpos]);
405 * SetMessageInList() - set a message number in the list currently in memory
407 void SetMessageInList(int whichpos, long newmsgnum) {
409 /* Return zero if the position is invalid */
410 if (whichpos >= CC->num_msgs) return;
412 CC->msglist[whichpos] = newmsgnum;
418 * sort message pointers
419 * (returns new msg count)
421 int sort_msglist(long listptrs[], int oldcount)
428 if (numitems < 2) return(oldcount);
431 for (a=numitems-2; a>=0; --a) {
432 for (b=0; b<=a; ++b) {
433 if (listptrs[b] > (listptrs[b+1])) {
435 hold2 = listptrs[b+1];
437 listptrs[b+1] = hold1;
442 /* and yank any nulls */
443 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
444 memcpy(&listptrs[0], &listptrs[1],
445 (sizeof(long) * (CC->num_msgs - 1)) );
454 * Determine whether a given room is one of the base non-editable rooms
456 int is_noneditable(struct quickroom *qrbuf) {
457 if (!strcasecmp(qrbuf->QRname, BASEROOM)) return(1);
458 else if (!strcasecmp(qrbuf->QRname, AIDEROOM)) return(1);
465 * Back-back-end for all room listing commands
467 void list_roomname(struct quickroom *qrbuf) {
468 char truncated_roomname[ROOMNAMELEN];
470 /* For mailbox rooms, chop off the owner prefix */
471 if (qrbuf->QRflags & QR_MAILBOX) {
472 strcpy(truncated_roomname, qrbuf->QRname);
473 strcpy(truncated_roomname, &truncated_roomname[11]);
474 cprintf("%s", truncated_roomname);
476 /* For all other rooms, just display the name in its entirety */
478 cprintf("%s", qrbuf->QRname);
481 /* ...and now the other parameters */
483 qrbuf->QRflags,qrbuf->QRfloor);
488 * cmd_lrms() - List all accessible rooms, known or forgotten
490 void cmd_lrms_backend(struct quickroom *qrbuf) {
491 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
492 & (UA_KNOWN | UA_ZAPPED)))
493 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
494 ||((CC->FloorBeingSearched)<0)) )
495 list_roomname(qrbuf);
498 void cmd_lrms(char *argbuf)
500 CC->FloorBeingSearched = (-1);
501 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
503 if (!(CC->logged_in)) {
504 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
508 if (getuser(&CC->usersupp,CC->curr_user)) {
509 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
513 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
515 ForEachRoom(cmd_lrms_backend);
522 * cmd_lkra() - List all known rooms
524 void cmd_lkra_backend(struct quickroom *qrbuf) {
525 if ( ((CtdlRoomAccess(qrbuf, &CC->usersupp)
527 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
528 ||((CC->FloorBeingSearched)<0)) )
529 list_roomname(qrbuf);
532 void cmd_lkra(char *argbuf)
534 CC->FloorBeingSearched = (-1);
535 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
537 if (!(CC->logged_in)) {
538 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
542 if (getuser(&CC->usersupp,CC->curr_user)) {
543 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
547 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
549 ForEachRoom(cmd_lkra_backend);
556 * cmd_lkrn() - List all known rooms with new messages
558 void cmd_lkrn_backend(struct quickroom *qrbuf) {
561 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
563 && (ra & UA_HASNEWMSGS)
564 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
565 ||((CC->FloorBeingSearched)<0)) )
566 list_roomname(qrbuf);
569 void cmd_lkrn(char *argbuf)
571 CC->FloorBeingSearched = (-1);
572 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
574 if (!(CC->logged_in)) {
575 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
579 if (getuser(&CC->usersupp,CC->curr_user)) {
580 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
584 cprintf("%d Rooms w/ new msgs:\n",LISTING_FOLLOWS);
586 ForEachRoom(cmd_lkrn_backend);
593 * cmd_lkro() - List all known rooms
595 void cmd_lkro_backend(struct quickroom *qrbuf) {
598 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
600 && ((ra & UA_HASNEWMSGS)==0)
601 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
602 ||((CC->FloorBeingSearched)<0)) )
603 list_roomname(qrbuf);
606 void cmd_lkro(char *argbuf)
608 CC->FloorBeingSearched = (-1);
609 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
611 if (!(CC->logged_in)) {
612 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
616 if (getuser(&CC->usersupp,CC->curr_user)) {
617 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
621 cprintf("%d Rooms w/o new msgs:\n",LISTING_FOLLOWS);
623 ForEachRoom(cmd_lkro_backend);
630 * cmd_lzrm() - List all forgotten rooms
632 void cmd_lzrm_backend(struct quickroom *qrbuf) {
635 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
636 if ( (ra & UA_GOTOALLOWED)
638 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
639 ||((CC->FloorBeingSearched)<0)) )
640 list_roomname(qrbuf);
643 void cmd_lzrm(char *argbuf)
645 CC->FloorBeingSearched = (-1);
646 if (strlen(argbuf)>0) CC->FloorBeingSearched = extract_int(argbuf,0);
648 if (!(CC->logged_in)) {
649 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
653 if (getuser(&CC->usersupp,CC->curr_user)) {
654 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
658 cprintf("%d Zapped rooms:\n",LISTING_FOLLOWS);
660 ForEachRoom(cmd_lzrm_backend);
666 void usergoto(char *where, int display_result)
669 int new_messages = 0;
670 int total_messages = 0;
674 int newmailcount = 0;
676 char truncated_roomname[ROOMNAMELEN];
678 strcpy(CC->quickroom.QRname, where);
679 getroom(&CC->quickroom, where);
680 lgetuser(&CC->usersupp,CC->curr_user);
681 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
683 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
684 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
686 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
687 lputuser(&CC->usersupp,CC->curr_user);
689 /* check for new mail */
690 newmailcount = NewMailCount();
692 /* set info to 1 if the user needs to read the room's info file */
693 if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
696 get_msglist(&CC->quickroom);
697 for (a=0; a<CC->num_msgs; ++a) {
698 if (MessageFromList(a)>0L) {
700 if (MessageFromList(a) > vbuf.v_lastseen) {
706 if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1;
709 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
710 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
713 strcpy(truncated_roomname, CC->quickroom.QRname);
714 if (CC->quickroom.QRflags & QR_MAILBOX) {
715 strcpy(truncated_roomname, &truncated_roomname[11]);
718 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
721 new_messages, total_messages,
722 info,CC->quickroom.QRflags,
723 CC->quickroom.QRhighest,
725 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
727 set_wtmpsupp_to_current_room();
732 * cmd_goto() - goto a new room
734 void cmd_goto(char *gargs)
736 struct quickroom QRscratch;
740 char augmented_roomname[256];
744 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
745 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
749 extract(towhere,gargs,0);
750 extract(password,gargs,1);
752 getuser(&CC->usersupp, CC->curr_user);
754 if (!strcasecmp(towhere, "_BASEROOM_"))
755 strcpy(towhere, BASEROOM);
757 if (!strcasecmp(towhere, "_MAIL_"))
758 strcpy(towhere, MAILROOM);
760 if (!strcasecmp(towhere, "_BITBUCKET_"))
761 strcpy(towhere, config.c_twitroom);
764 /* First try a regular match */
765 c = getroom(&QRscratch, towhere);
767 /* Then try a mailbox name match */
769 MailboxName(augmented_roomname, &CC->usersupp, towhere);
770 c = getroom(&QRscratch, augmented_roomname);
771 if (c == 0) strcpy(towhere, augmented_roomname);
774 /* And if the room was found... */
777 /* let internal programs go directly to any room */
778 if (CC->internal_pgm) {
779 usergoto(towhere, 1);
783 /* See if there is an existing user/room relationship */
784 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
786 /* normal clients have to pass through security */
787 if (ra & UA_GOTOALLOWED) ok = 1;
790 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
791 ((ra & UA_KNOWN) == 0) &&
792 (strcasecmp(QRscratch.QRpasswd,password))
794 cprintf("%d wrong or missing passwd\n",
795 ERROR+PASSWORD_REQUIRED);
799 usergoto(towhere, 1);
805 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
809 void cmd_whok(void) {
810 struct usersupp temp;
811 struct cdbdata *cdbus;
813 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
814 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
817 getuser(&CC->usersupp,CC->curr_user);
819 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
820 cprintf("%d Higher access required.\n",
821 ERROR+HIGHER_ACCESS_REQUIRED);
825 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
826 cdb_rewind(CDB_USERSUPP);
827 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
828 memset(&temp, 0, sizeof(struct usersupp));
829 memcpy(&temp, cdbus->ptr, cdbus->len);
832 if ( (CC->quickroom.QRflags & QR_INUSE)
833 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
834 ) cprintf("%s\n",temp.fullname);
841 * RDIR command for room directory
843 void cmd_rdir(void) {
850 if (!(CC->logged_in)) {
851 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
855 getroom(&CC->quickroom, CC->quickroom.QRname);
856 getuser(&CC->usersupp, CC->curr_user);
858 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
859 cprintf("%d not here.\n",ERROR+NOT_HERE);
863 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
864 && (CC->usersupp.axlevel<6)
865 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
866 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
870 cprintf("%d %s|%s/files/%s\n",
871 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
873 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
874 BBSDIR,CC->quickroom.QRdirname,CC->temp);
877 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
879 if (fd==NULL) fd=fopen("/dev/null","r");
881 ls = fopen(CC->temp,"r");
882 while (fgets(flnm,256,ls)!=NULL) {
883 flnm[strlen(flnm)-1]=0;
884 if (strcasecmp(flnm,"filedir")) {
885 sprintf(buf,"%s/files/%s/%s",
886 BBSDIR,CC->quickroom.QRdirname,flnm);
890 while ((fgets(buf,256,fd)!=NULL)
891 &&(strlen(comment)==0)) {
892 buf[strlen(buf)-1] = 0;
893 if ((!strncasecmp(buf,flnm,strlen(flnm)))
894 && (buf[strlen(flnm)]==' '))
896 &buf[strlen(flnm)+1],255);
898 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
909 * get room parameters (aide or room aide command)
911 void cmd_getr(void) {
912 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
913 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
917 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
918 cprintf("%d Higher access required.\n",
919 ERROR+HIGHER_ACCESS_REQUIRED);
923 if (is_noneditable(&CC->quickroom)) {
924 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
928 getroom(&CC->quickroom, CC->quickroom.QRname);
929 cprintf("%d%c%s|%s|%s|%d|%d\n",
931 CC->quickroom.QRname,
932 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
933 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
934 CC->quickroom.QRflags,
935 (int)CC->quickroom.QRfloor);
940 * set room parameters (aide or room aide command)
942 void cmd_setr(char *args) {
947 if (!(CC->logged_in)) {
948 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
952 if (!is_room_aide()) {
953 cprintf("%d Higher access required.\n",
954 ERROR+HIGHER_ACCESS_REQUIRED);
958 if (is_noneditable(&CC->quickroom)) {
959 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
963 if (num_parms(args)>=6) {
964 getfloor(&flbuf,extract_int(args,5));
965 if ((flbuf.f_flags & F_INUSE) == 0) {
966 cprintf("%d Invalid floor number.\n",
967 ERROR+INVALID_FLOOR_OPERATION);
972 lgetroom(&CC->quickroom, CC->quickroom.QRname);
973 extract(buf,args,0); buf[ROOMNAMELEN]=0;
974 strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
975 extract(buf,args,1); buf[10]=0;
976 strncpy(CC->quickroom.QRpasswd,buf,9);
977 extract(buf,args,2); buf[15]=0;
978 strncpy(CC->quickroom.QRdirname,buf,19);
979 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
981 /* Clean up a client boo-boo: if the client set the room to
982 * guess-name or passworded, ensure that the private flag is
985 if ((CC->quickroom.QRflags & QR_GUESSNAME)
986 ||(CC->quickroom.QRflags & QR_PASSWORDED))
987 CC->quickroom.QRflags |= QR_PRIVATE;
989 /* Kick everyone out if the client requested it (by changing the
990 * room's generation number)
992 if (extract_int(args,4)) {
993 time(&CC->quickroom.QRgen);
996 old_floor = CC->quickroom.QRfloor;
997 if (num_parms(args)>=6) {
998 CC->quickroom.QRfloor = extract_int(args,5);
1001 lputroom(&CC->quickroom, CC->quickroom.QRname);
1003 /* adjust the floor reference counts */
1004 lgetfloor(&flbuf,old_floor);
1005 --flbuf.f_ref_count;
1006 lputfloor(&flbuf,old_floor);
1007 lgetfloor(&flbuf,CC->quickroom.QRfloor);
1008 ++flbuf.f_ref_count;
1009 lputfloor(&flbuf,CC->quickroom.QRfloor);
1011 /* create a room directory if necessary */
1012 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1014 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1015 CC->quickroom.QRdirname);
1019 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
1021 cprintf("%d Ok\n",OK);
1027 * get the name of the room aide for this room
1029 void cmd_geta(void) {
1030 struct usersupp usbuf;
1032 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
1033 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1037 if (is_noneditable(&CC->quickroom)) {
1038 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1042 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
1043 cprintf("%d %s\n",OK,usbuf.fullname);
1046 cprintf("%d \n",OK);
1052 * set the room aide for this room
1054 void cmd_seta(char *new_ra)
1056 struct usersupp usbuf;
1061 if (!(CC->logged_in)) {
1062 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1066 if (!is_room_aide()) {
1067 cprintf("%d Higher access required.\n",
1068 ERROR+HIGHER_ACCESS_REQUIRED);
1072 if (getuser(&usbuf,new_ra)!=0) {
1076 newu = usbuf.usernum;
1079 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1081 if (CC->quickroom.QRroomaide != newu) {
1084 CC->quickroom.QRroomaide = newu;
1085 lputroom(&CC->quickroom, CC->quickroom.QRname);
1088 * We have to post the change notice _after_ writing changes to
1089 * the room table, otherwise it would deadlock!
1091 if (post_notice == 1) {
1092 sprintf(buf,"%s is now room aide for %s>",
1093 usbuf.fullname,CC->quickroom.QRname);
1096 cprintf("%d Ok\n",OK);
1100 * Generate an associated file name for a room
1102 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix) {
1105 sprintf(buf, "./prefix/%s.%ld", qrbuf->QRname, qrbuf->QRgen);
1106 for (a=0; a<strlen(buf); ++a) {
1107 if (buf[a]==32) buf[a]='.';
1112 * retrieve info file for this room
1114 void cmd_rinf(void) {
1119 assoc_file_name(filename, &CC->quickroom, "info");
1120 info_fp = fopen(filename,"r");
1122 if (info_fp==NULL) {
1123 cprintf("%d No info file.\n",ERROR);
1127 cprintf("%d Info:\n",LISTING_FOLLOWS);
1128 while (fgets(buf, 256, info_fp) != NULL) {
1129 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
1130 cprintf("%s\n", buf);
1137 * Back end processing to delete a room and everything associated with it
1139 void delete_room(struct quickroom *qrbuf) {
1145 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1147 /* Delete the info file */
1148 assoc_file_name(aaa, qrbuf, "info");
1151 /* Delete the image file */
1152 assoc_file_name(aaa, qrbuf, "images");
1155 /* first flag the room record as not in use */
1156 lgetroom(qrbuf, qrbuf->QRname);
1159 /* then delete the messages in the room */
1161 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1162 MsgToDelete = MessageFromList(a);
1163 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1169 delete_msglist(qrbuf);
1170 lputroom(qrbuf, qrbuf->QRname);
1172 /* then decrement the reference count for the floor */
1173 lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
1174 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1175 lputfloor(&flbuf,(int)(qrbuf->QRfloor));
1177 /* Delete the room record from the database! */
1178 putroom(NULL, qrbuf->QRname);
1183 * aide command: kill the current room
1185 void cmd_kill(char *argbuf) {
1187 char deleted_room_name[ROOMNAMELEN];
1190 kill_ok = extract_int(argbuf,0);
1192 if (!(CC->logged_in)) {
1193 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1197 if (!is_room_aide()) {
1198 cprintf("%d Higher access required.\n",
1199 ERROR+HIGHER_ACCESS_REQUIRED);
1203 if (is_noneditable(&CC->quickroom)) {
1204 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
1209 strcpy(deleted_room_name, CC->quickroom.QRname);
1210 delete_room(&CC->quickroom); /* Do the dirty work */
1211 usergoto(BASEROOM, 0); /* Return to the Lobby */
1213 /* tell the world what we did */
1214 sprintf(aaa,"%s> killed by %s",
1215 deleted_room_name, CC->curr_user);
1217 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1220 cprintf("%d ok to delete.\n",OK);
1226 * Internal code to create a new room (returns room flags)
1228 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1230 unsigned create_room(char *new_room_name,
1232 char *new_room_pass,
1233 int new_room_floor) {
1235 struct quickroom qrbuf;
1239 if (getroom(&qrbuf, new_room_name)==0) return(0); /* already exists */
1241 memset(&qrbuf, 0, sizeof(struct quickroom));
1242 strncpy(qrbuf.QRname,new_room_name,ROOMNAMELEN);
1243 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1244 qrbuf.QRflags = QR_INUSE;
1245 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1246 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1247 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1248 if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
1250 /* If the room is private, and the system administrator has elected
1251 * to automatically grant room aide privileges, do so now; otherwise,
1252 * set the room aide to undefined.
1254 if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) {
1255 qrbuf.QRroomaide=CC->usersupp.usernum;
1258 qrbuf.QRroomaide = (-1L);
1261 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1262 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1263 qrbuf.QRfloor = new_room_floor;
1265 /* save what we just did... */
1266 putroom(&qrbuf, qrbuf.QRname);
1268 /* bump the reference count on whatever floor the room is on */
1269 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1270 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1271 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1273 /* be sure not to kick the creator out of the room! */
1274 lgetuser(&CC->usersupp,CC->curr_user);
1275 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1276 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1277 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1278 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1279 lputuser(&CC->usersupp,CC->curr_user);
1281 /* resume our happy day */
1282 return(qrbuf.QRflags);
1289 void cmd_cre8(char *args)
1292 char new_room_name[256];
1294 char new_room_pass[256];
1298 struct quickroom qrbuf;
1301 cre8_ok = extract_int(args,0);
1302 extract(new_room_name,args,1);
1303 new_room_name[ROOMNAMELEN-1] = 0;
1304 new_room_type = extract_int(args,2);
1305 extract(new_room_pass,args,3);
1306 new_room_pass[9] = 0;
1309 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1310 cprintf("%d Invalid room name.\n",ERROR);
1314 if (num_parms(args)>=5) {
1315 getfloor(&flbuf,extract_int(args,4));
1316 if ((flbuf.f_flags & F_INUSE) == 0) {
1317 cprintf("%d Invalid floor number.\n",
1318 ERROR+INVALID_FLOOR_OPERATION);
1322 new_room_floor = extract_int(args,4);
1326 if (!(CC->logged_in)) {
1327 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1331 if (CC->usersupp.axlevel<3) {
1332 cprintf("%d You need higher access to create rooms.\n",
1333 ERROR+HIGHER_ACCESS_REQUIRED);
1337 if ((strlen(new_room_name)==0) && (cre8_ok==0)) {
1338 cprintf("%d Ok to create rooms.\n", OK);
1342 /* Check to make sure the requested room name doesn't already exist */
1343 if (getroom(&qrbuf, new_room_name)==0) {
1344 cprintf("%d '%s' already exists.\n",
1345 ERROR,qrbuf.QRname);
1349 if ((new_room_type < 0) || (new_room_type > 3)) {
1350 cprintf("%d Invalid room type.\n",ERROR);
1355 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1359 newflags = create_room(new_room_name,
1360 new_room_type,new_room_pass,new_room_floor);
1362 /* post a message in Aide> describing the new room */
1363 strncpy(aaa,new_room_name,255);
1364 strcat(aaa,"> created by ");
1365 strcat(aaa,CC->usersupp.fullname);
1366 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1367 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1368 if (newflags&QR_PASSWORDED) {
1369 strcat(aaa,"\n Password: ");
1370 strcat(aaa,new_room_pass);
1374 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1379 void cmd_einf(char *ok)
1380 { /* enter info file for current room */
1382 char infofilename[64];
1385 if (!(CC->logged_in)) {
1386 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1390 if (!is_room_aide()) {
1391 cprintf("%d Higher access required.\n",
1392 ERROR+HIGHER_ACCESS_REQUIRED);
1397 cprintf("%d Ok.\n",OK);
1401 cprintf("%d Send info...\n",SEND_LISTING);
1403 assoc_file_name(infofilename, &CC->quickroom, "info");
1405 fp=fopen(infofilename,"w");
1408 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1409 } while(strcmp(buf,"000"));
1412 /* now update the room index so people will see our new info */
1413 lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */
1414 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1415 lputroom(&CC->quickroom,CC->quickroom.QRname);
1420 * cmd_lflr() - List all known floors
1422 void cmd_lflr(void) {
1426 if (!(CC->logged_in)) {
1427 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1431 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1432 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1437 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1439 for (a=0; a<MAXFLOORS; ++a) {
1441 if (flbuf.f_flags & F_INUSE) {
1442 cprintf("%d|%s|%d\n",
1454 * create a new floor
1456 void cmd_cflr(char *argbuf)
1458 char new_floor_name[256];
1461 int free_slot = (-1);
1464 extract(new_floor_name,argbuf,0);
1465 cflr_ok = extract_int(argbuf,1);
1468 if (!(CC->logged_in)) {
1469 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1473 if (CC->usersupp.axlevel<6) {
1474 cprintf("%d You need higher access to create rooms.\n",
1475 ERROR+HIGHER_ACCESS_REQUIRED);
1479 for (a=0; a<MAXFLOORS; ++a) {
1482 /* note any free slots while we're scanning... */
1483 if ( ((flbuf.f_flags & F_INUSE)==0)
1484 && (free_slot < 0) ) free_slot = a;
1486 /* check to see if it already exists */
1487 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1488 && (flbuf.f_flags & F_INUSE) ) {
1489 cprintf("%d Floor '%s' already exists.\n",
1490 ERROR+ALREADY_EXISTS,
1498 cprintf("%d There is no space available for a new floor.\n",
1499 ERROR+INVALID_FLOOR_OPERATION);
1504 cprintf("%d ok to create...\n",OK);
1508 lgetfloor(&flbuf,free_slot);
1509 flbuf.f_flags = F_INUSE;
1510 flbuf.f_ref_count = 0;
1511 strncpy(flbuf.f_name,new_floor_name,255);
1512 lputfloor(&flbuf,free_slot);
1513 cprintf("%d %d\n",OK,free_slot);
1521 void cmd_kflr(char *argbuf)
1524 int floor_to_delete;
1528 floor_to_delete = extract_int(argbuf,0);
1529 kflr_ok = extract_int(argbuf,1);
1532 if (!(CC->logged_in)) {
1533 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1537 if (CC->usersupp.axlevel<6) {
1538 cprintf("%d You need higher access to delete floors.\n",
1539 ERROR+HIGHER_ACCESS_REQUIRED);
1543 lgetfloor(&flbuf,floor_to_delete);
1546 if ((flbuf.f_flags & F_INUSE) == 0) {
1547 cprintf("%d Floor %d not in use.\n",
1548 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1553 if (flbuf.f_ref_count != 0) {
1554 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1555 ERROR+INVALID_FLOOR_OPERATION,
1562 cprintf("%d Ok\n",OK);
1565 cprintf("%d Ok to delete...\n",OK);
1572 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1573 lputfloor(&flbuf,floor_to_delete);
1579 void cmd_eflr(char *argbuf)
1585 np = num_parms(argbuf);
1587 cprintf("%d Usage error.\n",ERROR);
1591 if (!(CC->logged_in)) {
1592 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1596 if (CC->usersupp.axlevel<6) {
1597 cprintf("%d You need higher access to edit floors.\n",
1598 ERROR+HIGHER_ACCESS_REQUIRED);
1602 floor_num = extract_int(argbuf,0);
1603 lgetfloor(&flbuf,floor_num);
1604 if ( (flbuf.f_flags & F_INUSE) == 0) {
1605 lputfloor(&flbuf,floor_num);
1606 cprintf("%d Floor %d is not in use.\n",
1607 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1610 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1611 lputfloor(&flbuf,floor_num);
1613 cprintf("%d Ok\n",OK);