mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-06 15:56:26 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7600372ca1 | ||
|
|
54cd5b5e0e | ||
|
|
ede6fcd7dd | ||
|
|
eaeacbd8de | ||
|
|
0ffed00bcb | ||
|
|
c0c3d6b30e | ||
|
|
9c59a83f04 | ||
|
|
95436cb073 | ||
|
|
cbb5502a40 | ||
|
|
d6dfe85f69 | ||
|
|
ae9af1470c | ||
|
|
9255c70b0b | ||
|
|
53c514ecc6 | ||
|
|
e348d59a7e | ||
|
|
244d27341f |
@@ -55,7 +55,7 @@ void ConfigInit() {
|
|||||||
R"({
|
R"({
|
||||||
"Port": 4444,
|
"Port": 4444,
|
||||||
"Build": "Default",
|
"Build": "Default",
|
||||||
"CachingDirectory": "./Resources",
|
"CachingDirectory": "./Resources"
|
||||||
})";
|
})";
|
||||||
cfg.close();
|
cfg.close();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -100,7 +100,11 @@ void StartGame(std::string Dir) {
|
|||||||
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;
|
pid_t pid;
|
||||||
int result = posix_spawn(&pid, filename.c_str(), NULL, NULL, argv, environ);
|
posix_spawn_file_actions_t spawn_actions;
|
||||||
|
posix_spawn_file_actions_init(&spawn_actions);
|
||||||
|
posix_spawn_file_actions_addclose(&spawn_actions, STDOUT_FILENO);
|
||||||
|
posix_spawn_file_actions_addclose(&spawn_actions, STDERR_FILENO);
|
||||||
|
int result = posix_spawn(&pid, filename.c_str(), &spawn_actions, nullptr, argv, environ);
|
||||||
|
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
error("Failed to Launch the game! launcher closing soon");
|
error("Failed to Launch the game! launcher closing soon");
|
||||||
|
|||||||
@@ -81,14 +81,20 @@ std::string HTTP::Get(const std::string& IP) {
|
|||||||
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 (status " + std::to_string(res->status) + ") '" + IP + "': " + res->reason + ", ssl verify = " + std::to_string(cli.get_openssl_verify_result()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isDownload) {
|
if (isDownload) {
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
}
|
}
|
||||||
|
auto result = cli.get_openssl_verify_result();
|
||||||
|
std::string verify_error;
|
||||||
|
if (result) {
|
||||||
|
verify_error = X509_verify_cert_error_string(result);
|
||||||
|
}
|
||||||
|
|
||||||
WriteHttpDebug(cli, "GET", IP, res);
|
WriteHttpDebug(cli, "GET", IP, res);
|
||||||
error("HTTP Get failed on " + to_string(res.error()) + ", ssl verify = " + std::to_string(cli.get_openssl_verify_result()));
|
error("HTTP Get failed on " + to_string(res.error()) + ", ssl verify = " + verify_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ret;
|
return Ret;
|
||||||
@@ -128,8 +134,13 @@ std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
|
|||||||
}
|
}
|
||||||
Ret = res->body;
|
Ret = res->body;
|
||||||
} else {
|
} else {
|
||||||
|
auto result = cli.get_openssl_verify_result();
|
||||||
|
std::string verify_error;
|
||||||
|
if (result) {
|
||||||
|
verify_error = X509_verify_cert_error_string(result);
|
||||||
|
}
|
||||||
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 = " + verify_error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
#include "Network/network.hpp"
|
#include "Network/network.hpp"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <ios>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
@@ -123,11 +125,19 @@ void UpdateUl(bool D, const std::string& msg) {
|
|||||||
UlStatus = "UlLoading Resource " + msg;
|
UlStatus = "UlLoading Resource " + msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float DownloadSpeed = 0;
|
||||||
|
|
||||||
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) + "%)");
|
std::string SpeedString = "";
|
||||||
|
if (DownloadSpeed > 0.01) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << " at " << std::setprecision(1) << std::fixed << DownloadSpeed << " Mbit/s";
|
||||||
|
SpeedString = ss.str();
|
||||||
|
}
|
||||||
|
UpdateUl(true, Name + " (" + Per.substr(0, Per.find('.') + 2) + "%)" + SpeedString);
|
||||||
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);
|
||||||
}
|
}
|
||||||
@@ -144,12 +154,12 @@ std::vector<char> TCPRcvRaw(SOCKET Sock, uint64_t& GRcv, uint64_t Size) {
|
|||||||
std::vector<char> File(Size);
|
std::vector<char> File(Size);
|
||||||
uint64_t Rcv = 0;
|
uint64_t Rcv = 0;
|
||||||
|
|
||||||
|
auto start = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
do {
|
do {
|
||||||
auto start = std::chrono::high_resolution_clock::now();
|
|
||||||
|
|
||||||
// receive at most some MB at a time
|
// receive at most some MB at a time
|
||||||
int Len = std::min(int(Size - Rcv), 2 * 1024 * 1024);
|
int Len = std::min(int(Size - Rcv), 1 * 1024 * 1024);
|
||||||
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));
|
||||||
@@ -161,12 +171,13 @@ std::vector<char> TCPRcvRaw(SOCKET Sock, uint64_t& GRcv, uint64_t Size) {
|
|||||||
Rcv += Temp;
|
Rcv += Temp;
|
||||||
GRcv += Temp;
|
GRcv += Temp;
|
||||||
|
|
||||||
// every 8th iteration calculate download speed for that iteration
|
auto end = std::chrono::high_resolution_clock::now();
|
||||||
|
auto difference = end - start;
|
||||||
|
float bits_per_s = float(Rcv * 8) / float(std::chrono::duration_cast<std::chrono::milliseconds>(difference).count());
|
||||||
|
float megabits_per_s = bits_per_s / 1000;
|
||||||
|
DownloadSpeed = megabits_per_s;
|
||||||
|
// every 8th iteration print the speed
|
||||||
if (i % 8 == 0) {
|
if (i % 8 == 0) {
|
||||||
auto end = std::chrono::high_resolution_clock::now();
|
|
||||||
auto difference = end - start;
|
|
||||||
float bits_per_s = float(Temp * 8) / float(std::chrono::duration_cast<std::chrono::milliseconds>(difference).count());
|
|
||||||
float megabits_per_s = bits_per_s / 1000;
|
|
||||||
debug("Download speed: " + std::to_string(uint32_t(megabits_per_s)) + "Mbit/s");
|
debug("Download speed: " + std::to_string(uint32_t(megabits_per_s)) + "Mbit/s");
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
@@ -204,6 +215,8 @@ SOCKET InitDSock() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<char> MultiDownload(SOCKET MSock, SOCKET DSock, uint64_t Size, const std::string& Name) {
|
std::vector<char> MultiDownload(SOCKET MSock, SOCKET DSock, uint64_t Size, const std::string& Name) {
|
||||||
|
DownloadSpeed = 0;
|
||||||
|
|
||||||
uint64_t GRcv = 0;
|
uint64_t GRcv = 0;
|
||||||
|
|
||||||
uint64_t MSize = Size / 2;
|
uint64_t MSize = Size / 2;
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ std::string GetVer() {
|
|||||||
return "2.1";
|
return "2.1";
|
||||||
}
|
}
|
||||||
std::string GetPatch() {
|
std::string GetPatch() {
|
||||||
return ".2";
|
return ".4";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetEP(char* P) {
|
std::string GetEP(char* P) {
|
||||||
|
|||||||
Reference in New Issue
Block a user