reformat all

This commit is contained in:
Lion Kortlepel
2020-12-23 23:34:30 +01:00
parent 0f4c08c068
commit a944565fb9
13 changed files with 171 additions and 147 deletions

View File

@@ -6,22 +6,22 @@
/// Created by Anonymous275 on 7/31/2020
///
#include <Lua/LuaSystem.hpp>
#include "Security/Enc.h"
#include "UnixCompat.h"
#include "Curl/Http.h"
#include "Settings.h"
#include "Network.h"
#include "Json.h"
#include "Logger.h"
#include "Network.h"
#include "Security/Enc.h"
#include "Settings.h"
#include "UnixCompat.h"
#include <Lua/LuaSystem.hpp>
#include <cstring>
#include <string>
#include <thread>
#include "Json.h"
std::string GetClientInfo(const std::string& PK) {
if (!PK.empty()) {
return PostHTTP("https://auth.beammp.com/pkToUser", R"({"key":")"+PK+"\"}",true);;
return PostHTTP("https://auth.beammp.com/pkToUser", R"({"key":")" + PK + "\"}", true);
;
}
return "";
}
@@ -32,13 +32,12 @@ Client* CreateClient(SOCKET TCPSock) {
return c;
}
void ClientKick(Client* c, const std::string& R){
void ClientKick(Client* c, const std::string& R) {
info("Client kicked: " + R);
TCPSend(c, "E" + R);
CloseSocketProper(c->GetTCPSock());
}
void Authentication(SOCKET TCPSock) {
DebugPrintTID();
auto* c = CreateClient(TCPSock);
@@ -49,36 +48,36 @@ void Authentication(SOCKET TCPSock) {
if (Rc.size() > 3 && Rc.substr(0, 2) == "VC") {
Rc = Rc.substr(2);
if (Rc.length() > 4 || Rc != GetCVer()) {
ClientKick(c,"Outdated Version!");
ClientKick(c, "Outdated Version!");
return;
}
} else {
ClientKick(c,"Invalid version header!");
ClientKick(c, "Invalid version header!");
return;
}
TCPSend(c, "S");
Rc = TCPRcv(c);
if(Rc.size() > 50){
ClientKick(c,"Invalid Key!");
if (Rc.size() > 50) {
ClientKick(c, "Invalid Key!");
return;
}
Rc = GetClientInfo(Rc);
json::Document d;
d.Parse(Rc.c_str());
if(Rc == "-1" || d.HasParseError()){
ClientKick(c,"Invalid key! Please restart your game.");
if (Rc == "-1" || d.HasParseError()) {
ClientKick(c, "Invalid key! Please restart your game.");
return;
}
if(d["username"].IsString() && d["roles"].IsString() && d["guest"].IsBool()){
if (d["username"].IsString() && d["roles"].IsString() && d["guest"].IsBool()) {
c->SetName(d["username"].GetString());
c->SetRoles(d["roles"].GetString());
c->isGuest = d["guest"].GetBool();
}else{
ClientKick(c,"Invalid authentication data!");
} else {
ClientKick(c, "Invalid authentication data!");
return;
}
@@ -86,7 +85,7 @@ void Authentication(SOCKET TCPSock) {
for (auto& Cl : CI->Clients) {
if (Cl != nullptr) {
if (Cl->GetName() == c->GetName() && Cl->isGuest == c->isGuest) {
info("Old client (" +Cl->GetName()+ ") kicked: Reconnecting");
info("Old client (" + Cl->GetName() + ") kicked: Reconnecting");
CloseSocketProper(Cl->GetTCPSock());
Cl->SetStatus(-2);
break;
@@ -94,14 +93,14 @@ void Authentication(SOCKET TCPSock) {
}
}
auto arg = std::make_unique<LuaArg>(LuaArg{{c->GetName(),c->GetRoles(),c->isGuest}});
std::any Res = TriggerLuaEvent("onPlayerAuth",false,nullptr, std::move(arg), true);
auto arg = std::make_unique<LuaArg>(LuaArg { { c->GetName(), c->GetRoles(), c->isGuest } });
std::any Res = TriggerLuaEvent("onPlayerAuth", false, nullptr, std::move(arg), true);
std::string Type = Res.type().name();
if(Type.find("int") != std::string::npos && std::any_cast<int>(Res)){
ClientKick(c,"you are not allowed on the server!");
if (Type.find("int") != std::string::npos && std::any_cast<int>(Res)) {
ClientKick(c, "you are not allowed on the server!");
return;
}else if(Type.find("string") != std::string::npos){
ClientKick(c,std::any_cast<std::string>(Res));
} else if (Type.find("string") != std::string::npos) {
ClientKick(c, std::any_cast<std::string>(Res));
return;
}
if (CI->Size() < MaxPlayers) {
@@ -109,34 +108,36 @@ void Authentication(SOCKET TCPSock) {
Client& Client = *c;
CI->AddClient(std::move(c));
TCPClient(&Client);
} else ClientKick(c,"Server full!");
} else
ClientKick(c, "Server full!");
}
void HandleDownload(SOCKET TCPSock){
void HandleDownload(SOCKET TCPSock) {
char D;
if(recv(TCPSock,&D,1,0) != 1){
if (recv(TCPSock, &D, 1, 0) != 1) {
CloseSocketProper(TCPSock);
return;
}
auto ID = uint8_t(D);
for(auto& c : CI->Clients){
if(c->GetID() == ID){
for (auto& c : CI->Clients) {
if (c->GetID() == ID) {
c->SetDownSock(TCPSock);
}
}
}
void Identify(SOCKET TCPSock){
void Identify(SOCKET TCPSock) {
char Code;
if(recv(TCPSock,&Code,1,0) != 1) {
if (recv(TCPSock, &Code, 1, 0) != 1) {
CloseSocketProper(TCPSock);
return;
}
if(Code == 'C'){
if (Code == 'C') {
Authentication(TCPSock);
}else if(Code == 'D'){
} else if (Code == 'D') {
HandleDownload(TCPSock);
}else CloseSocketProper(TCPSock);
} else
CloseSocketProper(TCPSock);
}
void TCPServerMain() {