1 Commits

Author SHA1 Message Date
Starystars67
7217cb1cab Update Startup.cpp 2023-12-16 03:01:28 +00:00
5 changed files with 33 additions and 103 deletions

View File

@@ -13,8 +13,6 @@ void NetReset();
extern bool Dev;
extern int ping;
extern bool ModWarningConfirmed;
[[noreturn]] void CoreNetwork();
extern int ProxyPort;
extern int ClientID;
@@ -48,4 +46,3 @@ void TCPClientMain(const std::string& IP,int Port);
void UDPClientMain(const std::string& IP,int Port);
void TCPGameServer(const std::string& IP, int Port);

View File

@@ -14,7 +14,6 @@
#include <ws2tcpip.h>
#include "Startup.h"
#include "Logger.h"
#include <nlohmann/json.hpp>
#include <charconv>
#include <thread>
#include <set>
@@ -25,8 +24,6 @@ bool TCPTerminate = false;
int DEFAULT_PORT = 4444;
bool Terminate = false;
bool LoginAuth = false;
std::string Username = "";
std::string UserRole = "";
std::string UlStatus;
std::string MStatus;
bool ModLoaded;
@@ -58,8 +55,6 @@ bool IsAllowedLink(const std::string& Link) {
return std::regex_search(Link,link_match, link_pattern) && link_match.position() == 0;
}
bool ModWarningConfirmed = false;
void Parse(std::string Data,SOCKET CSocket){
char Code = Data.at(0), SubCode = 0;
if(Data.length() > 1)SubCode = Data.at(1);
@@ -89,17 +84,6 @@ void Parse(std::string Data,SOCKET CSocket){
}
Data.clear();
break;
// response to "WMODS_FOUND" message, either Y (yes ok) or N (no)
case 'W': {
if (SubCode == 'Y') {
ModWarningConfirmed = true;
} else if (SubCode == 'N') {
ModWarningConfirmed = false;
NetReset();
Terminate = true;
TCPTerminate = true;
}
}
case 'P':
Data = Code + std::to_string(ProxyPort);
break;
@@ -142,16 +126,7 @@ void Parse(std::string Data,SOCKET CSocket){
break;
case 'N':
if (SubCode == 'c'){
nlohmann::json Auth = {
{"Auth", LoginAuth ? 1 : 0 },
};
if (!Username.empty()) {
Auth["username"] = Username;
}
if (!UserRole.empty()) {
Auth["role"] = UserRole;
}
Data = "N" + Auth.dump();
Data = "N{\"Auth\":"+std::to_string(LoginAuth)+"}";
}else{
Data = "N" + Login(Data.substr(Data.find(':') + 1));
}
@@ -218,10 +193,6 @@ void localRes(){
}
ConfList = new std::set<std::string>;
}
uint64_t TheClientSocket;
void CoreMain() {
debug("Core Network on start!");
WSADATA wsaData;
@@ -270,7 +241,6 @@ void CoreMain() {
error("(Core) accept failed with error: " + std::to_string(WSAGetLastError()));
continue;
}
TheClientSocket = CSocket;
localRes();
info("Game Connected!");
GameHandler(CSocket);

View File

@@ -21,8 +21,6 @@
#include <future>
#include <cmath>
extern SOCKET TheClientSocket;
namespace fs = std::filesystem;
std::string ListOfMods;
std::vector<std::string> Split(const std::string& String,const std::string& delimiter){
@@ -223,23 +221,6 @@ void SyncResources(SOCKET Sock){
std::string Ret = Auth(Sock);
if(Ret.empty())return;
ModWarningConfirmed = false;
Terminate = false;
std::string Data = "WMODS_FOUND";
send(TheClientSocket, (Data + "\n").c_str(), int(Data.size())+1, 0);
while (!Terminate && !ModWarningConfirmed) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
if (!ModWarningConfirmed) {
UlStatus = "UlMods rejected!";
info("Mods rejected by user!");
// game has already cancelled by now
return;
}
info("Checking Resources...");
CheckForDir();
@@ -341,4 +322,4 @@ void SyncResources(SOCKET Sock){
UlStatus = "Ulstart";
info("Connection Terminated!");
}
}
}

View File

@@ -17,8 +17,7 @@ namespace fs = std::filesystem;
std::string PublicKey;
std::string PrivateKey;
extern bool LoginAuth;
extern std::string Username;
extern std::string UserRole;
std::string Role;
void UpdateKey(const char* newKey){
if(newKey && std::isalnum(newKey[0])){
@@ -46,51 +45,39 @@ std::string GetFail(const std::string& R){
std::string Login(const std::string& fields){
if(fields == "LO"){
Username = "";
UserRole = "";
LoginAuth = false;
UpdateKey(nullptr);
return "";
}
info("Attempting to authenticate...");
try {
std::string Buffer = HTTP::Post("https://auth.beammp.com/userlogin", fields);
std::string Buffer = HTTP::Post("https://auth.beammp.com/userlogin", fields);
if(Buffer == "-1"){
return GetFail("Failed to communicate with the auth system!");
}
nlohmann::json d = nlohmann::json::parse(Buffer, nullptr, false);
if (Buffer.at(0) != '{' || d.is_discarded()) {
error(Buffer);
return GetFail("Invalid answer from authentication servers, please try again later!");
}
if(d.contains("success") && d["success"].get<bool>()){
LoginAuth = true;
if (d.contains("username")) {
Username = d["username"].get<std::string>();
}
if (d.contains("role")) {
UserRole = d["role"].get<std::string>();
}
if(d.contains("private_key")) {
UpdateKey(d["private_key"].get<std::string>().c_str());
}
if(d.contains("public_key")){
PublicKey = d["public_key"].get<std::string>();
}
info("Authentication successful!");
}else info("Authentication failed!");
if(d.contains("message")){
d.erase("private_key");
d.erase("public_key");
return d.dump();
}
return GetFail("Invalid message parsing!");
} catch (const std::exception& e) {
return GetFail(e.what());
if(Buffer == "-1"){
return GetFail("Failed to communicate with the auth system!");
}
nlohmann::json d = nlohmann::json::parse(Buffer, nullptr, false);
if (Buffer.at(0) != '{' || d.is_discarded()) {
error(Buffer);
return GetFail("Invalid answer from authentication servers, please try again later!");
}
if(d.contains("success") && d["success"].get<bool>()){
LoginAuth = true;
if(!d.contains("private_key")) {
UpdateKey(d["private_key"].get<std::string>().c_str());
}
if(!d.contains("public_key")){
PublicKey = d["public_key"].get<std::string>();
}
info("Authentication successful!");
}else info("Authentication failed!");
if(!d.contains("message")){
d.erase("private_key");
d.erase("public_key");
return d.dump();
}
return GetFail("Invalid message parsing!");
}
void CheckLocalKey(){
@@ -122,12 +109,7 @@ void CheckLocalKey(){
LoginAuth = true;
UpdateKey(d["private_key"].get<std::string>().c_str());
PublicKey = d["public_key"].get<std::string>();
if (d.contains("username")) {
Username = d["username"].get<std::string>();
}
if (d.contains("role")) {
UserRole = d["role"].get<std::string>();
}
Role = d["role"].get<std::string>();
//info(Role);
}else{
info("Auto-Authentication unsuccessful please re-login!");

View File

@@ -62,7 +62,7 @@ std::string GetVer(){
return "2.0";
}
std::string GetPatch(){
return ".85";
return ".84";
}
std::string GetEP(char*P){
@@ -272,8 +272,8 @@ void PreGame(const std::string& GamePath){
void set_headers(httplib::Response& res) {
res.set_header("Access-Control-Allow-Origin", "*");
res.set_header("Access-Control-Request-Method", "POST, OPTIONS, GET");
res.set_header("Access-Control-Request-Headers", "X-API-Version");
res.set_header("Access-Control-Allow-Headers", "X-API-Version");
res.set_header("Access-Control-Allow-Method", "GET,POST,OPTIONS");
}
void StartProxy() {