mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-03 06:16:15 +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")
|
||||
|
||||
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")
|
||||
find_package(httplib CONFIG REQUIRED)
|
||||
find_package(nlohmann_json CONFIG REQUIRED)
|
||||
|
||||
@@ -41,12 +41,12 @@ int KillSocket(uint64_t Dead);
|
||||
void UUl(const std::string& R);
|
||||
void UDPSend(std::string Data);
|
||||
bool CheckBytes(int32_t Bytes);
|
||||
void GameSend(std::string Data);
|
||||
void GameSend(std::string_view Data);
|
||||
void SendLarge(std::string Data);
|
||||
std::string TCPRcv(uint64_t Sock);
|
||||
void SyncResources(uint64_t TCPSock);
|
||||
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);
|
||||
void TCPSend(const std::string& Data, uint64_t Sock);
|
||||
void TCPClientMain(const std::string& IP, int Port);
|
||||
|
||||
@@ -19,10 +19,3 @@ void StartProxy();
|
||||
void ConfigInit();
|
||||
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 <vector>
|
||||
|
||||
std::vector<char> Comp(std::span<char> input);
|
||||
std::vector<char> DeComp(std::span<char> input);
|
||||
std::vector<char> Comp(std::span<const char> input);
|
||||
std::vector<char> DeComp(std::span<const char> input);
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
#include <cstring>
|
||||
#endif
|
||||
|
||||
std::vector<char> Comp(std::span<char> input) {
|
||||
std::vector<char> Comp(std::span<const char> input) {
|
||||
auto max_size = compressBound(input.size());
|
||||
std::vector<char> output(max_size);
|
||||
uLongf output_size = output.size();
|
||||
int res = compress(
|
||||
reinterpret_cast<Bytef*>(output.data()),
|
||||
&output_size,
|
||||
reinterpret_cast<Bytef*>(input.data()),
|
||||
reinterpret_cast<const Bytef*>(input.data()),
|
||||
static_cast<uLongf>(input.size()));
|
||||
if (res != Z_OK) {
|
||||
error("zlib compress() failed: " + std::to_string(res));
|
||||
@@ -33,7 +33,7 @@ std::vector<char> Comp(std::span<char> input) {
|
||||
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));
|
||||
|
||||
uLongf output_size = output_buffer.size();
|
||||
|
||||
@@ -48,8 +48,8 @@ void ConfigInit() {
|
||||
if (cfg.is_open()) {
|
||||
cfg <<
|
||||
R"({
|
||||
"Port": 4444,
|
||||
"Build": "Default"
|
||||
"Port": 4444,
|
||||
"Build": "Default"
|
||||
})";
|
||||
cfg.close();
|
||||
} else {
|
||||
|
||||
@@ -51,6 +51,7 @@ std::string GetGamePath() {
|
||||
std::string Ver = CheckVer(GetGameDir());
|
||||
Ver = Ver.substr(0, Ver.find('.', Ver.find('.') + 1));
|
||||
Path += Ver + "\\";
|
||||
info("Game user path: '" + Path + "'");
|
||||
return Path;
|
||||
}
|
||||
#elif defined(__linux__)
|
||||
@@ -63,6 +64,7 @@ std::string GetGamePath() {
|
||||
std::string Ver = CheckVer(GetGameDir());
|
||||
Ver = Ver.substr(0, Ver.find('.', Ver.find('.') + 1));
|
||||
Path += Ver + "/";
|
||||
info("Game user path: '" + Path + "'");
|
||||
return Path;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -39,6 +39,7 @@ bool Terminate = false;
|
||||
bool LoginAuth = false;
|
||||
std::string Username = "";
|
||||
std::string UserRole = "";
|
||||
int UserID = -1;
|
||||
std::string UlStatus;
|
||||
std::string MStatus;
|
||||
bool ModLoaded;
|
||||
@@ -180,6 +181,9 @@ void Parse(std::string Data, SOCKET CSocket) {
|
||||
if (!UserRole.empty()) {
|
||||
Auth["role"] = UserRole;
|
||||
}
|
||||
if (UserID != -1) {
|
||||
Auth["id"] = UserID;
|
||||
}
|
||||
Data = "N" + Auth.dump();
|
||||
} else {
|
||||
Data = "N" + Login(Data.substr(Data.find(':') + 1));
|
||||
@@ -230,8 +234,7 @@ void GameHandler(SOCKET Client) {
|
||||
if (Temp < 1)
|
||||
break;
|
||||
|
||||
std::thread Respond(Parse, Ret, Client);
|
||||
Respond.detach();
|
||||
Parse(Ret, Client);
|
||||
} while (Temp > 0);
|
||||
if (Temp == 0) {
|
||||
debug("(Core) Connection closing");
|
||||
@@ -266,7 +269,7 @@ void CoreMain() {
|
||||
|
||||
ZeroMemory(&hints, sizeof(hints));
|
||||
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = IPPROTO_TCP;
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
///
|
||||
|
||||
#include <string>
|
||||
#include "IPRegex.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <winsock2.h>
|
||||
@@ -19,8 +20,9 @@
|
||||
#include "Logger.h"
|
||||
|
||||
std::string GetAddr(const std::string& IP) {
|
||||
if (IP.find_first_not_of("0123456789.") == -1)
|
||||
if (!std::regex_match(IP, IP_REGEX)) {
|
||||
return IP;
|
||||
}
|
||||
hostent* host;
|
||||
#ifdef _WIN32
|
||||
WSADATA wsaData;
|
||||
@@ -40,4 +42,4 @@ std::string GetAddr(const std::string& IP) {
|
||||
std::string Ret = inet_ntoa(*((struct in_addr*)host->h_addr));
|
||||
WSACleanup();
|
||||
return Ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,13 +56,12 @@ bool CheckBytes(uint32_t Bytes) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void GameSend(std::string Data) {
|
||||
void GameSend(std::string_view Data) {
|
||||
static std::mutex Lock;
|
||||
std::scoped_lock Guard(Lock);
|
||||
if (TCPTerminate || !GConnected || CSocket == -1)
|
||||
return;
|
||||
int32_t Size, Temp, Sent;
|
||||
Data += '\n';
|
||||
Size = int32_t(Data.size());
|
||||
Sent = 0;
|
||||
#ifdef DEBUG
|
||||
@@ -78,6 +77,11 @@ void GameSend(std::string Data) {
|
||||
return;
|
||||
Sent += Temp;
|
||||
} 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) {
|
||||
if (Terminate || Data.empty())
|
||||
@@ -152,7 +156,7 @@ SOCKET SetupListener() {
|
||||
#endif
|
||||
|
||||
ZeroMemory(&hints, sizeof(hints));
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = IPPROTO_TCP;
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
@@ -194,7 +198,7 @@ void AutoPing() {
|
||||
}
|
||||
}
|
||||
int ClientID = -1;
|
||||
void ParserAsync(const std::string& Data) {
|
||||
void ParserAsync(std::string_view Data) {
|
||||
if (Data.empty())
|
||||
return;
|
||||
char Code = Data.at(0), SubCode = 0;
|
||||
@@ -217,7 +221,7 @@ void ParserAsync(const std::string& Data) {
|
||||
}
|
||||
GameSend(Data);
|
||||
}
|
||||
void ServerParser(const std::string& Data) {
|
||||
void ServerParser(std::string_view Data) {
|
||||
ParserAsync(Data);
|
||||
}
|
||||
void NetMain(const std::string& IP, int Port) {
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
///
|
||||
/// Created by Anonymous275 on 7/18/2020
|
||||
///
|
||||
#define CPPHTTPLIB_OPENSSL_SUPPORT
|
||||
|
||||
#include "Http.h"
|
||||
#include <Logger.h>
|
||||
|
||||
@@ -169,16 +169,16 @@ void MultiKill(SOCKET Sock, SOCKET Sock1) {
|
||||
Terminate = true;
|
||||
}
|
||||
SOCKET InitDSock() {
|
||||
SOCKET DSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
SOCKET DSock = socket(AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP);
|
||||
SOCKADDR_IN ServerAddr;
|
||||
if (DSock < 1) {
|
||||
KillSocket(DSock);
|
||||
Terminate = true;
|
||||
return 0;
|
||||
}
|
||||
ServerAddr.sin_family = AF_INET;
|
||||
ServerAddr.sin_family = AF_UNSPEC;
|
||||
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) {
|
||||
KillSocket(DSock);
|
||||
Terminate = true;
|
||||
@@ -296,13 +296,14 @@ void SyncResources(SOCKET Sock) {
|
||||
if (!fs::exists(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__)
|
||||
// Linux version of the game doesnt support uppercase letters in mod names
|
||||
for (char& c : name) {
|
||||
for (char& c : modname) {
|
||||
c = ::tolower(c);
|
||||
}
|
||||
#endif
|
||||
auto name = GetGamePath() + "mods/multiplayer" + modname;
|
||||
auto tmp_name = name + ".tmp";
|
||||
fs::copy_file(a, tmp_name, fs::copy_options::overwrite_existing);
|
||||
fs::rename(tmp_name, name);
|
||||
|
||||
@@ -14,14 +14,13 @@
|
||||
#include "linuxfixes.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <cstring>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include "Logger.h"
|
||||
#include <set>
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
SOCKET UDPSock = -1;
|
||||
@@ -48,13 +47,15 @@ void SendLarge(std::string Data) {
|
||||
TCPSend(Data, TCPSock);
|
||||
}
|
||||
|
||||
void UDPParser(std::string Packet) {
|
||||
void UDPParser(std::string_view Packet) {
|
||||
if (Packet.substr(0, 4) == "ABG:") {
|
||||
auto substr = Packet.substr(4);
|
||||
auto res = DeComp(std::span<char>(substr.data(), substr.size()));
|
||||
Packet = std::string(res.data(), res.size());
|
||||
auto res = DeComp(std::span<const char>(substr.data(), substr.size()));
|
||||
std::string DeCompPacket = std::string(res.data(), res.size());
|
||||
ServerParser(DeCompPacket);
|
||||
} else {
|
||||
ServerParser(Packet);
|
||||
}
|
||||
ServerParser(Packet);
|
||||
}
|
||||
void UDPRcv() {
|
||||
sockaddr_in FromServer {};
|
||||
@@ -64,13 +65,14 @@ void UDPRcv() {
|
||||
socklen_t clientLength = sizeof(FromServer);
|
||||
#endif
|
||||
ZeroMemory(&FromServer, clientLength);
|
||||
std::string Ret(10240, 0);
|
||||
static thread_local std::array<char, 10240> Ret {};
|
||||
if (UDPSock == -1)
|
||||
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)
|
||||
return;
|
||||
UDPParser(Ret.substr(0, Rcv));
|
||||
Ret[Rcv] = 0;
|
||||
UDPParser(std::string_view(Ret.data(), Rcv));
|
||||
}
|
||||
void UDPClientMain(const std::string& IP, int Port) {
|
||||
#ifdef _WIN32
|
||||
@@ -83,10 +85,10 @@ void UDPClientMain(const std::string& IP, int Port) {
|
||||
|
||||
delete ToServer;
|
||||
ToServer = new sockaddr_in;
|
||||
ToServer->sin_family = AF_INET;
|
||||
ToServer->sin_family = AF_UNSPEC;
|
||||
ToServer->sin_port = htons(Port);
|
||||
inet_pton(AF_INET, IP.c_str(), &ToServer->sin_addr);
|
||||
UDPSock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
inet_pton(AF_UNSPEC, IP.c_str(), &ToServer->sin_addr);
|
||||
UDPSock = socket(AF_UNSPEC, SOCK_DGRAM, 0);
|
||||
GameSend("P" + std::to_string(ClientID));
|
||||
TCPSend("H", TCPSock);
|
||||
UDPSend("p");
|
||||
|
||||
@@ -134,7 +134,7 @@ void TCPClientMain(const std::string& IP, int Port) {
|
||||
WSADATA wsaData;
|
||||
WSAStartup(514, &wsaData); // 2.2
|
||||
#endif
|
||||
TCPSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
TCPSock = socket(AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP);
|
||||
|
||||
if (TCPSock == -1) {
|
||||
printf("Client: socket failed! Error code: %d\n", WSAGetLastError());
|
||||
@@ -142,9 +142,9 @@ void TCPClientMain(const std::string& IP, int Port) {
|
||||
return;
|
||||
}
|
||||
|
||||
ServerAddr.sin_family = AF_INET;
|
||||
ServerAddr.sin_family = AF_UNSPEC;
|
||||
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));
|
||||
if (RetCode != 0) {
|
||||
UlStatus = "UlConnection Failed!";
|
||||
|
||||
@@ -18,6 +18,7 @@ std::string PrivateKey;
|
||||
extern bool LoginAuth;
|
||||
extern std::string Username;
|
||||
extern std::string UserRole;
|
||||
extern int UserID;
|
||||
|
||||
void UpdateKey(const char* newKey) {
|
||||
if (newKey && std::isalnum(newKey[0])) {
|
||||
@@ -48,6 +49,7 @@ std::string Login(const std::string& fields) {
|
||||
if (fields == "LO") {
|
||||
Username = "";
|
||||
UserRole = "";
|
||||
UserID = -1;
|
||||
LoginAuth = false;
|
||||
UpdateKey(nullptr);
|
||||
return "";
|
||||
@@ -74,6 +76,9 @@ std::string Login(const std::string& fields) {
|
||||
if (d.contains("role")) {
|
||||
UserRole = d["role"].get<std::string>();
|
||||
}
|
||||
if (d.contains("id")) {
|
||||
UserID = d["id"].get<int>();
|
||||
}
|
||||
if (d.contains("private_key")) {
|
||||
UpdateKey(d["private_key"].get<std::string>().c_str());
|
||||
}
|
||||
@@ -129,6 +134,9 @@ void CheckLocalKey() {
|
||||
if (d.contains("role")) {
|
||||
UserRole = d["role"].get<std::string>();
|
||||
}
|
||||
if (d.contains("id")) {
|
||||
UserID = d["id"].get<int>();
|
||||
}
|
||||
// info(Role);
|
||||
} else {
|
||||
info("Auto-Authentication unsuccessful please re-login!");
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
///
|
||||
|
||||
#include "zip_file.h"
|
||||
#include <charconv>
|
||||
#include <httplib.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <string>
|
||||
@@ -31,36 +32,44 @@ int ProxyPort = 0;
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
VersionParser::VersionParser(const std::string& from_string) {
|
||||
std::string token;
|
||||
std::istringstream tokenStream(from_string);
|
||||
while (std::getline(tokenStream, token, '.')) {
|
||||
data.emplace_back(std::stol(token));
|
||||
split.emplace_back(token);
|
||||
struct Version {
|
||||
uint8_t major;
|
||||
uint8_t minor;
|
||||
uint8_t patch;
|
||||
Version(uint8_t major, uint8_t minor, uint8_t patch);
|
||||
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<=>(
|
||||
const VersionParser& rhs) const noexcept {
|
||||
size_t const fields = std::min(data.size(), rhs.data.size());
|
||||
for (size_t i = 0; i != fields; ++i) {
|
||||
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;
|
||||
}
|
||||
Version::Version(uint8_t major, uint8_t minor, uint8_t patch)
|
||||
: major(major)
|
||||
, minor(minor)
|
||||
, patch(patch) { }
|
||||
|
||||
bool VersionParser::operator==(const VersionParser& rhs) const noexcept {
|
||||
return std::is_eq(*this <=> rhs);
|
||||
Version::Version(const std::array<uint8_t, 3>& v)
|
||||
: Version(v[0], v[1], v[2]) {
|
||||
}
|
||||
|
||||
std::string GetEN() {
|
||||
@@ -75,7 +84,7 @@ std::string GetVer() {
|
||||
return "2.0";
|
||||
}
|
||||
std::string GetPatch() {
|
||||
return ".85";
|
||||
return ".99";
|
||||
}
|
||||
|
||||
std::string GetEP(char* P) {
|
||||
@@ -163,7 +172,7 @@ void CheckForUpdates(int argc, char* args[], const std::string& CV) {
|
||||
system("clear");
|
||||
#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!");
|
||||
#if defined(__linux__)
|
||||
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,
|
||||
EP);
|
||||
URelaunch(argc, args);
|
||||
#endif
|
||||
#endif
|
||||
} else
|
||||
info("Launcher version is up to date");
|
||||
TraceBack++;
|
||||
|
||||
Reference in New Issue
Block a user