summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-03-02 17:38:22 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-03-02 17:38:25 +0100
commita25d857ed0bebc2c3e1473d06bea89286941886c (patch)
tree99c8069acb1b2c756951d3047d73db4cf1b6b4b4
parent72ceaaa426166bfa425f519c2418a66872839e12 (diff)
downloadMana-a25d857ed0bebc2c3e1473d06bea89286941886c.tar.gz
Mana-a25d857ed0bebc2c3e1473d06bea89286941886c.tar.bz2
Mana-a25d857ed0bebc2c3e1473d06bea89286941886c.tar.xz
Mana-a25d857ed0bebc2c3e1473d06bea89286941886c.zip
Exit with error when invalid server type is passed on CLI
Also made it exit with error when there is an unknown option or missing argument.
-rw-r--r--src/client.cpp2
-rw-r--r--src/client.h3
-rw-r--r--src/main.cpp23
3 files changed, 17 insertions, 11 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 98c8be30..15ebcf96 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -378,7 +378,7 @@ Client::Client(const Options &options):
// Initialize default server
mCurrentServer.hostname = options.serverName;
mCurrentServer.port = options.serverPort;
- mCurrentServer.type = ServerInfo::parseType(options.serverType);
+ mCurrentServer.type = options.serverType;
loginData.username = options.username;
loginData.password = options.password;
loginData.remember = config.getBoolValue("remember");
diff --git a/src/client.h b/src/client.h
index ccee43ba..dfcc3e70 100644
--- a/src/client.h
+++ b/src/client.h
@@ -135,6 +135,7 @@ public:
bool skipUpdate = false;
bool chooseDefault = false;
bool noOpenGL = false;
+ bool exitWithError = false;
std::string username;
std::string password;
std::string character;
@@ -145,7 +146,7 @@ public:
std::string configDir;
std::string localDataDir;
std::string screenshotDir;
- std::string serverType;
+ ServerType serverType = ServerType::UNKNOWN;
std::string serverName;
uint16_t serverPort = 0;
diff --git a/src/main.cpp b/src/main.cpp
index 6244b946..b44f4d3a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -118,6 +118,8 @@ static void parseOptions(int argc, char *argv[], Client::Options &options)
break;
case '?': // Unknown option
case ':': // Missing argument
+ options.exitWithError = true;
+ [[fallthrough]];
case 'h':
options.printHelp = true;
break;
@@ -158,7 +160,12 @@ static void parseOptions(int argc, char *argv[], Client::Options &options)
options.screenshotDir = optarg;
break;
case 'y':
- options.serverType = optarg;
+ options.serverType = ServerInfo::parseType(optarg);
+ if (options.serverType == ServerType::UNKNOWN)
+ {
+ std::cerr << _("Invalid server type, expected one of: tmwathena, manaserv") << std::endl;
+ options.exitWithError = true;
+ }
break;
}
}
@@ -203,16 +210,14 @@ int main(int argc, char *argv[])
Client::Options options;
parseOptions(argc, argv, options);
+ if (options.printVersion)
+ printVersion();
+
if (options.printHelp)
- {
printHelp();
- return 0;
- }
- else if (options.printVersion)
- {
- printVersion();
- return 0;
- }
+
+ if (options.printHelp || options.printVersion || options.exitWithError)
+ return options.exitWithError ? 1 : 0;
initInternationalization();