Ejemplo n.º 1
0
 def __init__(self, user, password):
     self.client = AsyncClient()
     self.user = user
     self.password = password
Ejemplo n.º 2
0
 def __init__(self, user, password):
     self.client = AsyncClient()
     self.user = user
     self.password = password
Ejemplo n.º 3
0
class GameServer(object):
    """
    Contacts redirect server.
    Accepts clients
    """

    class CustomGameFilter(GameFilter):
        """
        Inner class that is used to make hooks from methods in GameFilter to methods in GameServer
        Note: __init__ must have "self.controller = controller" as it's first line.
        """
        @staticmethod
        def runFunctionBeforeMethod(f):
            def decoratorMethod(m):
                @wraps(m)
                def wrapper(self, *args, **kwargs):
                    f(self.controller)
                    return m(self, *args, **kwargs)
                return wrapper
            return decoratorMethod

        @staticmethod
        def runFunctionAfterMethod(f):
            def decoratorMethod(m):
                @wraps(m)
                def wrapper(self, *args, **kwargs):
                    ret = m(self, *args, **kwargs)
                    f(self.controller)
                    return ret
                return wrapper
            return decoratorMethod

        def __init__(self, controller):
            self.controller = controller
            GameFilter.__init__(self)


    def __init__(self, user, password):
        self.client = AsyncClient()
        self.user = user
        self.password = password

    def GameFilter(self):
            return GameServer.CustomGameFilter(self)

    def sendToRedirect(self, l):
        self.client.send(sexpr.sexpr2str(l))

    def login(self):
        self.sendToRedirect(['login', self.user, self.password])
        if not('login-accepted' in self.client.getText()):
            raise ServerException("Could not login as %s" % self.user)

    def registerAsServer(self):
        self.sendToRedirect(['register-server'])
        if not('successful' in self.client.getText()):
            raise ServerException("Couldn't regiser as a server")

    def runServer(self, telnet_disabled):
        filters = ([PacketizerFilter, CompressionFilter] if telnet_disabled else []) + [self.GameFilter]
        self.server = TCPServer(19001,  *filters)
        server_thread = threading.Thread(None, self.server.run)
        server_thread.run()

    def run(self, telnet_disabled, address="localhost", port=19000):
        self.client.connect(address, port)
        self.login()
        self.registerAsServer()
        self.runServer(telnet_disabled)
Ejemplo n.º 4
0
class GameServer(object):
    """
    Contacts redirect server.
    Accepts clients
    """
    class CustomGameFilter(GameFilter):
        """
        Inner class that is used to make hooks from methods in GameFilter to methods in GameServer
        Note: __init__ must have "self.controller = controller" as it's first line.
        """
        @staticmethod
        def runFunctionBeforeMethod(f):
            def decoratorMethod(m):
                @wraps(m)
                def wrapper(self, *args, **kwargs):
                    f(self.controller)
                    return m(self, *args, **kwargs)

                return wrapper

            return decoratorMethod

        @staticmethod
        def runFunctionAfterMethod(f):
            def decoratorMethod(m):
                @wraps(m)
                def wrapper(self, *args, **kwargs):
                    ret = m(self, *args, **kwargs)
                    f(self.controller)
                    return ret

                return wrapper

            return decoratorMethod

        def __init__(self, controller):
            self.controller = controller
            GameFilter.__init__(self)

    def __init__(self, user, password):
        self.client = AsyncClient()
        self.user = user
        self.password = password

    def GameFilter(self):
        return GameServer.CustomGameFilter(self)

    def sendToRedirect(self, l):
        self.client.send(sexpr.sexpr2str(l))

    def login(self):
        self.sendToRedirect(['login', self.user, self.password])
        if not ('login-accepted' in self.client.getText()):
            raise ServerException("Could not login as %s" % self.user)

    def registerAsServer(self):
        self.sendToRedirect(['register-server'])
        if not ('successful' in self.client.getText()):
            raise ServerException("Couldn't regiser as a server")

    def runServer(self, telnet_disabled):
        filters = ([PacketizerFilter, CompressionFilter]
                   if telnet_disabled else []) + [self.GameFilter]
        self.server = TCPServer(19001, *filters)
        server_thread = threading.Thread(None, self.server.run)
        server_thread.run()

    def run(self, telnet_disabled, address="localhost", port=19000):
        self.client.connect(address, port)
        self.login()
        self.registerAsServer()
        self.runServer(telnet_disabled)