void config::includes (const section& sec, bool must_exist) { bool have_includes = false; try { rld::strings is; parse_items (sec, "include", is); have_includes = true; /* * Include records are a paths which we can load. */ for (rld::strings::const_iterator isi = is.begin (); isi != is.end (); ++isi) { load (*isi); } } catch (rld::error re) { /* * No include records, must be all inlined. If we have includes it must * be another error so throw it. */ if (have_includes || (!have_includes && must_exist)) throw; } }
int16 AttrGetBoolean( StringPtr attrs, StringPtr key, boolean *value ) { uint8 valstr[32] = ""; *value = FALSE; parse_items( attrs, key, valstr ); return read_cfg_bool( valstr, value ); }
int16 AttrGetInt32( StringPtr attrs, StringPtr key, int32 *value ) { uint8 valstr[32] = ""; uint8 *endptr = NULL; int16 ret = 0; if( parse_items( attrs, key, valstr ) ) { *value = strtol( valstr, &endptr, 10 ); ret = 1; } /* if( endptr == NULL || endptr == valstr ) ret = 0; */ return ret; }
player_t* parse_player( sim_t* sim, player_spec_t& player, cache::behavior_t caching ) { sim -> current_slot = 0; std::string result; if ( ! http_t::get( result, player.url, caching ) ) return 0; // if ( sim -> debug ) util_t::fprintf( sim -> output_file, "%s\n%s\n", url.c_str(), result.c_str() ); js_node_t* profile = js_t::create( sim, result ); if ( ! profile ) { sim -> errorf( "BCP API: Unable to download player from '%s'\n", player.url.c_str() ); return 0; } if ( sim -> debug ) js_t::print( profile, sim -> output_file ); std::string name; if ( js_t::get_value( name, profile, "name" ) ) player.name = name; else name = player.name; if ( player.talent_spec != "active" && ! player.talent_spec.empty() ) { name += '_'; name += player.talent_spec; } if ( ! name.empty() ) sim -> current_name = name; int level; if ( ! js_t::get_value( level, profile, "level" ) ) { sim -> errorf( "BCP API: Unable to extract player level from '%s'.\n", player.url.c_str() ); return 0; } int cid; if ( ! js_t::get_value( cid, profile, "class" ) ) { sim -> errorf( "BCP API: Unable to extract player class from '%s'.\n", player.url.c_str() ); return 0; } std::string class_name = util_t::player_type_string( util_t::translate_class_id( cid ) ); int rid; if ( ! js_t::get_value( rid, profile, "race" ) ) { sim -> errorf( "BCP API: Unable to extract player race from '%s'.\n", player.url.c_str() ); return 0; } player_t* p = player_t::create( sim, class_name, name, util_t::translate_race_id( rid ) ); sim -> active_player = p; if ( ! p ) { sim -> errorf( "BCP API: Unable to build player with class '%s' and name '%s' from '%s'.\n", class_name.c_str(), name.c_str(), player.url.c_str() ); return 0; } p -> level = level; p -> region_str = player.region.empty() ? sim -> default_region_str : player.region; if ( ! js_t::get_value( p -> server_str, profile, "realm" ) && ! player.server.empty() ) p -> server_str = player.server; if ( ! player.origin.empty() ) { p -> origin_str = player.origin; http_t::format( p -> origin_str ); } if ( js_t::get_value( p -> thumbnail_url, profile, "thumbnail" ) ) { p -> thumbnail_url = "http://" + p -> region_str + ".battle.net/static-render/" + p -> region_str + '/' + p -> thumbnail_url; http_t::format( p -> thumbnail_url ); } parse_profession( p -> professions_str, profile, 0 ); parse_profession( p -> professions_str, profile, 1 ); js_node_t* build = js_t::get_node( profile, "talents" ); if ( ! build ) { sim -> errorf( "BCP API: Player '%s' from URL '%s' has no talents.\n", name.c_str(), player.url.c_str() ); return 0; } build = pick_talents( build, player.talent_spec ); if ( ! build ) { sim -> errorf( "BCP API: Invalid talent spec '%s' for player '%s'.\n", player.talent_spec.c_str(), name.c_str() ); return 0; } if ( ! parse_talents( p, build ) ) return 0; if ( ! parse_glyphs( p, build ) ) return 0; if ( ! parse_items( p, js_t::get_child( profile, "items" ) ) ) return 0; if ( ! p -> server_str.empty() ) p -> armory_extensions( p -> region_str, p -> server_str, player.name, caching ); return p; }
int16 AttrGetString( StringPtr attrs, StringPtr key, StringPtr value ) { return parse_items( attrs, key, value ); }