mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-08-17 00:35:55 +00:00
reformat
This commit is contained in:
parent
3488136ca4
commit
a82b9fb36f
@ -6,14 +6,15 @@
|
|||||||
/// Created by Anonymous275 on 7/18/2020
|
/// Created by Anonymous275 on 7/18/2020
|
||||||
///
|
///
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include <string>
|
||||||
class HTTP {
|
class HTTP {
|
||||||
public:
|
public:
|
||||||
static bool Download(const std::string &IP, const std::string &Path);
|
static bool Download(const std::string& IP, const std::string& Path);
|
||||||
static std::string Post(const std::string& IP, const std::string& Fields);
|
static std::string Post(const std::string& IP, const std::string& Fields);
|
||||||
static std::string Get(const std::string &IP);
|
static std::string Get(const std::string& IP);
|
||||||
static bool ProgressBar(size_t c, size_t t);
|
static bool ProgressBar(size_t c, size_t t);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static bool isDownload;
|
static bool isDownload;
|
||||||
};
|
};
|
@ -6,8 +6,8 @@
|
|||||||
/// Created by Anonymous275 on 4/2/2020.
|
/// Created by Anonymous275 on 4/2/2020.
|
||||||
///
|
///
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
void InitLog();
|
void InitLog();
|
||||||
void except(const std::string& toPrint);
|
void except(const std::string& toPrint);
|
||||||
void fatal(const std::string& toPrint);
|
void fatal(const std::string& toPrint);
|
||||||
|
@ -6,19 +6,16 @@
|
|||||||
/// Created by Anonymous275 on 7/18/2020
|
/// Created by Anonymous275 on 7/18/2020
|
||||||
///
|
///
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#include <cstdint>
|
|
||||||
#include "linuxfixes.h"
|
#include "linuxfixes.h"
|
||||||
#include <bits/types/siginfo_t.h>
|
#include <bits/types/siginfo_t.h>
|
||||||
|
#include <cstdint>
|
||||||
#include <sys/ucontext.h>
|
#include <sys/ucontext.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void NetReset();
|
void NetReset();
|
||||||
extern bool Dev;
|
extern bool Dev;
|
||||||
extern int ping;
|
extern int ping;
|
||||||
@ -48,11 +45,10 @@ void GameSend(std::string Data);
|
|||||||
void SendLarge(std::string Data);
|
void SendLarge(std::string Data);
|
||||||
std::string TCPRcv(uint64_t Sock);
|
std::string TCPRcv(uint64_t Sock);
|
||||||
void SyncResources(uint64_t TCPSock);
|
void SyncResources(uint64_t TCPSock);
|
||||||
std::string GetAddr(const std::string&IP);
|
std::string GetAddr(const std::string& IP);
|
||||||
void ServerParser(const std::string& Data);
|
void ServerParser(const std::string& Data);
|
||||||
std::string Login(const std::string& fields);
|
std::string Login(const std::string& fields);
|
||||||
void TCPSend(const std::string&Data,uint64_t Sock);
|
void TCPSend(const std::string& Data, uint64_t Sock);
|
||||||
void TCPClientMain(const std::string& IP,int Port);
|
void TCPClientMain(const std::string& IP, int Port);
|
||||||
void UDPClientMain(const std::string& IP,int Port);
|
void UDPClientMain(const std::string& IP, int Port);
|
||||||
void TCPGameServer(const std::string& IP, int Port);
|
void TCPGameServer(const std::string& IP, int Port);
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
void PreGame(const std::string& GamePath);
|
void PreGame(const std::string& GamePath);
|
||||||
std::string CheckVer(const std::string &path);
|
std::string CheckVer(const std::string& path);
|
||||||
void InitGame(const std::string& Dir);
|
void InitGame(const std::string& Dir);
|
||||||
std::string GetGameDir();
|
std::string GetGameDir();
|
||||||
void LegitimacyCheck();
|
void LegitimacyCheck();
|
||||||
|
@ -6,12 +6,12 @@
|
|||||||
/// Created by Anonymous275 on 7/18/2020
|
/// Created by Anonymous275 on 7/18/2020
|
||||||
///
|
///
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
|
||||||
#include <compare>
|
#include <compare>
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
void InitLauncher(int argc, char* argv[]);
|
void InitLauncher(int argc, char* argv[]);
|
||||||
std::string GetEP(char*P = nullptr);
|
std::string GetEP(char* P = nullptr);
|
||||||
std::string GetGamePath();
|
std::string GetGamePath();
|
||||||
std::string GetVer();
|
std::string GetVer();
|
||||||
std::string GetEN();
|
std::string GetEN();
|
||||||
|
@ -13,45 +13,45 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define Biggest 30000
|
#define Biggest 30000
|
||||||
std::string Comp(std::string Data){
|
std::string Comp(std::string Data) {
|
||||||
char*C = new char[Biggest];
|
char* C = new char[Biggest];
|
||||||
memset(C, 0, Biggest);
|
memset(C, 0, Biggest);
|
||||||
z_stream defstream;
|
z_stream defstream;
|
||||||
defstream.zalloc = Z_NULL;
|
defstream.zalloc = Z_NULL;
|
||||||
defstream.zfree = Z_NULL;
|
defstream.zfree = Z_NULL;
|
||||||
defstream.opaque = Z_NULL;
|
defstream.opaque = Z_NULL;
|
||||||
defstream.avail_in = (uInt)Data.length();
|
defstream.avail_in = (uInt)Data.length();
|
||||||
defstream.next_in = (Bytef *)&Data[0];
|
defstream.next_in = (Bytef*)&Data[0];
|
||||||
defstream.avail_out = Biggest;
|
defstream.avail_out = Biggest;
|
||||||
defstream.next_out = reinterpret_cast<Bytef *>(C);
|
defstream.next_out = reinterpret_cast<Bytef*>(C);
|
||||||
deflateInit(&defstream, Z_BEST_COMPRESSION);
|
deflateInit(&defstream, Z_BEST_COMPRESSION);
|
||||||
deflate(&defstream, Z_SYNC_FLUSH);
|
deflate(&defstream, Z_SYNC_FLUSH);
|
||||||
deflate(&defstream, Z_FINISH);
|
deflate(&defstream, Z_FINISH);
|
||||||
deflateEnd(&defstream);
|
deflateEnd(&defstream);
|
||||||
int TO = defstream.total_out;
|
int TO = defstream.total_out;
|
||||||
std::string Ret(TO,0);
|
std::string Ret(TO, 0);
|
||||||
memcpy(&Ret[0],C,TO);
|
memcpy(&Ret[0], C, TO);
|
||||||
delete [] C;
|
delete[] C;
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
std::string DeComp(std::string Compressed){
|
std::string DeComp(std::string Compressed) {
|
||||||
char*C = new char[Biggest];
|
char* C = new char[Biggest];
|
||||||
memset(C, 0, Biggest);
|
memset(C, 0, Biggest);
|
||||||
z_stream infstream;
|
z_stream infstream;
|
||||||
infstream.zalloc = Z_NULL;
|
infstream.zalloc = Z_NULL;
|
||||||
infstream.zfree = Z_NULL;
|
infstream.zfree = Z_NULL;
|
||||||
infstream.opaque = Z_NULL;
|
infstream.opaque = Z_NULL;
|
||||||
infstream.avail_in = Biggest;
|
infstream.avail_in = Biggest;
|
||||||
infstream.next_in = (Bytef *)(&Compressed[0]);
|
infstream.next_in = (Bytef*)(&Compressed[0]);
|
||||||
infstream.avail_out = Biggest;
|
infstream.avail_out = Biggest;
|
||||||
infstream.next_out = (Bytef *)(C);
|
infstream.next_out = (Bytef*)(C);
|
||||||
inflateInit(&infstream);
|
inflateInit(&infstream);
|
||||||
inflate(&infstream, Z_SYNC_FLUSH);
|
inflate(&infstream, Z_SYNC_FLUSH);
|
||||||
inflate(&infstream, Z_FINISH);
|
inflate(&infstream, Z_FINISH);
|
||||||
inflateEnd(&infstream);
|
inflateEnd(&infstream);
|
||||||
int TO = infstream.total_out;
|
int TO = infstream.total_out;
|
||||||
std::string Ret(TO,0);
|
std::string Ret(TO, 0);
|
||||||
memcpy(&Ret[0],C,TO);
|
memcpy(&Ret[0], C, TO);
|
||||||
delete [] C;
|
delete[] C;
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
@ -2,57 +2,58 @@
|
|||||||
/// Created by Anonymous275 on 2/23/2021
|
/// Created by Anonymous275 on 2/23/2021
|
||||||
///
|
///
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include "Network/network.hpp"
|
|
||||||
#include <filesystem>
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <fstream>
|
#include "Network/network.hpp"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
std::string Branch;
|
std::string Branch;
|
||||||
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>();
|
DEFAULT_PORT = d["Port"].get<int>();
|
||||||
}
|
}
|
||||||
//Default -1
|
// Default -1
|
||||||
//Release 1
|
// Release 1
|
||||||
//EA 2
|
// EA 2
|
||||||
//Dev 3
|
// Dev 3
|
||||||
//Custom 3
|
// Custom 3
|
||||||
|
|
||||||
if(d["Build"].is_string()){
|
if (d["Build"].is_string()) {
|
||||||
Branch = d["Build"].get<std::string>();
|
Branch = d["Build"].get<std::string>();
|
||||||
for(char& c : Branch)c = char(tolower(c));
|
for (char& c : Branch)
|
||||||
|
c = char(tolower(c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigInit(){
|
void ConfigInit() {
|
||||||
if(fs::exists("Launcher.cfg")){
|
if (fs::exists("Launcher.cfg")) {
|
||||||
std::ifstream cfg("Launcher.cfg");
|
std::ifstream cfg("Launcher.cfg");
|
||||||
if(cfg.is_open()){
|
if (cfg.is_open()) {
|
||||||
auto Size = fs::file_size("Launcher.cfg");
|
auto Size = fs::file_size("Launcher.cfg");
|
||||||
std::string Buffer(Size, 0);
|
std::string Buffer(Size, 0);
|
||||||
cfg.read(&Buffer[0], Size);
|
cfg.read(&Buffer[0], Size);
|
||||||
cfg.close();
|
cfg.close();
|
||||||
nlohmann::json d = nlohmann::json::parse(Buffer, nullptr, false);
|
nlohmann::json d = nlohmann::json::parse(Buffer, nullptr, false);
|
||||||
if(d.is_discarded()){
|
if (d.is_discarded()) {
|
||||||
fatal("Config failed to parse make sure it's valid JSON!");
|
fatal("Config failed to parse make sure it's valid JSON!");
|
||||||
}
|
}
|
||||||
ParseConfig(d);
|
ParseConfig(d);
|
||||||
}else fatal("Failed to open Launcher.cfg!");
|
} else
|
||||||
}else{
|
fatal("Failed to open Launcher.cfg!");
|
||||||
|
} else {
|
||||||
std::ofstream cfg("Launcher.cfg");
|
std::ofstream cfg("Launcher.cfg");
|
||||||
if(cfg.is_open()){
|
if (cfg.is_open()) {
|
||||||
cfg <<
|
cfg <<
|
||||||
R"({
|
R"({
|
||||||
"Port": 4444,
|
"Port": 4444,
|
||||||
"Build": "Default"
|
"Build": "Default"
|
||||||
})";
|
})";
|
||||||
cfg.close();
|
cfg.close();
|
||||||
}else{
|
} else {
|
||||||
fatal("Failed to write config on disk!");
|
fatal("Failed to write config on disk!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,83 +6,83 @@
|
|||||||
/// Created by Anonymous275 on 7/19/2020
|
/// Created by Anonymous275 on 7/19/2020
|
||||||
///
|
///
|
||||||
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
#include "vdf_parser.hpp"
|
#include "vdf_parser.hpp"
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <spawn.h>
|
#include <spawn.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "Logger.h"
|
||||||
|
#include "Startup.h"
|
||||||
#include <Security/Init.h>
|
#include <Security/Init.h>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include "Startup.h"
|
|
||||||
#include "Logger.h"
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
unsigned long GamePID = 0;
|
unsigned long GamePID = 0;
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
std::string QueryKey(HKEY hKey,int ID);
|
std::string QueryKey(HKEY hKey, int ID);
|
||||||
std::string GetGamePath(){
|
std::string GetGamePath() {
|
||||||
static std::string Path;
|
static std::string Path;
|
||||||
if(!Path.empty())return Path;
|
if (!Path.empty())
|
||||||
|
return Path;
|
||||||
|
|
||||||
HKEY hKey;
|
HKEY hKey;
|
||||||
LPCTSTR sk = "Software\\BeamNG\\BeamNG.drive";
|
LPCTSTR sk = "Software\\BeamNG\\BeamNG.drive";
|
||||||
LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
|
LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
|
||||||
if (openRes != ERROR_SUCCESS){
|
if (openRes != ERROR_SUCCESS) {
|
||||||
fatal("Please launch the game at least once!");
|
fatal("Please launch the game at least once!");
|
||||||
}
|
}
|
||||||
Path = QueryKey(hKey,4);
|
Path = QueryKey(hKey, 4);
|
||||||
|
|
||||||
if(Path.empty()){
|
if (Path.empty()) {
|
||||||
sk = R"(SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)";
|
sk = R"(SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)";
|
||||||
openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
|
openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
|
||||||
if (openRes != ERROR_SUCCESS){
|
if (openRes != ERROR_SUCCESS) {
|
||||||
fatal("Cannot get Local Appdata directory!");
|
fatal("Cannot get Local Appdata directory!");
|
||||||
}
|
}
|
||||||
Path = QueryKey(hKey,5);
|
Path = QueryKey(hKey, 5);
|
||||||
Path += "\\BeamNG.drive\\";
|
Path += "\\BeamNG.drive\\";
|
||||||
}
|
}
|
||||||
std::string Ver = CheckVer(GetGameDir());
|
std::string Ver = CheckVer(GetGameDir());
|
||||||
Ver = Ver.substr(0,Ver.find('.',Ver.find('.')+1));
|
Ver = Ver.substr(0, Ver.find('.', Ver.find('.') + 1));
|
||||||
Path += Ver + "\\";
|
Path += Ver + "\\";
|
||||||
return Path;
|
return Path;
|
||||||
}
|
}
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
std::string GetGamePath(){
|
std::string GetGamePath() {
|
||||||
// Right now only steam is supported
|
// Right now only steam is supported
|
||||||
struct passwd *pw = getpwuid(getuid());
|
struct passwd* pw = getpwuid(getuid());
|
||||||
std::string homeDir = pw->pw_dir;
|
std::string homeDir = pw->pw_dir;
|
||||||
|
|
||||||
std::string Path = homeDir + "/.local/share/BeamNG.drive/";
|
std::string Path = homeDir + "/.local/share/BeamNG.drive/";
|
||||||
std::string Ver = CheckVer(GetGameDir());
|
std::string Ver = CheckVer(GetGameDir());
|
||||||
Ver = Ver.substr(0,Ver.find('.',Ver.find('.')+1));
|
Ver = Ver.substr(0, Ver.find('.', Ver.find('.') + 1));
|
||||||
Path += Ver + "/";
|
Path += Ver + "/";
|
||||||
return Path;
|
return Path;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
void StartGame(std::string Dir){
|
void StartGame(std::string Dir) {
|
||||||
BOOL bSuccess = FALSE;
|
BOOL bSuccess = FALSE;
|
||||||
PROCESS_INFORMATION pi;
|
PROCESS_INFORMATION pi;
|
||||||
STARTUPINFO si = {0};
|
STARTUPINFO si = { 0 };
|
||||||
si.cb = sizeof(si);
|
si.cb = sizeof(si);
|
||||||
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);
|
bSuccess = CreateProcessA(Dir.c_str(), nullptr, 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;
|
||||||
WaitForSingleObject(pi.hProcess, INFINITE);
|
WaitForSingleObject(pi.hProcess, INFINITE);
|
||||||
error("Game Closed! launcher closing soon");
|
error("Game Closed! launcher closing soon");
|
||||||
}else{
|
} else {
|
||||||
error("Failed to Launch the game! launcher closing soon");
|
error("Failed to Launch the game! launcher closing soon");
|
||||||
}
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||||
@ -92,26 +92,7 @@ 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};
|
char* argv[] = { filename.data(), NULL };
|
||||||
pid_t pid;
|
|
||||||
int result = posix_spawn(&pid, filename.c_str(), NULL, NULL, argv, environ);
|
|
||||||
|
|
||||||
if (result != 0) {
|
|
||||||
error("Failed to Launch the game! launcher closing soon");
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
waitpid(pid, &status, 0);
|
|
||||||
error("Game Closed! launcher closing soon");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
|
||||||
exit(2);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
void StartGame(std::string Dir) {
|
|
||||||
int status;
|
|
||||||
std::string filename = (Dir + "/BinLinux/BeamNG.drive.x64");
|
|
||||||
char *argv[] = {filename.data(), NULL};
|
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int result = posix_spawn(&pid, filename.c_str(), NULL, NULL, argv, environ);
|
int result = posix_spawn(&pid, filename.c_str(), NULL, NULL, argv, environ);
|
||||||
|
|
||||||
@ -128,8 +109,8 @@ void StartGame(std::string Dir) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void InitGame(const std::string& Dir){
|
void InitGame(const std::string& Dir) {
|
||||||
if(!Dev){
|
if (!Dev) {
|
||||||
std::thread Game(StartGame, Dir);
|
std::thread Game(StartGame, Dir);
|
||||||
Game.detach();
|
Game.detach();
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,11 @@
|
|||||||
/// Created by Anonymous275 on 7/17/2020
|
/// Created by Anonymous275 on 7/17/2020
|
||||||
///
|
///
|
||||||
|
|
||||||
#include "Startup.h"
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "Startup.h"
|
||||||
|
#include <chrono>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <chrono>
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
std::string getDate() {
|
std::string getDate() {
|
||||||
@ -24,24 +24,25 @@ std::string getDate() {
|
|||||||
std::string Min = (M > 9 ? std::to_string(M) : "0" + std::to_string(M));
|
std::string Min = (M > 9 ? std::to_string(M) : "0" + std::to_string(M));
|
||||||
std::string Hour = (H > 9 ? std::to_string(H) : "0" + std::to_string(H));
|
std::string Hour = (H > 9 ? std::to_string(H) : "0" + std::to_string(H));
|
||||||
date
|
date
|
||||||
<< "["
|
<< "["
|
||||||
<< local_tm.tm_mday << "/"
|
<< local_tm.tm_mday << "/"
|
||||||
<< local_tm.tm_mon + 1 << "/"
|
<< local_tm.tm_mon + 1 << "/"
|
||||||
<< local_tm.tm_year + 1900 << " "
|
<< local_tm.tm_year + 1900 << " "
|
||||||
<< Hour << ":"
|
<< Hour << ":"
|
||||||
<< Min << ":"
|
<< Min << ":"
|
||||||
<< Secs
|
<< Secs
|
||||||
<< "] ";
|
<< "] ";
|
||||||
return date.str();
|
return date.str();
|
||||||
}
|
}
|
||||||
void InitLog(){
|
void InitLog() {
|
||||||
std::ofstream LFS;
|
std::ofstream LFS;
|
||||||
LFS.open(GetEP() + "Launcher.log");
|
LFS.open(GetEP() + "Launcher.log");
|
||||||
if(!LFS.is_open()){
|
if (!LFS.is_open()) {
|
||||||
error("logger file init failed!");
|
error("logger file init failed!");
|
||||||
}else LFS.close();
|
} else
|
||||||
|
LFS.close();
|
||||||
}
|
}
|
||||||
void addToLog(const std::string& Line){
|
void addToLog(const std::string& Line) {
|
||||||
std::ofstream LFS;
|
std::ofstream LFS;
|
||||||
LFS.open(GetEP() + "Launcher.log", std::ios_base::app);
|
LFS.open(GetEP() + "Launcher.log", std::ios_base::app);
|
||||||
LFS << Line.c_str();
|
LFS << Line.c_str();
|
||||||
@ -53,12 +54,13 @@ void info(const std::string& toPrint) {
|
|||||||
addToLog(Print);
|
addToLog(Print);
|
||||||
}
|
}
|
||||||
void debug(const std::string& toPrint) {
|
void debug(const std::string& toPrint) {
|
||||||
if(!Dev)return;
|
if (!Dev)
|
||||||
|
return;
|
||||||
std::string Print = getDate() + "[DEBUG] " + toPrint + "\n";
|
std::string Print = getDate() + "[DEBUG] " + toPrint + "\n";
|
||||||
std::cout << Print;
|
std::cout << Print;
|
||||||
addToLog(Print);
|
addToLog(Print);
|
||||||
}
|
}
|
||||||
void warn(const std::string& toPrint){
|
void warn(const std::string& toPrint) {
|
||||||
std::string Print = getDate() + "[WARN] " + toPrint + "\n";
|
std::string Print = getDate() + "[WARN] " + toPrint + "\n";
|
||||||
std::cout << Print;
|
std::cout << Print;
|
||||||
addToLog(Print);
|
addToLog(Print);
|
||||||
|
@ -5,28 +5,28 @@
|
|||||||
///
|
///
|
||||||
/// Created by Anonymous275 on 7/20/2020
|
/// Created by Anonymous275 on 7/20/2020
|
||||||
///
|
///
|
||||||
|
#include "Http.h"
|
||||||
#include "Network/network.hpp"
|
#include "Network/network.hpp"
|
||||||
#include "Security/Init.h"
|
#include "Security/Init.h"
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include "Http.h"
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
|
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Startup.h"
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <nlohmann/json.hpp>
|
#include "Startup.h"
|
||||||
#include <charconv>
|
#include <charconv>
|
||||||
#include <thread>
|
#include <nlohmann/json.hpp>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
extern int TraceBack;
|
extern int TraceBack;
|
||||||
std::set<std::string>* ConfList = nullptr;
|
std::set<std::string>* ConfList = nullptr;
|
||||||
@ -41,11 +41,13 @@ std::string MStatus;
|
|||||||
bool ModLoaded;
|
bool ModLoaded;
|
||||||
int ping = -1;
|
int ping = -1;
|
||||||
|
|
||||||
void StartSync(const std::string &Data){
|
void StartSync(const std::string& Data) {
|
||||||
std::string IP = GetAddr(Data.substr(1,Data.find(':')-1));
|
std::string IP = GetAddr(Data.substr(1, Data.find(':') - 1));
|
||||||
if(IP.find('.') == -1){
|
if (IP.find('.') == -1) {
|
||||||
if(IP == "DNS")UlStatus ="UlConnection Failed! (DNS Lookup Failed)";
|
if (IP == "DNS")
|
||||||
else UlStatus = "UlConnection Failed! (WSA failed to start)";
|
UlStatus = "UlConnection Failed! (DNS Lookup Failed)";
|
||||||
|
else
|
||||||
|
UlStatus = "UlConnection Failed! (WSA failed to start)";
|
||||||
ListOfMods = "-";
|
ListOfMods = "-";
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
return;
|
return;
|
||||||
@ -56,7 +58,7 @@ void StartSync(const std::string &Data){
|
|||||||
Terminate = false;
|
Terminate = false;
|
||||||
ConfList->clear();
|
ConfList->clear();
|
||||||
ping = -1;
|
ping = -1;
|
||||||
std::thread GS(TCPGameServer,IP,std::stoi(Data.substr(Data.find(':')+1)));
|
std::thread GS(TCPGameServer, IP, std::stoi(Data.substr(Data.find(':') + 1)));
|
||||||
GS.detach();
|
GS.detach();
|
||||||
info("Connecting to server");
|
info("Connecting to server");
|
||||||
}
|
}
|
||||||
@ -64,138 +66,150 @@ void StartSync(const 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))");
|
std::regex link_pattern(R"(https:\/\/(?:\w+)?(?:\.)?(?:beammp\.com|discord\.gg))");
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parse(std::string Data,SOCKET CSocket){
|
void Parse(std::string Data, SOCKET CSocket) {
|
||||||
char Code = Data.at(0), SubCode = 0;
|
char Code = Data.at(0), SubCode = 0;
|
||||||
if(Data.length() > 1)SubCode = Data.at(1);
|
if (Data.length() > 1)
|
||||||
switch (Code){
|
SubCode = Data.at(1);
|
||||||
case 'A':
|
switch (Code) {
|
||||||
Data = Data.substr(0,1);
|
case 'A':
|
||||||
break;
|
Data = Data.substr(0, 1);
|
||||||
case 'B':
|
break;
|
||||||
|
case 'B':
|
||||||
|
NetReset();
|
||||||
|
Terminate = true;
|
||||||
|
TCPTerminate = true;
|
||||||
|
Data = Code + HTTP::Get("https://backend.beammp.com/servers-info");
|
||||||
|
break;
|
||||||
|
case 'C':
|
||||||
|
ListOfMods.clear();
|
||||||
|
StartSync(Data);
|
||||||
|
while (ListOfMods.empty() && !Terminate) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
|
}
|
||||||
|
if (ListOfMods == "-")
|
||||||
|
Data = "L";
|
||||||
|
else
|
||||||
|
Data = "L" + ListOfMods;
|
||||||
|
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
|
||||||
|
info("Opening Link \"" + Data.substr(1) + "\"");
|
||||||
|
}
|
||||||
|
Data.clear();
|
||||||
|
break;
|
||||||
|
case 'P':
|
||||||
|
Data = Code + std::to_string(ProxyPort);
|
||||||
|
break;
|
||||||
|
case 'U':
|
||||||
|
if (SubCode == 'l')
|
||||||
|
Data = UlStatus;
|
||||||
|
if (SubCode == 'p') {
|
||||||
|
if (ping > 800) {
|
||||||
|
Data = "Up-2";
|
||||||
|
} else
|
||||||
|
Data = "Up" + std::to_string(ping);
|
||||||
|
}
|
||||||
|
if (!SubCode) {
|
||||||
|
std::string Ping;
|
||||||
|
if (ping > 800)
|
||||||
|
Ping = "-2";
|
||||||
|
else
|
||||||
|
Ping = std::to_string(ping);
|
||||||
|
Data = std::string(UlStatus) + "\n" + "Up" + Ping;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'M':
|
||||||
|
Data = MStatus;
|
||||||
|
break;
|
||||||
|
case 'Q':
|
||||||
|
if (SubCode == 'S') {
|
||||||
NetReset();
|
NetReset();
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
TCPTerminate = true;
|
TCPTerminate = true;
|
||||||
Data = Code + HTTP::Get("https://backend.beammp.com/servers-info");
|
ping = -1;
|
||||||
break;
|
}
|
||||||
case 'C':
|
if (SubCode == 'G')
|
||||||
ListOfMods.clear();
|
exit(2);
|
||||||
StartSync(Data);
|
Data.clear();
|
||||||
while(ListOfMods.empty() && !Terminate){
|
break;
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
case 'R': // will send mod name
|
||||||
|
if (ConfList->find(Data) == ConfList->end()) {
|
||||||
|
ConfList->insert(Data);
|
||||||
|
ModLoaded = true;
|
||||||
|
}
|
||||||
|
Data.clear();
|
||||||
|
break;
|
||||||
|
case 'Z':
|
||||||
|
Data = "Z" + GetVer();
|
||||||
|
break;
|
||||||
|
case 'N':
|
||||||
|
if (SubCode == 'c') {
|
||||||
|
nlohmann::json Auth = {
|
||||||
|
{ "Auth", LoginAuth ? 1 : 0 },
|
||||||
|
};
|
||||||
|
if (!Username.empty()) {
|
||||||
|
Auth["username"] = Username;
|
||||||
}
|
}
|
||||||
if(ListOfMods == "-")Data = "L";
|
if (!UserRole.empty()) {
|
||||||
else Data = "L"+ListOfMods;
|
Auth["role"] = UserRole;
|
||||||
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
|
|
||||||
info("Opening Link \"" + Data.substr(1) + "\"");
|
|
||||||
}
|
}
|
||||||
Data.clear();
|
Data = Auth.dump();
|
||||||
break;
|
} else {
|
||||||
case 'P':
|
Data = "N" + Login(Data.substr(Data.find(':') + 1));
|
||||||
Data = Code + std::to_string(ProxyPort);
|
}
|
||||||
break;
|
break;
|
||||||
case 'U':
|
default:
|
||||||
if(SubCode == 'l')Data = UlStatus;
|
Data.clear();
|
||||||
if(SubCode == 'p'){
|
break;
|
||||||
if(ping > 800){
|
|
||||||
Data = "Up-2";
|
|
||||||
}else Data = "Up" + std::to_string(ping);
|
|
||||||
}
|
|
||||||
if(!SubCode){
|
|
||||||
std::string Ping;
|
|
||||||
if(ping > 800)Ping = "-2";
|
|
||||||
else Ping = std::to_string(ping);
|
|
||||||
Data = std::string(UlStatus) + "\n" + "Up" + Ping;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'M':
|
|
||||||
Data = MStatus;
|
|
||||||
break;
|
|
||||||
case 'Q':
|
|
||||||
if(SubCode == 'S'){
|
|
||||||
NetReset();
|
|
||||||
Terminate = true;
|
|
||||||
TCPTerminate = true;
|
|
||||||
ping = -1;
|
|
||||||
}
|
|
||||||
if(SubCode == 'G')exit(2);
|
|
||||||
Data.clear();
|
|
||||||
break;
|
|
||||||
case 'R': //will send mod name
|
|
||||||
if(ConfList->find(Data) == ConfList->end()){
|
|
||||||
ConfList->insert(Data);
|
|
||||||
ModLoaded = true;
|
|
||||||
}
|
|
||||||
Data.clear();
|
|
||||||
break;
|
|
||||||
case 'Z':
|
|
||||||
Data = "Z" + GetVer();
|
|
||||||
break;
|
|
||||||
case 'N':
|
|
||||||
if (SubCode == 'c'){
|
|
||||||
nlohmann::json Auth = {
|
|
||||||
{"Auth", LoginAuth ? 1 : 0 },
|
|
||||||
};
|
|
||||||
if (!Username.empty()) {
|
|
||||||
Auth["username"] = Username;
|
|
||||||
}
|
|
||||||
if (!UserRole.empty()) {
|
|
||||||
Auth["role"] = UserRole;
|
|
||||||
}
|
|
||||||
Data = Auth.dump();
|
|
||||||
}else{
|
|
||||||
Data = "N" + Login(Data.substr(Data.find(':') + 1));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Data.clear();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if(!Data.empty() && CSocket != -1){
|
if (!Data.empty() && CSocket != -1) {
|
||||||
int res = send(CSocket, (Data+"\n").c_str(), int(Data.size())+1, 0);
|
int res = send(CSocket, (Data + "\n").c_str(), int(Data.size()) + 1, 0);
|
||||||
if(res < 0){
|
if (res < 0) {
|
||||||
debug("(Core) send failed with error: " + std::to_string(WSAGetLastError()));
|
debug("(Core) send failed with error: " + std::to_string(WSAGetLastError()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void GameHandler(SOCKET Client){
|
void GameHandler(SOCKET Client) {
|
||||||
|
|
||||||
int32_t Size,Temp,Rcv;
|
int32_t Size, Temp, Rcv;
|
||||||
char Header[10] = {0};
|
char Header[10] = { 0 };
|
||||||
do{
|
do {
|
||||||
Rcv = 0;
|
Rcv = 0;
|
||||||
do{
|
do {
|
||||||
Temp = recv(Client,&Header[Rcv],1,0);
|
Temp = recv(Client, &Header[Rcv], 1, 0);
|
||||||
if(Temp < 1)break;
|
if (Temp < 1)
|
||||||
if(!isdigit(Header[Rcv]) && Header[Rcv] != '>') {
|
break;
|
||||||
|
if (!isdigit(Header[Rcv]) && Header[Rcv] != '>') {
|
||||||
error("(Core) Invalid lua communication");
|
error("(Core) Invalid lua communication");
|
||||||
KillSocket(Client);
|
KillSocket(Client);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}while(Header[Rcv++] != '>');
|
} while (Header[Rcv++] != '>');
|
||||||
if(Temp < 1)break;
|
if (Temp < 1)
|
||||||
if(std::from_chars(Header,&Header[Rcv],Size).ptr[0] != '>'){
|
break;
|
||||||
debug("(Core) Invalid lua Header -> " + std::string(Header,Rcv));
|
if (std::from_chars(Header, &Header[Rcv], Size).ptr[0] != '>') {
|
||||||
|
debug("(Core) Invalid lua Header -> " + std::string(Header, Rcv));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
std::string Ret(Size,0);
|
std::string Ret(Size, 0);
|
||||||
Rcv = 0;
|
Rcv = 0;
|
||||||
|
|
||||||
do{
|
do {
|
||||||
Temp = recv(Client,&Ret[Rcv],Size-Rcv,0);
|
Temp = recv(Client, &Ret[Rcv], Size - Rcv, 0);
|
||||||
if(Temp < 1)break;
|
if (Temp < 1)
|
||||||
|
break;
|
||||||
Rcv += Temp;
|
Rcv += Temp;
|
||||||
}while(Rcv < Size);
|
} while (Rcv < Size);
|
||||||
if(Temp < 1)break;
|
if (Temp < 1)
|
||||||
|
break;
|
||||||
|
|
||||||
std::thread Respond(Parse, Ret, Client);
|
std::thread Respond(Parse, Ret, Client);
|
||||||
Respond.detach();
|
Respond.detach();
|
||||||
}while(Temp > 0);
|
} while (Temp > 0);
|
||||||
if (Temp == 0) {
|
if (Temp == 0) {
|
||||||
debug("(Core) Connection closing");
|
debug("(Core) Connection closing");
|
||||||
} else {
|
} else {
|
||||||
@ -204,10 +218,10 @@ void GameHandler(SOCKET Client){
|
|||||||
NetReset();
|
NetReset();
|
||||||
KillSocket(Client);
|
KillSocket(Client);
|
||||||
}
|
}
|
||||||
void localRes(){
|
void localRes() {
|
||||||
MStatus = " ";
|
MStatus = " ";
|
||||||
UlStatus = "Ulstart";
|
UlStatus = "Ulstart";
|
||||||
if(ConfList != nullptr){
|
if (ConfList != nullptr) {
|
||||||
ConfList->clear();
|
ConfList->clear();
|
||||||
delete ConfList;
|
delete ConfList;
|
||||||
ConfList = nullptr;
|
ConfList = nullptr;
|
||||||
@ -216,15 +230,16 @@ void localRes(){
|
|||||||
}
|
}
|
||||||
void CoreMain() {
|
void CoreMain() {
|
||||||
debug("Core Network on start!");
|
debug("Core Network on start!");
|
||||||
SOCKET LSocket,CSocket;
|
SOCKET LSocket, CSocket;
|
||||||
struct addrinfo *res = nullptr;
|
struct addrinfo* res = nullptr;
|
||||||
struct addrinfo hints{};
|
struct addrinfo hints { };
|
||||||
int iRes;
|
int iRes;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
iRes = WSAStartup(514, &wsaData); //2.2
|
iRes = WSAStartup(514, &wsaData); // 2.2
|
||||||
if (iRes)debug("WSAStartup failed with error: " + std::to_string(iRes));
|
if (iRes)
|
||||||
#endif
|
debug("WSAStartup failed with error: " + std::to_string(iRes));
|
||||||
|
#endif
|
||||||
|
|
||||||
ZeroMemory(&hints, sizeof(hints));
|
ZeroMemory(&hints, sizeof(hints));
|
||||||
|
|
||||||
@ -233,13 +248,13 @@ void CoreMain() {
|
|||||||
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(nullptr, std::to_string(DEFAULT_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();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LSocket = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
LSocket = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
||||||
if (LSocket == -1){
|
if (LSocket == -1) {
|
||||||
debug("(Core) socket failed with error: " + std::to_string(WSAGetLastError()));
|
debug("(Core) socket failed with error: " + std::to_string(WSAGetLastError()));
|
||||||
freeaddrinfo(res);
|
freeaddrinfo(res);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
@ -261,7 +276,7 @@ void CoreMain() {
|
|||||||
WSACleanup();
|
WSACleanup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
do{
|
do {
|
||||||
CSocket = accept(LSocket, nullptr, nullptr);
|
CSocket = accept(LSocket, nullptr, nullptr);
|
||||||
if (CSocket == -1) {
|
if (CSocket == -1) {
|
||||||
error("(Core) accept failed with error: " + std::to_string(WSAGetLastError()));
|
error("(Core) accept failed with error: " + std::to_string(WSAGetLastError()));
|
||||||
@ -271,36 +286,37 @@ void CoreMain() {
|
|||||||
info("Game Connected!");
|
info("Game Connected!");
|
||||||
GameHandler(CSocket);
|
GameHandler(CSocket);
|
||||||
warn("Game Reconnecting...");
|
warn("Game Reconnecting...");
|
||||||
}while(CSocket);
|
} while (CSocket);
|
||||||
KillSocket(LSocket);
|
KillSocket(LSocket);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
int Handle(EXCEPTION_POINTERS *ep){
|
int Handle(EXCEPTION_POINTERS* ep) {
|
||||||
char* hex = new char[100];
|
char* hex = new char[100];
|
||||||
sprintf_s(hex,100, "%lX", ep->ExceptionRecord->ExceptionCode);
|
sprintf_s(hex, 100, "%lX", ep->ExceptionRecord->ExceptionCode);
|
||||||
except("(Core) Code : " + std::string(hex));
|
except("(Core) Code : " + std::string(hex));
|
||||||
delete [] hex;
|
delete[] hex;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
[[noreturn]] void CoreNetwork(){
|
[[noreturn]] void CoreNetwork() {
|
||||||
while(true) {
|
while (true) {
|
||||||
#if not defined(__MINGW32__)
|
#if not defined(__MINGW32__)
|
||||||
__try{
|
__try {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CoreMain();
|
CoreMain();
|
||||||
|
|
||||||
#if not defined(__MINGW32__) and not defined(__linux__)
|
#if not defined(__MINGW32__) and not defined(__linux__)
|
||||||
}__except(Handle(GetExceptionInformation())){}
|
} __except (Handle(GetExceptionInformation())) { }
|
||||||
#elif not defined(__MINGW32__) and defined(__linux__)
|
#elif not defined(__MINGW32__) and defined(__linux__)
|
||||||
} catch(...){
|
}
|
||||||
except("(Core) Code : " + std::string(strerror(errno)));
|
catch (...) {
|
||||||
}
|
except("(Core) Code : " + std::string(strerror(errno)));
|
||||||
#endif
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
}
|
}
|
||||||
|
@ -12,31 +12,32 @@
|
|||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
#include "linuxfixes.h"
|
#include "linuxfixes.h"
|
||||||
#include <netdb.h>
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <netdb.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
|
||||||
std::string GetAddr(const std::string&IP){
|
std::string GetAddr(const std::string& IP) {
|
||||||
if(IP.find_first_not_of("0123456789.") == -1)return IP;
|
if (IP.find_first_not_of("0123456789.") == -1)
|
||||||
hostent *host;
|
return IP;
|
||||||
#ifdef _WIN32
|
hostent* host;
|
||||||
|
#ifdef _WIN32
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
if(WSAStartup(514, &wsaData) != 0){
|
if (WSAStartup(514, &wsaData) != 0) {
|
||||||
error("WSA Startup Failed!");
|
error("WSA Startup Failed!");
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
host = gethostbyname(IP.c_str());
|
host = gethostbyname(IP.c_str());
|
||||||
if(!host){
|
if (!host) {
|
||||||
error("DNS lookup failed! on " + IP);
|
error("DNS lookup failed! on " + IP);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
return "DNS";
|
return "DNS";
|
||||||
}
|
}
|
||||||
std::string Ret = inet_ntoa(*((struct in_addr *)host->h_addr));
|
std::string Ret = inet_ntoa(*((struct in_addr*)host->h_addr));
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
@ -11,139 +11,149 @@
|
|||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
#include "linuxfixes.h"
|
#include "linuxfixes.h"
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <cstring>
|
||||||
|
#include <netdb.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <netdb.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <cstring>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <charconv>
|
#include <charconv>
|
||||||
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <mutex>
|
|
||||||
|
|
||||||
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;
|
||||||
bool CServer = true;
|
bool CServer = true;
|
||||||
SOCKET CSocket = -1;
|
SOCKET CSocket = -1;
|
||||||
SOCKET GSocket = -1;
|
SOCKET GSocket = -1;
|
||||||
|
|
||||||
int KillSocket(uint64_t Dead){
|
int KillSocket(uint64_t Dead) {
|
||||||
if(Dead == (SOCKET)-1){
|
if (Dead == (SOCKET)-1) {
|
||||||
debug("Kill socket got -1 returning...");
|
debug("Kill socket got -1 returning...");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
shutdown(Dead,SD_BOTH);
|
shutdown(Dead, SD_BOTH);
|
||||||
int a = closesocket(Dead);
|
int a = closesocket(Dead);
|
||||||
if(a != 0){
|
if (a != 0) {
|
||||||
warn("Failed to close socket!");
|
warn("Failed to close socket!");
|
||||||
}
|
}
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckBytes(uint32_t Bytes){
|
bool CheckBytes(uint32_t Bytes) {
|
||||||
if(Bytes == 0){
|
if (Bytes == 0) {
|
||||||
debug("(Proxy) Connection closing");
|
debug("(Proxy) Connection closing");
|
||||||
return false;
|
return false;
|
||||||
}else if(Bytes < 0){
|
} else if (Bytes < 0) {
|
||||||
debug("(Proxy) send failed with error: " + std::to_string(WSAGetLastError()));
|
debug("(Proxy) send failed with error: " + std::to_string(WSAGetLastError()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameSend(std::string Data){
|
void GameSend(std::string Data) {
|
||||||
static std::mutex Lock;
|
static std::mutex Lock;
|
||||||
std::scoped_lock Guard(Lock);
|
std::scoped_lock Guard(Lock);
|
||||||
if(TCPTerminate || !GConnected || CSocket == -1)return;
|
if (TCPTerminate || !GConnected || CSocket == -1)
|
||||||
int32_t Size,Temp,Sent;
|
return;
|
||||||
|
int32_t Size, Temp, Sent;
|
||||||
Data += '\n';
|
Data += '\n';
|
||||||
Size = int32_t(Data.size());
|
Size = int32_t(Data.size());
|
||||||
Sent = 0;
|
Sent = 0;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if(Size > 1000){
|
if (Size > 1000) {
|
||||||
debug("Launcher -> game (" +std::to_string(Size)+")");
|
debug("Launcher -> game (" + std::to_string(Size) + ")");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
do{
|
do {
|
||||||
if(Sent > -1){
|
if (Sent > -1) {
|
||||||
Temp = send(CSocket, &Data[Sent], Size - Sent, 0);
|
Temp = send(CSocket, &Data[Sent], Size - Sent, 0);
|
||||||
}
|
}
|
||||||
if(!CheckBytes(Temp))return;
|
if (!CheckBytes(Temp))
|
||||||
|
return;
|
||||||
Sent += Temp;
|
Sent += Temp;
|
||||||
}while(Sent < Size);
|
} while (Sent < Size);
|
||||||
}
|
}
|
||||||
void ServerSend(std::string Data, bool Rel){
|
void ServerSend(std::string Data, bool Rel) {
|
||||||
if(Terminate || Data.empty())return;
|
if (Terminate || Data.empty())
|
||||||
if(Data.find("Zp") != std::string::npos && Data.size() > 500){
|
return;
|
||||||
|
if (Data.find("Zp") != std::string::npos && Data.size() > 500) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
char C = 0;
|
char C = 0;
|
||||||
bool Ack = false;
|
bool Ack = false;
|
||||||
int DLen = int(Data.length());
|
int DLen = int(Data.length());
|
||||||
if(DLen > 3)C = Data.at(0);
|
if (DLen > 3)
|
||||||
if (C == 'O' || C == 'T')Ack = true;
|
C = Data.at(0);
|
||||||
if(C == 'N' || C == 'W' || C == 'Y' || C == 'V' || C == 'E' || C == 'C')Rel = true;
|
if (C == 'O' || C == 'T')
|
||||||
if(Ack || Rel){
|
Ack = true;
|
||||||
if(Ack || DLen > 1000)SendLarge(Data);
|
if (C == 'N' || C == 'W' || C == 'Y' || C == 'V' || C == 'E' || C == 'C')
|
||||||
else TCPSend(Data,TCPSock);
|
Rel = true;
|
||||||
}else UDPSend(Data);
|
if (Ack || Rel) {
|
||||||
|
if (Ack || DLen > 1000)
|
||||||
|
SendLarge(Data);
|
||||||
|
else
|
||||||
|
TCPSend(Data, TCPSock);
|
||||||
|
} else
|
||||||
|
UDPSend(Data);
|
||||||
|
|
||||||
if (DLen > 1000) {
|
if (DLen > 1000) {
|
||||||
debug("(Launcher->Server) Bytes sent: " + std::to_string(Data.length()) + " : "
|
debug("(Launcher->Server) Bytes sent: " + std::to_string(Data.length()) + " : "
|
||||||
+ Data.substr(0, 10)
|
+ Data.substr(0, 10)
|
||||||
+ Data.substr(Data.length() - 10));
|
+ Data.substr(Data.length() - 10));
|
||||||
}else if(C == 'Z'){
|
} else if (C == 'Z') {
|
||||||
//debug("(Game->Launcher) : " + Data);
|
// debug("(Game->Launcher) : " + Data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetReset(){
|
void NetReset() {
|
||||||
TCPTerminate = false;
|
TCPTerminate = false;
|
||||||
GConnected = false;
|
GConnected = false;
|
||||||
Terminate = false;
|
Terminate = false;
|
||||||
UlStatus = "Ulstart";
|
UlStatus = "Ulstart";
|
||||||
MStatus = " ";
|
MStatus = " ";
|
||||||
if(UDPSock != (SOCKET)(-1)){
|
if (UDPSock != (SOCKET)(-1)) {
|
||||||
debug("Terminating UDP Socket : " + std::to_string(TCPSock));
|
debug("Terminating UDP Socket : " + std::to_string(TCPSock));
|
||||||
KillSocket(UDPSock);
|
KillSocket(UDPSock);
|
||||||
}
|
}
|
||||||
UDPSock = -1;
|
UDPSock = -1;
|
||||||
if(TCPSock != (SOCKET)(-1)){
|
if (TCPSock != (SOCKET)(-1)) {
|
||||||
debug("Terminating TCP Socket : " + std::to_string(TCPSock));
|
debug("Terminating TCP Socket : " + std::to_string(TCPSock));
|
||||||
KillSocket(TCPSock);
|
KillSocket(TCPSock);
|
||||||
}
|
}
|
||||||
TCPSock = -1;
|
TCPSock = -1;
|
||||||
if(GSocket != (SOCKET)(-1)){
|
if (GSocket != (SOCKET)(-1)) {
|
||||||
debug("Terminating GTCP Socket : " + std::to_string(GSocket));
|
debug("Terminating GTCP Socket : " + std::to_string(GSocket));
|
||||||
KillSocket(GSocket);
|
KillSocket(GSocket);
|
||||||
}
|
}
|
||||||
GSocket = -1;
|
GSocket = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SOCKET SetupListener(){
|
SOCKET SetupListener() {
|
||||||
if(GSocket != -1)return GSocket;
|
if (GSocket != -1)
|
||||||
struct addrinfo *result = nullptr;
|
return GSocket;
|
||||||
struct addrinfo hints{};
|
struct addrinfo* result = nullptr;
|
||||||
|
struct addrinfo hints { };
|
||||||
int iRes;
|
int iRes;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
iRes = WSAStartup(514, &wsaData); //2.2
|
iRes = WSAStartup(514, &wsaData); // 2.2
|
||||||
if (iRes != 0) {
|
if (iRes != 0) {
|
||||||
error("(Proxy) WSAStartup failed with error: " + std::to_string(iRes));
|
error("(Proxy) WSAStartup failed with error: " + std::to_string(iRes));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ZeroMemory(&hints, sizeof(hints));
|
ZeroMemory(&hints, sizeof(hints));
|
||||||
hints.ai_family = AF_INET;
|
hints.ai_family = AF_INET;
|
||||||
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(DEFAULT_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();
|
||||||
@ -155,7 +165,7 @@ SOCKET SetupListener(){
|
|||||||
WSACleanup();
|
WSACleanup();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
iRes = bind(GSocket, result->ai_addr, (int) result->ai_addrlen);
|
iRes = bind(GSocket, result->ai_addr, (int)result->ai_addrlen);
|
||||||
if (iRes == SOCKET_ERROR) {
|
if (iRes == SOCKET_ERROR) {
|
||||||
error("(Proxy) bind failed with error: " + std::to_string(WSAGetLastError()));
|
error("(Proxy) bind failed with error: " + std::to_string(WSAGetLastError()));
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
@ -173,57 +183,61 @@ SOCKET SetupListener(){
|
|||||||
}
|
}
|
||||||
return GSocket;
|
return GSocket;
|
||||||
}
|
}
|
||||||
void AutoPing(){
|
void AutoPing() {
|
||||||
while(!Terminate){
|
while (!Terminate) {
|
||||||
ServerSend("p",false);
|
ServerSend("p", false);
|
||||||
PingStart = std::chrono::high_resolution_clock::now();
|
PingStart = std::chrono::high_resolution_clock::now();
|
||||||
std::this_thread::sleep_for(std::chrono::seconds (1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int ClientID = -1;
|
int ClientID = -1;
|
||||||
void ParserAsync(const std::string& Data){
|
void ParserAsync(const std::string& Data) {
|
||||||
if(Data.empty())return;
|
if (Data.empty())
|
||||||
char Code = Data.at(0),SubCode = 0;
|
return;
|
||||||
if(Data.length() > 1)SubCode = Data.at(1);
|
char Code = Data.at(0), SubCode = 0;
|
||||||
|
if (Data.length() > 1)
|
||||||
|
SubCode = Data.at(1);
|
||||||
switch (Code) {
|
switch (Code) {
|
||||||
case 'p':
|
case 'p':
|
||||||
PingEnd = std::chrono::high_resolution_clock::now();
|
PingEnd = std::chrono::high_resolution_clock::now();
|
||||||
if(PingStart > PingEnd)ping = 0;
|
if (PingStart > PingEnd)
|
||||||
else ping = int(std::chrono::duration_cast<std::chrono::milliseconds>(PingEnd-PingStart).count());
|
ping = 0;
|
||||||
return;
|
else
|
||||||
case 'M':
|
ping = int(std::chrono::duration_cast<std::chrono::milliseconds>(PingEnd - PingStart).count());
|
||||||
MStatus = Data;
|
return;
|
||||||
UlStatus = "Uldone";
|
case 'M':
|
||||||
return;
|
MStatus = Data;
|
||||||
default:
|
UlStatus = "Uldone";
|
||||||
break;
|
return;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
GameSend(Data);
|
GameSend(Data);
|
||||||
}
|
}
|
||||||
void ServerParser(const std::string& Data){
|
void ServerParser(const std::string& Data) {
|
||||||
ParserAsync(Data);
|
ParserAsync(Data);
|
||||||
}
|
}
|
||||||
void NetMain(const std::string& IP, int Port){
|
void NetMain(const std::string& IP, int Port) {
|
||||||
std::thread Ping(AutoPing);
|
std::thread Ping(AutoPing);
|
||||||
Ping.detach();
|
Ping.detach();
|
||||||
UDPClientMain(IP,Port);
|
UDPClientMain(IP, Port);
|
||||||
CServer = true;
|
CServer = true;
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
info("Connection Terminated!");
|
info("Connection Terminated!");
|
||||||
}
|
}
|
||||||
void TCPGameServer(const std::string& IP, int Port){
|
void TCPGameServer(const std::string& IP, int Port) {
|
||||||
GSocket = SetupListener();
|
GSocket = SetupListener();
|
||||||
while (!TCPTerminate && GSocket != -1){
|
while (!TCPTerminate && GSocket != -1) {
|
||||||
debug("MAIN LOOP OF GAME SERVER");
|
debug("MAIN LOOP OF GAME SERVER");
|
||||||
GConnected = false;
|
GConnected = false;
|
||||||
if(!CServer){
|
if (!CServer) {
|
||||||
warn("Connection still alive terminating");
|
warn("Connection still alive terminating");
|
||||||
NetReset();
|
NetReset();
|
||||||
TCPTerminate = true;
|
TCPTerminate = true;
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(CServer) {
|
if (CServer) {
|
||||||
std::thread Client(TCPClientMain, IP, Port);
|
std::thread Client(TCPClientMain, IP, Port);
|
||||||
Client.detach();
|
Client.detach();
|
||||||
}
|
}
|
||||||
@ -234,45 +248,52 @@ void TCPGameServer(const std::string& IP, int Port){
|
|||||||
}
|
}
|
||||||
debug("(Proxy) Game Connected!");
|
debug("(Proxy) Game Connected!");
|
||||||
GConnected = true;
|
GConnected = true;
|
||||||
if(CServer){
|
if (CServer) {
|
||||||
std::thread t1(NetMain, IP, Port);
|
std::thread t1(NetMain, IP, Port);
|
||||||
t1.detach();
|
t1.detach();
|
||||||
CServer = false;
|
CServer = false;
|
||||||
}
|
}
|
||||||
int32_t Size,Temp,Rcv;
|
int32_t Size, Temp, Rcv;
|
||||||
char Header[10] = {0};
|
char Header[10] = { 0 };
|
||||||
|
|
||||||
//Read byte by byte until '>' is rcved then get the size and read based on it
|
// Read byte by byte until '>' is rcved then get the size and read based on it
|
||||||
do{
|
do {
|
||||||
Rcv = 0;
|
Rcv = 0;
|
||||||
|
|
||||||
do{
|
do {
|
||||||
Temp = recv(CSocket,&Header[Rcv],1,0);
|
Temp = recv(CSocket, &Header[Rcv], 1, 0);
|
||||||
if(Temp < 1 || TCPTerminate)break;
|
if (Temp < 1 || TCPTerminate)
|
||||||
}while(Header[Rcv++] != '>');
|
break;
|
||||||
if(Temp < 1 || TCPTerminate)break;
|
} while (Header[Rcv++] != '>');
|
||||||
if(std::from_chars(Header,&Header[Rcv],Size).ptr[0] != '>'){
|
if (Temp < 1 || TCPTerminate)
|
||||||
debug("(Game) Invalid lua Header -> " + std::string(Header,Rcv));
|
break;
|
||||||
|
if (std::from_chars(Header, &Header[Rcv], Size).ptr[0] != '>') {
|
||||||
|
debug("(Game) Invalid lua Header -> " + std::string(Header, Rcv));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
std::string Ret(Size,0);
|
std::string Ret(Size, 0);
|
||||||
Rcv = 0;
|
Rcv = 0;
|
||||||
do{
|
do {
|
||||||
Temp = recv(CSocket,&Ret[Rcv],Size-Rcv,0);
|
Temp = recv(CSocket, &Ret[Rcv], Size - Rcv, 0);
|
||||||
if(Temp < 1)break;
|
if (Temp < 1)
|
||||||
|
break;
|
||||||
Rcv += Temp;
|
Rcv += Temp;
|
||||||
}while(Rcv < Size && !TCPTerminate);
|
} while (Rcv < Size && !TCPTerminate);
|
||||||
if(Temp < 1 || TCPTerminate)break;
|
if (Temp < 1 || TCPTerminate)
|
||||||
|
break;
|
||||||
|
|
||||||
ServerSend(Ret,false);
|
ServerSend(Ret, false);
|
||||||
|
|
||||||
}while(Temp > 0 && !TCPTerminate);
|
} while (Temp > 0 && !TCPTerminate);
|
||||||
if(Temp == 0)debug("(Proxy) Connection closing");
|
if (Temp == 0)
|
||||||
else debug("(Proxy) recv failed error : " + std::to_string(WSAGetLastError()));
|
debug("(Proxy) Connection closing");
|
||||||
|
else
|
||||||
|
debug("(Proxy) recv failed error : " + std::to_string(WSAGetLastError()));
|
||||||
}
|
}
|
||||||
TCPTerminate = true;
|
TCPTerminate = true;
|
||||||
GConnected = false;
|
GConnected = false;
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
if(CSocket != SOCKET_ERROR)KillSocket(CSocket);
|
if (CSocket != SOCKET_ERROR)
|
||||||
|
KillSocket(CSocket);
|
||||||
debug("END OF GAME SERVER");
|
debug("END OF GAME SERVER");
|
||||||
}
|
}
|
@ -7,175 +7,168 @@
|
|||||||
///
|
///
|
||||||
#define CPPHTTPLIB_OPENSSL_SUPPORT
|
#define CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <Logger.h>
|
|
||||||
#include <fstream>
|
|
||||||
#include "Http.h"
|
#include "Http.h"
|
||||||
#include <mutex>
|
#include <Logger.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
#include <httplib.h>
|
#include <httplib.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <mutex>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
void WriteHttpDebug(const httplib::Client& client, const std::string& method, const std::string& target, const httplib::Result& result) try {
|
void WriteHttpDebug(const httplib::Client& client, const std::string& method, const std::string& target, const httplib::Result& result) try {
|
||||||
const std::filesystem::path folder = ".https_debug";
|
const std::filesystem::path folder = ".https_debug";
|
||||||
std::filesystem::create_directories(folder);
|
std::filesystem::create_directories(folder);
|
||||||
if (!std::filesystem::exists(folder / "WHAT IS THIS FOLDER.txt")) {
|
if (!std::filesystem::exists(folder / "WHAT IS THIS FOLDER.txt")) {
|
||||||
std::ofstream ignore { folder / "WHAT IS THIS FOLDER.txt" };
|
std::ofstream ignore { folder / "WHAT IS THIS FOLDER.txt" };
|
||||||
ignore << "This folder exists to help debug current issues with the backend. Do not share this folder with anyone but BeamMP staff. It contains detailed logs of any failed http requests." << std::endl;
|
ignore << "This folder exists to help debug current issues with the backend. Do not share this folder with anyone but BeamMP staff. It contains detailed logs of any failed http requests." << std::endl;
|
||||||
}
|
}
|
||||||
const auto file = folder / (method + ".json");
|
const auto file = folder / (method + ".json");
|
||||||
// 1 MB limit
|
// 1 MB limit
|
||||||
if (std::filesystem::exists(file) && std::filesystem::file_size(file) > 1'000'000) {
|
if (std::filesystem::exists(file) && std::filesystem::file_size(file) > 1'000'000) {
|
||||||
std::filesystem::rename(file, file.generic_string() + ".bak");
|
std::filesystem::rename(file, file.generic_string() + ".bak");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ofstream of { file, std::ios::app };
|
std::ofstream of { file, std::ios::app };
|
||||||
nlohmann::json js {
|
nlohmann::json js {
|
||||||
{ "utc", std::chrono::system_clock::now().time_since_epoch().count() },
|
{ "utc", std::chrono::system_clock::now().time_since_epoch().count() },
|
||||||
{ "target", target },
|
{ "target", target },
|
||||||
{ "client_info", {
|
{ "client_info", {
|
||||||
{ "openssl_verify_result", client.get_openssl_verify_result() },
|
{ "openssl_verify_result", client.get_openssl_verify_result() },
|
||||||
{ "host", client.host()},
|
{ "host", client.host() },
|
||||||
{ "port", client.port()},
|
{ "port", client.port() },
|
||||||
{ "socket_open", client.is_socket_open()},
|
{ "socket_open", client.is_socket_open() },
|
||||||
{"valid", client.is_valid()},
|
{ "valid", client.is_valid() },
|
||||||
}
|
} },
|
||||||
},
|
};
|
||||||
};
|
if (result) {
|
||||||
if (result) {
|
auto value = result.value();
|
||||||
auto value = result.value();
|
js["result"] = {};
|
||||||
js["result"] = {};
|
js["result"]["body"] = value.body;
|
||||||
js["result"]["body"] = value.body;
|
js["result"]["status"] = value.status;
|
||||||
js["result"]["status"] = value.status;
|
js["result"]["headers"] = value.headers;
|
||||||
js["result"]["headers"] = value.headers;
|
js["result"]["version"] = value.version;
|
||||||
js["result"]["version"] = value.version;
|
js["result"]["location"] = value.location;
|
||||||
js["result"]["location"] = value.location;
|
js["result"]["reason"] = value.reason;
|
||||||
js["result"]["reason"] = value.reason;
|
}
|
||||||
}
|
of << js.dump();
|
||||||
of << js.dump();
|
} catch (const std::exception& e) {
|
||||||
}
|
error(e.what());
|
||||||
catch (const std::exception& e) {
|
|
||||||
error(e.what());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HTTP::isDownload = false;
|
bool HTTP::isDownload = false;
|
||||||
std::string HTTP::Get(const std::string& IP) {
|
std::string HTTP::Get(const std::string& IP) {
|
||||||
static std::mutex Lock;
|
static std::mutex Lock;
|
||||||
std::scoped_lock Guard(Lock);
|
std::scoped_lock Guard(Lock);
|
||||||
|
|
||||||
auto pos = IP.find('/', 10);
|
auto pos = IP.find('/', 10);
|
||||||
|
|
||||||
httplib::Client cli(IP.substr(0, pos).c_str());
|
httplib::Client cli(IP.substr(0, pos).c_str());
|
||||||
cli.set_connection_timeout(std::chrono::seconds(10));
|
cli.set_connection_timeout(std::chrono::seconds(10));
|
||||||
cli.set_follow_location(true);
|
cli.set_follow_location(true);
|
||||||
auto res = cli.Get(IP.substr(pos).c_str(), ProgressBar);
|
auto res = cli.Get(IP.substr(pos).c_str(), ProgressBar);
|
||||||
std::string Ret;
|
std::string Ret;
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
if (res->status == 200) {
|
if (res->status == 200) {
|
||||||
Ret = res->body;
|
Ret = res->body;
|
||||||
}
|
} else {
|
||||||
else {
|
WriteHttpDebug(cli, "GET", IP, res);
|
||||||
WriteHttpDebug(cli, "GET", IP, res);
|
error("Failed to GET '" + IP + "': " + res->reason + ", ssl verify = " + std::to_string(cli.get_openssl_verify_result()));
|
||||||
error("Failed to GET '" + IP + "': " + res->reason + ", ssl verify = " + std::to_string(cli.get_openssl_verify_result()));
|
}
|
||||||
|
} else {
|
||||||
|
if (isDownload) {
|
||||||
|
std::cout << "\n";
|
||||||
|
}
|
||||||
|
WriteHttpDebug(cli, "GET", IP, res);
|
||||||
|
error("HTTP Get failed on " + to_string(res.error()) + ", ssl verify = " + std::to_string(cli.get_openssl_verify_result()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
return Ret;
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (isDownload) {
|
|
||||||
std::cout << "\n";
|
|
||||||
}
|
|
||||||
WriteHttpDebug(cli, "GET", IP, res);
|
|
||||||
error("HTTP Get failed on " + to_string(res.error()) + ", ssl verify = " + std::to_string(cli.get_openssl_verify_result()));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
|
std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
|
||||||
static std::mutex Lock;
|
static std::mutex Lock;
|
||||||
std::scoped_lock Guard(Lock);
|
std::scoped_lock Guard(Lock);
|
||||||
|
|
||||||
auto pos = IP.find('/', 10);
|
auto pos = IP.find('/', 10);
|
||||||
|
|
||||||
httplib::Client cli(IP.substr(0, pos).c_str());
|
httplib::Client cli(IP.substr(0, pos).c_str());
|
||||||
cli.set_connection_timeout(std::chrono::seconds(10));
|
cli.set_connection_timeout(std::chrono::seconds(10));
|
||||||
std::string Ret;
|
std::string Ret;
|
||||||
|
|
||||||
if (!Fields.empty()) {
|
if (!Fields.empty()) {
|
||||||
httplib::Result res = cli.Post(IP.substr(pos).c_str(), Fields, "application/json");
|
httplib::Result res = cli.Post(IP.substr(pos).c_str(), Fields, "application/json");
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
if (res->status != 200) {
|
if (res->status != 200) {
|
||||||
error(res->reason);
|
error(res->reason);
|
||||||
}
|
}
|
||||||
Ret = res->body;
|
Ret = res->body;
|
||||||
}
|
} else {
|
||||||
else {
|
WriteHttpDebug(cli, "POST", IP, res);
|
||||||
WriteHttpDebug(cli, "POST", IP, res);
|
error("HTTP Post failed on " + to_string(res.error()) + ", ssl verify = " + std::to_string(cli.get_openssl_verify_result()));
|
||||||
error("HTTP Post failed on " + to_string(res.error()) + ", ssl verify = " + std::to_string(cli.get_openssl_verify_result()));
|
}
|
||||||
|
} else {
|
||||||
|
httplib::Result res = cli.Post(IP.substr(pos).c_str());
|
||||||
|
if (res) {
|
||||||
|
if (res->status != 200) {
|
||||||
|
error(res->reason);
|
||||||
|
}
|
||||||
|
Ret = res->body;
|
||||||
|
} else {
|
||||||
|
WriteHttpDebug(cli, "POST", IP, res);
|
||||||
|
error("HTTP Post failed on " + to_string(res.error()) + ", ssl verify = " + std::to_string(cli.get_openssl_verify_result()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
if (Ret.empty())
|
||||||
}
|
return "-1";
|
||||||
else {
|
else
|
||||||
httplib::Result res = cli.Post(IP.substr(pos).c_str());
|
return Ret;
|
||||||
if (res) {
|
|
||||||
if (res->status != 200) {
|
|
||||||
error(res->reason);
|
|
||||||
}
|
|
||||||
Ret = res->body;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
WriteHttpDebug(cli, "POST", IP, res);
|
|
||||||
error("HTTP Post failed on " + to_string(res.error()) + ", ssl verify = " + std::to_string(cli.get_openssl_verify_result()));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Ret.empty())return "-1";
|
|
||||||
else return Ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HTTP::ProgressBar(size_t c, size_t t) {
|
bool HTTP::ProgressBar(size_t c, size_t t) {
|
||||||
if (isDownload) {
|
if (isDownload) {
|
||||||
static double last_progress, progress_bar_adv;
|
static double last_progress, progress_bar_adv;
|
||||||
progress_bar_adv = round(c / double(t) * 25);
|
progress_bar_adv = round(c / double(t) * 25);
|
||||||
std::cout << "\r";
|
std::cout << "\r";
|
||||||
std::cout << "Progress : [ ";
|
std::cout << "Progress : [ ";
|
||||||
std::cout << round(c / double(t) * 100);
|
std::cout << round(c / double(t) * 100);
|
||||||
std::cout << "% ] [";
|
std::cout << "% ] [";
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i <= progress_bar_adv; i++)std::cout << "#";
|
for (i = 0; i <= progress_bar_adv; i++)
|
||||||
for (i = 0; i < 25 - progress_bar_adv; i++)std::cout << ".";
|
std::cout << "#";
|
||||||
std::cout << "]";
|
for (i = 0; i < 25 - progress_bar_adv; i++)
|
||||||
last_progress = round(c / double(t) * 100);
|
std::cout << ".";
|
||||||
}
|
std::cout << "]";
|
||||||
return true;
|
last_progress = round(c / double(t) * 100);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HTTP::Download(const std::string& IP, const std::string& Path) {
|
bool HTTP::Download(const std::string& IP, const std::string& Path) {
|
||||||
static std::mutex Lock;
|
static std::mutex Lock;
|
||||||
std::scoped_lock Guard(Lock);
|
std::scoped_lock Guard(Lock);
|
||||||
|
|
||||||
isDownload = true;
|
isDownload = true;
|
||||||
std::string Ret = Get(IP);
|
std::string Ret = Get(IP);
|
||||||
isDownload = false;
|
isDownload = false;
|
||||||
|
|
||||||
if (Ret.empty())return false;
|
if (Ret.empty())
|
||||||
|
return false;
|
||||||
|
|
||||||
std::ofstream File(Path, std::ios::binary);
|
std::ofstream File(Path, std::ios::binary);
|
||||||
if (File.is_open()) {
|
if (File.is_open()) {
|
||||||
File << Ret;
|
File << Ret;
|
||||||
File.close();
|
File.close();
|
||||||
std::cout << "\n";
|
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);
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -11,140 +11,146 @@
|
|||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
#include <sys/socket.h>
|
#include <arpa/inet.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <arpa/inet.h>
|
#include <sys/socket.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <filesystem>
|
|
||||||
#include "Startup.h"
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <iostream>
|
#include "Startup.h"
|
||||||
|
#include <atomic>
|
||||||
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <future>
|
||||||
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <atomic>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <future>
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
std::string ListOfMods;
|
std::string ListOfMods;
|
||||||
std::vector<std::string> Split(const std::string& String,const std::string& delimiter){
|
std::vector<std::string> Split(const std::string& String, const std::string& delimiter) {
|
||||||
std::vector<std::string> Val;
|
std::vector<std::string> Val;
|
||||||
size_t pos;
|
size_t pos;
|
||||||
std::string token,s = String;
|
std::string token, s = String;
|
||||||
while ((pos = s.find(delimiter)) != std::string::npos) {
|
while ((pos = s.find(delimiter)) != std::string::npos) {
|
||||||
token = s.substr(0, pos);
|
token = s.substr(0, pos);
|
||||||
if(!token.empty())Val.push_back(token);
|
if (!token.empty())
|
||||||
|
Val.push_back(token);
|
||||||
s.erase(0, pos + delimiter.length());
|
s.erase(0, pos + delimiter.length());
|
||||||
}
|
}
|
||||||
if(!s.empty())Val.push_back(s);
|
if (!s.empty())
|
||||||
|
Val.push_back(s);
|
||||||
return Val;
|
return Val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckForDir(){
|
void CheckForDir() {
|
||||||
if(!fs::exists("Resources")){
|
if (!fs::exists("Resources")) {
|
||||||
// Could we just use fs::create_directory instead?
|
// Could we just use fs::create_directory instead?
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
_wmkdir(L"Resources");
|
_wmkdir(L"Resources");
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
fs::create_directory(L"Resources");
|
fs::create_directory(L"Resources");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void WaitForConfirm(){
|
void WaitForConfirm() {
|
||||||
while(!Terminate && !ModLoaded){
|
while (!Terminate && !ModLoaded) {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
}
|
}
|
||||||
ModLoaded = false;
|
ModLoaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Abord() {
|
||||||
void Abord(){
|
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
TCPTerminate = true;
|
TCPTerminate = true;
|
||||||
info("Terminated!");
|
info("Terminated!");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Auth(SOCKET Sock){
|
std::string Auth(SOCKET Sock) {
|
||||||
TCPSend("VC" + GetVer(),Sock);
|
TCPSend("VC" + GetVer(), Sock);
|
||||||
|
|
||||||
auto Res = TCPRcv(Sock);
|
auto Res = TCPRcv(Sock);
|
||||||
|
|
||||||
if(Res.empty() || Res[0] == 'E' || Res[0] == 'K'){
|
if (Res.empty() || Res[0] == 'E' || Res[0] == 'K') {
|
||||||
Abord();
|
Abord();
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
TCPSend(PublicKey,Sock);
|
TCPSend(PublicKey, Sock);
|
||||||
if(Terminate)return "";
|
if (Terminate)
|
||||||
|
return "";
|
||||||
|
|
||||||
Res = TCPRcv(Sock);
|
Res = TCPRcv(Sock);
|
||||||
if(Res.empty() || Res[0] != 'P'){
|
if (Res.empty() || Res[0] != 'P') {
|
||||||
Abord();
|
Abord();
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
Res = Res.substr(1);
|
Res = Res.substr(1);
|
||||||
if(Res.find_first_not_of("0123456789") == std::string::npos){
|
if (Res.find_first_not_of("0123456789") == std::string::npos) {
|
||||||
ClientID = std::stoi(Res);
|
ClientID = std::stoi(Res);
|
||||||
}else{
|
} else {
|
||||||
Abord();
|
Abord();
|
||||||
UUl("Authentication failed!");
|
UUl("Authentication failed!");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
TCPSend("SR",Sock);
|
TCPSend("SR", Sock);
|
||||||
if(Terminate)return "";
|
if (Terminate)
|
||||||
|
return "";
|
||||||
|
|
||||||
Res = TCPRcv(Sock);
|
Res = TCPRcv(Sock);
|
||||||
|
|
||||||
if(Res[0] == 'E' || Res[0] == 'K'){
|
if (Res[0] == 'E' || Res[0] == 'K') {
|
||||||
Abord();
|
Abord();
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Res.empty() || Res == "-"){
|
if (Res.empty() || Res == "-") {
|
||||||
info("Didn't Receive any mods...");
|
info("Didn't Receive any mods...");
|
||||||
ListOfMods = "-";
|
ListOfMods = "-";
|
||||||
TCPSend("Done",Sock);
|
TCPSend("Done", Sock);
|
||||||
info("Done!");
|
info("Done!");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return Res;
|
return Res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateUl(bool D,const std::string& msg){
|
void UpdateUl(bool D, const std::string& msg) {
|
||||||
if(D)UlStatus = "UlDownloading Resource " + msg;
|
if (D)
|
||||||
else UlStatus = "UlLoading Resource " + msg;
|
UlStatus = "UlDownloading Resource " + msg;
|
||||||
|
else
|
||||||
|
UlStatus = "UlLoading Resource " + msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsyncUpdate(uint64_t& Rcv,uint64_t Size,const std::string& Name){
|
void AsyncUpdate(uint64_t& Rcv, uint64_t Size, const std::string& Name) {
|
||||||
do {
|
do {
|
||||||
double pr = double(Rcv) / double(Size) * 100;
|
double pr = double(Rcv) / double(Size) * 100;
|
||||||
std::string Per = std::to_string(trunc(pr * 10) / 10);
|
std::string Per = std::to_string(trunc(pr * 10) / 10);
|
||||||
UpdateUl(true, Name + " (" + Per.substr(0, Per.find('.') + 2) + "%)");
|
UpdateUl(true, Name + " (" + Per.substr(0, Per.find('.') + 2) + "%)");
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
}while(!Terminate && Rcv < Size);
|
} while (!Terminate && Rcv < Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* TCPRcvRaw(SOCKET Sock,uint64_t& GRcv, uint64_t Size){
|
char* TCPRcvRaw(SOCKET Sock, uint64_t& GRcv, uint64_t Size) {
|
||||||
if(Sock == -1){
|
if (Sock == -1) {
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
UUl("Invalid Socket");
|
UUl("Invalid Socket");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
char* File = new char[Size];
|
char* File = new char[Size];
|
||||||
uint64_t Rcv = 0;
|
uint64_t Rcv = 0;
|
||||||
do{
|
do {
|
||||||
int Len = int(Size-Rcv);
|
int Len = int(Size - Rcv);
|
||||||
if(Len > 1000000)Len = 1000000;
|
if (Len > 1000000)
|
||||||
|
Len = 1000000;
|
||||||
int32_t Temp = recv(Sock, &File[Rcv], Len, MSG_WAITALL);
|
int32_t Temp = recv(Sock, &File[Rcv], Len, MSG_WAITALL);
|
||||||
if(Temp < 1){
|
if (Temp < 1) {
|
||||||
info(std::to_string(Temp));
|
info(std::to_string(Temp));
|
||||||
UUl("Socket Closed Code 1");
|
UUl("Socket Closed Code 1");
|
||||||
KillSocket(Sock);
|
KillSocket(Sock);
|
||||||
@ -154,18 +160,18 @@ char* TCPRcvRaw(SOCKET Sock,uint64_t& GRcv, uint64_t Size){
|
|||||||
}
|
}
|
||||||
Rcv += Temp;
|
Rcv += Temp;
|
||||||
GRcv += Temp;
|
GRcv += Temp;
|
||||||
}while(Rcv < Size && !Terminate);
|
} while (Rcv < Size && !Terminate);
|
||||||
return File;
|
return File;
|
||||||
}
|
}
|
||||||
void MultiKill(SOCKET Sock,SOCKET Sock1){
|
void MultiKill(SOCKET Sock, SOCKET Sock1) {
|
||||||
KillSocket(Sock1);
|
KillSocket(Sock1);
|
||||||
KillSocket(Sock);
|
KillSocket(Sock);
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
}
|
}
|
||||||
SOCKET InitDSock(){
|
SOCKET InitDSock() {
|
||||||
SOCKET DSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
SOCKET DSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
SOCKADDR_IN ServerAddr;
|
SOCKADDR_IN ServerAddr;
|
||||||
if(DSock < 1){
|
if (DSock < 1) {
|
||||||
KillSocket(DSock);
|
KillSocket(DSock);
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
return 0;
|
return 0;
|
||||||
@ -173,13 +179,13 @@ SOCKET InitDSock(){
|
|||||||
ServerAddr.sin_family = AF_INET;
|
ServerAddr.sin_family = AF_INET;
|
||||||
ServerAddr.sin_port = htons(LastPort);
|
ServerAddr.sin_port = htons(LastPort);
|
||||||
inet_pton(AF_INET, LastIP.c_str(), &ServerAddr.sin_addr);
|
inet_pton(AF_INET, LastIP.c_str(), &ServerAddr.sin_addr);
|
||||||
if(connect(DSock, (SOCKADDR *) &ServerAddr, sizeof(ServerAddr)) != 0){
|
if (connect(DSock, (SOCKADDR*)&ServerAddr, sizeof(ServerAddr)) != 0) {
|
||||||
KillSocket(DSock);
|
KillSocket(DSock);
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
char Code[2] = {'D',char(ClientID)};
|
char Code[2] = { 'D', char(ClientID) };
|
||||||
if(send(DSock,Code,2,0) != 2){
|
if (send(DSock, Code, 2, 0) != 2) {
|
||||||
KillSocket(DSock);
|
KillSocket(DSock);
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
return 0;
|
return 0;
|
||||||
@ -187,55 +193,56 @@ SOCKET InitDSock(){
|
|||||||
return DSock;
|
return DSock;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MultiDownload(SOCKET MSock,SOCKET DSock, uint64_t Size, const std::string& Name){
|
std::string MultiDownload(SOCKET MSock, SOCKET DSock, uint64_t Size, const std::string& Name) {
|
||||||
|
|
||||||
uint64_t GRcv = 0, MSize = Size/2, DSize = Size - MSize;
|
uint64_t GRcv = 0, MSize = Size / 2, DSize = Size - MSize;
|
||||||
|
|
||||||
std::thread Au(AsyncUpdate,std::ref(GRcv), Size, Name);
|
std::thread Au(AsyncUpdate, std::ref(GRcv), Size, Name);
|
||||||
|
|
||||||
std::packaged_task<char*()> task([&] { return TCPRcvRaw(MSock,GRcv,MSize); });
|
std::packaged_task<char*()> task([&] { return TCPRcvRaw(MSock, GRcv, MSize); });
|
||||||
std::future<char*> f1 = task.get_future();
|
std::future<char*> f1 = task.get_future();
|
||||||
std::thread Dt(std::move(task));
|
std::thread Dt(std::move(task));
|
||||||
Dt.detach();
|
Dt.detach();
|
||||||
|
|
||||||
char* DData = TCPRcvRaw(DSock,GRcv,DSize);
|
char* DData = TCPRcvRaw(DSock, GRcv, DSize);
|
||||||
|
|
||||||
if(!DData){
|
if (!DData) {
|
||||||
MultiKill(MSock,DSock);
|
MultiKill(MSock, DSock);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
f1.wait();
|
f1.wait();
|
||||||
char* MData = f1.get();
|
char* MData = f1.get();
|
||||||
|
|
||||||
if(!MData){
|
if (!MData) {
|
||||||
MultiKill(MSock,DSock);
|
MultiKill(MSock, DSock);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Au.joinable())Au.join();
|
if (Au.joinable())
|
||||||
|
Au.join();
|
||||||
|
|
||||||
|
/// omg yes very ugly my god but i was in a rush will revisit
|
||||||
|
std::string Ret(Size, 0);
|
||||||
|
memcpy(&Ret[0], MData, MSize);
|
||||||
|
delete[] MData;
|
||||||
|
|
||||||
///omg yes very ugly my god but i was in a rush will revisit
|
memcpy(&Ret[MSize], DData, DSize);
|
||||||
std::string Ret(Size,0);
|
delete[] DData;
|
||||||
memcpy(&Ret[0],MData,MSize);
|
|
||||||
delete[]MData;
|
|
||||||
|
|
||||||
memcpy(&Ret[MSize],DData,DSize);
|
|
||||||
delete[]DData;
|
|
||||||
|
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InvalidResource(const std::string& File){
|
void InvalidResource(const std::string& File) {
|
||||||
UUl("Invalid mod \"" + File + "\"");
|
UUl("Invalid mod \"" + File + "\"");
|
||||||
warn("The server tried to sync \"" + File + "\" that is not a .zip file!");
|
warn("The server tried to sync \"" + File + "\" that is not a .zip file!");
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SyncResources(SOCKET Sock){
|
void SyncResources(SOCKET Sock) {
|
||||||
std::string Ret = Auth(Sock);
|
std::string Ret = Auth(Sock);
|
||||||
if(Ret.empty())return;
|
if (Ret.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
info("Checking Resources...");
|
info("Checking Resources...");
|
||||||
CheckForDir();
|
CheckForDir();
|
||||||
@ -246,59 +253,59 @@ void SyncResources(SOCKET Sock){
|
|||||||
list.clear();
|
list.clear();
|
||||||
Ret.clear();
|
Ret.clear();
|
||||||
|
|
||||||
int Amount = 0,Pos = 0;
|
int Amount = 0, Pos = 0;
|
||||||
std::string a,t;
|
std::string a, t;
|
||||||
for(const std::string&name : FNames){
|
for (const std::string& name : FNames) {
|
||||||
if(!name.empty()){
|
if (!name.empty()) {
|
||||||
t += name.substr(name.find_last_of('/') + 1) + ";";
|
t += name.substr(name.find_last_of('/') + 1) + ";";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(t.empty())ListOfMods = "-";
|
if (t.empty())
|
||||||
else ListOfMods = t;
|
ListOfMods = "-";
|
||||||
|
else
|
||||||
|
ListOfMods = t;
|
||||||
t.clear();
|
t.clear();
|
||||||
for(auto FN = FNames.begin(),FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN,++FS) {
|
for (auto FN = FNames.begin(), FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN, ++FS) {
|
||||||
auto pos = FN->find_last_of('/');
|
auto pos = FN->find_last_of('/');
|
||||||
auto ZIP = FN->find(".zip");
|
auto ZIP = FN->find(".zip");
|
||||||
if (ZIP == std::string::npos || FN->length() - ZIP != 4) {
|
if (ZIP == std::string::npos || FN->length() - ZIP != 4) {
|
||||||
InvalidResource(*FN);
|
InvalidResource(*FN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (pos == std::string::npos)continue;
|
if (pos == std::string::npos)
|
||||||
|
continue;
|
||||||
Amount++;
|
Amount++;
|
||||||
}
|
}
|
||||||
if(!FNames.empty())info("Syncing...");
|
if (!FNames.empty())
|
||||||
|
info("Syncing...");
|
||||||
SOCKET DSock = InitDSock();
|
SOCKET DSock = InitDSock();
|
||||||
for(auto FN = FNames.begin(),FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN,++FS) {
|
for (auto FN = FNames.begin(), FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN, ++FS) {
|
||||||
auto pos = FN->find_last_of('/');
|
auto pos = FN->find_last_of('/');
|
||||||
if (pos != std::string::npos) {
|
if (pos != std::string::npos) {
|
||||||
a = "Resources" + FN->substr(pos);
|
a = "Resources" + FN->substr(pos);
|
||||||
} else continue;
|
} else
|
||||||
|
continue;
|
||||||
Pos++;
|
Pos++;
|
||||||
if (fs::exists(a)) {
|
if (fs::exists(a)) {
|
||||||
if (FS->find_first_not_of("0123456789") != std::string::npos)continue;
|
if (FS->find_first_not_of("0123456789") != std::string::npos)
|
||||||
if (fs::file_size(a) == std::stoull(*FS)){
|
continue;
|
||||||
UpdateUl(false,std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + a.substr(a.find_last_of('/')));
|
if (fs::file_size(a) == std::stoull(*FS)) {
|
||||||
|
UpdateUl(false, std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + a.substr(a.find_last_of('/')));
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||||
try {
|
try {
|
||||||
if(!fs::exists(GetGamePath() + "mods/multiplayer")){
|
if (!fs::exists(GetGamePath() + "mods/multiplayer")) {
|
||||||
fs::create_directories(GetGamePath() + "mods/multiplayer");
|
fs::create_directories(GetGamePath() + "mods/multiplayer");
|
||||||
}
|
}
|
||||||
auto name = GetGamePath() + "mods/multiplayer" + a.substr(a.find_last_of('/'));
|
auto name = GetGamePath() + "mods/multiplayer" + a.substr(a.find_last_of('/'));
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
// Linux version of the game doesnt support uppercase letters in mod names
|
// Linux version of the game doesnt support uppercase letters in mod names
|
||||||
for(char &c : name){
|
for (char& c : name) {
|
||||||
c = ::tolower(c);
|
c = ::tolower(c);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
auto tmp_name = name + ".tmp";
|
auto tmp_name = name + ".tmp";
|
||||||
fs::copy_file(a,tmp_name,fs::copy_options::overwrite_existing);
|
fs::copy_file(a, tmp_name, fs::copy_options::overwrite_existing);
|
||||||
fs::rename(tmp_name, name);
|
fs::rename(tmp_name, name);
|
||||||
for(char &c : FName){
|
|
||||||
c = ::tolower(c);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
fs::copy_file(a, GetGamePath() + "mods/multiplayer" + FName,
|
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
error("Failed copy to the mods folder! " + std::string(e.what()));
|
error("Failed copy to the mods folder! " + std::string(e.what()));
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
@ -306,15 +313,16 @@ void SyncResources(SOCKET Sock){
|
|||||||
}
|
}
|
||||||
WaitForConfirm();
|
WaitForConfirm();
|
||||||
continue;
|
continue;
|
||||||
}else remove(a.c_str());
|
} else
|
||||||
|
remove(a.c_str());
|
||||||
}
|
}
|
||||||
CheckForDir();
|
CheckForDir();
|
||||||
std::string FName = a.substr(a.find_last_of('/'));
|
std::string FName = a.substr(a.find_last_of('/'));
|
||||||
do {
|
do {
|
||||||
TCPSend("f" + *FN,Sock);
|
TCPSend("f" + *FN, Sock);
|
||||||
|
|
||||||
std::string Data = TCPRcv(Sock);
|
std::string Data = TCPRcv(Sock);
|
||||||
if (Data == "CO" || Terminate){
|
if (Data == "CO" || Terminate) {
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
UUl("Server cannot find " + FName);
|
UUl("Server cannot find " + FName);
|
||||||
break;
|
break;
|
||||||
@ -322,10 +330,11 @@ void SyncResources(SOCKET Sock){
|
|||||||
|
|
||||||
std::string Name = std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + FName;
|
std::string Name = std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + FName;
|
||||||
|
|
||||||
Data = MultiDownload(Sock,DSock,std::stoull(*FS), Name);
|
Data = MultiDownload(Sock, DSock, std::stoull(*FS), Name);
|
||||||
|
|
||||||
if(Terminate)break;
|
if (Terminate)
|
||||||
UpdateUl(false,std::to_string(Pos)+"/"+std::to_string(Amount)+": "+FName);
|
break;
|
||||||
|
UpdateUl(false, std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + FName);
|
||||||
std::ofstream LFS;
|
std::ofstream LFS;
|
||||||
LFS.open(a.c_str(), std::ios_base::app | std::ios::binary);
|
LFS.open(a.c_str(), std::ios_base::app | std::ios::binary);
|
||||||
if (LFS.is_open()) {
|
if (LFS.is_open()) {
|
||||||
@ -333,28 +342,28 @@ void SyncResources(SOCKET Sock){
|
|||||||
LFS.close();
|
LFS.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}while(fs::file_size(a) != std::stoull(*FS) && !Terminate);
|
} while (fs::file_size(a) != std::stoull(*FS) && !Terminate);
|
||||||
if(!Terminate){
|
if (!Terminate) {
|
||||||
if(!fs::exists(GetGamePath() + "mods/multiplayer")){
|
if (!fs::exists(GetGamePath() + "mods/multiplayer")) {
|
||||||
fs::create_directories(GetGamePath() + "mods/multiplayer");
|
fs::create_directories(GetGamePath() + "mods/multiplayer");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Linux version of the game doesnt support uppercase letters in mod names
|
// Linux version of the game doesnt support uppercase letters in mod names
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
for(char &c : FName){
|
for (char& c : FName) {
|
||||||
c = ::tolower(c);
|
c = ::tolower(c);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fs::copy_file(a,GetGamePath() + "mods/multiplayer" + FName, fs::copy_options::overwrite_existing);
|
fs::copy_file(a, GetGamePath() + "mods/multiplayer" + FName, fs::copy_options::overwrite_existing);
|
||||||
}
|
}
|
||||||
WaitForConfirm();
|
WaitForConfirm();
|
||||||
}
|
}
|
||||||
KillSocket(DSock);
|
KillSocket(DSock);
|
||||||
if(!Terminate){
|
if (!Terminate) {
|
||||||
TCPSend("Done",Sock);
|
TCPSend("Done", Sock);
|
||||||
info("Done!");
|
info("Done!");
|
||||||
}else{
|
} else {
|
||||||
UlStatus = "Ulstart";
|
UlStatus = "Ulstart";
|
||||||
info("Connection Terminated!");
|
info("Connection Terminated!");
|
||||||
}
|
}
|
||||||
|
@ -5,76 +5,79 @@
|
|||||||
///
|
///
|
||||||
/// Created by Anonymous275 on 5/8/2020
|
/// Created by Anonymous275 on 5/8/2020
|
||||||
///
|
///
|
||||||
#include "Zlib/Compressor.h"
|
|
||||||
#include "Network/network.hpp"
|
#include "Network/network.hpp"
|
||||||
|
#include "Zlib/Compressor.h"
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
#include <sys/socket.h>
|
#include "linuxfixes.h"
|
||||||
#include <sys/types.h>
|
#include <arpa/inet.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <arpa/inet.h>
|
#include <sys/socket.h>
|
||||||
#include "linuxfixes.h"
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <string>
|
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
SOCKET UDPSock = -1;
|
SOCKET UDPSock = -1;
|
||||||
sockaddr_in* ToServer = nullptr;
|
sockaddr_in* ToServer = nullptr;
|
||||||
|
|
||||||
void UDPSend(std::string Data){
|
void UDPSend(std::string Data) {
|
||||||
if(ClientID == -1 || UDPSock == -1)return;
|
if (ClientID == -1 || UDPSock == -1)
|
||||||
if(Data.length() > 400){
|
return;
|
||||||
|
if (Data.length() > 400) {
|
||||||
std::string CMP(Comp(Data));
|
std::string CMP(Comp(Data));
|
||||||
Data = "ABG:" + CMP;
|
Data = "ABG:" + CMP;
|
||||||
}
|
}
|
||||||
std::string Packet = char(ClientID+1) + std::string(":") + Data;
|
std::string Packet = char(ClientID + 1) + std::string(":") + Data;
|
||||||
int sendOk = sendto(UDPSock, Packet.c_str(), int(Packet.size()), 0, (sockaddr*)ToServer, sizeof(*ToServer));
|
int sendOk = sendto(UDPSock, Packet.c_str(), int(Packet.size()), 0, (sockaddr*)ToServer, sizeof(*ToServer));
|
||||||
if (sendOk == SOCKET_ERROR)error("Error Code : " + std::to_string(WSAGetLastError()));
|
if (sendOk == SOCKET_ERROR)
|
||||||
|
error("Error Code : " + std::to_string(WSAGetLastError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SendLarge(std::string Data) {
|
||||||
void SendLarge(std::string Data){
|
if (Data.length() > 400) {
|
||||||
if(Data.length() > 400){
|
|
||||||
std::string CMP(Comp(Data));
|
std::string CMP(Comp(Data));
|
||||||
Data = "ABG:" + CMP;
|
Data = "ABG:" + CMP;
|
||||||
}
|
}
|
||||||
TCPSend(Data,TCPSock);
|
TCPSend(Data, TCPSock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDPParser(std::string Packet){
|
void UDPParser(std::string Packet) {
|
||||||
if(Packet.substr(0,4) == "ABG:"){
|
if (Packet.substr(0, 4) == "ABG:") {
|
||||||
Packet = DeComp(Packet.substr(4));
|
Packet = DeComp(Packet.substr(4));
|
||||||
}
|
}
|
||||||
ServerParser(Packet);
|
ServerParser(Packet);
|
||||||
}
|
}
|
||||||
void UDPRcv(){
|
void UDPRcv() {
|
||||||
sockaddr_in FromServer{};
|
sockaddr_in FromServer {};
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
int clientLength = sizeof(FromServer);
|
int clientLength = sizeof(FromServer);
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
socklen_t clientLength = sizeof(FromServer);
|
socklen_t clientLength = sizeof(FromServer);
|
||||||
#endif
|
#endif
|
||||||
ZeroMemory(&FromServer, clientLength);
|
ZeroMemory(&FromServer, clientLength);
|
||||||
std::string Ret(10240,0);
|
std::string Ret(10240, 0);
|
||||||
if(UDPSock == -1)return;
|
if (UDPSock == -1)
|
||||||
|
return;
|
||||||
int32_t Rcv = recvfrom(UDPSock, &Ret[0], 10240, 0, (sockaddr*)&FromServer, &clientLength);
|
int32_t Rcv = recvfrom(UDPSock, &Ret[0], 10240, 0, (sockaddr*)&FromServer, &clientLength);
|
||||||
if (Rcv == SOCKET_ERROR)return;
|
if (Rcv == SOCKET_ERROR)
|
||||||
UDPParser(Ret.substr(0,Rcv));
|
return;
|
||||||
|
UDPParser(Ret.substr(0, Rcv));
|
||||||
}
|
}
|
||||||
void UDPClientMain(const std::string& IP,int Port){
|
void UDPClientMain(const std::string& IP, int Port) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSADATA data;
|
WSADATA data;
|
||||||
if (WSAStartup(514, &data)){
|
if (WSAStartup(514, &data)) {
|
||||||
error("Can't start Winsock!");
|
error("Can't start Winsock!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
delete ToServer;
|
delete ToServer;
|
||||||
ToServer = new sockaddr_in;
|
ToServer = new sockaddr_in;
|
||||||
@ -82,10 +85,11 @@ void UDPClientMain(const std::string& IP,int Port){
|
|||||||
ToServer->sin_port = htons(Port);
|
ToServer->sin_port = htons(Port);
|
||||||
inet_pton(AF_INET, IP.c_str(), &ToServer->sin_addr);
|
inet_pton(AF_INET, IP.c_str(), &ToServer->sin_addr);
|
||||||
UDPSock = socket(AF_INET, SOCK_DGRAM, 0);
|
UDPSock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
GameSend("P"+std::to_string(ClientID));
|
GameSend("P" + std::to_string(ClientID));
|
||||||
TCPSend("H",TCPSock);
|
TCPSend("H", TCPSock);
|
||||||
UDPSend("p");
|
UDPSend("p");
|
||||||
while(!Terminate)UDPRcv();
|
while (!Terminate)
|
||||||
|
UDPRcv();
|
||||||
KillSocket(UDPSock);
|
KillSocket(UDPSock);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
}
|
}
|
@ -6,21 +6,21 @@
|
|||||||
/// Created by Anonymous275 on 5/8/2020
|
/// Created by Anonymous275 on 5/8/2020
|
||||||
///
|
///
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <vector>
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <iostream>
|
|
||||||
#include <Zlib/Compressor.h>
|
#include <Zlib/Compressor.h>
|
||||||
|
#include <chrono>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
#include <sys/socket.h>
|
#include <arpa/inet.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <arpa/inet.h>
|
#include <sys/socket.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Network/network.hpp"
|
#include "Network/network.hpp"
|
||||||
@ -29,12 +29,12 @@ int LastPort;
|
|||||||
std::string LastIP;
|
std::string LastIP;
|
||||||
SOCKET TCPSock = -1;
|
SOCKET TCPSock = -1;
|
||||||
|
|
||||||
bool CheckBytes(int32_t Bytes){
|
bool CheckBytes(int32_t Bytes) {
|
||||||
if (Bytes == 0){
|
if (Bytes == 0) {
|
||||||
debug("(TCP) Connection closing... CheckBytes(16)");
|
debug("(TCP) Connection closing... CheckBytes(16)");
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
return false;
|
return false;
|
||||||
}else if (Bytes < 0) {
|
} else if (Bytes < 0) {
|
||||||
debug("(TCP CB) recv failed with error: " + std::to_string(WSAGetLastError()));
|
debug("(TCP CB) recv failed with error: " + std::to_string(WSAGetLastError()));
|
||||||
KillSocket(TCPSock);
|
KillSocket(TCPSock);
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
@ -42,98 +42,99 @@ bool CheckBytes(int32_t Bytes){
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
void UUl(const std::string& R){
|
void UUl(const std::string& R) {
|
||||||
UlStatus = "UlDisconnected: " + R;
|
UlStatus = "UlDisconnected: " + R;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPSend(const std::string&Data,uint64_t Sock){
|
void TCPSend(const std::string& Data, uint64_t Sock) {
|
||||||
if(Sock == -1){
|
if (Sock == -1) {
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
UUl("Invalid Socket");
|
UUl("Invalid Socket");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t Size,Sent,Temp;
|
int32_t Size, Sent, Temp;
|
||||||
std::string Send(4,0);
|
std::string Send(4, 0);
|
||||||
Size = int32_t(Data.size());
|
Size = int32_t(Data.size());
|
||||||
memcpy(&Send[0],&Size,sizeof(Size));
|
memcpy(&Send[0], &Size, sizeof(Size));
|
||||||
Send += Data;
|
Send += Data;
|
||||||
// Do not use Size before this point for anything but the header
|
// Do not use Size before this point for anything but the header
|
||||||
Sent = 0;
|
Sent = 0;
|
||||||
Size += 4;
|
Size += 4;
|
||||||
do{
|
do {
|
||||||
if (size_t(Sent) >= Send.size()) {
|
if (size_t(Sent) >= Send.size()) {
|
||||||
error("string OOB in " + std::string(__func__));
|
error("string OOB in " + std::string(__func__));
|
||||||
UUl("TCP Send OOB");
|
UUl("TCP Send OOB");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Temp = send(Sock, &Send[Sent], Size - Sent, 0);
|
Temp = send(Sock, &Send[Sent], Size - Sent, 0);
|
||||||
if(!CheckBytes(Temp)){
|
if (!CheckBytes(Temp)) {
|
||||||
UUl("Socket Closed Code 2");
|
UUl("Socket Closed Code 2");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Sent += Temp;
|
Sent += Temp;
|
||||||
}while(Sent < Size);
|
} while (Sent < Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TCPRcv(SOCKET Sock){
|
std::string TCPRcv(SOCKET Sock) {
|
||||||
if(Sock == -1){
|
if (Sock == -1) {
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
UUl("Invalid Socket");
|
UUl("Invalid Socket");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
int32_t Header,BytesRcv = 0,Temp;
|
int32_t Header, BytesRcv = 0, Temp;
|
||||||
std::vector<char> Data(sizeof(Header));
|
std::vector<char> Data(sizeof(Header));
|
||||||
do{
|
do {
|
||||||
Temp = recv(Sock,&Data[BytesRcv],4-BytesRcv,0);
|
Temp = recv(Sock, &Data[BytesRcv], 4 - BytesRcv, 0);
|
||||||
if(!CheckBytes(Temp)){
|
if (!CheckBytes(Temp)) {
|
||||||
UUl("Socket Closed Code 3");
|
UUl("Socket Closed Code 3");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
BytesRcv += Temp;
|
BytesRcv += Temp;
|
||||||
}while(BytesRcv < 4);
|
} while (BytesRcv < 4);
|
||||||
memcpy(&Header,&Data[0],sizeof(Header));
|
memcpy(&Header, &Data[0], sizeof(Header));
|
||||||
|
|
||||||
if(!CheckBytes(BytesRcv)){
|
if (!CheckBytes(BytesRcv)) {
|
||||||
UUl("Socket Closed Code 4");
|
UUl("Socket Closed Code 4");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
Data.resize(Header);
|
Data.resize(Header);
|
||||||
BytesRcv = 0;
|
BytesRcv = 0;
|
||||||
do{
|
do {
|
||||||
Temp = recv(Sock,&Data[BytesRcv],Header-BytesRcv,0);
|
Temp = recv(Sock, &Data[BytesRcv], Header - BytesRcv, 0);
|
||||||
if(!CheckBytes(Temp)){
|
if (!CheckBytes(Temp)) {
|
||||||
UUl("Socket Closed Code 5");
|
UUl("Socket Closed Code 5");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
BytesRcv += Temp;
|
BytesRcv += Temp;
|
||||||
}while(BytesRcv < Header);
|
} while (BytesRcv < Header);
|
||||||
|
|
||||||
std::string Ret(Data.data(),Header);
|
std::string Ret(Data.data(), Header);
|
||||||
|
|
||||||
if (Ret.substr(0, 4) == "ABG:") {
|
if (Ret.substr(0, 4) == "ABG:") {
|
||||||
Ret = DeComp(Ret.substr(4));
|
Ret = DeComp(Ret.substr(4));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
//debug("Parsing from server -> " + std::to_string(Ret.size()));
|
// debug("Parsing from server -> " + std::to_string(Ret.size()));
|
||||||
#endif
|
#endif
|
||||||
if(Ret[0] == 'E' || Ret[0] == 'K')UUl(Ret.substr(1));
|
if (Ret[0] == 'E' || Ret[0] == 'K')
|
||||||
|
UUl(Ret.substr(1));
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPClientMain(const std::string& IP,int Port){
|
void TCPClientMain(const std::string& IP, int Port) {
|
||||||
LastIP = IP;
|
LastIP = IP;
|
||||||
LastPort = Port;
|
LastPort = Port;
|
||||||
SOCKADDR_IN ServerAddr;
|
SOCKADDR_IN ServerAddr;
|
||||||
int RetCode;
|
int RetCode;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
WSAStartup(514, &wsaData); //2.2
|
WSAStartup(514, &wsaData); // 2.2
|
||||||
#endif
|
#endif
|
||||||
TCPSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
TCPSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
|
|
||||||
if(TCPSock == -1){
|
if (TCPSock == -1) {
|
||||||
printf("Client: socket failed! Error code: %d\n", WSAGetLastError());
|
printf("Client: socket failed! Error code: %d\n", WSAGetLastError());
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
return;
|
return;
|
||||||
@ -142,8 +143,8 @@ void TCPClientMain(const std::string& IP,int Port){
|
|||||||
ServerAddr.sin_family = AF_INET;
|
ServerAddr.sin_family = AF_INET;
|
||||||
ServerAddr.sin_port = htons(Port);
|
ServerAddr.sin_port = htons(Port);
|
||||||
inet_pton(AF_INET, IP.c_str(), &ServerAddr.sin_addr);
|
inet_pton(AF_INET, IP.c_str(), &ServerAddr.sin_addr);
|
||||||
RetCode = connect(TCPSock, (SOCKADDR *) &ServerAddr, sizeof(ServerAddr));
|
RetCode = connect(TCPSock, (SOCKADDR*)&ServerAddr, sizeof(ServerAddr));
|
||||||
if(RetCode != 0){
|
if (RetCode != 0) {
|
||||||
UlStatus = "UlConnection Failed!";
|
UlStatus = "UlConnection Failed!";
|
||||||
error("Client: connect failed! Error code: " + std::to_string(WSAGetLastError()));
|
error("Client: connect failed! Error code: " + std::to_string(WSAGetLastError()));
|
||||||
KillSocket(TCPSock);
|
KillSocket(TCPSock);
|
||||||
@ -156,17 +157,16 @@ void TCPClientMain(const std::string& IP,int Port){
|
|||||||
char Code = 'C';
|
char Code = 'C';
|
||||||
send(TCPSock, &Code, 1, 0);
|
send(TCPSock, &Code, 1, 0);
|
||||||
SyncResources(TCPSock);
|
SyncResources(TCPSock);
|
||||||
while(!Terminate){
|
while (!Terminate) {
|
||||||
ServerParser(TCPRcv(TCPSock));
|
ServerParser(TCPRcv(TCPSock));
|
||||||
}
|
}
|
||||||
GameSend("T");
|
GameSend("T");
|
||||||
////Game Send Terminate
|
////Game Send Terminate
|
||||||
if(KillSocket(TCPSock) != 0)
|
if (KillSocket(TCPSock) != 0)
|
||||||
debug("(TCP) Cannot close socket. Error code: " + std::to_string(WSAGetLastError()));
|
debug("(TCP) Cannot close socket. Error code: " + std::to_string(WSAGetLastError()));
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if(WSACleanup() != 0)
|
if (WSACleanup() != 0)
|
||||||
debug("(TCP) Client: WSACleanup() failed!...");
|
debug("(TCP) Client: WSACleanup() failed!...");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,9 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
#include "vdf_parser.hpp"
|
#include "vdf_parser.hpp"
|
||||||
#include <vector>
|
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <vector>
|
||||||
#endif
|
#endif
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@ -27,11 +27,10 @@
|
|||||||
int TraceBack = 0;
|
int TraceBack = 0;
|
||||||
std::string GameDir;
|
std::string GameDir;
|
||||||
|
|
||||||
void lowExit(int code){
|
void lowExit(int code) {
|
||||||
TraceBack = 0;
|
TraceBack = 0;
|
||||||
std::string msg =
|
std::string msg = "Failed to find the game please launch it. Report this if the issue persists code ";
|
||||||
"Failed to find the game please launch it. Report this if the issue persists code ";
|
error(msg + std::to_string(code));
|
||||||
error(msg+std::to_string(code));
|
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
@ -51,124 +50,136 @@ void SteamExit(int code){
|
|||||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||||
exit(4);
|
exit(4);
|
||||||
}*/
|
}*/
|
||||||
std::string GetGameDir(){
|
std::string GetGameDir() {
|
||||||
//if(TraceBack != 4)Exit(0);
|
// if(TraceBack != 4)Exit(0);
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
return GameDir.substr(0,GameDir.find_last_of('\\'));
|
return GameDir.substr(0, GameDir.find_last_of('\\'));
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
return GameDir.substr(0,GameDir.find_last_of('/'));
|
return GameDir.substr(0, GameDir.find_last_of('/'));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
LONG OpenKey(HKEY root,const char* path,PHKEY hKey){
|
LONG OpenKey(HKEY root, const char* path, PHKEY hKey) {
|
||||||
return RegOpenKeyEx(root, reinterpret_cast<LPCSTR>(path), 0, KEY_READ, hKey);
|
return RegOpenKeyEx(root, reinterpret_cast<LPCSTR>(path), 0, KEY_READ, hKey);
|
||||||
}
|
}
|
||||||
std::string QueryKey(HKEY hKey,int ID){
|
std::string QueryKey(HKEY hKey, int ID) {
|
||||||
TCHAR achKey[MAX_KEY_LENGTH]; // buffer for subkey name
|
TCHAR achKey[MAX_KEY_LENGTH]; // buffer for subkey name
|
||||||
DWORD cbName; // size of name string
|
DWORD cbName; // size of name string
|
||||||
TCHAR achClass[MAX_PATH] = TEXT(""); // buffer for class name
|
TCHAR achClass[MAX_PATH] = TEXT(""); // buffer for class name
|
||||||
DWORD cchClassName = MAX_PATH; // size of class string
|
DWORD cchClassName = MAX_PATH; // size of class string
|
||||||
DWORD cSubKeys=0; // number of subkeys
|
DWORD cSubKeys = 0; // number of subkeys
|
||||||
DWORD cbMaxSubKey; // longest subkey size
|
DWORD cbMaxSubKey; // longest subkey size
|
||||||
DWORD cchMaxClass; // longest class string
|
DWORD cchMaxClass; // longest class string
|
||||||
DWORD cValues; // number of values for key
|
DWORD cValues; // number of values for key
|
||||||
DWORD cchMaxValue; // longest value name
|
DWORD cchMaxValue; // longest value name
|
||||||
DWORD cbMaxValueData; // longest value data
|
DWORD cbMaxValueData; // longest value data
|
||||||
DWORD cbSecurityDescriptor; // size of security descriptor
|
DWORD cbSecurityDescriptor; // size of security descriptor
|
||||||
FILETIME ftLastWriteTime; // last write time
|
FILETIME ftLastWriteTime; // last write time
|
||||||
|
|
||||||
DWORD i, retCode;
|
DWORD i, retCode;
|
||||||
|
|
||||||
TCHAR achValue[MAX_VALUE_NAME];
|
TCHAR achValue[MAX_VALUE_NAME];
|
||||||
DWORD cchValue = MAX_VALUE_NAME;
|
DWORD cchValue = MAX_VALUE_NAME;
|
||||||
|
|
||||||
retCode = RegQueryInfoKey(
|
retCode = RegQueryInfoKey(
|
||||||
hKey, // key handle
|
hKey, // key handle
|
||||||
achClass, // buffer for class name
|
achClass, // buffer for class name
|
||||||
&cchClassName, // size of class string
|
&cchClassName, // size of class string
|
||||||
nullptr, // reserved
|
nullptr, // reserved
|
||||||
&cSubKeys, // number of subkeys
|
&cSubKeys, // number of subkeys
|
||||||
&cbMaxSubKey, // longest subkey size
|
&cbMaxSubKey, // longest subkey size
|
||||||
&cchMaxClass, // longest class string
|
&cchMaxClass, // longest class string
|
||||||
&cValues, // number of values for this key
|
&cValues, // number of values for this key
|
||||||
&cchMaxValue, // longest value name
|
&cchMaxValue, // longest value name
|
||||||
&cbMaxValueData, // longest value data
|
&cbMaxValueData, // longest value data
|
||||||
&cbSecurityDescriptor, // security descriptor
|
&cbSecurityDescriptor, // security descriptor
|
||||||
&ftLastWriteTime); // last write time
|
&ftLastWriteTime); // last write time
|
||||||
|
|
||||||
BYTE* buffer = new BYTE[cbMaxValueData];
|
BYTE* buffer = new BYTE[cbMaxValueData];
|
||||||
ZeroMemory(buffer, cbMaxValueData);
|
ZeroMemory(buffer, cbMaxValueData);
|
||||||
if (cSubKeys){
|
if (cSubKeys) {
|
||||||
for (i=0; i<cSubKeys; i++){
|
for (i = 0; i < cSubKeys; i++) {
|
||||||
cbName = MAX_KEY_LENGTH;
|
cbName = MAX_KEY_LENGTH;
|
||||||
retCode = RegEnumKeyEx(hKey, i,achKey,&cbName,nullptr,nullptr,nullptr,&ftLastWriteTime);
|
retCode = RegEnumKeyEx(hKey, i, achKey, &cbName, nullptr, nullptr, nullptr, &ftLastWriteTime);
|
||||||
if (retCode == ERROR_SUCCESS){
|
if (retCode == ERROR_SUCCESS) {
|
||||||
if(strcmp(achKey,"Steam App 284160") == 0){
|
if (strcmp(achKey, "Steam App 284160") == 0) {
|
||||||
return achKey;
|
return achKey;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cValues){
|
if (cValues) {
|
||||||
for (i=0, retCode = ERROR_SUCCESS; i<cValues; i++){
|
for (i = 0, retCode = ERROR_SUCCESS; i < cValues; i++) {
|
||||||
cchValue = MAX_VALUE_NAME;
|
cchValue = MAX_VALUE_NAME;
|
||||||
achValue[0] = '\0';
|
achValue[0] = '\0';
|
||||||
retCode = RegEnumValue(hKey, i,achValue,&cchValue,nullptr,nullptr,nullptr,nullptr);
|
retCode = RegEnumValue(hKey, i, achValue, &cchValue, nullptr, nullptr, nullptr, nullptr);
|
||||||
if (retCode == ERROR_SUCCESS ){
|
if (retCode == ERROR_SUCCESS) {
|
||||||
DWORD lpData = cbMaxValueData;
|
DWORD lpData = cbMaxValueData;
|
||||||
buffer[0] = '\0';
|
buffer[0] = '\0';
|
||||||
LONG dwRes = RegQueryValueEx(hKey, achValue, nullptr, nullptr, buffer, &lpData);
|
LONG dwRes = RegQueryValueEx(hKey, achValue, nullptr, nullptr, buffer, &lpData);
|
||||||
std::string data = (char *)(buffer);
|
std::string data = (char*)(buffer);
|
||||||
std::string key = achValue;
|
std::string key = achValue;
|
||||||
|
|
||||||
switch (ID){
|
switch (ID) {
|
||||||
case 1: if(key == "SteamExe"){
|
case 1:
|
||||||
auto p = data.find_last_of("/\\");
|
if (key == "SteamExe") {
|
||||||
if(p != std::string::npos){
|
auto p = data.find_last_of("/\\");
|
||||||
return data.substr(0,p);
|
if (p != std::string::npos) {
|
||||||
}
|
return data.substr(0, p);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case 2: if(key == "Name" && data == "BeamNG.drive")return data;break;
|
break;
|
||||||
case 3: if(key == "rootpath")return data;break;
|
case 2:
|
||||||
case 4: if(key == "userpath_override")return data;
|
if (key == "Name" && data == "BeamNG.drive")
|
||||||
case 5: if(key == "Local AppData")return data;
|
return data;
|
||||||
default: break;
|
break;
|
||||||
|
case 3:
|
||||||
|
if (key == "rootpath")
|
||||||
|
return data;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
if (key == "userpath_override")
|
||||||
|
return data;
|
||||||
|
case 5:
|
||||||
|
if (key == "Local AppData")
|
||||||
|
return data;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete [] buffer;
|
delete[] buffer;
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
bool NameValid(const std::string& N){
|
bool NameValid(const std::string& N) {
|
||||||
if(N == "config" || N == "librarycache"){
|
if (N == "config" || N == "librarycache") {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(N.find_first_not_of("0123456789") == std::string::npos){
|
if (N.find_first_not_of("0123456789") == std::string::npos) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
void FileList(std::vector<std::string>&a,const std::string& Path){
|
void FileList(std::vector<std::string>& a, const std::string& Path) {
|
||||||
for (const auto &entry : fs::directory_iterator(Path)) {
|
for (const auto& entry : fs::directory_iterator(Path)) {
|
||||||
const auto& DPath = entry.path();
|
const auto& DPath = entry.path();
|
||||||
if (!entry.is_directory()) {
|
if (!entry.is_directory()) {
|
||||||
a.emplace_back(DPath.string());
|
a.emplace_back(DPath.string());
|
||||||
}else if(NameValid(DPath.filename().string())){
|
} else if (NameValid(DPath.filename().string())) {
|
||||||
FileList(a, DPath.string());
|
FileList(a, DPath.string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool Find(const std::string& FName,const std::string& Path){
|
bool Find(const std::string& FName, const std::string& Path) {
|
||||||
std::vector<std::string> FS;
|
std::vector<std::string> FS;
|
||||||
FileList(FS,Path+"\\userdata");
|
FileList(FS, Path + "\\userdata");
|
||||||
for(std::string&a : FS){
|
for (std::string& a : FS) {
|
||||||
if(a.find(FName) != std::string::npos){
|
if (a.find(FName) != std::string::npos) {
|
||||||
FS.clear();
|
FS.clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -176,22 +187,24 @@ bool Find(const std::string& FName,const std::string& Path){
|
|||||||
FS.clear();
|
FS.clear();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool FindHack(const std::string& Path){
|
bool FindHack(const std::string& Path) {
|
||||||
bool s = true;
|
bool s = true;
|
||||||
for (const auto &entry : fs::directory_iterator(Path)) {
|
for (const auto& entry : fs::directory_iterator(Path)) {
|
||||||
std::string Name = entry.path().filename().string();
|
std::string Name = entry.path().filename().string();
|
||||||
for(char&c : Name)c = char(tolower(c));
|
for (char& c : Name)
|
||||||
if(Name == "steam.exe")s = false;
|
c = char(tolower(c));
|
||||||
if(Name.find("greenluma") != -1){
|
if (Name == "steam.exe")
|
||||||
error("Found malicious file/folder \"" + Name+"\"");
|
s = false;
|
||||||
|
if (Name.find("greenluma") != -1) {
|
||||||
|
error("Found malicious file/folder \"" + Name + "\"");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Name.clear();
|
Name.clear();
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
std::vector<std::string> GetID(const std::string& log){
|
std::vector<std::string> GetID(const std::string& log) {
|
||||||
std::string vec,t,r;
|
std::string vec, t, r;
|
||||||
std::vector<std::string> Ret;
|
std::vector<std::string> Ret;
|
||||||
std::ifstream f(log.c_str(), std::ios::binary);
|
std::ifstream f(log.c_str(), std::ios::binary);
|
||||||
f.seekg(0, std::ios_base::end);
|
f.seekg(0, std::ios_base::end);
|
||||||
@ -203,10 +216,12 @@ std::vector<std::string> GetID(const std::string& log){
|
|||||||
std::stringstream ss(vec);
|
std::stringstream ss(vec);
|
||||||
bool S = false;
|
bool S = false;
|
||||||
while (std::getline(ss, t, '{')) {
|
while (std::getline(ss, t, '{')) {
|
||||||
if(!S)S = true;
|
if (!S)
|
||||||
else{
|
S = true;
|
||||||
for(char& c : t){
|
else {
|
||||||
if(isdigit(c))r += c;
|
for (char& c : t) {
|
||||||
|
if (isdigit(c))
|
||||||
|
r += c;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -216,15 +231,16 @@ std::vector<std::string> GetID(const std::string& log){
|
|||||||
S = false;
|
S = false;
|
||||||
bool L = true;
|
bool L = true;
|
||||||
while (std::getline(ss, t, '}')) {
|
while (std::getline(ss, t, '}')) {
|
||||||
if(L){
|
if (L) {
|
||||||
L = false;
|
L = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for(char& c : t){
|
for (char& c : t) {
|
||||||
if(c == '"'){
|
if (c == '"') {
|
||||||
if(!S)S = true;
|
if (!S)
|
||||||
else{
|
S = true;
|
||||||
if(r.length() > 10) {
|
else {
|
||||||
|
if (r.length() > 10) {
|
||||||
Ret.emplace_back(r);
|
Ret.emplace_back(r);
|
||||||
}
|
}
|
||||||
r.clear();
|
r.clear();
|
||||||
@ -232,13 +248,14 @@ std::vector<std::string> GetID(const std::string& log){
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(isdigit(c))r += c;
|
if (isdigit(c))
|
||||||
|
r += c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vec.clear();
|
vec.clear();
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
std::string GetManifest(const std::string& Man){
|
std::string GetManifest(const std::string& Man) {
|
||||||
std::string vec;
|
std::string vec;
|
||||||
std::ifstream f(Man.c_str(), std::ios::binary);
|
std::ifstream f(Man.c_str(), std::ios::binary);
|
||||||
f.seekg(0, std::ios_base::end);
|
f.seekg(0, std::ios_base::end);
|
||||||
@ -249,103 +266,109 @@ std::string GetManifest(const std::string& Man){
|
|||||||
f.close();
|
f.close();
|
||||||
std::string ToFind = "\"LastOwner\"\t\t\"";
|
std::string ToFind = "\"LastOwner\"\t\t\"";
|
||||||
int pos = int(vec.find(ToFind));
|
int pos = int(vec.find(ToFind));
|
||||||
if(pos != -1){
|
if (pos != -1) {
|
||||||
pos += int(ToFind.length());
|
pos += int(ToFind.length());
|
||||||
vec = vec.substr(pos);
|
vec = vec.substr(pos);
|
||||||
return vec.substr(0,vec.find('\"'));
|
return vec.substr(0, vec.find('\"'));
|
||||||
}else return "";
|
} else
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
bool IDCheck(std::string Man, std::string steam){
|
bool IDCheck(std::string Man, std::string steam) {
|
||||||
bool a = false,b = true;
|
bool a = false, b = true;
|
||||||
int pos = int(Man.rfind("steamapps"));
|
int pos = int(Man.rfind("steamapps"));
|
||||||
// if(pos == -1)Exit(5);
|
// if(pos == -1)Exit(5);
|
||||||
Man = Man.substr(0,pos+9) + "\\appmanifest_284160.acf";
|
Man = Man.substr(0, pos + 9) + "\\appmanifest_284160.acf";
|
||||||
steam += "\\config\\loginusers.vdf";
|
steam += "\\config\\loginusers.vdf";
|
||||||
if(fs::exists(Man) && fs::exists(steam)){
|
if (fs::exists(Man) && fs::exists(steam)) {
|
||||||
for(const std::string&ID : GetID(steam)){
|
for (const std::string& ID : GetID(steam)) {
|
||||||
if(ID == GetManifest(Man))b = false;
|
if (ID == GetManifest(Man))
|
||||||
|
b = false;
|
||||||
}
|
}
|
||||||
//if(b)Exit(6);
|
// if(b)Exit(6);
|
||||||
}else a = true;
|
} else
|
||||||
|
a = true;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
void LegitimacyCheck(){
|
void LegitimacyCheck() {
|
||||||
|
|
||||||
//std::string K1 = R"(Software\Valve\Steam)";
|
// std::string K1 = R"(Software\Valve\Steam)";
|
||||||
//std::string K2 = R"(Software\Valve\Steam\Apps\284160)";
|
// std::string K2 = R"(Software\Valve\Steam\Apps\284160)";
|
||||||
|
|
||||||
/*LONG dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K1.c_str(), &hKey);
|
/*LONG dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K1.c_str(), &hKey);
|
||||||
|
|
||||||
if(dwRegOPenKey == ERROR_SUCCESS) {
|
if(dwRegOPenKey == ERROR_SUCCESS) {
|
||||||
Result = QueryKey(hKey, 1);
|
Result = QueryKey(hKey, 1);
|
||||||
if(Result.empty())Exit(1);
|
if(Result.empty())Exit(1);
|
||||||
|
|
||||||
if(fs::exists(Result)){
|
if(fs::exists(Result)){
|
||||||
if(!Find("284160.json",Result))Exit(2);
|
if(!Find("284160.json",Result))Exit(2);
|
||||||
if(FindHack(Result))SteamExit(1);
|
if(FindHack(Result))SteamExit(1);
|
||||||
}else Exit(3);
|
}else Exit(3);
|
||||||
|
|
||||||
T = Result;
|
T = Result;
|
||||||
Result.clear();
|
Result.clear();
|
||||||
TraceBack++;
|
TraceBack++;
|
||||||
}else Exit(4);
|
}else Exit(4);
|
||||||
|
|
||||||
K1.clear();
|
K1.clear();
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K2.c_str(), &hKey);
|
dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K2.c_str(), &hKey);
|
||||||
if(dwRegOPenKey == ERROR_SUCCESS) {
|
if(dwRegOPenKey == ERROR_SUCCESS) {
|
||||||
Result = QueryKey(hKey, 2);
|
Result = QueryKey(hKey, 2);
|
||||||
if(Result.empty())lowExit(1);
|
if(Result.empty())lowExit(1);
|
||||||
TraceBack++;
|
TraceBack++;
|
||||||
}else lowExit(2);
|
}else lowExit(2);
|
||||||
K2.clear();
|
K2.clear();
|
||||||
RegCloseKey(hKey);*/
|
RegCloseKey(hKey);*/
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
std::string Result;
|
std::string Result;
|
||||||
std::string K3 = R"(Software\BeamNG\BeamNG.drive)";
|
std::string K3 = R"(Software\BeamNG\BeamNG.drive)";
|
||||||
HKEY hKey;
|
HKEY hKey;
|
||||||
LONG dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K3.c_str(), &hKey);
|
LONG dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K3.c_str(), &hKey);
|
||||||
if(dwRegOPenKey == ERROR_SUCCESS) {
|
if (dwRegOPenKey == ERROR_SUCCESS) {
|
||||||
Result = QueryKey(hKey, 3);
|
Result = QueryKey(hKey, 3);
|
||||||
if(Result.empty())lowExit(3);
|
if (Result.empty())
|
||||||
//if(IDCheck(Result,T))lowExit(5);
|
lowExit(3);
|
||||||
|
// if(IDCheck(Result,T))lowExit(5);
|
||||||
GameDir = Result;
|
GameDir = Result;
|
||||||
//TraceBack++;
|
// TraceBack++;
|
||||||
}else lowExit(4);
|
} else
|
||||||
|
lowExit(4);
|
||||||
K3.clear();
|
K3.clear();
|
||||||
Result.clear();
|
Result.clear();
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
//if(TraceBack < 3)exit(-1);
|
// if(TraceBack < 3)exit(-1);
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
struct passwd *pw = getpwuid(getuid());
|
struct passwd* pw = getpwuid(getuid());
|
||||||
std::string homeDir = pw->pw_dir;
|
std::string homeDir = pw->pw_dir;
|
||||||
// Right now only steam is supported
|
// Right now only steam is supported
|
||||||
std::ifstream libraryFolders(homeDir + "/.steam/root/steamapps/libraryfolders.vdf");
|
std::ifstream libraryFolders(homeDir + "/.steam/root/steamapps/libraryfolders.vdf");
|
||||||
auto root = tyti::vdf::read(libraryFolders);
|
auto root = tyti::vdf::read(libraryFolders);
|
||||||
|
|
||||||
for (auto folderInfo: root.childs){
|
for (auto folderInfo : root.childs) {
|
||||||
if (std::filesystem::exists(folderInfo.second->attribs["path"] + "/steamapps/common/BeamNG.drive/")){
|
if (std::filesystem::exists(folderInfo.second->attribs["path"] + "/steamapps/common/BeamNG.drive/")) {
|
||||||
GameDir = folderInfo.second->attribs["path"] + "/steamapps/common/BeamNG.drive/";
|
GameDir = folderInfo.second->attribs["path"] + "/steamapps/common/BeamNG.drive/";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
std::string CheckVer(const std::string &dir){
|
std::string CheckVer(const std::string& dir) {
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
std::string temp,Path = dir + "\\integrity.json";
|
std::string temp, Path = dir + "\\integrity.json";
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
std::string temp,Path = dir + "/integrity.json";
|
std::string temp, Path = dir + "/integrity.json";
|
||||||
#endif
|
#endif
|
||||||
std::ifstream f(Path.c_str(), std::ios::binary);
|
std::ifstream f(Path.c_str(), std::ios::binary);
|
||||||
int Size = int(std::filesystem::file_size(Path));
|
int Size = int(std::filesystem::file_size(Path));
|
||||||
std::string vec(Size,0);
|
std::string vec(Size, 0);
|
||||||
f.read(&vec[0], Size);
|
f.read(&vec[0], Size);
|
||||||
f.close();
|
f.close();
|
||||||
|
|
||||||
vec = vec.substr(vec.find_last_of("version"),vec.find_last_of('"'));
|
vec = vec.substr(vec.find_last_of("version"), vec.find_last_of('"'));
|
||||||
for(const char &a : vec){
|
for (const char& a : vec) {
|
||||||
if(isdigit(a) || a == '.')temp+=a;
|
if (isdigit(a) || a == '.')
|
||||||
|
temp += a;
|
||||||
}
|
}
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,11 @@
|
|||||||
/// Created by Anonymous275 on 11/26/2020
|
/// Created by Anonymous275 on 11/26/2020
|
||||||
///
|
///
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include "Http.h"
|
#include "Http.h"
|
||||||
#include <filesystem>
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
std::string PublicKey;
|
std::string PublicKey;
|
||||||
@ -20,15 +19,16 @@ extern bool LoginAuth;
|
|||||||
extern std::string Username;
|
extern std::string Username;
|
||||||
extern std::string UserRole;
|
extern std::string UserRole;
|
||||||
|
|
||||||
void UpdateKey(const char* newKey){
|
void UpdateKey(const char* newKey) {
|
||||||
if(newKey && std::isalnum(newKey[0])){
|
if (newKey && std::isalnum(newKey[0])) {
|
||||||
PrivateKey = newKey;
|
PrivateKey = newKey;
|
||||||
std::ofstream Key("key");
|
std::ofstream Key("key");
|
||||||
if(Key.is_open()){
|
if (Key.is_open()) {
|
||||||
Key << newKey;
|
Key << newKey;
|
||||||
Key.close();
|
Key.close();
|
||||||
}else fatal("Cannot write to disk!");
|
} else
|
||||||
}else if(fs::exists("key")){
|
fatal("Cannot write to disk!");
|
||||||
|
} else if (fs::exists("key")) {
|
||||||
remove("key");
|
remove("key");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -37,15 +37,15 @@ void UpdateKey(const char* newKey){
|
|||||||
/// "Guest":"Name"
|
/// "Guest":"Name"
|
||||||
/// "pk":"private_key"
|
/// "pk":"private_key"
|
||||||
|
|
||||||
std::string GetFail(const std::string& R){
|
std::string GetFail(const std::string& R) {
|
||||||
std::string DRet = R"({"success":false,"message":)";
|
std::string DRet = R"({"success":false,"message":)";
|
||||||
DRet += "\""+R+"\"}";
|
DRet += "\"" + R + "\"}";
|
||||||
error(R);
|
error(R);
|
||||||
return DRet;
|
return DRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Login(const std::string& fields){
|
std::string Login(const std::string& fields) {
|
||||||
if(fields == "LO"){
|
if (fields == "LO") {
|
||||||
Username = "";
|
Username = "";
|
||||||
UserRole = "";
|
UserRole = "";
|
||||||
LoginAuth = false;
|
LoginAuth = false;
|
||||||
@ -56,7 +56,7 @@ std::string Login(const std::string& fields){
|
|||||||
try {
|
try {
|
||||||
std::string Buffer = HTTP::Post("https://auth.beammp.com/userlogin", fields);
|
std::string Buffer = HTTP::Post("https://auth.beammp.com/userlogin", fields);
|
||||||
|
|
||||||
if(Buffer == "-1"){
|
if (Buffer == "-1") {
|
||||||
return GetFail("Failed to communicate with the auth system!");
|
return GetFail("Failed to communicate with the auth system!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ std::string Login(const std::string& fields){
|
|||||||
error(Buffer);
|
error(Buffer);
|
||||||
return GetFail("Invalid answer from authentication servers, please try again later!");
|
return GetFail("Invalid answer from authentication servers, please try again later!");
|
||||||
}
|
}
|
||||||
if(d.contains("success") && d["success"].get<bool>()){
|
if (d.contains("success") && d["success"].get<bool>()) {
|
||||||
LoginAuth = true;
|
LoginAuth = true;
|
||||||
if (d.contains("username")) {
|
if (d.contains("username")) {
|
||||||
Username = d["username"].get<std::string>();
|
Username = d["username"].get<std::string>();
|
||||||
@ -74,15 +74,16 @@ std::string Login(const std::string& fields){
|
|||||||
if (d.contains("role")) {
|
if (d.contains("role")) {
|
||||||
UserRole = d["role"].get<std::string>();
|
UserRole = d["role"].get<std::string>();
|
||||||
}
|
}
|
||||||
if(d.contains("private_key")) {
|
if (d.contains("private_key")) {
|
||||||
UpdateKey(d["private_key"].get<std::string>().c_str());
|
UpdateKey(d["private_key"].get<std::string>().c_str());
|
||||||
}
|
}
|
||||||
if(d.contains("public_key")){
|
if (d.contains("public_key")) {
|
||||||
PublicKey = d["public_key"].get<std::string>();
|
PublicKey = d["public_key"].get<std::string>();
|
||||||
}
|
}
|
||||||
info("Authentication successful!");
|
info("Authentication successful!");
|
||||||
}else info("Authentication failed!");
|
} else
|
||||||
if(d.contains("message")){
|
info("Authentication failed!");
|
||||||
|
if (d.contains("message")) {
|
||||||
d.erase("private_key");
|
d.erase("private_key");
|
||||||
d.erase("public_key");
|
d.erase("public_key");
|
||||||
return d.dump();
|
return d.dump();
|
||||||
@ -93,20 +94,20 @@ std::string Login(const std::string& fields){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckLocalKey(){
|
void CheckLocalKey() {
|
||||||
if(fs::exists("key") && fs::file_size("key") < 100){
|
if (fs::exists("key") && fs::file_size("key") < 100) {
|
||||||
std::ifstream Key("key");
|
std::ifstream Key("key");
|
||||||
if(Key.is_open()) {
|
if (Key.is_open()) {
|
||||||
auto Size = fs::file_size("key");
|
auto Size = fs::file_size("key");
|
||||||
std::string Buffer(Size, 0);
|
std::string Buffer(Size, 0);
|
||||||
Key.read(&Buffer[0], Size);
|
Key.read(&Buffer[0], Size);
|
||||||
Key.close();
|
Key.close();
|
||||||
|
|
||||||
for (char& c : Buffer) {
|
for (char& c : Buffer) {
|
||||||
if (!std::isalnum(c) && c != '-') {
|
if (!std::isalnum(c) && c != '-') {
|
||||||
UpdateKey(nullptr);
|
UpdateKey(nullptr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer = HTTP::Post("https://auth.beammp.com/userlogin", R"({"pk":")" + Buffer + "\"}");
|
Buffer = HTTP::Post("https://auth.beammp.com/userlogin", R"({"pk":")" + Buffer + "\"}");
|
||||||
@ -118,7 +119,7 @@ void CheckLocalKey(){
|
|||||||
info("Invalid answer from authentication servers.");
|
info("Invalid answer from authentication servers.");
|
||||||
UpdateKey(nullptr);
|
UpdateKey(nullptr);
|
||||||
}
|
}
|
||||||
if(d["success"].get<bool>()){
|
if (d["success"].get<bool>()) {
|
||||||
LoginAuth = true;
|
LoginAuth = true;
|
||||||
UpdateKey(d["private_key"].get<std::string>().c_str());
|
UpdateKey(d["private_key"].get<std::string>().c_str());
|
||||||
PublicKey = d["public_key"].get<std::string>();
|
PublicKey = d["public_key"].get<std::string>();
|
||||||
@ -128,14 +129,15 @@ void CheckLocalKey(){
|
|||||||
if (d.contains("role")) {
|
if (d.contains("role")) {
|
||||||
UserRole = d["role"].get<std::string>();
|
UserRole = d["role"].get<std::string>();
|
||||||
}
|
}
|
||||||
//info(Role);
|
// info(Role);
|
||||||
}else{
|
} else {
|
||||||
info("Auto-Authentication unsuccessful please re-login!");
|
info("Auto-Authentication unsuccessful please re-login!");
|
||||||
UpdateKey(nullptr);
|
UpdateKey(nullptr);
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
warn("Could not open saved key!");
|
warn("Could not open saved key!");
|
||||||
UpdateKey(nullptr);
|
UpdateKey(nullptr);
|
||||||
}
|
}
|
||||||
}else UpdateKey(nullptr);
|
} else
|
||||||
|
UpdateKey(nullptr);
|
||||||
}
|
}
|
||||||
|
212
src/Startup.cpp
212
src/Startup.cpp
@ -6,25 +6,24 @@
|
|||||||
/// Created by Anonymous275 on 7/16/2020
|
/// Created by Anonymous275 on 7/16/2020
|
||||||
///
|
///
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include <httplib.h>
|
|
||||||
#include "zip_file.h"
|
#include "zip_file.h"
|
||||||
|
#include <httplib.h>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include "Http.h"
|
||||||
|
#include "Logger.h"
|
||||||
#include "Network/network.hpp"
|
#include "Network/network.hpp"
|
||||||
#include "Security/Init.h"
|
#include "Security/Init.h"
|
||||||
#include <filesystem>
|
|
||||||
#include "Startup.h"
|
#include "Startup.h"
|
||||||
#include "hashpp.h"
|
#include "hashpp.h"
|
||||||
#include "Logger.h"
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include "Http.h"
|
|
||||||
|
|
||||||
|
|
||||||
extern int TraceBack;
|
extern int TraceBack;
|
||||||
bool Dev = false;
|
bool Dev = false;
|
||||||
@ -42,23 +41,29 @@ VersionParser::VersionParser(const std::string& from_string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::strong_ordering VersionParser::operator<=>(
|
std::strong_ordering VersionParser::operator<=>(
|
||||||
const VersionParser& rhs) const noexcept {
|
const VersionParser& rhs) const noexcept {
|
||||||
size_t const fields = std::min(data.size(), rhs.data.size());
|
size_t const fields = std::min(data.size(), rhs.data.size());
|
||||||
for (size_t i = 0; i != fields; ++i) {
|
for (size_t i = 0; i != fields; ++i) {
|
||||||
if (data[i] == rhs.data[i]) continue;
|
if (data[i] == rhs.data[i])
|
||||||
else if (data[i] < rhs.data[i]) return std::strong_ordering::less;
|
continue;
|
||||||
else return std::strong_ordering::greater;
|
else if (data[i] < rhs.data[i])
|
||||||
|
return std::strong_ordering::less;
|
||||||
|
else
|
||||||
|
return std::strong_ordering::greater;
|
||||||
}
|
}
|
||||||
if (data.size() == rhs.data.size()) return std::strong_ordering::equal;
|
if (data.size() == rhs.data.size())
|
||||||
else if (data.size() > rhs.data.size()) return std::strong_ordering::greater;
|
return std::strong_ordering::equal;
|
||||||
else return std::strong_ordering::less;
|
else if (data.size() > rhs.data.size())
|
||||||
|
return std::strong_ordering::greater;
|
||||||
|
else
|
||||||
|
return std::strong_ordering::less;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VersionParser::operator==(const VersionParser& rhs) const noexcept {
|
bool VersionParser::operator==(const VersionParser& rhs) const noexcept {
|
||||||
return std::is_eq(*this <=> rhs);
|
return std::is_eq(*this <=> rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetEN(){
|
std::string GetEN() {
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
return "BeamMP-Launcher.exe";
|
return "BeamMP-Launcher.exe";
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
@ -66,61 +71,61 @@ std::string GetEN(){
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetVer(){
|
std::string GetVer() {
|
||||||
return "2.0";
|
return "2.0";
|
||||||
}
|
}
|
||||||
std::string GetPatch(){
|
std::string GetPatch() {
|
||||||
return ".85";
|
return ".85";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetEP(char*P){
|
std::string GetEP(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);
|
||||||
} ();
|
}();
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
void ReLaunch(int argc,char*args[]){
|
void ReLaunch(int argc, char* args[]) {
|
||||||
std::string Arg;
|
std::string Arg;
|
||||||
for(int c = 2; c <= argc; c++){
|
for (int c = 2; c <= argc; c++) {
|
||||||
Arg += " ";
|
Arg += " ";
|
||||||
Arg += args[c-1];
|
Arg += args[c - 1];
|
||||||
}
|
}
|
||||||
system("cls");
|
system("cls");
|
||||||
ShellExecute(nullptr,"runas",(GetEP() + GetEN()).c_str(),Arg.c_str(),nullptr,SW_SHOWNORMAL);
|
ShellExecute(nullptr, "runas", (GetEP() + GetEN()).c_str(), Arg.c_str(), nullptr, SW_SHOWNORMAL);
|
||||||
ShowWindow(GetConsoleWindow(),0);
|
ShowWindow(GetConsoleWindow(), 0);
|
||||||
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(int argc, char* args[]) {
|
||||||
std::string Arg;
|
std::string Arg;
|
||||||
for(int c = 2; c <= argc; c++){
|
for (int c = 2; c <= argc; c++) {
|
||||||
Arg += " ";
|
Arg += " ";
|
||||||
Arg += args[c-1];
|
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);
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
void ReLaunch(int argc,char*args[]){
|
void ReLaunch(int argc, char* args[]) {
|
||||||
std::string Arg;
|
std::string Arg;
|
||||||
for(int c = 2; c <= argc; c++){
|
for (int c = 2; c <= argc; c++) {
|
||||||
Arg += " ";
|
Arg += " ";
|
||||||
Arg += args[c-1];
|
Arg += args[c - 1];
|
||||||
}
|
}
|
||||||
system("clear");
|
system("clear");
|
||||||
execl((GetEP() + GetEN()).c_str(), Arg.c_str(), NULL);
|
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);
|
||||||
}
|
}
|
||||||
void URelaunch(int argc,char* args[]){
|
void URelaunch(int argc, char* args[]) {
|
||||||
std::string Arg;
|
std::string Arg;
|
||||||
for(int c = 2; c <= argc; c++){
|
for (int c = 2; c <= argc; c++) {
|
||||||
Arg += " ";
|
Arg += " ";
|
||||||
Arg += args[c-1];
|
Arg += args[c - 1];
|
||||||
}
|
}
|
||||||
execl((GetEP() + GetEN()).c_str(), Arg.c_str(), NULL);
|
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));
|
||||||
@ -128,81 +133,86 @@ void URelaunch(int argc,char* args[]){
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void CheckName(int argc,char* args[]){
|
void CheckName(int argc, char* args[]) {
|
||||||
#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 = args[0], 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 = args[0], FN = CDir.substr(CDir.find_last_of('/') + 1);
|
||||||
#endif
|
#endif
|
||||||
if(FN != DN){
|
if (FN != DN) {
|
||||||
if(fs::exists(DN))remove(DN.c_str());
|
if (fs::exists(DN))
|
||||||
if(fs::exists(DN))ReLaunch(argc,args);
|
remove(DN.c_str());
|
||||||
|
if (fs::exists(DN))
|
||||||
|
ReLaunch(argc, args);
|
||||||
std::rename(FN.c_str(), DN.c_str());
|
std::rename(FN.c_str(), DN.c_str());
|
||||||
URelaunch(argc,args);
|
URelaunch(argc, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckForUpdates(int argc, char* args[], const std::string& CV) {
|
void CheckForUpdates(int argc, char* args[], 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);
|
||||||
|
|
||||||
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
|
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
|
||||||
std::string EP(GetEP() + GetEN()), Back(GetEP() + "BeamMP-Launcher.back");
|
std::string EP(GetEP() + GetEN()), Back(GetEP() + "BeamMP-Launcher.back");
|
||||||
|
|
||||||
std::string FileHash = hashpp::get::getFileHash(hashpp::ALGORITHMS::SHA2_256, EP);
|
std::string FileHash = hashpp::get::getFileHash(hashpp::ALGORITHMS::SHA2_256, EP);
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
system("clear");
|
system("clear");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (FileHash != LatestHash && VersionParser(LatestVersion) > VersionParser(GetVer()+GetPatch())) {
|
if (FileHash != LatestHash && VersionParser(LatestVersion) > VersionParser(GetVer() + GetPatch())) {
|
||||||
info("Launcher update found!");
|
info("Launcher update found!");
|
||||||
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(argc, args);
|
||||||
} else info("Launcher version is up to date");
|
} else
|
||||||
|
info("Launcher version is up to date");
|
||||||
TraceBack++;
|
TraceBack++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomPort(int argc, char* argv[]){
|
void CustomPort(int argc, char* argv[]) {
|
||||||
if(argc > 1){
|
if (argc > 1) {
|
||||||
std::string Port = argv[1];
|
std::string Port = argv[1];
|
||||||
if(Port.find_first_not_of("0123456789") == std::string::npos){
|
if (Port.find_first_not_of("0123456789") == std::string::npos) {
|
||||||
if(std::stoi(Port) > 1000){
|
if (std::stoi(Port) > 1000) {
|
||||||
DEFAULT_PORT = std::stoi(Port);
|
DEFAULT_PORT = std::stoi(Port);
|
||||||
warn("Running on custom port : " + std::to_string(DEFAULT_PORT));
|
warn("Running on custom port : " + std::to_string(DEFAULT_PORT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(argc > 2)Dev = true;
|
if (argc > 2)
|
||||||
|
Dev = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
void LinuxPatch(){
|
void LinuxPatch() {
|
||||||
HKEY hKey = nullptr;
|
HKEY hKey = nullptr;
|
||||||
LONG result = RegOpenKeyEx(HKEY_CURRENT_USER, R"(Software\Wine)", 0, KEY_READ, &hKey);
|
LONG result = RegOpenKeyEx(HKEY_CURRENT_USER, R"(Software\Wine)", 0, KEY_READ, &hKey);
|
||||||
if (result != ERROR_SUCCESS || getenv("USER") == nullptr)return;
|
if (result != ERROR_SUCCESS || getenv("USER") == nullptr)
|
||||||
|
return;
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
info("Wine/Proton Detected! If you are on windows delete HKEY_CURRENT_USER\\Software\\Wine in regedit");
|
info("Wine/Proton Detected! If you are on windows delete HKEY_CURRENT_USER\\Software\\Wine in regedit");
|
||||||
info("Applying patches...");
|
info("Applying patches...");
|
||||||
|
|
||||||
result = RegCreateKey(HKEY_CURRENT_USER, R"(Software\Valve\Steam\Apps\284160)", &hKey);
|
result = RegCreateKey(HKEY_CURRENT_USER, R"(Software\Valve\Steam\Apps\284160)", &hKey);
|
||||||
|
|
||||||
if (result != ERROR_SUCCESS){
|
if (result != ERROR_SUCCESS) {
|
||||||
fatal(R"(failed to create HKEY_CURRENT_USER\Software\Valve\Steam\Apps\284160)");
|
fatal(R"(failed to create HKEY_CURRENT_USER\Software\Valve\Steam\Apps\284160)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = RegSetValueEx(hKey, "Name", 0, REG_SZ, (BYTE*)"BeamNG.drive", 12);
|
result = RegSetValueEx(hKey, "Name", 0, REG_SZ, (BYTE*)"BeamNG.drive", 12);
|
||||||
|
|
||||||
if (result != ERROR_SUCCESS){
|
if (result != ERROR_SUCCESS) {
|
||||||
fatal(R"(failed to create the value "Name" under HKEY_CURRENT_USER\Software\Valve\Steam\Apps\284160)");
|
fatal(R"(failed to create the value "Name" under HKEY_CURRENT_USER\Software\Valve\Steam\Apps\284160)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -236,93 +246,100 @@ void InitLauncher(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
size_t DirCount(const std::filesystem::path& path){
|
size_t DirCount(const std::filesystem::path& path) {
|
||||||
return (size_t)std::distance(std::filesystem::directory_iterator{path}, std::filesystem::directory_iterator{});
|
return (size_t)std::distance(std::filesystem::directory_iterator { path }, std::filesystem::directory_iterator {});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckMP(const std::string& Path) {
|
void CheckMP(const std::string& Path) {
|
||||||
if (!fs::exists(Path))return;
|
if (!fs::exists(Path))
|
||||||
|
return;
|
||||||
size_t c = DirCount(fs::path(Path));
|
size_t c = DirCount(fs::path(Path));
|
||||||
try {
|
try {
|
||||||
for (auto& p : fs::directory_iterator(Path)){
|
for (auto& p : fs::directory_iterator(Path)) {
|
||||||
if(p.exists() && !p.is_directory()){
|
if (p.exists() && !p.is_directory()) {
|
||||||
std::string Name = p.path().filename().string();
|
std::string Name = p.path().filename().string();
|
||||||
for(char&Ch : Name)Ch = char(tolower(Ch));
|
for (char& Ch : Name)
|
||||||
if(Name != "beammp.zip")fs::remove(p.path());
|
Ch = char(tolower(Ch));
|
||||||
|
if (Name != "beammp.zip")
|
||||||
|
fs::remove(p.path());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
fatal("We were unable to clean the multiplayer mods folder! Is the game still running or do you have something open in that folder?");
|
fatal("We were unable to clean the multiplayer mods folder! Is the game still running or do you have something open in that folder?");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnableMP(){
|
void EnableMP() {
|
||||||
std::string File(GetGamePath() + "mods/db.json");
|
std::string File(GetGamePath() + "mods/db.json");
|
||||||
if(!fs::exists(File))return;
|
if (!fs::exists(File))
|
||||||
|
return;
|
||||||
auto Size = fs::file_size(File);
|
auto Size = fs::file_size(File);
|
||||||
if(Size < 2)return;
|
if (Size < 2)
|
||||||
|
return;
|
||||||
std::ifstream db(File);
|
std::ifstream db(File);
|
||||||
if(db.is_open()) {
|
if (db.is_open()) {
|
||||||
std::string Data(Size, 0);
|
std::string Data(Size, 0);
|
||||||
db.read(&Data[0], Size);
|
db.read(&Data[0], Size);
|
||||||
db.close();
|
db.close();
|
||||||
nlohmann::json d = nlohmann::json::parse(Data, nullptr, false);
|
nlohmann::json d = nlohmann::json::parse(Data, nullptr, false);
|
||||||
if(Data.at(0) != '{' || d.is_discarded()) {
|
if (Data.at(0) != '{' || d.is_discarded()) {
|
||||||
//error("Failed to parse " + File); //TODO illegal formatting
|
// error("Failed to parse " + File); //TODO illegal formatting
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(d.contains("mods") && d["mods"].contains("multiplayerbeammp")){
|
if (d.contains("mods") && d["mods"].contains("multiplayerbeammp")) {
|
||||||
d["mods"]["multiplayerbeammp"]["active"] = true;
|
d["mods"]["multiplayerbeammp"]["active"] = true;
|
||||||
std::ofstream ofs(File);
|
std::ofstream ofs(File);
|
||||||
if(ofs.is_open()){
|
if (ofs.is_open()) {
|
||||||
ofs << d.dump();
|
ofs << d.dump();
|
||||||
ofs.close();
|
ofs.close();
|
||||||
}else{
|
} else {
|
||||||
error("Failed to write " + File);
|
error("Failed to write " + File);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreGame(const std::string& GamePath){
|
void PreGame(const std::string& GamePath) {
|
||||||
std::string GameVer = CheckVer(GamePath);
|
std::string GameVer = CheckVer(GamePath);
|
||||||
info("Game Version : " + GameVer);
|
info("Game Version : " + GameVer);
|
||||||
|
|
||||||
CheckMP(GetGamePath() + "mods/multiplayer");
|
CheckMP(GetGamePath() + "mods/multiplayer");
|
||||||
|
|
||||||
if(!Dev) {
|
if (!Dev) {
|
||||||
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(),
|
||||||
[](auto const& c ) -> bool { return !std::isalnum(c); } ), LatestHash.end());
|
[](auto const& c) -> bool { return !std::isalnum(c); }),
|
||||||
|
LatestHash.end());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!fs::exists(GetGamePath() + "mods/multiplayer")) {
|
if (!fs::exists(GetGamePath() + "mods/multiplayer")) {
|
||||||
fs::create_directories(GetGamePath() + "mods/multiplayer");
|
fs::create_directories(GetGamePath() + "mods/multiplayer");
|
||||||
}
|
}
|
||||||
EnableMP();
|
EnableMP();
|
||||||
}catch(std::exception&e){
|
} catch (std::exception& e) {
|
||||||
fatal(e.what());
|
fatal(e.what());
|
||||||
}
|
}
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
std::string ZipPath(GetGamePath() + R"(mods\multiplayer\BeamMP.zip)");
|
std::string ZipPath(GetGamePath() + R"(mods\multiplayer\BeamMP.zip)");
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
// Linux version of the game cant handle mods with uppercase names
|
// Linux version of the game cant handle mods with uppercase names
|
||||||
std::string ZipPath(GetGamePath() + R"(mods/multiplayer/beammp.zip)");
|
std::string ZipPath(GetGamePath() + R"(mods/multiplayer/beammp.zip)");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::string FileHash = hashpp::get::getFileHash(hashpp::ALGORITHMS::SHA2_256, ZipPath);
|
std::string FileHash = hashpp::get::getFileHash(hashpp::ALGORITHMS::SHA2_256, ZipPath);
|
||||||
|
|
||||||
if (FileHash != LatestHash) {
|
if (FileHash != LatestHash) {
|
||||||
info("Downloading BeamMP Update " + LatestHash);
|
info("Downloading BeamMP Update " + LatestHash);
|
||||||
HTTP::Download("https://backend.beammp.com/builds/client?download=true"
|
HTTP::Download("https://backend.beammp.com/builds/client?download=true"
|
||||||
"&pk=" + PublicKey + "&branch=" + Branch, ZipPath);
|
"&pk="
|
||||||
|
+ PublicKey + "&branch=" + Branch,
|
||||||
|
ZipPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Target(GetGamePath() + "mods/unpacked/beammp");
|
std::string Target(GetGamePath() + "mods/unpacked/beammp");
|
||||||
|
|
||||||
if(fs::is_directory(Target)) {
|
if (fs::is_directory(Target)) {
|
||||||
fs::remove_all(Target);
|
fs::remove_all(Target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -335,15 +352,15 @@ void set_headers(httplib::Response& res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void StartProxy() {
|
void StartProxy() {
|
||||||
std::thread proxy([&](){
|
std::thread proxy([&]() {
|
||||||
httplib::Server HTTPProxy;
|
httplib::Server HTTPProxy;
|
||||||
httplib::Headers headers = {
|
httplib::Headers headers = {
|
||||||
{"User-Agent", "BeamMP-Launcher/" + GetVer() + GetPatch()},
|
{ "User-Agent", "BeamMP-Launcher/" + GetVer() + GetPatch() },
|
||||||
{"Accept", "*/*"}
|
{ "Accept", "*/*" }
|
||||||
};
|
};
|
||||||
std::string pattern = "/:any1";
|
std::string pattern = "/:any1";
|
||||||
for (int i = 2; i <= 4; i++) {
|
for (int i = 2; i <= 4; i++) {
|
||||||
HTTPProxy.Get(pattern, [&](const httplib::Request &req, httplib::Response &res) {
|
HTTPProxy.Get(pattern, [&](const httplib::Request& req, httplib::Response& res) {
|
||||||
httplib::Client cli("https://backend.beammp.com");
|
httplib::Client cli("https://backend.beammp.com");
|
||||||
set_headers(res);
|
set_headers(res);
|
||||||
if (req.has_header("X-BMP-Authentication")) {
|
if (req.has_header("X-BMP-Authentication")) {
|
||||||
@ -359,7 +376,7 @@ void StartProxy() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
HTTPProxy.Post(pattern, [&](const httplib::Request &req, httplib::Response &res) {
|
HTTPProxy.Post(pattern, [&](const httplib::Request& req, httplib::Response& res) {
|
||||||
httplib::Client cli("https://backend.beammp.com");
|
httplib::Client cli("https://backend.beammp.com");
|
||||||
set_headers(res);
|
set_headers(res);
|
||||||
if (req.has_header("X-BMP-Authentication")) {
|
if (req.has_header("X-BMP-Authentication")) {
|
||||||
@ -369,7 +386,8 @@ void StartProxy() {
|
|||||||
headers.emplace("X-API-Version", req.get_header_value("X-API-Version"));
|
headers.emplace("X-API-Version", req.get_header_value("X-API-Version"));
|
||||||
}
|
}
|
||||||
if (auto cli_res = cli.Post(req.path, headers, req.body,
|
if (auto cli_res = cli.Post(req.path, headers, req.body,
|
||||||
req.get_header_value("Content-Type")); cli_res) {
|
req.get_header_value("Content-Type"));
|
||||||
|
cli_res) {
|
||||||
res.set_content(cli_res->body, cli_res->get_header_value("Content-Type"));
|
res.set_content(cli_res->body, cli_res->get_header_value("Content-Type"));
|
||||||
} else {
|
} else {
|
||||||
res.set_content(to_string(cli_res.error()), "text/plain");
|
res.set_content(to_string(cli_res.error()), "text/plain");
|
||||||
|
12
src/main.cpp
12
src/main.cpp
@ -5,16 +5,16 @@
|
|||||||
///
|
///
|
||||||
/// Created by Anonymous275 on 7/16/2020
|
/// Created by Anonymous275 on 7/16/2020
|
||||||
///
|
///
|
||||||
|
#include "Http.h"
|
||||||
|
#include "Logger.h"
|
||||||
#include "Network/network.hpp"
|
#include "Network/network.hpp"
|
||||||
#include "Security/Init.h"
|
#include "Security/Init.h"
|
||||||
#include "Startup.h"
|
#include "Startup.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "Logger.h"
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include "Http.h"
|
|
||||||
|
|
||||||
[[noreturn]] void flush(){
|
[[noreturn]] void flush() {
|
||||||
while(true){
|
while (true) {
|
||||||
std::cout.flush();
|
std::cout.flush();
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
}
|
}
|
||||||
@ -32,7 +32,7 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
LegitimacyCheck();
|
LegitimacyCheck();
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception& e) {
|
||||||
fatal("Main 1 : " + std::string(e.what()));
|
fatal("Main 1 : " + std::string(e.what()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,5 +41,5 @@ int main(int argc, char* argv[]) {
|
|||||||
InitGame(GetGameDir());
|
InitGame(GetGameDir());
|
||||||
CoreNetwork();
|
CoreNetwork();
|
||||||
|
|
||||||
///TODO: make sure to use argv[0] for everything that should be in the same dir (mod down ect...)
|
/// TODO: make sure to use argv[0] for everything that should be in the same dir (mod down ect...)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user