/* * allows a user to rename their room */ void personal_room_rename(UR_OBJECT user, char *inpstr) { if (!amsys->personal_rooms) { write_user(user, "Personal room functions are currently disabled.\n"); return; } if (word_count < 2) { write_user(user, "Usage: myname <name you want room to have>\n"); return; } if (strcmp(user->room->owner, user->name)) { write_user(user, "You have to be in your personal room to rename it.\n"); return; } if (strlen(inpstr) > PERSONAL_ROOMNAME_LEN) { write_user(user, "You cannot have a room name that long.\n"); return; } if (strlen(inpstr) - teslen(inpstr, 0) < 1) { write_user(user, "You must enter a room name.\n"); return; } strcpy(user->room->show_name, inpstr); vwrite_user(user, "You have now renamed your room to: %s\n", user->room->show_name); if (!personal_room_store(user->name, 1, user->room)) { write_syslog(SYSLOG | ERRLOG, 1, "ERROR: Unable to save personal room status in personal_room_rename()\n"); } }
/* allows a user to rename their room */ void personal_room_rename(UR_OBJECT user,char *inpstr) { char name[ROOM_NAME_LEN+1]; RM_OBJECT rm; if (!amsys->personal_rooms) { write_user(user,"Personal room functions are currently disabled.\n"); return; } if (word_count<2) { write_usage(user, "%s <nazov>\n", command_table[MYNAME].name); return; } sprintf(name,"(%s)",user->name); strtolower(name); /* get room that user is in */ if ((rm=get_room_full(name))==NULL) { write_user(user,"Sorry, but you cannot use the room renaming feature at this time.\n"); return; } if (user->room!=rm) { write_user(user,"You have to be in your personal room to rename it.\n"); return; } if (strlen(inpstr)>PERSONAL_ROOMNAME_LEN) { write_user(user,"You cannot have a room name that long.\n"); return; } strcpy(rm->real_name,inpstr); vwrite_user(user,"You have now renamed your room to: %s\n",rm->real_name); if (!personal_room_store(user->name,1,rm)) write_syslog(SYSLOG,1,"ERROR: Unable to save personal room status in personal_room_rename()\n"); }
/* * Enter a description for a personal room */ void personal_room_decorate(UR_OBJECT user, char *inpstr) { if (inpstr) { if (!amsys->personal_rooms) { write_user(user, "Personal room functions are currently disabled.\n"); return; } if (strcmp(user->room->owner, user->name)) { write_user(user, "You have to be in your personal room to decorate it.\n"); return; } if (word_count < 2) { write_user(user, "\n~BB*** Decorating your personal room ***\n\n"); user->misc_op = 19; editor(user, NULL); return; } strcat(inpstr, "\n"); } else { inpstr = user->malloc_start; } *user->room->desc = '\0'; strncat(user->room->desc, inpstr, ROOM_DESC_LEN); if (strlen(user->room->desc) < strlen(inpstr)) { vwrite_user(user, "The description is too long for the room \"%s\".\n", user->room->name); } write_user(user, "You have now redecorated your personal room.\n"); if (!personal_room_store(user->name, 1, user->room)) { write_syslog(SYSLOG | ERRLOG, 1, "ERROR: Unable to save personal room status in personal_room_decorate()\n"); } }
/* * Parse the user rooms */ void parse_user_rooms(void) { char dirname[80], name[USER_NAME_LEN + 1], *s; DIR *dirp; struct dirent *dp; RM_OBJECT rm; sprintf(dirname, "%s/%s", USERFILES, USERROOMS); dirp = opendir(dirname); if (!dirp) { fprintf(stderr, "Amnuts: Directory open failure in parse_user_rooms().\n"); boot_exit(19); } /* parse the names of the files but do not include . and .. */ for (dp = readdir(dirp); dp; dp = readdir(dirp)) { s = strchr(dp->d_name, '.'); if (!s || strcmp(s, ".R")) { continue; } *name = '\0'; strncat(name, dp->d_name, (size_t) (s - dp->d_name)); rm = create_room(); if (!personal_room_store(name, 0, rm)) { write_syslog(SYSLOG | ERRLOG, 1, "ERROR: Could not read personal room attributes. Using standard config.\n"); } } closedir(dirp); }
/* * allows a user to lock their room out to access from anyone */ void personal_room_lock(UR_OBJECT user) { if (!amsys->personal_rooms) { write_user(user, "Personal room functions are currently disabled.\n"); return; } if (strcmp(user->room->owner, user->name)) { write_user(user, "You have to be in your personal room to lock and unlock it.\n"); return; } user->room->access ^= PRIVATE; if (is_private_room(user->room)) { write_user(user, "You have now ~OL~FRlocked~RS your room to all the other users.\n"); } else { write_user(user, "You have now ~OL~FGunlocked~RS your room to all the other users.\n"); } if (!personal_room_store(user->name, 1, user->room)) write_syslog(SYSLOG | ERRLOG, 1, "ERROR: Unable to save personal room status in personal_room_lock()\n"); }
/* * lets a user enter their own room. It creates the room if !exists */ void personal_room(UR_OBJECT user) { char rmname[ROOM_NAME_LEN + 1], filename[80]; UR_OBJECT u; RM_OBJECT rm; if (!amsys->personal_rooms) { write_user(user, "Personal room functions are currently disabled.\n"); return; } sprintf(rmname, "(%s)", user->name); strtolower(rmname); rm = get_room_full(rmname); /* if the user wants to delete their room */ if (word_count >= 2) { if (strcmp(word[1], "-d")) { write_user(user, "Usage: myroom [-d]\n"); return; } /* move to the user out of the room if they are in it */ if (!rm) { write_user(user, "You do not have a personal room built.\n"); return; } if (room_visitor_count(rm)) { write_user(user, "You cannot destroy your room if any people are in it.\n"); return; } write_user(user, "~OL~FRYou whistle a sharp spell and watch your room crumble into dust.~RS\n"); /* remove invites */ for (u = user_first; u; u = u->next) { if (u->invite_room == rm) { u->invite_room = NULL; } } /* remove all the key flags */ write_user(user, "~OL~FRAll keys to your room crumble to ashes.~RS\n"); all_unsetbit_flagged_user_entry(user, fufROOMKEY); /* destroy */ destruct_room(rm); /* delete the files */ sprintf(filename, "%s/%s/%s.R", USERFILES, USERROOMS, user->name); remove(filename); sprintf(filename, "%s/%s/%s.B", USERFILES, USERROOMS, user->name); remove(filename); sprintf(filename, "%s/%s/%s.K", USERFILES, USERROOMS, user->name); remove(filename); write_syslog(SYSLOG, 1, "%s destructed their personal room.\n", user->name); return; } /* if the user is moving to their room */ if (user->lroom == 2) { write_user(user, "You have been shackled and cannot move.\n"); return; } /* if room does not exist then create it */ if (!rm) { rm = create_room(); if (!rm) { write_user(user, "Sorry, but your room cannot be created at this time.\n"); write_syslog(SYSLOG | ERRLOG, 0, "ERROR: Cannot create room for in personal_room()\n"); return; } write_user(user, "\nYour room does not exists. Building it now...\n\n"); /* check to see if the room was just unloaded from memory first */ if (!personal_room_store(user->name, 0, rm)) { write_syslog(SYSLOG, 1, "%s creates their own room.\n", user->name); if (!personal_room_store(user->name, 1, rm)) { write_syslog(SYSLOG | ERRLOG, 1, "ERROR: Unable to save personal room status in personal_room()\n"); } } } /* if room just created then should not go in his block */ if (user->room == rm) { write_user(user, "You are already in your own room!\n"); return; } move_user(user, rm, 1); }
/****************************************************************************** The loading up and parsing of the configuration file *****************************************************************************/ void load_and_parse_config(void) { FILE *fp; char line[256+1]; /* Should be long enough */ char fname[FNAME_LEN], c; int i,section_in=0,got_init=0,got_rooms=0,got_topics=0, got_transport=0; RM_OBJECT rm1,rm2; #ifdef NETLINKS NL_OBJECT nl; #endif set_crash(); printf("Parsing config file \"%s\"...\n", confile); if (!(fp=fopen(confile,"r"))) { perror("Lotos: Can't open config file\n"); boot_exit(1); } /* Main reading loop */ config_line=0; fgets(line,81,fp); while (!feof(fp)) { config_line++; for(i=0;i<8;++i) wrd[i][0]='\0'; sscanf(line,"%s %s %s %s %s %s %s %s",wrd[0],wrd[1],wrd[2],wrd[3],wrd[4],wrd[5],wrd[6],wrd[7]); if (wrd[0][0]=='#' || wrd[0][0]=='\0') { fgets(line,81,fp); continue; } /* See if new section */ if (wrd[0][strlen(wrd[0])-1]==':') { if (!strcmp(wrd[0],"INIT:")) section_in=1; else if (!strcmp(wrd[0],"ROOMS:")) section_in=2; else if (!strcmp(wrd[0],"TOPICS:")) section_in=3; else if (!strcmp(wrd[0],"SITES:")) section_in=4; else if (!strcmp(wrd[0],"TRANSPORTS:")) section_in=5; else { fprintf(stderr, "Lotos: Unknown section header on line %d.\n",config_line); fclose(fp); boot_exit(1); } } switch (section_in) { case 1: parse_init_section(); got_init=1; break; case 2: parse_rooms_section(); got_rooms=1; break; case 3: parse_topics_section(remove_first(line)); got_topics=1; break; case 4: #ifdef NETLINKS parse_sites_section(); break; #else break; #endif case 5: parse_transports_section(); got_transport=1; break; default: fprintf(stderr,"Lotos: Section header expected on line %d.\n",config_line); fclose(fp); boot_exit(1); } fgets(line,81,fp); } fclose(fp); /* See if required sections were present (SITES and TOPICS is optional) and if required parameters were set. */ if (!got_init) { fprintf(stderr,"Lotos: INIT section missing from config file.\n"); boot_exit(1); } if (got_topics && !got_rooms) { fprintf(stderr,"Lotos: TOPICS section must come after ROOMS section in the config file.\n"); boot_exit(1); } if (got_transport && !got_rooms) { fprintf(stderr,"Lotos: TRANSPORTS section must come after ROOMS section in the config file.\n"); boot_exit(1); } if (got_topics && !got_transport) { fprintf(stderr,"Lotos: TOPICS section must come after TRANSPORTS section in the config file.\n"); boot_exit(1); } if (!got_rooms) { fprintf(stderr,"Lotos: ROOMS section missing from config file.\n"); boot_exit(1); } if (!got_transport) { fprintf(stderr,"Lotos: TRANSPORTS section missing from config file.\n"); boot_exit(1); } if (!port[0]) { fprintf(stderr,"Lotos: Main port number not set in config file.\n"); boot_exit(1); } if (!port[1]) { fprintf(stderr,"Lotos: Wiz port number not set in config file.\n"); boot_exit(1); } #ifdef NETLINKS if (!port[2]) { fprintf(stderr,"Lotos: Link port number not set in config file.\n"); boot_exit(1); } if (!verification[0]) { fprintf(stderr,"Lotos: Verification not set in config file.\n"); boot_exit(1); } if (port[0]==port[1] || port[1]==port[2] || port[0]==port[2] ) { #else if (port[0]==port[1]) { #endif fprintf(stderr,"Lotos: Port numbers must be unique.\n"); boot_exit(1); } if (room_first==NULL) { fprintf(stderr,"Lotos: No rooms configured in config file.\n"); boot_exit(1); } if (!syspp->auto_save) { fprintf(stderr,"Lotos: autosave period not set in config file.\n"); boot_exit(1); } if (syspp->auto_afk && syspp->auto_afk_time>=(amsys->user_idle_time-60)) { fprintf(stderr, "Lotos: Auto_afk_time musi byt vacsie ako user_idle_time-60.\n"); exit(1); } /* Parsing done, now check data is valid. Check room stuff first. */ for (rm1=room_first; rm1!=NULL; rm1=rm1->next) { if (rm1->transp!=NULL && rm1->link_label[1]=='\0') { fprintf(stderr, "Rooma %s je transport, preto musi mat minimalne 2 linky\n", rm1->name); boot_exit(1); } for (i=0;i<MAX_LINKS;++i) { if (!rm1->link_label[i][0]) break; if ((!strcmp(rm1->link_label[i], no_leave)) && (rm1->transp==NULL)) break; if ((!strcmp(rm1->link_label[i], no_leave)) && rm1->transp!=NULL) { fprintf(stderr,"Lotos: Rooma %s je transport, preto nemoze byt bez linkov\n", rm1->name); boot_exit(1); } for (rm2=room_first;rm2!=NULL;rm2=rm2->next) { if (rm1==rm2) continue; if (!strcmp(rm1->link_label[i],rm2->label)) { if (rm2->transp!=NULL) { fprintf(stderr,"Rooma %s nemoze byt nalinkovana na iny transport\n", rm1->name); boot_exit(1); } rm1->link[i]=rm2; break; } } if (rm1->link[i]==NULL) { fprintf(stderr,"Lotos: Room %s has undefined link label '%s'.\n",rm1->name,rm1->link_label[i]); boot_exit(1); } } } #ifdef NETLINKS /* Check external links */ for (rm1=room_first;rm1!=NULL;rm1=rm1->next) { if (rm1->netlink_name[0] && rm1->transp!=NULL) { fprintf(stderr, "Rooma %s je nadefinovana ako transport a preto nemoze mat netlink\n", rm1->name); boot_exit(1); } for (nl=nl_first;nl!=NULL;nl=nl->next) { if (!strcmp(nl->service,rm1->name)) { fprintf(stderr,"Lotos: Service name %s is also the name of a room.\n",nl->service); boot_exit(1); } if (rm1->netlink_name[0] && !strcmp(rm1->netlink_name,nl->service)) { rm1->netlink=nl; break; } } if (rm1->netlink_name[0] && rm1->netlink==NULL) { fprintf(stderr,"Lotos: Service name %s not defined for room %s.\n",rm1->netlink_name,rm1->name); boot_exit(1); } } #endif /* Load room descriptions */ for (rm1=room_first;rm1!=NULL;rm1=rm1->next) { if (rm1->transp!=NULL) sprintf(fname,"%s/%s.R", TRFILES, rm1->name); else sprintf(fname,"%s/%s.R", ROOMFILES, rm1->name); if (!(fp=fopen(fname,"r"))) { fprintf(stderr,"Lotos: Can't open description file for room %s.\n",rm1->name); write_syslog(ERRLOG,1,"Couldn't open description file for room %s.\n",rm1->name); continue; } i=0; c=getc(fp); while (!feof(fp)) { if (i==ROOM_DESC_LEN) { fprintf(stderr,"Lotos: Description too long for room %s.\n",rm1->name); write_syslog(ERRLOG,1,"Description too long for room %s.\n",rm1->name); break; } rm1->desc[i]=c; c=getc(fp); ++i; } rm1->desc[i]='\0'; fclose(fp); } } /*** Parse the user rooms ***/ void parse_user_rooms(void) { DIR *dirp; struct dirent *dp; char name[USER_NAME_LEN]; RM_OBJECT rm; if (!(dirp=opendir(USERROOMS))) { fprintf(stderr,"Lotos: Directory open failure in parse_user_rooms().\n"); boot_exit(19); } /* parse the names of the files but don't include . and .. */ while ((dp=readdir(dirp))!=NULL) { if (!strcmp(dp->d_name,".") || !strcmp(dp->d_name,"..")) continue; if (strstr(dp->d_name,".R")) { strcpy(name,dp->d_name); name[strlen(name)-2]='\0'; rm=create_room(); if (!(personal_room_store(name,0,rm))) { write_syslog(ERRLOG,1,"Could not read personal room attributes. Using standard config.\n"); } strtolower(name); sprintf(rm->name,"(%s)",name); } } closedir(dirp); }