def _check_inviter_id(self, proxy, data, inviter_id, req, timer): user = data.user.get(True) if user.is_invited() or user.id == inviter_id: res = user_pb2.InviteRes() res.status = 0 res.ret = user_pb2.INVITE_DUPLICATE defer = DataBase().commit(data) defer.addCallback(self._be_invited_succeed, req, res, timer) return defer user_result = proxy.get_result("user", inviter_id) if user_result is None: logger.warning("Invalid inviter[err_inviter_id=%d]" % inviter_id) res = user_pb2.InviteRes() res.status = 0 res.ret = user_pb2.INVITE_CODE_INVALID defer = DataBase().commit(data) defer.addCallback(self._be_invited_succeed, req, res, timer) return defer forward_req = user_pb2.InviteReq() forward_req.invite_code = req.invite_code forward_req.invitee_id = user.id forward_req.invitee_level = user.level forward_request = forward_req.SerializeToString() defer = GlobalObject().root.callChild('portal', "forward_be_invited", user_result.id, forward_request) defer.addCallback(self._check_forward_be_invited_result, data, inviter_id, req, timer) return defer
def _check_forward_invitee_upgrade_result(response, data): res = user_pb2.InviteRes() res.ParseFromString(response) if res.status != 0: logger.warning("Forward invitee upgrade result failed") #raise Exception("Forward invitee upgrade result failed") return DataBase().commit(data)
def _receive_invitee_upgrade_failed(self, err, req, timer): logger.fatal("Receive invitee upgrade failed[reason=%s]" % err) res = user_pb2.InviteRes() res.status = -1 response = res.SerializeToString() logger.notice("Receive invitee upgrade failed" "[user_id=%d][req=%s][res=%s][consume=%d]" % (timer.id, req, res, timer.count_ms())) return response
def _calc_receive_invitee_upgrade(self, data, req, timer): """ """ res = user_pb2.InviteRes() res.status = 0 user = data.user.get() user.update_invitee(req.invitee_id, req.invitee_level) res.ret = user_pb2.INVITE_OK defer = DataBase().commit(data) defer.addCallback(self._receive_invitee_upgrade_succeed, req, res, timer) return defer
def _calc_receive_from_invitee(self, data, req, timer): """ """ res = user_pb2.InviteRes() res.status = 0 user = data.user.get() if user.add_invitee(req.invitee_id, req.invitee_level): res.ret = user_pb2.INVITE_OK else: res.ret = user_pb2.INVITE_CODE_REACH_LIMITED defer = DataBase().commit(data) defer.addCallback(self._receive_from_invitee_succeed, req, res, timer) return defer
def _check_forward_be_invited_result(self, response, data, inviter_id, req, timer): res = user_pb2.InviteRes() res.ParseFromString(response) if res.status != 0: logger.warning("Forward be invited result failed") #raise Exception("Notice battle result failed") else: if res.ret == user_pb2.INVITE_OK: user = data.user.get() user.set_inviter(inviter_id) res.inviter_user_id = inviter_id defer = DataBase().commit(data) defer.addCallback(self._be_invited_succeed, req, res, timer) return defer