Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit 3df480b

Browse files
committed
Add Test Mode to skip RCON commands and testing
hide "_" the Config class's internal attributes to avoid accidental use
1 parent 60b2a8d commit 3df480b

File tree

6 files changed

+27
-17
lines changed

6 files changed

+27
-17
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Streamlabs-Rcon-Integration
22

33

4-
A Python exe for integrating Streamlabs and any game supporting Rcon. Its currently being used with Factorio, but should be compatible with any other Rcon interfaced game.
4+
A Python exe for integrating Streamlabs and any game supporting Rcon. It receives the Streamlabs events and uses configurable logic to send an approperiate RCON command to the game server to do something. Its currently being used with Factorio, but should be compatible with any other Rcon interfaced game.
55

66
At present only really tested with Twitch, but should work with mixer and youtube based on API spec.
77

@@ -53,6 +53,8 @@ Profile configuration files must be created with knowledge of quote escaping. Th
5353

5454
Manipulator script's are special in that they support raw python code that will be executed within a Python exec() function in addition to a python expression that is executed within a Python eval() function. The event handler will try to eval() the manipulator script first and should it error then try to exec() the manipulator script. As the manipulator script is supplied via the profile JSON file it must be in a single line format with `\n` for the line breaks. The Python maths module is included within the execution environment. The local variable `calcValue` is passed out of the exec environment as the value of `CALCVALUE`. See the `Factorio - Advanced Usage Example.json` for examples of the some of these combinations.
5555

56+
The config has a `Test Mode` option. When enabled it prints the RCON commands to the activity window rather than sending them. It also skips the RCON connection test which the Start button is clicked within the app. In effect not doing any RCON commands.
57+
5658

5759
Development Building
5860
=============

Source/Config.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
class Config():
66
def __init__(self, state):
77
self.state = state
8-
self.fileName = "config.json"
9-
self.settings = {}
10-
if Os.path.isfile(self.fileName):
11-
with open(self.fileName, "r") as file:
8+
self._fileName = "config.json"
9+
self._settings = {}
10+
if Os.path.isfile(self._fileName):
11+
with open(self._fileName, "r") as file:
1212
data = Json.load(file)
1313
file.closed
14-
self.settings = data
15-
self.settingsMissing = []
14+
self._settings = data
15+
self._settingsMissing = []
1616
self._PopulateMissingConfigDefaults()
1717

1818
def _PopulateMissingConfigDefaults(self):
@@ -26,17 +26,18 @@ def _PopulateMissingConfigDefaults(self):
2626
"Rcon Server Address": "",
2727
"Rcon Server Port": 25575,
2828
"Rcon Server Password": "",
29-
"Rcon Test Command": "/version"
29+
"Rcon Test Command": "/version",
30+
"Test Mode": False
3031
}
3132
for name, value in defaults.items():
32-
if not name in self.settings:
33-
self.settings[name] = value
34-
self.settingsMissing.append(name)
33+
if not name in self._settings:
34+
self._settings[name] = value
35+
self._settingsMissing.append(name)
3536

3637
def LogMissingSettings(self):
37-
for name in self.settingsMissing:
38+
for name in self._settingsMissing:
3839
self.state.logging.Log(
3940
"Config key missing, using default: " + name)
4041

4142
def GetSetting(self, name):
42-
return self.settings[name]
43+
return self._settings[name]

Source/Rcon.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def __init__(self, state):
1212
self.testCommand = self.state.config.GetSetting("Rcon Test Command")
1313

1414
def TestConnection(self):
15+
if self.state.config.GetSetting("Test Mode"):
16+
return True
1517
try:
1618
self.SendCommand(self.testCommand)
1719
return True
@@ -22,5 +24,9 @@ def TestConnection(self):
2224
return False
2325

2426
def SendCommand(self, commandString):
27+
if self.state.config.GetSetting("Test Mode"):
28+
self.state.RecordActivity(
29+
self.state.translations.GetTranslation("Rcon TestMode") + commandString)
30+
return ""
2531
with MCRcon(self.serverAddress, self.serverPassword, self.serverPort) as mcr:
2632
return mcr.command(commandString)

Source/Translations.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def LoadLocalisedTexts(self, language):
2929
"StreamlabsEvent EventHandled": "Event Handled: ",
3030
"Rcon CommandError": "ERROR: Rcon command failed, run manually: ",
3131
"Rcon CommandResponseWarning": "WARNING: Rcon got response from server: ",
32-
"Rcon TestErrorMessage": "Rcon connection test message: "
32+
"Rcon TestErrorMessage": "Rcon connection test message: ",
33+
"Rcon TestMode": "Rcon Test Mode: "
3334
}
3435

3536
def GetTranslation(self, key):

Source/config.sample.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
"Rcon Server Address": "",
99
"Rcon Server Port": 25575,
1010
"Rcon Server Password": "",
11-
"Rcon Test Command": "/version"
11+
"Rcon Test Command": "/version",
12+
"Test Mode": false
1213
}

ToDo.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Have a way to pause logs from updating and then resume
66
Add a way to fire test events data at this to allow better testing of responses than the Streamlabs Test Widgets button.
77
Support multiple calculated values via exec. Array in exec, to numbered strings in action script.
88
Support multiple rcon commands as an array in JSON.
9+
Handle paused Factorio server accepting but not reply to RCON command. It will honor the command when the server is unpaused. So different between start test connection and event handling.
910

1011

1112

@@ -15,5 +16,3 @@ Support multiple rcon commands as an array in JSON.
1516
add option for getting gift subscriptions from the gifter view as well as from the receiver view
1617

1718
can have multiple payloads per event. need to split these up to separate events internally.
18-
19-

0 commit comments

Comments
 (0)