Пример #1
0
    def applyInClub(self, avatar_mb):
        uid = avatar_mb.userId
        if len(avatar_mb.clubList) >= const.CLUB_NUM_LIMIT:
            avatar_mb.showTip("达到茶楼数量上限, 无法加入更多茶楼")
            return
        if uid in self.members:
            avatar_mb.showTip("您已经在该茶楼中, 无需重复加入")
            return
        if self.isApplicant(uid):
            avatar_mb.showTip("请等待审核, 无需重复申请")
            return
        if len(self.members) >= const.CLUB_MEMBER_LIMIT:
            avatar_mb.showTip("茶楼成员已满, 请加入别的茶楼")
            return

        app_info = {
            'userId': uid,
            'uuid': avatar_mb.uuid,
            'sex': avatar_mb.sex,
            'nickname': avatar_mb.name,
            'head_icon': avatar_mb.head_icon,
            'ts': utility.get_cur_timestamp(),
        }
        self.applicants[uid] = app_info
        avatar_mb.showTip("申请已发送, 请联系茶楼老板通过审核")
Пример #2
0
	def _onClubSaved(self, avatar_mb, owner_info, log_info, success, club):
		uid = owner_info['userId']
		INFO_MSG("ClubStub player{} _onClubSaved state: {}, {}".format(uid, success, club.databaseID))

		if success:
			self.clubList.append(club.databaseID)
			self.clubs[club.clubId] = club
			mem_info = {
				'userId': uid,
				'uuid': owner_info['uuid'],
				'sex': owner_info['sex'],
				'nickname': owner_info['nickname'],
				'head_icon': owner_info['head_icon'],
				'login_time': log_info['login_time'],
				'logout_time': log_info['logout_time'],
				'notes': '',
				'ts': utility.get_cur_timestamp(),
			}
			# 这么些是为了防止回调回来的时候avatar已经销毁
			if avatar_mb and not avatar_mb.isDestroyed:
				club.members[uid] = mem_info
				club.member_status[uid] = {'online': True, 'free': True, 'login_time': log_info['login_time'], 'logout_time': log_info['logout_time'],}
				avatar_mb.clubList.append(club.clubId)
				avatar_mb.createClubCallback(club.getDetailInfo())
			else:
				club._addMemberIn(uid, mem_info)
			self.writeToDB()
Пример #3
0
    def readyForDestroy(self):
        INFO_MSG('iRoomManager readyForDestroy()')
        self.destroyState = const.DESTROY_PROCESS_BEGIN
        self.destroy_ts = utility.get_cur_timestamp()

        card_req = {}
        for key in list(self.rooms.keys()):
            room = self.rooms[key]
            if room.room_type == const.AGENT_ROOM and room.current_round < 1:
                # 代开房间没开始打, 返还房卡
                card_cost, diamond_cost = switch.calc_cost(
                    room.game_round, room.getCalCostNeed())
                if room.agent:
                    key = room.agent.accountName
                    if key in card_req:
                        val = card_req[key]
                        card_req[key] = (val[0] + card_cost,
                                         val[1] + diamond_cost)
                    else:
                        card_req[key] = (card_cost, diamond_cost)
            try:
                room.destroyByServer()
            except:
                pass
        self.rooms.clear()
        self.handleCardBack(card_req)
Пример #4
0
 def processTableResult(self):
     now = utility.get_cur_timestamp()
     keep = []
     for r in self.records:
         ts = r['time']
         if now - ts < const.CLUB_TABLE_RESULT_TTL:
             keep.append(r)
     self.records = keep
Пример #5
0
    def readyForDestroy(self):
        # 以前是为了退还没开始游戏的代开房的卡, 现在不需要了
        INFO_MSG('iRoomManager readyForDestroy()')
        self.destroyState = const.DESTROY_PROCESS_BEGIN
        self.destroy_ts = utility.get_cur_timestamp()
        for k, v in self.rooms.items():
            v.destroyByServer('')

        self.rooms.clear()
        self.destroyProcessFinish()
Пример #6
0
	def record_round_result(self):
		# 玩家记录当局战绩
		d = datetime.fromtimestamp(utility.get_cur_timestamp())
		round_result_d = {
			'date': '-'.join([str(d.year), str(d.month), str(d.day)]),
			'time': ':'.join([str(d.hour), str(d.minute)]),
			'round_record': [p.get_round_result_info() for p in self.players_list if p is not None and p.identity == const_ps.GAME_PLAYER],
			'recordId': self.record_id
		}
		self.game_result['round_result'].append(round_result_d)
Пример #7
0
	def get_club_complete_dict(self):
		return {
			'gameType'		: self.gameTypeC,
			'roomID'		: self.roomIDC,
			'time'			: utility.get_cur_timestamp(),
			'game_round'	: self.game_round,
			'pay_mode'		: self.pay_mode,
			'roundResult'	: json.dumps(self.game_result.get('round_result', [])),
			'player_info_list': [p.get_club_client_dict() for p in self.players_list if p is not None],
			'cost'			: utility.calc_cost(self.gameTypeC, self.roomParamsC)[0] if self.current_round >= 2 else 0 # 第二局开始扣房卡
		}
Пример #8
0
    def agreeInClub(self, avatar_mb, target_uid):
        app_info = self.applicants.get(target_uid)
        if app_info is None:
            app_list = self.getApplicants()
            avatar_mb.gotClubApplicants(app_list)
            return
        if len(self.members) >= const.CLUB_MEMBER_LIMIT:
            avatar_mb.showTip("操作失败, 亲友圈成员已满")
            return

        # 移出申请列表
        del self.applicants[target_uid]
        # 没有玩家申请
        len(self.applicants) == 0 and self.event_mgr.push_event(
            Events.EVENT_CLUB_APPLY_HINT)

        if target_uid in self.members:
            avatar_mb.showTip("该玩家已经是亲友圈成员")
            avatar_mb.gotClubApplicants(self.getApplicants())
            return

        # 将玩家加入亲友圈成员
        mem_info = {
            'userId': target_uid,
            'uuid': app_info['uuid'],
            'sex': app_info['sex'],
            'nickname': app_info['nickname'],
            'head_icon': app_info['head_icon'],
            'login_time': app_info['login_time'],
            'logout_time': app_info['logout_time'],
            'notes': '',
            'ts': utility.get_cur_timestamp(),
            'power': const.CLUB_POWER_CIVIL
        }

        def add_cb(avatar_mb, result, msg=None):
            if result:
                # avatar_mb.gotClubMembers(self.clubId, self.getMembers())
                data = {
                    'op': const.CLUB_MEMBER_OP_ADD,
                    'online': self.member_status[target_uid]['online'],
                    'free': self.member_status[target_uid]['free']
                }
                data.update(mem_info)
                self.event_mgr.push_event(Events.EVENT_CLUB_MEMBER_CHANGE,
                                          data)
                self.event_mgr.push_event(Events.EVENT_MEMBER_NUM_CHANGE)
            else:
                msg and avatar_mb.showTip(msg)

        self._addMemberIn(target_uid, mem_info, Functor(add_cb, avatar_mb))
        avatar_mb.gotClubApplicants(self.getApplicants())
Пример #9
0
	def get_agent_complete_dict(self):
		# @formatter:off
		return {
			'roomID'	: self.roomID,
			'maxRound'	: self.game_round,
			'king_num'	: self.king_num,
			'pay_mode'	: self.pay_mode,
			'player_num': self.player_num,
			'lucky_num'	: self.lucky_num,
			'time'		: utility.get_cur_timestamp(),
			'hand_prepare': self.hand_prepare,
			'player_simple_info_list': [p.get_simple_client_dict() for p in self.origin_players_list if p is not None],
		}
Пример #10
0
	def get_agent_complete_dict(self):
		return {
			'roomID': self.roomID,
			'game_round': self.game_round,
			'pay_mode': self.pay_mode,
			'game_mode': self.game_mode,
			'game_max_lose': self.game_max_lose,
			'max_boom_times': self.max_boom_times,
			'player_num': self.player_num,
			'hand_prepare': self.hand_prepare,
			'time': utility.get_cur_timestamp(),
			'player_simple_info_list': [p.get_simple_client_dict() for p in self.players_list if p is not None],
		}
Пример #11
0
 def initDataStatisticTimer(self):
     # 每整5分钟的时候往后台发送实时在线数据
     ts = utility.get_cur_timestamp()
     period = 5 * 60
     left = ts % period
     if left == 0:
         self.add_timer(10, self.updateDataStatistics)
         self.add_repeat_timer(period, period, self.updateDataStatistics)
     else:
         offset = period - left
         # 如果剩余时间大于1分钟, 则开服10s先发送一次数据, 之后再在整5分钟的时候发送数据
         if offset >= 60:
             self.add_timer(10, self.updateDataStatistics)
         self.add_repeat_timer(offset, period, self.updateDataStatistics)
Пример #12
0
 def setMemberNotes(self, avatar_mb, target_uid, notes):
     mem = self.members.get(target_uid)
     if mem:
         notes = utility.filter_emoji(notes)
         notes = notes[:const.MEMBER_NOTES_LENGTH]
         mem['notes'] = notes
         # avatar_mb.gotClubMembers(self.clubId, self.getMembers())
         data = {
             'ts': utility.get_cur_timestamp(),
             'op': const.CLUB_MEMBER_OP_UPDATE,
             'online': self.member_status[target_uid]['online'],
             'free': self.member_status[target_uid]['free']
         }
         data.update(mem)
         self.event_mgr.push_event(Events.EVENT_CLUB_MEMBER_CHANGE, data)
     else:
         avatar_mb.showTip("成员不存在")
Пример #13
0
	def updateDataStatistics(self):
		""" 统计当前玩家数量和房间数量 """
		ts = utility.get_cur_timestamp()
		p_num = len(self.avatars)
		o_num = len([p for p in self.avatars.values() if getattr(p, "client", None) is not None])
		r_num = len(self.rooms)

		if switch.DEBUG_BASE == 0:
			def update_cb(content):
				if content:
					INFO_MSG("updateDataStatistics-{}: {}".format(ts, content))
				else:
					INFO_MSG("updateDataStatistics-{}: Nothing".format(ts))

			utility.update_data_statistics(ts, p_num, o_num, r_num, update_cb)
		else:
			# 测试服直接打印统计信息
			INFO_MSG("updateDataStatistics-{}: {}".format(ts, [p_num, o_num, r_num]))
Пример #14
0
def onReadyForShutDown():
    """
	KBEngine method.
	进程询问脚本层:我要shutdown了,脚本是否准备好了?
	如果返回True,则进程会进入shutdown的流程,其它值会使得进程在过一段时间后再次询问。
	用户可以在收到消息时进行脚本层的数据清理工作,以让脚本层的工作成果不会因为shutdown而丢失。
	"""
    INFO_MSG('onReadyForShutDown')
    if x42.GW.destroyState == None:
        x42.GW.readyForDestroy()
        return False

    if x42.GW.destroyState == const.DESTROY_PROCESS_END:
        return True
    else:
        now = utility.get_cur_timestamp()
        if now - x42.GW.destroy_ts >= const.DESTROY_PROCESS_TIME:
            return True
        else:
            return False
Пример #15
0
        def query_cb(uinfo):
            # 将玩家加入茶楼成员
            mem_info = {
                'userId': target_uid,
                'uuid': uinfo['uuid'],
                'sex': uinfo['sex'],
                'nickname': uinfo['name'],
                'head_icon': uinfo['head_icon'],
                'notes': '',
                'ts': utility.get_cur_timestamp(),
            }

            def add_cb(avatar_mb, result, msg=None):
                if result:
                    avatar_mb.showTip("邀请成功")
                    avatar_mb.gotClubMembers(self.getMembers())
                else:
                    msg and avatar_mb.showTip(msg)

            self._addMemberIn(target_uid, mem_info, Functor(add_cb, avatar_mb))
Пример #16
0
        def query_cb(uinfo):
            if uinfo is None:
                avatar_mb.showTip("查无此人")
                return
            # 将玩家加入亲友圈成员
            mem_info = {
                'userId': target_uid,
                'uuid': uinfo['uuid'],
                'sex': uinfo['sex'],
                'nickname': uinfo['name'],
                'head_icon': uinfo['head_icon'],
                'login_time': uinfo['login_time'],
                'logout_time': uinfo['logout_time'],
                'notes': '',
                'ts': utility.get_cur_timestamp(),
                'power': const.CLUB_POWER_CIVIL
            }

            def add_cb(avatar_mb, result, msg=None):
                if result:
                    avatar_mb.showTip("邀请成功")
                    # avatar_mb.gotClubMembers(self.clubId, self.getMembers())
                    data = {
                        'op': const.CLUB_MEMBER_OP_ADD,
                        'online': self.member_status[target_uid]['online'],
                        'free': self.member_status[target_uid]['free']
                    }
                    data.update(mem_info)
                    self.event_mgr.push_event(Events.EVENT_CLUB_MEMBER_CHANGE,
                                              data)
                    self.event_mgr.push_event(Events.EVENT_MEMBER_NUM_CHANGE)
                    # 移出申请列表
                    self.applicants.pop(target_uid, None)
                    # 没有玩家申请
                    len(self.applicants) == 0 and self.event_mgr.push_event(
                        Events.EVENT_CLUB_APPLY_HINT)
                else:
                    msg and avatar_mb.showTip(msg)

            self._addMemberIn(target_uid, mem_info, Functor(add_cb, avatar_mb))
Пример #17
0
	def get_agent_complete_dict(self):
		return {
			'roomID'			: self.roomID,
			'maxRound'			: self.game_round,
			# 'king_num'			: self.king_num,
			# 'game_mode'			: self.game_mode,
			# 'game_max_lose'		: self.game_max_lose,
			# 'round_max_lose'	: self.round_max_lose,
			'player_num'		: self.player_num,
			'pay_mode'			: self.pay_mode,
			# 'base_score'		: self.base_score,
			# 'king_mode'			: self.king_mode,
			# 'win_mode'			: self.win_mode,
			# 'three_job'			: self.three_job,
			# 'pong_useful'		: self.pong_useful,
			# 'bao_tou'			: self.bao_tou,
			# 'begin_dealer_mul'	: self.begin_dealer_mul,
			# 'lucky_num'			: self.lucky_num,
			'hand_prepare'		: self.hand_prepare,
			'time'				: utility.get_cur_timestamp(),
			'player_simple_info_list': [p.get_simple_client_dict() for p in self.origin_players_list if p is not None],
		}
Пример #18
0
    def agreeInClub(self, avatar_mb, target_uid):
        app_info = self.applicants.get(target_uid)
        if app_info is None:
            app_list = self.getApplicants()
            avatar_mb.gotClubApplicants(app_list)
            return
        if len(self.members) >= const.CLUB_MEMBER_LIMIT:
            avatar_mb.showTip("操作失败, 茶楼成员已满")
            return

        # 移出申请列表
        del self.applicants[target_uid]

        if target_uid in self.members:
            avatar_mb.showTip("该玩家已经是茶楼成员")
            avatar_mb.gotClubApplicants(self.getApplicants())
            return

        # 将玩家加入茶楼成员
        mem_info = {
            'userId': target_uid,
            'uuid': app_info['uuid'],
            'sex': app_info['sex'],
            'nickname': app_info['nickname'],
            'head_icon': app_info['head_icon'],
            'notes': '',
            'ts': utility.get_cur_timestamp(),
        }

        def add_cb(avatar_mb, result, msg=None):
            if result:
                avatar_mb.gotClubMembers(self.getMembers())
            else:
                msg and avatar_mb.showTip(msg)

        self._addMemberIn(target_uid, mem_info, Functor(add_cb, avatar_mb))
        avatar_mb.gotClubApplicants(self.getApplicants())
Пример #19
0
	def get_club_complete_dict(self):
		return {
			'roomID'		: self.roomID,
			'time'			: utility.get_cur_timestamp(),
			'player_info_list': [p.get_club_client_dict() for p in self.origin_players_list if p is not None],
		}