5 Commits

Author SHA1 Message Date
SaltySnail
169b14490c Added IPv6 support 2024-08-21 01:38:52 +02:00
Lion
a60ff48c08 Merge pull request #105 from WiserTixx/id-from-auth
Send id from auth to game
2024-08-17 20:34:19 +02:00
Lion
da3b49aa12 Merge pull request #106 from WiserTixx/fix-http-proxy-ub
Fix UB which was causing the http proxy to crash
2024-08-17 20:32:59 +02:00
Tixx
e505874af9 Send id from auth to game 2024-08-11 11:39:14 +02:00
Tixx
2f0a9fba99 move macro definition to cmakelist 2024-08-10 23:22:17 +02:00
9 changed files with 29 additions and 14 deletions

View File

@@ -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)

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -5,7 +5,6 @@
///
/// Created by Anonymous275 on 7/18/2020
///
#define CPPHTTPLIB_OPENSSL_SUPPORT
#include "Http.h"
#include <Logger.h>

View File

@@ -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;

View File

@@ -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");

View File

@@ -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!";

View File

@@ -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!");