mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 15:26:59 +00:00
more cleanup
This commit is contained in:
parent
2e7f2cc6bd
commit
97d8f9506e
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 5/8/2020
|
||||
///
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/24/2020
|
||||
///
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/18/2020
|
||||
///
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 11/27/2020
|
||||
///
|
||||
|
@ -1,8 +1,12 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 4/2/2020.
|
||||
///
|
||||
#pragma once
|
||||
#include "Security/Xor.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
@ -10,7 +14,6 @@ void InitLog();
|
||||
#define DebugPrintTID() DebugPrintTIDInternal(__func__, false)
|
||||
void DebugPrintTIDInternal(const std::string& func, bool overwrite = true); // prints the current thread id in debug mode, to make tracing of crashes and asserts easier
|
||||
void ConsoleOut(const std::string& msg);
|
||||
void QueueAbort();
|
||||
void except(const std::string& toPrint);
|
||||
void debug(const std::string& toPrint);
|
||||
void error(const std::string& toPrint);
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 5/20/2020
|
||||
///
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/31/2020
|
||||
///
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/28/2020
|
||||
///
|
||||
@ -7,15 +11,5 @@
|
||||
#else
|
||||
#include <WS2tcpip.h>
|
||||
#endif
|
||||
#include "Xor.h"
|
||||
#include <string>
|
||||
struct RSA {
|
||||
int n = 0;
|
||||
int e = 0;
|
||||
int d = 0;
|
||||
};
|
||||
std::string RSA_E(const std::string& Data, int e, int n);
|
||||
std::string RSA_E(const std::string& Data, RSA* k);
|
||||
std::string RSA_D(const std::string& Data, RSA* k);
|
||||
int Handle(EXCEPTION_POINTERS* ep, char* Origin);
|
||||
RSA* GenKey();
|
||||
|
@ -1,132 +0,0 @@
|
||||
///
|
||||
/// Created by Anonymous275 on 8/11/2020
|
||||
///
|
||||
#pragma once
|
||||
#include <array>
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
||||
#define BEGIN_NAMESPACE(x) namespace x {
|
||||
#define END_NAMESPACE }
|
||||
|
||||
BEGIN_NAMESPACE(XorCompileTime)
|
||||
|
||||
constexpr auto time = __TIME__;
|
||||
constexpr auto seed = static_cast<int>(time[7]) + static_cast<int>(time[6]) * 10 + static_cast<int>(time[4]) * 60 + static_cast<int>(time[3]) * 600 + static_cast<int>(time[1]) * 3600 + static_cast<int>(time[0]) * 36000;
|
||||
|
||||
// 1988, Stephen Park and Keith Miller
|
||||
// "Random Number Generators: Good Ones Are Hard To Find", considered as "minimal standard"
|
||||
// Park-Miller 31 bit pseudo-random number generator, implemented with G. Carta's optimisation:
|
||||
// with 32-bit math and without division
|
||||
|
||||
template <int N>
|
||||
struct RandomGenerator {
|
||||
private:
|
||||
static constexpr unsigned a = 16807; // 7^5
|
||||
static constexpr unsigned m = 2147483647; // 2^31 - 1
|
||||
|
||||
static constexpr unsigned s = RandomGenerator<N - 1>::value;
|
||||
static constexpr unsigned lo = a * (s & 0xFFFFu); // Multiply lower 16 bits by 16807
|
||||
static constexpr unsigned hi = a * (s >> 16u); // Multiply higher 16 bits by 16807
|
||||
static constexpr unsigned lo2 = lo + ((hi & 0x7FFFu) << 16u); // Combine lower 15 bits of hi with lo's upper bits
|
||||
static constexpr unsigned hi2 = hi >> 15u; // Discard lower 15 bits of hi
|
||||
static constexpr unsigned lo3 = lo2 + hi;
|
||||
|
||||
public:
|
||||
static constexpr unsigned max = m;
|
||||
static constexpr unsigned value = lo3 > m ? lo3 - m : lo3;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct RandomGenerator<0> {
|
||||
static constexpr unsigned value = seed;
|
||||
};
|
||||
|
||||
template <int N, int M>
|
||||
struct RandomInt {
|
||||
static constexpr auto value = RandomGenerator<N + 1>::value % M;
|
||||
};
|
||||
|
||||
template <int N>
|
||||
struct RandomChar {
|
||||
static const char value = static_cast<char>(1 + RandomInt<N, 0x7F - 1>::value);
|
||||
};
|
||||
|
||||
template <size_t N, int K, typename Char>
|
||||
struct XorString {
|
||||
private:
|
||||
const char _key;
|
||||
std::array<Char, N + 1> _encrypted;
|
||||
|
||||
constexpr Char enc(Char c) const {
|
||||
return c ^ _key;
|
||||
}
|
||||
|
||||
Char dec(Char c) const {
|
||||
return c ^ _key;
|
||||
}
|
||||
|
||||
public:
|
||||
template <size_t... Is>
|
||||
constexpr inline XorString(const Char* str, std::index_sequence<Is...>)
|
||||
: _key(RandomChar<K>::value)
|
||||
, _encrypted { enc(str[Is])... } { }
|
||||
|
||||
inline decltype(auto) decrypt() {
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
_encrypted[i] = dec(_encrypted[i]);
|
||||
}
|
||||
_encrypted[N] = '\0';
|
||||
return _encrypted.data();
|
||||
}
|
||||
};
|
||||
|
||||
static auto w_printf = [](const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vprintf(fmt, args);
|
||||
va_end(args);
|
||||
};
|
||||
|
||||
static auto w_printf_s = [](const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vprintf(fmt, args);
|
||||
va_end(args);
|
||||
};
|
||||
|
||||
/*static auto w_sprintf = [](char* buf, const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsprintf(buf, fmt, args);
|
||||
va_end(args);
|
||||
};*/
|
||||
|
||||
/*static auto w_sprintf_ret = [](char* buf, const char* fmt, ...) {
|
||||
int ret;
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
ret = vsprintf(buf, fmt, args);
|
||||
va_end(args);
|
||||
return ret;
|
||||
};*/
|
||||
|
||||
static auto w_sprintf_s = [](char* buf, size_t buf_size, const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsnprintf(buf, buf_size, fmt, args);
|
||||
va_end(args);
|
||||
};
|
||||
|
||||
static auto w_sprintf_s_ret = [](char* buf, size_t buf_size, const char* fmt, ...) {
|
||||
int ret;
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
ret = vsnprintf(buf, buf_size, fmt, args);
|
||||
va_end(args);
|
||||
return ret;
|
||||
};
|
||||
#define Sec(s) [] { constexpr XorCompileTime::XorString< sizeof(s)/sizeof(char) - 1, __COUNTER__, char > expr( s, std::make_index_sequence< sizeof(s)/sizeof(char) - 1>() ); return expr; }().decrypt()
|
||||
#define SecW(s) [] { constexpr XorCompileTime::XorString< sizeof(s)/sizeof(wchar_t) - 1, __COUNTER__, wchar_t > expr( s, std::make_index_sequence< sizeof(s)/sizeof(wchar_t) - 1>() ); return expr; }().decrypt()
|
||||
END_NAMESPACE
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/28/2020
|
||||
///
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/28/2020
|
||||
///
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/15/2020
|
||||
///
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 10/29/2020
|
||||
///
|
||||
@ -25,11 +29,11 @@ std::mutex MLock;
|
||||
std::unique_ptr<Lua> LuaConsole;
|
||||
void HandleInput(const std::string& cmd) {
|
||||
std::cout << std::endl;
|
||||
if (cmd == Sec("exit")) {
|
||||
if (cmd == ("exit")) {
|
||||
_Exit(0);
|
||||
} else if (cmd == Sec("clear") || cmd == Sec("cls")) {
|
||||
} else if (cmd == ("clear") || cmd == ("cls")) {
|
||||
// 2J is clearscreen, H is reset position to top-left
|
||||
ConsoleOut(Sec("\x1b[2J\x1b[H"));
|
||||
ConsoleOut(("\x1b[2J\x1b[H"));
|
||||
} else {
|
||||
LuaConsole->Execute(cmd);
|
||||
}
|
||||
@ -183,7 +187,7 @@ void ReadCin() {
|
||||
if (In == 0) {
|
||||
++null_byte_counter;
|
||||
if (null_byte_counter > 50) {
|
||||
info(Sec("too many null bytes in input, this is now assumed to be a background thread - console input is now disabled"));
|
||||
info(("too many null bytes in input, this is now assumed to be a background thread - console input is now disabled"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
118
src/Enc.cpp
118
src/Enc.cpp
@ -1,102 +1,24 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/28/2020
|
||||
///
|
||||
#include "Security/Enc.h"
|
||||
#include "CustomAssert.h"
|
||||
#include "Settings.h"
|
||||
//#include <windows.h>
|
||||
#include "Logger.h"
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
|
||||
int Rand() {
|
||||
std::random_device r;
|
||||
std::default_random_engine e1(r());
|
||||
std::uniform_int_distribution<int> uniform_dist(1, 5000);
|
||||
return uniform_dist(e1);
|
||||
}
|
||||
|
||||
int log_power(int n, unsigned int p, int mod) {
|
||||
int result = 1;
|
||||
for (; p; p >>= 1u) {
|
||||
if (p & 1u)
|
||||
result = int((1LL * result * n) % mod);
|
||||
n = int((1LL * n * n) % mod);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
bool rabin_miller(int n) {
|
||||
bool ok = true;
|
||||
for (int i = 1; i <= 5 && ok; i++) {
|
||||
int a = Rand() + 1;
|
||||
int result = log_power(a, n - 1, n);
|
||||
ok &= (result == 1);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
int generate_prime() {
|
||||
int generated = Rand();
|
||||
while (!rabin_miller(generated))
|
||||
generated = Rand();
|
||||
return generated;
|
||||
}
|
||||
int gcd(int a, int b) {
|
||||
while (b) {
|
||||
int r = a % b;
|
||||
a = b;
|
||||
b = r;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
int generate_coprime(int n) {
|
||||
int generated = Rand();
|
||||
while (gcd(n, generated) != 1)
|
||||
generated = Rand();
|
||||
return generated;
|
||||
}
|
||||
|
||||
std::pair<int, int> euclid_extended(int a, int b) {
|
||||
if (!b)
|
||||
return { 1, 0 };
|
||||
auto result = euclid_extended(b, a % b);
|
||||
return { result.second, result.first - (a / b) * result.second };
|
||||
}
|
||||
|
||||
int modular_inverse(int n, int mod) {
|
||||
int inverse = euclid_extended(n, mod).first;
|
||||
while (inverse < 0)
|
||||
inverse += mod;
|
||||
return inverse;
|
||||
}
|
||||
|
||||
RSA* GenKey() {
|
||||
int p, q;
|
||||
p = generate_prime();
|
||||
q = generate_prime();
|
||||
int n = p * q;
|
||||
int phi = (p - 1) * (q - 1);
|
||||
int e = generate_coprime(phi);
|
||||
int d = modular_inverse(e, phi);
|
||||
return new RSA { n, e, d };
|
||||
}
|
||||
|
||||
int Enc(int value, int e, int n) {
|
||||
return log_power(value, e, n);
|
||||
}
|
||||
|
||||
int Dec(int value, int d, int n) {
|
||||
return log_power(value, d, n);
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
int Handle(EXCEPTION_POINTERS* ep, char* Origin) {
|
||||
//Assert(false);
|
||||
Assert(false);
|
||||
std::stringstream R;
|
||||
R << Sec("Code : ") << std::hex
|
||||
R << ("Code : ") << std::hex
|
||||
<< ep->ExceptionRecord->ExceptionCode
|
||||
<< std::dec << Sec(" Origin : ") << Origin;
|
||||
<< std::dec << (" Origin : ") << Origin;
|
||||
except(R.str());
|
||||
return 1;
|
||||
}
|
||||
@ -104,29 +26,3 @@ int Handle(EXCEPTION_POINTERS* ep, char* Origin) {
|
||||
// stub
|
||||
int Handle(EXCEPTION_POINTERS*, char*) { return 1; }
|
||||
#endif // WIN32
|
||||
|
||||
std::string RSA_E(const std::string& Data, RSA* k) {
|
||||
std::stringstream stream;
|
||||
for (const char& c : Data) {
|
||||
stream << std::hex << Enc(uint8_t(c), k->e, k->n) << "g";
|
||||
}
|
||||
return stream.str();
|
||||
}
|
||||
std::string RSA_E(const std::string& Data, int e, int n) {
|
||||
std::stringstream stream;
|
||||
for (const char& c : Data) {
|
||||
stream << std::hex << Enc(uint8_t(c), e, n) << "g";
|
||||
}
|
||||
return stream.str();
|
||||
}
|
||||
std::string RSA_D(const std::string& Data, RSA* k) {
|
||||
std::stringstream ss(Data);
|
||||
std::string token, ret;
|
||||
while (std::getline(ss, token, 'g')) {
|
||||
if (token.find_first_not_of(Sec("0123456789abcdef")) != std::string::npos)
|
||||
return "";
|
||||
int c = std::stoi(token, nullptr, 16);
|
||||
ret += char(Dec(c, k->d, k->n));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/28/2020
|
||||
///
|
||||
@ -91,13 +95,13 @@ void LoadConfig(std::ifstream& IFS) {
|
||||
index++;
|
||||
}
|
||||
if (index - 1 < 11) {
|
||||
error(Sec("Outdated/Incorrect config please remove it server will close in 5 secs"));
|
||||
error(("Outdated/Incorrect config please remove it server will close in 5 secs"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
_Exit(0);
|
||||
}
|
||||
IFS.close();
|
||||
IFS.open(Sec("Server.cfg"));
|
||||
info(Sec("Config found updating values"));
|
||||
IFS.open(("Server.cfg"));
|
||||
info(("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
|
||||
@ -109,8 +113,8 @@ void LoadConfig(std::ifstream& IFS) {
|
||||
}
|
||||
void GenerateConfig() {
|
||||
std::ofstream FileStream;
|
||||
FileStream.open(Sec("Server.cfg"));
|
||||
FileStream << Sec("# This is the BeamMP Server Configuration File v0.60\n"
|
||||
FileStream.open(("Server.cfg"));
|
||||
FileStream << ("# This is the BeamMP Server Configuration File v0.60\n"
|
||||
"Debug = false # true or false to enable debug console output\n"
|
||||
"Private = true # Private?\n"
|
||||
"Port = 30814 # Port to run the server on UDP and TCP\n"
|
||||
@ -124,27 +128,27 @@ void GenerateConfig() {
|
||||
FileStream.close();
|
||||
}
|
||||
void Default() {
|
||||
info(Sec("Config not found generating default"));
|
||||
info(("Config not found generating default"));
|
||||
GenerateConfig();
|
||||
error(Sec("You are required to input the AuthKey"));
|
||||
error(("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"));
|
||||
debug(Sec("Port : ") + std::to_string(Port));
|
||||
debug(Sec("Max Cars : ") + std::to_string(MaxCars));
|
||||
debug(Sec("MaxPlayers : ") + std::to_string(MaxPlayers));
|
||||
debug(Sec("MapName : ") + MapName);
|
||||
debug(Sec("ServerName : ") + ServerName);
|
||||
debug(Sec("ServerDesc : ") + ServerDesc);
|
||||
debug(Sec("File : ") + Resource);
|
||||
debug(Sec("Key length: ") + std::to_string(Key.length()));
|
||||
debug(std::string(("Debug : ")) + (Debug ? "true" : "false"));
|
||||
debug(std::string(("Private : ")) + (Private ? "true" : "false"));
|
||||
debug(("Port : ") + std::to_string(Port));
|
||||
debug(("Max Cars : ") + std::to_string(MaxCars));
|
||||
debug(("MaxPlayers : ") + std::to_string(MaxPlayers));
|
||||
debug(("MapName : ") + MapName);
|
||||
debug(("ServerName : ") + ServerName);
|
||||
debug(("ServerDesc : ") + ServerDesc);
|
||||
debug(("File : ") + Resource);
|
||||
debug(("Key length: ") + std::to_string(Key.length()));
|
||||
}
|
||||
void InitConfig() {
|
||||
std::ifstream IFS;
|
||||
IFS.open(Sec("Server.cfg"));
|
||||
IFS.open(("Server.cfg"));
|
||||
if (IFS.good())
|
||||
LoadConfig(IFS);
|
||||
else
|
||||
@ -152,7 +156,7 @@ void InitConfig() {
|
||||
if (IFS.is_open())
|
||||
IFS.close();
|
||||
if (Key.empty()) {
|
||||
error(Sec("No AuthKey was found"));
|
||||
error(("No AuthKey was found"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
_Exit(0);
|
||||
}
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/28/2020
|
||||
///
|
||||
@ -66,7 +70,7 @@ std::string RunPromise(const std::string& IP, const std::string& R) {
|
||||
}
|
||||
//Server Authenticated
|
||||
if (T.length() == 4)
|
||||
info(Sec("Server authenticated"));
|
||||
info(("Server authenticated"));
|
||||
R.clear();
|
||||
T.clear();
|
||||
if (!isAuth) {
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/28/2020
|
||||
///
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/28/2020
|
||||
///
|
||||
@ -19,8 +23,8 @@ void Args(int argc, char* argv[]) {
|
||||
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")) {
|
||||
auto p = CustomIP.find_first_not_of((".0123456789"));
|
||||
if (p != std::string::npos || n != 3 || CustomIP.substr(0, 3) == ("127")) {
|
||||
CustomIP.clear();
|
||||
warn("IP Specified is invalid! Ignoring");
|
||||
} else info("Server started with custom IP");
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 5/20/2020
|
||||
///
|
||||
@ -24,9 +28,9 @@ bool NewFile(const std::string& Path) {
|
||||
void RegisterFiles(const std::string& Path, bool HotSwap) {
|
||||
std::string Name = Path.substr(Path.find_last_of('\\') + 1);
|
||||
if (!HotSwap)
|
||||
info(Sec("Loading plugin : ") + Name);
|
||||
info(("Loading plugin : ") + Name);
|
||||
for (const auto& entry : fs::directory_iterator(Path)) {
|
||||
auto pos = entry.path().string().find(Sec(".lua"));
|
||||
auto pos = entry.path().string().find((".lua"));
|
||||
if (pos != std::string::npos && entry.path().string().length() - pos == 4) {
|
||||
if (!HotSwap || NewFile(entry.path().string())) {
|
||||
auto FileName = entry.path().string();
|
||||
@ -35,7 +39,7 @@ void RegisterFiles(const std::string& Path, bool HotSwap) {
|
||||
PluginEngine.insert(std::move(ScriptToInsert));
|
||||
Script.Init();
|
||||
if (HotSwap)
|
||||
info(Sec("[HOTSWAP] Added : ") + Script.GetFileName().substr(Script.GetFileName().find('\\')));
|
||||
info(("[HOTSWAP] Added : ") + Script.GetFileName().substr(Script.GetFileName().find('\\')));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -57,12 +61,12 @@ void FolderList(const std::string& Path, bool HotSwap) {
|
||||
if (stat(Script->GetFileName().c_str(), &Info) != 0) {
|
||||
Script->SetStopThread(true);
|
||||
PluginEngine.erase(Script);
|
||||
info(Sec("[HOTSWAP] Removed removed script due to delete"));
|
||||
info(("[HOTSWAP] Removed removed script due to delete"));
|
||||
break;
|
||||
}
|
||||
if (Script->GetLastWrite() != fs::last_write_time(Script->GetFileName())) {
|
||||
Script->SetStopThread(true);
|
||||
info(Sec("[HOTSWAP] Updated Scripts due to edit"));
|
||||
info(("[HOTSWAP] Updated Scripts due to edit"));
|
||||
Script->SetLastWrite(fs::last_write_time(Script->GetFileName()));
|
||||
Script->Reload();
|
||||
}
|
||||
@ -77,12 +81,12 @@ void InitLua() {
|
||||
if (!fs::exists(Resource)) {
|
||||
fs::create_directory(Resource);
|
||||
}
|
||||
std::string Path = Resource + Sec("/Server");
|
||||
std::string Path = Resource + ("/Server");
|
||||
if (!fs::exists(Path)) {
|
||||
fs::create_directory(Path);
|
||||
}
|
||||
FolderList(Path, false);
|
||||
std::thread t1(HotSwaps, Path);
|
||||
t1.detach();
|
||||
info(Sec("Lua system online"));
|
||||
info(("Lua system online"));
|
||||
}
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 5/19/2020
|
||||
///
|
||||
@ -46,12 +50,12 @@ void SendError(lua_State* L, const std::string& msg) {
|
||||
auto MaybeS = GetScript(L);
|
||||
std::string a;
|
||||
if (!MaybeS.has_value()) {
|
||||
a = Sec("_Console");
|
||||
a = ("_Console");
|
||||
} else {
|
||||
Lua& S = MaybeS.value();
|
||||
a = fs::path(S.GetFileName()).filename().string();
|
||||
}
|
||||
warn(a + Sec(" | Incorrect Call of ") + msg);
|
||||
warn(a + (" | Incorrect Call of ") + msg);
|
||||
}
|
||||
std::any Trigger(Lua* lua, const std::string& R, std::shared_ptr<LuaArg> arg) {
|
||||
std::lock_guard<std::mutex> lockGuard(lua->Lock);
|
||||
@ -107,7 +111,7 @@ std::any TriggerLuaEvent(const std::string& Event, bool local, Lua* Caller, std:
|
||||
bool ConsoleCheck(lua_State* L, int r) {
|
||||
if (r != LUA_OK) {
|
||||
std::string msg = lua_tostring(L, -1);
|
||||
warn(Sec("_Console | ") + msg);
|
||||
warn(("_Console | ") + msg);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -136,7 +140,7 @@ int lua_RegisterEvent(lua_State* L) {
|
||||
if (Args == 2 && lua_isstring(L, 1) && lua_isstring(L, 2)) {
|
||||
Script.RegisterEvent(lua_tostring(L, 1), lua_tostring(L, 2));
|
||||
} else
|
||||
SendError(L, Sec("RegisterEvent invalid argument count expected 2 got ") + std::to_string(Args));
|
||||
SendError(L, ("RegisterEvent invalid argument count expected 2 got ") + std::to_string(Args));
|
||||
return 0;
|
||||
}
|
||||
int lua_TriggerEventL(lua_State* L) {
|
||||
@ -148,9 +152,9 @@ int lua_TriggerEventL(lua_State* L) {
|
||||
if (lua_isstring(L, 1)) {
|
||||
TriggerLuaEvent(lua_tostring(L, 1), true, &Script, CreateArg(L, Args, 2), false);
|
||||
} else
|
||||
SendError(L, Sec("TriggerLocalEvent wrong argument [1] need string"));
|
||||
SendError(L, ("TriggerLocalEvent wrong argument [1] need string"));
|
||||
} else {
|
||||
SendError(L, Sec("TriggerLocalEvent not enough arguments expected 1 got 0"));
|
||||
SendError(L, ("TriggerLocalEvent not enough arguments expected 1 got 0"));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -164,9 +168,9 @@ int lua_TriggerEventG(lua_State* L) {
|
||||
if (lua_isstring(L, 1)) {
|
||||
TriggerLuaEvent(lua_tostring(L, 1), false, &Script, CreateArg(L, Args, 2), false);
|
||||
} else
|
||||
SendError(L, Sec("TriggerGlobalEvent wrong argument [1] need string"));
|
||||
SendError(L, ("TriggerGlobalEvent wrong argument [1] need string"));
|
||||
} else
|
||||
SendError(L, Sec("TriggerGlobalEvent not enough arguments"));
|
||||
SendError(L, ("TriggerGlobalEvent not enough arguments"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -231,13 +235,13 @@ int lua_CreateThread(lua_State* L) {
|
||||
std::thread t1(CallAsync, &Script, STR, U);
|
||||
t1.detach();
|
||||
} else
|
||||
SendError(L, Sec("CreateThread wrong argument [2] number must be between 1 and 500"));
|
||||
SendError(L, ("CreateThread wrong argument [2] number must be between 1 and 500"));
|
||||
} else
|
||||
SendError(L, Sec("CreateThread wrong argument [2] need number"));
|
||||
SendError(L, ("CreateThread wrong argument [2] need number"));
|
||||
} else
|
||||
SendError(L, Sec("CreateThread wrong argument [1] need string"));
|
||||
SendError(L, ("CreateThread wrong argument [1] need string"));
|
||||
} else
|
||||
SendError(L, Sec("CreateThread not enough arguments"));
|
||||
SendError(L, ("CreateThread not enough arguments"));
|
||||
return 0;
|
||||
}
|
||||
int lua_Sleep(lua_State* L) {
|
||||
@ -245,7 +249,7 @@ int lua_Sleep(lua_State* L) {
|
||||
int t = int(lua_tonumber(L, 1));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(t));
|
||||
} else {
|
||||
SendError(L, Sec("Sleep not enough arguments"));
|
||||
SendError(L, ("Sleep not enough arguments"));
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
@ -267,7 +271,7 @@ int lua_isConnected(lua_State* L) {
|
||||
else
|
||||
return 0;
|
||||
} else {
|
||||
SendError(L, Sec("isConnected not enough arguments"));
|
||||
SendError(L, ("isConnected not enough arguments"));
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
@ -281,7 +285,7 @@ int lua_GetPlayerName(lua_State* L) {
|
||||
else
|
||||
return 0;
|
||||
} else {
|
||||
SendError(L, Sec("GetPlayerName not enough arguments"));
|
||||
SendError(L, ("GetPlayerName not enough arguments"));
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
@ -336,7 +340,7 @@ int lua_GetCars(lua_State* L) {
|
||||
} else
|
||||
return 0;
|
||||
} else {
|
||||
SendError(L, Sec("GetPlayerVehicles not enough arguments"));
|
||||
SendError(L, ("GetPlayerVehicles not enough arguments"));
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
@ -350,13 +354,13 @@ int lua_dropPlayer(lua_State* L) {
|
||||
return 0;
|
||||
std::string Reason;
|
||||
if (Args > 1 && lua_isstring(L, 2)) {
|
||||
Reason = std::string(Sec(" Reason : ")) + lua_tostring(L, 2);
|
||||
Reason = std::string((" Reason : ")) + lua_tostring(L, 2);
|
||||
}
|
||||
Respond(c, "C:Server:You have been Kicked from the server! " + Reason, true);
|
||||
c->SetStatus(-2);
|
||||
info(Sec("Closing socket due to kick"));
|
||||
info(("Closing socket due to kick"));
|
||||
CloseSocketProper(c->GetTCPSock());
|
||||
} else SendError(L, Sec("DropPlayer not enough arguments"));
|
||||
} else SendError(L, ("DropPlayer not enough arguments"));
|
||||
return 0;
|
||||
}
|
||||
int lua_sendChat(lua_State* L) {
|
||||
@ -374,18 +378,18 @@ int lua_sendChat(lua_State* L) {
|
||||
std::string Packet = "C:Server: " + std::string(lua_tostring(L, 2));
|
||||
Respond(c, Packet, true);
|
||||
} else
|
||||
SendError(L, Sec("SendChatMessage invalid argument [1] invalid ID"));
|
||||
SendError(L, ("SendChatMessage invalid argument [1] invalid ID"));
|
||||
}
|
||||
} else
|
||||
SendError(L, Sec("SendChatMessage invalid argument [2] expected string"));
|
||||
SendError(L, ("SendChatMessage invalid argument [2] expected string"));
|
||||
} else
|
||||
SendError(L, Sec("SendChatMessage invalid argument [1] expected number"));
|
||||
SendError(L, ("SendChatMessage invalid argument [1] expected number"));
|
||||
return 0;
|
||||
}
|
||||
int lua_RemoveVehicle(lua_State* L) {
|
||||
int Args = lua_gettop(L);
|
||||
if (Args != 2) {
|
||||
SendError(L, Sec("RemoveVehicle invalid argument count expected 2 got ") + std::to_string(Args));
|
||||
SendError(L, ("RemoveVehicle invalid argument count expected 2 got ") + std::to_string(Args));
|
||||
return 0;
|
||||
}
|
||||
if ((lua_isinteger(L, 1) || lua_isnumber(L, 1)) && (lua_isinteger(L, 2) || lua_isnumber(L, 2))) {
|
||||
@ -393,7 +397,7 @@ int lua_RemoveVehicle(lua_State* L) {
|
||||
int VID = int(lua_tointeger(L, 2));
|
||||
Client* c = GetClient(PID);
|
||||
if (c == nullptr) {
|
||||
SendError(L, Sec("RemoveVehicle invalid Player ID"));
|
||||
SendError(L, ("RemoveVehicle invalid Player ID"));
|
||||
return 0;
|
||||
}
|
||||
if (!c->GetCarData(VID).empty()) {
|
||||
@ -402,7 +406,7 @@ int lua_RemoveVehicle(lua_State* L) {
|
||||
c->DeleteCar(VID);
|
||||
}
|
||||
} else
|
||||
SendError(L, Sec("RemoveVehicle invalid argument expected number"));
|
||||
SendError(L, ("RemoveVehicle invalid argument expected number"));
|
||||
return 0;
|
||||
}
|
||||
int lua_HWID(lua_State* L) {
|
||||
@ -412,19 +416,19 @@ int lua_HWID(lua_State* L) {
|
||||
int lua_RemoteEvent(lua_State* L) {
|
||||
int Args = lua_gettop(L);
|
||||
if (Args != 3) {
|
||||
SendError(L, Sec("TriggerClientEvent invalid argument count expected 3 got ") + std::to_string(Args));
|
||||
SendError(L, ("TriggerClientEvent invalid argument count expected 3 got ") + std::to_string(Args));
|
||||
return 0;
|
||||
}
|
||||
if (!lua_isnumber(L, 1)) {
|
||||
SendError(L, Sec("TriggerClientEvent invalid argument [1] expected number"));
|
||||
SendError(L, ("TriggerClientEvent invalid argument [1] expected number"));
|
||||
return 0;
|
||||
}
|
||||
if (!lua_isstring(L, 2)) {
|
||||
SendError(L, Sec("TriggerClientEvent invalid argument [2] expected string"));
|
||||
SendError(L, ("TriggerClientEvent invalid argument [2] expected string"));
|
||||
return 0;
|
||||
}
|
||||
if (!lua_isstring(L, 3)) {
|
||||
SendError(L, Sec("TriggerClientEvent invalid argument [3] expected string"));
|
||||
SendError(L, ("TriggerClientEvent invalid argument [3] expected string"));
|
||||
return 0;
|
||||
}
|
||||
int ID = int(lua_tointeger(L, 1));
|
||||
@ -434,7 +438,7 @@ int lua_RemoteEvent(lua_State* L) {
|
||||
else {
|
||||
Client* c = GetClient(ID);
|
||||
if (c == nullptr) {
|
||||
SendError(L, Sec("TriggerClientEvent invalid Player ID"));
|
||||
SendError(L, ("TriggerClientEvent invalid Player ID"));
|
||||
return 0;
|
||||
}
|
||||
Respond(c, Packet, true);
|
||||
@ -452,17 +456,17 @@ int lua_ServerExit(lua_State*L) {
|
||||
int lua_Set(lua_State* L) {
|
||||
int Args = lua_gettop(L);
|
||||
if (Args != 2) {
|
||||
SendError(L, Sec("set invalid argument count expected 2 got ") + std::to_string(Args));
|
||||
SendError(L, ("set invalid argument count expected 2 got ") + std::to_string(Args));
|
||||
return 0;
|
||||
}
|
||||
if (!lua_isnumber(L, 1)) {
|
||||
SendError(L, Sec("set invalid argument [1] expected number"));
|
||||
SendError(L, ("set invalid argument [1] expected number"));
|
||||
return 0;
|
||||
}
|
||||
auto MaybeSrc = GetScript(L);
|
||||
std::string Name;
|
||||
if (!MaybeSrc.has_value()) {
|
||||
Name = Sec("_Console");
|
||||
Name = ("_Console");
|
||||
} else {
|
||||
Name = MaybeSrc.value().get().GetPluginName();
|
||||
}
|
||||
@ -471,54 +475,54 @@ int lua_Set(lua_State* L) {
|
||||
case 0: //debug
|
||||
if (lua_isboolean(L, 2)) {
|
||||
Debug = lua_toboolean(L, 2);
|
||||
info(Name + Sec(" | Debug -> ") + (Debug ? "true" : "false"));
|
||||
info(Name + (" | Debug -> ") + (Debug ? "true" : "false"));
|
||||
} else
|
||||
SendError(L, Sec("set invalid argument [2] expected boolean for ID : 0"));
|
||||
SendError(L, ("set invalid argument [2] expected boolean for ID : 0"));
|
||||
break;
|
||||
case 1: //private
|
||||
if (lua_isboolean(L, 2)) {
|
||||
Private = lua_toboolean(L, 2);
|
||||
info(Name + Sec(" | Private -> ") + (Private ? "true" : "false"));
|
||||
info(Name + (" | Private -> ") + (Private ? "true" : "false"));
|
||||
} else
|
||||
SendError(L, Sec("set invalid argument [2] expected boolean for ID : 1"));
|
||||
SendError(L, ("set invalid argument [2] expected boolean for ID : 1"));
|
||||
break;
|
||||
case 2: //max cars
|
||||
if (lua_isnumber(L, 2)) {
|
||||
MaxCars = int(lua_tointeger(L, 2));
|
||||
info(Name + Sec(" | MaxCars -> ") + std::to_string(MaxCars));
|
||||
info(Name + (" | MaxCars -> ") + std::to_string(MaxCars));
|
||||
} else
|
||||
SendError(L, Sec("set invalid argument [2] expected number for ID : 2"));
|
||||
SendError(L, ("set invalid argument [2] expected number for ID : 2"));
|
||||
break;
|
||||
case 3: //max players
|
||||
if (lua_isnumber(L, 2)) {
|
||||
MaxPlayers = int(lua_tointeger(L, 2));
|
||||
info(Name + Sec(" | MaxPlayers -> ") + std::to_string(MaxPlayers));
|
||||
info(Name + (" | MaxPlayers -> ") + std::to_string(MaxPlayers));
|
||||
} else
|
||||
SendError(L, Sec("set invalid argument [2] expected number for ID : 3"));
|
||||
SendError(L, ("set invalid argument [2] expected number for ID : 3"));
|
||||
break;
|
||||
case 4: //Map
|
||||
if (lua_isstring(L, 2)) {
|
||||
MapName = lua_tostring(L, 2);
|
||||
info(Name + Sec(" | MapName -> ") + MapName);
|
||||
info(Name + (" | MapName -> ") + MapName);
|
||||
} else
|
||||
SendError(L, Sec("set invalid argument [2] expected string for ID : 4"));
|
||||
SendError(L, ("set invalid argument [2] expected string for ID : 4"));
|
||||
break;
|
||||
case 5: //Name
|
||||
if (lua_isstring(L, 2)) {
|
||||
ServerName = lua_tostring(L, 2);
|
||||
info(Name + Sec(" | ServerName -> ") + ServerName);
|
||||
info(Name + (" | ServerName -> ") + ServerName);
|
||||
} else
|
||||
SendError(L, Sec("set invalid argument [2] expected string for ID : 5"));
|
||||
SendError(L, ("set invalid argument [2] expected string for ID : 5"));
|
||||
break;
|
||||
case 6: //Desc
|
||||
if (lua_isstring(L, 2)) {
|
||||
ServerDesc = lua_tostring(L, 2);
|
||||
info(Name + Sec(" | ServerDesc -> ") + ServerDesc);
|
||||
info(Name + (" | ServerDesc -> ") + ServerDesc);
|
||||
} else
|
||||
SendError(L, Sec("set invalid argument [2] expected string for ID : 6"));
|
||||
SendError(L, ("set invalid argument [2] expected string for ID : 6"));
|
||||
break;
|
||||
default:
|
||||
warn(Sec("Invalid config ID : ") + std::to_string(C));
|
||||
warn(("Invalid config ID : ") + std::to_string(C));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -530,9 +534,9 @@ int lua_Print(lua_State* L) {
|
||||
for (int i = 1; i <= Arg; i++) {
|
||||
auto str = lua_tostring(L, i);
|
||||
if (str != nullptr) {
|
||||
ConsoleOut(str + std::string(Sec("\n")));
|
||||
ConsoleOut(str + std::string(("\n")));
|
||||
} else {
|
||||
ConsoleOut(Sec("nil\n"));
|
||||
ConsoleOut(("nil\n"));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@ -564,7 +568,7 @@ void Lua::Execute(const std::string& Command) {
|
||||
}
|
||||
void Lua::Reload() {
|
||||
if (CheckLua(luaState, luaL_dofile(luaState, _FileName.c_str()))) {
|
||||
CallFunction(this, Sec("onInit"), nullptr);
|
||||
CallFunction(this, ("onInit"), nullptr);
|
||||
}
|
||||
}
|
||||
std::string Lua::GetOrigin() {
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/31/2020
|
||||
///
|
||||
@ -190,30 +194,30 @@ void TCPServerMain() {
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(uint16_t(Port));
|
||||
if (bind(Listener, (sockaddr*)&addr, sizeof(addr)) != 0) {
|
||||
error(Sec("Can't bind socket! ") + std::string(strerror(errno)));
|
||||
error(("Can't bind socket! ") + std::string(strerror(errno)));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
_Exit(-1);
|
||||
}
|
||||
if (Listener == -1) {
|
||||
error(Sec("Invalid listening socket"));
|
||||
error(("Invalid listening socket"));
|
||||
return;
|
||||
}
|
||||
if (listen(Listener, SOMAXCONN)) {
|
||||
error(Sec("listener failed ") + std::string(strerror(errno)));
|
||||
error(("listener failed ") + std::string(strerror(errno)));
|
||||
return;
|
||||
}
|
||||
info(Sec("Vehicle event network online"));
|
||||
info(("Vehicle event network online"));
|
||||
do {
|
||||
try {
|
||||
client = accept(Listener, nullptr, nullptr);
|
||||
if (client == -1) {
|
||||
warn(Sec("Got an invalid client socket on connect! Skipping..."));
|
||||
warn(("Got an invalid client socket on connect! Skipping..."));
|
||||
continue;
|
||||
}
|
||||
std::thread ID(Identify, client);
|
||||
ID.detach();
|
||||
} catch (const std::exception& e) {
|
||||
error(Sec("fatal: ") + std::string(e.what()));
|
||||
error(("fatal: ") + std::string(e.what()));
|
||||
}
|
||||
} while (client);
|
||||
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 5/8/2020
|
||||
///
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 8/1/2020
|
||||
///
|
||||
@ -43,18 +47,18 @@ void VehicleParser(Client* c, const std::string& Pckt) {
|
||||
switch (Code) { //Spawned Destroyed Switched/Moved NotFound Reset
|
||||
case 's':
|
||||
#ifdef DEBUG
|
||||
debug(std::string(Sec("got 'Os' packet: '")) + Packet + Sec("' (") + std::to_string(Packet.size()) + Sec(")"));
|
||||
debug(std::string(("got 'Os' packet: '")) + Packet + ("' (") + std::to_string(Packet.size()) + (")"));
|
||||
#endif
|
||||
if (Data.at(0) == '0') {
|
||||
int CarID = c->GetOpenCarID();
|
||||
debug(c->GetName() + Sec(" created a car with ID ") + std::to_string(CarID));
|
||||
debug(c->GetName() + (" created a car with ID ") + std::to_string(CarID));
|
||||
Packet = "Os:" + c->GetRoles() + ":" + c->GetName() + ":" + std::to_string(c->GetID()) + "-" + std::to_string(CarID) + Packet.substr(4);
|
||||
auto Res = TriggerLuaEvent(Sec("onVehicleSpawn"), false, nullptr, std::make_unique<LuaArg>(LuaArg { { c->GetID(), CarID, Packet.substr(3) } }), true);
|
||||
auto Res = TriggerLuaEvent(("onVehicleSpawn"), false, nullptr, std::make_unique<LuaArg>(LuaArg { { c->GetID(), CarID, Packet.substr(3) } }), true);
|
||||
if (c->GetCarCount() >= MaxCars || std::any_cast<int>(Res)) {
|
||||
Respond(c, Packet, true);
|
||||
std::string Destroy = "Od:" + std::to_string(c->GetID()) + "-" + std::to_string(CarID);
|
||||
Respond(c, Destroy, true);
|
||||
debug(c->GetName() + Sec(" (force : car limit/lua) removed ID ") + std::to_string(CarID));
|
||||
debug(c->GetName() + (" (force : car limit/lua) removed ID ") + std::to_string(CarID));
|
||||
} else {
|
||||
c->AddNewCar(CarID, Packet);
|
||||
SendToAll(nullptr, Packet, true, true);
|
||||
@ -63,7 +67,7 @@ void VehicleParser(Client* c, const std::string& Pckt) {
|
||||
return;
|
||||
case 'c':
|
||||
#ifdef DEBUG
|
||||
debug(std::string(Sec("got 'Oc' packet: '")) + Packet + Sec("' (") + std::to_string(Packet.size()) + Sec(")"));
|
||||
debug(std::string(("got 'Oc' packet: '")) + Packet + ("' (") + std::to_string(Packet.size()) + (")"));
|
||||
#endif
|
||||
pid = Data.substr(0, Data.find('-'));
|
||||
vid = Data.substr(Data.find('-') + 1, Data.find(':', 1) - Data.find('-') - 1);
|
||||
@ -72,7 +76,7 @@ void VehicleParser(Client* c, const std::string& Pckt) {
|
||||
VID = stoi(vid);
|
||||
}
|
||||
if (PID != -1 && VID != -1 && PID == c->GetID()) {
|
||||
auto Res = TriggerLuaEvent(Sec("onVehicleEdited"), false, nullptr,
|
||||
auto Res = TriggerLuaEvent(("onVehicleEdited"), false, nullptr,
|
||||
std::make_unique<LuaArg>(LuaArg { { c->GetID(), VID, Packet.substr(3) } }),
|
||||
true);
|
||||
if (!std::any_cast<int>(Res)) {
|
||||
@ -87,7 +91,7 @@ void VehicleParser(Client* c, const std::string& Pckt) {
|
||||
return;
|
||||
case 'd':
|
||||
#ifdef DEBUG
|
||||
debug(std::string(Sec("got 'Od' packet: '")) + Packet + Sec("' (") + std::to_string(Packet.size()) + Sec(")"));
|
||||
debug(std::string(("got 'Od' packet: '")) + Packet + ("' (") + std::to_string(Packet.size()) + (")"));
|
||||
#endif
|
||||
pid = Data.substr(0, Data.find('-'));
|
||||
vid = Data.substr(Data.find('-') + 1);
|
||||
@ -97,27 +101,27 @@ void VehicleParser(Client* c, const std::string& Pckt) {
|
||||
}
|
||||
if (PID != -1 && VID != -1 && PID == c->GetID()) {
|
||||
SendToAll(nullptr, Packet, true, true);
|
||||
TriggerLuaEvent(Sec("onVehicleDeleted"), false, nullptr,
|
||||
TriggerLuaEvent(("onVehicleDeleted"), false, nullptr,
|
||||
std::make_unique<LuaArg>(LuaArg { { c->GetID(), VID } }), false);
|
||||
c->DeleteCar(VID);
|
||||
debug(c->GetName() + Sec(" deleted car with ID ") + std::to_string(VID));
|
||||
debug(c->GetName() + (" deleted car with ID ") + std::to_string(VID));
|
||||
}
|
||||
return;
|
||||
case 'r':
|
||||
#ifdef DEBUG
|
||||
debug(std::string(Sec("got 'Or' packet: '")) + Packet + Sec("' (") + std::to_string(Packet.size()) + Sec(")"));
|
||||
debug(std::string(("got 'Or' packet: '")) + Packet + ("' (") + std::to_string(Packet.size()) + (")"));
|
||||
#endif
|
||||
SendToAll(c, Packet, false, true);
|
||||
return;
|
||||
case 't':
|
||||
#ifdef DEBUG
|
||||
debug(std::string(Sec("got 'Ot' packet: '")) + Packet + Sec("' (") + std::to_string(Packet.size()) + Sec(")"));
|
||||
debug(std::string(("got 'Ot' packet: '")) + Packet + ("' (") + std::to_string(Packet.size()) + (")"));
|
||||
#endif
|
||||
SendToAll(c, Packet, false, true);
|
||||
return;
|
||||
default:
|
||||
#ifdef DEBUG
|
||||
warn(std::string(Sec("possibly not implemented: '") + Packet + Sec("' (") + std::to_string(Packet.size()) + Sec(")")));
|
||||
warn(std::string(("possibly not implemented: '") + Packet + ("' (") + std::to_string(Packet.size()) + (")")));
|
||||
#endif // DEBUG
|
||||
return;
|
||||
}
|
||||
@ -128,9 +132,9 @@ void SyncClient(Client* c) {
|
||||
return;
|
||||
c->isSynced = true;
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
Respond(c, Sec("Sn") + c->GetName(), true);
|
||||
SendToAll(c, Sec("JWelcome ") + c->GetName() + "!", false, true);
|
||||
TriggerLuaEvent(Sec("onPlayerJoin"), false, nullptr, std::make_unique<LuaArg>(LuaArg { { c->GetID() } }), false);
|
||||
Respond(c, ("Sn") + c->GetName(), true);
|
||||
SendToAll(c, ("JWelcome ") + c->GetName() + "!", false, true);
|
||||
TriggerLuaEvent(("onPlayerJoin"), false, nullptr, std::make_unique<LuaArg>(LuaArg { { c->GetID() } }), false);
|
||||
for (auto& client : CI->Clients) {
|
||||
if (client != nullptr) {
|
||||
if (client.get() != c) {
|
||||
@ -144,14 +148,14 @@ void SyncClient(Client* c) {
|
||||
}
|
||||
}
|
||||
}
|
||||
info(c->GetName() + Sec(" is now synced!"));
|
||||
info(c->GetName() + (" is now synced!"));
|
||||
}
|
||||
void ParseVeh(Client* c, const std::string& Packet) {
|
||||
Assert(c);
|
||||
#ifdef WIN32
|
||||
__try {
|
||||
VehicleParser(c, Packet);
|
||||
} __except (Handle(GetExceptionInformation(), Sec("Vehicle Handler"))) { }
|
||||
} __except (Handle(GetExceptionInformation(), ("Vehicle Handler"))) { }
|
||||
#else // unix
|
||||
VehicleParser(c, Packet);
|
||||
#endif // WIN32
|
||||
@ -202,24 +206,24 @@ void GlobalParser(Client* c, const std::string& Pack) {
|
||||
SyncClient(c);
|
||||
return;
|
||||
case 'p':
|
||||
Respond(c, Sec("p"), false);
|
||||
Respond(c, ("p"), false);
|
||||
UpdatePlayers();
|
||||
return;
|
||||
case 'O':
|
||||
if (Packet.length() > 1000) {
|
||||
debug(Sec("Received data from: ") + c->GetName() + Sec(" Size: ") + std::to_string(Packet.length()));
|
||||
debug(("Received data from: ") + c->GetName() + (" Size: ") + std::to_string(Packet.length()));
|
||||
}
|
||||
ParseVeh(c, Packet);
|
||||
return;
|
||||
case 'J':
|
||||
#ifdef DEBUG
|
||||
debug(std::string(Sec("got 'J' packet: '")) + Pack + Sec("' (") + std::to_string(Packet.size()) + Sec(")"));
|
||||
debug(std::string(("got 'J' packet: '")) + Pack + ("' (") + std::to_string(Packet.size()) + (")"));
|
||||
#endif
|
||||
SendToAll(c, Packet, false, true);
|
||||
return;
|
||||
case 'C':
|
||||
#ifdef DEBUG
|
||||
debug(std::string(Sec("got 'C' packet: '")) + Pack + Sec("' (") + std::to_string(Packet.size()) + Sec(")"));
|
||||
debug(std::string(("got 'C' packet: '")) + Pack + ("' (") + std::to_string(Packet.size()) + (")"));
|
||||
#endif
|
||||
if (Packet.length() < 4 || Packet.find(':', 3) == std::string::npos)
|
||||
break;
|
||||
@ -231,7 +235,7 @@ void GlobalParser(Client* c, const std::string& Pack) {
|
||||
return;
|
||||
case 'E':
|
||||
#ifdef DEBUG
|
||||
debug(std::string(Sec("got 'E' packet: '")) + Pack + Sec("' (") + std::to_string(Packet.size()) + Sec(")"));
|
||||
debug(std::string(("got 'E' packet: '")) + Pack + ("' (") + std::to_string(Packet.size()) + (")"));
|
||||
#endif
|
||||
HandleEvent(c, Packet);
|
||||
return;
|
||||
@ -248,7 +252,7 @@ void GParser(Client* c, const std::string& Packet) {
|
||||
#ifdef WIN32
|
||||
__try {
|
||||
GlobalParser(c, Packet);
|
||||
} __except (Handle(GetExceptionInformation(), Sec("Global Handler"))) { }
|
||||
} __except (Handle(GetExceptionInformation(), ("Global Handler"))) { }
|
||||
#else
|
||||
GlobalParser(c, Packet);
|
||||
#endif // WIN32
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 4/9/2020
|
||||
///
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 8/1/2020
|
||||
///
|
||||
@ -9,8 +13,6 @@
|
||||
#include "Logger.h"
|
||||
#include <memory>
|
||||
|
||||
|
||||
|
||||
int OpenID() {
|
||||
int ID = 0;
|
||||
bool found;
|
||||
@ -61,7 +63,7 @@ void SendToAll(Client* c, const std::string& Data, bool Self, bool Rel) {
|
||||
}
|
||||
}
|
||||
void UpdatePlayers() {
|
||||
std::string Packet = Sec("Ss") + std::to_string(CI->Size()) + "/" + std::to_string(MaxPlayers) + ":";
|
||||
std::string Packet = ("Ss") + std::to_string(CI->Size()) + "/" + std::to_string(MaxPlayers) + ":";
|
||||
for (auto& c : CI->Clients) {
|
||||
if (c != nullptr)
|
||||
Packet += c->GetName() + ",";
|
||||
@ -71,7 +73,7 @@ void UpdatePlayers() {
|
||||
}
|
||||
void OnDisconnect(Client* c, bool kicked) {
|
||||
Assert(c);
|
||||
info(c->GetName() + Sec(" Connection Terminated"));
|
||||
info(c->GetName() + (" Connection Terminated"));
|
||||
std::string Packet;
|
||||
for (auto& v : c->GetAllCars()) {
|
||||
if (v != nullptr) {
|
||||
@ -80,14 +82,14 @@ void OnDisconnect(Client* c, bool kicked) {
|
||||
}
|
||||
}
|
||||
if (kicked)
|
||||
Packet = Sec("L") + c->GetName() + Sec(" was kicked!");
|
||||
Packet = Sec("L") + c->GetName() + Sec(" Left the server!");
|
||||
Packet = ("L") + c->GetName() + (" was kicked!");
|
||||
Packet = ("L") + c->GetName() + (" Left the server!");
|
||||
SendToAll(c, Packet, false, true);
|
||||
Packet.clear();
|
||||
TriggerLuaEvent(Sec("onPlayerDisconnect"), false, nullptr, std::make_unique<LuaArg>(LuaArg { { c->GetID() } }), false);
|
||||
TriggerLuaEvent(("onPlayerDisconnect"), false, nullptr, std::make_unique<LuaArg>(LuaArg { { c->GetID() } }), false);
|
||||
if(c->GetTCPSock())CloseSocketProper(c->GetTCPSock());
|
||||
if(c->GetDownSock())CloseSocketProper(c->GetDownSock());
|
||||
CI->RemoveClient(c); ///Removes the Client from existence
|
||||
CI->RemoveClient(c);
|
||||
}
|
||||
void OnConnect(Client* c) {
|
||||
Assert(c);
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 6/18/2020
|
||||
///
|
||||
|
@ -1,6 +1,11 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 8/1/2020
|
||||
///
|
||||
|
||||
#include "Security/Enc.h"
|
||||
#include "UnixCompat.h"
|
||||
#include "Settings.h"
|
||||
@ -73,7 +78,7 @@ void SendFile(Client*c, const std::string& Name) {
|
||||
|
||||
///Wait for connections
|
||||
int T = 0;
|
||||
while(c->GetDownSock() < 1 && T < 30){
|
||||
while(c->GetDownSock() < 1 && T < 50){
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
T++;
|
||||
}
|
||||
@ -109,7 +114,7 @@ void Parse(Client* c, const std::string& Packet) {
|
||||
return;
|
||||
case 'S':
|
||||
if (SubCode == 'R') {
|
||||
debug(Sec("Sending Mod Info"));
|
||||
debug("Sending Mod Info");
|
||||
std::string ToSend = FileList + FileSizes;
|
||||
if (ToSend.empty())ToSend = "-";
|
||||
TCPSend(c, ToSend);
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 8/1/2020
|
||||
///
|
||||
@ -45,13 +49,13 @@ bool CheckBytes(Client* c, int32_t BytesRcv) {
|
||||
return false;
|
||||
} else if (BytesRcv < 0) {
|
||||
#ifdef WIN32
|
||||
debug(Sec("(TCP) recv failed with error: ") + std::to_string(WSAGetLastError()));
|
||||
debug(("(TCP) recv failed with error: ") + std::to_string(WSAGetLastError()));
|
||||
#else // unix
|
||||
debug(Sec("(TCP) recv failed with error: ") + std::string(strerror(errno)));
|
||||
debug(("(TCP) recv failed with error: ") + std::string(strerror(errno)));
|
||||
#endif // WIN32
|
||||
if (c->GetStatus() > -1)
|
||||
c->SetStatus(-1);
|
||||
info(Sec("Closing socket in CheckBytes, BytesRcv < 0"));
|
||||
info(("Closing socket in CheckBytes, BytesRcv < 0"));
|
||||
CloseSocketProper(c->GetTCPSock());
|
||||
return false;
|
||||
}
|
||||
@ -69,7 +73,7 @@ std::string TCPRcv(Client* c) {
|
||||
Temp = recv(c->GetTCPSock(), &Data[BytesRcv], 4 - BytesRcv, 0);
|
||||
if (!CheckBytes(c, Temp)) {
|
||||
#ifdef DEBUG
|
||||
error(std::string(__func__) + Sec(": failed on CheckBytes in while(BytesRcv < 4)"));
|
||||
error(std::string(__func__) + (": failed on CheckBytes in while(BytesRcv < 4)"));
|
||||
#endif // DEBUG
|
||||
return "";
|
||||
}
|
||||
@ -78,11 +82,11 @@ std::string TCPRcv(Client* c) {
|
||||
memcpy(&Header, &Data[0], sizeof(Header));
|
||||
|
||||
#ifdef DEBUG
|
||||
//debug(std::string(__func__) + Sec(": expecting ") + std::to_string(Header) + Sec(" bytes."));
|
||||
//debug(std::string(__func__) + (": expecting ") + std::to_string(Header) + (" bytes."));
|
||||
#endif // DEBUG
|
||||
if (!CheckBytes(c, BytesRcv)) {
|
||||
#ifdef DEBUG
|
||||
error(std::string(__func__) + Sec(": failed on CheckBytes"));
|
||||
error(std::string(__func__) + (": failed on CheckBytes"));
|
||||
#endif // DEBUG
|
||||
return "";
|
||||
}
|
||||
@ -92,18 +96,18 @@ std::string TCPRcv(Client* c) {
|
||||
Temp = recv(c->GetTCPSock(), &Data[BytesRcv], Header - BytesRcv, 0);
|
||||
if (!CheckBytes(c, Temp)) {
|
||||
#ifdef DEBUG
|
||||
error(std::string(__func__) + Sec(": failed on CheckBytes in while(BytesRcv < Header)"));
|
||||
error(std::string(__func__) + (": failed on CheckBytes in while(BytesRcv < Header)"));
|
||||
#endif // DEBUG
|
||||
|
||||
return "";
|
||||
}
|
||||
#ifdef DEBUG
|
||||
//debug(std::string(__func__) + Sec(": Temp: ") + std::to_string(Temp) + Sec(", BytesRcv: ") + std::to_string(BytesRcv));
|
||||
//debug(std::string(__func__) + (": Temp: ") + std::to_string(Temp) + (", BytesRcv: ") + std::to_string(BytesRcv));
|
||||
#endif // DEBUG
|
||||
BytesRcv += Temp;
|
||||
} while (BytesRcv < Header);
|
||||
#ifdef DEBUG
|
||||
//debug(std::string(__func__) + Sec(": finished recv with Temp: ") + std::to_string(Temp) + Sec(", BytesRcv: ") + std::to_string(BytesRcv));
|
||||
//debug(std::string(__func__) + (": finished recv with Temp: ") + std::to_string(Temp) + (", BytesRcv: ") + std::to_string(BytesRcv));
|
||||
#endif // DEBUG
|
||||
std::string Ret(Data.data(), Header);
|
||||
|
||||
|
@ -1,20 +1,24 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 5/8/2020
|
||||
///
|
||||
///UDP
|
||||
#include "Client.hpp"
|
||||
#include "Compressor.h"
|
||||
#include "Logger.h"
|
||||
#include "Network.h"
|
||||
|
||||
#include "Security/Enc.h"
|
||||
#include "Settings.h"
|
||||
#include "Compressor.h"
|
||||
#include "UnixCompat.h"
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include "Client.hpp"
|
||||
#include "Settings.h"
|
||||
#include "Network.h"
|
||||
#include "Logger.h"
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
|
||||
int FC(const std::string& s, const std::string& p, int n);
|
||||
|
||||
SOCKET UDPSock;
|
||||
@ -39,21 +43,21 @@ void UDPSend(Client* c, std::string Data) {
|
||||
sendOk = sendto(UDPSock, Data.c_str(), len, 0, (sockaddr*)&Addr, AddrSize);
|
||||
#ifdef WIN32
|
||||
if (sendOk == -1) {
|
||||
debug(Sec("(UDP) Send Failed Code : ") + std::to_string(WSAGetLastError()));
|
||||
debug(("(UDP) Send Failed Code : ") + std::to_string(WSAGetLastError()));
|
||||
if (c->GetStatus() > -1)
|
||||
c->SetStatus(-1);
|
||||
} else if (sendOk == 0) {
|
||||
debug(Sec("(UDP) sendto returned 0"));
|
||||
debug(("(UDP) sendto returned 0"));
|
||||
if (c->GetStatus() > -1)
|
||||
c->SetStatus(-1);
|
||||
}
|
||||
#else // unix
|
||||
if (sendOk == -1) {
|
||||
debug(Sec("(UDP) Send Failed Code : ") + std::string(strerror(errno)));
|
||||
debug(("(UDP) Send Failed Code : ") + std::string(strerror(errno)));
|
||||
if (c->GetStatus() > -1)
|
||||
c->SetStatus(-1);
|
||||
} else if (sendOk == 0) {
|
||||
debug(Sec("(UDP) sendto returned 0"));
|
||||
debug(("(UDP) sendto returned 0"));
|
||||
if (c->GetStatus() > -1)
|
||||
c->SetStatus(-1);
|
||||
}
|
||||
@ -77,9 +81,9 @@ std::string UDPRcvFromClient(sockaddr_in& client) {
|
||||
int64_t Rcv = recvfrom(UDPSock, &Ret[0], 10240, 0, (sockaddr*)&client, (socklen_t*)&clientLength);
|
||||
if (Rcv == -1) {
|
||||
#ifdef WIN32
|
||||
error(Sec("(UDP) Error receiving from Client! Code : ") + std::to_string(WSAGetLastError()));
|
||||
error(("(UDP) Error receiving from Client! Code : ") + std::to_string(WSAGetLastError()));
|
||||
#else // unix
|
||||
error(Sec("(UDP) Error receiving from Client! Code : ") + std::string(strerror(errno)));
|
||||
error(("(UDP) Error receiving from Client! Code : ") + std::string(strerror(errno)));
|
||||
#endif // WIN32
|
||||
return "";
|
||||
}
|
||||
@ -102,7 +106,7 @@ void UDPParser(Client* c, std::string Packet) {
|
||||
#ifdef WIN32
|
||||
WSADATA data;
|
||||
if (WSAStartup(514, &data)) {
|
||||
error(Sec("Can't start Winsock!"));
|
||||
error(("Can't start Winsock!"));
|
||||
//return;
|
||||
}
|
||||
|
||||
@ -115,13 +119,13 @@ void UDPParser(Client* c, std::string Packet) {
|
||||
|
||||
// Try and bind the socket to the IP and port
|
||||
if (bind(UDPSock, (sockaddr*)&serverAddr, sizeof(serverAddr)) == SOCKET_ERROR) {
|
||||
error(Sec("Can't bind socket!") + std::to_string(WSAGetLastError()));
|
||||
error(("Can't bind socket!") + std::to_string(WSAGetLastError()));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
_Exit(-1);
|
||||
//return;
|
||||
}
|
||||
|
||||
info(Sec("Vehicle data network online on port ") + std::to_string(Port) + Sec(" with a Max of ") + std::to_string(MaxPlayers) + Sec(" Clients"));
|
||||
info(("Vehicle data network online on port ") + std::to_string(Port) + (" with a Max of ") + std::to_string(MaxPlayers) + (" Clients"));
|
||||
while (true) {
|
||||
try {
|
||||
sockaddr_in client {};
|
||||
@ -141,7 +145,7 @@ void UDPParser(Client* c, std::string Packet) {
|
||||
}
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
error(Sec("fatal: ") + std::string(e.what()));
|
||||
error(("fatal: ") + std::string(e.what()));
|
||||
}
|
||||
}
|
||||
/*CloseSocketProper(UDPSock);
|
||||
@ -157,13 +161,13 @@ void UDPParser(Client* c, std::string Packet) {
|
||||
|
||||
// Try and bind the socket to the IP and port
|
||||
if (bind(UDPSock, (sockaddr*)&serverAddr, sizeof(serverAddr)) != 0) {
|
||||
error(Sec("Can't bind socket!") + std::string(strerror(errno)));
|
||||
error(("Can't bind socket!") + std::string(strerror(errno)));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
_Exit(-1);
|
||||
//return;
|
||||
}
|
||||
|
||||
info(Sec("Vehicle data network online on port ") + std::to_string(Port) + Sec(" with a Max of ") + std::to_string(MaxPlayers) + Sec(" Clients"));
|
||||
info(("Vehicle data network online on port ") + std::to_string(Port) + (" with a Max of ") + std::to_string(MaxPlayers) + (" Clients"));
|
||||
while (true) {
|
||||
try {
|
||||
sockaddr_in client {};
|
||||
@ -183,7 +187,7 @@ void UDPParser(Client* c, std::string Packet) {
|
||||
}
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
error(Sec("fatal: ") + std::string(e.what()));
|
||||
error(("fatal: ") + std::string(e.what()));
|
||||
}
|
||||
}
|
||||
/*CloseSocketProper(UDPSock); // TODO: Why not this? We did this in TCPServerMain?
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 11/6/2020
|
||||
///
|
||||
@ -24,13 +28,13 @@ std::string GetRes(const beast::flat_buffer& buff) {
|
||||
void SyncData() {
|
||||
/*DebugPrintTID();
|
||||
try {
|
||||
std::string const host = Sec("95.216.35.232");
|
||||
std::string const host = ("95.216.35.232");
|
||||
|
||||
net::io_context ioc;
|
||||
tcp::resolver r(ioc);
|
||||
|
||||
websocket::stream<tcp::socket> ws(ioc);
|
||||
auto const results = r.resolve(host, Sec("3600"));
|
||||
auto const results = r.resolve(host, ("3600"));
|
||||
net::connect(ws.next_layer(), results.begin(), results.end());
|
||||
|
||||
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (c) 2020 Anonymous275.
|
||||
// BeamMP Server code is not in the public domain and is not free software.
|
||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||
///
|
||||
/// Created by Anonymous275 on 7/17/2020
|
||||
///
|
||||
@ -79,9 +83,9 @@ std::string getDate() {
|
||||
|
||||
void InitLog() {
|
||||
std::ofstream LFS;
|
||||
LFS.open(Sec("Server.log"));
|
||||
LFS.open(("Server.log"));
|
||||
if (!LFS.is_open()) {
|
||||
error(Sec("logger file init failed!"));
|
||||
error(("logger file init failed!"));
|
||||
} else
|
||||
LFS.close();
|
||||
}
|
||||
@ -101,13 +105,13 @@ void DebugPrintTIDInternal(const std::string& func, bool overwrite) {
|
||||
|
||||
void addToLog(const std::string& Line) {
|
||||
std::ofstream LFS;
|
||||
LFS.open(Sec("Server.log"), std::ios_base::app);
|
||||
LFS.open(("Server.log"), std::ios_base::app);
|
||||
LFS << Line.c_str();
|
||||
LFS.close();
|
||||
}
|
||||
void info(const std::string& toPrint) {
|
||||
std::scoped_lock Guard(LogLock);
|
||||
std::string Print = getDate() + Sec("[INFO] ") + toPrint + "\n";
|
||||
std::string Print = getDate() + ("[INFO] ") + toPrint + "\n";
|
||||
ConsoleOut(Print);
|
||||
addToLog(Print);
|
||||
}
|
||||
@ -115,25 +119,25 @@ void debug(const std::string& toPrint) {
|
||||
if (!Debug)
|
||||
return;
|
||||
std::scoped_lock Guard(LogLock);
|
||||
std::string Print = getDate() + Sec("[DEBUG] ") + toPrint + "\n";
|
||||
std::string Print = getDate() + ("[DEBUG] ") + toPrint + "\n";
|
||||
ConsoleOut(Print);
|
||||
addToLog(Print);
|
||||
}
|
||||
void warn(const std::string& toPrint) {
|
||||
std::scoped_lock Guard(LogLock);
|
||||
std::string Print = getDate() + Sec("[WARN] ") + toPrint + "\n";
|
||||
std::string Print = getDate() + ("[WARN] ") + toPrint + "\n";
|
||||
ConsoleOut(Print);
|
||||
addToLog(Print);
|
||||
}
|
||||
void error(const std::string& toPrint) {
|
||||
std::scoped_lock Guard(LogLock);
|
||||
std::string Print = getDate() + Sec("[ERROR] ") + toPrint + "\n";
|
||||
std::string Print = getDate() + ("[ERROR] ") + toPrint + "\n";
|
||||
ConsoleOut(Print);
|
||||
addToLog(Print);
|
||||
}
|
||||
void except(const std::string& toPrint) {
|
||||
std::scoped_lock Guard(LogLock);
|
||||
std::string Print = getDate() + Sec("[EXCEP] ") + toPrint + "\n";
|
||||
std::string Print = getDate() + ("[EXCEP] ") + toPrint + "\n";
|
||||
ConsoleOut(Print);
|
||||
addToLog(Print);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "CustomAssert.h"
|
||||
#include "Security/Xor.h"
|
||||
|
||||
#include "Startup.h"
|
||||
#include <curl/curl.h>
|
||||
#include <iostream>
|
||||
@ -9,10 +9,10 @@
|
||||
void UnixSignalHandler(int sig) {
|
||||
switch (sig) {
|
||||
case SIGPIPE:
|
||||
warn(Sec("ignored signal SIGPIPE: Pipe broken"));
|
||||
warn(("ignored signal SIGPIPE: Pipe broken"));
|
||||
break;
|
||||
default:
|
||||
error(Sec("Signal arrived in handler but was not handled: ") + std::to_string(sig));
|
||||
error(("Signal arrived in handler but was not handled: ") + std::to_string(sig));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user