mirror of
https://github.com/SantaSpeen/BeamMP-Server.git
synced 2026-04-22 00:00:13 +00:00
clang-format everything
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
///
|
||||
/// Created by Anonymous275 on 7/28/2020
|
||||
///
|
||||
#include "Security/Enc.h"
|
||||
#include "Logger.h"
|
||||
#include "CustomAssert.h"
|
||||
#include "Logger.h"
|
||||
#include "Security/Enc.h"
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
@@ -22,69 +22,75 @@ void SetValues(const std::string& Line, int Index) {
|
||||
int state = 0;
|
||||
std::string Data;
|
||||
bool Switch = false;
|
||||
if (Index > 5)Switch = true;
|
||||
if (Index > 5)
|
||||
Switch = true;
|
||||
for (char c : Line) {
|
||||
if (Switch){
|
||||
if (c == '\"')state++;
|
||||
if (state > 0 && state < 2)Data += c;
|
||||
}else{
|
||||
if (c == ' ')state++;
|
||||
if (state > 1)Data += c;
|
||||
if (Switch) {
|
||||
if (c == '\"')
|
||||
state++;
|
||||
if (state > 0 && state < 2)
|
||||
Data += c;
|
||||
} else {
|
||||
if (c == ' ')
|
||||
state++;
|
||||
if (state > 1)
|
||||
Data += c;
|
||||
}
|
||||
}
|
||||
Data = Data.substr(1);
|
||||
std::string::size_type sz;
|
||||
bool FoundTrue = std::string(Data).find("true") != std::string::npos;//searches for "true"
|
||||
bool FoundTrue = std::string(Data).find("true") != std::string::npos; //searches for "true"
|
||||
switch (Index) {
|
||||
case 1 :
|
||||
Debug = FoundTrue;//checks and sets the Debug Value
|
||||
break;
|
||||
case 2 :
|
||||
Private = FoundTrue;//checks and sets the Private Value
|
||||
break;
|
||||
case 3 :
|
||||
Port = std::stoi(Data, &sz);//sets the Port
|
||||
break;
|
||||
case 4 :
|
||||
MaxCars = std::stoi(Data, &sz);//sets the Max Car amount
|
||||
break;
|
||||
case 5 :
|
||||
MaxPlayers = std::stoi(Data, &sz); //sets the Max Amount of player
|
||||
break;
|
||||
case 6 :
|
||||
MapName = Data; //Map
|
||||
break;
|
||||
case 7 :
|
||||
ServerName = Data; //Name
|
||||
break;
|
||||
case 8 :
|
||||
ServerDesc = Data; //desc
|
||||
break;
|
||||
case 9 :
|
||||
Resource = Data; //File name
|
||||
break;
|
||||
case 10 :
|
||||
Key = Data; //File name
|
||||
default:
|
||||
break;
|
||||
case 1:
|
||||
Debug = FoundTrue; //checks and sets the Debug Value
|
||||
break;
|
||||
case 2:
|
||||
Private = FoundTrue; //checks and sets the Private Value
|
||||
break;
|
||||
case 3:
|
||||
Port = std::stoi(Data, &sz); //sets the Port
|
||||
break;
|
||||
case 4:
|
||||
MaxCars = std::stoi(Data, &sz); //sets the Max Car amount
|
||||
break;
|
||||
case 5:
|
||||
MaxPlayers = std::stoi(Data, &sz); //sets the Max Amount of player
|
||||
break;
|
||||
case 6:
|
||||
MapName = Data; //Map
|
||||
break;
|
||||
case 7:
|
||||
ServerName = Data; //Name
|
||||
break;
|
||||
case 8:
|
||||
ServerDesc = Data; //desc
|
||||
break;
|
||||
case 9:
|
||||
Resource = Data; //File name
|
||||
break;
|
||||
case 10:
|
||||
Key = Data; //File name
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::string RemoveComments(const std::string& Line){
|
||||
std::string RemoveComments(const std::string& Line) {
|
||||
std::string Return;
|
||||
for(char c : Line) {
|
||||
if(c == '#')break;
|
||||
for (char c : Line) {
|
||||
if (c == '#')
|
||||
break;
|
||||
Return += c;
|
||||
}
|
||||
return Return;
|
||||
}
|
||||
void LoadConfig(std::ifstream& IFS){
|
||||
void LoadConfig(std::ifstream& IFS) {
|
||||
Assert(IFS.is_open());
|
||||
std::string line;
|
||||
int index = 1;
|
||||
while (getline(IFS, line)) {
|
||||
index++;
|
||||
}
|
||||
if(index-1 < 11){
|
||||
if (index - 1 < 11) {
|
||||
error(Sec("Outdated/Incorrect config please remove it server will close in 5 secs"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
_Exit(0);
|
||||
@@ -94,39 +100,39 @@ void LoadConfig(std::ifstream& IFS){
|
||||
info(Sec("Config found updating values"));
|
||||
index = 1;
|
||||
while (getline(IFS, line)) {
|
||||
if(line.rfind('#', 0) != 0 && line.rfind(' ', 0) != 0){ //Checks if it starts as Comment
|
||||
if (line.rfind('#', 0) != 0 && line.rfind(' ', 0) != 0) { //Checks if it starts as Comment
|
||||
std::string CleanLine = RemoveComments(line); //Cleans it from the Comments
|
||||
SetValues(CleanLine,index); //sets the values
|
||||
SetValues(CleanLine, index); //sets the values
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
void GenerateConfig(){
|
||||
void GenerateConfig() {
|
||||
std::ofstream FileStream;
|
||||
FileStream.open (Sec("Server.cfg"));
|
||||
FileStream.open(Sec("Server.cfg"));
|
||||
FileStream << Sec("# This is the BeamMP Server Configuration File v0.60\n"
|
||||
"Debug = false # true or false to enable debug console output\n"
|
||||
"Private = false # Private?\n"
|
||||
"Port = 30814 # Port to run the server on UDP and TCP\n"
|
||||
"Cars = 1 # Max cars for every player\n"
|
||||
"MaxPlayers = 10 # Maximum Amount of Clients\n"
|
||||
"Map = \"/levels/gridmap/info.json\" # Default Map\n"
|
||||
"Name = \"BeamMP New Server\" # Server Name\n"
|
||||
"Desc = \"BeamMP Default Description\" # Server Description\n"
|
||||
"use = \"Resources\" # Resource file name\n"
|
||||
"AuthKey = \"\" # Auth Key");
|
||||
"Debug = false # true or false to enable debug console output\n"
|
||||
"Private = false # Private?\n"
|
||||
"Port = 30814 # Port to run the server on UDP and TCP\n"
|
||||
"Cars = 1 # Max cars for every player\n"
|
||||
"MaxPlayers = 10 # Maximum Amount of Clients\n"
|
||||
"Map = \"/levels/gridmap/info.json\" # Default Map\n"
|
||||
"Name = \"BeamMP New Server\" # Server Name\n"
|
||||
"Desc = \"BeamMP Default Description\" # Server Description\n"
|
||||
"use = \"Resources\" # Resource file name\n"
|
||||
"AuthKey = \"\" # Auth Key");
|
||||
FileStream.close();
|
||||
}
|
||||
void Default(){
|
||||
void Default() {
|
||||
info(Sec("Config not found generating default"));
|
||||
GenerateConfig();
|
||||
warn(Sec("You are required to input the AuthKey"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
_Exit(0);
|
||||
}
|
||||
void DebugData(){
|
||||
debug(std::string(Sec("Debug : ")) + (Debug?"true":"false"));
|
||||
debug(std::string(Sec("Private : ")) + (Private?"true":"false"));
|
||||
void DebugData() {
|
||||
debug(std::string(Sec("Debug : ")) + (Debug ? "true" : "false"));
|
||||
debug(std::string(Sec("Private : ")) + (Private ? "true" : "false"));
|
||||
debug(Sec("Port : ") + std::to_string(Port));
|
||||
debug(Sec("Max Cars : ") + std::to_string(MaxCars));
|
||||
debug(Sec("MaxPlayers : ") + std::to_string(MaxPlayers));
|
||||
@@ -136,16 +142,20 @@ void DebugData(){
|
||||
debug(Sec("File : ") + Resource);
|
||||
debug(Sec("Key length: ") + std::to_string(Key.length()));
|
||||
}
|
||||
void InitConfig(){
|
||||
void InitConfig() {
|
||||
std::ifstream IFS;
|
||||
IFS.open(Sec("Server.cfg"));
|
||||
if(IFS.good())LoadConfig(IFS);
|
||||
else Default();
|
||||
if(IFS.is_open())IFS.close();
|
||||
if(Key.empty()){
|
||||
if (IFS.good())
|
||||
LoadConfig(IFS);
|
||||
else
|
||||
Default();
|
||||
if (IFS.is_open())
|
||||
IFS.close();
|
||||
if (Key.empty()) {
|
||||
error(Sec("No AuthKey was found"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
_Exit(0);
|
||||
}
|
||||
if(Debug)DebugData();
|
||||
if (Debug)
|
||||
DebugData();
|
||||
}
|
||||
|
||||
@@ -1,82 +1,85 @@
|
||||
///
|
||||
/// Created by Anonymous275 on 7/28/2020
|
||||
///
|
||||
#include "Security/Enc.h"
|
||||
#include "Curl/Http.h"
|
||||
#include "Client.hpp"
|
||||
#include "Settings.h"
|
||||
#include "Curl/Http.h"
|
||||
#include "Logger.h"
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
#include "Security/Enc.h"
|
||||
#include "Settings.h"
|
||||
#include <chrono>
|
||||
#include <future>
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
|
||||
void WebsocketInit();
|
||||
std::string GetPlayers(){
|
||||
std::string GetPlayers() {
|
||||
std::string Return;
|
||||
for(auto& c : CI->Clients){
|
||||
if(c != nullptr){
|
||||
for (auto& c : CI->Clients) {
|
||||
if (c != nullptr) {
|
||||
Return += c->GetName() + ";";
|
||||
}
|
||||
}
|
||||
return Return;
|
||||
}
|
||||
std::string GenerateCall(){
|
||||
std::string GenerateCall() {
|
||||
std::stringstream Ret;
|
||||
Ret << "uuid=" << Key << "&players=" << CI->Size()
|
||||
<< "&maxplayers=" << MaxPlayers << "&port=" << Port
|
||||
<< "&map=" << MapName << "&private=" << (Private ? "true" : "false")
|
||||
<< "&version=" << GetSVer() << "&clientversion=" << GetCVer()
|
||||
<< "&name=" << ServerName << "&pps=" << StatReport
|
||||
<< "&modlist=" << FileList << "&modstotalsize=" << MaxModSize
|
||||
<< "&modstotal=" << ModsLoaded << "&playerslist=" << GetPlayers()
|
||||
<< "&desc=" << ServerDesc;
|
||||
<< "&maxplayers=" << MaxPlayers << "&port=" << Port
|
||||
<< "&map=" << MapName << "&private=" << (Private ? "true" : "false")
|
||||
<< "&version=" << GetSVer() << "&clientversion=" << GetCVer()
|
||||
<< "&name=" << ServerName << "&pps=" << StatReport
|
||||
<< "&modlist=" << FileList << "&modstotalsize=" << MaxModSize
|
||||
<< "&modstotal=" << ModsLoaded << "&playerslist=" << GetPlayers()
|
||||
<< "&desc=" << ServerDesc;
|
||||
return Ret.str();
|
||||
}
|
||||
std::string RunPromise(const std::string& IP, const std::string& R) {
|
||||
std::packaged_task<std::string()> task([&]() { return PostHTTP(IP,R); });
|
||||
std::packaged_task<std::string()> task([&]() { return PostHTTP(IP, R); });
|
||||
std::future<std::string> f1 = task.get_future();
|
||||
std::thread t(std::move(task));
|
||||
t.detach();
|
||||
auto status = f1.wait_for(std::chrono::seconds(10));
|
||||
if (status != std::future_status::timeout)return f1.get();
|
||||
if (status != std::future_status::timeout)
|
||||
return f1.get();
|
||||
error(Sec("Backend system Timeout please try again later"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
_Exit(0);
|
||||
}
|
||||
|
||||
void Heartbeat(){
|
||||
void Heartbeat() {
|
||||
DebugPrintTID();
|
||||
std::string R,T;
|
||||
std::string R, T;
|
||||
bool isAuth = false;
|
||||
while(true){
|
||||
while (true) {
|
||||
R = GenerateCall();
|
||||
if(!CustomIP.empty())R+="&ip="+CustomIP;
|
||||
if (!CustomIP.empty())
|
||||
R += "&ip=" + CustomIP;
|
||||
std::string link = Sec("https://beammp.com/heartbeatv2");
|
||||
T = RunPromise(link,R);
|
||||
if(T.find_first_not_of(Sec("20")) != std::string::npos){
|
||||
T = RunPromise(link, R);
|
||||
if (T.find_first_not_of(Sec("20")) != std::string::npos) {
|
||||
//Backend system refused server startup!
|
||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||
std::string Backup = Sec("https://backup1.beammp.com/heartbeatv2");
|
||||
T = RunPromise(Backup,R);
|
||||
if(T.find_first_not_of(Sec("20")) != std::string::npos) {
|
||||
T = RunPromise(Backup, R);
|
||||
if (T.find_first_not_of(Sec("20")) != std::string::npos) {
|
||||
error(Sec("Backend system refused server! Check your AuthKey"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
_Exit(-1);
|
||||
}
|
||||
}
|
||||
//Server Authenticated
|
||||
if(T.length() == 4)info(Sec("Server authenticated"));
|
||||
if (T.length() == 4)
|
||||
info(Sec("Server authenticated"));
|
||||
R.clear();
|
||||
T.clear();
|
||||
if(!isAuth){
|
||||
if (!isAuth) {
|
||||
WebsocketInit();
|
||||
isAuth = true;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
}
|
||||
}
|
||||
void HBInit(){
|
||||
void HBInit() {
|
||||
std::thread HB(Heartbeat);
|
||||
HB.detach();
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
///
|
||||
/// Created by Anonymous275 on 7/28/2020
|
||||
///
|
||||
#include "Logger.h"
|
||||
#include "Security/Enc.h"
|
||||
#include <filesystem>
|
||||
#include "Settings.h"
|
||||
#include <algorithm>
|
||||
#include "Logger.h"
|
||||
#include <filesystem>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@@ -14,22 +14,23 @@ std::string FileSizes;
|
||||
std::string FileList;
|
||||
int ModsLoaded = 0;
|
||||
|
||||
void InitRes(){
|
||||
void InitRes() {
|
||||
std::string Path = Resource + Sec("/Client");
|
||||
if(!fs::exists(Path))fs::create_directory(Path);
|
||||
for (const auto & entry : fs::directory_iterator(Path)){
|
||||
if (!fs::exists(Path))
|
||||
fs::create_directory(Path);
|
||||
for (const auto& entry : fs::directory_iterator(Path)) {
|
||||
auto pos = entry.path().string().find(Sec(".zip"));
|
||||
if(pos != std::string::npos){
|
||||
if(entry.path().string().length() - pos == 4){
|
||||
if (pos != std::string::npos) {
|
||||
if (entry.path().string().length() - pos == 4) {
|
||||
FileList += entry.path().string() + ";";
|
||||
FileSizes += std::to_string(fs::file_size(entry.path()))+";";
|
||||
FileSizes += std::to_string(fs::file_size(entry.path())) + ";";
|
||||
MaxModSize += fs::file_size(entry.path());
|
||||
ModsLoaded++;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::replace(FileList.begin(),FileList.end(),'\\','/');
|
||||
if(ModsLoaded){
|
||||
info(Sec("Loaded ")+std::to_string(ModsLoaded)+Sec(" Mods"));
|
||||
std::replace(FileList.begin(), FileList.end(), '\\', '/');
|
||||
if (ModsLoaded) {
|
||||
info(Sec("Loaded ") + std::to_string(ModsLoaded) + Sec(" Mods"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,36 @@
|
||||
///
|
||||
/// Created by Anonymous275 on 7/28/2020
|
||||
///
|
||||
#include "Security/Enc.h"
|
||||
#include "Client.hpp"
|
||||
#include "Logger.h"
|
||||
#include <string>
|
||||
#include "Security/Enc.h"
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
std::string CustomIP;
|
||||
std::string GetSVer(){
|
||||
std::string GetSVer() {
|
||||
static std::string r = Sec("1.0");
|
||||
return r;
|
||||
}
|
||||
std::string GetCVer(){
|
||||
std::string GetCVer() {
|
||||
static std::string r = Sec("1.70");
|
||||
return r;
|
||||
}
|
||||
void Args(int argc, char* argv[]){
|
||||
void Args(int argc, char* argv[]) {
|
||||
info(Sec("BeamMP Server Running version ") + GetSVer());
|
||||
if(argc > 1){
|
||||
if (argc > 1) {
|
||||
CustomIP = argv[1];
|
||||
size_t n = std::count(CustomIP.begin(), CustomIP.end(), '.');
|
||||
auto p = CustomIP.find_first_not_of(Sec(".0123456789"));
|
||||
if(p != std::string::npos || n != 3 || CustomIP.substr(0,3) == Sec("127")){
|
||||
if (p != std::string::npos || n != 3 || CustomIP.substr(0, 3) == Sec("127")) {
|
||||
CustomIP.clear();
|
||||
warn(Sec("IP Specified is invalid! Ignoring"));
|
||||
}else info(Sec("Server started with custom IP"));
|
||||
} else
|
||||
info(Sec("Server started with custom IP"));
|
||||
}
|
||||
}
|
||||
void InitServer(int argc, char* argv[]){
|
||||
void InitServer(int argc, char* argv[]) {
|
||||
InitLog();
|
||||
Args(argc,argv);
|
||||
Args(argc, argv);
|
||||
CI = std::make_unique<ClientInterface>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user