def on_join_table(self, gid, msg): ack = MsgPack(Message.MSG_SYS_JOIN_TABLE | Message.ID_ACK) tid = msg.get_param('tableId') self._info('player req to join table', tid) self.offline = False if self.tid > 0 and self.tid != tid: self.offline = True return ack.set_error(Enum.join_table_failed_multi) registry = Context.get_module(gid, 'registry') table = registry.create_table(gid, tid) if not table: self.offline = True return ack.set_error(Enum.join_table_failed_id) result = table.join_table(self.uid) if result != 0: self.offline = True return ack.set_error(result) self.table = table self.online_ts = Time.current_ts() sid = msg.get_param('seatId') if sid is not None: return self.on_sit_down(msg) return result
def onMessage(self, cmd, uid, gid, mi): if cmd == Message.MSG_INNER_TIMER: tid = mi.get_param('tableId') if tid: registry = Context.get_module(gid, 'registry') table = registry.get_table(tid) if table: with Context.GData.table_locker[tid]: table.onTimer(cmd, gid, mi) else: Context.Log.info(tid, 'table not exist', mi) else: Context.Log.info('miss table id', mi) else: registry = Context.get_module(gid, 'registry') player = registry.create_player(uid) if player: player.on_message(cmd, gid, mi) else: Context.Log.debug('no player found', mi)
def onInnerMessage(self, cmd, mi, *args, **kwargs): uid = mi.get_uid() gid = mi.get_gid() raw = mi.get_message() mi = MsgPack.unpack(cmd, raw) gid = mi.get_param('gameId', gid) game = Context.get_module(gid, 'game') with Context.GData.user_locker[uid]: if game: game.onMessage(cmd, uid, gid, mi) else: Context.Log.warn('no game found', mi)
def onInnerMessage(self, cmd, mi, *args, **kwargs): uid = mi.get_uid() gid = mi.get_gid() raw = mi.get_message() mi = MsgPack.unpack(cmd, raw) gid = mi.get_param('gameId', gid) quick = Context.get_module(gid, 'quick') with Context.GData.server_locker: if quick: quick.onMessage(cmd, uid, gid, mi) else: Context.Log.warn('error msg', cmd, mi)
def onGameInfo(self, uid, gid, mi): gid = mi.get_param('gameId') mo = MsgPack(Message.MSG_SYS_GAME_INFO | Message.ID_ACK) account = Context.get_module(gid, 'account', Account) is_new, data = account.get_game_info(uid, gid) if not data: mo.set_error(-1, 'no game info') else: mo.update_param(data) if is_new: mo.set_param('new', 1) info = Context.RedisCache.hash_mget('global.notice', 'led', 'start', 'end') led = info[0] if led: now_ts = Time.current_ts() start = int(info[1]) end = int(info[2]) if start < now_ts < end: mo.set_param('global_notice', { 'list': [led], 'end': end, 'now_ts': now_ts }) Context.GData.send_to_connect(uid, mo) if is_new: account.on_create_user(uid, gid) if account.auto_issue_benefit: benefit_config = Context.Configure.get_game_item_json( gid, 'benefit.config') if benefit_config and benefit_config['limit'] > data['chip']: benefit = Context.Daily.issue_benefit(uid, gid) mo = MsgPack(Message.MSG_SYS_BENEFIT | Message.ID_NTF) if not benefit: benefit = { 'which': 0, 'total': 0, 'reward': 0, 'chip': data['chip'], } mo.update_param(benefit) Context.GData.send_to_connect(uid, mo)
def kick_off_user(self, reason, kicked_uid, kicker_uid=None): evt = [{ 'type': Enum.table_event_kick_off, 'userId': kicked_uid, 'reason': reason, }] if kicker_uid and kicker_uid > 0: evt[0]['kicker'] = kicker_uid self.notify_event(evt) registry = Context.get_module(self.gid, 'registry') player = registry.get_player(kicked_uid) if player: player.leave_table() return 0
def onUserInfo(self, uid, gid, mi): mo = MsgPack(Message.MSG_SYS_USER_INFO | Message.ID_ACK) account = Context.get_module(gid, 'account', Account) data = account.get_user_info(uid, gid) if not data: mo.set_error(-1, 'no user info') else: mo.update_param(data) login = mi.get_param('login') if login: account.on_user_login(uid, gid) result, loc = Online.get_location(uid, gid) if result and loc: loc = { 'roomType': loc['room_type'], 'tableId': loc['table_id'], 'seatId': loc['seat_id'] } mo.set_param('loc', loc) return Context.GData.send_to_connect(uid, mo)
def onInnerMessage(self, cmd, mi, *args, **kwargs): uid = mi.get_uid() gid = mi.get_gid() raw = mi.get_message() mi = MsgPack.unpack(cmd, raw) gid = mi.get_param('gameId', gid) with Context.GData.user_locker[uid]: if cmd == Message.MSG_SYS_USER_INFO | Message.ID_REQ: self.onUserInfo(uid, gid, mi) elif cmd == Message.MSG_SYS_GAME_INFO | Message.ID_REQ: self.onGameInfo(uid, gid, mi) elif cmd == Message.MSG_SYS_SERVER_INFO | Message.ID_REQ: self.onServerInfo(uid, gid, mi) elif cmd == Message.MSG_SYS_LED | Message.ID_REQ: self.onLed(uid, gid, mi) else: entity = Context.get_module(gid, 'entity') if entity: entity.onMessage(cmd, uid, gid, mi) else: Context.Log.warn('error msg', cmd, mi)