Add support for setting ports through command line
This commit is contained in:
parent
c2303ac4cf
commit
2e98bfc4e9
@ -931,7 +931,18 @@ AStringVector ReadUpgradeIniPorts(
|
||||
)
|
||||
{
|
||||
// Read the regular value, but don't use the default (in order to detect missing value for upgrade):
|
||||
AStringVector Ports = StringSplitAndTrim(a_Settings.GetValue(a_KeyName, a_PortsValueName), ";,");
|
||||
|
||||
AStringVector Ports;
|
||||
|
||||
for (auto pair : a_Settings.GetValues(a_KeyName))
|
||||
{
|
||||
if (pair.first != a_PortsValueName)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
AStringVector temp = StringSplitAndTrim(pair.second, ";,");
|
||||
Ports.insert(Ports.end(), temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
if (Ports.empty())
|
||||
{
|
||||
|
13
src/main.cpp
13
src/main.cpp
@ -372,6 +372,8 @@ std::unique_ptr<cMemorySettingsRepository> parseArguments(int argc, char **argv)
|
||||
|
||||
TCLAP::ValueArg<int> slotsArg("s", "max-players", "Maximum number of slots for the server to use, overrides setting in setting.ini", false, -1, "number", cmd);
|
||||
|
||||
TCLAP::MultiArg<int> portsArg("p", "port", "The port number the server should listen to", false, "port", cmd);
|
||||
|
||||
cmd.parse(argc, argv);
|
||||
|
||||
auto repo = cpp14::make_unique<cMemorySettingsRepository>();
|
||||
@ -381,10 +383,19 @@ std::unique_ptr<cMemorySettingsRepository> parseArguments(int argc, char **argv)
|
||||
|
||||
int slots = slotsArg.getValue();
|
||||
|
||||
repo->SetValueI("Server", "MaxPlayers", slots);
|
||||
repo->AddValue("Server", "MaxPlayers", static_cast<Int64>(slots));
|
||||
|
||||
}
|
||||
|
||||
if (portsArg.isSet())
|
||||
{
|
||||
std::vector<int> ports = portsArg.getValue();
|
||||
for (auto port : ports)
|
||||
{
|
||||
repo->AddValue("Server", "Port", static_cast<Int64>(port));
|
||||
}
|
||||
}
|
||||
|
||||
repo->SetReadOnly();
|
||||
|
||||
return repo;
|
||||
|
Loading…
Reference in New Issue
Block a user