mirror of
https://github.com/SantaSpeen/BeamMP-Server.git
synced 2026-10-27 17:59:57 +00:00
Add new start argument - locale
Optimization for Russian locale.
This commit is contained in:
1 parent
660354574e
commit
924c946be9
1 file changed
+23
-6
+23
-6
@@ -36,6 +36,8 @@ ARGUMENTS:
|
|||||||
including the path given in --config.
|
including the path given in --config.
|
||||||
--version
|
--version
|
||||||
Prints version info and exits.
|
Prints version info and exits.
|
||||||
|
--locale
|
||||||
|
Set console locale.
|
||||||
|
|
||||||
EXAMPLES:
|
EXAMPLES:
|
||||||
BeamMP-Server --config=../MyWestCoastServerConfig.toml
|
BeamMP-Server --config=../MyWestCoastServerConfig.toml
|
||||||
@@ -55,17 +57,17 @@ struct MainArguments {
|
|||||||
std::string InvokedAs;
|
std::string InvokedAs;
|
||||||
};
|
};
|
||||||
|
|
||||||
int BeamMPServerMain(MainArguments Arguments);
|
int BeamMPServerMain(const MainArguments& Arguments);
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
MainArguments Args { argc, argv, {}, argv[0] };
|
MainArguments Args { argc, argv, {}, argv[0] };
|
||||||
Args.List.reserve(argc);
|
Args.List.reserve(argc);
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
Args.List.push_back(argv[i]);
|
Args.List.emplace_back(argv[i]);
|
||||||
}
|
}
|
||||||
int MainRet = 0;
|
int MainRet;
|
||||||
try {
|
try {
|
||||||
MainRet = BeamMPServerMain(std::move(Args));
|
MainRet = BeamMPServerMain(Args);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
beammp_error("A fatal exception has occurred and the server is forcefully shutting down.");
|
beammp_error("A fatal exception has occurred and the server is forcefully shutting down.");
|
||||||
beammp_error(e.what());
|
beammp_error(e.what());
|
||||||
@@ -75,7 +77,7 @@ int main(int argc, char** argv) {
|
|||||||
return MainRet;
|
return MainRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BeamMPServerMain(MainArguments Arguments) {
|
int BeamMPServerMain(const MainArguments& Arguments) {
|
||||||
setlocale(LC_ALL, "C");
|
setlocale(LC_ALL, "C");
|
||||||
Application::InitializeConsole();
|
Application::InitializeConsole();
|
||||||
ArgsParser Parser;
|
ArgsParser Parser;
|
||||||
@@ -83,6 +85,7 @@ int BeamMPServerMain(MainArguments Arguments) {
|
|||||||
Parser.RegisterArgument({ "version" }, ArgsParser::NONE);
|
Parser.RegisterArgument({ "version" }, ArgsParser::NONE);
|
||||||
Parser.RegisterArgument({ "config" }, ArgsParser::HAS_VALUE);
|
Parser.RegisterArgument({ "config" }, ArgsParser::HAS_VALUE);
|
||||||
Parser.RegisterArgument({ "working-directory" }, ArgsParser::HAS_VALUE);
|
Parser.RegisterArgument({ "working-directory" }, ArgsParser::HAS_VALUE);
|
||||||
|
Parser.RegisterArgument({ "locale" }, ArgsParser::HAS_VALUE);
|
||||||
Parser.Parse(Arguments.List);
|
Parser.Parse(Arguments.List);
|
||||||
if (!Parser.Verify()) {
|
if (!Parser.Verify()) {
|
||||||
return 1;
|
return 1;
|
||||||
@@ -98,7 +101,7 @@ int BeamMPServerMain(MainArguments Arguments) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ConfigPath = "ServerConfig.toml";
|
std::string ConfigPath = "config.toml";
|
||||||
if (Parser.FoundArgument({ "config" })) {
|
if (Parser.FoundArgument({ "config" })) {
|
||||||
auto MaybeConfigPath = Parser.GetValueOfArgument({ "config" });
|
auto MaybeConfigPath = Parser.GetValueOfArgument({ "config" });
|
||||||
if (MaybeConfigPath.has_value()) {
|
if (MaybeConfigPath.has_value()) {
|
||||||
@@ -118,6 +121,20 @@ int BeamMPServerMain(MainArguments Arguments) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Parser.FoundArgument({ "locale" })) {
|
||||||
|
auto MaybeLocale = Parser.GetValueOfArgument({ "locale" });
|
||||||
|
if (MaybeLocale.has_value()) {
|
||||||
|
std::string locale = MaybeLocale.value();
|
||||||
|
setlocale(LC_ALL, locale.c_str());
|
||||||
|
beammp_info("Custom locale requested via commandline arguments: '" + locale + "'");
|
||||||
|
if ((locale == "Russian" || locale == "Rus") && WIN32) {
|
||||||
|
beammp_info("Found Russian locale. Set CP1251 console coding.");
|
||||||
|
SetConsoleCP(1251);
|
||||||
|
SetConsoleOutputCP(1251);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Application::SetSubsystemStatus("Main", Application::Status::Starting);
|
Application::SetSubsystemStatus("Main", Application::Status::Starting);
|
||||||
|
|
||||||
Application::Console().StartLoggingToFile();
|
Application::Console().StartLoggingToFile();
|
||||||
|
|||||||
Reference in new issue
Block a user