bool LSL::OptionsWrapper::setSingleOptionTypeSwitch(const std::string& key, const std::string& value, Enum::GameOption modmapFlag, Enum::OptionType optType) { GameOptions& gameoptions = m_opts[modmapFlag]; switch (optType) { case Enum::opt_float: { const double d_val = Util::FromFloatString(value); if (d_val < (gameoptions.float_map)[key].min || d_val > (gameoptions.float_map)[key].max) { LslWarning("received number %f option %s exceeds boundaries %f %f", d_val, key.c_str(), (gameoptions.float_map)[key].min, (gameoptions.float_map)[key].max); return false; } else (gameoptions.float_map)[key].value = d_val; break; } case Enum::opt_bool: { const long l_val = Util::FromIntString(value); if (l_val != 1 && l_val != 0) { LslWarning("received bool option that is neither 0 or 1"); return false; } else (gameoptions.bool_map)[key].value = bool(l_val); break; } case Enum::opt_string: { // test if maxlength isn't exceeded unsigned int max_length = (gameoptions.string_map)[key].max_len; if ((max_length != 0) && (value.length() > max_length)) { LslWarning("received string option exceeds max_len"); return false; } else (gameoptions.string_map)[key].value = value; break; } case Enum::opt_list: { // test if valid value, aka is in list int listitemcount = (gameoptions.list_map)[key].listitems.size(); bool valid_string = false; int j = 0; for (; j < listitemcount; ++j) { if ((gameoptions.list_map)[key].listitems[j].key == value) { valid_string = true; break; } } if (valid_string) { //LOOKATME (koshi) if there's a problem with list modoption look here first (gameoptions.list_map)[key].value = (gameoptions.list_map)[key].listitems[j].key; (gameoptions.list_map)[key].cur_choice_index = j; } else { LslWarning("received list option \"%s\" is not valid", key.c_str()); return false; } break; } default: return false; } //if we made it here, all is good return true; }
bool Unitsync::LoadUnitSyncLib(const std::string& unitsyncloc) { LOCK_UNITSYNC; ClearCache(); const bool ret = susynclib().Load(unitsyncloc); if (!ret) { return false; } const std::string datadir = LSL::Util::config().GetDataDir(); const std::string curdatadir = susynclib().GetSpringDataDir(); if (datadir != curdatadir) { LslWarning("Reloading unitsync due to datadir change: %s -> %s", curdatadir.c_str(), datadir.c_str()); SetSpringDataPath(datadir); susynclib().Load(unitsyncloc); } supportsManualUnLoad = LSL::susynclib().GetSpringConfigInt("UnitsyncAutoUnLoadMapsIsSupported", 0) != 0; if (supportsManualUnLoad) { LslDebug("Unitsync supports manual loading of archives (faster, yey!)"); LSL::usync().SetSpringConfigInt("UnitsyncAutoUnLoadMaps", 1); } else { LslDebug("Unitsync doesn't support manual loading of archives :-/"); } m_cache_path = LSL::Util::config().GetCachePath(); PopulateArchiveList(); return true; }
server::server(const std::string& address, const std::string& port, const std::string& password) : io_service_() , signals_(io_service_) , acceptor_(io_service_) , connection_manager_() , socket_(io_service_) , request_handler_(password) { // Register to handle the signals that indicate when the server should exit. // It is safe to register for the same signal multiple times in a program, // provided all registration for the specified signal is made through Asio. signals_.add(SIGINT); signals_.add(SIGTERM); #if defined(SIGQUIT) signals_.add(SIGQUIT); #endif // defined(SIGQUIT) do_await_stop(); // Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR). boost::asio::ip::tcp::resolver resolver(io_service_); boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve({address, port}); acceptor_.open(endpoint.protocol()); acceptor_.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); acceptor_.bind(endpoint); acceptor_.listen(); do_accept(); LslWarning("Listening on http://%s:%s/", address.c_str(), port.c_str()); }
bool OptionsWrapper::keyExists(const std::string& key, const Enum::GameOption modmapFlag, bool showError, Enum::OptionType& optType) const { //std::string duplicateKeyError = "Please contact the game's author and tell him\nto use unique keys in his ModOptions.lua"; bool exists = false; optType = Enum::opt_undefined; GameOptionsMap::const_iterator optIt = m_opts.find((int)modmapFlag); if (optIt == m_opts.end()) return false; const GameOptions& gameoptions = optIt->second; if (gameoptions.list_map.find(key) != gameoptions.list_map.end()) { optType = Enum::opt_list; exists = true; } else if (gameoptions.string_map.find(key) != gameoptions.string_map.end()) { optType = Enum::opt_string; exists = true; } else if (gameoptions.bool_map.find(key) != gameoptions.bool_map.end()) { optType = Enum::opt_bool; exists = true; } else if (gameoptions.float_map.find(key) != gameoptions.float_map.end()) { optType = Enum::opt_float; exists = true; } else if (gameoptions.section_map.find(key) != gameoptions.section_map.end()) { optType = Enum::opt_section; exists = true; } if (exists && showError) { //TODO STH // customMessageBoxNoModal(SL_MAIN_ICON,duplicateKeyError, "Mod/map option error",wxOK); LslWarning("duplicate key in mapmodoptions"); return false; } else if (exists && !showError) { return true; } else return false; }
void Unitsync::FetchUnitsyncErrors(const std::string& prefix) { auto errors = susynclib().GetUnitsyncErrors(); std::string pre = prefix; if (!prefix.empty()) { pre += " "; } for (const std::string error : errors) { LslWarning("Unitsync: %s%s", pre.c_str(), error.c_str()); } }