mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-07 16:26:02 +00:00
Compare commits
5 Commits
ipv6-suppo
...
95-ipv6-su
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
169b14490c | ||
|
|
a60ff48c08 | ||
|
|
da3b49aa12 | ||
|
|
e505874af9 | ||
|
|
2f0a9fba99 |
@@ -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)
|
||||||
|
|||||||
@@ -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));
|
||||||
@@ -265,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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -85,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!");
|
||||||
|
|||||||
Reference in New Issue
Block a user