Exemple #1
0
	JusticeRegion::JusticeRegion( Clib::ConfigElem& elem, RegionId id ) :
	  Region( elem, id ),
	  guarded_( elem.remove_bool( "Guarded", false ) ),
	  nocombat_( elem.remove_bool( "NoCombat", false ) ),
	  region_name_( elem.rest() ),
	  entertext_( elem.remove_string( "EnterText", "" ) ),
	  leavetext_( elem.remove_string( "LeaveText", "" ) ),
	  enter_script_( elem.remove_string( "EnterScript", "" ) ),
	  leave_script_( elem.remove_string( "LeaveScript", "" ) )
	{}
Exemple #2
0
	USpell::USpell( Clib::ConfigElem& elem, Plib::Package* pkg ) :
	  pkg_( pkg ),
	  spellid_( elem.remove_ushort( "SPELLID" ) ),
	  name_( elem.remove_string( "NAME" ) ),
	  power_words_( elem.remove_string( "POWERWORDS" ) ),
	  scriptdef_( elem.remove_string( "SCRIPT", "" ), pkg, "scripts/" )
	{
	  unsigned short action;
	  if ( elem.remove_prop( "ANIMATION", &action ) )
	  {
		if ( UACTION_IS_VALID( action ) )
		{
		  action_ = static_cast<UACTION>( action );
		}
		else
		{
		  elem.throw_error( "Animation is out of range" );
		}
	  }
	  else
	  {
		action_ = ACTION_CAST_SPELL1;
	  }

	  unsigned short circle;
	  if ( elem.remove_prop( "CIRCLE", &circle ) )
	  {
		if ( circle < 1 || circle > spellcircles.size() ||
			 spellcircles[circle - 1] == NULL )
		{
          ERROR_PRINT << "Error reading spell " << name_
            << ": Circle " << circle << " is not defined.\n";
		  throw std::runtime_error( "Config file error" );
		}

		params_ = spellcircles[circle - 1]->params;
	  }
	  else
	  {
		params_ = USpellParams( elem );
	  }

	  std::string reagent_name;
	  while ( elem.remove_prop( "Reagent", &reagent_name ) )
	  {
        unsigned int reagent = Items::get_objtype_from_string( reagent_name );

		reglist_.push_back( reagent );
	  }
	}
Exemple #3
0
UOSkill::UOSkill( const Plib::Package* pkg, Clib::ConfigElem& elem )
    : inited( true ),
      skillid( strtoul( elem.rest(), nullptr, 10 ) ),
      attributename( elem.remove_string( "Attribute", "" ) ),
      pAttr( nullptr ),
      pkg( pkg )
{
  if ( skillid >= 500 )
    elem.throw_error( "SkillID must be < 500" );

  if ( !attributename.empty() )
  {
    bool required = false;
    if ( attributename[0] == '+' )
    {
      required = true;
      attributename = attributename.substr( 1, std::string::npos );
    }
    pAttr = Mobile::Attribute::FindAttribute( attributename );
    if ( !pAttr )
    {
      if ( required )
      {
        elem.throw_error( "Attribute " + attributename + " not found." );
      }
      else
      {
        elem.warn( "Attribute " + attributename + " not found." );
      }
    }
  }
}
Exemple #4
0
	void read_bannedips_config( bool initial_load )
	{
	  if ( !initial_load )
	  {
		Core::networkManager.banned_ips.clear();
	  }
	  if ( !Clib::FileExists( "config/bannedips.cfg" ) )
		return;

	  Clib::ConfigFile cf( "config/bannedips.cfg" );
	  Clib::ConfigElem elem;

	  while ( cf.read( elem ) )
	  {
		IPRule CurrentEntry;
		std::string iptext = elem.remove_string( "IPMatch" );
		std::string::size_type delim = iptext.find_first_of( "/" );
		if ( delim != std::string::npos )
		{
          std::string ipaddr_str = iptext.substr(0, delim);
          std::string ipmask_str = iptext.substr(delim + 1);
		  CurrentEntry.ipMatch = inet_addr( ipaddr_str.c_str() );
		  CurrentEntry.ipMask = inet_addr( ipmask_str.c_str() );
		  Core::networkManager.banned_ips.push_back( CurrentEntry );
		}
		else
		{
          std::string ipmask_str = "255.255.255.255";
		  CurrentEntry.ipMatch = inet_addr( iptext.c_str() );
		  CurrentEntry.ipMask = inet_addr( ipmask_str.c_str() );
		  Core::networkManager.banned_ips.push_back( CurrentEntry );
		}
	  }
	}
Exemple #5
0
AuxService::AuxService( const Plib::Package* pkg, Clib::ConfigElem& elem ) :
  _pkg( pkg ),
  _scriptdef( elem.remove_string( "SCRIPT" ), _pkg ),
  _port( elem.remove_ushort( "PORT" ) )
{
  std::string iptext;
  while ( elem.remove_prop( "IPMATCH", &iptext ) )
  {
    auto delim = iptext.find_first_of("/");
    if (delim != std::string::npos)
    {
      std::string ipaddr_str = iptext.substr(0, delim);
      std::string ipmask_str = iptext.substr(delim + 1);
      unsigned int ipaddr = inet_addr( ipaddr_str.c_str() );
      unsigned int ipmask = inet_addr( ipmask_str.c_str() );
      _aux_ip_match.push_back( ipaddr );
      _aux_ip_match_mask.push_back( ipmask );
    }
    else
    {
      unsigned int ipaddr = inet_addr( iptext.c_str() );
      _aux_ip_match.push_back( ipaddr );
      _aux_ip_match_mask.push_back( 0xFFffFFffLu );
    }
  }
}
Exemple #6
0
UoClientListener::UoClientListener( Clib::ConfigElem& elem ) :
  port( elem.remove_ushort( "PORT" ) ),
  aosresist( elem.remove_bool( "AOSRESISTANCES", false ) ),
  sticky( elem.remove_bool( "KeepClients", false ) )

{
  CalculateCryptKeys( elem.remove_string( "ENCRYPTION", "none" ), encryption );
}
Exemple #7
0
/// Since the constructor is doing some wrong guessing to tell when an armor is a shield,
/// forceShield will force to consider it a shield
ArmorDesc::ArmorDesc( u32 objtype, Clib::ConfigElem& elem, const Plib::Package* pkg,
                      bool forceShield )
    : EquipDesc( objtype, elem, ARMORDESC, pkg ),
      ar( elem.remove_ushort( "AR", 0 ) ),
      zones(),
      on_hit_script( elem.remove_string( "ONHITSCRIPT", "" ), pkg, "scripts/items/" )
{
  std::string coverage;
  while ( elem.remove_prop( "COVERAGE", &coverage ) )
  {
    try
    {
      zones.insert( Mobile::zone_name_to_zone( coverage.c_str() ) );
    }
    catch ( std::runtime_error& )
    {
      fmt::Writer tmp;
      tmp.Format( "Error in Objtype 0x{:X}" ) << objtype;
      if ( pkg == NULL )
        tmp << "config/itemdesc.cfg\n";
      else
        tmp << pkg->dir() << "itemdesc.cfg\n";

      ERROR_PRINT << tmp.str();
      throw;
    }
  }

  if ( zones.empty() )
  {
    // No 'COVERAGE' entries existed.
    // default coverage based on object type/layer
    unsigned short layer = Plib::systemstate.tile[graphic].layer;
    // special case for shields - they effectively have no coverage.
    if ( !forceShield && layer != Core::LAYER_HAND1 && layer != Core::LAYER_HAND2 )
    {
      try
      {
        zones.insert( Mobile::layer_to_zone( layer ) );
      }
      catch ( std::runtime_error& )
      {
        fmt::Writer tmp;
        tmp.Format( "Error in Objtype 0x{:X}" ) << objtype;
        if ( pkg == NULL )
          tmp << "config/itemdesc.cfg\n";
        else
          tmp << pkg->dir() << "itemdesc.cfg\n";

        ERROR_PRINT << tmp.str();
        throw;
      }
    }
  }
}
Exemple #8
0
Vital::Vital( const Plib::Package* pkg, Clib::ConfigElem& elem ) :
  pkg( pkg ),
  name( elem.rest() ),
  aliases(),
  vitalid( 0 ),
  next( NULL ),
  get_regenrate_func( FindExportedFunction( elem, pkg, elem.remove_string( "RegenRateFunction" ), 1 ) ),
  get_maximum_func( FindExportedFunction( elem, pkg, elem.remove_string( "MaximumFunction" ), 1 ) ),
  underflow_func( NULL ),
  regen_while_dead( elem.remove_bool( "RegenWhileDead", false ) )
{
  aliases.push_back( name );
  std::string tmp;
  while ( elem.remove_prop( "Alias", &tmp ) )
    aliases.push_back( tmp );

  if ( elem.remove_prop( "UnderflowFunction", &tmp ) )
  {
    underflow_func = FindExportedFunction( elem, pkg, tmp, 2 );
  }
}
	void Account::readfrom( Clib::ConfigElem& elem )
	{
	  if ( elem.has_prop( "Password" ) )
	  {
        std::string temppass = elem.remove_string("Password");
		if ( Plib::systemstate.config.retain_cleartext_passwords )
		{
		  password_ = temppass;
		}
		if ( !Clib::MD5_Encrypt( name_ + temppass, passwordhash_ ) )	//MD5
		  elem.throw_error( "Failed to encrypt password for " + name_ );
		Plib::systemstate.accounts_txt_dirty = true;
	  }
	  else if ( elem.has_prop( "PasswordHash" ) )
	  {
		passwordhash_ = elem.remove_string( "PasswordHash" );
	  }
	  else
		elem.throw_error( "Failed password reads for account " + name_ );

	  enabled_ = elem.remove_bool( "ENABLED", true );
	  banned_ = elem.remove_bool( "BANNED", false );
	  uo_expansion_ = convert_uo_expansion( elem.remove_string( "UOExpansion", "T2A" ) );

	  default_privs_.readfrom( elem.remove_string( "DefaultPrivs", "" ) );

	  std::string cmdaccstr = elem.remove_string( "DefaultCmdLevel", "player" );
	  Core::CmdLevel* cmdlevel_search = Core::find_cmdlevel( cmdaccstr.c_str( ) );
	  if ( cmdlevel_search != NULL )
		default_cmdlevel_ = cmdlevel_search->cmdlevel;
	  else
		elem.throw_error( "Didn't understand cmdlevel of '" + cmdaccstr + "'" );

	  props_.clear();
	  props_.readProperties( elem );
	}
	Account::Account( Clib::ConfigElem& elem ) :
	  active_character( NULL ),
	  characters_(),
	  name_( elem.remove_string( "NAME" ) ),
	  enabled_( true ),
	  banned_( false ),
	  default_cmdlevel_( 0 )
	{
	  // If too low, will cause the client to freeze and the console to report 
	  // Exception in message handler 0x91: vector
	  for ( int i = 0; i < Plib::systemstate.config.character_slots; i++ )
		characters_.push_back( Core::CharacterRef( NULL ) );

	  readfrom( elem );
	}
Exemple #11
0
RealmDescriptor::RealmDescriptor(const std::string& realm_name, const std::string& realm_path, Clib::ConfigElem& elem) :
  name( realm_name ),
  file_path( realm_path ),
  width( elem.remove_ushort( "width" ) ),
  height( elem.remove_ushort( "height" ) ),
  uomapid( elem.remove_unsigned( "uomapid", 0 ) ),
  uodif( elem.remove_bool( "uodif", false ) ),
  num_map_patches( elem.remove_unsigned( "num_map_patches", 0 ) ),
  num_static_patches( elem.remove_unsigned( "num_static_patches", 0 ) ),
  season( elem.remove_unsigned( "season", 1 ) ),
  mapserver_type( Clib::strlower( elem.remove_string( "mapserver", "memory" ) ) ),
  grid_width(calc_grid_size(width)),
  grid_height(calc_grid_size(height))
{
}
Exemple #12
0
void read_region_data( Clib::ConfigElem& elem )
{
  ResourceDef* rd = find_resource_def( elem.rest() );
  if ( rd == nullptr )
  {
    ERROR_PRINT << "Error reading RESOURCE.DAT: Unable to find resource type " << elem.rest()
                << "\n";
    throw std::runtime_error( "Data file error" );
  }
  std::string regionname = elem.remove_string( "Name" );
  ResourceRegion* rgn = rd->getregion( regionname );
  if ( rgn == nullptr )
  {
    ERROR_PRINT << "Error reading RESOURCE.DAT: Unable to find region " << regionname
                << " in resource " << elem.rest() << "\n";
    throw std::runtime_error( "Data file error" );
  }
  rgn->read_data( elem );
}
Exemple #13
0
Attribute::Attribute( const Plib::Package* pkg, Clib::ConfigElem& elem ) :
  pkg( pkg ),
  name( elem.rest() ),
  attrid( 0 ),
  aliases(),
  next( NULL ),
  getintrinsicmod_func( nullptr ),
  delay_seconds( elem.remove_ushort( "DELAY", 0 ) ),
  unhides( elem.remove_bool( "UNHIDES", true ) ),
  disable_core_checks( elem.remove_bool( "DisableCoreChecks", false ) ),
  default_cap( elem.remove_ushort( "DefaultCap", Core::settingsManager.ssopt.default_attribute_cap ) ),
  script_( elem.remove_string( "SCRIPT", "" ), pkg, "scripts/skills/" )
{
  aliases.push_back( name );
  std::string tmp;
  while ( elem.remove_prop( "Alias", &tmp ) )
    aliases.push_back( tmp );

  if ( elem.remove_prop( "GetIntrinsicModFunction", &tmp ) )
  {
    getintrinsicmod_func = Core::FindExportedFunction( elem, pkg, tmp, 1 );
  }
}
void read_npc_templates( Plib::Package* pkg )
{
  std::string filename = GetPackageCfgPath( pkg, "npcdesc.cfg" );
  if ( !Clib::FileExists( filename ) )
    return;

  Clib::ConfigFile cf( filename.c_str() );
  Clib::ConfigElem elem;
  while ( cf.read( elem ) )
  {
    if ( elem.type_is( "NpcTemplate" ) )
    {
      // first determine the NPC template name.
      std::string namebase;
      const char* rest = elem.rest();
      if ( rest != NULL && *rest != '\0' )
      {
        namebase = rest;
      }
      else
      {
        namebase = elem.remove_string( "TemplateName" );
      }
      std::string descname;
      if ( pkg != NULL )
      {
        descname = ":" + pkg->name() + ":" + namebase;
        elem.set_rest( descname.c_str() );
      }
      else
        descname = namebase;

      gamestate.npc_template_elems[descname] = NpcTemplateElem( cf, elem );
    }
  }
}
Exemple #15
0
int UoToolMain::main()
{
  const std::vector<std::string> binArgs = programArgs();

  /**********************************************
   * show help
   **********************************************/
  if (binArgs.size() == 1)
  {
    showHelp();
    return 0; // return "okay"
  }

  /**********************************************
   * TODO: rework the following cruft from former uotool.cpp
   **********************************************/
  Clib::ConfigFile cf( "pol.cfg" );
  Clib::ConfigElem elem;

  cf.readraw( elem );

  Plib::systemstate.config.uo_datafile_root = elem.remove_string( "UoDataFileRoot" );
  Plib::systemstate.config.uo_datafile_root = Clib::normalized_dir_form( Plib::systemstate.config.uo_datafile_root );

  unsigned short max_tile = elem.remove_ushort( "MaxTileID", UOBJ_DEFAULT_MAX );

  if ( max_tile != UOBJ_DEFAULT_MAX && max_tile != UOBJ_SA_MAX && max_tile != UOBJ_HSA_MAX )
    Plib::systemstate.config.max_tile_id = UOBJ_DEFAULT_MAX;
  else
    Plib::systemstate.config.max_tile_id = max_tile;

  std::string argvalue = binArgs[1];
  if ( argvalue[0] == '/' || argvalue[0] == ':' )
  {
    Plib::systemstate.config.uo_datafile_root = argvalue;
    if (binArgs.size() < 3)
    {
      showHelp();
      return 0;
    }
    argvalue = binArgs[2];
  }

  std::transform(argvalue.begin(), argvalue.end(), argvalue.begin(), ::tolower);

  if ( argvalue == "tiledump" )
  {
    return UoTool::tiledump( s_argc, s_argv );
  }
  else if ( argvalue == "vertile" )
  {
    return UoTool::vertile();
  }
  else if ( argvalue == "verlandtile" )
  {
    return UoTool::verlandtile();
  }
  else if ( argvalue == "landtilehist" )
  {
    return UoTool::landtilehist();
  }
  else if ( argvalue == "flagsearch" )
  {
    return UoTool::flagsearch( s_argc, s_argv );
  }
  else if ( argvalue == "landtileflagsearch" )
  {
    return UoTool::landtileflagsearch( s_argc, s_argv );
  }
  else if ( argvalue == "loschange" )
  {
    return UoTool::loschange( s_argc, s_argv );
  }
  else if ( argvalue == "rawdump" )
  {
    return UoTool::rawdump( s_argc, s_argv );
  }
  else if ( argvalue == "ctable" )
  {
    return UoTool::print_ctable();
  }
  else if ( argvalue == "sndlist" )
  {
    return UoTool::print_sndlist();
  }
  else if ( argvalue == "statics" )
  {
    return UoTool::print_statics();
  }
  else if ( argvalue == "verdata" )
  {
    return UoTool::print_verdata_info();
  }
  else if ( argvalue == "multis" )
  {
    return UoTool::print_multis();
  }
  else if ( argvalue == "water" )
  {
    return UoTool::print_water_data();
  }
  else if ( argvalue == "newstatics" )
  {
    return Core::write_pol_static_files( "main" );
  }
  else if ( argvalue == "staticsmax" )
  {
    Core::open_uo_data_files();
    Core::staticsmax();
    return 0;
  }
  else if ( argvalue == "watersearch" )
  {
    return UoTool::water_search();
  }
  else if ( argvalue == "zhist" )
  {
    return UoTool::z_histogram();
  }
  else if ( argvalue == "staticshist" )
  {
    return UoTool::statics_histogram();
  }
  else if ( argvalue == "writedungmap" )
  {
    return UoTool::write_polmap();
  }
  else if ( argvalue == "writekeys" )
  {
    INFO_PRINT << "Keys written to current.key\n";
    return 0;
  }
  else if ( argvalue == "mapdump" )
  {
    return UoTool::mapdump( s_argc, s_argv );
  }
  else if ( argvalue == "contour" )
  {
    return UoTool::contour();
  }
  else if ( argvalue == "findlandtile" )
  {
    return UoTool::findlandtile( s_argc - 1, s_argv + 1 );
  }
  else if ( argvalue == "findlandtileflags" )
  {
    return UoTool::findlandtileflags( s_argc - 1, s_argv + 1 );
  }
  else if ( argvalue == "findgraphic" )
  {
    return UoTool::findgraphic( s_argc - 1, s_argv + 1 );
  }
  else if ( argvalue == "defragstatics" )
  {
    return UoTool::defragstatics( s_argc - 1, s_argv + 1 );
  }
  else if ( argvalue == "formatdesc" )
  {
    return UoTool::format_description( s_argc - 1, s_argv + 1 );
  }
  else if ( argvalue == "checkmultis" )
  {
    return UoTool::checkmultis();
  }

  showHelp();
  return 0;
}
// FIXME inefficient.  Templates should be read in once, and reused.
bool FindNpcTemplate( const char* template_name, Clib::ConfigFile& cf, Clib::ConfigElem& elem )
{
  try
  {
    const Plib::Package* pkg;
    std::string npctemplate;
    if ( !Plib::pkgdef_split( template_name, NULL, &pkg, &npctemplate ) )
      return false;

    std::string filename =
        Plib::GetPackageCfgPath( const_cast<Plib::Package*>( pkg ), "npcdesc.cfg" );

    cf.open( filename.c_str() );
    while ( cf.read( elem ) )
    {
      if ( !elem.type_is( "NpcTemplate" ) )
        continue;

      std::string orig_rest = elem.rest();
      if ( pkg != NULL )
      {
        std::string newrest = ":" + pkg->name() + ":" + npctemplate;
        elem.set_rest( newrest.c_str() );
      }
      const char* rest = elem.rest();
      if ( rest != NULL && *rest != '\0' )
      {
        if ( stricmp( orig_rest.c_str(), npctemplate.c_str() ) == 0 )
          return true;
      }
      else
      {
        std::string tname = elem.remove_string( "TemplateName" );
        if ( stricmp( tname.c_str(), npctemplate.c_str() ) == 0 )
          return true;
      }
    }
    return false;
  }
  catch ( const char* msg )
  {
    ERROR_PRINT << "NPC Creation (" << template_name << ") Failed: " << msg << "\n";
  }
  catch ( std::string& str )
  {
    ERROR_PRINT << "NPC Creation (" << template_name << ") Failed: " << str << "\n";
  }                                 // egcs has some trouble realizing 'exception' should catch
  catch ( std::runtime_error& re )  // runtime_errors, so...
  {
    ERROR_PRINT << "NPC Creation (" << template_name << ") Failed: " << re.what() << "\n";
  }
  catch ( std::exception& ex )
  {
    ERROR_PRINT << "NPC Creation (" << template_name << ") Failed: " << ex.what() << "\n";
  }
#ifndef WIN32
  catch ( ... )
  {
  }
#endif
  return false;
}
int UoConvertMain::main()
{
  const std::vector<std::string>& binArgs = programArgs();

  /**********************************************
   * show help
   **********************************************/
  if ( binArgs.size() == 1 )
  {
    showHelp();
    return 0;  // return "okay"
  }

  /**********************************************
   * TODO: rework the following cruft from former uoconvert.cpp
   **********************************************/
  Plib::systemstate.config.max_tile_id = UOBJ_DEFAULT_MAX;  // default
  std::string argvalue = programArgsFindEquals( "uodata=", "" );
  if ( !argvalue.empty() )
  {
    Plib::systemstate.config.uo_datafile_root = argvalue;
    Plib::systemstate.config.uo_datafile_root =
        Clib::normalized_dir_form( Plib::systemstate.config.uo_datafile_root );
  }
  else
  {
    INFO_PRINT << "Reading pol.cfg.\n";
    Clib::ConfigFile cf( "pol.cfg" );
    Clib::ConfigElem elem;

    cf.readraw( elem );
    Plib::systemstate.config.uo_datafile_root = elem.remove_string( "UoDataFileRoot" );
    Plib::systemstate.config.uo_datafile_root =
        Clib::normalized_dir_form( Plib::systemstate.config.uo_datafile_root );

    unsigned short max_tile = elem.remove_ushort( "MaxTileID", UOBJ_DEFAULT_MAX );

    if ( max_tile == UOBJ_DEFAULT_MAX || max_tile == UOBJ_SA_MAX || max_tile == UOBJ_HSA_MAX )
      Plib::systemstate.config.max_tile_id = max_tile;
  }

  unsigned short max_tile =
      static_cast<unsigned short>( programArgsFindEquals( "maxtileid=", UOBJ_DEFAULT_MAX, true ) );
  if ( max_tile == UOBJ_DEFAULT_MAX || max_tile == UOBJ_SA_MAX || max_tile == UOBJ_HSA_MAX )
    Plib::systemstate.config.max_tile_id = max_tile;


  std::string main_cfg = "uoconvert.cfg";
  if ( Clib::FileExists( main_cfg.c_str() ) )
  {
    std::string temp;
    Clib::ConfigElem elem;
    INFO_PRINT << "Reading uoconvert.cfg.\n";
    Clib::ConfigFile cf_main( main_cfg.c_str() );
    while ( cf_main.read( elem ) )
    {
      if ( elem.type_is( "MultiTypes" ) )
      {
        temp = elem.remove_string( "Boats" );
        ISTRINGSTREAM is_boats( temp );
        std::string graphicnum;
        while ( is_boats >> graphicnum )
          UoConvert::BoatTypes.insert( strtoul( graphicnum.c_str(), NULL, 0 ) );

        temp = elem.remove_string( "Houses" );
        ISTRINGSTREAM is_houses( temp );
        while ( is_houses >> graphicnum )
          UoConvert::HouseTypes.insert( strtoul( graphicnum.c_str(), NULL, 0 ) );

        temp = elem.remove_string( "Stairs" );
        ISTRINGSTREAM is_stairs( temp );
        while ( is_stairs >> graphicnum )
          UoConvert::StairTypes.insert( strtoul( graphicnum.c_str(), NULL, 0 ) );
      }
      else if ( elem.type_is( "LOSOptions" ) )
Exemple #18
0
void UArmor::readProperties( Clib::ConfigElem& elem )
{
  base::readProperties( elem );
  this->ar_mod(static_cast<s16>( elem.remove_int( "AR_MOD", 0 ) ) );
  set_onhitscript( elem.remove_string( "ONHITSCRIPT", "" ) );
}