- new backend links

- self updating
- add open_url lua function with filter
This commit is contained in:
Anonymous-275
2023-07-12 21:30:05 +01:00
parent 58e9fef53f
commit a504114809
10 changed files with 4822 additions and 114 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ add_executable(${PROJECT_NAME}
src/Memory/IPC.cpp include/Memory/IPC.h src/Memory/IPC.cpp include/Memory/IPC.h
src/Logger.cpp include/Logger.h src/Logger.cpp include/Logger.h
#src/gui/Gui.cpp #src/gui/Gui.cpp
include/Json.h include/Json.h include/hashpp.h
src/Network/HttpAPI.cpp include/HttpAPI.h src/Network/HttpAPI.cpp include/HttpAPI.h
src/Network/Server.cpp include/Server.h src/Network/Server.cpp include/Server.h
src/Network/Login.cpp src/Network/Update.cpp src/Network/Login.cpp src/Network/Update.cpp
+5 -2
View File
@@ -33,10 +33,12 @@ class Launcher {
void SendIPC(const std::string& Data, bool core = true); void SendIPC(const std::string& Data, bool core = true);
void LoadConfig(const fs::path& conf); void LoadConfig(const fs::path& conf);
void RunDiscordRPC(); void RunDiscordRPC();
void UpdateCheck();
void WaitForGame(); void WaitForGame();
void LaunchGame(); void LaunchGame();
void CheckKey(); void CheckKey();
void SetupMOD(); void SetupMOD();
static std::string QueryValue(HKEY& hKey, const char* Name); static std::string QueryValue(HKEY& hKey, const char* Name);
public: // Getters and Setters public: // Getters and Setters
@@ -53,6 +55,7 @@ class Launcher {
private: // functions private: // functions
void HandleIPC(const std::string& Data); void HandleIPC(const std::string& Data);
bool IsAllowedLink(const std::string& Link);
std::string GetProfileVersion(); std::string GetProfileVersion();
fs::path GetProfileRoot(); fs::path GetProfileRoot();
void UpdatePresence(); void UpdatePresence();
@@ -65,8 +68,8 @@ class Launcher {
public: // variables public: // variables
static inline std::thread EntryThread{}; static inline std::thread EntryThread{};
static inline std::string Version{"2.0"}; static inline std::string Version{"2.1"};
static inline std::string FullVersion{Version + ".99"}; static inline std::string FullVersion{Version + ".0"};
private: // variables private: // variables
uint32_t GamePID{0}; uint32_t GamePID{0};
+4642
View File
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -48,7 +48,8 @@ void Launcher::LoadConfig(const fs::path& conf) { // check if json (issue)
auto GameProfile = GetProfileRoot(); auto GameProfile = GetProfileRoot();
std::ofstream tml(conf); std::ofstream tml(conf);
if (tml.is_open()) { if (tml.is_open()) {
tml << "Build = 'Default'\n" tml << "# Build is the lua build, it can be either default, canary, or public\n"
"Build = 'default'\n"
"CachePath = 'Resources'\n" "CachePath = 'Resources'\n"
"ProfilePath = '" "ProfilePath = '"
<< GameProfile.string() << "'"; << GameProfile.string() << "'";
+12
View File
@@ -8,6 +8,7 @@
#include "Logger.h" #include "Logger.h"
#include "Memory/BeamNG.h" #include "Memory/BeamNG.h"
#include "Memory/Memory.h" #include "Memory/Memory.h"
#include <regex>
void Launcher::HandleIPC(const std::string& Data) { //TODO Improve all cases since SendIPC can be called async void Launcher::HandleIPC(const std::string& Data) { //TODO Improve all cases since SendIPC can be called async
char Code = Data.at(0), SubCode = 0; char Code = Data.at(0), SubCode = 0;
@@ -56,11 +57,22 @@ void Launcher::HandleIPC(const std::string& Data) { //TODO Improve all cases si
SendIPC("N" + Login(Data.substr(Data.find(':') + 1))); SendIPC("N" + Login(Data.substr(Data.find(':') + 1)));
} }
break; break;
case 'O': //open default browser with URL
if(IsAllowedLink(Data.substr(1))) {
ShellExecuteA(nullptr, "open", Data.substr(1).c_str(), nullptr, nullptr,SW_SHOW); ///TODO: Look at when working on linux port
}
break;
default: default:
break; break;
} }
} }
bool Launcher::IsAllowedLink(const std::string& Link) {
std::regex link_pattern(R"(https:\/\/(?:\w+)?(?:\.)?(?:beammp|discord)\.com)");
std::smatch link_match;
return std::regex_search(Link,link_match, link_pattern) && link_match.position() == 0;
}
void Server::ServerParser(const std::string& Data) { void Server::ServerParser(const std::string& Data) {
if (Data.empty()) return; if (Data.empty()) return;
char Code = Data.at(0), SubCode = 0; char Code = Data.at(0), SubCode = 0;
+1 -1
View File
@@ -31,7 +31,7 @@ Launcher::Launcher(int argc, char* argv[]) :
DiscordTime = std::time(nullptr); DiscordTime = std::time(nullptr);
WindowsInit(); WindowsInit();
SetUnhandledExceptionFilter(CrashHandler); SetUnhandledExceptionFilter(CrashHandler);
LOG(INFO) << "Starting Launcher V" << FullVersion; LOG(INFO) << "Starting Launcher v" << FullVersion;
if (argc > 1) LoadConfig(fs::current_path() / argv[1]); if (argc > 1) LoadConfig(fs::current_path() / argv[1]);
else LoadConfig(fs::current_path() / "Launcher.toml"); else LoadConfig(fs::current_path() / "Launcher.toml");
} }
+11
View File
@@ -97,12 +97,23 @@ int LuaPop(lua_State* L) {
return 0; return 0;
} }
int LuaOpenURL(lua_State* L) {
if (lua_gettop(L) == 1) {
size_t Size;
const char* Data = GELua::lua_tolstring(L, 1, &Size);
std::string msg(Data, Size);
BeamNG::SendIPC("CO" + msg);
}
return 0;
}
void BeamNG::RegisterGEFunctions() { void BeamNG::RegisterGEFunctions() {
Memory::Print("Registering GE Functions"); Memory::Print("Registering GE Functions");
GELuaTable::Begin(GELua::State); GELuaTable::Begin(GELua::State);
GELuaTable::InsertFunction(GELua::State, "Core", Core); GELuaTable::InsertFunction(GELua::State, "Core", Core);
GELuaTable::InsertFunction(GELua::State, "Game", Game); GELuaTable::InsertFunction(GELua::State, "Game", Game);
GELuaTable::InsertFunction(GELua::State, "try_pop", LuaPop); GELuaTable::InsertFunction(GELua::State, "try_pop", LuaPop);
GELuaTable::InsertFunction(GELua::State, "open_url", LuaOpenURL);
GELuaTable::End(GELua::State, "MP"); GELuaTable::End(GELua::State, "MP");
Memory::Print("Registered!"); Memory::Print("Registered!");
} }
+5 -1
View File
@@ -63,8 +63,12 @@ std::string Launcher::Login(const std::string& fields) {
if (!d["public_key"].is_null()) { if (!d["public_key"].is_null()) {
PublicKey = d["public_key"].get<std::string>(); PublicKey = d["public_key"].get<std::string>();
} }
if (!d["role"].is_null()) {
UserRole = d["role"].get<std::string>();
}
LOG(INFO) << "Authentication successful!"; LOG(INFO) << "Authentication successful!";
} else LOG(WARNING) << "Authentication failed!"; } else
LOG(WARNING) << "Authentication failed!";
if (!d["message"].is_null()) { if (!d["message"].is_null()) {
d.erase("private_key"); d.erase("private_key");
+39 -5
View File
@@ -7,6 +7,7 @@
#include "Json.h" #include "Json.h"
#include "Launcher.h" #include "Launcher.h"
#include "Logger.h" #include "Logger.h"
#include "hashpp.h"
VersionParser::VersionParser(const std::string& from_string) { VersionParser::VersionParser(const std::string& from_string) {
std::string token; std::string token;
@@ -49,8 +50,11 @@ void Launcher::ResetMods() {
<< "mods/multiplayer will be cleared in 15 seconds, close to abort"; << "mods/multiplayer will be cleared in 15 seconds, close to abort";
std::this_thread::sleep_for(std::chrono::seconds(15)); std::this_thread::sleep_for(std::chrono::seconds(15));
} }
fs::remove_all(MPUserPath); for (auto &de: std::filesystem::directory_iterator(MPUserPath)) {
fs::create_directories(MPUserPath); if (de.path().filename() != "BeamMP.zip") {
std::filesystem::remove(de.path());
}
}
} }
void Launcher::EnableMP() { void Launcher::EnableMP() {
@@ -78,13 +82,43 @@ void Launcher::EnableMP() {
} }
} }
void Launcher::SetupMOD() { void Launcher::SetupMOD() {
std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/mod?branch=" + TargetBuild + "&pk=" + PublicKey);
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
std::string FileHash = hashpp::get::getFileHash(hashpp::ALGORITHMS::SHA2_256, (MPUserPath / "BeamMP.zip").string());
ResetMods(); ResetMods();
EnableMP(); EnableMP();
LOG(INFO) << "Downloading mod please wait";
if (FileHash != LatestHash) {
LOG(INFO) << "Downloading BeamMP Update " << LatestHash;
HTTP::Download( HTTP::Download(
"https://backend.beammp.com/builds/client?download=true" "https://backend.beammp.com/builds/mod?download=true"
"&pk=" + "&pk=" +
PublicKey + "&branch=" + TargetBuild, PublicKey + "&branch=" + TargetBuild,
(MPUserPath/"BeamMP.zip").string()); (MPUserPath / "BeamMP.zip").string());
}
}
void Launcher::UpdateCheck() {
std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/launcher?branch=" + TargetBuild + "&pk=" + PublicKey);
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
std::string FileHash = hashpp::get::getFileHash(hashpp::ALGORITHMS::SHA2_256, "BeamMP-Launcher.exe");
if(FileHash != LatestHash) {
LOG(INFO) << "Launcher update found!";
fs::remove("BeamMP-Launcher.back");
fs::rename("BeamMP-Launcher.exe", "BeamMP-Launcher.back");
LOG(INFO) << "Downloading Launcher update " << LatestHash;
HTTP::Download(
"https://backend.beammp.com/builds/launcher?download=true"
"&pk=" +
PublicKey + "&branch=" + TargetBuild,
"BeamMP-Launcher.exe");
throw ShutdownException("Launcher update");
}
} }
+2 -1
View File
@@ -9,9 +9,10 @@
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
try { try {
Launcher launcher(argc, argv); Launcher launcher(argc, argv);
launcher.UpdateCheck();
launcher.RunDiscordRPC(); launcher.RunDiscordRPC();
launcher.CheckKey(); launcher.CheckKey();
// launcher.SetupMOD(); launcher.SetupMOD();
launcher.LaunchGame(); launcher.LaunchGame();
launcher.WaitForGame(); launcher.WaitForGame();
LOG(INFO) << "Launcher shutting down"; LOG(INFO) << "Launcher shutting down";