def user_cb(content): DEBUG_MSG("cardCheck user_cb content is {}".format(content)) if avatar is None or avatar.isDestroyed: INFO_MSG( "Table AA_PAY_MODE cardCheck back avatar is destroyed") return if content is None: DEBUG_MSG("cardCheck user_cb content is None") callable(callback) and callback(False, "网络有点问题") return try: data = json.loads(content) # AA付费 自己房卡必须大于等于房间最低消耗数量, 否则不让玩家坐下游戏 card_cost, diamond_cost = utility.calc_cost( game_type, room_params) if data["card"] >= card_cost: callable(callback) and callback(True, None) else: callable(callback) and callback( False, "您的房卡不足, 无法坐下游戏") except: import traceback ERROR_MSG(traceback.format_exc()) callable(callback) and callback(False, "网络有点问题")
def callback(content): if self.isDestroyed: return if content is None: DEBUG_MSG("createRoom callback error: content is None, user id {}".format(self.userId)) self.createRoomFailed(const.CREATE_FAILED_NET_SERVER_ERROR) return try: DEBUG_MSG("cards response: {}".format(content)) if content[0] != '{': self.createRoomFailed(const.CREATE_FAILED_NET_SERVER_ERROR) return data = json.loads(content) card_cost, diamond_cost = utility.calc_cost(game_type, create_dict) DEBUG_MSG("card_cost={} diamond_cost={}".format(card_cost, diamond_cost)) if card_cost > data["card"] and diamond_cost > data["diamond"]: self.createRoomFailed(const.CREATE_FAILED_NO_ENOUGH_CARDS) return params = { 'owner_uid' : self.userId, 'club_id' : 0, } params.update(roomParamsGetter(game_type, create_dict)) room = x42.GW.createRoom(game_type, params) if room: self.createRoomSucceed(room) else: self.createRoomFailed(const.CREATE_FAILED_OTHER) except: import traceback ERROR_MSG("createRoom callback content = {} error:{}".format(content, traceback.format_exc())) self.createRoomFailed(const.CREATE_FAILED_OTHER)
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 user_info_callback(content): if content is None: entityCall.enterRoomFailed( const.CREATE_FAILED_NET_SERVER_ERROR) return try: data = json.loads(content) card_cost, diamond_cost = utility.calc_cost( self.gameType, self.roomParams) if card_cost > data["card"]: entityCall.enterRoomFailed( const.ENTER_FAILED_ROOM_DIAMOND_NOT_ENOUGH) return except: import traceback ERROR_MSG(traceback.format_exc()) entityCall.enterRoomFailed(const.CREATE_FAILED_OTHER) return enter_callback()
def charge(self, accountList): accountList = list(accountList) self.state = const.ROOM_TRANSITION if switch.DEBUG_BASE: self.chargeCallback(True) return card_cost, diamond_cost = utility.calc_cost(self.gameType, self.roomParams) if self.pay_mode == const.NORMAL_PAY_MODE: pay_account = accountList[0] reason = "{} RoomID:{} type:{}".format(const.GAME_NAME, self.roomID, self.className) def pay_callback(content): # ret = self._check_pay_callback(content) # self.chargeCallback(ret) INFO_MSG( "player {} charge NORMAL_PAY_MODE pay_callback content:{}". format(pay_account, content)) # 不论是否扣卡成功, 都让玩家继续游戏 self.chargeCallback(True) utility.update_card_diamond(pay_account, -card_cost, -diamond_cost, pay_callback, reason) elif self.pay_mode == const.CLUB_PAY_MODE: pay_account = self.club.owner['accountName'] reason = "{} Club:{} RoomID:{} type:{}".format( const.GAME_NAME, self.club.clubId, self.roomID, self.className) def pay_callback(content): # ret = self._check_pay_callback(content) # self.chargeCallback(ret) INFO_MSG( "player {} charge CLUB_PAY_MODE pay_callback content:{}". format(pay_account, content)) # 不论是否扣卡成功, 都让玩家继续游戏 self.chargeCallback(True) utility.update_card_diamond(pay_account, -card_cost, -diamond_cost, pay_callback, reason) elif self.pay_mode == const.AA_PAY_MODE: if self.club: reason = "{} Club:{} AA RoomID:{} type:{}".format( const.GAME_NAME, self.club.clubId, self.roomID, self.className) else: reason = "{} AA RoomID:{} type:{}".format( const.GAME_NAME, self.roomID, self.className) def pay_callback(content): # ret = self._check_aa_pay_callback(content) # self.chargeCallback(ret) INFO_MSG( "player {} charge AA_PAY_MODE pay_callback content:{}". format(str(accountList), content)) # 不论是否扣卡成功, 都让玩家继续游戏 self.chargeCallback(True) utility.update_card_diamond_aa(accountList, -card_cost, -diamond_cost, pay_callback, reason) else: ERROR_MSG("pay2StartGame Error: No this PayMode:{}".format( self.pay_mode)) self.chargeCallback(False)
def get_continue_list(self, callback, playing_players): # 如果时代开房需要检查代理的房卡 # 如果时房主 需要检查房主放房卡 # 如果时AA 需要检查所有人的房卡 card_cost, diamond_cost = utility.calc_cost(self.gameTypeC, self.roomParamsC) # Fixme: self.club is none 需要使用base上的club def _check_user_info(user_id, content): if self.club and not self.club.isMember(user_id): DEBUG_MSG("{0} userId:{1} get_continue_list callback error: not in club {2}".format(self.prefixLogStr, user_id, self.club.clubId)) return False if content is None: DEBUG_MSG("{0} userId:{1} get_continue_list callback error: content is None".format(self.prefixLogStr, user_id)) return False try: data = json.loads(content) if diamond_cost > data["diamond"] and card_cost > data["card"]: return False except: err, msg, stack = sys.exc_info() DEBUG_MSG("{0} _check_user_info callback error:{1} {4}, exc_info: {2} ,{3}".format(self.prefixLogStr, content, err, msg, user_id)) return False return True def _user_info_callback(user_id, content): if _check_user_info(user_id, content): callback and callback([const.ROOM_CONTINUE] * self.player_num) else: callback and callback([const.ROOM_END] * self.player_num) if switch.DEBUG_BASE > 0: if self.pay_mode == const.CLUB_PAY_MODE: if self.club is None: callback and callback([const.ROOM_END] * self.player_num) return callback and callback([random.randint(0, 1) if i % 2 == 0 and i > 0 else 1 for i in range(self.player_num)]) elif self.pay_mode == const.NORMAL_PAY_MODE: utility.get_user_info(self.players_list[0].accountName, Functor(_user_info_callback, self.players_list[0].userId)) elif self.pay_mode == const.AA_PAY_MODE: count = len(playing_players) stats = 0 result = [const.ROOM_END] * self.player_num for p in playing_players: result[p.idx] = const.ROOM_CONTINUE def _find_idx(user_id): for p in playing_players: if p.userId == user_id: return p.idx return -1 def _check_callback_aa(roomId, user_id, content): nonlocal stats nonlocal result stats += 1 if not _check_user_info(user_id, content): idx = _find_idx(user_id) if idx != -1: result[idx] = const.ROOM_END if count == stats: callback and callback(result) for p in playing_players: utility.get_user_info(p.accountName, Functor(_check_callback_aa, self.roomIDC, p.userId)) elif self.pay_mode == const.CLUB_PAY_MODE: if self.club is None: callback and callback([const.ROOM_END] * self.player_num) else: pay_account = self.club.owner['accountName'] utility.get_user_info(pay_account, Functor(_user_info_callback, self.club.owner['userId'])) else: ERROR_MSG("{} get_continue_list: not support {} {}".format(self.prefixLogStr, self.room_type, self.pay_mode)) callback and callback([0] * self.player_num)