Пример #1
0
    def _calc_accept_union_battle_box_result(self, union_response, data, req,
                                             timer):
        res = union_battle_pb2.QueryUnionBattleBoxRes()
        res.status = 0

        union_res = internal_union_pb2.InternalUnionBattleBoxRes()
        union_res.ParseFromString(union_response)

        if union_res.status != 0:
            raise Exception("accept union battle box failed")

        if union_res.ret != union_pb2.UNION_OK:
            res.ret = union_res.ret
            return self._accept_union_battle_box_succeed(data, req, res, timer)

        item_id = 0
        item_num = 0
        for member in union_res.box.members:
            if member.user_id == data.id:
                item_id = member.item_id
                item_num = member.item_num

        if item_id != 0:
            item_business.gain_item(data, [(item_id, item_num)],
                                    "union battle", log_formater.UNION_BATTLE)

        res.ret = union_pb2.UNION_OK
        res.box.CopyFrom(union_res.box)

        defer = DataBase().commit(data)
        defer.addCallback(self._accept_union_battle_box_succeed, req, res,
                          timer)
        return defer
Пример #2
0
 def _accept_union_battle_box_failed(self, err, req, timer):
     logger.fatal("Accept union battle box failed[reason=%s]" % err)
     res = union_battle_pb2.QueryUnionBattleBoxRes()
     res.status = -1
     response = res.SerializeToString()
     logger.notice("Accept union battle box failed"
                   "[user_id=%d][req=%s][res=%s][consume=%d]" %
                   (timer.id, req, res, timer.count_ms()))
     return response
Пример #3
0
    def _calc_accept_union_battle_box(self, data, req, timer):
        union = data.union.get(True)
        if union is None or not union.is_belong_to_target_union(req.union_id):
            res = union_battle_pb2.QueryUnionBattleBoxRes()
            res.status = 0
            res.ret = union_pb2.UNION_NOT_MATCHED
            return self._accept_union_battle_box_succeed(data, req, res, timer)

        user = data.user.get(True)
        union_req = internal_union_pb2.InternalUnionBattleBoxReq()
        union_req.user_id = data.id
        union_req.user_name = user.name
        union_req.icon_id = user.icon_id

        defer = GlobalObject().remote['gunion'].callRemote(
            "accept_union_battle_box_succeed", req.union_id,
            union_req.SerializeToString())
        defer.addCallback(self._calc_accept_union_battle_box_result, data, req,
                          timer)
        return defer