12 #include "sysdep_decls.h"
16 #include "serv_chat.h"
17 #include "citserver.h"
20 * is_known() - returns nonzero if room is in user's known room list
22 int is_known(struct quickroom *roombuf, int roomnum, struct usersupp *userbuf)
25 /* for internal programs, always succeed */
26 if (((CC->internal_pgm))&&(roombuf->QRflags & QR_INUSE)) return(1);
28 /* for regular rooms, check the permissions */
29 if ((roombuf->QRflags & QR_INUSE)
30 && ( (roomnum!=2) || (userbuf->axlevel>=6))
31 && (roombuf->QRgen != (userbuf->forget[roomnum]) )
33 && ( ((roombuf->QRflags&QR_PREFONLY)==0)
34 || ((userbuf->axlevel)>=5)
37 && ( ((roombuf->QRflags&QR_PRIVATE)==0)
38 || ((userbuf->axlevel)>=6)
39 || (roombuf->QRgen==(userbuf->generation[roomnum]))
48 * has_newmsgs() - returns nonzero if room has new messages
50 int has_newmsgs(struct quickroom *roombuf, int roomnum, struct usersupp *userbuf)
52 if (roombuf->QRhighest > (userbuf->lastseen[roomnum]) )
58 * is_zapped() - returns nonzero if room is on forgotten rooms list
60 int is_zapped(struct quickroom *roombuf, int roomnum, struct usersupp *userbuf)
62 if ((roombuf->QRflags & QR_INUSE)
63 && (roombuf->QRgen == (userbuf->forget[roomnum]) )
64 && ( (roomnum!=2) || ((userbuf->axlevel)>=6))
65 && ( ((roombuf->QRflags&QR_PRIVATE)==0)
66 || ((userbuf->axlevel)>=6)
67 || (roombuf->QRgen==(userbuf->generation[roomnum]))
74 * getroom() - retrieve room data from disk
76 void getroom(struct quickroom *qrbuf, int room_num)
78 struct cdbdata *cdbqr;
81 bzero(qrbuf, sizeof(struct quickroom));
82 cdbqr = cdb_fetch(CDB_QUICKROOM, &room_num, sizeof(int));
84 memcpy(qrbuf, cdbqr->ptr,
85 ( (cdbqr->len > sizeof(struct quickroom)) ?
86 sizeof(struct quickroom) : cdbqr->len) );
91 qrbuf->QRflags = QR_INUSE;
94 case 0: strcpy(qrbuf->QRname, "Lobby");
96 case 1: strcpy(qrbuf->QRname, "Mail");
98 case 2: strcpy(qrbuf->QRname, "Aide");
105 /** FIX ** VILE SLEAZY HACK ALERT!!
106 * This is a temporary fix until I can track down where room names
107 * are getting corrupted on some systems.
109 for (a=0; a<20; ++a) if (qrbuf->QRname[a] < 32) qrbuf->QRname[a] = 0;
110 qrbuf->QRname[19] = 0;
114 * lgetroom() - same as getroom() but locks the record (if supported)
116 void lgetroom(struct quickroom *qrbuf, int room_num)
118 begin_critical_section(S_QUICKROOM);
119 getroom(qrbuf,room_num);
124 * putroom() - store room data on disk
126 void putroom(struct quickroom *qrbuf, int room_num)
129 cdb_store(CDB_QUICKROOM, &room_num, sizeof(int),
130 qrbuf, sizeof(struct quickroom));
135 * lputroom() - same as putroom() but unlocks the record (if supported)
137 void lputroom(struct quickroom *qrbuf, int room_num)
140 putroom(qrbuf,room_num);
141 end_critical_section(S_QUICKROOM);
147 * getfloor() - retrieve floor data from disk
149 void getfloor(struct floor *flbuf, int floor_num)
151 struct cdbdata *cdbfl;
153 bzero(flbuf, sizeof(struct floor));
154 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
156 memcpy(flbuf, cdbfl->ptr,
157 ( (cdbfl->len > sizeof(struct floor)) ?
158 sizeof(struct floor) : cdbfl->len) );
162 if (floor_num == 0) {
163 strcpy(flbuf->f_name, "Main Floor");
164 flbuf->f_flags = F_INUSE;
165 flbuf->f_ref_count = 3;
172 * lgetfloor() - same as getfloor() but locks the record (if supported)
174 void lgetfloor(struct floor *flbuf, int floor_num)
177 begin_critical_section(S_FLOORTAB);
178 getfloor(flbuf,floor_num);
183 * putfloor() - store floor data on disk
185 void putfloor(struct floor *flbuf, int floor_num)
187 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
188 flbuf, sizeof(struct floor));
193 * lputfloor() - same as putfloor() but unlocks the record (if supported)
195 void lputfloor(struct floor *flbuf, int floor_num)
198 putfloor(flbuf,floor_num);
199 end_critical_section(S_FLOORTAB);
206 * get_msglist() - retrieve room message pointers
208 void get_msglist(int room_num)
210 struct cdbdata *cdbfr;
212 if (CC->msglist != NULL) {
219 cdbfr = cdb_fetch(CDB_MSGLISTS, &room_num, sizeof(int));
222 cdbfr = cdb_fetch(CDB_MAILBOXES, &CC->usersupp.usernum,
230 CC->msglist = malloc(cdbfr->len);
231 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
232 CC->num_msgs = cdbfr->len / sizeof(long);
238 * put_msglist() - retrieve room message pointers
240 void put_msglist(int room_num)
244 cdb_store(CDB_MSGLISTS, &room_num, sizeof(int),
245 CC->msglist, (CC->num_msgs * sizeof(long)) );
248 cdb_store(CDB_MAILBOXES, &CC->usersupp.usernum, sizeof(long),
249 CC->msglist, (CC->num_msgs * sizeof(long)) );
255 * MessageFromList() - get a message number from the list currently in memory
257 long MessageFromList(int whichpos) {
259 /* Return zero if the position is invalid */
260 if (whichpos >= CC->num_msgs) return 0L;
262 return(CC->msglist[whichpos]);
266 * SetMessageInList() - set a message number in the list currently in memory
268 void SetMessageInList(int whichpos, long newmsgnum) {
270 /* Return zero if the position is invalid */
271 if (whichpos >= CC->num_msgs) return;
273 CC->msglist[whichpos] = newmsgnum;
279 * sort message pointers
280 * (returns new msg count)
282 int sort_msglist(long listptrs[], int oldcount)
289 if (numitems < 2) return(oldcount);
292 for (a=numitems-2; a>=0; --a) {
293 for (b=0; b<=a; ++b) {
294 if (listptrs[b] > (listptrs[b+1])) {
296 hold2 = listptrs[b+1];
298 listptrs[b+1] = hold1;
303 /* and yank any nulls */
304 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
305 memcpy(&listptrs[0], &listptrs[1],
306 (sizeof(long) * (CC->num_msgs - 1)) );
317 * cmd_lrms() - List all accessible rooms, known or forgotten
319 void cmd_lrms(char *argbuf)
322 int target_floor = (-1);
323 struct quickroom qrbuf;
325 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
327 if (!(CC->logged_in)) {
328 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
332 if (getuser(&CC->usersupp,CC->curr_user)) {
333 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
337 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
339 for (a=0; a<MAXROOMS; ++a) {
341 if ( ( (is_known(&qrbuf,a,&CC->usersupp))
342 || (is_zapped(&qrbuf,a,&CC->usersupp)) )
343 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) )
344 cprintf("%s|%u|%d\n",
345 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
351 * cmd_lkra() - List all known rooms
353 void cmd_lkra(char *argbuf)
356 struct quickroom qrbuf;
357 int target_floor = (-1);
359 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
361 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
362 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
366 if (!(CC->internal_pgm)) if (getuser(&CC->usersupp,CC->curr_user)) {
367 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
371 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
373 for (a=0; a<MAXROOMS; ++a) {
375 if ((is_known(&qrbuf,a,&CC->usersupp))
376 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) )
377 cprintf("%s|%u|%d\n",
378 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
384 * cmd_lkrn() - List Known Rooms with New messages
386 void cmd_lkrn(char *argbuf)
389 struct quickroom qrbuf;
390 int target_floor = (-1);
392 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
394 if (!(CC->logged_in)) {
395 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
399 if (getuser(&CC->usersupp,CC->curr_user)) {
400 cprintf("%d can't locate user\n",ERROR+INTERNAL_ERROR);
404 cprintf("%d list of rms w/ new msgs\n",LISTING_FOLLOWS);
406 for (a=0; a<MAXROOMS; ++a) {
408 if ( ( (is_known(&qrbuf,a,&CC->usersupp))
409 && (has_newmsgs(&qrbuf,a,&CC->usersupp)) )
410 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) )
411 cprintf("%s|%u|%d\n",
412 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
418 * cmd_lkro() - List Known Rooms with Old (no new) messages
420 void cmd_lkro(char *argbuf)
423 struct quickroom qrbuf;
424 int target_floor = (-1);
426 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
428 if (!(CC->logged_in)) {
429 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
433 if (getuser(&CC->usersupp,CC->curr_user)) {
434 cprintf("%d can't locate user\n",ERROR+INTERNAL_ERROR);
438 cprintf("%d list of rms w/o new msgs\n",LISTING_FOLLOWS);
440 for (a=0; a<MAXROOMS; ++a) {
442 if ( ( (is_known(&qrbuf,a,&CC->usersupp))
443 && (!has_newmsgs(&qrbuf,a,&CC->usersupp)) )
444 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) ) {
445 if (!strcmp(qrbuf.QRname,"000")) cprintf(">");
446 cprintf("%s|%u|%d\n",
447 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
454 * cmd_lzrm() - List Zapped RooMs
456 void cmd_lzrm(char *argbuf)
459 struct quickroom qrbuf;
460 int target_floor = (-1);
462 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
464 if (!(CC->logged_in)) {
465 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
469 if (getuser(&CC->usersupp,CC->curr_user)) {
470 cprintf("%d can't locate user\n",ERROR+INTERNAL_ERROR);
474 cprintf("%d list of forgotten rms\n",LISTING_FOLLOWS);
476 for (a=0; a<MAXROOMS; ++a) {
478 if ( (is_zapped(&qrbuf,a,&CC->usersupp))
479 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) ) {
480 if (!strcmp(qrbuf.QRname,"000")) cprintf(">");
481 cprintf("%s|%u|%d\n",
482 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
490 void usergoto(int where, int display_result)
496 int newmailcount = 0;
497 struct cdbdata *cdbmb;
502 getroom(&CC->quickroom,CC->curr_rm);
503 lgetuser(&CC->usersupp,CC->curr_user);
504 CC->usersupp.forget[CC->curr_rm]=(-1);
505 CC->usersupp.generation[CC->curr_rm]=CC->quickroom.QRgen;
506 lputuser(&CC->usersupp,CC->curr_user);
508 /* check for new mail */
511 cdbmb = cdb_fetch(CDB_MAILBOXES, &CC->usersupp.usernum, sizeof(long));
513 num_mails = cdbmb->len / sizeof(long);
514 mailbox = (long *) cdbmb->ptr;
515 if (num_mails > 0) for (a=0; a<num_mails; ++a) {
516 if (mailbox[a] > (CC->usersupp.lastseen[1]))
522 /* set info to 1 if the user needs to read the room's info file */
523 if (CC->quickroom.QRinfo > CC->usersupp.lastseen[CC->curr_rm]) info = 1;
527 get_msglist(CC->curr_rm);
528 for (a=0; a<CC->num_msgs; ++a) {
529 if (MessageFromList(a)>0L) {
531 if (MessageFromList(a)
532 > CC->usersupp.lastseen[CC->curr_rm]) ++c;
537 if (CC->curr_rm == 1) rmailflag = 1;
540 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
541 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
544 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
546 CC->quickroom.QRname,c,b,info,CC->quickroom.QRflags,
547 CC->quickroom.QRhighest,CC->usersupp.lastseen[CC->curr_rm],
548 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
549 if (CC->quickroom.QRflags & QR_PRIVATE) {
550 set_wtmpsupp("<private room>");
553 set_wtmpsupp(CC->quickroom.QRname);
559 * cmd_goto() - goto a new room
561 void cmd_goto(char *gargs)
563 struct quickroom QRscratch;
566 char bbb[20],towhere[32],password[20];
568 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
569 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
573 extract(towhere,gargs,0);
574 extract(password,gargs,1);
577 getuser(&CC->usersupp,CC->curr_user);
578 for (a=0; a<MAXROOMS; ++a) {
579 getroom(&QRscratch,a);
580 if ((a==0)&&(!strcasecmp(towhere,"_BASEROOM_"))) {
581 strncpy(towhere,QRscratch.QRname,31);
583 if ((a==1)&&(!strcasecmp(towhere,"_MAIL_"))) {
584 strncpy(towhere,QRscratch.QRname,31);
586 if ((!strcasecmp(QRscratch.QRname,config.c_twitroom))
587 &&(!strcasecmp(towhere,"_BITBUCKET_"))) {
588 strncpy(towhere,QRscratch.QRname,31);
590 strcpy(bbb,QRscratch.QRname);
593 /* let internal programs go directly to any room */
594 if (((CC->internal_pgm))&&(!strcasecmp(bbb,towhere))) {
599 /* normal clients have to pass through security */
601 (strcasecmp(bbb,towhere)==0)
602 && ((QRscratch.QRflags&QR_INUSE)!=0)
604 && ( ((QRscratch.QRflags&QR_PREFONLY)==0)
605 || (CC->usersupp.axlevel>=5)
608 && ( (a!=2) || (CC->usersupp.axlevel>=6) )
610 && ( ((QRscratch.QRflags&QR_PRIVATE)==0)
611 || (QRscratch.QRflags&QR_GUESSNAME)
612 || (CC->usersupp.axlevel>=6)
613 || (QRscratch.QRflags&QR_PASSWORDED)
614 || (QRscratch.QRgen==CC->usersupp.generation[a])
622 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
623 (CC->usersupp.axlevel<6) &&
624 (QRscratch.QRgen!=CC->usersupp.generation[a]) &&
625 (strcasecmp(QRscratch.QRpasswd,password))
627 cprintf("%d wrong or missing passwd\n",
628 ERROR+PASSWORD_REQUIRED);
637 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
641 void cmd_whok(void) {
642 struct usersupp temp;
643 struct cdbdata *cdbus;
645 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
646 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
649 getuser(&CC->usersupp,CC->curr_user);
651 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
652 cprintf("%d Higher access required.\n",
653 ERROR+HIGHER_ACCESS_REQUIRED);
657 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
658 cdb_rewind(CDB_USERSUPP);
659 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
660 bzero(&temp, sizeof(struct usersupp));
661 memcpy(&temp, cdbus->ptr, cdbus->len);
663 if ((CC->quickroom.QRflags & QR_INUSE)
664 && ( (CC->curr_rm!=2) || (temp.axlevel>=6) )
665 && (CC->quickroom.QRgen != (temp.forget[CC->curr_rm]) )
667 && ( ((CC->quickroom.QRflags&QR_PREFONLY)==0)
671 && ( ((CC->quickroom.QRflags&QR_PRIVATE)==0)
673 || (CC->quickroom.QRgen==(temp.generation[CC->curr_rm]))
676 && (strncmp(temp.fullname,"000",3))
678 ) cprintf("%s\n",temp.fullname);
685 * RDIR command for room directory
687 void cmd_rdir(void) {
694 if (!(CC->logged_in)) {
695 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
699 getroom(&CC->quickroom,CC->curr_rm);
700 getuser(&CC->usersupp,CC->curr_user);
702 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
703 cprintf("%d not here.\n",ERROR+NOT_HERE);
707 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
708 && (CC->usersupp.axlevel<6)
709 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
710 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
714 cprintf("%d %s|%s/files/%s\n",
715 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
717 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
718 BBSDIR,CC->quickroom.QRdirname,CC->temp);
721 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
723 if (fd==NULL) fd=fopen("/dev/null","r");
725 ls = fopen(CC->temp,"r");
726 while (fgets(flnm,256,ls)!=NULL) {
727 flnm[strlen(flnm)-1]=0;
728 if (strcasecmp(flnm,"filedir")) {
729 sprintf(buf,"%s/files/%s/%s",
730 BBSDIR,CC->quickroom.QRdirname,flnm);
734 while ((fgets(buf,256,fd)!=NULL)
735 &&(strlen(comment)==0)) {
736 buf[strlen(buf)-1] = 0;
737 if ((!strncasecmp(buf,flnm,strlen(flnm)))
738 && (buf[strlen(flnm)]==' '))
740 &buf[strlen(flnm)+1],255);
742 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
753 * get room parameters (aide or room aide command)
755 void cmd_getr(void) {
756 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
757 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
761 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
762 cprintf("%d Higher access required.\n",
763 ERROR+HIGHER_ACCESS_REQUIRED);
767 if (CC->curr_rm < 3) {
768 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
772 getroom(&CC->quickroom,CC->curr_rm);
773 cprintf("%d%c%s|%s|%s|%d|%d\n",
775 CC->quickroom.QRname,
776 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
777 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
778 CC->quickroom.QRflags,
779 (int)CC->quickroom.QRfloor);
784 * set room parameters (aide or room aide command)
786 void cmd_setr(char *args) {
791 if (!(CC->logged_in)) {
792 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
796 if (!is_room_aide()) {
797 cprintf("%d Higher access required.\n",
798 ERROR+HIGHER_ACCESS_REQUIRED);
802 if (CC->curr_rm < 3) {
803 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
807 if (num_parms(args)>=6) {
808 getfloor(&flbuf,extract_int(args,5));
809 if ((flbuf.f_flags & F_INUSE) == 0) {
810 cprintf("%d Invalid floor number.\n",
811 ERROR+INVALID_FLOOR_OPERATION);
816 lgetroom(&CC->quickroom,CC->curr_rm);
817 extract(buf,args,0); buf[20]=0;
818 strncpy(CC->quickroom.QRname,buf,19);
819 extract(buf,args,1); buf[10]=0;
820 strncpy(CC->quickroom.QRpasswd,buf,9);
821 extract(buf,args,2); buf[15]=0;
822 strncpy(CC->quickroom.QRdirname,buf,19);
823 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
825 /* Clean up a client boo-boo: if the client set the room to
826 * guess-name or passworded, ensure that the private flag is
829 if ((CC->quickroom.QRflags & QR_GUESSNAME)
830 ||(CC->quickroom.QRflags & QR_PASSWORDED))
831 CC->quickroom.QRflags |= QR_PRIVATE;
833 /* Kick everyone out if the client requested it */
834 if (extract_int(args,4)) {
835 ++CC->quickroom.QRgen;
836 if (CC->quickroom.QRgen==100) CC->quickroom.QRgen=1;
839 old_floor = CC->quickroom.QRfloor;
840 if (num_parms(args)>=6) {
841 CC->quickroom.QRfloor = extract_int(args,5);
844 lputroom(&CC->quickroom,CC->curr_rm);
846 /* adjust the floor reference counts */
847 lgetfloor(&flbuf,old_floor);
849 lputfloor(&flbuf,old_floor);
850 lgetfloor(&flbuf,CC->quickroom.QRfloor);
852 lputfloor(&flbuf,CC->quickroom.QRfloor);
854 /* create a room directory if necessary */
855 if (CC->quickroom.QRflags & QR_DIRECTORY) {
857 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
858 CC->quickroom.QRdirname);
862 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
864 cprintf("%d Ok\n",OK);
870 * get the name of the room aide for this room
872 void cmd_geta(void) {
873 struct usersupp usbuf;
875 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
876 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
880 if (CC->curr_rm < 0) {
881 cprintf("%d No current room.\n",ERROR);
885 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
886 cprintf("%d %s\n",OK,usbuf.fullname);
895 * set the room aide for this room
897 void cmd_seta(char *new_ra)
899 struct usersupp usbuf;
904 if (!(CC->logged_in)) {
905 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
909 if (!is_room_aide()) {
910 cprintf("%d Higher access required.\n",
911 ERROR+HIGHER_ACCESS_REQUIRED);
915 if (CC->curr_rm < 3) {
916 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
920 if (getuser(&usbuf,new_ra)!=0) {
924 newu = usbuf.usernum;
927 lgetroom(&CC->quickroom,CC->curr_rm);
929 if (CC->quickroom.QRroomaide != newu) {
932 CC->quickroom.QRroomaide = newu;
933 lputroom(&CC->quickroom,CC->curr_rm);
936 * We have to post the change notice _after_ writing changes to
937 * the room table, otherwise it would deadlock!
939 if (post_notice == 1) {
940 sprintf(buf,"%s is now room aide for %s>",
941 usbuf.fullname,CC->quickroom.QRname);
944 cprintf("%d Ok\n",OK);
949 * retrieve info file for this room
951 void cmd_rinf(void) {
956 sprintf(filename,"./info/%d",CC->curr_rm);
957 info_fp = fopen(filename,"r");
960 cprintf("%d No info file.\n",ERROR);
964 cprintf("%d Info:\n",LISTING_FOLLOWS);
965 while (fgets(buf, 256, info_fp) != NULL) {
966 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
967 cprintf("%s\n", buf);
974 * aide command: kill the current room
976 void cmd_kill(char *argbuf)
984 kill_ok = extract_int(argbuf,0);
986 if (!(CC->logged_in)) {
987 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
991 if (!is_room_aide()) {
992 cprintf("%d Higher access required.\n",
993 ERROR+HIGHER_ACCESS_REQUIRED);
997 if (CC->curr_rm < 3) {
998 cprintf("%d Can't kill this room.\n",ERROR+NOT_HERE);
1004 /* first flag the room record as not in use */
1005 lgetroom(&CC->quickroom,CC->curr_rm);
1006 CC->quickroom.QRflags=0;
1008 /* then delete the messages in the room */
1009 get_msglist(CC->curr_rm);
1010 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1011 MsgToDelete = MessageFromList(a);
1012 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1014 put_msglist(CC->curr_rm);
1017 cdb_delete(CDB_MSGLISTS, &CC->curr_rm, sizeof(int));
1019 lputroom(&CC->quickroom,CC->curr_rm);
1022 /* then decrement the reference count for the floor */
1023 lgetfloor(&flbuf,(int)CC->quickroom.QRfloor);
1024 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1025 lputfloor(&flbuf,(int)CC->quickroom.QRfloor);
1027 /* tell the world what we did */
1028 sprintf(aaa,"%s> killed by %s",CC->quickroom.QRname,CC->curr_user);
1031 cprintf("%d '%s' deleted.\n",OK,CC->quickroom.QRname);
1034 cprintf("%d ok to delete.\n",OK);
1040 * Find a free slot to create a new room in, or return -1 for error.
1041 * search_dir is the direction to search in. 1 causes this function to
1042 * return the first available slot, -1 gets the last available slot.
1044 int get_free_room_slot(int search_dir)
1047 struct quickroom qrbuf;
1049 st = ((search_dir>0) ? 3 : (MAXROOMS-1));
1051 for (a=st; ((a<MAXROOMS)&&(a>=3)); a=a+search_dir) {
1053 if ((qrbuf.QRflags & QR_INUSE)==0) return(a);
1060 * internal code to create a new room (returns room flags)
1062 unsigned create_room(int free_slot, char *new_room_name, int new_room_type, char *new_room_pass, int new_room_floor)
1064 struct quickroom qrbuf;
1067 lgetroom(&qrbuf,free_slot);
1068 strncpy(qrbuf.QRname,new_room_name,19);
1069 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1070 qrbuf.QRflags = QR_INUSE;
1071 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1072 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1073 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1074 qrbuf.QRroomaide = (-1L);
1075 if ((new_room_type > 0)&&(CREATAIDE==1))
1076 qrbuf.QRroomaide=CC->usersupp.usernum;
1077 qrbuf.QRhighest = 0L;
1078 ++qrbuf.QRgen; if (qrbuf.QRgen>=126) qrbuf.QRgen=10;
1079 qrbuf.QRfloor = new_room_floor;
1081 /* save what we just did... */
1082 lputroom(&qrbuf,free_slot);
1084 /* bump the reference count on whatever floor the room is on */
1085 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1086 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1087 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1089 /* be sure not to kick the creator out of the room! */
1090 lgetuser(&CC->usersupp,CC->curr_user);
1091 CC->usersupp.generation[free_slot] = qrbuf.QRgen;
1092 CC->usersupp.forget[free_slot] = (-1);
1093 lputuser(&CC->usersupp,CC->curr_user);
1095 /* resume our happy day */
1096 return(qrbuf.QRflags);
1103 void cmd_cre8(char *args)
1108 char new_room_name[256];
1110 char new_room_pass[256];
1114 struct quickroom qrbuf;
1117 cre8_ok = extract_int(args,0);
1118 extract(new_room_name,args,1);
1119 new_room_name[19] = 0;
1120 new_room_type = extract_int(args,2);
1121 extract(new_room_pass,args,3);
1122 new_room_pass[9] = 0;
1125 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1126 cprintf("%d Invalid room name.\n",ERROR);
1130 if (num_parms(args)>=5) {
1131 getfloor(&flbuf,extract_int(args,4));
1132 if ((flbuf.f_flags & F_INUSE) == 0) {
1133 cprintf("%d Invalid floor number.\n",
1134 ERROR+INVALID_FLOOR_OPERATION);
1138 new_room_floor = extract_int(args,4);
1142 if (!(CC->logged_in)) {
1143 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1147 if (CC->usersupp.axlevel<3) {
1148 cprintf("%d You need higher access to create rooms.\n",
1149 ERROR+HIGHER_ACCESS_REQUIRED);
1153 free_slot = get_free_room_slot(1);
1155 cprintf("%d There is no space available for a new room.\n",
1161 cprintf("%d ok to create...\n",OK);
1165 for (a=0; a<MAXROOMS; ++a) {
1167 if ( (!strcasecmp(qrbuf.QRname,new_room_name))
1168 && (qrbuf.QRflags & QR_INUSE) ) {
1169 cprintf("%d '%s' already exists.\n",
1170 ERROR,qrbuf.QRname);
1175 if ((new_room_type < 0) || (new_room_type > 3)) {
1176 cprintf("%d Invalid room type.\n",ERROR);
1180 newflags = create_room(free_slot,new_room_name,
1181 new_room_type,new_room_pass,new_room_floor);
1183 /* post a message in Aide> describing the new room */
1184 strncpy(aaa,new_room_name,255);
1185 strcat(aaa,"> created by ");
1186 strcat(aaa,CC->usersupp.fullname);
1187 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1188 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1189 if (newflags&QR_PASSWORDED) {
1190 strcat(aaa,"\n Password: ");
1191 strcat(aaa,new_room_pass);
1195 sprintf(aaa,"./info/%d",free_slot); /* delete old info file */
1197 sprintf(aaa,"./images/room.%d.gif",free_slot); /* and picture */
1200 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1205 void cmd_einf(char *ok)
1206 { /* enter info file for current room */
1208 char infofilename[32];
1211 if (!(CC->logged_in)) {
1212 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1216 if (!is_room_aide()) {
1217 cprintf("%d Higher access required.\n",
1218 ERROR+HIGHER_ACCESS_REQUIRED);
1223 cprintf("%d Ok.\n",OK);
1227 cprintf("%d Send info...\n",SEND_LISTING);
1229 sprintf(infofilename,"./info/%d",CC->curr_rm);
1231 fp=fopen(infofilename,"w");
1234 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1235 } while(strcmp(buf,"000"));
1238 /* now update the room index so people will see our new info */
1239 lgetroom(&CC->quickroom,CC->curr_rm); /* lock so no one steps on us */
1240 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1241 lputroom(&CC->quickroom,CC->curr_rm);
1246 * cmd_lflr() - List all known floors
1248 void cmd_lflr(void) {
1252 if (!(CC->logged_in)) {
1253 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1257 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1258 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1263 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1265 for (a=0; a<MAXFLOORS; ++a) {
1267 if (flbuf.f_flags & F_INUSE) {
1268 cprintf("%d|%s|%d\n",
1280 * create a new floor
1282 void cmd_cflr(char *argbuf)
1284 char new_floor_name[256];
1287 int free_slot = (-1);
1290 extract(new_floor_name,argbuf,0);
1291 cflr_ok = extract_int(argbuf,1);
1294 if (!(CC->logged_in)) {
1295 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1299 if (CC->usersupp.axlevel<6) {
1300 cprintf("%d You need higher access to create rooms.\n",
1301 ERROR+HIGHER_ACCESS_REQUIRED);
1305 for (a=0; a<MAXFLOORS; ++a) {
1308 /* note any free slots while we're scanning... */
1309 if ( ((flbuf.f_flags & F_INUSE)==0)
1310 && (free_slot < 0) ) free_slot = a;
1312 /* check to see if it already exists */
1313 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1314 && (flbuf.f_flags & F_INUSE) ) {
1315 cprintf("%d Floor '%s' already exists.\n",
1316 ERROR+ALREADY_EXISTS,
1324 cprintf("%d There is no space available for a new floor.\n",
1325 ERROR+INVALID_FLOOR_OPERATION);
1330 cprintf("%d ok to create...\n",OK);
1334 lgetfloor(&flbuf,free_slot);
1335 flbuf.f_flags = F_INUSE;
1336 flbuf.f_ref_count = 0;
1337 strncpy(flbuf.f_name,new_floor_name,255);
1338 lputfloor(&flbuf,free_slot);
1339 cprintf("%d %d\n",OK,free_slot);
1347 void cmd_kflr(char *argbuf)
1350 int floor_to_delete;
1354 floor_to_delete = extract_int(argbuf,0);
1355 kflr_ok = extract_int(argbuf,1);
1358 if (!(CC->logged_in)) {
1359 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1363 if (CC->usersupp.axlevel<6) {
1364 cprintf("%d You need higher access to delete floors.\n",
1365 ERROR+HIGHER_ACCESS_REQUIRED);
1369 lgetfloor(&flbuf,floor_to_delete);
1372 if ((flbuf.f_flags & F_INUSE) == 0) {
1373 cprintf("%d Floor %d not in use.\n",
1374 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1379 if (flbuf.f_ref_count != 0) {
1380 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1381 ERROR+INVALID_FLOOR_OPERATION,
1388 cprintf("%d Ok\n",OK);
1391 cprintf("%d Ok to delete...\n",OK);
1398 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1399 lputfloor(&flbuf,floor_to_delete);
1405 void cmd_eflr(char *argbuf)
1411 np = num_parms(argbuf);
1413 cprintf("%d Usage error.\n",ERROR);
1417 if (!(CC->logged_in)) {
1418 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1422 if (CC->usersupp.axlevel<6) {
1423 cprintf("%d You need higher access to edit floors.\n",
1424 ERROR+HIGHER_ACCESS_REQUIRED);
1428 floor_num = extract_int(argbuf,0);
1429 lgetfloor(&flbuf,floor_num);
1430 if ( (flbuf.f_flags & F_INUSE) == 0) {
1431 lputfloor(&flbuf,floor_num);
1432 cprintf("%d Floor %d is not in use.\n",
1433 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1436 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1437 lputfloor(&flbuf,floor_num);
1439 cprintf("%d Ok\n",OK);