Skip to content

Commit

Permalink
Merge pull request #113 from mr-guard/experimental
Browse files Browse the repository at this point in the history
Experimental
  • Loading branch information
mr-guard authored Feb 24, 2024
2 parents e696b0c + 5fbc391 commit 9e994de
Show file tree
Hide file tree
Showing 14 changed files with 249 additions and 162 deletions.
43 changes: 27 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Also supports linux server (See [Linux Server Usage](#linux-server))
<br><a name="requirements"></a>
## Installation Requirements <hr>

* A Windows (Root) Server with RDP/Shell access
* A Windows or linux (Root) Server with RDP/Shell access
* hosted instances (like nitrado) cannot use this EXCEPT they can run arbitrary programs
* To download mods: A steam account that owns DayZ and has SteamGuard set to EMAIL or DEACTIVATED!
* That's it!
Expand All @@ -124,26 +124,27 @@ Also supports linux server (See [Linux Server Usage](#linux-server))
## Usage <hr>

* Download the [latest version](https://github.com/mr-guard/dayz-server-manager/releases/latest) of the manager
* Extract the manager and the config template
* Copy and rename the config template to `server-manager.json`
* Extract the manager in the directory where you want your serverfiles to be
* Start the manager once to create a new config with default values
* Edit the `server-manager.json` config to fit your needs
* Fill the required fields (everything is described in the file)
`!IMPORTANT! Change the admin and rcon password`
* Other than that the defaults will probably fit your needs
* You can also checkout the [configuration guides](#configuration)
* Start the manager in the folder where the config is situated

* Start the manager and it will use the updated config
<br>
* It is recommended to create a separate Steam account which owns DayZ. You need to set SteamGuard to EMAIL or DEACTIVATED! Do not use Mobile authenticator because those codes will not be saved on the server and need to be entered on every download/update.

* Optionally you can add it as Windows Service instead of launching it manually
<br>
* Optionally you can add it as Windows/Linux Service instead of launching it manually
<br>
* Make sure the "Execution Location" is the folder, where the config is located (this is not necessarily the folder where the manager executable is located)

<br><a name="updating"></a>
## Updating <hr>

This app was written with backwards compatibility in mind.<br>
Sometimes, however, some bracking changes to the server manager config will occur.<br>
The best strategy to update is to take the config template of the new version and and modify it to match your old version.<br>
Sometimes, however, some breaking changes to the server manager config will occur.<br>
The best strategy to update, is to take the config template of the new version and modify it to match your old values.<br>
This way you can not miss out on new properties which might be required.<br>

<br><a name="configuration"></a>
Expand Down Expand Up @@ -205,17 +206,17 @@ The example snippet shows how to add an admin, a manager and a moderator.<br>
...
"admins": [
{
"userId": "FunkyDude#1234",
"userId": "FunkyDude",
"userLevel": "admin",
"password": "admin"
},
{
"userId": "TheDude#4242",
"userId": "the-discord-dude",
"userLevel": "manage",
"password": "somecoolpassword"
},
{
"userId": "InternDude#4321",
"userId": "InternDude",
"userLevel": "moderate",
"password": "somoderatormuchwow"
}
Expand Down Expand Up @@ -420,7 +421,7 @@ If the manager crashes or shuts down, your dayz server will also be shut down.
Replace `/dayz` with the directory you want your server to be in, but make sure its already created
```sh
useradd --system -m -d /dayz -s /bin/bash dayz
chown dayz:dayz /dayz && \
chown dayz:dayz /dayz
```
3. Download and extract the latest linux release from the releases page
4. Setup the manager files
Expand Down Expand Up @@ -534,7 +535,6 @@ If you are really paranoid about pasting your password somewhere, or you use ste
* Provide self generated/signed certificates for HTTPS
* More script hooks
* Custom discord commands
* Edit/View Bans in WebUI
* Examples and integration scripts for Workbench (for mod Development)

<br><a name="folder-layout"></a>
Expand All @@ -550,6 +550,8 @@ If you are really paranoid about pasting your password somewhere, or you use ste
----- steamcmd.exe
----- ..
-- Workshop // contains the actual workshop mods
-- STEAM_GUARD_CODE // Optional text file. Containing only your steam guard code. will be deleted after usage. See Known Issues / Limitations for more details.
-- SERVER_LOCK // Optional file. If exists server restarts will be skipped
```

You can, however, change these paths to fit your needs
Expand All @@ -560,8 +562,9 @@ You can, however, change these paths to fit your needs
The server manager is a self contained NodeJS-App written in TypeScript and packaged with pkg.
You DON'T need to install NodeJS or anything else.
Everything you need is contained in the single executable (exe).
However, due to that the exe is around 50MB in size.
This tool makes use of the windows commandline tools (namely netsh and wmic) to determine installation requirements and the state of the server.
However, due to that the exe is around 90MB in size.
This tool makes use of the windows commandline tools (namely netsh and wmic) or the linux cli tools and procfs to determine installation requirements and the state of the server.
It is recommended NOT to use an elevated user for running it.
<br><a name="security"></a>
## Security <hr>
Expand Down Expand Up @@ -604,6 +607,14 @@ This way the traffic is handled securely until terminated at the reverse proxy.<
<br>
* SteamCMD Rate-Limit:
* The SteamCMD rate limit might occur if you download many mods at once (i.e. first setup)
* You will see an error that includes status code = 5 or rate limit
* this is nothing bad.. you are not banned.. you just need to wait some time and retry
* the manager already tries to downloads mods in batches to prevent this by default, but sometimes thats not enough
<br>
* Apparently the steam cmd reverts changes to the default mission `dayzOffline.ChernarusPlus` when validating the isntallation..
* to prevent this simply add your own mission
* simply copy `dayzOffline.chernarusplus` and rename it to `dayz.chernarusplus` (or something else)
Expand Down
40 changes: 40 additions & 0 deletions src/config/config-file-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { inject, injectable, singleton } from 'tsyringe';
import { FSAPI, InjectionTokens } from '../util/apis';
import { IService } from '../types/service';
import { LoggerFactory } from '../services/loggerfactory';
import { origExit } from '../util/exit-capture';
import { randomUUID } from 'crypto';
import { detectOS } from '../util/detect-os';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const configschema = require('./config.schema.json');
Expand Down Expand Up @@ -96,4 +99,41 @@ export class ConfigFileHelper extends IService {
}
}

public createDefaultConfig(): void {

const cfgPath = this.getConfigFilePath();

if (!this.fs.existsSync(cfgPath)) {
const defaultConfig = commentJson.parse(generateConfigTemplate(configschema)) as any as Config;

// apply safe defaults
defaultConfig.admins[0].password = randomUUID();
defaultConfig.ingameApiKey = randomUUID();
defaultConfig.rconPassword = randomUUID();
defaultConfig.serverCfg.passwordAdmin = randomUUID();

// linux specifics
if (detectOS() !== 'windows') {
defaultConfig.serverExe = 'DayZServer';
}

this.fs.writeFileSync(
cfgPath,
commentJson.stringify(defaultConfig, null, 2),
);

console.log('\n\n\n');
console.log('Did not find a server manager config!');
console.log(`Created a new config with default values at: ${cfgPath}`);
console.log('Adjust the config to fit your needs and restart the manager!');
console.log('\n\n');

if (typeof global.it === 'function') {
return;
}
origExit(0); // end process
}

}

}
6 changes: 2 additions & 4 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ export class Config {
*
* example:
* {
* "userId": "senfo",
* "password": "admin",
* "userId": "admin",
* "password": "my-password",
* "userLevel": "admin"
* }
*
Expand Down Expand Up @@ -536,14 +536,12 @@ export class Config {
* Whether or not to publish the Ingame Rest API
*
* Same as publish webport but for the Ingame REST API.
* Can be used for shared hives / provide the api for external servers.
*/
public publishIngameApi: boolean = false;

/**
* Alternative host for the Ingame Rest API.
*
* Can be used for shared hives.
* Provide "ip:port" to make the addon connect to another Ingame API.
*/
public ingameApiHostOverride: string | null = null;
Expand Down
17 changes: 13 additions & 4 deletions src/control/manager-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { MetricsCollector } from '../services/metrics-collector';
import { IngameREST } from '../interface/ingame-rest';
import { SyberiaCompat } from '../services/syberia-compat';
import { DiscordEventConverter } from '../services/discord-event-converter';
import { ConfigFileHelper } from '../config/config-file-helper';

@singleton()
@registry([
Expand Down Expand Up @@ -123,7 +124,8 @@ export class ManagerController {

private working = false;
private started = false;
private skipInitialCheck: boolean = false;

private skipInit: boolean = process.argv.includes('--skip-init');

private log: Logger;

Expand All @@ -137,6 +139,7 @@ export class ManagerController {
private requirements: Requirements,
private discord: DiscordBot,
private discordEvents: DiscordEventConverter,
private configFileHelper: ConfigFileHelper,
) {
this.log = loggerFactory.createLogger('Bootstrap');
}
Expand Down Expand Up @@ -200,6 +203,8 @@ export class ManagerController {

public async start(): Promise<void> {

this.configFileHelper.createDefaultConfig();

if (this.working) {
this.log.log(LogLevel.DEBUG, `Start called while ${this.started ? 'stopping' : 'starting'}`);
return;
Expand All @@ -225,15 +230,19 @@ export class ManagerController {
process.title = `Server-Manager ${this.manager.getServerExePath()}`;

// check any requirements before even starting
await this.requirements.check();
if (!this.skipInit) {
await this.requirements.check();
}

this.log.log(LogLevel.DEBUG, 'Setting up services..');

// init
this.log.log(LogLevel.DEBUG, 'Services are set up');
try {

await this.initialSetup();
if (!this.skipInit) {
await this.initialSetup();
}

this.log.log(LogLevel.DEBUG, 'Initial Check done. Starting Init..');
for (const service of this.getStatefulServices()) {
Expand Down Expand Up @@ -284,7 +293,7 @@ export class ManagerController {

private async initialSetup(): Promise<void> {

if (this.skipInitialCheck || await this.serverDetector.isServerRunning()) {
if (await this.serverDetector.isServerRunning()) {
this.log.log(LogLevel.IMPORTANT, 'Skipping initial SteamCMD check because the server is already running');
return;
}
Expand Down
17 changes: 17 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ import { isRunFromWindowsGUI } from './util/is-run-from-gui';
import * as childProcess from 'child_process';
import * as fs from 'fs';
import { container } from 'tsyringe';
import { origExit } from './util/exit-capture';

const helpText = `
Usage
$ dayz-server-manager
Options
--skip-init Skip the init process (requirements check, server update, mod update)
--start-locked Activates the server restart lock so it does not start the dayz server when the manager starts
--skip-events Skips execution of scheduled events
`;

if (process.argv.includes('--help')) {
console.log(helpText);
origExit(0);
}


void (async () => {

Expand Down
Loading

0 comments on commit 9e994de

Please sign in to comment.