Exemplo n.º 1
0
    def get_keyed_data(self, persist_data, key):
        ret = {}
        profile = None
        game = None
        try:
            profile = Profile.select().where(
                (Profile.id == persist_data["profileid"])).get()
            game = Game.select().where(
                (Game.id == persist_data["game_id"])).get()
        except (PersistKeyedData.DoesNotExist, Profile.DoesNotExist) as e:
            pass
        try:
            where = (PersistKeyedData.key_name == key) & (
                PersistKeyedData.data_index == persist_data["data_index"]) & (
                    PersistKeyedData.persist_type == persist_data["data_type"]
                ) & (PersistKeyedData.profileid
                     == profile.id) & (PersistKeyedData.gameid == game.id)
            if "modified_since" in persist_data:
                where = (where) & (PersistKeyedData.modified >
                                   persist_data["modified_since"])
            data_entry = PersistKeyedData.select().where(where).get()
            ret = model_to_dict(data_entry)
            ret["modified"] = calendar.timegm(ret["modified"].utctimetuple())
            del ret["profile"]
        except (PersistKeyedData.DoesNotExist) as e:
            pass

        return ret
Exemplo n.º 2
0
    def set_persist_raw_data(self, persist_data):
        profile = None
        game = None
        try:
            profile = Profile.select().where(
                (Profile.id == persist_data["profileid"])).get()
            game = Game.select().where(
                (Game.id == persist_data["game_id"])).get()
        except (PersistKeyedData.DoesNotExist, Profile.DoesNotExist) as e:
            pass
        try:

            data_entry = PersistData.select().where(
                (PersistData.data_index == persist_data["data_index"])
                & (PersistData.persist_type == persist_data["data_type"])
                & (PersistData.profileid == profile.id)
                & (PersistData.gameid == game.id)).get()
            data_entry.base64Data = persist_data["data"]
            data_entry.modified = datetime.utcnow()

            data_entry.save()
        except (PersistData.DoesNotExist) as e:
            data_entry = PersistData.create(
                base64Data=persist_data["data"],
                data_index=persist_data["data_index"],
                persist_type=persist_data["data_type"],
                modified=datetime.utcnow(),
                profileid=persist_data["profileid"],
                gameid=persist_data["game_id"])

        ret = model_to_dict(data_entry)
        del ret["profile"]

        ret["modified"] = calendar.timegm(ret["modified"].utctimetuple())
        return ret
Exemplo n.º 3
0
 def handle_delete_group(self, request):
     group_data = request["group"]
     game = Game.select().where(Game.id == group_data["gameid"]).get()
     count = GameGroup.delete().where(
         GameGroup.groupid == group_data["groupid"]).execute()
     self.redis_group_ctx.delete("{}:{}:".format(game.gamename,
                                                 group_data["groupid"]))
     self.redis_group_ctx.delete("{}:{}:custkeys".format(
         game.gamename, group_data["groupid"]))
     return {"success": True, "count": count}
Exemplo n.º 4
0
    def handle_update_game(self, request):
        game_data = request["game"]
        game = Game.select().where(Game.id == game_data["id"]).get()

        old_data = model_to_dict(game)
        for key in game_data:
            if key != "id":
                setattr(game, key, game_data[key])
        game.save()
        self.sync_game_to_redis(model_to_dict(game), old_data)
        return {"success": True}
Exemplo n.º 5
0
    def sync_group_to_redis(self, new_data, old_data):
        new_game = Game.select().where(Game.id == new_data["gameid"]).get()
        old_game = Game.select().where(Game.id == old_data["gameid"]).get()
        self.redis_group_ctx.delete("{}:{}:".format(old_game.gamename,
                                                    old_data["groupid"]))
        self.redis_group_ctx.delete("{}:{}:custkeys".format(
            old_game.gamename, old_data["groupid"]))

        redis_key = "{}:{}:".format(new_game.gamename, new_data["groupid"])
        self.redis_group_ctx.hset(redis_key, "gameid", new_data["gameid"])
        self.redis_group_ctx.hset(redis_key, "groupid", new_data["groupid"])
        self.redis_group_ctx.hset(redis_key, "maxwaiting",
                                  new_data["maxwaiting"])
        self.redis_group_ctx.hset(redis_key, "password", 0)
        self.redis_group_ctx.hset(redis_key, "numwaiting", 0)

        other_str = new_data["other"]
        other_data = other_str.split("\\")[1::]

        it = iter(other_data)
        for x in it:
            key = x
            val = next(it)
            self.redis_group_ctx.hset("{}custkeys".format(redis_key), key, val)
Exemplo n.º 6
0
    def handle_get_games(self, request):
        ret = []
        where_statement = 1 == 1
        if "where" in request:
            where_req = request["where"]
            if "id" in where_req:
                where_statement = (where_statement) & (Game.id == int(
                    where_req["id"]))
            elif "gamename" in where_req:
                where_statement = where_statement & (Game.gamename
                                                     == where_req["gamename"])
        games = Game.select().where(where_statement)

        for game in games:
            ret.append(model_to_dict(game))
        return ret
Exemplo n.º 7
0
    def validate_request(self, xml_tree):
        request_info = {"success": False}
        game_id = xml_tree.find("{http://gamespy.net/sake}gameid").text
        secretkey = xml_tree.find("{http://gamespy.net/sake}secretKey").text
        loginTicket = xml_tree.find(
            "{http://gamespy.net/sake}loginTicket").text
        #gameid = xml_tree.find()
        #print("GameID: {}\n".format(game_id))
        game = Game.select().where(Game.id == game_id).get()
        profile = Profile.select().where(Profile.id == 10000).get()
        #print("Profile: {}\nGame: {}\n{} - {}\n".format(profile,game, game.secretkey, secretkey))
        if game.secretkey != secretkey:
            return request_info

        request_info["success"] = True
        request_info["game"] = game
        request_info["profile"] = profile
        return request_info
Exemplo n.º 8
0
    def update_or_create_keyed_data(self, persist_data, key, value):
        profile = None
        game = None
        try:
            profile = Profile.select().where(
                (Profile.id == persist_data["profileid"])).get()
            game = Game.select().where(
                (Game.id == persist_data["game_id"])).get()
        except (Profile.DoesNotExist, Game.DoesNotExist) as e:
            pass
        try:

            data_entry = PersistKeyedData.select().where(
                (PersistKeyedData.key_name == key)
                & (PersistKeyedData.data_index == persist_data["data_index"])
                & (PersistKeyedData.persist_type == persist_data["data_type"])
                & (PersistKeyedData.profileid == profile.id)
                & (PersistKeyedData.gameid == game.id)).get()
            data_entry.key_value = value
            data_entry.modified = datetime.utcnow()

            data_entry.save()
        except (PersistKeyedData.DoesNotExist) as e:
            data_entry = PersistKeyedData.create(
                key_name=key,
                key_value=value,
                data_index=persist_data["data_index"],
                persist_type=persist_data["data_type"],
                modified=datetime.utcnow(),
                profileid=persist_data["profileid"],
                gameid=persist_data["game_id"])

        ret = model_to_dict(data_entry)
        del ret["profile"]

        ret["modified"] = calendar.timegm(ret["modified"].utctimetuple())
        return ret