Compare commits

...

18 Commits

Author SHA1 Message Date
8ec4602ee3 Add PyAPI skell 2022-09-27 16:30:47 +03:00
5f4ae36bbf Del const 2022-09-27 15:55:48 +03:00
15f6321310 Change server dir 2022-09-27 15:55:38 +03:00
842d142a0e Modify LUA 2022-09-27 14:28:39 +03:00
fb52f01295 Fix for linux 2022-09-27 13:00:05 +03:00
b974f194da Fix for linux 2022-09-27 12:59:09 +03:00
18c01fddfe ReTab.. :) 2022-09-27 12:46:44 +03:00
cd5252a473 Change *.log naming. 2022-09-27 12:46:26 +03:00
924c946be9 Add new start argument - locale
Optimization for Russian locale.
2022-09-27 12:46:07 +03:00
660354574e Change vcpkg command 2022-09-27 05:18:44 +03:00
3fc998d402 Change in Clion Files 2022-09-27 05:04:06 +03:00
7abc4566ad Merge README from master branch 2022-09-27 04:27:37 +03:00
f77ec41303 Add vcpkg packages for x64 systems 2022-09-27 03:55:36 +03:00
e81acbe60d Fix debian dependencies 2022-09-27 03:52:46 +03:00
b8d38f0b6d Add a little formatting 2022-09-27 03:52:25 +03:00
c6f52dbcb7 Syntax fix 2022-09-27 03:51:26 +03:00
8162dd4d75 Add MacOs block 2022-09-27 03:26:52 +03:00
2d4d40c24c Change URL and set clone from branch with Python support. 2022-09-27 03:25:15 +03:00
14 changed files with 155 additions and 84 deletions

3
.gitignore vendored
View File

@@ -27,8 +27,7 @@ mono_crash.*
out/
#Clion Files
cmake-build-debug/
cmake-build-release/
cmake-build-*/
.idea/
# Build results
[Dd]ebug/

View File

@@ -108,7 +108,10 @@ add_executable(BeamMP-Server
include/TScopedTimer.h src/TScopedTimer.cpp
include/SignalHandling.h src/SignalHandling.cpp
include/ArgsParser.h src/ArgsParser.cpp
include/Environment.h)
include/Environment.h
src/TPyEngine.cpp include/TPyEngine.h
src/TPyPlugin.cpp include/TPyPlugin.h
src/PyAPI.cpp include/PyAPI.h)
target_compile_definitions(BeamMP-Server PRIVATE SECRET_SENTRY_URL="${BEAMMP_SECRET_SENTRY_URL}")
include_directories(BeamMP-Server PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

View File

@@ -4,9 +4,9 @@
[![CMake Linux Build](https://github.com/BeamMP/BeamMP-Server/workflows/CMake%20Linux%20Build/badge.svg?branch=master)](https://github.com/BeamMP/BeamMP-Server/actions?query=workflow%3A%22CMake+Linux+Build%22)
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 throug which all clients communicate. You can write lua mods for the server, detailed instructions on the [BeamMP Wiki](https://wiki.beammp.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, listed below under "prerequisites".**
**For Linux, you __need__ the runtime dependencies, listed below under "[prerequisites](#prerequisites)".**
## Support + Contact
@@ -14,6 +14,7 @@ Feel free to ask any questions via the following channels:
- **IRC**: `#beammp` on [irc.libera.chat](https://web.libera.chat/)
- **Discord**: [click for invite](https://discord.gg/beammp)
- **BeamMP Forum**: [BeamMP Forum Support](https://forum.beammp.com/c/support/33)
## Minimum Requirements
@@ -28,21 +29,21 @@ These values are guesstimated and are subject to change with each release.
## Contributing
TLDR; [Issues](https://github.com/BeamMP/BeamMP-Server/issues) with the "help wanted" label or with nobody assigned, any [trello](https://trello.com/b/Kw75j3zZ/beamngdrive-multiplayer) cards in the "To-Do" column.
TLDR; [Issues](https://github.com/BeamMP/BeamMP-Server/issues) with the "help wanted" label or with nobody assigned.
To contribute, look at the active [issues](https://github.com/BeamMP/BeamMP-Server/issues) and at the [trello](https://trello.com/b/Kw75j3zZ/beamngdrive-multiplayer). Any issues that have the "help wanted" label or don't have anyone assigned and any trello cards that aren't assigned or in the "In-Progress" section are good tasks to take on. You can either contribute by programming or by testing and adding more info and ideas.
To contribute, look at the active [issues](https://github.com/BeamMP/BeamMP-Server/issues). Any issues that have the "help wanted" label or don't have anyone assigned are good tasks to take on. You can either contribute by programming or by testing and adding more info and ideas.
Fork this repository, make a new branch for your feature, implement your feature or fix, and then create a pull-request here. Even incomplete features and fixes can be pull-requested.
If you need support with understanding the codebase, please write us in the discord. You'll need to be proficient in modern C++.
If you need support with understanding the codebase, please write us in the Discord. You'll need to be proficient in modern C++.
## About Building from Source
We only allow building unmodified (original) source code for public use. `master` is considered **unstable** and we will not provide technical support if such a build doesn't work, so always build from a tag. You can checkout a tag with `git checkout tags/TAGNAME`, where `TAGNAME` is the tag, for example `v1.20`.
We only allow building unmodified (original) source code for public use. `master` is considered **unstable,** and we will not provide technical support if such a build doesn't work, so always build from a tag. You can check out a tag with `git checkout tags/TAGNAME`, where `TAGNAME` is the tag, for example `v1.20`.
## 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 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.
The code itself supports (the 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.
@@ -52,7 +53,7 @@ You can find precompiled binaries under [Releases](https://github.com/BeamMP/Bea
**__Do not compile from `master`. Always build from a release tag, i.e. `tags/v2.3.3`!__**
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)).
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
@@ -60,40 +61,24 @@ Currently only linux and windows are supported (generally). See [Releases](https
Please use the prepackaged binaries in [Releases](https://github.com/BeamMP/BeamMP-Server/releases/).
Dependencies for **windows** can be installed with `vcpkg`.
Dependencies for **windows** can be installed with [`vcpkg`](https://github.com/microsoft/vcpkg).
These are:
```
lua
zlib
rapidjson
openssl
websocketpp
curl
> vcpkg install lua:x64-windows-static zlib:x64-windows-static rapidjson:x64-windows-static openssl:x64-windows-static websocketpp:x64-windows-static curl:x64-windows-static
```
#### Linux
These package names are in the debian / ubuntu style. Feel free to PR your own guide for a different distro.
Runtime dependencies for **linux** are (debian/ubuntu):
```
libz-dev
rapidjson-dev
liblua5.3
libssl-dev
libwebsocketpp-dev
libcurl4-openssl-dev
Runtime dependencies for **linux**:
**Debian / Ubuntu**
```shell
$ sudo apt install libz-dev rapidjson-dev liblua5.3-dev libssl-dev libwebsocketpp-dev libcurl4-openssl-dev git make cmake g++
```
Build-time dependencies for **linux** are:
```
git
make
cmake
g++
```
For other distributions (e.g. Arch) you want to find packages for:
For other distributions (e.g. **Arch**) you want to find packages for:
- libz
- rapidjson
- lua5.3
@@ -102,20 +87,35 @@ For other distributions (e.g. Arch) you want to find packages for:
- curl (with ssl support)
- \+ the build time dependencies from above
#### 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.
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 --recurse-submodules https://github.com/BeamMP/BeamMP-Server`.
3. Ensure that all submodules are initialized by running `git submodule update --init --recursive`. Then change into the cloned directory by running `cd BeamMP-Server`.
4. Checkout the branch of the release you want to compile (`master` is often unstable), for example `git checkout tags/v2.3.3` for version 2.3.3. You can find the latest version [here](https://github.com/BeamMP/BeamMP-Server/tags).
2. Clone the repository in a location of your choice with `git clone -b v3.0.2-WithPython --recurse-submodules https://github.com/SantaSpeen/BeamMP-Server`.
3. Change into the BeamMP-Server directory by running `cd BeamMP-Server`.
4. Ensure that all submodules are initialized by running `git submodule update --init --recursive`. Then change into the cloned directory by running `cd BeamMP-Server`.
5. Run `cmake . -DCMAKE_BUILD_TYPE=Release` (with `.`)
6. Run `make`
7. You will 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_Mod) for further setup after installation (which we just did), such as port-forwarding and getting a key to actually run the server.
6. Run `make -j 4` (Set `-j {cores in your CPU}`. This param use for quickly compile.)
7. You will 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, doesn't matter) instructions on the [wiki](https://wiki.beammp.com/en/home/Server_Mod) 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.
## Copyright
Copyright (c) 2019-present Anonymous275 (@Anonymous-275), Lion Kortlepel (@lionkor).

View File

@@ -5,7 +5,7 @@
namespace LuaAPI {
int PanicHandler(lua_State* State);
std::string LuaToString(const sol::object Value, size_t Indent = 1, bool QuoteStrings = false);
std::string LuaToString(sol::object Value, size_t Indent = 1, bool QuoteStrings = false);
void Print(sol::variadic_args);
namespace MP {
extern TLuaEngine* Engine;
@@ -36,4 +36,8 @@ namespace FS {
bool IsFile(const std::string& Path);
std::string ConcatPaths(sol::variadic_args Args);
}
namespace CL {
void SendPacket(int ID, const std::string& Packet);
void SendNotify(int ID, const std::string& Notify);
}
}

13
include/PyAPI.h Normal file
View File

@@ -0,0 +1,13 @@
#pragma once
#include "TPyEngine.h"
#include <tuple>
namespace PyAPI {
namespace MP {
}
namespace FS {
}
namespace CL {
}
}

3
include/TPyEngine.h Normal file
View File

@@ -0,0 +1,3 @@
#pragma once
class TPyPlugin;

1
include/TPyPlugin.h Normal file
View File

@@ -0,0 +1 @@
#pragma once

View File

@@ -352,3 +352,24 @@ std::string LuaAPI::FS::ConcatPaths(sol::variadic_args Args) {
auto Result = Path.lexically_normal().string();
return Result;
}
void LuaAPI::CL::SendPacket(int ID, const std::string& Packet) {
if (ID == -1) {
LuaAPI::MP::Engine->Network().SendToAll(nullptr, Packet, true, true);
} else {
auto MaybeClient = GetClient(LuaAPI::MP::Engine->Server(), ID);
if (MaybeClient && !MaybeClient.value().expired()) {
auto c = MaybeClient.value().lock();
if (!c->IsSynced())
return;
beammp_info("[LUA] Send packet to <" + c->GetName() + ">: " + Packet);
LuaAPI::MP::Engine->Network().Respond(*c, Packet, true);
} else {
beammp_lua_error("SendChatMessage invalid argument [1] invalid ID");
}
}
}
void LuaAPI::CL::SendNotify(int ID, const std::string& Notify) {
SendPacket(ID, "L:Server: " + Notify);
}

1
src/PyAPI.cpp Normal file
View File

@@ -0,0 +1 @@
#include "PyAPI.h"

View File

@@ -50,7 +50,7 @@ std::string GetDate() {
}
void TConsole::BackupOldLog() {
fs::path Path = "Server.log";
fs::path Path = "server.log";
if (fs::exists(Path)) {
auto OldLog = Path.filename().stem().string() + ".old.log";
try {
@@ -98,7 +98,7 @@ void TConsole::BackupOldLog() {
}
void TConsole::StartLoggingToFile() {
mLogFileStream.open("Server.log");
mLogFileStream.open("server.log");
Application::Console().Internal().on_write = [this](const std::string& ToWrite) {
// TODO: Sanitize by removing all ansi escape codes (vt100)
std::unique_lock Lock(mLogFileStreamMtx);

View File

@@ -15,13 +15,13 @@
TLuaEngine* LuaAPI::MP::Engine;
TLuaEngine::TLuaEngine()
: mPluginMonitor(fs::path(Application::Settings.Resource) / "Server", *this, mShutdown) {
: mPluginMonitor(fs::path(Application::Settings.Resource) / "server", *this, mShutdown) {
Application::SetSubsystemStatus("LuaEngine", Application::Status::Starting);
LuaAPI::MP::Engine = this;
if (!fs::exists(Application::Settings.Resource)) {
fs::create_directory(Application::Settings.Resource);
}
fs::path Path = fs::path(Application::Settings.Resource) / "Server";
fs::path Path = fs::path(Application::Settings.Resource) / "server";
if (!fs::exists(Path)) {
fs::create_directory(Path);
}
@@ -568,6 +568,11 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, std::atomi
FSTable.set_function("IsDirectory", &LuaAPI::FS::IsDirectory);
FSTable.set_function("IsFile", &LuaAPI::FS::IsFile);
FSTable.set_function("ConcatPaths", &LuaAPI::FS::ConcatPaths);
auto CLTable = StateView.create_named_table("CL");
CLTable.set_function("SendPacket", &LuaAPI::CL::SendPacket);
CLTable.set_function("SendNotify", &LuaAPI::CL::SendNotify);
Start();
}

1
src/TPyEngine.cpp Normal file
View File

@@ -0,0 +1 @@
#include "TPyEngine.h"

1
src/TPyPlugin.cpp Normal file
View File

@@ -0,0 +1 @@
#include "TPyPlugin.h"

View File

@@ -36,6 +36,8 @@ ARGUMENTS:
including the path given in --config.
--version
Prints version info and exits.
--locale
Set console locale.
EXAMPLES:
BeamMP-Server --config=../MyWestCoastServerConfig.toml
@@ -55,17 +57,17 @@ struct MainArguments {
std::string InvokedAs;
};
int BeamMPServerMain(MainArguments Arguments);
int BeamMPServerMain(const MainArguments& Arguments);
int main(int argc, char** argv) {
MainArguments Args { argc, argv, {}, argv[0] };
Args.List.reserve(argc);
for (int i = 1; i < argc; ++i) {
Args.List.push_back(argv[i]);
Args.List.emplace_back(argv[i]);
}
int MainRet = 0;
int MainRet;
try {
MainRet = BeamMPServerMain(std::move(Args));
MainRet = BeamMPServerMain(Args);
} catch (const std::exception& e) {
beammp_error("A fatal exception has occurred and the server is forcefully shutting down.");
beammp_error(e.what());
@@ -75,7 +77,7 @@ int main(int argc, char** argv) {
return MainRet;
}
int BeamMPServerMain(MainArguments Arguments) {
int BeamMPServerMain(const MainArguments& Arguments) {
setlocale(LC_ALL, "C");
Application::InitializeConsole();
ArgsParser Parser;
@@ -83,6 +85,7 @@ int BeamMPServerMain(MainArguments Arguments) {
Parser.RegisterArgument({ "version" }, ArgsParser::NONE);
Parser.RegisterArgument({ "config" }, ArgsParser::HAS_VALUE);
Parser.RegisterArgument({ "working-directory" }, ArgsParser::HAS_VALUE);
Parser.RegisterArgument({ "locale" }, ArgsParser::HAS_VALUE);
Parser.Parse(Arguments.List);
if (!Parser.Verify()) {
return 1;
@@ -98,7 +101,7 @@ int BeamMPServerMain(MainArguments Arguments) {
return 0;
}
std::string ConfigPath = "ServerConfig.toml";
std::string ConfigPath = "config.toml";
if (Parser.FoundArgument({ "config" })) {
auto MaybeConfigPath = Parser.GetValueOfArgument({ "config" });
if (MaybeConfigPath.has_value()) {
@@ -118,6 +121,22 @@ int BeamMPServerMain(MainArguments Arguments) {
}
}
if (Parser.FoundArgument({ "locale" })) {
auto MaybeLocale = Parser.GetValueOfArgument({ "locale" });
if (MaybeLocale.has_value()) {
std::string locale = MaybeLocale.value();
setlocale(LC_ALL, locale.c_str());
beammp_info("Custom locale requested via commandline arguments: '" + locale + "'");
#if WIN32
if (locale == "Russian" || locale == "Rus") {
beammp_info("Found Russian locale. Set CP1251 console coding.");
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
}
#endif
}
}
Application::SetSubsystemStatus("Main", Application::Status::Starting);
Application::Console().StartLoggingToFile();