Compare commits

..

62 Commits

Author SHA1 Message Date
Lion Kortlepel 0cbf62c157 add release action 2023-12-05 16:44:17 +01:00
Lion Kortlepel 46757951bd use vcpkg caching everywhere 2023-12-05 16:40:43 +01:00
Lion Kortlepel dba723837c try using x-gha 2023-12-05 16:38:14 +01:00
Lion Kortlepel b5b625ec10 fix windows path 2023-12-05 16:34:22 +01:00
Lion Kortlepel a35887b3c6 invalidate cache on vcpkg.json change 2023-12-05 16:32:32 +01:00
Lion Kortlepel d28add2747 move commandline custom build down in the file 2023-12-05 16:24:35 +01:00
Lion Kortlepel fa3da4ddf2 cache vcpkg buildtrees 2023-12-05 16:23:02 +01:00
Lion Kortlepel 5ed220c58d add commandline custom build 2023-12-05 15:42:25 +01:00
Lion Kortlepel 8bcc77578b try building commandline static 2023-12-05 15:37:03 +01:00
Lion Kortlepel 63e071212f update commandline 2023-12-05 15:35:01 +01:00
Lion Kortlepel 471bfff92e attempt to fix windows workflow 2023-12-05 15:30:42 +01:00
Lion Kortlepel bde1f24552 fix runtime deps for tests runs 2023-12-05 15:16:52 +01:00
Lion Kortlepel 69e632e6a9 add include dirs to tests executable 2023-12-05 15:11:12 +01:00
Lion Kortlepel 0c3adb8899 fix target triplet in windows workflow 2023-12-05 15:08:54 +01:00
Lion Kortlepel c36d6a8380 add unit test running step 2023-12-05 14:54:08 +01:00
Lion Kortlepel 84b06c94de set triplet before running vcpkg 2023-12-05 14:47:46 +01:00
Lion Kortlepel 567a770ed9 fix vcpkg cmake to not run when CMAKE_TOOLCHAIN_FILE is defined 2023-12-05 14:47:02 +01:00
Lion Kortlepel ea2088d5fd use static windows vcpkg triplet 2023-12-05 14:32:23 +01:00
Lion Kortlepel bd923acf4e add windows build step 2023-12-05 14:29:09 +01:00
Lion Kortlepel 47084841a0 consolidate build workflows into one file for linux 2023-12-05 14:13:22 +01:00
Lion Kortlepel 5da2065372 fix syntax error in ubuntu workflow 2023-12-05 14:09:56 +01:00
Lion Kortlepel 582bb0a021 add toolchain file to configure call to skip second vcpkg install step 2023-12-05 14:08:31 +01:00
Lion Kortlepel 98673069f2 remove cat from configure step 2023-12-05 14:07:36 +01:00
Lion Kortlepel 0f2fa609b1 add mutex include to tconsole.h 2023-12-05 14:03:38 +01:00
Lion Kortlepel 6f125e08d4 fix compile error in tconsole 2023-12-05 14:00:59 +01:00
Lion Kortlepel 162e1dc922 run ubuntu build in container 2023-12-05 14:00:13 +01:00
Lion Kortlepel 9a8c9f3cc6 fix ubuntu build to actually be called ubuntu build 2023-12-05 13:59:31 +01:00
Lion Kortlepel bb4b5a3cf8 add ubuntu 22.04 build step 2023-12-05 13:58:34 +01:00
Lion Kortlepel 295f814f0f run vcpkg install before configure 2023-12-05 13:55:02 +01:00
Lion Kortlepel 90a17ec5f4 add back vcpkg step 2023-12-05 13:53:32 +01:00
Lion Kortlepel 2fd0d2b0dd remove vcpkg step again 2023-12-05 13:52:35 +01:00
Lion Kortlepel 876fc617e0 fix vcpkg.json to not include a baseline commit 2023-12-05 13:51:45 +01:00
Lion Kortlepel df1514a657 set toolchain file 2023-12-05 13:49:20 +01:00
Lion Kortlepel 96ce0e05a1 add git safe 2023-12-05 13:45:13 +01:00
Lion Kortlepel b0e011cabf add safe directories 2023-12-05 13:42:42 +01:00
Lion Kortlepel c598884b9a remove vcpkg fetch 2023-12-05 13:39:51 +01:00
Lion Kortlepel fc6655f104 add git fetch before cmake configure 2023-12-05 13:35:29 +01:00
Lion Kortlepel 599c407d77 update vcpkg 2023-12-05 13:31:46 +01:00
Lion Kortlepel a66614d426 remove manual clone of commandline 2023-12-05 13:31:13 +01:00
Lion Kortlepel 1c409ff354 add git 2023-12-05 13:30:34 +01:00
Lion Kortlepel 8ab018485b add back recursive fetch 2023-12-05 13:29:59 +01:00
Lion Kortlepel c047565b0a remove apt upgrade 2023-12-05 13:28:08 +01:00
Lion Kortlepel 4fe9159b0c clone commandline if not exists 2023-12-05 13:27:19 +01:00
Lion Kortlepel c05287dbde remove workdir 2023-12-05 13:25:03 +01:00
Lion Kortlepel cdb17d4bbb add submodule fetch 2023-12-05 13:23:30 +01:00
Lion Kortlepel 9c1954caf0 no sudo 2023-12-05 13:22:02 +01:00
Lion Kortlepel 22933084d4 fix run 2023-12-05 13:21:31 +01:00
Lion Kortlepel efdb400747 remove tests for now 2023-12-05 13:20:23 +01:00
Lion Kortlepel d260563d99 try using debian 2023-12-05 13:19:28 +01:00
Lion Kortlepel 161f8127fa simplify build steps 2023-12-05 13:18:43 +01:00
Lion Kortlepel c56adcb8c5 take source dir from cli args 2023-12-04 16:11:18 +01:00
Lion Kortlepel 59be12f7ac fix runtime deps 2023-12-04 16:07:35 +01:00
Lion Kortlepel 4c99f1df00 fix paths 2023-12-04 16:05:07 +01:00
Lion Kortlepel d04e88c0be create build dir before running cmake 2023-12-04 16:01:13 +01:00
Lion Kortlepel 1ad65e26b8 Revert "remove shebang from scripts"
This reverts commit 1e592f6810.
2023-12-04 15:58:16 +01:00
Lion Kortlepel 1e592f6810 remove shebang from scripts 2023-12-04 15:53:49 +01:00
Lion Kortlepel 30f69c9c27 run ci scripts explicitly with sudo 2023-12-04 15:50:14 +01:00
Lion Kortlepel 0b199d8b2f remove unused submodules 2023-12-04 15:47:22 +01:00
Lion Kortlepel f01756f296 fix compile errors & remove sentry 2023-12-04 15:46:39 +01:00
Lion Kortlepel f9d023314c run install scripts as sudo 2023-12-04 15:33:28 +01:00
Lion Kortlepel fff1f56631 switch to vcpkg+cmake build system 2023-12-04 15:31:03 +01:00
Lion Kortlepel a28e31d080 update commandline 2023-12-04 15:03:23 +01:00
18 changed files with 158 additions and 111 deletions
@@ -1,5 +1,5 @@
---
name: Feature
name: Feature request
about: Suggest an idea for this project
title: "[Feature Request]"
labels: enhancement
@@ -7,13 +7,14 @@ assignees: ''
---
#### **Describe the feature you'd like in detail**
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. For example: "I'm always frustrated when ...".
**Describe the solution you'd like**
A clear and concise description of what you want to happen. Also supply OS information if relevant, for example "*On Linux*, I would like to be able to...".
#### **Describe alternatives you've considered**
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
#### **Acceptance Criteria**
- [ ] *Only fill this out if you're a developer, otherwise leave as-is*
**Additional context**
Add any other context about the feature request here.
+1 -2
View File
@@ -4,7 +4,6 @@ on: [push]
env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
CMAKE_BUILD_TYPE: "Release"
jobs:
debian-11-build:
@@ -148,4 +147,4 @@ jobs:
- name: Test
run: |
chmod +x ./BeamMP-Server-tests
./BeamMP-Server-tests
./BeamMP-Server-tests
+13 -4
View File
@@ -7,7 +7,6 @@ on:
env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
CMAKE_BUILD_TYPE: "Release"
jobs:
create-release:
@@ -28,7 +27,7 @@ jobs:
prerelease: true
body: |
Files included in this release:
- `BeamMP-Server.exe` is the windows build. You need to install the [Visual C++ Redistributables](https://aka.ms/vs/17/release/vc_redist.x64.exe) to run this.
- `BeamMP-Server.exe` is the windows build.
- `BeamMP-Server-debian` is a Debian 11 build, requires `liblua5.3-0`.
- `BeamMP-Server-ubuntu` is a Ubuntu 22.04 build, requires `liblua5.3-0`.
@@ -114,6 +113,11 @@ jobs:
- name: Install Dependencies
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
run: bash ./scripts/ubuntu-22.04/2-configure.sh '-DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake'
@@ -132,7 +136,7 @@ jobs:
asset_content_type: application/x-elf
upload-release-files-windows:
name: Build and upload Windows Release Files
name: Upload Windows Release Files
runs-on: windows-latest
needs: create-release
env:
@@ -149,6 +153,11 @@ jobs:
with:
submodules: 'recursive'
- name: Setup vcpkg
uses: lukka/run-vcpkg@v11
with:
runVcpkgInstall: true
- name: Create Build Environment
shell: bash
run: ./scripts/windows/1-configure.sh
@@ -166,4 +175,4 @@ jobs:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ./bin/Release/BeamMP-Server.exe
asset_name: BeamMP-Server.exe
asset_content_type: application/vnd.microsoft.portable-executable
asset_content_type: application/vnd.microsoft.portable-executable
+1 -2
View File
@@ -5,7 +5,6 @@ on: [push]
env:
VCPKG_DEFAULT_TRIPLET: x64-windows-static
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
CMAKE_BUILD_TYPE: "Release"
jobs:
windows-build:
@@ -39,5 +38,5 @@ jobs:
uses: actions/upload-artifact@v2
with:
name: BeamMP-Server-windows
path: ./bin/Release/BeamMP-Server.exe
path: ./bin/BeamMP-Server.exe
+3 -4
View File
@@ -126,10 +126,9 @@ include(FindThreads)
# enables compile_commands.json for clang-related tools (such as the clang LS)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# build release builds by default (if not specified otherwise)
if(NOT DEFINED CMAKE_BUILD_TYPE)
message(NOTICE "No build type specified, defaulting to 'Release'")
set(CMAKE_BUILD_TYPE "Release")
# build debug builds by default (if not specified otherwise)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
if(UNIX)
+112 -19
View File
@@ -6,7 +6,7 @@
This is the server for the multiplayer mod **[BeamMP](https://beammp.com/)** for the game [BeamNG.drive](https://www.beamng.com/).
The server is the point through which all clients communicate. You can write Lua mods for the server, there are detailed instructions on the [BeamMP Wiki](https://wiki.beammp.com).
**For Linux, you __need__ the runtime dependencies, which are listed below under [Runtime Dependencies](#runtime-dependencies)**
**For Linux, you __need__ the runtime dependencies, listed below under "[prerequisites](#prerequisites)".**
## Support + Contact
@@ -43,7 +43,7 @@ We only allow building unmodified (original) source code for public use. `master
## Supported Operating Systems
The code itself supports (latest stable) Linux and Windows. In terms of actual build support, for now we usually only distribute Windows binaries and Linux. For any other distro or OS, you just have to find the same libraries listed in [Runtime Dependencies](#runtime-dependencies) further down the page, and it should build fine.
The code itself supports (latest stable) Linux and Windows. In terms of actual build support, for now we usually only distribute Windows binaries and sometimes Linux. For any other distro or OS, you just have to find the same libraries listed in the Linux Build [Prerequisites](#prerequisites) further down the page, and it should build fine. We don't currently support any big-endian architectures.
Recommended compilers: MSVC, GCC, CLANG.
@@ -51,35 +51,128 @@ You can find precompiled binaries under [Releases](https://github.com/BeamMP/Bea
## Build Instructions
On Linux, you need some dependencies to **build** the server (on Windows, you don't):
**__Do not compile from `master`. Always build from a release tag, i.e. `tags/v3.1.0`!__**
For Debian, Ubuntu and others you can find scripts that do this in `scripts/`.
Currently only Linux and Windows are supported (generally). See [Releases](https://github.com/BeamMP/BeamMP-Server/releases/) for official binary releases. On systems to which we do not provide binaries (so anything but windows), you are allowed to compile the program and use it. Other restrictions, such as not being allowed to distribute those binaries, still apply (see [copyright notice](#copyright)).
### Prerequisites
#### Windows
There are **no runtime libraries** needed for Windows.
Please use the prepackaged binaries in [Releases](https://github.com/BeamMP/BeamMP-Server/releases/).
Dependencies for **Windows** can be installed with `vcpkg`.
These are:
```
liblua5.3-dev curl zip unzip tar cmake make git g++
lua zlib rapidjson openssl websocketpp curl
```
The triplet we use for releases is `x64-windows-static`.
The names of each package may change depending on your platform. See in `scripts/` or use a search engine to find out what they're called for you.
#### Linux
You can build on **Windows, Linux** or other platforms by following these steps:
We recommend Ubuntu 22.04 or Arch Linux. Any Linux distribution will work, but you have to figure out the package names yourself (please feel free to PR in a change to this README with that info).
1. Check out the repository with git: `git clone --recursive https://github.com/BeamMP/BeamMP-Server`.
2. Go into the directory `cd BeamMP-Server`.
3. Run CMake `cmake -S . -B bin -DCMAKE_BUILD_TYPE=Release` - this can take a few minutes and may take a lot of disk space and bandwidth.
4. Build via `cmake --build bin --parallel -t BeamMP-Server`.
5. Your executable can be found in `bin/`.
When you make changes to the code, you only have to run step 4 again.
### Runtime Dependencies
##### Runtime Dependencies
These are needed to *run* the server.
Debian, Ubuntu and friends: `liblua5.3-0`
<details>
<summary>
Ubuntu 22.04
</summary>
Other Linux distros: `liblua` of *some kind*.
`apt-get install` the following libraries:
```
liblua5.3-0
libssl3
curl
```
</details>
Windows: No libraries.
<details>
<summary>
Arch Linux
</summary>
`pacman -Syu` the following libraries:
```
lua53
openssl
curl
```
</details>
##### Build Dependencies
These are needed for you to *build* the server, in addition to the [runtime dependencies](#runtime-dependencies).
<details>
<summary>
Ubuntu 22.04
</summary>
`apt-get install` the following libraries and programs:
```
git
libz-dev
rapidjson-dev
liblua5.3
libssl-dev
libwebsocketpp-dev
libcurl4-openssl-dev
cmake
g++-10
libboost1.74-all-dev
libssl3
curl
```
</details>
<details>
<summary>
Arch Linux
</summary>
`pacman -Syu` the following libraries and programs:
```
lua53
openssl
curl
git
cmake
g++
cmake
zlib
boost
websocketpp
```
</details>
#### macOS
Dependencies for **macOS** can be installed with homebrew.
```
brew install lua@5.3 rapidjson websocketpp cmake openssl@1.1
```
Some packages are included in **macOS** but you might want to install homebrew versions.
```
brew install curl zlib git make
```
### How to build
On Windows, use git-bash for these commands. On Linux, these should work in your shell.
1. Make sure you have all [prerequisites](#prerequisites) installed
2. Clone the repository in a location of your choice with `git clone https://github.com/BeamMP/BeamMP-Server` .
3. Change into the BeamMP-Server directory by running `cd BeamMP-Server`.
4. Checkout the branch or tag of the release you want to compile, for example `git checkout tags/v3.0.2` for version 3.0.2. You can find the latest version [here](https://github.com/BeamMP/BeamMP-Server/tags).
6. Run `cmake . -DCMAKE_BUILD_TYPE=Release` (with `.`). This may take some time, and will update all submodules and prepare the build.
7. Run `make -j` . This step will take some time and will use a lot of CPU and RAM. Remove the `-j` if you run out of memory. *If you change something in the source code, you only have to re-run this step.*
8. You now have a `BeamMP-Server` file in your directory, which is executable with `./BeamMP-Server` (`.\BeamMP-Server.exe` for windows). Follow the (Windows or Linux, doesnt matter) instructions on the [wiki](https://wiki.beammp.com/en/home/server-installation) for further setup after installation (which we just did), such as port-forwarding and getting a key to actually run the server.
*tip: to run the server in the background, simply (in bash, zsh, etc) run:* `nohup ./BeamMP-Server &`*.*
## Support
The BeamMP project is supported by community donations via our [Patreon](https://www.patreon.com/BeamMP). This brings perks such as Patreon-only channels on our Discord, early access to new updates, and more server keys.
+1 -2
View File
@@ -46,7 +46,6 @@ public:
std::string Resource { "Resources" };
std::string MapName { "/levels/gridmap_v2/info.json" };
std::string Key {};
std::string Password{};
std::string SSLKeyPath { "./.ssl/HttpServer/key.pem" };
std::string SSLCertPath { "./.ssl/HttpServer/cert.pem" };
bool HTTPServerEnabled { false };
@@ -135,7 +134,7 @@ private:
static inline std::mutex mShutdownHandlersMutex {};
static inline std::deque<TShutdownHandler> mShutdownHandlers {};
static inline Version mVersion { 3, 1, 3 };
static inline Version mVersion { 3, 1, 2 };
};
std::string ThreadName(bool DebugModeOverride = false);
+1 -1
View File
@@ -8,7 +8,7 @@ public:
IThreaded()
// invokes operator() on this object
: mThread() { }
virtual ~IThreaded() noexcept {
~IThreaded() noexcept {
if (mThread.joinable()) {
mThread.join();
}
+3 -10
View File
@@ -41,14 +41,7 @@ struct TLuaResult {
sol::object Result { sol::lua_nil };
TLuaStateId StateId;
std::string Function;
std::shared_ptr<std::mutex> ReadyMutex {
std::make_shared<std::mutex>()
};
std::shared_ptr<std::condition_variable> ReadyCondition {
std::make_shared<std::condition_variable>()
};
void MarkAsReady();
// TODO: Add condition_variable
void WaitUntilReady();
};
@@ -105,8 +98,8 @@ public:
return mLuaStates.size();
}
std::vector<std::string> GetLuaStateNames() {
std::vector<std::string> names {};
for (auto const& [stateId, _] : mLuaStates) {
std::vector<std::string> names{};
for(auto const& [stateId, _ ] : mLuaStates) {
names.push_back(stateId);
}
return names;
-1
View File
@@ -52,5 +52,4 @@ private:
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);
-1
View File
@@ -9,7 +9,6 @@ class TNetwork;
class TPPSMonitor : public IThreaded {
public:
explicit TPPSMonitor(TServer& Server);
virtual ~TPPSMonitor() {}
void operator()() override;
+1 -1
View File
@@ -2,4 +2,4 @@
set -ex
cmake --build bin --parallel -t BeamMP-Server --config Release
cmake --build bin --parallel -t BeamMP-Server
+2 -2
View File
@@ -51,7 +51,7 @@ TClient::TVehicleDataLockPair TClient::GetAllCars() {
std::string TClient::GetCarPositionRaw(int Ident) {
std::unique_lock lock(mVehiclePositionMutex);
try {
return mVehiclePosition.at(size_t(Ident));
return mVehiclePosition.at(Ident);
} catch (const std::out_of_range& oor) {
return "";
}
@@ -73,7 +73,7 @@ void TClient::Disconnect(std::string_view Reason) {
void TClient::SetCarPosition(int Ident, const std::string& Data) {
std::unique_lock lock(mVehiclePositionMutex);
mVehiclePosition[size_t(Ident)] = Data;
mVehiclePosition[Ident] = Data;
}
std::string TClient::GetCarData(int Ident) {
-5
View File
@@ -18,7 +18,6 @@ static constexpr std::string_view StrDescription = "Description";
static constexpr std::string_view StrResourceFolder = "ResourceFolder";
static constexpr std::string_view StrAuthKey = "AuthKey";
static constexpr std::string_view StrLogChat = "LogChat";
static constexpr std::string_view StrPassword = "Password";
// Misc
static constexpr std::string_view StrSendErrors = "SendErrors";
@@ -107,8 +106,6 @@ void TConfig::FlushToFile() {
data["General"][StrMap.data()] = Application::Settings.MapName;
data["General"][StrDescription.data()] = Application::Settings.ServerDesc;
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
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.");
@@ -192,7 +189,6 @@ void TConfig::ParseFromFile(std::string_view name) {
TryReadValue(data, "General", StrResourceFolder, Application::Settings.Resource);
TryReadValue(data, "General", StrAuthKey, Application::Settings.Key);
TryReadValue(data, "General", StrLogChat, Application::Settings.LogChat);
TryReadValue(data, "General", StrPassword, Application::Settings.Password);
// Misc
TryReadValue(data, "Misc", StrSendErrors, Application::Settings.SendErrors);
TryReadValue(data, "Misc", StrHideUpdateMessages, Application::Settings.HideUpdateMessages);
@@ -244,7 +240,6 @@ void TConfig::PrintDebug() {
beammp_debug(std::string(StrHTTPServerIP) + ": \"" + Application::Settings.HTTPServerIP + "\"");
// special!
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() {
+3 -1
View File
@@ -606,7 +606,9 @@ TConsole::TConsole() {
HandleLuaInternalCommand(cmd.substr(1));
} else {
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) {
beammp_lua_error("error in " + mStateId + ": " + Future->ErrorMessage);
}
+1 -2
View File
@@ -133,8 +133,7 @@ std::string THeartbeatThread::GenerateCall() {
<< "&modstotalsize=" << mResourceManager.MaxModSize()
<< "&modstotal=" << mResourceManager.ModsLoaded()
<< "&playerslist=" << GetPlayers()
<< "&desc=" << Application::Settings.ServerDesc
<< "&pass=" << (Application::Settings.Password.empty() ? "false" : "true");
<< "&desc=" << Application::Settings.ServerDesc;
return Ret.str();
}
THeartbeatThread::THeartbeatThread(TResourceManager& ResourceManager, TServer& Server)
+8 -18
View File
@@ -286,7 +286,6 @@ void TLuaEngine::WaitForAll(std::vector<std::shared_ptr<TLuaResult>>& Results, c
bool Cancelled = false;
size_t ms = 0;
std::set<std::string> WarnedResults;
while (!Result->Ready && !Cancelled) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
ms += 10;
@@ -301,7 +300,6 @@ void TLuaEngine::WaitForAll(std::vector<std::shared_ptr<TLuaResult>>& Results, c
}
}
}
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.");
LuaAPI::MP::Engine->ReportErrors({ Result });
@@ -427,7 +425,7 @@ sol::table TLuaEngine::StateThreadData::Lua_TriggerGlobalEvent(const std::string
Result->Error = true;
Result->ErrorMessage = "Function result in TriggerGlobalEvent was invalid";
}
Result->MarkAsReady();
Result->Ready = true;
Return.push_back(Result);
}
}
@@ -957,7 +955,7 @@ void TLuaEngine::StateThreadData::operator()() {
sol::error Err = Res;
S.second->ErrorMessage = Err.what();
}
S.second->MarkAsReady();
S.second->Ready = true;
}
}
{ // StateFunctionQueue Scope
@@ -1018,11 +1016,11 @@ void TLuaEngine::StateThreadData::operator()() {
sol::error Err = Res;
Result->ErrorMessage = Err.what();
}
Result->MarkAsReady();
Result->Ready = true;
} else {
Result->Error = true;
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);
}
void TLuaResult::MarkAsReady() {
{
std::lock_guard<std::mutex> readyLock(*this->ReadyMutex);
this->Ready = true;
}
this->ReadyCondition->notify_all();
}
void TLuaResult::WaitUntilReady() {
std::unique_lock readyLock(*this->ReadyMutex);
// wait if not ready yet
if(!this->Ready)
this->ReadyCondition->wait(readyLock);
while (!Ready) {
std::this_thread::yield();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}
TLuaChunk::TLuaChunk(std::shared_ptr<std::string> Content, std::string FileName, std::string PluginPath)
+1 -30
View File
@@ -11,8 +11,6 @@
#include <boost/asio/ip/address_v4.hpp>
#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) {
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) {
auto Client = CreateClient(std::move(RawConnection.Socket));
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()));
return nullptr;
}
if (!TCPSend(*Client, StringToVector("A"))) { //changed to A for Accepted version
if (!TCPSend(*Client, StringToVector("S"))) {
// TODO: handle
}
@@ -316,22 +304,6 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
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());
mServer.ForEachClient([&](const std::weak_ptr<TClient>& ClientPtr) -> bool {
std::shared_ptr<TClient> Cl;
@@ -381,7 +353,6 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
} else {
ClientKick(*Client, "Server full!");
}
return Client;
}