Skip to content

Commit

Permalink
feat: linux server now with crash handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Yamashi committed Apr 17, 2022
1 parent b8cbf2e commit 677a505
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 13 deletions.
26 changes: 20 additions & 6 deletions Code/components/crash_handler/CrashHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,31 @@
#include <BuildInfo.h>


void InstallCrashHandler()
void InstallCrashHandler(bool aServer, bool aSkyrim)
{
sentry_options_t* options = sentry_options_new();

sentry_options_set_database_path(options, ".sentry-native");

#if defined(TARGET_ST)
sentry_options_set_dsn(options, "https://96c601d451c94b32adb826aa62c6d50f@o228105.ingest.sentry.io/6269770");
#else
sentry_options_set_dsn(options, "https://63886f8f9ef54328bc3373b07750a028@o228105.ingest.sentry.io/6273696");
#endif
if (aSkyrim)
{
if (aServer)
sentry_options_set_dsn(options,
"https://6aff0a6955754bdebfffb064813b9042@o228105.ingest.sentry.io/6303666");
else
sentry_options_set_dsn(options,
"https://96c601d451c94b32adb826aa62c6d50f@o228105.ingest.sentry.io/6269770");
}
else
{
if (aServer)
sentry_options_set_dsn(options,
"https://2a3d561652734ca78e539c3fb5219a38@o228105.ingest.sentry.io/6303669");
else
sentry_options_set_dsn(options,
"https://63886f8f9ef54328bc3373b07750a028@o228105.ingest.sentry.io/6273696");
}


sentry_options_set_auto_session_tracking(options, false);
sentry_options_set_symbolize_stacktraces(options, true);
Expand Down
2 changes: 1 addition & 1 deletion Code/components/crash_handler/CrashHandler.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once

void InstallCrashHandler();
void InstallCrashHandler(bool aServer = false, bool aSkyrim = true);
void UninstallCrashHandler();
9 changes: 9 additions & 0 deletions Code/server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <console/IniSettingsProvider.h>
#include <console/StringTokenizer.h>

#include <CrashHandler.h>

constexpr char kSettingsFileName[] =
#if SKYRIM
"STServer.ini"
Expand Down Expand Up @@ -272,9 +274,14 @@ static bool IsEULAAccepted()

int main(int argc, char** argv)
{
InstallCrashHandler(true);

LogInstance logInstance;
(void)logInstance;

int* i = 0;
*i = 42;

if (!IsEULAAccepted())
{
spdlog::error("Please accept the EULA by setting bConfirmEULA to true in EULA.txt");
Expand All @@ -291,5 +298,7 @@ int main(int argc, char** argv)
}
cpRunner->RunGSThread();

UninstallCrashHandler();

return 0;
}
16 changes: 15 additions & 1 deletion Code/server/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
local function istable(t) return type(t) == 'table' end

local function build_server()
add_includedirs(
".",
"../../Libraries/")

after_install(function(target)
local linkdir = target:pkg("sentry-native"):get("linkdirs")
if istable(linkdir) then
linkdir = linkdir[1] -- Yes lua index starts at 1
end
local bindir = path.join(linkdir, "..", "bin")
os.cp(bindir, target:installdir())
end)

set_pcxxheader("stdafx.h")
add_headerfiles("**.h")
add_files(
Expand All @@ -13,6 +25,7 @@ local function build_server()
"CommonLib",
"Console",
"ESLoader",
"CrashHandler",
"BaseLib",
"AdminProtocol",
"TiltedScript",
Expand All @@ -28,7 +41,8 @@ local function build_server()
"glm",
"entt",
"cpp-httplib",
"tiltedcore")
"tiltedcore",
"sentry-native")
end

target("SkyrimTogetherServer")
Expand Down
11 changes: 9 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ RUN export XMAKE_ROOTDIR="/root/.local/bin" && \
export PATH="$XMAKE_ROOTDIR:$PATH" && \
export XMAKE_ROOT=y && \
xmake config -y && \
xmake -j8
xmake -j8 && \
objcopy --only-keep-debug /home/server/build/linux/x64/release/SkyrimTogetherServer /home/server/build/linux/x64/release/SkyrimTogetherServer.debug
RUN export XMAKE_ROOTDIR="/root/.local/bin" && \
export PATH="$XMAKE_ROOTDIR:$PATH" && \
export XMAKE_ROOT=y && \
xmake install -o package

FROM ubuntu:20.04 AS skyrim

Expand All @@ -35,7 +40,9 @@ RUN apt update && \
apt remove software-properties-common -y && \
apt autoremove -y

COPY --from=builder /home/server/build/linux/x64/release/SkyrimTogetherServer /home/server/SkyrimTogetherServer
COPY --from=builder /home/server/package/bin/SkyrimTogetherServer /home/server/SkyrimTogetherServer
COPY --from=builder /home/server/package/bin/crashpad_handler /home/server/crashpad_handler
COPY --from=builder /home/server/build/linux/x64/release/SkyrimTogetherServer.debug /home/server/SkyrimTogetherServer.debug
WORKDIR /home/server
ENTRYPOINT ["./SkyrimTogetherServer"]

Expand Down
6 changes: 6 additions & 0 deletions MakeLinux.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@echo off

docker build . -t skyrim_build
docker run --rm --entrypoint /bin/sh skyrim_build -c "cat /home/server/SkyrimTogetherServer.debug" > ./build/linux/x64/SkyrimTogetherServer.debug
docker run --rm --entrypoint /bin/sh skyrim_build -c "cat /home/server/SkyrimTogetherServer" > ./build/linux/x64/SkyrimTogetherServer
timeout /t 30 /nobreak
21 changes: 18 additions & 3 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ task("upload-symbols")
import("core.base.option")

local key = option.get('key')
local linux = option.get('linux')

if key ~= nil then
import("net.http")
Expand All @@ -64,13 +65,26 @@ task("upload-symbols")
config.load()

local sentrybin = path.join(os.projectdir(), "build", "sentry-cli.exe")
local path = path.join(os.projectdir(), "build", config.get("plat"), config.get("arch"), config.get("mode"), "SkyrimTogether.pdb")
local file_path = path.join(os.projectdir(), "build", config.get("plat"), config.get("arch"), config.get("mode"), "SkyrimTogether.pdb")
if linux then
file_path = path.join(os.projectdir(), "build", "linux", "x64", "SkyrimTogetherServer.debug")
end

if not os.exists(sentrybin) then
http.download("https://github.com/getsentry/sentry-cli/releases/download/2.0.2/sentry-cli-Windows-x86_64.exe", sentrybin)
end

os.execv(sentrybin, {"--auth-token", key, "upload-dif", "-o", "together-team", "-p", "st-reborn", path})
local project = "st-reborn"
if linux then
project = "st-server"
end

os.execv(sentrybin, {"--auth-token", key, "upload-dif", "-o", "together-team", "-p", project, file_path})

if not linux then
local file_path = path.join(os.projectdir(), "build", config.get("plat"), config.get("arch"), config.get("mode"), "SkyrimTogetherServer.pdb")
os.execv(sentrybin, {"--auth-token", key, "upload-dif", "-o", "together-team", "-p", "st-server", file_path})
end

else
print("An API key is required to proceed!")
Expand All @@ -81,6 +95,7 @@ task("upload-symbols")
usage = "xmake upload-symbols",
description = "Upload symbols to sentry",
options = {
{'k', "key", "kv", nil, "The API key to use." }
{'k', "key", "kv", nil, "The API key to use." },
{'l', "linux", "v", false, "Upload linux symbols that were manually copied." },
}
}

0 comments on commit 677a505

Please sign in to comment.