Compare commits

...

36 Commits

Author SHA1 Message Date
Lucca Jiménez Könings
6f02ff92c2 fix typos and phrasing in README.md
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
2024-01-19 14:14:09 +01:00
Lucca Jiménez Könings
3ddc2d8f8b remove unecessary comment
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
2024-01-19 14:10:14 +01:00
Lucca Jiménez Könings
4d0864790a move undef macros into Compat.h
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
2024-01-19 14:09:56 +01:00
Lucca Jiménez Könings
a22ad66d2b update README.md
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
2024-01-19 14:09:09 +01:00
Lucca Jiménez Könings
b17c72f56e document FreeBSD specific undefs
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
2024-01-19 12:42:51 +01:00
Lucca Jiménez Könings
1bd8b024b8 fix typo
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
2024-01-19 12:38:12 +01:00
Lucca Jiménez Könings
df524097fb update README.md
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
2024-01-19 12:35:19 +01:00
Lucca Jiménez Könings
38532babd3 fix tests on FreeBSD
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
2024-01-19 10:51:04 +01:00
Lucca Jiménez Könings
924efe4331 add FreeBSD build target
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
2024-01-19 09:46:27 +01:00
Lion Kortlepel
9915c83363 fix release arm64 workflow 2024-01-15 14:49:17 +01:00
Lion Kortlepel
9f5a30a871 fix windows build wrongly calling vcpg from the submodule 2024-01-15 14:49:17 +01:00
Lion Kortlepel
6832fd05d6 remove --build-id=none from build flags 2024-01-15 14:49:17 +01:00
Lion Kortlepel
c6aa7776fc make update message adjustable by provider 2024-01-09 17:41:05 +01:00
Lion
b0f5976121 Update release.yml to fix release message 2024-01-09 15:35:47 +01:00
Lion Kortlepel
1bd47fa649 add noninteractive flag for debian/ubuntu 2024-01-09 15:35:47 +01:00
Lion Kortlepel
0e924d0d51 fix bootstrap call 2024-01-09 15:35:47 +01:00
Lion Kortlepel
70a7a41882 add vcpkg bootstrap step 2024-01-09 15:35:47 +01:00
Lion Kortlepel
6ee816d10d add lua to vcpkg dependencies on windows 2024-01-09 15:35:47 +01:00
Lion Kortlepel
8695413211 add ubuntu 20.04, debian 12 scripts 2024-01-09 15:35:47 +01:00
Lion Kortlepel
52c5a995cc fix wrong action dependency 2024-01-09 15:35:47 +01:00
Lion Kortlepel
9d5568dc56 make all ci/cd build actions matrix generic 2024-01-09 15:35:47 +01:00
Lion
c62a1b6add add arm64 builds to github actions
Update linux.yml to build ARM64 binaries for debian11

update linux.yml to fix incorrect runs-on tags

add ubuntu 22.04 arm64 build

Update linux.yml

Update linux.yml

Update linux.yml

Update linux.yml

Update linux.yml

Update linux.yml

Update 2-configure.sh

Update 2-configure.sh

Update 1-install-deps.sh

Update 1-install-deps.sh

Update 2-configure.sh

Update 2-configure.sh

Update linux.yml

use get-cmake

update vcpkg

force arm64 triplet
2024-01-09 15:35:47 +01:00
Lion Kortlepel
4228e18c90 reset default ID to 0 2024-01-09 15:34:33 +01:00
Lion Kortlepel
023e968302 refactor position packet handling, add regression tests 2024-01-09 15:34:33 +01:00
Lion Kortlepel
a4eb10b6a4 fix MP.GetPositionRaw 2024-01-09 15:34:33 +01:00
Lion Kortlepel
0166e488d0 fix calling GlobalParser as static 2024-01-09 15:34:33 +01:00
Lion Kortlepel
0836fd3af8 fix bug in HandlePosition which caused the vehicle position not to be
saved properly
2024-01-09 15:34:33 +01:00
Lion Kortlepel
9791b8875c fix wrong order of SendErrorsShowMessage and SendErrors 2024-01-09 15:34:16 +01:00
Lion
01e8a1644a Bump version to v3.2.2 (#253) 2024-01-08 19:40:00 +01:00
Lion Kortlepel
cebb2634a1 bump version 2024-01-08 17:43:54 +01:00
Lion
21a7ca1b64 Update README.md to remove mention of scripts and add ARM instructions (#243) 2023-12-30 15:07:39 +01:00
Lion
bd4ab2b10d Update README.md 2023-12-30 10:22:12 +01:00
Lion
1cdc8e8f48 bump version number (#241) 2023-12-29 01:43:40 +01:00
Lion Kortlepel
1f72a45231 bump version number 2023-12-29 01:43:03 +01:00
Lion
002223afda Fix Server.log empty when stdout or stdin redirected (#235) 2023-12-28 21:27:44 +01:00
Lion Kortlepel
ecc79b1918 update commandline to fix redirect issue 2023-12-28 21:23:31 +01:00
37 changed files with 387 additions and 115 deletions

View File

@@ -2,16 +2,33 @@ name: Linux
on: [push]
env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
VCPKG_FORCE_SYSTEM_BINARIES: 1
CMAKE_BUILD_TYPE: "Release"
DEBIAN_FRONTEND: "noninteractive"
jobs:
debian-11-build:
runs-on: ubuntu-latest
x86_64-matrix:
runs-on: ubuntu-22.04
strategy:
matrix:
include:
- distro: debian
version: 11
- distro: debian
version: 12
- distro: ubuntu
version: 22.04
- distro: ubuntu
version: 20.04
container:
image: debian:11
image: ${{ matrix.distro }}:${{ matrix.version }}
steps:
- name: get-cmake
uses: lukka/get-cmake@v3.28.1
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v6
with:
@@ -30,43 +47,59 @@ jobs:
- name: Git config safe directory
shell: bash
run: bash ./scripts/debian-11/1.5-git-safe.sh
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/1.5-git-safe.sh
- name: Install Dependencies
run: bash ./scripts/debian-11/1-install-deps.sh
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/1-install-deps.sh
- name: Create Build Environment
run: bash ./scripts/debian-11/2-configure.sh '-DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake'
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/2-configure.sh '-DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake'
- name: Build Server
run: bash ./scripts/debian-11/3-build.sh
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/3-build.sh
- name: Archive server artifact
uses: actions/upload-artifact@v2
with:
name: BeamMP-Server-debian
name: BeamMP-Server.${{ matrix.distro }}.${{ matrix.version }}.x86_64
path: ./bin/BeamMP-Server
- name: Archive server debug info artifact
uses: actions/upload-artifact@v2
with:
name: BeamMP-Server-debian.debug
name: debuginfo.${{ matrix.distro }}.${{ matrix.version }}.x86_64
path: ./bin/BeamMP-Server.debug
- name: Build Tests
run: bash ./scripts/debian-11/3-build-tests.sh
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/3-build-tests.sh
- name: Install Runtime Dependencies
run: bash ./scripts/debian-11/4-install-runtime-deps.sh
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/4-install-runtime-deps.sh
- name: Test
run: ./bin/BeamMP-Server-tests
ubuntu-22-04-build:
runs-on: ubuntu-latest
arm64-matrix:
runs-on: [Linux, ARM64]
env:
VCPKG_DEFAULT_TRIPLET: "arm64-linux"
strategy:
matrix:
include:
- distro: debian
version: 11
- distro: debian
version: 12
- distro: ubuntu
version: 22.04
- distro: ubuntu
version: 20.04
container:
image: ubuntu:22.04
image: ${{ matrix.distro }}:${{ matrix.version }}
steps:
- name: get-cmake
uses: lukka/get-cmake@v3.28.1
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v6
with:
@@ -85,39 +118,35 @@ jobs:
- name: Git config safe directory
shell: bash
run: bash ./scripts/ubuntu-22.04/1.5-git-safe.sh
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/1.5-git-safe.sh
- name: Install Dependencies
run: bash ./scripts/ubuntu-22.04/1-install-deps.sh
- name: Setup vcpkg
uses: lukka/run-vcpkg@v11
with:
runVcpkgInstall: true
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/1-install-deps.sh
- name: Create Build Environment
run: bash ./scripts/ubuntu-22.04/2-configure.sh '-DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake'
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/2-configure.sh '-DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake'
- name: Build Server
run: bash ./scripts/ubuntu-22.04/3-build.sh
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/3-build.sh
- name: Archive server artifact
uses: actions/upload-artifact@v2
with:
name: BeamMP-Server-ubuntu
name: BeamMP-Server.${{ matrix.distro }}.${{ matrix.version }}.arm64
path: ./bin/BeamMP-Server
- name: Archive server debug info artifact
uses: actions/upload-artifact@v2
with:
name: BeamMP-Server-ubuntu.debug
name: debuginfo.${{ matrix.distro }}.${{ matrix.version }}.arm64
path: ./bin/BeamMP-Server.debug
- name: Build Tests
run: bash ./scripts/ubuntu-22.04/3-build-tests.sh
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/3-build-tests.sh
- name: Install Runtime Dependencies
run: bash ./scripts/ubuntu-22.04/4-install-runtime-deps.sh
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/4-install-runtime-deps.sh
- name: Test
run: ./bin/BeamMP-Server-tests
run: ./bin/BeamMP-Server-tests

View File

@@ -8,6 +8,7 @@ on:
env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
CMAKE_BUILD_TYPE: "Release"
DEBIAN_FRONTEND: "noninteractive"
jobs:
create-release:
@@ -27,18 +28,30 @@ jobs:
draft: false
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-debian` is a Debian 11 build, requires `liblua5.3-0`.
- `BeamMP-Server-ubuntu` is a Ubuntu 22.04 build, requires `liblua5.3-0`.
Files included in this release are:
- `BeamMP-Server.$DISTRO.$DISTROVERSION.$ARCH` for linux builds, for example `BeamMP-Server.debian.11.x86_64` for the Debian 11 build for x86_64. All require `liblua5.3` to be installed.
- `BeamMP-Server.exe` for the Windows build (x86_64). You need to install the [Visual C++ Redistributables](https://aka.ms/vs/17/release/vc_redist.x64.exe) to run this.
upload-release-files-debian-11:
name: Build and upload Debian 11 Release Files
x86_64-matrix:
runs-on: ubuntu-22.04
needs: create-release
strategy:
matrix:
include:
- distro: debian
version: 11
- distro: debian
version: 12
- distro: ubuntu
version: 22.04
- distro: ubuntu
version: 20.04
container:
image: debian:11
image: ${{ matrix.distro }}:${{ matrix.version }}
steps:
- name: get-cmake
uses: lukka/get-cmake@v3.28.1
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v6
with:
@@ -57,21 +70,16 @@ jobs:
- name: Git config safe directory
shell: bash
run: bash ./scripts/debian-11/1.5-git-safe.sh
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/1.5-git-safe.sh
- name: Install Dependencies
run: bash ./scripts/debian-11/1-install-deps.sh
- name: Setup vcpkg
uses: lukka/run-vcpkg@v11
with:
runVcpkgInstall: true
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/1-install-deps.sh
- name: Create Build Environment
run: bash ./scripts/debian-11/2-configure.sh '-DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake'
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/2-configure.sh '-DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake'
- name: Build Server
run: bash ./scripts/debian-11/3-build.sh
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/3-build.sh
- name: Upload Release Asset
id: upload-release-asset
@@ -79,9 +87,9 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
asset_name: BeamMP-Server.${{ matrix.distro }}.${{ matrix.version }}.x86_64
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ./bin/BeamMP-Server
asset_name: BeamMP-Server-debian
asset_content_type: application/x-elf
- name: Upload Debug Info
@@ -90,18 +98,34 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
asset_name: debuginfo.${{ matrix.distro }}.${{ matrix.version }}.x86_64
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ./bin/BeamMP-Server.debug
asset_name: debuginfo-debian.debug
asset_content_type: application/x-elf
upload-release-files-ubuntu-22-04:
name: Build and upload Ubuntu 22.04 Release Files
runs-on: ubuntu-22.04
arm64-matrix:
runs-on: [Linux, ARM64]
needs: create-release
strategy:
matrix:
include:
- distro: debian
version: 11
- distro: debian
version: 12
- distro: ubuntu
version: 22.04
- distro: ubuntu
version: 20.04
env:
VCPKG_DEFAULT_TRIPLET: "arm64-linux"
VCPKG_FORCE_SYSTEM_BINARIES: 1
container:
image: ubuntu:22.04
image: ${{ matrix.distro }}:${{ matrix.version }}
steps:
- name: get-cmake
uses: lukka/get-cmake@v3.28.1
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v6
with:
@@ -120,16 +144,16 @@ jobs:
- name: Git config safe directory
shell: bash
run: bash ./scripts/ubuntu-22.04/1.5-git-safe.sh
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/1.5-git-safe.sh
- name: Install Dependencies
run: bash ./scripts/ubuntu-22.04/1-install-deps.sh
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/1-install-deps.sh
- name: Create Build Environment
run: bash ./scripts/ubuntu-22.04/2-configure.sh '-DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake'
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/2-configure.sh '-DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake'
- name: Build Server
run: bash ./scripts/ubuntu-22.04/3-build.sh
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/3-build.sh
- name: Upload Release Asset
id: upload-release-asset
@@ -137,9 +161,9 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
asset_name: BeamMP-Server.${{ matrix.distro }}.${{ matrix.version }}.arm64
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ./bin/BeamMP-Server
asset_name: BeamMP-Server-ubuntu
asset_content_type: application/x-elf
- name: Upload Debug Info
@@ -148,9 +172,9 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
asset_name: debuginfo.${{ matrix.distro }}.${{ matrix.version }}.arm64
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ./bin/BeamMP-Server.debug
asset_name: debuginfo-ubuntu.debug
asset_content_type: application/x-elf
upload-release-files-windows:

View File

@@ -48,6 +48,7 @@ set(PRJ_HEADERS
include/TScopedTimer.h
include/TServer.h
include/VehicleData.h
include/Env.h
)
# add all source files (.cpp) to this, except the one with main()
set(PRJ_SOURCES
@@ -70,6 +71,7 @@ set(PRJ_SOURCES
src/TScopedTimer.cpp
src/TServer.cpp
src/VehicleData.cpp
src/Env.cpp
)
find_package(Lua REQUIRED)

View File

@@ -42,7 +42,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, Windows and FreeBSD. 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.
Recommended compilers: MSVC, GCC, CLANG.
@@ -52,23 +52,33 @@ You can find precompiled binaries under [Releases](https://github.com/BeamMP/Bea
On Linux, you need some dependencies to **build** the server (on Windows, you don't):
For Debian, Ubuntu and others you can find scripts that do this in `scripts/`.
```
liblua5.3-dev curl zip unzip tar cmake make git g++
```
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.
You can install these with your distribution's package manager. You will need sudo or need root for ONLY this step.
The names of each package may change depending on your platform.
If you are building for ARM (like aarch64), you need to run `export VCPKG_FORCE_SYSTEM_BINARIES=1` before the following commands.
You can build on **Windows, Linux** or other platforms by following these steps:
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`.
4. Build via `cmake --build bin --parallel --config Release -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.
### Building for FreeBSD
Building is only supported for major release branches of FreeBSD that are currently not EOL. The build process is the same as on Linux, although build dependencies can be universally installed from ports via pkg:
```
pkg install git cmake-core zip bash devel/ninja devel/pkgconf lua53
```
After installing the necessary build dependencies, follow the Linux build instructions beginning from step 3. Beware that running the initial cmake command will compile vcpkg from source, as vcpkg has no native FreeBSD port - this may take some time.
On systems with a single logical CPU core, `make` may fail to build the server when using the `--parallel` option when calling CMake. If you see error messages related to make, simply omit the `--parallel` from the command: `cmake --build bin --config Release -t BeamMP-Server`.
### Runtime Dependencies

View File

@@ -134,7 +134,7 @@ private:
static inline std::mutex mShutdownHandlersMutex {};
static inline std::deque<TShutdownHandler> mShutdownHandlers {};
static inline Version mVersion { 3, 2, 0 };
static inline Version mVersion { 3, 2, 2 };
};
void SplitString(std::string const& str, const char delim, std::vector<std::string>& out);

View File

@@ -9,7 +9,17 @@
#include <termios.h>
#include <unistd.h>
char _getch();
#endif // unix
#endif // linux
#ifdef BEAMMP_FREEBSD
#include <errno.h>
#include <termios.h>
#include <unistd.h>
char _getch();
// macros 'major' and 'minor' need to be undefined on FreeBSD to avoid naming collision with system headers
#undef major
#undef minor
#endif // freebsd
// ======================= APPLE ========================

16
include/Env.h Normal file
View File

@@ -0,0 +1,16 @@
#pragma once
#include <optional>
#include <string>
namespace Env {
enum class Key {
// provider settings
PROVIDER_UPDATE_MESSAGE,
};
std::optional<std::string> Get(Key key);
std::string_view ToString(Key key);
}

View File

@@ -3,11 +3,13 @@
// one of BEAMMP_{WINDOWS,LINUX,APPLE} will be set at the end of this
// clang-format off
#if !defined(BEAMMP_WINDOWS) && !defined(BEAMMP_UNIX) && !defined(BEAMMP_APPLE)
#if !defined(BEAMMP_WINDOWS) && !defined(BEAMMP_UNIX) && !defined(BEAMMP_APPLE) && !defined(BEAMMP_FREEBSD)
#if defined(_WIN32) || defined(__CYGWIN__)
#define BEAMMP_WINDOWS
#elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__unix__) || defined(__unix) || defined(unix)
#elif defined(__linux__) || defined(__linux) || defined(linux)
#define BEAMMP_LINUX
#elif defined(__FreeBSD__)
#define BEAMMP_FREEBSD
#elif defined(__APPLE__) || defined(__MACH__)
#define BEAMMP_APPLE
#else

View File

@@ -26,7 +26,7 @@ public:
void ForEachClient(const std::function<bool(std::weak_ptr<TClient>)>& Fn);
size_t ClientCount() const;
static void GlobalParser(const std::weak_ptr<TClient>& Client, std::vector<uint8_t>&& Packet, TPPSMonitor& PPSMonitor, TNetwork& Network);
void GlobalParser(const std::weak_ptr<TClient>& Client, std::vector<uint8_t>&& Packet, TPPSMonitor& PPSMonitor, TNetwork& Network);
static void HandleEvent(TClient& c, const std::string& Data);
RWMutex& GetClientMutex() const { return mClientsMutex; }
@@ -43,7 +43,7 @@ private:
static bool ShouldSpawn(TClient& c, const std::string& CarJson, int ID);
static bool IsUnicycle(TClient& c, const std::string& CarJson);
static void Apply(TClient& c, int VID, const std::string& pckt);
static void HandlePosition(TClient& c, const std::string& Packet);
void HandlePosition(TClient& c, const std::string& Packet);
};
struct BufferView {

View File

@@ -4,4 +4,4 @@ set -ex
apt-get update -y
apt-get install -y liblua5.3-0 liblua5.3-dev curl zip unzip tar cmake make git g++
apt-get install -y liblua5.3-0 liblua5.3-dev curl zip unzip tar cmake make git g++ ninja-build

View File

@@ -2,4 +2,6 @@
set -ex
cmake . -B bin $1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-O3 -g -Wl,-z,norelro -Wl,--hash-style=gnu -Wl,--build-id=none -Wl,-z,noseparate-code -ffunction-sections -fdata-sections -Wl,--gc-sections" -DBeamMP-Server_ENABLE_LTO=ON
./vcpkg/bootstrap-vcpkg.sh
cmake . -B bin $1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-O3 -g -Wl,-z,norelro -Wl,--hash-style=gnu -Wl,-z,noseparate-code -ffunction-sections -fdata-sections -Wl,--gc-sections" -DBeamMP-Server_ENABLE_LTO=ON

View File

@@ -0,0 +1,7 @@
#!/bin/bash
set -ex
apt-get update -y
apt-get install -y liblua5.3-0 liblua5.3-dev curl zip unzip tar cmake make git g++ ninja-build

View File

@@ -0,0 +1,7 @@
#!/bin/bash
set -ex
git config --global --add safe.directory $(pwd)
git config --global --add safe.directory $(pwd)/vcpkg
git config --global --add safe.directory $(pwd)/deps/commandline

View File

@@ -0,0 +1,7 @@
#!/bin/bash
set -ex
./vcpkg/bootstrap-vcpkg.sh
cmake . -B bin $1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-O3 -g -Wl,-z,norelro -Wl,--hash-style=gnu -Wl,-z,noseparate-code -ffunction-sections -fdata-sections -Wl,--gc-sections" -DBeamMP-Server_ENABLE_LTO=ON

View File

@@ -0,0 +1,5 @@
#!/bin/bash
set -ex
cmake --build bin --parallel -t BeamMP-Server-tests

10
scripts/debian-12/3-build.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/bash
set -ex
cmake --build bin --parallel -t BeamMP-Server
objcopy --only-keep-debug bin/BeamMP-Server bin/BeamMP-Server.debug
objcopy --add-gnu-debuglink bin/BeamMP-Server bin/BeamMP-Server.debug
strip -s bin/BeamMP-Server

View File

@@ -0,0 +1,8 @@
#!/bin/bash
set -ex
apt-get update -y
apt-get install -y liblua5.3-0 curl

View File

@@ -0,0 +1,7 @@
#!/bin/bash
set -ex
apt-get update -y
apt-get install -y liblua5.3-0 liblua5.3-dev curl zip unzip tar cmake make git g++ ninja-build

View File

@@ -0,0 +1,7 @@
#!/bin/bash
set -ex
git config --global --add safe.directory $(pwd)
git config --global --add safe.directory $(pwd)/vcpkg
git config --global --add safe.directory $(pwd)/deps/commandline

View File

@@ -0,0 +1,7 @@
#!/bin/bash
set -ex
./vcpkg/bootstrap-vcpkg.sh
cmake . -B bin $1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-O3 -g -Wl,-z,norelro -Wl,--hash-style=gnu -Wl,-z,noseparate-code -ffunction-sections -fdata-sections -Wl,--gc-sections" -DBeamMP-Server_ENABLE_LTO=ON

View File

@@ -0,0 +1,5 @@
#!/bin/bash
set -ex
cmake --build bin --parallel -t BeamMP-Server-tests

10
scripts/ubuntu-20.04/3-build.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/bash
set -ex
cmake --build bin --parallel -t BeamMP-Server
objcopy --only-keep-debug bin/BeamMP-Server bin/BeamMP-Server.debug
objcopy --add-gnu-debuglink bin/BeamMP-Server bin/BeamMP-Server.debug
strip -s bin/BeamMP-Server

View File

@@ -0,0 +1,8 @@
#!/bin/bash
set -ex
apt-get update -y
apt-get install -y liblua5.3-0 curl

View File

@@ -4,4 +4,4 @@ set -ex
apt-get update -y
apt-get install -y liblua5.3-0 liblua5.3-dev curl zip unzip tar cmake make git g++
apt-get install -y liblua5.3-0 liblua5.3-dev curl zip unzip tar cmake make git g++ ninja-build

View File

@@ -2,4 +2,6 @@
set -ex
cmake . -B bin $1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-O3 -g -Wl,-z,norelro -Wl,--hash-style=gnu -Wl,--build-id=none -Wl,-z,noseparate-code -ffunction-sections -fdata-sections -Wl,--gc-sections" -DBeamMP-Server_ENABLE_LTO=ON
./vcpkg/bootstrap-vcpkg.sh
cmake . -B bin $1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-O3 -g -Wl,-z,norelro -Wl,--hash-style=gnu -Wl,-z,noseparate-code -ffunction-sections -fdata-sections -Wl,--gc-sections" -DBeamMP-Server_ENABLE_LTO=ON

2
scripts/windows/1-configure.sh Normal file → Executable file
View File

@@ -2,4 +2,6 @@
set -ex
vcpkg add port lua
cmake . -B bin $1 -DCMAKE_BUILD_TYPE=Release -DBeamMP-Server_ENABLE_LTO=ON -DVCPKG_TARGET_TRIPLET=x64-windows-static

View File

@@ -53,9 +53,9 @@ std::string TClient::GetCarPositionRaw(int Ident) {
try {
return mVehiclePosition.at(size_t(Ident));
} catch (const std::out_of_range& oor) {
beammp_debugf("Failed to get vehicle position for {}: {}", Ident, oor.what());
return "";
}
return "";
}
void TClient::Disconnect(std::string_view Reason) {
@@ -146,6 +146,8 @@ std::optional<std::weak_ptr<TClient>> GetClient(TServer& Server, int ID) {
MaybeClient = CPtr;
return false;
}
} else {
beammp_debugf("Found an expired client while looking for id {}", ID);
}
return true;
});

View File

@@ -1,8 +1,10 @@
#include "Common.h"
#include "Env.h"
#include "TConsole.h"
#include <array>
#include <charconv>
#include <fmt/core.h>
#include <iostream>
#include <map>
#include <regex>
@@ -201,8 +203,11 @@ void Application::CheckForUpdates() {
auto MyVersion = ServerVersion();
auto RemoteVersion = Version(VersionStrToInts(Response));
if (IsOutdated(MyVersion, RemoteVersion)) {
std::string RealVersionString = RemoteVersion.AsString();
beammp_warn(std::string(ANSI_YELLOW_BOLD) + "NEW VERSION IS OUT! Please update to the new version (v" + RealVersionString + ") of the BeamMP-Server! Download it here: https://beammp.com/! For a guide on how to update, visit: https://wiki.beammp.com/en/home/server-maintenance#updating-the-server" + std::string(ANSI_RESET));
std::string RealVersionString = std::string("v") + RemoteVersion.AsString();
const std::string DefaultUpdateMsg = "NEW VERSION IS OUT! Please update to the new version ({}) of the BeamMP-Server! Download it here: https://beammp.com/! For a guide on how to update, visit: https://wiki.beammp.com/en/home/server-maintenance#updating-the-server";
auto UpdateMsg = Env::Get(Env::Key::PROVIDER_UPDATE_MESSAGE).value_or(DefaultUpdateMsg);
UpdateMsg = fmt::vformat(std::string_view(UpdateMsg), fmt::make_format_args(RealVersionString));
beammp_warnf("{}{}{}", ANSI_YELLOW_BOLD, UpdateMsg, ANSI_RESET);
} else {
if (FirstTime) {
beammp_info("Server up-to-date!");
@@ -270,6 +275,8 @@ void RegisterThread(const std::string& str) {
ThreadId = std::to_string(getpid()); // todo: research if 'getpid()' is a valid, posix compliant alternative to 'gettid()'
#elif defined(BEAMMP_LINUX)
ThreadId = std::to_string(gettid());
#elif defined(BEAMMP_FREEBSD)
ThreadId = std::to_string(getpid());
#endif
if (Application::Settings.DebugModeEnabled) {
std::ofstream ThreadFile(".Threads.log", std::ios::app);

View File

@@ -41,7 +41,9 @@ TEST_CASE("init and reset termios") {
CHECK_EQ(current.c_iflag, original.c_iflag);
CHECK_EQ(current.c_ispeed, original.c_ispeed);
CHECK_EQ(current.c_lflag, original.c_lflag);
#ifndef BEAMMP_FREEBSD // The 'c_line' attribute seems to only exist on Linux, so we need to omit it on other platforms
CHECK_EQ(current.c_line, original.c_line);
#endif
CHECK_EQ(current.c_oflag, original.c_oflag);
CHECK_EQ(current.c_ospeed, original.c_ospeed);
}

20
src/Env.cpp Normal file
View File

@@ -0,0 +1,20 @@
#include "Env.h"
#include <optional>
std::optional<std::string> Env::Get(Env::Key key) {
auto StrKey = ToString(key);
auto Value = std::getenv(StrKey.data());
if (!Value || std::string_view(Value).empty()) {
return std::nullopt;
}
return Value;
}
std::string_view Env::ToString(Env::Key key) {
switch (key) {
case Key::PROVIDER_UPDATE_MESSAGE:
return "BEAMMP_PROVIDER_UPDATE_MESSAGE";
break;
}
return "";
}

View File

@@ -120,9 +120,9 @@ void TConfig::FlushToFile() {
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.");
data["Misc"][StrSendErrors.data()] = Application::Settings.SendErrors;
SetComment(data["Misc"][StrSendErrors.data()].comments(), " You can turn on/off the SendErrors message you get on startup here");
SetComment(data["Misc"][StrSendErrors.data()].comments(), " If SendErrors is `true`, the server will send helpful info about crashes and other issues back to the BeamMP developers. This info may include your config, who is on your server at the time of the error, and similar general information. This kind of data is vital in helping us diagnose and fix issues faster. This has no impact on server performance. You can opt-out of this system by setting this to `false`");
data["Misc"][StrSendErrorsMessageEnabled.data()] = Application::Settings.SendErrorsMessageEnabled;
SetComment(data["Misc"][StrSendErrorsMessageEnabled.data()].comments(), " If SendErrors is `true`, the server will send helpful info about crashes and other issues back to the BeamMP developers. This info may include your config, who is on your server at the time of the error, and similar general information. This kind of data is vital in helping us diagnose and fix issues faster. This has no impact on server performance. You can opt-out of this system by setting this to `false`");
SetComment(data["Misc"][StrSendErrorsMessageEnabled.data()].comments(), " You can turn on/off the SendErrors message you get on startup here");
std::stringstream Ss;
Ss << "# This is the BeamMP-Server config file.\n"
"# Help & Documentation: `https://wiki.beammp.com/en/home/server-maintenance`\n"
@@ -313,6 +313,6 @@ std::string TConfig::TagsAsPrettyArray() const {
for (size_t i = 0; i < TagsArray.size() - 1; ++i) {
Pretty += '\"' + TagsArray[i] + "\", ";
}
Pretty += '\"' + TagsArray.at(TagsArray.size()-1) + "\"";
Pretty += '\"' + TagsArray.at(TagsArray.size() - 1) + "\"";
return Pretty;
}

View File

@@ -601,7 +601,7 @@ std::pair<sol::table, std::string> TLuaEngine::StateThreadData::Lua_GetPositionR
return Result;
} else {
// return std::make_tuple(sol::lua_nil, sol::make_object(StateView, "Client expired"));
Result.second = "Client expired";
Result.second = "No such player";
return Result;
}
}

View File

@@ -101,7 +101,7 @@ void TNetwork::UDPServerMain() {
Client->SetUDPAddr(client);
Client->SetIsConnected(true);
Data.erase(Data.begin(), Data.begin() + 2);
TServer::GlobalParser(ClientPtr, std::move(Data), mPPSMonitor, *this);
mServer.GlobalParser(ClientPtr, std::move(Data), mPPSMonitor, *this);
}
return true;
@@ -552,7 +552,7 @@ void TNetwork::TCPClient(const std::weak_ptr<TClient>& c) {
Client->Disconnect("TCPRcv failed");
break;
}
TServer::GlobalParser(c, std::move(res), mPPSMonitor, *this);
mServer.GlobalParser(c, std::move(res), mPPSMonitor, *this);
}
if (QueueSync.joinable())

View File

@@ -7,6 +7,7 @@
#include <TLuaPlugin.h>
#include <algorithm>
#include <any>
#include <optional>
#include <sstream>
#include <nlohmann/json.hpp>
@@ -51,6 +52,30 @@ TEST_CASE("GetPidVid") {
CHECK_EQ(pid, 10);
CHECK_EQ(vid, 12);
}
SUBCASE("Valid doubledigit 2") {
const auto MaybePidVid = GetPidVid("10-2");
CHECK(MaybePidVid);
auto [pid, vid] = MaybePidVid.value();
CHECK_EQ(pid, 10);
CHECK_EQ(vid, 2);
}
SUBCASE("Valid doubledigit 3") {
const auto MaybePidVid = GetPidVid("33-23");
CHECK(MaybePidVid);
auto [pid, vid] = MaybePidVid.value();
CHECK_EQ(pid, 33);
CHECK_EQ(vid, 23);
}
SUBCASE("Valid doubledigit 4") {
const auto MaybePidVid = GetPidVid("3-23");
CHECK(MaybePidVid);
auto [pid, vid] = MaybePidVid.value();
CHECK_EQ(pid, 3);
CHECK_EQ(vid, 23);
}
SUBCASE("Empty string") {
const auto MaybePidVid = GetPidVid("");
CHECK(!MaybePidVid);
@@ -214,6 +239,7 @@ void TServer::GlobalParser(const std::weak_ptr<TClient>& Client, std::vector<uin
PPSMonitor.IncrementInternalPPS();
Network.SendToAll(LockedClient.get(), Packet, false, false);
HandlePosition(*LockedClient, StringPacket);
return;
default:
return;
}
@@ -388,7 +414,7 @@ void TServer::Apply(TClient& c, int VID, const std::string& pckt) {
FoundPos = VD.find('{');
if (FoundPos == std::string::npos) {
return;
return;
}
VD = VD.substr(FoundPos);
rapidjson::Document Veh, Pack;
@@ -422,35 +448,63 @@ void TServer::InsertClient(const std::shared_ptr<TClient>& NewClient) {
(void)mClients.insert(NewClient);
}
void TServer::HandlePosition(TClient& c, const std::string& Packet) {
struct PidVidData {
int PID;
int VID;
std::string Data;
};
static std::optional<PidVidData> ParsePositionPacket(const std::string& Packet) {
if (Packet.size() < 3) {
// invalid packet
return;
return std::nullopt;
}
// Zp:serverVehicleID:data
// Zp:0:data
// Zp:PID-VID:DATA
std::string withoutCode = Packet.substr(3);
auto NameDataSep = withoutCode.find(':', 2);
if (NameDataSep == std::string::npos || NameDataSep < 2) {
// invalid packet
return;
}
// FIXME: ensure that -2 does what it should... it seems weird.
std::string ServerVehicleID = withoutCode.substr(2, NameDataSep - 2);
if (NameDataSep + 1 > withoutCode.size()) {
// invalid packet
return;
}
std::string Data = withoutCode.substr(NameDataSep + 1);
// parse veh ID
auto MaybePidVid = GetPidVid(ServerVehicleID);
if (MaybePidVid) {
int PID = -1;
int VID = -1;
// FIXME: check that the VID and PID are valid, so that we don't waste memory
std::tie(PID, VID) = MaybePidVid.value();
if (auto DataBeginPos = withoutCode.find('{'); DataBeginPos != std::string::npos && DataBeginPos != 0) {
// separator is :{, so position of { minus one
auto PidVidOnly = withoutCode.substr(0, DataBeginPos - 1);
auto MaybePidVid = GetPidVid(PidVidOnly);
if (MaybePidVid) {
int PID = -1;
int VID = -1;
// FIXME: check that the VID and PID are valid, so that we don't waste memory
std::tie(PID, VID) = MaybePidVid.value();
c.SetCarPosition(VID, Data);
std::string Data = withoutCode.substr(DataBeginPos);
return PidVidData {
.PID = PID,
.VID = VID,
.Data = Data,
};
} else {
// invalid packet
return std::nullopt;
}
}
// invalid packet
return std::nullopt;
}
TEST_CASE("ParsePositionPacket") {
const auto TestData = R"({"tim":10.428000331623,"vel":[-2.4171722121385e-05,-9.7184734153252e-06,-7.6420763232237e-06],"rot":[-0.0001296154171915,0.0031575385950029,0.98994906610295,0.14138903660382],"rvel":[5.3640324636461e-05,-9.9824529946024e-05,5.1664064641372e-05],"pos":[-0.27281248907838,-0.20515357944633,0.49695488960431],"ping":0.032999999821186})";
SUBCASE("All the pids and vids") {
for (int pid = 0; pid < 100; ++pid) {
for (int vid = 0; vid < 100; ++vid) {
std::optional<PidVidData> MaybeRes = ParsePositionPacket(fmt::format("Zp:{}-{}:{}", pid, vid, TestData));
CHECK(MaybeRes.has_value());
CHECK_EQ(MaybeRes.value().PID, pid);
CHECK_EQ(MaybeRes.value().VID, vid);
CHECK_EQ(MaybeRes.value().Data, TestData);
}
}
}
}
void TServer::HandlePosition(TClient& c, const std::string& Packet) {
if (auto Parsed = ParsePositionPacket(Packet); Parsed.has_value()) {
c.SetCarPosition(Parsed.value().VID, Parsed.value().Data);
}
}

2
vcpkg

Submodule vcpkg updated: 72010900b7...8397227251

View File

@@ -2,18 +2,18 @@
"name": "server",
"version-string": "0.1.0",
"dependencies": [
"fmt",
"doctest",
"boost-asio",
"boost-variant",
"boost-spirit",
"boost-uuid",
"boost-variant",
"cpp-httplib",
"toml11",
"doctest",
"fmt",
"libzip",
"rapidjson",
"nlohmann-json",
"openssl",
"sol2"
"rapidjson",
"sol2",
"toml11"
]
}
}