mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-07-14 10:44:30 +00:00
Compare commits
62 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0cbf62c157 | |||
| 46757951bd | |||
| dba723837c | |||
| b5b625ec10 | |||
| a35887b3c6 | |||
| d28add2747 | |||
| fa3da4ddf2 | |||
| 5ed220c58d | |||
| 8bcc77578b | |||
| 63e071212f | |||
| 471bfff92e | |||
| bde1f24552 | |||
| 69e632e6a9 | |||
| 0c3adb8899 | |||
| c36d6a8380 | |||
| 84b06c94de | |||
| 567a770ed9 | |||
| ea2088d5fd | |||
| bd923acf4e | |||
| 47084841a0 | |||
| 5da2065372 | |||
| 582bb0a021 | |||
| 98673069f2 | |||
| 0f2fa609b1 | |||
| 6f125e08d4 | |||
| 162e1dc922 | |||
| 9a8c9f3cc6 | |||
| bb4b5a3cf8 | |||
| 295f814f0f | |||
| 90a17ec5f4 | |||
| 2fd0d2b0dd | |||
| 876fc617e0 | |||
| df1514a657 | |||
| 96ce0e05a1 | |||
| b0e011cabf | |||
| c598884b9a | |||
| fc6655f104 | |||
| 599c407d77 | |||
| a66614d426 | |||
| 1c409ff354 | |||
| 8ab018485b | |||
| c047565b0a | |||
| 4fe9159b0c | |||
| c05287dbde | |||
| cdb17d4bbb | |||
| 9c1954caf0 | |||
| 22933084d4 | |||
| efdb400747 | |||
| d260563d99 | |||
| 161f8127fa | |||
| c56adcb8c5 | |||
| 59be12f7ac | |||
| 4c99f1df00 | |||
| d04e88c0be | |||
| 1ad65e26b8 | |||
| 1e592f6810 | |||
| 30f69c9c27 | |||
| 0b199d8b2f | |||
| f01756f296 | |||
| f9d023314c | |||
| fff1f56631 | |||
| a28e31d080 |
@@ -113,6 +113,11 @@ jobs:
|
|||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: bash ./scripts/ubuntu-22.04/1-install-deps.sh
|
run: bash ./scripts/ubuntu-22.04/1-install-deps.sh
|
||||||
|
|
||||||
|
- name: Setup vcpkg
|
||||||
|
uses: lukka/run-vcpkg@v11
|
||||||
|
with:
|
||||||
|
runVcpkgInstall: true
|
||||||
|
|
||||||
- name: Create Build Environment
|
- name: Create Build Environment
|
||||||
run: bash ./scripts/ubuntu-22.04/2-configure.sh '-DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake'
|
run: bash ./scripts/ubuntu-22.04/2-configure.sh '-DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake'
|
||||||
|
|
||||||
@@ -131,7 +136,7 @@ jobs:
|
|||||||
asset_content_type: application/x-elf
|
asset_content_type: application/x-elf
|
||||||
|
|
||||||
upload-release-files-windows:
|
upload-release-files-windows:
|
||||||
name: Build and upload Windows Release Files
|
name: Upload Windows Release Files
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
needs: create-release
|
needs: create-release
|
||||||
env:
|
env:
|
||||||
@@ -148,6 +153,11 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
submodules: 'recursive'
|
submodules: 'recursive'
|
||||||
|
|
||||||
|
- name: Setup vcpkg
|
||||||
|
uses: lukka/run-vcpkg@v11
|
||||||
|
with:
|
||||||
|
runVcpkgInstall: true
|
||||||
|
|
||||||
- name: Create Build Environment
|
- name: Create Build Environment
|
||||||
shell: bash
|
shell: bash
|
||||||
run: ./scripts/windows/1-configure.sh
|
run: ./scripts/windows/1-configure.sh
|
||||||
@@ -163,6 +173,6 @@ jobs:
|
|||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
with:
|
with:
|
||||||
upload_url: ${{ needs.create-release.outputs.upload_url }}
|
upload_url: ${{ needs.create-release.outputs.upload_url }}
|
||||||
asset_path: ./bin/BeamMP-Server.exe
|
asset_path: ./bin/Release/BeamMP-Server.exe
|
||||||
asset_name: BeamMP-Server.exe
|
asset_name: BeamMP-Server.exe
|
||||||
asset_content_type: application/vnd.microsoft.portable-executable
|
asset_content_type: application/vnd.microsoft.portable-executable
|
||||||
@@ -117,7 +117,7 @@ Ubuntu 22.04
|
|||||||
git
|
git
|
||||||
libz-dev
|
libz-dev
|
||||||
rapidjson-dev
|
rapidjson-dev
|
||||||
liblua5.3-dev
|
liblua5.3
|
||||||
libssl-dev
|
libssl-dev
|
||||||
libwebsocketpp-dev
|
libwebsocketpp-dev
|
||||||
libcurl4-openssl-dev
|
libcurl4-openssl-dev
|
||||||
@@ -142,6 +142,7 @@ curl
|
|||||||
git
|
git
|
||||||
cmake
|
cmake
|
||||||
g++
|
g++
|
||||||
|
cmake
|
||||||
zlib
|
zlib
|
||||||
boost
|
boost
|
||||||
websocketpp
|
websocketpp
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ public:
|
|||||||
std::string Resource { "Resources" };
|
std::string Resource { "Resources" };
|
||||||
std::string MapName { "/levels/gridmap_v2/info.json" };
|
std::string MapName { "/levels/gridmap_v2/info.json" };
|
||||||
std::string Key {};
|
std::string Key {};
|
||||||
std::string Password{};
|
|
||||||
std::string SSLKeyPath { "./.ssl/HttpServer/key.pem" };
|
std::string SSLKeyPath { "./.ssl/HttpServer/key.pem" };
|
||||||
std::string SSLCertPath { "./.ssl/HttpServer/cert.pem" };
|
std::string SSLCertPath { "./.ssl/HttpServer/cert.pem" };
|
||||||
bool HTTPServerEnabled { false };
|
bool HTTPServerEnabled { false };
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@ public:
|
|||||||
IThreaded()
|
IThreaded()
|
||||||
// invokes operator() on this object
|
// invokes operator() on this object
|
||||||
: mThread() { }
|
: mThread() { }
|
||||||
virtual ~IThreaded() noexcept {
|
~IThreaded() noexcept {
|
||||||
if (mThread.joinable()) {
|
if (mThread.joinable()) {
|
||||||
mThread.join();
|
mThread.join();
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-13
@@ -18,9 +18,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#define SOL_ALL_SAFETIES_ON 1
|
#define SOL_ALL_SAFETIES_ON 1
|
||||||
#define SOL_USER_C_ASSERT SOL_ON
|
|
||||||
#define SOL_C_ASSERT(...) \
|
|
||||||
beammp_lua_errorf("SOL2 assertion failure: Assertion `{}` failed in {}:{}. This *should* be a fatal error, but BeamMP Server overrides it to not be fatal. This may cause the Lua Engine to crash, or cause other issues.", #__VA_ARGS__, __FILE__, __LINE__)
|
|
||||||
#include <sol/sol.hpp>
|
#include <sol/sol.hpp>
|
||||||
|
|
||||||
using TLuaStateId = std::string;
|
using TLuaStateId = std::string;
|
||||||
@@ -44,14 +41,7 @@ struct TLuaResult {
|
|||||||
sol::object Result { sol::lua_nil };
|
sol::object Result { sol::lua_nil };
|
||||||
TLuaStateId StateId;
|
TLuaStateId StateId;
|
||||||
std::string Function;
|
std::string Function;
|
||||||
std::shared_ptr<std::mutex> ReadyMutex {
|
// TODO: Add condition_variable
|
||||||
std::make_shared<std::mutex>()
|
|
||||||
};
|
|
||||||
std::shared_ptr<std::condition_variable> ReadyCondition {
|
|
||||||
std::make_shared<std::condition_variable>()
|
|
||||||
};
|
|
||||||
|
|
||||||
void MarkAsReady();
|
|
||||||
void WaitUntilReady();
|
void WaitUntilReady();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -108,8 +98,8 @@ public:
|
|||||||
return mLuaStates.size();
|
return mLuaStates.size();
|
||||||
}
|
}
|
||||||
std::vector<std::string> GetLuaStateNames() {
|
std::vector<std::string> GetLuaStateNames() {
|
||||||
std::vector<std::string> names {};
|
std::vector<std::string> names{};
|
||||||
for (auto const& [stateId, _] : mLuaStates) {
|
for(auto const& [stateId, _ ] : mLuaStates) {
|
||||||
names.push_back(stateId);
|
names.push_back(stateId);
|
||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
|
|||||||
@@ -52,5 +52,4 @@ private:
|
|||||||
static const uint8_t* SendSplit(TClient& c, ip::tcp::socket& Socket, const uint8_t* DataPtr, size_t Size);
|
static const uint8_t* SendSplit(TClient& c, ip::tcp::socket& Socket, const uint8_t* DataPtr, size_t Size);
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string HashPassword(const std::string& str);
|
|
||||||
std::vector<uint8_t> StringToVector(const std::string& Str);
|
std::vector<uint8_t> StringToVector(const std::string& Str);
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ class TNetwork;
|
|||||||
class TPPSMonitor : public IThreaded {
|
class TPPSMonitor : public IThreaded {
|
||||||
public:
|
public:
|
||||||
explicit TPPSMonitor(TServer& Server);
|
explicit TPPSMonitor(TServer& Server);
|
||||||
virtual ~TPPSMonitor() {}
|
|
||||||
|
|
||||||
void operator()() override;
|
void operator()() override;
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -51,7 +51,7 @@ TClient::TVehicleDataLockPair TClient::GetAllCars() {
|
|||||||
std::string TClient::GetCarPositionRaw(int Ident) {
|
std::string TClient::GetCarPositionRaw(int Ident) {
|
||||||
std::unique_lock lock(mVehiclePositionMutex);
|
std::unique_lock lock(mVehiclePositionMutex);
|
||||||
try {
|
try {
|
||||||
return mVehiclePosition.at(size_t(Ident));
|
return mVehiclePosition.at(Ident);
|
||||||
} catch (const std::out_of_range& oor) {
|
} catch (const std::out_of_range& oor) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ void TClient::Disconnect(std::string_view Reason) {
|
|||||||
|
|
||||||
void TClient::SetCarPosition(int Ident, const std::string& Data) {
|
void TClient::SetCarPosition(int Ident, const std::string& Data) {
|
||||||
std::unique_lock lock(mVehiclePositionMutex);
|
std::unique_lock lock(mVehiclePositionMutex);
|
||||||
mVehiclePosition[size_t(Ident)] = Data;
|
mVehiclePosition[Ident] = Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TClient::GetCarData(int Ident) {
|
std::string TClient::GetCarData(int Ident) {
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ static constexpr std::string_view StrDescription = "Description";
|
|||||||
static constexpr std::string_view StrResourceFolder = "ResourceFolder";
|
static constexpr std::string_view StrResourceFolder = "ResourceFolder";
|
||||||
static constexpr std::string_view StrAuthKey = "AuthKey";
|
static constexpr std::string_view StrAuthKey = "AuthKey";
|
||||||
static constexpr std::string_view StrLogChat = "LogChat";
|
static constexpr std::string_view StrLogChat = "LogChat";
|
||||||
static constexpr std::string_view StrPassword = "Password";
|
|
||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
static constexpr std::string_view StrSendErrors = "SendErrors";
|
static constexpr std::string_view StrSendErrors = "SendErrors";
|
||||||
@@ -107,8 +106,6 @@ void TConfig::FlushToFile() {
|
|||||||
data["General"][StrMap.data()] = Application::Settings.MapName;
|
data["General"][StrMap.data()] = Application::Settings.MapName;
|
||||||
data["General"][StrDescription.data()] = Application::Settings.ServerDesc;
|
data["General"][StrDescription.data()] = Application::Settings.ServerDesc;
|
||||||
data["General"][StrResourceFolder.data()] = Application::Settings.Resource;
|
data["General"][StrResourceFolder.data()] = Application::Settings.Resource;
|
||||||
data["General"][StrPassword.data()] = Application::Settings.Password;
|
|
||||||
SetComment(data["General"][StrPassword.data()].comments(), " Sets a password on this server, which restricts people from joining. To join, a player must enter this exact password. Leave empty ("") to disable the password.");
|
|
||||||
// Misc
|
// Misc
|
||||||
data["Misc"][StrHideUpdateMessages.data()] = Application::Settings.HideUpdateMessages;
|
data["Misc"][StrHideUpdateMessages.data()] = Application::Settings.HideUpdateMessages;
|
||||||
SetComment(data["Misc"][StrHideUpdateMessages.data()].comments(), " Hides the periodic update message which notifies you of a new server version. You should really keep this on and always update as soon as possible. For more information visit https://wiki.beammp.com/en/home/server-maintenance#updating-the-server. An update message will always appear at startup regardless.");
|
SetComment(data["Misc"][StrHideUpdateMessages.data()].comments(), " Hides the periodic update message which notifies you of a new server version. You should really keep this on and always update as soon as possible. For more information visit https://wiki.beammp.com/en/home/server-maintenance#updating-the-server. An update message will always appear at startup regardless.");
|
||||||
@@ -192,7 +189,6 @@ void TConfig::ParseFromFile(std::string_view name) {
|
|||||||
TryReadValue(data, "General", StrResourceFolder, Application::Settings.Resource);
|
TryReadValue(data, "General", StrResourceFolder, Application::Settings.Resource);
|
||||||
TryReadValue(data, "General", StrAuthKey, Application::Settings.Key);
|
TryReadValue(data, "General", StrAuthKey, Application::Settings.Key);
|
||||||
TryReadValue(data, "General", StrLogChat, Application::Settings.LogChat);
|
TryReadValue(data, "General", StrLogChat, Application::Settings.LogChat);
|
||||||
TryReadValue(data, "General", StrPassword, Application::Settings.Password);
|
|
||||||
// Misc
|
// Misc
|
||||||
TryReadValue(data, "Misc", StrSendErrors, Application::Settings.SendErrors);
|
TryReadValue(data, "Misc", StrSendErrors, Application::Settings.SendErrors);
|
||||||
TryReadValue(data, "Misc", StrHideUpdateMessages, Application::Settings.HideUpdateMessages);
|
TryReadValue(data, "Misc", StrHideUpdateMessages, Application::Settings.HideUpdateMessages);
|
||||||
@@ -244,7 +240,6 @@ void TConfig::PrintDebug() {
|
|||||||
beammp_debug(std::string(StrHTTPServerIP) + ": \"" + Application::Settings.HTTPServerIP + "\"");
|
beammp_debug(std::string(StrHTTPServerIP) + ": \"" + Application::Settings.HTTPServerIP + "\"");
|
||||||
// special!
|
// special!
|
||||||
beammp_debug("Key Length: " + std::to_string(Application::Settings.Key.length()) + "");
|
beammp_debug("Key Length: " + std::to_string(Application::Settings.Key.length()) + "");
|
||||||
beammp_debug("Password Protected: " + std::string(Application::Settings.Password.empty() ? "false" : "true"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TConfig::ParseOldFormat() {
|
void TConfig::ParseOldFormat() {
|
||||||
|
|||||||
+3
-1
@@ -606,7 +606,9 @@ TConsole::TConsole() {
|
|||||||
HandleLuaInternalCommand(cmd.substr(1));
|
HandleLuaInternalCommand(cmd.substr(1));
|
||||||
} else {
|
} else {
|
||||||
auto Future = mLuaEngine->EnqueueScript(mStateId, { std::make_shared<std::string>(TrimmedCmd), "", "" });
|
auto Future = mLuaEngine->EnqueueScript(mStateId, { std::make_shared<std::string>(TrimmedCmd), "", "" });
|
||||||
Future->WaitUntilReady();
|
while (!Future->Ready) {
|
||||||
|
std::this_thread::yield(); // TODO: Add a timeout
|
||||||
|
}
|
||||||
if (Future->Error) {
|
if (Future->Error) {
|
||||||
beammp_lua_error("error in " + mStateId + ": " + Future->ErrorMessage);
|
beammp_lua_error("error in " + mStateId + ": " + Future->ErrorMessage);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,8 +133,7 @@ std::string THeartbeatThread::GenerateCall() {
|
|||||||
<< "&modstotalsize=" << mResourceManager.MaxModSize()
|
<< "&modstotalsize=" << mResourceManager.MaxModSize()
|
||||||
<< "&modstotal=" << mResourceManager.ModsLoaded()
|
<< "&modstotal=" << mResourceManager.ModsLoaded()
|
||||||
<< "&playerslist=" << GetPlayers()
|
<< "&playerslist=" << GetPlayers()
|
||||||
<< "&desc=" << Application::Settings.ServerDesc
|
<< "&desc=" << Application::Settings.ServerDesc;
|
||||||
<< "&pass=" << (Application::Settings.Password.empty() ? "false" : "true");
|
|
||||||
return Ret.str();
|
return Ret.str();
|
||||||
}
|
}
|
||||||
THeartbeatThread::THeartbeatThread(TResourceManager& ResourceManager, TServer& Server)
|
THeartbeatThread::THeartbeatThread(TResourceManager& ResourceManager, TServer& Server)
|
||||||
|
|||||||
+8
-18
@@ -286,7 +286,6 @@ void TLuaEngine::WaitForAll(std::vector<std::shared_ptr<TLuaResult>>& Results, c
|
|||||||
bool Cancelled = false;
|
bool Cancelled = false;
|
||||||
size_t ms = 0;
|
size_t ms = 0;
|
||||||
std::set<std::string> WarnedResults;
|
std::set<std::string> WarnedResults;
|
||||||
|
|
||||||
while (!Result->Ready && !Cancelled) {
|
while (!Result->Ready && !Cancelled) {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
ms += 10;
|
ms += 10;
|
||||||
@@ -301,7 +300,6 @@ void TLuaEngine::WaitForAll(std::vector<std::shared_ptr<TLuaResult>>& Results, c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Cancelled) {
|
if (Cancelled) {
|
||||||
beammp_lua_warn("'" + Result->Function + "' in '" + Result->StateId + "' failed to execute in time and was not waited for. It may still finish executing at a later time.");
|
beammp_lua_warn("'" + Result->Function + "' in '" + Result->StateId + "' failed to execute in time and was not waited for. It may still finish executing at a later time.");
|
||||||
LuaAPI::MP::Engine->ReportErrors({ Result });
|
LuaAPI::MP::Engine->ReportErrors({ Result });
|
||||||
@@ -427,7 +425,7 @@ sol::table TLuaEngine::StateThreadData::Lua_TriggerGlobalEvent(const std::string
|
|||||||
Result->Error = true;
|
Result->Error = true;
|
||||||
Result->ErrorMessage = "Function result in TriggerGlobalEvent was invalid";
|
Result->ErrorMessage = "Function result in TriggerGlobalEvent was invalid";
|
||||||
}
|
}
|
||||||
Result->MarkAsReady();
|
Result->Ready = true;
|
||||||
Return.push_back(Result);
|
Return.push_back(Result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -957,7 +955,7 @@ void TLuaEngine::StateThreadData::operator()() {
|
|||||||
sol::error Err = Res;
|
sol::error Err = Res;
|
||||||
S.second->ErrorMessage = Err.what();
|
S.second->ErrorMessage = Err.what();
|
||||||
}
|
}
|
||||||
S.second->MarkAsReady();
|
S.second->Ready = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{ // StateFunctionQueue Scope
|
{ // StateFunctionQueue Scope
|
||||||
@@ -1018,11 +1016,11 @@ void TLuaEngine::StateThreadData::operator()() {
|
|||||||
sol::error Err = Res;
|
sol::error Err = Res;
|
||||||
Result->ErrorMessage = Err.what();
|
Result->ErrorMessage = Err.what();
|
||||||
}
|
}
|
||||||
Result->MarkAsReady();
|
Result->Ready = true;
|
||||||
} else {
|
} else {
|
||||||
Result->Error = true;
|
Result->Error = true;
|
||||||
Result->ErrorMessage = BeamMPFnNotFoundError; // special error kind that we can ignore later
|
Result->ErrorMessage = BeamMPFnNotFoundError; // special error kind that we can ignore later
|
||||||
Result->MarkAsReady();
|
Result->Ready = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1072,19 +1070,11 @@ void TLuaEngine::StateThreadData::AddPath(const fs::path& Path) {
|
|||||||
mPaths.push(Path);
|
mPaths.push(Path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TLuaResult::MarkAsReady() {
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> readyLock(*this->ReadyMutex);
|
|
||||||
this->Ready = true;
|
|
||||||
}
|
|
||||||
this->ReadyCondition->notify_all();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TLuaResult::WaitUntilReady() {
|
void TLuaResult::WaitUntilReady() {
|
||||||
std::unique_lock readyLock(*this->ReadyMutex);
|
while (!Ready) {
|
||||||
// wait if not ready yet
|
std::this_thread::yield();
|
||||||
if(!this->Ready)
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
this->ReadyCondition->wait(readyLock);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TLuaChunk::TLuaChunk(std::shared_ptr<std::string> Content, std::string FileName, std::string PluginPath)
|
TLuaChunk::TLuaChunk(std::shared_ptr<std::string> Content, std::string FileName, std::string PluginPath)
|
||||||
|
|||||||
+1
-30
@@ -11,8 +11,6 @@
|
|||||||
#include <boost/asio/ip/address_v4.hpp>
|
#include <boost/asio/ip/address_v4.hpp>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
typedef boost::asio::detail::socket_option::integer<SOL_SOCKET, SO_RCVTIMEO> rcv_timeout_option;
|
|
||||||
|
|
||||||
std::vector<uint8_t> StringToVector(const std::string& Str) {
|
std::vector<uint8_t> StringToVector(const std::string& Str) {
|
||||||
return std::vector<uint8_t>(Str.data(), Str.data() + Str.size());
|
return std::vector<uint8_t>(Str.data(), Str.data() + Str.size());
|
||||||
}
|
}
|
||||||
@@ -227,15 +225,6 @@ void TNetwork::HandleDownload(TConnection&& Conn) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string HashPassword(const std::string& str) {
|
|
||||||
std::stringstream ret;
|
|
||||||
unsigned char* hash = SHA256(reinterpret_cast<const unsigned char*>(str.c_str()), str.length(), nullptr);
|
|
||||||
for (int i = 0; i < 32; i++) {
|
|
||||||
ret << std::hex << static_cast<int>(hash[i]);
|
|
||||||
}
|
|
||||||
return ret.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
|
std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
|
||||||
auto Client = CreateClient(std::move(RawConnection.Socket));
|
auto Client = CreateClient(std::move(RawConnection.Socket));
|
||||||
Client->SetIdentifier("ip", RawConnection.SockAddr.address().to_string());
|
Client->SetIdentifier("ip", RawConnection.SockAddr.address().to_string());
|
||||||
@@ -259,8 +248,7 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
|
|||||||
ClientKick(*Client, fmt::format("Invalid version header: '{}' ({})", std::string(reinterpret_cast<const char*>(Data.data()), Data.size()), Data.size()));
|
ClientKick(*Client, fmt::format("Invalid version header: '{}' ({})", std::string(reinterpret_cast<const char*>(Data.data()), Data.size()), Data.size()));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
if (!TCPSend(*Client, StringToVector("S"))) {
|
||||||
if (!TCPSend(*Client, StringToVector("A"))) { //changed to A for Accepted version
|
|
||||||
// TODO: handle
|
// TODO: handle
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,22 +304,6 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Application::Settings.Password.empty()) { // ask password
|
|
||||||
if(!TCPSend(*Client, StringToVector("S"))) {
|
|
||||||
// TODO: handle
|
|
||||||
}
|
|
||||||
beammp_info("Waiting for password");
|
|
||||||
Data = TCPRcv(*Client);
|
|
||||||
std::string Pass = std::string(reinterpret_cast<const char*>(Data.data()), Data.size());
|
|
||||||
if(Pass != HashPassword(Application::Settings.Password)) {
|
|
||||||
beammp_debug(Client->GetName() + " attempted to connect with a wrong password");
|
|
||||||
ClientKick(*Client, "Wrong password!");
|
|
||||||
return {};
|
|
||||||
} else {
|
|
||||||
beammp_debug(Client->GetName() + " used the correct password");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
beammp_debug("Name -> " + Client->GetName() + ", Guest -> " + std::to_string(Client->IsGuest()) + ", Roles -> " + Client->GetRoles());
|
beammp_debug("Name -> " + Client->GetName() + ", Guest -> " + std::to_string(Client->IsGuest()) + ", Roles -> " + Client->GetRoles());
|
||||||
mServer.ForEachClient([&](const std::weak_ptr<TClient>& ClientPtr) -> bool {
|
mServer.ForEachClient([&](const std::weak_ptr<TClient>& ClientPtr) -> bool {
|
||||||
std::shared_ptr<TClient> Cl;
|
std::shared_ptr<TClient> Cl;
|
||||||
@@ -381,7 +353,6 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
|
|||||||
} else {
|
} else {
|
||||||
ClientKick(*Client, "Server full!");
|
ClientKick(*Client, "Server full!");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Client;
|
return Client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user