Compare commits

..

714 Commits

Author SHA1 Message Date
Lion Kortlepel
931d94b7d8 start integrating lua with the rest 2024-02-06 17:50:22 +01:00
Lion Kortlepel
43429eadb3 fixup 2024-02-06 00:11:31 +01:00
Lion Kortlepel
6af471f025 start working on event handlers 2024-02-05 20:45:46 +01:00
Lion Kortlepel
5468e5c854 make the compiler happy 2024-02-05 20:22:22 +01:00
Lion Kortlepel
a0241d1b36 replace literally the entire lua engine 2024-02-05 19:49:39 +01:00
Lion Kortlepel
55fff0138b remove old lua stuff 2024-02-05 19:49:16 +01:00
Lion
126e4b077a Remove all unused platforms from FUNDING.yml 2024-02-05 19:48:48 +01:00
Lion
d25eabda5e Create FUNDING.yml 2024-02-05 19:48:48 +01:00
Lion
01ad397a84 Update README.md 2024-02-05 19:48:48 +01:00
Lion
ef47865e88 Update LICENSE 2024-02-05 19:48:48 +01:00
Lion Kortlepel
94ea20b6b7 add AGPL-3.0 license header 2024-02-05 19:48:46 +01:00
Lucca Jiménez Könings
3e2bbf1539 fix typos and phrasing in README.md
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
2024-02-05 19:48:31 +01:00
Lucca Jiménez Könings
f5532ec105 remove unecessary comment
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
2024-02-05 19:48:31 +01:00
Lucca Jiménez Könings
9c44c1fbe8 move undef macros into Compat.h
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
2024-02-05 19:48:31 +01:00
Lucca Jiménez Könings
4914068f90 update README.md
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
2024-02-05 19:48:31 +01:00
Lucca Jiménez Könings
0bc3676e8e document FreeBSD specific undefs
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
2024-02-05 19:48:31 +01:00
Lucca Jiménez Könings
fb0590653d fix typo
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
2024-02-05 19:48:31 +01:00
Lucca Jiménez Könings
83e0aaaaa2 update README.md
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
2024-02-05 19:48:31 +01:00
Lucca Jiménez Könings
b053c3c22f fix tests on FreeBSD
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
2024-02-05 19:48:31 +01:00
Lucca Jiménez Könings
cd9f8e3056 add FreeBSD build target
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
2024-02-05 19:48:31 +01:00
Lion Kortlepel
23ea3311cf fix release arm64 workflow 2024-02-05 19:48:31 +01:00
Lion Kortlepel
f9d43eac66 fix windows build wrongly calling vcpg from the submodule 2024-02-05 19:48:31 +01:00
Lion Kortlepel
94b9ef3eae remove --build-id=none from build flags 2024-02-05 19:48:31 +01:00
Lion Kortlepel
d0cc23333c ensure client stays referenced while referenced in thread pool 2024-01-26 10:32:41 +01:00
Lion Kortlepel
c173ffdbdc implement state change to playing 2024-01-25 12:12:06 +01:00
Lion Kortlepel
7d813f7562 use a single strand per client to avoid writing to tcp out of order 2024-01-25 08:52:11 +01:00
Lion Kortlepel
ee74d6291b update protocol 2024-01-25 08:40:45 +01:00
Lion Kortlepel
8654beb706 implement most of the Playing state, vehicle positions, vehicle data 2024-01-22 18:23:50 +01:00
Lion Kortlepel
630d5f1cfa implement session sync 2024-01-22 16:56:07 +01:00
Lion Kortlepel
bde689d31a implement fully async read and write with individual timeouts 2024-01-21 22:54:36 +01:00
Lion Kortlepel
303a619ece implement async accept, async read for tcp 2024-01-20 19:20:33 +01:00
Lion Kortlepel
24723c01da update protocol 2024-01-20 18:18:15 +01:00
Lion Kortlepel
b06991aaca migrate codebase to new network
marked non-implemented stuff with an exception
2024-01-19 17:34:36 +01:00
Lion Kortlepel
e0fe6693e0 implement vehicle specifics, code needed for the rest of the server 2024-01-19 17:33:53 +01:00
Lion Kortlepel
b882174ae7 add boost thread, glm 2024-01-19 17:33:19 +01:00
Lion Kortlepel
3de142a6d0 use boost::scoped_thread in IThreaded 2024-01-19 14:42:21 +01:00
Lion Kortlepel
9502048525 move packet to protocol 2024-01-17 14:59:45 +01:00
Lion Kortlepel
9e99177fcb implement compression and decompression 2024-01-17 14:52:09 +01:00
Lion Kortlepel
dbab9eb894 handle udp packets like usual packets 2024-01-16 01:03:03 +01:00
Lion Kortlepel
9ea0931e13 implement udp connection 2024-01-16 00:58:14 +01:00
Lion Kortlepel
e9805c3679 refactor identification to its own method 2024-01-15 22:22:27 +01:00
Lion Kortlepel
ff33f1d42f update protocol 2024-01-15 22:18:59 +01:00
Lion Kortlepel
65d2ba3556 server-side identification done 2024-01-15 22:18:25 +01:00
Lion Kortlepel
6a411171f9 start implementing parsing of packets server-side 2024-01-15 22:11:44 +01:00
Lion Kortlepel
05dfb4e0c3 fix c header -> c++ header 2024-01-15 20:57:15 +01:00
Lion Kortlepel
4aca87d3e6 fully implement tcp and udp send and recv of packet types 2024-01-15 20:56:44 +01:00
Lion Kortlepel
7e9bb0cbf2 start rewriting networking 2024-01-15 20:39:32 +01:00
Lion Kortlepel
443871ec0f remove usages of weak_ptr 2024-01-11 14:30:25 +01:00
Lion Kortlepel
130e1acdb3 refactor client disconnect, client interation
anywhere a client is disconnected, TNetwork::Disconnect is called now.
Nothing else is valid.
ForEachClientWeak() was fully removed.
2024-01-11 14:14:34 +01:00
Lion Kortlepel
aa29d04b60 remove unused TVehicleDataLockPair 2024-01-11 14:14:34 +01:00
Lion Kortlepel
b9f73f77c3 major refactor of Client and Server
this refactor includes changes to TClient:

- all member fields are now public, but protected with Sync (an alias
  for boost::synchronized_value
- removed all (now) obsolete getters and setters

changes to TServer and TNetwork:

- thread-safe ID generation, previously it was possible for there to be
  ID duplicates. this is now solved by moving id generation and
  assignment into the same mutex locked context.
- deprecated ForEachClientWeak and replaced some usages of it with
  ForEachClient, getting rid of the weak_ptr shit in most places
- implemented a bunch of new functions for getting rid of more weak_ptr
  everywhere
2024-01-11 14:14:31 +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
Lion
d5000aea87 Remove changelog (#232)
now fully replaced by github releases due to issue-based workflow
2023-12-28 14:25:42 +01:00
Lion
810788a3e4 Add Tags Feature (#192)
This PR adds a tags functionality to the BeamMP server config and
heartbeat.
The intended purpose of this is to enable better filtering on the server
list based on keywords such as gamemode or roleplay.
2023-12-28 13:58:59 +01:00
Lion Kortlepel
e724a2e467 Merge remote-tracking branch 'origin/master' into feature-tags 2023-12-28 13:57:49 +01:00
Lion Kortlepel
54ba295fce remove changelog
now fully replaced by github releases due to issue-based workflow
2023-12-28 13:53:32 +01:00
Lion
f419550061 Allow env to override serverconfig (#227) 2023-12-28 13:51:00 +01:00
Lion Kortlepel
8cccbe8542 Merge remote-tracking branch 'origin/master' into 226-allow-env-to-override-serverconfig 2023-12-28 13:49:02 +01:00
Lion Kortlepel
6787843b37 pretty-print tags on startup 2023-12-28 12:58:29 +01:00
Lion Kortlepel
16d3c6f796 Merge remote-tracking branch 'origin/master' into feature-tags 2023-12-28 12:36:22 +01:00
Lion
21e5101560 Make debug symbols available for release builds (#216)
Closes #214
2023-12-28 12:30:40 +01:00
Lion
1adf19d416 Bump version to 3.2.0 (#231)
Due to new features like ENV reading this is now a feature release, so
minor
2023-12-28 12:16:05 +01:00
Lion
c7e228fbae bump version to 3.2.0
due to new features like ENV reading this is now a feature release, so minor
2023-12-28 11:56:25 +01:00
Lion
6e04b2d93a Fix GitHub Actions not downloading the latest tests to run them (#220)
Closes #219
2023-12-28 11:55:02 +01:00
Lion
57a4c47cb0 Remove HTTP Server settings from config (#221)
This is not implemented and won't be implemented
2023-12-28 11:50:33 +01:00
Lion
416e0399af Remove [Feature Request] from issue title (#217) 2023-12-28 11:47:51 +01:00
Lion
050b574cc0 Remove [Bug] title from issue template (#218) 2023-12-28 11:47:39 +01:00
Lion
d65f3cf75b Fix hot reload not working with symlinked entire plugins (#230) 2023-12-28 11:42:39 +01:00
Lion Kortlepel
329d2eb268 fix hot reload not working with symlinked entire plugins 2023-12-28 11:22:00 +01:00
Lion Kortlepel
221f491019 return early after reading ENV in config 2023-12-25 16:19:53 +01:00
Lion Kortlepel
89db370e12 use env variables by default to override config values 2023-12-25 16:16:01 +01:00
Lion
aa84a65546 Update feature_request.md 2023-12-21 13:15:48 +01:00
Lion Kortlepel
b28c69a515 remove http settings from config 2023-12-21 13:07:35 +01:00
Lion Kortlepel
ac41547123 bump version to 3.1.4 2023-12-21 13:05:33 +01:00
Lion Kortlepel
2fc610f6bc fix tests not downloading artifacts by not using artifacts 2023-12-21 13:01:50 +01:00
Lion Kortlepel
ddd3883aa9 fix failing gh actions test run 2023-12-21 13:01:50 +01:00
Lion
defadf094f Fix exit after 10 seconds (#215)
Also fixes initializing the console too early by @lionkor
2023-12-21 12:50:19 +01:00
Lion Kortlepel
81299db946 fix console initializing too early
the console was initialized too early, leading to the server waiting for
it to shut down if the authkey is invalid, among other issues.
2023-12-21 12:49:20 +01:00
Lion
c3895ec1ca remove [Bug] title from issue template 2023-12-21 12:17:50 +01:00
Lion
c741fe5310 remove [Feature Request] from issue title 2023-12-21 12:17:11 +01:00
Lion Kortlepel
e1dfb1085e modify release workflows to add debug info artifacts 2023-12-21 11:17:17 +01:00
Lion Kortlepel
142b6fa47a modify build scripts to generate .debug files with debug info 2023-12-21 11:13:51 +01:00
Bennett
a6cbffc774 fix exit after 10 seconds 2023-12-21 02:01:21 -08:00
Starystars67
dc4ead532d Changed default tag to Freeroam as that is the majority of servers. 2023-12-18 14:10:07 +00:00
Lion
f28d9bc7dc Update README.md 2023-12-16 20:18:40 +00:00
Starystars67
8c73eb8aea Added Tags Feature to the BeamMP Server. This allows better filtering on the server list. 2023-12-10 12:50:24 +01:00
Lion
43b1b050e2 Fix workflows to make release builds (#202)
Currently the Windows workflow doesn't properly create a release binary.
2023-12-09 20:17:10 +01:00
Lion Kortlepel
9f87edc6e9 add msvcp140.dll comment to the release text 2023-12-09 20:09:56 +01:00
Lion Kortlepel
c6f78c5522 fix release build path 2023-12-09 20:06:50 +01:00
Lion Kortlepel
9f01268538 update version to 3.1.3 2023-12-09 20:01:53 +01:00
Lion Kortlepel
5523a4fe4b force build release config on windows 2023-12-09 20:00:33 +01:00
Lion Kortlepel
7f11d0f002 make release builds by default 2023-12-09 19:22:50 +01:00
Lion Kortlepel
6b31ba35fd attempt to fix workflows to make release builds 2023-12-09 19:18:33 +01:00
Lion
d2329f0723 Remove password setting from config to avoid confusion (#199)
...until implemented.

The client afaik currently doesn't support this setting.
2023-12-09 19:05:54 +01:00
Luuk van Oijen
ef45efeb86 Update readme to new build system (#200)
Now building is like 2 steps, so the readme reflects that now.
2023-12-09 18:33:46 +01:00
Lion
edcca75637 Update README.md 2023-12-08 17:18:54 +01:00
Lion
c1bacf1f3a remove old instructions from readme, cleanup 2023-12-08 17:16:47 +01:00
Lion Kortlepel
795b651744 remove macos section 2023-12-05 18:35:57 +01:00
Lion Kortlepel
be108bb8b3 update readme to new build system 2023-12-05 18:34:06 +01:00
Lion Kortlepel
d8b8812026 remove password setting from config to avoid confusion
...until implemented
2023-12-05 18:23:23 +01:00
Lion
872c2d410d New buildsystem (#197) 2023-12-05 18:21:20 +01:00
Lion Kortlepel
f98704e0f3 fix warnings about implicit conversion 2023-12-05 18:05:35 +01:00
Lion Kortlepel
dea203c108 make IThreaded::~IThreaded virtual to make destruction happen 2023-12-05 18:03:13 +01:00
Lion Kortlepel
e245c9e9e2 fix pps monitor warning about virtual dtor 2023-12-05 18:02:35 +01:00
Lion Kortlepel
11fe5ad200 fix invalid timeout value 2023-12-05 18:00:34 +01:00
Lion Kortlepel
667da22b0e Merge remote-tracking branch 'origin/master' into new-buildsystem 2023-12-05 17:59:05 +01:00
Lion Kortlepel
a6eb2f7bfe switch to vcpkg+cmake, add debian build to workflows
using lionkor's template (MIT licensed)

This is a combination of 64 commits.
2023-12-05 17:57:19 +01:00
Lion Kortlepel
103d2dc030 update vcpkg in workflows 2023-12-03 17:50:45 +01:00
Lion Kortlepel
7f206fd0d4 bump version to 3.1.2 2023-12-03 17:49:12 +01:00
Lion Kortlepel
22805af716 fix crash in authentication 2023-12-03 17:43:41 +01:00
Lion
2c29a195f9 optimize: Add conditional variable to LuaResult (#162)
Implementing TODO for optimization I saw in the code.
2023-03-27 13:31:21 +02:00
rgnter
222d2492ff Merge branch 'master' into optimize/add_cv_to_luaresult 2023-03-21 20:17:17 +01:00
Simon
879b9772f5 Apply suggestions from code review
Co-authored-by: Lion <development@kortlepel.com>
2023-01-15 17:12:35 +00:00
Anonymous275
c51cf090ef fix linux build 2023-01-15 17:12:35 +00:00
Anonymous275
d677d8d58d rename Hash function to HashPassword
move HashPassword to cpp only
move check to line 285
2023-01-15 17:12:35 +00:00
Anonymous275
4b30918659 - add 120 seconds timeout 2023-01-15 17:12:35 +00:00
Anonymous275
688e46f524 - fix linux build 2023-01-15 17:12:35 +00:00
Anonymous275
9f59c27b1f - add hash function
- add password config
- add debug messages for password stages
- add pass boolean for heartbeat
- adjust network codes
2023-01-15 17:12:35 +00:00
Lion
6a11bcd20b fix bad package name for Ubuntu in Readme (#161)
The package name for liblua required to build is not correct. The
correct name is
[`liblua-5.3-dev`](https://packages.ubuntu.com/search?suite=all&searchon=names&keywords=liblua5.3)
2022-12-21 16:29:49 +01:00
rgnter
b7b578bf3e add conditional variable to LuaResult 2022-12-18 14:45:33 +01:00
rgnter
6c145a6dbf fix: Bad package name for Ubuntu 2022-12-18 12:32:45 +01:00
Lion
67d792e0e0 remove repeated dependency from README (#155) 2022-11-14 14:32:19 +01:00
Qest333
eaeef0c7d0 Remove double dependency from README 2022-11-14 14:00:21 +01:00
Lion
47e64a7343 merge release candidate v3.1.1 (#142)
patches and hotfixes!
2022-10-31 11:32:16 +01:00
Lion Kortlepel
7f5b3919f4 make destructors of virtual classes virtual
this causes warnings in clang, and rightfully so :^)
2022-10-31 11:31:16 +01:00
Lion Kortlepel
896e777e23 update changelog 2022-10-31 11:31:16 +01:00
Lion Kortlepel
aa58c1e211 another potential fix for #141 2022-10-31 11:31:15 +01:00
Lion Kortlepel
49a9226dca update changelog to mention fixes 2022-10-31 11:31:15 +01:00
Lion Kortlepel
b10d5d0f4e fix empty events causing issues in the server
an empty event packet, if sent just right, could crash the server
2022-10-31 11:31:15 +01:00
Lion Kortlepel
5581fd1692 fix chat message impersonation issue
instead of using the supplied name, we ignore it entirely and use the
server's internal name for the client
2022-10-31 11:31:15 +01:00
Lion Kortlepel
d36bb7962c ignore empty chat messages
this could happen with a malicious client of some kind, we should simply
ignore them
2022-10-31 11:31:15 +01:00
Lion Kortlepel
4e8bd993d5 remove J packet handler
it wasn't used by anything in the launcher, mod, or during the join
sequence, so i removed it for now.
2022-10-31 11:31:15 +01:00
Lion Kortlepel
abff9bfbdb fix crash when chat message is malformed 2022-10-31 11:31:15 +01:00
Lion Kortlepel
b024533f90 fix crash when the header of a TCP packet is negative 2022-10-31 11:31:15 +01:00
Lion Kortlepel
f9251ff92c add more warning prints on unexpected cases 2022-10-31 11:31:15 +01:00
Lion Kortlepel
99f41c28cb fix #135 by making onPlayerDisconnect blocking, and calling it before removing the player
before, the handlers were not waited for, so the client was usually
destructed before lua got to the actual event handler call. Now, the
handler is called and waited on, and once all handlers are done, the
client is properly removed from the players internally, thus making
calls to GetPlayerName, GetPlayerIdentifiers, etc. return nil etc.
2022-10-31 11:31:15 +01:00
Lion Kortlepel
bbd27c9cba fix formatting bug in status (closes #143) 2022-10-31 11:31:15 +01:00
Lion Kortlepel
4682922467 add more fixes for msvc static linking 2022-10-31 11:31:15 +01:00
Lion Kortlepel
83fb387dfe potential fix to #141 2022-10-31 11:31:09 +01:00
Lion Kortlepel
2b61f11a86 fix EnsureArgsCount not properly printing min/max 2022-10-31 11:24:13 +01:00
Lion Kortlepel
a8b1a205f7 bump version to 3.1.1
I'm expecting to release a 3.1.1 with some fixes
2022-10-31 11:24:13 +01:00
Lion
dd9376447a Fix README errors (#138) 2022-10-26 14:34:01 +02:00
Lion
aa185afabf Update README.md 2022-10-23 03:35:39 +02:00
Lion
e8caeb9126 merge release candidate v3.1.0 (#83)
See https://github.com/BeamMP/BeamMP-Server/blob/rc-v3.1.0/Changelog.md for
a list of changes
2022-10-22 23:24:48 +02:00
Lion Kortlepel
fa1944dbef update readme to reflect dependency- and code-changes in 3.1.0 2022-10-22 23:22:42 +02:00
Lion Kortlepel
093f905fd8 remove redundant addition libboost library install in cmake-linux action 2022-10-22 23:06:11 +02:00
Lion Kortlepel
2a45d2282d update rc-v3.1.0 to master 2022-10-22 22:55:12 +02:00
Lion Kortlepel
aeb024953a fix sentry line that caused build to fail 2022-10-22 22:48:23 +02:00
ㄗㄠˋ ㄑㄧˊ
12a0ab7fdd document dependencies for macos (#109) 2022-10-22 22:47:53 +02:00
Lion Kortlepel
917c501faf fix typo causing beammp forum id not to show in identifiers (fix #137) 2022-10-22 21:16:31 +02:00
Lion Kortlepel
340933bbb3 fix dependencies for test run (add curl, fix ssl) 2022-10-22 21:01:44 +02:00
Lion Kortlepel
a63359479e rename dependencies for test run in github actions 2022-10-22 20:44:47 +02:00
Lion Kortlepel
bdf2da758c remove pps from heartbeat
"PPS has no meaning anymore and is completely irrelevant. You should
ignore it, it is not an indicator of ANYTHING. If it’s high, that means
NOTHING. If it’s low, that means NOTHING. If it’s -, that means
NOTHING."

It's packets per second per player per vehicle, but is only sent every
30 seconds, its not averaged, and on the client-side, it shows a ping
icon next to it.

A client can open a new connection to the server and send a `P`, and
measure the time to the `P` response packet. The connection is then
closed. This was added ages ago, please use this instead for ping :)
2022-10-17 14:05:51 +02:00
Lion Kortlepel
88c0ed56e4 add _WIN32_WINNT and move CRT no warnings flag 2022-10-17 12:25:13 +02:00
Lion Kortlepel
4256977400 remove crt's "this function or variable may be unsafe" warnings
they are useless, as they are in dependencies or parts of the code
we don't care about. Also, the "safe" alternatives straightup dont work
on linux.
2022-10-17 12:21:27 +02:00
Lion Kortlepel
309a9d1fa9 fix invalid windows workflows indentation 2022-10-17 12:12:55 +02:00
Lion Kortlepel
ad860835ca fix linux tests run not installing openssl properly 2022-10-17 12:10:52 +02:00
Lion Kortlepel
c6c2efb0b1 revert "update linux and windows workflows to run on pr open, reopen, review submit"
This reverts commit 23e9941704.
2022-10-17 12:09:36 +02:00
Lion
c4c3b03b7a replace networking with boost::asio (synchronous) (#134)
- replaced all networking with boost::asio abstractions
- rewrote the SetStatus(), GetStatus() crap (now IsDisconnected() and
Disconnect() with reason)
- fixed bug related to ghost players / ghost cars
- handles packets as binary for the most part (vector<uint8_t> instead
of string) to fix various issues
2022-10-17 12:03:43 +02:00
Lion Kortlepel
fd51336a91 update vcpkg 2022-10-17 12:01:08 +02:00
Lion Kortlepel
466845b314 add udp binary data fix to Changelog 2022-10-16 00:05:02 +02:00
Lion Kortlepel
92632b53b5 fix binary data breaking in UDPRcvFromClient 2022-10-15 23:30:09 +02:00
Lion Kortlepel
331a597ec7 add info about new networking to changelog 2022-10-15 23:19:33 +02:00
Lion Kortlepel
87965433c2 change log levels of common warnings and errors to debug
this hides a lot of the "standard" errors we get behind the debug flag.
for example, disconnecting a disconnected player would be such an error
2022-10-15 23:16:16 +02:00
Lion Kortlepel
75ff9f7571 remove "backend response failed to parse as valid json" 2022-10-15 23:16:16 +02:00
Lion Kortlepel
94c0547a35 fix crash when the client disconnects while sending first identify setting 2022-10-15 23:16:16 +02:00
Lion Kortlepel
98f77e157f add WIN32_STATIC_RUNTIME option to cmake 2022-10-15 23:16:16 +02:00
Lion Kortlepel
54730d2baf remove heartbeat spam logging 2022-10-15 23:16:16 +02:00
Lion Kortlepel
064e71e59f fix client version check 2022-10-15 23:16:16 +02:00
Lion Kortlepel
2678234d67 dont check for -Werror=zero-as-null-pointer-constant 2022-10-15 23:16:16 +02:00
Lion Kortlepel
4320a91e5c use message() instead of what() for ec 2022-10-15 23:16:16 +02:00
Lion Kortlepel
7d1318653c fix boost::system::error_code 2022-10-15 23:16:16 +02:00
Lion Kortlepel
67d02d4cf2 remove unused error check 2022-10-15 23:16:16 +02:00
Lion Kortlepel
93b2559120 switch to boost 1.74 2022-10-15 23:16:05 +02:00
Lion Kortlepel
ed872f730d link against boost::system 2022-10-06 00:57:31 +02:00
Lion Kortlepel
b25f4a875c run on latest ubuntu 2022-10-06 00:54:57 +02:00
Lion Kortlepel
cc6b7846b2 add system include 2022-10-06 00:51:51 +02:00
Lion Kortlepel
88f5db514f remove unused headers 2022-10-06 00:46:35 +02:00
Lion Kortlepel
e595192829 rename header to boost errc 2022-10-06 00:43:17 +02:00
Lion Kortlepel
c69418ea5e add boost_system dependency for linux gh actions 2022-10-06 00:40:39 +02:00
Lion Kortlepel
917e3f98ab fix github actions dependencies for linux to use proper boost version 2022-10-06 00:36:57 +02:00
Lion Kortlepel
c42a523532 remove SO_SNDTIMEO for now 2022-10-06 00:24:13 +02:00
Lion Kortlepel
95ae0f5d03 fix 'Od' and 'Or' packets not being broadcast 2022-10-05 22:17:56 +02:00
Lion Kortlepel
fc0a509bd9 fix clientversion parameter in heartbeat 2022-10-05 21:15:11 +02:00
Lion Kortlepel
6249397fb5 add libboost-all-dev to github actions
it's a new dependency
2022-10-05 20:50:28 +02:00
Lion Kortlepel
231b13a0e7 fix a ghost client bug 2022-10-05 18:17:18 +02:00
Lion Kortlepel
7d2e4d4581 replace tcp networking with boost::asio tcp networking 2022-10-05 18:17:04 +02:00
Lion Kortlepel
7446526a19 fix binding of udp server socket
it was not binding properly because it wasn't open()ed, i guess
2022-10-05 13:06:36 +02:00
Lion Kortlepel
6e97a3cd6e switch udp networking to boost implementation 2022-10-05 12:14:25 +02:00
Lion Kortlepel
30482d290a add boost 1.75 dependency
this should be available on most platforms.
boost allows us to simplify a LOT of code.
2022-10-05 11:50:15 +02:00
Lion Kortlepel
5f1d003077 fix various potential crashes in TServer::HandlePosition 2022-10-03 17:06:32 +02:00
Lion Kortlepel
5d3dff3c88 add identifiers (beammp id, ip) as an argument to onPlayerAuth 2022-10-03 15:31:32 +02:00
Lion Kortlepel
cb0cb30797 fix windows compiler not understanding a CLEAR AND SIMPLE FUNCTION-STYLE
CONSTRUCTOR CALL

AHHHHHHH
2022-10-03 15:12:59 +02:00
Lion Kortlepel
1f14de2e71 revert 9c6127a105 and apply proper fix 2022-10-03 15:11:26 +02:00
Lion Kortlepel
658b37acac fix error sometimes not displaying when failing inside global event handler 2022-10-03 14:38:19 +02:00
Lion Kortlepel
d63c84286e replace logging functions with new fmt versions in ParseVehicle 2022-10-01 22:25:45 +02:00
Lion Kortlepel
9c6127a105 fix bug which may cause a server to crash when a car is spawned
thanks @Anonymous275
2022-10-01 19:10:21 +02:00
Lion Kortlepel
a1d99c0203 update commandline library
includes a fix for alpine
2022-09-27 23:07:30 +02:00
Lion Kortlepel
10dff185e0 change changelog to correctly say "Util.Json*", not MP 2022-09-27 17:25:18 +02:00
Lion Kortlepel
dd17b95427 add changelog message about MP.TriggerClientEventJson 2022-09-27 17:02:25 +02:00
Lion Kortlepel
1a9872db00 fix unhandled return value of fread in TConfig::TConfig unit test 2022-09-27 15:49:55 +02:00
Lion Kortlepel
dbb01998ea fix ignored return value in getch_ 2022-09-26 12:24:44 +02:00
Lion
3c4737a145 fix colon in changelog once more, thanks to github's editor being bad 2022-09-26 12:23:30 +02:00
Lion
36e8ba1614 fix colon in changelog to be in proper code quotes 2022-09-26 12:22:22 +02:00
Lion Kortlepel
988f19fd00 fix getch_ to explicitly ignore read() return value 2022-09-26 12:20:07 +02:00
ㄗㄠˋ ㄑㄧˊ
fdf24815bb document dependencies for macos (#109) 2022-09-26 12:18:47 +02:00
Lion Kortlepel
b145c8159e update changelog to add HOME and END button, fix ip comment 2022-09-26 12:12:16 +02:00
Lion Kortlepel
ae517b30c0 fix bug which caused updates to only check the first URL 2022-09-26 12:04:42 +02:00
Lion Kortlepel
e638c25f70 change assertions to print the error in release builds
this should make it easier to debug crashes in the server remotely in
release builds when sentry is down.
2022-09-26 12:03:57 +02:00
Lion Kortlepel
24c98eb2b2 add more compile-time diagnostics, implement fixes for them
Before, a lot of common errors went unnoticed, due to insufficient
compiler diagnostics. This commit fixes this by adding a lot of new
diagnostics, and fixing the issues found by this.
2022-09-26 12:02:05 +02:00
Lion
501fddadc6 Merge pull request #127 from BeamMP/feature-betterautocomplete
Feature: Better autocomplete
2022-09-26 10:44:15 +02:00
Lion Kortlepel
6da9a921d0 fix "init and reset termios" unit test
it was testing via memory-equality, which is not valid.
2022-09-26 01:14:08 +02:00
Lion Kortlepel
a8333359ce update commandline to work with new autocomplete 2022-09-26 00:17:23 +02:00
20dka
b71aa2db04 advanced autocomplete for lua 2022-09-26 00:13:16 +02:00
Lion
78f7cdc17a Merge branch 'master' into rc-v3.1.0 2022-09-25 19:50:12 +02:00
Lion Kortlepel
36a1da3218 fix TServer::HandlePosition declaration
it was different from the implementation
2022-09-14 20:59:07 +02:00
Lion Kortlepel
23e9941704 update linux and windows workflows to run on pr open, reopen, review submit 2022-09-14 20:42:25 +02:00
Lion
469eb78c80 Merge pull request #123 from 20dka/rc-v3.1.0
Add MP.GetPositionRaw() with lua fixes and features
2022-09-14 20:41:33 +02:00
Lion Kortlepel
af5658d0e1 update toml11 2022-09-14 20:41:00 +02:00
Lion Kortlepel
1062e29582 update sentry-native 2022-09-14 20:41:00 +02:00
Lion Kortlepel
ec9a280d30 update libzip 2022-09-14 20:41:00 +02:00
Lion Kortlepel
784bbd4f6b update fmt 2022-09-14 20:41:00 +02:00
Lion Kortlepel
bc6b4e40e1 update httplib 2022-09-14 20:41:00 +02:00
Lion Kortlepel
071ba08dfe update sol2 2022-09-14 20:41:00 +02:00
Lion Kortlepel
023738c41b update json 2022-09-14 20:41:00 +02:00
Lion Kortlepel
6a166110f6 update doctest 2022-09-14 20:41:00 +02:00
Lion Kortlepel
71fbf7b7cc update commandline 2022-09-14 20:41:00 +02:00
20dka
4b242c26fc optimize function argument passing in GetPidVid, TServer::HandlePosition 2022-09-14 18:53:44 +02:00
20dka
a84d042a8a add error messages to some lua events 2022-09-14 12:45:40 +02:00
20dka
44b94c9e58 add MP.GetPositionRaw(pid, vid)
fix vehicles sometimes not deleting for all players
2022-09-14 01:54:49 +02:00
Lion
660f94b691 Merge pull request #110 from tsao-chi-forks/patch-2
Support build on apple silicon
2022-09-13 16:15:34 +02:00
Lion
a7c4103f7c add section about adding features 2022-08-08 20:10:50 +03:00
Lion Kortlepel
0932078e4b add CONTRIBUTING.md 2022-08-08 20:10:50 +03:00
Lion Kortlepel
54e02abad1 update toml11 2022-08-03 18:16:56 +02:00
Lion Kortlepel
e4cbba59ef update sentry-native 2022-08-03 18:14:19 +02:00
Lion Kortlepel
e4db66782e update libzip 2022-08-03 18:13:49 +02:00
Lion Kortlepel
b443bec72e update fmt 2022-08-03 18:13:25 +02:00
Lion Kortlepel
76a8f231ac update httplib 2022-08-03 14:02:11 +02:00
Lion Kortlepel
398f8d3fa4 update sol2 2022-08-03 14:01:40 +02:00
Lion Kortlepel
60dd1e2472 update json 2022-08-03 14:01:04 +02:00
Lion Kortlepel
e634b4b6b7 update doctest 2022-08-03 14:00:26 +02:00
Lion Kortlepel
1caa5e3517 update commandline 2022-08-03 13:59:54 +02:00
Lion Kortlepel
b009a37f35 update asio to 1-23-0 2022-08-03 13:59:11 +02:00
Lion Kortlepel
054016a099 remove debug print 2022-07-20 16:08:56 +02:00
Lion Kortlepel
8b57f6e35a fix missing Lua error messages in ResultCheckThread 2022-07-20 16:07:00 +02:00
Lion Kortlepel
f21d3d0389 fix bug which caused Lua hot-reload not to report syntax errors 2022-07-20 14:56:58 +02:00
Lion Kortlepel
2ed92c4aa1 fix plugin monitor eating a whole cpu core
i must have messed this up when i changed the plugin monitor behavior
recently
2022-07-20 14:42:07 +02:00
Lion Kortlepel
fd7b11f436 fix event loop timing issue
The event loop tries to run no faster than every 10ms. If it detects
that it goes faster, it would incorrectly calculate the difference, and
then wait (what I assume was) way too long or too short.
Either way, now it's fixed and it correctly works, even when introducing
new lua states.
2022-07-20 14:33:19 +02:00
Lion Kortlepel
6a94060970 update changelog 2022-07-14 02:08:28 +02:00
Lion Kortlepel
51ccf31373 add beammp_debugf 2022-07-14 01:38:35 +02:00
Lion Kortlepel
a2cc629153 add onFileChanged (fixes #116) 2022-07-14 01:18:50 +02:00
Lion Kortlepel
ad414ec5c9 call onInit on hot-reload, cleanup, remove warnings
onInit is now called on hot-reload, for the whole plugin. Arguably, this
is not expected behavior, since only one file is being reloaded, but
this is the easiest way to do it, and the entire hot-reload process is
only for development purposes. Open an issue if this breaks your stuff
:^)
2022-07-14 00:37:47 +02:00
Lion Kortlepel
0a8e7d8e50 add TriggerLocalEvent 2022-07-14 00:27:44 +02:00
Lion
bbd026e399 Merge pull request #114 from Mack29446/rc-v3.1.0
Add support to properly parse IPs
2022-07-13 00:02:40 +02:00
Mackenzie
04bbdff6b7 Add code from EvanMulawski 2022-07-12 22:59:41 +01:00
Lion
a28b3e1532 Merge pull request #113 from Mack29446/master
Update README.md
2022-07-10 12:55:23 +02:00
Mackenzie
b01bed2996 change dependency section 2022-07-10 11:51:19 +01:00
Mackenzie
7bdc2b304b refactor: master is considered unstable 2022-07-10 11:47:55 +01:00
Mackenzie
b19bca4c82 fix numbering 2022-07-10 11:38:51 +01:00
Mackenzie
708848f275 Update README.md 2022-07-10 11:35:44 +01:00
Lion Kortlepel
2d8ce09b2c Merge remote-tracking branch 'origin/master' into rc-v3.1.0 2022-07-09 23:03:46 +02:00
Lion
05251efc06 Merge pull request #98 from BeamMP/rc-v3.0.2
RC v3.0.2
2022-07-09 22:55:16 +02:00
Lion Kortlepel
f8d622352f generate toml from scratch 2022-07-09 22:42:38 +02:00
Lion Kortlepel
6c1d02a425 add fclose 2022-07-09 22:29:12 +02:00
Lion Kortlepel
38eeec39b4 another attempt to fix #105 2022-07-09 22:27:05 +02:00
Lion Kortlepel
696e080e1c fix #105 2022-07-09 22:01:53 +02:00
Lion Kortlepel
98681254e6 update toml11 2022-07-09 21:50:23 +02:00
Lion Kortlepel
420e6c3533 roll back to an ancient version of sentry
sentry-native deprecated compiling without error somewhere around one of
the next version
2022-07-09 21:40:19 +02:00
Lion Kortlepel
06f8ba5a0e update sentry-native to 0.4.18 2022-07-09 21:11:34 +02:00
Lion Kortlepel
9420d8a7a0 update changelog 2022-06-30 21:30:56 +02:00
Lion Kortlepel
dfa90da8af check if Resources/Server directory exists, and only create it if it doesnt
While this doesn't make a difference with usual setups, it does if the
server path exists but is a symlink. In that case, the
create_directories call fails, and the server aborts.

this fixes that. :^)
2022-06-30 20:19:48 +02:00
ㄗㄠˋ ㄑㄧˊ
d6625187d1 Support build on apple silicon 2022-06-29 13:43:36 +08:00
Lion Kortlepel
6e46d5aca9 start building the clear command 2022-06-28 03:29:01 +02:00
Lion Kortlepel
817bd4b588 start fixing mod download 2022-06-28 03:20:42 +02:00
Lion Kortlepel
25391fa0c7 thank you toml11 maintainer for naming your header some super generic name that clashes with every single other toml library B) 2022-06-04 16:51:34 +03:00
Lion
28270072d4 Merge pull request #102 from Mack29446/master
update version number in git checkout command
2022-05-30 19:16:10 +02:00
Lion Kortlepel
758d5b2c96 Revert "let's try vcpkg"
This reverts commit 8d7505956d.
2022-05-29 14:37:50 +02:00
Lion Kortlepel
1970d97ea4 Revert "Remove unneeded submodules"
This reverts commit a5153e4bc1.
2022-05-29 14:37:41 +02:00
Lion Kortlepel
d8526f0649 TNetwork::SplitLoad: Use managed memory 2022-05-29 14:30:57 +02:00
Lion Kortlepel
0621c0bf82 rebase fixup 2022-05-26 21:13:18 +02:00
Lion Kortlepel
36547d1e9e Move PluginMonitor out of TLuaEngine 2022-05-26 20:59:53 +02:00
Lion Kortlepel
f06f31c2a0 add moar tests!!! 2022-05-26 16:58:13 +02:00
Lion Kortlepel
46b92b4992 only run termios test if stdin is a tty 2022-05-26 16:14:05 +02:00
Lion Kortlepel
70e53c2a70 fix dependencies
ubuntu's package naming is confusing me
2022-05-26 16:00:36 +02:00
Lion Kortlepel
cc35d83834 make linux workflow parallel, add runtime dependencies 2022-05-26 15:54:23 +02:00
Lion Kortlepel
b4f97a6da0 make tests executable before running
:^)
2022-05-26 15:44:39 +02:00
Lion Kortlepel
3d7db6d0bc windows
me waiting for MSVC to stop making me write properly, deepls retarded
code: https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fmedia.istockphoto.com%2Fphotos%2Fskeleton-reaching-for-a-window-picture-id155154794%3Fk%3D6%26m%3D155154794%26s%3D612x612%26w%3D0%26h%3DKNIrAKdhAsI1FCoMtSLXd99ZnP9MO1zZj8VkThTvwVs%3D&f=1&nofb=1
2022-05-26 15:41:52 +02:00
Lion Kortlepel
1c3b1ecc76 fix workflow test run path 2022-05-26 15:37:33 +02:00
Lion Kortlepel
303da19f48 add -t to linux workflow 2022-05-26 14:43:38 +02:00
Lion Kortlepel
c455d4855c possibly fix workflow 2022-05-26 14:40:56 +02:00
Lion Kortlepel
8df61fe44c add g++ to workflow 2022-05-26 13:58:29 +02:00
Lion Kortlepel
7224e90c68 add test workflow 2022-05-26 13:56:58 +02:00
Lion Kortlepel
fde5bc7fb6 remove tests from linux action 2022-05-26 13:50:50 +02:00
Lion Kortlepel
22b63220c7 add more tests to LuaAPI::FS, minor fixes to LuaAPI::FS
test config file creation, too
2022-05-26 13:49:13 +02:00
Lion Kortlepel
811ace1999 fix Application::IsOutdated test case types 2022-05-26 13:36:02 +02:00
Lion Kortlepel
2cf083a7e4 run tests in github actions 2022-05-26 13:34:29 +02:00
Lion Kortlepel
28c43a51ee add some tests for LuaAPI FS, termios 2022-05-26 13:33:08 +02:00
Lion Kortlepel
00f156cb86 start adding tests 2022-05-26 13:02:09 +02:00
Lion Kortlepel
67b8565a4d update json 2022-05-26 12:06:36 +02:00
Lion Kortlepel
ed8d8a6419 remove unused code 2022-05-26 12:03:03 +02:00
Lion Kortlepel
895058f85f revert sentry to 0.4.9 2022-05-26 12:01:27 +02:00
Lion Kortlepel
a0876ed58c update submodules, remove ssl crap 2022-05-26 11:59:36 +02:00
Lion Kortlepel
4f69ca1ad0 remove ssl code
@jimkoen

This was removed because, as useful and as much work as this was, we
can't reasonably take responsibility for this. Instead, a server like
this should *always* be localhost only, and if it's not, it should be
behind an nginx reverse proxy anyways. We're removing the config options
regarding this in one of the next commits.
2022-05-26 11:54:19 +02:00
Lion Kortlepel
bc1628afeb fix some sentry and linking related issues 2022-05-26 11:51:26 +02:00
Lion Kortlepel
019c5202ea add tests executable 2022-05-26 11:44:20 +02:00
Lion Kortlepel
2dd181d492 gracefully shutdown on bind() failure 2022-05-26 11:19:48 +02:00
Lion Kortlepel
a5153e4bc1 Remove unneeded submodules 2022-04-28 16:28:23 +02:00
Lion Kortlepel
8d7505956d let's try vcpkg 2022-04-28 16:26:30 +02:00
Lion Kortlepel
3b2016d09f Windows moment
Windows deprecated when
2022-04-28 14:59:41 +02:00
Lion Kortlepel
ed03096cf5 Windows moment
Windows deprecated when
2022-04-28 14:58:07 +02:00
Lion Kortlepel
88f1976668 Merge branch 'rc-v3.0.2' into rc-v3.1.0 2022-04-28 14:40:57 +02:00
Lion Kortlepel
ca52d233c0 Use another git commit id for vcpkg
this should really be done properly, yikes
2022-04-28 14:34:05 +02:00
Lion Kortlepel
34b39aad4d add message to shutdown suggesting Ctrl+C if it takes too long
This is an ongoing issue that needs to be resolved properly,
but I'm not sure what's hanging it.
2022-04-28 14:30:44 +02:00
Lion Kortlepel
f4eb492d91 Actions: try to use master as vcpkgGitCommitId 2022-04-28 14:24:02 +02:00
Lion Kortlepel
7f41a2a574 Update Changelog to reflect latest changes 2022-04-28 14:18:10 +02:00
Lion Kortlepel
11c53e0b3a Remove unused error, as Sentry's code fails to build otherwise
Thanks, sentry.
2022-04-28 14:13:51 +02:00
Lion Kortlepel
974dda9f8b HTTPServer: Add config value to specify listen IP
Change default IP to localhost,
Set default SSL to false due to this.
2022-04-28 14:12:26 +02:00
Lion Kortlepel
0979c8b1e4 HTTPServer: Attempt to catch more errors 2022-04-28 14:04:54 +02:00
Lion Kortlepel
0761036c8c TConsole::StartLoggingToFile: implement 2022-04-28 13:46:25 +02:00
Lion Kortlepel
5ded713b4b Application::CheckForUpdates: only print status the first time 2022-04-28 13:33:38 +02:00
Lion Kortlepel
668cc496b6 update commandline, unused are now errors 2022-04-28 13:29:16 +02:00
Lion Kortlepel
056d20292a Make "unable to fetch version" a trace message 2022-04-28 13:14:28 +02:00
Mackenzie
58e2383b2e update version number in git checkout command 2022-04-13 19:48:12 +01:00
Lion Kortlepel
d8c33c03ee start work on new logger 2022-04-05 22:27:45 +02:00
Lion Kortlepel
1bab3276e9 fix setsockopt SO_SNDTIMEO for windows, bump version number to 3.0.2, update commandline 2022-04-05 10:59:16 +02:00
Lion Kortlepel
4ff69528bd fix some missing declaration 2022-03-31 23:56:02 +02:00
Lion Kortlepel
5e4c7eac51 add send timeout to client tcp socket 2022-03-31 23:53:10 +02:00
Lion Kortlepel
952631bb80 add send timeout to client tcp socket 2022-03-31 23:48:07 +02:00
Lion Kortlepel
23af76dba1 Only warn once about event handlers taking >60s 2022-03-31 23:12:50 +02:00
Lion Kortlepel
5755ead9be Change :detach to :exit
@20dka
2022-03-31 22:18:55 +02:00
Lion Kortlepel
450f0a6875 Fixup merge 2022-03-31 22:17:10 +02:00
Lion Kortlepel
104737571c Merge branch 'rc-v3.0.2' into rc-v3.1.0
This is a periodic merge to keep 3.1.0 up to date with 3.0.2
2022-03-31 22:10:49 +02:00
Lion Kortlepel
d01d79a49a update changelog 2022-03-31 20:27:08 +02:00
Lion Kortlepel
d4b30a2583 CreateEventTimer: Implement CallStrategy
There are two CallStrategies:

- BestEffort (default): Will try to get your event to trigger at the specified
  interval, but will refuse to queue handlers if a handler takes too
  long.
- Precise: Will enqueue event handlers at the exact interval specified.
  Can lead to the queue filling up if the handler takes longer than the
  interval.
2022-03-31 20:13:59 +02:00
Lion Kortlepel
81dbf747d5 Kick client if we fail to send them a client event 2022-03-31 16:50:00 +02:00
Lion Kortlepel
b97397132d TLuaEngine: improve result queue handling 2022-03-31 15:59:31 +02:00
Lion Kortlepel
d86efabb1a Modernize CMakeLists, automatically update submodules
CMake will now find packages in a modern way (include(Find*)), and will
also ensure that submodules are updated, unless told otherwise.

Also removed some apple-specific workarounds, we will need to look at
that again.
2022-03-30 12:14:13 +02:00
Lion Kortlepel
de82caef33 Add HideUpdateMessages setting ("ImScaredOfUpdates") and periodic update reminders (every 5th heartbeat) 2022-03-25 13:34:28 +01:00
Lion Kortlepel
f8c58f363a Change default MaxPlayers to 8 2022-03-25 13:32:41 +01:00
Lion Kortlepel
71c2d4b859 Simplify "Backend heartbeat response" error (closes #97) 2022-03-25 12:55:35 +01:00
Lion Kortlepel
b2f27c21be update changelog 2022-03-24 16:53:39 +01:00
Lion Kortlepel
b780a08f73 use MB constant 2022-03-24 15:16:24 +01:00
Lion Kortlepel
cd4332b790 prepend . to Threads.log to make it invisible on *nix 2022-03-24 14:47:15 +01:00
Lion Kortlepel
7a814ed35e use fmt properly in beammp_*f logging functions 2022-03-24 14:45:53 +01:00
Lion Kortlepel
9e0d02c6db add fmt library, add beammp_*f 2022-03-24 14:36:39 +01:00
Lion Kortlepel
d0bb32ec63 cleanup fixme's, todo's 2022-03-24 14:26:02 +01:00
Lion Kortlepel
5180c96e2b TServer::HandleEvent: Fix mistreatment of ':' in event data 2022-03-24 14:06:50 +01:00
Lion Kortlepel
dbfe4a4d11 Fix inconsistencies with handling errors in early network startup
In most cases, when socket creation, bind, listen, or similar fails,
it's best to gracefully shutdown. We do that now.
2022-03-24 14:06:03 +01:00
Lion Kortlepel
4cb299061e add pos argument to on_autocomplete 2022-03-23 16:10:51 +01:00
Lion Kortlepel
ef902a03f3 update lionkor/commandline to v2.0.0 2022-03-23 12:06:35 +01:00
Lion Kortlepel
c1e216957b move Json* to Util, add Random, RandomRange, RandomIntRange, catch
errors in TPluginMonitor
2022-03-18 01:52:31 +01:00
Lion Kortlepel
39db1a5e42 Fix JsonEncode with mixed key/value index/value tables 2022-03-17 19:27:17 +01:00
Lion Kortlepel
be498be661 change TriggerClientEvent to take object, not string, and add TriggerClientEventJson 2022-03-17 18:48:50 +01:00
Lion
0466ae55a4 Merge pull request #96 from 20dka/feature-supressBackend
Ignore backend response if server is Private
2022-03-17 09:57:16 +01:00
20dka
6a43694c0f Ignore backend response if server is Private 2022-03-17 01:30:24 +01:00
Lion Kortlepel
fe06726d75 update commandline 2022-03-16 16:03:23 +01:00
20dka
3c08e54471 Add basic autocomplete (fix #95) 2022-03-15 01:58:26 +01:00
Lion
a97763a94f Merge pull request #91 from BeamMP/rc-v3.0.1
Release Candidate v3.0.1
2022-03-10 17:03:43 +01:00
Lion Kortlepel
daa674f448 add infinite snowmen bug to changelog 2022-03-10 12:31:02 +01:00
Lion Kortlepel
710b15535e Merge branch 'rc-v3.0.1' into rc-v3.1.0 2022-03-10 12:24:44 +01:00
Lion Kortlepel
a85fef15c2 only use sentry if URL is specified, possibly fix stupid microsoft compiler error
hey @microsoft, maybe don't have a limit on the size of obj files.
2022-03-10 12:23:24 +01:00
Lion Kortlepel
359faee696 Fix Unicycle "infinite spawning" bug 2022-03-10 12:22:11 +01:00
Lion Kortlepel
299004b14e fix msvc /bigobj issue 2022-03-10 12:21:08 +01:00
Lion Kortlepel
b09f5a401d update lionkor/commandline to 1.0.0 (adds cursor left- and right
movement)
2022-03-10 12:19:01 +01:00
Lion Kortlepel
2caa74d913 update lionkor/commandline to 1.0.0 (adds cursor left- and right
movement)
2022-03-10 12:17:46 +01:00
Lion Kortlepel
e3d9d11bbd only use sentry if URL is specified, possibly fix stupid microsoft compiler error
hey @microsoft, maybe don't have a limit on the size of obj files.
2022-03-10 01:40:47 +01:00
Lion Kortlepel
09c9b24cbf Fix Unicycle "infinite spawning" bug 2022-03-10 01:27:16 +01:00
Lion Kortlepel
a450531b8a Merge branch 'rc-v3.0.1' into rc-v3.1.0 2022-03-05 23:39:02 +01:00
Lion Kortlepel
ace7aaada7 Fix issue which caused assignments and similar lua code to not work in the console 2022-03-03 12:38:23 +01:00
Lion Kortlepel
ca3314b416 add JsonDiffApply, JsonMinify, JsonPrettify, JsonFlatten, JsonUnflatten 2022-03-03 12:25:06 +01:00
Lion Kortlepel
7d97c3b560 add FS.ListFiles, FS.ListDirectories 2022-03-02 23:41:32 +01:00
Lion Kortlepel
dd5cf1a4af move some things in changelog from 3.0.1 to 3.1.0 2022-03-02 13:30:56 +01:00
Lion Kortlepel
9a0cdc6517 rename JsonSerialize to JsonEncode, JsonDeserialize to JsonDecode 2022-03-02 13:26:53 +01:00
Lion Kortlepel
965935a0e6 catch invalid json to JsonDeserialize, use lua_nil instead of nil 2022-03-02 13:25:29 +01:00
Lion Kortlepel
96a0e4b6fb update changelog 2022-03-02 13:23:08 +01:00
Lion Kortlepel
b52677e585 Add JsonDeserialize 2022-03-02 13:22:26 +01:00
Lion Kortlepel
95b417bb36 Add MP.JsonSerialize 2022-03-02 11:43:48 +01:00
Lion Kortlepel
8ce3be03a3 make bigobj a linker flag? 2022-02-17 12:00:03 +01:00
Lion Kortlepel
687b4e4235 add bigobj flag 2022-02-17 11:47:28 +01:00
Lion Kortlepel
86ad28abdc Microsoft (R) Windows (TM) needs deprecation 2022-02-17 11:29:51 +01:00
Lion Kortlepel
a982d54202 add debug build to windows github actions 2022-02-17 11:13:07 +01:00
Lion Kortlepel
588c68ebe1 Use proper argument parser 2022-02-17 11:08:48 +01:00
Lion Kortlepel
548b2512cc proper command parsing 2022-02-15 16:06:59 +01:00
Lion Kortlepel
8ff94a57d7 Add ParseCommand implementation 2022-02-15 15:34:33 +01:00
Lion Kortlepel
a44684f6e7 Add backend provided message to all auth loggings 2022-02-15 15:20:25 +01:00
Lion Kortlepel
944b68c6d5 format backend refused message nicer 2022-02-15 15:19:41 +01:00
Lion Kortlepel
01268821dc Merge branch 'rc-v3.0.1' into rc-v3.1.0 2022-02-15 15:15:51 +01:00
Lion Kortlepel
5553aca0bb set heartbeat status properly 2022-02-12 22:08:49 +01:00
Lion Kortlepel
beaea4f624 Fix crash when giving commandline arguments with no console initialized 2022-02-11 11:57:01 +01:00
Lion
a4f07c9a4d Merge pull request #86 from BeamMP/rc-v3.0.1
Release Candidate v3.0.1
2022-02-11 11:07:39 +01:00
Lion Kortlepel
dada8fe6bf update changelog 2022-02-11 11:01:39 +01:00
Lion Kortlepel
36853ca683 add MSG_NOSIGNAL to all calls to send() to get rid of useless SIGPIPE signals 2022-02-11 10:59:17 +01:00
Lion Kortlepel
d969c4a2c2 Use nlohmann/json for IsUnicycle 2022-02-11 10:36:10 +01:00
Lion Kortlepel
f26ca6b40d add nlohmann/json
this will conflict with a change in the http branch, but i dont care
right now
2022-02-11 10:19:10 +01:00
Lion Kortlepel
17c571811a Add config option to turn off chat logging
When LogChat is disabled, using the `say` command in the console will
trigger a "chat message sent!" reply, as UX feedback.
2022-02-06 21:46:51 +01:00
Lion
b72de4bd0a Merge pull request #82 from BeamMP/rc-v3.0.1
Release Candidate v3.0.1
2022-02-04 04:37:09 +01:00
Lion Kortlepel
fdb7c9ce71 update version to 3.1.0 2022-02-03 19:57:25 +01:00
Lion Kortlepel
c391abcc93 Merge branch 'rc-v3.0.1' into rc-v3.1.0 2022-02-03 19:56:33 +01:00
Lion Kortlepel
144ccf14ec Add AddResultToCheck 2022-02-03 19:52:19 +01:00
Lion Kortlepel
40b23cbbe6 update changelog 2022-02-03 19:52:19 +01:00
Lion Kortlepel
7b458e3e27 Use yield() where possible
Replaced calls of this_thread::sleep_* with this_thread::yield(), which
yields the thread to the OS' scheduler.
2022-02-03 19:52:18 +01:00
Lion Kortlepel
69656f95db Move commandline initialization after cwd setting
This fixes an issue where the log file is written to the original
directory, even if --working-directory=path was used. This can obviously
be pretty bad.
2022-02-03 19:51:59 +01:00
Lion Kortlepel
0f5c476d09 update libraries 2022-02-03 19:51:59 +01:00
Lion Kortlepel
86b6aed350 UpdateCheck: Try all URLs 2022-02-03 19:51:59 +01:00
Lion Kortlepel
81780294f8 advance to 3.0.1 2022-02-03 19:51:59 +01:00
Lion Kortlepel
7c1fb12625 add api-v header to heartbeat post 2022-02-03 19:51:59 +01:00
Lion Kortlepel
9f892af997 start fixing backend heartbeat 2022-02-03 19:51:59 +01:00
Lion Kortlepel
9494bc70fb fix changelog 2022-02-03 19:46:31 +01:00
Lion Kortlepel
5c44a307bc update changelog 2022-02-03 19:03:21 +01:00
Lion Kortlepel
754053e73f Use yield() where possible
Replaced calls of this_thread::sleep_* with this_thread::yield(), which
yields the thread to the OS' scheduler.
2022-02-03 18:57:52 +01:00
Lion Kortlepel
29f8d29e33 Move commandline initialization after cwd setting
This fixes an issue where the log file is written to the original
directory, even if --working-directory=path was used. This can obviously
be pretty bad.
2022-02-03 18:31:18 +01:00
Lion Kortlepel
e043361abb update libraries 2022-02-03 18:30:00 +01:00
Lion Kortlepel
fd12ee672d Add various debug functions 2022-01-26 20:33:12 +01:00
Lion Kortlepel
fca5bbcec9 UpdateCheck: Try all URLs 2022-01-21 14:26:42 +01:00
Lion Kortlepel
2a588954be advance to 3.0.1 2022-01-20 21:31:00 +01:00
Lion Kortlepel
cd4129e05d add api-v header to heartbeat post 2022-01-20 16:09:08 +01:00
Lion Kortlepel
c42c748b37 start fixing backend heartbeat 2022-01-20 15:46:13 +01:00
Lion
179b33a7ab Merge pull request #76 from BeamMP/patch-http-server-default
HTTP Server disabled by default
2021-12-23 14:28:33 +01:00
Lion Kortlepel
1b14206a3c HTTP Server disabled by default 2021-12-23 14:24:00 +01:00
Lion
0cf81cf3f4 Merge pull request #73 from BeamMP/lionkor-readme-patch
Patch README Dependency List, fix Changelog
2021-12-16 23:54:33 +01:00
Lion
801780bcb1 Update Changelog.md 2021-12-16 16:02:31 +01:00
Lion
84d52578e0 Merge pull request #75 from BeamMP/release-3-0-0-patch
Release v3.0.0 final patch
2021-12-15 18:26:08 +01:00
Lion Kortlepel
3555cec5fe Simplify fix for event argument bug 2021-12-13 13:48:18 +01:00
Lion Kortlepel
71efe30345 Bump to 3.0.0, possible fix for event argument bug 2021-12-13 13:22:58 +01:00
Lion
5df8aedf08 Update Changelog.md 2021-12-11 10:35:11 +01:00
Lion
c3ab4b729a Update README.md 2021-12-09 14:15:50 +01:00
Lion
464aa3b59f Update README.md 2021-12-09 14:13:05 +01:00
Lion
cfe63198c7 Merge pull request #50 from BeamMP/rewrite-lua
Rewrite Lua + New Lua Features + New Console + Commandline Args
2021-12-09 13:04:48 +01:00
Lion Kortlepel
435d73f0c1 Remove message thing from master, reimplement this later 2021-12-09 12:09:55 +01:00
Lion Kortlepel
a5c23f8dde Add ping packet support 2021-12-09 12:08:41 +01:00
Lion
6c5b2cbeb5 Merge branch 'master' into rewrite-lua 2021-12-09 12:04:33 +01:00
Lion Kortlepel
ca5b3956a1 Http: Dont generate ssl key/cert with ssl off, reinterpret_cast for
windows
2021-12-08 17:39:13 +01:00
Lion Kortlepel
924e18c163 Remove /status placeholder 2021-12-08 17:39:13 +01:00
Rouven Himmelstein
bbe92dfa0f fix: broken .gitmodules file 2021-12-08 17:35:29 +01:00
Lion Kortlepel
a19943c96d Example impl for /status 2021-12-07 15:34:01 +01:00
Lion Kortlepel
cd19ae0836 Add shutting down / shutdown states to state keeper 2021-12-07 14:25:04 +01:00
Lion Kortlepel
3ee83904a1 Windows rewrite when
jfc since when is `c_str()` not convertible to `const char*`?
2021-12-06 15:13:55 +01:00
Lion Kortlepel
fe652cbf42 Fix server paths 2021-12-06 15:08:01 +01:00
Lion Kortlepel
2c115a2b2c Fix GCC pragma to not appear on windows 2021-12-06 15:04:28 +01:00
Lion Kortlepel
1172420b77 Add https to changelog 2021-12-06 14:21:25 +01:00
Lion Kortlepel
92d9857902 Re-add commandline
Bruh @jimkoen
2021-12-06 14:16:40 +01:00
Lion Kortlepel
816d3d5df8 Re-add split history (?) 2021-12-06 14:12:54 +01:00
Lion Kortlepel
817a146699 Add state id to lua prompt 2021-12-06 13:57:40 +01:00
Lion Kortlepel
3cce875fbb Add UseSSL option to server config 2021-12-06 13:47:07 +01:00
Lion Kortlepel
a1335e8c7d Add statuses, status messages 2021-12-06 13:17:54 +01:00
Lion Kortlepel
0f74eca2ee Fix various issues and crashes 2021-12-06 12:28:52 +01:00
Lion Kortlepel
279c93179c Fix segfault in http 2021-12-06 10:22:52 +01:00
Lion Kortlepel
62cc1e9ce4 Http: Add config value to turn it off, move all http settings into a category in the config 2021-12-06 09:53:13 +01:00
Lion Kortlepel
bd41382233 Application::TSettings: Improve default initialisation 2021-12-06 09:00:57 +01:00
awesome_milou
9d283738aa Add preliminary work for HTTP health endpoint (#68)
* Add preliminary work for HTTP health endpoint

* Http: Fix infinite loop bug in Tx509KeypairGenerator::generateKey()

* update commandline

* Add TLS Support class for use with http server

* Add preliminary HTTP Server; TLS still broken; fix in later commit

* Fix TLS handshake, due to server being unable to serve key/certfile in 'Http.h/Http.cpp'; Cause was httlib not being threadsafe due to being a blocking http library

* Run clang format

* Add option to configure http server port via ServerConfig

* TConfig: add HTTPServerPort to config parsing step

* Fix SSL Cert / Key path not auto generating when not existing

* Add health endpoint; Fix SSL Cert serial no. not refreshing when regenerating

* Switch arround status codes in /health route

* Run clang format

Co-authored-by: Lion Kortlepel <development@kortlepel.com>
2021-12-05 18:24:55 +01:00
Lion Kortlepel
b33d50361c fix typo in --help 2021-12-05 01:40:39 +01:00
Lion Kortlepel
479bb9f931 TLuaEngine: Make WaitForAll timeout optional 2021-12-05 01:32:15 +01:00
Lion Kortlepel
672c7d02d1 Common: Add lua warn 2021-12-05 01:31:44 +01:00
Lion Kortlepel
a289d0e872 Add timeout to WaitForAll 2021-12-05 01:09:41 +01:00
Lion Kortlepel
86169ad0fa TConsole: Add notice about help command on wrong command 2021-12-05 00:55:42 +01:00
Lion Kortlepel
f477570a1c Add changelog about new console 2021-12-05 00:54:24 +01:00
Lion Kortlepel
7b99ccb08e Add --working-directory flag 2021-12-05 00:42:50 +01:00
Lion Kortlepel
265dd710cf add status command 2021-12-02 01:25:17 +01:00
Lion Kortlepel
eb67f483b2 Another possible fix for deadlock 2021-11-29 03:07:20 +01:00
Lion Kortlepel
98c7fea139 Possible fix for event handler timeouts 2021-11-29 02:56:41 +01:00
Lion Kortlepel
ccdc5dae17 update commandline 2021-11-29 02:09:05 +01:00
Lion Kortlepel
1bc9a5293e Add kick response 2021-11-29 02:03:20 +01:00
Lion Kortlepel
c3151093e2 CMake: remove __linux completely 2021-11-29 01:42:23 +01:00
Lion Kortlepel
8f77f1c8c0 Add kick, fix cmakelists pretending to be on linux all the time
lol
2021-11-29 01:34:35 +01:00
Lion Kortlepel
19d67dee95 Add GetPlayerIDByName, kick, say 2021-11-29 01:14:37 +01:00
Lion Kortlepel
fc440bea2a Add ability to switch into other lua states 2021-11-29 00:37:00 +01:00
Lion Kortlepel
c91f3ee33c Print entering and leaving lua as raw 2021-11-29 00:17:09 +01:00
Lion Kortlepel
297b646d33 update commandline 2021-11-29 00:17:03 +01:00
Lion Kortlepel
768d0466f4 Add simple command interface 2021-11-28 23:45:03 +01:00
Lion Kortlepel
1e0ab6bbb3 Update commandline 2021-11-28 23:44:56 +01:00
Lion Kortlepel
472ec3390c Update changelog 2021-11-27 12:25:31 +01:00
Lion Kortlepel
a4123d7d7c Remove --ip example 2021-11-27 03:28:35 +01:00
Lion Kortlepel
6fd54f7907 Fix server message printing bug
There was a space missing
2021-11-27 02:31:21 +01:00
Lion Kortlepel
fd7bea0f36 Add BEAMMP_{WINDOWS,LINUX,APPLE} preprocessor defines instead of platform specific ones 2021-11-27 02:11:22 +01:00
Lion Kortlepel
9d2d4bb221 Remove --ip
This should be re-added later as a ServerConfig value
2021-11-26 19:08:05 +01:00
Lion Kortlepel
e1756298af Fix doubled consent settings in ServerConfig 2021-11-26 19:07:08 +01:00
Lion Kortlepel
eae27633db Add commandline arguments, implement --config, --version, --help 2021-11-26 19:04:21 +01:00
Lion Kortlepel
938774618c Fix apple + linux compatibility 2021-11-26 13:25:09 +01:00
Lucca Jiménez Könings
1a2a123d87 Fix various macOS compatibility issues 2021-11-25 02:01:44 +01:00
Lucca Jiménez Könings
6247061d09 Replace gettid() call with POSIX compliant getpid() call in 'Common.cpp' 2021-11-25 02:01:44 +01:00
Lucca Jiménez Könings
08a62261e7 Add temporary cmake mods to make project compile on macOS, add ifdefs in 'Compat.h' for target darwin 2021-11-25 02:01:44 +01:00
Lion Kortlepel
a7db41ebaa write thread ids to file 2021-11-21 03:31:35 +01:00
Lion Kortlepel
66d4e34a75 print always 2021-11-21 03:29:22 +01:00
Lion Kortlepel
7169e65305 clarify thread names 2021-11-21 03:19:02 +01:00
Lion Kortlepel
097e52674b update commandline 2021-11-21 03:04:50 +01:00
Lion Kortlepel
1ec47252f2 update commandline 2021-11-21 02:31:52 +01:00
Lion Kortlepel
2ddac7f138 update commandline 2021-11-21 02:26:02 +01:00
Lion Kortlepel
cf08dee84f Common: Make TID work on Windows 2021-11-19 13:12:27 +01:00
Lion Kortlepel
f1148ed1c4 LuaAPI: Show quotes around strings in table dumps (#60) 2021-11-19 13:03:27 +01:00
Lion Kortlepel
b6fa3574fd RegisterThread: Add TID print (#63) 2021-11-19 12:46:43 +01:00
Lion Kortlepel
7079e80b71 Lua: Remove leading space in onChatMessage (fix #35) 2021-11-19 12:43:27 +01:00
Lion Kortlepel
48b9aa72dc update commandline 2021-11-10 00:38:03 +01:00
Lion Kortlepel
c36ea52f60 Http: Use ipv4 2021-11-08 23:45:35 +01:00
Lion Kortlepel
87f23427a1 CMake: Nail down lua to be 5.3 2021-11-08 23:13:47 +01:00
Lion Kortlepel
7197c23632 TNetwork: Possible ip address fix 2021-11-08 23:10:24 +01:00
Lion Kortlepel
b5ea084c9b update commandline 2021-11-08 22:25:23 +01:00
Lion Kortlepel
f8af134dc9 start writing http lua stuff, also heartbeat debug printing 2021-11-08 22:08:07 +01:00
Lion Kortlepel
3e7aa763ed fix release build 2021-11-08 00:01:41 +01:00
Lion Kortlepel
5fdd7beac8 remove stray zip.h include 2021-11-07 23:56:22 +01:00
Lion Kortlepel
701a7feee3 remove boost, add httplib, temporarily remove http* lua 2021-11-07 23:54:33 +01:00
Lion Kortlepel
1e305c3c90 Http: cleanup 2021-11-07 23:09:06 +01:00
Lion Kortlepel
9f5fa8fb9b Remove libzip 2021-11-06 13:03:20 +01:00
Lion Kortlepel
fdc205f521 Add ScopedTimer, Remove some comments 2021-10-31 01:27:21 +02:00
Lion
a18abd6c8b Update README.md 2021-10-27 18:33:50 +01:00
Lion
1b2ea88a71 README: add irc and discord links 2021-10-27 18:33:50 +01:00
Lion Kortlepel
50589fbe3d send 'Om' to self 2021-10-26 17:39:59 +02:00
Lion Kortlepel
7287fce341 possible actions fix
thank you, anon!
2021-10-26 02:22:03 +02:00
Lion Kortlepel
6de625682d fix compiler error, empty content_type does nothing now 2021-10-26 02:12:17 +02:00
Lion Kortlepel
6189aed6e7 broadcast Om packets 2021-10-26 02:08:02 +02:00
Lion Kortlepel
c4d6aab08b fix MP.HttpGET (was not passing contentType) 2021-10-08 08:44:20 +02:00
Lion Kortlepel
577d4c429d TNetwork: Use 'K' packet instead of 'E' to kick players 2021-10-02 01:44:13 +02:00
Lion Kortlepel
d027f7f29f Lua: Kick properly (with ClientKick), add chat message printing 2021-10-02 01:28:58 +02:00
Lion Kortlepel
af14188ec0 remove spammy debug 2021-10-01 04:22:33 +02:00
Lion Kortlepel
1ee45c9d1a Ignore BEAMMP_FN_NOT_FOUND errors 2021-10-01 04:09:40 +02:00
Lion Kortlepel
d1f890752a Report errors on WaitForAll 2021-10-01 03:56:18 +02:00
Lion Kortlepel
9eabd19e17 Report more errors, better 2021-10-01 03:52:12 +02:00
Lion Kortlepel
ae7a63669f detect recursion in LuaToString 2021-10-01 03:35:13 +02:00
Lion Kortlepel
243e96d503 Check all futures 2021-10-01 03:27:24 +02:00
Lion Kortlepel
932fbe2b2f reintroduce waiting for results 2021-10-01 03:01:28 +02:00
Lion Kortlepel
26ec50b199 Build libzip statically 2021-10-01 02:31:48 +02:00
Lion Kortlepel
87ecc3f9f6 fix readme invalid cmake invocation, show ms in debug output 2021-10-01 02:03:11 +02:00
Lion Kortlepel
7f1d37a0e6 Fix libzip 2021-10-01 01:57:29 +02:00
Lion Kortlepel
255feb4f8e CMake: Fix minor mistake in cmakelists 2021-10-01 01:52:13 +02:00
Lion Kortlepel
013ca14ab8 add libzip module path 2021-10-01 01:51:22 +02:00
Lion Kortlepel
e7f29ce04f Fix server event timing 2021-10-01 01:40:37 +02:00
Lion Kortlepel
e948edca8d Add zip files with past logs 2021-09-30 23:24:23 +02:00
Lion Kortlepel
d0431c0b9d Use v2 api 2021-09-27 15:46:37 +02:00
Lion Kortlepel
0961f86662 Add heartbeat-api-v API version header 2021-09-27 15:46:37 +02:00
Lion Kortlepel
7f2ca025f8 Start using new heartbeat response format 2021-09-27 15:46:37 +02:00
Lion Kortlepel
33ebfa82f0 Remove spammy TRACE 2021-09-22 21:08:01 +02:00
Lion Kortlepel
9d0caf2c7d Lua: Implement Hot-Reload 2021-09-21 16:21:09 +02:00
Lion Kortlepel
fe3ccafc1d Lua: Add various FS functions 2021-09-21 00:27:09 +02:00
Lion Kortlepel
23ffa25d78 Lua: Add FS.GetParentFolder 2021-09-20 23:44:17 +02:00
Lion Kortlepel
908f67a799 Fix compile error 2021-09-20 23:40:28 +02:00
Lion Kortlepel
27b5c6d850 Add GetFilename, GetExtension, 2021-09-20 22:45:12 +02:00
Lion Kortlepel
32756ccc4a Use read instead of ifstream rdbuf 2021-09-20 17:19:38 +02:00
Lion Kortlepel
3626f4108e Use filestreams instead of c-lib 2021-09-20 17:05:28 +02:00
Lion Kortlepel
d7a4322313 More windows fixes 2021-09-20 17:00:30 +02:00
Lion Kortlepel
d84051bdd3 possible fix for windows path issue 2021-09-20 16:59:42 +02:00
Lion Kortlepel
238577a4f7 Remove debug symbols 2021-09-20 16:36:37 +02:00
Lion Kortlepel
041db23a69 Lua: info,debug -> trace 2021-09-20 16:23:38 +02:00
Lion Kortlepel
a3a18a3b56 Lua: Add CancelEventTimer 2021-09-20 16:09:17 +02:00
Lion Kortlepel
9efe352e7a Lua: Working MP.CreateEventTimer 2021-09-20 15:41:40 +03:00
Lion Kortlepel
3edb9322d4 Lua: Simple CreateEventTimer improvements 2021-09-20 13:39:14 +03:00
Lion Kortlepel
4bf89706b4 Lua: Add MP.CreateTimedEvent as CreateThread replacement 2021-09-20 12:43:00 +03:00
Lion Kortlepel
a97791d4ee Please MSVC stop being so bad 2021-09-20 00:46:13 +02:00
Lion Kortlepel
323184911d Add new FS functions to Changelog 2021-09-20 00:39:12 +02:00
Lion Kortlepel
6f9f790c5b Lua: Add FS.Remove, FS.Rename (move), FS.Copy, FS.Exists 2021-09-20 00:36:22 +02:00
Lion Kortlepel
4de80e0c7a Lua: Remove debug prints, add GetLuaMemoryUsage 2021-09-19 23:55:24 +02:00
Lion Kortlepel
366a7dc9a6 Lua: Add Lua panic handler 2021-09-19 23:34:27 +02:00
Lion Kortlepel
785b858651 Same as last one
yikes.
2021-09-19 12:29:02 +02:00
Lion Kortlepel
a4ff9488c5 Satisfy MSVC's weird attraction to using .string() when its not necessary
I cannot bear another minute of msvc, i swear
2021-09-19 12:23:26 +02:00
Lion Kortlepel
60b86e2be6 Create TLuaChunk constructor to satisfy MSVC 2021-09-19 12:12:38 +02:00
Lion Kortlepel
701e613990 Lua: Fix float printing
Now prints 0, not 0.000000, etc.
2021-09-19 12:10:38 +02:00
Lion Kortlepel
7dbf859529 Lua: Implement event arguments 2021-09-19 11:45:58 +02:00
Lion Kortlepel
8419ca2234 possible windows compiler fix 2021-09-19 01:32:30 +02:00
Lion Kortlepel
7f63dd8d7d Lua: Add FS, FS.CreateDirectory 2021-09-19 01:30:59 +02:00
Lion Kortlepel
da78d77e6c Changelog: add MP.PrintRaw 2021-09-19 01:21:30 +02:00
Lion Kortlepel
1ff5107707 Lua: Add MP.PrintRaw 2021-09-19 01:20:17 +02:00
Lion Kortlepel
dd70e88e4c SignalHandling: ensure that a signal handler is present on compilation 2021-09-18 22:08:20 +02:00
Lion Kortlepel
38dffc5462 Lua: Pass plugin path and filename to queue for later 2021-09-18 01:20:26 +02:00
Lion Kortlepel
f98ef7d41c Lua: Call local eventhandlers synchronously when TriggerGlobalEvent is called from inside a handling state 2021-09-18 00:05:51 +02:00
Lion Kortlepel
29a858e74a Network: Fix TConnection related compiler issue 2021-09-17 15:33:16 +02:00
Lion Kortlepel
e53f2d9877 Changelog: Add MP.Https* documentation 2021-09-17 15:32:01 +02:00
Lion Kortlepel
be3ac45abb add MP.HttpsGET, MP.HttpsPOST 2021-09-17 15:30:30 +02:00
Lion Kortlepel
246f8289b6 CMake: Fix compiler error with mismatching visibility of target_link_libraries 2021-09-17 15:22:06 +02:00
Lion Kortlepel
3c7109b23f Update Changelog, fix assert formatting 2021-09-17 15:21:06 +02:00
Lion Kortlepel
82a5fc3999 Assert: Fix compiler error 2021-09-17 15:06:13 +02:00
Lion Kortlepel
11d4d9ff91 remove old commandline path 2021-09-17 15:02:53 +02:00
Lion Kortlepel
48caae25fd Finalize master&new-lua-features merge 2021-09-17 14:58:40 +02:00
Lion Kortlepel
9dfe9f659a Update cmakelists to remove socket.io 2021-09-17 14:30:33 +02:00
Lion Kortlepel
a07b5062de Reintroduce gitmodules 2021-09-17 14:28:45 +02:00
Lion Kortlepel
fcbb188ee0 update modules, cmakelists 2021-09-17 14:25:11 +02:00
Lion Kortlepel
883d69ba27 Merge remote-tracking branch 'origin/master' into rewrite-lua 2021-09-17 14:24:12 +02:00
Lion Kortlepel
7459779363 update cmakelists 2021-09-17 14:21:20 +02:00
Lion Kortlepel
a0c47d9947 move sentry-native 2021-09-17 14:17:27 +02:00
Lion Kortlepel
7db345cfbc update submodules 2021-09-17 13:36:16 +02:00
Lion Kortlepel
1d3958817f Merge remote-tracking branch 'origin/new-lua-features' into rewrite-lua
This is the first of a few commits to merge the new lua features and the
rewrite
2021-09-17 13:29:44 +02:00
Lion Kortlepel
fd3088c78f Re-add SendChatMessage 2021-09-17 12:58:07 +02:00
Lion Kortlepel
c2b73d93b5 Lua: Implement more core functions 2021-09-17 12:56:08 +02:00
Lion Kortlepel
9a37ed4341 Lua: Add GetPlayerName 2021-09-17 12:45:34 +02:00
Lion Kortlepel
e64114e4fa Possible compiler fix 2021-09-17 02:44:49 +02:00
Lion Kortlepel
79531334dd another nice fix 2021-09-17 02:38:14 +02:00
Lion Kortlepel
ed6f5282d9 Nice fix. 2021-09-17 02:36:06 +02:00
Lion Kortlepel
62fd369625 Lua: Fix more compile errors for windows 2021-09-17 02:30:20 +02:00
Lion Kortlepel
1880536276 Lua: Call onInit properly 2021-09-17 02:26:49 +02:00
Lion Kortlepel
bac476ec34 Lua: Set package.path and package.cpath before onInit is called 2021-09-17 02:19:45 +02:00
Lion Kortlepel
e75e65815c Lua: change a static_cast to a reinterpret_cast, fun times
:^)
2021-09-17 01:27:45 +02:00
Lion Kortlepel
b0c467f971 Lua: Add timer 2021-09-17 01:25:52 +02:00
Lion Kortlepel
6b17990d4d Add GetOSTimeMS 2021-09-17 00:57:43 +02:00
Lion Kortlepel
c73d56c143 Possible compiler fix 2021-09-17 00:54:41 +02:00
Lion Kortlepel
a44050f0f1 Lua: Almost Working events, all triggers working 2021-09-17 00:21:43 +02:00
Lion Kortlepel
cb1eb40def Lua: remove unimplemented 2021-09-16 22:31:54 +02:00
Lion Kortlepel
4c03a90157 Lua: Add more old API 2021-09-16 22:31:09 +02:00
Lion Kortlepel
be61511bdf Fix CMake, Add more Lua API 2021-09-16 19:38:31 +02:00
Lion Kortlepel
968d9ff999 Lua: Implement most API functions 2021-09-16 19:00:13 +02:00
Lion Kortlepel
1c80a4deb7 Lua: working events, global and local 2021-09-16 18:14:11 +02:00
Lion Kortlepel
e602decb96 Lua: Fix multiple issues with events 2021-09-16 14:58:47 +02:00
Lion Kortlepel
dca573b15c Fix more compile issues with lua, add TriggerGlobalEvent 2021-09-16 13:06:04 +02:00
Lion Kortlepel
26231c6272 Fix compile issue with asio, implement Lua events 2021-09-16 13:03:00 +02:00
Lion Kortlepel
ebe3630ec8 LuaAPI: Implement GetOSName 2021-09-16 12:22:49 +02:00
Lion Kortlepel
d7f7a81cb0 LuaAPI: Print: dump tables properly and recursively 2021-09-16 12:21:11 +02:00
Lion Kortlepel
9ef6c32864 CMake: fix include paths 2021-09-16 11:59:00 +02:00
Lion Kortlepel
9b9c18a4c1 Lua: Add variadic print, LuaAPI 2021-09-16 11:54:52 +02:00
Lion Kortlepel
5978665ad6 Lua: Fix threading related crash 2021-09-16 10:07:04 +02:00
Lion Kortlepel
2cf368c2b0 First working console 2021-09-16 03:40:24 +02:00
Lion Kortlepel
ba0678dade Continue Lua Rewrite 2021-09-16 03:21:00 +02:00
Lion Kortlepel
c309fa28c6 update sol2 to v3.2.3 2021-09-16 01:09:24 +02:00
Lion Kortlepel
f5b2be0a03 rename Assert to beammp_assert 2021-09-16 01:04:38 +02:00
Lion Kortlepel
dd4e4c4467 Start rewrite of lua, rename all print functions 2021-09-16 01:04:01 +02:00
Lion Kortlepel
d082620525 add sol2 2021-09-16 00:34:09 +02:00
Lion Kortlepel
be90a8a2c0 add sol2 2021-09-16 00:33:13 +02:00
Lion Kortlepel
8b69127cdd Finish moving deps to deps/ 2021-09-16 00:22:33 +02:00
Lion Kortlepel
bb34378b8e Move all dependencies to deps/ 2021-09-16 00:09:39 +02:00
Lion Kortlepel
588242822c CMake: Remove socketio link, forgot 2021-09-09 12:33:59 +03:00
Lion Kortlepel
58da200901 Client: fix socklen_t compile error 2021-09-09 12:32:33 +03:00
Lion Kortlepel
f4ccf6c177 add sentry native db folder to gitignore 2021-09-09 12:26:26 +03:00
Lion Kortlepel
27103a73a9 remove socket.io module 2021-09-09 12:26:03 +03:00
Lion Kortlepel
2727f90430 Remove Socket.io for now
it is being built every time and we dont need it
2021-09-09 12:25:08 +03:00
Lion Kortlepel
2a96546c8c Lua: Add GetPluginName, GetPluginPath 2021-09-09 12:15:57 +03:00
Lion Kortlepel
6462636b29 Multiple merge fixes, rebase, working Https::GET 2021-09-09 12:15:55 +03:00
Lion Kortlepel
5742ab0dad possible windows compiler fix 2021-09-09 12:15:19 +03:00
Lion Kortlepel
0087205d55 fix issues caused by rebase 2021-09-09 12:15:17 +03:00
Lion Kortlepel
d16843e45d TNetwork: clarify error messages 2021-09-09 12:14:32 +03:00
Lion Kortlepel
24516dbfd7 TNetwork: setsockopt: cast optval to void* 2021-09-09 12:14:32 +03:00
Lion Kortlepel
a311d58e11 TNetwork: reuseaddr instead of reuseport 2021-09-09 12:14:32 +03:00
Lion Kortlepel
1444d91e7e Common: missed semicolon 2021-09-09 12:14:32 +03:00
Lion Kortlepel
1e2f060107 improve error reporting, remove duplicate code 2021-09-09 12:14:32 +03:00
Lion Kortlepel
fdb5da2ed6 CMake: remove mentions of luasocket again 2021-09-09 12:14:32 +03:00
Lion Kortlepel
de57613326 remove luasocket-cmake 2021-09-09 12:14:32 +03:00
Lion Kortlepel
b49782e8a3 Common: Add sstream include for std::stringstream 2021-09-09 12:14:32 +03:00
Lion Kortlepel
ff80b4cf63 CMake: include luasocket after finding lua 2021-09-09 12:14:32 +03:00
Lion Kortlepel
4c23b78f84 add luasocket 2021-09-09 12:14:32 +03:00
Lion Kortlepel
aca3c52c20 remove luasocket again 2021-09-09 12:14:32 +03:00
Lion Kortlepel
51d6c4fb0a add CMakeLists for lib/ 2021-09-09 12:14:32 +03:00
Lion Kortlepel
2af9491fd6 add luasocket submodule 2021-09-09 12:14:32 +03:00
Lion Kortlepel
95c036836e add ws2tcpip.h 2021-09-09 12:14:32 +03:00
Lion Kortlepel
a7f2f85e45 fix version printing 2021-09-09 12:14:32 +03:00
Lion Kortlepel
42c5aaad5a use inet_ntop instead of inet_ntoa (STILL BROKEN THOUGH) 2021-09-09 12:14:32 +03:00
Lion Kortlepel
88684bd9af clarify installation 2021-09-09 12:14:32 +03:00
Lion Kortlepel
c6457f7df4 Add Settings enum, better print 2021-09-09 12:14:32 +03:00
Lion Kortlepel
ba3fd0e144 add GetServerVersion 2021-09-09 12:14:30 +03:00
Lion Kortlepel
e3b6fd7998 use fake version for lua update for now 2021-09-09 12:13:45 +03:00
Lion Kortlepel
943159cd40 Lua: add onShutdown 2021-09-09 12:13:37 +03:00
Lion Kortlepel
9423831937 add ip to identifiers, changed value format 2021-09-09 12:13:34 +03:00
Lion Kortlepel
95188042c5 fix luatable in GetPlayerIdentifiers 2021-09-09 12:12:54 +03:00
Lion Kortlepel
a0a7b8ecce fix comment 2021-09-09 12:12:54 +03:00
Lion Kortlepel
53617abae4 Add printRaw
Same as print() but does not prefix with time, date, filename, etc.
Use with care.
2021-09-09 12:12:54 +03:00
Lion Kortlepel
853b078124 add MP.HttpsGET, MP.HttpsPOST 2021-09-09 12:12:54 +03:00
Anonymous-275
549517c518 TODO edit 2021-09-09 12:12:54 +03:00
Anonymous-275
2be4b8fd91 Fully working lua_Register 2021-09-09 12:12:54 +03:00
Lion Kortlepel
2cfb27820a switch to toml11
it's better, believe me
2021-09-09 12:12:54 +03:00
Anonymous-275
1ff12cb2bf simpler lua_Register 2021-09-09 12:12:54 +03:00
Lion Kortlepel
518cb0664e rebase 2021-09-09 12:12:54 +03:00
Lion Kortlepel
80432eb718 implement GetOSName, start working on HttpsPOST 2021-09-09 12:12:54 +03:00
Anonymous-275
b1caf5c29a lua Register 2021-09-09 12:12:54 +03:00
Lion Kortlepel
950cee9fd0 README: fix git submodule update command 2021-09-09 12:12:54 +03:00
Lion Kortlepel
046097579e README: ensure that submodules are initialized recursively 2021-09-09 12:12:53 +03:00
Lion Kortlepel
35a3dab1ce TNetwork: clarify error messages 2021-08-07 23:51:56 +02:00
Lion Kortlepel
131ade02cd TNetwork: setsockopt: cast optval to void* 2021-08-02 14:23:20 +02:00
Lion Kortlepel
2c2f76b340 TNetwork: reuseaddr instead of reuseport 2021-08-02 14:15:30 +02:00
Lion Kortlepel
106d8e5863 Common: missed semicolon 2021-08-02 14:06:00 +02:00
Lion Kortlepel
1fb7cb6bc1 improve error reporting, remove duplicate code 2021-08-02 14:01:20 +02:00
Lion Kortlepel
9666fff622 CMake: remove mentions of luasocket again 2021-08-02 14:01:20 +02:00
Lion Kortlepel
5d5f155f0c remove luasocket-cmake 2021-08-02 14:01:20 +02:00
Lion Kortlepel
cfe348770c Common: Add sstream include for std::stringstream 2021-08-02 14:01:20 +02:00
Lion Kortlepel
206120dcef CMake: include luasocket after finding lua 2021-08-02 14:01:20 +02:00
Lion Kortlepel
2a3bb1bef8 add luasocket 2021-08-02 14:01:20 +02:00
Lion Kortlepel
0faa46d48c remove luasocket again 2021-08-02 14:01:20 +02:00
Lion Kortlepel
dae52a71fd add CMakeLists for lib/ 2021-08-02 14:01:20 +02:00
Lion Kortlepel
c46c36bf09 add luasocket submodule 2021-08-02 14:01:20 +02:00
Lion Kortlepel
ed3d0834e6 add ws2tcpip.h 2021-08-02 14:01:20 +02:00
Lion Kortlepel
9d4c6e880b fix version printing 2021-08-02 14:01:20 +02:00
Lion Kortlepel
d39b5d7c77 use inet_ntop instead of inet_ntoa (STILL BROKEN THOUGH) 2021-08-02 14:01:20 +02:00
Lion Kortlepel
b071906db5 clarify installation 2021-08-02 14:01:20 +02:00
Lion Kortlepel
8420cdb5bf Add Settings enum, better print 2021-08-02 14:01:20 +02:00
Lion Kortlepel
e11211f201 add GetServerVersion 2021-08-02 14:01:20 +02:00
Lion Kortlepel
9595ef164e use fake version for lua update for now 2021-08-02 14:01:17 +02:00
Lion Kortlepel
d18afdf84b Lua: add onShutdown 2021-08-02 14:01:01 +02:00
Lion Kortlepel
0acbb70d10 add ip to identifiers, changed value format 2021-08-02 14:01:01 +02:00
Lion Kortlepel
7a3848e640 fix luatable in GetPlayerIdentifiers 2021-08-02 14:01:01 +02:00
Lion Kortlepel
261aa8f320 fix comment 2021-08-02 14:01:01 +02:00
Lion Kortlepel
e994cdd8a2 Add printRaw
Same as print() but does not prefix with time, date, filename, etc.
Use with care.
2021-08-02 14:01:01 +02:00
Lion Kortlepel
44e0f3aa21 add MP.HttpsGET, MP.HttpsPOST 2021-08-02 14:01:00 +02:00
Anonymous-275
8853cef809 TODO edit 2021-08-02 14:01:00 +02:00
Anonymous-275
fb76b8309a Fully working lua_Register 2021-08-02 14:01:00 +02:00
Lion Kortlepel
a23946dddf switch to toml11
it's better, believe me
2021-08-02 14:01:00 +02:00
Anonymous-275
55ee1d3747 simpler lua_Register 2021-08-02 14:01:00 +02:00
Lion Kortlepel
4cd0093687 rebase 2021-08-02 14:01:00 +02:00
Lion Kortlepel
cc88734279 implement GetOSName, start working on HttpsPOST 2021-08-02 14:01:00 +02:00
Anonymous-275
a865c95e2a lua Register 2021-08-02 14:01:00 +02:00
128 changed files with 9170 additions and 4901 deletions

1
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1 @@
patreon: BeamMP

View File

@@ -1,7 +1,6 @@
---
name: Bug report
about: Create a report to help us improve
title: "[Bug] Enter issue title here"
labels: bug
assignees: ''

View File

@@ -1,8 +1,7 @@
---
name: Feature request
about: Suggest an idea for this project
title: "[Feature Request]"
labels: enhancement
labels: feature
assignees: ''
---

View File

@@ -1,46 +0,0 @@
name: CMake Linux Build
on: [push]
env:
BUILD_TYPE: Release
jobs:
linux-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Install Dependencies
env:
beammp_sentry_url: ${{ secrets.BEAMMP_SECRET_SENTRY_URL }}
run: |
echo ${#beammp_sentry_url}
sudo apt-get update
sudo apt-get install -y libz-dev rapidjson-dev liblua5.3 libssl-dev libwebsocketpp-dev libcurl4-openssl-dev
sudo add-apt-repository ppa:mhier/libboost-latest
sudo apt-get install -y libboost1.70-dev libboost1.70
- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/build-linux
- name: Configure CMake
shell: bash
working-directory: ${{github.workspace}}/build-linux
env:
beammp_sentry_url: ${{ secrets.BEAMMP_SECRET_SENTRY_URL }}
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_CXX_COMPILER=g++-10 -DBEAMMP_SECRET_SENTRY_URL="$beammp_sentry_url"
- name: Build
working-directory: ${{github.workspace}}/build-linux
shell: bash
run: cmake --build . --config $BUILD_TYPE
- name: Archive artifacts
uses: actions/upload-artifact@v2
with:
name: BeamMP-Server-linux
path: ${{github.workspace}}/build-linux/BeamMP-Server

View File

@@ -1,53 +0,0 @@
name: CMake Windows Build
on: [push]
env:
BUILD_TYPE: RelWithDebInfo
jobs:
windows-build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Restore artifacts, or run vcpkg, build and cache artifacts
uses: lukka/run-vcpkg@main
id: runvcpkg
with:
vcpkgArguments: 'lua zlib rapidjson boost-beast boost-asio openssl websocketpp curl'
vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
vcpkgGitCommitId: '8dddc6c899ce6fdbeab38b525a31e7f23cb2d5bb'
vcpkgTriplet: 'x64-windows-static'
- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/build-windows
- name: Configure CMake
shell: bash
working-directory: ${{github.workspace}}/build-windows
env:
beammp_sentry_url: ${{ secrets.BEAMMP_SECRET_SENTRY_URL }}
run: cmake $GITHUB_WORKSPACE -DSENTRY_BACKEND=breakpad -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE='${{ runner.workspace }}/b/vcpkg/scripts/buildsystems/vcpkg.cmake' -DVCPKG_TARGET_TRIPLET=x64-windows-static -DBEAMMP_SECRET_SENTRY_URL="$beammp_sentry_url"
- name: Build
working-directory: ${{github.workspace}}/build-windows
shell: bash
run: cmake --build . --config $BUILD_TYPE
- name: Archive artifacts
uses: actions/upload-artifact@v2
with:
name: BeamMP-Server.exe
path: ${{github.workspace}}/build-windows/RelWithDebInfo/BeamMP-Server.exe
- name: Archive artifacts
uses: actions/upload-artifact@v2
with:
name: BeamMP-Server.pdb
path: ${{github.workspace}}/build-windows/RelWithDebInfo/BeamMP-Server.pdb

152
.github/workflows/linux.yml vendored Normal file
View File

@@ -0,0 +1,152 @@
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:
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: ${{ 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:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Install git
run: |
apt-get update -y
apt-get install -y git
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Git config safe directory
shell: bash
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/1.5-git-safe.sh
- name: Install Dependencies
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/1-install-deps.sh
- name: Create Build Environment
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/2-configure.sh '-DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake'
- name: Build Server
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/3-build.sh
- name: Archive server artifact
uses: actions/upload-artifact@v2
with:
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: debuginfo.${{ matrix.distro }}.${{ matrix.version }}.x86_64
path: ./bin/BeamMP-Server.debug
- name: Build Tests
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/3-build-tests.sh
- name: Install Runtime Dependencies
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/4-install-runtime-deps.sh
- name: Test
run: ./bin/BeamMP-Server-tests
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: ${{ 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:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Install git
run: |
apt-get update -y
apt-get install -y git
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Git config safe directory
shell: bash
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/1.5-git-safe.sh
- name: Install Dependencies
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/1-install-deps.sh
- name: Create Build Environment
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/2-configure.sh '-DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake'
- name: Build Server
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/3-build.sh
- name: Archive server artifact
uses: actions/upload-artifact@v2
with:
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: debuginfo.${{ matrix.distro }}.${{ matrix.version }}.arm64
path: ./bin/BeamMP-Server.debug
- name: Build Tests
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/3-build-tests.sh
- name: Install Runtime Dependencies
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/4-install-runtime-deps.sh
- name: Test
run: ./bin/BeamMP-Server-tests

View File

@@ -1,117 +0,0 @@
name: Release Create & Build
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
env:
BUILD_TYPE: Release
jobs:
create-release:
runs-on: ubuntu-latest
name: Create Release
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: true
body: |
Files included in this release:
- `BeamMP-Server.exe` is the windows build
- `BeamMP-Server-linux` is a ubuntu build, so you need the dependencies listed in README.md to run it. For any other distros please build from source as described in README.md.
upload-release-files-linux:
name: Upload Linux Release Files
runs-on: ubuntu-latest
needs: create-release
steps:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y libz-dev rapidjson-dev liblua5.3 libssl-dev libwebsocketpp-dev libcurl4-openssl-dev
sudo add-apt-repository ppa:mhier/libboost-latest
sudo apt-get install -y libboost1.70-dev libboost1.70
- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/build-linux
- name: Configure CMake
shell: bash
working-directory: ${{github.workspace}}/build-linux
env:
beammp_sentry_url: ${{ secrets.BEAMMP_SECRET_SENTRY_URL }}
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_CXX_COMPILER=g++-10 -DBEAMMP_SECRET_SENTRY_URL="$beammp_sentry_url"
- name: Build
working-directory: ${{github.workspace}}/build-linux
shell: bash
run: cmake --build . --config $BUILD_TYPE
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ${{github.workspace}}/build-linux/BeamMP-Server
asset_name: BeamMP-Server-linux
asset_content_type: application/x-elf
upload-release-files-windows:
name: Upload Windows Release Files
runs-on: windows-latest
needs: create-release
steps:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Restore artifacts, or run vcpkg, build and cache artifacts
uses: lukka/run-vcpkg@main
id: runvcpkg
with:
vcpkgArguments: 'lua zlib rapidjson boost-beast boost-asio openssl websocketpp curl'
vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
vcpkgGitCommitId: '8dddc6c899ce6fdbeab38b525a31e7f23cb2d5bb'
vcpkgTriplet: 'x64-windows-static'
- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/build-windows
- name: Configure CMake
shell: bash
working-directory: ${{github.workspace}}/build-windows
env:
beammp_sentry_url: ${{ secrets.BEAMMP_SECRET_SENTRY_URL }}
run: cmake $GITHUB_WORKSPACE -DSENTRY_BACKEND=breakpad -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_TOOLCHAIN_FILE='${{ runner.workspace }}/b/vcpkg/scripts/buildsystems/vcpkg.cmake' -DVCPKG_TARGET_TRIPLET=x64-windows-static -DBEAMMP_SECRET_SENTRY_URL="$beammp_sentry_url"
- name: Build
working-directory: ${{github.workspace}}/build-windows
shell: bash
run: cmake --build . --config $BUILD_TYPE
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ${{github.workspace}}/build-windows/Release/BeamMP-Server.exe
asset_name: BeamMP-Server.exe
asset_content_type: application/vnd.microsoft.portable-executable

215
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,215 @@
name: Release Create & Build
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
CMAKE_BUILD_TYPE: "Release"
DEBIAN_FRONTEND: "noninteractive"
jobs:
create-release:
runs-on: ubuntu-latest
name: Create Release
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: true
body: |
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.
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: ${{ 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:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Install git
run: |
apt-get update -y
apt-get install -y git
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Git config safe directory
shell: bash
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/1.5-git-safe.sh
- name: Install Dependencies
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/1-install-deps.sh
- name: Create Build Environment
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/2-configure.sh '-DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake'
- name: Build Server
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/3-build.sh
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
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_content_type: application/x-elf
- name: Upload Debug Info
id: upload-debug-info
uses: actions/upload-release-asset@v1
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_content_type: application/x-elf
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: ${{ 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:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Install git
run: |
apt-get update -y
apt-get install -y git
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Git config safe directory
shell: bash
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/1.5-git-safe.sh
- name: Install Dependencies
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/1-install-deps.sh
- name: Create Build Environment
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/2-configure.sh '-DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake'
- name: Build Server
run: bash ./scripts/${{ matrix.distro }}-${{ matrix.version }}/3-build.sh
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
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_content_type: application/x-elf
- name: Upload Debug Info
id: upload-debug-info
uses: actions/upload-release-asset@v1
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_content_type: application/x-elf
upload-release-files-windows:
name: Build and upload Windows Release Files
runs-on: windows-latest
needs: create-release
env:
VCPKG_DEFAULT_TRIPLET: x64-windows-static
steps:
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v6
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Create Build Environment
shell: bash
run: ./scripts/windows/1-configure.sh
- name: Build Server
shell: bash
run: bash ./scripts/windows/2-build.sh
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
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

43
.github/workflows/windows.yml vendored Normal file
View File

@@ -0,0 +1,43 @@
name: Windows
on: [push]
env:
VCPKG_DEFAULT_TRIPLET: x64-windows-static
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
CMAKE_BUILD_TYPE: "Release"
jobs:
windows-build:
runs-on: windows-latest
steps:
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v6
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- uses: actions/checkout@v2
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
- name: Build Server
shell: bash
run: bash ./scripts/windows/2-build.sh
- name: Archive server artifact
uses: actions/upload-artifact@v2
with:
name: BeamMP-Server-windows
path: ./bin/Release/BeamMP-Server.exe

1
.gitignore vendored
View File

@@ -1,4 +1,5 @@
.idea/
.sentry-native/
*.orig
*.toml
boost_*

27
.gitmodules vendored
View File

@@ -1,18 +1,9 @@
[submodule "include/commandline"]
path = include/commandline
url = https://github.com/lionkor/commandline
[submodule "socket.io-client-cpp"]
path = socket.io-client-cpp
url = https://github.com/socketio/socket.io-client-cpp
[submodule "asio"]
path = asio
url = https://github.com/chriskohlhoff/asio
[submodule "rapidjson"]
path = rapidjson
url = https://github.com/Tencent/rapidjson
[submodule "include/tomlplusplus"]
path = include/tomlplusplus
url = https://github.com/marzer/tomlplusplus
[submodule "include/sentry-native"]
path = include/sentry-native
url = https://github.com/getsentry/sentry-native
[submodule "deps/commandline"]
path = deps/commandline
url = https://github.com/lionkor/commandline
[submodule "vcpkg"]
path = vcpkg
url = https://github.com/Microsoft/vcpkg.git
[submodule "deps/BeamMP-Protocol"]
path = deps/BeamMP-Protocol
url = https://github.com/BeamMP/BeamMP-Protocol

View File

@@ -1,145 +1,218 @@
cmake_minimum_required(VERSION 3.0)
message(STATUS "You can find build instructions and a list of dependencies in the README at \
https://github.com/BeamMP/BeamMP-Server")
project(BeamMP-Server
DESCRIPTION "Server for BeamMP - The Multiplayer Mod for BeamNG.drive"
HOMEPAGE_URL https://beammp.com
LANGUAGES CXX C)
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
if (WIN32)
# this has to happen before sentry, so that crashpad on windows links with these settings.
message(STATUS "MSVC -> forcing use of statically-linked runtime.")
STRING(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
set(VCPKG_TARGET_TRIPLET x64-windows-static)
endif()
include_directories("include/sentry-native/include")
include(cmake/Vcpkg.cmake) # needs to happen before project()
set(SENTRY_BUILD_SHARED_LIBS OFF)
if (MSVC)
set(SENTRY_BUILD_RUNTIMESTATIC ON)
endif()
set(SENTRY_BACKEND breakpad)
add_subdirectory("include/sentry-native")
project(
"BeamMP-Server" # replace this
VERSION 3.3.0
)
message(STATUS "Setting compiler flags")
if (WIN32)
add_subdirectory("include/watchdog")
#-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static
set(VcpkgRoot ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET})
include_directories(${VcpkgRoot}/include)
link_directories(${VcpkgRoot}/lib)
elseif (UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -static-libstdc++")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -gz -fno-builtin")
if (SANITIZE)
message(STATUS "sanitize is ON")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined,thread")
endif (SANITIZE)
endif ()
include(cmake/StandardSettings.cmake)
include(cmake/StaticAnalyzers.cmake)
include(cmake/Git.cmake)
message(STATUS "Checking for Sentry URL")
# this is set by the build system.
# IMPORTANT: if you're building from source, just leave this empty
if (NOT DEFINED BEAMMP_SECRET_SENTRY_URL)
message(WARNING "No sentry URL configured. Sentry logging is disabled for this build. \
This is not an error, and if you're building the BeamMP-Server yourself, this is expected and can be ignored.")
set(BEAMMP_SECRET_SENTRY_URL "")
else()
string(LENGTH ${BEAMMP_SECRET_SENTRY_URL} URL_LEN)
message(STATUS "Sentry URL is length ${URL_LEN}")
endif()
add_subdirectory(deps/BeamMP-Protocol)
message(STATUS "Adding local source dependencies")
# this has to happen before -DDEBUG since it wont compile properly with -DDEBUG
include_directories("asio/asio/include")
include_directories("rapidjson/include")
include_directories("websocketpp")
add_subdirectory("socket.io-client-cpp")
add_subdirectory("include/commandline")
# below are options which should be changed
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
### SETTINGS ###
message(STATUS "Looking for Boost")
find_package(Boost REQUIRED COMPONENTS system thread)
# add all headers (.h, .hpp) to this
set(PRJ_HEADERS
include/ArgsParser.h
include/BoostAliases.h
include/Common.h
include/Compat.h
include/Cryptography.h
include/CustomAssert.h
include/Defer.h
include/Environment.h
include/FileWatcher.h
include/Http.h
include/IThreaded.h
include/Json.h
include/LuaAPI.h
include/LuaPlugin.h
include/Plugin.h
include/PluginManager.h
include/RWMutex.h
include/SignalHandling.h
include/TConfig.h
include/TConsole.h
include/THeartbeatThread.h
include/TScopedTimer.h
include/Value.h
include/VehicleData.h
include/Network.h
include/Env.h
)
# add all source files (.cpp) to this, except the one with main()
set(PRJ_SOURCES
src/ArgsParser.cpp
src/Common.cpp
src/Compat.cpp
src/FileWatcher.cpp
src/Http.cpp
src/LuaAPI.cpp
src/LuaPlugin.cpp
src/SignalHandling.cpp
src/TConfig.cpp
src/TConsole.cpp
src/THeartbeatThread.cpp
src/TScopedTimer.cpp
src/Value.cpp
src/VehicleData.cpp
src/Network.cpp
src/Env.cpp
)
file(GLOB source_files src/main.cpp
include/TConsole.h src/TConsole.cpp
include/TServer.h src/TServer.cpp
include/Compat.h src/Compat.cpp
include/Common.h src/Common.cpp
include/Client.h src/Client.cpp
include/VehicleData.h src/VehicleData.cpp
include/TConfig.h src/TConfig.cpp
include/TLuaEngine.h src/TLuaEngine.cpp
include/TLuaFile.h src/TLuaFile.cpp
include/TResourceManager.h src/TResourceManager.cpp
include/THeartbeatThread.h src/THeartbeatThread.cpp
include/Http.h src/Http.cpp
include/TSentry.h src/TSentry.cpp
include/TPPSMonitor.h src/TPPSMonitor.cpp
include/TNetwork.h src/TNetwork.cpp
include/SignalHandling.h src/SignalHandling.cpp)
add_executable(BeamMP-Server ${source_files})
target_compile_definitions(BeamMP-Server PRIVATE SECRET_SENTRY_URL="${BEAMMP_SECRET_SENTRY_URL}")
target_include_directories(BeamMP-Server PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/commandline")
message(STATUS "Looking for Lua")
find_package(Lua REQUIRED)
target_include_directories(BeamMP-Server PUBLIC
${Boost_INCLUDE_DIRS}
${LUA_INCLUDE_DIR}
${CURL_INCLUDE_DIRS}
"socket.io-client-cpp/src"
"include/tomlplusplus"
"include/sentry-native/include"
"include/curl/include")
message(STATUS "Looking for SSL")
# set the source file containing main()
set(PRJ_MAIN src/main.cpp)
# set the source file containing the test's main
set(PRJ_TEST_MAIN test/test_main.cpp)
# set include paths not part of libraries
set(PRJ_INCLUDE_DIRS ${LUA_INCLUDE_DIR})
# set compile features (e.g. standard version)
set(PRJ_COMPILE_FEATURES cxx_std_20)
# set #defines (test enable/disable not included here)
set(PRJ_DEFINITIONS CPPHTTPLIB_OPENSSL_SUPPORT)
# add all libraries used by the project (WARNING: also set them in vcpkg.json!)
set(PRJ_LIBRARIES
fmt::fmt
doctest::doctest
Threads::Threads
commandline_static
toml11::toml11
rapidjson
sol2
httplib::httplib
libzip::zip
OpenSSL::SSL OpenSSL::Crypto
protocol
${LUA_LIBRARIES}
zstd::libzstd_static
Boost::thread
Boost::json
glm::glm
)
# add dependency find_package calls and similar here
find_package(fmt CONFIG REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(doctest CONFIG REQUIRED)
find_package(Boost REQUIRED COMPONENTS thread json)
find_package(httplib CONFIG REQUIRED)
find_package(libzip CONFIG REQUIRED)
find_package(RapidJSON CONFIG REQUIRED)
find_package(sol2 CONFIG REQUIRED)
find_package(toml11 CONFIG REQUIRED)
find_package(zstd CONFIG REQUIRED)
find_package(glm CONFIG REQUIRED)
message(STATUS "CURL IS ${CURL_LIBRARIES}")
include_directories(include)
if (UNIX)
target_link_libraries(BeamMP-Server
z
pthread
stdc++fs
${LUA_LIBRARIES}
crypto
${OPENSSL_LIBRARIES}
commandline
sioclient_tls
sentry)
elseif (WIN32)
set_source_files_properties(${source_files} PROPERTIES COMPILE_FLAGS "/Gh /GH")
add_compile_options("$<$<NOT:$<CONFIG:Debug>>:/Zi>")
add_link_options("$<$<NOT:$<CONFIG:Debug>>:/DEBUG>")
add_link_options("$<$<NOT:$<CONFIG:Debug>>:/OPT:REF>")
add_link_options("$<$<NOT:$<CONFIG:Debug>>:/OPT:ICF>")
include(FindLua)
message(STATUS "Looking for libz")
find_package(ZLIB REQUIRED)
message(STATUS "Looking for RapidJSON")
find_package(RapidJSON CONFIG REQUIRED)
target_include_directories(BeamMP-Server PRIVATE ${RAPIDJSON_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
target_link_libraries(BeamMP-Server PRIVATE
ws2_32
ZLIB::ZLIB
${LUA_LIBRARIES}
${OPENSSL_LIBRARIES}
commandline
sioclient_tls
sentry
watchdog
Dbghelp)
# to enable multithreading and the Threads::Threads dependency
include(FindThreads)
### END SETTINGS ###
# DONT change anything beyond this point unless you've read the cmake bible and
# swore on it not to bonk up the ci/cd pipelines with your changes.
####################
# 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")
endif()
if(UNIX)
# this will allow to use same _DEBUG macro available in both Linux as well as Windows - MSCV environment. Easy to put Debug specific code.
add_compile_options("$<$<CONFIG:DEBUG>:-D_DEBUG>")
endif(UNIX)
if (WIN32)
add_compile_options("-D_WIN32_WINNT=0x0601")
endif(WIN32)
include(cmake/CompilerWarnings.cmake)
# set MT library for msvc - this is required (says documentation)
# linux/mac/etc should simply ignore this by default.
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(PRJ_DEFINITIONS ${PRJ_DEFINITIONS}
PRJ_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
PRJ_VERSION_MINOR=${PROJECT_VERSION_MINOR}
PRJ_VERSION_PATCH=${PROJECT_VERSION_PATCH}
)
# build commandline manually for funky windows flags to carry over without a custom toolchain file
add_library(commandline_static
deps/commandline/src/impls.h
deps/commandline/src/windows_impl.cpp
deps/commandline/src/linux_impl.cpp
deps/commandline/src/backends/InteractiveBackend.cpp
deps/commandline/src/backends/InteractiveBackend.h
deps/commandline/src/backends/Backend.cpp
deps/commandline/src/backends/Backend.h
deps/commandline/src/commandline.h
deps/commandline/src/commandline.cpp
deps/commandline/src/backends/BufferedBackend.cpp
deps/commandline/src/backends/BufferedBackend.h
)
if (WIN32)
target_compile_definitions(commandline_static PRIVATE -DPLATFORM_WINDOWS=1)
else ()
target_compile_definitions(commandline_static PRIVATE -DPLATFORM_LINUX=1)
endif ()
target_include_directories(commandline_static PUBLIC "deps/commandline/src")
target_link_libraries(commandline_static Threads::Threads)
# end of commandline custom build
add_executable(${PROJECT_NAME} ${PRJ_HEADERS} ${PRJ_SOURCES} ${PRJ_MAIN})
set_target_properties(${PROJECT_NAME} PROPERTIES
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
target_include_directories(${PROJECT_NAME} PRIVATE ${PRJ_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${PRJ_LIBRARIES})
target_compile_features(${PROJECT_NAME} PRIVATE ${PRJ_COMPILE_FEATURES})
target_compile_definitions(${PROJECT_NAME} PRIVATE ${PRJ_DEFINITIONS} ${PRJ_WARNINGS}
DOCTEST_CONFIG_DISABLE # disables all test code in the final executable
)
if(MSVC)
target_link_options(${PROJECT_NAME} PRIVATE "/SUBSYSTEM:CONSOLE")
endif(MSVC)
# setup all warnings (from cmake/CompilerWarnings.cmake)
set_project_warnings(${PROJECT_NAME})
if(${PROJECT_NAME}_ENABLE_UNIT_TESTING)
message(STATUS "Unit tests are enabled and will be built as '${PROJECT_NAME}-tests'")
add_executable(${PROJECT_NAME}-tests ${PRJ_HEADERS} ${PRJ_SOURCES} ${PRJ_TEST_MAIN})
target_include_directories(${PROJECT_NAME}-tests PRIVATE ${PRJ_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME}-tests ${PRJ_LIBRARIES})
target_compile_features(${PROJECT_NAME}-tests PRIVATE ${PRJ_COMPILE_FEATURES})
target_compile_definitions(${PROJECT_NAME}-tests PRIVATE ${PRJ_DEFINITIONS} ${PRJ_WARNINGS})
set_project_warnings(${PROJECT_NAME}-tests)
if(MSVC)
target_link_options(${PROJECT_NAME}-tests PRIVATE "/SUBSYSTEM:CONSOLE")
endif(MSVC)
endif()

111
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,111 @@
# Contributing to BeamMP-Server
Unlike other parts of BeamMP, the BeamMP-Server does not have any dependency to the BeamNG.drive game.
To contribute *C++ code*, you'll need a MacOS, Linux or Windows PC, and intermediate to advanced knowledge of C++.
For reference, you should know be reasonably comfortable with the STL, the concept of RAII, templates, and generally know how to read & write post-C++17 code. To contribute anything else, you won't need most of this (though it'd be helpful to have some vocabulary about computers).
# Ways to Contribute
## Bug Reports
If you work with BeamMP-Server, either by simply using it, or even writing plugins for it, and you run into any issues, we definitely want to know about it. Please use [GitHub issues](https://github.com/BeamMP/BeamMP-Server/issues) and select the "Bug" template, read it, and fill it out accordingly.
## Bug Fixes
If you are interested in fixing bugs, check out the [GitHub issues](https://github.com/BeamMP/BeamMP-Server/issues). There, you can pick any issue that has nobody assigned to it. For example, some bugs which we definitely need some help with are marked with the "help wanted" tag.
Once you picked a bug, you need to reproduce it. Start by following the instructions in the bug report, and don't be afraid to ask for more information or clarification on the issue itself.
Refer to [getting started with the codebase](#getting-started-with-the-codebase) for more information on how to build the server. You can also ask on our [Discord server](https://discord.gg/beammp), or on IRC ([irc.libera.chat](https://web.libera.chat/), join `#beammp`).
## Features
If you want to add new features, please make an issue for it first or ask on our [Discord server](https://discord.gg/beammp), or on IRC ([irc.libera.chat](https://web.libera.chat/), join `#beammp`).
You need to make sure the feature isn't being worked on by someone else, and aligns with the vision we have for the server.
# Git Guidelines
**Read this carefully. Failing to follow these rules results in your changes not being accepted**. This applies for outside contributors, members of the BeamMP development team ("BeamMP Developers"), project owners, maintainers, frequent contributors, and literally everyone else. **It applies to everyone**.
## How to Commit
Commit messages **MUST** (mandatory):
- start with a **lower case action verb in present tense**, for example `add`, `fix`, `implement`, `refactor`, `remove`, `rename`. *Counter examples (these are bad): ~~`Fixed`, `fixing`, `added`, `removing`~~*.
- not have a first line much longer than 70 characters.
- explain briefly the changes made.
- reference the issue by number, if there is an issue the commit addresses, like so: `#<number>`. Example: `#123`.
If any of these are not followed, **your changes will not be accepted.**
Commit messages **SHOULD** (optional, "nice to have"):
- only address one "atomic" change.
- have an empty second line, and the subsequent lines explaining the changes in more detail (if more detail is available).
Commits may be squashed (via a Git "interactive rebase") in order to satisfy these rules, but history that is >1h old should not be rewritten if possible. Force pushes are ugly ;)
## Pulling, Merging
Do **NOT** pull with merge. This is the default git behavior for `git pull`, but creates ugly and unnecessary commit messages like `"merge origin/master into master"`. Instead, pull with rebase, for example via `git pull -r`. If you get conflicts, resolve them properly.
The only acceptable merge commits are those which actually merge functionally different branches into each other, for example for merging one feature branch into another.
## Branches
### Which branch should I base my work on?
Each *feature* or *bug-fix* is implemented on a new Git branch, branched off of the branch it should be based on. The `master` branch is usually stable, so we don't do development on it. It is always a safe bet to branch off of `master`, but it may be more work to merge later. Branches to base your work on are usually branches like `rc-v3.3.0`, when the latest public version is `3.2.0`, for example. These can often be found in Pull-Requests on GitHub which are tagged `Release Candidate`.
## Unit tests & CI/CD
We use GitHub Actions, which runs our unit-tests. PR's which fail these tests, or even fail any of our actions (which run automatically), will not be merged and require further changes until they compile, link, and all tests pass properly. If you have issues with this, feel free to ask in our [Discord server](https://discord.gg/beammp), or on IRC ([irc.libera.chat](https://web.libera.chat/), join `#beammp`)
### What should I call by branch?
Keep branch names **unique**, **descriptive**, and **shorter than 30 characters**. Names must be in present-tense, such as `fix-xyz`, **not** ~~`fixing-xyz`~~.
We generally use *feature branches*, so we keep one branch per feature or fix.
For example:
- You want to fix issue number #123? You could call the branch `fix-123`.
- You want to add a feature described in issue #456? You could call the branch `implement-456`.
- You want to add a feature or fix a bug that has no issue? You should probably make an issue for it first! Or, if you're not ready for that yet, you could call it by the feature name or bug description, for example for a bug that makes cars disappear: `fix-disappearing-cars`.
## Pull Requests, Code Review
Once you are ready to show what you did, and get feedback on it, you open a Pull-Request on GitHub. Please make sure to pick the right branches, and a descriptive title. Mention any related issues with `#<issue number>`, for example `#123`.
Make sure to explain what the PR does, what it fixes, and what needs to still be done (if anything).
A BeamMP-Developer must review your code in detail, and leave a review. If this takes too long, feel free to @ a maintainer/developer, or leave another comment on the PR. It helps to say something like "Ready for review", for example.
# Getting Started with the Codebase
1. Look at current Pull-Requests, look at the git branches, or ask in our [Discord server](https://discord.gg/beammp), or on IRC ([irc.libera.chat](https://web.libera.chat/), join `#beammp`), in order to find out which branch you should work on to minimize conflict. See [this section on branches](#branches) for more info.
2. Fork the repository (with that branch) on GitHub. GitHub, by default, gives you only the `master` branch when forking, so make sure you fork with other branches enabled when you want to work on a branch that isn't master (it's a checkbox when you fork).
3. Clone the fork to your local machine.
4. Check out the branch you want to work on (see 1.).
5. Run `git submodule update --init --recursive`.
6. Make a new branch for your feature or fix from the branch you are on. You can do this via `git checkout -b <branch name>`. See [this section on branches](#branches) for more info on branch naming.
7. Install all dependencies. Those are usually listed in the `README.md` in the branch you're in, or, more reliably, in one of the files in `.github/workflows` (if you can read `yaml`).
8. Run CMake to configure the project. You can find tutorials on this online. You will want to tell CMake to build with `CMAKE_BUILD_TYPE=Debug`, for example by passing it to CMake via the commandline switch `-DCMAKE_BUILD_TYPE=Debug`. You may also want to turn off sentry by setting `SENTRY_BACKEND=none` (for example via commandline switch `-DSENTRY_BACKEND=none`). An example invocation on Linux with GNU make would be
`cmake . -DCMAKE_BUILD_TYPE=Debug -DSENTRY_BACKEND=none` .
9. Build the `BeamMP-Server` target to build the BeamMP-Server, or the `BeamMP-Server-tests` target to build the unit-tests (does not include a working server). In the example from 8. (on Linux), you could build with `make BeamMP-Server`, `make -j BeamMP-Server` or `cmake --build . --parallel --target BeamMP-Server` . Or, on Windows, (in Visual Studio), you would just press some big green "run" or "debug" button.
10. When making changes, refer to [this section on how to commit properly](#how-to-commit). Not following those guidelines will result in your changes being rejected, so please take a look.
11. Make sure to add Unit-tests with `doctest` if you build new stuff. You can find examples all over the latest version of the codebase (search for `TEST_CASE`).
# Code Guidelines
## Formatting
1. Use `clang-format` to format your code before committig. A `.clang-format` file is provided in the root of the repository.
2. All identifiers, type names, function names, etc. should be `PascalCase`. Type names may also have the `T` prefix, although this is not enforced (for example `TNetwork`).
## Modular code
Write code that is modular and testable. Generally, if you can write a good unit-test for it, it's modular. If you can't, it's not.
Don't overdo it though - sometimes its okay to just write code, do the job, be done with it. You'll get feedback on this in the code review for your PR.

View File

@@ -1,82 +0,0 @@
# v2.3.3
- CHANGED servers to be private by default
# v2.3.2
- ADDED Ctrl+C causes a graceful shutdown on windows (did already on linux)
- ADDED more meaningful shutdown messages
- ADDED even better backend connection error reporting
- ADDED `SendErrors` config in `ServerConfig.toml` to opt-out of error reporting
- ADDED hard-shutdown if Ctrl+C pressed 3 times
- FIXED issue with shells like bash being unusable after server exit
# v2.3.1
- CHANGED join/sync timeout to 20 minutes, players wont drop if loading takes >5 mins
# v2.3.0
- ADDED version check - the server will now let you know when a new release is out
- ADDED logging of various errors, crashes and exceptions to the backend
- ADDED chat messages are now logged to the server console as [CHAT]
- ADDED debug message telling you when the server heartbeats to the backend
- REMOVED various [DEBUG] messages which were confusing (such as "breaking client loop")
- FIXED various crashes and issues with handling unexpected backend responses
- FIXED minor bugs due to code correctness
# v2.2.0
- FIXED major security flaw
- FIXED minor bugs
# v2.1.4
- ADDED debug heartbeat print
- ADDED kicking every player before shutdown
- FIXED rare bug which led to violent crash
- FIXED minor bugs
# v2.1.3
- FIXED Lua events not cancelling properly on Linux
# v2.1.2
- CHANGED default map to gridmap v2
- FIXED version number display
# v2.1.1
# v2.1.0 (pre-v2.1.1)
# v2.0.4 (pre-v2.1.0)
- REMOVED boost as a runtime dependency
- FIXED Lua plugins on Linux
- FIXED console history on Windows
- CHANGED to new config format TOML
# v2.0.3
- WORKAROUND for timeout bug / ghost player bug
- FIXED 100% CPU spin when stdin is /dev/null.
# v2.0.2
- ADDED fully new commandline
- ADDED new backend
- ADDED automated build system
- ADDED lua GetPlayerIdentifiers
- ADDED lots of debug info
- ADDED better POSTing and GETing
- ADDED a license
- FIXED ghost players in player list issue
- FIXED ghost vehicle after joining issue
- FIXED missing vehicle after joining issue
- FIXED a lot of desync issues
- FIXED some memory leaks
- FIXED various crashes
- FIXED various data-races
- FIXED some linux-specific crashes
- FIXED some linux-specific issues
- FIXED bug which caused kicking to be logged as leaving
- FIXED various internal developer quality-of-life things

663
LICENSE
View File

@@ -1,2 +1,661 @@
Copyright (c) 2019-present Anonymous275 (@Anonymous-275), Lion Kortlepel (@lionkor). BeamMP-Server code is not in the public domain and is not free software. One must be granted explicit permission by the copyright holder(s) in order to modify or distribute any part of the source or binaries. Special permission to modify the source-code is implicitly granted only for the purpose of upstreaming those changes directly to github.com/BeamMP/BeamMP-Server via a GitHub pull-request.
Commercial usage is prohibited, unless explicit permission has been granted prior to usage.
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU Affero General Public License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<https://www.gnu.org/licenses/>.

View File

@@ -4,7 +4,16 @@
[![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, which are listed below under [Runtime Dependencies](#runtime-dependencies)**
## Support + Contact
Feel free to ask any questions via the following channels:
- **Discord**: [click for invite](https://discord.gg/beammp)
- **BeamMP Forum**: [BeamMP Forum Support](https://forum.beammp.com/c/support/33)
## Minimum Requirements
@@ -19,21 +28,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" or "good first issue" 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 checkout a tag with `git checkout tags/TAGNAME`, where `TAGNAME` is the tag, for example `v3.1.0`.
## 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 (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.
@@ -41,56 +50,45 @@ You can find precompiled binaries under [Releases](https://github.com/BeamMP/Bea
## Build Instructions
**__Do not compile from `master`. Always build from a release tag, i.e. `tags/v2.0`!__**
On Linux, you need some dependencies to **build** the server (on Windows, you don't):
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)).
```
liblua5.3-dev curl zip unzip tar cmake make git g++
```
### Prerequisites
You can install these with your distribution's package manager. You will need sudo or need root for ONLY this step.
#### Windows
The names of each package may change depending on your platform.
Please use the prepackaged binaries in [Releases](https://github.com/BeamMP/BeamMP-Server/releases/).
If you are building for ARM (like aarch64), you need to run `export VCPKG_FORCE_SYSTEM_BINARIES=1` before the following commands.
Dependencies for windows can be installed with `vcpkg`, in which case the current dependencies are the `x64-windows-static` versions of `lua`, `zlib`, `rapidjson`, `boost-beast`, `boost-asio` and `openssl`.
You can build on **Windows, Linux** or other platforms by following these steps:
#### Linux / \*nix
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 --config Release -t BeamMP-Server`.
5. Your executable can be found in `bin/`.
These package names are in the debian / ubuntu style. Feel free to PR your own guide for a different distro.
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.
- `git`
- `make`
- `cmake`
- `g++`
- `libcurl4-openssl-dev` or similar (search for `libcurl` and look for one with `-dev`)
Must support ISO C++17. If your distro's `g++` doesn't support C++17, chances are that it has a `g++-8` or `g++-10` package that does. If this is the case. you just need to run CMake with `-DCMAKE_CXX_COMPILER=g++-10` (replace `g++-10` with your compiler's name).
- `liblua5.3-dev`
Any 5.x version should work, but 5.3 is what we officially use. Any other version might break in the future.
You can also use any version of `libluajit`, but the same applies regarding the version.
- `libz-dev`
- `rapidjson-dev`
- `libopenssl-dev` or `libssl-dev`
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`.
**If** you're building it from source, you'll need `libboost1.70-all-dev` or `libboost1.71-all-dev` or higher as well.
If you can't find this version of boost (only 1.6x, for example), you can either update to a newer version of your distro, build boost yourself, or use an unstable rolling release (like Debian `sid` aka `unstable`).
### Runtime Dependencies
### How to build
These are needed to *run* the server.
On windows, use git-bash for these commands. On Linux, these should work in your shell.
Debian, Ubuntu and friends: `liblua5.3-0`
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`**. Now change into the cloned directory by running `cd 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/v1.20` for version 1.20. You can find the latest version [here](https://github.com/BeamMP/BeamMP-Server/tags).
5. Run `cmake .` (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.
Other Linux distros: `liblua` of *some kind*.
*tip: to run the server in the background, simply (in bash, zsh, etc) run:* `nohup ./BeamMP-Server &`*.*
Windows: No libraries.
## Copyright
Copyright (c) 2019-present Anonymous275 (@Anonymous-275), Lion Kortlepel (@lionkor).
BeamMP-Server code is not in the public domain and is not free software. One must be granted explicit permission by the copyright holder(s) in order to modify or distribute any part of the source or binaries. Special permission to modify the source-code is implicitly granted only for the purpose of upstreaming those changes directly to github.com/BeamMP/BeamMP-Server via a GitHub pull-request.
Commercial usage is prohibited, unless explicit permission has been granted prior to usage.
## 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
asio

Submodule asio deleted from 230c0d2ae0

View File

@@ -0,0 +1,114 @@
# from here:
#
# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md
# Courtesy of Jason Turner
# License here: https://github.com/cpp-best-practices/cppbestpractices/blob/master/LICENSE
#
# This version has been modified by the owners of the current respository.
# Modifications have mostly been marked with "modified" or similar, though this is not
# strictly required.
function(set_project_warnings project_name)
set(MSVC_WARNINGS
/W4 # Baseline reasonable warnings
/w14242 # 'identifier': conversion from 'type1' to 'type1', possible loss
# of data
/w14254 # 'operator': conversion from 'type1:field_bits' to
# 'type2:field_bits', possible loss of data
/w14263 # 'function': member function does not override any base class
# virtual member function
/w14265 # 'classname': class has virtual functions, but destructor is not
# virtual instances of this class may not be destructed correctly
/w14287 # 'operator': unsigned/negative constant mismatch
/we4289 # nonstandard extension used: 'variable': loop control variable
# declared in the for-loop is used outside the for-loop scope
/w14296 # 'operator': expression is always 'boolean_value'
/w14311 # 'variable': pointer truncation from 'type1' to 'type2'
/w14545 # expression before comma evaluates to a function which is missing
# an argument list
/w14546 # function call before comma missing argument list
/w14547 # 'operator': operator before comma has no effect; expected
# operator with side-effect
/w14549 # 'operator': operator before comma has no effect; did you intend
# 'operator'?
/w14555 # expression has no effect; expected expression with side- effect
/w14619 # pragma warning: there is no warning number 'number'
/w14640 # Enable warning on thread un-safe static member initialization
/w14826 # Conversion from 'type1' to 'type_2' is sign-extended. This may
# cause unexpected runtime behavior.
/w14905 # wide string literal cast to 'LPSTR'
/w14906 # string literal cast to 'LPWSTR'
/w14928 # illegal copy-initialization; more than one user-defined
# conversion has been implicitly applied
/permissive- # standards conformance mode for MSVC compiler.
)
set(CLANG_WARNINGS
-Wall
-Wextra # reasonable and standard
-Wshadow # warn the user if a variable declaration shadows one from a
# parent context
-Wnon-virtual-dtor # warn the user if a class with virtual functions has a
# non-virtual destructor. This helps catch hard to
# track down memory errors
-Wold-style-cast # warn for c-style casts
-Wcast-align # warn for potential performance problem casts
-Wunused # warn on anything being unused
-Woverloaded-virtual # warn if you overload (not override) a virtual
# function
-Wpedantic # warn if non-standard C++ is used
-Wconversion # warn on type conversions that may lose data
-Wsign-conversion # warn on sign conversions
-Wnull-dereference # warn if a null dereference is detected
-Wdouble-promotion # warn if float is implicit promoted to double
-Wformat=2 # warn on security issues around functions that format output
# (ie printf)
# modified; added more errors / warnings
# some have been set to be errors, but the option _WARNINGS_AS_ERRORS
# (see below) should still be used in strict pipelines.
-Werror=uninitialized
-Werror=float-equal
-Werror=write-strings
-Werror=strict-aliasing -fstrict-aliasing
-Werror=missing-declarations
-Werror=ctor-dtor-privacy
-Wno-missing-field-initializers
-Wswitch-default
-Werror=unused-result
-Werror=implicit-fallthrough
-Werror=return-type
-Wmissing-include-dirs
)
if (${PROJECT_NAME}_WARNINGS_AS_ERRORS)
set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror)
set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX)
endif()
set(GCC_WARNINGS
${CLANG_WARNINGS}
-Wmisleading-indentation # warn if indentation implies blocks where blocks
# do not exist
-Wduplicated-cond # warn if if / else chain has duplicated conditions
-Wduplicated-branches # warn if if / else branches have duplicated code
-Wlogical-op # warn about logical operations being used where bitwise were
# probably wanted
# -Wuseless-cast # warn if you perform a cast to the same type (modified: removed)
)
if(MSVC)
set(PRJ_WARNINGS ${MSVC_WARNINGS})
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
set(PRJ_WARNINGS ${CLANG_WARNINGS})
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(PRJ_WARNINGS ${GCC_WARNINGS})
else()
message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.")
endif()
target_compile_options(${project_name} PUBLIC ${PRJ_WARNINGS})
if(NOT TARGET ${project_name})
message(AUTHOR_WARNING "${project_name} is not a target, thus no compiler warning were added.")
endif()
endfunction()

21
cmake/Git.cmake Normal file
View File

@@ -0,0 +1,21 @@
find_package(Git)
if(${PROJECT_NAME}_CHECKOUT_GIT_SUBMODULES)
if(Git_FOUND)
message(STATUS "Git found, submodule update and init")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(SEND_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules. This may result in missing dependencies.")
endif()
else()
message(SEND_ERROR "git required for checking out submodules, but not found. Submodules will not be checked out - this may result in missing dependencies.")
endif()
endif()
if(Git_FOUND)
else()
message(STATUS "Git not found - the version will not include a git hash.")
set(PRJ_GIT_HASH "unknown")
endif()

View File

@@ -0,0 +1,44 @@
# Modified, original version from https://github.com/filipdutescu/modern-cpp-template (Unlicense)
option(${PROJECT_NAME}_WARNINGS_AS_ERRORS "Treat compiler warnings as errors." OFF)
option(${PROJECT_NAME}_CHECKOUT_GIT_SUBMODULES "If git is found, initialize all submodules." ON)
option(${PROJECT_NAME}_ENABLE_UNIT_TESTING "Enable unit tests for the projects (from the `test` subfolder)." ON)
option(${PROJECT_NAME}_ENABLE_CLANG_TIDY "Enable static analysis with Clang-Tidy." OFF)
option(${PROJECT_NAME}_ENABLE_CPPCHECK "Enable static analysis with Cppcheck." OFF)
# TODO Implement code coverage
# option(${PROJECT_NAME}_ENABLE_CODE_COVERAGE "Enable code coverage through GCC." OFF)
option(${PROJECT_NAME}_ENABLE_DOXYGEN "Enable Doxygen documentation builds of source." OFF)
# Generate compile_commands.json for clang based tools
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Export all symbols when building a shared library
if(BUILD_SHARED_LIBS)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS OFF)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
endif()
option(${PROJECT_NAME}_ENABLE_LTO "Enable Interprocedural Optimization, aka Link Time Optimization (LTO)." OFF)
if(${PROJECT_NAME}_ENABLE_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT result OUTPUT output)
if(result)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(SEND_ERROR "IPO is not supported: ${output}.")
endif()
endif()
option(${PROJECT_NAME}_ENABLE_CCACHE "Enable the usage of Ccache, in order to speed up rebuild times." ON)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif()
option(${PROJECT_NAME}_ENABLE_SANITIZER "Enable sanitizer to detect memory errors, undefined behavior, etc. (slows down the executable)." OFF)
if(${PROJECT_NAME}_ENABLE_SANITIZER)
add_compile_options(-fsanitize=address,undefined)
add_link_options(-fsanitize=address,undefined)
endif()

View File

@@ -0,0 +1,20 @@
if(${PROJECT_NAME}_ENABLE_CLANG_TIDY)
find_program(CLANGTIDY clang-tidy)
if(CLANGTIDY)
set(CMAKE_CXX_CLANG_TIDY ${CLANGTIDY} -extra-arg=-Wno-unknown-warning-option)
message("Clang-Tidy finished setting up.")
else()
message(SEND_ERROR "Clang-Tidy requested but executable not found.")
endif()
endif()
if(${PROJECT_NAME}_ENABLE_CPPCHECK)
find_program(CPPCHECK cppcheck)
if(CPPCHECK)
set(CMAKE_CXX_CPPCHECK ${CPPCHECK} --suppress=missingInclude --enable=all
--inline-suppr --inconclusive)
message("Cppcheck finished setting up.")
else()
message(SEND_ERROR "Cppcheck requested but executable not found.")
endif()
endif()

17
cmake/Vcpkg.cmake Normal file
View File

@@ -0,0 +1,17 @@
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake)
find_package(Git)
if(Git_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive vcpkg
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(SEND_ERROR "Checking out vcpkg in source tree failed with ${GIT_SUBMOD_RESULT}.")
endif()
else()
message(FATAL_ERROR "Could not find git or vcpkg.cmake. Please either, install git and re-run cmake (or run `git submodule update --init --recursive`), or install vcpkg and add `-DCMAKE_TOOLCHAIN_FILE=<path-to-vcpkg>/scripts/buildsystems/vcpkg.cmake` to your cmake invocation. Please try again after making those changes.")
endif()
endif()
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake)
endif()

1
deps/BeamMP-Protocol vendored Submodule

Submodule deps/BeamMP-Protocol added at 8eda5714c0

1
deps/commandline vendored Submodule

Submodule deps/commandline added at b2a29733f9

67
include/ArgsParser.h Normal file
View File

@@ -0,0 +1,67 @@
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <initializer_list>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
/*
* Allows syntax:
* --help : long flags
* --path=/home/lion : long assignments
*/
class ArgsParser {
public:
enum Flags : int {
NONE = 0,
REQUIRED = 1, // argument is required
HAS_VALUE = 2, // argument must have a value
};
ArgsParser() = default;
void Parse(const std::vector<std::string_view>& ArgList);
// prints errors if any errors occurred, in that case also returns false
bool Verify();
void RegisterArgument(std::vector<std::string>&& ArgumentNames, int Flags);
// pass all possible names for this argument (short, long, etc)
bool FoundArgument(const std::vector<std::string>& Names);
std::optional<std::string> GetValueOfArgument(const std::vector<std::string>& Names);
private:
void ConsumeLongAssignment(const std::string& Arg);
void ConsumeLongFlag(const std::string& Arg);
bool IsRegistered(const std::string& Name);
struct Argument {
std::string Name;
std::optional<std::string> Value;
};
struct RegisteredArgument {
std::vector<std::string> Names;
int Flags;
};
std::vector<RegisteredArgument> mRegisteredArguments;
std::vector<Argument> mFoundArgs;
};

24
include/BoostAliases.h Normal file
View File

@@ -0,0 +1,24 @@
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <boost/asio.hpp>
#include <boost/system/error_code.hpp>
using namespace boost::asio;

View File

@@ -1,94 +0,0 @@
#pragma once
#include <chrono>
#include <memory>
#include <queue>
#include <string>
#include <unordered_set>
#include "Common.h"
#include "Compat.h"
#include "VehicleData.h"
class TServer;
class TClient final {
public:
using TSetOfVehicleData = std::vector<TVehicleData>;
struct TVehicleDataLockPair {
TSetOfVehicleData* VehicleData;
std::unique_lock<std::mutex> Lock;
};
explicit TClient(TServer& Server);
TClient(const TClient&) = delete;
TClient& operator=(const TClient&) = delete;
void AddNewCar(int Ident, const std::string& Data);
void SetCarData(int Ident, const std::string& Data);
TVehicleDataLockPair GetAllCars();
void SetName(const std::string& Name) { mName = Name; }
void SetRoles(const std::string& Role) { mRole = Role; }
void AddIdentifier(const std::string& ID) { mIdentifiers.insert(ID); };
std::string GetCarData(int Ident);
void SetUDPAddr(sockaddr_in Addr) { mUDPAddress = Addr; }
void SetDownSock(SOCKET CSock) { mSocket[1] = CSock; }
void SetTCPSock(SOCKET CSock) { mSocket[0] = CSock; }
void SetStatus(int Status) { mStatus = Status; }
// locks
void DeleteCar(int Ident);
[[nodiscard]] std::set<std::string> GetIdentifiers() const { return mIdentifiers; }
[[nodiscard]] sockaddr_in GetUDPAddr() const { return mUDPAddress; }
[[nodiscard]] SOCKET GetDownSock() const { return mSocket[1]; }
[[nodiscard]] SOCKET GetTCPSock() const { return mSocket[0]; }
[[nodiscard]] std::string GetRoles() const { return mRole; }
[[nodiscard]] std::string GetName() const { return mName; }
void SetUnicycleID(int ID) { mUnicycleID = ID; }
void SetID(int ID) { mID = ID; }
[[nodiscard]] int GetOpenCarID() const;
[[nodiscard]] int GetCarCount() const;
void ClearCars();
[[nodiscard]] int GetStatus() const { return mStatus; }
[[nodiscard]] int GetID() const { return mID; }
[[nodiscard]] int GetUnicycleID() const { return mUnicycleID; }
[[nodiscard]] bool IsConnected() const { return mIsConnected; }
[[nodiscard]] bool IsSynced() const { return mIsSynced; }
[[nodiscard]] bool IsSyncing() const { return mIsSyncing; }
[[nodiscard]] bool IsGuest() const { return mIsGuest; }
void SetIsGuest(bool NewIsGuest) { mIsGuest = NewIsGuest; }
void SetIsSynced(bool NewIsSynced) { mIsSynced = NewIsSynced; }
void SetIsSyncing(bool NewIsSyncing) { mIsSyncing = NewIsSyncing; }
void EnqueuePacket(const std::string& Packet);
[[nodiscard]] std::queue<std::string>& MissedPacketQueue() { return mPacketsSync; }
[[nodiscard]] const std::queue<std::string>& MissedPacketQueue() const { return mPacketsSync; }
[[nodiscard]] size_t MissedPacketQueueSize() const { return mPacketsSync.size(); }
[[nodiscard]] std::mutex& MissedPacketQueueMutex() const { return mMissedPacketsMutex; }
void SetIsConnected(bool NewIsConnected) { mIsConnected = NewIsConnected; }
[[nodiscard]] TServer& Server() const;
void UpdatePingTime();
int SecondsSinceLastPing();
private:
void InsertVehicle(int ID, const std::string& Data);
TServer& mServer;
bool mIsConnected = false;
bool mIsSynced = false;
bool mIsSyncing = false;
mutable std::mutex mMissedPacketsMutex;
std::queue<std::string> mPacketsSync;
std::set<std::string> mIdentifiers;
bool mIsGuest = false;
std::mutex mVehicleDataMutex;
TSetOfVehicleData mVehicleData;
std::string mName = "Unknown Client";
SOCKET mSocket[2] { SOCKET(0), SOCKET(0) };
sockaddr_in mUDPAddress {}; // is this initialization OK? yes it is
int mUnicycleID = -1;
std::string mRole;
std::string mDID;
int mStatus = 0;
int mID = -1;
std::chrono::time_point<std::chrono::high_resolution_clock> mLastPingTime;
};

View File

@@ -1,17 +1,59 @@
#pragma once
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "TSentry.h"
extern TSentry Sentry;
#pragma once
#include <array>
#include <atomic>
#include <cstring>
#include <deque>
#include <filesystem>
#include <fmt/chrono.h>
#include <fmt/format.h>
#include <fmt/ostream.h>
#include <fmt/ranges.h>
#include <fmt/std.h>
#include <functional>
#include <memory>
#include <mutex>
#include <shared_mutex>
#include <sstream>
#include <unordered_map>
#include <zlib.h>
#include <doctest/doctest.h>
#include <filesystem>
namespace fs = std::filesystem;
#include "TConsole.h"
struct Version {
uint8_t major;
uint8_t minor;
uint8_t patch;
Version(uint8_t major, uint8_t minor, uint8_t patch);
Version(const std::array<uint8_t, 3>& v);
std::string AsString();
};
template <typename T>
using SparseArray = std::unordered_map<size_t, T>;
// static class handling application start, shutdown, etc.
// yes, static classes, singletons, globals are all pretty
// bad idioms. In this case we need a central way to access
@@ -21,33 +63,32 @@ class Application final {
public:
// types
struct TSettings {
TSettings() noexcept
: ServerName("BeamMP Server")
, ServerDesc("BeamMP Default Description")
, Resource("Resources")
, MapName("/levels/gridmap_v2/info.json")
, MaxPlayers(10)
, Private(true)
, MaxCars(1)
, DebugModeEnabled(false)
, Port(30814)
, SendErrors(true)
, SendErrorsMessageEnabled(true) { }
std::string ServerName;
std::string ServerDesc;
std::string Resource;
std::string MapName;
std::string Key;
int MaxPlayers;
bool Private;
int MaxCars;
bool DebugModeEnabled;
int Port;
std::string CustomIP;
bool SendErrors;
bool SendErrorsMessageEnabled;
std::string ServerName { "BeamMP Server" };
std::string ServerDesc { "BeamMP Default Description" };
std::string ServerTags { "Freeroam" };
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 };
int MaxPlayers { 8 };
bool Private { true };
int MaxCars { 1 };
bool DebugModeEnabled { false };
int Port { 30814 };
std::string CustomIP {};
bool LogChat { true };
bool SendErrors { true };
bool SendErrorsMessageEnabled { true };
int HTTPServerPort { 8080 };
std::string HTTPServerIP { "127.0.0.1" };
bool HTTPServerUseSSL { false };
bool HideUpdateMessages { false };
[[nodiscard]] bool HasCustomIP() const { return !CustomIP.empty(); }
};
using TShutdownHandler = std::function<void()>;
// methods
@@ -57,101 +98,202 @@ public:
static void RegisterShutdownHandler(const TShutdownHandler& Handler);
// Causes all threads to finish up and exit gracefull gracefully
static void GracefullyShutdown();
static TConsole& Console() { return *mConsole; }
static std::string ServerVersion() { return "2.3.2"; }
static std::string ClientVersion() { return "2.0"; }
static TConsole& Console() { return mConsole; }
static std::string ServerVersionString();
static const Version& ServerVersion() { return mVersion; }
static uint8_t ClientMajorVersion() { return 2; }
static std::string PPS() { return mPPS; }
static void SetPPS(const std::string& NewPPS) { mPPS = NewPPS; }
static inline TSettings Settings {};
static TSettings Settings;
static std::vector<std::string> GetBackendUrlsInOrder() {
return {
"backend.beammp.com",
"backup1.beammp.com",
"backup2.beammp.com"
};
}
static std::string GetBackendUrlForAuth() { return "auth.beammp.com"; }
static std::string GetBackendHostname() { return "backend.beammp.com"; }
static std::string GetBackup1Hostname() { return "backup1.beammp.com"; }
static std::string GetBackup2Hostname() { return "backup2.beammp.com"; }
static std::string GetBackendUrlForSocketIO() { return "https://backend.beammp.com"; }
static void CheckForUpdates();
static std::array<int, 3> VersionStrToInts(const std::string& str);
static bool IsOutdated(const std::array<int, 3>& Current, const std::array<int, 3>& Newest);
static std::array<uint8_t, 3> VersionStrToInts(const std::string& str);
static bool IsOutdated(const Version& Current, const Version& Newest);
static bool IsShuttingDown();
static void SleepSafeSeconds(size_t Seconds);
static void InitializeConsole() {
mConsole.InitializeCommandline();
}
enum class Status {
Starting,
Good,
Bad,
ShuttingDown,
Shutdown,
};
using SystemStatusMap = std::unordered_map<std::string /* system name */, Status /* status */>;
static const SystemStatusMap& GetSubsystemStatuses() {
std::unique_lock Lock(mSystemStatusMapMutex);
return mSystemStatusMap;
}
static void SetSubsystemStatus(const std::string& Subsystem, Status status);
private:
static void SetShutdown(bool Val);
static inline SystemStatusMap mSystemStatusMap {};
static inline std::mutex mSystemStatusMapMutex {};
static inline std::string mPPS;
static std::unique_ptr<TConsole> mConsole;
static inline TConsole mConsole;
static inline std::shared_mutex mShutdownMtx {};
static inline bool mShutdown { false };
static inline std::mutex mShutdownHandlersMutex {};
static inline std::deque<TShutdownHandler> mShutdownHandlers {};
static inline Version mVersion { 3, 2, 2 };
};
void SplitString(std::string const& str, const char delim, std::vector<std::string>& out);
std::string ThreadName(bool DebugModeOverride = false);
void RegisterThread(const std::string& str);
#define RegisterThreadAuto() RegisterThread(__func__)
#define KB 1024
#define MB (KB * 1024)
#define KB 1024llu
#define MB (KB * 1024llu)
#define GB (MB * 1024llu)
#define SSU_UNRAW SECRET_SENTRY_URL
#define _file_basename std::filesystem::path(__FILE__).filename().string()
#define _line std::to_string(__LINE__)
#define _in_lambda (std::string(__func__) == "operator()")
// we would like the full function signature 'void a::foo() const'
// on windows this is __FUNCSIG__, on GCC it's __PRETTY_FUNCTION__,
// feel free to add more
#if defined(WIN32)
#define _function_name std::string(__FUNCSIG__)
#elif defined(__unix) || defined(__unix__)
#define _function_name std::string(__PRETTY_FUNCTION__)
#else
#define _function_name std::string(__func__)
#endif
// for those times when you just need to ignore something :^)
// explicity disables a [[nodiscard]] warning
#define beammp_ignore(x) (void)x
// clang-format off
#ifdef DOCTEST_CONFIG_DISABLE
// we would like the full function signature 'void a::foo() const'
// on windows this is __FUNCSIG__, on GCC it's __PRETTY_FUNCTION__,
// feel free to add more
#if defined(WIN32)
#define _function_name std::string(__FUNCSIG__)
#elif defined(__unix) || defined(__unix__)
#define _function_name std::string(__PRETTY_FUNCTION__)
#else
#define _function_name std::string(__func__)
#endif
#ifndef NDEBUG
#define DEBUG
#endif
#if defined(DEBUG)
// if this is defined, we will show the full function signature infront of
// each info/debug/warn... call instead of the 'filename:line' format.
#if defined(BMP_FULL_FUNCTION_NAMES)
#define _this_location (ThreadName() + _function_name + " ")
#else
#define _this_location (ThreadName() + _file_basename + ":" + _line + " ")
#endif
#endif // defined(DEBUG)
#define beammp_warn(x) Application::Console().Write(_this_location + std::string("[WARN] ") + (x))
#define beammp_info(x) Application::Console().Write(_this_location + std::string("[INFO] ") + (x))
#define beammp_error(x) \
do { \
Application::Console().Write(_this_location + std::string("[ERROR] ") + (x)); \
} while (false)
#define beammp_lua_error(x) \
do { \
Application::Console().Write(_this_location + std::string("[LUA ERROR] ") + (x)); \
} while (false)
#define beammp_lua_warn(x) \
do { \
Application::Console().Write(_this_location + std::string("[LUA WARN] ") + (x)); \
} while (false)
#define beammp_lua_info(x) \
do { \
Application::Console().Write(_this_location + std::string("[LUA INFO] ") + (x)); \
} while (false)
#define beammp_lua_debug(x) \
do { \
if (Application::Settings.DebugModeEnabled) { \
Application::Console().Write(_this_location + std::string("[LUA DEBUG] ") + (x)); \
} \
} while (false)
#define luaprint(x) Application::Console().Write(_this_location + std::string("[LUA] ") + (x))
#define beammp_debug(x) \
do { \
if (Application::Settings.DebugModeEnabled) { \
Application::Console().Write(_this_location + std::string("[DEBUG] ") + (x)); \
} \
} while (false)
#define beammp_event(x) \
do { \
if (Application::Settings.DebugModeEnabled) { \
Application::Console().Write(_this_location + std::string("[EVENT] ") + (x)); \
} \
} while (false)
// trace() is a debug-build debug()
#if defined(DEBUG)
#define beammp_trace(x) \
do { \
if (Application::Settings.DebugModeEnabled) { \
Application::Console().Write(_this_location + std::string("[TRACE] ") + (x)); \
} \
} while (false)
#else
#define beammp_trace(x)
#endif // defined(DEBUG)
#define beammp_errorf(...) beammp_error(fmt::format(__VA_ARGS__))
#define beammp_infof(...) beammp_info(fmt::format(__VA_ARGS__))
#define beammp_debugf(...) beammp_debug(fmt::format(__VA_ARGS__))
#define beammp_warnf(...) beammp_warn(fmt::format(__VA_ARGS__))
#define beammp_tracef(...) beammp_trace(fmt::format(__VA_ARGS__))
#else // DOCTEST_CONFIG_DISABLE
#define beammp_error(x) /* x */
#define beammp_lua_error(x) /* x */
#define beammp_warn(x) /* x */
#define beammp_lua_warn(x) /* x */
#define beammp_info(x) /* x */
#define beammp_event(x) /* x */
#define beammp_debug(x) /* x */
#define beammp_trace(x) /* x */
#define luaprint(x) /* x */
#define beammp_errorf(...) beammp_error(fmt::format(__VA_ARGS__))
#define beammp_infof(...) beammp_info(fmt::format(__VA_ARGS__))
#define beammp_warnf(...) beammp_warn(fmt::format(__VA_ARGS__))
#define beammp_debugf(...) beammp_debug(fmt::format(__VA_ARGS__))
#define beammp_tracef(...) beammp_trace(fmt::format(__VA_ARGS__))
#define beammp_lua_errorf(...) beammp_lua_error(fmt::format(__VA_ARGS__))
#define beammp_lua_warnf(...) beammp_lua_warn(fmt::format(__VA_ARGS__))
#endif // DOCTEST_CONFIG_DISABLE
#if defined(DEBUG)
// if this is defined, we will show the full function signature infront of
// each info/debug/warn... call instead of the 'filename:line' format.
#if defined(BMP_FULL_FUNCTION_NAMES)
#define _this_location (ThreadName() + _function_name + " ")
#define SU_RAW SSU_UNRAW
#else
#define _this_location (ThreadName() + _file_basename + ":" + _line + " ")
#define SU_RAW RAWIFY(SSU_UNRAW)
#define _this_location (ThreadName())
#endif
#define SU_RAW SSU_UNRAW
#else // !defined(DEBUG)
#define SU_RAW RAWIFY(SSU_UNRAW)
#define _this_location (ThreadName())
#endif // defined(DEBUG)
#define warn(x) Application::Console().Write(_this_location + std::string("[WARN] ") + (x))
#define info(x) Application::Console().Write(_this_location + std::string("[INFO] ") + (x))
#define error(x) \
do { \
Application::Console().Write(_this_location + std::string("[ERROR] ") + (x)); \
Sentry.AddErrorBreadcrumb((x), _file_basename, _line); \
} while (false)
#define luaprint(x) Application::Console().Write(_this_location + std::string("[LUA] ") + (x))
#define debug(x) \
do { \
if (Application::Settings.DebugModeEnabled) { \
Application::Console().Write(_this_location + std::string("[DEBUG] ") + (x)); \
} \
} while (false)
// trace() is a debug-build debug()
#if defined(DEBUG)
#define trace(x) \
do { \
if (Application::Settings.DebugModeEnabled) { \
Application::Console().Write(_this_location + std::string("[TRACE] ") + (x)); \
} \
} while (false)
#else
#define trace(x)
#endif // defined(DEBUG)
// clang-format on
void LogChatMessage(const std::string& name, int id, const std::string& msg);
#define Biggest 30000
std::string Comp(std::string Data);
std::string DeComp(std::string Compressed);
std::string GetPlatformAgnosticErrorString();
#define S_DSN SU_RAW

View File

@@ -1,36 +1,55 @@
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "Environment.h"
// ======================= UNIX ========================
#ifdef __unix
#include <arpa/inet.h>
#include <sys/socket.h>
#ifdef BEAMMP_LINUX
#include <errno.h>
#include <termios.h>
#include <unistd.h>
char _getch();
#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 ========================
#ifdef BEAMMP_APPLE
#include <errno.h>
#include <termios.h>
#include <unistd.h>
using SOCKET = int;
using DWORD = unsigned long;
using PDWORD = unsigned long*;
using LPDWORD = unsigned long*;
char _getch();
inline void CloseSocketProper(int TheSocket) {
shutdown(TheSocket, SHUT_RDWR);
close(TheSocket);
}
#endif // unix
// ======================= WIN32 =======================
// ======================= WINDOWS =======================
#ifdef WIN32
#ifdef BEAMMP_WINDOWS
#include <conio.h>
#include <winsock2.h>
inline void CloseSocketProper(SOCKET TheSocket) {
shutdown(TheSocket, 2); // 2 == SD_BOTH
closesocket(TheSocket);
}
#endif // WIN32
// ======================= OTHER =======================
#if !defined(WIN32) && !defined(__unix)
#error "OS not supported"
#endif

View File

@@ -1,4 +1,20 @@
// Copyright Anonymous275 8/11/2020
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <array>
@@ -91,14 +107,14 @@ static auto w_printf_s = [](const char* fmt, ...) {
va_end(args);
};
static auto w_sprintf_s = [](char* buf, size_t buf_size, const char* fmt, ...) {
static auto w_sprintf_s = [](char* buf, size_t, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
vsprintf(buf, fmt, args);
va_end(args);
};
static auto w_sprintf_s_ret = [](char* buf, size_t buf_size, const char* fmt, ...) {
static auto w_sprintf_s_ret = [](char* buf, size_t, const char* fmt, ...) {
int ret;
va_list args;
va_start(args, fmt);

View File

@@ -1,4 +1,20 @@
// Author: lionkor
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
/*
* Asserts are to be used anywhere where assumptions about state are made
@@ -55,19 +71,18 @@ inline void _assert([[maybe_unused]] const char* file, [[maybe_unused]] const ch
}
}
#define Assert(cond) _assert(__FILE__, __func__, __LINE__, #cond, (cond))
#define AssertNotReachable() _assert(__FILE__, __func__, __LINE__, "reached unreachable code", false)
#define beammp_assert(cond) _assert(__FILE__, __func__, __LINE__, #cond, (cond))
#define beammp_assert_not_reachable() _assert(__FILE__, __func__, __LINE__, "reached unreachable code", false)
#else
// In release build, these macros turn into NOPs. The compiler will optimize these out.
#define Assert(cond) \
do { \
bool result = (cond); \
if (!result) { \
Sentry.LogAssert(#cond, _file_basename, _line, __func__); \
} \
#define beammp_assert(cond) \
do { \
bool result = (cond); \
if (!result) { \
beammp_errorf("Assertion failed in '{}:{}': {}.", __func__, _line, #cond); \
} \
} while (false)
#define AssertNotReachable() \
do { \
Sentry.LogAssert("code is unreachable", _file_basename, _line, __func__); \
#define beammp_assert_not_reachable() \
do { \
beammp_errorf("Assertion failed in '{}:{}': Unreachable code reached. This may result in a crash or undefined state of the program.", __func__, _line); \
} while (false)
#endif // DEBUG

View File

@@ -1,3 +1,21 @@
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <functional>

34
include/Env.h Normal file
View File

@@ -0,0 +1,34 @@
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#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);
}

37
include/Environment.h Normal file
View File

@@ -0,0 +1,37 @@
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
// 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) && !defined(BEAMMP_FREEBSD)
#if defined(_WIN32) || defined(__CYGWIN__)
#define BEAMMP_WINDOWS
#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
#error "This platform is not known. Please define one of the above for your OS."
#endif
#endif
// clang-format on

120
include/Error.h Normal file
View File

@@ -0,0 +1,120 @@
#pragma once
#include <fmt/core.h>
#include <optional>
#include <string>
/// The Error class represents an error or the absence of an
/// error. It behaves like a bool, depending on context.
///
/// The idea is to use this class to pass around errors, together with
/// [[nodiscard]], in order to make errors displayable for the users and
/// to give errors some context. The only way to construct an error is to come
/// up with an error message with this class, so this is an attempt to enforce
/// this.
///
/// A default constructed Error means "no error" / "success", while
/// the only available non-default constructor is one which takes any format.
/// For example:
///
/// \code{.cpp}
/// Error myfunc() {
/// if (ok) {
/// return {}; // no error
/// } else {
/// return Error("Something went wrong: {}", 42); // error
/// }
/// }
///
/// // ... handling:
///
/// Error err = myfunc();
/// if (err) {
/// // error occurred
/// l::error("Error running myfunc: {}", err.error);
/// } else {
/// // ok
/// }
/// \endcode
struct Error {
/// Constructs a "non-error" / empty error, which is not considered
/// to be an error. Use this as the "no error occurred" return value.
Error() = default;
/// Constructs an error with a message. Accepts fmt::format() arguments.
///
/// Example:
///
/// \code{.cpp}
/// // format with fmt (automatically), all arguments are forwarded to fmt::format
/// return Error("failed to open '{}': {}", file, error);
/// // or just as a constexpr string
/// return Error("failed to open file");
/// \endcode
template<typename... Args>
Error(fmt::format_string<Args...> s, Args&&... args)
: is_error(true)
, error(fmt::format(s, std::forward<Args>(args)...)) { }
/// Whether this error represents an error (true) or success (false).
/// Use operator bool() instead of reading this if possible.
bool is_error { false };
/// The error message. Is a valid string even if is_error is false, but will
/// be "Success".
std::string error { "Success" };
/// Implicit conversion to boolean.
/// True if this Error contains an error, false if not.
operator bool() const { return is_error; }
};
// TODO: Add docs
template<typename T>
struct Result {
/// Constructs an error-value result.
/// Currently, you may have to force this by passing a second
/// empty string argument.
template<typename... Args>
Result(fmt::format_string<Args...> s, Args&&... args)
: is_error(true)
, error(fmt::format(s, std::forward<Args>(args)...)) { }
/// Constructs a value-result via an explicit type.
template<typename S>
Result(S&& value)
: result(std::move(value)) {
}
/// Constructs a value-result via an explicit type.
template<typename S>
explicit Result(const S& value)
: result(value) {
}
/// Constructs a value-result via an implicit conversion.
Result(T&& value)
: result(std::move(value)) {
}
/// Constructs a value-result via an implicit conversion.
explicit Result(const T& value)
: result(value) {
}
/// Converts to bool in context. If it has an error, its considered "not a result",
/// so it returns true only if a value is contained.
operator bool() const { return !is_error; }
/// Accesses the value contained by moving it out.
T&& move() { return std::move(result.value()); }
/// Accesses the value contained by const reference.
const T& value() const { return result.value(); }
/// Holds the optional result value. On error, is nullopt.
std::optional<T> result;
/// Whether this result holds an error.
bool is_error { false };
/// Error message.
std::string error { "Success" };
};

92
include/FileWatcher.h Normal file
View File

@@ -0,0 +1,92 @@
#pragma once
/// @file
/// This file holds the FileWatcher interface.
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/date_time/posix_time/posix_time_duration.hpp>
#include <boost/signals2.hpp>
#include <boost/system/detail/error_code.hpp>
#include <boost/thread/scoped_thread.hpp>
#include <boost/thread/synchronized_value.hpp>
#include <filesystem>
#include <functional>
#include <unordered_map>
#include <unordered_set>
/// The FileWatcher class watches a directory or a file for changes,
/// and then notifies the caller through a signal.
///
/// This is a pretty convoluted implementation, and you may find it difficult
/// to read. This is not intentional, but simplifying this would
/// cost more time than to write this excuse.
///
/// It operates as follows:
///
/// A boost::asio::deadline_timer is waited on asynchronously.
/// Once expired, this timer calls FileWatcher::on_tick.
/// That function then loops through all registered files and directories,
/// taking great care to follow symlinks, and tries to find a file which has changed.
/// It determines this by storing the last known modification time.
/// Once a file is found which has a new modification time, the FileWatcher::sig_file_changed
/// signal is fired, and all connected slots must take care to handle the signal.
class FileWatcher {
public:
/// Constructs the FileWatcher to watch the given files every few seconds, as
/// specified by the seconds argument.
FileWatcher(unsigned seconds);
/// Stops the thread via m_shutdown.
~FileWatcher();
/// Add a file to watch. If this file changes, FileWatcher::sig_file_changed is triggered
/// with the path to the file.
void watch_file(const std::filesystem::path& path);
/// Add a directory to watch. If any file in the directory, or any subdirectories, change,
/// FileWatcher::sig_file_changed is triggered.
void watch_files_in(const std::filesystem::path& dir);
boost::signals2::signal<void(const std::filesystem::path&)> sig_file_changed {};
private:
/// Entry point for the timer thread.
void thread_main();
/// Called every time the timer runs out, watches for file changes, then starts
/// a new timer.
void on_tick(const boost::system::error_code&);
/// Checks files for changes, calls FileWatcher::sig_file_changed on change.
void check_files();
/// Checks directories for files which changed, calls FileWatcher::sig_file_changed on change.
void check_directories();
/// Checks a single file for change.
void check_file(const std::filesystem::path& file);
/// Interval in seconds for the timer. Needed to be able to restart the timer over and over.
boost::synchronized_value<boost::posix_time::seconds> m_seconds;
/// If set, the thread handling the file watching will shut down. Set in the destructor.
boost::synchronized_value<bool> m_shutdown { false };
/// Io context handles the scheduling of timers on the thread.
boost::asio::io_context m_io {};
/// Holds all files that are to be checked.
///
/// It uses a boost::hash<> because in the original C++17
/// standard, std::hash of a filesystem path was not defined, and as such
/// some implementations still don't have it.
/// See https://cplusplus.github.io/LWG/issue3657
boost::synchronized_value<std::unordered_set<std::filesystem::path, boost::hash<std::filesystem::path>>> m_files {};
/// Holds all the directories that are to be searched for files to be checked.
///
/// See FileWatcher::m_files for an explanation for the boost::hash.
boost::synchronized_value<std::unordered_set<std::filesystem::path, boost::hash<std::filesystem::path>>> m_dirs {};
/// Holds the last known modification times of all found files.
std::unordered_map<std::filesystem::path, std::filesystem::file_time_type, boost::hash<std::filesystem::path>> m_file_mod_times {};
/// Timer used to time the checks. Restarted every FileWatcher::m_seconds seconds.
boost::synchronized_value<boost::asio::deadline_timer> m_timer;
/// Work guard helps the io_context "sleep" while there is no work to be done - must be reset in the
/// destructor in order to not cause work to be thrown away (though in this case we probably don't care).
boost::asio::executor_work_guard<boost::asio::io_context::executor_type> m_work_guard = boost::asio::make_work_guard(m_io);
/// Thread on which all watching and timing work runs.
boost::scoped_thread<> m_thread;
};

22
include/HashMap.h Normal file
View File

@@ -0,0 +1,22 @@
#pragma once
/// @file
/// HashMap holds hash map implementations and typedefs.
///
/// The idea is that we can easily swap out the implementation
/// in case there is a performance or memory usage concern.
#include <boost/container/flat_map.hpp>
#include <boost/thread/synchronized_value.hpp>
/// A hash map to be used for any kind of small number of key-value pairs.
/// Iterators and pointers may be invalidated on modification.
template<typename K, typename V>
using HashMap = boost::container::flat_map<K, V>;
/// A synchronized hash map is a hash map in which each
/// access is thread-safe. In this case, this is achieved by locking
/// each access with a mutex (which often ends up being a futex in the implementation).
template<typename K, typename V>
using SynchronizedHashMap = boost::synchronized_value<boost::container::flat_map<K, V>>;

View File

@@ -1,12 +1,60 @@
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <Common.h>
#include <IThreaded.h>
#include <filesystem>
#include <string>
#include <unordered_map>
#if defined(BEAMMP_LINUX)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#pragma GCC diagnostic ignored "-Wcast-qual"
#pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
#include <httplib.h>
#if defined(BEAMMP_LINUX)
#pragma GCC diagnostic pop
#endif
namespace fs = std::filesystem;
namespace Http {
std::string GET(const std::string& host, int port, const std::string& target, unsigned int* status = nullptr);
std::string POST(const std::string& host, const std::string& target, const std::unordered_map<std::string, std::string>& fields, const std::string& body, bool json, int* status = nullptr);
std::string POST(const std::string& host, int port, const std::string& target, const std::string& body, const std::string& ContentType, unsigned int* status = nullptr, const httplib::Headers& headers = {});
namespace Status {
std::string ToString(int code);
}
const std::string ErrorString = "-1";
namespace Server {
class THttpServerInstance {
public:
THttpServerInstance();
protected:
void operator()();
private:
std::thread mThread;
};
}
}

View File

@@ -1,5 +1,24 @@
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <boost/thread/scoped_thread.hpp>
#include <thread>
// pure virtual class to be inherited from by classes which intend to be threaded
@@ -8,12 +27,15 @@ public:
IThreaded()
// invokes operator() on this object
: mThread() { }
virtual ~IThreaded() noexcept {
mThread.interrupt();
}
virtual void Start() final {
mThread = std::thread([this] { (*this)(); });
mThread = boost::scoped_thread<>([this] { (*this)(); });
}
virtual void operator()() = 0;
protected:
std::thread mThread;
boost::scoped_thread<> mThread {};
};

View File

@@ -1,6 +1,20 @@
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// Created by anon on 4/21/21.
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "rapidjson/stringbuffer.h"

71
include/LuaAPI.h Normal file
View File

@@ -0,0 +1,71 @@
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <sol/sol.hpp>
#include <string>
#include <tuple>
#include <utility>
namespace LuaAPI {
namespace MP {
std::string GetOSName();
std::tuple<int, int, int> GetServerVersion();
std::pair<bool, std::string> TriggerClientEvent(int PlayerID, const std::string& EventName, const sol::object& Data);
std::pair<bool, std::string> TriggerClientEventJson(int PlayerID, const std::string& EventName, const sol::table& Data);
size_t GetPlayerCount();
std::pair<bool, std::string> DropPlayer(int ID, std::optional<std::string> MaybeReason);
std::pair<bool, std::string> SendChatMessage(int ID, const std::string& Message);
std::pair<bool, std::string> RemoveVehicle(int PlayerID, int VehicleID);
void Set(int ConfigID, sol::object NewValue);
bool IsPlayerGuest(int ID);
bool IsPlayerConnected(int ID);
/// Returns the current time in millisecond accuracy.
size_t GetTimeMS();
/// Returns the current time in seconds, with millisecond accuracy (w/ decimal point).
double GetTimeS();
}
namespace Util {
std::string JsonEncode(const sol::object& object);
sol::table JsonDecode(sol::this_state s, const std::string& string);
std::string JsonDiff(const std::string& a, const std::string& b);
std::string JsonDiffApply(const std::string& data, const std::string& patch);
std::string JsonPrettify(const std::string& json);
std::string JsonMinify(const std::string& json);
std::string JsonFlatten(const std::string& json);
std::string JsonUnflatten(const std::string& json);
}
namespace FS {
std::pair<bool, std::string> CreateDirectory(const std::string& Path);
std::pair<bool, std::string> Remove(const std::string& Path);
std::pair<bool, std::string> Rename(const std::string& Path, const std::string& NewPath);
std::pair<bool, std::string> Copy(const std::string& Path, const std::string& NewPath);
std::string GetFilename(const std::string& Path);
std::string GetExtension(const std::string& Path);
std::string GetParentFolder(const std::string& Path);
bool Exists(const std::string& Path);
bool IsDirectory(const std::string& Path);
bool IsFile(const std::string& Path);
std::string ConcatPaths(sol::variadic_args Args);
sol::table ListFiles(sol::this_state s, const std::string& path);
sol::table ListDirectories(sol::this_state s, const std::string& path);
}
}

144
include/LuaPlugin.h Normal file
View File

@@ -0,0 +1,144 @@
#pragma once
#include "Common.h"
#include "FileWatcher.h"
#include "HashMap.h"
#include "Plugin.h"
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/post.hpp>
#include <boost/date_time/posix_time/posix_time_duration.hpp>
#include <boost/signals2.hpp>
#include <boost/thread/scoped_thread.hpp>
#include <boost/thread/synchronized_value.hpp>
#include <sol/forward.hpp>
#include <sol/variadic_args.hpp>
#include <spdlog/logger.h>
#include <sol/sol.hpp>
struct Timer {
Timer(boost::asio::deadline_timer&& timer_, long interval_)
: timer(std::move(timer_))
, interval(interval_) { }
boost::asio::deadline_timer timer;
boost::posix_time::milliseconds interval;
};
static constexpr const char* BEAMMP_MEMORY_STATE = ":console:";
class LuaPlugin : public Plugin {
public:
/// Declare a new plugin with the path.
/// Loading of any files only happens on LuaPlugin::initialize().
LuaPlugin(const std::string& path);
/// Shuts down lua thread, may hang if there is still work to be done.
~LuaPlugin();
template <typename FnT>
void register_function(const std::string& table, const std::string& identifier, const FnT& func) {
boost::asio::post(m_io, [this, table, identifier, func] {
if (!m_state.globals()[table].valid()) {
m_state.globals().create_named(table);
}
if (m_state.globals()[table][identifier].valid()) {
beammp_errorf("Global '{}.{}' already exists and could not be injected as function.", table, identifier);
} else {
m_state.globals()[table][identifier] = func;
}
});
}
/// Dangerous: Only use this on a special memory state.
/// Results are *printed to stdout*.
void run_raw_lua(const std::string& raw);
private:
/// Initializes the error handlers for panic and exceptions.
Error initialize_error_handlers();
/// Initializes / loads base packages and libraries.
Error initialize_libraries();
/// Loads main file of the plugin.
Error load_files();
/// Overrides functions such as `print()`
Error initialize_overrides();
/// Fixes lua's package.path and package.cpath to understand our own file structure better.
Error fix_lua_paths();
/// Loads an extension. Call this from the lua thread.
/// This function cannot fail, as it reports errors to the user.
void load_extension(const std::filesystem::path& file, const std::string& ext_name);
/// Loads all extension from the folder, using the base as a prefix.
/// This function is recursive.
/// Returns the amount of extensions found. This function cannot fail.
size_t load_extensions(const std::filesystem::path& extensions_folder, const std::string& base = "");
/// Entry point for the lua plugin's thread.
void thread_main();
// Plugin interface
public:
/// Initializes the Lua Plugin, loads file(s), starts executing code.
virtual Error initialize() override;
// TODO cleanup
virtual Error cleanup() override;
// TODO reload
virtual Error reload() override;
/// Name of this lua plugin (the base name of the folder).
virtual std::string name() const override;
/// Path to the folder containing this lua plugin.
virtual std::filesystem::path path() const override;
/// Dispatches the event to the thread which runs all lua.
virtual std::shared_future<std::vector<Value>> handle_event(const std::string& event_name, const std::shared_ptr<Value>& args) override;
/// Returns the memory usage of this thread, updated at the slowest every 5 seconds.
virtual size_t memory_usage() const override;
private:
/// Path to the plugin's root folder.
std::filesystem::path m_path;
/// Thread where all lua work must happen. Started within the constructor but is blocked until LuaPlugin::initialize is called
boost::scoped_thread<> m_thread;
/// This asio context schedules all tasks. It's run in the m_thread thread.
boost::asio::io_context m_io;
/// Event handlers which are legacy-style (by name)
HashMap<std::string, std::vector<std::string>> m_event_handlers_named {};
/// Event handlers which are functions (v4 style)
HashMap<std::string, std::vector<sol::protected_function>> m_event_handlers {};
/// Main (and usually only) lua state of this plugin.
/// ONLY access this from the m_thread thread.
sol::state m_state;
/// Whether the lua thread should shutdown. Triggered by the LuaPlugin::~LuaPlugin dtor.
boost::synchronized_value<bool> m_shutdown { false };
/// Current memory usage. Cached to avoid having to synchronize access to the lua state.
boost::synchronized_value<size_t> m_memory { 0 };
/// Hash map of all event handlers in this state.
// HashMap<std::string, sol::protected_function> m_event_handlers {};
SynchronizedHashMap<std::string, std::filesystem::path> m_known_extensions {};
boost::asio::executor_work_guard<boost::asio::io_context::executor_type> m_work_guard = boost::asio::make_work_guard(m_io);
/// Iteration options to be used whenever iterating over a directory in this class.
static inline auto s_directory_iteration_options = std::filesystem::directory_options::follow_directory_symlink | std::filesystem::directory_options::skip_permission_denied;
FileWatcher m_extensions_watcher { 2 };
boost::signals2::connection m_extensions_watch_conn;
std::vector<std::shared_ptr<Timer>> m_timers {};
std::shared_ptr<Timer> make_timer(size_t ms);
void cancel_timer(const std::shared_ptr<Timer>& timer);
// Lua API
/// Override for lua's base.print().
/// Dumps tables, arrays, etc. properly.
void l_print(const sol::variadic_args&);
std::shared_ptr<Timer> l_mp_schedule_call_repeat(size_t ms, const sol::function& fn, sol::variadic_args args);
void l_mp_schedule_call_helper(const boost::system::error_code& err, std::shared_ptr<Timer> timer, const sol::function& fn, std::shared_ptr<ValueTuple> args);
void l_mp_schedule_call_once(size_t ms, const sol::function& fn, sol::variadic_args args);
std::string print_impl(const std::vector<sol::object>&);
};

250
include/Network.h Normal file
View File

@@ -0,0 +1,250 @@
#pragma once
#include "Common.h"
#include "Packet.h"
#include "State.h"
#include "Sync.h"
#include "Transport.h"
#include "Util.h"
#include <boost/asio.hpp>
#include <boost/asio/execution_context.hpp>
#include <boost/asio/thread_pool.hpp>
#include <boost/thread/scoped_thread.hpp>
#include <boost/thread/synchronized_value.hpp>
#include <cstdint>
#include <filesystem>
#include <glm/detail/qualifier.hpp>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <memory>
#include <mutex>
#include <nlohmann/json.hpp>
#include <optional>
#include <unordered_map>
#include <vector>
using ClientID = uint32_t;
using VehicleID = uint16_t;
using namespace boost::asio;
struct Client : std::enable_shared_from_this<Client> {
using StrandPtr = std::shared_ptr<boost::asio::strand<ip::tcp::socket::executor_type>>;
using Ptr = std::shared_ptr<Client>;
ClientID id;
Sync<bmp::State> state { bmp::State::None };
Sync<std::string> name;
Sync<std::string> role;
Sync<bool> is_guest;
Sync<std::unordered_map<std::string /* identifier */, std::string /* value */>> identifiers;
/// Writes the packet to the TCP stream. Blocks all other writes.
void tcp_write(bmp::Packet& packet);
/// Writes the specified to the TCP stream without a header or any metadata - use in
/// conjunction with something else. Blocks other writes.
void tcp_write_file_raw(const std::filesystem::path& path);
/// Ensures no client is ever created as a non-shared-ptr, so that enable_shared_from_this works.
static Client::Ptr make_ptr(ClientID new_id, class Network& network, ip::tcp::socket&& tcp_socket);
~Client();
ip::tcp::socket& tcp_socket() { return m_tcp_socket; }
void start_tcp();
/// Used to associate the udp socket with this client.
/// This isn't very secure and still allows spoofing of the UDP connection (technically),
/// but better than simply using the ID like the old protocol.
const uint64_t udp_magic;
const ip::udp::endpoint& udp_endpoint() const { return m_udp_endpoint; }
void set_udp_endpoint(const ip::udp::endpoint& ep) { m_udp_endpoint = ep; }
private:
/// Ctor must be private to ensure all clients are constructed as shared_ptr to enable_shared_from_this.
Client(ClientID id, class Network& network, ip::tcp::socket&& tcp_socket);
/// Call this when the client seems to have timed out. Will send a ping and set a flag.
/// Returns true if try-again, false if the connection was closed.
[[nodiscard]] bool handle_timeout();
bool m_timed_out { false };
/// Timeout used for typical tcp reads.
boost::posix_time::milliseconds m_read_timeout { 5000 };
/// Timeout used for typical tcp writes. Specified in milliseconds per byte.
/// For example, 10 mbit/s works out to 1250 B/ms, so a value of 1250 here would
/// cause clients with >10 mbit/s download speed to usually not time out.
/// This is done because a write is considered completed when all data is written,
/// and worst-case this could mean that we're limited by their download speed.
/// We're setting it to 50, which will drop clients who are below a download speed + ping
/// combination of 0.4 mbit/s.
double m_write_byte_timeout { 0.01 };
/// Timeout used for mod download tcp writes.
/// This is typically orders of magnitude larger
/// to allow for slow downloads.
boost::posix_time::milliseconds m_download_write_timeout { 60000 };
std::mutex m_tcp_read_mtx;
std::mutex m_tcp_write_mtx;
std::mutex m_udp_read_mtx;
ip::tcp::socket m_tcp_socket;
boost::scoped_thread<> m_tcp_thread;
std::vector<uint8_t> m_header { bmp::Header::SERIALIZED_SIZE };
bmp::Packet m_packet {};
ip::udp::endpoint m_udp_endpoint;
class Network& m_network;
StrandPtr m_tcp_strand;
};
struct Vehicle {
using Ptr = std::shared_ptr<Vehicle>;
Sync<ClientID> owner;
Sync<std::vector<uint8_t>> data;
Vehicle(std::span<uint8_t> raw_data)
: data(std::vector<uint8_t>(raw_data.begin(), raw_data.end())) {
reset_status(data.get());
}
/// Resets all status fields to zero and reads any statuses present in the data into the fields.
void reset_status(std::span<const uint8_t> status_data);
struct Status {
glm::vec3 rvel {};
glm::vec4 rot {};
glm::vec3 vel {};
glm::vec3 pos {};
float time {};
};
Status get_status();
void update_status(std::span<const uint8_t> raw_packet);
const std::vector<uint8_t>& get_raw_status() const { return m_status_data; }
private:
std::recursive_mutex m_mtx;
/// Holds pos, rvel, vel, etc. raw, updated every time
/// such a packet arrives.
std::vector<uint8_t> m_status_data;
/// Parses the status_data on request sets needs_refresh = false.
void refresh_cache(std::unique_lock<std::recursive_mutex>& lock);
bool m_needs_refresh = false;
glm::vec3 m_rvel {};
glm::vec4 m_rot {};
glm::vec3 m_vel {};
glm::vec3 m_pos {};
float m_time {};
};
class Network {
public:
Network();
~Network();
friend Client;
void disconnect(ClientID id, const std::string& msg);
void send_to(ClientID id, bmp::Packet& packet);
/// Returns a map of <id, client> containing only clients which are
/// fully connected, i.e. who have mods downloaded and everything spawned in.
/// If you're unsure which to use, use this one.
std::unordered_map<ClientID, Client::Ptr> playing_clients() const;
/// Returns a map of <id, client> containing only clients who are authenticated.
std::unordered_map<ClientID, Client::Ptr> authenticated_clients() const;
/// Returns all clients, including non-authenticated clients. Use only for debugging,
/// information, stats, status.
std::unordered_map<ClientID, Client::Ptr> all_clients() const;
std::optional<Client::Ptr> get_client(ClientID id, bmp::State min_state) const;
std::unordered_map<VehicleID, Vehicle::Ptr> get_vehicles_owned_by(ClientID id);
std::optional<Vehicle::Ptr> get_vehicle(VehicleID id);
/// Builds the SessionSetup.PlayersInfo json which contains all player info and all vehicles.
nlohmann::json build_players_info();
size_t authenticated_client_count() const;
size_t clients_in_state_count(bmp::State state) const;
size_t guest_count() const;
size_t vehicle_count() const;
/// Creates a Playing state packet from uncompressed data.
bmp::Packet make_playing_packet(bmp::Purpose purpose, ClientID from_id, VehicleID veh_id, const std::vector<uint8_t>& data);
/// Sends a <System> or <Server> chat message to all or only one client(s).
void send_system_chat_message(const std::string& msg, ClientID to = 0xffffffff);
/// To be called by accept() async handler once an accept() is completed.
void accept();
/// Gets the async i/o context of the network - can be used to "schedule" tasks on it.
boost::asio::thread_pool& context() {
return m_threadpool;
}
private:
void handle_packet(ClientID id, const bmp::Packet& packet);
/// Reads a packet from the given UDP socket, returning the client's endpoint as an out-argument.
bmp::Packet udp_read(ip::udp::endpoint& out_ep);
/// Sends a packet to the specified UDP endpoint via the UDP socket.
void udp_write(bmp::Packet& packet, const ip::udp::endpoint& ep);
void udp_read_main();
void tcp_listen_main();
/// Handles all packets which are allowed during the Identification state.
void handle_identification(ClientID id, const bmp::Packet& packet, std::shared_ptr<Client>& client);
/// Handles all packets which are allowed during the Authentication state.
void handle_authentication(ClientID id, const bmp::Packet& packet, std::shared_ptr<Client>& client);
/// Handles all packets which are allowed during the ModDownload state.
void handle_mod_download(ClientID id, const bmp::Packet& packet, std::shared_ptr<Client>& client);
/// Handles all packets which are allowed during the SessionSetup state.
void handle_session_setup(ClientID id, const bmp::Packet& packet, std::shared_ptr<Client>& client);
/// Handles all packets which are allowed during the Playing state.
void handle_playing(ClientID id, const bmp::Packet& packet, std::shared_ptr<Client>& client);
/// On failure, throws an exception with the error for the client.
static void authenticate_user(const std::string& public_key, std::shared_ptr<Client>& client);
/// Called by accept() once completed (completion handler).
void handle_accept(const boost::system::error_code& ec);
Sync<std::unordered_map<ClientID, Client::Ptr>> m_clients {};
Sync<std::unordered_map<VehicleID, Vehicle::Ptr>> m_vehicles {};
Sync<std::unordered_map<uint64_t, ClientID>> m_client_magics {};
Sync<std::unordered_map<ip::udp::endpoint, ClientID>> m_udp_endpoints {};
ClientID new_client_id();
VehicleID new_vehicle_id();
thread_pool m_threadpool { std::thread::hardware_concurrency() };
Sync<bool> m_shutdown { false };
ip::udp::socket m_udp_socket { m_threadpool };
ip::tcp::socket m_tcp_listener { m_threadpool };
ip::tcp::acceptor m_tcp_acceptor { m_threadpool };
/// This socket gets accepted into, and is then moved.
ip::tcp::socket m_temp_socket { m_threadpool };
boost::scoped_thread<> m_tcp_listen_thread;
boost::scoped_thread<> m_udp_read_thread;
};

68
include/Plugin.h Normal file
View File

@@ -0,0 +1,68 @@
#pragma once
#include "Error.h"
#include "Value.h"
#include <filesystem>
#include <future>
#include <utility>
#include <variant>
/// The Plugin class is an abstract interface for any plugin.
///
/// A plugin must itself figure out how to deal with events, load itself,
/// and must react quickly and appropriately to any incoming events or function calls.
/// A plugin may *not* ever block a calling thread unless explicitly marked with
/// "this may block the caller" or similar.
class Plugin {
public:
/// Self-managing pointer type of this plugin.
using Pointer = std::shared_ptr<Plugin>;
/// Allocates a Plugin of the specific derived plugin type.
template <typename T, typename... Args>
static Pointer make_pointer(Args&&... args) {
return std::shared_ptr<Plugin>(new T(std::forward<Args>(args)...));
}
/// Default constructor to enable derived classes to default-construct.
Plugin() = default;
/// Plugin is not copyable.
Plugin(const Plugin&) = delete;
/// Plugin is not copyable.
Plugin& operator=(const Plugin&) = delete;
/// Plugin is movable.
Plugin(Plugin&&) = default;
/// Plugin is movable.
Plugin& operator=(Plugin&&) = default;
/// Default destructor but virtual, to make the compiler happy.
virtual ~Plugin() = default;
/// Called when the plugin should initialize its state.
/// This may block the caller.
virtual Error initialize() = 0;
/// Called when the plugin should tear down and clean up its state.
/// This may block the caller.
virtual Error cleanup() = 0;
/// Called when the plugin should be reloaded. Usually it's a good idea
/// to notify the plugin's code, call cleanup(), etc. internally.
virtual Error reload() = 0;
/// Returns the name of the plugin.
virtual std::string name() const = 0;
/// Returns the path to the plugin - this can either be the folder in which
/// the plugin's files live, or the plugin itself if it's a single file.
/// The exact format of what this returns (directory/file) is implementation defined.
virtual std::filesystem::path path() const = 0;
/// Instructs the plugin to handle the given event, with the given arguments.
/// Returns a future with a result if this event will be handled by the plugin, otherwise must return
/// std::nullopt.
virtual std::shared_future<std::vector<Value>> handle_event(const std::string& event_name, const std::shared_ptr<Value>& args) = 0;
/// Returns how much memory this state thinks it uses.
///
/// This value is difficult to calculate for some use-cases, but a rough ballpark
/// should be returned regardless.
virtual size_t memory_usage() const = 0;
};

73
include/PluginManager.h Normal file
View File

@@ -0,0 +1,73 @@
#pragma once
#include "HashMap.h"
#include "Plugin.h"
/// The PluginManager class manages all plugins, specifically their lifetime,
/// events and memory.
class PluginManager {
public:
/// Iterates through all plugins, ask them for their usage, take the sum.
size_t memory_usage() const {
size_t total = 0;
auto plugins = m_plugins.synchronize();
for (const auto& [name, plugin] : *plugins) {
(void)name; // name ignored
total += plugin->memory_usage();
}
return total;
}
/// Triggers (sends) the event to all plugins and gathers the results as futures.
///
/// PLEASE be aware that some plugins' handlers may take a while to handle the event,
/// so try not to wait on these futures without a timeout.
///
/// This function should not block.
std::vector<std::shared_future<std::vector<Value>>> trigger_event(const std::string& event_name, const std::shared_ptr<Value>& args) {
// results will go in here
std::vector<std::shared_future<std::vector<Value>>> results;
// synchronize practically grabs a lock to the mutex, this is (as the name suggests)
// a synchronization point. technically, it could dead-lock if something that is called
// in this locked context tries to lock the m_plugins mutex.
// Plugin::handle_event should NEVER do much else than dispatch the event to the
// plugin's main thread, so this really cannot happen.
// that said, if you end up here with gdb, make sure it doesn't ;)
auto plugins = m_plugins.synchronize();
// allocate as many as we could possibly have, to avoid realloc()'s
results.reserve(plugins->size());
for (const auto& [name, plugin] : *plugins) {
(void)name; // ignore the name
// propagates the event to the plugin, this returns a future
// we assume that at this point no plugin-specific code has executed
auto result = plugin->handle_event(event_name, args);
// if the plugin had no handler, this result has no value, and we can ignore it
results.push_back(std::move(result));
}
return results;
}
/// Adds the plugin, calls Plugin::initialize(), and so on
[[nodiscard]] Error add_plugin(Plugin::Pointer plugin) {
auto plugins = m_plugins.synchronize();
if (plugins->contains(plugin->name())) {
return Error("Plugin with the name '{}' already exists, refusing to replace it.", plugin->name());
} else {
auto [iter, b] = plugins->insert({ plugin->name(), std::move(plugin) });
(void)b; // ignore b
auto err = iter->second->initialize();
if (err) {
return err;
}
return {};
}
}
HashMap<std::string, Plugin::Pointer> get_plugins() {
return *m_plugins;
}
private:
/// All plugins as pointers to allow inheritance.
SynchronizedHashMap<std::string, Plugin::Pointer> m_plugins;
};

View File

@@ -1,4 +1,21 @@
// Author: lionkor
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
/*

View File

@@ -1,3 +1,21 @@
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
void SetupSignalHandlers();

View File

@@ -1,69 +0,0 @@
#pragma once
#include <atomic>
#include <deque>
#include <mutex>
#include <sio_client.h>
#include <thread>
#include <memory>
/*
* We send relevant server events over socket.io to the backend.
*
* We send all events to `backend.beammp.com`, to the room `/key`
* where `key` is the currently active auth-key.
*/
enum class SocketIOEvent {
ConsoleOut,
CPUUsage,
MemoryUsage,
NetworkUsage,
PlayerList,
};
enum class SocketIORoom {
None,
Stats,
Player,
Info,
Console,
};
class SocketIO final {
private:
struct Event;
public:
enum class EventType {
};
// Singleton pattern
static SocketIO& Get();
void Emit(SocketIOEvent Event, const std::string& Data);
~SocketIO();
void SetAuthenticated(bool auth) { mAuthenticated = auth; }
private:
SocketIO() noexcept;
void ThreadMain();
struct Event {
std::string Name;
std::string Data;
};
bool mAuthenticated { false };
sio::client mClient;
std::thread mThread;
std::atomic_bool mCloseThread { false };
std::mutex mQueueMutex;
std::deque<Event> mQueue;
friend std::unique_ptr<SocketIO> std::make_unique<SocketIO>();
};

10
include/Sync.h Normal file
View File

@@ -0,0 +1,10 @@
#pragma once
#include <boost/thread/synchronized_value.hpp>
#include <mutex>
/// This header provides convenience aliases for synchronization primitives.
template<typename T>
using Sync = boost::synchronized_value<T, std::recursive_mutex>;

View File

@@ -1,21 +1,52 @@
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "Common.h"
#include <atomic>
#include <filesystem>
#define TOML11_PRESERVE_COMMENTS_BY_DEFAULT
#include <toml.hpp> // header-only version of TOML++
namespace fs = std::filesystem;
class TConfig {
public:
explicit TConfig();
explicit TConfig(const std::string& ConfigFileName);
[[nodiscard]] bool Failed() const { return mFailed; }
void FlushToFile();
private:
void CreateConfigFile(std::string_view name);
void CreateConfigFile();
void ParseFromFile(std::string_view name);
void PrintDebug();
void TryReadValue(toml::value& Table, const std::string& Category, const std::string_view& Key, const std::string_view& Env, std::string& OutValue);
void TryReadValue(toml::value& Table, const std::string& Category, const std::string_view& Key, const std::string_view& Env, bool& OutValue);
void TryReadValue(toml::value& Table, const std::string& Category, const std::string_view& Key, const std::string_view& Env, int& OutValue);
void ParseOldFormat();
std::string TagsAsPrettyArray() const;
bool IsDefault();
bool mFailed { false };
std::string mConfigFileName;
};

View File

@@ -1,20 +1,90 @@
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "commandline/commandline.h"
#include "TLuaFile.h"
#include "Cryptography.h"
#include "LuaPlugin.h"
#include "TScopedTimer.h"
#include "commandline.h"
#include <atomic>
#include <fstream>
#include <functional>
#include <mutex>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
class TConsole {
public:
TConsole();
// Initializes the commandline app to take over I/O
void InitializeCommandline();
void Write(const std::string& str);
void WriteRaw(const std::string& str);
void InitializeLuaConsole(TLuaEngine& Engine);
// void InitializeLuaConsole(TLuaEngine& Engine);
void BackupOldLog();
void StartLoggingToFile();
Commandline& Internal() { return *mCommandline; }
private:
std::unique_ptr<TLuaFile> mLuaConsole { nullptr };
Commandline mCommandline;
void RunAsCommand(const std::string& cmd, bool IgnoreNotACommand = false);
void ChangeToLuaConsole(const std::string& LuaStateId);
void ChangeToRegularConsole();
void HandleLuaInternalCommand(const std::string& cmd);
void Command_Lua(const std::string& cmd, const std::vector<std::string>& args);
void Command_Help(const std::string& cmd, const std::vector<std::string>& args);
void Command_Kick(const std::string& cmd, const std::vector<std::string>& args);
void Command_List(const std::string& cmd, const std::vector<std::string>& args);
void Command_Status(const std::string& cmd, const std::vector<std::string>& args);
void Command_Settings(const std::string& cmd, const std::vector<std::string>& args);
void Command_Clear(const std::string&, const std::vector<std::string>& args);
void Command_Say(const std::string& FullCommand);
bool EnsureArgsCount(const std::vector<std::string>& args, size_t n);
bool EnsureArgsCount(const std::vector<std::string>& args, size_t min, size_t max);
static std::tuple<std::string, std::vector<std::string>> ParseCommand(const std::string& cmd);
static std::string ConcatArgs(const std::vector<std::string>& args, char space = ' ');
std::unordered_map<std::string, std::function<void(const std::string&, const std::vector<std::string>&)>> mCommandMap = {
{ "lua", [this](const auto& a, const auto& b) { Command_Lua(a, b); } },
{ "help", [this](const auto& a, const auto& b) { Command_Help(a, b); } },
{ "kick", [this](const auto& a, const auto& b) { Command_Kick(a, b); } },
{ "list", [this](const auto& a, const auto& b) { Command_List(a, b); } },
{ "status", [this](const auto& a, const auto& b) { Command_Status(a, b); } },
{ "settings", [this](const auto& a, const auto& b) { Command_Settings(a, b); } },
{ "clear", [this](const auto& a, const auto& b) { Command_Clear(a, b); } },
{ "say", [this](const auto&, const auto&) { Command_Say(""); } }, // shouldn't actually be called
};
std::unique_ptr<Commandline> mCommandline { nullptr };
std::vector<std::string> mCachedLuaHistory;
std::vector<std::string> mCachedRegularHistory;
bool mIsLuaConsole { false };
bool mFirstTime { true };
std::string mStateId;
const std::string mDefaultStateId = BEAMMP_MEMORY_STATE;
std::ofstream mLogFileStream;
std::mutex mLogFileStreamMtx;
TScopedTimer mUptimeTimer{};
};

View File

@@ -1,13 +1,30 @@
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "Common.h"
#include "IThreaded.h"
#include "TResourceManager.h"
#include "TServer.h"
#include "Network.h"
class THeartbeatThread : public IThreaded {
public:
THeartbeatThread(TResourceManager& ResourceManager, TServer& Server);
THeartbeatThread(std::shared_ptr<Network> network);
//~THeartbeatThread();
void operator()() override;
@@ -15,7 +32,5 @@ private:
std::string GenerateCall();
std::string GetPlayers();
bool mShutdown = false;
TResourceManager& mResourceManager;
TServer& mServer;
};
std::shared_ptr<Network> m_network;
};

View File

@@ -1,39 +0,0 @@
#pragma once
#include "Common.h"
#include "IThreaded.h"
#include "TLuaFile.h"
#include "TServer.h"
#include <lua.hpp>
#include <memory>
#include <optional>
#include <set>
class TLuaEngine : public IThreaded {
public:
explicit TLuaEngine(TServer& Server, TNetwork& Network);
using TSetOfLuaFile = std::set<std::unique_ptr<TLuaFile>>;
void operator()() override;
[[nodiscard]] const TSetOfLuaFile& LuaFiles() const { return mLuaFiles; }
[[nodiscard]] TServer& Server() { return mServer; }
[[nodiscard]] const TServer& Server() const { return mServer; }
[[nodiscard]] TNetwork& Network() { return mNetwork; }
[[nodiscard]] const TNetwork& Network() const { return mNetwork; }
std::optional<std::reference_wrapper<TLuaFile>> GetScript(lua_State* L);
private:
void FolderList(const std::string& Path, bool HotSwap);
void RegisterFiles(const fs::path& Path, bool HotSwap);
bool IsNewFile(const std::string& Path);
TNetwork& mNetwork;
TServer& mServer;
std::string mPath;
bool mShutdown { false };
TSetOfLuaFile mLuaFiles;
std::mutex mListMutex;
};

View File

@@ -1,62 +0,0 @@
#ifndef TLUAFILE_H
#define TLUAFILE_H
#include <any>
#include <filesystem>
#include <lua.hpp>
#include <mutex>
#include <set>
#include <string>
#include <vector>
namespace fs = std::filesystem;
struct TLuaArg {
std::vector<std::any> args;
void PushArgs(lua_State* State);
};
class TLuaEngine;
class TLuaFile {
public:
void RegisterEvent(const std::string& Event, const std::string& FunctionName);
void UnRegisterEvent(const std::string& Event);
void SetLastWrite(fs::file_time_type time);
bool IsRegistered(const std::string& Event);
void SetPluginName(const std::string& Name);
void Execute(const std::string& Command);
void SetFileName(const std::string& Name);
fs::file_time_type GetLastWrite();
lua_State* GetState();
std::string GetOrigin();
std::mutex Lock;
void Reload();
void Init(const std::string& PluginName, const std::string& FileName, fs::file_time_type LastWrote);
explicit TLuaFile(TLuaEngine& Engine, bool Console = false);
~TLuaFile();
void SetStopThread(bool StopThread) { mStopThread = StopThread; }
TLuaEngine& Engine() { return mEngine; }
[[nodiscard]] std::string GetPluginName() const;
[[nodiscard]] std::string GetFileName() const;
[[nodiscard]] const lua_State* GetState() const;
[[nodiscard]] bool GetStopThread() const { return mStopThread; }
[[nodiscard]] const TLuaEngine& Engine() const { return mEngine; }
[[nodiscard]] std::string GetRegistered(const std::string& Event) const;
private:
TLuaEngine& mEngine;
std::set<std::pair<std::string, std::string>> mRegisteredEvents;
lua_State* mLuaState { nullptr };
fs::file_time_type mLastWrote;
std::string mPluginName {};
std::string mFileName {};
bool mStopThread = false;
bool mConsole = false;
void Load();
std::mutex mInitMutex;
};
std::any TriggerLuaEvent(const std::string& Event, bool local, TLuaFile* Caller, std::shared_ptr<TLuaArg> arg, bool Wait);
#endif // TLUAFILE_H

View File

@@ -1,49 +0,0 @@
#pragma once
#include "Compat.h"
#include "TResourceManager.h"
#include "TServer.h"
class TNetwork {
public:
TNetwork(TServer& Server, TPPSMonitor& PPSMonitor, TResourceManager& ResourceManager);
[[nodiscard]] bool TCPSend(TClient& c, const std::string& Data, bool IsSync = false);
[[nodiscard]] bool SendLarge(TClient& c, std::string Data, bool isSync = false);
[[nodiscard]] bool Respond(TClient& c, const std::string& MSG, bool Rel, bool isSync = false);
std::shared_ptr<TClient> CreateClient(SOCKET TCPSock);
std::string TCPRcv(TClient& c);
void ClientKick(TClient& c, const std::string& R);
[[nodiscard]] bool SyncClient(const std::weak_ptr<TClient>& c);
void Identify(SOCKET TCPSock);
void Authentication(SOCKET TCPSock);
[[nodiscard]] bool CheckBytes(TClient& c, int32_t BytesRcv);
void SyncResources(TClient& c);
[[nodiscard]] bool UDPSend(TClient& Client, std::string Data) const;
void SendToAll(TClient* c, const std::string& Data, bool Self, bool Rel);
void UpdatePlayer(TClient& Client);
private:
void UDPServerMain();
void TCPServerMain();
TServer& mServer;
TPPSMonitor& mPPSMonitor;
SOCKET mUDPSock {};
bool mShutdown { false };
TResourceManager& mResourceManager;
std::thread mUDPThread;
std::thread mTCPThread;
std::string UDPRcvFromClient(sockaddr_in& client) const;
void HandleDownload(SOCKET TCPSock);
void OnConnect(const std::weak_ptr<TClient>& c);
void TCPClient(const std::weak_ptr<TClient>& c);
void Looper(const std::weak_ptr<TClient>& c);
int OpenID();
void OnDisconnect(const std::weak_ptr<TClient>& ClientPtr, bool kicked);
void Parse(TClient& c, const std::string& Packet);
void SendFile(TClient& c, const std::string& Name);
static bool TCPSendRaw(TClient& C, SOCKET socket, char* Data, int32_t Size);
static void SplitLoad(TClient& c, size_t Sent, size_t Size, bool D, const std::string& Name);
};

View File

@@ -1,27 +0,0 @@
#pragma once
#include "Common.h"
#include "TServer.h"
#include <optional>
class TNetwork;
class TPPSMonitor : public IThreaded {
public:
explicit TPPSMonitor(TServer& Server);
void operator()() override;
void SetInternalPPS(int NewPPS) { mInternalPPS = NewPPS; }
void IncrementInternalPPS() { ++mInternalPPS; }
[[nodiscard]] int InternalPPS() const { return mInternalPPS; }
void SetNetwork(TNetwork& Server) { mNetwork = std::ref(Server); }
private:
TNetwork& Network() { return mNetwork->get(); }
TServer& mServer;
std::optional<std::reference_wrapper<TNetwork>> mNetwork { std::nullopt };
bool mShutdown { false };
int mInternalPPS { 0 };
};

View File

@@ -1,21 +0,0 @@
#pragma once
#include "Common.h"
class TResourceManager {
public:
TResourceManager();
[[nodiscard]] size_t MaxModSize() const { return mMaxModSize; }
[[nodiscard]] std::string FileList() const { return mFileList; }
[[nodiscard]] std::string TrimmedList() const { return mTrimmedList; }
[[nodiscard]] std::string FileSizes() const { return mFileSizes; }
[[nodiscard]] int ModsLoaded() const { return mModsLoaded; }
private:
size_t mMaxModSize = 0;
std::string mFileSizes;
std::string mFileList;
std::string mTrimmedList;
int mModsLoaded = 0;
};

43
include/TScopedTimer.h Normal file
View File

@@ -0,0 +1,43 @@
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <chrono>
#include <functional>
#include <string>
class TScopedTimer {
public:
TScopedTimer();
TScopedTimer(const std::string& Name);
TScopedTimer(std::function<void(size_t)> OnDestroy);
~TScopedTimer();
auto GetElapsedTime() const {
auto EndTime = std::chrono::high_resolution_clock::now();
auto Delta = EndTime - mStartTime;
size_t TimeDelta = Delta / std::chrono::milliseconds(1);
return TimeDelta;
}
std::function<void(size_t /* time_ms */)> OnDestroy { nullptr };
private:
std::chrono::high_resolution_clock::time_point mStartTime;
std::string Name;
};

View File

@@ -1,38 +0,0 @@
#ifndef SENTRY_H
#define SENTRY_H
#include <mutex>
#include <string>
#include <unordered_map>
enum class SentryLevel {
Debug = -1,
Info = 0,
Warning = 1,
Error = 2,
Fatal = 3,
};
// singleton, dont make this twice
class TSentry final {
public:
TSentry();
~TSentry();
void PrintWelcome();
void SetupUser();
void Log(SentryLevel level, const std::string& logger, const std::string& text);
void LogError(const std::string& text, const std::string& file, const std::string& line);
void SetContext(const std::string& context_name, const std::unordered_map<std::string, std::string>& map);
void LogException(const std::exception& e, const std::string& file, const std::string& line);
void LogAssert(const std::string& condition_string, const std::string& file, const std::string& line, const std::string& function);
void AddErrorBreadcrumb(const std::string& msg, const std::string& file, const std::string& line);
// cleared when Logged
void SetTransaction(const std::string& id);
[[nodiscard]] std::unique_lock<std::mutex> CreateExclusiveContext();
private:
bool mValid { true };
std::mutex mMutex;
};
#endif // SENTRY_H

View File

@@ -1,37 +0,0 @@
#pragma once
#include "IThreaded.h"
#include "RWMutex.h"
#include <functional>
#include <memory>
#include <mutex>
#include <unordered_set>
class TClient;
class TNetwork;
class TPPSMonitor;
class TServer final {
public:
using TClientSet = std::unordered_set<std::shared_ptr<TClient>>;
TServer(int argc, char** argv);
void InsertClient(const std::shared_ptr<TClient>& Ptr);
std::weak_ptr<TClient> InsertNewClient();
void RemoveClient(const std::weak_ptr<TClient>&);
// in Fn, return true to continue, return false to break
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::string Packet, TPPSMonitor& PPSMonitor, TNetwork& Network);
static void HandleEvent(TClient& c, const std::string& Data);
RWMutex& GetClientMutex() const { return mClientsMutex; }
private:
TClientSet mClients;
mutable RWMutex mClientsMutex;
static void ParseVehicle(TClient& c, const std::string& Pckt, TNetwork& Network);
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);
};

269
include/Value.h Normal file
View File

@@ -0,0 +1,269 @@
#pragma once
/// @file
/// The Value.h file describes a collection of wrapper types for use in
/// cross-plugin communication and similar. These wrapper types are
/// typically not zero-cost, so be careful and use these sparigly.
///
/// Base visitors, such as ValueToStringVisitor, should be declared
/// here also.
#include "Error.h"
#include "HashMap.h"
#include "boost/variant/variant_fwd.hpp"
#include <boost/json.hpp>
#include <boost/variant.hpp>
#include <boost/variant/variant.hpp>
#include <ostream>
#include <sol/forward.hpp>
#include <string>
#include <vector>
/// Dynamic array, can resize.
template<typename T>
using Array = std::vector<T>;
/// Null value, for use in Value.
struct Null {
/// Makes a null value. It's an identity value,
/// so its existance is the value.
explicit Null() { }
};
/// Formats "null".
std::ostream& operator<<(std::ostream& os, const Null&);
/// Contains a boolean value, for use in Value,
/// as booleans will be implicitly converted to int.
struct Bool {
/// Construct a bool from a boolean.
explicit Bool(bool b_)
: b(b_) { }
/// Contained value.
bool b;
/// Implicit conversion to bool, because it's expected to work this way.
operator bool() const { return b; }
};
template<typename T>
struct Tuple final : public Array<T> {
using Array<T>::Array;
};
/// Formats to "true" or "false".
std::ostream& operator<<(std::ostream& os, const Bool&);
/// The Value type is a recursively defined variant, which allows
/// passing a single value with any of a selection of types, including
/// the possibility to pass hashmaps of hashmaps of hashmaps of types (and so on).
///
/// In common pseudo-C++, this would be written as:
///
/// \code{.cpp}
/// using Value = variant<string, int, double, HashMap<string, Value>;
/// // ^^^^^
/// \endcode
/// Note the `^^^` annotated recursion. This isn't directly possible in C++,
/// so we use boost's recursive variants for this. Documentation is here
/// https://www.boost.org/doc/libs/1_82_0/doc/html/variant/tutorial.html#variant.tutorial.recursive
///
/// The use-case of a Value is to represent almost any primitive-ish type we may get from, or
/// may want to pass to, a Plugin.
///
/// For example, a table of key-value pairs, or a table of tables, or just a string, or a float, could all
/// be represented by this.
///
/// See the abstract template class ValueVisitor for how to access this with the
/// visitor pattern.
using Value = boost::make_recursive_variant<
std::string,
int64_t,
double,
Null,
Array<boost::recursive_variant_>,
HashMap<std::string, boost::recursive_variant_>,
Bool,
Tuple<boost::recursive_variant_>>::type;
// the following VALUE_TYPE_* variables are used mostly for
// unit-tests and code that can't use visitors.
/// Index of string in Value
[[maybe_unused]] constexpr int VALUE_TYPE_IDX_STRING = 0;
/// Index of int in Value
[[maybe_unused]] constexpr int VALUE_TYPE_IDX_INT = 1;
/// Index of double in Value
[[maybe_unused]] constexpr int VALUE_TYPE_IDX_DOUBLE = 2;
/// Index of null in Value
[[maybe_unused]] constexpr int VALUE_TYPE_IDX_NULL = 3;
/// Index of array in Value
[[maybe_unused]] constexpr int VALUE_TYPE_IDX_ARRAY = 4;
/// Index of hashmap in Value
[[maybe_unused]] constexpr int VALUE_TYPE_IDX_HASHMAP = 5;
/// Index of bool in Value
[[maybe_unused]] constexpr int VALUE_TYPE_IDX_BOOL = 6;
/// Index of tuple in Value
[[maybe_unused]] constexpr int VALUE_TYPE_IDX_TUPLE = 7;
/// A handy typedef for the recursive HashMap type inside a Value.
/// You may have to use this in order to make the compiler understand
/// what kind of value (a hash map) you are constructing.
using ValueHashMap = HashMap<std::string, Value>;
/// A handy typedef for the recursive Array type inside a Value.
/// You may have to use this in order to make the compiler understand
/// what kind of value (an array) you are constructing.
using ValueArray = Array<Value>;
/// A handy dandy typedef for using a tuple of values.
using ValueTuple = Tuple<Value>;
/// The ValueVisitor class is an abstract interface which allows the implementation
/// to easily construct a visitor for a Value object.
///
/// A Value object is a recursive variant class, and as such it's not simple to access
/// (no variants are really trivial to access). The visitor pattern gives us a type-safe
/// way to access such a variant, and the boost::static_visitor pattern does so in a
/// pretty concise way.
///
/// An example use is the ValueToStringVisitor.
template<typename ResultT>
class ValueVisitor : public boost::static_visitor<ResultT> {
public:
/// Needs to be default-constructible for the standard use case (see example above).
ValueVisitor() = default;
/// Cannot be copied.
ValueVisitor(const ValueVisitor&) = delete;
/// Cannot be copied.
ValueVisitor& operator=(const ValueVisitor&) = delete;
/// Virtual destructor is needed for virtual classes.
virtual ~ValueVisitor() = default;
/// ResultT from string.
virtual ResultT operator()(const std::string& str) const = 0;
/// ResultT from integer.
virtual ResultT operator()(int64_t i) const = 0;
/// ResultT from float.
virtual ResultT operator()(double d) const = 0;
/// ResultT from null.
virtual ResultT operator()(Null null) const = 0;
/// ResultT from boolean.
virtual ResultT operator()(Bool b) const = 0;
/// ResultT from array of values (must recursively visit).
virtual ResultT operator()(const ValueArray& array) const = 0;
/// ResultT from tuple of values (must recursively visit).
virtual ResultT operator()(const ValueTuple& array) const = 0;
/// ResultT from hashmap of values (must recursively visit).
virtual ResultT operator()(const HashMap<std::string, Value>& map) const = 0;
};
/// The ValueToStringVisitor class implements a visitor for a Value which
/// turns it into a human-readable string.
///
/// Example
/// \code{.cpp}
/// #include <boost/variant.hpp>
///
/// Value value = ...;
///
/// std::string str = boost::apply_visitor(ValueToStringVisitor(), value);
/// // ^--------------------^ ^---^
/// // default ctor |
/// // value to visit
/// \endcode
class ValueToStringVisitor : public ValueVisitor<std::string> {
public:
/// Flag used to specify behavior of ValueToStringVisitor.
enum Flag {
/// No options
NONE = 0,
/// Quote strings, `value` becomes `"value"`.
QUOTE_STRINGS = 0b1,
};
/// Constructs a ValueToStringVisitor with options.
/// With flags you can change, for example, whether strings should be quoted
/// when they standalone.
/// Depth is used by recursion, ignore it.
explicit ValueToStringVisitor(Flag flags = QUOTE_STRINGS, int depth = 1);
/// Returns the same string, possibly quoted (depends on flags).
std::string operator()(const std::string& str) const;
/// Uses fmt::format() to stringify the integer.
std::string operator()(int64_t i) const;
/// Uses fmt::format() to stringify the double.
std::string operator()(double d) const;
/// Returns "null".
std::string operator()(Null null) const;
/// Returns "true" or "false".
std::string operator()(Bool b) const;
/// Returns an object of format [ value, value, value ].
/// Recursively visits the elements of the array.
std::string operator()(const ValueArray& array) const;
/// Returns a tuple of format ( value, value, value ).
/// Recursively visits the elements of the array.
std::string operator()(const ValueTuple& array) const;
/// Returns an object of format { key: value, key: value }.
/// Recursively visits the elements of the map.
std::string operator()(const HashMap<std::string, Value>& map) const;
private:
/// Whether to quote strings before output.
bool m_quote_strings;
/// How many 2-space "tabs" to use - used by recursion.
int m_depth;
};
/// The ValueToJsonVisitor class is used to convert a Value into
/// a boost::json object.
class ValueToJsonVisitor : public ValueVisitor<boost::json::value> {
public:
/// Converts to json string.
boost::json::value operator()(const std::string& str) const;
/// Converts to json integer.
boost::json::value operator()(int64_t i) const;
/// Converts to json float.
boost::json::value operator()(double d) const;
/// Converts to empty json value.
boost::json::value operator()(Null null) const;
/// Converts to json boolean.
boost::json::value operator()(Bool b) const;
/// Converts to json array.
boost::json::value operator()(const ValueArray& array) const;
/// Converts to json array (because tuples don't exist).
boost::json::value operator()(const ValueTuple& array) const;
/// Converts to json object.
boost::json::value operator()(const HashMap<std::string, Value>& map) const;
};
/// The ValueToLuaVisitor class is used to convert a Value into a
/// sol object.
class ValueToLuaVisitor : public ValueVisitor<sol::object> {
public:
/// ValueToLuaVisitor needs a sol state in order to construct objects.
ValueToLuaVisitor(sol::state& state);
sol::object operator()(const std::string& str) const;
sol::object operator()(int64_t i) const;
sol::object operator()(double d) const;
sol::object operator()(Null null) const;
sol::object operator()(Bool b) const;
sol::object operator()(const ValueArray& array) const;
sol::object operator()(const ValueTuple& array) const;
sol::object operator()(const HashMap<std::string, Value>& map) const;
private:
sol::state& m_state;
};
/// This function converts from a lua (sol) wrapped value into a beammp value, for use in C++.
///
/// Value is a type which can be passed around between threads, and has no external dependencies.
/// Sol values are not like that, as they are references to stack indices in lua, and similar.
///
/// This function is also used to print values, by first converting them to a Value, then using a
/// ValueToStringVisitor.
///
/// The second argument is a provider for values which the function can't convert.
/// "invalid provider" means "provider of values for invalid sol values". If nullptr, then
/// any invalid value (such as a function) will be resolved to an error instead and the function will
/// fail.
Result<Value> sol_obj_to_value(const sol::object&, const std::function<Result<Value>(const sol::object&)>& invalid_provider = nullptr, size_t max_depth = 50);

View File

@@ -1,3 +1,21 @@
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <string>

View File

@@ -1,8 +0,0 @@
cmake_minimum_required(VERSION 3.0)
project(watchdog CXX ASM_MASM)
set(CMAKE_CXX_STANDARD 17)
add_library(watchdog STATIC watchdog.cpp watchdog.h x64Def.asm)
set_source_files_properties(watchdog.cpp PROPERTIES COMPILE_FLAGS "/O2 /Ob2 /DNDEBUG")
STRING(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
target_link_libraries(watchdog Dbghelp)

View File

@@ -1,80 +0,0 @@
//
// Created by Anonymous275 on 9/5/2021.
//
#pragma once
#include <cstring>
#include <iostream>
namespace fst {
template<size_t Cap>
class stack_string {
public:
stack_string() noexcept {
memset(Data, 0, Cap);
}
explicit stack_string(const char* Ptr) {
size_t len = strlen(Ptr);
Copy(Ptr, len);
memset(Data + len, 0, Cap - len);
}
stack_string(const char* Ptr, size_t PSize) {
Copy(Ptr, PSize);
memset(Data + PSize, 0, Cap - PSize);
}
inline size_t capacity() noexcept {
return Cap;
}
inline size_t size() noexcept {
return Size;
}
inline size_t length() noexcept {
return Size;
}
inline char* get() {
return Data;
}
[[nodiscard]] inline const char* c_str() const noexcept {
return Data;
}
char& operator[](size_t idx) {
if (idx >= Size) {
throw std::exception("stack_string out of boundaries operator[]");
}
return Data[idx];
}
inline void resize(size_t newSize) noexcept {
Size = newSize;
}
inline void push_back(const char* Ptr) {
Copy(Ptr, strlen(Ptr));
}
inline void push_back(const char* Ptr, size_t Count) {
Copy(Ptr, Count);
}
inline void push_back(char Ptr) {
Copy(&Ptr, 1);
}
friend std::ostream& operator<<(std::ostream& os, const stack_string& obj) {
os << obj.Data;
return os;
}
inline stack_string& operator+=(const char* Ptr) {
push_back(Ptr);
return *this;
}
inline stack_string& operator+=(char Ptr) {
push_back(Ptr);
return *this;
}
private:
inline void Copy(const char* Ptr, size_t PSize) {
if((PSize + Size) <= Cap) {
memcpy(&Data[Size], Ptr, PSize);
Size += PSize;
} else throw std::exception("stack_string out of boundaries copy");
}
char Data[Cap]{};
size_t Size{0};
};
}

View File

@@ -1,281 +0,0 @@
//
// Created by Anonymous275 on 9/9/2021.
//
#include <windows.h>
#include <imagehlp.h>
#include <strsafe.h>
#include <cstdint>
#include "stack_string.h"
struct function_info {
void* func_address;
uint32_t thread_id;
bool enter;
};
fst::stack_string<1024> crash_file;
template <typename I>
fst::stack_string<(sizeof(I)<<1)+1> HexString(I w) {
static const char* digits = "0123456789ABCDEF";
const size_t hex_len = sizeof(I)<<1;
fst::stack_string<hex_len+1> rc;
rc.resize(hex_len+1);
memset(rc.get(), '0', hex_len);
memset(rc.get() + hex_len, 0, 1);
for (size_t i=0, j=(hex_len-1)*4 ; i<hex_len; ++i,j-=4)
rc[i] = digits[(w>>j) & 0x0f];
return rc;
}
template<class T_>
class heap_array {
public:
heap_array() noexcept {
Data = (T_*)(GlobalAlloc(GPTR, Cap * sizeof(T_)));
init = true;
}
explicit heap_array(size_t Cap_) noexcept {
Cap = Cap_;
Data = (T_*)(GlobalAlloc(GPTR, Cap * sizeof(T_)));
init = true;
}
~heap_array() {
free(Data);
}
inline T_* get() noexcept {
return Data;
}
inline const T_* cget() noexcept {
return Data;
}
inline void insert(const T_& T) {
if(!init)return;
if(Size >= Cap) {
Grow();
}
Data[Size++] = T;
}
inline void string_insert(const T_* T, size_t len = 0) {
if(len == 0)len = strlen(T);
if(Size+len >= Cap) {
Grow(len);
}
memcpy(&Data[Size], T, len);
Size += len;
}
inline T_ at(size_t idx) {
return Data[idx];
}
inline size_t size() const noexcept {
return Size;
}
const T_& operator[](size_t idx) {
if (idx >= Size) {
throw std::exception("out of boundaries operator[]");
}
return Data[idx];
}
private:
inline void Grow(size_t add = 0) {
Cap = (Cap*2) + add;
auto* NewData = (T_*)(GlobalAlloc(GPTR, Cap * sizeof(T_)));
for(size_t C = 0; C < Size; C++) {
NewData[C] = Data[C];
}
GlobalFree(Data);
Data = NewData;
}
size_t Size{0}, Cap{5};
bool init{false};
T_* Data;
};
heap_array<function_info>* watch_data;
struct watchdog_mutex {
static void Create() noexcept {
hMutex = CreateMutex(nullptr, FALSE, nullptr);
}
static void Lock() {
WaitForSingleObject(hMutex, INFINITE);
}
static void Unlock() {
ReleaseMutex(hMutex);
}
struct [[nodiscard]] ScopedLock {
ScopedLock() {
if(hMutex)
watchdog_mutex::Lock();
}
~ScopedLock() {
if(hMutex)
watchdog_mutex::Unlock();
}
};
private:
static HANDLE hMutex;
};
HANDLE watchdog_mutex::hMutex{nullptr};
std::atomic<bool> Init{false}, Sym;
std::atomic<int64_t> Offset{0};
void watchdog_setOffset(int64_t Off) {
Offset.store(Off);
}
void notify(const char* msg) {
HANDLE stdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if (stdOut != nullptr && stdOut != INVALID_HANDLE_VALUE) {
DWORD written = 0;
WriteConsoleA(stdOut, "[WATCHDOG] ", 11, &written, nullptr);
WriteConsoleA(stdOut, msg, DWORD(strlen(msg)), &written, nullptr);
WriteConsoleA(stdOut, "\n", 1, &written, nullptr);
}
}
fst::stack_string<MAX_SYM_NAME> FindFunction(void* Address) {
if(!Sym.load()) {
fst::stack_string<MAX_SYM_NAME> undName;
return undName;
}
static HANDLE process = GetCurrentProcess();
DWORD64 symDisplacement = 0;
fst::stack_string<MAX_SYM_NAME> undName;
TCHAR buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
memset(&buffer,0, sizeof(buffer));
auto pSymbolInfo = (PSYMBOL_INFO)buffer;
pSymbolInfo->SizeOfStruct = sizeof(SYMBOL_INFO);
pSymbolInfo->MaxNameLen = MAX_SYM_NAME;
if (SymFromAddr(process, DWORD64(Address) + Offset, &symDisplacement, pSymbolInfo)) {
undName.push_back(pSymbolInfo->Name);
}
return undName;
}
fst::stack_string<512> getCrashInfo(void* Address){
if(!Sym.load()){
fst::stack_string<512> Value;
Value.push_back("unknown", 7);
return Value;
}
DWORD pdwDisplacement = 0;
IMAGEHLP_LINE64 line{sizeof(IMAGEHLP_LINE64)};
SymGetLineFromAddr64(GetCurrentProcess(), DWORD64(Address) + Offset, &pdwDisplacement, &line);
char* Name = nullptr;
if(line.FileName) {
Name = strrchr(line.FileName, '\\');
}
fst::stack_string<512> Value;
if(Name)Value.push_back(Name+1);
else Value.push_back("unknown", 7);
char buffer[20];
auto n = sprintf(buffer, ":%lu", line.LineNumber);
Value.push_back(buffer, n);
return Value;
}
const char* getFunctionDetails(void* Address) {
return FindFunction(Address).c_str();
}
const char* getCrashLocation(void* Address) {
return getCrashInfo(Address).c_str();
}
void InitSym(const char* PDBLocation) {
SymInitialize(GetCurrentProcess(), PDBLocation, TRUE);
Sym.store(true);
}
void write_report(const char* report, size_t size) {
HANDLE hFile = CreateFile(crash_file.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (hFile == INVALID_HANDLE_VALUE) {
notify("Failed to open crash file for writing!");
return;
}
DWORD dwBytesWritten = 0;
auto Flag = WriteFile(hFile, report, DWORD(size), &dwBytesWritten, nullptr);
if (Flag == FALSE) {
notify("Failed to write to crash file!");
}
CloseHandle(hFile);
}
void generate_crash_report(uint32_t Code, void* Address) {
watchdog_mutex::ScopedLock guard;
notify("generating crash report, please wait");
Init.store(false);
heap_array<char> Report(watch_data->size() * sizeof(function_info));
Report.string_insert("crash code ");
Report.string_insert(HexString(Code).c_str());
Report.string_insert(" at ");
Report.string_insert(HexString(size_t(Address) + Offset).c_str());
Report.string_insert("\n");
if(Address) {
Report.string_insert("origin and line number -> ");
Report.string_insert(getCrashInfo(Address).c_str());
Report.string_insert("\n");
}
Report.string_insert("Call history: \n");
char buff[20];
for(size_t C = 0; C < watch_data->size(); C++){
auto entry = watch_data->at(C);
auto Name = FindFunction(entry.func_address);
if(entry.enter){
Report.string_insert("[Entry] ");
}
else {
Report.string_insert("[Exit ] ");
}
auto n = sprintf(buff, "(%d) ", entry.thread_id);
Report.string_insert(buff, n);
if(Name.size() > 0){
Report.string_insert(Name.c_str(), Name.size());
Report.string_insert(" | ");
auto location = getCrashInfo(entry.func_address);
Report.string_insert(location.c_str(), location.size());
}
else {
Report.string_insert(HexString(size_t(entry.func_address) + Offset).c_str());
}
Report.string_insert("\n");
}
write_report(Report.cget(), Report.size());
notify("crash report generated");
Init.store(true);
}
LONG WINAPI CrashHandler(EXCEPTION_POINTERS* p) {
Init.store(false);
notify("CAUGHT EXCEPTION!");
generate_crash_report(p->ExceptionRecord->ExceptionCode, p->ExceptionRecord->ExceptionAddress);
return EXCEPTION_EXECUTE_HANDLER;
}
void watchdog_init(const char* crashFile, const char* SpecificPDBLocation, bool Symbols) {
if(Symbols)SymInitialize(GetCurrentProcess(), SpecificPDBLocation, TRUE);
Sym.store(Symbols);
SetUnhandledExceptionFilter(CrashHandler);
watch_data = new heap_array<function_info>();
watchdog_mutex::Create();
crash_file.push_back(crashFile);
notify("initialized!");
Init.store(true);
}
inline void AddEntry(void* func_address, uint32_t thread_id, bool entry) {
watchdog_mutex::ScopedLock guard;
if(Init.load()) {
watch_data->insert({func_address, thread_id, entry});
}
}
extern "C" {
void FuncEntry(void* func) {
AddEntry(func, GetCurrentThreadId(), true);
}
void FuncExit(void* func) {
AddEntry(func, GetCurrentThreadId(), false);
}
}

View File

@@ -1,12 +0,0 @@
//
// Created by Anonymous275 on 9/9/2021.
//
#pragma once
#include <cstdint>
extern void watchdog_init(const char* crashFile, const char* SpecificPDBLocation, bool Symbols = true);
extern void generate_crash_report(uint32_t Code, void* Address);
const char* getFunctionDetails(void* Address);
extern void watchdog_setOffset(int64_t Off);
const char* getCrashLocation(void* Address);
void InitSym(const char* PDBLocation);

View File

@@ -1,85 +0,0 @@
;//
;// Created by Anonymous275 on 9/9/2021.
;//
;External C functions used by _penter and _pexit
extern FuncEntry:Proc
extern FuncExit:Proc
.code
_penter proc
; Store the volatile registers
push r11
push r10
push r9
push r8
push rax
push rdx
push rcx
; reserve space for 4 registers [ rcx,rdx,r8 and r9 ] 32 bytes
sub rsp,20h
; Get the return address of the function
mov rcx,rsp
mov rcx,qword ptr[rcx+58h]
sub rcx,5
;call the function to get the name of the callee and caller
call FuncEntry
;Release the space reserved for the registersk by adding 32 bytes
add rsp,20h
;Restore the registers back by poping out
pop rcx
pop rdx
pop rax
pop r8
pop r9
pop r10
pop r11
;return
ret
_penter endp
_pexit proc
; Store the volatile registers
push r11
push r10
push r9
push r8
push rax
push rdx
push rcx
; reserve space for 4 registers [ rcx,rdx,r8 and r9 ] 32 bytes
sub rsp,20h
; Get the return address of the function
mov rcx,rsp
mov rcx,qword ptr[rcx+58h]
call FuncExit
;Release the space reserved for the registersk by adding 32 bytes
add rsp,20h
;Restore the registers back by poping out
pop rcx
pop rdx
pop rax
pop r8
pop r9
pop r10
pop r11
;return
ret
_pexit endp
end

Submodule rapidjson deleted from 13dfc96c9c

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-11/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/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

@@ -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-22.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

7
scripts/windows/1-configure.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
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

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

5
scripts/windows/2-build.sh Executable file
View File

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

188
src/ArgsParser.cpp Normal file
View File

@@ -0,0 +1,188 @@
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "ArgsParser.h"
#include "Common.h"
#include <algorithm>
#include <doctest/doctest.h>
void ArgsParser::Parse(const std::vector<std::string_view>& ArgList) {
for (const auto& Arg : ArgList) {
if (Arg.size() > 2 && Arg.substr(0, 2) == "--") {
// long arg
if (Arg.find("=") != Arg.npos) {
ConsumeLongAssignment(std::string(Arg));
} else {
ConsumeLongFlag(std::string(Arg));
}
} else {
beammp_errorf("Error parsing commandline arguments: Supplied argument '{}' is not a valid argument and was ignored.", Arg);
}
}
}
bool ArgsParser::Verify() {
bool Ok = true;
for (const auto& RegisteredArg : mRegisteredArguments) {
if (RegisteredArg.Flags & Flags::REQUIRED && !FoundArgument(RegisteredArg.Names)) {
beammp_errorf("Error in commandline arguments: Argument '{}' is required but wasn't found.", RegisteredArg.Names.at(0));
Ok = false;
continue;
} else if (FoundArgument(RegisteredArg.Names)) {
if (RegisteredArg.Flags & Flags::HAS_VALUE) {
if (!GetValueOfArgument(RegisteredArg.Names).has_value()) {
beammp_error("Error in commandline arguments: Argument '" + std::string(RegisteredArg.Names.at(0)) + "' expects a value, but no value was given.");
Ok = false;
}
} else if (GetValueOfArgument(RegisteredArg.Names).has_value()) {
beammp_error("Error in commandline arguments: Argument '" + std::string(RegisteredArg.Names.at(0)) + "' does not expect a value, but one was given.");
Ok = false;
}
}
}
return Ok;
}
void ArgsParser::RegisterArgument(std::vector<std::string>&& ArgumentNames, int Flags) {
mRegisteredArguments.push_back({ ArgumentNames, Flags });
}
bool ArgsParser::FoundArgument(const std::vector<std::string>& Names) {
// if any of the found args match any of the names
return std::any_of(mFoundArgs.begin(), mFoundArgs.end(),
[&Names](const Argument& Arg) -> bool {
// if any of the names match this arg's name
return std::any_of(Names.begin(), Names.end(), [&Arg](const std::string& Name) -> bool {
return Arg.Name == Name;
});
});
}
std::optional<std::string> ArgsParser::GetValueOfArgument(const std::vector<std::string>& Names) {
// finds an entry which has a name that is any of the names in 'Names'
auto Found = std::find_if(mFoundArgs.begin(), mFoundArgs.end(), [&Names](const Argument& Arg) -> bool {
return std::any_of(Names.begin(), Names.end(), [&Arg](const std::string_view& Name) -> bool {
return Arg.Name == Name;
});
});
if (Found != mFoundArgs.end()) {
// found
return Found->Value;
} else {
return std::nullopt;
}
}
bool ArgsParser::IsRegistered(const std::string& Name) {
return std::any_of(mRegisteredArguments.begin(), mRegisteredArguments.end(), [&Name](const RegisteredArgument& Arg) {
auto Iter = std::find(Arg.Names.begin(), Arg.Names.end(), Name);
return Iter != Arg.Names.end();
});
}
void ArgsParser::ConsumeLongAssignment(const std::string& Arg) {
auto Value = Arg.substr(Arg.rfind("=") + 1);
auto Name = Arg.substr(2, Arg.rfind("=") - 2);
if (!IsRegistered(Name)) {
beammp_warn("Argument '" + Name + "' was supplied but isn't a known argument, so it is likely being ignored.");
}
mFoundArgs.push_back({ Name, Value });
}
void ArgsParser::ConsumeLongFlag(const std::string& Arg) {
auto Name = Arg.substr(2, Arg.rfind("=") - 2);
mFoundArgs.push_back({ Name, std::nullopt });
if (!IsRegistered(Name)) {
beammp_warn("Argument '" + Name + "' was supplied but isn't a known argument, so it is likely being ignored.");
}
}
TEST_CASE("ArgsParser") {
ArgsParser parser;
SUBCASE("Simple args") {
parser.RegisterArgument({ "a" }, ArgsParser::Flags::NONE);
parser.RegisterArgument({ "hello" }, ArgsParser::Flags::NONE);
parser.Parse({ "--a", "--hello" });
CHECK(parser.Verify());
CHECK(parser.FoundArgument({ "a" }));
CHECK(parser.FoundArgument({ "hello" }));
CHECK(parser.FoundArgument({ "a", "hello" }));
CHECK(!parser.FoundArgument({ "b" }));
CHECK(!parser.FoundArgument({ "goodbye" }));
}
SUBCASE("No args") {
parser.RegisterArgument({ "a" }, ArgsParser::Flags::NONE);
parser.RegisterArgument({ "hello" }, ArgsParser::Flags::NONE);
parser.Parse({});
CHECK(parser.Verify());
CHECK(!parser.FoundArgument({ "a" }));
CHECK(!parser.FoundArgument({ "hello" }));
CHECK(!parser.FoundArgument({ "a", "hello" }));
CHECK(!parser.FoundArgument({ "b" }));
CHECK(!parser.FoundArgument({ "goodbye" }));
CHECK(!parser.FoundArgument({ "" }));
}
SUBCASE("Value args") {
parser.RegisterArgument({ "a" }, ArgsParser::Flags::HAS_VALUE);
parser.RegisterArgument({ "hello" }, ArgsParser::Flags::HAS_VALUE);
parser.Parse({ "--a=5", "--hello=world" });
CHECK(parser.Verify());
REQUIRE(parser.FoundArgument({ "a" }));
REQUIRE(parser.FoundArgument({ "hello" }));
CHECK(parser.GetValueOfArgument({ "a" }).has_value());
CHECK(parser.GetValueOfArgument({ "a" }).value() == "5");
CHECK(parser.GetValueOfArgument({ "hello" }).has_value());
CHECK(parser.GetValueOfArgument({ "hello" }).value() == "world");
}
SUBCASE("Mixed value & no-value args") {
parser.RegisterArgument({ "a" }, ArgsParser::Flags::HAS_VALUE);
parser.RegisterArgument({ "hello" }, ArgsParser::Flags::NONE);
parser.Parse({ "--a=5", "--hello" });
CHECK(parser.Verify());
REQUIRE(parser.FoundArgument({ "a" }));
REQUIRE(parser.FoundArgument({ "hello" }));
CHECK(parser.GetValueOfArgument({ "a" }).has_value());
CHECK(parser.GetValueOfArgument({ "a" }).value() == "5");
CHECK(!parser.GetValueOfArgument({ "hello" }).has_value());
}
SUBCASE("Required args") {
SUBCASE("Two required, two present") {
parser.RegisterArgument({ "a" }, ArgsParser::Flags::REQUIRED);
parser.RegisterArgument({ "hello" }, ArgsParser::Flags::REQUIRED);
parser.Parse({ "--a", "--hello" });
CHECK(parser.Verify());
}
SUBCASE("Two required, one present") {
parser.RegisterArgument({ "a" }, ArgsParser::Flags::REQUIRED);
parser.RegisterArgument({ "hello" }, ArgsParser::Flags::REQUIRED);
parser.Parse({ "--a" });
CHECK(!parser.Verify());
}
SUBCASE("Two required, none present") {
parser.RegisterArgument({ "a" }, ArgsParser::Flags::REQUIRED);
parser.RegisterArgument({ "hello" }, ArgsParser::Flags::REQUIRED);
parser.Parse({ "--b" });
CHECK(!parser.Verify());
}
}
}

Some files were not shown because too many files have changed in this diff Show More