mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-14 19:56:17 +00:00
Compare commits
14 Commits
fix-little
...
95-ipv6-su
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
169b14490c | ||
|
|
a60ff48c08 | ||
|
|
da3b49aa12 | ||
|
|
e505874af9 | ||
|
|
2f0a9fba99 | ||
|
|
b034072027 | ||
|
|
f94b9adf7a | ||
|
|
c95178ea59 | ||
|
|
1f7c498bd9 | ||
|
|
e46d4b2f0e | ||
|
|
d32da036bc | ||
|
|
8b0f4f99f6 | ||
|
|
17e887442c | ||
|
|
fc454cd11e |
@@ -12,6 +12,8 @@ set(CMAKE_CXX_STANDARD 20)
|
|||||||
|
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
|
||||||
|
|
||||||
|
add_compile_definitions(CPPHTTPLIB_OPENSSL_SUPPORT)
|
||||||
|
|
||||||
file(GLOB source_files "src/*.cpp" "src/*/*.cpp" "src/*/*.hpp" "include/*.h" "include/*/*.h" "include/*/*/*.h" "include/*.hpp" "include/*/*.hpp" "include/*/*/*.hpp")
|
file(GLOB source_files "src/*.cpp" "src/*/*.cpp" "src/*/*.hpp" "include/*.h" "include/*/*.h" "include/*/*/*.h" "include/*.hpp" "include/*/*.hpp" "include/*/*/*.hpp")
|
||||||
find_package(httplib CONFIG REQUIRED)
|
find_package(httplib CONFIG REQUIRED)
|
||||||
find_package(nlohmann_json CONFIG REQUIRED)
|
find_package(nlohmann_json CONFIG REQUIRED)
|
||||||
|
|||||||
@@ -41,12 +41,12 @@ int KillSocket(uint64_t Dead);
|
|||||||
void UUl(const std::string& R);
|
void UUl(const std::string& R);
|
||||||
void UDPSend(std::string Data);
|
void UDPSend(std::string Data);
|
||||||
bool CheckBytes(int32_t Bytes);
|
bool CheckBytes(int32_t Bytes);
|
||||||
void GameSend(std::string Data);
|
void GameSend(std::string_view 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(std::string_view 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);
|
||||||
|
|||||||
@@ -19,10 +19,3 @@ void StartProxy();
|
|||||||
void ConfigInit();
|
void ConfigInit();
|
||||||
extern bool Dev;
|
extern bool Dev;
|
||||||
|
|
||||||
struct VersionParser {
|
|
||||||
explicit VersionParser(const std::string& from_string);
|
|
||||||
std::strong_ordering operator<=>(VersionParser const& rhs) const noexcept;
|
|
||||||
bool operator==(VersionParser const& rhs) const noexcept;
|
|
||||||
std::vector<std::string> split;
|
|
||||||
std::vector<size_t> data;
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -9,5 +9,5 @@
|
|||||||
#include <span>
|
#include <span>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
std::vector<char> Comp(std::span<char> input);
|
std::vector<char> Comp(std::span<const char> input);
|
||||||
std::vector<char> DeComp(std::span<char> input);
|
std::vector<char> DeComp(std::span<const char> input);
|
||||||
|
|||||||
@@ -15,14 +15,14 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::vector<char> Comp(std::span<char> input) {
|
std::vector<char> Comp(std::span<const char> input) {
|
||||||
auto max_size = compressBound(input.size());
|
auto max_size = compressBound(input.size());
|
||||||
std::vector<char> output(max_size);
|
std::vector<char> output(max_size);
|
||||||
uLongf output_size = output.size();
|
uLongf output_size = output.size();
|
||||||
int res = compress(
|
int res = compress(
|
||||||
reinterpret_cast<Bytef*>(output.data()),
|
reinterpret_cast<Bytef*>(output.data()),
|
||||||
&output_size,
|
&output_size,
|
||||||
reinterpret_cast<Bytef*>(input.data()),
|
reinterpret_cast<const Bytef*>(input.data()),
|
||||||
static_cast<uLongf>(input.size()));
|
static_cast<uLongf>(input.size()));
|
||||||
if (res != Z_OK) {
|
if (res != Z_OK) {
|
||||||
error("zlib compress() failed: " + std::to_string(res));
|
error("zlib compress() failed: " + std::to_string(res));
|
||||||
@@ -33,7 +33,7 @@ std::vector<char> Comp(std::span<char> input) {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<char> DeComp(std::span<char> input) {
|
std::vector<char> DeComp(std::span<const char> input) {
|
||||||
std::vector<char> output_buffer(std::min<size_t>(input.size() * 5, 15 * 1024 * 1024));
|
std::vector<char> output_buffer(std::min<size_t>(input.size() * 5, 15 * 1024 * 1024));
|
||||||
|
|
||||||
uLongf output_size = output_buffer.size();
|
uLongf output_size = output_buffer.size();
|
||||||
|
|||||||
@@ -48,8 +48,8 @@ void ConfigInit() {
|
|||||||
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 {
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ std::string GetGamePath() {
|
|||||||
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 + "\\";
|
||||||
|
info("Game user path: '" + Path + "'");
|
||||||
return Path;
|
return Path;
|
||||||
}
|
}
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
@@ -63,6 +64,7 @@ std::string GetGamePath() {
|
|||||||
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 + "/";
|
||||||
|
info("Game user path: '" + Path + "'");
|
||||||
return Path;
|
return Path;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ bool Terminate = false;
|
|||||||
bool LoginAuth = false;
|
bool LoginAuth = false;
|
||||||
std::string Username = "";
|
std::string Username = "";
|
||||||
std::string UserRole = "";
|
std::string UserRole = "";
|
||||||
|
int UserID = -1;
|
||||||
std::string UlStatus;
|
std::string UlStatus;
|
||||||
std::string MStatus;
|
std::string MStatus;
|
||||||
bool ModLoaded;
|
bool ModLoaded;
|
||||||
@@ -180,6 +181,9 @@ void Parse(std::string Data, SOCKET CSocket) {
|
|||||||
if (!UserRole.empty()) {
|
if (!UserRole.empty()) {
|
||||||
Auth["role"] = UserRole;
|
Auth["role"] = UserRole;
|
||||||
}
|
}
|
||||||
|
if (UserID != -1) {
|
||||||
|
Auth["id"] = UserID;
|
||||||
|
}
|
||||||
Data = "N" + Auth.dump();
|
Data = "N" + Auth.dump();
|
||||||
} else {
|
} else {
|
||||||
Data = "N" + Login(Data.substr(Data.find(':') + 1));
|
Data = "N" + Login(Data.substr(Data.find(':') + 1));
|
||||||
@@ -230,8 +234,7 @@ void GameHandler(SOCKET Client) {
|
|||||||
if (Temp < 1)
|
if (Temp < 1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
std::thread Respond(Parse, Ret, Client);
|
Parse(Ret, Client);
|
||||||
Respond.detach();
|
|
||||||
} while (Temp > 0);
|
} while (Temp > 0);
|
||||||
if (Temp == 0) {
|
if (Temp == 0) {
|
||||||
debug("(Core) Connection closing");
|
debug("(Core) Connection closing");
|
||||||
@@ -266,7 +269,7 @@ void CoreMain() {
|
|||||||
|
|
||||||
ZeroMemory(&hints, sizeof(hints));
|
ZeroMemory(&hints, sizeof(hints));
|
||||||
|
|
||||||
hints.ai_family = AF_INET;
|
hints.ai_family = AF_UNSPEC;
|
||||||
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;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "IPRegex.h"
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
@@ -19,8 +20,9 @@
|
|||||||
#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)
|
if (!std::regex_match(IP, IP_REGEX)) {
|
||||||
return IP;
|
return IP;
|
||||||
|
}
|
||||||
hostent* host;
|
hostent* host;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
@@ -40,4 +42,4 @@ std::string GetAddr(const std::string& IP) {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,13 +56,12 @@ bool CheckBytes(uint32_t Bytes) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameSend(std::string Data) {
|
void GameSend(std::string_view Data) {
|
||||||
static std::mutex Lock;
|
static std::mutex Lock;
|
||||||
std::scoped_lock Guard(Lock);
|
std::scoped_lock Guard(Lock);
|
||||||
if (TCPTerminate || !GConnected || CSocket == -1)
|
if (TCPTerminate || !GConnected || CSocket == -1)
|
||||||
return;
|
return;
|
||||||
int32_t Size, Temp, Sent;
|
int32_t Size, Temp, Sent;
|
||||||
Data += '\n';
|
|
||||||
Size = int32_t(Data.size());
|
Size = int32_t(Data.size());
|
||||||
Sent = 0;
|
Sent = 0;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@@ -78,6 +77,11 @@ void GameSend(std::string Data) {
|
|||||||
return;
|
return;
|
||||||
Sent += Temp;
|
Sent += Temp;
|
||||||
} while (Sent < Size);
|
} while (Sent < Size);
|
||||||
|
// send separately to avoid an allocation for += "\n"
|
||||||
|
Temp = send(CSocket, "\n", 1, 0);
|
||||||
|
if (!CheckBytes(Temp)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void ServerSend(std::string Data, bool Rel) {
|
void ServerSend(std::string Data, bool Rel) {
|
||||||
if (Terminate || Data.empty())
|
if (Terminate || Data.empty())
|
||||||
@@ -152,7 +156,7 @@ SOCKET SetupListener() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
ZeroMemory(&hints, sizeof(hints));
|
ZeroMemory(&hints, sizeof(hints));
|
||||||
hints.ai_family = AF_INET;
|
hints.ai_family = AF_UNSPEC;
|
||||||
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;
|
||||||
@@ -194,7 +198,7 @@ void AutoPing() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
int ClientID = -1;
|
int ClientID = -1;
|
||||||
void ParserAsync(const std::string& Data) {
|
void ParserAsync(std::string_view Data) {
|
||||||
if (Data.empty())
|
if (Data.empty())
|
||||||
return;
|
return;
|
||||||
char Code = Data.at(0), SubCode = 0;
|
char Code = Data.at(0), SubCode = 0;
|
||||||
@@ -217,7 +221,7 @@ void ParserAsync(const std::string& Data) {
|
|||||||
}
|
}
|
||||||
GameSend(Data);
|
GameSend(Data);
|
||||||
}
|
}
|
||||||
void ServerParser(const std::string& Data) {
|
void ServerParser(std::string_view Data) {
|
||||||
ParserAsync(Data);
|
ParserAsync(Data);
|
||||||
}
|
}
|
||||||
void NetMain(const std::string& IP, int Port) {
|
void NetMain(const std::string& IP, int Port) {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
///
|
///
|
||||||
/// Created by Anonymous275 on 7/18/2020
|
/// Created by Anonymous275 on 7/18/2020
|
||||||
///
|
///
|
||||||
#define CPPHTTPLIB_OPENSSL_SUPPORT
|
|
||||||
|
|
||||||
#include "Http.h"
|
#include "Http.h"
|
||||||
#include <Logger.h>
|
#include <Logger.h>
|
||||||
|
|||||||
@@ -169,16 +169,16 @@ void MultiKill(SOCKET Sock, SOCKET Sock1) {
|
|||||||
Terminate = true;
|
Terminate = true;
|
||||||
}
|
}
|
||||||
SOCKET InitDSock() {
|
SOCKET InitDSock() {
|
||||||
SOCKET DSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
SOCKET DSock = socket(AF_UNSPEC, 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;
|
||||||
}
|
}
|
||||||
ServerAddr.sin_family = AF_INET;
|
ServerAddr.sin_family = AF_UNSPEC;
|
||||||
ServerAddr.sin_port = htons(LastPort);
|
ServerAddr.sin_port = htons(LastPort);
|
||||||
inet_pton(AF_INET, LastIP.c_str(), &ServerAddr.sin_addr);
|
inet_pton(AF_UNSPEC, 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;
|
||||||
@@ -296,13 +296,14 @@ void SyncResources(SOCKET Sock) {
|
|||||||
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 modname = 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 : modname) {
|
||||||
c = ::tolower(c);
|
c = ::tolower(c);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
auto name = GetGamePath() + "mods/multiplayer" + modname;
|
||||||
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);
|
||||||
|
|||||||
@@ -14,14 +14,13 @@
|
|||||||
#include "linuxfixes.h"
|
#include "linuxfixes.h"
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <errno.h>
|
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <set>
|
#include <array>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
SOCKET UDPSock = -1;
|
SOCKET UDPSock = -1;
|
||||||
@@ -48,13 +47,15 @@ void SendLarge(std::string Data) {
|
|||||||
TCPSend(Data, TCPSock);
|
TCPSend(Data, TCPSock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDPParser(std::string Packet) {
|
void UDPParser(std::string_view Packet) {
|
||||||
if (Packet.substr(0, 4) == "ABG:") {
|
if (Packet.substr(0, 4) == "ABG:") {
|
||||||
auto substr = Packet.substr(4);
|
auto substr = Packet.substr(4);
|
||||||
auto res = DeComp(std::span<char>(substr.data(), substr.size()));
|
auto res = DeComp(std::span<const char>(substr.data(), substr.size()));
|
||||||
Packet = std::string(res.data(), res.size());
|
std::string DeCompPacket = std::string(res.data(), res.size());
|
||||||
|
ServerParser(DeCompPacket);
|
||||||
|
} else {
|
||||||
|
ServerParser(Packet);
|
||||||
}
|
}
|
||||||
ServerParser(Packet);
|
|
||||||
}
|
}
|
||||||
void UDPRcv() {
|
void UDPRcv() {
|
||||||
sockaddr_in FromServer {};
|
sockaddr_in FromServer {};
|
||||||
@@ -64,13 +65,14 @@ void UDPRcv() {
|
|||||||
socklen_t clientLength = sizeof(FromServer);
|
socklen_t clientLength = sizeof(FromServer);
|
||||||
#endif
|
#endif
|
||||||
ZeroMemory(&FromServer, clientLength);
|
ZeroMemory(&FromServer, clientLength);
|
||||||
std::string Ret(10240, 0);
|
static thread_local std::array<char, 10240> Ret {};
|
||||||
if (UDPSock == -1)
|
if (UDPSock == -1)
|
||||||
return;
|
return;
|
||||||
int32_t Rcv = recvfrom(UDPSock, &Ret[0], 10240, 0, (sockaddr*)&FromServer, &clientLength);
|
int32_t Rcv = recvfrom(UDPSock, Ret.data(), Ret.size() - 1, 0, (sockaddr*)&FromServer, &clientLength);
|
||||||
if (Rcv == SOCKET_ERROR)
|
if (Rcv == SOCKET_ERROR)
|
||||||
return;
|
return;
|
||||||
UDPParser(Ret.substr(0, Rcv));
|
Ret[Rcv] = 0;
|
||||||
|
UDPParser(std::string_view(Ret.data(), Rcv));
|
||||||
}
|
}
|
||||||
void UDPClientMain(const std::string& IP, int Port) {
|
void UDPClientMain(const std::string& IP, int Port) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -83,10 +85,10 @@ void UDPClientMain(const std::string& IP, int Port) {
|
|||||||
|
|
||||||
delete ToServer;
|
delete ToServer;
|
||||||
ToServer = new sockaddr_in;
|
ToServer = new sockaddr_in;
|
||||||
ToServer->sin_family = AF_INET;
|
ToServer->sin_family = AF_UNSPEC;
|
||||||
ToServer->sin_port = htons(Port);
|
ToServer->sin_port = htons(Port);
|
||||||
inet_pton(AF_INET, IP.c_str(), &ToServer->sin_addr);
|
inet_pton(AF_UNSPEC, IP.c_str(), &ToServer->sin_addr);
|
||||||
UDPSock = socket(AF_INET, SOCK_DGRAM, 0);
|
UDPSock = socket(AF_UNSPEC, 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");
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ void TCPClientMain(const std::string& IP, int Port) {
|
|||||||
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_UNSPEC, 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());
|
||||||
@@ -142,9 +142,9 @@ void TCPClientMain(const std::string& IP, int Port) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerAddr.sin_family = AF_INET;
|
ServerAddr.sin_family = AF_UNSPEC;
|
||||||
ServerAddr.sin_port = htons(Port);
|
ServerAddr.sin_port = htons(Port);
|
||||||
inet_pton(AF_INET, IP.c_str(), &ServerAddr.sin_addr);
|
inet_pton(AF_UNSPEC, 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!";
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ std::string PrivateKey;
|
|||||||
extern bool LoginAuth;
|
extern bool LoginAuth;
|
||||||
extern std::string Username;
|
extern std::string Username;
|
||||||
extern std::string UserRole;
|
extern std::string UserRole;
|
||||||
|
extern int UserID;
|
||||||
|
|
||||||
void UpdateKey(const char* newKey) {
|
void UpdateKey(const char* newKey) {
|
||||||
if (newKey && std::isalnum(newKey[0])) {
|
if (newKey && std::isalnum(newKey[0])) {
|
||||||
@@ -48,6 +49,7 @@ std::string Login(const std::string& fields) {
|
|||||||
if (fields == "LO") {
|
if (fields == "LO") {
|
||||||
Username = "";
|
Username = "";
|
||||||
UserRole = "";
|
UserRole = "";
|
||||||
|
UserID = -1;
|
||||||
LoginAuth = false;
|
LoginAuth = false;
|
||||||
UpdateKey(nullptr);
|
UpdateKey(nullptr);
|
||||||
return "";
|
return "";
|
||||||
@@ -74,6 +76,9 @@ 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("id")) {
|
||||||
|
UserID = d["id"].get<int>();
|
||||||
|
}
|
||||||
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());
|
||||||
}
|
}
|
||||||
@@ -129,6 +134,9 @@ void CheckLocalKey() {
|
|||||||
if (d.contains("role")) {
|
if (d.contains("role")) {
|
||||||
UserRole = d["role"].get<std::string>();
|
UserRole = d["role"].get<std::string>();
|
||||||
}
|
}
|
||||||
|
if (d.contains("id")) {
|
||||||
|
UserID = d["id"].get<int>();
|
||||||
|
}
|
||||||
// info(Role);
|
// info(Role);
|
||||||
} else {
|
} else {
|
||||||
info("Auto-Authentication unsuccessful please re-login!");
|
info("Auto-Authentication unsuccessful please re-login!");
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
#include "zip_file.h"
|
#include "zip_file.h"
|
||||||
|
#include <charconv>
|
||||||
#include <httplib.h>
|
#include <httplib.h>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -31,36 +32,44 @@ int ProxyPort = 0;
|
|||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
VersionParser::VersionParser(const std::string& from_string) {
|
struct Version {
|
||||||
std::string token;
|
uint8_t major;
|
||||||
std::istringstream tokenStream(from_string);
|
uint8_t minor;
|
||||||
while (std::getline(tokenStream, token, '.')) {
|
uint8_t patch;
|
||||||
data.emplace_back(std::stol(token));
|
Version(uint8_t major, uint8_t minor, uint8_t patch);
|
||||||
split.emplace_back(token);
|
Version(const std::array<uint8_t, 3>& v);
|
||||||
|
};
|
||||||
|
|
||||||
|
std::array<uint8_t, 3> VersionStrToInts(const std::string& str) {
|
||||||
|
std::array<uint8_t, 3> Version;
|
||||||
|
std::stringstream ss(str);
|
||||||
|
for (uint8_t& i : Version) {
|
||||||
|
std::string Part;
|
||||||
|
std::getline(ss, Part, '.');
|
||||||
|
std::from_chars(&*Part.begin(), &*Part.begin() + Part.size(), i);
|
||||||
|
}
|
||||||
|
return Version;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsOutdated(const Version& Current, const Version& Newest) {
|
||||||
|
if (Newest.major > Current.major) {
|
||||||
|
return true;
|
||||||
|
} else if (Newest.major == Current.major && Newest.minor > Current.minor) {
|
||||||
|
return true;
|
||||||
|
} else if (Newest.major == Current.major && Newest.minor == Current.minor && Newest.patch > Current.patch) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::strong_ordering VersionParser::operator<=>(
|
Version::Version(uint8_t major, uint8_t minor, uint8_t patch)
|
||||||
const VersionParser& rhs) const noexcept {
|
: major(major)
|
||||||
size_t const fields = std::min(data.size(), rhs.data.size());
|
, minor(minor)
|
||||||
for (size_t i = 0; i != fields; ++i) {
|
, patch(patch) { }
|
||||||
if (data[i] == rhs.data[i])
|
|
||||||
continue;
|
|
||||||
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;
|
|
||||||
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 {
|
Version::Version(const std::array<uint8_t, 3>& v)
|
||||||
return std::is_eq(*this <=> rhs);
|
: Version(v[0], v[1], v[2]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetEN() {
|
std::string GetEN() {
|
||||||
@@ -75,7 +84,7 @@ std::string GetVer() {
|
|||||||
return "2.0";
|
return "2.0";
|
||||||
}
|
}
|
||||||
std::string GetPatch() {
|
std::string GetPatch() {
|
||||||
return ".85";
|
return ".99";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetEP(char* P) {
|
std::string GetEP(char* P) {
|
||||||
@@ -163,7 +172,7 @@ void CheckForUpdates(int argc, char* args[], const std::string& CV) {
|
|||||||
system("clear");
|
system("clear");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (FileHash != LatestHash && VersionParser(LatestVersion) > VersionParser(GetVer() + GetPatch())) {
|
if (FileHash != LatestHash && IsOutdated(Version(VersionStrToInts(GetVer() + GetPatch())), Version(VersionStrToInts(LatestVersion))) && !Dev) {
|
||||||
info("Launcher update found!");
|
info("Launcher update found!");
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
error("Auto update is NOT implemented for the Linux version. Please update manually ASAP as updates contain security patches.");
|
error("Auto update is NOT implemented for the Linux version. Please update manually ASAP as updates contain security patches.");
|
||||||
@@ -177,7 +186,7 @@ void CheckForUpdates(int argc, char* args[], const std::string& CV) {
|
|||||||
+ PublicKey + "&branch=" + Branch,
|
+ PublicKey + "&branch=" + Branch,
|
||||||
EP);
|
EP);
|
||||||
URelaunch(argc, args);
|
URelaunch(argc, args);
|
||||||
#endif
|
#endif
|
||||||
} else
|
} else
|
||||||
info("Launcher version is up to date");
|
info("Launcher version is up to date");
|
||||||
TraceBack++;
|
TraceBack++;
|
||||||
|
|||||||
Reference in New Issue
Block a user