Ejemplo n.º 1
0
    def newTable(self,
                 user,
                 ruleset,
                 playOpen,
                 autoPlay,
                 wantedGame,
                 tableId=None):
        """user creates new table and joins it"""
        def gotRuleset(ruleset):
            """now we have the full ruleset definition from the client"""
            Ruleset.cached(
                ruleset).save()  # make it known to the cache and save in db

        if tableId in self.tables:
            return fail(
                srvError(
                    pb.Error,
                    'You want a new table with id=%d but that id is already used for table %s'
                    % (tableId, self.tables[tableId])))
        if Ruleset.hashIsKnown(ruleset):
            return self.__newTable(None, user, ruleset, playOpen, autoPlay,
                                   wantedGame, tableId)
        else:
            return self.callRemote(
                user, 'needRuleset',
                ruleset).addCallback(gotRuleset).addCallback(
                    self.__newTable, user, ruleset, playOpen, autoPlay,
                    wantedGame, tableId)
Ejemplo n.º 2
0
 def remote_serverRulesets(hashes):
     """the server will normally send us hashes of rulesets. If
     a hash is not known by us, tell the server so it will send the
     full ruleset definition instead of the hash. It would be even better if
     the server always only sends the hash and the client then says "I do
     not know this ruleset, please send definition", but that would mean
     more changes to the client code"""
     return list(x for x in hashes if not Ruleset.hashIsKnown(x))
Ejemplo n.º 3
0
 def remote_serverRulesets(hashes):
     """the server will normally send us hashes of rulesets. If
     a hash is not known by us, tell the server so it will send the
     full ruleset definition instead of the hash. It would be even better if
     the server always only sends the hash and the client then says "I do
     not know this ruleset, please send definition", but that would mean
     more changes to the client code"""
     return list(x for x in hashes if not Ruleset.hashIsKnown(x))
Ejemplo n.º 4
0
 def remote_newTables(self, tables):
     """update table list"""
     assert len(tables)
     def gotRulesets(result):
         """the server sent us the wanted ruleset definitions"""
         for ruleset in result:
             Ruleset.cached(ruleset).save(copy=True) # make it known to the cache and save in db
         return tables
     rulesetHashes = set(x[1] for x in tables)
     needRulesets = list(x for x in rulesetHashes if not Ruleset.hashIsKnown(x))
     if needRulesets:
         self.callServer('needRulesets', needRulesets).addCallback(gotRulesets).addCallback(self.__receiveTables)
     else:
         self.__receiveTables(tables)
Ejemplo n.º 5
0
    def remote_newTables(self, tables):
        """update table list"""
        assert len(tables)

        def gotRulesets(result):
            """the server sent us the wanted ruleset definitions"""
            for ruleset in result:
                Ruleset.cached(ruleset).save()  # make it known to the cache and save in db
            return tables
        rulesetHashes = set(x[1] for x in tables)
        needRulesets = list(
            x for x in rulesetHashes if not Ruleset.hashIsKnown(x))
        if needRulesets:
            self.callServer(
                'needRulesets',
                needRulesets).addCallback(
                    gotRulesets).addCallback(
                        self.__receiveTables)
        else:
            self.__receiveTables(tables)