mirror of
https://github.com/SantaSpeen/BeamMP-Server.git
synced 2026-04-19 02:19:52 +00:00
Add new start argument - locale
Optimization for Russian locale.
This commit is contained in:
29
src/main.cpp
29
src/main.cpp
@@ -36,6 +36,8 @@ ARGUMENTS:
|
||||
including the path given in --config.
|
||||
--version
|
||||
Prints version info and exits.
|
||||
--locale
|
||||
Set console locale.
|
||||
|
||||
EXAMPLES:
|
||||
BeamMP-Server --config=../MyWestCoastServerConfig.toml
|
||||
@@ -55,17 +57,17 @@ struct MainArguments {
|
||||
std::string InvokedAs;
|
||||
};
|
||||
|
||||
int BeamMPServerMain(MainArguments Arguments);
|
||||
int BeamMPServerMain(const MainArguments& Arguments);
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
MainArguments Args { argc, argv, {}, argv[0] };
|
||||
Args.List.reserve(argc);
|
||||
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 {
|
||||
MainRet = BeamMPServerMain(std::move(Args));
|
||||
MainRet = BeamMPServerMain(Args);
|
||||
} catch (const std::exception& e) {
|
||||
beammp_error("A fatal exception has occurred and the server is forcefully shutting down.");
|
||||
beammp_error(e.what());
|
||||
@@ -75,7 +77,7 @@ int main(int argc, char** argv) {
|
||||
return MainRet;
|
||||
}
|
||||
|
||||
int BeamMPServerMain(MainArguments Arguments) {
|
||||
int BeamMPServerMain(const MainArguments& Arguments) {
|
||||
setlocale(LC_ALL, "C");
|
||||
Application::InitializeConsole();
|
||||
ArgsParser Parser;
|
||||
@@ -83,6 +85,7 @@ int BeamMPServerMain(MainArguments Arguments) {
|
||||
Parser.RegisterArgument({ "version" }, ArgsParser::NONE);
|
||||
Parser.RegisterArgument({ "config" }, ArgsParser::HAS_VALUE);
|
||||
Parser.RegisterArgument({ "working-directory" }, ArgsParser::HAS_VALUE);
|
||||
Parser.RegisterArgument({ "locale" }, ArgsParser::HAS_VALUE);
|
||||
Parser.Parse(Arguments.List);
|
||||
if (!Parser.Verify()) {
|
||||
return 1;
|
||||
@@ -98,7 +101,7 @@ int BeamMPServerMain(MainArguments Arguments) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string ConfigPath = "ServerConfig.toml";
|
||||
std::string ConfigPath = "config.toml";
|
||||
if (Parser.FoundArgument({ "config" })) {
|
||||
auto MaybeConfigPath = Parser.GetValueOfArgument({ "config" });
|
||||
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::Console().StartLoggingToFile();
|
||||
|
||||
Reference in New Issue
Block a user