mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-07 00:06:08 +00:00
Compare commits
146 Commits
v1.80.0
...
add-warnin
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e5fe80202 | ||
|
|
7ff4681263 | ||
|
|
3be1262b07 | ||
|
|
cfcabf31a4 | ||
|
|
5714c3de76 | ||
|
|
12711d77c7 | ||
|
|
e08a4de6db | ||
|
|
acd5f4ed09 | ||
|
|
c4e7b9a919 | ||
|
|
3db1f6773e | ||
|
|
8c9d3a5455 | ||
|
|
9dcfa1dca4 | ||
|
|
bd4cfe06b1 | ||
|
|
9c7034e401 | ||
|
|
aeb167c1e8 | ||
|
|
7967ec38e8 | ||
|
|
250be2ccdc | ||
|
|
6158069d4d | ||
|
|
b2e5b8d2d3 | ||
|
|
5db1b48e07 | ||
|
|
56dcfcc5ed | ||
|
|
7c1106a46a | ||
|
|
9afdfd4d1b | ||
|
|
c2f260a86c | ||
|
|
2781179b4b | ||
|
|
3b479abf64 | ||
|
|
c731718f50 | ||
|
|
0fd0a9fe7e | ||
|
|
302582bfe1 | ||
|
|
839bb48cd6 | ||
|
|
c4ebdda1a4 | ||
|
|
d6b494c6c4 | ||
|
|
a80d4f5147 | ||
|
|
811b04485c | ||
|
|
a64fead653 | ||
|
|
399461d1b1 | ||
|
|
ec5e8ed5b3 | ||
|
|
5655164e60 | ||
|
|
3d9b7c2d67 | ||
|
|
764e3ab5c1 | ||
|
|
3314362faf | ||
|
|
e483f520db | ||
|
|
c92e32c0e1 | ||
|
|
cb872f8a41 | ||
|
|
0aae245054 | ||
|
|
480a7d038f | ||
|
|
f62f44d4c0 | ||
|
|
e316b89fb1 | ||
|
|
3b2dbcac1b | ||
|
|
d881c9faf6 | ||
|
|
11d9375f36 | ||
|
|
4207d7adcf | ||
|
|
832b1d66a0 | ||
|
|
cd829f9f22 | ||
|
|
f7c70eb6df | ||
|
|
01960f6470 | ||
|
|
f6065a1c00 | ||
|
|
ba3b7f0ed0 | ||
|
|
056eadbef2 | ||
|
|
2bb2dc9040 | ||
|
|
17553fd412 | ||
|
|
08c1c0f682 | ||
|
|
84959ae9c9 | ||
|
|
c90c102097 | ||
|
|
5b004426ce | ||
|
|
69c9060dd2 | ||
|
|
49870639ff | ||
|
|
0843862af9 | ||
|
|
71a9a567bc | ||
|
|
a6e3d0fad9 | ||
|
|
411d0786a5 | ||
|
|
acb6b11e24 | ||
|
|
1739393a73 | ||
|
|
298ef33ab7 | ||
|
|
d2433cceca | ||
|
|
705e0ab9c4 | ||
|
|
53c40a2bc3 | ||
|
|
96c60ef05a | ||
|
|
61759b8531 | ||
|
|
691be8cd08 | ||
|
|
082445c295 | ||
|
|
f4bda81be0 | ||
|
|
1ad8e0b8e5 | ||
|
|
6c673e78e5 | ||
|
|
09abe75fbb | ||
|
|
b45e4b40f2 | ||
|
|
15d1539a92 | ||
|
|
14a5f47549 | ||
|
|
584998277d | ||
|
|
fb59b6997c | ||
|
|
a1f5ec9ba5 | ||
|
|
989ac981be | ||
|
|
d425b8035a | ||
|
|
f0540c2df5 | ||
|
|
9df08025ad | ||
|
|
bb732f102f | ||
|
|
ec3bcffe7c | ||
|
|
e70cf0f877 | ||
|
|
b40ab5e36a | ||
|
|
54a27f5c4c | ||
|
|
37cfec9fdc | ||
|
|
16f0769f87 | ||
|
|
9f1e58bb70 | ||
|
|
83b43d782d | ||
|
|
3a0b96da52 | ||
|
|
aa2b07b359 | ||
|
|
289402a9ba | ||
|
|
1afa81e420 | ||
|
|
ae6725ece3 | ||
|
|
fff747afca | ||
|
|
5c1b7b1dbf | ||
|
|
e290910312 | ||
|
|
fb7831d629 | ||
|
|
5b4b930701 | ||
|
|
fe59083257 | ||
|
|
fbc5e28d25 | ||
|
|
d96f968dde | ||
|
|
ba5ba4b8b4 | ||
|
|
263b6c9c0d | ||
|
|
78875c2c9c | ||
|
|
8e55edaa29 | ||
|
|
c77f8742b4 | ||
|
|
0a58001b09 | ||
|
|
075d4a8c4d | ||
|
|
00313e32f9 | ||
|
|
16ea84b4cf | ||
|
|
6b124e89a8 | ||
|
|
543183b852 | ||
|
|
fda7567044 | ||
|
|
6b4211d9cf | ||
|
|
3572a188d1 | ||
|
|
775e44a68f | ||
|
|
eaa8796c02 | ||
|
|
2a03448b3f | ||
|
|
9734a7f3d5 | ||
|
|
e207f2febd | ||
|
|
9f821a01f0 | ||
|
|
9a04665c34 | ||
|
|
ab2a58bf42 | ||
|
|
32bcbac979 | ||
|
|
757ac6303b | ||
|
|
20ba2b9e0a | ||
|
|
99006627a4 | ||
|
|
7cd25fbb22 | ||
|
|
76a1b05056 | ||
|
|
b7ffa153b1 |
43
.github/workflows/cmake-windows.yml
vendored
Normal file
43
.github/workflows/cmake-windows.yml
vendored
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
name: CMake Windows Build
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
env:
|
||||||
|
BUILD_TYPE: Release
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
windows-build:
|
||||||
|
runs-on: windows-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
submodules: 'true'
|
||||||
|
|
||||||
|
- name: Restore artifacts, or run vcpkg, build and cache artifacts
|
||||||
|
uses: lukka/run-vcpkg@v7
|
||||||
|
id: runvcpkg
|
||||||
|
with:
|
||||||
|
vcpkgArguments: 'discord-rpc zlib nlohmann-json openssl cpp-httplib[openssl]'
|
||||||
|
vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
|
||||||
|
vcpkgGitCommitId: '16ee2ecb31788c336ace8bb14c21801efb6836e4'
|
||||||
|
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: Archive artifacts
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: BeamMP-Launcher.exe
|
||||||
|
path: ${{github.workspace}}/build-windows/Release/BeamMP-Launcher.exe
|
||||||
72
.github/workflows/release-build.yml
vendored
Normal file
72
.github/workflows/release-build.yml
vendored
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
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 nlohmann-json openssl cpp-httplib[openssl]'
|
||||||
|
vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
|
||||||
|
vcpkgGitCommitId: '16ee2ecb31788c336ace8bb14c21801efb6836e4'
|
||||||
|
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
|
||||||
16
.gitignore
vendored
16
.gitignore
vendored
@@ -1,13 +1,7 @@
|
|||||||
cmake-build-debug/CMakeFiles/
|
cmake-build-debug
|
||||||
cmake-build-release/CMakeFiles/
|
cmake-build-release
|
||||||
cmake-build-debug/BeamNG/
|
|
||||||
cmake-build-release/BeamNG/
|
|
||||||
cmake-build-debug/Resources/
|
|
||||||
cmake-build-release/Resources/
|
|
||||||
cmake-build-debug/*.*
|
|
||||||
cmake-build-release/*.*
|
|
||||||
cmake-build-debug/Makefile
|
|
||||||
cmake-build-release/Makefile
|
|
||||||
/.idea/
|
/.idea/
|
||||||
*.log
|
*.log
|
||||||
cmake-build-release/key
|
/*.sh
|
||||||
|
/*.obj
|
||||||
|
/*.exe
|
||||||
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "evpp"]
|
||||||
|
path = evpp
|
||||||
|
url = https://github.com/BeamMP/evpp.git
|
||||||
@@ -1,12 +1,42 @@
|
|||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
project(Launcher)
|
project(Launcher)
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
|
||||||
|
if (WIN32)
|
||||||
|
message(STATUS "MSVC -> forcing use of statically-linked runtime.")
|
||||||
|
STRING(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
|
||||||
|
STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
|
||||||
|
endif(WIN32)
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
file(GLOB source_files "src/*.cpp" "src/*/*.cpp" "src/*/*.hpp" "include/*.h" "include/*/*.h" "include/*/*/*.h")
|
file(GLOB source_files "src/*.cpp" "src/*/*.cpp" "src/*/*.hpp" "include/*.h" "include/*/*.h" "include/*/*/*.h")
|
||||||
|
find_package(httplib CONFIG REQUIRED)
|
||||||
|
find_package(nlohmann_json CONFIG 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")
|
||||||
find_package(ZLIB REQUIRED)
|
|
||||||
find_package(CURL CONFIG REQUIRED)
|
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE ws2_32 rstrtmgr discord-rpc CURL::libcurl ZLIB::ZLIB)
|
if (WIN32)
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
|
find_package(ZLIB REQUIRED)
|
||||||
|
find_package(OpenSSL REQUIRED)
|
||||||
|
#-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static
|
||||||
|
set(VcpkgRoot ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET})
|
||||||
|
include_directories(${VcpkgRoot}/include)
|
||||||
|
link_directories(${VcpkgRoot}/lib)
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||||
|
ZLIB::ZLIB OpenSSL::SSL OpenSSL::Crypto ws2_32 httplib::httplib nlohmann_json::nlohmann_json)
|
||||||
|
|
||||||
|
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE ${VcpkgRoot}/lib/discord-rpc.lib)
|
||||||
|
else ()
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE ${VcpkgRoot}/debug/lib/discord-rpc.lib)
|
||||||
|
endif()
|
||||||
|
else(WIN32) #MINGW
|
||||||
|
add_definitions("-D_WIN32_WINNT=0x0600")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -s --static")
|
||||||
|
target_link_libraries(${PROJECT_NAME} discord-rpc ssl crypto ws2_32 ssp crypt32 z)
|
||||||
|
endif(WIN32)
|
||||||
|
target_include_directories(${PROJECT_NAME} PRIVATE "include")
|
||||||
11
README.md
Normal file → Executable file
11
README.md
Normal file → Executable file
@@ -1 +1,10 @@
|
|||||||
# BeamMP-Launcher
|
# BeamMP-Launcher
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
|
||||||
|
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,
|
||||||
|
the only permission that has been granted is to use the software in its compiled form as distributed from the BeamMP.com website.
|
||||||
|
Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||||
|
|||||||
1
evpp
Submodule
1
evpp
Submodule
Submodule evpp added at 44e10774e2
0
include/Discord/discord_info.h
Normal file → Executable file
0
include/Discord/discord_info.h
Normal file → Executable file
@@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <stdint.h>
|
#include <cstdint>
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
||||||
|
|||||||
13
include/Curl/http.h → include/Http.h
Normal file → Executable file
13
include/Curl/http.h → include/Http.h
Normal file → Executable file
@@ -7,6 +7,13 @@
|
|||||||
///
|
///
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
int Download(const std::string& URL,const std::string& Path,bool close);
|
#include "Logger.h"
|
||||||
std::string PostHTTP(const std::string& IP, const std::string& Fields);
|
class HTTP {
|
||||||
std::string HTTP_REQUEST(const std::string& IP,int port);
|
public:
|
||||||
|
static bool Download(const std::string &IP, const std::string &Path);
|
||||||
|
static std::string Post(const std::string& IP, const std::string& Fields);
|
||||||
|
static std::string Get(const std::string &IP);
|
||||||
|
static bool ProgressBar(size_t c, size_t t);
|
||||||
|
public:
|
||||||
|
static bool isDownload;
|
||||||
|
};
|
||||||
@@ -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;
|
|
||||||
0
include/Logger.h
Normal file → Executable file
0
include/Logger.h
Normal file → Executable file
11
include/Network/network.h
Normal file → Executable file
11
include/Network/network.h
Normal file → Executable file
@@ -5,12 +5,18 @@
|
|||||||
///
|
///
|
||||||
/// Created by Anonymous275 on 7/18/2020
|
/// Created by Anonymous275 on 7/18/2020
|
||||||
///
|
///
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
void NetReset();
|
void NetReset();
|
||||||
extern bool Dev;
|
extern bool Dev;
|
||||||
extern int ping;
|
extern int ping;
|
||||||
void CoreNetwork();
|
|
||||||
|
extern bool ModWarningConfirmed;
|
||||||
|
|
||||||
|
[[noreturn]] void CoreNetwork();
|
||||||
|
extern int ProxyPort;
|
||||||
extern int ClientID;
|
extern int ClientID;
|
||||||
extern int LastPort;
|
extern int LastPort;
|
||||||
extern bool ModLoaded;
|
extern bool ModLoaded;
|
||||||
@@ -18,11 +24,13 @@ extern bool Terminate;
|
|||||||
extern int DEFAULT_PORT;
|
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 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 PrivateKey;
|
||||||
extern std::string ListOfMods;
|
extern std::string ListOfMods;
|
||||||
int KillSocket(uint64_t Dead);
|
int KillSocket(uint64_t Dead);
|
||||||
void UUl(const std::string& R);
|
void UUl(const std::string& R);
|
||||||
@@ -40,3 +48,4 @@ 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);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
0
include/Security/Game.h
Normal file → Executable file
0
include/Security/Game.h
Normal file → Executable file
2
include/Security/Init.h
Normal file → Executable file
2
include/Security/Init.h
Normal file → Executable file
@@ -7,7 +7,7 @@
|
|||||||
///
|
///
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
void PreGame(int argc, char* argv[],const std::string& GamePath);
|
void PreGame(const std::string& GamePath);
|
||||||
std::string CheckVer(const std::string &path);
|
std::string CheckVer(const std::string &path);
|
||||||
void InitGame(const std::string& Dir);
|
void InitGame(const std::string& Dir);
|
||||||
std::string GetGameDir();
|
std::string GetGameDir();
|
||||||
|
|||||||
17
include/Startup.h
Normal file → Executable file
17
include/Startup.h
Normal file → Executable file
@@ -7,9 +7,22 @@
|
|||||||
///
|
///
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <compare>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
void InitLauncher(int argc, char* argv[]);
|
void InitLauncher(int argc, char* argv[]);
|
||||||
void CheckDir(int argc,char* args[]);
|
std::string GetEP(char*P = nullptr);
|
||||||
std::string GetGamePath();
|
std::string GetGamePath();
|
||||||
std::string GetVer();
|
std::string GetVer();
|
||||||
std::string GetEN();
|
std::string GetEN();
|
||||||
extern bool Dev;
|
void StartProxy();
|
||||||
|
void ConfigInit();
|
||||||
|
extern bool Dev;
|
||||||
|
|
||||||
|
struct VersionParser {
|
||||||
|
explicit VersionParser(const std::string& from_string);
|
||||||
|
std::strong_ordering operator<=>(VersionParser const& rhs) const noexcept;
|
||||||
|
bool operator==(VersionParser const& rhs) const noexcept;
|
||||||
|
std::vector<std::string> split;
|
||||||
|
std::vector<size_t> data;
|
||||||
|
};
|
||||||
|
|||||||
0
include/Zlib/Compressor.h
Normal file → Executable file
0
include/Zlib/Compressor.h
Normal file → Executable file
4642
include/hashpp.h
Normal file
4642
include/hashpp.h
Normal file
File diff suppressed because it is too large
Load Diff
0
include/rapidjson/allocators.h
Normal file → Executable file
0
include/rapidjson/allocators.h
Normal file → Executable file
0
include/rapidjson/cursorstreamwrapper.h
Normal file → Executable file
0
include/rapidjson/cursorstreamwrapper.h
Normal file → Executable file
0
include/rapidjson/document.h
Normal file → Executable file
0
include/rapidjson/document.h
Normal file → Executable file
0
include/rapidjson/encodedstream.h
Normal file → Executable file
0
include/rapidjson/encodedstream.h
Normal file → Executable file
0
include/rapidjson/encodings.h
Normal file → Executable file
0
include/rapidjson/encodings.h
Normal file → Executable file
0
include/rapidjson/error/en.h
Normal file → Executable file
0
include/rapidjson/error/en.h
Normal file → Executable file
0
include/rapidjson/error/error.h
Normal file → Executable file
0
include/rapidjson/error/error.h
Normal file → Executable file
0
include/rapidjson/filereadstream.h
Normal file → Executable file
0
include/rapidjson/filereadstream.h
Normal file → Executable file
0
include/rapidjson/filewritestream.h
Normal file → Executable file
0
include/rapidjson/filewritestream.h
Normal file → Executable file
0
include/rapidjson/fwd.h
Normal file → Executable file
0
include/rapidjson/fwd.h
Normal file → Executable file
0
include/rapidjson/internal/biginteger.h
Normal file → Executable file
0
include/rapidjson/internal/biginteger.h
Normal file → Executable file
0
include/rapidjson/internal/clzll.h
Normal file → Executable file
0
include/rapidjson/internal/clzll.h
Normal file → Executable file
0
include/rapidjson/internal/diyfp.h
Normal file → Executable file
0
include/rapidjson/internal/diyfp.h
Normal file → Executable file
0
include/rapidjson/internal/dtoa.h
Normal file → Executable file
0
include/rapidjson/internal/dtoa.h
Normal file → Executable file
0
include/rapidjson/internal/ieee754.h
Normal file → Executable file
0
include/rapidjson/internal/ieee754.h
Normal file → Executable file
0
include/rapidjson/internal/itoa.h
Normal file → Executable file
0
include/rapidjson/internal/itoa.h
Normal file → Executable file
0
include/rapidjson/internal/meta.h
Normal file → Executable file
0
include/rapidjson/internal/meta.h
Normal file → Executable file
0
include/rapidjson/internal/pow10.h
Normal file → Executable file
0
include/rapidjson/internal/pow10.h
Normal file → Executable file
0
include/rapidjson/internal/regex.h
Normal file → Executable file
0
include/rapidjson/internal/regex.h
Normal file → Executable file
0
include/rapidjson/internal/stack.h
Normal file → Executable file
0
include/rapidjson/internal/stack.h
Normal file → Executable file
0
include/rapidjson/internal/strfunc.h
Normal file → Executable file
0
include/rapidjson/internal/strfunc.h
Normal file → Executable file
0
include/rapidjson/internal/strtod.h
Normal file → Executable file
0
include/rapidjson/internal/strtod.h
Normal file → Executable file
0
include/rapidjson/internal/swap.h
Normal file → Executable file
0
include/rapidjson/internal/swap.h
Normal file → Executable file
0
include/rapidjson/istreamwrapper.h
Normal file → Executable file
0
include/rapidjson/istreamwrapper.h
Normal file → Executable file
0
include/rapidjson/memorybuffer.h
Normal file → Executable file
0
include/rapidjson/memorybuffer.h
Normal file → Executable file
0
include/rapidjson/memorystream.h
Normal file → Executable file
0
include/rapidjson/memorystream.h
Normal file → Executable file
0
include/rapidjson/msinttypes/inttypes.h
Normal file → Executable file
0
include/rapidjson/msinttypes/inttypes.h
Normal file → Executable file
0
include/rapidjson/msinttypes/stdint.h
Normal file → Executable file
0
include/rapidjson/msinttypes/stdint.h
Normal file → Executable file
0
include/rapidjson/ostreamwrapper.h
Normal file → Executable file
0
include/rapidjson/ostreamwrapper.h
Normal file → Executable file
0
include/rapidjson/pointer.h
Normal file → Executable file
0
include/rapidjson/pointer.h
Normal file → Executable file
0
include/rapidjson/prettywriter.h
Normal file → Executable file
0
include/rapidjson/prettywriter.h
Normal file → Executable file
0
include/rapidjson/rapidjson.h
Normal file → Executable file
0
include/rapidjson/rapidjson.h
Normal file → Executable file
0
include/rapidjson/reader.h
Normal file → Executable file
0
include/rapidjson/reader.h
Normal file → Executable file
0
include/rapidjson/schema.h
Normal file → Executable file
0
include/rapidjson/schema.h
Normal file → Executable file
0
include/rapidjson/stream.h
Normal file → Executable file
0
include/rapidjson/stream.h
Normal file → Executable file
0
include/rapidjson/stringbuffer.h
Normal file → Executable file
0
include/rapidjson/stringbuffer.h
Normal file → Executable file
0
include/rapidjson/writer.h
Normal file → Executable file
0
include/rapidjson/writer.h
Normal file → Executable file
24
include/winmain-inl.h
Normal file
24
include/winmain-inl.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
struct OnApp {
|
||||||
|
OnApp() {
|
||||||
|
#ifdef WIN32
|
||||||
|
// Initialize Winsock 2.2
|
||||||
|
WSADATA wsaData;
|
||||||
|
int err = WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
std::cout << "WSAStartup() failed with error: %d" << err;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
~OnApp() {
|
||||||
|
#ifdef WIN32
|
||||||
|
WSACleanup();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
} __s_onexit_pause;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
5710
include/zip_file.h
Normal file
5710
include/zip_file.h
Normal file
File diff suppressed because it is too large
Load Diff
0
src/Compressor.cpp
Normal file → Executable file
0
src/Compressor.cpp
Normal file → Executable file
58
src/Config.cpp
Executable file
58
src/Config.cpp
Executable file
@@ -0,0 +1,58 @@
|
|||||||
|
///
|
||||||
|
/// Created by Anonymous275 on 2/23/2021
|
||||||
|
///
|
||||||
|
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include "Network/network.h"
|
||||||
|
#include <filesystem>
|
||||||
|
#include "Logger.h"
|
||||||
|
#include <fstream>
|
||||||
|
#include <cstdint>
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
std::string Branch;
|
||||||
|
void ParseConfig(const nlohmann::json& d){
|
||||||
|
if(d["Port"].is_number()){
|
||||||
|
DEFAULT_PORT = d["Port"].get<int>();
|
||||||
|
}
|
||||||
|
//Default -1
|
||||||
|
//Release 1
|
||||||
|
//EA 2
|
||||||
|
//Dev 3
|
||||||
|
//Custom 3
|
||||||
|
|
||||||
|
if(d["Build"].is_string()){
|
||||||
|
Branch = d["Build"].get<std::string>();
|
||||||
|
for(char& c : Branch)c = char(tolower(c));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigInit(){
|
||||||
|
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"
|
||||||
|
})";
|
||||||
|
cfg.close();
|
||||||
|
}else{
|
||||||
|
fatal("Failed to write config on disk!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
6
src/Discord.cpp
Normal file → Executable file
6
src/Discord.cpp
Normal file → Executable file
@@ -7,7 +7,7 @@
|
|||||||
///
|
///
|
||||||
#include "Discord/discord_rpc.h"
|
#include "Discord/discord_rpc.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <iostream>
|
#include <cstring>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
@@ -99,8 +99,8 @@ void ErrorAboard(){
|
|||||||
exit(6);
|
exit(6);
|
||||||
}
|
}
|
||||||
void Discord_Main(){
|
void Discord_Main(){
|
||||||
std::thread t1(DMain);
|
/*std::thread t1(DMain);
|
||||||
t1.detach();
|
t1.detach();*/
|
||||||
/*info("Connecting to discord client...");
|
/*info("Connecting to discord client...");
|
||||||
int C = 0;
|
int C = 0;
|
||||||
while(DiscordInfo == nullptr && C < 80){
|
while(DiscordInfo == nullptr && C < 80){
|
||||||
|
|||||||
25
src/GameStart.cpp
Normal file → Executable file
25
src/GameStart.cpp
Normal file → Executable file
@@ -6,11 +6,10 @@
|
|||||||
/// Created by Anonymous275 on 7/19/2020
|
/// Created by Anonymous275 on 7/19/2020
|
||||||
///
|
///
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Security/Init.h>
|
||||||
|
#include <windows.h>
|
||||||
#include "Startup.h"
|
#include "Startup.h"
|
||||||
#include <ShlObj.h>
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <iostream>
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
unsigned long GamePID = 0;
|
unsigned long GamePID = 0;
|
||||||
@@ -23,21 +22,22 @@ std::string GetGamePath(){
|
|||||||
LPCTSTR sk = "Software\\BeamNG\\BeamNG.drive";
|
LPCTSTR sk = "Software\\BeamNG\\BeamNG.drive";
|
||||||
LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
|
LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
|
||||||
if (openRes != ERROR_SUCCESS){
|
if (openRes != ERROR_SUCCESS){
|
||||||
fatal("Please launch the game at least once");
|
fatal("Please launch the game at least once!");
|
||||||
}
|
}
|
||||||
Path = QueryKey(hKey,4);
|
Path = QueryKey(hKey,4);
|
||||||
|
|
||||||
if(Path.empty()){
|
if(Path.empty()){
|
||||||
CoInitialize(nullptr);
|
sk = R"(SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)";
|
||||||
wchar_t * path = nullptr;
|
openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
|
||||||
SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_SIMPLE_IDLIST, nullptr, (PWSTR *)(&path));
|
if (openRes != ERROR_SUCCESS){
|
||||||
CoTaskMemFree(path);
|
fatal("Cannot get Local Appdata directory!");
|
||||||
std::wstring ws(path);
|
}
|
||||||
std::string s(ws.begin(), ws.end());
|
Path = QueryKey(hKey,5);
|
||||||
Path = s;
|
|
||||||
Path += "\\BeamNG.drive\\";
|
Path += "\\BeamNG.drive\\";
|
||||||
}
|
}
|
||||||
|
std::string Ver = CheckVer(GetGameDir());
|
||||||
|
Ver = Ver.substr(0,Ver.find('.',Ver.find('.')+1));
|
||||||
|
Path += Ver + "\\";
|
||||||
return Path;
|
return Path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,6 +61,7 @@ void StartGame(std::string Dir){
|
|||||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitGame(const std::string& Dir){
|
void InitGame(const std::string& Dir){
|
||||||
if(!Dev){
|
if(!Dev){
|
||||||
std::thread Game(StartGame, Dir);
|
std::thread Game(StartGame, Dir);
|
||||||
|
|||||||
16
src/Logger.cpp
Normal file → Executable file
16
src/Logger.cpp
Normal file → Executable file
@@ -14,16 +14,8 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
std::string getDate() {
|
std::string getDate() {
|
||||||
typedef std::chrono::duration<int, std::ratio_multiply<std::chrono::hours::period, std::ratio<24>>::type> days;
|
time_t tt = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
||||||
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
|
tm local_tm = *localtime(&tt);
|
||||||
std::chrono::system_clock::duration tp = now.time_since_epoch();
|
|
||||||
days d = std::chrono::duration_cast<days>(tp);tp -= d;
|
|
||||||
auto h = std::chrono::duration_cast<std::chrono::hours>(tp);tp -= h;
|
|
||||||
auto m = std::chrono::duration_cast<std::chrono::minutes>(tp);tp -= m;
|
|
||||||
auto s = std::chrono::duration_cast<std::chrono::seconds>(tp);tp -= s;
|
|
||||||
time_t tt = std::chrono::system_clock::to_time_t(now);
|
|
||||||
tm local_tm{};
|
|
||||||
localtime_s(&local_tm,&tt);
|
|
||||||
std::stringstream date;
|
std::stringstream date;
|
||||||
int S = local_tm.tm_sec;
|
int S = local_tm.tm_sec;
|
||||||
int M = local_tm.tm_min;
|
int M = local_tm.tm_min;
|
||||||
@@ -44,14 +36,14 @@ std::string getDate() {
|
|||||||
}
|
}
|
||||||
void InitLog(){
|
void InitLog(){
|
||||||
std::ofstream LFS;
|
std::ofstream LFS;
|
||||||
LFS.open ("Launcher.log");
|
LFS.open(GetEP() + "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("Launcher.log", std::ios_base::app);
|
LFS.open(GetEP() + "Launcher.log", std::ios_base::app);
|
||||||
LFS << Line.c_str();
|
LFS << Line.c_str();
|
||||||
LFS.close();
|
LFS.close();
|
||||||
}
|
}
|
||||||
|
|||||||
68
src/Network/Core.cpp
Normal file → Executable file
68
src/Network/Core.cpp
Normal file → Executable file
@@ -5,14 +5,16 @@
|
|||||||
///
|
///
|
||||||
/// Created by Anonymous275 on 7/20/2020
|
/// Created by Anonymous275 on 7/20/2020
|
||||||
///
|
///
|
||||||
|
|
||||||
#include "Network/network.h"
|
#include "Network/network.h"
|
||||||
#include "Security/Init.h"
|
#include "Security/Init.h"
|
||||||
|
#include <regex>
|
||||||
#include "Curl/http.h"
|
#include "Http.h"
|
||||||
#include <WinSock2.h>
|
#include <winsock2.h>
|
||||||
#include <WS2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#include "Startup.h"
|
#include "Startup.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
#include <charconv>
|
#include <charconv>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <set>
|
#include <set>
|
||||||
@@ -23,6 +25,8 @@ bool TCPTerminate = false;
|
|||||||
int DEFAULT_PORT = 4444;
|
int DEFAULT_PORT = 4444;
|
||||||
bool Terminate = false;
|
bool Terminate = false;
|
||||||
bool LoginAuth = false;
|
bool LoginAuth = false;
|
||||||
|
std::string Username = "";
|
||||||
|
std::string UserRole = "";
|
||||||
std::string UlStatus;
|
std::string UlStatus;
|
||||||
std::string MStatus;
|
std::string MStatus;
|
||||||
bool ModLoaded;
|
bool ModLoaded;
|
||||||
@@ -47,6 +51,15 @@ void StartSync(const std::string &Data){
|
|||||||
GS.detach();
|
GS.detach();
|
||||||
info("Connecting to server");
|
info("Connecting to server");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsAllowedLink(const std::string& Link) {
|
||||||
|
std::regex link_pattern(R"(https:\/\/(?:\w+)?(?:\.)?(?:beammp\.com|discord\.gg))");
|
||||||
|
std::smatch link_match;
|
||||||
|
return std::regex_search(Link,link_match, link_pattern) && link_match.position() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ModWarningConfirmed = false;
|
||||||
|
|
||||||
void Parse(std::string Data,SOCKET CSocket){
|
void Parse(std::string Data,SOCKET CSocket){
|
||||||
char Code = Data.at(0), SubCode = 0;
|
char Code = Data.at(0), SubCode = 0;
|
||||||
if(Data.length() > 1)SubCode = Data.at(1);
|
if(Data.length() > 1)SubCode = Data.at(1);
|
||||||
@@ -58,7 +71,7 @@ void Parse(std::string Data,SOCKET CSocket){
|
|||||||
NetReset();
|
NetReset();
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
TCPTerminate = true;
|
TCPTerminate = true;
|
||||||
Data = Code + HTTP_REQUEST("https://beammp.com/servers-info",443);
|
Data = Code + HTTP::Get("https://backend.beammp.com/servers-info");
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
ListOfMods.clear();
|
ListOfMods.clear();
|
||||||
@@ -69,6 +82,27 @@ void Parse(std::string Data,SOCKET CSocket){
|
|||||||
if(ListOfMods == "-")Data = "L";
|
if(ListOfMods == "-")Data = "L";
|
||||||
else Data = "L"+ListOfMods;
|
else Data = "L"+ListOfMods;
|
||||||
break;
|
break;
|
||||||
|
case 'O': //open default browser with URL
|
||||||
|
if(IsAllowedLink(Data.substr(1))) {
|
||||||
|
ShellExecuteA(nullptr, "open", Data.substr(1).c_str(), nullptr, nullptr,SW_SHOW); ///TODO: Look at when working on linux port
|
||||||
|
info("Opening Link \"" + Data.substr(1) + "\"");
|
||||||
|
}
|
||||||
|
Data.clear();
|
||||||
|
break;
|
||||||
|
// response to "WMODS_FOUND" message, either Y (yes ok) or N (no)
|
||||||
|
case 'W': {
|
||||||
|
if (SubCode == 'Y') {
|
||||||
|
ModWarningConfirmed = true;
|
||||||
|
} else if (SubCode == 'N') {
|
||||||
|
ModWarningConfirmed = false;
|
||||||
|
NetReset();
|
||||||
|
Terminate = true;
|
||||||
|
TCPTerminate = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 'P':
|
||||||
|
Data = Code + std::to_string(ProxyPort);
|
||||||
|
break;
|
||||||
case 'U':
|
case 'U':
|
||||||
if(SubCode == 'l')Data = UlStatus;
|
if(SubCode == 'l')Data = UlStatus;
|
||||||
if(SubCode == 'p'){
|
if(SubCode == 'p'){
|
||||||
@@ -108,7 +142,16 @@ void Parse(std::string Data,SOCKET CSocket){
|
|||||||
break;
|
break;
|
||||||
case 'N':
|
case 'N':
|
||||||
if (SubCode == 'c'){
|
if (SubCode == 'c'){
|
||||||
Data = "N{\"Auth\":"+std::to_string(LoginAuth)+"}";
|
nlohmann::json Auth = {
|
||||||
|
{"Auth", LoginAuth ? 1 : 0 },
|
||||||
|
};
|
||||||
|
if (!Username.empty()) {
|
||||||
|
Auth["username"] = Username;
|
||||||
|
}
|
||||||
|
if (!UserRole.empty()) {
|
||||||
|
Auth["role"] = UserRole;
|
||||||
|
}
|
||||||
|
Data = "N" + Auth.dump();
|
||||||
}else{
|
}else{
|
||||||
Data = "N" + Login(Data.substr(Data.find(':') + 1));
|
Data = "N" + Login(Data.substr(Data.find(':') + 1));
|
||||||
}
|
}
|
||||||
@@ -175,6 +218,10 @@ void localRes(){
|
|||||||
}
|
}
|
||||||
ConfList = new std::set<std::string>;
|
ConfList = new std::set<std::string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint64_t TheClientSocket;
|
||||||
|
|
||||||
void CoreMain() {
|
void CoreMain() {
|
||||||
debug("Core Network on start!");
|
debug("Core Network on start!");
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
@@ -223,6 +270,7 @@ void CoreMain() {
|
|||||||
error("(Core) accept failed with error: " + std::to_string(WSAGetLastError()));
|
error("(Core) accept failed with error: " + std::to_string(WSAGetLastError()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
TheClientSocket = CSocket;
|
||||||
localRes();
|
localRes();
|
||||||
info("Game Connected!");
|
info("Game Connected!");
|
||||||
GameHandler(CSocket);
|
GameHandler(CSocket);
|
||||||
@@ -240,11 +288,15 @@ int Handle(EXCEPTION_POINTERS *ep){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CoreNetwork(){
|
[[noreturn]] void CoreNetwork(){
|
||||||
while(TraceBack >= 4){
|
while(true) {
|
||||||
|
#ifndef __MINGW32__
|
||||||
__try{
|
__try{
|
||||||
|
#endif
|
||||||
CoreMain();
|
CoreMain();
|
||||||
|
#ifndef __MINGW32__
|
||||||
}__except(Handle(GetExceptionInformation())){}
|
}__except(Handle(GetExceptionInformation())){}
|
||||||
|
#endif
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
src/Network/DNS.cpp
Normal file → Executable file
2
src/Network/DNS.cpp
Normal file → Executable file
@@ -7,7 +7,7 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <winsock.h>
|
#include <winsock2.h>
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
|
||||||
std::string GetAddr(const std::string&IP){
|
std::string GetAddr(const std::string&IP){
|
||||||
|
|||||||
10
src/Network/GlobalHandler.cpp
Normal file → Executable file
10
src/Network/GlobalHandler.cpp
Normal file → Executable file
@@ -6,17 +6,15 @@
|
|||||||
/// Created by Anonymous275 on 7/25/2020
|
/// Created by Anonymous275 on 7/25/2020
|
||||||
///
|
///
|
||||||
#include "Network/network.h"
|
#include "Network/network.h"
|
||||||
#include "Security/Init.h"
|
#include <winsock2.h>
|
||||||
|
#include <ws2tcpip.h>
|
||||||
#include <WinSock2.h>
|
|
||||||
#include <WS2tcpip.h>
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <charconv>
|
#include <charconv>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
std::chrono::time_point<std::chrono::steady_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;
|
||||||
@@ -77,7 +75,7 @@ void ServerSend(std::string Data, bool Rel){
|
|||||||
int DLen = int(Data.length());
|
int DLen = int(Data.length());
|
||||||
if(DLen > 3)C = Data.at(0);
|
if(DLen > 3)C = Data.at(0);
|
||||||
if (C == 'O' || C == 'T')Ack = true;
|
if (C == 'O' || C == 'T')Ack = true;
|
||||||
if(C == 'W' || C == 'Y' || C == 'V' || C == 'E')Rel = true;
|
if(C == 'N' || C == 'W' || C == 'Y' || C == 'V' || C == 'E' || C == 'C')Rel = true;
|
||||||
if(Ack || Rel){
|
if(Ack || Rel){
|
||||||
if(Ack || DLen > 1000)SendLarge(Data);
|
if(Ack || DLen > 1000)SendLarge(Data);
|
||||||
else TCPSend(Data,TCPSock);
|
else TCPSend(Data,TCPSock);
|
||||||
|
|||||||
237
src/Network/Http.cpp
Normal file → Executable file
237
src/Network/Http.cpp
Normal file → Executable file
@@ -1,115 +1,122 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
// Copyright (c) 2019-present Anonymous275.
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
// 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.
|
// 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.
|
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||||
///
|
///
|
||||||
/// Created by Anonymous275 on 7/18/2020
|
/// Created by Anonymous275 on 7/18/2020
|
||||||
///
|
///
|
||||||
|
#define CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
#include "Security/Game.h"
|
|
||||||
|
#include <iostream>
|
||||||
#include <curl/curl.h>
|
#include <Logger.h>
|
||||||
#include <iostream>
|
#include <fstream>
|
||||||
#include <mutex>
|
#include "Http.h"
|
||||||
|
#include <mutex>
|
||||||
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp){
|
#include <cmath>
|
||||||
((std::string*)userp)->append((char*)contents, size * nmemb);
|
#include <httplib.h>
|
||||||
return size * nmemb;
|
|
||||||
}
|
bool HTTP::isDownload = false;
|
||||||
|
std::string HTTP::Get(const std::string &IP) {
|
||||||
std::string HTTP_REQUEST(const std::string& IP,int port){
|
static std::mutex Lock;
|
||||||
static std::mutex Lock;
|
std::scoped_lock Guard(Lock);
|
||||||
Lock.lock();
|
|
||||||
CURL *curl;
|
auto pos = IP.find('/',10);
|
||||||
CURLcode res;
|
|
||||||
std::string readBuffer;
|
httplib::Client cli(IP.substr(0, pos).c_str());
|
||||||
curl = curl_easy_init();
|
cli.set_connection_timeout(std::chrono::seconds(10));
|
||||||
if(curl) {
|
cli.set_follow_location(true);
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, IP.c_str());
|
auto res = cli.Get(IP.substr(pos).c_str(), ProgressBar);
|
||||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
|
std::string Ret;
|
||||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
|
|
||||||
curl_easy_setopt(curl, CURLOPT_PORT, port);
|
if(res){
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
if(res->status == 200){
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
|
Ret = res->body;
|
||||||
res = curl_easy_perform(curl);
|
}else error(res->reason);
|
||||||
curl_easy_cleanup(curl);
|
|
||||||
if(res != CURLE_OK)return "-1";
|
}else{
|
||||||
}
|
if(isDownload) {
|
||||||
Lock.unlock();
|
std::cout << "\n";
|
||||||
return readBuffer;
|
}
|
||||||
}
|
error("HTTP Get failed on " + to_string(res.error()));
|
||||||
|
}
|
||||||
int nb_bar;
|
|
||||||
double last_progress, progress_bar_adv;
|
return Ret;
|
||||||
int progress_bar (void *bar, double t, double d){
|
}
|
||||||
if(last_progress != round(d/t*100)){
|
|
||||||
nb_bar = 25;
|
std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
|
||||||
progress_bar_adv = round(d/t*nb_bar);
|
static std::mutex Lock;
|
||||||
std::cout<<"\r";
|
std::scoped_lock Guard(Lock);
|
||||||
std::cout<< "Progress : [ ";
|
|
||||||
if(t!=0)std::cout<<round(d/t*100);else std::cout<<0;
|
auto pos = IP.find('/',10);
|
||||||
std::cout << "% ] [";
|
|
||||||
int i;
|
httplib::Client cli(IP.substr(0, pos).c_str());
|
||||||
for(i = 0; i <= progress_bar_adv; i++)std::cout<<"#";
|
cli.set_connection_timeout(std::chrono::seconds(10));
|
||||||
for(i = 0; i < nb_bar - progress_bar_adv; i++)std::cout<<".";
|
std::string Ret;
|
||||||
std::cout<<"]";
|
|
||||||
last_progress = round(d/t*100);
|
if(!Fields.empty()) {
|
||||||
}
|
httplib::Result res = cli.Post(IP.substr(pos).c_str(), Fields, "application/json");
|
||||||
return 0;
|
|
||||||
}
|
if(res) {
|
||||||
struct File {
|
if (res->status != 200) {
|
||||||
const char *filename;
|
error(res->reason);
|
||||||
FILE *stream;
|
}
|
||||||
};
|
Ret = res->body;
|
||||||
static size_t my_fwrite(void *buffer,size_t size,size_t nmemb,void *stream){
|
}else{
|
||||||
auto *out = (struct File*)stream;
|
error("HTTP Post failed on " + to_string(res.error()));
|
||||||
if(!out->stream) {
|
}
|
||||||
fopen_s(&out->stream,out->filename,"wb");
|
}else{
|
||||||
if(!out->stream)return -1;
|
httplib::Result res = cli.Post(IP.substr(pos).c_str());
|
||||||
}
|
if(res) {
|
||||||
return fwrite(buffer, size, nmemb, out->stream);
|
if (res->status != 200) {
|
||||||
}
|
error(res->reason);
|
||||||
int Download(const std::string& URL,const std::string& Path,bool close){
|
}
|
||||||
CURL *curl;
|
Ret = res->body;
|
||||||
CURLcode res;
|
}else{
|
||||||
struct File file = {Path.c_str(),nullptr};
|
error("HTTP Post failed on " + to_string(res.error()));
|
||||||
curl = curl_easy_init();
|
}
|
||||||
if(curl){
|
}
|
||||||
curl_easy_setopt(curl, CURLOPT_URL,URL.c_str());
|
|
||||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
|
if(Ret.empty())return "-1";
|
||||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
|
else return Ret;
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
|
}
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &file);
|
|
||||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);
|
bool HTTP::ProgressBar(size_t c, size_t t){
|
||||||
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_bar);
|
if(isDownload) {
|
||||||
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
|
static double last_progress, progress_bar_adv;
|
||||||
res = curl_easy_perform(curl);
|
progress_bar_adv = round(c / double(t) * 25);
|
||||||
curl_easy_cleanup(curl);
|
std::cout << "\r";
|
||||||
if(res != CURLE_OK)return res;
|
std::cout << "Progress : [ ";
|
||||||
}
|
std::cout << round(c / double(t) * 100);
|
||||||
if(file.stream)fclose(file.stream);
|
std::cout << "% ] [";
|
||||||
std::cout << std::endl;
|
int i;
|
||||||
return -1;
|
for (i = 0; i <= progress_bar_adv; i++)std::cout << "#";
|
||||||
}
|
for (i = 0; i < 25 - progress_bar_adv; i++)std::cout << ".";
|
||||||
std::string PostHTTP(const std::string& IP, const std::string& Fields) {
|
std::cout << "]";
|
||||||
static auto *header = new curl_slist{(char*)"Content-Type: application/json"};
|
last_progress = round(c / double(t) * 100);
|
||||||
CURL* curl;
|
}
|
||||||
CURLcode res;
|
return true;
|
||||||
std::string readBuffer;
|
}
|
||||||
curl = curl_easy_init();
|
|
||||||
if (curl) {
|
bool HTTP::Download(const std::string &IP, const std::string &Path) {
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, IP.c_str());
|
static std::mutex Lock;
|
||||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
|
std::scoped_lock Guard(Lock);
|
||||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, Fields.size());
|
|
||||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, Fields.c_str());
|
isDownload = true;
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
std::string Ret = Get(IP);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
|
isDownload = false;
|
||||||
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
|
||||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 5);
|
if(Ret.empty())return false;
|
||||||
res = curl_easy_perform(curl);
|
|
||||||
curl_easy_cleanup(curl);
|
std::ofstream File(Path, std::ios::binary);
|
||||||
if (res != CURLE_OK)
|
if(File.is_open()) {
|
||||||
return "-1";
|
File << Ret;
|
||||||
}
|
File.close();
|
||||||
return readBuffer;
|
std::cout << "\n";
|
||||||
}
|
info("Download Complete!");
|
||||||
|
}else{
|
||||||
|
error("Failed to open file directory: " + Path);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
75
src/Network/Resources.cpp
Normal file → Executable file
75
src/Network/Resources.cpp
Normal file → Executable file
@@ -7,8 +7,7 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
#include "Network/network.h"
|
#include "Network/network.h"
|
||||||
|
#include <ws2tcpip.h>
|
||||||
#include <WS2tcpip.h>
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include "Startup.h"
|
#include "Startup.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
@@ -20,8 +19,11 @@
|
|||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <future>
|
#include <future>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
namespace fs = std::experimental::filesystem;
|
extern SOCKET TheClientSocket;
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
std::string ListOfMods;
|
std::string ListOfMods;
|
||||||
std::vector<std::string> Split(const std::string& String,const std::string& delimiter){
|
std::vector<std::string> Split(const std::string& String,const std::string& delimiter){
|
||||||
std::vector<std::string> Val;
|
std::vector<std::string> Val;
|
||||||
@@ -37,8 +39,7 @@ std::vector<std::string> Split(const std::string& String,const std::string& deli
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CheckForDir(){
|
void CheckForDir(){
|
||||||
struct stat info{};
|
if(!fs::exists("Resources")){
|
||||||
if(stat( "Resources", &info) != 0){
|
|
||||||
_wmkdir(L"Resources");
|
_wmkdir(L"Resources");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,7 +62,7 @@ std::string Auth(SOCKET Sock){
|
|||||||
|
|
||||||
auto Res = TCPRcv(Sock);
|
auto Res = TCPRcv(Sock);
|
||||||
|
|
||||||
if(Res.empty() || Res[0] == 'E'){
|
if(Res.empty() || Res[0] == 'E' || Res[0] == 'K'){
|
||||||
Abord();
|
Abord();
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -88,7 +89,7 @@ std::string Auth(SOCKET Sock){
|
|||||||
|
|
||||||
Res = TCPRcv(Sock);
|
Res = TCPRcv(Sock);
|
||||||
|
|
||||||
if(Res[0] == 'E'){
|
if(Res[0] == 'E' || Res[0] == 'K'){
|
||||||
Abord();
|
Abord();
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -103,18 +104,17 @@ std::string Auth(SOCKET Sock){
|
|||||||
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)UlStatus = "UlDownloading Resource " + msg;
|
||||||
else UlStatus = "UlLoading Resource " + msg;
|
else UlStatus = "UlLoading Resource " + msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsyncUpdate(uint64_t& Rcv,uint64_t Size,const std::string& Name){
|
void AsyncUpdate(uint64_t& Rcv,uint64_t Size,const std::string& Name){
|
||||||
do {
|
do {
|
||||||
double pr = 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) + "%)");
|
UpdateUl(true, Name + " (" + Per.substr(0, Per.find('.') + 2) + "%)");
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,11 +126,10 @@ char* TCPRcvRaw(SOCKET Sock,uint64_t& GRcv, uint64_t Size){
|
|||||||
}
|
}
|
||||||
char* File = new char[Size];
|
char* File = new char[Size];
|
||||||
uint64_t Rcv = 0;
|
uint64_t Rcv = 0;
|
||||||
int32_t Temp;
|
|
||||||
do{
|
do{
|
||||||
int Len = int(Size-Rcv);
|
int Len = int(Size-Rcv);
|
||||||
if(Len > 1000000)Len = 1000000;
|
if(Len > 1000000)Len = 1000000;
|
||||||
Temp = recv(Sock, &File[Rcv], Len, MSG_WAITALL);
|
int32_t Temp = recv(Sock, &File[Rcv], Len, MSG_WAITALL);
|
||||||
if(Temp < 1){
|
if(Temp < 1){
|
||||||
info(std::to_string(Temp));
|
info(std::to_string(Temp));
|
||||||
UUl("Socket Closed Code 1");
|
UUl("Socket Closed Code 1");
|
||||||
@@ -153,6 +152,7 @@ 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);
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -177,8 +177,7 @@ std::string MultiDownload(SOCKET MSock,SOCKET DSock, uint64_t Size, const std::s
|
|||||||
|
|
||||||
uint64_t GRcv = 0, MSize = Size/2, DSize = Size - MSize;
|
uint64_t GRcv = 0, MSize = Size/2, DSize = Size - MSize;
|
||||||
|
|
||||||
std::thread Au(AsyncUpdate,std::ref(GRcv),Size,Name);
|
std::thread Au(AsyncUpdate,std::ref(GRcv), Size, Name);
|
||||||
Au.detach();
|
|
||||||
|
|
||||||
std::packaged_task<char*()> task([&] { return TCPRcvRaw(MSock,GRcv,MSize); });
|
std::packaged_task<char*()> task([&] { return TCPRcvRaw(MSock,GRcv,MSize); });
|
||||||
std::future<char*> f1 = task.get_future();
|
std::future<char*> f1 = task.get_future();
|
||||||
@@ -199,6 +198,7 @@ std::string MultiDownload(SOCKET MSock,SOCKET DSock, uint64_t Size, const std::s
|
|||||||
MultiKill(MSock,DSock);
|
MultiKill(MSock,DSock);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Au.joinable())Au.join();
|
if(Au.joinable())Au.join();
|
||||||
|
|
||||||
|
|
||||||
@@ -213,11 +213,33 @@ std::string MultiDownload(SOCKET MSock,SOCKET DSock, uint64_t Size, const std::s
|
|||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InvalidResource(const std::string& File){
|
||||||
|
UUl("Invalid mod \"" + File + "\"");
|
||||||
|
warn("The server tried to sync \"" + File + "\" that is not a .zip file!");
|
||||||
|
Terminate = true;
|
||||||
|
}
|
||||||
|
|
||||||
void SyncResources(SOCKET Sock){
|
void SyncResources(SOCKET Sock){
|
||||||
std::string Ret = Auth(Sock);
|
std::string Ret = Auth(Sock);
|
||||||
if(Ret.empty())return;
|
if(Ret.empty())return;
|
||||||
|
|
||||||
|
ModWarningConfirmed = false;
|
||||||
|
Terminate = false;
|
||||||
|
|
||||||
|
std::string Data = "WMODS_FOUND";
|
||||||
|
send(TheClientSocket, (Data + "\n").c_str(), int(Data.size())+1, 0);
|
||||||
|
|
||||||
|
while (!Terminate && !ModWarningConfirmed) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ModWarningConfirmed) {
|
||||||
|
UlStatus = "UlMods rejected!";
|
||||||
|
info("Mods rejected by user!");
|
||||||
|
// game has already cancelled by now
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
info("Checking Resources...");
|
info("Checking Resources...");
|
||||||
CheckForDir();
|
CheckForDir();
|
||||||
|
|
||||||
@@ -239,10 +261,16 @@ void SyncResources(SOCKET Sock){
|
|||||||
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");
|
||||||
|
if (ZIP == std::string::npos || FN->length() - ZIP != 4) {
|
||||||
|
InvalidResource(*FN);
|
||||||
|
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();
|
||||||
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) {
|
||||||
@@ -251,15 +279,17 @@ void SyncResources(SOCKET Sock){
|
|||||||
Pos++;
|
Pos++;
|
||||||
if (fs::exists(a)) {
|
if (fs::exists(a)) {
|
||||||
if (FS->find_first_not_of("0123456789") != std::string::npos)continue;
|
if (FS->find_first_not_of("0123456789") != std::string::npos)continue;
|
||||||
if (fs::file_size(a) == std::stoi(*FS)){
|
if (fs::file_size(a) == std::stoull(*FS)){
|
||||||
UpdateUl(false,std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + a.substr(a.find_last_of('/')));
|
UpdateUl(false,std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + a.substr(a.find_last_of('/')));
|
||||||
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() + "mods/multiplayer")){
|
||||||
fs::create_directory(GetGamePath() + "mods/multiplayer");
|
fs::create_directories(GetGamePath() + "mods/multiplayer");
|
||||||
}
|
}
|
||||||
fs::copy_file(a, GetGamePath() + "mods/multiplayer" + a.substr(a.find_last_of('/')),
|
auto name = GetGamePath() + "mods/multiplayer" + a.substr(a.find_last_of('/'));
|
||||||
fs::copy_options::overwrite_existing);
|
auto tmp_name = name + ".tmp";
|
||||||
|
fs::copy_file(a,tmp_name,fs::copy_options::overwrite_existing);
|
||||||
|
fs::rename(tmp_name, name);
|
||||||
} 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;
|
||||||
@@ -271,7 +301,6 @@ void SyncResources(SOCKET Sock){
|
|||||||
}
|
}
|
||||||
CheckForDir();
|
CheckForDir();
|
||||||
std::string FName = a.substr(a.find_last_of('/'));
|
std::string FName = a.substr(a.find_last_of('/'));
|
||||||
SOCKET DSock = InitDSock();
|
|
||||||
do {
|
do {
|
||||||
TCPSend("f" + *FN,Sock);
|
TCPSend("f" + *FN,Sock);
|
||||||
|
|
||||||
@@ -295,16 +324,16 @@ void SyncResources(SOCKET Sock){
|
|||||||
LFS.close();
|
LFS.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}while(fs::file_size(a) != std::stoi(*FS) && !Terminate);
|
}while(fs::file_size(a) != std::stoull(*FS) && !Terminate);
|
||||||
KillSocket(DSock);
|
|
||||||
if(!Terminate){
|
if(!Terminate){
|
||||||
if(!fs::exists(GetGamePath() + "mods/multiplayer")){
|
if(!fs::exists(GetGamePath() + "mods/multiplayer")){
|
||||||
fs::create_directory(GetGamePath() + "mods/multiplayer");
|
fs::create_directories(GetGamePath() + "mods/multiplayer");
|
||||||
}
|
}
|
||||||
fs::copy_file(a,GetGamePath() + "mods/multiplayer" + FName, fs::copy_options::overwrite_existing);
|
fs::copy_file(a,GetGamePath() + "mods/multiplayer" + FName, fs::copy_options::overwrite_existing);
|
||||||
}
|
}
|
||||||
WaitForConfirm();
|
WaitForConfirm();
|
||||||
}
|
}
|
||||||
|
KillSocket(DSock);
|
||||||
if(!Terminate){
|
if(!Terminate){
|
||||||
TCPSend("Done",Sock);
|
TCPSend("Done",Sock);
|
||||||
info("Done!");
|
info("Done!");
|
||||||
@@ -312,4 +341,4 @@ void SyncResources(SOCKET Sock){
|
|||||||
UlStatus = "Ulstart";
|
UlStatus = "Ulstart";
|
||||||
info("Connection Terminated!");
|
info("Connection Terminated!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
src/Network/VehicleData.cpp
Normal file → Executable file
2
src/Network/VehicleData.cpp
Normal file → Executable file
@@ -8,7 +8,7 @@
|
|||||||
#include "Zlib/Compressor.h"
|
#include "Zlib/Compressor.h"
|
||||||
#include "Network/network.h"
|
#include "Network/network.h"
|
||||||
|
|
||||||
#include <WS2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|||||||
11
src/Network/VehicleEvent.cpp
Normal file → Executable file
11
src/Network/VehicleEvent.cpp
Normal file → Executable file
@@ -10,7 +10,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <WS2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#include <Zlib/Compressor.h>
|
#include <Zlib/Compressor.h>
|
||||||
|
|
||||||
#include "Network/network.h"
|
#include "Network/network.h"
|
||||||
@@ -109,7 +109,7 @@ std::string TCPRcv(SOCKET Sock){
|
|||||||
#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')UUl(Ret.substr(1));
|
if(Ret[0] == 'E' || Ret[0] == 'K')UUl(Ret.substr(1));
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,15 +133,16 @@ void TCPClientMain(const std::string& IP,int Port){
|
|||||||
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!";
|
||||||
std::cout << "Client: connect failed! Error code: " << WSAGetLastError() << std::endl;
|
error("Client: connect failed! Error code: " + std::to_string(WSAGetLastError()));
|
||||||
KillSocket(TCPSock);
|
KillSocket(TCPSock);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
getsockname(TCPSock, (SOCKADDR *)&ServerAddr, (int *)sizeof(ServerAddr));
|
info("Connected!");
|
||||||
|
|
||||||
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));
|
||||||
|
|||||||
610
src/Security/BeamNG.cpp
Normal file → Executable file
610
src/Security/BeamNG.cpp
Normal file → Executable file
@@ -1,292 +1,318 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
// Copyright (c) 2019-present Anonymous275.
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
// 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.
|
// 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.
|
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||||
///
|
///
|
||||||
/// Created by Anonymous275 on 7/18/2020
|
/// Created by Anonymous275 on 7/18/2020
|
||||||
///
|
///
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <Windows.h>
|
#include <windows.h>
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#define MAX_KEY_LENGTH 255
|
#define MAX_KEY_LENGTH 255
|
||||||
#define MAX_VALUE_NAME 16383
|
#define MAX_VALUE_NAME 16383
|
||||||
|
|
||||||
int TraceBack = 0;
|
int TraceBack = 0;
|
||||||
std::string GameDir;
|
std::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){
|
/*void Exit(int code){
|
||||||
TraceBack = 0;
|
TraceBack = 0;
|
||||||
std::string msg =
|
std::string msg =
|
||||||
"Sorry. We do not support cracked copies report this if you believe this is a mistake code ";
|
"Sorry. We do not support cracked copies report this if you believe this is a mistake 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(3);
|
exit(3);
|
||||||
}
|
}
|
||||||
void SteamExit(int code){
|
void SteamExit(int code){
|
||||||
TraceBack = 0;
|
TraceBack = 0;
|
||||||
std::string msg =
|
std::string msg =
|
||||||
"Illegal steam modifications detected report this if you believe this is a mistake code ";
|
"Illegal steam modifications detected report this if you believe this is a mistake 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(4);
|
exit(4);
|
||||||
}
|
}*/
|
||||||
std::string GetGameDir(){
|
std::string GetGameDir(){
|
||||||
if(TraceBack != 4)Exit(0);
|
//if(TraceBack != 4)Exit(0);
|
||||||
return GameDir.substr(0,GameDir.find_last_of('\\'));
|
return GameDir.substr(0,GameDir.find_last_of('\\'));
|
||||||
}
|
}
|
||||||
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::string QueryKey(HKEY hKey,int ID){
|
||||||
TCHAR achKey[MAX_KEY_LENGTH]; // buffer for subkey name
|
TCHAR achKey[MAX_KEY_LENGTH]; // 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];
|
TCHAR achValue[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 = RegEnumKeyEx(hKey, i,achKey,&cbName,nullptr,nullptr,nullptr,&ftLastWriteTime);
|
||||||
if (retCode == ERROR_SUCCESS){
|
if (retCode == ERROR_SUCCESS){
|
||||||
if(strcmp(achKey,"Steam App 284160") == 0){
|
if(strcmp(achKey,"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 = RegEnumValue(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 = RegQueryValueEx(hKey, achValue, nullptr, nullptr, buffer, &lpData);
|
||||||
std::string data = reinterpret_cast<const char *const>(buffer);
|
std::string data = (char *)(buffer);
|
||||||
std::string key = achValue;
|
std::string key = achValue;
|
||||||
switch (ID){
|
|
||||||
case 1: if(key == "SteamExe"){
|
switch (ID){
|
||||||
auto p = data.find_last_of('/');
|
case 1: if(key == "SteamExe"){
|
||||||
if(p != std::string::npos)return data.substr(0,p);
|
auto p = data.find_last_of("/\\");
|
||||||
}break;
|
if(p != std::string::npos){
|
||||||
case 2: if(key == "Name" && data == "BeamNG.drive")return data;break;
|
return data.substr(0,p);
|
||||||
case 3: if(key == "rootpath")return data;break;
|
}
|
||||||
case 4: if(key == "userpath_override")return data;
|
}
|
||||||
default: break;
|
break;
|
||||||
}
|
case 2: if(key == "Name" && data == "BeamNG.drive")return data;break;
|
||||||
}
|
case 3: if(key == "rootpath")return data;break;
|
||||||
}
|
case 4: if(key == "userpath_override")return data;
|
||||||
}
|
case 5: if(key == "Local AppData")return data;
|
||||||
delete [] buffer;
|
default: break;
|
||||||
return "";
|
}
|
||||||
}
|
}
|
||||||
namespace fs = std::experimental::filesystem;
|
}
|
||||||
void FileList(std::vector<std::string>&a,const std::string& Path){
|
}
|
||||||
for (const auto &entry : fs::directory_iterator(Path)) {
|
delete [] buffer;
|
||||||
auto pos = entry.path().filename().string().find('.');
|
return "";
|
||||||
if (pos != std::string::npos) {
|
}
|
||||||
a.emplace_back(entry.path().string());
|
namespace fs = std::filesystem;
|
||||||
}else FileList(a,entry.path().string());
|
|
||||||
}
|
bool NameValid(const std::string& N){
|
||||||
}
|
if(N == "config" || N == "librarycache"){
|
||||||
bool Find(const std::string& FName,const std::string& Path){
|
return true;
|
||||||
std::vector<std::string> FS;
|
}
|
||||||
FileList(FS,Path+"/userdata");
|
if(N.find_first_not_of("0123456789") == std::string::npos){
|
||||||
for(std::string&a : FS){
|
return true;
|
||||||
if(a.find(FName) != std::string::npos){
|
}
|
||||||
FS.clear();
|
return false;
|
||||||
return true;
|
}
|
||||||
}
|
void FileList(std::vector<std::string>&a,const std::string& Path){
|
||||||
}
|
for (const auto &entry : fs::directory_iterator(Path)) {
|
||||||
FS.clear();
|
const auto& DPath = entry.path();
|
||||||
return false;
|
if (!entry.is_directory()) {
|
||||||
}
|
a.emplace_back(DPath.string());
|
||||||
bool FindHack(const std::string& Path){
|
}else if(NameValid(DPath.filename().string())){
|
||||||
bool s = true;
|
FileList(a, DPath.string());
|
||||||
for (const auto &entry : fs::directory_iterator(Path)) {
|
}
|
||||||
std::string Name = entry.path().filename().string();
|
}
|
||||||
for(char&c : Name)c = char(tolower(c));
|
}
|
||||||
if(Name == "steam.exe")s = false;
|
bool Find(const std::string& FName,const std::string& Path){
|
||||||
if(Name.find("greenluma") != -1)return true;
|
std::vector<std::string> FS;
|
||||||
Name.clear();
|
FileList(FS,Path+"\\userdata");
|
||||||
}
|
for(std::string&a : FS){
|
||||||
return s;
|
if(a.find(FName) != std::string::npos){
|
||||||
}
|
FS.clear();
|
||||||
std::vector<std::string> GetID(const std::string& log){
|
return true;
|
||||||
std::string vec,t,r;
|
}
|
||||||
std::vector<std::string> Ret;
|
}
|
||||||
std::ifstream f(log.c_str(), std::ios::binary);
|
FS.clear();
|
||||||
f.seekg(0, std::ios_base::end);
|
return false;
|
||||||
std::streampos fileSize = f.tellg();
|
}
|
||||||
vec.resize(size_t(fileSize) + 1);
|
bool FindHack(const std::string& Path){
|
||||||
f.seekg(0, std::ios_base::beg);
|
bool s = true;
|
||||||
f.read(&vec[0], fileSize);
|
for (const auto &entry : fs::directory_iterator(Path)) {
|
||||||
f.close();
|
std::string Name = entry.path().filename().string();
|
||||||
std::stringstream ss(vec);
|
for(char&c : Name)c = char(tolower(c));
|
||||||
bool S = false;
|
if(Name == "steam.exe")s = false;
|
||||||
while (std::getline(ss, t, '{')) {
|
if(Name.find("greenluma") != -1){
|
||||||
if(!S)S = true;
|
error("Found malicious file/folder \"" + Name+"\"");
|
||||||
else{
|
return true;
|
||||||
for(char& c : t){
|
}
|
||||||
if(isdigit(c))r += c;
|
Name.clear();
|
||||||
}
|
}
|
||||||
break;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
std::vector<std::string> GetID(const std::string& log){
|
||||||
Ret.emplace_back(r);
|
std::string vec,t,r;
|
||||||
r.clear();
|
std::vector<std::string> Ret;
|
||||||
S = false;
|
std::ifstream f(log.c_str(), std::ios::binary);
|
||||||
bool L = true;
|
f.seekg(0, std::ios_base::end);
|
||||||
while (std::getline(ss, t, '}')) {
|
std::streampos fileSize = f.tellg();
|
||||||
if(L){
|
vec.resize(size_t(fileSize) + 1);
|
||||||
L = false;
|
f.seekg(0, std::ios_base::beg);
|
||||||
continue;
|
f.read(&vec[0], fileSize);
|
||||||
}
|
f.close();
|
||||||
for(char& c : t){
|
std::stringstream ss(vec);
|
||||||
if(c == '"'){
|
bool S = false;
|
||||||
if(!S)S = true;
|
while (std::getline(ss, t, '{')) {
|
||||||
else{
|
if(!S)S = true;
|
||||||
if(r.length() > 10) {
|
else{
|
||||||
Ret.emplace_back(r);
|
for(char& c : t){
|
||||||
}
|
if(isdigit(c))r += c;
|
||||||
r.clear();
|
}
|
||||||
S = false;
|
break;
|
||||||
continue;
|
}
|
||||||
}
|
}
|
||||||
}
|
Ret.emplace_back(r);
|
||||||
if(isdigit(c))r += c;
|
r.clear();
|
||||||
}
|
S = false;
|
||||||
}
|
bool L = true;
|
||||||
vec.clear();
|
while (std::getline(ss, t, '}')) {
|
||||||
return Ret;
|
if(L){
|
||||||
}
|
L = false;
|
||||||
std::string GetManifest(const std::string& Man){
|
continue;
|
||||||
std::string vec;
|
}
|
||||||
std::ifstream f(Man.c_str(), std::ios::binary);
|
for(char& c : t){
|
||||||
f.seekg(0, std::ios_base::end);
|
if(c == '"'){
|
||||||
std::streampos fileSize = f.tellg();
|
if(!S)S = true;
|
||||||
vec.resize(size_t(fileSize) + 1);
|
else{
|
||||||
f.seekg(0, std::ios_base::beg);
|
if(r.length() > 10) {
|
||||||
f.read(&vec[0], fileSize);
|
Ret.emplace_back(r);
|
||||||
f.close();
|
}
|
||||||
std::string ToFind = "\"LastOwner\"\t\t\"";
|
r.clear();
|
||||||
int pos = int(vec.find(ToFind));
|
S = false;
|
||||||
if(pos != -1){
|
continue;
|
||||||
pos += int(ToFind.length());
|
}
|
||||||
vec = vec.substr(pos);
|
}
|
||||||
return vec.substr(0,vec.find('\"'));
|
if(isdigit(c))r += c;
|
||||||
}else return "";
|
}
|
||||||
}
|
}
|
||||||
bool IDCheck(std::string Man, std::string steam){
|
vec.clear();
|
||||||
bool a = false,b = true;
|
return Ret;
|
||||||
int pos = int(Man.rfind("steamapps"));
|
}
|
||||||
if(pos == -1)Exit(5);
|
std::string GetManifest(const std::string& Man){
|
||||||
Man = Man.substr(0,pos+9) + "/appmanifest_284160.acf";
|
std::string vec;
|
||||||
steam += "/config/loginusers.vdf";
|
std::ifstream f(Man.c_str(), std::ios::binary);
|
||||||
if(fs::exists(Man) && fs::exists(steam)){
|
f.seekg(0, std::ios_base::end);
|
||||||
for(const std::string&ID : GetID(steam)){
|
std::streampos fileSize = f.tellg();
|
||||||
if(ID == GetManifest(Man))b = false;
|
vec.resize(size_t(fileSize) + 1);
|
||||||
}
|
f.seekg(0, std::ios_base::beg);
|
||||||
if(b)Exit(6);
|
f.read(&vec[0], fileSize);
|
||||||
}else a = true;
|
f.close();
|
||||||
return a;
|
std::string ToFind = "\"LastOwner\"\t\t\"";
|
||||||
}
|
int pos = int(vec.find(ToFind));
|
||||||
void LegitimacyCheck(){
|
if(pos != -1){
|
||||||
std::string Result,T;
|
pos += int(ToFind.length());
|
||||||
std::string K1 = R"(Software\Valve\Steam)";
|
vec = vec.substr(pos);
|
||||||
std::string K2 = R"(Software\Valve\Steam\Apps\284160)";
|
return vec.substr(0,vec.find('\"'));
|
||||||
std::string K3 = R"(Software\BeamNG\BeamNG.drive)";
|
}else return "";
|
||||||
HKEY hKey;
|
}
|
||||||
LONG dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K1.c_str(), &hKey);
|
bool IDCheck(std::string Man, std::string steam){
|
||||||
if(dwRegOPenKey == ERROR_SUCCESS) {
|
bool a = false,b = true;
|
||||||
Result = QueryKey(hKey, 1);
|
int pos = int(Man.rfind("steamapps"));
|
||||||
if(Result.empty())Exit(1);
|
// if(pos == -1)Exit(5);
|
||||||
if(fs::exists(Result)){
|
Man = Man.substr(0,pos+9) + "\\appmanifest_284160.acf";
|
||||||
if(!Find("284160.json",Result))Exit(2);
|
steam += "\\config\\loginusers.vdf";
|
||||||
if(FindHack(Result))SteamExit(1);
|
if(fs::exists(Man) && fs::exists(steam)){
|
||||||
}else Exit(3);
|
for(const std::string&ID : GetID(steam)){
|
||||||
T = Result;
|
if(ID == GetManifest(Man))b = false;
|
||||||
Result.clear();
|
}
|
||||||
TraceBack++;
|
//if(b)Exit(6);
|
||||||
}else Exit(4);
|
}else a = true;
|
||||||
K1.clear();
|
return a;
|
||||||
RegCloseKey(hKey);
|
}
|
||||||
dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K2.c_str(), &hKey);
|
void LegitimacyCheck(){
|
||||||
if(dwRegOPenKey == ERROR_SUCCESS) {
|
|
||||||
Result = QueryKey(hKey, 2);
|
//std::string K1 = R"(Software\Valve\Steam)";
|
||||||
if(Result.empty())lowExit(1);
|
//std::string K2 = R"(Software\Valve\Steam\Apps\284160)";
|
||||||
TraceBack++;
|
|
||||||
}else lowExit(2);
|
/*LONG dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K1.c_str(), &hKey);
|
||||||
K2.clear();
|
|
||||||
RegCloseKey(hKey);
|
if(dwRegOPenKey == ERROR_SUCCESS) {
|
||||||
dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K3.c_str(), &hKey);
|
Result = QueryKey(hKey, 1);
|
||||||
if(dwRegOPenKey == ERROR_SUCCESS) {
|
if(Result.empty())Exit(1);
|
||||||
Result = QueryKey(hKey, 3);
|
|
||||||
if(Result.empty())lowExit(3);
|
if(fs::exists(Result)){
|
||||||
if(IDCheck(Result,T))lowExit(5);
|
if(!Find("284160.json",Result))Exit(2);
|
||||||
GameDir = Result;
|
if(FindHack(Result))SteamExit(1);
|
||||||
TraceBack++;
|
}else Exit(3);
|
||||||
}else lowExit(4);
|
|
||||||
K3.clear();
|
T = Result;
|
||||||
Result.clear();
|
Result.clear();
|
||||||
RegCloseKey(hKey);
|
TraceBack++;
|
||||||
if(TraceBack < 3)exit(-1);
|
}else Exit(4);
|
||||||
}
|
|
||||||
std::string CheckVer(const std::string &dir){
|
K1.clear();
|
||||||
std::string temp,Path = dir + "\\integrity.json";
|
RegCloseKey(hKey);
|
||||||
std::ifstream f(Path.c_str(), std::ios::binary);
|
dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K2.c_str(), &hKey);
|
||||||
int Size = int(std::filesystem::file_size(Path));
|
if(dwRegOPenKey == ERROR_SUCCESS) {
|
||||||
std::string vec(Size,0);
|
Result = QueryKey(hKey, 2);
|
||||||
f.read(&vec[0], Size);
|
if(Result.empty())lowExit(1);
|
||||||
f.close();
|
TraceBack++;
|
||||||
|
}else lowExit(2);
|
||||||
vec = vec.substr(vec.find_last_of("version"),vec.find_last_of('"'));
|
K2.clear();
|
||||||
for(const char &a : vec){
|
RegCloseKey(hKey);*/
|
||||||
if(isdigit(a) || a == '.')temp+=a;
|
std::string Result;
|
||||||
}
|
std::string K3 = R"(Software\BeamNG\BeamNG.drive)";
|
||||||
return temp;
|
HKEY hKey;
|
||||||
}
|
LONG dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K3.c_str(), &hKey);
|
||||||
|
if(dwRegOPenKey == ERROR_SUCCESS) {
|
||||||
|
Result = QueryKey(hKey, 3);
|
||||||
|
if(Result.empty())lowExit(3);
|
||||||
|
//if(IDCheck(Result,T))lowExit(5);
|
||||||
|
GameDir = Result;
|
||||||
|
//TraceBack++;
|
||||||
|
}else lowExit(4);
|
||||||
|
K3.clear();
|
||||||
|
Result.clear();
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
//if(TraceBack < 3)exit(-1);
|
||||||
|
}
|
||||||
|
std::string CheckVer(const std::string &dir){
|
||||||
|
std::string temp,Path = dir + "\\integrity.json";
|
||||||
|
std::ifstream f(Path.c_str(), std::ios::binary);
|
||||||
|
int Size = int(std::filesystem::file_size(Path));
|
||||||
|
std::string vec(Size,0);
|
||||||
|
f.read(&vec[0], Size);
|
||||||
|
f.close();
|
||||||
|
|
||||||
|
vec = vec.substr(vec.find_last_of("version"),vec.find_last_of('"'));
|
||||||
|
for(const char &a : vec){
|
||||||
|
if(isdigit(a) || a == '.')temp+=a;
|
||||||
|
}
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|||||||
235
src/Security/Login.cpp
Normal file → Executable file
235
src/Security/Login.cpp
Normal file → Executable file
@@ -1,94 +1,141 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
// Copyright (c) 2019-present Anonymous275.
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
// 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.
|
// 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.
|
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
|
||||||
///
|
///
|
||||||
/// Created by Anonymous275 on 11/26/2020
|
/// Created by Anonymous275 on 11/26/2020
|
||||||
///
|
///
|
||||||
|
|
||||||
#include "Curl/http.h"
|
#include <nlohmann/json.hpp>
|
||||||
#include <filesystem>
|
#include "Http.h"
|
||||||
#include "Logger.h"
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include "Logger.h"
|
||||||
#include "Json.h"
|
#include <fstream>
|
||||||
|
|
||||||
using namespace std::filesystem;
|
|
||||||
std::string PublicKey;
|
namespace fs = std::filesystem;
|
||||||
extern bool LoginAuth;
|
std::string PublicKey;
|
||||||
|
std::string PrivateKey;
|
||||||
void UpdateKey(const char* newKey){
|
extern bool LoginAuth;
|
||||||
if(newKey){
|
extern std::string Username;
|
||||||
std::ofstream Key("key");
|
extern std::string UserRole;
|
||||||
if(Key.is_open()){
|
|
||||||
Key << newKey;
|
void UpdateKey(const char* newKey){
|
||||||
Key.close();
|
if(newKey && std::isalnum(newKey[0])){
|
||||||
}else fatal("Cannot write to disk!");
|
PrivateKey = newKey;
|
||||||
}else if(exists("key")){
|
std::ofstream Key("key");
|
||||||
remove("key");
|
if(Key.is_open()){
|
||||||
}
|
Key << newKey;
|
||||||
}
|
Key.close();
|
||||||
|
}else fatal("Cannot write to disk!");
|
||||||
/// "username":"value","password":"value"
|
}else if(fs::exists("key")){
|
||||||
/// "Guest":"Name"
|
remove("key");
|
||||||
/// "pk":"private_key"
|
}
|
||||||
|
}
|
||||||
std::string Login(const std::string& fields){
|
|
||||||
info("Attempting to authenticate...");
|
/// "username":"value","password":"value"
|
||||||
std::string Buffer = PostHTTP("https://auth.beammp.com/userlogin", fields);
|
/// "Guest":"Name"
|
||||||
json::Document d;
|
/// "pk":"private_key"
|
||||||
d.Parse(Buffer.c_str());
|
|
||||||
if(Buffer == "-1"){
|
std::string GetFail(const std::string& R){
|
||||||
fatal("Failed to communicate with the auth system!");
|
std::string DRet = R"({"success":false,"message":)";
|
||||||
}
|
DRet += "\""+R+"\"}";
|
||||||
if (Buffer.find('{') == -1 || d.HasParseError()) {
|
error(R);
|
||||||
fatal("Invalid answer from authentication servers, please try again later!");
|
return DRet;
|
||||||
}
|
}
|
||||||
if(!d["success"].IsNull() && d["success"].GetBool()){
|
|
||||||
LoginAuth = true;
|
std::string Login(const std::string& fields){
|
||||||
if(!d["private_key"].IsNull()){
|
if(fields == "LO"){
|
||||||
UpdateKey(d["private_key"].GetString());
|
Username = "";
|
||||||
}
|
UserRole = "";
|
||||||
if(!d["public_key"].IsNull()){
|
LoginAuth = false;
|
||||||
PublicKey = d["public_key"].GetString();
|
UpdateKey(nullptr);
|
||||||
}
|
return "";
|
||||||
info("Authentication successful!");
|
}
|
||||||
}else info("Authentication failed!");
|
info("Attempting to authenticate...");
|
||||||
if(!d["message"].IsNull()){
|
try {
|
||||||
d.RemoveMember("private_key");
|
std::string Buffer = HTTP::Post("https://auth.beammp.com/userlogin", fields);
|
||||||
d.RemoveMember("public_key");
|
|
||||||
rapidjson::StringBuffer buffer;
|
if(Buffer == "-1"){
|
||||||
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
return GetFail("Failed to communicate with the auth system!");
|
||||||
d.Accept(writer);
|
}
|
||||||
return buffer.GetString();
|
|
||||||
}
|
nlohmann::json d = nlohmann::json::parse(Buffer, nullptr, false);
|
||||||
return "{\"success\":false}";
|
|
||||||
}
|
if (Buffer.at(0) != '{' || d.is_discarded()) {
|
||||||
|
error(Buffer);
|
||||||
void CheckLocalKey(){
|
return GetFail("Invalid answer from authentication servers, please try again later!");
|
||||||
if(exists("key") && file_size("key") < 100){
|
}
|
||||||
std::ifstream Key("key");
|
if(d.contains("success") && d["success"].get<bool>()){
|
||||||
if(Key.is_open()) {
|
LoginAuth = true;
|
||||||
auto Size = file_size("key");
|
if (d.contains("username")) {
|
||||||
std::string Buffer(Size, 0);
|
Username = d["username"].get<std::string>();
|
||||||
Key.read(&Buffer[0], Size);
|
}
|
||||||
Key.close();
|
if (d.contains("role")) {
|
||||||
Buffer = PostHTTP("https://auth.beammp.com/userlogin", R"({"pk":")"+Buffer+"\"}");
|
UserRole = d["role"].get<std::string>();
|
||||||
json::Document d;
|
}
|
||||||
d.Parse(Buffer.c_str());
|
if(d.contains("private_key")) {
|
||||||
if (Buffer == "-1" || Buffer.find('{') == -1 || d.HasParseError()) {
|
UpdateKey(d["private_key"].get<std::string>().c_str());
|
||||||
fatal("Invalid answer from authentication servers, please try again later!");
|
}
|
||||||
}
|
if(d.contains("public_key")){
|
||||||
if(d["success"].GetBool()){
|
PublicKey = d["public_key"].get<std::string>();
|
||||||
LoginAuth = true;
|
}
|
||||||
UpdateKey(d["private_key"].GetString());
|
info("Authentication successful!");
|
||||||
PublicKey = d["public_key"].GetString();
|
}else info("Authentication failed!");
|
||||||
}else{
|
if(d.contains("message")){
|
||||||
info("Auto-Authentication unsuccessful please re-login!");
|
d.erase("private_key");
|
||||||
UpdateKey(nullptr);
|
d.erase("public_key");
|
||||||
}
|
return d.dump();
|
||||||
}else{
|
}
|
||||||
warn("Could not open saved key!");
|
return GetFail("Invalid message parsing!");
|
||||||
UpdateKey(nullptr);
|
} catch (const std::exception& e) {
|
||||||
}
|
return GetFail(e.what());
|
||||||
}else UpdateKey(nullptr);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CheckLocalKey(){
|
||||||
|
if(fs::exists("key") && fs::file_size("key") < 100){
|
||||||
|
std::ifstream Key("key");
|
||||||
|
if(Key.is_open()) {
|
||||||
|
auto Size = fs::file_size("key");
|
||||||
|
std::string Buffer(Size, 0);
|
||||||
|
Key.read(&Buffer[0], Size);
|
||||||
|
Key.close();
|
||||||
|
|
||||||
|
for (char& c : Buffer) {
|
||||||
|
if (!std::isalnum(c) && c != '-') {
|
||||||
|
UpdateKey(nullptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Buffer = HTTP::Post("https://auth.beammp.com/userlogin", R"({"pk":")" + Buffer + "\"}");
|
||||||
|
|
||||||
|
nlohmann::json d = nlohmann::json::parse(Buffer, nullptr, false);
|
||||||
|
|
||||||
|
if (Buffer == "-1" || 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>();
|
||||||
|
}
|
||||||
|
//info(Role);
|
||||||
|
}else{
|
||||||
|
info("Auto-Authentication unsuccessful please re-login!");
|
||||||
|
UpdateKey(nullptr);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
warn("Could not open saved key!");
|
||||||
|
UpdateKey(nullptr);
|
||||||
|
}
|
||||||
|
}else UpdateKey(nullptr);
|
||||||
|
}
|
||||||
|
|||||||
562
src/Startup.cpp
Normal file → Executable file
562
src/Startup.cpp
Normal file → Executable file
@@ -1,236 +1,326 @@
|
|||||||
// Copyright (c) 2019-present Anonymous275.
|
// Copyright (c) 2019-present Anonymous275.
|
||||||
// BeamMP Launcher code is not in the public domain and is not free software.
|
// 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.
|
// 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.
|
// 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
|
/// Created by Anonymous275 on 7/16/2020
|
||||||
///
|
///
|
||||||
#include "Discord/discord_info.h"
|
|
||||||
#include "Network/network.h"
|
#include <nlohmann/json.hpp>
|
||||||
#include "Security/Init.h"
|
#include <httplib.h>
|
||||||
|
#include "zip_file.h"
|
||||||
#include "Curl/http.h"
|
#include <windows.h>
|
||||||
#include <curl/curl.h>
|
#include "Discord/discord_info.h"
|
||||||
#include <filesystem>
|
#include "Network/network.h"
|
||||||
#include "Startup.h"
|
#include "Security/Init.h"
|
||||||
#include <iostream>
|
#include <filesystem>
|
||||||
#include "Logger.h"
|
#include "Startup.h"
|
||||||
#include <thread>
|
#include "hashpp.h"
|
||||||
|
#include "Logger.h"
|
||||||
extern int TraceBack;
|
#include <fstream>
|
||||||
bool Dev = false;
|
#include <thread>
|
||||||
namespace fs = std::experimental::filesystem;
|
#include "Http.h"
|
||||||
std::string GetEN(){
|
|
||||||
return "BeamMP-Launcher.exe";
|
|
||||||
}
|
extern int TraceBack;
|
||||||
std::string GetVer(){
|
bool Dev = false;
|
||||||
return "1.80";
|
int ProxyPort = 0;
|
||||||
}
|
|
||||||
std::string GetPatch(){
|
namespace fs = std::filesystem;
|
||||||
return "";
|
|
||||||
}
|
VersionParser::VersionParser(const std::string& from_string) {
|
||||||
void ReLaunch(int argc,char*args[]){
|
std::string token;
|
||||||
std::string Arg;
|
std::istringstream tokenStream(from_string);
|
||||||
for(int c = 2; c <= argc; c++){
|
while (std::getline(tokenStream, token, '.')) {
|
||||||
Arg += " ";
|
data.emplace_back(std::stol(token));
|
||||||
Arg += args[c-1];
|
split.emplace_back(token);
|
||||||
}
|
}
|
||||||
system("cls");
|
}
|
||||||
ShellExecute(nullptr,"runas",GetEN().c_str(),Arg.c_str(),nullptr,SW_SHOWNORMAL);
|
|
||||||
ShowWindow(GetConsoleWindow(),0);
|
std::strong_ordering VersionParser::operator<=>(
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
const VersionParser& rhs) const noexcept {
|
||||||
exit(1);
|
size_t const fields = std::min(data.size(), rhs.data.size());
|
||||||
}
|
for (size_t i = 0; i != fields; ++i) {
|
||||||
void URelaunch(int argc,char* args[]){
|
if (data[i] == rhs.data[i]) continue;
|
||||||
std::string Arg;
|
else if (data[i] < rhs.data[i]) return std::strong_ordering::less;
|
||||||
for(int c = 2; c <= argc; c++){
|
else return std::strong_ordering::greater;
|
||||||
Arg += " ";
|
}
|
||||||
Arg += args[c-1];
|
if (data.size() == rhs.data.size()) return std::strong_ordering::equal;
|
||||||
}
|
else if (data.size() > rhs.data.size()) return std::strong_ordering::greater;
|
||||||
ShellExecute(nullptr,"open",GetEN().c_str(),Arg.c_str(),nullptr,SW_SHOWNORMAL);
|
else return std::strong_ordering::less;
|
||||||
ShowWindow(GetConsoleWindow(),0);
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
||||||
exit(1);
|
bool VersionParser::operator==(const VersionParser& rhs) const noexcept {
|
||||||
}
|
return std::is_eq(*this <=> rhs);
|
||||||
void CheckName(int argc,char* args[]){
|
}
|
||||||
struct stat info{};
|
|
||||||
std::string DN = GetEN(),CDir = args[0],FN = CDir.substr(CDir.find_last_of('\\')+1);
|
|
||||||
if(FN != DN){
|
std::string GetEN(){
|
||||||
if(stat(DN.c_str(),&info)==0)remove(DN.c_str());
|
return "BeamMP-Launcher.exe";
|
||||||
if(stat(DN.c_str(),&info)==0)ReLaunch(argc,args);
|
}
|
||||||
std::rename(FN.c_str(), DN.c_str());
|
std::string GetVer(){
|
||||||
URelaunch(argc,args);
|
return "2.0";
|
||||||
}
|
}
|
||||||
}
|
std::string GetPatch(){
|
||||||
|
return ".85";
|
||||||
/// Deprecated
|
}
|
||||||
void RequestRole(){
|
|
||||||
auto NPos = std::string::npos;
|
std::string GetEP(char*P){
|
||||||
std::string HTTP_Result = HTTP_REQUEST("https://beammp.com/entitlement?did="+GetDID()+"&t=l",443);
|
static std::string Ret = [&](){
|
||||||
if(HTTP_Result == "-1"){
|
std::string path(P);
|
||||||
HTTP_Result = HTTP_REQUEST("https://backup1.beammp.com/entitlement?did="+GetDID()+"&t=l",443);
|
return path.substr(0, path.find_last_of("\\/") + 1);
|
||||||
if(HTTP_Result == "-1") {
|
} ();
|
||||||
fatal("Sorry Backend System Outage! Don't worry it will back on soon!");
|
return Ret;
|
||||||
}
|
}
|
||||||
}
|
void ReLaunch(int argc,char*args[]){
|
||||||
if(HTTP_Result.find("\"MDEV\"") != NPos || HTTP_Result.find("\"CON\"") != NPos){
|
std::string Arg;
|
||||||
Dev = true;
|
for(int c = 2; c <= argc; c++){
|
||||||
}
|
Arg += " ";
|
||||||
if(HTTP_Result.find("Error") != NPos){
|
Arg += args[c-1];
|
||||||
fatal("Sorry You need to be in the official BeamMP Discord to proceed! https://discord.gg/beammp");
|
}
|
||||||
}
|
system("cls");
|
||||||
info("Client Connected!");
|
ShellExecute(nullptr,"runas",(GetEP() + GetEN()).c_str(),Arg.c_str(),nullptr,SW_SHOWNORMAL);
|
||||||
}
|
ShowWindow(GetConsoleWindow(),0);
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
void CheckForUpdates(int argc,char*args[],const std::string& CV){
|
exit(1);
|
||||||
std::string link = "https://beammp.com/builds/launcher?version=true";
|
}
|
||||||
std::string HTTP = HTTP_REQUEST(link,443);
|
void URelaunch(int argc,char* args[]){
|
||||||
bool fallback = false;
|
std::string Arg;
|
||||||
if(HTTP.find_first_of("0123456789") == std::string::npos){
|
for(int c = 2; c <= argc; c++){
|
||||||
link = "https://backup1.beammp.com/builds/launcher?version=true";
|
Arg += " ";
|
||||||
HTTP = HTTP_REQUEST(link,443);
|
Arg += args[c-1];
|
||||||
fallback = true;
|
}
|
||||||
if(HTTP.find_first_of("0123456789") == std::string::npos) {
|
ShellExecute(nullptr,"open",(GetEP() + GetEN()).c_str(),Arg.c_str(),nullptr,SW_SHOWNORMAL);
|
||||||
fatal("Primary Servers Offline! sorry for the inconvenience!");
|
ShowWindow(GetConsoleWindow(),0);
|
||||||
}
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
}
|
exit(1);
|
||||||
if(fallback){
|
}
|
||||||
link = "https://backup1.beammp.com/builds/launcher?download=true";
|
void CheckName(int argc,char* args[]){
|
||||||
}else link = "https://beammp.com/builds/launcher?download=true";
|
std::string DN = GetEN(),CDir = args[0],FN = CDir.substr(CDir.find_last_of('\\')+1);
|
||||||
|
if(FN != DN){
|
||||||
struct stat buffer{};
|
if(fs::exists(DN))remove(DN.c_str());
|
||||||
std::string Back = "BeamMP-Launcher.back";
|
if(fs::exists(DN))ReLaunch(argc,args);
|
||||||
if(stat(Back.c_str(), &buffer) == 0)remove(Back.c_str());
|
std::rename(FN.c_str(), DN.c_str());
|
||||||
if(HTTP > CV){
|
URelaunch(argc,args);
|
||||||
system("cls");
|
}
|
||||||
info("Update found!");
|
}
|
||||||
info("Updating...");
|
|
||||||
if(std::rename(GetEN().c_str(), Back.c_str()))error("failed creating a backup!");
|
void CheckForUpdates(int argc, char* args[], const std::string& CV) {
|
||||||
int i = Download(link, GetEN(),true);
|
std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/launcher?branch=" + Branch + "&pk=" + PublicKey);
|
||||||
if(i != -1){
|
std::string LatestVersion = HTTP::Get(
|
||||||
error("Launcher Update failed! trying again... code : " + std::to_string(i));
|
"https://backend.beammp.com/version/launcher?branch=" + Branch + "&pk=" + PublicKey);
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
|
||||||
int i2 = Download(link, GetEN(),true);
|
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
|
||||||
if(i2 != -1){
|
std::string EP(GetEP() + GetEN()), Back(GetEP() + "BeamMP-Launcher.back");
|
||||||
error("Launcher Update failed! code : " + std::to_string(i2));
|
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
std::string FileHash = hashpp::get::getFileHash(hashpp::ALGORITHMS::SHA2_256, EP);
|
||||||
ReLaunch(argc,args);
|
|
||||||
}
|
if (FileHash != LatestHash && VersionParser(LatestVersion) > VersionParser(GetVer()+GetPatch())) {
|
||||||
}
|
info("Launcher update found!");
|
||||||
URelaunch(argc,args);
|
fs::remove(Back);
|
||||||
}else{
|
fs::rename(EP, Back);
|
||||||
info("Version is up to date");
|
info("Downloading Launcher update " + LatestHash);
|
||||||
}
|
HTTP::Download(
|
||||||
TraceBack++;
|
"https://backend.beammp.com/builds/launcher?download=true"
|
||||||
}
|
"&pk=" +
|
||||||
void CheckDir(int argc,char*args[]){
|
PublicKey + "&branch=" + Branch,
|
||||||
std::string CDir = args[0];
|
EP);
|
||||||
std::string MDir = "BeamNG\\mods";
|
URelaunch(argc, args);
|
||||||
if(!fs::is_directory("BeamNG")){
|
} else info("Launcher version is up to date");
|
||||||
if(!fs::create_directory("BeamNG")){
|
TraceBack++;
|
||||||
error("Cannot Create BeamNG Directory! Retrying...");
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
|
||||||
ReLaunch(argc,args);
|
void CustomPort(int argc, char* argv[]){
|
||||||
}
|
if(argc > 1){
|
||||||
}
|
std::string Port = argv[1];
|
||||||
if(fs::is_directory(MDir) && !Dev){
|
if(Port.find_first_not_of("0123456789") == std::string::npos){
|
||||||
int c = 0;
|
if(std::stoi(Port) > 1000){
|
||||||
for (auto& p : fs::directory_iterator(MDir))c++;
|
DEFAULT_PORT = std::stoi(Port);
|
||||||
if(c > 2) {
|
warn("Running on custom port : " + std::to_string(DEFAULT_PORT));
|
||||||
warn(std::to_string(c-1) + " local launcher mods will be wiped! Close this window if you don't want that!");
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(15));
|
}
|
||||||
}
|
if(argc > 2)Dev = true;
|
||||||
try{
|
}
|
||||||
fs::remove_all(MDir);
|
}
|
||||||
} catch (...) {
|
|
||||||
error("Please close the game and try again");
|
void LinuxPatch(){
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
HKEY hKey = nullptr;
|
||||||
exit(1);
|
LONG result = RegOpenKeyEx(HKEY_CURRENT_USER, R"(Software\Wine)", 0, KEY_READ, &hKey);
|
||||||
}
|
if (result != ERROR_SUCCESS || getenv("USER") == nullptr)return;
|
||||||
}
|
RegCloseKey(hKey);
|
||||||
if(fs::is_directory(MDir) && !Dev)ReLaunch(argc,args);
|
info("Wine/Proton Detected! If you are on windows delete HKEY_CURRENT_USER\\Software\\Wine in regedit");
|
||||||
if(!fs::create_directory(MDir) && !Dev){
|
info("Applying patches...");
|
||||||
error("Cannot Create Mods Directory! Retrying...");
|
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
result = RegCreateKey(HKEY_CURRENT_USER, R"(Software\Valve\Steam\Apps\284160)", &hKey);
|
||||||
ReLaunch(argc,args);
|
|
||||||
}
|
if (result != ERROR_SUCCESS){
|
||||||
if(!fs::is_directory("BeamNG\\settings")){
|
fatal(R"(failed to create HKEY_CURRENT_USER\Software\Valve\Steam\Apps\284160)");
|
||||||
if(!fs::create_directory("BeamNG\\settings")){
|
return;
|
||||||
error("Cannot Create Settings Directory! Retrying...");
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
|
||||||
ReLaunch(argc,args);
|
result = RegSetValueEx(hKey, "Name", 0, REG_SZ, (BYTE*)"BeamNG.drive", 12);
|
||||||
}
|
|
||||||
}
|
if (result != ERROR_SUCCESS){
|
||||||
}
|
fatal(R"(failed to create the value "Name" under HKEY_CURRENT_USER\Software\Valve\Steam\Apps\284160)");
|
||||||
void CustomPort(int argc, char* argv[]){
|
return;
|
||||||
if(argc > 1){
|
}
|
||||||
std::string Port = argv[1];
|
RegCloseKey(hKey);
|
||||||
if(Port.find_first_not_of("0123456789") == std::string::npos){
|
|
||||||
if(std::stoi(Port) > 1000){
|
info("Patched!");
|
||||||
DEFAULT_PORT = std::stoi(Port);
|
}
|
||||||
warn("Running on custom port : " + std::to_string(DEFAULT_PORT));
|
|
||||||
}
|
void InitLauncher(int argc, char* argv[]) {
|
||||||
}
|
system("cls");
|
||||||
if(argc > 2)Dev = false;
|
SetConsoleTitleA(("BeamMP Launcher v" + std::string(GetVer()) + GetPatch()).c_str());
|
||||||
}
|
InitLog();
|
||||||
}
|
CheckName(argc, argv);
|
||||||
void InitLauncher(int argc, char* argv[]) {
|
LinuxPatch();
|
||||||
system("cls");
|
CheckLocalKey();
|
||||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
ConfigInit();
|
||||||
SetConsoleTitleA(("BeamMP Launcher v" + std::string(GetVer()) + GetPatch()).c_str());
|
CustomPort(argc, argv);
|
||||||
InitLog();
|
Discord_Main();
|
||||||
CheckName(argc, argv);
|
CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch());
|
||||||
CheckLocalKey(); //will replace RequestRole
|
}
|
||||||
Discord_Main();
|
|
||||||
//RequestRole();
|
size_t DirCount(const std::filesystem::path& path){
|
||||||
CustomPort(argc, argv);
|
return (size_t)std::distance(std::filesystem::directory_iterator{path}, std::filesystem::directory_iterator{});
|
||||||
CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch());
|
}
|
||||||
}
|
|
||||||
|
void CheckMP(const std::string& Path) {
|
||||||
void PreGame(int argc, char* argv[],const std::string& GamePath){
|
if (!fs::exists(Path))return;
|
||||||
info("Game Version : " + CheckVer(GamePath));
|
size_t c = DirCount(fs::path(Path));
|
||||||
std::string DUI = R"(BeamNG\settings\uiapps-layouts.json)";
|
try {
|
||||||
std::string GS = R"(BeamNG\settings\game-settings.ini)";
|
for (auto& p : fs::directory_iterator(Path)){
|
||||||
std::string link = "https://beammp.com/client-ui-data";
|
if(p.exists() && !p.is_directory()){
|
||||||
bool fallback = false;
|
std::string Name = p.path().filename().string();
|
||||||
int i;
|
for(char&Ch : Name)Ch = char(tolower(Ch));
|
||||||
if(!fs::exists(DUI)){
|
if(Name != "beammp.zip")fs::remove(p.path());
|
||||||
info("Downloading default ui data...");
|
}
|
||||||
i = Download(link,DUI,true);
|
}
|
||||||
if(i != -1){
|
} catch (...) {
|
||||||
fallback = true;
|
fatal("We were unable to clean the multiplayer mods folder! Is the game still running or do you have something open in that folder?");
|
||||||
remove(DUI.c_str());
|
}
|
||||||
link = "https://backup1.beammp.com/client-ui-data";
|
|
||||||
i = Download(link,DUI,true);
|
}
|
||||||
if(i != -1) {
|
|
||||||
error("Failed to download code : " + std::to_string(i));
|
void EnableMP(){
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
std::string File(GetGamePath() + "mods/db.json");
|
||||||
ReLaunch(argc, argv);
|
if(!fs::exists(File))return;
|
||||||
}
|
auto Size = fs::file_size(File);
|
||||||
}
|
if(Size < 2)return;
|
||||||
info("Download Complete!");
|
std::ifstream db(File);
|
||||||
}
|
if(db.is_open()) {
|
||||||
if(!fs::exists(GS)) {
|
std::string Data(Size, 0);
|
||||||
info("Downloading default game settings...");
|
db.read(&Data[0], Size);
|
||||||
if(fallback)link = "https://backup1.beammp.com/client-settings-data";
|
db.close();
|
||||||
else link = "https://beammp.com/client-settings-data";
|
nlohmann::json d = nlohmann::json::parse(Data, nullptr, false);
|
||||||
Download(link, GS,true);
|
if(Data.at(0) != '{' || d.is_discarded()) {
|
||||||
info("Download Complete!");
|
//error("Failed to parse " + File); //TODO illegal formatting
|
||||||
}
|
return;
|
||||||
if(!Dev) {
|
}
|
||||||
info("Downloading mod...");
|
if(d.contains("mods") && d["mods"].contains("multiplayerbeammp")){
|
||||||
if(fallback)link = "https://backup1.beammp.com/builds/client";
|
d["mods"]["multiplayerbeammp"]["active"] = true;
|
||||||
else link ="https://beammp.com/builds/client";
|
std::ofstream ofs(File);
|
||||||
if(!fs::exists(GetGamePath() + "mods")){
|
if(ofs.is_open()){
|
||||||
fs::create_directory(GetGamePath() + "mods");
|
ofs << d.dump();
|
||||||
}
|
ofs.close();
|
||||||
if(!fs::exists(GetGamePath() + "mods/multiplayer")){
|
}else{
|
||||||
fs::create_directory(GetGamePath() + "mods/multiplayer");
|
error("Failed to write " + File);
|
||||||
}
|
}
|
||||||
Download(link, GetGamePath() + R"(mods\multiplayer\BeamMP.zip)", true);
|
}
|
||||||
info("Download Complete!");
|
}
|
||||||
}
|
}
|
||||||
/*debug("Name : " + GetDName());
|
|
||||||
debug("Discriminator : " + GetDTag());
|
void PreGame(const std::string& GamePath){
|
||||||
debug("Unique ID : " + GetDID());*/
|
std::string GameVer = CheckVer(GamePath);
|
||||||
}
|
info("Game Version : " + GameVer);
|
||||||
|
|
||||||
|
CheckMP(GetGamePath() + "mods/multiplayer");
|
||||||
|
|
||||||
|
if(!Dev) {
|
||||||
|
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() + "mods/multiplayer")) {
|
||||||
|
fs::create_directories(GetGamePath() + "mods/multiplayer");
|
||||||
|
}
|
||||||
|
EnableMP();
|
||||||
|
}catch(std::exception&e){
|
||||||
|
fatal(e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ZipPath(GetGamePath() + R"(mods\multiplayer\BeamMP.zip)");
|
||||||
|
|
||||||
|
std::string FileHash = hashpp::get::getFileHash(hashpp::ALGORITHMS::SHA2_256, ZipPath);
|
||||||
|
|
||||||
|
if (FileHash != LatestHash) {
|
||||||
|
info("Downloading BeamMP Update " + LatestHash);
|
||||||
|
HTTP::Download("https://backend.beammp.com/builds/client?download=true"
|
||||||
|
"&pk=" + PublicKey + "&branch=" + Branch, ZipPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Target(GetGamePath() + "mods/unpacked/beammp");
|
||||||
|
|
||||||
|
if(fs::is_directory(Target)) {
|
||||||
|
fs::remove_all(Target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 StartProxy() {
|
||||||
|
std::thread proxy([&](){
|
||||||
|
httplib::Server HTTPProxy;
|
||||||
|
httplib::Headers headers = {
|
||||||
|
{"User-Agent", "BeamMP-Launcher/" + GetVer() + GetPatch()},
|
||||||
|
{"Accept", "*/*"}
|
||||||
|
};
|
||||||
|
std::string pattern = "/:any1";
|
||||||
|
for (int i = 2; i <= 4; i++) {
|
||||||
|
HTTPProxy.Get(pattern, [&](const httplib::Request &req, httplib::Response &res) {
|
||||||
|
httplib::Client cli("https://backend.beammp.com");
|
||||||
|
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"));
|
||||||
|
}
|
||||||
|
if (auto cli_res = cli.Get(req.path, headers); 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.Post(pattern, [&](const httplib::Request &req, httplib::Response &res) {
|
||||||
|
httplib::Client cli("https://backend.beammp.com");
|
||||||
|
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"));
|
||||||
|
}
|
||||||
|
if (auto cli_res = cli.Post(req.path, headers, req.body,
|
||||||
|
req.get_header_value("Content-Type")); 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");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
pattern += "/:any" + std::to_string(i);
|
||||||
|
}
|
||||||
|
ProxyPort = HTTPProxy.bind_to_any_port("0.0.0.0");
|
||||||
|
HTTPProxy.listen_after_bind();
|
||||||
|
});
|
||||||
|
proxy.detach();
|
||||||
|
}
|
||||||
|
|||||||
32
src/main.cpp
Normal file → Executable file
32
src/main.cpp
Normal file → Executable file
@@ -8,25 +8,37 @@
|
|||||||
#include "Network/network.h"
|
#include "Network/network.h"
|
||||||
#include "Security/Init.h"
|
#include "Security/Init.h"
|
||||||
#include "Startup.h"
|
#include "Startup.h"
|
||||||
#include <thread>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "Logger.h"
|
||||||
|
#include <thread>
|
||||||
|
#include "Http.h"
|
||||||
|
|
||||||
[[noreturn]] void flush(){
|
[[noreturn]] void flush(){
|
||||||
while(true){
|
while(true){
|
||||||
std::cout.flush();
|
std::cout.flush();
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
std::thread th(flush);
|
std::thread th(flush);
|
||||||
th.detach();
|
th.detach();
|
||||||
#endif
|
#endif
|
||||||
InitLauncher(argc,argv);
|
GetEP(argv[0]);
|
||||||
CheckDir(argc,argv);
|
|
||||||
LegitimacyCheck();
|
InitLauncher(argc, argv);
|
||||||
PreGame(argc,argv,GetGameDir());
|
|
||||||
|
try {
|
||||||
|
LegitimacyCheck();
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
fatal("Main 1 : " + std::string(e.what()));
|
||||||
|
}
|
||||||
|
|
||||||
|
StartProxy();
|
||||||
|
PreGame(GetGameDir());
|
||||||
InitGame(GetGameDir());
|
InitGame(GetGameDir());
|
||||||
CoreNetwork();
|
CoreNetwork();
|
||||||
|
|
||||||
|
///TODO: make sure to use argv[0] for everything that should be in the same dir (mod down ect...)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user