mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-03 06:16:15 +00:00
Compare commits
45 Commits
fix-resour
...
v2.3.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a8e0be1a1 | ||
|
|
e0041666ca | ||
|
|
ed686333ec | ||
|
|
8938fd84ea | ||
|
|
bd4c9c34a9 | ||
|
|
8519e279a7 | ||
|
|
54895eb1b0 | ||
|
|
1423c1193b | ||
|
|
288e76594d | ||
|
|
4fdc3c4031 | ||
|
|
708da44fec | ||
|
|
6b6e304cfd | ||
|
|
06cb366bb5 | ||
|
|
0b35f0484f | ||
|
|
9dbbd8298d | ||
|
|
ca9dd1ae75 | ||
|
|
9ebd218856 | ||
|
|
d9874ce70e | ||
|
|
423519f31e | ||
|
|
3f12bb757a | ||
|
|
7d52e44434 | ||
|
|
4fbd25b551 | ||
|
|
3cf1a2e51b | ||
|
|
49874fd633 | ||
|
|
6a23518eff | ||
|
|
3297b3e62e | ||
|
|
76cfc47a2f | ||
|
|
7b59cb6f87 | ||
|
|
0eba745d4c | ||
|
|
259b21502e | ||
|
|
afac729505 | ||
|
|
f57ebb7a92 | ||
|
|
ace96b7e33 | ||
|
|
0c53ff4cd4 | ||
|
|
68a4d64387 | ||
|
|
5bdd8c11da | ||
|
|
47681cda50 | ||
|
|
c99fecfa1c | ||
|
|
d26e0320e4 | ||
|
|
57422a6105 | ||
|
|
467c8dc584 | ||
|
|
2ddb576e72 | ||
|
|
e242057583 | ||
|
|
06686688fc | ||
|
|
aca61886d0 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -12,3 +12,4 @@ Resources/
|
|||||||
bin/
|
bin/
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
key
|
key
|
||||||
|
out/
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -9,8 +9,8 @@ The launcher is the way we communitcate to outside the game, it does a few autom
|
|||||||
In the root directory of the project,
|
In the root directory of the project,
|
||||||
1. `cmake -DCMAKE_BUILD_TYPE=Release . -B bin -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static`
|
1. `cmake -DCMAKE_BUILD_TYPE=Release . -B bin -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static`
|
||||||
2. `cmake --build bin --parallel --config Release`
|
2. `cmake --build bin --parallel --config Release`
|
||||||
|
|
||||||
Remember to change `C:/vcpkg` to wherever you have vcpkg installed.
|
Remember to change `C:/vcpkg` to wherever you have vcpkg installed.
|
||||||
|
|
||||||
## How to build - Debug
|
## How to build - Debug
|
||||||
|
|
||||||
@@ -18,10 +18,4 @@ In the root directory of the project,
|
|||||||
1. `cmake . -B bin -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static`
|
1. `cmake . -B bin -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static`
|
||||||
2. `cmake --build bin --parallel`
|
2. `cmake --build bin --parallel`
|
||||||
|
|
||||||
Remember to change `C:/vcpkg` to wherever you have vcpkg installed.
|
Remember to change `C:/vcpkg` to wherever you have vcpkg installed.
|
||||||
|
|
||||||
Copyright (c) 2019-present Anonymous275.
|
|
||||||
BeamMP Launcher code is not in the public domain and is not free software.
|
|
||||||
One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries,
|
|
||||||
the only permission that has been granted is to use the software in its compiled form as distributed from the BeamMP.com website.
|
|
||||||
Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
|
||||||
|
|||||||
@@ -17,5 +17,4 @@ public:
|
|||||||
static void StartProxy();
|
static void StartProxy();
|
||||||
public:
|
public:
|
||||||
static bool isDownload;
|
static bool isDownload;
|
||||||
static inline bool SkipSslVerify = false;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ extern int ClientID;
|
|||||||
extern int LastPort;
|
extern int LastPort;
|
||||||
extern bool ModLoaded;
|
extern bool ModLoaded;
|
||||||
extern bool Terminate;
|
extern bool Terminate;
|
||||||
extern int DEFAULT_PORT;
|
|
||||||
extern uint64_t UDPSock;
|
extern uint64_t UDPSock;
|
||||||
extern uint64_t TCPSock;
|
extern uint64_t TCPSock;
|
||||||
extern std::string Branch;
|
extern std::string Branch;
|
||||||
|
|||||||
24
include/Options.h
Normal file
24
include/Options.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
struct Options {
|
||||||
|
#if defined(_WIN32)
|
||||||
|
std::string executable_name = "BeamMP-Launcher.exe";
|
||||||
|
#elif defined(__linux__)
|
||||||
|
std::string executable_name = "BeamMP-Launcher";
|
||||||
|
#endif
|
||||||
|
unsigned int port = 4444;
|
||||||
|
bool verbose = false;
|
||||||
|
bool no_download = false;
|
||||||
|
bool no_update = false;
|
||||||
|
bool no_launch = false;
|
||||||
|
const char **game_arguments = nullptr;
|
||||||
|
int game_arguments_length = 0;
|
||||||
|
const char** argv = nullptr;
|
||||||
|
int argc = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
void InitOptions(int argc, const char *argv[], Options &options);
|
||||||
|
|
||||||
|
extern Options options;
|
||||||
@@ -10,12 +10,10 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
void InitLauncher(int argc, char* argv[]);
|
void InitLauncher();
|
||||||
std::string GetEP(char* P = nullptr);
|
std::string GetEP(const char* P = nullptr);
|
||||||
std::string GetGamePath();
|
std::string GetGamePath();
|
||||||
std::string GetVer();
|
std::string GetVer();
|
||||||
std::string GetPatch();
|
std::string GetPatch();
|
||||||
std::string GetEN();
|
std::string GetEN();
|
||||||
void ConfigInit();
|
void ConfigInit();
|
||||||
extern bool Dev;
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
#include "Options.h"
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
std::string Branch;
|
std::string Branch;
|
||||||
@@ -15,7 +16,7 @@ std::string CachingDirectory = "./Resources";
|
|||||||
|
|
||||||
void ParseConfig(const nlohmann::json& d) {
|
void ParseConfig(const nlohmann::json& d) {
|
||||||
if (d["Port"].is_number()) {
|
if (d["Port"].is_number()) {
|
||||||
DEFAULT_PORT = d["Port"].get<int>();
|
options.port = d["Port"].get<int>();
|
||||||
}
|
}
|
||||||
// Default -1
|
// Default -1
|
||||||
// Release 1
|
// Release 1
|
||||||
@@ -31,6 +32,14 @@ void ParseConfig(const nlohmann::json& d) {
|
|||||||
CachingDirectory = d["CachingDirectory"].get<std::string>();
|
CachingDirectory = d["CachingDirectory"].get<std::string>();
|
||||||
info("Mod caching directory: " + CachingDirectory);
|
info("Mod caching directory: " + CachingDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (d.contains("Dev") && d["Dev"].is_boolean()) {
|
||||||
|
bool dev = d["Dev"].get<bool>();
|
||||||
|
options.verbose = dev;
|
||||||
|
options.no_download = dev;
|
||||||
|
options.no_launch = dev;
|
||||||
|
options.no_update = dev;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigInit() {
|
void ConfigInit() {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include <Security/Init.h>
|
#include <Security/Init.h>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include "Options.h"
|
||||||
|
|
||||||
unsigned long GamePID = 0;
|
unsigned long GamePID = 0;
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
@@ -83,7 +84,14 @@ void StartGame(std::string Dir) {
|
|||||||
std::string BaseDir = Dir; //+"\\Bin64";
|
std::string BaseDir = Dir; //+"\\Bin64";
|
||||||
// Dir += R"(\Bin64\BeamNG.drive.x64.exe)";
|
// Dir += R"(\Bin64\BeamNG.drive.x64.exe)";
|
||||||
Dir += "\\BeamNG.drive.exe";
|
Dir += "\\BeamNG.drive.exe";
|
||||||
bSuccess = CreateProcessA(Dir.c_str(), nullptr, nullptr, nullptr, TRUE, 0, nullptr, BaseDir.c_str(), &si, &pi);
|
std::string gameArgs = "";
|
||||||
|
|
||||||
|
for (int i = 0; i < options.game_arguments_length; i++) {
|
||||||
|
gameArgs += " ";
|
||||||
|
gameArgs += options.game_arguments[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
bSuccess = CreateProcessA(nullptr, (LPSTR)(Dir + gameArgs).c_str(), nullptr, nullptr, TRUE, 0, nullptr, BaseDir.c_str(), &si, &pi);
|
||||||
if (bSuccess) {
|
if (bSuccess) {
|
||||||
info("Game Launched!");
|
info("Game Launched!");
|
||||||
GamePID = pi.dwProcessId;
|
GamePID = pi.dwProcessId;
|
||||||
@@ -99,13 +107,19 @@ void StartGame(std::string Dir) {
|
|||||||
void StartGame(std::string Dir) {
|
void StartGame(std::string Dir) {
|
||||||
int status;
|
int status;
|
||||||
std::string filename = (Dir + "/BinLinux/BeamNG.drive.x64");
|
std::string filename = (Dir + "/BinLinux/BeamNG.drive.x64");
|
||||||
char* argv[] = { filename.data(), NULL };
|
std::vector<const char*> argv;
|
||||||
|
argv.push_back(filename.data());
|
||||||
|
for (int i = 0; i < options.game_arguments_length; i++) {
|
||||||
|
argv.push_back(options.game_arguments[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
argv.push_back(nullptr);
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
posix_spawn_file_actions_t spawn_actions;
|
posix_spawn_file_actions_t spawn_actions;
|
||||||
posix_spawn_file_actions_init(&spawn_actions);
|
posix_spawn_file_actions_init(&spawn_actions);
|
||||||
posix_spawn_file_actions_addclose(&spawn_actions, STDOUT_FILENO);
|
posix_spawn_file_actions_addclose(&spawn_actions, STDOUT_FILENO);
|
||||||
posix_spawn_file_actions_addclose(&spawn_actions, STDERR_FILENO);
|
posix_spawn_file_actions_addclose(&spawn_actions, STDERR_FILENO);
|
||||||
int result = posix_spawn(&pid, filename.c_str(), &spawn_actions, nullptr, argv, environ);
|
int result = posix_spawn(&pid, filename.c_str(), &spawn_actions, nullptr, const_cast<char**>(argv.data()), environ);
|
||||||
|
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
error("Failed to Launch the game! launcher closing soon");
|
error("Failed to Launch the game! launcher closing soon");
|
||||||
@@ -121,7 +135,7 @@ void StartGame(std::string Dir) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void InitGame(const std::string& Dir) {
|
void InitGame(const std::string& Dir) {
|
||||||
if (!Dev) {
|
if (!options.no_launch) {
|
||||||
std::thread Game(StartGame, Dir);
|
std::thread Game(StartGame, Dir);
|
||||||
Game.detach();
|
Game.detach();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include "Options.h"
|
||||||
|
|
||||||
std::string getDate() {
|
std::string getDate() {
|
||||||
time_t tt = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
time_t tt = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
||||||
@@ -55,7 +56,7 @@ void info(const std::string& toPrint) {
|
|||||||
}
|
}
|
||||||
void debug(const std::string& toPrint) {
|
void debug(const std::string& toPrint) {
|
||||||
std::string Print = getDate() + "[DEBUG] " + toPrint + "\n";
|
std::string Print = getDate() + "[DEBUG] " + toPrint + "\n";
|
||||||
if (Dev) {
|
if (options.verbose) {
|
||||||
std::cout << Print;
|
std::cout << Print;
|
||||||
}
|
}
|
||||||
addToLog(Print);
|
addToLog(Print);
|
||||||
|
|||||||
@@ -30,11 +30,14 @@
|
|||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <mutex>
|
||||||
|
#include "Options.h"
|
||||||
|
|
||||||
|
#include <future>
|
||||||
|
|
||||||
extern int TraceBack;
|
extern int TraceBack;
|
||||||
std::set<std::string>* ConfList = nullptr;
|
std::set<std::string>* ConfList = nullptr;
|
||||||
bool TCPTerminate = false;
|
bool TCPTerminate = false;
|
||||||
int DEFAULT_PORT = 4444;
|
|
||||||
bool Terminate = false;
|
bool Terminate = false;
|
||||||
bool LoginAuth = false;
|
bool LoginAuth = false;
|
||||||
std::string Username = "";
|
std::string Username = "";
|
||||||
@@ -87,7 +90,11 @@ void StartSync(const std::string& Data) {
|
|||||||
info("Connecting to server");
|
info("Connecting to server");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::mutex sendMutex;
|
||||||
|
|
||||||
void CoreSend(std::string data) {
|
void CoreSend(std::string data) {
|
||||||
|
std::lock_guard lock(sendMutex);
|
||||||
|
|
||||||
if (CoreSocket != -1) {
|
if (CoreSocket != -1) {
|
||||||
int res = send(CoreSocket, (data + "\n").c_str(), int(data.size()) + 1, 0);
|
int res = send(CoreSocket, (data + "\n").c_str(), int(data.size()) + 1, 0);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
@@ -97,7 +104,7 @@ void CoreSend(std::string data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool IsAllowedLink(const std::string& Link) {
|
bool IsAllowedLink(const std::string& Link) {
|
||||||
std::regex link_pattern(R"(https:\/\/(?:\w+)?(?:\.)?(?:beammp\.com|discord\.gg|patreon\.com\/BeamMP))");
|
std::regex link_pattern(R"(https:\/\/(?:\w+)?(?:\.)?(?:beammp\.com|beammp\.gg|github.com\/BeamMP\/|discord\.gg|patreon\.com\/BeamMP))");
|
||||||
std::smatch link_match;
|
std::smatch link_match;
|
||||||
return std::regex_search(Link, link_match, link_pattern) && link_match.position() == 0;
|
return std::regex_search(Link, link_match, link_pattern) && link_match.position() == 0;
|
||||||
}
|
}
|
||||||
@@ -110,11 +117,15 @@ void Parse(std::string Data, SOCKET CSocket) {
|
|||||||
case 'A':
|
case 'A':
|
||||||
Data = Data.substr(0, 1);
|
Data = Data.substr(0, 1);
|
||||||
break;
|
break;
|
||||||
case 'B':
|
case 'B': {
|
||||||
NetReset();
|
NetReset();
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
TCPTerminate = true;
|
TCPTerminate = true;
|
||||||
Data = Code + HTTP::Get("https://backend.beammp.com/servers-info");
|
Data.clear();
|
||||||
|
auto future = std::async(std::launch::async, []() {
|
||||||
|
CoreSend("B" + HTTP::Get("https://backend.beammp.com/servers-info"));
|
||||||
|
});
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
StartSync(Data);
|
StartSync(Data);
|
||||||
@@ -210,7 +221,10 @@ void Parse(std::string Data, SOCKET CSocket) {
|
|||||||
}
|
}
|
||||||
Data = "N" + Auth.dump();
|
Data = "N" + Auth.dump();
|
||||||
} else {
|
} else {
|
||||||
Data = "N" + Login(Data.substr(Data.find(':') + 1));
|
auto future = std::async(std::launch::async, [data = std::move(Data)]() {
|
||||||
|
CoreSend("N" + Login(data.substr(data.find(':') + 1)));
|
||||||
|
});
|
||||||
|
Data.clear();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'W':
|
case 'W':
|
||||||
@@ -226,12 +240,8 @@ void Parse(std::string Data, SOCKET CSocket) {
|
|||||||
Data.clear();
|
Data.clear();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!Data.empty() && CSocket != -1) {
|
if (!Data.empty())
|
||||||
int res = send(CSocket, (Data + "\n").c_str(), int(Data.size()) + 1, 0);
|
CoreSend(Data);
|
||||||
if (res < 0) {
|
|
||||||
debug("(Core) send failed with error: " + std::to_string(WSAGetLastError()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void GameHandler(SOCKET Client) {
|
void GameHandler(SOCKET Client) {
|
||||||
CoreSocket = Client;
|
CoreSocket = Client;
|
||||||
@@ -288,7 +298,7 @@ void localRes() {
|
|||||||
ConfList = new std::set<std::string>;
|
ConfList = new std::set<std::string>;
|
||||||
}
|
}
|
||||||
void CoreMain() {
|
void CoreMain() {
|
||||||
debug("Core Network on start!");
|
debug("Core Network on start! port: " + std::to_string(options.port));
|
||||||
SOCKET LSocket, CSocket;
|
SOCKET LSocket, CSocket;
|
||||||
struct addrinfo* res = nullptr;
|
struct addrinfo* res = nullptr;
|
||||||
struct addrinfo hints { };
|
struct addrinfo hints { };
|
||||||
@@ -306,7 +316,7 @@ void CoreMain() {
|
|||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
hints.ai_protocol = IPPROTO_TCP;
|
hints.ai_protocol = IPPROTO_TCP;
|
||||||
hints.ai_flags = AI_PASSIVE;
|
hints.ai_flags = AI_PASSIVE;
|
||||||
iRes = getaddrinfo(nullptr, std::to_string(DEFAULT_PORT).c_str(), &hints, &res);
|
iRes = getaddrinfo("127.0.0.1", std::to_string(options.port).c_str(), &hints, &res);
|
||||||
if (iRes) {
|
if (iRes) {
|
||||||
debug("(Core) addr info failed with error: " + std::to_string(iRes));
|
debug("(Core) addr info failed with error: " + std::to_string(iRes));
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include "Options.h"
|
||||||
|
|
||||||
std::chrono::time_point<std::chrono::high_resolution_clock> PingStart, PingEnd;
|
std::chrono::time_point<std::chrono::high_resolution_clock> PingStart, PingEnd;
|
||||||
bool GConnected = false;
|
bool GConnected = false;
|
||||||
@@ -161,7 +162,7 @@ SOCKET SetupListener() {
|
|||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
hints.ai_protocol = IPPROTO_TCP;
|
hints.ai_protocol = IPPROTO_TCP;
|
||||||
hints.ai_flags = AI_PASSIVE;
|
hints.ai_flags = AI_PASSIVE;
|
||||||
iRes = getaddrinfo(nullptr, std::to_string(DEFAULT_PORT + 1).c_str(), &hints, &result);
|
iRes = getaddrinfo(nullptr, std::to_string(options.port + 1).c_str(), &hints, &result);
|
||||||
if (iRes != 0) {
|
if (iRes != 0) {
|
||||||
error("(Proxy) info failed with error: " + std::to_string(iRes));
|
error("(Proxy) info failed with error: " + std::to_string(iRes));
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
|
|||||||
@@ -77,7 +77,8 @@ std::string HTTP::Get(const std::string& IP) {
|
|||||||
curl_easy_setopt(curl, CURLOPT_URL, IP.c_str());
|
curl_easy_setopt(curl, CURLOPT_URL, IP.c_str());
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWriteCallback);
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWriteCallback);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&Ret);
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&Ret);
|
||||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10); // seconds
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10); // seconds
|
||||||
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||||
res = curl_easy_perform(curl);
|
res = curl_easy_perform(curl);
|
||||||
if (res != CURLE_OK) {
|
if (res != CURLE_OK) {
|
||||||
error("GET to " + IP + " failed: " + std::string(curl_easy_strerror(res)));
|
error("GET to " + IP + " failed: " + std::string(curl_easy_strerror(res)));
|
||||||
@@ -104,7 +105,8 @@ std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
|
|||||||
struct curl_slist* list = nullptr;
|
struct curl_slist* list = nullptr;
|
||||||
list = curl_slist_append(list, "Content-Type: application/json");
|
list = curl_slist_append(list, "Content-Type: application/json");
|
||||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
|
||||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10); // seconds
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10); // seconds
|
||||||
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||||
res = curl_easy_perform(curl);
|
res = curl_easy_perform(curl);
|
||||||
curl_slist_free_all(list);
|
curl_slist_free_all(list);
|
||||||
if (res != CURLE_OK) {
|
if (res != CURLE_OK) {
|
||||||
@@ -134,7 +136,6 @@ bool HTTP::Download(const std::string& IP, const std::string& Path) {
|
|||||||
if (File.is_open()) {
|
if (File.is_open()) {
|
||||||
File << Ret;
|
File << Ret;
|
||||||
File.close();
|
File.close();
|
||||||
std::cout << "\n";
|
|
||||||
info("Download Complete!");
|
info("Download Complete!");
|
||||||
} else {
|
} else {
|
||||||
error("Failed to open file directory: " + Path);
|
error("Failed to open file directory: " + Path);
|
||||||
@@ -260,7 +261,7 @@ void HTTP::StartProxy() {
|
|||||||
handle_request(req, res);
|
handle_request(req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
ProxyPort = HTTPProxy.bind_to_any_port("0.0.0.0");
|
ProxyPort = HTTPProxy.bind_to_any_port("127.0.0.1");
|
||||||
debug("HTTP Proxy listening on port " + std::to_string(ProxyPort));
|
debug("HTTP Proxy listening on port " + std::to_string(ProxyPort));
|
||||||
HTTPProxy.listen_after_bind();
|
HTTPProxy.listen_after_bind();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -362,10 +362,15 @@ std::string GetSha256HashReallyFast(const std::string& filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct ModInfo {
|
struct ModInfo {
|
||||||
static std::vector<ModInfo> ParseModInfosFromPacket(const std::string& packet) {
|
static std::pair<bool, std::vector<ModInfo>> ParseModInfosFromPacket(const std::string& packet) {
|
||||||
|
bool success = false;
|
||||||
std::vector<ModInfo> modInfos;
|
std::vector<ModInfo> modInfos;
|
||||||
try {
|
try {
|
||||||
auto json = nlohmann::json::parse(packet);
|
auto json = nlohmann::json::parse(packet);
|
||||||
|
if (json.empty()) {
|
||||||
|
return std::make_pair(true, modInfos);
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto& entry : json) {
|
for (const auto& entry : json) {
|
||||||
ModInfo modInfo {
|
ModInfo modInfo {
|
||||||
.FileName = entry["file_name"],
|
.FileName = entry["file_name"],
|
||||||
@@ -374,13 +379,13 @@ struct ModInfo {
|
|||||||
.HashAlgorithm = entry["hash_algorithm"],
|
.HashAlgorithm = entry["hash_algorithm"],
|
||||||
};
|
};
|
||||||
modInfos.push_back(modInfo);
|
modInfos.push_back(modInfo);
|
||||||
|
success = true;
|
||||||
}
|
}
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
debug(std::string("Failed to receive mod list: ") + e.what());
|
debug(std::string("Failed to receive mod list: ") + e.what());
|
||||||
error("Failed to receive mod list!");
|
warn("Failed to receive new mod list format! This server may be outdated, but everything should still work as expected.");
|
||||||
// TODO: Cry and die
|
|
||||||
}
|
}
|
||||||
return modInfos;
|
return std::make_pair(success, modInfos);
|
||||||
}
|
}
|
||||||
std::string FileName;
|
std::string FileName;
|
||||||
size_t FileSize;
|
size_t FileSize;
|
||||||
@@ -389,6 +394,13 @@ struct ModInfo {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<ModInfo> ModInfos) {
|
void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<ModInfo> ModInfos) {
|
||||||
|
if (ModInfos.empty()) {
|
||||||
|
CoreSend("L");
|
||||||
|
TCPSend("Done", Sock);
|
||||||
|
info("Done!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!SecurityWarning())
|
if (!SecurityWarning())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -511,11 +523,17 @@ void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<Mo
|
|||||||
void SyncResources(SOCKET Sock) {
|
void SyncResources(SOCKET Sock) {
|
||||||
std::string Ret = Auth(Sock);
|
std::string Ret = Auth(Sock);
|
||||||
|
|
||||||
auto ModInfos = ModInfo::ParseModInfosFromPacket(Ret);
|
debug("Mod info: " + Ret);
|
||||||
|
|
||||||
if (!ModInfos.empty()) {
|
if (Ret.starts_with("R")) {
|
||||||
NewSyncResources(Sock, Ret, ModInfos);
|
debug("This server is likely outdated, not trying to parse new mod info format");
|
||||||
return;
|
} else {
|
||||||
|
auto [success, modInfo] = ModInfo::ParseModInfosFromPacket(Ret);
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
NewSyncResources(Sock, Ret, modInfo);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ret.empty())
|
if (Ret.empty())
|
||||||
|
|||||||
107
src/Options.cpp
Normal file
107
src/Options.cpp
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
#include "Options.h"
|
||||||
|
|
||||||
|
#include "Logger.h"
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
void InitOptions(int argc, const char *argv[], Options &options) {
|
||||||
|
int i = 1;
|
||||||
|
|
||||||
|
options.argc = argc;
|
||||||
|
options.argv = argv;
|
||||||
|
|
||||||
|
std::string AllOptions;
|
||||||
|
for (int i = 0; i < argc; ++i) {
|
||||||
|
AllOptions += std::string(argv[i]);
|
||||||
|
if (i + 1 < argc) {
|
||||||
|
AllOptions += " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
debug("Launcher was invoked as: '" + AllOptions + "'");
|
||||||
|
|
||||||
|
|
||||||
|
if (argc > 2) {
|
||||||
|
if (std::string(argv[1]) == "0" && std::string(argv[2]) == "0") {
|
||||||
|
options.verbose = true;
|
||||||
|
options.no_download = true;
|
||||||
|
options.no_launch = true;
|
||||||
|
options.no_update = true;
|
||||||
|
warn("You are using deprecated commandline arguments, please use --dev instead");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
options.executable_name = std::string(argv[0]);
|
||||||
|
|
||||||
|
while (i < argc) {
|
||||||
|
std::string argument(argv[i]);
|
||||||
|
if (argument == "-p" || argument == "--port") {
|
||||||
|
if (i + 1 >= argc) {
|
||||||
|
std::string error_message =
|
||||||
|
"No port specified, resorting to default (";
|
||||||
|
error_message += std::to_string(options.port);
|
||||||
|
error_message += ")";
|
||||||
|
error(error_message);
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int port = options.port;
|
||||||
|
|
||||||
|
try {
|
||||||
|
port = std::stoi(argv[i + 1]);
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
error("Invalid port specified: " + std::string(argv[i + 1]) + " " + std::string(e.what()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (port <= 0) {
|
||||||
|
std::string error_message =
|
||||||
|
"Port invalid, must be a non-zero positive "
|
||||||
|
"integer, resorting to default (";
|
||||||
|
error_message += options.port;
|
||||||
|
error_message += ")";
|
||||||
|
error(error_message);
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
options.port = port;
|
||||||
|
i++;
|
||||||
|
} else if (argument == "-v" || argument == "--verbose") {
|
||||||
|
options.verbose = true;
|
||||||
|
} else if (argument == "--no-download") {
|
||||||
|
options.no_download = true;
|
||||||
|
} else if (argument == "--no-update") {
|
||||||
|
options.no_update = true;
|
||||||
|
} else if (argument == "--no-launch") {
|
||||||
|
options.no_launch = true;
|
||||||
|
} else if (argument == "--dev") {
|
||||||
|
options.verbose = true;
|
||||||
|
options.no_download = true;
|
||||||
|
options.no_launch = true;
|
||||||
|
options.no_update = true;
|
||||||
|
} else if (argument == "--" || argument == "--game") {
|
||||||
|
options.game_arguments = &argv[i + 1];
|
||||||
|
options.game_arguments_length = argc - i - 1;
|
||||||
|
break;
|
||||||
|
} else if (argument == "--help" || argument == "-h" || argument == "/?") {
|
||||||
|
std::cout << "USAGE:\n"
|
||||||
|
"\t" + std::filesystem::path(options.executable_name).filename().string() + " [OPTIONS] [-- <GAME ARGS>...]\n"
|
||||||
|
"\n"
|
||||||
|
"OPTIONS:\n"
|
||||||
|
"\t--port <port> -p Change the default listen port to <port>. This must be configured ingame, too\n"
|
||||||
|
"\t--verbose -v Verbose mode, prints debug messages\n"
|
||||||
|
"\t--no-download Skip downloading and installing the BeamMP Lua mod\n"
|
||||||
|
"\t--no-update Skip applying launcher updates (you must update manually)\n"
|
||||||
|
"\t--no-launch Skip launching the game (you must launch the game manually)\n"
|
||||||
|
"\t--dev Developer mode, same as --verbose --no-download --no-launch --no-update\n"
|
||||||
|
"\t--game <args...> Passes ALL following arguments to the game, see also `--`\n"
|
||||||
|
<< std::flush;
|
||||||
|
exit(0);
|
||||||
|
} else {
|
||||||
|
warn("Unknown option: " + argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -91,6 +91,7 @@ std::string Login(const std::string& fields) {
|
|||||||
if (d.contains("message")) {
|
if (d.contains("message")) {
|
||||||
d.erase("private_key");
|
d.erase("private_key");
|
||||||
d.erase("public_key");
|
d.erase("public_key");
|
||||||
|
debug("Authentication result: " + d["message"].get<std::string>());
|
||||||
return d.dump();
|
return d.dump();
|
||||||
}
|
}
|
||||||
return GetFail("Invalid message parsing!");
|
return GetFail("Invalid message parsing!");
|
||||||
|
|||||||
119
src/Startup.cpp
119
src/Startup.cpp
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "zip_file.h"
|
#include "zip_file.h"
|
||||||
#include <charconv>
|
#include <charconv>
|
||||||
|
#include <cstring>
|
||||||
#include <httplib.h>
|
#include <httplib.h>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -25,9 +26,9 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include "Options.h"
|
||||||
|
|
||||||
extern int TraceBack;
|
extern int TraceBack;
|
||||||
bool Dev = false;
|
|
||||||
int ProxyPort = 0;
|
int ProxyPort = 0;
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
@@ -81,13 +82,13 @@ std::string GetEN() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string GetVer() {
|
std::string GetVer() {
|
||||||
return "2.2";
|
return "2.3";
|
||||||
}
|
}
|
||||||
std::string GetPatch() {
|
std::string GetPatch() {
|
||||||
return ".0";
|
return ".1";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetEP(char* P) {
|
std::string GetEP(const char* P) {
|
||||||
static std::string Ret = [&]() {
|
static std::string Ret = [&]() {
|
||||||
std::string path(P);
|
std::string path(P);
|
||||||
return path.substr(0, path.find_last_of("\\/") + 1);
|
return path.substr(0, path.find_last_of("\\/") + 1);
|
||||||
@@ -95,11 +96,11 @@ std::string GetEP(char* P) {
|
|||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
void ReLaunch(int argc, char* args[]) {
|
void ReLaunch() {
|
||||||
std::string Arg;
|
std::string Arg;
|
||||||
for (int c = 2; c <= argc; c++) {
|
for (int c = 2; c <= options.argc; c++) {
|
||||||
|
Arg += options.argv[c - 1];
|
||||||
Arg += " ";
|
Arg += " ";
|
||||||
Arg += args[c - 1];
|
|
||||||
}
|
}
|
||||||
info("Relaunch!");
|
info("Relaunch!");
|
||||||
system("cls");
|
system("cls");
|
||||||
@@ -108,11 +109,11 @@ void ReLaunch(int argc, char* args[]) {
|
|||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
void URelaunch(int argc, char* args[]) {
|
void URelaunch() {
|
||||||
std::string Arg;
|
std::string Arg;
|
||||||
for (int c = 2; c <= argc; c++) {
|
for (int c = 2; c <= options.argc; c++) {
|
||||||
|
Arg += options.argv[c - 1];
|
||||||
Arg += " ";
|
Arg += " ";
|
||||||
Arg += args[c - 1];
|
|
||||||
}
|
}
|
||||||
ShellExecute(nullptr, "open", (GetEP() + GetEN()).c_str(), Arg.c_str(), nullptr, SW_SHOWNORMAL);
|
ShellExecute(nullptr, "open", (GetEP() + GetEN()).c_str(), Arg.c_str(), nullptr, SW_SHOWNORMAL);
|
||||||
ShowWindow(GetConsoleWindow(), 0);
|
ShowWindow(GetConsoleWindow(), 0);
|
||||||
@@ -120,47 +121,50 @@ void URelaunch(int argc, char* args[]) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
void ReLaunch(int argc, char* args[]) {
|
void ReLaunch() {
|
||||||
std::string Arg;
|
std::string Arg;
|
||||||
for (int c = 2; c <= argc; c++) {
|
for (int c = 2; c <= options.argc; c++) {
|
||||||
|
Arg += options.argv[c - 1];
|
||||||
Arg += " ";
|
Arg += " ";
|
||||||
Arg += args[c - 1];
|
|
||||||
}
|
}
|
||||||
info("Relaunch!");
|
info("Relaunch!");
|
||||||
system("clear");
|
system("clear");
|
||||||
execl((GetEP() + GetEN()).c_str(), Arg.c_str(), NULL);
|
int ret = execv(options.executable_name.c_str(), const_cast<char**>(options.argv));
|
||||||
|
if (ret < 0) {
|
||||||
|
error(std::string("execv() failed with: ") + strerror(errno) + ". Failed to relaunch");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
void URelaunch(int argc, char* args[]) {
|
void URelaunch() {
|
||||||
std::string Arg;
|
int ret = execv(options.executable_name.c_str(), const_cast<char**>(options.argv));
|
||||||
for (int c = 2; c <= argc; c++) {
|
if (ret < 0) {
|
||||||
Arg += " ";
|
error(std::string("execv() failed with: ") + strerror(errno) + ". Failed to relaunch");
|
||||||
Arg += args[c - 1];
|
exit(1);
|
||||||
}
|
}
|
||||||
execl((GetEP() + GetEN()).c_str(), Arg.c_str(), NULL);
|
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void CheckName(int argc, char* args[]) {
|
void CheckName() {
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
std::string DN = GetEN(), CDir = args[0], FN = CDir.substr(CDir.find_last_of('\\') + 1);
|
std::string DN = GetEN(), CDir = options.executable_name, FN = CDir.substr(CDir.find_last_of('\\') + 1);
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
std::string DN = GetEN(), CDir = args[0], FN = CDir.substr(CDir.find_last_of('/') + 1);
|
std::string DN = GetEN(), CDir = options.executable_name, FN = CDir.substr(CDir.find_last_of('/') + 1);
|
||||||
#endif
|
#endif
|
||||||
if (FN != DN) {
|
if (FN != DN) {
|
||||||
if (fs::exists(DN))
|
if (fs::exists(DN))
|
||||||
remove(DN.c_str());
|
remove(DN.c_str());
|
||||||
if (fs::exists(DN))
|
if (fs::exists(DN))
|
||||||
ReLaunch(argc, args);
|
ReLaunch();
|
||||||
std::rename(FN.c_str(), DN.c_str());
|
std::rename(FN.c_str(), DN.c_str());
|
||||||
URelaunch(argc, args);
|
URelaunch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckForUpdates(int argc, char* args[], const std::string& CV) {
|
void CheckForUpdates(const std::string& CV) {
|
||||||
std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/launcher?branch=" + Branch + "&pk=" + PublicKey);
|
std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/launcher?branch=" + Branch + "&pk=" + PublicKey);
|
||||||
std::string LatestVersion = HTTP::Get(
|
std::string LatestVersion = HTTP::Get(
|
||||||
"https://backend.beammp.com/version/launcher?branch=" + Branch + "&pk=" + PublicKey);
|
"https://backend.beammp.com/version/launcher?branch=" + Branch + "&pk=" + PublicKey);
|
||||||
@@ -170,39 +174,30 @@ void CheckForUpdates(int argc, char* args[], const std::string& CV) {
|
|||||||
|
|
||||||
std::string FileHash = hashpp::get::getFileHash(hashpp::ALGORITHMS::SHA2_256, EP);
|
std::string FileHash = hashpp::get::getFileHash(hashpp::ALGORITHMS::SHA2_256, EP);
|
||||||
|
|
||||||
if (FileHash != LatestHash && IsOutdated(Version(VersionStrToInts(GetVer() + GetPatch())), Version(VersionStrToInts(LatestVersion))) && !Dev) {
|
if (FileHash != LatestHash && IsOutdated(Version(VersionStrToInts(GetVer() + GetPatch())), Version(VersionStrToInts(LatestVersion)))) {
|
||||||
info("Launcher update found!");
|
if (!options.no_update) {
|
||||||
|
info("Launcher update found!");
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
error("Auto update is NOT implemented for the Linux version. Please update manually ASAP as updates contain security patches.");
|
error("Auto update is NOT implemented for the Linux version. Please update manually ASAP as updates contain security patches.");
|
||||||
#else
|
#else
|
||||||
fs::remove(Back);
|
fs::remove(Back);
|
||||||
fs::rename(EP, Back);
|
fs::rename(EP, Back);
|
||||||
info("Downloading Launcher update " + LatestHash);
|
info("Downloading Launcher update " + LatestHash);
|
||||||
HTTP::Download(
|
HTTP::Download(
|
||||||
"https://backend.beammp.com/builds/launcher?download=true"
|
"https://backend.beammp.com/builds/launcher?download=true"
|
||||||
"&pk="
|
"&pk="
|
||||||
+ PublicKey + "&branch=" + Branch,
|
+ PublicKey + "&branch=" + Branch,
|
||||||
EP);
|
EP);
|
||||||
URelaunch(argc, args);
|
URelaunch();
|
||||||
#endif
|
#endif
|
||||||
|
} else {
|
||||||
|
warn("Launcher update was found, but not updating because --no-update or --dev was specified.");
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
info("Launcher version is up to date");
|
info("Launcher version is up to date");
|
||||||
TraceBack++;
|
TraceBack++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomPort(int argc, char* argv[]) {
|
|
||||||
if (argc > 1) {
|
|
||||||
std::string Port = argv[1];
|
|
||||||
if (Port.find_first_not_of("0123456789") == std::string::npos) {
|
|
||||||
if (std::stoi(Port) > 1000) {
|
|
||||||
DEFAULT_PORT = std::stoi(Port);
|
|
||||||
warn("Running on custom port : " + std::to_string(DEFAULT_PORT));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (argc > 2)
|
|
||||||
Dev = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
void LinuxPatch() {
|
void LinuxPatch() {
|
||||||
@@ -234,25 +229,21 @@ void LinuxPatch() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
void InitLauncher(int argc, char* argv[]) {
|
|
||||||
|
void InitLauncher() {
|
||||||
SetConsoleTitleA(("BeamMP Launcher v" + std::string(GetVer()) + GetPatch()).c_str());
|
SetConsoleTitleA(("BeamMP Launcher v" + std::string(GetVer()) + GetPatch()).c_str());
|
||||||
InitLog();
|
CheckName();
|
||||||
CheckName(argc, argv);
|
|
||||||
LinuxPatch();
|
LinuxPatch();
|
||||||
CheckLocalKey();
|
CheckLocalKey();
|
||||||
ConfigInit();
|
CheckForUpdates(std::string(GetVer()) + GetPatch());
|
||||||
CustomPort(argc, argv);
|
|
||||||
CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch());
|
|
||||||
}
|
}
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
void InitLauncher(int argc, char* argv[]) {
|
|
||||||
InitLog();
|
void InitLauncher() {
|
||||||
info("BeamMP Launcher v" + GetVer() + GetPatch());
|
info("BeamMP Launcher v" + GetVer() + GetPatch());
|
||||||
CheckName(argc, argv);
|
CheckName();
|
||||||
CheckLocalKey();
|
CheckLocalKey();
|
||||||
ConfigInit();
|
CheckForUpdates(std::string(GetVer()) + GetPatch());
|
||||||
CustomPort(argc, argv);
|
|
||||||
CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch());
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -316,7 +307,7 @@ void PreGame(const std::string& GamePath) {
|
|||||||
CheckMP(GetGamePath() + "mods/multiplayer");
|
CheckMP(GetGamePath() + "mods/multiplayer");
|
||||||
info("Game user path: " + GetGamePath());
|
info("Game user path: " + GetGamePath());
|
||||||
|
|
||||||
if (!Dev) {
|
if (!options.no_download) {
|
||||||
std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/mod?branch=" + Branch + "&pk=" + PublicKey);
|
std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/mod?branch=" + Branch + "&pk=" + PublicKey);
|
||||||
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
|
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
|
||||||
LatestHash.erase(std::remove_if(LatestHash.begin(), LatestHash.end(),
|
LatestHash.erase(std::remove_if(LatestHash.begin(), LatestHash.end(),
|
||||||
|
|||||||
30
src/main.cpp
30
src/main.cpp
@@ -13,6 +13,9 @@
|
|||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include "Options.h"
|
||||||
|
|
||||||
|
Options options;
|
||||||
|
|
||||||
[[noreturn]] void flush() {
|
[[noreturn]] void flush() {
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -21,7 +24,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) try {
|
int main(int argc, const char** argv) try {
|
||||||
|
#if defined(_WIN32)
|
||||||
|
system("cls");
|
||||||
|
#elif defined(__linux__)
|
||||||
|
system("clear");
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
std::thread th(flush);
|
std::thread th(flush);
|
||||||
th.detach();
|
th.detach();
|
||||||
@@ -29,23 +38,12 @@ int main(int argc, char** argv) try {
|
|||||||
|
|
||||||
curl_global_init(CURL_GLOBAL_ALL);
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
system("cls");
|
|
||||||
#elif defined(__linux__)
|
|
||||||
system("clear");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
GetEP(argv[0]);
|
GetEP(argv[0]);
|
||||||
|
|
||||||
for (int i = 0; i < argc; ++i) {
|
InitLog();
|
||||||
if (std::string_view(argv[i]) == "--skip-ssl-verify") {
|
ConfigInit();
|
||||||
info("SSL verification skip enabled");
|
InitOptions(argc, argv, options);
|
||||||
HTTP::SkipSslVerify = true;
|
InitLauncher();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
InitLauncher(argc, argv);
|
|
||||||
|
|
||||||
info("IMPORTANT: You MUST keep this window open to play BeamMP!");
|
info("IMPORTANT: You MUST keep this window open to play BeamMP!");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user