Skip to content

Commit

Permalink
feat(skymp5-server): introduce settings repositories (#1857)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pospelove authored Apr 21, 2024
1 parent bb9fd41 commit e2727d8
Show file tree
Hide file tree
Showing 9 changed files with 803 additions and 365 deletions.
23 changes: 22 additions & 1 deletion docs/docs_server_configuration_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,32 @@ In case this field is not provided, some default, yet hardcoded, values are in u
"WeapTypeDagger": 4.0,
"WeapTypeShortSword": 5.0,
"WeapTypeSword": 6.0,
...
// ...
}
// ...
}
```

## additionalServerSettings

To automate the fetching of the latest server settings from GitHub, configure the additionalServerSettings in your server's startup script or configuration file as follows:

```json5
{
// ...
"additionalServerSettings": [
{
"type": "github",
"repo": "your-org/server-settings-repo",
"ref": "main", // Specify the branch, tag, or commit hash here
"pathRegex": "^(common|indev)/.*", // No need to check for .json extension
"token": "YOUR_GITHUB_PERSONAL_ACCESS_TOKEN"
}
]
// ...
}
```

## damageMultFormulaSettings
This setting allows you to control server damage mult formula through its variables.
If "damageMultFormulaSettings" is not present, the server will use some default values.
Expand Down
3 changes: 3 additions & 0 deletions skymp5-server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "scam_native" PREFI
target_link_libraries(${PROJECT_NAME} PRIVATE unofficial::node-addon-api::node-addon-api)
target_include_directories(${PROJECT_NAME} PRIVATE ${SKYMP5_SERVER_SOURCE_DIR}/cpp/addon)

# Make 'cmake --build . --target skymp5-server' building typescript part as well
add_dependencies(${PROJECT_NAME} skymp5-server-ts)

# Put build artifacts into build/dist/server
if(WIN32)
set_target_properties(${PROJECT_NAME} PROPERTIES
Expand Down
64 changes: 30 additions & 34 deletions skymp5-server/cpp/addon/ScampServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ Napi::Object ScampServer::Init(Napi::Env env, Napi::Object exports)
InstanceMethod("setEnabled", &ScampServer::SetEnabled),
InstanceMethod("createBot", &ScampServer::CreateBot),
InstanceMethod("getUserByActor", &ScampServer::GetUserByActor),
InstanceMethod("writeLogs", &ScampServer::WriteLogs),
InstanceMethod("getUserIp", &ScampServer::GetUserIp),

InstanceMethod("getLocalizedString", &ScampServer::GetLocalizedString),
Expand Down Expand Up @@ -110,9 +109,35 @@ Napi::Object ScampServer::Init(Napi::Env env, Napi::Object exports)
constructor = Napi::Persistent(func);
constructor.SuppressDestruct();
exports.Set("ScampServer", func);

exports.Set("writeLogs", Napi::Function::New(env, WriteLogs));
return exports;
}

Napi::Value ScampServer::WriteLogs(const Napi::CallbackInfo& info)
{
try {
Napi::String logLevel = info[0].As<Napi::String>();
Napi::String message = info[1].As<Napi::String>();

auto messageStr = static_cast<std::string>(message);
while (!messageStr.empty() && messageStr.back() == '\n') {
messageStr.pop_back();
}

if (static_cast<std::string>(logLevel) == "info") {
GetLogger()->info(messageStr);
} else if (static_cast<std::string>(logLevel) == "error") {
GetLogger()->error(messageStr);
}
} catch (std::exception& e) {
// No sense to rethrow, NodeJS will unlikely be able to print this
// exception
GetLogger()->error("ScampServer::WriteLogs - {}", e.what());
}
return info.Env().Undefined();
}

ScampServer::ScampServer(const Napi::CallbackInfo& info)
: ObjectWrap(info)
, tickEnv(info.Env())
Expand All @@ -124,22 +149,17 @@ ScampServer::ScampServer(const Napi::CallbackInfo& info)
Napi::Number port = info[0].As<Napi::Number>(),
maxConnections = info[1].As<Napi::Number>();

std::string serverSettingsJson =
static_cast<std::string>(info[2].As<Napi::String>());

serverMock = std::make_shared<Networking::MockServer>();

std::string dataDir;

const auto& logger = GetLogger();
partOne->AttachLogger(logger);

std::ifstream f("server-settings.json");
if (!f.good()) {
throw std::runtime_error("server-settings.json is missing");
}

std::stringstream buffer;
buffer << f.rdbuf();

auto serverSettings = nlohmann::json::parse(buffer.str());
auto serverSettings = nlohmann::json::parse(serverSettingsJson);

if (serverSettings.find("weaponStaminaModifiers") !=
serverSettings.end()) {
Expand Down Expand Up @@ -614,30 +634,6 @@ Napi::Value ScampServer::GetUserByActor(const Napi::CallbackInfo& info)
return info.Env().Undefined();
}

Napi::Value ScampServer::WriteLogs(const Napi::CallbackInfo& info)
{
try {
Napi::String logLevel = info[0].As<Napi::String>();
Napi::String message = info[1].As<Napi::String>();

auto messageStr = static_cast<std::string>(message);
while (!messageStr.empty() && messageStr.back() == '\n') {
messageStr.pop_back();
}

if (static_cast<std::string>(logLevel) == "info") {
GetLogger()->info(messageStr);
} else if (static_cast<std::string>(logLevel) == "error") {
GetLogger()->error(messageStr);
}
} catch (std::exception& e) {
// No sense to rethrow, NodeJS will unlikely be able to print this
// exception
GetLogger()->error("ScampServer::WriteLogs - {}", e.what());
}
return info.Env().Undefined();
}

Napi::Value ScampServer::GetUserIp(const Napi::CallbackInfo& info)
{
try {
Expand Down
3 changes: 2 additions & 1 deletion skymp5-server/cpp/addon/ScampServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ScampServer : public Napi::ObjectWrap<ScampServer>
static Napi::Object Init(Napi::Env env, Napi::Object exports);
ScampServer(const Napi::CallbackInfo& info);

static Napi::Value WriteLogs(const Napi::CallbackInfo& info);

Napi::Value AttachSaveStorage(const Napi::CallbackInfo& info);
Napi::Value Tick(const Napi::CallbackInfo& info);
Napi::Value On(const Napi::CallbackInfo& info);
Expand All @@ -33,7 +35,6 @@ class ScampServer : public Napi::ObjectWrap<ScampServer>
Napi::Value SetEnabled(const Napi::CallbackInfo& info);
Napi::Value CreateBot(const Napi::CallbackInfo& info);
Napi::Value GetUserByActor(const Napi::CallbackInfo& info);
Napi::Value WriteLogs(const Napi::CallbackInfo& info);
Napi::Value GetUserIp(const Napi::CallbackInfo& info);

Napi::Value GetLocalizedString(const Napi::CallbackInfo& info);
Expand Down
3 changes: 3 additions & 0 deletions skymp5-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
},
"author": "Leonid Pospelov <pospelovlm@yandex.ru>",
"dependencies": {
"@octokit/rest": "^20.0.2",
"@types/lodash": "^4.14.202",
"argparse": "^2.0.1",
"axios": "^1.6.0",
"chokidar": "^3.5.3",
Expand All @@ -17,6 +19,7 @@
"koa-proxy": "^1.0.0-alpha.3",
"koa-router": "^12.0.0",
"koa-static": "^5.0.0",
"lodash": "^4.17.21",
"source-map-support": "^0.5.21",
"ws": "^8.13.0"
},
Expand Down
12 changes: 10 additions & 2 deletions skymp5-server/ts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@ yarn_execute_command(
COMMAND install
)

file(GLOB_RECURSE sources ${SKYMP5_SERVER_SOURCE_DIR}/ts/*)
file(GLOB_RECURSE sources ${CMAKE_CURRENT_LIST_DIR}/*.ts)

set(out
${CMAKE_BINARY_DIR}/dist/server/dist_back/skymp5-server.js
)
add_custom_command(
OUTPUT ${out}
COMMAND yarn --cwd "\"${SKYMP5_SERVER_SOURCE_DIR}\"" build-ts
DEPENDS ${sources}
)
add_custom_target(skymp5-server-ts ALL
DEPENDS ${out}
SOURCES ${sources}
COMMAND yarn --cwd "\"${SKYMP5_SERVER_SOURCE_DIR}\"" build-ts
)
Loading

0 comments on commit e2727d8

Please sign in to comment.