Working server
This commit is contained in:
@@ -12,6 +12,35 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "td/misc/Backward.hpp"
|
#include "td/misc/Backward.hpp"
|
||||||
|
#include "td/misc/Log.h"
|
||||||
|
#include "td/misc/Format.h"
|
||||||
|
#include "server/Server.h"
|
||||||
|
|
||||||
|
struct Argument {
|
||||||
|
std::string Name;
|
||||||
|
std::string Descritpion;
|
||||||
|
};
|
||||||
|
|
||||||
|
using namespace td::utils;
|
||||||
|
|
||||||
|
static std::vector<Argument> CMD_ARGUMENTS = {
|
||||||
|
{ "<Map file>" , "The map to load"},
|
||||||
|
{ "-P\t" , "The port to listen to. Default : 25565"},
|
||||||
|
{ "--help\t", "Displays help"}
|
||||||
|
};
|
||||||
|
|
||||||
|
static void DisplayHelp() {
|
||||||
|
LOG("Usage :");
|
||||||
|
for (std::size_t i = 0; i < CMD_ARGUMENTS.size(); i++) {
|
||||||
|
Argument& arg = CMD_ARGUMENTS[i];
|
||||||
|
LOG(format("\t%s\t%s", arg.Name.c_str(), arg.Descritpion.c_str()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool StartServer(const std::string& mapPath, std::uint16_t port) {
|
||||||
|
td::server::Server server {mapPath};
|
||||||
|
return !server.Start(port);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
extern "C"
|
extern "C"
|
||||||
@@ -23,5 +52,42 @@ int main(int argc, const char* args[]) {
|
|||||||
backward::SignalHandling sh;
|
backward::SignalHandling sh;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
std::string mapFilePath;
|
||||||
|
std::uint16_t port = 25565;
|
||||||
|
|
||||||
|
for (int i = 1; i < argc; i++) {
|
||||||
|
std::string arg = args[i];
|
||||||
|
|
||||||
|
if (arg == "--help") {
|
||||||
|
DisplayHelp();
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg == "-P") {
|
||||||
|
i++;
|
||||||
|
|
||||||
|
if (i >= argc) {
|
||||||
|
LOG("You must specify a valid port !");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
port = std::stoi(args[i]);
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
LOG("You must specify a valid port !");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mapFilePath.empty()) {
|
||||||
|
LOG(format("Uknown parameter : %s !", arg.c_str()));
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
mapFilePath = arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
return StartServer(mapFilePath, port);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user