def createRoom(self, gameRound, roomMode, is_agent): DEBUG_MSG("create room,gameRound:{0}, roomMode:{1}".format( gameRound, roomMode)) if gameRound != 8 and gameRound != 16: if getattr(self, 'client', None): self.client.createRoomFailed(const.CREATE_FAILED_OTHER) return # params = { # 'owner_uid': self.userId, # 'roomMode' : roomMode, # 'game_round': gameRound, # 'lucky_tile': 0, # "maxOldDealNum" : 0, # "startOldDealNum" : 0, # "diceAddNum" : 0, # "isSameAdd" : 0, # "maxLoseScore" : 0, # 'is_agent': is_agent, # } # KBEngine.createBaseAnywhere("GameRoom", params, self.createRoomCallback) def callback(content): content = content.decode() try: DEBUG_MSG("cards response: {}".format(content)) if content[0] != '{': if getattr(self, 'client', None): self.client.createRoomFailed(const.CREATE_FAILED_OTHER) return data = json.loads(content) card_cost, diamond_cost = switch.calc_cost(roomMode, gameRound) if not KBEngine.globalData[ "GameWorld"].free_play and card_cost > data[ "card"] and diamond_cost > data["diamond"]: if getattr(self, 'client', None): self.client.createRoomFailed( const.CREATE_FAILED_NO_ENOUGH_CARDS) return params = { 'owner_uid': self.userId, 'roomMode': roomMode, 'game_round': gameRound, 'lucky_tile': 0, "maxOldDealNum": 0, "startOldDealNum": 0, "diceAddNum": 0, "isSameAdd": 0, "maxLoseScore": 0, 'is_agent': is_agent, } KBEngine.createBaseAnywhere("GameRoom", params, self.createRoomCallback) except: DEBUG_MSG("createRoom callback error:{}".format(content)) if getattr(self, 'self', None): self.client.createRoomFailed(const.CREATE_FAILED_OTHER) if switch.DEBUG_BASE: callback('{"card":99, "diamond":999}'.encode()) else: utility.get_user_info(self.accountName, callback)
def createRoom(self, player_num, game_round, follow_state, kong_state, kong_draw_win_double, dragon_state, contract_state, max_bet_num, is_agent): DEBUG_MSG( "create room, {0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}".format( player_num, game_round, follow_state, kong_state, kong_draw_win_double, dragon_state, contract_state, max_bet_num, is_agent)) if game_round != 8 and game_round != 16 and game_round != -2: return def callback(content): content = content.decode() try: DEBUG_MSG("cards response: {}".format(content)) if content[0] != '{': if getattr(self, 'client', None): self.client.createRoomFailed(const.CREATE_FAILED_OTHER) return data = json.loads(content) card_cost, diamond_cost = switch.calc_cost( game_round, player_num) if not KBEngine.globalData[ "GameWorld"].free_play and card_cost > data[ "card"] and diamond_cost > data["diamond"]: if getattr(self, 'client', None): self.client.createRoomFailed( const.CREATE_FAILED_NO_ENOUGH_CARDS) return # params = { # 'owner_uid': self.userId, # 'player_num': player_num, # 'win_quantity': win_quantity, # 'game_round': game_round, # 'king_num' : king_num, # 'is_agent': is_agent, # } params = { 'owner_uid': self.userId, 'player_num': player_num, 'game_round': game_round, 'follow_state': follow_state, 'kong_state': kong_state, 'kong_draw_win_double': kong_draw_win_double, 'dragon_state': dragon_state, 'contract_state': contract_state, 'max_bet_num': max_bet_num, 'is_agent': is_agent, } KBEngine.createBaseAnywhere("GameRoom", params, self.createRoomCallback) except: DEBUG_MSG("createRoom callback error:{}".format(content)) if getattr(self, 'self', None): self.client.createRoomFailed(const.CREATE_FAILED_OTHER) if switch.DEBUG_BASE: callback('{"card":99, "diamond":999}'.encode()) else: utility.get_user_info(self.accountName, callback)
def join(self, avt_mb): def callback(content): DEBUG_MSG("sport {} cards response: {}".format( self.sportId, content)) if content[0] != '{': DEBUG_MSG(content) return data = json.loads(content) card_cost, diamond_cost = self.base_info['cost'] if card_cost != 0 and data["card"] < card_cost: avt_mb.client.showTip("摩卡不足") elif diamond_cost != 0 and data["diamond"] < diamond_cost: avt_mb.client.showTip("钻石不足") elif data["card"] >= card_cost or data["diamond"] >= diamond_cost: self.pay(avt_mb) return if self.canJoinDailySport(avt_mb) == 0: avt_mb.client.showTip("请等待其他玩家结束比赛") return if avt_mb.free_sport_list[self.sportId - 1] > 0: avt_mb.free_sport_list[self.sportId - 1] -= 1 self.joinSuccess(avt_mb) elif avt_mb.isBot: self.joinSuccess(avt_mb) else: if switch.DEBUG_BASE: self.joinSuccess(avt_mb) # callback('{"card":99, "diamond":999}') else: utility.get_user_info(avt_mb.accountName, callback)
def createRoom(self, room_mode, game_round, insert_card, deal_mode, score_mode, changeSeat, best_phase, is_agent): DEBUG_MSG( "create room, user_id:{0} room_mode:{1}, game_round:{2}, insert_card:{3}, deal_mode:{4}, score_mode:{5}, changeSeat:{6}, best_phase:{7}, is_agent:{8}" .format(self.userId, room_mode, game_round, insert_card, deal_mode, score_mode, changeSeat, best_phase, is_agent)) if game_round != 4 and game_round != 8 and game_round != 12 and game_round != 16 and game_round != 20 and game_round != 24: game_round = 4 # params = { # 'owner_uid': self.userId, # 'game_round': game_round, # 'room_mode' : room_mode, # 'score_mode' : score_mode, # 'changeSeat' : changeSeat, # 'is_agent': is_agent, # } # KBEngine.createBaseAnywhere("GameRoom", params, self.createRoomCallback) def callback(content): content = content.decode() try: DEBUG_MSG("cards response: {}".format(content)) if content[0] != '{': if getattr(self, 'client', None): self.client.createRoomFailed(const.CREATE_FAILED_OTHER) return data = json.loads(content) card_cost, diamond_cost = switch.calc_cost( game_round, room_mode) if not KBEngine.globalData[ "GameWorld"].free_play and card_cost > data[ "card"] and diamond_cost > data["diamond"]: if getattr(self, 'client', None): self.client.createRoomFailed( const.CREATE_FAILED_NO_ENOUGH_CARDS) return params = { 'owner_uid': self.userId, 'room_mode': room_mode, 'game_round': game_round, 'insert_card': insert_card, 'deal_mode': deal_mode, 'score_mode': score_mode, 'changeSeat': changeSeat, 'best_phase': best_phase, 'is_agent': is_agent, } KBEngine.createBaseAnywhere("GameRoom", params, self.createRoomCallback) except: DEBUG_MSG("createRoom callback error:{}".format(content)) if getattr(self, 'self', None): self.client.createRoomFailed(const.CREATE_FAILED_OTHER) if switch.DEBUG_BASE: callback('{"card":99, "diamond":999}'.encode()) else: utility.get_user_info(self.accountName, callback)
def reqEnterRoom(self, avt_mb, first=False): """ defined. 客户端调用该接口请求进入房间/桌子 """ if self.isFull: avt_mb.enterRoomFailed(const.ENTER_FAILED_ROOM_FULL) return def callback(content): content = content.decode() try: data = json.loads(content) card_cost, diamond_cost = switch.calc_cost( self.game_round, self.player_num, self.pay_mode) if diamond_cost > data["diamond"]: avt_mb.enterRoomFailed( const.ENTER_FAILED_ROOM_DIAMOND_NOT_ENOUGH) return # 代开房 if first and self.is_agent == 1: self.agent = PlayerProxy(avt_mb, self, -1) self.players_dict[avt_mb.userId] = self.agent avt_mb.enterRoomSucceed(self, -1) return for i, p in enumerate(self.players_list): if p and p.mb and p.mb.userId == avt_mb.userId: p.mb = avt_mb avt_mb.enterRoomSucceed(self, i) return DEBUG_MSG("Room.reqEnterRoom: %s" % (self.roomID)) idx = self.getSit() n_player = PlayerProxy(avt_mb, self, idx) self.players_dict[avt_mb.userId] = n_player self.players_list[idx] = n_player # 确认准备 # if idx not in self.confirm_next_idx: # self.confirm_next_idx.append(idx) if not first: self.broadcastEnterRoom(idx) self.check_same_ip() if self.isFull: self.origin_players_list = self.players_list[:] except: DEBUG_MSG("enterRoomFailed callback error:{}".format(content)) if switch.DEBUG_BASE: callback('{"card":99, "diamond":999}'.encode()) else: if first or self.pay_mode != 0: callback('{"card":99, "diamond":999}'.encode()) else: utility.get_user_info(avt_mb.accountName, callback)
def createRoom(self, game_type, create_json): create_dict = None try: create_dict = json.loads(create_json) except: return DEBUG_MSG("create room game_type={} args = {}".format(game_type, create_dict)) create_dict['room_type'] = const.NORMAL_ROOM if not roomParamsChecker(game_type, create_dict): return if self.req_entering_room: return if self.cell is not None: self.createRoomFailed(const.CREATE_FAILED_ALREADY_IN_ROOM) return self.req_entering_room = True 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) if switch.DEBUG_BASE or x42.GW.isDailyActFree: callback('{"card":99, "diamond":9999}') else: utility.get_user_info(self.accountName, callback)
def createRoom(self, player_num, win_quantity, game_round, king_num, pay_mode, game_mode, is_agent): DEBUG_MSG("create room, {0}, {1}, {2}, {3}, {4}, {5}, {6}".format( player_num, win_quantity, game_round, king_num, pay_mode, game_mode, is_agent)) if game_round <= 0: game_round = 4 def callback(content): content = content.decode() try: DEBUG_MSG("cards response: {}".format(content)) if content[0] != '{': if getattr(self, 'client', None): self.client.createRoomFailed(const.CREATE_FAILED_OTHER) return data = json.loads(content) card_cost, diamond_cost = switch.calc_cost( game_round, game_mode, pay_mode, player_num) if not KBEngine.globalData[ "GameWorld"].free_play and card_cost > data[ "card"] and diamond_cost > data["diamond"]: if getattr(self, 'client', None): self.client.createRoomFailed( const.CREATE_FAILED_NO_ENOUGH_CARDS) return params = { 'owner_uid': self.userId, 'player_num': player_num, 'win_quantity': win_quantity, 'game_round': game_round, 'king_num': king_num, 'pay_mode': pay_mode, 'game_mode': game_mode, 'is_agent': is_agent, } KBEngine.createBaseAnywhere("GameRoom", params, self.createRoomCallback) except: DEBUG_MSG("createRoom callback error:{}".format(content)) if getattr(self, 'self', None): self.client.createRoomFailed(const.CREATE_FAILED_OTHER) if switch.DEBUG_BASE: callback('{"card":99, "diamond":999}'.encode()) else: utility.get_user_info(self.accountName, callback)
def createRoom(self, createRoomInfoList): DEBUG_MSG("create room info list:{0}".format(str(createRoomInfoList))) if len(createRoomInfoList) < 4: return maxOldDealNum, startOldDealNum, diceAddNum, isSameAdd, maxLoseScore, is_agent = utility.getCreateRoomInfo(createRoomInfoList) def callback(content): content = content.decode() try: DEBUG_MSG("cards response: {}".format(content)) if content[0] != '{': if getattr(self, 'client', None): self.client.createRoomFailed(const.CREATE_FAILED_OTHER) return data = json.loads(content) card_cost, diamond_cost = switch.calc_cost(maxOldDealNum, maxLoseScore) if not KBEngine.globalData["GameWorld"].free_play and card_cost > data["card"] and diamond_cost > data["diamond"]: if getattr(self, 'client', None): self.client.createRoomFailed(const.CREATE_FAILED_NO_ENOUGH_CARDS) return params = { 'owner_uid': self.userId, 'game_round': 999, 'lucky_tile': 0, "maxOldDealNum" : maxOldDealNum, "startOldDealNum" : startOldDealNum, "diceAddNum" : diceAddNum, "isSameAdd" : isSameAdd, "maxLoseScore" : maxLoseScore, 'is_agent': is_agent, "createRoomInfoList" : createRoomInfoList } KBEngine.createBaseAnywhere("GameRoom", params, self.createRoomCallback) except: DEBUG_MSG("createRoom callback error:{}".format(content)) if getattr(self, 'self', None): self.client.createRoomFailed(const.CREATE_FAILED_OTHER) if switch.DEBUG_BASE: callback('{"card":99, "diamond":999}'.encode()) else: utility.get_user_info(self.accountName, callback)
def createClub(self): # 检查代理创建亲友圈的权限 if not self.canCreateClub(): self.clubOperationFailed(const.CLUB_OP_ERR_PERMISSION_DENY) return if self.club_creating: return self.club_creating = True def callback(content): if self.check_info_cb(content): self.createPayCallback() else: self.club_creating = False self.clubOperationFailed(const.CLUB_OP_ERR_CARD_NOT_ENOUGH) if switch.DEBUG_BASE > 0: self.createPayCallback() else: utility.get_user_info(self.accountName, callback)
def enterRoom(self, entityCall, first=False): """ defined method. 请求进入某个space中 """ # 检查玩家数量 if self.isFull: entityCall.enterRoomFailed(const.ENTER_FAILED_ROOM_FULL) return # 如果是亲友圈房间检查是否是亲友圈成员 if self.room_type == const.CLUB_ROOM: if self.club and not self.club.isMember(entityCall.userId): entityCall.enterRoomFailed(const.ENTER_FAILED_NOT_CLUB_MEMBER) return if self.club and self.club.isLocked(): entityCall.enterRoomFailed(const.ENTER_FAILED_CLUB_LOCKED) return if self.club and self.club.isBlack(entityCall.userId): entityCall.enterRoomFailed(const.ENTER_FAILED_ROOM_BLACK) return def enter_callback(): if self.isDestroyed: entityCall.enterRoomFailed(const.ENTER_FAILED_ROOM_DESTROYED) return # AA支付的情况下, 可能多个玩家同时走到这里 if self.isFull: entityCall.enterRoomFailed(const.ENTER_FAILED_ROOM_FULL) return if self.cell: self.onEnter(entityCall) else: self.request.append(entityCall) # 如果是AA支付类型, 检查房卡余量是否足够 if switch.DEBUG_BASE: enter_callback() else: if first or self.pay_mode != const.AA_PAY_MODE: enter_callback() else: def user_info_callback(content): if entityCall is None or entityCall.isDestroyed: INFO_MSG( "Room AA_PAY_MODE cardCheck back avatar is destroyed" ) return 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() utility.get_user_info(entityCall.accountName, user_info_callback)
def cardCheck(self, avatar, callback): # 调试环境直接返回成功 if switch.DEBUG_BASE > 0: callable(callback) and callback(True) return club_game_round = self.club.roomType['game_round'] club_pay_mode = self.club.roomType['pay_mode'] if club_pay_mode == const.AA_PAY_MODE: account = avatar.accountName def user_cb(content): DEBUG_MSG("cardCheck user_cb content is {}".format(content)) 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 = switch.calc_cost(club_game_round, self.club.getCalCostNeed()) 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, "网络有点问题") utility.get_user_info(account, user_cb) elif club_pay_mode == const.CLUB_PAY_MODE: account = self.club.owner['accountName'] def user_cb(content): DEBUG_MSG("cardCheck user_cb content is {}".format(content)) if content is None: DEBUG_MSG("cardCheck user_cb content is None") callable(callback) and callback(False, "网络有点问题") return try: data = json.loads(content) # 亲友圈老板的房卡必须大于最低房卡数量, 否则不让玩家坐下游戏 # param = dict(self.club.roomType) # d = {'game_mode': param['game_mode'], 'pay_mode': param['pay_mode'], 'game_max_lose': param['game_max_lose']} # card_cost, diamond_cost = switch.calc_cost(param['game_round'], param['pay_mode']) # DEBUG_MSG("cardCheck user_cb card_cost:{}, diamond_cost:{}".format(card_cost, diamond_cost)) if data["card"] >= switch.CLUB_CARD_MIN: msg = None if data['card'] < switch.CLUB_CARD_WARN: msg = "亲友圈房卡即将不足, 请及时提醒亲友圈老板" callable(callback) and callback(True, msg) else: callable(callback) and callback(False, "亲友圈老板房卡不足, 无法坐下游戏") except: import traceback ERROR_MSG(traceback.format_exc()) callable(callback) and callback(False, "网络有点问题") utility.get_user_info(account, user_cb) else: callable(callback) and callback(False, "扣卡方式不正确")
def cardCheck(self, avatar, callback): # 调试环境直接返回成功 if switch.DEBUG_BASE > 0: callable(callback) and callback(True) return game_type = self.gameType room_params = self.roomParams club_pay_mode = room_params['pay_mode'] room_params['isAgent'] = self.club.owner['isAgent'] if club_pay_mode == const.AA_PAY_MODE: account = avatar.accountName 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, "网络有点问题") utility.get_user_info(account, user_cb) elif club_pay_mode == const.CLUB_PAY_MODE: account = self.club.owner['accountName'] 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) # 亲友圈老板的房卡必须大于最低房卡数量, 否则不让玩家坐下游戏 if data["card"] >= switch.CLUB_CARD_MIN: msg = None if data['card'] < switch.CLUB_CARD_WARN: msg = "亲友圈房卡即将不足, 请及时提醒亲友圈老板" callable(callback) and callback(True, msg) else: callable(callback) and callback( False, "亲友圈老板房卡不足, 无法坐下游戏") except: import traceback ERROR_MSG(traceback.format_exc()) callable(callback) and callback(False, "网络有点问题") utility.get_user_info(account, user_cb) else: callable(callback) and callback(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)
def createRoom(self, create_dict): DEBUG_MSG("create room args = {}".format(create_dict)) if self.req_entering_room: DEBUG_MSG( "iRoomOperation: createRoom failed; entering or creating room") return if self.isInRoom: self.createRoomFailed(const.CREATE_FAILED_ALREADY_IN_ROOM) return game_mode = create_dict['game_mode'] pay_mode = create_dict['pay_mode'] king_mode = create_dict['king_mode'] game_round = create_dict['game_round'] round_mode = create_dict['round_mode'] base_score_mode = create_dict['base_score_mode'] max_lose = create_dict['max_lose'] score = create_dict['score'] job = create_dict['job'] discard_seconds = create_dict['discard_seconds'] hand_prepare = create_dict['hand_prepare'] room_type = create_dict['room_type'] # Attention: 客户端传过来的数据都不可信, 必须检查一下 if game_mode not in const.GAME_MODE \ or game_round not in const.ROUND \ or king_mode not in const.KING_MODES \ or round_mode not in const.ROUND_MODE \ or base_score_mode not in const.BASE_SCORE_MODE \ or max_lose not in const.MAX_LOSE \ or score not in const.GAME_SCORE \ or job not in const.JOB_MODE \ or discard_seconds not in const.DISCARD_SECONDS \ or hand_prepare not in const.PREPARE_MODE \ or pay_mode not in (const.NORMAL_PAY_MODE, const.AA_PAY_MODE, const.AGENT_PAY_MODE) \ or room_type not in (const.NORMAL_ROOM, const.AGENT_ROOM): DEBUG_MSG("createRoom params error") return game_round = game_round if round_mode == const.ROUND_MODE_SCORE: game_round = 9999 # 检查代开房上限 if room_type == const.AGENT_ROOM: if not self.isAgent: self.createRoomFailed(const.CREATE_FAILED_PERMISSION_DENIED) return if len(self.playingRoomList) >= const.AGENT_ROOM_LIMIT: self.createRoomFailed(const.CREATE_FAILED_AGENT_ROOM_LIMIT) return self.req_entering_room = True def callback(content): 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 = switch.calc_cost( game_round, { "round_mode": round_mode, "pay_mode": pay_mode }) if not KBEngine.globalData[ "GameWorld"].free_play and card_cost > data[ "card"] and diamond_cost > data["diamond"]: self.createRoomFailed(const.CREATE_FAILED_NO_ENOUGH_CARDS) return params = { 'owner_uid': self.userId, 'king_num': 1, 'player_num': 4, 'game_round': game_round, 'round_mode': round_mode, 'base_score_mode': base_score_mode, 'pay_mode': pay_mode, 'game_mode': game_mode, 'king_mode': king_mode, 'max_lose': max_lose, 'score': score, 'job': job, 'discard_seconds': discard_seconds, 'hand_prepare': hand_prepare, 'room_type': room_type, } KBEngine.createBaseAnywhere("GameRoom", params, self.createRoomCallback) except: err, msg, stack = sys.exc_info() DEBUG_MSG( "createRoom callback error:{} , exc_info: {} ,{}".format( content, err, msg)) self.createRoomFailed(const.CREATE_FAILED_OTHER) if switch.DEBUG_BASE or KBEngine.globalData["GameWorld"].isDailyActFree: callback('{"card":99, "diamond":9999}') else: utility.get_user_info(self.accountName, callback)
def createRoom(self, create_dict): DEBUG_MSG("create room args = {}".format(create_dict)) game_mode = create_dict['game_mode'] base_score = create_dict['base_score'] play_list = create_dict['play_list'] round_max_lose = create_dict['round_max_lose'] game_max_lose = create_dict['game_max_lose'] game_round = create_dict['game_round'] hand_prepare = create_dict['hand_prepare'] pay_mode = create_dict['pay_mode'] room_type = create_dict['room_type'] if game_mode not in const.GAME_MODE \ or base_score not in const.BASE_SCORE \ or len(play_list) != 6 \ or play_list[0] not in const.KING_MODE \ or play_list[1] not in const.BEGIN_DEALER_MUL \ or play_list[2] not in const.WIN_MODE \ or play_list[3] not in const.THREE_JOB \ or play_list[4] not in const.PONG_USEFUL \ or play_list[5] not in const.BAO_TOU \ or round_max_lose not in const.ROUND_MAX_LOSE \ or game_max_lose not in const.GAME_MAX_LOSE \ or game_round not in const.GAME_ROUND \ or hand_prepare not in const.PREPARE_MODE \ or pay_mode not in (const.NORMAL_PAY_MODE, const.AA_PAY_MODE, const.AGENT_PAY_MODE) \ or room_type not in (const.NORMAL_ROOM, const.AGENT_ROOM): return if self.req_entering_room: return if self.isInRoom: self.createRoomFailed(const.CREATE_FAILED_ALREADY_IN_ROOM) return # 检查代开房上限 if room_type == const.AGENT_ROOM: if not self.isAgent: self.createRoomFailed(const.CREATE_FAILED_PERMISSION_DENIED) return if len(self.playingRoomList) >= const.AGENT_ROOM_LIMIT: self.createRoomFailed(const.CREATE_FAILED_AGENT_ROOM_LIMIT) return self.req_entering_room = True def callback(content): 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 = switch.calc_cost( game_round, { "game_mode": game_mode, "pay_mode": pay_mode, "game_max_lose": game_max_lose }) if not KBEngine.globalData[ "GameWorld"].free_play and card_cost > data[ "card"] and diamond_cost > data["diamond"]: self.createRoomFailed(const.CREATE_FAILED_NO_ENOUGH_CARDS) return params = { # 基本必填信息 'owner_uid': self.userId, 'king_num': 1, 'player_num': 4, 'lucky_num': 0, # client 2 svr 'game_mode': game_mode, 'base_score': base_score if game_mode == 0 else 1, 'king_mode': play_list[0], 'begin_dealer_mul': play_list[1], 'win_mode': play_list[2], 'three_job': play_list[3], 'pong_useful': play_list[4], 'bao_tou': play_list[5], 'round_max_lose': round_max_lose if game_mode == 0 else 0, 'game_max_lose': game_max_lose if game_mode == 1 else 999999, 'game_round': game_round if game_mode == 0 else 999999, 'hand_prepare': hand_prepare, 'pay_mode': pay_mode, 'room_type': room_type, } KBEngine.createBaseAnywhere("GameRoom", params, self.createRoomCallback) except: err, msg, stack = sys.exc_info() DEBUG_MSG( "createRoom callback error:{} , exc_info: {} ,{}".format( content, err, msg)) self.createRoomFailed(const.CREATE_FAILED_OTHER) if switch.DEBUG_BASE or KBEngine.globalData["GameWorld"].isDailyActFree: callback('{"card":99, "diamond":9999}') else: utility.get_user_info(self.accountName, callback)
def reqCreateDetailRoom(self, room_op, belong_info): DEBUG_MSG("reqCreateGroupRoom", room_op) if self.req_entering_room: return if self.inRoom: self.createRoomFailed(const.CREATE_FAILED_ALREADY_IN_ROOM) return # 检查客户端传过来的房间参数 game_mode = room_op["game_mode"] game_round = room_op["game_round"] player_num = room_op["player_num"] game_function = room_op["game_function"] game_start = room_op["game_start"] game_hei3 = room_op["game_hei3"] game_deal = room_op["game_deal"] game_force = room_op["game_force"] game_cardnum = room_op["game_cardnum"] game_plays = room_op["game_plays"] game_end = room_op["game_end"] anticheating = room_op["anticheating"] is_competition = room_op["is_competition"] is_agent = room_op["is_agent"] if game_mode not in const.GAME_MODE \ or game_round not in const.GAME_ROUND \ or player_num not in const.PLAYER_NUMBER \ or game_function not in const.GAME_FUNCTION \ or game_start not in const.GAME_START \ or game_hei3 not in const.GAME_HEI3 \ or game_deal not in const.GAME_DEAL \ or game_force not in const.GAME_FORCE \ or game_cardnum not in const.GAME_CARD_NUM \ or len(game_plays) != const.GAME_PLAYS_LENGTH \ or not utility.checkValuesIn(game_plays, const.GAME_PLAYS_VALUE) \ or len(game_end) != const.GAME_END_LENGTH \ or not utility.checkValuesIn(game_end, const.GAME_END_VALUE) \ or anticheating not in const.ANTI_CHEATING \ or is_competition not in const.ANTI_CHEATING \ or is_agent not in const.ROOM_TYPE: return self.req_entering_room = True def callback(content): try: DEBUG_MSG("cards response: {}".format(content)) if content[0] != '{': self.createRoomFailed(const.CREATE_FAILED_OTHER) return data = json.loads(content) card_cost, diamond_cost = switch.calc_cost(room_op["game_round"]) can_do = False if x42.GW.free_play: can_do = True if card_cost and card_cost <= data['card']: can_do = True if diamond_cost and diamond_cost <= data['diamond']: can_do = True if not can_do: self.createRoomFailed(const.CREATE_FAILED_NO_ENOUGH_CARDS) return detail_op = {} detail_op["game_mode"] = game_mode # FIXME 测试用, 正式时候记得改回来 # detail_op["game_round"] = game_round detail_op["game_round"] = 2 detail_op["player_num"] = player_num detail_op["game_function"] = game_function detail_op["game_start"] = game_start detail_op["game_hei3"] = game_hei3 detail_op["game_deal"] = game_deal detail_op["game_force"] = game_force detail_op["game_cardnum"] = game_cardnum detail_op["game_plays"] = game_plays detail_op["game_end"] = game_end detail_op["anticheating"] = anticheating detail_op["is_competition"] = is_competition detail_op["is_agent"] = is_agent detail_op.setdefault("match_mode", belong_info["match_mode"]) detail_op.setdefault("group_id", belong_info["group_id"]) detail_op.setdefault("team_uuid", belong_info["team_uuid"]) detail_op.setdefault("sportId", belong_info["sportId"]) detail_op.setdefault("owner_uid", self.userId) detail_op.setdefault("create_time", time.time()) DEBUG_MSG("reqCreate----GroupRoom", detail_op) KBEngine.createBaseAnywhere("GameRoom", detail_op, self.createRoomCallback) except: self.createRoomFailed(const.CREATE_FAILED_OTHER) if switch.DEBUG_BASE: callback('{"card":99, "diamond":999}') elif is_competition != 0: callback('{"card":99, "diamond":999}') else: accountName = self.accountName if belong_info["group_id"] > 0: group = KBEngine.globalData["GameWorld"].groupDict.get(belong_info["group_id"]) if group: accountName = KBEngine.globalData["GameWorld"].cacheDict.get(group.owner_info["userId"], {}).get("accountName", "") utility.get_user_info(accountName, callback)
def createRoom(self, create_dict): DEBUG_MSG("create room args = {}".format(create_dict)) game_round = create_dict['game_round'] lucky_poker = create_dict['lucky_poker'] pay_mode = create_dict['pay_mode'] hand_prepare = create_dict['hand_prepare'] room_type = create_dict['room_type'] # Attention: 客户端传过来的数据都不可信, 必须检查一下 if game_round not in const.ROUND \ or pay_mode not in (const.NORMAL_PAY_MODE, const.AA_PAY_MODE, const.AGENT_PAY_MODE) \ or lucky_poker not in const.LUCKY_POKER \ or room_type not in (const.NORMAL_ROOM, const.AGENT_ROOM) \ or hand_prepare not in const.PREPARE_MODE: return if self.req_entering_room: return if self.isInRoom: self.createRoomFailed(const.CREATE_FAILED_ALREADY_IN_ROOM) return # 检查代开房上限 if room_type == const.AGENT_ROOM: if not self.isAgent: self.createRoomFailed(const.CREATE_FAILED_PERMISSION_DENIED) return if len(self.playingRoomList) >= const.AGENT_ROOM_LIMIT: self.createRoomFailed(const.CREATE_FAILED_AGENT_ROOM_LIMIT) return self.req_entering_room = True def callback(content): 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 = switch.calc_cost( game_round, pay_mode) if not KBEngine.globalData[ "GameWorld"].free_play and card_cost > data[ "card"] and diamond_cost > data["diamond"]: self.createRoomFailed(const.CREATE_FAILED_NO_ENOUGH_CARDS) return # @formatter:off params = { 'owner_uid': self.userId, 'player_num': 4, 'lucky_poker': lucky_poker, 'game_round': game_round, 'pay_mode': pay_mode, 'hand_prepare': hand_prepare, 'room_type': room_type, } # @formatter:on KBEngine.createBaseAnywhere("GameRoom", params, self.createRoomCallback) except: err, msg, stack = sys.exc_info() DEBUG_MSG( "createRoom callback error:{} , exc_info: {} ,{}".format( content, err, msg)) self.createRoomFailed(const.CREATE_FAILED_OTHER) if switch.DEBUG_BASE or KBEngine.globalData["GameWorld"].isDailyActFree: callback('{"card":99, "diamond":9999}') else: utility.get_user_info(self.accountName, callback)
def createRoom(self, create_room_dict): DEBUG_MSG("create room, {}, {}".format(create_room_dict, self.req_entering_room)) game_round = create_room_dict['game_round'] game_mode = create_room_dict['game_mode'] player_num = create_room_dict['player_num'] hand_prepare = create_room_dict['hand_prepare'] op_seconds = create_room_dict['op_seconds'] room_type = create_room_dict['room_type'] pay_mode = create_room_dict['pay_mode'] max_boom_times = create_room_dict['max_boom_times'] if game_round not in const.GAME_ROUND \ or game_mode not in const.GAME_MODE \ or max_boom_times not in const.MAX_BOOM_TIMES \ or player_num != 3 \ or hand_prepare not in const.PREPARE_MODE \ or op_seconds not in const.OP_SECONDS \ or pay_mode not in (const.NORMAL_PAY_MODE, const.AA_PAY_MODE, const.AGENT_PAY_MODE) \ or room_type not in (const.NORMAL_ROOM, const.AGENT_ROOM): return if self.req_entering_room: return if self.isInRoom: self.createRoomFailed(const.CREATE_FAILED_ALREADY_IN_ROOM) return # 检查代开房上限 if room_type == const.AGENT_ROOM: if not self.isAgent: self.createRoomFailed(const.CREATE_FAILED_PERMISSION_DENIED) return if len(self.playingRoomList) >= const.AGENT_ROOM_LIMIT: self.createRoomFailed(const.CREATE_FAILED_AGENT_ROOM_LIMIT) return self.req_entering_room = True def callback(content): 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 = switch.calc_cost( game_round, { "game_mode": game_mode, "game_max_lose": 999999, 'pay_mode': pay_mode }) if not KBEngine.globalData[ "GameWorld"].free_play and card_cost > data[ "card"] and diamond_cost > data["diamond"]: self.createRoomFailed(const.CREATE_FAILED_NO_ENOUGH_CARDS) return params = { # 基本必填信息 'owner_uid': self.userId, 'player_num': player_num, # client 2 svr 'game_mode': game_mode, 'op_seconds': op_seconds, 'max_boom_times': max_boom_times, 'game_max_lose': 999999, 'game_round': game_round, 'hand_prepare': hand_prepare, 'pay_mode': pay_mode, 'room_type': room_type, } KBEngine.createBaseAnywhere("GameRoom", params, self.createRoomCallback) except: err, msg, stack = sys.exc_info() DEBUG_MSG( "createRoom callback error:{} , exc_info: {} ,{}".format( content, err, msg)) self.createRoomFailed(const.CREATE_FAILED_OTHER) if switch.DEBUG_BASE or KBEngine.globalData["GameWorld"].isDailyActFree: callback('{"card":99, "diamond":9999}') else: utility.get_user_info(self.accountName, callback)
def createRoom(self, create_room_dict): """ base_score: (1/2 2/4 3/6 ) ( 1/2/3/4 2/4/6/8 3/6/9/12 ) expand_cards: 特殊牌型 花牛×5 炸弹牛×6 五小牛×8 [poker_type,...] in ALL_POKER_TYPE mul_mode: 翻倍规则 牛牛×4 牛九×3 牛八×2 牛七×2 牛牛×3 牛九×2 牛八×2 10->0 [4,3,2] enter_mode: 中途加入 0:不允许 1:允许 """ DEBUG_MSG("create room, {}, {}".format(create_room_dict, self.req_entering_room)) base_score = tuple(create_room_dict['base_score']) game_round = create_room_dict['game_round'] game_mode = create_room_dict['game_mode'] expand_cards = create_room_dict['expand_cards'] mul_mode = create_room_dict['mul_mode'] enter_mode = create_room_dict['enter_mode'] player_num = create_room_dict['player_num'] hand_prepare = create_room_dict['hand_prepare'] op_seconds = create_room_dict['op_seconds'] room_type = create_room_dict['room_type'] pay_mode = create_room_dict['pay_mode'] if game_round not in const.GAME_ROUND \ or game_mode not in const.GAME_MODE \ or base_score not in const.BASE_SCORE[game_mode] \ or not (i in const.ALL_POKER_TYPE for i in expand_cards) \ or len(mul_mode) > 10 \ or enter_mode not in const.ENTERING_MODE \ or player_num not in const.ROOM_PLAYER_NUMBER_LIST \ or hand_prepare not in const.PREPARE_MODE \ or op_seconds not in const.OP_SECONDS \ or pay_mode not in (const.NORMAL_PAY_MODE, const.AA_PAY_MODE, const.AGENT_PAY_MODE) \ or room_type not in (const.NORMAL_ROOM, const.AGENT_ROOM): return if self.req_entering_room: return if self.isInRoom: self.createRoomFailed(const.CREATE_FAILED_ALREADY_IN_ROOM) return # 检查代开房上限 if room_type == const.AGENT_ROOM: if not self.isAgent: self.createRoomFailed(const.CREATE_FAILED_PERMISSION_DENIED) return if len(self.playingRoomList) >= const.AGENT_ROOM_LIMIT: self.createRoomFailed(const.CREATE_FAILED_AGENT_ROOM_LIMIT) return self.req_entering_room = True def callback(content): 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 = switch.calc_cost( game_round, { "game_mode": game_mode, "game_max_lose": 999999, 'pay_mode': pay_mode }) if not KBEngine.globalData[ "GameWorld"].free_play and card_cost > data[ "card"] and diamond_cost > data["diamond"]: self.createRoomFailed(const.CREATE_FAILED_NO_ENOUGH_CARDS) return params = { # 基本必填信息 'owner_uid': self.userId, 'player_num': player_num, # client 2 svr 'game_mode': game_mode, 'base_score': base_score, 'expand_cards': expand_cards, 'mul_mode': mul_mode, 'enter_mode': enter_mode, 'op_seconds': op_seconds, 'game_max_lose': 999999, 'game_round': game_round, 'hand_prepare': hand_prepare, 'pay_mode': pay_mode, 'room_type': room_type, } KBEngine.createBaseAnywhere("GameRoom", params, self.createRoomCallback) except: err, msg, stack = sys.exc_info() DEBUG_MSG( "createRoom callback error:{} , exc_info: {} ,{}".format( content, err, msg)) self.createRoomFailed(const.CREATE_FAILED_OTHER) if switch.DEBUG_BASE or KBEngine.globalData["GameWorld"].isDailyActFree: callback('{"card":99, "diamond":9999}') else: utility.get_user_info(self.accountName, callback)
def reqEnterRoom(self, avt_mb, first=False): """ defined. 客户端调用该接口请求进入房间/桌子 """ if self.isFull: avt_mb.enterRoomFailed(const.ENTER_FAILED_ROOM_FULL) return if self.room_type == const.CLUB_ROOM: if self.club and not self.club.isMember(avt_mb.userId): avt_mb.enterRoomFailed(const.ENTER_FAILED_NOT_CLUB_MEMBER) return def _check_user_info(content): if content is None: DEBUG_MSG("room:{0},curround:{1} userId:{2} enterRoomFailed callback error: content is None".format(self.roomID, self.current_round, avt_mb.userId)) if not first: avt_mb.enterRoomFailed(const.CREATE_FAILED_NET_SERVER_ERROR) return False try: data = json.loads(content) card_cost, diamond_cost = switch.calc_cost(self.game_round, self.getCalCostNeed()) if card_cost > data["card"]: avt_mb.enterRoomFailed(const.ENTER_FAILED_ROOM_DIAMOND_NOT_ENOUGH) return False except: err, msg, stack = sys.exc_info() DEBUG_MSG("room:{0},curround:{1} _check_user_info callback error:{2} , exc_info: {3} ,{4}".format(self.roomID, self.current_round, content, err, msg)) avt_mb.enterRoomFailed(const.CREATE_FAILED_OTHER) return False return True def callback(): if self.isDestroyed: avt_mb.enterRoomFailed(const.ENTER_FAILED_ROOM_DESTROYED) return # AA支付的情况下, 可能多个玩家同时走到这里 if self.isFull: avt_mb.enterRoomFailed(const.ENTER_FAILED_ROOM_FULL) return for i, p in enumerate(self.players_list): if p and p.mb and p.mb.userId == avt_mb.userId: p.mb = avt_mb avt_mb.enterRoomSucceed(self, i) return DEBUG_MSG("room:{0},curround:{1} userId:{2} reqEnterRoom".format(self.roomID, self.current_round, avt_mb.userId)) idx = self.getSit() # if idx is None: # avt_mb.enterRoomFailed(const.ENTER_FAILED_ROOM_FULL) # return n_player = PlayerProxy(avt_mb, self, idx) self.players_dict[avt_mb.userId] = n_player self.players_list[idx] = n_player # 茶楼座位信息变更 if self.club_table: self.club_table.seatInfoChanged() # 确认准备,不需要手动准备 if self.hand_prepare == const.AUTO_PREPARE: self.prepare(avt_mb) if not first: self.broadcastEnterRoom(idx) else: avt_mb.createRoomSucceed(self) self.ready_after_prepare() if switch.DEBUG_BASE: callback() else: if first or self.pay_mode != const.AA_PAY_MODE: callback() else: def _user_info_callback(content): if _check_user_info(content): callback() utility.get_user_info(avt_mb.accountName, _user_info_callback)