def _calc_query(self, data, req, timer, force): union = data.union.get(True) if not force and not union.is_belong_to_target_union(req.union_id): #已经不属于对应联盟 res = union_pb2.QueryUnionRes() res.status = 0 res.ret = union_pb2.UNION_NOT_MATCHED res.monarch.user_id = data.id res.monarch.union_id = union.union_id defer = DataBase().commit(data) defer.addCallback(self._query_succeed, req, res, timer) return defer union.update_daily_info(timer.now) union_req = internal_union_pb2.InternalQueryUnionReq() union_req.user_id = data.id #请求 Union 模块,查询联盟情况 if not force: defer = GlobalObject().remote['gunion'].callRemote( "query_union", union.union_id, union_req.SerializeToString()) else: defer = GlobalObject().remote['gunion'].callRemote( "query_union_force", req.union_id, union_req.SerializeToString()) defer.addCallback(self._update_query_info, data, req, timer) return defer
def _query_union_info(self, proxy, data, plunder, rival, req, timer): """""" union_req = internal_union_pb2.InternalQueryUnionReq() union_req.user_id = data.id defer = GlobalObject().remote['gunion'].callRemote( "query_union_summary", rival.union_id, union_req.SerializeToString()) defer.addCallback(self._pack_query_player_response, data, plunder, rival, req, timer) return defer
def _sync_union(self, data, union_id, timer): """同步联盟信息 """ #请求 Union 模块 union_req = internal_union_pb2.InternalQueryUnionReq() union_req.user_id = data.id defer = GlobalObject().remote['gunion'].callRemote( "sync_union", union_id, union_req.SerializeToString()) defer.addCallback(self._calc_sync_result, data, timer) return defer
def query_summary(self, union_id, request): """查询联盟摘要 """ timer = Timer(union_id) req = internal_union_pb2.InternalQueryUnionReq() req.ParseFromString(request) defer = DataBase().get_data(union_id) defer.addCallback(self._calc_query_summary, req, timer) defer.addErrback(self._query_failed, req, timer) return defer
def sync(self, union_id, request): """同步联盟信息(内部接口) 同步是否在联盟中,联盟等级 """ timer = Timer(union_id) req = internal_union_pb2.InternalQueryUnionReq() req.ParseFromString(request) defer = DataBase().get_data(union_id) defer.addCallback(self._calc_sync, req, timer) defer.addErrback(self._sync_failed, req, timer) return defer