mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-03 14:26:15 +00:00
Compare commits
293 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77f3375658 | ||
|
|
ae6e5b51bf | ||
|
|
8a0f87f476 | ||
|
|
33b2030f97 | ||
|
|
5b2eb0a1a0 | ||
|
|
f27d3c6120 | ||
|
|
7a4b24d616 | ||
|
|
b6b0e4ba3e | ||
|
|
a87aa7230a | ||
|
|
b9cc025083 | ||
|
|
c0ed056440 | ||
|
|
e6e5bf8327 | ||
|
|
e7cfb6e406 | ||
|
|
185818d174 | ||
|
|
406c79ef82 | ||
|
|
f104451bb9 | ||
|
|
d52def2114 | ||
|
|
d71757b56c | ||
|
|
f7d3fcf925 | ||
|
|
7bef6f35c2 | ||
|
|
b64d645f73 | ||
|
|
1780133569 | ||
|
|
c89afdf477 | ||
|
|
9d44146224 | ||
|
|
a5c02217fa | ||
|
|
303fc55d94 | ||
|
|
5f1e7c6409 | ||
|
|
8025c0884f | ||
|
|
51d096deac | ||
|
|
9c53f86593 | ||
|
|
e0257e9526 | ||
|
|
8b96ffb098 | ||
|
|
6c740e2562 | ||
|
|
06c741edc5 | ||
|
|
5e448dc34f | ||
|
|
676084f283 | ||
|
|
a8cd208208 | ||
|
|
2529146d5a | ||
|
|
8d641f326d | ||
|
|
5af9f5da36 | ||
|
|
baba0ad026 | ||
|
|
b1ebcfc18d | ||
|
|
187ef3b24f | ||
|
|
943889d588 | ||
|
|
edbd99f389 | ||
|
|
0341d401e7 | ||
|
|
da84d62391 | ||
|
|
cc6167cd2e | ||
|
|
d3263acead | ||
|
|
4de0bc9a40 | ||
|
|
25a1061700 | ||
|
|
f193c25de6 | ||
|
|
efe9f5b614 | ||
|
|
6244fdafc6 | ||
|
|
ca93effb7d | ||
|
|
f9d347bd9b | ||
|
|
a63f1bd27c | ||
|
|
ffc36e7f3d | ||
|
|
e216b6ec06 | ||
|
|
6597fe5e26 | ||
|
|
2fa5d69369 | ||
|
|
fec80e2c67 | ||
|
|
dc78883451 | ||
|
|
fa8627a22b | ||
|
|
dd5256ae22 | ||
|
|
e24cbf61bb | ||
|
|
472e2d16b6 | ||
|
|
ae650cc142 | ||
|
|
ad7177bec8 | ||
|
|
a4005c5876 | ||
|
|
a3ad6f8700 | ||
|
|
d3bddb0203 | ||
|
|
9e93fa35fa | ||
|
|
8373a70c4b | ||
|
|
d52a791dd9 | ||
|
|
08a6f9a093 | ||
|
|
e5e40e186b | ||
|
|
bfbff52cb1 | ||
|
|
8d4ba6f158 | ||
|
|
a5d450b680 | ||
|
|
f4e985976f | ||
|
|
db9ec53a6e | ||
|
|
f9b2edd410 | ||
|
|
333a95262b | ||
|
|
e53885a8a8 | ||
|
|
c22ea1e85d | ||
|
|
f8ea9bd8a3 | ||
|
|
ad8eab3d66 | ||
|
|
e880da5cf9 | ||
|
|
d14b64c652 | ||
|
|
649514ca1a | ||
|
|
a8a4dfb77c | ||
|
|
7149075d53 | ||
|
|
c485fba26b | ||
|
|
d35567dd47 | ||
|
|
f2b86cd5a0 | ||
|
|
3e7d16a8e8 | ||
|
|
03748d096f | ||
|
|
096d07fe9b | ||
|
|
e7a0325e70 | ||
|
|
7f627aaf92 | ||
|
|
63aee03969 | ||
|
|
46e6fda26e | ||
|
|
87c7edf404 | ||
|
|
f4fcbd63f5 | ||
|
|
7f1072b7c2 | ||
|
|
89327b8e20 | ||
|
|
ebf1579ce4 | ||
|
|
a06470cb70 | ||
|
|
80a3feb349 | ||
|
|
f2166ff8c6 | ||
|
|
ec1a09bbcb | ||
|
|
811fe41afb | ||
|
|
c518a036ed | ||
|
|
d8c1af4ac2 | ||
|
|
00bd5be4d0 | ||
|
|
dff2f2712b | ||
|
|
3effe0d4de | ||
|
|
d58ff960ec | ||
|
|
f67f8573e0 | ||
|
|
8a8e0be1a1 | ||
|
|
e0041666ca | ||
|
|
ed686333ec | ||
|
|
8938fd84ea | ||
|
|
bd4c9c34a9 | ||
|
|
8519e279a7 | ||
|
|
54895eb1b0 | ||
|
|
1423c1193b | ||
|
|
288e76594d | ||
|
|
4fdc3c4031 | ||
|
|
708da44fec | ||
|
|
6b6e304cfd | ||
|
|
06cb366bb5 | ||
|
|
0b35f0484f | ||
|
|
9dbbd8298d | ||
|
|
ca9dd1ae75 | ||
|
|
9ebd218856 | ||
|
|
43b02f0118 | ||
|
|
d9874ce70e | ||
|
|
423519f31e | ||
|
|
3f12bb757a | ||
|
|
7d52e44434 | ||
|
|
4fbd25b551 | ||
|
|
3cf1a2e51b | ||
|
|
49874fd633 | ||
|
|
6a23518eff | ||
|
|
3297b3e62e | ||
|
|
76cfc47a2f | ||
|
|
7b59cb6f87 | ||
|
|
0eba745d4c | ||
|
|
259b21502e | ||
|
|
afac729505 | ||
|
|
f57ebb7a92 | ||
|
|
ace96b7e33 | ||
|
|
fcb51adcb8 | ||
|
|
0c53ff4cd4 | ||
|
|
68a4d64387 | ||
|
|
5bdd8c11da | ||
|
|
47681cda50 | ||
|
|
c99fecfa1c | ||
|
|
d26e0320e4 | ||
|
|
57422a6105 | ||
|
|
467c8dc584 | ||
|
|
2ddb576e72 | ||
|
|
e242057583 | ||
|
|
06686688fc | ||
|
|
aca61886d0 | ||
|
|
768f11f6ec | ||
|
|
7944e9dbe8 | ||
|
|
0c68f91fb2 | ||
|
|
b8fdbc4ed9 | ||
|
|
85908e42d5 | ||
|
|
5c77e60f29 | ||
|
|
c74455e0fe | ||
|
|
dc13e4a03c | ||
|
|
1d7eb64fe0 | ||
|
|
1676d4174e | ||
|
|
ad468a8971 | ||
|
|
d3805f2cfd | ||
|
|
9f1cc15b15 | ||
|
|
c0fb4e4ad6 | ||
|
|
7600372ca1 | ||
|
|
54cd5b5e0e | ||
|
|
ede6fcd7dd | ||
|
|
eaeacbd8de | ||
|
|
0ffed00bcb | ||
|
|
c0c3d6b30e | ||
|
|
9c59a83f04 | ||
|
|
95436cb073 | ||
|
|
cbb5502a40 | ||
|
|
d6dfe85f69 | ||
|
|
ae9af1470c | ||
|
|
9255c70b0b | ||
|
|
53c514ecc6 | ||
|
|
e348d59a7e | ||
|
|
244d27341f | ||
|
|
3a55b62907 | ||
|
|
0c3ae43910 | ||
|
|
8436586566 | ||
|
|
19d1245379 | ||
|
|
470eeac821 | ||
|
|
9c6aa86e68 | ||
|
|
1362471657 | ||
|
|
aa46b454e2 | ||
|
|
02465c529d | ||
|
|
c68cbf8946 | ||
|
|
46542c1dce | ||
|
|
97f58dd413 | ||
|
|
4bedfc8e96 | ||
|
|
cd17df5cc2 | ||
|
|
0b589a74c9 | ||
|
|
1260515a40 | ||
|
|
007cd6573e | ||
|
|
7b022f9907 | ||
|
|
96c9c89238 | ||
|
|
b4949af1d7 | ||
|
|
85086909a6 | ||
|
|
79209219dd | ||
|
|
18e1b7a2bb | ||
|
|
a5766639d6 | ||
|
|
191fbf083d | ||
|
|
8c4342853a | ||
|
|
3937ac1ae7 | ||
|
|
a128099619 | ||
|
|
deed24f6e8 | ||
|
|
ac2db7c73f | ||
|
|
06db6d0341 | ||
|
|
2d43e11e96 | ||
|
|
8911158f81 | ||
|
|
a714dc3188 | ||
|
|
29445f65ce | ||
|
|
48be292850 | ||
|
|
2397f45d3f | ||
|
|
d1fb67f1f0 | ||
|
|
eae6d11476 | ||
|
|
452fc1e484 | ||
|
|
de3888618a | ||
|
|
4678701f42 | ||
|
|
7481ba4539 | ||
|
|
d791e2ac92 | ||
|
|
a60ff48c08 | ||
|
|
da3b49aa12 | ||
|
|
e505874af9 | ||
|
|
2f0a9fba99 | ||
|
|
b034072027 | ||
|
|
f94b9adf7a | ||
|
|
c95178ea59 | ||
|
|
1f7c498bd9 | ||
|
|
e46d4b2f0e | ||
|
|
f2b34543f9 | ||
|
|
d32da036bc | ||
|
|
8b0f4f99f6 | ||
|
|
17e887442c | ||
|
|
fc454cd11e | ||
|
|
e0e2607632 | ||
|
|
25f28e7fee | ||
|
|
ba9719ed67 | ||
|
|
bb04d1bfe1 | ||
|
|
82e58e6513 | ||
|
|
274a1dac7c | ||
|
|
ae7f8f44e3 | ||
|
|
a82b9fb36f | ||
|
|
3488136ca4 | ||
|
|
05ffa0b638 | ||
|
|
942cc78406 | ||
|
|
46690b5bbf | ||
|
|
adba66afb9 | ||
|
|
cc42a5e0ab | ||
|
|
c8a1b77a54 | ||
|
|
b9d252fd8a | ||
|
|
2b02475fd4 | ||
|
|
8aa7a67100 | ||
|
|
348090a127 | ||
|
|
c0df995e28 | ||
|
|
8c9d3a5455 | ||
|
|
9dcfa1dca4 | ||
|
|
bd4cfe06b1 | ||
|
|
9c7034e401 | ||
|
|
aeb167c1e8 | ||
|
|
7967ec38e8 | ||
|
|
250be2ccdc | ||
|
|
6158069d4d | ||
|
|
b2e5b8d2d3 | ||
|
|
5db1b48e07 | ||
|
|
56dcfcc5ed | ||
|
|
7c1106a46a | ||
|
|
9afdfd4d1b | ||
|
|
c2f260a86c | ||
|
|
2781179b4b | ||
|
|
3b479abf64 | ||
|
|
c731718f50 | ||
|
|
0fd0a9fe7e | ||
|
|
302582bfe1 |
5
.clang-format
Normal file
5
.clang-format
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
BasedOnStyle: WebKit
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
SpaceAfterTemplateKeyword: false
|
||||||
|
...
|
||||||
6
.github/pull_request_template.md
vendored
Normal file
6
.github/pull_request_template.md
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
Please replace this text <-> with your PR description and leave the below declarations intact.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
By creating this pull request, I understand that code that is AI generated or otherwise automatically generated may be rejected without further discussion.
|
||||||
|
I declare that I fully understand all code I pushed into this PR, and wrote all this code myself and own the rights to this code.
|
||||||
12
.github/workflows/cmake-linux.yml
vendored
12
.github/workflows/cmake-linux.yml
vendored
@@ -13,6 +13,14 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
submodules: 'true'
|
submodules: 'true'
|
||||||
|
|
||||||
|
- name: Restore artifacts, or run vcpkg, build and cache artifacts
|
||||||
|
uses: lukka/run-vcpkg@v7
|
||||||
|
id: runvcpkg
|
||||||
|
with:
|
||||||
|
vcpkgArguments: 'zlib nlohmann-json openssl cpp-httplib[openssl]'
|
||||||
|
vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
|
||||||
|
vcpkgGitCommitId: '40616a5e954f7be1077ef37db3fbddbd5dcd1ca6'
|
||||||
|
|
||||||
- name: Create Build Environment
|
- name: Create Build Environment
|
||||||
run: cmake -E make_directory ${{github.workspace}}/build-linux
|
run: cmake -E make_directory ${{github.workspace}}/build-linux
|
||||||
@@ -20,7 +28,7 @@ jobs:
|
|||||||
- name: Configure CMake
|
- name: Configure CMake
|
||||||
shell: bash
|
shell: bash
|
||||||
working-directory: ${{github.workspace}}/build-linux
|
working-directory: ${{github.workspace}}/build-linux
|
||||||
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
|
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_TOOLCHAIN_FILE='${{ runner.workspace }}/b/vcpkg/scripts/buildsystems/vcpkg.cmake'
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
working-directory: ${{github.workspace}}/build-linux
|
working-directory: ${{github.workspace}}/build-linux
|
||||||
@@ -28,7 +36,7 @@ jobs:
|
|||||||
run: cmake --build . --config $BUILD_TYPE
|
run: cmake --build . --config $BUILD_TYPE
|
||||||
|
|
||||||
- name: Archive artifacts
|
- name: Archive artifacts
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: BeamMP-Launcher
|
name: BeamMP-Launcher
|
||||||
path: ${{github.workspace}}/build-linux/BeamMP-Launcher
|
path: ${{github.workspace}}/build-linux/BeamMP-Launcher
|
||||||
|
|||||||
6
.github/workflows/cmake-windows.yml
vendored
6
.github/workflows/cmake-windows.yml
vendored
@@ -18,9 +18,9 @@ jobs:
|
|||||||
uses: lukka/run-vcpkg@v7
|
uses: lukka/run-vcpkg@v7
|
||||||
id: runvcpkg
|
id: runvcpkg
|
||||||
with:
|
with:
|
||||||
vcpkgArguments: 'discord-rpc zlib rapidjson openssl'
|
vcpkgArguments: 'discord-rpc zlib nlohmann-json openssl cpp-httplib[openssl]'
|
||||||
vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
|
vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
|
||||||
vcpkgGitCommitId: '06b5f4a769d848d1a20fa0acd556019728b56273'
|
vcpkgGitCommitId: '40616a5e954f7be1077ef37db3fbddbd5dcd1ca6'
|
||||||
vcpkgTriplet: 'x64-windows-static'
|
vcpkgTriplet: 'x64-windows-static'
|
||||||
|
|
||||||
- name: Create Build Environment
|
- name: Create Build Environment
|
||||||
@@ -37,7 +37,7 @@ jobs:
|
|||||||
run: cmake --build . --config $BUILD_TYPE
|
run: cmake --build . --config $BUILD_TYPE
|
||||||
|
|
||||||
- name: Archive artifacts
|
- name: Archive artifacts
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: BeamMP-Launcher.exe
|
name: BeamMP-Launcher.exe
|
||||||
path: ${{github.workspace}}/build-windows/Release/BeamMP-Launcher.exe
|
path: ${{github.workspace}}/build-windows/Release/BeamMP-Launcher.exe
|
||||||
|
|||||||
104
.github/workflows/release-build.yml
vendored
104
.github/workflows/release-build.yml
vendored
@@ -1,104 +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: Release ${{ github.ref }}
|
|
||||||
draft: false
|
|
||||||
prerelease: false
|
|
||||||
body: |
|
|
||||||
Files included in this release:
|
|
||||||
- `BeamMP-Launcher.exe` windows build
|
|
||||||
- `BeamMP-Launcher` linux build
|
|
||||||
|
|
||||||
upload-release-files-windows:
|
|
||||||
name: Upload Windows Release Files
|
|
||||||
runs-on: windows-latest
|
|
||||||
needs: create-release
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
submodules: 'true'
|
|
||||||
|
|
||||||
- name: Restore artifacts, or run vcpkg, build and cache artifacts
|
|
||||||
uses: lukka/run-vcpkg@main
|
|
||||||
id: runvcpkg
|
|
||||||
with:
|
|
||||||
vcpkgArguments: 'discord-rpc zlib rapidjson openssl'
|
|
||||||
vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
|
|
||||||
vcpkgGitCommitId: '06b5f4a769d848d1a20fa0acd556019728b56273'
|
|
||||||
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
|
|
||||||
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_TOOLCHAIN_FILE='${{ runner.workspace }}/b/vcpkg/scripts/buildsystems/vcpkg.cmake' -DVCPKG_TARGET_TRIPLET=x64-windows-static
|
|
||||||
|
|
||||||
- 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-Launcher.exe
|
|
||||||
asset_name: BeamMP-Launcher.exe
|
|
||||||
asset_content_type: application/vnd.microsoft.portable-executable
|
|
||||||
|
|
||||||
upload-release-files-linux:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
submodules: 'true'
|
|
||||||
|
|
||||||
- name: Create Build Environment
|
|
||||||
run: cmake -E make_directory ${{github.workspace}}/build-linux
|
|
||||||
|
|
||||||
- name: Configure CMake
|
|
||||||
shell: bash
|
|
||||||
working-directory: ${{github.workspace}}/build-linux
|
|
||||||
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
|
|
||||||
|
|
||||||
- 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-Launcher
|
|
||||||
asset_name: BeamMP-Launcher
|
|
||||||
asset_content_type: application/octet-stream
|
|
||||||
10
.gitignore
vendored
10
.gitignore
vendored
@@ -4,4 +4,12 @@ cmake-build-release
|
|||||||
*.log
|
*.log
|
||||||
/*.sh
|
/*.sh
|
||||||
/*.obj
|
/*.obj
|
||||||
/*.exe
|
/*.exe
|
||||||
|
.cache/
|
||||||
|
.https_debug/
|
||||||
|
Launcher.cfg
|
||||||
|
Resources/
|
||||||
|
bin/
|
||||||
|
compile_commands.json
|
||||||
|
key
|
||||||
|
out/
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
|
||||||
project(Launcher)
|
project(Launcher)
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
@@ -7,11 +8,16 @@ if (WIN32)
|
|||||||
STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
|
STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
|
||||||
endif(WIN32)
|
endif(WIN32)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
|
||||||
|
|
||||||
|
add_compile_definitions(CPPHTTPLIB_OPENSSL_SUPPORT)
|
||||||
|
|
||||||
file(GLOB source_files "src/*.cpp" "src/*/*.cpp" "src/*/*.hpp" "include/*.h" "include/*/*.h" "include/*/*/*.h" "include/*.hpp" "include/*/*.hpp" "include/*/*/*.hpp")
|
file(GLOB source_files "src/*.cpp" "src/*/*.cpp" "src/*/*.hpp" "include/*.h" "include/*/*.h" "include/*/*/*.h" "include/*.hpp" "include/*/*.hpp" "include/*/*/*.hpp")
|
||||||
|
find_package(httplib CONFIG REQUIRED)
|
||||||
|
find_package(nlohmann_json CONFIG REQUIRED)
|
||||||
|
find_package(CURL REQUIRED)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} ${source_files})
|
add_executable(${PROJECT_NAME} ${source_files})
|
||||||
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "BeamMP-Launcher")
|
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "BeamMP-Launcher")
|
||||||
@@ -19,20 +25,16 @@ set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "BeamMP-Launcher")
|
|||||||
if (WIN32)
|
if (WIN32)
|
||||||
find_package(ZLIB REQUIRED)
|
find_package(ZLIB REQUIRED)
|
||||||
find_package(OpenSSL REQUIRED)
|
find_package(OpenSSL REQUIRED)
|
||||||
#-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||||
set(VcpkgRoot ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET})
|
ZLIB::ZLIB OpenSSL::SSL OpenSSL::Crypto ws2_32 httplib::httplib nlohmann_json::nlohmann_json CURL::libcurl)
|
||||||
include_directories(${VcpkgRoot}/include)
|
elseif (UNIX)
|
||||||
link_directories(${VcpkgRoot}/lib)
|
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE ${VcpkgRoot}/lib/discord-rpc.lib
|
|
||||||
ZLIB::ZLIB OpenSSL::SSL OpenSSL::Crypto ws2_32)
|
|
||||||
elseif (LINUX)
|
|
||||||
find_package(ZLIB REQUIRED)
|
find_package(ZLIB REQUIRED)
|
||||||
find_package(OpenSSL REQUIRED)
|
find_package(OpenSSL REQUIRED)
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||||
ZLIB::ZLIB OpenSSL::SSL OpenSSL::Crypto)
|
ZLIB::ZLIB OpenSSL::SSL OpenSSL::Crypto CURL::libcurl)
|
||||||
else(WIN32) #MINGW
|
else(WIN32) #MINGW
|
||||||
add_definitions("-D_WIN32_WINNT=0x0600")
|
add_definitions("-D_WIN32_WINNT=0x0600")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -s --static")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -s --static")
|
||||||
target_link_libraries(${PROJECT_NAME} discord-rpc ssl crypto ws2_32 ssp crypt32 z)
|
target_link_libraries(${PROJECT_NAME} ssl crypto ws2_32 ssp crypt32 z CURL::libcurl)
|
||||||
endif(WIN32)
|
endif(WIN32)
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE "include")
|
target_include_directories(${PROJECT_NAME} PRIVATE "include")
|
||||||
|
|||||||
661
LICENSE
Normal file
661
LICENSE
Normal file
@@ -0,0 +1,661 @@
|
|||||||
|
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/>.
|
||||||
23
README.md
Executable file → Normal file
23
README.md
Executable file → Normal file
@@ -2,9 +2,22 @@
|
|||||||
|
|
||||||
The launcher is the way we communitcate to outside the game, it does a few automated actions such as but not limited to: downloading the mod, launching the game, and create a connection to a server.
|
The launcher is the way we communitcate to outside the game, it does a few automated actions such as but not limited to: downloading the mod, launching the game, and create a connection to a server.
|
||||||
|
|
||||||
|
## [Getting started](https://docs.beammp.com/game/getting-started/)
|
||||||
|
|
||||||
Copyright (c) 2019-present Anonymous275.
|
## License
|
||||||
BeamMP Launcher code is not in the public domain and is not free software.
|
|
||||||
One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries,
|
BeamMP Launcher, a launcher for the BeamMP mod for BeamNG.drive
|
||||||
the only permission that has been granted is to use the software in its compiled form as distributed from the BeamMP.com website.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
|
||||||
|
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/>.
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
|
||||||
///
|
|
||||||
/// Created by Anonymous275 on 7/16/2020
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include <string>
|
|
||||||
void Discord_Main();
|
|
||||||
std::string GetDName();
|
|
||||||
std::string GetDTag();
|
|
||||||
std::string GetDID();
|
|
||||||
void DAboard();
|
|
||||||
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#if defined(DISCORD_DYNAMIC_LIB)
|
|
||||||
#if defined(_WIN32)
|
|
||||||
#if defined(DISCORD_BUILDING_SDK)
|
|
||||||
#define DISCORD_EXPORT __declspec(dllexport)
|
|
||||||
#else
|
|
||||||
#define DISCORD_EXPORT __declspec(dllimport)
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define DISCORD_EXPORT __attribute__((visibility("default")))
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define DISCORD_EXPORT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
DISCORD_EXPORT void Discord_Register(const char* applicationId, const char* command);
|
|
||||||
DISCORD_EXPORT void Discord_RegisterSteamGame(const char* applicationId, const char* steamId);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
|
|
||||||
#if defined(DISCORD_DYNAMIC_LIB)
|
|
||||||
# if defined(_WIN32)
|
|
||||||
# if defined(DISCORD_BUILDING_SDK)
|
|
||||||
# define DISCORD_EXPORT __declspec(dllexport)
|
|
||||||
# else
|
|
||||||
# define DISCORD_EXPORT __declspec(dllimport)
|
|
||||||
# endif
|
|
||||||
# else
|
|
||||||
# define DISCORD_EXPORT __attribute__((visibility("default")))
|
|
||||||
# endif
|
|
||||||
#else
|
|
||||||
# define DISCORD_EXPORT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// clang-format on
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct DiscordRichPresence {
|
|
||||||
const char* state; /* max 128 bytes */
|
|
||||||
const char* details; /* max 128 bytes */
|
|
||||||
int64_t startTimestamp;
|
|
||||||
int64_t endTimestamp;
|
|
||||||
const char* largeImageKey; /* max 32 bytes */
|
|
||||||
const char* largeImageText; /* max 128 bytes */
|
|
||||||
const char* smallImageKey; /* max 32 bytes */
|
|
||||||
const char* smallImageText; /* max 128 bytes */
|
|
||||||
const char* partyId; /* max 128 bytes */
|
|
||||||
int partySize;
|
|
||||||
int partyMax;
|
|
||||||
const char* matchSecret; /* max 128 bytes */
|
|
||||||
const char* joinSecret; /* max 128 bytes */
|
|
||||||
const char* spectateSecret; /* max 128 bytes */
|
|
||||||
int8_t instance;
|
|
||||||
} DiscordRichPresence;
|
|
||||||
|
|
||||||
typedef struct DiscordUser {
|
|
||||||
const char* userId;
|
|
||||||
const char* username;
|
|
||||||
const char* discriminator;
|
|
||||||
const char* avatar;
|
|
||||||
} DiscordUser;
|
|
||||||
|
|
||||||
typedef struct DiscordEventHandlers {
|
|
||||||
void (*ready)(const DiscordUser* request);
|
|
||||||
void (*disconnected)(int errorCode, const char* message);
|
|
||||||
void (*errored)(int errorCode, const char* message);
|
|
||||||
void (*joinGame)(const char* joinSecret);
|
|
||||||
void (*spectateGame)(const char* spectateSecret);
|
|
||||||
void (*joinRequest)(const DiscordUser* request);
|
|
||||||
} DiscordEventHandlers;
|
|
||||||
|
|
||||||
#define DISCORD_REPLY_NO 0
|
|
||||||
#define DISCORD_REPLY_YES 1
|
|
||||||
#define DISCORD_REPLY_IGNORE 2
|
|
||||||
|
|
||||||
DISCORD_EXPORT void Discord_Initialize(const char* applicationId,
|
|
||||||
DiscordEventHandlers* handlers,
|
|
||||||
int autoRegister,
|
|
||||||
const char* optionalSteamId);
|
|
||||||
DISCORD_EXPORT void Discord_Shutdown(void);
|
|
||||||
|
|
||||||
/* checks for incoming messages, dispatches callbacks */
|
|
||||||
DISCORD_EXPORT void Discord_RunCallbacks(void);
|
|
||||||
|
|
||||||
/* If you disable the lib starting its own io thread, you'll need to call this from your own */
|
|
||||||
#ifdef DISCORD_DISABLE_IO_THREAD
|
|
||||||
DISCORD_EXPORT void Discord_UpdateConnection(void);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
DISCORD_EXPORT void Discord_UpdatePresence(const DiscordRichPresence* presence);
|
|
||||||
DISCORD_EXPORT void Discord_ClearPresence(void);
|
|
||||||
|
|
||||||
DISCORD_EXPORT void Discord_Respond(const char* userid, /* DISCORD_REPLY_ */ int reply);
|
|
||||||
|
|
||||||
DISCORD_EXPORT void Discord_UpdateHandlers(DiscordEventHandlers* handlers);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
} /* extern "C" */
|
|
||||||
#endif
|
|
||||||
25
include/Http.h
Executable file → Normal file
25
include/Http.h
Executable file → Normal file
@@ -1,20 +1,21 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
/*
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
///
|
*/
|
||||||
/// Created by Anonymous275 on 7/18/2020
|
|
||||||
///
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
class HTTP {
|
class HTTP {
|
||||||
public:
|
public:
|
||||||
static bool Download(const std::string &IP, const std::string &Path);
|
static bool Download(const std::string& IP, const beammp_fs_string& Path, const std::string& Hash);
|
||||||
static std::string Post(const std::string& IP, const std::string& Fields);
|
static std::string Post(const std::string& IP, const std::string& Fields);
|
||||||
static std::string Get(const std::string &IP);
|
static std::string Get(const std::string& IP);
|
||||||
static bool ProgressBar(size_t c, size_t t);
|
static bool ProgressBar(size_t c, size_t t);
|
||||||
|
static void StartProxy();
|
||||||
public:
|
public:
|
||||||
static bool isDownload;
|
static bool isDownload;
|
||||||
static std::string Codes_[];
|
};
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
|
||||||
///
|
|
||||||
/// Created by Anonymous275 on 11/27/2020
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include "rapidjson/stringbuffer.h"
|
|
||||||
#include "rapidjson/document.h"
|
|
||||||
#include "rapidjson/writer.h"
|
|
||||||
namespace json = rapidjson;
|
|
||||||
23
include/Logger.h
Executable file → Normal file
23
include/Logger.h
Executable file → Normal file
@@ -1,13 +1,12 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
/*
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
///
|
*/
|
||||||
/// Created by Anonymous275 on 4/2/2020.
|
|
||||||
///
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
void InitLog();
|
void InitLog();
|
||||||
void except(const std::string& toPrint);
|
void except(const std::string& toPrint);
|
||||||
void fatal(const std::string& toPrint);
|
void fatal(const std::string& toPrint);
|
||||||
@@ -15,3 +14,11 @@ void debug(const std::string& toPrint);
|
|||||||
void error(const std::string& toPrint);
|
void error(const std::string& toPrint);
|
||||||
void info(const std::string& toPrint);
|
void info(const std::string& toPrint);
|
||||||
void warn(const std::string& toPrint);
|
void warn(const std::string& toPrint);
|
||||||
|
|
||||||
|
void except(const std::wstring& toPrint);
|
||||||
|
void fatal(const std::wstring& toPrint);
|
||||||
|
void debug(const std::wstring& toPrint);
|
||||||
|
void error(const std::wstring& toPrint);
|
||||||
|
void info(const std::wstring& toPrint);
|
||||||
|
void warn(const std::wstring& toPrint);
|
||||||
|
std::string getDate();
|
||||||
|
|||||||
39
include/Network/network.hpp
Executable file → Normal file
39
include/Network/network.hpp
Executable file → Normal file
@@ -1,56 +1,57 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
/*
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
///
|
*/
|
||||||
/// Created by Anonymous275 on 7/18/2020
|
|
||||||
///
|
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <filesystem>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#include <cstdint>
|
|
||||||
#include "linuxfixes.h"
|
#include "linuxfixes.h"
|
||||||
#include <bits/types/siginfo_t.h>
|
#include <bits/types/siginfo_t.h>
|
||||||
|
#include <cstdint>
|
||||||
#include <sys/ucontext.h>
|
#include <sys/ucontext.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void NetReset();
|
void NetReset();
|
||||||
extern bool Dev;
|
extern bool Dev;
|
||||||
extern int ping;
|
extern int ping;
|
||||||
|
|
||||||
[[noreturn]] void CoreNetwork();
|
[[noreturn]] void CoreNetwork();
|
||||||
|
extern int ProxyPort;
|
||||||
extern int ClientID;
|
extern int ClientID;
|
||||||
extern int LastPort;
|
extern int LastPort;
|
||||||
extern bool ModLoaded;
|
extern bool ModLoaded;
|
||||||
extern bool Terminate;
|
extern bool Terminate;
|
||||||
extern int DEFAULT_PORT;
|
|
||||||
extern uint64_t UDPSock;
|
extern uint64_t UDPSock;
|
||||||
extern uint64_t TCPSock;
|
extern uint64_t TCPSock;
|
||||||
extern std::string Branch;
|
extern std::string Branch;
|
||||||
|
extern std::filesystem::path CachingDirectory;
|
||||||
|
extern bool deleteDuplicateMods;
|
||||||
extern bool TCPTerminate;
|
extern bool TCPTerminate;
|
||||||
extern std::string LastIP;
|
extern std::string LastIP;
|
||||||
extern std::string MStatus;
|
extern std::string MStatus;
|
||||||
extern std::string UlStatus;
|
extern std::string UlStatus;
|
||||||
extern std::string PublicKey;
|
extern std::string PublicKey;
|
||||||
extern std::string ListOfMods;
|
extern std::string PrivateKey;
|
||||||
int KillSocket(uint64_t Dead);
|
int KillSocket(uint64_t Dead);
|
||||||
void UUl(const std::string& R);
|
void UUl(const std::string& R);
|
||||||
void UDPSend(std::string Data);
|
void UDPSend(std::string Data);
|
||||||
bool CheckBytes(int32_t Bytes);
|
bool CheckBytes(int32_t Bytes);
|
||||||
void GameSend(std::string Data);
|
void GameSend(std::string_view Data);
|
||||||
void SendLarge(std::string Data);
|
void SendLarge(std::string Data);
|
||||||
std::string TCPRcv(uint64_t Sock);
|
std::string TCPRcv(uint64_t Sock);
|
||||||
void SyncResources(uint64_t TCPSock);
|
void SyncResources(uint64_t TCPSock);
|
||||||
std::string GetAddr(const std::string&IP);
|
std::string GetAddr(const std::string& IP);
|
||||||
void ServerParser(const std::string& Data);
|
void ServerParser(std::string_view Data);
|
||||||
std::string Login(const std::string& fields);
|
std::string Login(const std::string& fields);
|
||||||
void TCPSend(const std::string&Data,uint64_t Sock);
|
void TCPSend(const std::string& Data, uint64_t Sock);
|
||||||
void TCPClientMain(const std::string& IP,int Port);
|
void TCPClientMain(const std::string& IP, int Port);
|
||||||
void UDPClientMain(const std::string& IP,int Port);
|
void UDPClientMain(const std::string& IP, int Port);
|
||||||
void TCPGameServer(const std::string& IP, int Port);
|
void TCPGameServer(const std::string& IP, int Port);
|
||||||
|
bool SecurityWarning();
|
||||||
|
void CoreSend(std::string data);
|
||||||
|
|||||||
31
include/Options.h
Normal file
31
include/Options.h
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
struct Options {
|
||||||
|
#if defined(_WIN32)
|
||||||
|
std::string executable_name = "BeamMP-Launcher.exe";
|
||||||
|
#elif defined(__linux__)
|
||||||
|
std::string executable_name = "BeamMP-Launcher";
|
||||||
|
#endif
|
||||||
|
unsigned int port = 4444;
|
||||||
|
bool verbose = false;
|
||||||
|
bool no_download = false;
|
||||||
|
bool no_update = false;
|
||||||
|
bool no_launch = false;
|
||||||
|
const char* user_path = nullptr;
|
||||||
|
const char **game_arguments = nullptr;
|
||||||
|
int game_arguments_length = 0;
|
||||||
|
const char** argv = nullptr;
|
||||||
|
int argc = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
void InitOptions(int argc, const char *argv[], Options &options);
|
||||||
|
|
||||||
|
extern Options options;
|
||||||
13
include/Security/Game.h
Executable file → Normal file
13
include/Security/Game.h
Executable file → Normal file
@@ -1,9 +1,8 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
/*
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
///
|
*/
|
||||||
/// Created by Anonymous275 on 7/19/2020
|
|
||||||
///
|
|
||||||
#pragma once
|
#pragma once
|
||||||
extern unsigned long GamePID;
|
extern unsigned long GamePID;
|
||||||
|
|||||||
21
include/Security/Init.h
Executable file → Normal file
21
include/Security/Init.h
Executable file → Normal file
@@ -1,15 +1,14 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
/*
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
///
|
*/
|
||||||
/// Created by Anonymous275 on 7/18/2020
|
|
||||||
///
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
void PreGame(const std::string& GamePath);
|
void PreGame(const beammp_fs_string& GamePath);
|
||||||
std::string CheckVer(const std::string &path);
|
std::string CheckVer(const std::filesystem::path& path);
|
||||||
void InitGame(const std::string& Dir);
|
void InitGame(const beammp_fs_string& Dir);
|
||||||
std::string GetGameDir();
|
beammp_fs_string GetGameDir();
|
||||||
void LegitimacyCheck();
|
void LegitimacyCheck();
|
||||||
void CheckLocalKey();
|
void CheckLocalKey();
|
||||||
29
include/Startup.h
Executable file → Normal file
29
include/Startup.h
Executable file → Normal file
@@ -1,16 +1,21 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
/*
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
///
|
*/
|
||||||
/// Created by Anonymous275 on 7/18/2020
|
|
||||||
///
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
#include <compare>
|
||||||
#include <string>
|
#include <string>
|
||||||
void InitLauncher(int argc, char* argv[]);
|
#include <vector>
|
||||||
std::string GetEP(char*P = nullptr);
|
|
||||||
std::string GetGamePath();
|
void InitLauncher();
|
||||||
|
beammp_fs_string GetEP(const beammp_fs_char* P = nullptr);
|
||||||
|
std::filesystem::path GetBP(const beammp_fs_char* P = nullptr);
|
||||||
|
std::filesystem::path GetGamePath();
|
||||||
std::string GetVer();
|
std::string GetVer();
|
||||||
std::string GetEN();
|
std::string GetPatch();
|
||||||
|
beammp_fs_string GetEN();
|
||||||
void ConfigInit();
|
void ConfigInit();
|
||||||
extern bool Dev;
|
|
||||||
294
include/Utils.h
Normal file
294
include/Utils.h
Normal file
@@ -0,0 +1,294 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <cassert>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <locale>
|
||||||
|
#include <map>
|
||||||
|
#include <openssl/err.h>
|
||||||
|
#include <openssl/evp.h>
|
||||||
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
#include <variant>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define beammp_fs_string std::wstring
|
||||||
|
#define beammp_fs_char wchar_t
|
||||||
|
#define beammp_wide(str) L##str
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#define beammp_fs_string std::string
|
||||||
|
#define beammp_fs_char char
|
||||||
|
#define beammp_wide(str) str
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace Utils {
|
||||||
|
inline std::vector<std::string> Split(const std::string& String, const std::string& delimiter) {
|
||||||
|
std::vector<std::string> Val;
|
||||||
|
size_t pos;
|
||||||
|
std::string token, s = String;
|
||||||
|
while ((pos = s.find(delimiter)) != std::string::npos) {
|
||||||
|
token = s.substr(0, pos);
|
||||||
|
if (!token.empty())
|
||||||
|
Val.push_back(token);
|
||||||
|
s.erase(0, pos + delimiter.length());
|
||||||
|
}
|
||||||
|
if (!s.empty())
|
||||||
|
Val.push_back(s);
|
||||||
|
return Val;
|
||||||
|
};
|
||||||
|
inline std::string ExpandEnvVars(const std::string& input) {
|
||||||
|
std::string result;
|
||||||
|
std::regex envPattern(R"(%([^%]+)%|\$([A-Za-z_][A-Za-z0-9_]*)|\$\{([^}]+)\})");
|
||||||
|
|
||||||
|
std::sregex_iterator begin(input.begin(), input.end(), envPattern);
|
||||||
|
std::sregex_iterator end;
|
||||||
|
|
||||||
|
size_t lastPos = 0;
|
||||||
|
|
||||||
|
for (auto it = begin; it != end; ++it) {
|
||||||
|
const auto& match = *it;
|
||||||
|
|
||||||
|
result.append(input, lastPos, match.position() - lastPos);
|
||||||
|
|
||||||
|
std::string varName;
|
||||||
|
if (match[1].matched) varName = match[1].str(); // %VAR%
|
||||||
|
else if (match[2].matched) varName = match[2].str(); // $VAR
|
||||||
|
else if (match[3].matched) varName = match[3].str(); // ${VAR}
|
||||||
|
|
||||||
|
if (const char* envValue = std::getenv(varName.c_str())) {
|
||||||
|
result.append(envValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
lastPos = match.position() + match.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
result.append(input, lastPos, input.length() - lastPos);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#ifdef _WIN32
|
||||||
|
inline std::wstring ExpandEnvVars(const std::wstring& input) {
|
||||||
|
std::wstring result;
|
||||||
|
std::wregex envPattern(LR"(%([^%]+)%|\$([A-Za-z_][A-Za-z0-9_]*)|\$\{([^}]+)\})");
|
||||||
|
|
||||||
|
std::wsregex_iterator begin(input.begin(), input.end(), envPattern);
|
||||||
|
std::wsregex_iterator end;
|
||||||
|
|
||||||
|
size_t lastPos = 0;
|
||||||
|
|
||||||
|
for (auto it = begin; it != end; ++it) {
|
||||||
|
const auto& match = *it;
|
||||||
|
|
||||||
|
result.append(input, lastPos, match.position() - lastPos);
|
||||||
|
|
||||||
|
std::wstring varName;
|
||||||
|
assert(match.size() == 4 && "Input regex has incorrect amount of capturing groups");
|
||||||
|
if (match[1].matched) varName = match[1].str(); // %VAR%
|
||||||
|
else if (match[2].matched) varName = match[2].str(); // $VAR
|
||||||
|
else if (match[3].matched) varName = match[3].str(); // ${VAR}
|
||||||
|
|
||||||
|
if (const wchar_t* envValue = _wgetenv(varName.c_str())) {
|
||||||
|
if (envValue != nullptr) {
|
||||||
|
result.append(envValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lastPos = match.position() + match.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
result.append(input, lastPos, input.length() - lastPos);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
inline std::map<std::string, std::variant<std::map<std::string, std::string>, std::string>> ParseINI(const std::string& contents) {
|
||||||
|
std::map<std::string, std::variant<std::map<std::string, std::string>, std::string>> ini;
|
||||||
|
|
||||||
|
std::string currentSection;
|
||||||
|
auto sections = Split(contents, "\n");
|
||||||
|
|
||||||
|
for (size_t i = 0; i < sections.size(); i++) {
|
||||||
|
std::string line = sections[i];
|
||||||
|
if (line.empty() || line[0] == ';' || line[0] == '#')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (auto& c : line) {
|
||||||
|
if (c == '#' || c == ';') {
|
||||||
|
line = line.substr(0, &c - &line[0]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto invalidLineLog = [&]{
|
||||||
|
debug("Invalid INI line: " + line);
|
||||||
|
debug("Surrounding lines: \n" +
|
||||||
|
(i > 0 ? sections[i - 1] : "") + "\n" +
|
||||||
|
(i < sections.size() - 1 ? sections[i + 1] : ""));
|
||||||
|
};
|
||||||
|
|
||||||
|
if (line[0] == '[') {
|
||||||
|
currentSection = line.substr(1, line.find(']') - 1);
|
||||||
|
} else {
|
||||||
|
std::string key, value;
|
||||||
|
size_t pos = line.find('=');
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
key = line.substr(0, pos);
|
||||||
|
|
||||||
|
key = key.substr(0, key.find_last_not_of(" \t") + 1);
|
||||||
|
|
||||||
|
value = line.substr(pos + 1);
|
||||||
|
if (currentSection.empty()) {
|
||||||
|
ini[key] = value;
|
||||||
|
} else {
|
||||||
|
std::get<std::map<std::string, std::string>>(ini[currentSection])[key] = value;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
invalidLineLog();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
key.erase(key.find_last_not_of(" \t") + 1);
|
||||||
|
value.erase(0, value.find_first_not_of(" \t"));
|
||||||
|
value.erase(value.find_last_not_of(" \t") + 1);
|
||||||
|
|
||||||
|
std::get<std::map<std::string, std::string>>(ini[currentSection])[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ini;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
inline std::wstring ToWString(const std::string& s) {
|
||||||
|
if (s.empty()) return std::wstring();
|
||||||
|
|
||||||
|
int size_needed = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), (int)s.size(), nullptr, 0);
|
||||||
|
if (size_needed <= 0) {
|
||||||
|
return L"";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring result(size_needed, 0);
|
||||||
|
|
||||||
|
MultiByteToWideChar(CP_UTF8, 0, s.c_str(), (int)s.size(), &result[0], size_needed);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
inline std::string ToWString(const std::string& s) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
inline std::string GetSha256HashReallyFastFile(const beammp_fs_string& filename) {
|
||||||
|
try {
|
||||||
|
EVP_MD_CTX* mdctx;
|
||||||
|
const EVP_MD* md;
|
||||||
|
uint8_t sha256_value[EVP_MAX_MD_SIZE];
|
||||||
|
md = EVP_sha256();
|
||||||
|
if (md == nullptr) {
|
||||||
|
throw std::runtime_error("EVP_sha256() failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
mdctx = EVP_MD_CTX_new();
|
||||||
|
if (mdctx == nullptr) {
|
||||||
|
throw std::runtime_error("EVP_MD_CTX_new() failed");
|
||||||
|
}
|
||||||
|
if (!EVP_DigestInit_ex2(mdctx, md, NULL)) {
|
||||||
|
EVP_MD_CTX_free(mdctx);
|
||||||
|
throw std::runtime_error("EVP_DigestInit_ex2() failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ifstream stream(filename, std::ios::binary);
|
||||||
|
|
||||||
|
const size_t FileSize = std::filesystem::file_size(filename);
|
||||||
|
size_t Read = 0;
|
||||||
|
std::vector<char> Data;
|
||||||
|
while (Read < FileSize) {
|
||||||
|
Data.resize(size_t(std::min<size_t>(FileSize - Read, 4096)));
|
||||||
|
size_t RealDataSize = Data.size();
|
||||||
|
stream.read(Data.data(), std::streamsize(Data.size()));
|
||||||
|
if (stream.eof() || stream.fail()) {
|
||||||
|
RealDataSize = size_t(stream.gcount());
|
||||||
|
}
|
||||||
|
Data.resize(RealDataSize);
|
||||||
|
if (RealDataSize == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (RealDataSize > 0 && !EVP_DigestUpdate(mdctx, Data.data(), Data.size())) {
|
||||||
|
EVP_MD_CTX_free(mdctx);
|
||||||
|
throw std::runtime_error("EVP_DigestUpdate() failed");
|
||||||
|
}
|
||||||
|
Read += RealDataSize;
|
||||||
|
}
|
||||||
|
unsigned int sha256_len = 0;
|
||||||
|
if (!EVP_DigestFinal_ex(mdctx, sha256_value, &sha256_len)) {
|
||||||
|
EVP_MD_CTX_free(mdctx);
|
||||||
|
throw std::runtime_error("EVP_DigestFinal_ex() failed");
|
||||||
|
}
|
||||||
|
EVP_MD_CTX_free(mdctx);
|
||||||
|
|
||||||
|
std::string result;
|
||||||
|
for (size_t i = 0; i < sha256_len; i++) {
|
||||||
|
char buf[3];
|
||||||
|
sprintf(buf, "%02x", sha256_value[i]);
|
||||||
|
buf[2] = '\0';
|
||||||
|
result += buf;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
error(beammp_wide("Sha256 hashing of '") + filename + beammp_wide("' failed: ") + ToWString(e.what()));
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inline std::string GetSha256HashReallyFast(const std::string& text, const beammp_fs_string& filename) {
|
||||||
|
try {
|
||||||
|
EVP_MD_CTX* mdctx;
|
||||||
|
const EVP_MD* md;
|
||||||
|
uint8_t sha256_value[EVP_MAX_MD_SIZE];
|
||||||
|
md = EVP_sha256();
|
||||||
|
if (md == nullptr) {
|
||||||
|
throw std::runtime_error("EVP_sha256() failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
mdctx = EVP_MD_CTX_new();
|
||||||
|
if (mdctx == nullptr) {
|
||||||
|
throw std::runtime_error("EVP_MD_CTX_new() failed");
|
||||||
|
}
|
||||||
|
if (!EVP_DigestInit_ex2(mdctx, md, NULL)) {
|
||||||
|
EVP_MD_CTX_free(mdctx);
|
||||||
|
throw std::runtime_error("EVP_DigestInit_ex2() failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!EVP_DigestUpdate(mdctx, text.data(), text.size())) {
|
||||||
|
EVP_MD_CTX_free(mdctx);
|
||||||
|
throw std::runtime_error("EVP_DigestUpdate() failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int sha256_len = 0;
|
||||||
|
if (!EVP_DigestFinal_ex(mdctx, sha256_value, &sha256_len)) {
|
||||||
|
EVP_MD_CTX_free(mdctx);
|
||||||
|
throw std::runtime_error("EVP_DigestFinal_ex() failed");
|
||||||
|
}
|
||||||
|
EVP_MD_CTX_free(mdctx);
|
||||||
|
|
||||||
|
std::string result;
|
||||||
|
for (size_t i = 0; i < sha256_len; i++) {
|
||||||
|
char buf[3];
|
||||||
|
sprintf(buf, "%02x", sha256_value[i]);
|
||||||
|
buf[2] = '\0';
|
||||||
|
result += buf;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
error(beammp_wide("Sha256 hashing of '") + filename + beammp_wide("' failed: ") + ToWString(e.what()));
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
21
include/Zlib/Compressor.h
Executable file → Normal file
21
include/Zlib/Compressor.h
Executable file → Normal file
@@ -1,11 +1,12 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
/*
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
///
|
*/
|
||||||
/// Created by Anonymous275 on 7/24/2020
|
|
||||||
///
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <span>
|
||||||
std::string Comp(std::string Data);
|
#include <vector>
|
||||||
std::string DeComp(std::string Compressed);
|
|
||||||
|
std::vector<char> Comp(std::span<const char> input);
|
||||||
|
std::vector<char> DeComp(std::span<const char> input);
|
||||||
|
|||||||
4642
include/hashpp.h
Normal file
4642
include/hashpp.h
Normal file
File diff suppressed because it is too large
Load Diff
7578
include/httplib.h
7578
include/httplib.h
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef _LINUXFIXES_H
|
#ifndef _LINUXFIXES_H
|
||||||
#define _LINUXFIXES_H
|
#define _LINUXFIXES_H
|
||||||
|
|
||||||
@@ -11,7 +17,7 @@
|
|||||||
#define closesocket close
|
#define closesocket close
|
||||||
#define SD_BOTH SHUT_RDWR
|
#define SD_BOTH SHUT_RDWR
|
||||||
// We dont need wsacleanup
|
// We dont need wsacleanup
|
||||||
#define WSACleanup()
|
#define WSACleanup()
|
||||||
#define SOCKET_ERROR -1
|
#define SOCKET_ERROR -1
|
||||||
|
|
||||||
#define ZeroMemory(mem, len) memset(mem, 0, len)
|
#define ZeroMemory(mem, len) memset(mem, 0, len)
|
||||||
|
|||||||
0
include/rapidjson/allocators.h
Executable file → Normal file
0
include/rapidjson/allocators.h
Executable file → Normal file
0
include/rapidjson/cursorstreamwrapper.h
Executable file → Normal file
0
include/rapidjson/cursorstreamwrapper.h
Executable file → Normal file
0
include/rapidjson/document.h
Executable file → Normal file
0
include/rapidjson/document.h
Executable file → Normal file
0
include/rapidjson/encodedstream.h
Executable file → Normal file
0
include/rapidjson/encodedstream.h
Executable file → Normal file
0
include/rapidjson/encodings.h
Executable file → Normal file
0
include/rapidjson/encodings.h
Executable file → Normal file
0
include/rapidjson/error/en.h
Executable file → Normal file
0
include/rapidjson/error/en.h
Executable file → Normal file
0
include/rapidjson/error/error.h
Executable file → Normal file
0
include/rapidjson/error/error.h
Executable file → Normal file
0
include/rapidjson/filereadstream.h
Executable file → Normal file
0
include/rapidjson/filereadstream.h
Executable file → Normal file
0
include/rapidjson/filewritestream.h
Executable file → Normal file
0
include/rapidjson/filewritestream.h
Executable file → Normal file
0
include/rapidjson/fwd.h
Executable file → Normal file
0
include/rapidjson/fwd.h
Executable file → Normal file
0
include/rapidjson/internal/biginteger.h
Executable file → Normal file
0
include/rapidjson/internal/biginteger.h
Executable file → Normal file
0
include/rapidjson/internal/clzll.h
Executable file → Normal file
0
include/rapidjson/internal/clzll.h
Executable file → Normal file
0
include/rapidjson/internal/diyfp.h
Executable file → Normal file
0
include/rapidjson/internal/diyfp.h
Executable file → Normal file
0
include/rapidjson/internal/dtoa.h
Executable file → Normal file
0
include/rapidjson/internal/dtoa.h
Executable file → Normal file
0
include/rapidjson/internal/ieee754.h
Executable file → Normal file
0
include/rapidjson/internal/ieee754.h
Executable file → Normal file
0
include/rapidjson/internal/itoa.h
Executable file → Normal file
0
include/rapidjson/internal/itoa.h
Executable file → Normal file
0
include/rapidjson/internal/meta.h
Executable file → Normal file
0
include/rapidjson/internal/meta.h
Executable file → Normal file
0
include/rapidjson/internal/pow10.h
Executable file → Normal file
0
include/rapidjson/internal/pow10.h
Executable file → Normal file
0
include/rapidjson/internal/regex.h
Executable file → Normal file
0
include/rapidjson/internal/regex.h
Executable file → Normal file
0
include/rapidjson/internal/stack.h
Executable file → Normal file
0
include/rapidjson/internal/stack.h
Executable file → Normal file
0
include/rapidjson/internal/strfunc.h
Executable file → Normal file
0
include/rapidjson/internal/strfunc.h
Executable file → Normal file
0
include/rapidjson/internal/strtod.h
Executable file → Normal file
0
include/rapidjson/internal/strtod.h
Executable file → Normal file
0
include/rapidjson/internal/swap.h
Executable file → Normal file
0
include/rapidjson/internal/swap.h
Executable file → Normal file
0
include/rapidjson/istreamwrapper.h
Executable file → Normal file
0
include/rapidjson/istreamwrapper.h
Executable file → Normal file
0
include/rapidjson/memorybuffer.h
Executable file → Normal file
0
include/rapidjson/memorybuffer.h
Executable file → Normal file
0
include/rapidjson/memorystream.h
Executable file → Normal file
0
include/rapidjson/memorystream.h
Executable file → Normal file
0
include/rapidjson/msinttypes/inttypes.h
Executable file → Normal file
0
include/rapidjson/msinttypes/inttypes.h
Executable file → Normal file
0
include/rapidjson/msinttypes/stdint.h
Executable file → Normal file
0
include/rapidjson/msinttypes/stdint.h
Executable file → Normal file
0
include/rapidjson/ostreamwrapper.h
Executable file → Normal file
0
include/rapidjson/ostreamwrapper.h
Executable file → Normal file
0
include/rapidjson/pointer.h
Executable file → Normal file
0
include/rapidjson/pointer.h
Executable file → Normal file
0
include/rapidjson/prettywriter.h
Executable file → Normal file
0
include/rapidjson/prettywriter.h
Executable file → Normal file
0
include/rapidjson/rapidjson.h
Executable file → Normal file
0
include/rapidjson/rapidjson.h
Executable file → Normal file
0
include/rapidjson/reader.h
Executable file → Normal file
0
include/rapidjson/reader.h
Executable file → Normal file
0
include/rapidjson/schema.h
Executable file → Normal file
0
include/rapidjson/schema.h
Executable file → Normal file
0
include/rapidjson/stream.h
Executable file → Normal file
0
include/rapidjson/stream.h
Executable file → Normal file
0
include/rapidjson/stringbuffer.h
Executable file → Normal file
0
include/rapidjson/stringbuffer.h
Executable file → Normal file
0
include/rapidjson/writer.h
Executable file → Normal file
0
include/rapidjson/writer.h
Executable file → Normal file
104
src/Compressor.cpp
Executable file → Normal file
104
src/Compressor.cpp
Executable file → Normal file
@@ -1,57 +1,61 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
/*
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
///
|
*/
|
||||||
/// Created by Anonymous275 on 7/15/2020
|
|
||||||
///
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
#include "Logger.h"
|
||||||
|
#include <span>
|
||||||
|
#include <vector>
|
||||||
|
#include <zconf.h>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define Biggest 30000
|
std::vector<char> Comp(std::span<const char> input) {
|
||||||
std::string Comp(std::string Data){
|
auto max_size = compressBound(input.size());
|
||||||
char*C = new char[Biggest];
|
std::vector<char> output(max_size);
|
||||||
memset(C, 0, Biggest);
|
uLongf output_size = output.size();
|
||||||
z_stream defstream;
|
int res = compress(
|
||||||
defstream.zalloc = Z_NULL;
|
reinterpret_cast<Bytef*>(output.data()),
|
||||||
defstream.zfree = Z_NULL;
|
&output_size,
|
||||||
defstream.opaque = Z_NULL;
|
reinterpret_cast<const Bytef*>(input.data()),
|
||||||
defstream.avail_in = (uInt)Data.length();
|
static_cast<uLongf>(input.size()));
|
||||||
defstream.next_in = (Bytef *)&Data[0];
|
if (res != Z_OK) {
|
||||||
defstream.avail_out = Biggest;
|
error("zlib compress() failed (code: " + std::to_string(res) + ", message: " + zError(res) + ")");
|
||||||
defstream.next_out = reinterpret_cast<Bytef *>(C);
|
throw std::runtime_error("zlib compress() failed");
|
||||||
deflateInit(&defstream, Z_BEST_COMPRESSION);
|
}
|
||||||
deflate(&defstream, Z_SYNC_FLUSH);
|
debug("zlib compressed " + std::to_string(input.size()) + " B to " + std::to_string(output_size) + " B");
|
||||||
deflate(&defstream, Z_FINISH);
|
output.resize(output_size);
|
||||||
deflateEnd(&defstream);
|
return output;
|
||||||
int TO = defstream.total_out;
|
}
|
||||||
std::string Ret(TO,0);
|
|
||||||
memcpy(&Ret[0],C,TO);
|
std::vector<char> DeComp(std::span<const char> input) {
|
||||||
delete [] C;
|
std::vector<char> output_buffer(std::min<size_t>(input.size() * 5, 15 * 1024 * 1024));
|
||||||
return Ret;
|
|
||||||
|
uLongf output_size = output_buffer.size();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
int res = uncompress(
|
||||||
|
reinterpret_cast<Bytef*>(output_buffer.data()),
|
||||||
|
&output_size,
|
||||||
|
reinterpret_cast<const Bytef*>(input.data()),
|
||||||
|
static_cast<uLongf>(input.size()));
|
||||||
|
if (res == Z_BUF_ERROR) {
|
||||||
|
if (output_buffer.size() > 30 * 1024 * 1024) {
|
||||||
|
throw std::runtime_error("decompressed packet size of 30 MB exceeded");
|
||||||
|
}
|
||||||
|
debug("zlib uncompress() failed, trying with 2x buffer size of " + std::to_string(output_buffer.size() * 2));
|
||||||
|
output_buffer.resize(output_buffer.size() * 2);
|
||||||
|
output_size = output_buffer.size();
|
||||||
|
} else if (res != Z_OK) {
|
||||||
|
error("zlib uncompress() failed (code: " + std::to_string(res) + ", message: " + zError(res) + ")");
|
||||||
|
throw std::runtime_error("zlib uncompress() failed");
|
||||||
|
} else if (res == Z_OK) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} output_buffer.resize(output_size);
|
||||||
|
return output_buffer;
|
||||||
}
|
}
|
||||||
std::string DeComp(std::string Compressed){
|
|
||||||
char*C = new char[Biggest];
|
|
||||||
memset(C, 0, Biggest);
|
|
||||||
z_stream infstream;
|
|
||||||
infstream.zalloc = Z_NULL;
|
|
||||||
infstream.zfree = Z_NULL;
|
|
||||||
infstream.opaque = Z_NULL;
|
|
||||||
infstream.avail_in = Biggest;
|
|
||||||
infstream.next_in = (Bytef *)(&Compressed[0]);
|
|
||||||
infstream.avail_out = Biggest;
|
|
||||||
infstream.next_out = (Bytef *)(C);
|
|
||||||
inflateInit(&infstream);
|
|
||||||
inflate(&infstream, Z_SYNC_FLUSH);
|
|
||||||
inflate(&infstream, Z_FINISH);
|
|
||||||
inflateEnd(&infstream);
|
|
||||||
int TO = infstream.total_out;
|
|
||||||
std::string Ret(TO,0);
|
|
||||||
memcpy(&Ret[0],C,TO);
|
|
||||||
delete [] C;
|
|
||||||
return Ret;
|
|
||||||
}
|
|
||||||
142
src/Config.cpp
Executable file → Normal file
142
src/Config.cpp
Executable file → Normal file
@@ -1,59 +1,83 @@
|
|||||||
///
|
/*
|
||||||
/// Created by Anonymous275 on 2/23/2021
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
///
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
#include "Network/network.hpp"
|
*/
|
||||||
#include <filesystem>
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <fstream>
|
#include "Network/network.hpp"
|
||||||
#include "Json.h"
|
#include "Options.h"
|
||||||
#include <cstdint>
|
#include "Utils.h"
|
||||||
namespace fs = std::filesystem;
|
#include <cstdint>
|
||||||
|
#include <filesystem>
|
||||||
std::string Branch;
|
#include <fstream>
|
||||||
void ParseConfig(const json::Document& d){
|
#include <nlohmann/json.hpp>
|
||||||
if(d["Port"].IsInt()){
|
namespace fs = std::filesystem;
|
||||||
DEFAULT_PORT = d["Port"].GetInt();
|
|
||||||
}
|
std::string Branch;
|
||||||
//Default -1
|
std::filesystem::path CachingDirectory = std::filesystem::path("./Resources");
|
||||||
//Release 1
|
bool deleteDuplicateMods = false;
|
||||||
//EA 2
|
|
||||||
//Dev 3
|
void ParseConfig(const nlohmann::json& d) {
|
||||||
//Custom 3
|
if (d["Port"].is_number()) {
|
||||||
|
options.port = d["Port"].get<int>();
|
||||||
if(d["Build"].IsString()){
|
}
|
||||||
Branch = d["Build"].GetString();
|
// Default -1
|
||||||
for(char& c : Branch)c = char(tolower(c));
|
// Release 1
|
||||||
}
|
// EA 2
|
||||||
}
|
// Dev 3
|
||||||
|
// Custom 3
|
||||||
void ConfigInit(){
|
if (d["Build"].is_string()) {
|
||||||
if(fs::exists("Launcher.cfg")){
|
Branch = d["Build"].get<std::string>();
|
||||||
std::ifstream cfg("Launcher.cfg");
|
for (char& c : Branch)
|
||||||
if(cfg.is_open()){
|
c = char(tolower(c));
|
||||||
auto Size = fs::file_size("Launcher.cfg");
|
}
|
||||||
std::string Buffer(Size, 0);
|
if (d.contains("CachingDirectory") && d["CachingDirectory"].is_string()) {
|
||||||
cfg.read(&Buffer[0], Size);
|
CachingDirectory = std::filesystem::path(d["CachingDirectory"].get<std::string>());
|
||||||
cfg.close();
|
info(beammp_wide("Mod caching directory: ") + beammp_fs_string(CachingDirectory.relative_path()));
|
||||||
json::Document d;
|
}
|
||||||
d.Parse(Buffer.c_str());
|
|
||||||
if(d.HasParseError()){
|
if (d.contains("Dev") && d["Dev"].is_boolean()) {
|
||||||
fatal("Config failed to parse make sure it's valid JSON! Code : " + std::to_string(d.GetParseError()));
|
bool dev = d["Dev"].get<bool>();
|
||||||
}
|
options.verbose = dev;
|
||||||
ParseConfig(d);
|
options.no_download = dev;
|
||||||
}else fatal("Failed to open Launcher.cfg!");
|
options.no_launch = dev;
|
||||||
}else{
|
options.no_update = dev;
|
||||||
std::ofstream cfg("Launcher.cfg");
|
}
|
||||||
if(cfg.is_open()){
|
|
||||||
cfg <<
|
if (d.contains(("DeleteDuplicateMods")) && d["DeleteDuplicateMods"].is_boolean()) {
|
||||||
R"({
|
deleteDuplicateMods = d["DeleteDuplicateMods"].get<bool>();
|
||||||
"Port": 4444,
|
}
|
||||||
"Build": "Default"
|
|
||||||
})";
|
}
|
||||||
cfg.close();
|
|
||||||
}else{
|
void ConfigInit() {
|
||||||
fatal("Failed to write config on disk!");
|
if (fs::exists("Launcher.cfg")) {
|
||||||
}
|
std::ifstream cfg("Launcher.cfg");
|
||||||
}
|
if (cfg.is_open()) {
|
||||||
}
|
auto Size = fs::file_size("Launcher.cfg");
|
||||||
|
std::string Buffer(Size, 0);
|
||||||
|
cfg.read(&Buffer[0], Size);
|
||||||
|
cfg.close();
|
||||||
|
nlohmann::json d = nlohmann::json::parse(Buffer, nullptr, false);
|
||||||
|
if (d.is_discarded()) {
|
||||||
|
fatal("Config failed to parse make sure it's valid JSON!");
|
||||||
|
}
|
||||||
|
ParseConfig(d);
|
||||||
|
} else
|
||||||
|
fatal("Failed to open Launcher.cfg!");
|
||||||
|
} else {
|
||||||
|
std::ofstream cfg("Launcher.cfg");
|
||||||
|
if (cfg.is_open()) {
|
||||||
|
cfg <<
|
||||||
|
R"({
|
||||||
|
"Port": 4444,
|
||||||
|
"Build": "Default",
|
||||||
|
"CachingDirectory": "./Resources"
|
||||||
|
})";
|
||||||
|
cfg.close();
|
||||||
|
} else {
|
||||||
|
fatal("Failed to write config on disk!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
116
src/Discord.cpp
116
src/Discord.cpp
@@ -1,116 +0,0 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
|
||||||
///
|
|
||||||
/// Created by Anonymous275 on 7/16/2020
|
|
||||||
///
|
|
||||||
|
|
||||||
#ifndef __linux__
|
|
||||||
|
|
||||||
#include "Discord/discord_rpc.h"
|
|
||||||
#include "Logger.h"
|
|
||||||
#include <cstring>
|
|
||||||
#include <thread>
|
|
||||||
#include <ctime>
|
|
||||||
|
|
||||||
struct DInfo{
|
|
||||||
std::string Name;
|
|
||||||
std::string Tag;
|
|
||||||
std::string DID;
|
|
||||||
};
|
|
||||||
DInfo* DiscordInfo = nullptr;
|
|
||||||
int64_t StartTime;
|
|
||||||
void updateDiscordPresence(){
|
|
||||||
//if (SendPresence) {
|
|
||||||
//char buffer[256];
|
|
||||||
DiscordRichPresence discordPresence;
|
|
||||||
memset(&discordPresence, 0, sizeof(discordPresence));
|
|
||||||
std::string P = "Playing with friends!"; ///to be revisited
|
|
||||||
discordPresence.state = P.c_str();
|
|
||||||
//sprintf(buffer, "Frustration level: %d", FrustrationLevel);
|
|
||||||
//discordPresence.details = buffer;
|
|
||||||
discordPresence.startTimestamp = StartTime;
|
|
||||||
//discordPresence.endTimestamp = time(0) + 5 * 60;
|
|
||||||
|
|
||||||
discordPresence.largeImageKey = "mainlogo";
|
|
||||||
//discordPresence.smallImageKey = "logo";
|
|
||||||
//discordPresence.partyId = "party1234";
|
|
||||||
//discordPresence.partySize = 1;
|
|
||||||
//discordPresence.partyMax = 6;
|
|
||||||
//discordPresence.matchSecret = "xyzzy";
|
|
||||||
//discordPresence.joinSecret = "join";
|
|
||||||
//discordPresence.spectateSecret = "look";
|
|
||||||
//discordPresence.instance = 0;
|
|
||||||
Discord_UpdatePresence(&discordPresence);
|
|
||||||
//}
|
|
||||||
//else {
|
|
||||||
// Discord_ClearPresence();
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
void handleDiscordReady(const DiscordUser* User){
|
|
||||||
DiscordInfo = new DInfo{
|
|
||||||
User->username,
|
|
||||||
User->discriminator,
|
|
||||||
User->userId
|
|
||||||
};
|
|
||||||
}
|
|
||||||
void discordInit(){
|
|
||||||
DiscordEventHandlers handlers;
|
|
||||||
memset(&handlers, 0, sizeof(handlers));
|
|
||||||
handlers.ready = handleDiscordReady;
|
|
||||||
/*handlers.disconnected = handleDiscordDisconnected;
|
|
||||||
handlers.errored = handleDiscordError;
|
|
||||||
handlers.joinGame = handleDiscordJoin;
|
|
||||||
handlers.spectateGame = handleDiscordSpectate;
|
|
||||||
handlers.joinRequest = handleDiscordJoinRequest;*/
|
|
||||||
Discord_Initialize("629743237988352010", &handlers, 1,nullptr);
|
|
||||||
}
|
|
||||||
[[noreturn]] void Loop(){
|
|
||||||
StartTime = time(nullptr);
|
|
||||||
while (true) {
|
|
||||||
updateDiscordPresence();
|
|
||||||
#ifdef DISCORD_DISABLE_IO_THREAD
|
|
||||||
Discord_UpdateConnection();
|
|
||||||
#endif
|
|
||||||
Discord_RunCallbacks();
|
|
||||||
if(DiscordInfo == nullptr){
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(250));
|
|
||||||
}else std::this_thread::sleep_for(std::chrono::seconds(2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DMain(){
|
|
||||||
discordInit();
|
|
||||||
Loop();
|
|
||||||
}
|
|
||||||
std::string GetDName(){
|
|
||||||
return DiscordInfo->Name;
|
|
||||||
}
|
|
||||||
std::string GetDTag(){
|
|
||||||
return DiscordInfo->Tag;
|
|
||||||
}
|
|
||||||
std::string GetDID(){
|
|
||||||
return DiscordInfo->DID;
|
|
||||||
}
|
|
||||||
void DAboard(){
|
|
||||||
DiscordInfo = nullptr;
|
|
||||||
}
|
|
||||||
void ErrorAboard(){
|
|
||||||
error("Discord timeout! please start the discord app and try again after 30 secs");
|
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
|
||||||
exit(6);
|
|
||||||
}
|
|
||||||
void Discord_Main(){
|
|
||||||
/*std::thread t1(DMain);
|
|
||||||
t1.detach();*/
|
|
||||||
/*info("Connecting to discord client...");
|
|
||||||
int C = 0;
|
|
||||||
while(DiscordInfo == nullptr && C < 80){
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
|
||||||
C++;
|
|
||||||
}
|
|
||||||
if(DiscordInfo == nullptr)ErrorAboard();*/
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
195
src/GameStart.cpp
Executable file → Normal file
195
src/GameStart.cpp
Executable file → Normal file
@@ -1,89 +1,174 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
/*
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
///
|
*/
|
||||||
/// Created by Anonymous275 on 7/19/2020
|
|
||||||
///
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <windows.h>
|
#include <shlobj.h>
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
#include "vdf_parser.hpp"
|
#include "vdf_parser.hpp"
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <spawn.h>
|
#include <spawn.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "Logger.h"
|
||||||
|
#include "Options.h"
|
||||||
|
#include "Startup.h"
|
||||||
|
#include "Utils.h"
|
||||||
#include <Security/Init.h>
|
#include <Security/Init.h>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include "Startup.h"
|
|
||||||
#include "Logger.h"
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
unsigned long GamePID = 0;
|
unsigned long GamePID = 0;
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
std::string QueryKey(HKEY hKey,int ID);
|
std::wstring QueryKey(HKEY hKey, int ID);
|
||||||
std::string GetGamePath(){
|
std::filesystem::path GetGamePath() {
|
||||||
static std::string Path;
|
static std::filesystem::path Path;
|
||||||
if(!Path.empty())return Path;
|
if (!Path.empty())
|
||||||
|
return Path.wstring();
|
||||||
|
|
||||||
HKEY hKey;
|
if (options.user_path) {
|
||||||
LPCTSTR sk = "Software\\BeamNG\\BeamNG.drive";
|
if (std::filesystem::exists(options.user_path)) {
|
||||||
LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
|
Path = options.user_path;
|
||||||
if (openRes != ERROR_SUCCESS){
|
debug(L"Using custom user folder path: " + Path.wstring());
|
||||||
fatal("Please launch the game at least once!");
|
} else
|
||||||
|
warn(L"Invalid or non-existent path (" + Utils::ToWString(options.user_path) + L") specified using --user-path, skipping");
|
||||||
}
|
}
|
||||||
Path = QueryKey(hKey,4);
|
|
||||||
|
|
||||||
if(Path.empty()){
|
if (const auto startupIniPath = std::filesystem::path(GetGameDir()) / "startup.ini"; exists(startupIniPath)) {
|
||||||
sk = R"(SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)";
|
|
||||||
openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
|
if (std::ifstream startupIni(startupIniPath); startupIni.is_open()) {
|
||||||
if (openRes != ERROR_SUCCESS){
|
std::string contents((std::istreambuf_iterator(startupIni)), std::istreambuf_iterator<char>());
|
||||||
fatal("Cannot get Local Appdata directory!");
|
startupIni.close();
|
||||||
|
|
||||||
|
auto ini = Utils::ParseINI(contents);
|
||||||
|
if (ini.empty())
|
||||||
|
warn("Failed to parse startup.ini");
|
||||||
|
else
|
||||||
|
debug("Successfully parsed startup.ini");
|
||||||
|
|
||||||
|
std::wstring userPath;
|
||||||
|
if (ini.contains("filesystem") && std::get<std::map<std::string, std::string>>(ini["filesystem"]).contains("UserPath"))
|
||||||
|
userPath = Utils::ToWString(std::get<std::map<std::string, std::string>>(ini["filesystem"])["UserPath"]);
|
||||||
|
|
||||||
|
if (!userPath.empty() && Path.empty())
|
||||||
|
if (userPath = Utils::ExpandEnvVars(userPath); std::filesystem::exists(userPath)) {
|
||||||
|
Path = userPath;
|
||||||
|
debug(L"Using custom user folder path from startup.ini: " + Path.wstring());
|
||||||
|
} else
|
||||||
|
warn(L"Found custom user folder path (" + userPath + L") in startup.ini but it doesn't exist, skipping");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Path.empty()) {
|
||||||
|
wchar_t* appDataPath = new wchar_t[MAX_PATH];
|
||||||
|
HRESULT result = SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, appDataPath);
|
||||||
|
|
||||||
|
if (!SUCCEEDED(result)) {
|
||||||
|
fatal("Cannot get Local Appdata directory");
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BeamNGAppdataPath = std::filesystem::path(appDataPath) / "BeamNG";
|
||||||
|
|
||||||
|
if (const auto beamngIniPath = BeamNGAppdataPath / "BeamNG.Drive.ini"; exists(beamngIniPath)) {
|
||||||
|
if (std::ifstream beamngIni(beamngIniPath); beamngIni.is_open()) {
|
||||||
|
std::string contents((std::istreambuf_iterator(beamngIni)), std::istreambuf_iterator<char>());
|
||||||
|
beamngIni.close();
|
||||||
|
|
||||||
|
auto ini = Utils::ParseINI(contents);
|
||||||
|
if (ini.empty())
|
||||||
|
warn("Failed to parse BeamNG.Drive.ini");
|
||||||
|
else
|
||||||
|
debug("Successfully parsed BeamNG.Drive.ini");
|
||||||
|
|
||||||
|
std::wstring userPath;
|
||||||
|
|
||||||
|
if (ini.contains("userFolder")) {
|
||||||
|
userPath = Utils::ToWString(std::get<std::string>(ini["userFolder"]));
|
||||||
|
userPath.erase(0, userPath.find_first_not_of(L" \t"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!userPath.empty() && Path.empty())
|
||||||
|
if (userPath = std::filesystem::path(Utils::ExpandEnvVars(userPath)); std::filesystem::exists(userPath)) {
|
||||||
|
Path = userPath;
|
||||||
|
debug(L"Using custom user folder path from BeamNG.Drive.ini: " + Path.wstring());
|
||||||
|
} else
|
||||||
|
warn(L"Found custom user folder path (" + userPath + L") in BeamNG.Drive.ini but it doesn't exist, skipping");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Path.empty()) {
|
||||||
|
Path = BeamNGAppdataPath / "BeamNG.drive";
|
||||||
|
}
|
||||||
|
|
||||||
|
delete[] appDataPath;
|
||||||
}
|
}
|
||||||
Path = QueryKey(hKey,5);
|
|
||||||
Path += "\\BeamNG.drive\\";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Ver = CheckVer(GetGameDir());
|
std::string Ver = CheckVer(GetGameDir());
|
||||||
Ver = Ver.substr(0,Ver.find('.',Ver.find('.')+1));
|
Ver = Ver.substr(0, Ver.find('.', Ver.find('.') + 1));
|
||||||
Path += Ver + "\\";
|
Path /= Utils::ToWString("current");
|
||||||
return Path;
|
return Path;
|
||||||
}
|
}
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
std::string GetGamePath(){
|
std::filesystem::path GetGamePath() {
|
||||||
// Right now only steam is supported
|
// Right now only steam is supported
|
||||||
struct passwd *pw = getpwuid(getuid());
|
struct passwd* pw = getpwuid(getuid());
|
||||||
std::string homeDir = pw->pw_dir;
|
std::string homeDir = pw->pw_dir;
|
||||||
|
|
||||||
std::string Path = homeDir + "/.local/share/BeamNG.drive/";
|
std::string Path = homeDir + "/.local/share/BeamNG.drive/";
|
||||||
std::string Ver = CheckVer(GetGameDir());
|
std::string Ver = CheckVer(GetGameDir());
|
||||||
Ver = Ver.substr(0,Ver.find('.',Ver.find('.')+1));
|
Ver = Ver.substr(0, Ver.find('.', Ver.find('.') + 1));
|
||||||
Path += Ver + "/";
|
Path += Ver + "/";
|
||||||
return Path;
|
return Path;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
void StartGame(std::string Dir){
|
void StartGame(std::wstring Dir) {
|
||||||
BOOL bSuccess = FALSE;
|
BOOL bSuccess = FALSE;
|
||||||
PROCESS_INFORMATION pi;
|
PROCESS_INFORMATION pi;
|
||||||
STARTUPINFO si = {0};
|
STARTUPINFOW si = { 0 };
|
||||||
si.cb = sizeof(si);
|
si.cb = sizeof(si);
|
||||||
std::string BaseDir = Dir; //+"\\Bin64";
|
std::wstring BaseDir = Dir; //+"\\Bin64";
|
||||||
//Dir += R"(\Bin64\BeamNG.drive.x64.exe)";
|
// Dir += R"(\Bin64\BeamNG.drive.x64.exe)";
|
||||||
Dir += "\\BeamNG.drive.exe";
|
Dir += L"\\BeamNG.drive.exe";
|
||||||
bSuccess = CreateProcessA(Dir.c_str(), nullptr, nullptr, nullptr, TRUE, 0, nullptr, BaseDir.c_str(), &si, &pi);
|
std::wstring gameArgs = L"";
|
||||||
if (bSuccess){
|
|
||||||
|
for (int i = 0; i < options.game_arguments_length; i++) {
|
||||||
|
gameArgs += L" ";
|
||||||
|
gameArgs += Utils::ToWString(options.game_arguments[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
debug(L"BeamNG executable path: " + Dir);
|
||||||
|
|
||||||
|
bSuccess = CreateProcessW(nullptr, (wchar_t*)(Dir + gameArgs).c_str(), nullptr, nullptr, TRUE, 0, nullptr, BaseDir.c_str(), &si, &pi);
|
||||||
|
if (bSuccess) {
|
||||||
info("Game Launched!");
|
info("Game Launched!");
|
||||||
GamePID = pi.dwProcessId;
|
GamePID = pi.dwProcessId;
|
||||||
WaitForSingleObject(pi.hProcess, INFINITE);
|
WaitForSingleObject(pi.hProcess, INFINITE);
|
||||||
error("Game Closed! launcher closing soon");
|
error("Game Closed! launcher closing soon");
|
||||||
}else{
|
} else {
|
||||||
error("Failed to Launch the game! launcher closing soon");
|
std::string err = "";
|
||||||
|
|
||||||
|
DWORD dw = GetLastError();
|
||||||
|
LPVOID lpErrorMsgBuffer;
|
||||||
|
|
||||||
|
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw,
|
||||||
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpErrorMsgBuffer, 0, nullptr)
|
||||||
|
== 0) {
|
||||||
|
err = "Unknown error code: " + std::to_string(dw);
|
||||||
|
} else {
|
||||||
|
err = "Error " + std::to_string(dw) + ": " + (char*)lpErrorMsgBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
error("Failed to Launch the game! launcher closing soon. " + err);
|
||||||
}
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||||
exit(2);
|
exit(2);
|
||||||
@@ -92,9 +177,19 @@ void StartGame(std::string Dir){
|
|||||||
void StartGame(std::string Dir) {
|
void StartGame(std::string Dir) {
|
||||||
int status;
|
int status;
|
||||||
std::string filename = (Dir + "/BinLinux/BeamNG.drive.x64");
|
std::string filename = (Dir + "/BinLinux/BeamNG.drive.x64");
|
||||||
char *argv[] = {filename.data(), NULL};
|
std::vector<const char*> argv;
|
||||||
|
argv.push_back(filename.data());
|
||||||
|
for (int i = 0; i < options.game_arguments_length; i++) {
|
||||||
|
argv.push_back(options.game_arguments[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
argv.push_back(nullptr);
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int result = posix_spawn(&pid, filename.c_str(), NULL, NULL, argv, environ);
|
posix_spawn_file_actions_t spawn_actions;
|
||||||
|
posix_spawn_file_actions_init(&spawn_actions);
|
||||||
|
posix_spawn_file_actions_addclose(&spawn_actions, STDOUT_FILENO);
|
||||||
|
posix_spawn_file_actions_addclose(&spawn_actions, STDERR_FILENO);
|
||||||
|
int result = posix_spawn(&pid, filename.c_str(), &spawn_actions, nullptr, const_cast<char**>(argv.data()), environ);
|
||||||
|
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
error("Failed to Launch the game! launcher closing soon");
|
error("Failed to Launch the game! launcher closing soon");
|
||||||
@@ -109,8 +204,8 @@ void StartGame(std::string Dir) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void InitGame(const std::string& Dir){
|
void InitGame(const beammp_fs_string& Dir) {
|
||||||
if(!Dev){
|
if (!options.no_launch) {
|
||||||
std::thread Game(StartGame, Dir);
|
std::thread Game(StartGame, Dir);
|
||||||
Game.detach();
|
Game.detach();
|
||||||
}
|
}
|
||||||
|
|||||||
101
src/Logger.cpp
Executable file → Normal file
101
src/Logger.cpp
Executable file → Normal file
@@ -1,17 +1,18 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
/*
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
///
|
*/
|
||||||
/// Created by Anonymous275 on 7/17/2020
|
|
||||||
///
|
|
||||||
|
|
||||||
#include "Startup.h"
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "Startup.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
#include <chrono>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <chrono>
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include "Options.h"
|
||||||
|
|
||||||
std::string getDate() {
|
std::string getDate() {
|
||||||
time_t tt = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
time_t tt = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
||||||
@@ -24,26 +25,33 @@ std::string getDate() {
|
|||||||
std::string Min = (M > 9 ? std::to_string(M) : "0" + std::to_string(M));
|
std::string Min = (M > 9 ? std::to_string(M) : "0" + std::to_string(M));
|
||||||
std::string Hour = (H > 9 ? std::to_string(H) : "0" + std::to_string(H));
|
std::string Hour = (H > 9 ? std::to_string(H) : "0" + std::to_string(H));
|
||||||
date
|
date
|
||||||
<< "["
|
<< "["
|
||||||
<< local_tm.tm_mday << "/"
|
<< local_tm.tm_mday << "/"
|
||||||
<< local_tm.tm_mon + 1 << "/"
|
<< local_tm.tm_mon + 1 << "/"
|
||||||
<< local_tm.tm_year + 1900 << " "
|
<< local_tm.tm_year + 1900 << " "
|
||||||
<< Hour << ":"
|
<< Hour << ":"
|
||||||
<< Min << ":"
|
<< Min << ":"
|
||||||
<< Secs
|
<< Secs
|
||||||
<< "] ";
|
<< "] ";
|
||||||
return date.str();
|
return date.str();
|
||||||
}
|
}
|
||||||
void InitLog(){
|
void InitLog() {
|
||||||
std::ofstream LFS;
|
std::ofstream LFS;
|
||||||
LFS.open(GetEP() + "Launcher.log");
|
LFS.open(GetEP() + beammp_wide("Launcher.log"));
|
||||||
if(!LFS.is_open()){
|
if (!LFS.is_open()) {
|
||||||
error("logger file init failed!");
|
error("logger file init failed!");
|
||||||
}else LFS.close();
|
} else
|
||||||
|
LFS.close();
|
||||||
}
|
}
|
||||||
void addToLog(const std::string& Line){
|
void addToLog(const std::string& Line) {
|
||||||
std::ofstream LFS;
|
std::ofstream LFS;
|
||||||
LFS.open(GetEP() + "Launcher.log", std::ios_base::app);
|
LFS.open(GetEP() + beammp_wide("Launcher.log"), std::ios_base::app);
|
||||||
|
LFS << Line.c_str();
|
||||||
|
LFS.close();
|
||||||
|
}
|
||||||
|
void addToLog(const std::wstring& Line) {
|
||||||
|
std::wofstream LFS;
|
||||||
|
LFS.open(GetEP() + beammp_wide("Launcher.log"), std::ios_base::app);
|
||||||
LFS << Line.c_str();
|
LFS << Line.c_str();
|
||||||
LFS.close();
|
LFS.close();
|
||||||
}
|
}
|
||||||
@@ -53,12 +61,13 @@ void info(const std::string& toPrint) {
|
|||||||
addToLog(Print);
|
addToLog(Print);
|
||||||
}
|
}
|
||||||
void debug(const std::string& toPrint) {
|
void debug(const std::string& toPrint) {
|
||||||
if(!Dev)return;
|
|
||||||
std::string Print = getDate() + "[DEBUG] " + toPrint + "\n";
|
std::string Print = getDate() + "[DEBUG] " + toPrint + "\n";
|
||||||
std::cout << Print;
|
if (options.verbose) {
|
||||||
|
std::cout << Print;
|
||||||
|
}
|
||||||
addToLog(Print);
|
addToLog(Print);
|
||||||
}
|
}
|
||||||
void warn(const std::string& toPrint){
|
void warn(const std::string& toPrint) {
|
||||||
std::string Print = getDate() + "[WARN] " + toPrint + "\n";
|
std::string Print = getDate() + "[WARN] " + toPrint + "\n";
|
||||||
std::cout << Print;
|
std::cout << Print;
|
||||||
addToLog(Print);
|
addToLog(Print);
|
||||||
@@ -73,10 +82,48 @@ void fatal(const std::string& toPrint) {
|
|||||||
std::cout << Print;
|
std::cout << Print;
|
||||||
addToLog(Print);
|
addToLog(Print);
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||||
_Exit(-1);
|
std::exit(1);
|
||||||
}
|
}
|
||||||
void except(const std::string& toPrint) {
|
void except(const std::string& toPrint) {
|
||||||
std::string Print = getDate() + "[EXCEP] " + toPrint + "\n";
|
std::string Print = getDate() + "[EXCEP] " + toPrint + "\n";
|
||||||
std::cout << Print;
|
std::cout << Print;
|
||||||
addToLog(Print);
|
addToLog(Print);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
void info(const std::wstring& toPrint) {
|
||||||
|
std::wstring Print = Utils::ToWString(getDate()) + L"[INFO] " + toPrint + L"\n";
|
||||||
|
std::wcout << Print;
|
||||||
|
addToLog(Print);
|
||||||
|
}
|
||||||
|
void debug(const std::wstring& toPrint) {
|
||||||
|
std::wstring Print = Utils::ToWString(getDate()) + L"[DEBUG] " + toPrint + L"\n";
|
||||||
|
if (options.verbose) {
|
||||||
|
std::wcout << Print;
|
||||||
|
}
|
||||||
|
addToLog(Print);
|
||||||
|
}
|
||||||
|
void warn(const std::wstring& toPrint) {
|
||||||
|
std::wstring Print = Utils::ToWString(getDate()) + L"[WARN] " + toPrint + L"\n";
|
||||||
|
std::wcout << Print;
|
||||||
|
addToLog(Print);
|
||||||
|
}
|
||||||
|
void error(const std::wstring& toPrint) {
|
||||||
|
std::wstring Print = Utils::ToWString(getDate()) + L"[ERROR] " + toPrint + L"\n";
|
||||||
|
std::wcout << Print;
|
||||||
|
addToLog(Print);
|
||||||
|
}
|
||||||
|
void fatal(const std::wstring& toPrint) {
|
||||||
|
std::wstring Print = Utils::ToWString(getDate()) + L"[FATAL] " + toPrint + L"\n";
|
||||||
|
std::wcout << Print;
|
||||||
|
addToLog(Print);
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||||
|
std::exit(1);
|
||||||
|
}
|
||||||
|
void except(const std::wstring& toPrint) {
|
||||||
|
std::wstring Print = Utils::ToWString(getDate()) + L"[EXCEP] " + toPrint + L"\n";
|
||||||
|
std::wcout << Print;
|
||||||
|
addToLog(Print);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
521
src/Network/Core.cpp
Executable file → Normal file
521
src/Network/Core.cpp
Executable file → Normal file
@@ -1,50 +1,82 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
/*
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
///
|
*/
|
||||||
/// Created by Anonymous275 on 7/20/2020
|
|
||||||
///
|
|
||||||
#include "Network/network.hpp"
|
|
||||||
#include "Security/Init.h"
|
|
||||||
|
|
||||||
#include "Http.h"
|
#include "Http.h"
|
||||||
|
#include "Network/network.hpp"
|
||||||
|
#include "Security/Init.h"
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <regex>
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
|
#include <shellapi.h>
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <spawn.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Startup.h"
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "Startup.h"
|
||||||
#include <charconv>
|
#include <charconv>
|
||||||
#include <thread>
|
#include <nlohmann/json.hpp>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <thread>
|
||||||
|
#include <mutex>
|
||||||
|
#include "Options.h"
|
||||||
|
|
||||||
|
#include <future>
|
||||||
|
|
||||||
extern int TraceBack;
|
extern int TraceBack;
|
||||||
std::set<std::string>* ConfList = nullptr;
|
std::set<std::string>* ConfList = nullptr;
|
||||||
bool TCPTerminate = false;
|
bool TCPTerminate = false;
|
||||||
int DEFAULT_PORT = 4444;
|
|
||||||
bool Terminate = false;
|
bool Terminate = false;
|
||||||
bool LoginAuth = false;
|
bool LoginAuth = false;
|
||||||
|
std::string Username = "";
|
||||||
|
std::string UserRole = "";
|
||||||
|
int UserID = -1;
|
||||||
std::string UlStatus;
|
std::string UlStatus;
|
||||||
std::string MStatus;
|
std::string MStatus;
|
||||||
bool ModLoaded;
|
bool ModLoaded;
|
||||||
int ping = -1;
|
int ping = -1;
|
||||||
|
SOCKET CoreSocket = -1;
|
||||||
|
signed char confirmed = -1;
|
||||||
|
|
||||||
void StartSync(const std::string &Data){
|
bool SecurityWarning() {
|
||||||
std::string IP = GetAddr(Data.substr(1,Data.find(':')-1));
|
confirmed = -1;
|
||||||
if(IP.find('.') == -1){
|
CoreSend("WMODS_FOUND");
|
||||||
if(IP == "DNS")UlStatus ="UlConnection Failed! (DNS Lookup Failed)";
|
|
||||||
else UlStatus = "UlConnection Failed! (WSA failed to start)";
|
while (confirmed == -1)
|
||||||
ListOfMods = "-";
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
|
|
||||||
|
if (confirmed == 1)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
NetReset();
|
||||||
|
Terminate = true;
|
||||||
|
TCPTerminate = true;
|
||||||
|
ping = -1;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartSync(const std::string& Data) {
|
||||||
|
std::string IP = GetAddr(Data.substr(1, Data.find(':') - 1));
|
||||||
|
if (IP.find('.') == -1) {
|
||||||
|
if (IP == "DNS")
|
||||||
|
UlStatus = "UlConnection Failed! (DNS Lookup Failed)";
|
||||||
|
else
|
||||||
|
UlStatus = "UlConnection Failed! (WSA failed to start)";
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
|
CoreSend("L");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CheckLocalKey();
|
CheckLocalKey();
|
||||||
@@ -53,120 +85,309 @@ void StartSync(const std::string &Data){
|
|||||||
Terminate = false;
|
Terminate = false;
|
||||||
ConfList->clear();
|
ConfList->clear();
|
||||||
ping = -1;
|
ping = -1;
|
||||||
std::thread GS(TCPGameServer,IP,std::stoi(Data.substr(Data.find(':')+1)));
|
std::thread GS(TCPGameServer, IP, std::stoi(Data.substr(Data.find(':') + 1)));
|
||||||
GS.detach();
|
GS.detach();
|
||||||
info("Connecting to server");
|
info("Connecting to server");
|
||||||
}
|
}
|
||||||
void Parse(std::string Data,SOCKET CSocket){
|
|
||||||
char Code = Data.at(0), SubCode = 0;
|
void GetServerInfo(std::string Data) {
|
||||||
if(Data.length() > 1)SubCode = Data.at(1);
|
debug("Fetching server info of " + Data.substr(1));
|
||||||
switch (Code){
|
|
||||||
case 'A':
|
std::string IP = GetAddr(Data.substr(1, Data.find(':') - 1));
|
||||||
Data = Data.substr(0,1);
|
if (IP.find('.') == -1) {
|
||||||
break;
|
if (IP == "DNS")
|
||||||
case 'B':
|
warn("Connection Failed! (DNS Lookup Failed) for " + Data);
|
||||||
NetReset();
|
else
|
||||||
Terminate = true;
|
warn("Connection Failed! (WSA failed to start) for " + Data);
|
||||||
TCPTerminate = true;
|
CoreSend("I" + Data + ";");
|
||||||
Data = Code + HTTP::Get("https://backend.beammp.com/servers-info");
|
return;
|
||||||
break;
|
|
||||||
case 'C':
|
|
||||||
ListOfMods.clear();
|
|
||||||
StartSync(Data);
|
|
||||||
while(ListOfMods.empty() && !Terminate){
|
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
||||||
}
|
|
||||||
if(ListOfMods == "-")Data = "L";
|
|
||||||
else Data = "L"+ListOfMods;
|
|
||||||
break;
|
|
||||||
case 'U':
|
|
||||||
if(SubCode == 'l')Data = UlStatus;
|
|
||||||
if(SubCode == 'p'){
|
|
||||||
if(ping > 800){
|
|
||||||
Data = "Up-2";
|
|
||||||
}else Data = "Up" + std::to_string(ping);
|
|
||||||
}
|
|
||||||
if(!SubCode){
|
|
||||||
std::string Ping;
|
|
||||||
if(ping > 800)Ping = "-2";
|
|
||||||
else Ping = std::to_string(ping);
|
|
||||||
Data = std::string(UlStatus) + "\n" + "Up" + Ping;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'M':
|
|
||||||
Data = MStatus;
|
|
||||||
break;
|
|
||||||
case 'Q':
|
|
||||||
if(SubCode == 'S'){
|
|
||||||
NetReset();
|
|
||||||
Terminate = true;
|
|
||||||
TCPTerminate = true;
|
|
||||||
ping = -1;
|
|
||||||
}
|
|
||||||
if(SubCode == 'G')exit(2);
|
|
||||||
Data.clear();
|
|
||||||
break;
|
|
||||||
case 'R': //will send mod name
|
|
||||||
if(ConfList->find(Data) == ConfList->end()){
|
|
||||||
ConfList->insert(Data);
|
|
||||||
ModLoaded = true;
|
|
||||||
}
|
|
||||||
Data.clear();
|
|
||||||
break;
|
|
||||||
case 'Z':
|
|
||||||
Data = "Z" + GetVer();
|
|
||||||
break;
|
|
||||||
case 'N':
|
|
||||||
if (SubCode == 'c'){
|
|
||||||
Data = "N{\"Auth\":"+std::to_string(LoginAuth)+"}";
|
|
||||||
}else{
|
|
||||||
Data = "N" + Login(Data.substr(Data.find(':') + 1));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Data.clear();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if(!Data.empty() && CSocket != -1){
|
|
||||||
int res = send(CSocket, (Data+"\n").c_str(), int(Data.size())+1, 0);
|
SOCKET ISock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
if(res < 0){
|
SOCKADDR_IN ServerAddr;
|
||||||
|
if (ISock < 1) {
|
||||||
|
debug("Socket creation failed with error: " + std::to_string(WSAGetLastError()));
|
||||||
|
KillSocket(ISock);
|
||||||
|
CoreSend("I" + Data + ";");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ServerAddr.sin_family = AF_INET;
|
||||||
|
|
||||||
|
int port = std::stoi(Data.substr(Data.find(':') + 1));
|
||||||
|
|
||||||
|
if (port < 1 || port > 65535) {
|
||||||
|
debug("Invalid port number: " + std::to_string(port));
|
||||||
|
KillSocket(ISock);
|
||||||
|
CoreSend("I" + Data + ";");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerAddr.sin_port = htons(port);
|
||||||
|
inet_pton(AF_INET, IP.c_str(), &ServerAddr.sin_addr);
|
||||||
|
if (connect(ISock, (SOCKADDR*)&ServerAddr, sizeof(ServerAddr)) != 0) {
|
||||||
|
debug("Connection to server failed with error: " + std::to_string(WSAGetLastError()));
|
||||||
|
KillSocket(ISock);
|
||||||
|
CoreSend("I" + Data + ";");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char Code[1] = { 'I' };
|
||||||
|
if (send(ISock, Code, 1, 0) != 1) {
|
||||||
|
debug("Sending data to server failed with error: " + std::to_string(WSAGetLastError()));
|
||||||
|
KillSocket(ISock);
|
||||||
|
CoreSend("I" + Data + ";");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string buffer = ([&]() -> std::string {
|
||||||
|
int32_t Header;
|
||||||
|
std::vector<char> data(sizeof(Header));
|
||||||
|
int Temp = recv(ISock, data.data(), sizeof(Header), MSG_WAITALL);
|
||||||
|
|
||||||
|
auto checkBytes = ([&](const int32_t bytes) -> bool {
|
||||||
|
if (bytes == 0) {
|
||||||
|
return false;
|
||||||
|
} else if (bytes < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!checkBytes(Temp)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
memcpy(&Header, data.data(), sizeof(Header));
|
||||||
|
|
||||||
|
if (!checkBytes(Temp)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
data.resize(Header, 0);
|
||||||
|
Temp = recv(ISock, data.data(), Header, MSG_WAITALL);
|
||||||
|
if (!checkBytes(Temp)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return std::string(data.data(), Header);
|
||||||
|
})();
|
||||||
|
|
||||||
|
if (!buffer.empty()) {
|
||||||
|
debug("Server Info: " + buffer);
|
||||||
|
|
||||||
|
CoreSend("I" + Data + ";" + buffer);
|
||||||
|
} else {
|
||||||
|
debug("Receiving data from server failed with error: " + std::to_string(WSAGetLastError()));
|
||||||
|
debug("Failed to receive server info from " + Data);
|
||||||
|
CoreSend("I" + Data + ";");
|
||||||
|
}
|
||||||
|
|
||||||
|
KillSocket(ISock);
|
||||||
|
}
|
||||||
|
std::mutex sendMutex;
|
||||||
|
|
||||||
|
void CoreSend(std::string data) {
|
||||||
|
std::lock_guard lock(sendMutex);
|
||||||
|
|
||||||
|
if (CoreSocket != -1) {
|
||||||
|
int res = send(CoreSocket, (data + "\n").c_str(), int(data.size()) + 1, 0);
|
||||||
|
if (res < 0) {
|
||||||
debug("(Core) send failed with error: " + std::to_string(WSAGetLastError()));
|
debug("(Core) send failed with error: " + std::to_string(WSAGetLastError()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void GameHandler(SOCKET Client){
|
|
||||||
|
|
||||||
int32_t Size,Temp,Rcv;
|
bool IsAllowedLink(const std::string& Link) {
|
||||||
char Header[10] = {0};
|
std::regex link_pattern(R"(https:\/\/(?:\w+)?(?:\.)?(?:beammp\.com|beammp\.gg|github\.com\/BeamMP\/|discord\.gg|patreon\.com\/BeamMP))");
|
||||||
do{
|
std::smatch link_match;
|
||||||
|
return std::regex_search(Link, link_match, link_pattern) && link_match.position() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::future<void>> futures;
|
||||||
|
|
||||||
|
void Parse(std::string Data, SOCKET CSocket) {
|
||||||
|
std::erase_if(futures, [](const std::future<void>& f) {
|
||||||
|
if (f.wait_for(std::chrono::seconds(0)) == std::future_status::ready) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
char Code = Data.at(0), SubCode = 0;
|
||||||
|
if (Data.length() > 1)
|
||||||
|
SubCode = Data.at(1);
|
||||||
|
switch (Code) {
|
||||||
|
case 'A':
|
||||||
|
Data = Data.substr(0, 1);
|
||||||
|
break;
|
||||||
|
case 'B': {
|
||||||
|
NetReset();
|
||||||
|
Terminate = true;
|
||||||
|
TCPTerminate = true;
|
||||||
|
Data.clear();
|
||||||
|
futures.push_back(std::async(std::launch::async, []() {
|
||||||
|
CoreSend("B" + HTTP::Get("https://backend.beammp.com/servers-info"));
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'C':
|
||||||
|
StartSync(Data);
|
||||||
|
Data.clear();
|
||||||
|
break;
|
||||||
|
case 'O': // open default browser with URL
|
||||||
|
if (IsAllowedLink(Data.substr(1))) {
|
||||||
|
#if defined(__linux)
|
||||||
|
if (char* browser = getenv("BROWSER"); browser != nullptr && !std::string_view(browser).empty()) {
|
||||||
|
pid_t pid;
|
||||||
|
auto arg = Data.substr(1);
|
||||||
|
char* argv[] = { browser, arg.data() };
|
||||||
|
auto status = posix_spawn(&pid, browser, nullptr, nullptr, argv, environ);
|
||||||
|
if (status == 0) {
|
||||||
|
debug("Browser PID: " + std::to_string(pid));
|
||||||
|
// we don't wait for it to exit, because we just don't care.
|
||||||
|
// typically, you'd waitpid() here.
|
||||||
|
} else {
|
||||||
|
error("Failed to open the following link in the browser (error follows below): " + arg);
|
||||||
|
error(std::string("posix_spawn: ") + strerror(status));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error("Failed to open the following link in the browser because the $BROWSER environment variable is not set: " + Data.substr(1));
|
||||||
|
}
|
||||||
|
#elif defined(WIN32)
|
||||||
|
ShellExecuteA(nullptr, "open", Data.substr(1).c_str(), nullptr, nullptr, SW_SHOW); /// TODO: Look at when working on linux port
|
||||||
|
#endif
|
||||||
|
|
||||||
|
info("Opening Link \"" + Data.substr(1) + "\"");
|
||||||
|
}
|
||||||
|
Data.clear();
|
||||||
|
break;
|
||||||
|
case 'P':
|
||||||
|
Data = Code + std::to_string(ProxyPort);
|
||||||
|
break;
|
||||||
|
case 'U':
|
||||||
|
if (SubCode == 'l')
|
||||||
|
Data = UlStatus;
|
||||||
|
if (SubCode == 'p') {
|
||||||
|
if (ping > 800) {
|
||||||
|
Data = "Up-2";
|
||||||
|
} else
|
||||||
|
Data = "Up" + std::to_string(ping);
|
||||||
|
}
|
||||||
|
if (!SubCode) {
|
||||||
|
std::string Ping;
|
||||||
|
if (ping > 800)
|
||||||
|
Ping = "-2";
|
||||||
|
else
|
||||||
|
Ping = std::to_string(ping);
|
||||||
|
Data = std::string(UlStatus) + "\n" + "Up" + Ping;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'M':
|
||||||
|
Data = MStatus;
|
||||||
|
break;
|
||||||
|
case 'Q':
|
||||||
|
if (SubCode == 'S') {
|
||||||
|
NetReset();
|
||||||
|
Terminate = true;
|
||||||
|
TCPTerminate = true;
|
||||||
|
ping = -1;
|
||||||
|
}
|
||||||
|
if (SubCode == 'G') {
|
||||||
|
debug("Closing via 'G' packet");
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
Data.clear();
|
||||||
|
break;
|
||||||
|
case 'R': // will send mod name
|
||||||
|
if (ConfList->find(Data) == ConfList->end()) {
|
||||||
|
ConfList->insert(Data);
|
||||||
|
ModLoaded = true;
|
||||||
|
}
|
||||||
|
Data.clear();
|
||||||
|
break;
|
||||||
|
case 'Z':
|
||||||
|
Data = "Z" + GetVer();
|
||||||
|
break;
|
||||||
|
case 'N':
|
||||||
|
if (SubCode == 'c') {
|
||||||
|
nlohmann::json Auth = {
|
||||||
|
{ "Auth", LoginAuth ? 1 : 0 },
|
||||||
|
};
|
||||||
|
if (!Username.empty()) {
|
||||||
|
Auth["username"] = Username;
|
||||||
|
}
|
||||||
|
if (!UserRole.empty()) {
|
||||||
|
Auth["role"] = UserRole;
|
||||||
|
}
|
||||||
|
if (UserID != -1) {
|
||||||
|
Auth["id"] = UserID;
|
||||||
|
}
|
||||||
|
Data = "N" + Auth.dump();
|
||||||
|
} else {
|
||||||
|
futures.push_back(std::async(std::launch::async, [data = std::move(Data)]() {
|
||||||
|
CoreSend("N" + Login(data.substr(data.find(':') + 1)));
|
||||||
|
}));
|
||||||
|
Data.clear();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'W':
|
||||||
|
if (SubCode == 'Y') {
|
||||||
|
confirmed = 1;
|
||||||
|
} else if (SubCode == 'N') {
|
||||||
|
confirmed = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Data.clear();
|
||||||
|
break;
|
||||||
|
case 'I': {
|
||||||
|
auto future = std::async(std::launch::async, [data = std::move(Data)]() {
|
||||||
|
GetServerInfo(data);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
Data.clear();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!Data.empty())
|
||||||
|
CoreSend(Data);
|
||||||
|
}
|
||||||
|
void GameHandler(SOCKET Client) {
|
||||||
|
CoreSocket = Client;
|
||||||
|
int32_t Size, Rcv;
|
||||||
|
int Temp;
|
||||||
|
char Header[10] = { 0 };
|
||||||
|
do {
|
||||||
Rcv = 0;
|
Rcv = 0;
|
||||||
do{
|
do {
|
||||||
Temp = recv(Client,&Header[Rcv],1,0);
|
Temp = recv(Client, &Header[Rcv], 1, 0);
|
||||||
if(Temp < 1)break;
|
if (Temp < 1)
|
||||||
if(!isdigit(Header[Rcv]) && Header[Rcv] != '>') {
|
break;
|
||||||
|
if (!isdigit(Header[Rcv]) && Header[Rcv] != '>') {
|
||||||
error("(Core) Invalid lua communication");
|
error("(Core) Invalid lua communication");
|
||||||
KillSocket(Client);
|
KillSocket(Client);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}while(Header[Rcv++] != '>');
|
} while (Header[Rcv++] != '>');
|
||||||
if(Temp < 1)break;
|
if (Temp < 1)
|
||||||
if(std::from_chars(Header,&Header[Rcv],Size).ptr[0] != '>'){
|
break;
|
||||||
debug("(Core) Invalid lua Header -> " + std::string(Header,Rcv));
|
if (std::from_chars(Header, &Header[Rcv], Size).ptr[0] != '>') {
|
||||||
|
debug("(Core) Invalid lua Header -> " + std::string(Header, Rcv));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
std::string Ret(Size,0);
|
std::string Ret(Size, 0);
|
||||||
Rcv = 0;
|
Rcv = 0;
|
||||||
|
|
||||||
do{
|
do {
|
||||||
Temp = recv(Client,&Ret[Rcv],Size-Rcv,0);
|
Temp = recv(Client, &Ret[Rcv], Size - Rcv, 0);
|
||||||
if(Temp < 1)break;
|
if (Temp < 1)
|
||||||
|
break;
|
||||||
Rcv += Temp;
|
Rcv += Temp;
|
||||||
}while(Rcv < Size);
|
} while (Rcv < Size);
|
||||||
if(Temp < 1)break;
|
if (Temp < 1)
|
||||||
|
break;
|
||||||
|
|
||||||
std::thread Respond(Parse, Ret, Client);
|
Parse(Ret, Client);
|
||||||
Respond.detach();
|
} while (Temp > 0);
|
||||||
}while(Temp > 0);
|
|
||||||
if (Temp == 0) {
|
if (Temp == 0) {
|
||||||
debug("(Core) Connection closing");
|
debug("(Core) Connection closing");
|
||||||
} else {
|
} else {
|
||||||
@@ -175,10 +396,10 @@ void GameHandler(SOCKET Client){
|
|||||||
NetReset();
|
NetReset();
|
||||||
KillSocket(Client);
|
KillSocket(Client);
|
||||||
}
|
}
|
||||||
void localRes(){
|
void localRes() {
|
||||||
MStatus = " ";
|
MStatus = " ";
|
||||||
UlStatus = "Ulstart";
|
UlStatus = "Ulstart";
|
||||||
if(ConfList != nullptr){
|
if (ConfList != nullptr) {
|
||||||
ConfList->clear();
|
ConfList->clear();
|
||||||
delete ConfList;
|
delete ConfList;
|
||||||
ConfList = nullptr;
|
ConfList = nullptr;
|
||||||
@@ -186,31 +407,32 @@ void localRes(){
|
|||||||
ConfList = new std::set<std::string>;
|
ConfList = new std::set<std::string>;
|
||||||
}
|
}
|
||||||
void CoreMain() {
|
void CoreMain() {
|
||||||
debug("Core Network on start!");
|
debug("Core Network on start! port: " + std::to_string(options.port));
|
||||||
SOCKET LSocket,CSocket;
|
SOCKET LSocket, CSocket;
|
||||||
struct addrinfo *res = nullptr;
|
struct addrinfo* res = nullptr;
|
||||||
struct addrinfo hints{};
|
struct addrinfo hints { };
|
||||||
int iRes;
|
int iRes;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
iRes = WSAStartup(514, &wsaData); //2.2
|
iRes = WSAStartup(514, &wsaData); // 2.2
|
||||||
if (iRes)debug("WSAStartup failed with error: " + std::to_string(iRes));
|
if (iRes)
|
||||||
#endif
|
debug("WSAStartup failed with error: " + std::to_string(iRes));
|
||||||
|
#endif
|
||||||
|
|
||||||
ZeroMemory(&hints, sizeof(hints));
|
ZeroMemory(&hints, sizeof(hints));
|
||||||
|
|
||||||
hints.ai_family = AF_INET;
|
hints.ai_family = AF_INET;
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
hints.ai_protocol = IPPROTO_TCP;
|
hints.ai_protocol = IPPROTO_TCP;
|
||||||
hints.ai_flags = AI_PASSIVE;
|
hints.ai_flags = AI_PASSIVE;
|
||||||
iRes = getaddrinfo(nullptr, std::to_string(DEFAULT_PORT).c_str(), &hints, &res);
|
iRes = getaddrinfo("127.0.0.1", std::to_string(options.port).c_str(), &hints, &res);
|
||||||
if (iRes){
|
if (iRes) {
|
||||||
debug("(Core) addr info failed with error: " + std::to_string(iRes));
|
debug("(Core) addr info failed with error: " + std::to_string(iRes));
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LSocket = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
LSocket = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
||||||
if (LSocket == -1){
|
if (LSocket == -1) {
|
||||||
debug("(Core) socket failed with error: " + std::to_string(WSAGetLastError()));
|
debug("(Core) socket failed with error: " + std::to_string(WSAGetLastError()));
|
||||||
freeaddrinfo(res);
|
freeaddrinfo(res);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
@@ -232,7 +454,7 @@ void CoreMain() {
|
|||||||
WSACleanup();
|
WSACleanup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
do{
|
do {
|
||||||
CSocket = accept(LSocket, nullptr, nullptr);
|
CSocket = accept(LSocket, nullptr, nullptr);
|
||||||
if (CSocket == -1) {
|
if (CSocket == -1) {
|
||||||
error("(Core) accept failed with error: " + std::to_string(WSAGetLastError()));
|
error("(Core) accept failed with error: " + std::to_string(WSAGetLastError()));
|
||||||
@@ -242,36 +464,37 @@ void CoreMain() {
|
|||||||
info("Game Connected!");
|
info("Game Connected!");
|
||||||
GameHandler(CSocket);
|
GameHandler(CSocket);
|
||||||
warn("Game Reconnecting...");
|
warn("Game Reconnecting...");
|
||||||
}while(CSocket);
|
} while (CSocket);
|
||||||
KillSocket(LSocket);
|
KillSocket(LSocket);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
int Handle(EXCEPTION_POINTERS *ep){
|
int Handle(EXCEPTION_POINTERS* ep) {
|
||||||
char* hex = new char[100];
|
char* hex = new char[100];
|
||||||
sprintf_s(hex,100, "%lX", ep->ExceptionRecord->ExceptionCode);
|
sprintf_s(hex, 100, "%lX", ep->ExceptionRecord->ExceptionCode);
|
||||||
except("(Core) Code : " + std::string(hex));
|
except("(Core) Code : " + std::string(hex));
|
||||||
delete [] hex;
|
delete[] hex;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
[[noreturn]] void CoreNetwork(){
|
[[noreturn]] void CoreNetwork() {
|
||||||
while(true) {
|
while (true) {
|
||||||
#if not defined(__MINGW32__)
|
#if not defined(__MINGW32__)
|
||||||
__try{
|
__try {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CoreMain();
|
|
||||||
|
|
||||||
#if not defined(__MINGW32__) and not defined(__linux__)
|
CoreMain();
|
||||||
}__except(Handle(GetExceptionInformation())){}
|
|
||||||
#elif not defined(__MINGW32__) and defined(__linux__)
|
#if not defined(__MINGW32__) and not defined(__linux__)
|
||||||
} catch(...){
|
} __except (Handle(GetExceptionInformation())) { }
|
||||||
except("(Core) Code : " + std::string(strerror(errno)));
|
#elif not defined(__MINGW32__) and defined(__linux__)
|
||||||
}
|
}
|
||||||
#endif
|
catch (...) {
|
||||||
|
except("(Core) Code : " + std::string(strerror(errno)));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
}
|
}
|
||||||
|
|||||||
34
src/Network/DNS.cpp
Executable file → Normal file
34
src/Network/DNS.cpp
Executable file → Normal file
@@ -1,10 +1,9 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
/*
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
///
|
*/
|
||||||
/// Created by Anonymous275 on 9/25/2020
|
|
||||||
///
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -12,31 +11,32 @@
|
|||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
#include "linuxfixes.h"
|
#include "linuxfixes.h"
|
||||||
#include <netdb.h>
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <netdb.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
|
||||||
std::string GetAddr(const std::string&IP){
|
std::string GetAddr(const std::string& IP) {
|
||||||
if(IP.find_first_not_of("0123456789.") == -1)return IP;
|
if (IP.find_first_not_of("0123456789.") == -1)
|
||||||
hostent *host;
|
return IP;
|
||||||
#ifdef _WIN32
|
hostent* host;
|
||||||
|
#ifdef _WIN32
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
if(WSAStartup(514, &wsaData) != 0){
|
if (WSAStartup(514, &wsaData) != 0) {
|
||||||
error("WSA Startup Failed!");
|
error("WSA Startup Failed!");
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
host = gethostbyname(IP.c_str());
|
host = gethostbyname(IP.c_str());
|
||||||
if(!host){
|
if (!host) {
|
||||||
error("DNS lookup failed! on " + IP);
|
error("DNS lookup failed! on " + IP);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
return "DNS";
|
return "DNS";
|
||||||
}
|
}
|
||||||
std::string Ret = inet_ntoa(*((struct in_addr *)host->h_addr));
|
std::string Ret = inet_ntoa(*((struct in_addr*)host->h_addr));
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
275
src/Network/GlobalHandler.cpp
Executable file → Normal file
275
src/Network/GlobalHandler.cpp
Executable file → Normal file
@@ -1,149 +1,168 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
/*
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
///
|
*/
|
||||||
/// Created by Anonymous275 on 7/25/2020
|
|
||||||
///
|
|
||||||
#include "Network/network.hpp"
|
#include "Network/network.hpp"
|
||||||
|
#include <memory>
|
||||||
|
#include <zlib.h>
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
#include "linuxfixes.h"
|
#include "linuxfixes.h"
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <cstring>
|
||||||
|
#include <netdb.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <netdb.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <cstring>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <charconv>
|
#include <charconv>
|
||||||
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <mutex>
|
#include "Options.h"
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
std::chrono::time_point<std::chrono::high_resolution_clock> PingStart,PingEnd;
|
std::chrono::time_point<std::chrono::high_resolution_clock> PingStart, PingEnd;
|
||||||
bool GConnected = false;
|
bool GConnected = false;
|
||||||
bool CServer = true;
|
bool CServer = true;
|
||||||
SOCKET CSocket = -1;
|
SOCKET CSocket = -1;
|
||||||
SOCKET GSocket = -1;
|
SOCKET GSocket = -1;
|
||||||
|
|
||||||
int KillSocket(uint64_t Dead){
|
int KillSocket(uint64_t Dead) {
|
||||||
if(Dead == (SOCKET)-1){
|
if (Dead == (SOCKET)-1) {
|
||||||
debug("Kill socket got -1 returning...");
|
debug("Kill socket got -1 returning...");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
shutdown(Dead,SD_BOTH);
|
shutdown(Dead, SD_BOTH);
|
||||||
int a = closesocket(Dead);
|
int a = closesocket(Dead);
|
||||||
if(a != 0){
|
if (a != 0) {
|
||||||
warn("Failed to close socket!");
|
warn("Failed to close socket!");
|
||||||
}
|
}
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckBytes(uint32_t Bytes){
|
bool CheckBytes(uint32_t Bytes) {
|
||||||
if(Bytes == 0){
|
if (Bytes == 0) {
|
||||||
debug("(Proxy) Connection closing");
|
debug("(Proxy) Connection closing");
|
||||||
return false;
|
return false;
|
||||||
}else if(Bytes < 0){
|
} else if (Bytes < 0) {
|
||||||
debug("(Proxy) send failed with error: " + std::to_string(WSAGetLastError()));
|
debug("(Proxy) send failed with error: " + std::to_string(WSAGetLastError()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameSend(std::string Data){
|
void GameSend(std::string_view Data) {
|
||||||
static std::mutex Lock;
|
static std::mutex Lock;
|
||||||
std::scoped_lock Guard(Lock);
|
std::scoped_lock Guard(Lock);
|
||||||
if(TCPTerminate || !GConnected || CSocket == -1)return;
|
if (TCPTerminate || !GConnected || CSocket == -1)
|
||||||
int32_t Size,Temp,Sent;
|
return;
|
||||||
Data += '\n';
|
int32_t Size, Temp, Sent;
|
||||||
Size = int32_t(Data.size());
|
Size = int32_t(Data.size());
|
||||||
Sent = 0;
|
Sent = 0;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if(Size > 1000){
|
if (Size > 1000) {
|
||||||
debug("Launcher -> game (" +std::to_string(Size)+")");
|
debug("Launcher -> game (" + std::to_string(Size) + ")");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
do{
|
do {
|
||||||
if(Sent > -1){
|
if (Sent > -1) {
|
||||||
Temp = send(CSocket, &Data[Sent], Size - Sent, 0);
|
Temp = send(CSocket, &Data[Sent], Size - Sent, 0);
|
||||||
}
|
}
|
||||||
if(!CheckBytes(Temp))return;
|
if (!CheckBytes(Temp))
|
||||||
|
return;
|
||||||
Sent += Temp;
|
Sent += Temp;
|
||||||
}while(Sent < Size);
|
} while (Sent < Size);
|
||||||
|
// send separately to avoid an allocation for += "\n"
|
||||||
|
Temp = send(CSocket, "\n", 1, 0);
|
||||||
|
if (!CheckBytes(Temp)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void ServerSend(std::string Data, bool Rel){
|
void ServerSend(std::string Data, bool Rel) {
|
||||||
if(Terminate || Data.empty())return;
|
if (Terminate || Data.empty())
|
||||||
if(Data.find("Zp") != std::string::npos && Data.size() > 500){
|
return;
|
||||||
|
if (Data.find("Zp") != std::string::npos && Data.size() > 500) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
char C = 0;
|
char C = 0;
|
||||||
bool Ack = false;
|
bool Ack = false;
|
||||||
int DLen = int(Data.length());
|
int DLen = int(Data.length());
|
||||||
if(DLen > 3)C = Data.at(0);
|
if (DLen > 3)
|
||||||
if (C == 'O' || C == 'T')Ack = true;
|
C = Data.at(0);
|
||||||
if(C == 'N' || C == 'W' || C == 'Y' || C == 'V' || C == 'E' || C == 'C')Rel = true;
|
if (C == 'O' || C == 'T')
|
||||||
if(Ack || Rel){
|
Ack = true;
|
||||||
if(Ack || DLen > 1000)SendLarge(Data);
|
if (C == 'N' || C == 'W' || C == 'Y' || C == 'V' || C == 'E' || C == 'C')
|
||||||
else TCPSend(Data,TCPSock);
|
Rel = true;
|
||||||
}else UDPSend(Data);
|
if (compressBound(Data.size()) > 1024)
|
||||||
|
Rel = true;
|
||||||
|
if (Ack || Rel) {
|
||||||
|
if (Ack || DLen > 1000)
|
||||||
|
SendLarge(Data);
|
||||||
|
else
|
||||||
|
TCPSend(Data, TCPSock);
|
||||||
|
} else
|
||||||
|
UDPSend(Data);
|
||||||
|
|
||||||
if (DLen > 1000) {
|
if (DLen > 1000) {
|
||||||
debug("(Launcher->Server) Bytes sent: " + std::to_string(Data.length()) + " : "
|
debug("(Launcher->Server) Bytes sent: " + std::to_string(Data.length()) + " : "
|
||||||
+ Data.substr(0, 10)
|
+ Data.substr(0, 10)
|
||||||
+ Data.substr(Data.length() - 10));
|
+ Data.substr(Data.length() - 10));
|
||||||
}else if(C == 'Z'){
|
} else if (C == 'Z') {
|
||||||
//debug("(Game->Launcher) : " + Data);
|
// debug("(Game->Launcher) : " + Data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetReset(){
|
void NetReset() {
|
||||||
TCPTerminate = false;
|
TCPTerminate = false;
|
||||||
GConnected = false;
|
GConnected = false;
|
||||||
Terminate = false;
|
Terminate = false;
|
||||||
UlStatus = "Ulstart";
|
UlStatus = "Ulstart";
|
||||||
MStatus = " ";
|
MStatus = " ";
|
||||||
if(UDPSock != (SOCKET)(-1)){
|
if (UDPSock != (SOCKET)(-1)) {
|
||||||
debug("Terminating UDP Socket : " + std::to_string(TCPSock));
|
debug("Terminating UDP Socket: " + std::to_string(TCPSock));
|
||||||
KillSocket(UDPSock);
|
KillSocket(UDPSock);
|
||||||
}
|
}
|
||||||
UDPSock = -1;
|
UDPSock = -1;
|
||||||
if(TCPSock != (SOCKET)(-1)){
|
if (TCPSock != (SOCKET)(-1)) {
|
||||||
debug("Terminating TCP Socket : " + std::to_string(TCPSock));
|
debug("Terminating TCP Socket: " + std::to_string(TCPSock));
|
||||||
KillSocket(TCPSock);
|
KillSocket(TCPSock);
|
||||||
}
|
}
|
||||||
TCPSock = -1;
|
TCPSock = -1;
|
||||||
if(GSocket != (SOCKET)(-1)){
|
if (GSocket != (SOCKET)(-1)) {
|
||||||
debug("Terminating GTCP Socket : " + std::to_string(GSocket));
|
debug("Terminating GTCP Socket: " + std::to_string(GSocket));
|
||||||
KillSocket(GSocket);
|
KillSocket(GSocket);
|
||||||
}
|
}
|
||||||
GSocket = -1;
|
GSocket = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SOCKET SetupListener(){
|
SOCKET SetupListener() {
|
||||||
if(GSocket != -1)return GSocket;
|
if (GSocket != -1)
|
||||||
struct addrinfo *result = nullptr;
|
return GSocket;
|
||||||
struct addrinfo hints{};
|
struct addrinfo* result = nullptr;
|
||||||
|
struct addrinfo hints { };
|
||||||
int iRes;
|
int iRes;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
iRes = WSAStartup(514, &wsaData); //2.2
|
iRes = WSAStartup(514, &wsaData); // 2.2
|
||||||
if (iRes != 0) {
|
if (iRes != 0) {
|
||||||
error("(Proxy) WSAStartup failed with error: " + std::to_string(iRes));
|
error("(Proxy) WSAStartup failed with error: " + std::to_string(iRes));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ZeroMemory(&hints, sizeof(hints));
|
ZeroMemory(&hints, sizeof(hints));
|
||||||
hints.ai_family = AF_INET;
|
hints.ai_family = AF_INET;
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
hints.ai_protocol = IPPROTO_TCP;
|
hints.ai_protocol = IPPROTO_TCP;
|
||||||
hints.ai_flags = AI_PASSIVE;
|
hints.ai_flags = AI_PASSIVE;
|
||||||
iRes = getaddrinfo(nullptr, std::to_string(DEFAULT_PORT+1).c_str(), &hints, &result);
|
iRes = getaddrinfo(nullptr, std::to_string(options.port + 1).c_str(), &hints, &result);
|
||||||
if (iRes != 0) {
|
if (iRes != 0) {
|
||||||
error("(Proxy) info failed with error: " + std::to_string(iRes));
|
error("(Proxy) info failed with error: " + std::to_string(iRes));
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
@@ -155,7 +174,7 @@ SOCKET SetupListener(){
|
|||||||
WSACleanup();
|
WSACleanup();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
iRes = bind(GSocket, result->ai_addr, (int) result->ai_addrlen);
|
iRes = bind(GSocket, result->ai_addr, (int)result->ai_addrlen);
|
||||||
if (iRes == SOCKET_ERROR) {
|
if (iRes == SOCKET_ERROR) {
|
||||||
error("(Proxy) bind failed with error: " + std::to_string(WSAGetLastError()));
|
error("(Proxy) bind failed with error: " + std::to_string(WSAGetLastError()));
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
@@ -173,59 +192,64 @@ SOCKET SetupListener(){
|
|||||||
}
|
}
|
||||||
return GSocket;
|
return GSocket;
|
||||||
}
|
}
|
||||||
void AutoPing(){
|
void AutoPing() {
|
||||||
while(!Terminate){
|
while (!Terminate) {
|
||||||
ServerSend("p",false);
|
ServerSend("p", false);
|
||||||
PingStart = std::chrono::high_resolution_clock::now();
|
PingStart = std::chrono::high_resolution_clock::now();
|
||||||
std::this_thread::sleep_for(std::chrono::seconds (1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int ClientID = -1;
|
int ClientID = -1;
|
||||||
void ParserAsync(const std::string& Data){
|
void ParserAsync(std::string_view Data) {
|
||||||
if(Data.empty())return;
|
if (Data.empty())
|
||||||
char Code = Data.at(0),SubCode = 0;
|
return;
|
||||||
if(Data.length() > 1)SubCode = Data.at(1);
|
char Code = Data.at(0), SubCode = 0;
|
||||||
|
if (Data.length() > 1)
|
||||||
|
SubCode = Data.at(1);
|
||||||
switch (Code) {
|
switch (Code) {
|
||||||
case 'p':
|
case 'p':
|
||||||
PingEnd = std::chrono::high_resolution_clock::now();
|
PingEnd = std::chrono::high_resolution_clock::now();
|
||||||
if(PingStart > PingEnd)ping = 0;
|
if (PingStart > PingEnd)
|
||||||
else ping = int(std::chrono::duration_cast<std::chrono::milliseconds>(PingEnd-PingStart).count());
|
ping = 0;
|
||||||
return;
|
else
|
||||||
case 'M':
|
ping = int(std::chrono::duration_cast<std::chrono::milliseconds>(PingEnd - PingStart).count());
|
||||||
MStatus = Data;
|
return;
|
||||||
UlStatus = "Uldone";
|
case 'M':
|
||||||
return;
|
MStatus = Data;
|
||||||
default:
|
UlStatus = "Uldone";
|
||||||
break;
|
return;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
GameSend(Data);
|
GameSend(Data);
|
||||||
}
|
}
|
||||||
void ServerParser(const std::string& Data){
|
void ServerParser(std::string_view Data) {
|
||||||
ParserAsync(Data);
|
ParserAsync(Data);
|
||||||
}
|
}
|
||||||
void NetMain(const std::string& IP, int Port){
|
void NetMain(const std::string& IP, int Port) {
|
||||||
std::thread Ping(AutoPing);
|
std::thread Ping(AutoPing);
|
||||||
Ping.detach();
|
Ping.detach();
|
||||||
UDPClientMain(IP,Port);
|
UDPClientMain(IP, Port);
|
||||||
CServer = true;
|
CServer = true;
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
info("Connection Terminated!");
|
info("Connection Terminated!");
|
||||||
}
|
}
|
||||||
void TCPGameServer(const std::string& IP, int Port){
|
void TCPGameServer(const std::string& IP, int Port) {
|
||||||
GSocket = SetupListener();
|
GSocket = SetupListener();
|
||||||
while (!TCPTerminate && GSocket != -1){
|
std::unique_ptr<std::thread> ClientThread {};
|
||||||
|
std::unique_ptr<std::thread> NetMainThread {};
|
||||||
|
while (!TCPTerminate && GSocket != -1) {
|
||||||
debug("MAIN LOOP OF GAME SERVER");
|
debug("MAIN LOOP OF GAME SERVER");
|
||||||
GConnected = false;
|
GConnected = false;
|
||||||
if(!CServer){
|
if (!CServer) {
|
||||||
warn("Connection still alive terminating");
|
warn("Connection still alive terminating");
|
||||||
NetReset();
|
NetReset();
|
||||||
TCPTerminate = true;
|
TCPTerminate = true;
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(CServer) {
|
if (CServer) {
|
||||||
std::thread Client(TCPClientMain, IP, Port);
|
ClientThread = std::make_unique<std::thread>(TCPClientMain, IP, Port);
|
||||||
Client.detach();
|
|
||||||
}
|
}
|
||||||
CSocket = accept(GSocket, nullptr, nullptr);
|
CSocket = accept(GSocket, nullptr, nullptr);
|
||||||
if (CSocket == -1) {
|
if (CSocket == -1) {
|
||||||
@@ -234,45 +258,62 @@ void TCPGameServer(const std::string& IP, int Port){
|
|||||||
}
|
}
|
||||||
debug("(Proxy) Game Connected!");
|
debug("(Proxy) Game Connected!");
|
||||||
GConnected = true;
|
GConnected = true;
|
||||||
if(CServer){
|
if (CServer) {
|
||||||
std::thread t1(NetMain, IP, Port);
|
NetMainThread = std::make_unique<std::thread>(NetMain, IP, Port);
|
||||||
t1.detach();
|
|
||||||
CServer = false;
|
CServer = false;
|
||||||
}
|
}
|
||||||
int32_t Size,Temp,Rcv;
|
int32_t Size, Rcv;
|
||||||
char Header[10] = {0};
|
int Temp;
|
||||||
|
char Header[10] = { 0 };
|
||||||
|
|
||||||
//Read byte by byte until '>' is rcved then get the size and read based on it
|
// Read byte by byte until '>' is rcved then get the size and read based on it
|
||||||
do{
|
do {
|
||||||
Rcv = 0;
|
Rcv = 0;
|
||||||
|
|
||||||
do{
|
do {
|
||||||
Temp = recv(CSocket,&Header[Rcv],1,0);
|
Temp = recv(CSocket, &Header[Rcv], 1, 0);
|
||||||
if(Temp < 1 || TCPTerminate)break;
|
if (Temp < 1 || TCPTerminate)
|
||||||
}while(Header[Rcv++] != '>');
|
break;
|
||||||
if(Temp < 1 || TCPTerminate)break;
|
} while (Header[Rcv++] != '>');
|
||||||
if(std::from_chars(Header,&Header[Rcv],Size).ptr[0] != '>'){
|
if (Temp < 1 || TCPTerminate)
|
||||||
debug("(Game) Invalid lua Header -> " + std::string(Header,Rcv));
|
break;
|
||||||
|
if (std::from_chars(Header, &Header[Rcv], Size).ptr[0] != '>') {
|
||||||
|
debug("(Game) Invalid lua Header -> " + std::string(Header, Rcv));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
std::string Ret(Size,0);
|
std::string Ret(Size, 0);
|
||||||
Rcv = 0;
|
Rcv = 0;
|
||||||
do{
|
do {
|
||||||
Temp = recv(CSocket,&Ret[Rcv],Size-Rcv,0);
|
Temp = recv(CSocket, &Ret[Rcv], Size - Rcv, 0);
|
||||||
if(Temp < 1)break;
|
if (Temp < 1)
|
||||||
|
break;
|
||||||
Rcv += Temp;
|
Rcv += Temp;
|
||||||
}while(Rcv < Size && !TCPTerminate);
|
} while (Rcv < Size && !TCPTerminate);
|
||||||
if(Temp < 1 || TCPTerminate)break;
|
if (Temp < 1 || TCPTerminate)
|
||||||
|
break;
|
||||||
|
|
||||||
ServerSend(Ret,false);
|
ServerSend(Ret, false);
|
||||||
|
|
||||||
}while(Temp > 0 && !TCPTerminate);
|
} while (Temp > 0 && !TCPTerminate);
|
||||||
if(Temp == 0)debug("(Proxy) Connection closing");
|
if (Temp == 0)
|
||||||
else debug("(Proxy) recv failed error : " + std::to_string(WSAGetLastError()));
|
debug("(Proxy) Connection closing");
|
||||||
|
else
|
||||||
|
debug("(Proxy) recv failed error : " + std::to_string(WSAGetLastError()));
|
||||||
}
|
}
|
||||||
TCPTerminate = true;
|
TCPTerminate = true;
|
||||||
GConnected = false;
|
GConnected = false;
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
if(CSocket != SOCKET_ERROR)KillSocket(CSocket);
|
if (ClientThread) {
|
||||||
|
debug("Waiting for client thread");
|
||||||
|
ClientThread->join();
|
||||||
|
debug("Client thread done");
|
||||||
|
}
|
||||||
|
if (NetMainThread) {
|
||||||
|
debug("Waiting for net main thread");
|
||||||
|
NetMainThread->join();
|
||||||
|
debug("Net main thread done");
|
||||||
|
}
|
||||||
|
if (CSocket != SOCKET_ERROR)
|
||||||
|
KillSocket(CSocket);
|
||||||
debug("END OF GAME SERVER");
|
debug("END OF GAME SERVER");
|
||||||
}
|
}
|
||||||
|
|||||||
415
src/Network/Http.cpp
Executable file → Normal file
415
src/Network/Http.cpp
Executable file → Normal file
@@ -1,129 +1,286 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
/*
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
///
|
*/
|
||||||
/// Created by Anonymous275 on 7/18/2020
|
|
||||||
///
|
|
||||||
#define CPPHTTPLIB_OPENSSL_SUPPORT
|
#include "Http.h"
|
||||||
|
#include <Logger.h>
|
||||||
#include <iostream>
|
#include <Network/network.hpp>
|
||||||
#include <Logger.h>
|
#include <Startup.h>
|
||||||
#include <fstream>
|
#include <Utils.h>
|
||||||
#include "Http.h"
|
#include <cmath>
|
||||||
#include <mutex>
|
#include <curl/curl.h>
|
||||||
#include <cmath>
|
#include <curl/easy.h>
|
||||||
#include <httplib.h>
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
std::string HTTP::Codes_[] =
|
#include <httplib.h>
|
||||||
{
|
#include <iostream>
|
||||||
"Success","Unknown","Connection","BindIPAddress",
|
#include <mutex>
|
||||||
"Read","Write","ExceedRedirectCount","Canceled",
|
#include <nlohmann/json.hpp>
|
||||||
"SSLConnection","SSLLoadingCerts","SSLServerVerification",
|
|
||||||
"UnsupportedMultipartBoundaryChars","Compression"
|
void WriteHttpDebug(const httplib::Client& client, const std::string& method, const std::string& target, const httplib::Result& result) try {
|
||||||
};
|
const std::filesystem::path folder = ".https_debug";
|
||||||
bool HTTP::isDownload = false;
|
std::filesystem::create_directories(folder);
|
||||||
std::string HTTP::Get(const std::string &IP) {
|
if (!std::filesystem::exists(folder / "WHAT IS THIS FOLDER.txt")) {
|
||||||
static std::mutex Lock;
|
std::ofstream ignore { folder / "WHAT IS THIS FOLDER.txt" };
|
||||||
std::scoped_lock Guard(Lock);
|
ignore << "This folder exists to help debug current issues with the backend. Do not share this folder with anyone but BeamMP staff. It contains detailed logs of any failed http requests." << std::endl;
|
||||||
|
}
|
||||||
auto pos = IP.find('/',10);
|
const auto file = folder / (method + ".json");
|
||||||
|
// 1 MB limit
|
||||||
httplib::Client cli(IP.substr(0, pos).c_str());
|
if (std::filesystem::exists(file) && std::filesystem::file_size(file) > 1'000'000) {
|
||||||
cli.set_connection_timeout(std::chrono::seconds(10));
|
std::filesystem::rename(file, file.generic_string() + ".bak");
|
||||||
cli.set_follow_location(true);
|
}
|
||||||
auto res = cli.Get(IP.substr(pos).c_str(), ProgressBar);
|
|
||||||
std::string Ret;
|
std::ofstream of { file, std::ios::app };
|
||||||
|
nlohmann::json js {
|
||||||
if(res.error() == 0){
|
{ "utc", std::chrono::system_clock::now().time_since_epoch().count() },
|
||||||
if(res->status == 200){
|
{ "target", target },
|
||||||
Ret = res->body;
|
{ "client_info", {
|
||||||
}else error(res->reason);
|
{ "openssl_verify_result", client.get_openssl_verify_result() },
|
||||||
|
{ "host", client.host() },
|
||||||
}else{
|
{ "port", client.port() },
|
||||||
if(isDownload) {
|
{ "socket_open", client.is_socket_open() },
|
||||||
std::cout << "\n";
|
{ "valid", client.is_valid() },
|
||||||
}
|
} },
|
||||||
error("HTTP Get failed on " + Codes_[res.error()]);
|
};
|
||||||
}
|
if (result) {
|
||||||
|
auto value = result.value();
|
||||||
return Ret;
|
js["result"] = {};
|
||||||
}
|
js["result"]["body"] = value.body;
|
||||||
|
js["result"]["status"] = value.status;
|
||||||
std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
|
js["result"]["headers"] = value.headers;
|
||||||
static std::mutex Lock;
|
js["result"]["version"] = value.version;
|
||||||
std::scoped_lock Guard(Lock);
|
js["result"]["location"] = value.location;
|
||||||
|
js["result"]["reason"] = value.reason;
|
||||||
auto pos = IP.find('/',10);
|
}
|
||||||
|
of << js.dump();
|
||||||
httplib::Client cli(IP.substr(0, pos).c_str());
|
} catch (const std::exception& e) {
|
||||||
cli.set_connection_timeout(std::chrono::seconds(10));
|
error(e.what());
|
||||||
std::string Ret;
|
}
|
||||||
|
|
||||||
if(!Fields.empty()) {
|
static size_t CurlWriteCallback(void* contents, size_t size, size_t nmemb, void* userp) {
|
||||||
httplib::Result res = cli.Post(IP.substr(pos).c_str(), Fields, "application/json");
|
std::string* Result = reinterpret_cast<std::string*>(userp);
|
||||||
|
std::string NewContents(reinterpret_cast<char*>(contents), size * nmemb);
|
||||||
if(res.error() == 0) {
|
*Result += NewContents;
|
||||||
if (res->status != 200) {
|
return size * nmemb;
|
||||||
error(res->reason);
|
}
|
||||||
}
|
|
||||||
Ret = res->body;
|
bool HTTP::isDownload = false;
|
||||||
}else{
|
std::string HTTP::Get(const std::string& IP) {
|
||||||
error("HTTP Post failed on " + Codes_[res.error()]);
|
std::string Ret;
|
||||||
}
|
static thread_local CURL* curl = curl_easy_init();
|
||||||
}else{
|
if (curl) {
|
||||||
httplib::Result res = cli.Post(IP.substr(pos).c_str());
|
CURLcode res;
|
||||||
if(res.error() == 0) {
|
char errbuf[CURL_ERROR_SIZE];
|
||||||
if (res->status != 200) {
|
curl_easy_setopt(curl, CURLOPT_URL, IP.c_str());
|
||||||
error(res->reason);
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWriteCallback);
|
||||||
}
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&Ret);
|
||||||
Ret = res->body;
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 120); // seconds
|
||||||
}else{
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||||
error("HTTP Post failed on " + Codes_[res.error()]);
|
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
|
||||||
}
|
errbuf[0] = 0;
|
||||||
}
|
res = curl_easy_perform(curl);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
if(Ret.empty())return "-1";
|
error("GET to " + IP + " failed: " + std::string(curl_easy_strerror(res)));
|
||||||
else return Ret;
|
error("Curl error: " + std::string(errbuf));
|
||||||
}
|
return "";
|
||||||
|
}
|
||||||
bool HTTP::ProgressBar(size_t c, size_t t){
|
} else {
|
||||||
if(isDownload) {
|
error("Curl easy init failed");
|
||||||
static double last_progress, progress_bar_adv;
|
return "";
|
||||||
progress_bar_adv = round(c / double(t) * 25);
|
}
|
||||||
std::cout << "\r";
|
return Ret;
|
||||||
std::cout << "Progress : [ ";
|
}
|
||||||
std::cout << round(c / double(t) * 100);
|
|
||||||
std::cout << "% ] [";
|
std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
|
||||||
int i;
|
std::string Ret;
|
||||||
for (i = 0; i <= progress_bar_adv; i++)std::cout << "#";
|
static thread_local CURL* curl = curl_easy_init();
|
||||||
for (i = 0; i < 25 - progress_bar_adv; i++)std::cout << ".";
|
if (curl) {
|
||||||
std::cout << "]";
|
CURLcode res;
|
||||||
last_progress = round(c / double(t) * 100);
|
char errbuf[CURL_ERROR_SIZE];
|
||||||
}
|
curl_easy_setopt(curl, CURLOPT_URL, IP.c_str());
|
||||||
return true;
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWriteCallback);
|
||||||
}
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&Ret);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_POST, 1);
|
||||||
bool HTTP::Download(const std::string &IP, const std::string &Path) {
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, Fields.c_str());
|
||||||
static std::mutex Lock;
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, Fields.size());
|
||||||
std::scoped_lock Guard(Lock);
|
struct curl_slist* list = nullptr;
|
||||||
|
list = curl_slist_append(list, "Content-Type: application/json");
|
||||||
isDownload = true;
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
|
||||||
std::string Ret = Get(IP);
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 120); // seconds
|
||||||
isDownload = false;
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
|
||||||
if(Ret.empty())return false;
|
errbuf[0] = 0;
|
||||||
|
res = curl_easy_perform(curl);
|
||||||
std::ofstream File(Path, std::ios::binary);
|
curl_slist_free_all(list);
|
||||||
if(File.is_open()) {
|
if (res != CURLE_OK) {
|
||||||
File << Ret;
|
error("POST to " + IP + " failed: " + std::string(curl_easy_strerror(res)));
|
||||||
File.close();
|
error("Curl error: " + std::string(errbuf));
|
||||||
std::cout << "\n";
|
return "";
|
||||||
info("Download Complete!");
|
}
|
||||||
}else{
|
} else {
|
||||||
error("Failed to open file directory: " + Path);
|
error("Curl easy init failed");
|
||||||
return false;
|
return "";
|
||||||
}
|
}
|
||||||
|
return Ret;
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
|
bool HTTP::Download(const std::string& IP, const beammp_fs_string& Path, const std::string& Hash) {
|
||||||
|
static std::mutex Lock;
|
||||||
|
std::scoped_lock Guard(Lock);
|
||||||
|
|
||||||
|
info("Downloading an update (this may take a while)");
|
||||||
|
std::string Ret = Get(IP);
|
||||||
|
|
||||||
|
if (Ret.empty()) {
|
||||||
|
error("Download failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string RetHash = Utils::GetSha256HashReallyFast(Ret, Path);
|
||||||
|
|
||||||
|
debug("Return hash: " + RetHash);
|
||||||
|
debug("Expected hash: " + Hash);
|
||||||
|
|
||||||
|
if (RetHash != Hash) {
|
||||||
|
error("Downloaded file hash does not match expected hash");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ofstream File(Path, std::ios::binary);
|
||||||
|
if (File.is_open()) {
|
||||||
|
File << Ret;
|
||||||
|
File.close();
|
||||||
|
info("Download Complete!");
|
||||||
|
} else {
|
||||||
|
error(beammp_wide("Failed to open file directory: ") + Path);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_headers(httplib::Response& res) {
|
||||||
|
res.set_header("Access-Control-Allow-Origin", "*");
|
||||||
|
res.set_header("Access-Control-Request-Method", "POST, OPTIONS, GET");
|
||||||
|
res.set_header("Access-Control-Request-Headers", "X-API-Version");
|
||||||
|
}
|
||||||
|
|
||||||
|
void HTTP::StartProxy() {
|
||||||
|
std::thread proxy([&]() {
|
||||||
|
httplib::Server HTTPProxy;
|
||||||
|
httplib::Headers headers = {
|
||||||
|
{ "User-Agent", "BeamMP-Launcher/" + GetVer() + GetPatch() },
|
||||||
|
{ "Accept", "*/*" }
|
||||||
|
};
|
||||||
|
httplib::Client backend("https://backend.beammp.com");
|
||||||
|
httplib::Client forum("https://forum.beammp.com");
|
||||||
|
|
||||||
|
const std::string pattern = ".*";
|
||||||
|
|
||||||
|
auto handle_request = [&](const httplib::Request& req, httplib::Response& res) {
|
||||||
|
set_headers(res);
|
||||||
|
if (req.has_header("X-BMP-Authentication")) {
|
||||||
|
headers.emplace("X-BMP-Authentication", PrivateKey);
|
||||||
|
}
|
||||||
|
if (req.has_header("X-API-Version")) {
|
||||||
|
headers.emplace("X-API-Version", req.get_header_value("X-API-Version"));
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<std::string> path = Utils::Split(req.path, "/");
|
||||||
|
|
||||||
|
httplib::Result cli_res;
|
||||||
|
const std::string method = req.method;
|
||||||
|
std::string host = "";
|
||||||
|
|
||||||
|
if (!path.empty())
|
||||||
|
host = path[0];
|
||||||
|
|
||||||
|
if (host == "backend") {
|
||||||
|
std::string remaining_path = req.path.substr(std::strlen("/backend"));
|
||||||
|
|
||||||
|
if (method == "GET")
|
||||||
|
cli_res = backend.Get(remaining_path, headers);
|
||||||
|
else if (method == "POST")
|
||||||
|
cli_res = backend.Post(remaining_path, headers);
|
||||||
|
|
||||||
|
} else if (host == "avatar") {
|
||||||
|
bool error = false;
|
||||||
|
std::string username;
|
||||||
|
std::string avatar_size = "100";
|
||||||
|
|
||||||
|
if (path.size() > 1) {
|
||||||
|
username = path[1];
|
||||||
|
} else {
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path.size() > 2) {
|
||||||
|
try {
|
||||||
|
if (std::stoi(path[2]) > 0)
|
||||||
|
avatar_size = path[2];
|
||||||
|
|
||||||
|
} catch (std::exception&) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
httplib::Result summary_res;
|
||||||
|
|
||||||
|
if (!error) {
|
||||||
|
summary_res = forum.Get("/u/" + username + ".json", headers);
|
||||||
|
|
||||||
|
if (!summary_res || summary_res->status != 200) {
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!error) {
|
||||||
|
try {
|
||||||
|
nlohmann::json d = nlohmann::json::parse(summary_res->body, nullptr, false); // can fail with parse_error
|
||||||
|
|
||||||
|
auto user = d.at("user"); // can fail with out_of_range
|
||||||
|
auto avatar_link_json = user.at("avatar_template"); // can fail with out_of_range
|
||||||
|
|
||||||
|
auto avatar_link = avatar_link_json.get<std::string>();
|
||||||
|
size_t start_pos = avatar_link.find("{size}");
|
||||||
|
if (start_pos != std::string::npos)
|
||||||
|
avatar_link.replace(start_pos, std::strlen("{size}"), avatar_size);
|
||||||
|
|
||||||
|
cli_res = forum.Get(avatar_link, headers);
|
||||||
|
|
||||||
|
} catch (std::exception&) {
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
cli_res = forum.Get("/user_avatar/forum.beammp.com/user/0/0.png", headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
res.set_content("Host not found", "text/plain");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cli_res) {
|
||||||
|
res.set_content(cli_res->body, cli_res->get_header_value("Content-Type"));
|
||||||
|
} else {
|
||||||
|
res.set_content(to_string(cli_res.error()), "text/plain");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
HTTPProxy.Get(pattern, [&](const httplib::Request& req, httplib::Response& res) {
|
||||||
|
handle_request(req, res);
|
||||||
|
});
|
||||||
|
|
||||||
|
HTTPProxy.Post(pattern, [&](const httplib::Request& req, httplib::Response& res) {
|
||||||
|
handle_request(req, res);
|
||||||
|
});
|
||||||
|
|
||||||
|
ProxyPort = HTTPProxy.bind_to_any_port("127.0.0.1");
|
||||||
|
debug("HTTP Proxy listening on port " + std::to_string(ProxyPort));
|
||||||
|
HTTPProxy.listen_after_bind();
|
||||||
|
});
|
||||||
|
proxy.detach();
|
||||||
|
}
|
||||||
|
|||||||
747
src/Network/Resources.cpp
Executable file → Normal file
747
src/Network/Resources.cpp
Executable file → Normal file
@@ -1,171 +1,205 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
/*
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
///
|
*/
|
||||||
/// Created by Anonymous275 on 4/11/2020
|
|
||||||
///
|
|
||||||
|
|
||||||
#include "Network/network.hpp"
|
#include "Network/network.hpp"
|
||||||
|
#include <chrono>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <ios>
|
||||||
|
#include <mutex>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <openssl/err.h>
|
||||||
|
#include <openssl/evp.h>
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
#include <sys/socket.h>
|
#include <arpa/inet.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <arpa/inet.h>
|
#include <sys/socket.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <filesystem>
|
|
||||||
#include "Startup.h"
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <iostream>
|
#include "Startup.h"
|
||||||
#include <cstring>
|
#include <Utils.h>
|
||||||
#include <fstream>
|
|
||||||
#include <string>
|
|
||||||
#include <thread>
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <vector>
|
|
||||||
#include <future>
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cstring>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <future>
|
||||||
|
#include <iostream>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
#include "hashpp.h"
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
std::string ListOfMods;
|
|
||||||
std::vector<std::string> Split(const std::string& String,const std::string& delimiter){
|
|
||||||
std::vector<std::string> Val;
|
|
||||||
size_t pos;
|
|
||||||
std::string token,s = String;
|
|
||||||
while ((pos = s.find(delimiter)) != std::string::npos) {
|
|
||||||
token = s.substr(0, pos);
|
|
||||||
if(!token.empty())Val.push_back(token);
|
|
||||||
s.erase(0, pos + delimiter.length());
|
|
||||||
}
|
|
||||||
if(!s.empty())Val.push_back(s);
|
|
||||||
return Val;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckForDir(){
|
void CheckForDir() {
|
||||||
if(!fs::exists("Resources")){
|
if (!fs::exists(CachingDirectory)) {
|
||||||
// Could we just use fs::create_directory instead?
|
try {
|
||||||
#if defined(_WIN32)
|
fs::create_directories(CachingDirectory);
|
||||||
_wmkdir(L"Resources");
|
} catch (const std::exception& e) {
|
||||||
#elif defined(__linux__)
|
error(std::string("Failed to create caching directory: ") + e.what() + ". This is a fatal error. Please make sure to configure a directory which you have permission to create, read and write from/to.");
|
||||||
fs::create_directory(L"Resources");
|
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||||
#endif
|
std::exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void WaitForConfirm(){
|
void WaitForConfirm() {
|
||||||
while(!Terminate && !ModLoaded){
|
while (!Terminate && !ModLoaded) {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
}
|
}
|
||||||
ModLoaded = false;
|
ModLoaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Abord() {
|
||||||
void Abord(){
|
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
TCPTerminate = true;
|
TCPTerminate = true;
|
||||||
info("Terminated!");
|
info("Terminated!");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Auth(SOCKET Sock){
|
std::string Auth(SOCKET Sock) {
|
||||||
TCPSend("VC" + GetVer(),Sock);
|
TCPSend("VC" + GetVer(), Sock);
|
||||||
|
|
||||||
auto Res = TCPRcv(Sock);
|
auto Res = TCPRcv(Sock);
|
||||||
|
|
||||||
if(Res.empty() || Res[0] == 'E' || Res[0] == 'K'){
|
if (Res.empty() || Res[0] == 'E' || Res[0] == 'K') {
|
||||||
Abord();
|
Abord();
|
||||||
|
CoreSend("L");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
TCPSend(PublicKey,Sock);
|
TCPSend(PublicKey, Sock);
|
||||||
if(Terminate)return "";
|
if (Terminate) {
|
||||||
|
CoreSend("L");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
Res = TCPRcv(Sock);
|
Res = TCPRcv(Sock);
|
||||||
if(Res.empty() || Res[0] != 'P'){
|
if (Res.empty() || Res[0] != 'P') {
|
||||||
Abord();
|
Abord();
|
||||||
|
CoreSend("L");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
Res = Res.substr(1);
|
Res = Res.substr(1);
|
||||||
if(Res.find_first_not_of("0123456789") == std::string::npos){
|
if (Res.find_first_not_of("0123456789") == std::string::npos) {
|
||||||
ClientID = std::stoi(Res);
|
ClientID = std::stoi(Res);
|
||||||
}else{
|
} else {
|
||||||
Abord();
|
Abord();
|
||||||
|
CoreSend("L");
|
||||||
UUl("Authentication failed!");
|
UUl("Authentication failed!");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
TCPSend("SR",Sock);
|
TCPSend("SR", Sock);
|
||||||
if(Terminate)return "";
|
if (Terminate) {
|
||||||
|
CoreSend("L");
|
||||||
Res = TCPRcv(Sock);
|
|
||||||
|
|
||||||
if(Res[0] == 'E' || Res[0] == 'K'){
|
|
||||||
Abord();
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Res.empty() || Res == "-"){
|
Res = TCPRcv(Sock);
|
||||||
|
|
||||||
|
if (Res[0] == 'E' || Res[0] == 'K') {
|
||||||
|
Abord();
|
||||||
|
CoreSend("L");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Res.empty() || Res == "-") {
|
||||||
info("Didn't Receive any mods...");
|
info("Didn't Receive any mods...");
|
||||||
ListOfMods = "-";
|
CoreSend("L");
|
||||||
TCPSend("Done",Sock);
|
TCPSend("Done", Sock);
|
||||||
info("Done!");
|
info("Done!");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return Res;
|
return Res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateUl(bool D,const std::string&msg){
|
void UpdateUl(bool D, const std::string& msg) {
|
||||||
if(D)UlStatus = "UlDownloading Resource " + msg;
|
if (D)
|
||||||
else UlStatus = "UlLoading Resource " + msg;
|
UlStatus = "UlDownloading Resource " + msg;
|
||||||
|
else
|
||||||
|
UlStatus = "UlLoading Resource " + msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsyncUpdate(uint64_t& Rcv,uint64_t Size,const std::string& Name){
|
float DownloadSpeed = 0;
|
||||||
|
|
||||||
|
void AsyncUpdate(uint64_t& Rcv, uint64_t Size, const std::string& Name) {
|
||||||
do {
|
do {
|
||||||
double pr = double(Rcv) / double(Size) * 100;
|
double pr = double(Rcv) / double(Size) * 100;
|
||||||
std::string Per = std::to_string(trunc(pr * 10) / 10);
|
std::string Per = std::to_string(trunc(pr * 10) / 10);
|
||||||
UpdateUl(true, Name + " (" + Per.substr(0, Per.find('.') + 2) + "%)");
|
std::string SpeedString = "";
|
||||||
|
if (DownloadSpeed > 0.01) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << " at " << std::setprecision(1) << std::fixed << DownloadSpeed << " Mbit/s";
|
||||||
|
SpeedString = ss.str();
|
||||||
|
}
|
||||||
|
UpdateUl(true, Name + " (" + Per.substr(0, Per.find('.') + 2) + "%)" + SpeedString);
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
}while(!Terminate && Rcv < Size);
|
} while (!Terminate && Rcv < Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* TCPRcvRaw(SOCKET Sock,uint64_t& GRcv, uint64_t Size){
|
// MICROSOFT, I DONT CARE, WRITE BETTER CODE
|
||||||
if(Sock == -1){
|
#undef min
|
||||||
|
|
||||||
|
std::vector<char> TCPRcvRaw(SOCKET Sock, uint64_t& GRcv, uint64_t Size) {
|
||||||
|
if (Sock == -1) {
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
UUl("Invalid Socket");
|
UUl("Invalid Socket");
|
||||||
return nullptr;
|
return {};
|
||||||
}
|
}
|
||||||
char* File = new char[Size];
|
std::vector<char> File(Size);
|
||||||
uint64_t Rcv = 0;
|
uint64_t Rcv = 0;
|
||||||
do{
|
|
||||||
int Len = int(Size-Rcv);
|
auto start = std::chrono::high_resolution_clock::now();
|
||||||
if(Len > 1000000)Len = 1000000;
|
|
||||||
int32_t Temp = recv(Sock, &File[Rcv], Len, MSG_WAITALL);
|
int i = 0;
|
||||||
if(Temp < 1){
|
do {
|
||||||
info(std::to_string(Temp));
|
// receive at most some MB at a time
|
||||||
|
int Len = std::min(int(Size - Rcv), 1 * 1024 * 1024);
|
||||||
|
int Temp = recv(Sock, &File[Rcv], Len, MSG_WAITALL);
|
||||||
|
if (Temp == -1 || Temp == 0) {
|
||||||
|
debug("Recv returned: " + std::to_string(Temp));
|
||||||
|
if (Temp == -1) {
|
||||||
|
error("Socket error during download: " + std::to_string(WSAGetLastError()));
|
||||||
|
}
|
||||||
UUl("Socket Closed Code 1");
|
UUl("Socket Closed Code 1");
|
||||||
KillSocket(Sock);
|
KillSocket(Sock);
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
delete[] File;
|
return {};
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
Rcv += Temp;
|
Rcv += Temp;
|
||||||
GRcv += Temp;
|
GRcv += Temp;
|
||||||
}while(Rcv < Size && !Terminate);
|
|
||||||
|
auto end = std::chrono::high_resolution_clock::now();
|
||||||
|
auto difference = end - start;
|
||||||
|
double bits_per_s = double(Rcv * 8) / double(std::chrono::duration_cast<std::chrono::milliseconds>(difference).count());
|
||||||
|
double megabits_per_s = bits_per_s / 1000;
|
||||||
|
DownloadSpeed = megabits_per_s;
|
||||||
|
// every 8th iteration print the speed
|
||||||
|
if (i % 8 == 0) {
|
||||||
|
debug("Download speed: " + std::to_string(uint32_t(megabits_per_s)) + "Mbit/s");
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
} while (Rcv < Size && !Terminate);
|
||||||
return File;
|
return File;
|
||||||
}
|
}
|
||||||
void MultiKill(SOCKET Sock,SOCKET Sock1){
|
void MultiKill(SOCKET Sock, SOCKET Sock1) {
|
||||||
KillSocket(Sock1);
|
KillSocket(Sock1);
|
||||||
KillSocket(Sock);
|
KillSocket(Sock);
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
}
|
}
|
||||||
SOCKET InitDSock(){
|
SOCKET InitDSock() {
|
||||||
SOCKET DSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
SOCKET DSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
SOCKADDR_IN ServerAddr;
|
SOCKADDR_IN ServerAddr;
|
||||||
if(DSock < 1){
|
if (DSock < 1) {
|
||||||
KillSocket(DSock);
|
KillSocket(DSock);
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -173,13 +207,13 @@ SOCKET InitDSock(){
|
|||||||
ServerAddr.sin_family = AF_INET;
|
ServerAddr.sin_family = AF_INET;
|
||||||
ServerAddr.sin_port = htons(LastPort);
|
ServerAddr.sin_port = htons(LastPort);
|
||||||
inet_pton(AF_INET, LastIP.c_str(), &ServerAddr.sin_addr);
|
inet_pton(AF_INET, LastIP.c_str(), &ServerAddr.sin_addr);
|
||||||
if(connect(DSock, (SOCKADDR *) &ServerAddr, sizeof(ServerAddr)) != 0){
|
if (connect(DSock, (SOCKADDR*)&ServerAddr, sizeof(ServerAddr)) != 0) {
|
||||||
KillSocket(DSock);
|
KillSocket(DSock);
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
char Code[2] = {'D',char(ClientID)};
|
char Code[2] = { 'D', char(ClientID) };
|
||||||
if(send(DSock,Code,2,0) != 2){
|
if (send(DSock, Code, 2, 0) != 2) {
|
||||||
KillSocket(DSock);
|
KillSocket(DSock);
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -187,113 +221,469 @@ SOCKET InitDSock(){
|
|||||||
return DSock;
|
return DSock;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MultiDownload(SOCKET MSock,SOCKET DSock, uint64_t Size, const std::string& Name){
|
std::vector<char> SingleNormalDownload(SOCKET MSock, uint64_t Size, const std::string& Name) {
|
||||||
|
DownloadSpeed = 0;
|
||||||
|
|
||||||
uint64_t GRcv = 0, MSize = Size/2, DSize = Size - MSize;
|
uint64_t GRcv = 0;
|
||||||
|
|
||||||
std::thread Au(AsyncUpdate,std::ref(GRcv), Size, Name);
|
std::thread Au([&] { AsyncUpdate(GRcv, Size, Name); });
|
||||||
|
|
||||||
std::packaged_task<char*()> task([&] { return TCPRcvRaw(MSock,GRcv,MSize); });
|
const std::vector<char> MData = TCPRcvRaw(MSock, GRcv, Size);
|
||||||
std::future<char*> f1 = task.get_future();
|
|
||||||
std::thread Dt(std::move(task));
|
|
||||||
Dt.detach();
|
|
||||||
|
|
||||||
char* DData = TCPRcvRaw(DSock,GRcv,DSize);
|
if (MData.empty()) {
|
||||||
|
KillSocket(MSock);
|
||||||
if(!DData){
|
Terminate = true;
|
||||||
MultiKill(MSock,DSock);
|
Au.join();
|
||||||
return "";
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
f1.wait();
|
// ensure that GRcv is good before joining the async update thread
|
||||||
char* MData = f1.get();
|
GRcv = MData.size();
|
||||||
|
if (GRcv != Size) {
|
||||||
if(!MData){
|
error("Something went wrong during download; didn't get enough data. Expected " + std::to_string(Size) + " bytes, got " + std::to_string(GRcv) + " bytes instead");
|
||||||
MultiKill(MSock,DSock);
|
Terminate = true;
|
||||||
return "";
|
Au.join();
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Au.joinable())Au.join();
|
Au.join();
|
||||||
|
return MData;
|
||||||
|
|
||||||
///omg yes very ugly my god but i was in a rush will revisit
|
|
||||||
std::string Ret(Size,0);
|
|
||||||
memcpy(&Ret[0],MData,MSize);
|
|
||||||
delete[]MData;
|
|
||||||
|
|
||||||
memcpy(&Ret[MSize],DData,DSize);
|
|
||||||
delete[]DData;
|
|
||||||
|
|
||||||
return Ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InvalidResource(const std::string& File){
|
std::vector<char> MultiDownload(SOCKET MSock, SOCKET DSock, uint64_t Size, const std::string& Name) {
|
||||||
|
DownloadSpeed = 0;
|
||||||
|
|
||||||
|
uint64_t GRcv = 0;
|
||||||
|
|
||||||
|
uint64_t MSize = Size / 2;
|
||||||
|
uint64_t DSize = Size - MSize;
|
||||||
|
|
||||||
|
std::thread Au([&] { AsyncUpdate(GRcv, Size, Name); });
|
||||||
|
|
||||||
|
const std::vector<char> MData = TCPRcvRaw(MSock, GRcv, MSize);
|
||||||
|
|
||||||
|
if (MData.empty()) {
|
||||||
|
MultiKill(MSock, DSock);
|
||||||
|
Terminate = true;
|
||||||
|
Au.join();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<char> DData = TCPRcvRaw(DSock, GRcv, DSize);
|
||||||
|
|
||||||
|
if (DData.empty()) {
|
||||||
|
MultiKill(MSock, DSock);
|
||||||
|
Terminate = true;
|
||||||
|
Au.join();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure that GRcv is good before joining the async update thread
|
||||||
|
GRcv = MData.size() + DData.size();
|
||||||
|
if (GRcv != Size) {
|
||||||
|
error("Something went wrong during download; didn't get enough data. Expected " + std::to_string(Size) + " bytes, got " + std::to_string(GRcv) + " bytes instead");
|
||||||
|
Terminate = true;
|
||||||
|
Au.join();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
Au.join();
|
||||||
|
|
||||||
|
std::vector<char> Result {};
|
||||||
|
Result.insert(Result.begin(), MData.begin(), MData.end());
|
||||||
|
Result.insert(Result.end(), DData.begin(), DData.end());
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void InvalidResource(const std::string& File) {
|
||||||
UUl("Invalid mod \"" + File + "\"");
|
UUl("Invalid mod \"" + File + "\"");
|
||||||
warn("The server tried to sync \"" + File + "\" that is not a .zip file!");
|
warn("The server tried to sync \"" + File + "\" that is not a .zip file!");
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SyncResources(SOCKET Sock){
|
struct ModInfo {
|
||||||
|
static std::pair<bool, std::vector<ModInfo>> ParseModInfosFromPacket(const std::string& packet) {
|
||||||
|
bool success = false;
|
||||||
|
std::vector<ModInfo> modInfos;
|
||||||
|
try {
|
||||||
|
auto json = nlohmann::json::parse(packet);
|
||||||
|
if (json.empty()) {
|
||||||
|
return std::make_pair(true, modInfos);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& entry : json) {
|
||||||
|
ModInfo modInfo {
|
||||||
|
.FileName = entry["file_name"],
|
||||||
|
.FileSize = entry["file_size"],
|
||||||
|
.Hash = entry["hash"],
|
||||||
|
.HashAlgorithm = entry["hash_algorithm"],
|
||||||
|
};
|
||||||
|
|
||||||
|
if (entry.contains("protected")) {
|
||||||
|
modInfo.Protected = entry["protected"];
|
||||||
|
}
|
||||||
|
|
||||||
|
modInfos.push_back(modInfo);
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
debug(std::string("Failed to receive mod list: ") + e.what());
|
||||||
|
debug("Failed to receive new mod list format! This server may be outdated, but everything should still work as expected.");
|
||||||
|
}
|
||||||
|
return std::make_pair(success, modInfos);
|
||||||
|
}
|
||||||
|
std::string FileName;
|
||||||
|
size_t FileSize;
|
||||||
|
std::string Hash;
|
||||||
|
std::string HashAlgorithm;
|
||||||
|
bool Protected = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
nlohmann::json modUsage = {};
|
||||||
|
|
||||||
|
void UpdateModUsage(const std::string& fileName) {
|
||||||
|
try {
|
||||||
|
fs::path usageFile = CachingDirectory / "mods.json";
|
||||||
|
|
||||||
|
if (!fs::exists(usageFile)) {
|
||||||
|
if (std::ofstream file(usageFile); !file.is_open()) {
|
||||||
|
error("Failed to create mods.json");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::fstream file(usageFile, std::ios::in | std::ios::out);
|
||||||
|
if (!file.is_open()) {
|
||||||
|
error("Failed to open or create mods.json");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modUsage.empty()) {
|
||||||
|
auto Size = fs::file_size(CachingDirectory / "mods.json");
|
||||||
|
std::string modsJson(Size, 0);
|
||||||
|
file.read(&modsJson[0], Size);
|
||||||
|
|
||||||
|
if (!modsJson.empty()) {
|
||||||
|
auto parsedModJson = nlohmann::json::parse(modsJson, nullptr, false);
|
||||||
|
|
||||||
|
if (parsedModJson.is_object())
|
||||||
|
modUsage = parsedModJson;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
modUsage[fileName] = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||||
|
|
||||||
|
file.clear();
|
||||||
|
file.seekp(0, std::ios::beg);
|
||||||
|
file << modUsage.dump();
|
||||||
|
file.close();
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
error("Failed to update mods.json: " + std::string(e.what()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<ModInfo> ModInfos) {
|
||||||
|
if (ModInfos.empty()) {
|
||||||
|
CoreSend("L");
|
||||||
|
TCPSend("Done", Sock);
|
||||||
|
info("Done!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SecurityWarning())
|
||||||
|
return;
|
||||||
|
|
||||||
|
info("Checking Resources...");
|
||||||
|
|
||||||
|
CheckForDir();
|
||||||
|
|
||||||
|
std::string t;
|
||||||
|
for (const auto& mod : ModInfos) {
|
||||||
|
t += mod.FileName + ";";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t.empty())
|
||||||
|
CoreSend("L");
|
||||||
|
else
|
||||||
|
CoreSend("L" + t);
|
||||||
|
t.clear();
|
||||||
|
|
||||||
|
info("Syncing...");
|
||||||
|
|
||||||
|
std::vector<std::pair<std::string, std::filesystem::path>> CachedMods = {};
|
||||||
|
if (deleteDuplicateMods) {
|
||||||
|
for (const auto& entry : fs::directory_iterator(CachingDirectory)) {
|
||||||
|
const std::string filename = entry.path().filename().string();
|
||||||
|
if (entry.is_regular_file() && entry.path().extension() == ".zip" && filename.length() > 10) {
|
||||||
|
CachedMods.push_back(std::make_pair(filename.substr(0, filename.length() - 13) + ".zip", entry.path()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int ModNo = 0;
|
||||||
|
int TotalMods = ModInfos.size();
|
||||||
|
for (auto ModInfoIter = ModInfos.begin(), AlsoModInfoIter = ModInfos.begin(); ModInfoIter != ModInfos.end() && !Terminate; ++ModInfoIter, ++AlsoModInfoIter) {
|
||||||
|
++ModNo;
|
||||||
|
if (deleteDuplicateMods) {
|
||||||
|
for (auto& CachedMod : CachedMods) {
|
||||||
|
const bool cachedModExists = CachedMod.first == ModInfoIter->FileName;
|
||||||
|
const bool cachedModIsNotNewestVersion = CachedMod.second.stem().string() + ".zip" != std::filesystem::path(ModInfoIter->FileName).stem().string() + "-" + ModInfoIter->Hash.substr(0, 8) + ".zip";
|
||||||
|
if (cachedModExists && cachedModIsNotNewestVersion) {
|
||||||
|
debug("Found duplicate mod '" + CachedMod.second.stem().string() + ".zip" + "' in cache, removing it");
|
||||||
|
std::filesystem::remove(CachedMod.second);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ModInfoIter->Hash.length() < 8 || ModInfoIter->HashAlgorithm != "sha256") {
|
||||||
|
error("Unsupported hash algorithm or invalid hash for '" + ModInfoIter->FileName + "'");
|
||||||
|
Terminate = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto FileName = std::filesystem::path(ModInfoIter->FileName).stem().string() + "-" + ModInfoIter->Hash.substr(0, 8) + std::filesystem::path(ModInfoIter->FileName).extension().string();
|
||||||
|
auto PathToSaveTo = (CachingDirectory / FileName);
|
||||||
|
if (fs::exists(PathToSaveTo) && Utils::GetSha256HashReallyFastFile(PathToSaveTo) == ModInfoIter->Hash) {
|
||||||
|
debug("Mod '" + FileName + "' found in cache");
|
||||||
|
UpdateUl(false, std::to_string(ModNo) + "/" + std::to_string(TotalMods) + ": " + ModInfoIter->FileName);
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||||
|
try {
|
||||||
|
if (!fs::exists(GetGamePath() / beammp_wide("mods/multiplayer"))) {
|
||||||
|
fs::create_directories(GetGamePath() / beammp_wide("mods/multiplayer"));
|
||||||
|
}
|
||||||
|
auto modname = ModInfoIter->FileName;
|
||||||
|
#if defined(__linux__)
|
||||||
|
// Linux version of the game doesnt support uppercase letters in mod names
|
||||||
|
for (char& c : modname) {
|
||||||
|
c = ::tolower(c);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
debug("Mod name: " + modname);
|
||||||
|
auto name = std::filesystem::path(GetGamePath()) / "mods/multiplayer" / modname;
|
||||||
|
std::string tmp_name = name.string();
|
||||||
|
tmp_name += ".tmp";
|
||||||
|
|
||||||
|
fs::copy_file(PathToSaveTo, tmp_name, fs::copy_options::overwrite_existing);
|
||||||
|
fs::rename(tmp_name, name);
|
||||||
|
UpdateModUsage(FileName);
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
error("Failed copy to the mods folder! " + std::string(e.what()));
|
||||||
|
Terminate = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
WaitForConfirm();
|
||||||
|
continue;
|
||||||
|
} else if (auto OldCachedPath = CachingDirectory / std::filesystem::path(ModInfoIter->FileName).filename();
|
||||||
|
fs::exists(OldCachedPath) && Utils::GetSha256HashReallyFastFile(OldCachedPath) == ModInfoIter->Hash) {
|
||||||
|
debug("Mod '" + FileName + "' found in old cache, copying it to the new cache");
|
||||||
|
UpdateUl(false, std::to_string(ModNo) + "/" + std::to_string(TotalMods) + ": " + ModInfoIter->FileName);
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||||
|
try {
|
||||||
|
fs::copy_file(OldCachedPath, PathToSaveTo, fs::copy_options::overwrite_existing);
|
||||||
|
|
||||||
|
if (!fs::exists(GetGamePath() / beammp_wide("mods/multiplayer"))) {
|
||||||
|
fs::create_directories(GetGamePath() / beammp_wide("mods/multiplayer"));
|
||||||
|
}
|
||||||
|
|
||||||
|
auto modname = ModInfoIter->FileName;
|
||||||
|
|
||||||
|
#if defined(__linux__)
|
||||||
|
// Linux version of the game doesnt support uppercase letters in mod names
|
||||||
|
for (char& c : modname) {
|
||||||
|
c = ::tolower(c);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
debug("Mod name: " + modname);
|
||||||
|
auto name = std::filesystem::path(GetGamePath()) / "mods/multiplayer" / modname;
|
||||||
|
std::string tmp_name = name.string();
|
||||||
|
tmp_name += ".tmp";
|
||||||
|
|
||||||
|
fs::copy_file(PathToSaveTo, tmp_name, fs::copy_options::overwrite_existing);
|
||||||
|
fs::rename(tmp_name, name);
|
||||||
|
UpdateModUsage(FileName);
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
error("Failed copy to the mods folder! " + std::string(e.what()));
|
||||||
|
Terminate = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
WaitForConfirm();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ModInfoIter->Protected) {
|
||||||
|
std::string message = "Mod '" + ModInfoIter->FileName + "' is protected and therefore must be placed in the Resources/Caching folder manually here: " + absolute(CachingDirectory).string();
|
||||||
|
|
||||||
|
error(message);
|
||||||
|
UUl(message);
|
||||||
|
Terminate = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CheckForDir();
|
||||||
|
std::string FName = ModInfoIter->FileName;
|
||||||
|
do {
|
||||||
|
debug(beammp_wide("Loading file '") + Utils::ToWString(FName) + beammp_wide("' to '") + beammp_fs_string(PathToSaveTo) + beammp_wide("'"));
|
||||||
|
TCPSend("f" + ModInfoIter->FileName, Sock);
|
||||||
|
|
||||||
|
std::string Data = TCPRcv(Sock);
|
||||||
|
if (Data == "CO" || Terminate) {
|
||||||
|
Terminate = true;
|
||||||
|
UUl("Server cannot find " + FName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Data != "AG") {
|
||||||
|
UUl("Received corrupted download confirmation, aborting download.");
|
||||||
|
debug("Corrupted download confirmation: " + Data);
|
||||||
|
Terminate = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Name = std::to_string(ModNo) + "/" + std::to_string(TotalMods) + ": " + FName;
|
||||||
|
|
||||||
|
std::vector<char> DownloadedFile = SingleNormalDownload(Sock, ModInfoIter->FileSize, Name);
|
||||||
|
|
||||||
|
if (Terminate)
|
||||||
|
break;
|
||||||
|
UpdateUl(false, std::to_string(ModNo) + "/" + std::to_string(TotalMods) + ": " + FName);
|
||||||
|
|
||||||
|
// 1. write downloaded file to disk
|
||||||
|
{
|
||||||
|
std::ofstream OutFile(PathToSaveTo, std::ios::binary | std::ios::trunc);
|
||||||
|
OutFile.write(DownloadedFile.data(), DownloadedFile.size());
|
||||||
|
OutFile.flush();
|
||||||
|
}
|
||||||
|
// 2. verify size and hash
|
||||||
|
if (std::filesystem::file_size(PathToSaveTo) != DownloadedFile.size()) {
|
||||||
|
error(beammp_wide("Failed to write the entire file '") + beammp_fs_string(PathToSaveTo) + beammp_wide("' correctly (file size mismatch)"));
|
||||||
|
Terminate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Utils::GetSha256HashReallyFastFile(PathToSaveTo) != ModInfoIter->Hash) {
|
||||||
|
error(beammp_wide("Failed to write or download the entire file '") + beammp_fs_string(PathToSaveTo) + beammp_wide("' correctly (hash mismatch)"));
|
||||||
|
Terminate = true;
|
||||||
|
}
|
||||||
|
} while (fs::file_size(PathToSaveTo) != ModInfoIter->FileSize && !Terminate);
|
||||||
|
if (!Terminate) {
|
||||||
|
if (!fs::exists(GetGamePath() / beammp_wide("mods/multiplayer"))) {
|
||||||
|
fs::create_directories(GetGamePath() / beammp_wide("mods/multiplayer"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Linux version of the game doesnt support uppercase letters in mod names
|
||||||
|
#if defined(__linux__)
|
||||||
|
for (char& c : FName) {
|
||||||
|
c = ::tolower(c);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
fs::copy_file(PathToSaveTo, std::filesystem::path(GetGamePath()) / "mods/multiplayer" / FName, fs::copy_options::overwrite_existing);
|
||||||
|
UpdateModUsage(FName);
|
||||||
|
}
|
||||||
|
WaitForConfirm();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Terminate) {
|
||||||
|
TCPSend("Done", Sock);
|
||||||
|
info("Done!");
|
||||||
|
} else {
|
||||||
|
UlStatus = "Ulstart";
|
||||||
|
info("Connection Terminated!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SyncResources(SOCKET Sock) {
|
||||||
std::string Ret = Auth(Sock);
|
std::string Ret = Auth(Sock);
|
||||||
if(Ret.empty())return;
|
|
||||||
|
debug("Mod info: " + Ret);
|
||||||
|
|
||||||
|
if (Ret.starts_with("R")) {
|
||||||
|
debug("This server is likely outdated, not trying to parse new mod info format");
|
||||||
|
} else {
|
||||||
|
auto [success, modInfo] = ModInfo::ParseModInfosFromPacket(Ret);
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
NewSyncResources(Sock, Ret, modInfo);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Ret.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!SecurityWarning())
|
||||||
|
return;
|
||||||
|
|
||||||
info("Checking Resources...");
|
info("Checking Resources...");
|
||||||
CheckForDir();
|
CheckForDir();
|
||||||
|
|
||||||
std::vector<std::string> list = Split(Ret, ";");
|
std::vector<std::string> list = Utils::Split(Ret, ";");
|
||||||
std::vector<std::string> FNames(list.begin(), list.begin() + (list.size() / 2));
|
std::vector<std::string> FNames(list.begin(), list.begin() + (list.size() / 2));
|
||||||
std::vector<std::string> FSizes(list.begin() + (list.size() / 2), list.end());
|
std::vector<std::string> FSizes(list.begin() + (list.size() / 2), list.end());
|
||||||
list.clear();
|
list.clear();
|
||||||
Ret.clear();
|
Ret.clear();
|
||||||
|
|
||||||
int Amount = 0,Pos = 0;
|
int Amount = 0, Pos = 0;
|
||||||
std::string a,t;
|
std::filesystem::path PathToSaveTo;
|
||||||
for(const std::string&name : FNames){
|
std::string t;
|
||||||
if(!name.empty()){
|
for (const std::string& name : FNames) {
|
||||||
|
if (!name.empty()) {
|
||||||
t += name.substr(name.find_last_of('/') + 1) + ";";
|
t += name.substr(name.find_last_of('/') + 1) + ";";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(t.empty())ListOfMods = "-";
|
if (t.empty())
|
||||||
else ListOfMods = t;
|
CoreSend("L");
|
||||||
|
else
|
||||||
|
CoreSend("L" + t);
|
||||||
t.clear();
|
t.clear();
|
||||||
for(auto FN = FNames.begin(),FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN,++FS) {
|
for (auto FN = FNames.begin(), FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN, ++FS) {
|
||||||
auto pos = FN->find_last_of('/');
|
auto pos = FN->find_last_of('/');
|
||||||
auto ZIP = FN->find(".zip");
|
auto ZIP = FN->find(".zip");
|
||||||
if (ZIP == std::string::npos || FN->length() - ZIP != 4) {
|
if (ZIP == std::string::npos || FN->length() - ZIP != 4) {
|
||||||
InvalidResource(*FN);
|
InvalidResource(*FN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (pos == std::string::npos)continue;
|
if (pos == std::string::npos)
|
||||||
|
continue;
|
||||||
Amount++;
|
Amount++;
|
||||||
}
|
}
|
||||||
if(!FNames.empty())info("Syncing...");
|
if (!FNames.empty())
|
||||||
|
info("Syncing...");
|
||||||
SOCKET DSock = InitDSock();
|
SOCKET DSock = InitDSock();
|
||||||
for(auto FN = FNames.begin(),FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN,++FS) {
|
for (auto FN = FNames.begin(), FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN, ++FS) {
|
||||||
auto pos = FN->find_last_of('/');
|
auto pos = FN->find_last_of('/');
|
||||||
if (pos != std::string::npos) {
|
if (pos != std::string::npos) {
|
||||||
a = "Resources" + FN->substr(pos);
|
PathToSaveTo = CachingDirectory / std::filesystem::path(*FN).filename();
|
||||||
} else continue;
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Pos++;
|
Pos++;
|
||||||
if (fs::exists(a)) {
|
auto FileSize = std::stoull(*FS);
|
||||||
if (FS->find_first_not_of("0123456789") != std::string::npos)continue;
|
if (fs::exists(PathToSaveTo)) {
|
||||||
if (fs::file_size(a) == std::stoull(*FS)){
|
if (FS->find_first_not_of("0123456789") != std::string::npos)
|
||||||
UpdateUl(false,std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + a.substr(a.find_last_of('/')));
|
continue;
|
||||||
|
if (fs::file_size(PathToSaveTo) == FileSize) {
|
||||||
|
UpdateUl(false, std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + PathToSaveTo.filename().string());
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||||
try {
|
try {
|
||||||
if(!fs::exists(GetGamePath() + "mods/multiplayer")){
|
if (!fs::exists(GetGamePath() / beammp_wide("mods/multiplayer"))) {
|
||||||
fs::create_directories(GetGamePath() + "mods/multiplayer");
|
fs::create_directories(GetGamePath() / beammp_wide("mods/multiplayer"));
|
||||||
}
|
}
|
||||||
|
auto modname = PathToSaveTo.filename().string();
|
||||||
std::string FName = a.substr(a.find_last_of('/'));
|
#if defined(__linux__)
|
||||||
// Linux version of the game doesnt support uppercase letters in mod names
|
// Linux version of the game doesnt support uppercase letters in mod names
|
||||||
#if defined(__linux__)
|
for (char& c : modname) {
|
||||||
for(char &c : FName){
|
|
||||||
c = ::tolower(c);
|
c = ::tolower(c);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
auto name = GetGamePath() / beammp_wide("mods/multiplayer") / Utils::ToWString(modname);
|
||||||
fs::copy_file(a, GetGamePath() + "mods/multiplayer" + FName,
|
auto tmp_name = name;
|
||||||
fs::copy_options::overwrite_existing);
|
tmp_name += L".tmp";
|
||||||
|
fs::copy_file(PathToSaveTo, tmp_name, fs::copy_options::overwrite_existing);
|
||||||
|
fs::rename(tmp_name, name);
|
||||||
|
UpdateModUsage(modname);
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
error("Failed copy to the mods folder! " + std::string(e.what()));
|
error("Failed copy to the mods folder! " + std::string(e.what()));
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
@@ -301,15 +691,17 @@ void SyncResources(SOCKET Sock){
|
|||||||
}
|
}
|
||||||
WaitForConfirm();
|
WaitForConfirm();
|
||||||
continue;
|
continue;
|
||||||
}else remove(a.c_str());
|
} else
|
||||||
|
fs::remove(PathToSaveTo.wstring());
|
||||||
}
|
}
|
||||||
CheckForDir();
|
CheckForDir();
|
||||||
std::string FName = a.substr(a.find_last_of('/'));
|
std::string FName = PathToSaveTo.filename().string();
|
||||||
do {
|
do {
|
||||||
TCPSend("f" + *FN,Sock);
|
debug("Loading file '" + FName + "' to '" + PathToSaveTo.string() + "'");
|
||||||
|
TCPSend("f" + *FN, Sock);
|
||||||
|
|
||||||
std::string Data = TCPRcv(Sock);
|
std::string Data = TCPRcv(Sock);
|
||||||
if (Data == "CO" || Terminate){
|
if (Data == "CO" || Terminate) {
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
UUl("Server cannot find " + FName);
|
UUl("Server cannot find " + FName);
|
||||||
break;
|
break;
|
||||||
@@ -317,40 +709,47 @@ void SyncResources(SOCKET Sock){
|
|||||||
|
|
||||||
std::string Name = std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + FName;
|
std::string Name = std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + FName;
|
||||||
|
|
||||||
Data = MultiDownload(Sock,DSock,std::stoull(*FS), Name);
|
std::vector<char> DownloadedFile = MultiDownload(Sock, DSock, FileSize, Name);
|
||||||
|
|
||||||
if(Terminate)break;
|
if (Terminate)
|
||||||
UpdateUl(false,std::to_string(Pos)+"/"+std::to_string(Amount)+": "+FName);
|
break;
|
||||||
std::ofstream LFS;
|
UpdateUl(false, std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + FName);
|
||||||
LFS.open(a.c_str(), std::ios_base::app | std::ios::binary);
|
|
||||||
if (LFS.is_open()) {
|
// 1. write downloaded file to disk
|
||||||
LFS.write(&Data[0], Data.size());
|
{
|
||||||
LFS.close();
|
std::ofstream OutFile(PathToSaveTo, std::ios::binary | std::ios::trunc);
|
||||||
|
OutFile.write(DownloadedFile.data(), DownloadedFile.size());
|
||||||
|
}
|
||||||
|
// 2. verify size
|
||||||
|
if (std::filesystem::file_size(PathToSaveTo) != DownloadedFile.size()) {
|
||||||
|
error(beammp_wide("Failed to write the entire file '") + beammp_fs_string(PathToSaveTo) + beammp_wide("' correctly (file size mismatch)"));
|
||||||
|
Terminate = true;
|
||||||
|
}
|
||||||
|
} while (fs::file_size(PathToSaveTo) != std::stoull(*FS) && !Terminate);
|
||||||
|
if (!Terminate) {
|
||||||
|
if (!fs::exists(GetGamePath() / beammp_wide("mods/multiplayer"))) {
|
||||||
|
fs::create_directories(GetGamePath() / beammp_wide("mods/multiplayer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}while(fs::file_size(a) != std::stoull(*FS) && !Terminate);
|
// Linux version of the game doesnt support uppercase letters in mod names
|
||||||
if(!Terminate){
|
#if defined(__linux__)
|
||||||
if(!fs::exists(GetGamePath() + "mods/multiplayer")){
|
for (char& c : FName) {
|
||||||
fs::create_directories(GetGamePath() + "mods/multiplayer");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Linux version of the game doesnt support uppercase letters in mod names
|
|
||||||
#if defined(__linux__)
|
|
||||||
for(char &c : FName){
|
|
||||||
c = ::tolower(c);
|
c = ::tolower(c);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fs::copy_file(a,GetGamePath() + "mods/multiplayer" + FName, fs::copy_options::overwrite_existing);
|
fs::copy_file(PathToSaveTo, GetGamePath() / beammp_wide("mods/multiplayer") / Utils::ToWString(FName), fs::copy_options::overwrite_existing);
|
||||||
|
UpdateModUsage(FN->substr(pos));
|
||||||
}
|
}
|
||||||
WaitForConfirm();
|
WaitForConfirm();
|
||||||
}
|
}
|
||||||
|
|
||||||
KillSocket(DSock);
|
KillSocket(DSock);
|
||||||
if(!Terminate){
|
if (!Terminate) {
|
||||||
TCPSend("Done",Sock);
|
TCPSend("Done", Sock);
|
||||||
info("Done!");
|
info("Done!");
|
||||||
}else{
|
} else {
|
||||||
UlStatus = "Ulstart";
|
UlStatus = "Ulstart";
|
||||||
info("Connection Terminated!");
|
info("Connection Terminated!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
115
src/Network/VehicleData.cpp
Executable file → Normal file
115
src/Network/VehicleData.cpp
Executable file → Normal file
@@ -1,91 +1,106 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
/*
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
///
|
*/
|
||||||
/// Created by Anonymous275 on 5/8/2020
|
|
||||||
///
|
|
||||||
#include "Zlib/Compressor.h"
|
|
||||||
#include "Network/network.hpp"
|
#include "Network/network.hpp"
|
||||||
|
#include "Zlib/Compressor.h"
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
|
#include "linuxfixes.h"
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <cstring>
|
||||||
|
#include <netdb.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <cstring>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include "linuxfixes.h"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include <array>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <set>
|
|
||||||
|
|
||||||
SOCKET UDPSock = -1;
|
SOCKET UDPSock = -1;
|
||||||
sockaddr_in* ToServer = nullptr;
|
sockaddr_in* ToServer = nullptr;
|
||||||
|
|
||||||
void UDPSend(std::string Data){
|
void UDPSend(std::string Data) {
|
||||||
if(ClientID == -1 || UDPSock == -1)return;
|
if (ClientID == -1 || UDPSock == -1)
|
||||||
if(Data.length() > 400){
|
return;
|
||||||
std::string CMP(Comp(Data));
|
if (Data.length() > 400) {
|
||||||
Data = "ABG:" + CMP;
|
auto res = Comp(std::span<char>(Data.data(), Data.size()));
|
||||||
|
Data = "ABG:" + std::string(res.data(), res.size());
|
||||||
}
|
}
|
||||||
std::string Packet = char(ClientID+1) + std::string(":") + Data;
|
std::string Packet = char(ClientID + 1) + std::string(":") + Data;
|
||||||
int sendOk = sendto(UDPSock, Packet.c_str(), int(Packet.size()), 0, (sockaddr*)ToServer, sizeof(*ToServer));
|
int sendOk = sendto(UDPSock, Packet.c_str(), int(Packet.size()), 0, (sockaddr*)ToServer, sizeof(*ToServer));
|
||||||
if (sendOk == SOCKET_ERROR)error("Error Code : " + std::to_string(WSAGetLastError()));
|
if (sendOk == SOCKET_ERROR)
|
||||||
|
error("Error Code : " + std::to_string(WSAGetLastError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SendLarge(std::string Data) {
|
||||||
void SendLarge(std::string Data){
|
if (Data.length() > 400) {
|
||||||
if(Data.length() > 400){
|
auto res = Comp(std::span<char>(Data.data(), Data.size()));
|
||||||
std::string CMP(Comp(Data));
|
Data = "ABG:" + std::string(res.data(), res.size());
|
||||||
Data = "ABG:" + CMP;
|
|
||||||
}
|
}
|
||||||
TCPSend(Data,TCPSock);
|
TCPSend(Data, TCPSock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDPParser(std::string Packet){
|
void UDPParser(std::string_view Packet) {
|
||||||
if(Packet.substr(0,4) == "ABG:"){
|
if (Packet.substr(0, 4) == "ABG:") {
|
||||||
Packet = DeComp(Packet.substr(4));
|
auto substr = Packet.substr(4);
|
||||||
|
try {
|
||||||
|
auto res = DeComp(std::span<const char>(substr.data(), substr.size()));
|
||||||
|
std::string DeCompPacket = std::string(res.data(), res.size());
|
||||||
|
ServerParser(DeCompPacket);
|
||||||
|
} catch (const std::runtime_error& err) {
|
||||||
|
error("Error in decompression of UDP, ignoring");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ServerParser(Packet);
|
||||||
}
|
}
|
||||||
ServerParser(Packet);
|
|
||||||
}
|
}
|
||||||
void UDPRcv(){
|
void UDPRcv() {
|
||||||
sockaddr_in FromServer{};
|
sockaddr_in FromServer {};
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
int clientLength = sizeof(FromServer);
|
int clientLength = sizeof(FromServer);
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
socklen_t clientLength = sizeof(FromServer);
|
socklen_t clientLength = sizeof(FromServer);
|
||||||
#endif
|
#endif
|
||||||
ZeroMemory(&FromServer, clientLength);
|
ZeroMemory(&FromServer, clientLength);
|
||||||
std::string Ret(10240,0);
|
static thread_local std::array<char, 10240> Ret {};
|
||||||
if(UDPSock == -1)return;
|
if (UDPSock == -1)
|
||||||
int32_t Rcv = recvfrom(UDPSock, &Ret[0], 10240, 0, (sockaddr*)&FromServer, &clientLength);
|
return;
|
||||||
if (Rcv == SOCKET_ERROR)return;
|
int32_t Rcv = recvfrom(UDPSock, Ret.data(), Ret.size() - 1, 0, (sockaddr*)&FromServer, &clientLength);
|
||||||
UDPParser(Ret.substr(0,Rcv));
|
if (Rcv == SOCKET_ERROR)
|
||||||
|
return;
|
||||||
|
Ret[Rcv] = 0;
|
||||||
|
UDPParser(std::string_view(Ret.data(), Rcv));
|
||||||
}
|
}
|
||||||
void UDPClientMain(const std::string& IP,int Port){
|
void UDPClientMain(const std::string& IP, int Port) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSADATA data;
|
WSADATA data;
|
||||||
if (WSAStartup(514, &data)){
|
if (WSAStartup(514, &data)) {
|
||||||
error("Can't start Winsock!");
|
error("Can't start Winsock!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
delete ToServer;
|
delete ToServer;
|
||||||
ToServer = new sockaddr_in;
|
ToServer = new sockaddr_in;
|
||||||
ToServer->sin_family = AF_INET;
|
ToServer->sin_family = AF_INET;
|
||||||
ToServer->sin_port = htons(Port);
|
ToServer->sin_port = htons(Port);
|
||||||
inet_pton(AF_INET, IP.c_str(), &ToServer->sin_addr);
|
inet_pton(AF_INET, IP.c_str(), &ToServer->sin_addr);
|
||||||
UDPSock = socket(AF_INET, SOCK_DGRAM, 0);
|
UDPSock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
GameSend("P"+std::to_string(ClientID));
|
GameSend("P" + std::to_string(ClientID));
|
||||||
TCPSend("H",TCPSock);
|
TCPSend("H", TCPSock);
|
||||||
UDPSend("p");
|
UDPSend("p");
|
||||||
while(!Terminate)UDPRcv();
|
debug("Starting UDP receive loop");
|
||||||
|
while (!Terminate) {
|
||||||
|
UDPRcv();
|
||||||
|
}
|
||||||
|
debug("UDP receive loop done");
|
||||||
KillSocket(UDPSock);
|
KillSocket(UDPSock);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
}
|
}
|
||||||
|
|||||||
171
src/Network/VehicleEvent.cpp
Executable file → Normal file
171
src/Network/VehicleEvent.cpp
Executable file → Normal file
@@ -1,26 +1,25 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
/*
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
///
|
*/
|
||||||
/// Created by Anonymous275 on 5/8/2020
|
|
||||||
///
|
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <vector>
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <iostream>
|
|
||||||
#include <Zlib/Compressor.h>
|
#include <Zlib/Compressor.h>
|
||||||
|
#include <chrono>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
#include <sys/socket.h>
|
#include <arpa/inet.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <arpa/inet.h>
|
#include <sys/socket.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Network/network.hpp"
|
#include "Network/network.hpp"
|
||||||
@@ -29,12 +28,12 @@ int LastPort;
|
|||||||
std::string LastIP;
|
std::string LastIP;
|
||||||
SOCKET TCPSock = -1;
|
SOCKET TCPSock = -1;
|
||||||
|
|
||||||
bool CheckBytes(int32_t Bytes){
|
bool CheckBytes(int32_t Bytes) {
|
||||||
if (Bytes == 0){
|
if (Bytes == 0) {
|
||||||
debug("(TCP) Connection closing... CheckBytes(16)");
|
debug("(TCP) Connection closing... CheckBytes(16)");
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
return false;
|
return false;
|
||||||
}else if (Bytes < 0) {
|
} else if (Bytes < 0) {
|
||||||
debug("(TCP CB) recv failed with error: " + std::to_string(WSAGetLastError()));
|
debug("(TCP CB) recv failed with error: " + std::to_string(WSAGetLastError()));
|
||||||
KillSocket(TCPSock);
|
KillSocket(TCPSock);
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
@@ -42,98 +41,102 @@ bool CheckBytes(int32_t Bytes){
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
void UUl(const std::string& R){
|
void UUl(const std::string& R) {
|
||||||
UlStatus = "UlDisconnected: " + R;
|
UlStatus = "UlDisconnected: " + R;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPSend(const std::string&Data,uint64_t Sock){
|
void TCPSend(const std::string& Data, uint64_t Sock) {
|
||||||
if(Sock == -1){
|
if (Sock == -1) {
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
UUl("Invalid Socket");
|
UUl("Invalid Socket");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t Size,Sent,Temp;
|
int32_t Size, Sent, Temp;
|
||||||
std::string Send(4,0);
|
std::string Send(4, 0);
|
||||||
Size = int32_t(Data.size());
|
Size = int32_t(Data.size());
|
||||||
memcpy(&Send[0],&Size,sizeof(Size));
|
memcpy(&Send[0], &Size, sizeof(Size));
|
||||||
Send += Data;
|
Send += Data;
|
||||||
// Do not use Size before this point for anything but the header
|
// Do not use Size before this point for anything but the header
|
||||||
Sent = 0;
|
Sent = 0;
|
||||||
Size += 4;
|
Size += 4;
|
||||||
do{
|
do {
|
||||||
if (size_t(Sent) >= Send.size()) {
|
if (size_t(Sent) >= Send.size()) {
|
||||||
error("string OOB in " + std::string(__func__));
|
error("string OOB in " + std::string(__func__));
|
||||||
UUl("TCP Send OOB");
|
UUl("TCP Send OOB");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Temp = send(Sock, &Send[Sent], Size - Sent, 0);
|
Temp = send(Sock, &Send[Sent], Size - Sent, 0);
|
||||||
if(!CheckBytes(Temp)){
|
if (!CheckBytes(Temp)) {
|
||||||
UUl("Socket Closed Code 2");
|
UUl("Socket Closed Code 2");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Sent += Temp;
|
Sent += Temp;
|
||||||
}while(Sent < Size);
|
} while (Sent < Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TCPRcv(SOCKET Sock){
|
std::string TCPRcv(SOCKET Sock) {
|
||||||
if(Sock == -1){
|
if (Sock == -1) {
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
UUl("Invalid Socket");
|
UUl("Invalid Socket");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
int32_t Header,BytesRcv = 0,Temp;
|
int32_t Header;
|
||||||
|
int Temp;
|
||||||
std::vector<char> Data(sizeof(Header));
|
std::vector<char> Data(sizeof(Header));
|
||||||
do{
|
Temp = recv(Sock, Data.data(), sizeof(Header), MSG_WAITALL);
|
||||||
Temp = recv(Sock,&Data[BytesRcv],4-BytesRcv,0);
|
if (!CheckBytes(Temp)) {
|
||||||
if(!CheckBytes(Temp)){
|
UUl("Socket Closed Code 3");
|
||||||
UUl("Socket Closed Code 3");
|
return "";
|
||||||
return "";
|
}
|
||||||
}
|
memcpy(&Header, Data.data(), sizeof(Header));
|
||||||
BytesRcv += Temp;
|
|
||||||
}while(BytesRcv < 4);
|
|
||||||
memcpy(&Header,&Data[0],sizeof(Header));
|
|
||||||
|
|
||||||
if(!CheckBytes(BytesRcv)){
|
if (!CheckBytes(Temp)) {
|
||||||
UUl("Socket Closed Code 4");
|
UUl("Socket Closed Code 4");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
Data.resize(Header);
|
|
||||||
BytesRcv = 0;
|
|
||||||
do{
|
|
||||||
Temp = recv(Sock,&Data[BytesRcv],Header-BytesRcv,0);
|
|
||||||
if(!CheckBytes(Temp)){
|
|
||||||
UUl("Socket Closed Code 5");
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
BytesRcv += Temp;
|
|
||||||
}while(BytesRcv < Header);
|
|
||||||
|
|
||||||
std::string Ret(Data.data(),Header);
|
Data.resize(Header, 0);
|
||||||
|
Temp = recv(Sock, Data.data(), Header, MSG_WAITALL);
|
||||||
|
if (!CheckBytes(Temp)) {
|
||||||
|
UUl("Socket Closed Code 5");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Ret(Data.data(), Header);
|
||||||
|
|
||||||
if (Ret.substr(0, 4) == "ABG:") {
|
if (Ret.substr(0, 4) == "ABG:") {
|
||||||
Ret = DeComp(Ret.substr(4));
|
auto substr = Ret.substr(4);
|
||||||
|
try {
|
||||||
|
auto res = DeComp(std::span<char>(substr.data(), substr.size()));
|
||||||
|
Ret = std::string(res.data(), res.size());
|
||||||
|
} catch (const std::runtime_error& err) {
|
||||||
|
// this happens e.g. when we're out of memory, or when we get incomplete data
|
||||||
|
error("Decompression failed");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
//debug("Parsing from server -> " + std::to_string(Ret.size()));
|
// debug("Parsing from server -> " + std::to_string(Ret.size()));
|
||||||
#endif
|
#endif
|
||||||
if(Ret[0] == 'E' || Ret[0] == 'K')UUl(Ret.substr(1));
|
if (Ret[0] == 'E' || Ret[0] == 'K')
|
||||||
|
UUl(Ret.substr(1));
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPClientMain(const std::string& IP,int Port){
|
void TCPClientMain(const std::string& IP, int Port) {
|
||||||
LastIP = IP;
|
LastIP = IP;
|
||||||
LastPort = Port;
|
LastPort = Port;
|
||||||
SOCKADDR_IN ServerAddr;
|
SOCKADDR_IN ServerAddr;
|
||||||
int RetCode;
|
int RetCode;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
WSAStartup(514, &wsaData); //2.2
|
WSAStartup(514, &wsaData); // 2.2
|
||||||
#endif
|
#endif
|
||||||
TCPSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
TCPSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
|
|
||||||
if(TCPSock == -1){
|
if (TCPSock == -1) {
|
||||||
printf("Client: socket failed! Error code: %d\n", WSAGetLastError());
|
printf("Client: socket failed! Error code: %d\n", WSAGetLastError());
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
return;
|
return;
|
||||||
@@ -142,13 +145,14 @@ void TCPClientMain(const std::string& IP,int Port){
|
|||||||
ServerAddr.sin_family = AF_INET;
|
ServerAddr.sin_family = AF_INET;
|
||||||
ServerAddr.sin_port = htons(Port);
|
ServerAddr.sin_port = htons(Port);
|
||||||
inet_pton(AF_INET, IP.c_str(), &ServerAddr.sin_addr);
|
inet_pton(AF_INET, IP.c_str(), &ServerAddr.sin_addr);
|
||||||
RetCode = connect(TCPSock, (SOCKADDR *) &ServerAddr, sizeof(ServerAddr));
|
RetCode = connect(TCPSock, (SOCKADDR*)&ServerAddr, sizeof(ServerAddr));
|
||||||
if(RetCode != 0){
|
if (RetCode != 0) {
|
||||||
UlStatus = "UlConnection Failed!";
|
UlStatus = "UlConnection Failed!";
|
||||||
error("Client: connect failed! Error code: " + std::to_string(WSAGetLastError()));
|
error("Client: connect failed! Error code: " + std::to_string(WSAGetLastError()));
|
||||||
KillSocket(TCPSock);
|
KillSocket(TCPSock);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
|
CoreSend("L");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
info("Connected!");
|
info("Connected!");
|
||||||
@@ -156,17 +160,16 @@ void TCPClientMain(const std::string& IP,int Port){
|
|||||||
char Code = 'C';
|
char Code = 'C';
|
||||||
send(TCPSock, &Code, 1, 0);
|
send(TCPSock, &Code, 1, 0);
|
||||||
SyncResources(TCPSock);
|
SyncResources(TCPSock);
|
||||||
while(!Terminate){
|
while (!Terminate) {
|
||||||
ServerParser(TCPRcv(TCPSock));
|
ServerParser(TCPRcv(TCPSock));
|
||||||
}
|
}
|
||||||
GameSend("T");
|
GameSend("T");
|
||||||
////Game Send Terminate
|
////Game Send Terminate
|
||||||
if(KillSocket(TCPSock) != 0)
|
if (KillSocket(TCPSock) != 0)
|
||||||
debug("(TCP) Cannot close socket. Error code: " + std::to_string(WSAGetLastError()));
|
debug("(TCP) Cannot close socket. Error code: " + std::to_string(WSAGetLastError()));
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if(WSACleanup() != 0)
|
if (WSACleanup() != 0)
|
||||||
debug("(TCP) Client: WSACleanup() failed!...");
|
debug("(TCP) Client: WSACleanup() failed!...");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
120
src/Options.cpp
Normal file
120
src/Options.cpp
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Options.h"
|
||||||
|
|
||||||
|
#include "Logger.h"
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
void InitOptions(int argc, const char *argv[], Options &options) {
|
||||||
|
int i = 1;
|
||||||
|
|
||||||
|
options.argc = argc;
|
||||||
|
options.argv = argv;
|
||||||
|
|
||||||
|
std::string AllOptions;
|
||||||
|
for (int i = 0; i < argc; ++i) {
|
||||||
|
AllOptions += std::string(argv[i]);
|
||||||
|
if (i + 1 < argc) {
|
||||||
|
AllOptions += " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
debug("Launcher was invoked as: '" + AllOptions + "'");
|
||||||
|
|
||||||
|
|
||||||
|
if (argc > 2) {
|
||||||
|
if (std::string(argv[1]) == "0" && std::string(argv[2]) == "0") {
|
||||||
|
options.verbose = true;
|
||||||
|
options.no_download = true;
|
||||||
|
options.no_launch = true;
|
||||||
|
options.no_update = true;
|
||||||
|
warn("You are using deprecated commandline arguments, please use --dev instead");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
options.executable_name = std::string(argv[0]);
|
||||||
|
|
||||||
|
while (i < argc) {
|
||||||
|
std::string argument(argv[i]);
|
||||||
|
if (argument == "-p" || argument == "--port") {
|
||||||
|
if (i + 1 >= argc) {
|
||||||
|
std::string error_message =
|
||||||
|
"No port specified, resorting to default (";
|
||||||
|
error_message += std::to_string(options.port);
|
||||||
|
error_message += ")";
|
||||||
|
error(error_message);
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int port = options.port;
|
||||||
|
|
||||||
|
try {
|
||||||
|
port = std::stoi(argv[i + 1]);
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
error("Invalid port specified: " + std::string(argv[i + 1]) + " " + std::string(e.what()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (port <= 0) {
|
||||||
|
std::string error_message =
|
||||||
|
"Port invalid, must be a non-zero positive "
|
||||||
|
"integer, resorting to default (";
|
||||||
|
error_message += options.port;
|
||||||
|
error_message += ")";
|
||||||
|
error(error_message);
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
options.port = port;
|
||||||
|
i++;
|
||||||
|
} else if (argument == "-v" || argument == "--verbose") {
|
||||||
|
options.verbose = true;
|
||||||
|
} else if (argument == "--no-download") {
|
||||||
|
options.no_download = true;
|
||||||
|
} else if (argument == "--no-update") {
|
||||||
|
options.no_update = true;
|
||||||
|
} else if (argument == "--no-launch") {
|
||||||
|
options.no_launch = true;
|
||||||
|
} else if (argument == "--dev") {
|
||||||
|
options.verbose = true;
|
||||||
|
options.no_download = true;
|
||||||
|
options.no_launch = true;
|
||||||
|
options.no_update = true;
|
||||||
|
} else if (argument == "--user-path") {
|
||||||
|
if (i + 1 >= argc) {
|
||||||
|
error("You must specify a path after the `--user-path` argument");
|
||||||
|
}
|
||||||
|
options.user_path = argv[i + 1];
|
||||||
|
i++;
|
||||||
|
} else if (argument == "--" || argument == "--game") {
|
||||||
|
options.game_arguments = &argv[i + 1];
|
||||||
|
options.game_arguments_length = argc - i - 1;
|
||||||
|
break;
|
||||||
|
} else if (argument == "--help" || argument == "-h" || argument == "/?") {
|
||||||
|
std::cout << "USAGE:\n"
|
||||||
|
"\t" + std::filesystem::path(options.executable_name).filename().string() + " [OPTIONS] [-- <GAME ARGS>...]\n"
|
||||||
|
"\n"
|
||||||
|
"OPTIONS:\n"
|
||||||
|
"\t--port <port> -p Change the default listen port to <port>. This must be configured ingame, too\n"
|
||||||
|
"\t--verbose -v Verbose mode, prints debug messages\n"
|
||||||
|
"\t--no-download Skip downloading and installing the BeamMP Lua mod\n"
|
||||||
|
"\t--no-update Skip applying launcher updates (you must update manually)\n"
|
||||||
|
"\t--no-launch Skip launching the game (you must launch the game manually)\n"
|
||||||
|
"\t--dev Developer mode, same as --verbose --no-download --no-launch --no-update\n"
|
||||||
|
"\t--user-path <path> Path to BeamNG's User Path\n"
|
||||||
|
"\t--game <args...> Passes ALL following arguments to the game, see also `--`\n"
|
||||||
|
<< std::flush;
|
||||||
|
exit(0);
|
||||||
|
} else {
|
||||||
|
warn("Unknown option: " + argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
428
src/Security/BeamNG.cpp
Executable file → Normal file
428
src/Security/BeamNG.cpp
Executable file → Normal file
@@ -1,23 +1,22 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
/*
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
///
|
*/
|
||||||
/// Created by Anonymous275 on 7/18/2020
|
|
||||||
///
|
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <windows.h>
|
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
#include "vdf_parser.hpp"
|
#include "vdf_parser.hpp"
|
||||||
#include <vector>
|
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <vector>
|
||||||
#endif
|
#endif
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
@@ -25,327 +24,228 @@
|
|||||||
#define MAX_VALUE_NAME 16383
|
#define MAX_VALUE_NAME 16383
|
||||||
|
|
||||||
int TraceBack = 0;
|
int TraceBack = 0;
|
||||||
std::string GameDir;
|
beammp_fs_string GameDir;
|
||||||
|
|
||||||
void lowExit(int code){
|
void lowExit(int code) {
|
||||||
TraceBack = 0;
|
TraceBack = 0;
|
||||||
std::string msg =
|
std::string msg = "Failed to find the game please launch it. Report this if the issue persists code ";
|
||||||
"Failed to find the game please launch it. Report this if the issue persists code ";
|
error(msg + std::to_string(code));
|
||||||
error(msg+std::to_string(code));
|
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
/*void Exit(int code){
|
|
||||||
TraceBack = 0;
|
beammp_fs_string GetGameDir() {
|
||||||
std::string msg =
|
#if defined(_WIN32)
|
||||||
"Sorry. We do not support cracked copies report this if you believe this is a mistake code ";
|
return GameDir.substr(0, GameDir.find_last_of('\\'));
|
||||||
error(msg+std::to_string(code));
|
#elif defined(__linux__)
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
return GameDir.substr(0, GameDir.find_last_of('/'));
|
||||||
exit(3);
|
#endif
|
||||||
}
|
|
||||||
void SteamExit(int code){
|
|
||||||
TraceBack = 0;
|
|
||||||
std::string msg =
|
|
||||||
"Illegal steam modifications detected report this if you believe this is a mistake code ";
|
|
||||||
error(msg+std::to_string(code));
|
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
|
||||||
exit(4);
|
|
||||||
}*/
|
|
||||||
std::string GetGameDir(){
|
|
||||||
//if(TraceBack != 4)Exit(0);
|
|
||||||
#if defined(_WIN32)
|
|
||||||
return GameDir.substr(0,GameDir.find_last_of('\\'));
|
|
||||||
#elif defined(__linux__)
|
|
||||||
return GameDir.substr(0,GameDir.find_last_of('/'));
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
LONG OpenKey(HKEY root,const char* path,PHKEY hKey){
|
LONG OpenKey(HKEY root, const char* path, PHKEY hKey) {
|
||||||
return RegOpenKeyEx(root, reinterpret_cast<LPCSTR>(path), 0, KEY_READ, hKey);
|
return RegOpenKeyEx(root, reinterpret_cast<LPCSTR>(path), 0, KEY_READ, hKey);
|
||||||
}
|
}
|
||||||
std::string QueryKey(HKEY hKey,int ID){
|
std::wstring QueryKey(HKEY hKey, int ID) {
|
||||||
TCHAR achKey[MAX_KEY_LENGTH]; // buffer for subkey name
|
wchar_t* achKey; // buffer for subkey name
|
||||||
DWORD cbName; // size of name string
|
DWORD cbName; // size of name string
|
||||||
TCHAR achClass[MAX_PATH] = TEXT(""); // buffer for class name
|
TCHAR achClass[MAX_PATH] = TEXT(""); // buffer for class name
|
||||||
DWORD cchClassName = MAX_PATH; // size of class string
|
DWORD cchClassName = MAX_PATH; // size of class string
|
||||||
DWORD cSubKeys=0; // number of subkeys
|
DWORD cSubKeys = 0; // number of subkeys
|
||||||
DWORD cbMaxSubKey; // longest subkey size
|
DWORD cbMaxSubKey; // longest subkey size
|
||||||
DWORD cchMaxClass; // longest class string
|
DWORD cchMaxClass; // longest class string
|
||||||
DWORD cValues; // number of values for key
|
DWORD cValues; // number of values for key
|
||||||
DWORD cchMaxValue; // longest value name
|
DWORD cchMaxValue; // longest value name
|
||||||
DWORD cbMaxValueData; // longest value data
|
DWORD cbMaxValueData; // longest value data
|
||||||
DWORD cbSecurityDescriptor; // size of security descriptor
|
DWORD cbSecurityDescriptor; // size of security descriptor
|
||||||
FILETIME ftLastWriteTime; // last write time
|
FILETIME ftLastWriteTime; // last write time
|
||||||
|
|
||||||
DWORD i, retCode;
|
DWORD i, retCode;
|
||||||
|
|
||||||
TCHAR achValue[MAX_VALUE_NAME];
|
wchar_t* achValue = new wchar_t[MAX_VALUE_NAME];
|
||||||
DWORD cchValue = MAX_VALUE_NAME;
|
DWORD cchValue = MAX_VALUE_NAME;
|
||||||
|
|
||||||
retCode = RegQueryInfoKey(
|
retCode = RegQueryInfoKey(
|
||||||
hKey, // key handle
|
hKey, // key handle
|
||||||
achClass, // buffer for class name
|
achClass, // buffer for class name
|
||||||
&cchClassName, // size of class string
|
&cchClassName, // size of class string
|
||||||
nullptr, // reserved
|
nullptr, // reserved
|
||||||
&cSubKeys, // number of subkeys
|
&cSubKeys, // number of subkeys
|
||||||
&cbMaxSubKey, // longest subkey size
|
&cbMaxSubKey, // longest subkey size
|
||||||
&cchMaxClass, // longest class string
|
&cchMaxClass, // longest class string
|
||||||
&cValues, // number of values for this key
|
&cValues, // number of values for this key
|
||||||
&cchMaxValue, // longest value name
|
&cchMaxValue, // longest value name
|
||||||
&cbMaxValueData, // longest value data
|
&cbMaxValueData, // longest value data
|
||||||
&cbSecurityDescriptor, // security descriptor
|
&cbSecurityDescriptor, // security descriptor
|
||||||
&ftLastWriteTime); // last write time
|
&ftLastWriteTime); // last write time
|
||||||
|
|
||||||
BYTE* buffer = new BYTE[cbMaxValueData];
|
BYTE* buffer = new BYTE[cbMaxValueData];
|
||||||
ZeroMemory(buffer, cbMaxValueData);
|
ZeroMemory(buffer, cbMaxValueData);
|
||||||
if (cSubKeys){
|
if (cSubKeys) {
|
||||||
for (i=0; i<cSubKeys; i++){
|
for (i = 0; i < cSubKeys; i++) {
|
||||||
cbName = MAX_KEY_LENGTH;
|
cbName = MAX_KEY_LENGTH;
|
||||||
retCode = RegEnumKeyEx(hKey, i,achKey,&cbName,nullptr,nullptr,nullptr,&ftLastWriteTime);
|
retCode = RegEnumKeyExW(hKey, i, achKey, &cbName, nullptr, nullptr, nullptr, &ftLastWriteTime);
|
||||||
if (retCode == ERROR_SUCCESS){
|
if (retCode == ERROR_SUCCESS) {
|
||||||
if(strcmp(achKey,"Steam App 284160") == 0){
|
if (wcscmp(achKey, L"Steam App 284160") == 0) {
|
||||||
return achKey;
|
return achKey;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cValues){
|
if (cValues) {
|
||||||
for (i=0, retCode = ERROR_SUCCESS; i<cValues; i++){
|
for (i = 0, retCode = ERROR_SUCCESS; i < cValues; i++) {
|
||||||
cchValue = MAX_VALUE_NAME;
|
cchValue = MAX_VALUE_NAME;
|
||||||
achValue[0] = '\0';
|
achValue[0] = '\0';
|
||||||
retCode = RegEnumValue(hKey, i,achValue,&cchValue,nullptr,nullptr,nullptr,nullptr);
|
retCode = RegEnumValueW(hKey, i, achValue, &cchValue, nullptr, nullptr, nullptr, nullptr);
|
||||||
if (retCode == ERROR_SUCCESS ){
|
if (retCode == ERROR_SUCCESS) {
|
||||||
DWORD lpData = cbMaxValueData;
|
DWORD lpData = cbMaxValueData;
|
||||||
buffer[0] = '\0';
|
buffer[0] = '\0';
|
||||||
LONG dwRes = RegQueryValueEx(hKey, achValue, nullptr, nullptr, buffer, &lpData);
|
LONG dwRes = RegQueryValueExW(hKey, achValue, nullptr, nullptr, buffer, &lpData);
|
||||||
std::string data = (char *)(buffer);
|
std::wstring data = (wchar_t*)(buffer);
|
||||||
std::string key = achValue;
|
std::wstring key = achValue;
|
||||||
|
|
||||||
switch (ID){
|
|
||||||
case 1: if(key == "SteamExe"){
|
switch (ID) {
|
||||||
auto p = data.find_last_of("/\\");
|
case 1:
|
||||||
if(p != std::string::npos){
|
if (key == L"SteamExe") {
|
||||||
return data.substr(0,p);
|
auto p = data.find_last_of(L"/\\");
|
||||||
}
|
if (p != std::string::npos) {
|
||||||
}
|
return data.substr(0, p);
|
||||||
break;
|
}
|
||||||
case 2: if(key == "Name" && data == "BeamNG.drive")return data;break;
|
}
|
||||||
case 3: if(key == "rootpath")return data;break;
|
break;
|
||||||
case 4: if(key == "userpath_override")return data;
|
case 2:
|
||||||
case 5: if(key == "Local AppData")return data;
|
if (key == L"Name" && data == L"BeamNG.drive")
|
||||||
default: break;
|
return data;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
if (key == L"rootpath")
|
||||||
|
return data;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
if (key == L"userpath_override")
|
||||||
|
return data;
|
||||||
|
case 5:
|
||||||
|
if (key == L"Local AppData")
|
||||||
|
return data;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete [] buffer;
|
delete[] achValue;
|
||||||
return "";
|
delete[] buffer;
|
||||||
|
return L"";
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
bool NameValid(const std::string& N){
|
bool NameValid(const std::string& N) {
|
||||||
if(N == "config" || N == "librarycache"){
|
if (N == "config" || N == "librarycache") {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(N.find_first_not_of("0123456789") == std::string::npos){
|
if (N.find_first_not_of("0123456789") == std::string::npos) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
void FileList(std::vector<std::string>&a,const std::string& Path){
|
void FileList(std::vector<std::string>& a, const std::string& Path) {
|
||||||
for (const auto &entry : fs::directory_iterator(Path)) {
|
for (const auto& entry : fs::directory_iterator(Path)) {
|
||||||
const auto& DPath = entry.path();
|
const auto& DPath = entry.path();
|
||||||
if (!entry.is_directory()) {
|
if (!entry.is_directory()) {
|
||||||
a.emplace_back(DPath.u8string());
|
a.emplace_back(DPath.string());
|
||||||
}else if(NameValid(DPath.filename().u8string())){
|
} else if (NameValid(DPath.filename().string())) {
|
||||||
FileList(a, DPath.u8string());
|
FileList(a, DPath.string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool Find(const std::string& FName,const std::string& Path){
|
void LegitimacyCheck() {
|
||||||
std::vector<std::string> FS;
|
#if defined(_WIN32)
|
||||||
FileList(FS,Path+"\\userdata");
|
std::wstring Result;
|
||||||
for(std::string&a : FS){
|
|
||||||
if(a.find(FName) != std::string::npos){
|
|
||||||
FS.clear();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
FS.clear();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bool FindHack(const std::string& Path){
|
|
||||||
bool s = true;
|
|
||||||
for (const auto &entry : fs::directory_iterator(Path)) {
|
|
||||||
std::string Name = entry.path().filename().u8string();
|
|
||||||
for(char&c : Name)c = char(tolower(c));
|
|
||||||
if(Name == "steam.exe")s = false;
|
|
||||||
if(Name.find("greenluma") != -1){
|
|
||||||
error("Found malicious file/folder \"" + Name+"\"");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Name.clear();
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
std::vector<std::string> GetID(const std::string& log){
|
|
||||||
std::string vec,t,r;
|
|
||||||
std::vector<std::string> Ret;
|
|
||||||
std::ifstream f(log.c_str(), std::ios::binary);
|
|
||||||
f.seekg(0, std::ios_base::end);
|
|
||||||
std::streampos fileSize = f.tellg();
|
|
||||||
vec.resize(size_t(fileSize) + 1);
|
|
||||||
f.seekg(0, std::ios_base::beg);
|
|
||||||
f.read(&vec[0], fileSize);
|
|
||||||
f.close();
|
|
||||||
std::stringstream ss(vec);
|
|
||||||
bool S = false;
|
|
||||||
while (std::getline(ss, t, '{')) {
|
|
||||||
if(!S)S = true;
|
|
||||||
else{
|
|
||||||
for(char& c : t){
|
|
||||||
if(isdigit(c))r += c;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ret.emplace_back(r);
|
|
||||||
r.clear();
|
|
||||||
S = false;
|
|
||||||
bool L = true;
|
|
||||||
while (std::getline(ss, t, '}')) {
|
|
||||||
if(L){
|
|
||||||
L = false;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for(char& c : t){
|
|
||||||
if(c == '"'){
|
|
||||||
if(!S)S = true;
|
|
||||||
else{
|
|
||||||
if(r.length() > 10) {
|
|
||||||
Ret.emplace_back(r);
|
|
||||||
}
|
|
||||||
r.clear();
|
|
||||||
S = false;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(isdigit(c))r += c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
vec.clear();
|
|
||||||
return Ret;
|
|
||||||
}
|
|
||||||
std::string GetManifest(const std::string& Man){
|
|
||||||
std::string vec;
|
|
||||||
std::ifstream f(Man.c_str(), std::ios::binary);
|
|
||||||
f.seekg(0, std::ios_base::end);
|
|
||||||
std::streampos fileSize = f.tellg();
|
|
||||||
vec.resize(size_t(fileSize) + 1);
|
|
||||||
f.seekg(0, std::ios_base::beg);
|
|
||||||
f.read(&vec[0], fileSize);
|
|
||||||
f.close();
|
|
||||||
std::string ToFind = "\"LastOwner\"\t\t\"";
|
|
||||||
int pos = int(vec.find(ToFind));
|
|
||||||
if(pos != -1){
|
|
||||||
pos += int(ToFind.length());
|
|
||||||
vec = vec.substr(pos);
|
|
||||||
return vec.substr(0,vec.find('\"'));
|
|
||||||
}else return "";
|
|
||||||
}
|
|
||||||
bool IDCheck(std::string Man, std::string steam){
|
|
||||||
bool a = false,b = true;
|
|
||||||
int pos = int(Man.rfind("steamapps"));
|
|
||||||
// if(pos == -1)Exit(5);
|
|
||||||
Man = Man.substr(0,pos+9) + "\\appmanifest_284160.acf";
|
|
||||||
steam += "\\config\\loginusers.vdf";
|
|
||||||
if(fs::exists(Man) && fs::exists(steam)){
|
|
||||||
for(const std::string&ID : GetID(steam)){
|
|
||||||
if(ID == GetManifest(Man))b = false;
|
|
||||||
}
|
|
||||||
//if(b)Exit(6);
|
|
||||||
}else a = true;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
void LegitimacyCheck(){
|
|
||||||
|
|
||||||
//std::string K1 = R"(Software\Valve\Steam)";
|
|
||||||
//std::string K2 = R"(Software\Valve\Steam\Apps\284160)";
|
|
||||||
|
|
||||||
/*LONG dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K1.c_str(), &hKey);
|
|
||||||
|
|
||||||
if(dwRegOPenKey == ERROR_SUCCESS) {
|
|
||||||
Result = QueryKey(hKey, 1);
|
|
||||||
if(Result.empty())Exit(1);
|
|
||||||
|
|
||||||
if(fs::exists(Result)){
|
|
||||||
if(!Find("284160.json",Result))Exit(2);
|
|
||||||
if(FindHack(Result))SteamExit(1);
|
|
||||||
}else Exit(3);
|
|
||||||
|
|
||||||
T = Result;
|
|
||||||
Result.clear();
|
|
||||||
TraceBack++;
|
|
||||||
}else Exit(4);
|
|
||||||
|
|
||||||
K1.clear();
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K2.c_str(), &hKey);
|
|
||||||
if(dwRegOPenKey == ERROR_SUCCESS) {
|
|
||||||
Result = QueryKey(hKey, 2);
|
|
||||||
if(Result.empty())lowExit(1);
|
|
||||||
TraceBack++;
|
|
||||||
}else lowExit(2);
|
|
||||||
K2.clear();
|
|
||||||
RegCloseKey(hKey);*/
|
|
||||||
#if defined(_WIN32)
|
|
||||||
std::string Result;
|
|
||||||
std::string K3 = R"(Software\BeamNG\BeamNG.drive)";
|
std::string K3 = R"(Software\BeamNG\BeamNG.drive)";
|
||||||
HKEY hKey;
|
HKEY hKey;
|
||||||
LONG dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K3.c_str(), &hKey);
|
LONG dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K3.c_str(), &hKey);
|
||||||
if(dwRegOPenKey == ERROR_SUCCESS) {
|
if (dwRegOPenKey == ERROR_SUCCESS) {
|
||||||
Result = QueryKey(hKey, 3);
|
Result = QueryKey(hKey, 3);
|
||||||
if(Result.empty())lowExit(3);
|
if (Result.empty()) {
|
||||||
//if(IDCheck(Result,T))lowExit(5);
|
debug("Failed to QUERY key HKEY_CURRENT_USER\\Software\\BeamNG\\BeamNG.drive");
|
||||||
|
lowExit(3);
|
||||||
|
}
|
||||||
GameDir = Result;
|
GameDir = Result;
|
||||||
//TraceBack++;
|
} else {
|
||||||
}else lowExit(4);
|
debug("Failed to OPEN key HKEY_CURRENT_USER\\Software\\BeamNG\\BeamNG.drive");
|
||||||
|
lowExit(4);
|
||||||
|
}
|
||||||
K3.clear();
|
K3.clear();
|
||||||
Result.clear();
|
Result.clear();
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
//if(TraceBack < 3)exit(-1);
|
#elif defined(__linux__)
|
||||||
#elif defined(__linux__)
|
struct passwd* pw = getpwuid(getuid());
|
||||||
struct passwd *pw = getpwuid(getuid());
|
std::filesystem::path homeDir = pw->pw_dir;
|
||||||
std::string homeDir = pw->pw_dir;
|
|
||||||
// Right now only steam is supported
|
|
||||||
std::ifstream libraryFolders(homeDir + "/.steam/root/steamapps/libraryfolders.vdf");
|
|
||||||
auto root = tyti::vdf::read(libraryFolders);
|
|
||||||
|
|
||||||
for (auto folderInfo: root.childs){
|
// Right now only steam is supported
|
||||||
if (std::filesystem::exists(folderInfo.second->attribs["path"] + "/steamapps/common/BeamNG.drive/")){
|
std::vector<std::filesystem::path> steamappsCommonPaths = {
|
||||||
|
".steam/root/steamapps", // default
|
||||||
|
".steam/steam/steamapps", // Legacy Steam installations
|
||||||
|
".var/app/com.valvesoftware.Steam/.steam/root/steamapps", // flatpak
|
||||||
|
"snap/steam/common/.local/share/Steam/steamapps" // snap
|
||||||
|
};
|
||||||
|
|
||||||
|
std::filesystem::path steamappsPath;
|
||||||
|
std::filesystem::path libraryFoldersPath;
|
||||||
|
bool steamappsFolderFound = false;
|
||||||
|
bool libraryFoldersFound = false;
|
||||||
|
|
||||||
|
for (const auto& path : steamappsCommonPaths) {
|
||||||
|
steamappsPath = homeDir / path;
|
||||||
|
if (std::filesystem::exists(steamappsPath)) {
|
||||||
|
steamappsFolderFound = true;
|
||||||
|
libraryFoldersPath = steamappsPath / "libraryfolders.vdf";
|
||||||
|
if (std::filesystem::exists(libraryFoldersPath)) {
|
||||||
|
libraryFoldersPath = libraryFoldersPath;
|
||||||
|
libraryFoldersFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!steamappsFolderFound) {
|
||||||
|
error("Unsupported Steam installation.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!libraryFoldersFound) {
|
||||||
|
error("libraryfolders.vdf is missing.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ifstream libraryFolders(libraryFoldersPath);
|
||||||
|
auto root = tyti::vdf::read(libraryFolders);
|
||||||
|
for (auto folderInfo : root.childs) {
|
||||||
|
if (std::filesystem::exists(folderInfo.second->attribs["path"] + "/steamapps/common/BeamNG.drive/integrity.json")){
|
||||||
GameDir = folderInfo.second->attribs["path"] + "/steamapps/common/BeamNG.drive/";
|
GameDir = folderInfo.second->attribs["path"] + "/steamapps/common/BeamNG.drive/";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
if (GameDir.empty()) {
|
||||||
|
error("The game directory was not found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
std::string CheckVer(const std::string &dir){
|
std::string CheckVer(const std::filesystem::path& dir) {
|
||||||
#if defined(_WIN32)
|
std::string temp;
|
||||||
std::string temp,Path = dir + "\\integrity.json";
|
std::filesystem::path Path = dir / beammp_wide("integrity.json");
|
||||||
#elif defined(__linux__)
|
|
||||||
std::string temp,Path = dir + "/integrity.json";
|
|
||||||
#endif
|
|
||||||
std::ifstream f(Path.c_str(), std::ios::binary);
|
std::ifstream f(Path.c_str(), std::ios::binary);
|
||||||
int Size = int(std::filesystem::file_size(Path));
|
int Size = int(std::filesystem::file_size(Path));
|
||||||
std::string vec(Size,0);
|
std::string vec(Size, 0);
|
||||||
f.read(&vec[0], Size);
|
f.read(&vec[0], Size);
|
||||||
f.close();
|
f.close();
|
||||||
|
|
||||||
vec = vec.substr(vec.find_last_of("version"),vec.find_last_of('"'));
|
vec = vec.substr(vec.find_last_of("version"), vec.find_last_of('"'));
|
||||||
for(const char &a : vec){
|
for (const char& a : vec) {
|
||||||
if(isdigit(a) || a == '.')temp+=a;
|
if (isdigit(a) || a == '.')
|
||||||
|
temp += a;
|
||||||
}
|
}
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
272
src/Security/Login.cpp
Executable file → Normal file
272
src/Security/Login.cpp
Executable file → Normal file
@@ -1,122 +1,150 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
/*
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
///
|
*/
|
||||||
/// Created by Anonymous275 on 11/26/2020
|
|
||||||
///
|
|
||||||
|
#include "Http.h"
|
||||||
#include "Http.h"
|
#include "Logger.h"
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include "Logger.h"
|
#include <fstream>
|
||||||
#include <fstream>
|
#include <nlohmann/json.hpp>
|
||||||
#include "Json.h"
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
namespace fs = std::filesystem;
|
std::string PublicKey;
|
||||||
std::string PublicKey;
|
std::string PrivateKey;
|
||||||
extern bool LoginAuth;
|
extern bool LoginAuth;
|
||||||
std::string Role;
|
extern std::string Username;
|
||||||
|
extern std::string UserRole;
|
||||||
void UpdateKey(const char* newKey){
|
extern int UserID;
|
||||||
if(newKey && std::isalnum(newKey[0])){
|
|
||||||
std::ofstream Key("key");
|
void UpdateKey(const char* newKey) {
|
||||||
if(Key.is_open()){
|
if (newKey && std::isalnum(newKey[0])) {
|
||||||
Key << newKey;
|
PrivateKey = newKey;
|
||||||
Key.close();
|
std::ofstream Key("key");
|
||||||
}else fatal("Cannot write to disk!");
|
if (Key.is_open()) {
|
||||||
}else if(fs::exists("key")){
|
Key << newKey;
|
||||||
remove("key");
|
Key.close();
|
||||||
}
|
} else
|
||||||
}
|
fatal("Cannot write to disk!");
|
||||||
|
} else if (fs::exists("key")) {
|
||||||
/// "username":"value","password":"value"
|
remove("key");
|
||||||
/// "Guest":"Name"
|
}
|
||||||
/// "pk":"private_key"
|
}
|
||||||
|
|
||||||
std::string GetFail(const std::string& R){
|
/// "username":"value","password":"value"
|
||||||
std::string DRet = R"({"success":false,"message":)";
|
/// "Guest":"Name"
|
||||||
DRet += "\""+R+"\"}";
|
/// "pk":"private_key"
|
||||||
error(R);
|
|
||||||
return DRet;
|
std::string GetFail(const std::string& R) {
|
||||||
}
|
std::string DRet = R"({"success":false,"message":)";
|
||||||
|
DRet += "\"" + R + "\"}";
|
||||||
std::string Login(const std::string& fields){
|
error(R);
|
||||||
if(fields == "LO"){
|
return DRet;
|
||||||
LoginAuth = false;
|
}
|
||||||
UpdateKey(nullptr);
|
|
||||||
return "";
|
std::string Login(const std::string& fields) {
|
||||||
}
|
if (fields == "LO") {
|
||||||
info("Attempting to authenticate...");
|
Username = "";
|
||||||
std::string Buffer = HTTP::Post("https://auth.beammp.com/userlogin", fields);
|
UserRole = "";
|
||||||
json::Document d;
|
UserID = -1;
|
||||||
d.Parse(Buffer.c_str());
|
LoginAuth = false;
|
||||||
if(Buffer == "-1"){
|
UpdateKey(nullptr);
|
||||||
return GetFail("Failed to communicate with the auth system!");
|
return "";
|
||||||
}
|
}
|
||||||
|
info("Attempting to authenticate...");
|
||||||
if (Buffer.at(0) != '{' || d.HasParseError()) {
|
try {
|
||||||
error(Buffer);
|
std::string Buffer = HTTP::Post("https://auth.beammp.com/userlogin", fields);
|
||||||
return GetFail("Invalid answer from authentication servers, please try again later!");
|
|
||||||
}
|
if (Buffer.empty()) {
|
||||||
if(d.HasMember("success") && !d["success"].IsNull() && d["success"].GetBool()){
|
return GetFail("Failed to communicate with the auth system!");
|
||||||
LoginAuth = true;
|
}
|
||||||
if(d.HasMember("private_key") && !d["private_key"].IsNull()){
|
|
||||||
UpdateKey(d["private_key"].GetString());
|
nlohmann::json d = nlohmann::json::parse(Buffer, nullptr, false);
|
||||||
}
|
|
||||||
if(d.HasMember("public_key") && !d["public_key"].IsNull()){
|
if (Buffer.at(0) != '{' || d.is_discarded()) {
|
||||||
PublicKey = d["public_key"].GetString();
|
error(Buffer);
|
||||||
}
|
return GetFail("Invalid answer from authentication servers, please try again later!");
|
||||||
info("Authentication successful!");
|
}
|
||||||
}else info("Authentication failed!");
|
if (d.contains("success") && d["success"].get<bool>()) {
|
||||||
if(d.HasMember("message") && !d["message"].IsNull()){
|
LoginAuth = true;
|
||||||
d.RemoveMember("private_key");
|
if (d.contains("username")) {
|
||||||
d.RemoveMember("public_key");
|
Username = d["username"].get<std::string>();
|
||||||
rapidjson::StringBuffer buffer;
|
}
|
||||||
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
if (d.contains("role")) {
|
||||||
d.Accept(writer);
|
UserRole = d["role"].get<std::string>();
|
||||||
return buffer.GetString();
|
}
|
||||||
}
|
if (d.contains("id")) {
|
||||||
return GetFail("Invalid message parsing!");
|
UserID = d["id"].get<int>();
|
||||||
}
|
}
|
||||||
|
if (d.contains("private_key")) {
|
||||||
void CheckLocalKey(){
|
UpdateKey(d["private_key"].get<std::string>().c_str());
|
||||||
if(fs::exists("key") && fs::file_size("key") < 100){
|
}
|
||||||
std::ifstream Key("key");
|
if (d.contains("public_key")) {
|
||||||
if(Key.is_open()) {
|
PublicKey = d["public_key"].get<std::string>();
|
||||||
auto Size = fs::file_size("key");
|
}
|
||||||
std::string Buffer(Size, 0);
|
info("Authentication successful!");
|
||||||
Key.read(&Buffer[0], Size);
|
} else
|
||||||
Key.close();
|
info("Authentication failed!");
|
||||||
|
if (d.contains("message")) {
|
||||||
for (char& c : Buffer) {
|
d.erase("private_key");
|
||||||
if (!std::isalnum(c) && c != '-') {
|
d.erase("public_key");
|
||||||
UpdateKey(nullptr);
|
debug("Authentication result: " + d["message"].get<std::string>());
|
||||||
return;
|
return d.dump();
|
||||||
}
|
}
|
||||||
}
|
return GetFail("Invalid message parsing!");
|
||||||
|
} catch (const std::exception& e) {
|
||||||
Buffer = HTTP::Post("https://auth.beammp.com/userlogin", R"({"pk":")" + Buffer + "\"}");
|
return GetFail(e.what());
|
||||||
|
}
|
||||||
json::Document d;
|
}
|
||||||
d.Parse(Buffer.c_str());
|
|
||||||
if (Buffer == "-1" || Buffer.at(0) != '{' || d.HasParseError()) {
|
void CheckLocalKey() {
|
||||||
error(Buffer);
|
if (fs::exists("key") && fs::file_size("key") < 100) {
|
||||||
info("Invalid answer from authentication servers.");
|
std::ifstream Key("key");
|
||||||
UpdateKey(nullptr);
|
if (Key.is_open()) {
|
||||||
}
|
auto Size = fs::file_size("key");
|
||||||
if(d.HasMember("success") && d["success"].GetBool()){
|
std::string Buffer(Size, 0);
|
||||||
LoginAuth = true;
|
Key.read(&Buffer[0], Size);
|
||||||
UpdateKey(d["private_key"].GetString());
|
Key.close();
|
||||||
PublicKey = d["public_key"].GetString();
|
|
||||||
Role = d["role"].GetString();
|
for (char& c : Buffer) {
|
||||||
//info(Role);
|
if (!std::isalnum(c) && c != '-') {
|
||||||
}else{
|
UpdateKey(nullptr);
|
||||||
info("Auto-Authentication unsuccessful please re-login!");
|
return;
|
||||||
UpdateKey(nullptr);
|
}
|
||||||
}
|
}
|
||||||
}else{
|
|
||||||
warn("Could not open saved key!");
|
Buffer = HTTP::Post("https://auth.beammp.com/userlogin", R"({"pk":")" + Buffer + "\"}");
|
||||||
UpdateKey(nullptr);
|
|
||||||
}
|
nlohmann::json d = nlohmann::json::parse(Buffer, nullptr, false);
|
||||||
}else UpdateKey(nullptr);
|
|
||||||
}
|
if (Buffer.empty() || Buffer.at(0) != '{' || d.is_discarded()) {
|
||||||
|
error(Buffer);
|
||||||
|
info("Invalid answer from authentication servers.");
|
||||||
|
UpdateKey(nullptr);
|
||||||
|
}
|
||||||
|
if (d["success"].get<bool>()) {
|
||||||
|
LoginAuth = true;
|
||||||
|
UpdateKey(d["private_key"].get<std::string>().c_str());
|
||||||
|
PublicKey = d["public_key"].get<std::string>();
|
||||||
|
if (d.contains("username")) {
|
||||||
|
Username = d["username"].get<std::string>();
|
||||||
|
}
|
||||||
|
if (d.contains("role")) {
|
||||||
|
UserRole = d["role"].get<std::string>();
|
||||||
|
}
|
||||||
|
if (d.contains("id")) {
|
||||||
|
UserID = d["id"].get<int>();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
info("Auto-Authentication unsuccessful please re-login!");
|
||||||
|
UpdateKey(nullptr);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
warn("Could not open saved key!");
|
||||||
|
UpdateKey(nullptr);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
UpdateKey(nullptr);
|
||||||
|
}
|
||||||
|
|||||||
725
src/Startup.cpp
Executable file → Normal file
725
src/Startup.cpp
Executable file → Normal file
@@ -1,339 +1,386 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
/*
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
///
|
*/
|
||||||
/// Created by Anonymous275 on 7/16/2020
|
|
||||||
///
|
|
||||||
#include "zip_file.h"
|
#include "zip_file.h"
|
||||||
#include <string>
|
#include <charconv>
|
||||||
#if defined(_WIN32)
|
#include <cstring>
|
||||||
#include <windows.h>
|
#include <httplib.h>
|
||||||
#elif defined(__linux__)
|
#include <nlohmann/json.hpp>
|
||||||
#include <unistd.h>
|
#include <string>
|
||||||
#endif
|
#if defined(_WIN32)
|
||||||
#include "Discord/discord_info.h"
|
#elif defined(__linux__)
|
||||||
#include "Network/network.hpp"
|
#include <unistd.h>
|
||||||
#include "Security/Init.h"
|
#elif defined (__APPLE__)
|
||||||
#include <filesystem>
|
#include <unistd.h>
|
||||||
#include "Startup.h"
|
#include <libproc.h>
|
||||||
#include "Logger.h"
|
#endif // __APPLE__
|
||||||
#include <fstream>
|
#include "Http.h"
|
||||||
#include <thread>
|
#include "Logger.h"
|
||||||
#include "Http.h"
|
#include "Network/network.hpp"
|
||||||
#include "Json.h"
|
#include "Options.h"
|
||||||
|
#include "Security/Init.h"
|
||||||
extern int TraceBack;
|
#include "Startup.h"
|
||||||
bool Dev = false;
|
#include "Utils.h"
|
||||||
namespace fs = std::filesystem;
|
#include "hashpp.h"
|
||||||
|
#include <filesystem>
|
||||||
#if defined(_WIN32)
|
#include <fstream>
|
||||||
std::string GetEN(){
|
#include <thread>
|
||||||
return "BeamMP-Launcher.exe";
|
|
||||||
}
|
extern int TraceBack;
|
||||||
#elif defined(__linux__)
|
int ProxyPort = 0;
|
||||||
std::string GetEN(){
|
|
||||||
return "BeamMP-Launcher";
|
namespace fs = std::filesystem;
|
||||||
}
|
|
||||||
#endif
|
struct Version {
|
||||||
|
uint8_t major;
|
||||||
std::string GetVer(){
|
uint8_t minor;
|
||||||
return "2.0";
|
uint8_t patch;
|
||||||
}
|
Version(uint8_t major, uint8_t minor, uint8_t patch);
|
||||||
std::string GetPatch(){
|
Version(const std::array<uint8_t, 3>& v);
|
||||||
return ".82";
|
};
|
||||||
}
|
|
||||||
|
std::array<uint8_t, 3> VersionStrToInts(const std::string& str) {
|
||||||
std::string GetEP(char*P){
|
std::array<uint8_t, 3> Version;
|
||||||
static std::string Ret = [&](){
|
std::stringstream ss(str);
|
||||||
std::string path(P);
|
for (uint8_t& i : Version) {
|
||||||
return path.substr(0, path.find_last_of("\\/") + 1);
|
std::string Part;
|
||||||
} ();
|
std::getline(ss, Part, '.');
|
||||||
return Ret;
|
std::from_chars(&*Part.begin(), &*Part.begin() + Part.size(), i);
|
||||||
}
|
}
|
||||||
#if defined(_WIN32)
|
return Version;
|
||||||
void ReLaunch(int argc,char*args[]){
|
}
|
||||||
std::string Arg;
|
|
||||||
for(int c = 2; c <= argc; c++){
|
bool IsOutdated(const Version& Current, const Version& Newest) {
|
||||||
Arg += " ";
|
if (Newest.major > Current.major) {
|
||||||
Arg += args[c-1];
|
return true;
|
||||||
}
|
} else if (Newest.major == Current.major && Newest.minor > Current.minor) {
|
||||||
system("cls");
|
return true;
|
||||||
ShellExecute(nullptr,"runas",(GetEP() + GetEN()).c_str(),Arg.c_str(),nullptr,SW_SHOWNORMAL);
|
} else if (Newest.major == Current.major && Newest.minor == Current.minor && Newest.patch > Current.patch) {
|
||||||
ShowWindow(GetConsoleWindow(),0);
|
return true;
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
} else {
|
||||||
exit(1);
|
return false;
|
||||||
}
|
}
|
||||||
void URelaunch(int argc,char* args[]){
|
}
|
||||||
std::string Arg;
|
|
||||||
for(int c = 2; c <= argc; c++){
|
Version::Version(uint8_t major, uint8_t minor, uint8_t patch)
|
||||||
Arg += " ";
|
: major(major)
|
||||||
Arg += args[c-1];
|
, minor(minor)
|
||||||
}
|
, patch(patch) { }
|
||||||
ShellExecute(nullptr,"open",(GetEP() + GetEN()).c_str(),Arg.c_str(),nullptr,SW_SHOWNORMAL);
|
|
||||||
ShowWindow(GetConsoleWindow(),0);
|
Version::Version(const std::array<uint8_t, 3>& v)
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
: Version(v[0], v[1], v[2]) {
|
||||||
exit(1);
|
}
|
||||||
}
|
|
||||||
#elif defined(__linux__)
|
beammp_fs_string GetEN() {
|
||||||
void ReLaunch(int argc,char*args[]){
|
#if defined(_WIN32)
|
||||||
std::string Arg;
|
return L"BeamMP-Launcher.exe";
|
||||||
for(int c = 2; c <= argc; c++){
|
#elif defined(__linux__)
|
||||||
Arg += " ";
|
return "BeamMP-Launcher";
|
||||||
Arg += args[c-1];
|
#endif
|
||||||
}
|
}
|
||||||
system("clear");
|
|
||||||
execl((GetEP() + GetEN()).c_str(), Arg.c_str(), NULL);
|
std::string GetVer() {
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
return "2.6";
|
||||||
exit(1);
|
}
|
||||||
}
|
std::string GetPatch() {
|
||||||
void URelaunch(int argc,char* args[]){
|
return ".0";
|
||||||
std::string Arg;
|
}
|
||||||
for(int c = 2; c <= argc; c++){
|
|
||||||
Arg += " ";
|
beammp_fs_string GetEP(const beammp_fs_char* P) {
|
||||||
Arg += args[c-1];
|
static beammp_fs_string Ret = [&]() {
|
||||||
}
|
beammp_fs_string path(P);
|
||||||
execl((GetEP() + GetEN()).c_str(), Arg.c_str(), NULL);
|
return path.substr(0, path.find_last_of(beammp_wide("\\/")) + 1);
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
}();
|
||||||
exit(1);
|
return Ret;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
fs::path GetBP(const beammp_fs_char* P) {
|
||||||
void CheckName(int argc,char* args[]){
|
fs::path fspath = {};
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
std::string DN = GetEN(),CDir = args[0],FN = CDir.substr(CDir.find_last_of('\\')+1);
|
beammp_fs_char path[256];
|
||||||
#elif defined(__linux__)
|
GetModuleFileNameW(nullptr, path, sizeof(path));
|
||||||
std::string DN = GetEN(),CDir = args[0],FN = CDir.substr(CDir.find_last_of('/')+1);
|
fspath = path;
|
||||||
#endif
|
#elif defined(__linux__)
|
||||||
if(FN != DN){
|
fspath = fs::canonical("/proc/self/exe");
|
||||||
if(fs::exists(DN))remove(DN.c_str());
|
#elif defined(__APPLE__)
|
||||||
if(fs::exists(DN))ReLaunch(argc,args);
|
pid_t pid = getpid();
|
||||||
std::rename(FN.c_str(), DN.c_str());
|
char path[PROC_PIDPATHINFO_MAXSIZE];
|
||||||
URelaunch(argc,args);
|
// While this is fine for a raw executable,
|
||||||
}
|
// an application bundle is read-only and these files
|
||||||
}
|
// should instead be placed in Application Support.
|
||||||
|
proc_pidpath(pid, path, sizeof(path));
|
||||||
void CheckForUpdates(int argc,char*args[],const std::string& CV){
|
fspath = std::string(path);
|
||||||
std::string link;
|
#else
|
||||||
std::string HTTP = HTTP::Get("https://beammp.com/builds/launcher?version=true");
|
fspath = beammp_fs_string(P);
|
||||||
bool fallback = false;
|
#endif
|
||||||
if(HTTP.find_first_of("0123456789") == std::string::npos){
|
fspath = fs::weakly_canonical(fspath.string() + "/..");
|
||||||
HTTP = HTTP::Get("https://backup1.beammp.com/builds/launcher?version=true");
|
#if defined(_WIN32)
|
||||||
fallback = true;
|
return fspath.wstring();
|
||||||
if(HTTP.find_first_of("0123456789") == std::string::npos) {
|
#else
|
||||||
fatal("Primary Servers Offline! sorry for the inconvenience!");
|
return fspath.string();
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
if(fallback){
|
|
||||||
link = "https://backup1.beammp.com/builds/launcher?download=true";
|
#if defined(_WIN32)
|
||||||
}else link = "https://beammp.com/builds/launcher?download=true";
|
void ReLaunch() {
|
||||||
|
std::wstring Arg;
|
||||||
std::string EP(GetEP() + GetEN()), Back(GetEP() + "BeamMP-Launcher.back");
|
for (int c = 2; c <= options.argc; c++) {
|
||||||
|
Arg += Utils::ToWString(options.argv[c - 1]);
|
||||||
if(fs::exists(Back))remove(Back.c_str());
|
Arg += L" ";
|
||||||
|
}
|
||||||
if(HTTP > CV){
|
info("Relaunch!");
|
||||||
#if defined(_WIN32)
|
system("cls");
|
||||||
system("cls");
|
ShellExecuteW(nullptr, L"runas", (GetBP() / GetEN()).c_str(), Arg.c_str(), nullptr, SW_SHOWNORMAL);
|
||||||
#elif defined(__linux__)
|
ShowWindow(GetConsoleWindow(), 0);
|
||||||
system("clear");
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
#endif
|
exit(1);
|
||||||
info("Update found!");
|
}
|
||||||
info("Updating...");
|
void URelaunch() {
|
||||||
if(std::rename(EP.c_str(), Back.c_str()))error("failed creating a backup!");
|
std::wstring Arg;
|
||||||
|
for (int c = 2; c <= options.argc; c++) {
|
||||||
if(!HTTP::Download(link, EP)){
|
Arg += Utils::ToWString(options.argv[c - 1]);
|
||||||
error("Launcher Update failed! trying again...");
|
Arg += L" ";
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
}
|
||||||
|
ShellExecuteW(nullptr, L"open", (GetBP() / GetEN()).c_str(), Arg.c_str(), nullptr, SW_SHOWNORMAL);
|
||||||
if(!HTTP::Download(link, EP)){
|
ShowWindow(GetConsoleWindow(), 0);
|
||||||
error("Launcher Update failed!");
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
exit(1);
|
||||||
ReLaunch(argc,args);
|
}
|
||||||
}
|
#elif defined(__linux__)
|
||||||
}
|
void ReLaunch() {
|
||||||
URelaunch(argc,args);
|
std::string Arg;
|
||||||
}else info("Launcher version is up to date");
|
for (int c = 2; c <= options.argc; c++) {
|
||||||
TraceBack++;
|
Arg += options.argv[c - 1];
|
||||||
}
|
Arg += " ";
|
||||||
|
}
|
||||||
void CustomPort(int argc, char* argv[]){
|
info("Relaunch!");
|
||||||
if(argc > 1){
|
system("clear");
|
||||||
std::string Port = argv[1];
|
int ret = execv((GetBP() / GetEN()).c_str(), const_cast<char**>(options.argv));
|
||||||
if(Port.find_first_not_of("0123456789") == std::string::npos){
|
if (ret < 0) {
|
||||||
if(std::stoi(Port) > 1000){
|
error(std::string("execv() failed with: ") + strerror(errno) + ". Failed to relaunch");
|
||||||
DEFAULT_PORT = std::stoi(Port);
|
exit(1);
|
||||||
warn("Running on custom port : " + std::to_string(DEFAULT_PORT));
|
}
|
||||||
}
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
}
|
exit(1);
|
||||||
if(argc > 2)Dev = true;
|
}
|
||||||
}
|
void URelaunch() {
|
||||||
}
|
int ret = execv((GetBP() / GetEN()).c_str(), const_cast<char**>(options.argv));
|
||||||
|
if (ret < 0) {
|
||||||
#ifdef _WIN32
|
error(std::string("execv() failed with: ") + strerror(errno) + ". Failed to relaunch");
|
||||||
void LinuxPatch(){
|
exit(1);
|
||||||
HKEY hKey = nullptr;
|
}
|
||||||
LONG result = RegOpenKeyEx(HKEY_CURRENT_USER, R"(Software\Wine)", 0, KEY_READ, &hKey);
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
if (result != ERROR_SUCCESS || getenv("USER") == nullptr)return;
|
exit(1);
|
||||||
RegCloseKey(hKey);
|
}
|
||||||
info("Wine/Proton Detected! If you are on windows delete HKEY_CURRENT_USER\\Software\\Wine in regedit");
|
#endif
|
||||||
info("Applying patches...");
|
|
||||||
|
void CheckName() {
|
||||||
result = RegCreateKey(HKEY_CURRENT_USER, R"(Software\Valve\Steam\Apps\284160)", &hKey);
|
#if defined(_WIN32)
|
||||||
|
std::wstring DN = GetEN(), CDir = Utils::ToWString(options.executable_name), FN = CDir.substr(CDir.find_last_of('\\') + 1);
|
||||||
if (result != ERROR_SUCCESS){
|
#elif defined(__linux__)
|
||||||
fatal(R"(failed to create HKEY_CURRENT_USER\Software\Valve\Steam\Apps\284160)");
|
std::string DN = GetEN(), CDir = options.executable_name, FN = CDir.substr(CDir.find_last_of('/') + 1);
|
||||||
return;
|
#endif
|
||||||
}
|
if (FN != DN) {
|
||||||
|
if (fs::exists(DN))
|
||||||
result = RegSetValueEx(hKey, "Name", 0, REG_SZ, (BYTE*)"BeamNG.drive", 12);
|
fs::remove(DN.c_str());
|
||||||
|
if (fs::exists(DN))
|
||||||
if (result != ERROR_SUCCESS){
|
ReLaunch();
|
||||||
fatal(R"(failed to create the value "Name" under HKEY_CURRENT_USER\Software\Valve\Steam\Apps\284160)");
|
fs::rename(FN.c_str(), DN.c_str());
|
||||||
return;
|
URelaunch();
|
||||||
}
|
}
|
||||||
RegCloseKey(hKey);
|
}
|
||||||
|
|
||||||
std::string Path = R"(Z:\home\)" + std::string(getenv("USER")) + R"(\.steam\steam\Steam.exe)";
|
void CheckForUpdates(const std::string& CV) {
|
||||||
|
std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/launcher?branch=" + Branch + "&pk=" + PublicKey);
|
||||||
if(!fs::exists(Path)) {
|
std::string LatestVersion = HTTP::Get(
|
||||||
std::ofstream ofs(Path);
|
"https://backend.beammp.com/version/launcher?branch=" + Branch + "&pk=" + PublicKey);
|
||||||
if (!ofs.is_open()) {
|
|
||||||
fatal("Failed to create file \"" + Path + "\"");
|
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
|
||||||
return;
|
beammp_fs_string BP(GetBP() / GetEN()), Back(GetBP() / beammp_wide("BeamMP-Launcher.back"));
|
||||||
} else ofs.close();
|
|
||||||
}
|
std::string FileHash = Utils::GetSha256HashReallyFastFile(BP);
|
||||||
|
|
||||||
result = RegOpenKeyEx(HKEY_CURRENT_USER, R"(Software\Valve\Steam)", 0, KEY_ALL_ACCESS, &hKey);
|
if (FileHash != LatestHash && IsOutdated(Version(VersionStrToInts(GetVer() + GetPatch())), Version(VersionStrToInts(LatestVersion)))) {
|
||||||
if (result != ERROR_SUCCESS){
|
if (!options.no_update) {
|
||||||
fatal(R"(failed to open HKEY_CURRENT_USER\Software\Valve\Steam)");
|
info("Launcher update " + LatestVersion + " found!");
|
||||||
return;
|
#if defined(__linux__)
|
||||||
}
|
error("Auto update is NOT implemented for the Linux version. Please update manually ASAP as updates contain security patches.");
|
||||||
|
#else
|
||||||
result = RegSetValueEx(hKey, "SteamExe", 0, REG_SZ, (BYTE*)Path.c_str(), Path.size());
|
info("Downloading Launcher update " + LatestHash);
|
||||||
|
HTTP::Download(
|
||||||
if (result != ERROR_SUCCESS){
|
"https://backend.beammp.com/builds/launcher?download=true"
|
||||||
fatal(R"(failed to create the value "Name" under HKEY_CURRENT_USER\Software\Valve\Steam\Apps\284160)");
|
"&pk="
|
||||||
return;
|
+ PublicKey + "&branch=" + Branch,
|
||||||
}
|
beammp_wide("new_") + BP, LatestHash);
|
||||||
|
std::error_code ec;
|
||||||
RegCloseKey(hKey);
|
fs::remove(Back, ec);
|
||||||
|
if (ec == std::errc::permission_denied) {
|
||||||
info("Patched!");
|
error("Failed to remove old backup file: " + ec.message() + ". Using alternative name.");
|
||||||
}
|
fs::rename(BP, Back + beammp_wide(".") + Utils::ToWString(FileHash.substr(0, 8)));
|
||||||
#endif
|
} else {
|
||||||
|
fs::rename(BP, Back);
|
||||||
#if defined(_WIN32)
|
}
|
||||||
void InitLauncher(int argc, char* argv[]) {
|
fs::rename(beammp_wide("new_") + BP, BP);
|
||||||
system("cls");
|
URelaunch();
|
||||||
SetConsoleTitleA(("BeamMP Launcher v" + std::string(GetVer()) + GetPatch()).c_str());
|
#endif
|
||||||
InitLog();
|
} else {
|
||||||
CheckName(argc, argv);
|
warn("Launcher update was found, but not updating because --no-update or --dev was specified.");
|
||||||
LinuxPatch();
|
}
|
||||||
CheckLocalKey();
|
} else
|
||||||
ConfigInit();
|
info("Launcher version is up to date. Latest version: " + LatestVersion);
|
||||||
CustomPort(argc, argv);
|
TraceBack++;
|
||||||
Discord_Main();
|
}
|
||||||
CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch());
|
|
||||||
}
|
|
||||||
#elif defined(__linux__)
|
#ifdef _WIN32
|
||||||
void InitLauncher(int argc, char* argv[]) {
|
void LinuxPatch() {
|
||||||
system("clear");
|
HKEY hKey = nullptr;
|
||||||
InitLog();
|
LONG result = RegOpenKeyEx(HKEY_CURRENT_USER, R"(Software\Wine)", 0, KEY_READ, &hKey);
|
||||||
CheckName(argc, argv);
|
if (result != ERROR_SUCCESS || getenv("USER") == nullptr)
|
||||||
CheckLocalKey();
|
return;
|
||||||
ConfigInit();
|
RegCloseKey(hKey);
|
||||||
CustomPort(argc, argv);
|
info("Wine/Proton Detected! If you are on windows delete HKEY_CURRENT_USER\\Software\\Wine in regedit");
|
||||||
CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch());
|
info("Applying patches...");
|
||||||
}
|
|
||||||
#endif
|
result = RegCreateKey(HKEY_CURRENT_USER, R"(Software\Valve\Steam\Apps\284160)", &hKey);
|
||||||
|
|
||||||
size_t DirCount(const std::filesystem::path& path){
|
if (result != ERROR_SUCCESS) {
|
||||||
return (size_t)std::distance(std::filesystem::directory_iterator{path}, std::filesystem::directory_iterator{});
|
fatal(R"(failed to create HKEY_CURRENT_USER\Software\Valve\Steam\Apps\284160)");
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
void CheckMP(const std::string& Path) {
|
|
||||||
if (!fs::exists(Path))return;
|
result = RegSetValueEx(hKey, "Name", 0, REG_SZ, (BYTE*)"BeamNG.drive", 12);
|
||||||
size_t c = DirCount(fs::path(Path));
|
|
||||||
try {
|
if (result != ERROR_SUCCESS) {
|
||||||
for (auto& p : fs::directory_iterator(Path)){
|
fatal(R"(failed to create the value "Name" under HKEY_CURRENT_USER\Software\Valve\Steam\Apps\284160)");
|
||||||
if(p.exists() && !p.is_directory()){
|
return;
|
||||||
std::string Name = p.path().filename().u8string();
|
}
|
||||||
for(char&Ch : Name)Ch = char(tolower(Ch));
|
RegCloseKey(hKey);
|
||||||
if(Name != "beammp.zip")fs::remove(p.path());
|
|
||||||
}
|
info("Patched!");
|
||||||
}
|
}
|
||||||
} catch (...) {
|
#endif
|
||||||
fatal("We were unable to clean the multiplayer mods folder! Is the game still running or do you have something open in that folder?");
|
|
||||||
}
|
#if defined(_WIN32)
|
||||||
|
|
||||||
}
|
void InitLauncher() {
|
||||||
|
SetConsoleTitleA(("BeamMP Launcher v" + std::string(GetVer()) + GetPatch()).c_str());
|
||||||
void EnableMP(){
|
debug("Launcher Version : " + GetVer() + GetPatch());
|
||||||
std::string File(GetGamePath() + "mods/db.json");
|
CheckName();
|
||||||
if(!fs::exists(File))return;
|
LinuxPatch();
|
||||||
auto Size = fs::file_size(File);
|
CheckLocalKey();
|
||||||
if(Size < 2)return;
|
CheckForUpdates(std::string(GetVer()) + GetPatch());
|
||||||
std::ifstream db(File);
|
}
|
||||||
if(db.is_open()) {
|
#elif defined(__linux__)
|
||||||
std::string Data(Size, 0);
|
|
||||||
db.read(&Data[0], Size);
|
void InitLauncher() {
|
||||||
db.close();
|
info("BeamMP Launcher v" + GetVer() + GetPatch());
|
||||||
json::Document d;
|
CheckName();
|
||||||
d.Parse(Data.c_str());
|
CheckLocalKey();
|
||||||
if(Data.at(0) != '{' || d.HasParseError()){
|
CheckForUpdates(std::string(GetVer()) + GetPatch());
|
||||||
//error("Failed to parse " + File); //TODO illegal formatting
|
}
|
||||||
return;
|
#endif
|
||||||
}
|
|
||||||
if(d.HasMember("mods") && !d["mods"].IsNull() && d["mods"].HasMember("multiplayerbeammp") && !d["mods"]["multiplayerbeammp"].IsNull()){
|
size_t DirCount(const fs::path& path) {
|
||||||
d["mods"]["multiplayerbeammp"]["active"] = true;
|
return (size_t)std::distance(fs::directory_iterator { path }, fs::directory_iterator {});
|
||||||
rapidjson::StringBuffer buffer;
|
}
|
||||||
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
|
||||||
d.Accept(writer);
|
void CheckMP(const beammp_fs_string& Path) {
|
||||||
std::ofstream ofs(File);
|
if (!fs::exists(Path))
|
||||||
if(ofs.is_open()){
|
return;
|
||||||
ofs << buffer.GetString();
|
size_t c = DirCount(fs::path(Path));
|
||||||
ofs.close();
|
try {
|
||||||
}else{
|
for (auto& p : fs::directory_iterator(Path)) {
|
||||||
error("Failed to write " + File);
|
if (p.exists() && !p.is_directory()) {
|
||||||
}
|
std::string Name = p.path().filename().string();
|
||||||
}
|
for (char& Ch : Name)
|
||||||
}
|
Ch = char(tolower(Ch));
|
||||||
}
|
if (Name != "beammp.zip")
|
||||||
|
fs::remove(p.path());
|
||||||
void PreGame(const std::string& GamePath){
|
}
|
||||||
std::string GameVer = CheckVer(GamePath);
|
}
|
||||||
info("Game Version : " + GameVer);
|
} catch (...) {
|
||||||
|
fatal("We were unable to clean the multiplayer mods folder! Is the game still running or do you have something open in that folder?");
|
||||||
CheckMP(GetGamePath() + "mods/multiplayer");
|
}
|
||||||
|
}
|
||||||
if(!Dev) {
|
|
||||||
info("Downloading mod please wait...");
|
void EnableMP() {
|
||||||
try {
|
beammp_fs_string File(GetGamePath() / beammp_wide("mods/db.json"));
|
||||||
if (!fs::exists(GetGamePath() + "mods/multiplayer")) {
|
if (!fs::exists(File))
|
||||||
fs::create_directories(GetGamePath() + "mods/multiplayer");
|
return;
|
||||||
}
|
auto Size = fs::file_size(File);
|
||||||
EnableMP();
|
if (Size < 2)
|
||||||
}catch(std::exception&e){
|
return;
|
||||||
fatal(e.what());
|
std::ifstream db(File);
|
||||||
}
|
if (db.is_open()) {
|
||||||
#if defined(_WIN32)
|
std::string Data(Size, 0);
|
||||||
std::string ZipPath(GetGamePath() + R"(mods\multiplayer\BeamMP.zip)");
|
db.read(&Data[0], Size);
|
||||||
#elif defined(__linux__)
|
db.close();
|
||||||
// Linux version of the game cant handle mods with uppercase names
|
nlohmann::json d = nlohmann::json::parse(Data, nullptr, false);
|
||||||
std::string ZipPath(GetGamePath() + R"(mods/multiplayer/beammp.zip)");
|
if (Data.at(0) != '{' || d.is_discarded()) {
|
||||||
#endif
|
// error("Failed to parse " + File); //TODO illegal formatting
|
||||||
|
return;
|
||||||
HTTP::Download("https://backend.beammp.com/builds/client?download=true"
|
}
|
||||||
"&pk=" + PublicKey + "&branch=" + Branch, ZipPath);
|
if (d.contains("mods") && d["mods"].contains("multiplayerbeammp")) {
|
||||||
|
d["mods"]["multiplayerbeammp"]["active"] = true;
|
||||||
std::string Target(GetGamePath() + "mods/unpacked/beammp");
|
std::ofstream ofs(File);
|
||||||
|
if (ofs.is_open()) {
|
||||||
if(fs::is_directory(Target)) {
|
ofs << d.dump();
|
||||||
fs::remove_all(Target);
|
ofs.close();
|
||||||
}
|
} else {
|
||||||
|
error(beammp_wide("Failed to write ") + File);
|
||||||
//HTTP::Download("beammp.com/builds/client", GetGamePath() + R"(mods\multiplayer\BeamMP.zip)");
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PreGame(const beammp_fs_string& GamePath) {
|
||||||
|
std::string GameVer = CheckVer(GamePath);
|
||||||
|
info("Game Version : " + GameVer);
|
||||||
|
|
||||||
|
CheckMP(GetGamePath() / beammp_wide("mods/multiplayer"));
|
||||||
|
info(beammp_wide("Game user path: ") + beammp_fs_string(GetGamePath()));
|
||||||
|
|
||||||
|
if (!options.no_download) {
|
||||||
|
std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/mod?branch=" + Branch + "&pk=" + PublicKey);
|
||||||
|
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
|
||||||
|
LatestHash.erase(std::remove_if(LatestHash.begin(), LatestHash.end(),
|
||||||
|
[](auto const& c) -> bool { return !std::isalnum(c); }),
|
||||||
|
LatestHash.end());
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!fs::exists(GetGamePath() / beammp_wide("mods/multiplayer"))) {
|
||||||
|
fs::create_directories(GetGamePath() / beammp_wide("mods/multiplayer"));
|
||||||
|
}
|
||||||
|
EnableMP();
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
fatal(e.what());
|
||||||
|
}
|
||||||
|
#if defined(_WIN32)
|
||||||
|
std::wstring ZipPath(GetGamePath() / LR"(mods\multiplayer\BeamMP.zip)");
|
||||||
|
#elif defined(__linux__)
|
||||||
|
// Linux version of the game cant handle mods with uppercase names
|
||||||
|
std::string ZipPath(GetGamePath() / R"(mods/multiplayer/beammp.zip)");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::string FileHash = fs::exists(ZipPath) ? Utils::GetSha256HashReallyFastFile(ZipPath) : "";
|
||||||
|
|
||||||
|
if (FileHash != LatestHash) {
|
||||||
|
info("Downloading BeamMP Update " + LatestHash);
|
||||||
|
HTTP::Download("https://backend.beammp.com/builds/client?download=true"
|
||||||
|
"&pk="
|
||||||
|
+ PublicKey + "&branch=" + Branch,
|
||||||
|
ZipPath, LatestHash);
|
||||||
|
}
|
||||||
|
|
||||||
|
beammp_fs_string Target(GetGamePath() / beammp_wide("mods/unpacked/beammp"));
|
||||||
|
|
||||||
|
if (fs::is_directory(Target) && !fs::is_directory(Target + beammp_wide("/.git"))) {
|
||||||
|
fs::remove_all(Target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
71
src/main.cpp
Executable file → Normal file
71
src/main.cpp
Executable file → Normal file
@@ -1,43 +1,70 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
/*
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
|
||||||
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
|
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
|
||||||
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
///
|
*/
|
||||||
/// Created by Anonymous275 on 7/16/2020
|
|
||||||
///
|
#include "Http.h"
|
||||||
|
#include "Logger.h"
|
||||||
#include "Network/network.hpp"
|
#include "Network/network.hpp"
|
||||||
#include "Security/Init.h"
|
#include "Security/Init.h"
|
||||||
#include "Startup.h"
|
#include "Startup.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
#include <curl/curl.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "Logger.h"
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include "Http.h"
|
#include "Options.h"
|
||||||
|
|
||||||
[[noreturn]] void flush(){
|
Options options;
|
||||||
while(true){
|
|
||||||
|
[[noreturn]] void flush() {
|
||||||
|
while (true) {
|
||||||
std::cout.flush();
|
std::cout.flush();
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, const char** argv) try {
|
||||||
#ifdef DEBUG
|
#if defined(_WIN32)
|
||||||
std::thread th(flush);
|
system("cls");
|
||||||
th.detach();
|
#elif defined(__linux__)
|
||||||
#endif
|
system("clear");
|
||||||
GetEP(argv[0]);
|
#endif
|
||||||
|
|
||||||
InitLauncher(argc,argv);
|
#ifdef DEBUG
|
||||||
|
std::thread th(flush);
|
||||||
|
th.detach();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
|
|
||||||
|
GetEP(Utils::ToWString(std::string(argv[0])).c_str());
|
||||||
|
|
||||||
|
InitLog();
|
||||||
|
ConfigInit();
|
||||||
|
InitOptions(argc, argv, options);
|
||||||
|
InitLauncher();
|
||||||
|
|
||||||
|
info("IMPORTANT: You MUST keep this window open to play BeamMP!");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LegitimacyCheck();
|
LegitimacyCheck();
|
||||||
}catch (std::exception& e){
|
} catch (std::exception& e) {
|
||||||
fatal("Main 1 : " + std::string(e.what()));
|
error("Failure in LegitimacyCheck: " + std::string(e.what()));
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
HTTP::StartProxy();
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
error(std::string("Failed to start HTTP proxy: Some in-game functions may not work. Error: ") + e.what());
|
||||||
|
}
|
||||||
PreGame(GetGameDir());
|
PreGame(GetGameDir());
|
||||||
InitGame(GetGameDir());
|
InitGame(GetGameDir());
|
||||||
CoreNetwork();
|
CoreNetwork();
|
||||||
|
} catch (const std::exception& e) {
|
||||||
///TODO: make sure to use argv[0] for everything that should be in the same dir (mod down ect...)
|
error(std::string("Exception in main(): ") + e.what());
|
||||||
|
info("Closing in 5 seconds");
|
||||||
|
info("If this keeps happening, contact us on either: Forum: https://forum.beammp.com, Discord: https://discord.gg/beammp");
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||||
}
|
}
|
||||||
|
|||||||
9
vcpkg.json
Normal file
9
vcpkg.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"dependencies": [
|
||||||
|
"cpp-httplib",
|
||||||
|
"nlohmann-json",
|
||||||
|
"zlib",
|
||||||
|
"openssl",
|
||||||
|
"curl"
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user