mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-03 06:16:15 +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")
|
||||
|
||||
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)
|
||||
|
||||
@@ -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));
|
||||
@@ -265,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -85,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!");
|
||||
|
||||
Reference in New Issue
Block a user