def doSendLedToUser(userId): gameIdList = onlinedata.getGameEnterIds(userId) if not gameIdList: return clientId = sessiondata.getClientId(userId) _, clientVer, _ = strutil.parseClientId(clientId) for gameId in gameIdList: try: leds = getLedMsgList(gameId) if ftlog.is_debug(): ftlog.debug('hallled.doSendLedToUser gameId=', gameId, 'gameId=', gameId, 'userId=', userId, 'clientId=', clientId, 'leds=', leds) if leds: msgDict = leds[0][2] if clientVer >= 3.6: mo = MsgPack() mo.setCmd('led') for k, v in msgDict.iteritems(): mo.setResult(k, v) else: mo = MsgPack() mo.setCmd('led') if gameId in (1, 8): msgDictV2 = translateToMsgDictV2(msgDict) if msgDictV2: mo.setKey('richText', msgDictV2.get('richText')) msgV1 = translateToMsgDictV1(msgDict) if msgV1: gameId = msgDict.get('gameId', leds[0][1]) mo.setKey('result', [[leds[0][0], gameId, msgV1]]) router.sendToUser(mo, userId) except: ftlog.error()
def doSendLedToUser(userId): global _ledClosesConf gameIdList = onlinedata.getGameEnterIds(userId) lastGameId = onlinedata.getLastGameId(userId) if not HALL_GAMEID in gameIdList: gameIdList.append(HALL_GAMEID) if not lastGameId in gameIdList: gameIdList.append(lastGameId) clientId = sessiondata.getClientId(userId) gameIdInClientId = strutil.getGameIdFromHallClientId(clientId) if not gameIdInClientId in gameIdList: gameIdList.append(gameIdInClientId) if ftlog.is_debug(): ftlog.debug('hallled.doSendLedToUser userId=', userId, 'gameIdList=', gameIdList, 'clientId=', clientId, 'gameIdInClientId=', gameIdInClientId, 'lastGameId=', lastGameId) _, clientVer, _ = strutil.parseClientId(clientId) for gameId in gameIdList: try: leds = getLedMsgList(gameId) if ftlog.is_debug(): ftlog.debug('hallled.doSendLedToUser gameId=', gameId, 'userId=', userId, 'clientId=', clientId, 'leds=', leds) if leds: for led in leds: if canSendToUser(userId, clientId, led): msgDict = led[2] if clientVer >= 3.6: mo = MsgPack() mo.setCmd('led') for k, v in msgDict.iteritems(): mo.setResult(k, v) mo.setResult('scope', led[3]) else: mo = MsgPack() mo.setCmd('led') if gameId in (1, 8): msgDictV2 = translateToMsgDictV2(msgDict) if msgDictV2: mo.setKey('richText', msgDictV2.get('richText')) msgV1 = translateToMsgDictV1(msgDict) if msgV1: gameId = msgDict.get('gameId', led[1]) mo.setKey('result', [[led[0], gameId, msgV1]]) router.sendToUser(mo, userId) except: ftlog.error("error leds:", leds)
def _handlerRpcCommand(markParams, msg): handler = markParams['handler'] fun_method = markParams['fun_method'] argl = msg.getParam('argl') argd = msg.getParam('argd') ret = fun_method(handler, *argl, **argd) if markParams['syncCall']: mo = MsgPack() mo.setKey('result', ret) router.responseQurery(mo, 'QR')
def updateMsg(msg=None, cmd=None, params=None, result=None): if not msg: msg = MsgPack() if cmd: msg.setCmd(cmd) if params is not None: msg.setKey('params', params) if result is not None: msg.setKey('result', result) return msg
def make_led_mo(newleds, clientVer, clientId): mo = MsgPack() mo.setCmd('led') if clientVer >= 3.6: if ledWithTodoTask: mo.setKey('result', ledWithTodoTask) return mo.pack() return None if newleds['origLeds']: mo.setKey('result', newleds['origLeds']) if newleds['richLeds']: mo.setKey('result', newleds['richLeds']) mo.setKey('richText', newleds['richLeds']) mo.setResult('gameId', gameId) if gameId == 8: if clientVer < 3.0: # 德州老单包有问题,所有格式都转为没有按钮的LED (也就是type='led') newleds['richLeds']['type'] = 'led' elif newleds['richLeds'][ 'type'] == 'vip' and clientVer == 3.37 and 'hall8' in clientId: # 德州大厅3.37版本BUG: 如果消息中有 richText,则收不到消息 mo.rmKey('richText') if popWinInfo and clientId.startswith('Winpc'): mo.setResult('popWin', popWinInfo) return mo.pack()
def _notifyUserOnlineStatus(user, isOnline): ''' 发送用户的上下线通知到UTIL服务 ''' mo = MsgPack() mo.setCmd('user') mo.setParam('userId', user.userId) mo.setParam('clientId', user.clientId) mo.setKey('clientId', user.clientId) if isOnline: mo.setParam('action', 'online') else: mo.setParam('action', 'offline') router.sendUtilServer(mo, user.userId) userdata.updateUserDataAliveTime(user.userId) # 用户上下线的同时, 更新用户的数据时间
def makeLedMsg(gameId, msgDict, scope, clientVer): if clientVer >= 3.6: mo = MsgPack() mo.setCmd('led') for k, v in msgDict.iteritems(): mo.setResult(k, v) mo.setResult('scope', scope) else: mo = MsgPack() mo.setCmd('led') if gameId in (1, 8): msgDictV2 = translateToMsgDictV2(msgDict) if msgDictV2: mo.setKey('richText', msgDictV2.get('richText')) msgV1 = translateToMsgDictV1(msgDict) if msgV1: gameId = msgDict.get('gameId', gameId) mo.setKey('result', [[0, gameId, msgV1]]) return mo
def updateMsg(cls, msg=None, cmd=None, params=None, result=None, **other): if not msg: msg = MsgPack() if cmd: msg.setCmd(cmd) if params is not None: msg.setKey('params', params) if result is not None: msg.setKey('result', result) for k, v in other.items(): msg.setKey(k, v) return msg
def doSendLedToUser(userId): global _ledClosesConf gameIdList = onlinedata.getGameEnterIds(userId) lastGameId = onlinedata.getLastGameId(userId) if not HALL_GAMEID in gameIdList: gameIdList.append(HALL_GAMEID) if not lastGameId in gameIdList: gameIdList.append(lastGameId) clientId = sessiondata.getClientId(userId) if clientId in _ledClosesConf: if ftlog.is_debug(): ftlog.debug('hallled.doSendLedToUser clientId:', clientId, ' is in closes list:', _ledClosesConf, ' return') return gameIdInClientId = strutil.getGameIdFromHallClientId(clientId) if not gameIdInClientId in gameIdList: gameIdList.append(gameIdInClientId) if ftlog.is_debug(): ftlog.debug('hallled.doSendLedToUser userId=', userId, 'gameIdList=', gameIdList, 'clientId=', clientId, 'gameIdInClientId=', gameIdInClientId, 'lastGameId=', lastGameId) _, clientVer, _ = strutil.parseClientId(clientId) for gameId in gameIdList: try: leds = getLedMsgList(gameId) if ftlog.is_debug(): ftlog.debug('hallled.doSendLedToUser gameId=', gameId, 'userId=', userId, 'clientId=', clientId, 'leds=', leds) if leds: for led in leds: msgDict = led[2] if clientVer >= 3.6: mo = MsgPack() mo.setCmd('led') for k, v in msgDict.iteritems(): mo.setResult(k, v) mo.setResult('scope', led[3]) else: mo = MsgPack() mo.setCmd('led') if gameId in (1, 8): msgDictV2 = translateToMsgDictV2(msgDict) if msgDictV2: mo.setKey('richText', msgDictV2.get('richText')) msgV1 = translateToMsgDictV1(msgDict) if msgV1: gameId = msgDict.get('gameId', led[1]) mo.setKey('result', [[led[0], gameId, msgV1]]) # 过滤LED clientIdFilter = led[4] if len(clientIdFilter) == 0 or clientId in clientIdFilter: if ftlog.is_debug(): ftlog.debug('sendLed to user='******'msg=', mo) router.sendToUser(mo, userId) except: ftlog.error("error leds:", leds)
def sendGameLed(cls, msgPackIn): ''' ''' if not LED_ON: ftlog.debug("<< not LED_ON") return if ftlog.is_debug(): ftlog.debug("<< |msgPackIn:", msgPackIn, caller=cls) gameId = msgPackIn.getResult('gameId', 0) if gameId <= 0: ftlog.warn("gameId <=0", gameId, caller=cls) return ledWithTodoTask = msgPackIn.getResult('ledWithTodoTask') if not ledWithTodoTask: ftlog.warn("ledWithTodoTask is None!", caller=cls) return ledMsg = MsgPack() ledMsg.setCmd('led') ledMsg.setKey('result', ledWithTodoTask) receivers = msgPackIn.getResult('receivers') if not receivers: ftlog.warn("receivers is None!", caller=cls) return excludeUsers = msgPackIn.getResult('excludeUsers', set()) force = msgPackIn.getResult('force', []) # 这里指定的用户不能过滤,必须收 # receivers = receivers + force timelimit = msgPackIn.getResult('timelimit', {}) intervals = timelimit.get('timeLimitIntervals') # 这个时间内收过led的不再收 limitName = timelimit.get('timeLimitName') # 时间间隔的种类,反射机制设置到 user 对象中去 sendLedCount = [0] # 为了控制每次发送的led数量,使用list类型是为了在闭包里能修改此值 def sendled(): clientVer = sessiondata.getClientIdVer(userId) if clientVer < 3.6: return if sendLedCount[0] <= SEND_COUNT_LIMIT: sendLedCount[0] += 1 if ftlog.is_debug(): ftlog.debug("|send led count:", sendLedCount, caller=cls) if sendLedCount[0] % 10 == 0: if ftlog.is_debug(): ftlog.info("|send led count:", sendLedCount, caller=cls) onlines.notifyUsers(ledMsg.pack(), [userId]) # 需求:两次同类型led之间需要相隔intervals now = time.time() if ftlog.is_debug(): ftlog.info("|len of receivers:", len(receivers), caller=cls) for userId in receivers: if userId in force: if limitName: gamedata.setGameAttr(userId, gameId, limitName, now) sendled() continue if userId not in excludeUsers: if limitName and intervals: # 时间限制 lastSendTime = gamedata.getGameAttr( userId, gameId, limitName) if not lastSendTime: lastSendTime = 0 if ftlog.is_debug(): ftlog.debug( '|userId, limitName, intervals, lastSendTime, now:', userId, limitName, intervals, lastSendTime, now, caller=cls) if lastSendTime + intervals <= now: gamedata.setGameAttr(userId, gameId, limitName, now) sendled() else: sendled()