|
@@ -11,18 +11,22 @@ from twisted.python import log
|
|
|
from twisted.python.logfile import DailyLogFile
|
|
|
import pendulum
|
|
|
from subprocess import check_output
|
|
|
-
|
|
|
+import os
|
|
|
from colorama import Fore, Back, Style
|
|
|
|
|
|
from pprint import pformat
|
|
|
|
|
|
-# This isn't the best configuration, but it's simple
|
|
|
-# and works. Mostly.
|
|
|
+import yaml
|
|
|
+
|
|
|
+def config_load(filename):
|
|
|
+ global config
|
|
|
+ with open(filename, 'r') as fp:
|
|
|
+ config = yaml.safe_load(fp)
|
|
|
|
|
|
-try:
|
|
|
- from config_dev import *
|
|
|
-except ModuleNotFoundError:
|
|
|
- from config import *
|
|
|
+if os.path.exists('config_dev.yaml'):
|
|
|
+ config_load('config_dev.yaml')
|
|
|
+else:
|
|
|
+ config_load('config.yaml')
|
|
|
|
|
|
# Extract the version information from git.
|
|
|
# The match gives us only tags starting with v[0-9]* Using anything else trips up on double digits.
|
|
@@ -127,7 +131,7 @@ class Game(protocol.Protocol):
|
|
|
|
|
|
def lineReceived(self, line):
|
|
|
""" line received from the game. """
|
|
|
- if LOG_LINES:
|
|
|
+ if 'log_lines' in config and config['log_lines']:
|
|
|
log.msg("<< [{0}]".format(line))
|
|
|
|
|
|
# if "TWGS v2.20b" in line and "www.eisonline.com" in line:
|
|
@@ -292,7 +296,7 @@ class Player(protocol.Protocol):
|
|
|
self.glue = factory
|
|
|
|
|
|
# Make connection to the game server
|
|
|
- reactor.connectTCP(HOST, PORT, factory, 5)
|
|
|
+ reactor.connectTCP(config['host'], config['port'], factory, 5)
|
|
|
|
|
|
def setGameReceived(self):
|
|
|
""" Get deferred from client queue, callback clientDataReceived. """
|
|
@@ -382,7 +386,7 @@ class Player(protocol.Protocol):
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
- if LOGFILE:
|
|
|
+ if 'logfile' in config and config['logfile']:
|
|
|
log.startLogging(DailyLogFile("proxy.log", "."))
|
|
|
else:
|
|
|
log.startLogging(sys.stdout)
|
|
@@ -390,5 +394,12 @@ if __name__ == "__main__":
|
|
|
log.msg("This is version: %s" % version)
|
|
|
factory = protocol.Factory()
|
|
|
factory.protocol = Player
|
|
|
- reactor.listenTCP(LISTEN_PORT, factory, interface=LISTEN_ON)
|
|
|
+ reactor.listenTCP(config['listen_port'], factory, interface=config['listen_on'])
|
|
|
reactor.run()
|
|
|
+else:
|
|
|
+ # I can't seem to get twistd -y tcp-proxy.py
|
|
|
+ # to work. Missing imports?
|
|
|
+ application = service.Application("TradeWarsGameServer-Proxy")
|
|
|
+ factory = protocol.Factory()
|
|
|
+ factory.protocol = Player
|
|
|
+ internet.TCPServer(config['listen_port'], factory).setServiceParent(application)
|