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("申请已发送, 请联系茶楼老板通过审核")
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()
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)
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
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()
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)
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 # 第二局开始扣房卡 }
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())
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], }
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], }
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)
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("成员不存在")
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]))
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
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))
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))
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], }
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())
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], }