diff --git a/admin_page_server.py b/admin_page_server.py index 6338531..26f2835 100644 --- a/admin_page_server.py +++ b/admin_page_server.py @@ -29,8 +29,10 @@ import collections import json import os.path import logging + import other.utils as utils import gamespy.gs_utility as gs_utils +import dwc_config logger_output_to_console = True logger_output_to_file = True @@ -478,7 +480,7 @@ class AdminPage(resource.Resource): else: return self.get_header() + self.get_footer() -port = 9009 +_, port = dwc_config.get_ip_port('AdminPage') class AdminPageServer(object): diff --git a/altwfc.cfg b/altwfc.cfg new file mode 100755 index 0000000..831fb6f --- /dev/null +++ b/altwfc.cfg @@ -0,0 +1,51 @@ +# ALTWFC - Configuration File + +[StorageServer] +IP = 127.0.0.1 +Port = 8000 + +[NasServer] +IP = 127.0.0.1 +Port = 9000 +# Port = 80 + +[InternalStatsServer] +IP = 127.0.0.1 +Port = 9001 + +[GameStatsServerHttp] +IP = 127.0.0.1 +Port = 9002 + +[AdminPage] +IP = 127.0.0.1 +Port = 9009 + +[GameSpyManager] +# GamespyBackendServer +IP = 127.0.0.1 +Port = 27500 + +[GameSpyQRServer] +IP = 0.0.0.0 +Port = 27900 + +[GameSpyNatNegServer] +IP = 0.0.0.0 +Port = 27901 + +[GameSpyServerBrowserServer] +IP = 0.0.0.0 +Port = 28910 + +[GameSpyProfileServer] +IP = 0.0.0.0 +Port = 29900 + +[GameSpyPlayerSearchServer] +IP = 0.0.0.0 +Port = 29901 + +[GameSpyGamestatsServer] +IP = 0.0.0.0 +Port = 29920 diff --git a/dwc_config.py b/dwc_config.py new file mode 100755 index 0000000..a034de2 --- /dev/null +++ b/dwc_config.py @@ -0,0 +1,50 @@ +"""DWC Network Server Emulator + + Copyright (C) 2014 SMTDDR + Copyright (C) 2014 kyle95wm + Copyright (C) 2014 AdmiralCurtiss + Copyright (C) 2015 Sepalani + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Configuration module. +""" + +try: + # Python 2 + import ConfigParser +except ImportError: + # Python 3 + import configparser as ConfigParser + + +def get_ip_port(section, filename='altwfc.cfg'): + """Return a tuple (IP, Port) of the corresponding section.""" + config = ConfigParser.RawConfigParser(allow_no_value=True) + config.read(filename) + return (config.get(section, 'IP'), config.getint(section, 'Port')) + + +def get_ip(section, filename='altwfc.cfg'): + """Return the IP of the corresponding section.""" + config = ConfigParser.RawConfigParser(allow_no_value=True) + config.read(filename) + return config.get(section, 'IP') + + +def get_port(section, filename='altwfc.cfg'): + """Return the port of the corresponding section.""" + config = ConfigParser.RawConfigParser(allow_no_value=True) + config.read(filename) + return config.getint(section, 'Port') diff --git a/dwc_network_server_emulator.pyproj b/dwc_network_server_emulator.pyproj index 12d0a08..06d0cb0 100644 --- a/dwc_network_server_emulator.pyproj +++ b/dwc_network_server_emulator.pyproj @@ -30,6 +30,7 @@ + diff --git a/gamespy_backend_server.py b/gamespy_backend_server.py index f74445d..f1ffd11 100644 --- a/gamespy_backend_server.py +++ b/gamespy_backend_server.py @@ -54,6 +54,7 @@ import ast from multiprocessing.managers import BaseManager from multiprocessing import freeze_support import other.utils as utils +import dwc_config class TokenType: @@ -119,7 +120,7 @@ class GameSpyBackendServer(object): ) def start(self): - address = ("127.0.0.1", 27500) + address = dwc_config.get_ip_port('GameSpyManager') password = "" logger.log(logging.INFO, diff --git a/gamespy_gamestats_server.py b/gamespy_gamestats_server.py index 3fa6c5b..dae6a38 100644 --- a/gamespy_gamestats_server.py +++ b/gamespy_gamestats_server.py @@ -35,6 +35,7 @@ import gamespy.gs_database as gs_database import gamespy.gs_query as gs_query import gamespy.gs_utility as gs_utils import other.utils as utils +import dwc_config # Logger settings logger_output_to_console = True @@ -44,7 +45,7 @@ logger_filename = "gamespy_gamestats_server.log" logger = utils.create_logger(logger_name, logger_filename, -1, logger_output_to_console, logger_output_to_file) -address = ("0.0.0.0", 29920) +address = dwc_config.get_ip_port('GameSpyGamestatsServer') class GameSpyGamestatsServer(object): diff --git a/gamespy_natneg_server.py b/gamespy_natneg_server.py index 5601f88..6a3051f 100644 --- a/gamespy_natneg_server.py +++ b/gamespy_natneg_server.py @@ -34,6 +34,7 @@ import other.utils as utils import traceback from multiprocessing.managers import BaseManager +import dwc_config # Logger settings logger_output_to_console = True @@ -64,7 +65,7 @@ class GameSpyNatNegServer(object): self.secret_key_list = gs_utils.generate_secret_keys("gslist.cfg") self.server_manager = GameSpyServerDatabase( - address=("127.0.0.1", 27500), + address=dwc_config.get_ip_port('GameSpyManager'), authkey="" ) self.server_manager.connect() @@ -74,7 +75,7 @@ class GameSpyNatNegServer(object): # Start natneg server # Accessible to outside connections (use this if you don't know # what you're doing) - address = ('0.0.0.0', 27901) + address = dwc_config.get_ip_port('GameSpyNatNegServer') self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.socket.bind(address) diff --git a/gamespy_player_search_server.py b/gamespy_player_search_server.py index 3322060..c473f75 100644 --- a/gamespy_player_search_server.py +++ b/gamespy_player_search_server.py @@ -30,6 +30,7 @@ from twisted.internet.error import ReactorAlreadyRunning import gamespy.gs_database as gs_database import gamespy.gs_query as gs_query import other.utils as utils +import dwc_config # Logger settings logger_output_to_console = True @@ -39,7 +40,7 @@ logger_filename = "gamespy_player_search_server.log" logger = utils.create_logger(logger_name, logger_filename, -1, logger_output_to_console, logger_output_to_file) -address = ("0.0.0.0", 29901) +address = dwc_config.get_ip_port('GameSpyPlayerSearchServer') class GameSpyPlayerSearchServer(object): diff --git a/gamespy_profile_server.py b/gamespy_profile_server.py index bd0931d..8192fdd 100644 --- a/gamespy_profile_server.py +++ b/gamespy_profile_server.py @@ -34,7 +34,7 @@ import gamespy.gs_database as gs_database import gamespy.gs_query as gs_query import gamespy.gs_utility as gs_utils import other.utils as utils - +import dwc_config # Logger settings logger_output_to_console = True @@ -44,7 +44,7 @@ logger_filename = "gamespy_profile_server.log" logger = utils.create_logger(logger_name, logger_filename, -1, logger_output_to_console, logger_output_to_file) -address = ("0.0.0.0", 29900) +address = dwc_config.get_ip_port('GameSpyProfileServer') class GameSpyProfileServer(object): diff --git a/gamespy_qr_server.py b/gamespy_qr_server.py index aeb748b..f1f8102 100644 --- a/gamespy_qr_server.py +++ b/gamespy_qr_server.py @@ -38,6 +38,7 @@ from multiprocessing.managers import BaseManager import gamespy.gs_utility as gs_utils import gamespy.gs_database as gs_database import other.utils as utils +import dwc_config from gamespy_server_browser_server import GameSpyServerBrowserServer # Logger settings @@ -98,7 +99,7 @@ class GameSpyQRServer(object): def start(self): try: - manager_address = ("127.0.0.1", 27500) + manager_address = dwc_config.get_ip_port('GameSpyManager') manager_password = "" self.server_manager = GameSpyServerDatabase( @@ -110,7 +111,7 @@ class GameSpyQRServer(object): # Start QR server # Accessible to outside connections (use this if you don't know # what you're doing) - address = ('0.0.0.0', 27900) + address = dwc_config.get_ip_port('GameSpyQRServer') self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.socket.bind(address) diff --git a/gamespy_server_browser_server.py b/gamespy_server_browser_server.py index 4c9d11b..ddb1f3e 100644 --- a/gamespy_server_browser_server.py +++ b/gamespy_server_browser_server.py @@ -34,6 +34,7 @@ from twisted.internet.error import ReactorAlreadyRunning import gamespy.gs_utility as gs_utils import other.utils as utils +import dwc_config from multiprocessing.managers import BaseManager @@ -68,7 +69,7 @@ GameSpyServerDatabase.register("add_natneg_server") GameSpyServerDatabase.register("get_natneg_server") GameSpyServerDatabase.register("delete_natneg_server") -address = ("0.0.0.0", 28910) +address = dwc_config.get_ip_port('GameSpyServerBrowserServer') class GameSpyServerBrowserServer(object): @@ -117,7 +118,7 @@ class Session(LineReceiver): self.own_server = None self.buffer = [] - manager_address = ("127.0.0.1", 27500) + manager_address = dwc_config.get_ip_port('GameSpyManager') manager_password = "" self.server_manager = GameSpyServerDatabase(address=manager_address, authkey=manager_password) diff --git a/gamestats_server_http.py b/gamestats_server_http.py index 13a606a..057424a 100644 --- a/gamestats_server_http.py +++ b/gamestats_server_http.py @@ -32,6 +32,7 @@ import base64 import gamespy.gs_database as gs_database import gamespy.gs_utility as gs_utils import other.utils as utils +import dwc_config logger_output_to_console = True logger_output_to_file = True @@ -40,8 +41,7 @@ logger_filename = "gamestats_server_http.log" logger = utils.create_logger(logger_name, logger_filename, -1, logger_output_to_console, logger_output_to_file) -# address = ("0.0.0.0", 80) -address = ("127.0.0.1", 9002) +address = dwc_config.get_ip_port('GameStatsServerHttp') class GameStatsBase(object): diff --git a/internal_stats_server.py b/internal_stats_server.py index 4a0bba7..de51fd9 100644 --- a/internal_stats_server.py +++ b/internal_stats_server.py @@ -26,7 +26,9 @@ import time import datetime import json import logging + import other.utils as utils +import dwc_config logger_output_to_console = True logger_output_to_file = True @@ -118,14 +120,14 @@ class InternalStatsServer(object): self.seconds_per_update = 60 def start(self): - manager_address = ("127.0.0.1", 27500) + manager_address = dwc_config.get_ip_port('GameSpyManager') manager_password = "" self.server_manager = GameSpyServerDatabase(address=manager_address, authkey=manager_password) self.server_manager.connect() site = server.Site(StatsPage(self)) - reactor.listenTCP(9001, site) + reactor.listenTCP(dwc_config.get_port('InternalStatsServer'), site) try: if not reactor.running: diff --git a/nas_server.py b/nas_server.py index ec3d805..c03cbf2 100644 --- a/nas_server.py +++ b/nas_server.py @@ -33,6 +33,7 @@ import traceback import gamespy.gs_database as gs_database import other.utils as utils +import dwc_config logger_output_to_console = True logger_output_to_file = True @@ -68,7 +69,7 @@ gamecodes_return_random_file = [ 'IPGS' ] -address = ("127.0.0.1", 9000) +address = dwc_config.get_ip_port('NasServer') class NasServer(object): @@ -363,7 +364,8 @@ class NasHTTPServerHandler(BaseHTTPServer.BaseHTTPRequestHandler): ret, post["token"] ) - elif post["gamecd"] in gamecodes_return_random_file: + elif post["gamecd"] in \ + gamecodes_return_random_file: # Pokemon Gen 4 Mystery Gifts, same here ret = self.filter_list( safeloadfi("_list.txt"), diff --git a/storage_server.py b/storage_server.py index 1651c06..c525be9 100644 --- a/storage_server.py +++ b/storage_server.py @@ -29,6 +29,7 @@ import xml.dom.minidom as minidom import other.utils as utils import gamespy.gs_database as gs_database +import dwc_config logger_output_to_console = True logger_output_to_file = True @@ -37,7 +38,7 @@ logger_filename = "storage_server.log" logger = utils.create_logger(logger_name, logger_filename, -1, logger_output_to_console, logger_output_to_file) # Paths to ProxyPass: /SakeStorageServer, /SakeFileServer -address = ("127.0.0.1", 8000) +address = dwc_config.get_ip_port('StorageServer') def escape_xml(s): s = s.replace( "&", "&" )