13 #include "sysdep_decls.h"
17 #include "serv_chat.h"
18 #include "citserver.h"
21 * is_known() - returns nonzero if room is in user's known room list
23 int is_known(struct quickroom *roombuf, int roomnum, struct usersupp *userbuf)
26 /* for internal programs, always succeed */
27 if (((CC->internal_pgm))&&(roombuf->QRflags & QR_INUSE)) return(1);
29 /* for regular rooms, check the permissions */
30 if ((roombuf->QRflags & QR_INUSE)
31 && ( (roomnum!=2) || (userbuf->axlevel>=6))
32 && (roombuf->QRgen != (userbuf->forget[roomnum]) )
34 && ( ((roombuf->QRflags&QR_PREFONLY)==0)
35 || ((userbuf->axlevel)>=5)
38 && ( ((roombuf->QRflags&QR_PRIVATE)==0)
39 || ((userbuf->axlevel)>=6)
40 || (roombuf->QRgen==(userbuf->generation[roomnum]))
49 * has_newmsgs() - returns nonzero if room has new messages
51 int has_newmsgs(struct quickroom *roombuf, int roomnum, struct usersupp *userbuf)
53 if (roombuf->QRhighest > (userbuf->lastseen[roomnum]) )
59 * is_zapped() - returns nonzero if room is on forgotten rooms list
61 int is_zapped(struct quickroom *roombuf, int roomnum, struct usersupp *userbuf)
63 if ((roombuf->QRflags & QR_INUSE)
64 && (roombuf->QRgen == (userbuf->forget[roomnum]) )
65 && ( (roomnum!=2) || ((userbuf->axlevel)>=6))
66 && ( ((roombuf->QRflags&QR_PRIVATE)==0)
67 || ((userbuf->axlevel)>=6)
68 || (roombuf->QRgen==(userbuf->generation[roomnum]))
75 * getroom() - retrieve room data from disk
77 void getroom(struct quickroom *qrbuf, int room_num)
79 struct cdbdata *cdbqr;
82 bzero(qrbuf, sizeof(struct quickroom));
83 cdbqr = cdb_fetch(CDB_QUICKROOM, &room_num, sizeof(int));
85 memcpy(qrbuf, cdbqr->ptr,
86 ( (cdbqr->len > sizeof(struct quickroom)) ?
87 sizeof(struct quickroom) : cdbqr->len) );
92 qrbuf->QRflags = QR_INUSE;
95 case 0: strcpy(qrbuf->QRname, "Lobby");
97 case 1: strcpy(qrbuf->QRname, "Mail");
99 case 2: strcpy(qrbuf->QRname, "Aide");
106 /** FIX ** VILE SLEAZY HACK ALERT!!
107 * This is a temporary fix until we can track down where room names
108 * are getting corrupted on some systems.
110 for (a=0; a<20; ++a) if (qrbuf->QRname[a] < 32) qrbuf->QRname[a] = 0;
111 qrbuf->QRname[19] = 0;
115 * lgetroom() - same as getroom() but locks the record (if supported)
117 void lgetroom(struct quickroom *qrbuf, int room_num)
119 begin_critical_section(S_QUICKROOM);
120 getroom(qrbuf,room_num);
125 * putroom() - store room data on disk
127 void putroom(struct quickroom *qrbuf, int room_num)
129 time(&qrbuf->QRmtime);
130 cdb_store(CDB_QUICKROOM, &room_num, sizeof(int),
131 qrbuf, sizeof(struct quickroom));
136 * lputroom() - same as putroom() but unlocks the record (if supported)
138 void lputroom(struct quickroom *qrbuf, int room_num)
141 putroom(qrbuf,room_num);
142 end_critical_section(S_QUICKROOM);
148 * getfloor() - retrieve floor data from disk
150 void getfloor(struct floor *flbuf, int floor_num)
152 struct cdbdata *cdbfl;
154 bzero(flbuf, sizeof(struct floor));
155 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
157 memcpy(flbuf, cdbfl->ptr,
158 ( (cdbfl->len > sizeof(struct floor)) ?
159 sizeof(struct floor) : cdbfl->len) );
163 if (floor_num == 0) {
164 strcpy(flbuf->f_name, "Main Floor");
165 flbuf->f_flags = F_INUSE;
166 flbuf->f_ref_count = 3;
173 * lgetfloor() - same as getfloor() but locks the record (if supported)
175 void lgetfloor(struct floor *flbuf, int floor_num)
178 begin_critical_section(S_FLOORTAB);
179 getfloor(flbuf,floor_num);
184 * putfloor() - store floor data on disk
186 void putfloor(struct floor *flbuf, int floor_num)
188 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
189 flbuf, sizeof(struct floor));
194 * lputfloor() - same as putfloor() but unlocks the record (if supported)
196 void lputfloor(struct floor *flbuf, int floor_num)
199 putfloor(flbuf,floor_num);
200 end_critical_section(S_FLOORTAB);
207 * get_msglist() - retrieve room message pointers
209 void get_msglist(int room_num)
211 struct cdbdata *cdbfr;
213 if (CC->msglist != NULL) {
220 cdbfr = cdb_fetch(CDB_MSGLISTS, &room_num, sizeof(int));
223 cdbfr = cdb_fetch(CDB_MAILBOXES, &CC->usersupp.usernum,
231 CC->msglist = malloc(cdbfr->len);
232 memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
233 CC->num_msgs = cdbfr->len / sizeof(long);
239 * put_msglist() - retrieve room message pointers
241 void put_msglist(int room_num)
245 cdb_store(CDB_MSGLISTS, &room_num, sizeof(int),
246 CC->msglist, (CC->num_msgs * sizeof(long)) );
249 cdb_store(CDB_MAILBOXES, &CC->usersupp.usernum, sizeof(long),
250 CC->msglist, (CC->num_msgs * sizeof(long)) );
256 * MessageFromList() - get a message number from the list currently in memory
258 long MessageFromList(int whichpos) {
260 /* Return zero if the position is invalid */
261 if (whichpos >= CC->num_msgs) return 0L;
263 return(CC->msglist[whichpos]);
267 * SetMessageInList() - set a message number in the list currently in memory
269 void SetMessageInList(int whichpos, long newmsgnum) {
271 /* Return zero if the position is invalid */
272 if (whichpos >= CC->num_msgs) return;
274 CC->msglist[whichpos] = newmsgnum;
280 * sort message pointers
281 * (returns new msg count)
283 int sort_msglist(long listptrs[], int oldcount)
290 if (numitems < 2) return(oldcount);
293 for (a=numitems-2; a>=0; --a) {
294 for (b=0; b<=a; ++b) {
295 if (listptrs[b] > (listptrs[b+1])) {
297 hold2 = listptrs[b+1];
299 listptrs[b+1] = hold1;
304 /* and yank any nulls */
305 while ( (numitems > 0) && (listptrs[0] == 0L) ) {
306 memcpy(&listptrs[0], &listptrs[1],
307 (sizeof(long) * (CC->num_msgs - 1)) );
318 * cmd_lrms() - List all accessible rooms, known or forgotten
320 void cmd_lrms(char *argbuf)
323 int target_floor = (-1);
324 struct quickroom qrbuf;
326 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
328 if (!(CC->logged_in)) {
329 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
333 if (getuser(&CC->usersupp,CC->curr_user)) {
334 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
338 cprintf("%d Accessible rooms:\n",LISTING_FOLLOWS);
340 for (a=0; a<MAXROOMS; ++a) {
342 if ( ( (is_known(&qrbuf,a,&CC->usersupp))
343 || (is_zapped(&qrbuf,a,&CC->usersupp)) )
344 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) )
345 cprintf("%s|%u|%d\n",
346 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
352 * cmd_lkra() - List all known rooms
354 void cmd_lkra(char *argbuf)
357 struct quickroom qrbuf;
358 int target_floor = (-1);
360 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
362 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
363 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
367 if (!(CC->internal_pgm)) if (getuser(&CC->usersupp,CC->curr_user)) {
368 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
372 cprintf("%d Known rooms:\n",LISTING_FOLLOWS);
374 for (a=0; a<MAXROOMS; ++a) {
376 if ((is_known(&qrbuf,a,&CC->usersupp))
377 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) )
378 cprintf("%s|%u|%d\n",
379 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
385 * cmd_lkrn() - List Known Rooms with New messages
387 void cmd_lkrn(char *argbuf)
390 struct quickroom qrbuf;
391 int target_floor = (-1);
393 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
395 if (!(CC->logged_in)) {
396 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
400 if (getuser(&CC->usersupp,CC->curr_user)) {
401 cprintf("%d can't locate user\n",ERROR+INTERNAL_ERROR);
405 cprintf("%d list of rms w/ new msgs\n",LISTING_FOLLOWS);
407 for (a=0; a<MAXROOMS; ++a) {
409 if ( ( (is_known(&qrbuf,a,&CC->usersupp))
410 && (has_newmsgs(&qrbuf,a,&CC->usersupp)) )
411 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) )
412 cprintf("%s|%u|%d\n",
413 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
419 * cmd_lkro() - List Known Rooms with Old (no new) messages
421 void cmd_lkro(char *argbuf)
424 struct quickroom qrbuf;
425 int target_floor = (-1);
427 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
429 if (!(CC->logged_in)) {
430 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
434 if (getuser(&CC->usersupp,CC->curr_user)) {
435 cprintf("%d can't locate user\n",ERROR+INTERNAL_ERROR);
439 cprintf("%d list of rms w/o new msgs\n",LISTING_FOLLOWS);
441 for (a=0; a<MAXROOMS; ++a) {
443 if ( ( (is_known(&qrbuf,a,&CC->usersupp))
444 && (!has_newmsgs(&qrbuf,a,&CC->usersupp)) )
445 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) ) {
446 if (!strcmp(qrbuf.QRname,"000")) cprintf(">");
447 cprintf("%s|%u|%d\n",
448 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
455 * cmd_lzrm() - List Zapped RooMs
457 void cmd_lzrm(char *argbuf)
460 struct quickroom qrbuf;
461 int target_floor = (-1);
463 if (strlen(argbuf)>0) target_floor = extract_int(argbuf,0);
465 if (!(CC->logged_in)) {
466 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
470 if (getuser(&CC->usersupp,CC->curr_user)) {
471 cprintf("%d can't locate user\n",ERROR+INTERNAL_ERROR);
475 cprintf("%d list of forgotten rms\n",LISTING_FOLLOWS);
477 for (a=0; a<MAXROOMS; ++a) {
479 if ( (is_zapped(&qrbuf,a,&CC->usersupp))
480 && ((qrbuf.QRfloor == target_floor)||(target_floor<0)) ) {
481 if (!strcmp(qrbuf.QRname,"000")) cprintf(">");
482 cprintf("%s|%u|%d\n",
483 qrbuf.QRname,qrbuf.QRflags,qrbuf.QRfloor);
491 void usergoto(int where, int display_result)
497 int newmailcount = 0;
498 struct cdbdata *cdbmb;
503 getroom(&CC->quickroom,CC->curr_rm);
504 lgetuser(&CC->usersupp,CC->curr_user);
505 CC->usersupp.forget[CC->curr_rm]=(-1);
506 CC->usersupp.generation[CC->curr_rm]=CC->quickroom.QRgen;
507 lputuser(&CC->usersupp,CC->curr_user);
509 /* check for new mail */
512 cdbmb = cdb_fetch(CDB_MAILBOXES, &CC->usersupp.usernum, sizeof(long));
514 num_mails = cdbmb->len / sizeof(long);
515 mailbox = (long *) cdbmb->ptr;
516 if (num_mails > 0) for (a=0; a<num_mails; ++a) {
517 if (mailbox[a] > (CC->usersupp.lastseen[1]))
523 /* set info to 1 if the user needs to read the room's info file */
524 if (CC->quickroom.QRinfo > CC->usersupp.lastseen[CC->curr_rm]) info = 1;
528 get_msglist(CC->curr_rm);
529 for (a=0; a<CC->num_msgs; ++a) {
530 if (MessageFromList(a)>0L) {
532 if (MessageFromList(a)
533 > CC->usersupp.lastseen[CC->curr_rm]) ++c;
538 if (CC->curr_rm == 1) rmailflag = 1;
541 if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
542 || (CC->usersupp.axlevel>=6) ) raideflag = 1;
545 if (display_result) cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
547 CC->quickroom.QRname,c,b,info,CC->quickroom.QRflags,
548 CC->quickroom.QRhighest,CC->usersupp.lastseen[CC->curr_rm],
549 rmailflag,raideflag,newmailcount,CC->quickroom.QRfloor);
550 if (CC->quickroom.QRflags & QR_PRIVATE) {
551 set_wtmpsupp("<private room>");
554 set_wtmpsupp(CC->quickroom.QRname);
560 * cmd_goto() - goto a new room
562 void cmd_goto(char *gargs)
564 struct quickroom QRscratch;
567 char bbb[20],towhere[32],password[20];
569 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
570 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
574 extract(towhere,gargs,0);
575 extract(password,gargs,1);
578 getuser(&CC->usersupp,CC->curr_user);
579 for (a=0; a<MAXROOMS; ++a) {
580 getroom(&QRscratch,a);
581 if ((a==0)&&(!strcasecmp(towhere,"_BASEROOM_"))) {
582 strncpy(towhere,QRscratch.QRname,31);
584 if ((a==1)&&(!strcasecmp(towhere,"_MAIL_"))) {
585 strncpy(towhere,QRscratch.QRname,31);
587 if ((!strcasecmp(QRscratch.QRname,config.c_twitroom))
588 &&(!strcasecmp(towhere,"_BITBUCKET_"))) {
589 strncpy(towhere,QRscratch.QRname,31);
591 strcpy(bbb,QRscratch.QRname);
594 /* let internal programs go directly to any room */
595 if (((CC->internal_pgm))&&(!strcasecmp(bbb,towhere))) {
600 /* normal clients have to pass through security */
602 (strcasecmp(bbb,towhere)==0)
603 && ((QRscratch.QRflags&QR_INUSE)!=0)
605 && ( ((QRscratch.QRflags&QR_PREFONLY)==0)
606 || (CC->usersupp.axlevel>=5)
609 && ( (a!=2) || (CC->usersupp.axlevel>=6) )
611 && ( ((QRscratch.QRflags&QR_PRIVATE)==0)
612 || (QRscratch.QRflags&QR_GUESSNAME)
613 || (CC->usersupp.axlevel>=6)
614 || (QRscratch.QRflags&QR_PASSWORDED)
615 || (QRscratch.QRgen==CC->usersupp.generation[a])
623 if ( (QRscratch.QRflags&QR_PASSWORDED) &&
624 (CC->usersupp.axlevel<6) &&
625 (QRscratch.QRgen!=CC->usersupp.generation[a]) &&
626 (strcasecmp(QRscratch.QRpasswd,password))
628 cprintf("%d wrong or missing passwd\n",
629 ERROR+PASSWORD_REQUIRED);
638 cprintf("%d room '%s' not found\n",ERROR+ROOM_NOT_FOUND,towhere);
642 void cmd_whok(void) {
643 struct usersupp temp;
644 struct cdbdata *cdbus;
646 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
647 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
650 getuser(&CC->usersupp,CC->curr_user);
652 if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
653 cprintf("%d Higher access required.\n",
654 ERROR+HIGHER_ACCESS_REQUIRED);
658 cprintf("%d Who knows room:\n",LISTING_FOLLOWS);
659 cdb_rewind(CDB_USERSUPP);
660 while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
661 bzero(&temp, sizeof(struct usersupp));
662 memcpy(&temp, cdbus->ptr, cdbus->len);
664 if ((CC->quickroom.QRflags & QR_INUSE)
665 && ( (CC->curr_rm!=2) || (temp.axlevel>=6) )
666 && (CC->quickroom.QRgen != (temp.forget[CC->curr_rm]) )
668 && ( ((CC->quickroom.QRflags&QR_PREFONLY)==0)
672 && ( ((CC->quickroom.QRflags&QR_PRIVATE)==0)
674 || (CC->quickroom.QRgen==(temp.generation[CC->curr_rm]))
677 && (strncmp(temp.fullname,"000",3))
679 ) cprintf("%s\n",temp.fullname);
686 * RDIR command for room directory
688 void cmd_rdir(void) {
695 if (!(CC->logged_in)) {
696 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
700 getroom(&CC->quickroom,CC->curr_rm);
701 getuser(&CC->usersupp,CC->curr_user);
703 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
704 cprintf("%d not here.\n",ERROR+NOT_HERE);
708 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
709 && (CC->usersupp.axlevel<6)
710 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
711 cprintf("%d not here.\n",ERROR+HIGHER_ACCESS_REQUIRED);
715 cprintf("%d %s|%s/files/%s\n",
716 LISTING_FOLLOWS,config.c_fqdn,BBSDIR,CC->quickroom.QRdirname);
718 sprintf(buf,"cd %s/files/%s; ls >%s 2>/dev/null",
719 BBSDIR,CC->quickroom.QRdirname,CC->temp);
722 sprintf(buf,"%s/files/%s/filedir",BBSDIR,CC->quickroom.QRdirname);
724 if (fd==NULL) fd=fopen("/dev/null","r");
726 ls = fopen(CC->temp,"r");
727 while (fgets(flnm,256,ls)!=NULL) {
728 flnm[strlen(flnm)-1]=0;
729 if (strcasecmp(flnm,"filedir")) {
730 sprintf(buf,"%s/files/%s/%s",
731 BBSDIR,CC->quickroom.QRdirname,flnm);
735 while ((fgets(buf,256,fd)!=NULL)
736 &&(strlen(comment)==0)) {
737 buf[strlen(buf)-1] = 0;
738 if ((!strncasecmp(buf,flnm,strlen(flnm)))
739 && (buf[strlen(flnm)]==' '))
741 &buf[strlen(flnm)+1],255);
743 cprintf("%s|%ld|%s\n",flnm,statbuf.st_size,comment);
754 * get room parameters (aide or room aide command)
756 void cmd_getr(void) {
757 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
758 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
762 if ( (!is_room_aide()) && (!(CC->internal_pgm)) ) {
763 cprintf("%d Higher access required.\n",
764 ERROR+HIGHER_ACCESS_REQUIRED);
768 if (CC->curr_rm < 3) {
769 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
773 getroom(&CC->quickroom,CC->curr_rm);
774 cprintf("%d%c%s|%s|%s|%d|%d\n",
776 CC->quickroom.QRname,
777 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
778 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
779 CC->quickroom.QRflags,
780 (int)CC->quickroom.QRfloor);
785 * set room parameters (aide or room aide command)
787 void cmd_setr(char *args) {
792 if (!(CC->logged_in)) {
793 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
797 if (!is_room_aide()) {
798 cprintf("%d Higher access required.\n",
799 ERROR+HIGHER_ACCESS_REQUIRED);
803 if (CC->curr_rm < 3) {
804 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
808 if (num_parms(args)>=6) {
809 getfloor(&flbuf,extract_int(args,5));
810 if ((flbuf.f_flags & F_INUSE) == 0) {
811 cprintf("%d Invalid floor number.\n",
812 ERROR+INVALID_FLOOR_OPERATION);
817 lgetroom(&CC->quickroom,CC->curr_rm);
818 extract(buf,args,0); buf[20]=0;
819 strncpy(CC->quickroom.QRname,buf,19);
820 extract(buf,args,1); buf[10]=0;
821 strncpy(CC->quickroom.QRpasswd,buf,9);
822 extract(buf,args,2); buf[15]=0;
823 strncpy(CC->quickroom.QRdirname,buf,19);
824 CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
826 /* Clean up a client boo-boo: if the client set the room to
827 * guess-name or passworded, ensure that the private flag is
830 if ((CC->quickroom.QRflags & QR_GUESSNAME)
831 ||(CC->quickroom.QRflags & QR_PASSWORDED))
832 CC->quickroom.QRflags |= QR_PRIVATE;
834 /* Kick everyone out if the client requested it */
835 if (extract_int(args,4)) {
836 ++CC->quickroom.QRgen;
837 if (CC->quickroom.QRgen==100) CC->quickroom.QRgen=1;
840 old_floor = CC->quickroom.QRfloor;
841 if (num_parms(args)>=6) {
842 CC->quickroom.QRfloor = extract_int(args,5);
845 lputroom(&CC->quickroom,CC->curr_rm);
847 /* adjust the floor reference counts */
848 lgetfloor(&flbuf,old_floor);
850 lputfloor(&flbuf,old_floor);
851 lgetfloor(&flbuf,CC->quickroom.QRfloor);
853 lputfloor(&flbuf,CC->quickroom.QRfloor);
855 /* create a room directory if necessary */
856 if (CC->quickroom.QRflags & QR_DIRECTORY) {
858 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
859 CC->quickroom.QRdirname);
863 sprintf(buf,"%s> edited by %s",CC->quickroom.QRname,CC->curr_user);
865 cprintf("%d Ok\n",OK);
871 * get the name of the room aide for this room
873 void cmd_geta(void) {
874 struct usersupp usbuf;
876 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
877 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
881 if (CC->curr_rm < 0) {
882 cprintf("%d No current room.\n",ERROR);
886 if (getuserbynumber(&usbuf,CC->quickroom.QRroomaide)==0) {
887 cprintf("%d %s\n",OK,usbuf.fullname);
896 * set the room aide for this room
898 void cmd_seta(char *new_ra)
900 struct usersupp usbuf;
905 if (!(CC->logged_in)) {
906 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
910 if (!is_room_aide()) {
911 cprintf("%d Higher access required.\n",
912 ERROR+HIGHER_ACCESS_REQUIRED);
916 if (CC->curr_rm < 3) {
917 cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
921 if (getuser(&usbuf,new_ra)!=0) {
925 newu = usbuf.usernum;
928 lgetroom(&CC->quickroom,CC->curr_rm);
930 if (CC->quickroom.QRroomaide != newu) {
933 CC->quickroom.QRroomaide = newu;
934 lputroom(&CC->quickroom,CC->curr_rm);
937 * We have to post the change notice _after_ writing changes to
938 * the room table, otherwise it would deadlock!
940 if (post_notice == 1) {
941 sprintf(buf,"%s is now room aide for %s>",
942 usbuf.fullname,CC->quickroom.QRname);
945 cprintf("%d Ok\n",OK);
950 * retrieve info file for this room
952 void cmd_rinf(void) {
957 sprintf(filename,"./info/%d",CC->curr_rm);
958 info_fp = fopen(filename,"r");
961 cprintf("%d No info file.\n",ERROR);
965 cprintf("%d Info:\n",LISTING_FOLLOWS);
966 while (fgets(buf, 256, info_fp) != NULL) {
967 if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
968 cprintf("%s\n", buf);
975 * aide command: kill the current room
977 void cmd_kill(char *argbuf)
985 kill_ok = extract_int(argbuf,0);
987 if (!(CC->logged_in)) {
988 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
992 if (!is_room_aide()) {
993 cprintf("%d Higher access required.\n",
994 ERROR+HIGHER_ACCESS_REQUIRED);
998 if (CC->curr_rm < 3) {
999 cprintf("%d Can't kill this room.\n",ERROR+NOT_HERE);
1005 /* first flag the room record as not in use */
1006 lgetroom(&CC->quickroom,CC->curr_rm);
1007 CC->quickroom.QRflags=0;
1009 /* then delete the messages in the room */
1010 get_msglist(CC->curr_rm);
1011 if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
1012 MsgToDelete = MessageFromList(a);
1013 cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
1015 put_msglist(CC->curr_rm);
1018 cdb_delete(CDB_MSGLISTS, &CC->curr_rm, sizeof(int));
1020 lputroom(&CC->quickroom,CC->curr_rm);
1023 /* then decrement the reference count for the floor */
1024 lgetfloor(&flbuf,(int)CC->quickroom.QRfloor);
1025 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1026 lputfloor(&flbuf,(int)CC->quickroom.QRfloor);
1028 /* tell the world what we did */
1029 sprintf(aaa,"%s> killed by %s",CC->quickroom.QRname,CC->curr_user);
1032 cprintf("%d '%s' deleted.\n",OK,CC->quickroom.QRname);
1035 cprintf("%d ok to delete.\n",OK);
1041 * Find a free slot to create a new room in, or return -1 for error.
1042 * search_dir is the direction to search in. 1 causes this function to
1043 * return the first available slot, -1 gets the last available slot.
1045 int get_free_room_slot(int search_dir)
1048 struct quickroom qrbuf;
1050 st = ((search_dir>0) ? 3 : (MAXROOMS-1));
1052 for (a=st; ((a<MAXROOMS)&&(a>=3)); a=a+search_dir) {
1054 if ((qrbuf.QRflags & QR_INUSE)==0) return(a);
1061 * internal code to create a new room (returns room flags)
1063 unsigned create_room(int free_slot, char *new_room_name, int new_room_type, char *new_room_pass, int new_room_floor)
1065 struct quickroom qrbuf;
1068 lgetroom(&qrbuf,free_slot);
1069 strncpy(qrbuf.QRname,new_room_name,19);
1070 strncpy(qrbuf.QRpasswd,new_room_pass,9);
1071 qrbuf.QRflags = QR_INUSE;
1072 if (new_room_type > 0) qrbuf.QRflags=(qrbuf.QRflags|QR_PRIVATE);
1073 if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
1074 if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
1075 qrbuf.QRroomaide = (-1L);
1076 if ((new_room_type > 0)&&(CREATAIDE==1))
1077 qrbuf.QRroomaide=CC->usersupp.usernum;
1078 qrbuf.QRhighest = 0L;
1079 ++qrbuf.QRgen; if (qrbuf.QRgen>=126) qrbuf.QRgen=10;
1080 qrbuf.QRfloor = new_room_floor;
1082 /* save what we just did... */
1083 lputroom(&qrbuf,free_slot);
1085 /* bump the reference count on whatever floor the room is on */
1086 lgetfloor(&flbuf,(int)qrbuf.QRfloor);
1087 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1088 lputfloor(&flbuf,(int)qrbuf.QRfloor);
1090 /* be sure not to kick the creator out of the room! */
1091 lgetuser(&CC->usersupp,CC->curr_user);
1092 CC->usersupp.generation[free_slot] = qrbuf.QRgen;
1093 CC->usersupp.forget[free_slot] = (-1);
1094 lputuser(&CC->usersupp,CC->curr_user);
1096 /* resume our happy day */
1097 return(qrbuf.QRflags);
1104 void cmd_cre8(char *args)
1109 char new_room_name[256];
1111 char new_room_pass[256];
1115 struct quickroom qrbuf;
1118 cre8_ok = extract_int(args,0);
1119 extract(new_room_name,args,1);
1120 new_room_name[19] = 0;
1121 new_room_type = extract_int(args,2);
1122 extract(new_room_pass,args,3);
1123 new_room_pass[9] = 0;
1126 if ((strlen(new_room_name)==0) && (cre8_ok==1)) {
1127 cprintf("%d Invalid room name.\n",ERROR);
1131 if (num_parms(args)>=5) {
1132 getfloor(&flbuf,extract_int(args,4));
1133 if ((flbuf.f_flags & F_INUSE) == 0) {
1134 cprintf("%d Invalid floor number.\n",
1135 ERROR+INVALID_FLOOR_OPERATION);
1139 new_room_floor = extract_int(args,4);
1143 if (!(CC->logged_in)) {
1144 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1148 if (CC->usersupp.axlevel<3) {
1149 cprintf("%d You need higher access to create rooms.\n",
1150 ERROR+HIGHER_ACCESS_REQUIRED);
1154 free_slot = get_free_room_slot(1);
1156 cprintf("%d There is no space available for a new room.\n",
1162 cprintf("%d ok to create...\n",OK);
1166 for (a=0; a<MAXROOMS; ++a) {
1168 if ( (!strcasecmp(qrbuf.QRname,new_room_name))
1169 && (qrbuf.QRflags & QR_INUSE) ) {
1170 cprintf("%d '%s' already exists.\n",
1171 ERROR,qrbuf.QRname);
1176 if ((new_room_type < 0) || (new_room_type > 3)) {
1177 cprintf("%d Invalid room type.\n",ERROR);
1181 newflags = create_room(free_slot,new_room_name,
1182 new_room_type,new_room_pass,new_room_floor);
1184 /* post a message in Aide> describing the new room */
1185 strncpy(aaa,new_room_name,255);
1186 strcat(aaa,"> created by ");
1187 strcat(aaa,CC->usersupp.fullname);
1188 if (newflags&QR_PRIVATE) strcat(aaa," [private]");
1189 if (newflags&QR_GUESSNAME) strcat(aaa,"[guessname] ");
1190 if (newflags&QR_PASSWORDED) {
1191 strcat(aaa,"\n Password: ");
1192 strcat(aaa,new_room_pass);
1196 sprintf(aaa,"./info/%d",free_slot); /* delete old info file */
1198 sprintf(aaa,"./images/room.%d.gif",free_slot); /* and picture */
1201 cprintf("%d '%s' has been created.\n",OK,qrbuf.QRname);
1206 void cmd_einf(char *ok)
1207 { /* enter info file for current room */
1209 char infofilename[32];
1212 if (!(CC->logged_in)) {
1213 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1217 if (!is_room_aide()) {
1218 cprintf("%d Higher access required.\n",
1219 ERROR+HIGHER_ACCESS_REQUIRED);
1224 cprintf("%d Ok.\n",OK);
1228 cprintf("%d Send info...\n",SEND_LISTING);
1230 sprintf(infofilename,"./info/%d",CC->curr_rm);
1232 fp=fopen(infofilename,"w");
1235 if (strcmp(buf,"000")) fprintf(fp,"%s\n",buf);
1236 } while(strcmp(buf,"000"));
1239 /* now update the room index so people will see our new info */
1240 lgetroom(&CC->quickroom,CC->curr_rm); /* lock so no one steps on us */
1241 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1242 lputroom(&CC->quickroom,CC->curr_rm);
1247 * cmd_lflr() - List all known floors
1249 void cmd_lflr(void) {
1253 if (!(CC->logged_in)) {
1254 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1258 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1259 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1264 cprintf("%d Known floors:\n",LISTING_FOLLOWS);
1266 for (a=0; a<MAXFLOORS; ++a) {
1268 if (flbuf.f_flags & F_INUSE) {
1269 cprintf("%d|%s|%d\n",
1281 * create a new floor
1283 void cmd_cflr(char *argbuf)
1285 char new_floor_name[256];
1288 int free_slot = (-1);
1291 extract(new_floor_name,argbuf,0);
1292 cflr_ok = extract_int(argbuf,1);
1295 if (!(CC->logged_in)) {
1296 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1300 if (CC->usersupp.axlevel<6) {
1301 cprintf("%d You need higher access to create rooms.\n",
1302 ERROR+HIGHER_ACCESS_REQUIRED);
1306 for (a=0; a<MAXFLOORS; ++a) {
1309 /* note any free slots while we're scanning... */
1310 if ( ((flbuf.f_flags & F_INUSE)==0)
1311 && (free_slot < 0) ) free_slot = a;
1313 /* check to see if it already exists */
1314 if ( (!strcasecmp(flbuf.f_name,new_floor_name))
1315 && (flbuf.f_flags & F_INUSE) ) {
1316 cprintf("%d Floor '%s' already exists.\n",
1317 ERROR+ALREADY_EXISTS,
1325 cprintf("%d There is no space available for a new floor.\n",
1326 ERROR+INVALID_FLOOR_OPERATION);
1331 cprintf("%d ok to create...\n",OK);
1335 lgetfloor(&flbuf,free_slot);
1336 flbuf.f_flags = F_INUSE;
1337 flbuf.f_ref_count = 0;
1338 strncpy(flbuf.f_name,new_floor_name,255);
1339 lputfloor(&flbuf,free_slot);
1340 cprintf("%d %d\n",OK,free_slot);
1348 void cmd_kflr(char *argbuf)
1351 int floor_to_delete;
1355 floor_to_delete = extract_int(argbuf,0);
1356 kflr_ok = extract_int(argbuf,1);
1359 if (!(CC->logged_in)) {
1360 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1364 if (CC->usersupp.axlevel<6) {
1365 cprintf("%d You need higher access to delete floors.\n",
1366 ERROR+HIGHER_ACCESS_REQUIRED);
1370 lgetfloor(&flbuf,floor_to_delete);
1373 if ((flbuf.f_flags & F_INUSE) == 0) {
1374 cprintf("%d Floor %d not in use.\n",
1375 ERROR+INVALID_FLOOR_OPERATION,floor_to_delete);
1380 if (flbuf.f_ref_count != 0) {
1381 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1382 ERROR+INVALID_FLOOR_OPERATION,
1389 cprintf("%d Ok\n",OK);
1392 cprintf("%d Ok to delete...\n",OK);
1399 if ( (delete_ok == 1) && (kflr_ok == 1) ) flbuf.f_flags = 0;
1400 lputfloor(&flbuf,floor_to_delete);
1406 void cmd_eflr(char *argbuf)
1412 np = num_parms(argbuf);
1414 cprintf("%d Usage error.\n",ERROR);
1418 if (!(CC->logged_in)) {
1419 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
1423 if (CC->usersupp.axlevel<6) {
1424 cprintf("%d You need higher access to edit floors.\n",
1425 ERROR+HIGHER_ACCESS_REQUIRED);
1429 floor_num = extract_int(argbuf,0);
1430 lgetfloor(&flbuf,floor_num);
1431 if ( (flbuf.f_flags & F_INUSE) == 0) {
1432 lputfloor(&flbuf,floor_num);
1433 cprintf("%d Floor %d is not in use.\n",
1434 ERROR+INVALID_FLOOR_OPERATION,floor_num);
1437 if (np >= 2) extract(flbuf.f_name,argbuf,1);
1438 lputfloor(&flbuf,floor_num);
1440 cprintf("%d Ok\n",OK);