mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-07-15 11:13:45 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e25f2b0382 | |||
| e91fee7186 | |||
| bfe9cfd41b | |||
| d4f40ca889 | |||
| d0431c0b9d | |||
| 0961f86662 | |||
| 7f2ca025f8 |
@@ -3,7 +3,7 @@ name: CMake Windows Build
|
|||||||
on: [push]
|
on: [push]
|
||||||
|
|
||||||
env:
|
env:
|
||||||
BUILD_TYPE: RelWithDebInfo
|
BUILD_TYPE: Release
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
windows-build:
|
windows-build:
|
||||||
@@ -31,7 +31,7 @@ jobs:
|
|||||||
working-directory: ${{github.workspace}}/build-windows
|
working-directory: ${{github.workspace}}/build-windows
|
||||||
env:
|
env:
|
||||||
beammp_sentry_url: ${{ secrets.BEAMMP_SECRET_SENTRY_URL }}
|
beammp_sentry_url: ${{ secrets.BEAMMP_SECRET_SENTRY_URL }}
|
||||||
run: cmake $GITHUB_WORKSPACE -DSENTRY_BACKEND=breakpad -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE='${{ runner.workspace }}/b/vcpkg/scripts/buildsystems/vcpkg.cmake' -DVCPKG_TARGET_TRIPLET=x64-windows-static -DBEAMMP_SECRET_SENTRY_URL="$beammp_sentry_url"
|
run: cmake $GITHUB_WORKSPACE -DSENTRY_BACKEND=breakpad -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_TOOLCHAIN_FILE='${{ runner.workspace }}/b/vcpkg/scripts/buildsystems/vcpkg.cmake' -DVCPKG_TARGET_TRIPLET=x64-windows-static -DBEAMMP_SECRET_SENTRY_URL="$beammp_sentry_url"
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
working-directory: ${{github.workspace}}/build-windows
|
working-directory: ${{github.workspace}}/build-windows
|
||||||
@@ -42,12 +42,6 @@ jobs:
|
|||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v2
|
||||||
with:
|
with:
|
||||||
name: BeamMP-Server.exe
|
name: BeamMP-Server.exe
|
||||||
path: ${{github.workspace}}/build-windows/RelWithDebInfo/BeamMP-Server.exe
|
path: ${{github.workspace}}/build-windows/Release/BeamMP-Server.exe
|
||||||
|
|
||||||
- name: Archive artifacts
|
|
||||||
uses: actions/upload-artifact@v2
|
|
||||||
with:
|
|
||||||
name: BeamMP-Server.pdb
|
|
||||||
path: ${{github.workspace}}/build-windows/RelWithDebInfo/BeamMP-Server.pdb
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+3
-13
@@ -16,7 +16,6 @@ if (WIN32)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
include_directories("include/sentry-native/include")
|
include_directories("include/sentry-native/include")
|
||||||
|
|
||||||
set(SENTRY_BUILD_SHARED_LIBS OFF)
|
set(SENTRY_BUILD_SHARED_LIBS OFF)
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
set(SENTRY_BUILD_RUNTIMESTATIC ON)
|
set(SENTRY_BUILD_RUNTIMESTATIC ON)
|
||||||
@@ -26,7 +25,6 @@ add_subdirectory("include/sentry-native")
|
|||||||
|
|
||||||
message(STATUS "Setting compiler flags")
|
message(STATUS "Setting compiler flags")
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
add_subdirectory("include/watchdog")
|
|
||||||
#-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static
|
#-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static
|
||||||
set(VcpkgRoot ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET})
|
set(VcpkgRoot ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET})
|
||||||
include_directories(${VcpkgRoot}/include)
|
include_directories(${VcpkgRoot}/include)
|
||||||
@@ -67,7 +65,8 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
|
|||||||
message(STATUS "Looking for Boost")
|
message(STATUS "Looking for Boost")
|
||||||
find_package(Boost REQUIRED COMPONENTS system thread)
|
find_package(Boost REQUIRED COMPONENTS system thread)
|
||||||
|
|
||||||
file(GLOB source_files src/main.cpp
|
add_executable(BeamMP-Server
|
||||||
|
src/main.cpp
|
||||||
include/TConsole.h src/TConsole.cpp
|
include/TConsole.h src/TConsole.cpp
|
||||||
include/TServer.h src/TServer.cpp
|
include/TServer.h src/TServer.cpp
|
||||||
include/Compat.h src/Compat.cpp
|
include/Compat.h src/Compat.cpp
|
||||||
@@ -85,8 +84,6 @@ file(GLOB source_files src/main.cpp
|
|||||||
include/TNetwork.h src/TNetwork.cpp
|
include/TNetwork.h src/TNetwork.cpp
|
||||||
include/SignalHandling.h src/SignalHandling.cpp)
|
include/SignalHandling.h src/SignalHandling.cpp)
|
||||||
|
|
||||||
add_executable(BeamMP-Server ${source_files})
|
|
||||||
|
|
||||||
target_compile_definitions(BeamMP-Server PRIVATE SECRET_SENTRY_URL="${BEAMMP_SECRET_SENTRY_URL}")
|
target_compile_definitions(BeamMP-Server PRIVATE SECRET_SENTRY_URL="${BEAMMP_SECRET_SENTRY_URL}")
|
||||||
|
|
||||||
target_include_directories(BeamMP-Server PUBLIC
|
target_include_directories(BeamMP-Server PUBLIC
|
||||||
@@ -121,11 +118,6 @@ if (UNIX)
|
|||||||
sioclient_tls
|
sioclient_tls
|
||||||
sentry)
|
sentry)
|
||||||
elseif (WIN32)
|
elseif (WIN32)
|
||||||
set_source_files_properties(${source_files} PROPERTIES COMPILE_FLAGS "/Gh /GH")
|
|
||||||
add_compile_options("$<$<NOT:$<CONFIG:Debug>>:/Zi>")
|
|
||||||
add_link_options("$<$<NOT:$<CONFIG:Debug>>:/DEBUG>")
|
|
||||||
add_link_options("$<$<NOT:$<CONFIG:Debug>>:/OPT:REF>")
|
|
||||||
add_link_options("$<$<NOT:$<CONFIG:Debug>>:/OPT:ICF>")
|
|
||||||
include(FindLua)
|
include(FindLua)
|
||||||
message(STATUS "Looking for libz")
|
message(STATUS "Looking for libz")
|
||||||
find_package(ZLIB REQUIRED)
|
find_package(ZLIB REQUIRED)
|
||||||
@@ -139,7 +131,5 @@ elseif (WIN32)
|
|||||||
${OPENSSL_LIBRARIES}
|
${OPENSSL_LIBRARIES}
|
||||||
commandline
|
commandline
|
||||||
sioclient_tls
|
sioclient_tls
|
||||||
sentry
|
sentry)
|
||||||
watchdog
|
|
||||||
Dbghelp)
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.0)
|
|
||||||
project(watchdog CXX ASM_MASM)
|
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
|
||||||
add_library(watchdog STATIC watchdog.cpp watchdog.h x64Def.asm)
|
|
||||||
set_source_files_properties(watchdog.cpp PROPERTIES COMPILE_FLAGS "/O2 /Ob2 /DNDEBUG")
|
|
||||||
STRING(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
|
|
||||||
target_link_libraries(watchdog Dbghelp)
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Anonymous275 on 9/5/2021.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <cstring>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
namespace fst {
|
|
||||||
template<size_t Cap>
|
|
||||||
class stack_string {
|
|
||||||
public:
|
|
||||||
stack_string() noexcept {
|
|
||||||
memset(Data, 0, Cap);
|
|
||||||
}
|
|
||||||
explicit stack_string(const char* Ptr) {
|
|
||||||
size_t len = strlen(Ptr);
|
|
||||||
Copy(Ptr, len);
|
|
||||||
memset(Data + len, 0, Cap - len);
|
|
||||||
}
|
|
||||||
stack_string(const char* Ptr, size_t PSize) {
|
|
||||||
Copy(Ptr, PSize);
|
|
||||||
memset(Data + PSize, 0, Cap - PSize);
|
|
||||||
}
|
|
||||||
inline size_t capacity() noexcept {
|
|
||||||
return Cap;
|
|
||||||
}
|
|
||||||
inline size_t size() noexcept {
|
|
||||||
return Size;
|
|
||||||
}
|
|
||||||
inline size_t length() noexcept {
|
|
||||||
return Size;
|
|
||||||
}
|
|
||||||
inline char* get() {
|
|
||||||
return Data;
|
|
||||||
}
|
|
||||||
[[nodiscard]] inline const char* c_str() const noexcept {
|
|
||||||
return Data;
|
|
||||||
}
|
|
||||||
char& operator[](size_t idx) {
|
|
||||||
if (idx >= Size) {
|
|
||||||
throw std::exception("stack_string out of boundaries operator[]");
|
|
||||||
}
|
|
||||||
return Data[idx];
|
|
||||||
}
|
|
||||||
inline void resize(size_t newSize) noexcept {
|
|
||||||
Size = newSize;
|
|
||||||
}
|
|
||||||
inline void push_back(const char* Ptr) {
|
|
||||||
Copy(Ptr, strlen(Ptr));
|
|
||||||
}
|
|
||||||
inline void push_back(const char* Ptr, size_t Count) {
|
|
||||||
Copy(Ptr, Count);
|
|
||||||
}
|
|
||||||
inline void push_back(char Ptr) {
|
|
||||||
Copy(&Ptr, 1);
|
|
||||||
}
|
|
||||||
friend std::ostream& operator<<(std::ostream& os, const stack_string& obj) {
|
|
||||||
os << obj.Data;
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
inline stack_string& operator+=(const char* Ptr) {
|
|
||||||
push_back(Ptr);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
inline stack_string& operator+=(char Ptr) {
|
|
||||||
push_back(Ptr);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
inline void Copy(const char* Ptr, size_t PSize) {
|
|
||||||
if((PSize + Size) <= Cap) {
|
|
||||||
memcpy(&Data[Size], Ptr, PSize);
|
|
||||||
Size += PSize;
|
|
||||||
} else throw std::exception("stack_string out of boundaries copy");
|
|
||||||
}
|
|
||||||
char Data[Cap]{};
|
|
||||||
size_t Size{0};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,281 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Anonymous275 on 9/9/2021.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
#include <imagehlp.h>
|
|
||||||
#include <strsafe.h>
|
|
||||||
#include <cstdint>
|
|
||||||
#include "stack_string.h"
|
|
||||||
|
|
||||||
struct function_info {
|
|
||||||
void* func_address;
|
|
||||||
uint32_t thread_id;
|
|
||||||
bool enter;
|
|
||||||
};
|
|
||||||
|
|
||||||
fst::stack_string<1024> crash_file;
|
|
||||||
|
|
||||||
template <typename I>
|
|
||||||
fst::stack_string<(sizeof(I)<<1)+1> HexString(I w) {
|
|
||||||
static const char* digits = "0123456789ABCDEF";
|
|
||||||
const size_t hex_len = sizeof(I)<<1;
|
|
||||||
fst::stack_string<hex_len+1> rc;
|
|
||||||
rc.resize(hex_len+1);
|
|
||||||
memset(rc.get(), '0', hex_len);
|
|
||||||
memset(rc.get() + hex_len, 0, 1);
|
|
||||||
for (size_t i=0, j=(hex_len-1)*4 ; i<hex_len; ++i,j-=4)
|
|
||||||
rc[i] = digits[(w>>j) & 0x0f];
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T_>
|
|
||||||
class heap_array {
|
|
||||||
public:
|
|
||||||
heap_array() noexcept {
|
|
||||||
Data = (T_*)(GlobalAlloc(GPTR, Cap * sizeof(T_)));
|
|
||||||
init = true;
|
|
||||||
}
|
|
||||||
explicit heap_array(size_t Cap_) noexcept {
|
|
||||||
Cap = Cap_;
|
|
||||||
Data = (T_*)(GlobalAlloc(GPTR, Cap * sizeof(T_)));
|
|
||||||
init = true;
|
|
||||||
}
|
|
||||||
~heap_array() {
|
|
||||||
free(Data);
|
|
||||||
}
|
|
||||||
inline T_* get() noexcept {
|
|
||||||
return Data;
|
|
||||||
}
|
|
||||||
inline const T_* cget() noexcept {
|
|
||||||
return Data;
|
|
||||||
}
|
|
||||||
inline void insert(const T_& T) {
|
|
||||||
if(!init)return;
|
|
||||||
if(Size >= Cap) {
|
|
||||||
Grow();
|
|
||||||
}
|
|
||||||
Data[Size++] = T;
|
|
||||||
}
|
|
||||||
inline void string_insert(const T_* T, size_t len = 0) {
|
|
||||||
if(len == 0)len = strlen(T);
|
|
||||||
if(Size+len >= Cap) {
|
|
||||||
Grow(len);
|
|
||||||
}
|
|
||||||
memcpy(&Data[Size], T, len);
|
|
||||||
Size += len;
|
|
||||||
}
|
|
||||||
inline T_ at(size_t idx) {
|
|
||||||
return Data[idx];
|
|
||||||
}
|
|
||||||
inline size_t size() const noexcept {
|
|
||||||
return Size;
|
|
||||||
}
|
|
||||||
const T_& operator[](size_t idx) {
|
|
||||||
if (idx >= Size) {
|
|
||||||
throw std::exception("out of boundaries operator[]");
|
|
||||||
}
|
|
||||||
return Data[idx];
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
inline void Grow(size_t add = 0) {
|
|
||||||
Cap = (Cap*2) + add;
|
|
||||||
auto* NewData = (T_*)(GlobalAlloc(GPTR, Cap * sizeof(T_)));
|
|
||||||
for(size_t C = 0; C < Size; C++) {
|
|
||||||
NewData[C] = Data[C];
|
|
||||||
}
|
|
||||||
GlobalFree(Data);
|
|
||||||
Data = NewData;
|
|
||||||
}
|
|
||||||
size_t Size{0}, Cap{5};
|
|
||||||
bool init{false};
|
|
||||||
T_* Data;
|
|
||||||
};
|
|
||||||
|
|
||||||
heap_array<function_info>* watch_data;
|
|
||||||
|
|
||||||
struct watchdog_mutex {
|
|
||||||
static void Create() noexcept {
|
|
||||||
hMutex = CreateMutex(nullptr, FALSE, nullptr);
|
|
||||||
}
|
|
||||||
static void Lock() {
|
|
||||||
WaitForSingleObject(hMutex, INFINITE);
|
|
||||||
}
|
|
||||||
static void Unlock() {
|
|
||||||
ReleaseMutex(hMutex);
|
|
||||||
}
|
|
||||||
struct [[nodiscard]] ScopedLock {
|
|
||||||
ScopedLock() {
|
|
||||||
if(hMutex)
|
|
||||||
watchdog_mutex::Lock();
|
|
||||||
}
|
|
||||||
~ScopedLock() {
|
|
||||||
if(hMutex)
|
|
||||||
watchdog_mutex::Unlock();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
private:
|
|
||||||
static HANDLE hMutex;
|
|
||||||
};
|
|
||||||
HANDLE watchdog_mutex::hMutex{nullptr};
|
|
||||||
std::atomic<bool> Init{false}, Sym;
|
|
||||||
std::atomic<int64_t> Offset{0};
|
|
||||||
|
|
||||||
void watchdog_setOffset(int64_t Off) {
|
|
||||||
Offset.store(Off);
|
|
||||||
}
|
|
||||||
|
|
||||||
void notify(const char* msg) {
|
|
||||||
HANDLE stdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
||||||
if (stdOut != nullptr && stdOut != INVALID_HANDLE_VALUE) {
|
|
||||||
DWORD written = 0;
|
|
||||||
WriteConsoleA(stdOut, "[WATCHDOG] ", 11, &written, nullptr);
|
|
||||||
WriteConsoleA(stdOut, msg, DWORD(strlen(msg)), &written, nullptr);
|
|
||||||
WriteConsoleA(stdOut, "\n", 1, &written, nullptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fst::stack_string<MAX_SYM_NAME> FindFunction(void* Address) {
|
|
||||||
if(!Sym.load()) {
|
|
||||||
fst::stack_string<MAX_SYM_NAME> undName;
|
|
||||||
return undName;
|
|
||||||
}
|
|
||||||
static HANDLE process = GetCurrentProcess();
|
|
||||||
DWORD64 symDisplacement = 0;
|
|
||||||
fst::stack_string<MAX_SYM_NAME> undName;
|
|
||||||
TCHAR buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
|
|
||||||
memset(&buffer,0, sizeof(buffer));
|
|
||||||
auto pSymbolInfo = (PSYMBOL_INFO)buffer;
|
|
||||||
pSymbolInfo->SizeOfStruct = sizeof(SYMBOL_INFO);
|
|
||||||
pSymbolInfo->MaxNameLen = MAX_SYM_NAME;
|
|
||||||
if (SymFromAddr(process, DWORD64(Address) + Offset, &symDisplacement, pSymbolInfo)) {
|
|
||||||
undName.push_back(pSymbolInfo->Name);
|
|
||||||
}
|
|
||||||
return undName;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fst::stack_string<512> getCrashInfo(void* Address){
|
|
||||||
if(!Sym.load()){
|
|
||||||
fst::stack_string<512> Value;
|
|
||||||
Value.push_back("unknown", 7);
|
|
||||||
return Value;
|
|
||||||
}
|
|
||||||
DWORD pdwDisplacement = 0;
|
|
||||||
IMAGEHLP_LINE64 line{sizeof(IMAGEHLP_LINE64)};
|
|
||||||
SymGetLineFromAddr64(GetCurrentProcess(), DWORD64(Address) + Offset, &pdwDisplacement, &line);
|
|
||||||
char* Name = nullptr;
|
|
||||||
if(line.FileName) {
|
|
||||||
Name = strrchr(line.FileName, '\\');
|
|
||||||
}
|
|
||||||
fst::stack_string<512> Value;
|
|
||||||
if(Name)Value.push_back(Name+1);
|
|
||||||
else Value.push_back("unknown", 7);
|
|
||||||
char buffer[20];
|
|
||||||
auto n = sprintf(buffer, ":%lu", line.LineNumber);
|
|
||||||
Value.push_back(buffer, n);
|
|
||||||
return Value;
|
|
||||||
}
|
|
||||||
const char* getFunctionDetails(void* Address) {
|
|
||||||
return FindFunction(Address).c_str();
|
|
||||||
}
|
|
||||||
const char* getCrashLocation(void* Address) {
|
|
||||||
return getCrashInfo(Address).c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitSym(const char* PDBLocation) {
|
|
||||||
SymInitialize(GetCurrentProcess(), PDBLocation, TRUE);
|
|
||||||
Sym.store(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void write_report(const char* report, size_t size) {
|
|
||||||
HANDLE hFile = CreateFile(crash_file.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
|
||||||
if (hFile == INVALID_HANDLE_VALUE) {
|
|
||||||
notify("Failed to open crash file for writing!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
DWORD dwBytesWritten = 0;
|
|
||||||
auto Flag = WriteFile(hFile, report, DWORD(size), &dwBytesWritten, nullptr);
|
|
||||||
if (Flag == FALSE) {
|
|
||||||
notify("Failed to write to crash file!");
|
|
||||||
}
|
|
||||||
CloseHandle(hFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
void generate_crash_report(uint32_t Code, void* Address) {
|
|
||||||
watchdog_mutex::ScopedLock guard;
|
|
||||||
notify("generating crash report, please wait");
|
|
||||||
Init.store(false);
|
|
||||||
heap_array<char> Report(watch_data->size() * sizeof(function_info));
|
|
||||||
Report.string_insert("crash code ");
|
|
||||||
Report.string_insert(HexString(Code).c_str());
|
|
||||||
Report.string_insert(" at ");
|
|
||||||
Report.string_insert(HexString(size_t(Address) + Offset).c_str());
|
|
||||||
Report.string_insert("\n");
|
|
||||||
if(Address) {
|
|
||||||
Report.string_insert("origin and line number -> ");
|
|
||||||
Report.string_insert(getCrashInfo(Address).c_str());
|
|
||||||
Report.string_insert("\n");
|
|
||||||
}
|
|
||||||
Report.string_insert("Call history: \n");
|
|
||||||
char buff[20];
|
|
||||||
for(size_t C = 0; C < watch_data->size(); C++){
|
|
||||||
auto entry = watch_data->at(C);
|
|
||||||
auto Name = FindFunction(entry.func_address);
|
|
||||||
if(entry.enter){
|
|
||||||
Report.string_insert("[Entry] ");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Report.string_insert("[Exit ] ");
|
|
||||||
}
|
|
||||||
auto n = sprintf(buff, "(%d) ", entry.thread_id);
|
|
||||||
Report.string_insert(buff, n);
|
|
||||||
if(Name.size() > 0){
|
|
||||||
Report.string_insert(Name.c_str(), Name.size());
|
|
||||||
Report.string_insert(" | ");
|
|
||||||
auto location = getCrashInfo(entry.func_address);
|
|
||||||
Report.string_insert(location.c_str(), location.size());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Report.string_insert(HexString(size_t(entry.func_address) + Offset).c_str());
|
|
||||||
}
|
|
||||||
Report.string_insert("\n");
|
|
||||||
}
|
|
||||||
write_report(Report.cget(), Report.size());
|
|
||||||
notify("crash report generated");
|
|
||||||
Init.store(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
LONG WINAPI CrashHandler(EXCEPTION_POINTERS* p) {
|
|
||||||
Init.store(false);
|
|
||||||
notify("CAUGHT EXCEPTION!");
|
|
||||||
generate_crash_report(p->ExceptionRecord->ExceptionCode, p->ExceptionRecord->ExceptionAddress);
|
|
||||||
return EXCEPTION_EXECUTE_HANDLER;
|
|
||||||
}
|
|
||||||
|
|
||||||
void watchdog_init(const char* crashFile, const char* SpecificPDBLocation, bool Symbols) {
|
|
||||||
if(Symbols)SymInitialize(GetCurrentProcess(), SpecificPDBLocation, TRUE);
|
|
||||||
Sym.store(Symbols);
|
|
||||||
SetUnhandledExceptionFilter(CrashHandler);
|
|
||||||
watch_data = new heap_array<function_info>();
|
|
||||||
watchdog_mutex::Create();
|
|
||||||
crash_file.push_back(crashFile);
|
|
||||||
notify("initialized!");
|
|
||||||
Init.store(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void AddEntry(void* func_address, uint32_t thread_id, bool entry) {
|
|
||||||
watchdog_mutex::ScopedLock guard;
|
|
||||||
if(Init.load()) {
|
|
||||||
watch_data->insert({func_address, thread_id, entry});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
void FuncEntry(void* func) {
|
|
||||||
AddEntry(func, GetCurrentThreadId(), true);
|
|
||||||
}
|
|
||||||
void FuncExit(void* func) {
|
|
||||||
AddEntry(func, GetCurrentThreadId(), false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Anonymous275 on 9/9/2021.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <cstdint>
|
|
||||||
extern void watchdog_init(const char* crashFile, const char* SpecificPDBLocation, bool Symbols = true);
|
|
||||||
extern void generate_crash_report(uint32_t Code, void* Address);
|
|
||||||
const char* getFunctionDetails(void* Address);
|
|
||||||
extern void watchdog_setOffset(int64_t Off);
|
|
||||||
const char* getCrashLocation(void* Address);
|
|
||||||
void InitSym(const char* PDBLocation);
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
;//
|
|
||||||
;// Created by Anonymous275 on 9/9/2021.
|
|
||||||
;//
|
|
||||||
;External C functions used by _penter and _pexit
|
|
||||||
extern FuncEntry:Proc
|
|
||||||
extern FuncExit:Proc
|
|
||||||
|
|
||||||
.code
|
|
||||||
|
|
||||||
_penter proc
|
|
||||||
|
|
||||||
; Store the volatile registers
|
|
||||||
push r11
|
|
||||||
push r10
|
|
||||||
push r9
|
|
||||||
push r8
|
|
||||||
push rax
|
|
||||||
push rdx
|
|
||||||
push rcx
|
|
||||||
|
|
||||||
; reserve space for 4 registers [ rcx,rdx,r8 and r9 ] 32 bytes
|
|
||||||
sub rsp,20h
|
|
||||||
|
|
||||||
; Get the return address of the function
|
|
||||||
mov rcx,rsp
|
|
||||||
mov rcx,qword ptr[rcx+58h]
|
|
||||||
sub rcx,5
|
|
||||||
|
|
||||||
;call the function to get the name of the callee and caller
|
|
||||||
call FuncEntry
|
|
||||||
|
|
||||||
;Release the space reserved for the registersk by adding 32 bytes
|
|
||||||
add rsp,20h
|
|
||||||
|
|
||||||
;Restore the registers back by poping out
|
|
||||||
pop rcx
|
|
||||||
pop rdx
|
|
||||||
pop rax
|
|
||||||
pop r8
|
|
||||||
pop r9
|
|
||||||
pop r10
|
|
||||||
pop r11
|
|
||||||
|
|
||||||
;return
|
|
||||||
ret
|
|
||||||
|
|
||||||
_penter endp
|
|
||||||
|
|
||||||
_pexit proc
|
|
||||||
|
|
||||||
; Store the volatile registers
|
|
||||||
push r11
|
|
||||||
push r10
|
|
||||||
push r9
|
|
||||||
push r8
|
|
||||||
push rax
|
|
||||||
push rdx
|
|
||||||
push rcx
|
|
||||||
|
|
||||||
; reserve space for 4 registers [ rcx,rdx,r8 and r9 ] 32 bytes
|
|
||||||
sub rsp,20h
|
|
||||||
|
|
||||||
; Get the return address of the function
|
|
||||||
mov rcx,rsp
|
|
||||||
mov rcx,qword ptr[rcx+58h]
|
|
||||||
|
|
||||||
call FuncExit
|
|
||||||
|
|
||||||
;Release the space reserved for the registersk by adding 32 bytes
|
|
||||||
add rsp,20h
|
|
||||||
|
|
||||||
;Restore the registers back by poping out
|
|
||||||
pop rcx
|
|
||||||
pop rdx
|
|
||||||
pop rax
|
|
||||||
pop r8
|
|
||||||
pop r9
|
|
||||||
pop r10
|
|
||||||
pop r11
|
|
||||||
|
|
||||||
;return
|
|
||||||
ret
|
|
||||||
|
|
||||||
_pexit endp
|
|
||||||
end
|
|
||||||
@@ -84,8 +84,6 @@ void Application::CheckForUpdates() {
|
|||||||
warn(std::string(ANSI_YELLOW_BOLD) + "NEW VERSION OUT! There's a new version (v" + RealVersionString + ") of the BeamMP-Server available! For more info visit https://wiki.beammp.com/en/home/server-maintenance#updating-the-server." + std::string(ANSI_RESET));
|
warn(std::string(ANSI_YELLOW_BOLD) + "NEW VERSION OUT! There's a new version (v" + RealVersionString + ") of the BeamMP-Server available! For more info visit https://wiki.beammp.com/en/home/server-maintenance#updating-the-server." + std::string(ANSI_RESET));
|
||||||
} else {
|
} else {
|
||||||
info("Server up-to-date!");
|
info("Server up-to-date!");
|
||||||
char* crasher = nullptr;
|
|
||||||
crasher[4555] = 'c';
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
warn("Unable to fetch version from backend.");
|
warn("Unable to fetch version from backend.");
|
||||||
|
|||||||
+65
-20
@@ -3,8 +3,12 @@
|
|||||||
#include "Client.h"
|
#include "Client.h"
|
||||||
#include "Http.h"
|
#include "Http.h"
|
||||||
//#include "SocketIO.h"
|
//#include "SocketIO.h"
|
||||||
|
#include <rapidjson/document.h>
|
||||||
|
#include <rapidjson/rapidjson.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace json = rapidjson;
|
||||||
|
|
||||||
void THeartbeatThread::operator()() {
|
void THeartbeatThread::operator()() {
|
||||||
RegisterThread("Heartbeat");
|
RegisterThread("Heartbeat");
|
||||||
std::string Body;
|
std::string Body;
|
||||||
@@ -41,42 +45,83 @@ void THeartbeatThread::operator()() {
|
|||||||
{ { "response-body", T },
|
{ { "response-body", T },
|
||||||
{ "request-body", Body } });
|
{ "request-body", Body } });
|
||||||
Sentry.SetTransaction(transaction);
|
Sentry.SetTransaction(transaction);
|
||||||
trace("sending log to sentry: " + std::to_string(status) + " for " + transaction);
|
|
||||||
Sentry.Log(SentryLevel::Error, "default", Http::Status::ToString(status) + " (" + std::to_string(status) + ")");
|
Sentry.Log(SentryLevel::Error, "default", Http::Status::ToString(status) + " (" + std::to_string(status) + ")");
|
||||||
};
|
};
|
||||||
|
|
||||||
auto Target = "/heartbeat";
|
auto Target = "/heartbeat";
|
||||||
int ResponseCode = -1;
|
int ResponseCode = -1;
|
||||||
T = Http::POST(Application::GetBackendHostname(), Target, {}, Body, false, &ResponseCode);
|
const std::vector<std::string> Urls = {
|
||||||
|
Application::GetBackendHostname(),
|
||||||
|
Application::GetBackup1Hostname(),
|
||||||
|
Application::GetBackup2Hostname(),
|
||||||
|
};
|
||||||
|
|
||||||
if ((T.substr(0, 2) != "20" && ResponseCode != 200) || ResponseCode != 200) {
|
json::Document Doc;
|
||||||
trace("got " + T + " from backend");
|
bool Ok = false;
|
||||||
SentryReportError(Application::GetBackendHostname() + Target, ResponseCode);
|
for (const auto& Url : Urls) {
|
||||||
|
T = Http::POST(Url, Target, { { "api-v", "2" } }, Body, false, &ResponseCode);
|
||||||
|
trace(T);
|
||||||
|
Doc.Parse(T.data(), T.size());
|
||||||
|
if (Doc.HasParseError() || !Doc.IsObject()) {
|
||||||
|
error("Backend response failed to parse as valid json");
|
||||||
|
debug("Response was: `" + T + "`");
|
||||||
|
Sentry.SetContext("JSON Response", { { "reponse", T } });
|
||||||
|
SentryReportError(Url + Target, ResponseCode);
|
||||||
|
} else if (ResponseCode != 200) {
|
||||||
|
SentryReportError(Url + Target, ResponseCode);
|
||||||
|
} else {
|
||||||
|
// all ok
|
||||||
|
Ok = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
T = Http::POST(Application::GetBackup1Hostname(), Target, {}, Body, false, &ResponseCode);
|
}
|
||||||
if ((T.substr(0, 2) != "20" && ResponseCode != 200) || ResponseCode != 200) {
|
std::string Status {};
|
||||||
SentryReportError(Application::GetBackup1Hostname() + Target, ResponseCode);
|
std::string Code {};
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
std::string Message {};
|
||||||
T = Http::POST(Application::GetBackup2Hostname(), Target, {}, Body, false, &ResponseCode);
|
const auto StatusKey = "status";
|
||||||
if ((T.substr(0, 2) != "20" && ResponseCode != 200) || ResponseCode != 200) {
|
const auto CodeKey = "code";
|
||||||
warn("Backend system refused server! Server will not show in the public server list.");
|
const auto MessageKey = "msg";
|
||||||
isAuth = false;
|
|
||||||
SentryReportError(Application::GetBackup2Hostname() + Target, ResponseCode);
|
if (Ok) {
|
||||||
}
|
if (Doc.HasMember(StatusKey) && Doc[StatusKey].IsString()) {
|
||||||
|
Status = Doc[StatusKey].GetString();
|
||||||
|
} else {
|
||||||
|
Sentry.SetContext("JSON Response", { { StatusKey, "invalid string / missing" } });
|
||||||
|
Ok = false;
|
||||||
|
}
|
||||||
|
if (Doc.HasMember(CodeKey) && Doc[CodeKey].IsString()) {
|
||||||
|
Code = Doc[CodeKey].GetString();
|
||||||
|
} else {
|
||||||
|
Sentry.SetContext("JSON Response", { { CodeKey, "invalid string / missing" } });
|
||||||
|
Ok = false;
|
||||||
|
}
|
||||||
|
if (Doc.HasMember(MessageKey) && Doc[MessageKey].IsString()) {
|
||||||
|
Message = Doc[MessageKey].GetString();
|
||||||
|
} else {
|
||||||
|
Sentry.SetContext("JSON Response", { { MessageKey, "invalid string / missing" } });
|
||||||
|
Ok = false;
|
||||||
|
}
|
||||||
|
if (!Ok) {
|
||||||
|
error("Missing/invalid json members in backend response");
|
||||||
|
Sentry.LogError("Missing/invalid json members in backend response", __FILE__, std::to_string(__LINE__));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isAuth) {
|
if (Ok && !isAuth) {
|
||||||
if (T == "2000") {
|
if (Status == "2000") {
|
||||||
info(("Authenticated!"));
|
info(("Authenticated!"));
|
||||||
isAuth = true;
|
isAuth = true;
|
||||||
} else if (T == "200") {
|
} else if (Status == "200") {
|
||||||
info(("Resumed authenticated session!"));
|
info(("Resumed authenticated session!"));
|
||||||
isAuth = true;
|
isAuth = true;
|
||||||
|
} else {
|
||||||
|
if (Message.empty()) {
|
||||||
|
Message = "Backend didn't provide a reason";
|
||||||
|
}
|
||||||
|
error("Backend REFUSED the auth key. " + Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//SocketIO::Get().SetAuthenticated(isAuth);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+48
-44
@@ -11,7 +11,7 @@
|
|||||||
#include "TPPSMonitor.h"
|
#include "TPPSMonitor.h"
|
||||||
#include "TResourceManager.h"
|
#include "TResourceManager.h"
|
||||||
#include "TServer.h"
|
#include "TServer.h"
|
||||||
#include "../include/watchdog/watchdog.h"
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
@@ -19,53 +19,57 @@
|
|||||||
// global, yes, this is ugly, no, it cant be done another way
|
// global, yes, this is ugly, no, it cant be done another way
|
||||||
TSentry Sentry {};
|
TSentry Sentry {};
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) try {
|
||||||
#ifdef WIN32
|
setlocale(LC_ALL, "C");
|
||||||
watchdog_init("watchdog_crash.log", nullptr);
|
|
||||||
#endif
|
|
||||||
try {
|
|
||||||
setlocale(LC_ALL, "C");
|
|
||||||
|
|
||||||
SetupSignalHandlers();
|
SetupSignalHandlers();
|
||||||
|
|
||||||
bool Shutdown = false;
|
bool Shutdown = false;
|
||||||
Application::RegisterShutdownHandler([&Shutdown] { Shutdown = true; });
|
Application::RegisterShutdownHandler([&Shutdown] { Shutdown = true; });
|
||||||
|
|
||||||
TServer Server(argc, argv);
|
TServer Server(argc, argv);
|
||||||
TConfig Config;
|
TConfig Config;
|
||||||
|
|
||||||
if (Config.Failed()) {
|
if (Config.Failed()) {
|
||||||
info("Closing in 10 seconds");
|
info("Closing in 10 seconds");
|
||||||
// loop to make it possible to ctrl+c instead
|
// loop to make it possible to ctrl+c instead
|
||||||
for (size_t i = 0; i < 20; ++i) {
|
for (size_t i = 0; i < 20; ++i) {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
return 1;
|
||||||
RegisterThread("Main");
|
|
||||||
|
|
||||||
trace("Running in debug mode on a debug build");
|
|
||||||
|
|
||||||
Sentry.SetupUser();
|
|
||||||
Sentry.PrintWelcome();
|
|
||||||
TResourceManager ResourceManager;
|
|
||||||
TPPSMonitor PPSMonitor(Server);
|
|
||||||
THeartbeatThread Heartbeat(ResourceManager, Server);
|
|
||||||
TNetwork Network(Server, PPSMonitor, ResourceManager);
|
|
||||||
TLuaEngine LuaEngine(Server, Network);
|
|
||||||
PPSMonitor.SetNetwork(Network);
|
|
||||||
Application::Console().InitializeLuaConsole(LuaEngine);
|
|
||||||
Application::CheckForUpdates();
|
|
||||||
|
|
||||||
// TODO: replace
|
|
||||||
while (!Shutdown) {
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
|
||||||
}
|
|
||||||
info("Shutdown.");
|
|
||||||
|
|
||||||
} catch (const std::exception& e) {
|
|
||||||
error(e.what());
|
|
||||||
Sentry.LogException(e, _file_basename, _line);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RegisterThread("Main");
|
||||||
|
|
||||||
|
trace("Running in debug mode on a debug build");
|
||||||
|
|
||||||
|
Sentry.SetupUser();
|
||||||
|
Sentry.PrintWelcome();
|
||||||
|
TResourceManager ResourceManager;
|
||||||
|
TPPSMonitor PPSMonitor(Server);
|
||||||
|
THeartbeatThread Heartbeat(ResourceManager, Server);
|
||||||
|
TNetwork Network(Server, PPSMonitor, ResourceManager);
|
||||||
|
TLuaEngine LuaEngine(Server, Network);
|
||||||
|
PPSMonitor.SetNetwork(Network);
|
||||||
|
Application::Console().InitializeLuaConsole(LuaEngine);
|
||||||
|
Application::CheckForUpdates();
|
||||||
|
|
||||||
|
Sentry.LogError("test error", __FILE__, std::to_string(__LINE__));
|
||||||
|
|
||||||
|
error("goodbye, crashing now");
|
||||||
|
volatile int* a = nullptr;
|
||||||
|
// oh boy
|
||||||
|
*a = -0;
|
||||||
|
a[318008]++;
|
||||||
|
// bye now
|
||||||
|
abort();
|
||||||
|
|
||||||
|
// TODO: replace
|
||||||
|
while (!Shutdown) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||||
|
}
|
||||||
|
info("Shutdown.");
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
error(e.what());
|
||||||
|
Sentry.LogException(e, _file_basename, _line);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user