def start(self):
        try:
            manager_address = dwc_config.get_ip_port('GameSpyManager')
            manager_password = ""

            self.server_manager = GameSpyServerDatabase(
                address=manager_address,
                authkey=manager_password
            )
            self.server_manager.connect()

            # Start QR server
            # Accessible to outside connections (use this if you don't know
            # what you're doing)
            address = dwc_config.get_ip_port('GameSpyQRServer')

            self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            self.socket.bind(address)
            self.socket.setblocking(0)

            logger.log(logging.INFO,
                       "Server is now listening on %s:%s...",
                       address[0], address[1])

            # Dependencies! I don't really like this solution but it's easier
            # than trying to manage it another way.
            server_browser_server = GameSpyServerBrowserServer(self)
            server_browser_server_thread = threading.Thread(
                target=server_browser_server.start
            )
            server_browser_server_thread.start()

            self.write_queue = Queue.Queue()
            self.db = gs_database.GamespyDatabase()
            threading.Thread(target=self.write_queue_worker).start()

            while True:
                ready = select.select([self.socket], [], [], 15)

                if ready[0]:
                    try:
                        recv_data, address = self.socket.recvfrom(2048)
                        self.handle_packet(self.socket, recv_data, address)
                    except:
                        logger.log(logging.ERROR,
                                   "Failed to handle client: %s",
                                   traceback.format_exc())

                self.keepalive_check()
        except:
            logger.log(logging.ERROR,
                       "Unknown exception: %s",
                       traceback.format_exc())
    def start(self):
        try:
            manager_address = dwc_config.get_ip_port('GameSpyManager')
            manager_password = ""

            self.server_manager = GameSpyServerDatabase(
                address=manager_address, authkey=manager_password)
            self.server_manager.connect()

            # Start QR server
            # Accessible to outside connections (use this if you don't know
            # what you're doing)
            address = dwc_config.get_ip_port('GameSpyQRServer')

            self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            self.socket.bind(address)
            self.socket.setblocking(0)

            logger.log(logging.INFO, "Server is now listening on %s:%s...",
                       address[0], address[1])

            # Dependencies! I don't really like this solution but it's easier
            # than trying to manage it another way.
            server_browser_server = GameSpyServerBrowserServer(self)
            server_browser_server_thread = threading.Thread(
                target=server_browser_server.start)
            server_browser_server_thread.start()

            self.write_queue = Queue.Queue()
            self.db = gs_database.GamespyDatabase()
            threading.Thread(target=self.write_queue_worker).start()

            while True:
                ready = select.select([self.socket], [], [], 15)

                if ready[0]:
                    try:
                        recv_data, address = self.socket.recvfrom(2048)
                        self.handle_packet(self.socket, recv_data, address)
                    except:
                        logger.log(logging.ERROR,
                                   "Failed to handle client: %s",
                                   traceback.format_exc())

                self.keepalive_check()
        except:
            logger.log(logging.ERROR, "Unknown exception: %s",
                       traceback.format_exc())
Esempio n. 3
0
    def __init__(self,
                 server_address=dwc_config.get_ip_port('GameSpyNatNegServer'),
                 RequestHandlerClass=GameSpyNatNegUDPServerHandler,
                 bind_and_activate=True):
        SocketServer.UDPServer.__init__(self, server_address,
                                        RequestHandlerClass, bind_and_activate)
        self.session_list = {}
        self.natneg_preinit_session = {}
        self.secret_key_list = gs_utils.generate_secret_keys("gslist.cfg")

        self.server_manager = GameSpyServerDatabase(
            address=dwc_config.get_ip_port('GameSpyManager'), authkey="")
        self.server_manager.connect()

        self.write_queue = Queue.Queue()
        threading.Thread(target=self.write_queue_worker).start()
    def start(self):
        try:
            # Start natneg server
            # Accessible to outside connections (use this if you don't know
            #  what you're doing)
            address = dwc_config.get_ip_port('GameSpyNatNegServer')

            self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            self.socket.bind(address)

            self.write_queue = Queue.Queue()

            logger.log(logging.INFO,
                       "Server is now listening on %s:%s...",
                       address[0], address[1])
            threading.Thread(target=self.write_queue_worker).start()

            while True:
                recv_data, addr = self.socket.recvfrom(2048)

                self.handle_packet(recv_data, addr)
        except:
            logger.log(logging.ERROR,
                       "Unknown exception: %s",
                       traceback.format_exc())
Esempio n. 5
0
    def __init__(self):
        self.session_list = {}
        self.natneg_preinit_session = {}
        self.secret_key_list = gs_utils.generate_secret_keys("gslist.cfg")

        self.server_manager = GameSpyServerDatabase(
            address=dwc_config.get_ip_port('GameSpyManager'), authkey="")
        self.server_manager.connect()
    def start(self):
        address = dwc_config.get_ip_port('GameSpyManager')
        password = ""

        logger.log(logging.INFO, "Started server on %s:%d...", address[0],
                   address[1])

        manager = GameSpyServerDatabase(address=address, authkey=password)
        server = manager.get_server()
        server.serve_forever()
    def __init__(self):
        self.session_list = {}
        self.natneg_preinit_session = {}
        self.secret_key_list = gs_utils.generate_secret_keys("gslist.cfg")

        self.server_manager = GameSpyServerDatabase(
            address=dwc_config.get_ip_port('GameSpyManager'),
            authkey=""
        )
        self.server_manager.connect()
    def __init__(self,
                 server_address=dwc_config.get_ip_port('GameSpyNatNegServer'),
                 RequestHandlerClass=GameSpyNatNegUDPServerHandler,
                 bind_and_activate=True):
        SocketServer.UDPServer.__init__(self,
                                        server_address,
                                        RequestHandlerClass,
                                        bind_and_activate)
        self.session_list = {}
        self.natneg_preinit_session = {}
        self.secret_key_list = gs_utils.generate_secret_keys("gslist.cfg")

        self.server_manager = GameSpyServerDatabase(
            address=dwc_config.get_ip_port('GameSpyManager'),
            authkey=""
        )
        self.server_manager.connect()

        self.write_queue = Queue.Queue()
        threading.Thread(target=self.write_queue_worker).start()
    def start(self):
        address = dwc_config.get_ip_port('GameSpyManager')
        password = ""

        logger.log(logging.INFO,
                   "Started server on %s:%d...",
                   address[0], address[1])

        manager = GameSpyServerDatabase(address=address,
                                        authkey=password)
        server = manager.get_server()
        server.serve_forever()
    def start(self):
        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(dwc_config.get_port('InternalStatsServer'), site)

        try:
            if not reactor.running:
                reactor.run(installSignalHandlers=0)
        except ReactorAlreadyRunning:
            pass
Esempio n. 11
0
    def start(self):
        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(dwc_config.get_port('InternalStatsServer'), site)

        try:
            if not reactor.running:
                reactor.run(installSignalHandlers=0)
        except ReactorAlreadyRunning:
            pass
    def __init__(self, address, secret_key_list, server_cache, qr):
        self.setRawMode()  # We're dealing with binary data so set to raw mode
        self.address = address
        # Don't waste time parsing every session, so just accept it from
        # the parent
        self.secret_key_list = secret_key_list
        self.console = 0
        self.server_cache = server_cache
        self.qr = qr
        self.own_server = None
        self.buffer = []

        manager_address = dwc_config.get_ip_port('GameSpyManager')
        manager_password = ""
        self.server_manager = GameSpyServerDatabase(address=manager_address,
                                                    authkey=manager_password)
        self.server_manager.connect()
Esempio n. 13
0
    def __init__(self, address, secret_key_list, server_cache, qr):
        self.setRawMode()  # We're dealing with binary data so set to raw mode
        self.address = address
        # Don't waste time parsing every session, so just accept it from
        # the parent
        self.secret_key_list = secret_key_list
        self.console = 0
        self.server_cache = server_cache
        self.qr = qr
        self.own_server = None
        self.buffer = []

        manager_address = dwc_config.get_ip_port('GameSpyManager')
        manager_password = ""
        self.server_manager = GameSpyServerDatabase(address=manager_address,
                                                    authkey=manager_password)
        self.server_manager.connect()
Esempio n. 14
0
    def start(self):
        try:
            # Start natneg server
            # Accessible to outside connections (use this if you don't know
            #  what you're doing)
            address = dwc_config.get_ip_port('GameSpyNatNegServer')

            self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            self.socket.bind(address)

            self.write_queue = Queue.Queue()

            logger.log(logging.INFO, "Server is now listening on %s:%s...",
                       address[0], address[1])
            threading.Thread(target=self.write_queue_worker).start()

            while True:
                recv_data, addr = self.socket.recvfrom(2048)

                self.handle_packet(recv_data, addr)
        except:
            logger.log(logging.ERROR, "Unknown exception: %s",
                       traceback.format_exc())
import logging
import BaseHTTPServer
import cgi
import urlparse
import sqlite3
import xml.dom.minidom as minidom

import other.utils as utils
import gamespy.gs_database as gs_database
import dwc_config

from io import BytesIO

# Paths to ProxyPass: /SakeStorageServer, /SakeFileServer
logger = dwc_config.get_logger('StorageServer')
address = dwc_config.get_ip_port('StorageServer')


def escape_xml(s):
    s = s.replace("&", "&")
    s = s.replace('"', """)
    s = s.replace("'", "'")
    s = s.replace("<", "&lt;")
    s = s.replace(">", "&gt;")
    return s


class StorageServer(object):
    def start(self):
        httpd = StorageHTTPServer((address[0], address[1]),
                                  StorageHTTPServerHandler)
import logging
import traceback

from twisted.internet.protocol import Factory
from twisted.internet.endpoints import serverFromString
from twisted.protocols.basic import LineReceiver
from twisted.internet import reactor
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 = dwc_config.get_logger('GameSpyPlayerSearchServer')
address = dwc_config.get_ip_port('GameSpyPlayerSearchServer')


class GameSpyPlayerSearchServer(object):
    def __init__(self):
        pass

    def start(self):
        endpoint_search = serverFromString(
            reactor, "tcp:%d:interface=%s" % (address[1], address[0]))
        conn_search = endpoint_search.listen(PlayerSearchFactory())

        try:
            if not reactor.running:
                reactor.run(installSignalHandlers=0)
        except ReactorAlreadyRunning:
import re

from twisted.internet.protocol import Factory
from twisted.internet.endpoints import serverFromString
from twisted.protocols.basic import LineReceiver
from twisted.internet import reactor
from twisted.internet.error import ReactorAlreadyRunning

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 = dwc_config.get_logger('GameSpyGamestatsServer')
address = dwc_config.get_ip_port('GameSpyGamestatsServer')


class GameSpyGamestatsServer(object):
    def __init__(self):
        pass

    def start(self):
        endpoint_search = serverFromString(
            reactor, "tcp:%d:interface=%s" % (address[1], address[0]))
        conn_search = endpoint_search.listen(GamestatsFactory())

        try:
            if not reactor.running:
                reactor.run(installSignalHandlers=0)
        except ReactorAlreadyRunning:
Esempio n. 18
0
import re
import base64
import codecs
import sqlite3
import collections
import json
import time
import datetime
import logging

import other.utils as utils
import gamespy.gs_utility as gs_utils
import dwc_config

logger = dwc_config.get_logger('RegisterPage')
_, port = dwc_config.get_ip_port('RegisterPage')


class RegPage(resource.Resource):
    isLeaf = True

    def __init__(self, regpage):
        self.regpage = regpage

    def get_header(self, title=None):
        if not title:
            title = 'Register a Console'
        s = """
        <html>
        <head>
            <title>%s</title>
Esempio n. 19
0
from twisted.internet import reactor
from twisted.internet.error import ReactorAlreadyRunning
import base64
import codecs
import sqlite3
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 = dwc_config.get_logger('AdminPage')
_, port = dwc_config.get_ip_port('AdminPage')

# Example of adminpageconf.json
#
# {"username":"******","password":"******"}
#
# NOTE: Must use double-quotes or json module will fail
# NOTE2: Do not check the .json file into public git!

adminpageconf = None
admin_username = None
admin_password = None

if os.path.exists('adminpageconf.json'):
    try:
        adminpageconf = json.loads(file('adminpageconf.json').read().strip())
import traceback

from twisted.internet.protocol import Factory
from twisted.internet.endpoints import serverFromString
from twisted.protocols.basic import LineReceiver
from twisted.internet import reactor
from twisted.internet.error import ReactorAlreadyRunning

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 = dwc_config.get_logger('GameSpyProfileServer')
address = dwc_config.get_ip_port('GameSpyProfileServer')


class GameSpyProfileServer(object):
    def __init__(self):
        pass

    def start(self):
        endpoint = serverFromString(
            reactor,
            "tcp:%d:interface=%s" % (address[1], address[0])
        )
        conn = endpoint.listen(PlayerFactory())

        try:
            if not reactor.running:
Esempio n. 21
0
    HAS_FULL_RULES_FLAG = 128


class GameSpyServerDatabase(BaseManager):
    pass


GameSpyServerDatabase.register("get_server_list")
GameSpyServerDatabase.register("modify_server_list")
GameSpyServerDatabase.register("find_servers")
GameSpyServerDatabase.register("find_server_by_address")
GameSpyServerDatabase.register("add_natneg_server")
GameSpyServerDatabase.register("get_natneg_server")
GameSpyServerDatabase.register("delete_natneg_server")

address = dwc_config.get_ip_port('GameSpyServerBrowserServer')


class GameSpyServerBrowserServer(object):
    def __init__(self, qr=None):
        self.qr = qr

    def start(self):
        endpoint = serverFromString(
            reactor, "tcp:%d:interface=%s" % (address[1], address[0]))
        conn = endpoint.listen(SessionFactory(self.qr))

        try:
            if not reactor.running:
                reactor.run(installSignalHandlers=0)
        except ReactorAlreadyRunning:
 def start(self):
     address = dwc_config.get_ip_port('NasServer')
     httpd = NasHTTPServer(address, NasHTTPServerHandler)
     logger.log(logging.INFO, "Now listening for connections on %s:%d...",
                *address)
     httpd.serve_forever()
import logging
import urlparse
import BaseHTTPServer
import traceback
import os
import hashlib
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 = dwc_config.get_logger('GameStatsServerHttp')
address = dwc_config.get_ip_port('GameStatsServerHttp')


class GameStatsBase(object):
    def do_GET(self, conn, key, append_hash, append_text=""):
        try:
            conn.send_response(200)
            conn.send_header("Content-type", "text/html")
            conn.send_header("Server", "Microsoft-IIS/6.0")
            conn.send_header("Server", "GSTPRDSTATSWEB2")
            conn.send_header("X-Powered-By", "ASP.NET")
            conn.end_headers()

            params = conn.str_to_dict(conn.path)
            ret = ""
            if "hash" not in params:
import os
import random
import logging
import BaseHTTPServer
import cgi
import urlparse
import sqlite3
import xml.dom.minidom as minidom

import other.utils as utils
import gamespy.gs_database as gs_database
import dwc_config

# Paths to ProxyPass: /SakeStorageServer, /SakeFileServer
logger = dwc_config.get_logger('StorageServer')
address = dwc_config.get_ip_port('StorageServer')


def escape_xml(s):
    s = s.replace( "&", "&amp;" )
    s = s.replace( '"', "&quot;" )
    s = s.replace( "'", "&apos;" )
    s = s.replace( "<", "&lt;" )
    s = s.replace( ">", "&gt;" )
    return s


class StorageServer(object):
    def start(self):
        httpd = StorageHTTPServer((address[0], address[1]), StorageHTTPServerHandler)
        logger.log(logging.INFO, "Now listening for connections on %s:%d...", address[0], address[1])
Esempio n. 25
0
import traceback

from twisted.internet.protocol import Factory
from twisted.internet.endpoints import serverFromString
from twisted.protocols.basic import LineReceiver
from twisted.internet import reactor
from twisted.internet.error import ReactorAlreadyRunning

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 = dwc_config.get_logger('GameSpyProfileServer')
address = dwc_config.get_ip_port('GameSpyProfileServer')


class GameSpyProfileServer(object):
    def __init__(self):
        pass

    def start(self):
        endpoint = serverFromString(
            reactor, "tcp:%d:interface=%s" % (address[1], address[0]))
        conn = endpoint.listen(PlayerFactory())

        try:
            if not reactor.running:
                reactor.run(installSignalHandlers=0)
        except ReactorAlreadyRunning:
from twisted.internet import reactor
from twisted.internet.error import ReactorAlreadyRunning
import base64
import codecs
import sqlite3
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 = dwc_config.get_logger('AdminPage')
_, port = dwc_config.get_ip_port('AdminPage')


# Example of adminpageconf.json
#
# {"username":"******","password":"******"}
#
# NOTE: Must use double-quotes or json module will fail
# NOTE2: Do not check the .json file into public git!

adminpageconf = None
admin_username = None
admin_password = None

if os.path.exists('adminpageconf.json'):
    try:
import gamespy.gs_database as gs_database
import other.utils as utils
import dwc_config

logger = dwc_config.get_logger('NasServer')

# If a game from this list requests a file listing, the server will return
# that only one exists and return a random one.
# This is used for Mystery Gift distribution on Generation 4 Pokemon games
gamecodes_return_random_file = [
    'ADAD', 'ADAE', 'ADAF', 'ADAI', 'ADAJ', 'ADAK', 'ADAS', 'CPUD', 'CPUE',
    'CPUF', 'CPUI', 'CPUJ', 'CPUK', 'CPUS', 'IPGD', 'IPGE', 'IPGF', 'IPGI',
    'IPGJ', 'IPGK', 'IPGS'
]

address = dwc_config.get_ip_port('NasServer')


class NasServer(object):
    def start(self):
        httpd = NasHTTPServer((address[0], address[1]), NasHTTPServerHandler)
        t = threading.Thread(target=httpd.serve_forever)
        t.daemon = True
        t.start()
        logger.log(logging.INFO, "Now listening for connections on %s:%d...",
                   address[0], address[1])
        httpd.serve_forever()


class NasHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer):
    def __init__(self, server_address, RequestHandlerClass):
    HAS_KEYS_FLAG = 64
    HAS_FULL_RULES_FLAG = 128


class GameSpyServerDatabase(BaseManager):
    pass

GameSpyServerDatabase.register("get_server_list")
GameSpyServerDatabase.register("modify_server_list")
GameSpyServerDatabase.register("find_servers")
GameSpyServerDatabase.register("find_server_by_address")
GameSpyServerDatabase.register("add_natneg_server")
GameSpyServerDatabase.register("get_natneg_server")
GameSpyServerDatabase.register("delete_natneg_server")

address = dwc_config.get_ip_port('GameSpyServerBrowserServer')


class GameSpyServerBrowserServer(object):
    def __init__(self, qr=None):
        self.qr = qr

    def start(self):
        endpoint = serverFromString(
            reactor, "tcp:%d:interface=%s" % (address[1], address[0])
        )
        conn = endpoint.listen(SessionFactory(self.qr))

        try:
            if not reactor.running:
                reactor.run(installSignalHandlers=0)
import traceback

from twisted.internet.protocol import Factory
from twisted.internet.endpoints import serverFromString
from twisted.protocols.basic import LineReceiver
from twisted.internet import reactor
from twisted.internet.error import ReactorAlreadyRunning

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 = dwc_config.get_logger('GameSpyGamestatsServer')
address = dwc_config.get_ip_port('GameSpyGamestatsServer')


class GameSpyGamestatsServer(object):
    def __init__(self):
        pass

    def start(self):
        endpoint_search = serverFromString(
            reactor,
            "tcp:%d:interface=%s" % (address[1], address[0])
        )
        conn_search = endpoint_search.listen(GamestatsFactory())

        try:
            if not reactor.running:
import logging
import urlparse
import BaseHTTPServer
import traceback
import os
import hashlib
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 = dwc_config.get_logger('GameStatsServerHttp')
address = dwc_config.get_ip_port('GameStatsServerHttp')


class GameStatsBase(object):
    def do_GET(self, conn, key, append_hash, append_text=""):
        try:
            conn.send_response(200)
            conn.send_header("Content-type", "text/html")
            conn.send_header("Server", "Microsoft-IIS/6.0")
            conn.send_header("Server", "GSTPRDSTATSWEB2")
            conn.send_header("X-Powered-By", "ASP.NET")
            conn.end_headers()

            params = conn.str_to_dict(conn.path)
            ret = ""
            if "hash" not in params:
    'CPUE',
    'CPUF',
    'CPUI',
    'CPUJ',
    'CPUK',
    'CPUS',
    'IPGD',
    'IPGE',
    'IPGF',
    'IPGI',
    'IPGJ',
    'IPGK',
    'IPGS'
]

address = dwc_config.get_ip_port('NasServer')


class NasServer(object):
    def start(self):
        httpd = NasHTTPServer(address, NasHTTPServerHandler)
        logger.log(logging.INFO, "Now listening for connections on %s:%d...",
                   *address)
        httpd.serve_forever()


class NasHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer):
    def __init__(self, server_address, RequestHandlerClass):
        # self.db = gs_database.GamespyDatabase()
        BaseHTTPServer.HTTPServer.__init__(self, server_address,
                                           RequestHandlerClass)
import re
import base64
import codecs
import sqlite3
import collections
import json
import time
import datetime
import logging

import other.utils as utils
import gamespy.gs_utility as gs_utils
import dwc_config

logger = dwc_config.get_logger('RegisterPage')
_, port = dwc_config.get_ip_port('RegisterPage')


class RegPage(resource.Resource):
    isLeaf = True

    def __init__(self, regpage):
        self.regpage = regpage

    def get_header(self, title=None):
        if not title:
            title = 'Register a Console'
        s = """
        <html>
        <head>
            <title>%s</title>
import logging
import traceback

from twisted.internet.protocol import Factory
from twisted.internet.endpoints import serverFromString
from twisted.protocols.basic import LineReceiver
from twisted.internet import reactor
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 = dwc_config.get_logger('GameSpyPlayerSearchServer')
address = dwc_config.get_ip_port('GameSpyPlayerSearchServer')


class GameSpyPlayerSearchServer(object):
    def __init__(self):
        pass

    def start(self):
        endpoint_search = serverFromString(
            reactor,
            "tcp:%d:interface=%s" % (address[1], address[0])
        )
        conn_search = endpoint_search.listen(PlayerSearchFactory())

        try:
            if not reactor.running: