Skip to content

Instantly share code, notes, and snippets.

@gallexme
Created November 18, 2018 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gallexme/25eb9ec323652625e8572730c3813c8d to your computer and use it in GitHub Desktop.
Save gallexme/25eb9ec323652625e8572730c3813c8d to your computer and use it in GitHub Desktop.
{lib, pkgs, config, packages, ... }:
with lib;
let
cfg = config.services.dzServer;
wine = pkgs.wine.override { wineBuild = "wine64";wineRelease = "staging"; };
dzServerConfig = pkgs.writeText "dzServer.cfg" ''
hostname = "MisterOutofTimes Deathmatch"; // Server name
password = ""; // Password for connection to the server
passwordAdmin = "admin"; // Password to become server admin
maxPlayers = 127; // Maximum amount of players
motd[]= {"MisterOutofTime"};
motdInterval = 5;
verifySignatures = 0; // Verifies .pbos against .bisign files. (use only 2)
forceSameBuild = 1; // Server will allow connection only to clients with same exe revision as server when active (value 0-1)
disablePublisherBanKick = true;
disableVAC = true;
logAI=1;
logAverageFps = 1; // Logs the average server FPS (value in seconds), needs to have -dologs launch parameter active
logMemory = 1; // Logs the server memory usage (value in seconds), needs to have the -dologs launch parameter active
logPlayers = 1;
disableVoN = 0; // Enable/disable voice over network (value 0-1)
vonCodecQuality = 7; // Voice over network codec quality (values 0-30)
disable3rdPerson=0; //turn on/off 3rd person view for players on the particular server instance (value 0-1)
disableCrosshair=0; //turn on/off cross-hair on the particular server instance (value 0-1)
serverTime="2018/4/8/12/00"; // Server Start Time // Initial ingame time of server. "SystemTime" means local time of machine. Another possibility is to set the time to some value in "YYYY/MM/DD/HH/MM" format, f.e. "2015/4/8/17/23" .
serverTimeAcceleration=24; // Accelerated Time (value 0-24) // This is a time multiplier for in-game time. In this case time would move 24 times faster than normal, an entire day would pass in one hour.
serverTimePersistent=0; // Persistent Time (value 0-1) // Actual server time is saved to storage, so when active, next server start will use saved time value.
battleEye = 0;
guaranteedUpdates=1; // Communication protocol used with game server (use only number 1)
loginQueueConcurrentPlayers=5; // Number of players concurrently processed during login process. Should prevent massive performance drop during connection when a lot of people are connecting in the same time.
loginQueueMaxPlayers=500; // Maximum number of players that can wait in login queue
steamPort = ${toString((toInt cfg.port) +2)};
steamQueryPort = ${toString((toInt cfg.port) +1)};
instanceId = 32; // DayZ server instance id to identify number of instances per box and their storage folders with persistence files
lootHistory = 1; // how many persistence history files should been kept by instance, number is looped over during save
storeHouseStateDisabled = false; // Disable houses/doors persistence (value true/false), usable in case of problems with persistence
storageAutoFix = 1; // Checks if persistence files are corrupted and replaces corrupted ones with empty ones (value 0-1)
enableDebugMonitor=1;
respawnTime = 1;
onLoadMission= "start";
onLoadMissionTime="test";
onLoadIntro="creash";
onLoadIntroTime="log.txt";
enableItemsDropping=0;
statisticsEnabled=1;
demo=1;
class Missions
{
class DayZ
{
template="${cfg.missionName}"; //used mission //first part is mission name, second part is used map
};
};
'';
in {
options.services.dzServer = {
enable = mkEnableOption "dzServer service";
varPath = mkOption {
default = "/home/dayz/dzServer";
type = types.string;
description = ''Path of read/write files needed for operation and configuration.'';
};
port = mkOption {
default = "2302";
type = types.string;
description = ''TCP port number for dzServer to bind to.'';
};
profilePath = mkOption {
default = "profile";
type = types.string;
description = ''Path of log files needed for operation and configuration.'';
};
steamUsername = mkOption {
default = "";
type = types.string;
description = ''Path of log files needed for operation and configuration.'';
};
steamPassword = mkOption {
default = "";
type = types.string;
description = ''Path of log files needed for operation and configuration.'';
};
missionName = mkOption {
default = "mine.chernarusplus";
type = types.string;
description = ''Path of log files needed for operation and configuration.'';
};
missionGit = mkOption {
default = "https://github.com/gallexme/samission.git";
type = types.string;
description = ''Path of log files needed for operation and configuration.'';
};
};
config = lib.mkIf cfg.enable (
mkMerge [{
systemd.services.dzServerInit = {
description = "DayzServer initial task";
after = [ "network.target" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = false;
};
script = ''
if ! test -e ${cfg.varPath}/$d; then
${pkgs.coreutils}/bin/mkdir -m0700 --p {${cfg.varPath},${cfg.varPath}/${cfg.profilePath}}
${pkgs.steamcmd }/bin/steamcmd +@sSteamCmdForcePlatformType windows +login ${cfg.steamUsername} ${cfg.steamPassword} +force_install_dir ${cfg.varPath} +app_update 223350 validate +quit
fi
if ! test -e ${cfg.varPath}/mpmissions/${cfg.missionName}$d; then
${pkgs.git}/bin/git clone ${cfg.missionGit} ${cfg.varPath}/mpmissions/${cfg.missionName}
else
pushd
cd ${cfg.varPath}/mpmissions/${cfg.missionName}
${pkgs.git}/bin/git pull
popd
fi
cp -rf ${dzServerConfig} ${cfg.varPath}/${cfg.profilePath}/dzServer.cfg
'';
};
} {
systemd.services.dzServer = {
after = [ "dzServerInit.service" ];
description = "DayZServer";
restartIfChanged = true;
environment = {WINEARCH = "win64"; WINEPREFIX = "/root/.wine64"; };
serviceConfig = {
#ExecStart = "${pkgs.xvfb_run }/bin/xvfb-run --auto-servernum --server-args='-screen 0 640x480x24:32' ${wine}/bin/wine ${cfg.varPath}/DayZServer_x64.exe ${cfg.profilePath}/serverDZ.cfg -port=${cfg.port} -BEpath=battleye -profiles=${cfg.profilePath} -dologs -netlog -adminlog -enDebugPlayerPositions=1";
ExecStart = "${pkgs.xvfb_run }/bin/xvfb-run --auto-servernum --server-args='-screen 0 640x480x24:32' ${wine}/bin/wine ${cfg.varPath}/DayZServer_x64.exe ${cfg.profilePath}/dzServer.cfg -port=${cfg.port} -BEpath=battleye -profiles=${cfg.profilePath} -dologs -netlog -adminlog -enDebugPlayerPositions=1";
WorkingDirectory ="${cfg.varPath}";
Restart = "always";
};
};
}]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment