mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-03 14:26:15 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7600372ca1 | ||
|
|
54cd5b5e0e | ||
|
|
ede6fcd7dd | ||
|
|
eaeacbd8de | ||
|
|
0ffed00bcb | ||
|
|
c0c3d6b30e | ||
|
|
9c59a83f04 | ||
|
|
95436cb073 | ||
|
|
cbb5502a40 | ||
|
|
d6dfe85f69 |
@@ -97,10 +97,14 @@ void StartGame(std::string Dir) {
|
||||
#elif defined(__linux__)
|
||||
void StartGame(std::string Dir) {
|
||||
int status;
|
||||
std::string filename = (Dir + "/BinLinux/BeamNG.x64");
|
||||
std::string filename = (Dir + "/BinLinux/BeamNG.drive.x64");
|
||||
char* argv[] = { filename.data(), NULL };
|
||||
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) {
|
||||
error("Failed to Launch the game! launcher closing soon");
|
||||
|
||||
@@ -81,14 +81,20 @@ std::string HTTP::Get(const std::string& IP) {
|
||||
Ret = res->body;
|
||||
} else {
|
||||
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 {
|
||||
if (isDownload) {
|
||||
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);
|
||||
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;
|
||||
@@ -128,8 +134,13 @@ std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
|
||||
}
|
||||
Ret = res->body;
|
||||
} 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);
|
||||
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 <chrono>
|
||||
#include <iomanip>
|
||||
#include <ios>
|
||||
#include <mutex>
|
||||
|
||||
#if defined(_WIN32)
|
||||
@@ -123,11 +125,19 @@ void UpdateUl(bool D, const std::string& msg) {
|
||||
UlStatus = "UlLoading Resource " + msg;
|
||||
}
|
||||
|
||||
float DownloadSpeed = 0;
|
||||
|
||||
void AsyncUpdate(uint64_t& Rcv, uint64_t Size, const std::string& Name) {
|
||||
do {
|
||||
double pr = double(Rcv) / double(Size) * 100;
|
||||
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));
|
||||
} 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);
|
||||
uint64_t Rcv = 0;
|
||||
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
int i = 0;
|
||||
do {
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
// 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);
|
||||
if (Temp < 1) {
|
||||
info(std::to_string(Temp));
|
||||
@@ -161,12 +171,13 @@ std::vector<char> TCPRcvRaw(SOCKET Sock, uint64_t& GRcv, uint64_t Size) {
|
||||
Rcv += 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) {
|
||||
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");
|
||||
}
|
||||
++i;
|
||||
@@ -204,6 +215,8 @@ SOCKET InitDSock() {
|
||||
}
|
||||
|
||||
std::vector<char> MultiDownload(SOCKET MSock, SOCKET DSock, uint64_t Size, const std::string& Name) {
|
||||
DownloadSpeed = 0;
|
||||
|
||||
uint64_t GRcv = 0;
|
||||
|
||||
uint64_t MSize = Size / 2;
|
||||
|
||||
@@ -84,7 +84,7 @@ std::string GetVer() {
|
||||
return "2.1";
|
||||
}
|
||||
std::string GetPatch() {
|
||||
return ".3";
|
||||
return ".4";
|
||||
}
|
||||
|
||||
std::string GetEP(char* P) {
|
||||
|
||||
Reference in New Issue
Block a user