예제 #1
0
파일: todotask.py 프로젝트: zhaozw/mjserver
def sendTodoTaskInviteFriends(userId, gameId, invite_uids, play_mode, roomId,
                              tableId, info_str, purl):
    """ 邀请好友来牌桌
    @param        name        发送邀请的用户名
    @param        invite_uids 被邀请的玩家uid列表
    @param        table       牌桌对象
    """
    ftlog.debug('userId =', userId, 'roomId =', roomId, 'tableId =', tableId,
                'invite_uids =', invite_uids, 'info_str =', info_str)
    if not TYPlayer.isHuman(userId):
        ftlog.debug('robot is not supported!')
        return

    for uid in invite_uids:
        last_gameId = onlinedata.getLastGameId(uid)
        if last_gameId == gameId:  # 如果玩家在麻将里
            sendFriendInviteTodotask(uid, userId, gameId, play_mode, roomId,
                                     tableId, info_str, purl)
        elif last_gameId == 9999:  # 如果玩家在大厅主界面
            sendFriendInviteEnterGameTodotask(uid, gameId, play_mode, roomId,
                                              tableId, info_str)
        else:  # 在其它游戏里,直接忽略
            ftlog.debug('last_gameId is not 7 or 9999', 'last_gameId =',
                        last_gameId)
            return
        from majiang2.entity import util
        util.sendPrivateMessage(uid, info_str)
예제 #2
0
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)
예제 #3
0
def pushNotify(userId, gameId, clientId):
    '''玩家自己push消息'''
    # cmd='user', action='heart_beat' 6s client req once but real 30s
    gameId = onlinedata.getLastGameId(userId)
    if ftlog.is_debug():
        ftlog.debug('hallnewnotify pushNotify', userId, gameId, clientId)

    global notify_today_list, _pushed
    if ftlog.is_debug():
        ftlog.debug('hallnewnotify.pushNotify', userId, gameId, clientId,
                    notify_today_list, _pushed)
    if _pushed is False:
        ftlog.hinfo('hallnewnotify.pushNotify is in cannot push time', userId,
                    gameId, clientId)
        return

    upNotifyTodayList()

    length = len(notify_today_list)
    if length == 0:
        ftlog.hinfo('hallnewnotify.notifytodaylist is empty', userId, gameId,
                    clientId)
        return

    todaynotifylist = gamedata.getGameAttr(userId, HALL_GAMEID,
                                           'todaynotifylist')
    if not todaynotifylist:
        todaynotifylist = []
    else:
        todaynotifylist = json.loads(todaynotifylist)
    clientSys, _, _ = strutil.parseClientId(clientId)
    if ftlog.is_debug():
        ftlog.hinfo('hallnewnotify.pushNotify todaynotifylist:', userId,
                    gameId, clientId, todaynotifylist)

    todaykeyList = notify_today_list.keys()
    for uuid in todaykeyList:
        notifyIns = notify_today_list[uuid]
        if ftlog.is_debug():
            ftlog.hinfo('hallnewnotify.pushNotify.loop notifyIns', uuid,
                        userId, notifyIns.alive, notifyIns.uuid,
                        todaynotifylist, notifyIns.uuid not in todaynotifylist)
        if notifyIns.alive:
            if notifyIns.uuid not in todaynotifylist:
                notifyIns.pushNotify(userId, gameId, clientId, clientSys)
                todaynotifylist.append(notifyIns.uuid)
    gamedata.setGameAttr(userId, HALL_GAMEID, 'todaynotifylist',
                         json.dumps(todaynotifylist))
예제 #4
0
def doSendLedToUser(userId):
    """
    发送LED消息给玩家(由客户端心跳消息触发,大概15s一次)
    """
    from newfish.entity import util
    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)
    lang = util.getLanguage(userId, clientId)
    if ftlog.is_debug():
        ftlog.debug("led.doSendLedToUser userId=", userId, "gameIdList=",
                    gameIdList, "clientId=", clientId, "gameIdInClientId=",
                    gameIdInClientId, "lastGameId=", lastGameId)
    for gameId in gameIdList:
        try:
            leds = getLedMsgList(gameId)
            if ftlog.is_debug():
                ftlog.debug("led.doSendLedToUser gameId=", gameId, "userId=",
                            userId, "clientId=", clientId, "leds=", leds)
            if leds:
                for led in leds:
                    if canSendToUser(userId, clientId, led, lang):
                        msgDict = led[2]
                        mo = MsgPack()
                        mo.setCmd("led")
                        for k, v in msgDict.iteritems():
                            mo.setResult(k, v)
                        mo.setResult("scope", led[3])
                        router.sendToUser(mo, userId)
        except:
            ftlog.error("error leds:", leds)
예제 #5
0
파일: todotask.py 프로젝트: zhaozw/mjserver
def sendTodoTaskInviteFriends(userId, gameId, invite_uids, play_mode, roomId, tableId, info_str, purl):
    """ 邀请好友来牌桌
    @param        name        发送邀请的用户名
    @param        invite_uids 被邀请的玩家uid列表
    @param        table       牌桌对象
    """
    ftlog.debug('userId =', userId, 'roomId =', roomId, 'tableId =', tableId,
                'invite_uids =', invite_uids, 'info_str =', info_str)
    if not TYPlayer.isHuman(userId):
        ftlog.debug('robot is not supported!')
        return

    for uid in invite_uids:
        last_gameId = onlinedata.getLastGameId(uid)
        if last_gameId == gameId:     # 如果玩家在麻将里
            sendFriendInviteTodotask(uid, userId, gameId, play_mode, roomId, tableId, info_str, purl)
        elif last_gameId == 9999:                       # 如果玩家在大厅主界面
            sendFriendInviteEnterGameTodotask(uid, gameId, play_mode, roomId, tableId, info_str)
        else:                                           # 在其它游戏里,直接忽略
            ftlog.debug('last_gameId is not 7 or 9999', 'last_gameId =', last_gameId)
            return
        from majiang2.entity import util
        util.sendPrivateMessage(uid, info_str)
예제 #6
0
파일: hallled.py 프로젝트: zhaozw/hall37
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)