Skip to content

Commit

Permalink
Fixed last issues with config being incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
NullSoldier committed Jul 12, 2017
1 parent 639bcdd commit 9bb1a04
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Conan Server Manager (now known as Server Thrall) is a python based dedicated se
| **UptimeTracker** | Records the percentage of time the server has been online. If the server thrall is closed, this counts against the uptime percentage. | **enabled**: Set to true or false to prevent this plugin from running<br>**seconds_up**: The total amount of seconds the server has been up<br>**initial**: unix timestamp of when the server uptime started to be recorded. Delete this to restart your uptime counter |
| **RaidPlugin** | Allows you to set a period of time under which "Raiding" is enabled. This means that building damage will only be enabled during this time. Works by changing the games configuration and rebooting the server at the boundries of raiding times. This plugin modifies the CanDamagePlayerOwnedStructures option in ServerSettings. | **enabled**: Set to true or false to prevent this plugin from running<br>**start_hour**: The hour of the day that raiding should be enabled. This should be in 24 hour time. So 17 would be 5pm in the servers computers timezone.<br>**length_in_hours**: The number of hours after start_hour that raiding should be enabled. |
| **ApiUploader** | Uploads your server data to serverthrallapi so you can see your data online. If your **server_id** was `2`, and your **private_secret** was `200cd768-5b1d-11e7-9e82-d60626067254` you would access your servers characters at this URL: https://serverthrallapi.herokuapp.com/api/2/characters?private_secret=200cd768-5b1d-11e7-9e82-d60626067254 | **enabled**: Set to true or false to prevent this plugin from running<br>**server_id**: The registered server id with serverthrallapi, used to access your data.<br>**public_secret**: A public code you can give to your players to access a "public" view of your servers data. This is unused but will be used later.<br>**private_secret** A secret code that is used to make modifications to your server and synchronize data. Do NOT give this out to your players |
| **ServerConfig** | Allows you to configure common server settings from your server thrall config. If the config differs from expected, the config will be edited and the server restarted. **NOTE** This even works for NetServerMaxTickRate which needs to be written to DefaultEngine, but all other settings get written to saved settings. |**enabled**: Set to true or false to prevent this plugin from running<br> **ServerName**=My Server: Sets the name that will be displayed in the server list.<br> **ServerPassword**=Password123: Sets the server password that will need to be entered to join the server. Leave blank for no password.<br> **GameServerQueryPort**=27015: Sets the query port for Steam matchmaking. Same as setting -QueryPort in the command line.<br> **Port**=7777: Sets the game server port.<br> **MaxPlayers**=70: Sets the maximum number of players.<br> **AdminPassword**=SecretPassword: Sets the administrative password for the server. This will grant players administrative rights when used from the settings menu in-game.<br> **MaxNudity**=2: Sets the maximum nudity level allowed on the server. (0=None, 1=Partial, 2=Full)<br> **IsBattleEyeEnabled**=True: Enables/disables BattlEye protection for the server.<br> **ServerRegion**=1: Sets the server's region. (0=EU, 1=NA, 2=Asia)<br> **ServerCommunity**=1: Sets the server's play style (0=None, 1=Purist, 2=Relaxed, 3=Hard Core, 4=Role Playing, 5=Experimental)<br> **PVPBlitzServer**=False: Enables/disables Blitz mode. (accelerated progression)<br> **PVPEnabled**=True: Enables/disables PvP on the server.<br> **NetServerMaxTickRate**=30: Sets the maximum tick rate (update rate) for the server. **WARNING**: High values can cause unwanted behavior.<br> |
| **ServerConfig** | Allows you to configure common server settings from your server thrall config. If the config differs from expected, the config will be edited and the server restarted. |**enabled**: Set to true or false to prevent this plugin from running<br> **ServerName**=My Server: Sets the name that will be displayed in the server list.<br> **ServerPassword**=Password123: Sets the server password that will need to be entered to join the server. Leave blank for no password.<br> **QueryPort**=27015: Sets the query port for Steam matchmaking. Same as setting -QueryPort in the command line.<br> **Port**=7777: Sets the game server port.<br> **MaxPlayers**=70: Sets the maximum number of players.<br> **AdminPassword**=SecretPassword: Sets the administrative password for the server. This will grant players administrative rights when used from the settings menu in-game.<br> **MaxNudity**=2: Sets the maximum nudity level allowed on the server. (0=None, 1=Partial, 2=Full)<br> **IsBattleEyeEnabled**=True: Enables/disables BattlEye protection for the server.<br> **ServerRegion**=1: Sets the server's region. (0=EU, 1=NA, 2=Asia)<br> **ServerCommunity**=1: Sets the server's play style (0=None, 1=Purist, 2=Relaxed, 3=Hard Core, 4=Role Playing, 5=Experimental)<br> **PVPBlitzServer**=False: Enables/disables Blitz mode. (accelerated progression)<br> **PVPEnabled**=True: Enables/disables PvP on the server.<br> **NetServerMaxTickRate**=30: Sets the maximum tick rate (update rate) for the server. **WARNING**: High values can cause unwanted behavior.<br> |


### Example Config
Expand Down
3 changes: 2 additions & 1 deletion serverthrall/conanconfig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def __init__(self, conan_server_directory):
}

self.logger = logging.getLogger('serverthrall.conan_config')
self.logger.setLevel(logging.DEBUG)

def refresh(self):
groups = {}
Expand Down Expand Up @@ -91,6 +90,8 @@ def set(self, group, section, option, value, first=False):
self.dirty[group][index][section][option] = value
self.groups[group][index].set(section, option, value)

return self.group_paths[group][index]

def setboolean(self, group, section, option, value):
self.set(group, section, option, 'True' if value else 'False')

Expand Down
3 changes: 1 addition & 2 deletions serverthrall/conanserver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from .conanconfig import ConanConfig
import subprocess
import psutil
import time
Expand All @@ -13,7 +12,7 @@ def __init__(self, path, steamcmd, arguments, high_priority):
self.path = path
self.steamcmd = steamcmd
self.arguments = arguments
self.high_priority = high_priority;
self.high_priority = high_priority
self.logger = logging.getLogger('serverthrall')
self.process = None

Expand Down
20 changes: 10 additions & 10 deletions serverthrall/plugins/serverconfig.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from .thrallplugin import ThrallPlugin
from configparser import NoOptionError, NoSectionError
from configparser import NoOptionError


class ServerConfig(ThrallPlugin):

CONFIG_MAPPING = {
'ServerName': ('Engine', 'OnlineSubsystemSteam', 'ServerName'),
'ServerPassword': ('Engine', 'OnlineSubsystemSteam', 'ServerPassword'),
'GameServerQueryPort': ('Engine', 'OnlineSubsystemSteam', 'GameServerQueryPort'),
'QueryPort': ('Engine', 'OnlineSubsystemSteam', 'QueryPort'),
'Port': ('Engine', 'URL', 'Port'),
'MaxPlayers': ('Game', '/Script/Engine.GameSession', 'MaxPlayers'),
'AdminPassword': ('ServerSettings', 'ServerSettings', 'AdminPassword'),
Expand All @@ -20,15 +20,15 @@ class ServerConfig(ThrallPlugin):
'NetServerMaxTickRate': ('Engine', '/Script/OnlineSubsystemUtils.IpNetDriver', 'NetServerMaxTickRate'),
}

FIRST_WHITE_LIST = ('NetServerMaxTickRate',)
DEFAULT_WHITE_LIST = []

def config_get_safe(self, src):
try:
return self.config.get(src)
except NoOptionError:
return None

def sync_mapping(self,mapping):
def sync_mapping(self, mapping):
changed = False

for src, dest in self.CONFIG_MAPPING.items():
Expand All @@ -37,20 +37,20 @@ def sync_mapping(self,mapping):
value = self.config_get_safe(src)
original = self.thrall.conan_config.get(group, section, option)

path = '%s/%s/%s=%s'

if value is not None and value != original:
self.logger.info('Syncing option %s to %s/%s/%s as %s' % (src, group, section, option, value))
self.thrall.conan_config.set(group, section, option, value, option in self.FIRST_WHITE_LIST)
use_default_config = option in self.DEFAULT_WHITE_LIST
path = self.thrall.conan_config.set(group, section, option, value, use_default_config)
self.logger.info('Syncing %s.%s=%s, %s' % (section, option, value, path))
changed = True

return changed

def tick(self):
self.thrall.conan_config.refresh()
changed = self.sync_mapping(self.CONFIG_MAPPING)

if changed:
self.thrall.conan_config.save()
self.logger.info('Restarting server for config to take into affect')
self.server.close()
self.server.start()
self.thrall.conan_config.save()
self.server.start()
9 changes: 4 additions & 5 deletions serverthrall/plugins/serverupdater.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import datetime
import time
import subprocess
import os
import os


class ServerUpdater(IntervalTickPlugin):
Expand All @@ -19,7 +19,7 @@ def __init__(self, config):
def ready(self, steamcmd, server, thrall):
super(ServerUpdater, self).ready(steamcmd, server, thrall)
self.installed_version = self.config.get('installed_version')

if self.installed_version == self.NO_INSTALLED_VERSION:
self.detect_existing_version()

Expand Down Expand Up @@ -109,6 +109,5 @@ def tick_interval(self):
self.logger.info('An update is available from build %s to %s' % (current, target))
self.server.close()
self.update_server(target)
self.server.start()


self.thrall.conan_config.refresh()
self.server.start()
2 changes: 1 addition & 1 deletion serverthrall/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
steamcmd_logger.setLevel(logging.WARNING)

conan_config_logger = logging.getLogger('serverthrall.conan_config')
conan_config_logger.setLevel(logging.WARNING)
conan_config_logger.setLevel(logging.INFO)
2 changes: 2 additions & 0 deletions tests/test_conanconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ def test_set_hierarchy(self):

self.config.group_paths = {'Test': [parent, child]}
self.config.refresh()

assert self.config.get('Test', 'URL', 'Port') == '7777'

self.config.set('Test', 'URL', 'Port', '7778', first=True)
self.config.set('Test', 'URL', 'Port', '7778')
self.config.save()
Expand Down

0 comments on commit 9bb1a04

Please sign in to comment.