Пример #1
0
    def __init__(self, *args, **kwargs):
        PokerClientFactory.__init__(self, *args, **kwargs)

        if self.settings.headerGet("/settings/@batch") != "yes":
            self.skin = PokerSkin2D(settings=self.settings)
            self.renderer = PokerRenderer(self)
            self.initDisplay()

            self.interface = PokerInterface2D(self.settings)
            self.skin.interfaceReady(self.interface, self.display)
            self.renderer.interfaceReady(self.interface)

        self.checkNetwork("pokersource.info")
Пример #2
0
    def __init__(self, *args, **kwargs):
        PokerClientFactory.__init__(self, *args, **kwargs)

        if self.settings.headerGet("/settings/@batch") != "yes":
            self.skin = PokerSkin2D(settings = self.settings)
            self.renderer = PokerRenderer(self)
            self.initDisplay()

            self.interface = PokerInterface2D(self.settings)
            self.skin.interfaceReady(self.interface, self.display)
            self.renderer.interfaceReady(self.interface)

        self.checkNetwork("pokersource.info")
Пример #3
0
class PokerClientFactory2D(PokerClientFactory):
    def __init__(self, *args, **kwargs):
        PokerClientFactory.__init__(self, *args, **kwargs)

        if self.settings.headerGet("/settings/@batch") != "yes":
            self.skin = PokerSkin2D(settings=self.settings)
            self.renderer = PokerRenderer(self)
            self.initDisplay()

            self.interface = PokerInterface2D(self.settings)
            self.skin.interfaceReady(self.interface, self.display)
            self.renderer.interfaceReady(self.interface)

        self.checkNetwork("pokersource.info")

    def networkNotAvailable(self):
        message = "No network available or maybe your firewall block your connexion\n"
        if self.settings.headerGet("/settings/@batch") == "yes":
            print message
        else:
            interface = self.interface
            interface.messageBox(message)
            interface.registerHandler(pokerinterface.INTERFACE_MESSAGE_BOX,
                                      lambda: self.quit())

    def networkAvailable(self):
        if self.settings.headerGet("/settings/@upgrades") == "yes":
            self.checkClientVersion(
                (version.major(), version.medium(), version.minor()))
        else:
            self.clientVersionOk()

    def clientVersionOk(self):
        if self.settings.headerGet("/settings/@batch") == "yes":
            self.quit()
        else:
            self.showServers()

    def failedUpgradeNoNetwork(self, logs, reason):
        message = "No network available or maybe your firewall block your connexion\n" + logs
        if self.settings.headerGet("/settings/@batch") == "yes":
            print message
        else:
            interface = self.interface
            interface.messageBox(message)
            interface.registerHandler(pokerinterface.INTERFACE_MESSAGE_BOX,
                                      lambda: self.quit())

    def failedUpgradeHostNotFound(self, logs, reason):
        message = "Host not found\n" + logs
        if self.settings.headerGet("/settings/@batch") == "yes":
            print message
        else:
            interface = self.interface
            interface.messageBox(message)
            interface.registerHandler(pokerinterface.INTERFACE_MESSAGE_BOX,
                                      lambda: self.quit())

    def failedUpgrade(self, logs, reason):
        message = "Unable to upgrade software\n" + logs
        if self.settings.headerGet("/settings/@batch") == "yes":
            print message
        else:
            interface = self.interface
            interface.messageBox(message)
            interface.registerHandler(pokerinterface.INTERFACE_MESSAGE_BOX,
                                      lambda: self.quit())

    def needUpgrade(self, version):
        if self.settings.headerGet("/settings/@batch") == "yes":
            self.upgradeConfirmed(confirmed=True, version=version)
            print "Upgrading to client version " + str(version)
        else:
            interface = self.interface
            interface.yesnoBox("Client version " + str(version) +
                               " is available, do you want to upgrade now ?")
            interface.registerHandler(
                pokerinterface.INTERFACE_YESNO,
                lambda result: self.upgradeConfirmed(result, version))

    def upgradeConfirmed(self, confirmed, version):
        if confirmed:
            self.upgrade(version, ("poker2d.xml", ))
        else:
            self.quit()

    def initDisplay(self):
        if self.settings.headerGet("/settings/@batch") == "yes":
            self.display = PokerDisplay(settings=self.settings,
                                        config=self.config,
                                        factory=self)
        else:
            self.display = PokerDisplay2D(settings=self.settings,
                                          config=self.config,
                                          factory=self)
        self.display.init()

    def showServers(self):
        servers = split(self.settings.headerGet("/settings/servers"))
        if len(servers) > 1:
            interface = self.interface
            interface.chooser("Choose a poker server", servers)
            interface.registerHandler(pokerinterface.INTERFACE_CHOOSER,
                                      self.selectServer)
        else:
            self.selectServer(servers[0])

    def selectServer(self, server):
        (self.host, self.port) = split(server, ":")
        if ";" in self.port:
            (self.port, want_ssl) = split(self.port, ";")
        else:
            want_ssl = None
        self.port = int(self.port)

        ssl_context = want_ssl and ssl.ClientContextFactory()

        settings = self.settings
        proxy = settings.headerGet("/settings/servers/@proxy")
        if proxy:
            if self.verbose > 1:
                print "connection thru proxy " + proxy
            (host, port) = proxy.split(':')
            port = int(port)
        else:
            (host, port) = (self.host, self.port)

        timeout = settings.headerGetInt("/settings/@tcptimeout")

        c = Connector(host, port, self, ssl_context, timeout, None, reactor)
        if proxy:
            c.setProxyHost("%s:%d" % (self.host, self.port))
        c.connect()

    def buildProtocol(self, addr):
        protocol = PokerClientFactory.buildProtocol(self, addr)
        self.renderer.setProtocol(protocol)
        self.display.setProtocol(protocol)
        return protocol

    def clientConnectionFailed(self, connector, reason):
        print "connectionFailed: %s" % reason
        self.interface.messageBox(
            "Unable to reach the poker\nserver at %s:%d" %
            (self.host, self.port))
        self.interface.registerHandler(pokerinterface.INTERFACE_MESSAGE_BOX,
                                       self.showServers)

    def clientConnectionLost(self, connector, reason):
        self.renderer.setProtocol(None)
        reconnect = True
        if hasattr(self, "reconnect"):
            reconnect = self.reconnect
            del self.reconnect

        if reconnect:
            message = "The poker server connection was closed"
            if not reason.check(error.ConnectionDone):
                message += " " + str(reason)
            print message
            if self.interface:
                self.interface.messageBox(
                    "Lost connection to poker\nserver at %s:%d" %
                    (self.host, self.port))
                self.interface.registerHandler(
                    pokerinterface.INTERFACE_MESSAGE_BOX, self.quit)
Пример #4
0
class PokerClientFactory2D(PokerClientFactory):
    def __init__(self, *args, **kwargs):
        PokerClientFactory.__init__(self, *args, **kwargs)

        if self.settings.headerGet("/settings/@batch") != "yes":
            self.skin = PokerSkin2D(settings = self.settings)
            self.renderer = PokerRenderer(self)
            self.initDisplay()

            self.interface = PokerInterface2D(self.settings)
            self.skin.interfaceReady(self.interface, self.display)
            self.renderer.interfaceReady(self.interface)

        self.checkNetwork("pokersource.info")

    def networkNotAvailable(self):
        message = "No network available or maybe your firewall block your connexion\n"
        if self.settings.headerGet("/settings/@batch") == "yes":
            print message
        else:
            interface = self.interface
            interface.messageBox(message)
            interface.registerHandler(pokerinterface.INTERFACE_MESSAGE_BOX, lambda: self.quit())

    def networkAvailable(self):
        if self.settings.headerGet("/settings/@upgrades") == "yes":
            self.checkClientVersion((version.major(), version.medium(), version.minor()))
        else:
            self.clientVersionOk()

    def clientVersionOk(self):
        if self.settings.headerGet("/settings/@batch") == "yes":
            self.quit()
        else:
            self.showServers()

    def failedUpgradeNoNetwork(self, logs, reason):
        message = "No network available or maybe your firewall block your connexion\n" + logs
        if self.settings.headerGet("/settings/@batch") == "yes":
            print message
        else:
            interface = self.interface
            interface.messageBox(message)
            interface.registerHandler(pokerinterface.INTERFACE_MESSAGE_BOX, lambda: self.quit())

    def failedUpgradeHostNotFound(self, logs, reason):
        message = "Host not found\n" + logs
        if self.settings.headerGet("/settings/@batch") == "yes":
            print message
        else:
            interface = self.interface
            interface.messageBox(message)
            interface.registerHandler(pokerinterface.INTERFACE_MESSAGE_BOX, lambda: self.quit())

    def failedUpgrade(self, logs, reason):
        message = "Unable to upgrade software\n" + logs
        if self.settings.headerGet("/settings/@batch") == "yes":
            print message
        else:
            interface = self.interface
            interface.messageBox(message)
            interface.registerHandler(pokerinterface.INTERFACE_MESSAGE_BOX, lambda: self.quit())
        
    def needUpgrade(self, version):
        if self.settings.headerGet("/settings/@batch") == "yes":
            self.upgradeConfirmed(confirmed = True, version = version)
            print "Upgrading to client version " + str(version)
        else:
            interface = self.interface
            interface.yesnoBox("Client version " + str(version) + " is available, do you want to upgrade now ?")
            interface.registerHandler(pokerinterface.INTERFACE_YESNO, lambda result: self.upgradeConfirmed(result, version))

    def upgradeConfirmed(self, confirmed, version):
        if confirmed:
            self.upgrade(version, ("poker2d.xml", ))
        else:
            self.quit()

    def initDisplay(self):
        if self.settings.headerGet("/settings/@batch") == "yes":
            self.display = PokerDisplay(settings = self.settings,
                                        config = self.config,
                                        factory = self)
        else:
            self.display = PokerDisplay2D(settings = self.settings,
                                          config = self.config,
                                          factory = self)
        self.display.init()
            
    def showServers(self):
        servers = split(self.settings.headerGet("/settings/servers"))
        if len(servers) > 1:
            interface = self.interface
            interface.chooser("Choose a poker server", servers)
            interface.registerHandler(pokerinterface.INTERFACE_CHOOSER, self.selectServer)
        else:
            self.selectServer(servers[0])
            
    def selectServer(self, server):
        (self.host, self.port) = split(server, ":")
        if ";" in self.port:
            (self.port, want_ssl) = split(self.port, ";")
        else:
            want_ssl = None
        self.port = int(self.port)

        ssl_context = want_ssl and ssl.ClientContextFactory()
        
        settings = self.settings
        proxy = settings.headerGet("/settings/servers/@proxy")
        if proxy:
            if self.verbose > 1:
                print "connection thru proxy " + proxy
            ( host, port ) = proxy.split(':')
            port = int(port)
        else:
            ( host, port ) = ( self.host, self.port )

        timeout = settings.headerGetInt("/settings/@tcptimeout")

        c = Connector(host, port, self, ssl_context, timeout, None, reactor)
        if proxy:
            c.setProxyHost("%s:%d" % (self.host, self.port))
        c.connect()

    def buildProtocol(self, addr):
        protocol = PokerClientFactory.buildProtocol(self, addr)
        self.renderer.setProtocol(protocol)
        self.display.setProtocol(protocol)
        return protocol

    def clientConnectionFailed(self, connector, reason):
        print "connectionFailed: %s" % reason
        self.interface.messageBox("Unable to reach the poker\nserver at %s:%d" % ( self.host, self.port ))
        self.interface.registerHandler(pokerinterface.INTERFACE_MESSAGE_BOX, self.showServers)
        
    def clientConnectionLost(self, connector, reason):
        self.renderer.setProtocol(None)
        reconnect = True
        if hasattr(self, "reconnect"):
            reconnect = self.reconnect
            del self.reconnect

        if reconnect:
            message = "The poker server connection was closed"
            if not reason.check(error.ConnectionDone):
                message += " " + str(reason)
            print message
            if self.interface:
                self.interface.messageBox("Lost connection to poker\nserver at %s:%d" % ( self.host, self.port ))
                self.interface.registerHandler(pokerinterface.INTERFACE_MESSAGE_BOX, self.quit)
Пример #5
0
 def _handleConnection(self, protocol, packet):
     self.packet_processed.append(packet)
     PokerRenderer._handleConnection(self, protocol, packet)
Пример #6
0
 def changeState(self, state, *args, **kwargs):
     self.change_state.append((self.state, state))
     PokerRenderer.changeState(self, state, *args, **kwargs)
Пример #7
0
 def __init__(self, *args, **kwargs):
     PokerRenderer.__init__(self, *args, **kwargs)