Esempio n. 1
0
        def update_portrait(self, pl):
            def players():
                return {p.account.username for p in self.portraits if p.account}

            orig_players = players()
            full = True

            for i, p in enumerate(pl):
                accdata = p["account"]
                acc = Account.parse(accdata) if accdata else None
                if not accdata:
                    full = False

                port = self.portraits[i]
                port.account = acc
                port.ready = p["state"] == "ready"

                port.update()

            curr_players = players()

            for player in orig_players - curr_players:
                self.parent.chat_box.append(u"|B|R>> |r玩家|c0000ffff|B%s|r已离开游戏\n" % player)

            for player in curr_players - orig_players:
                self.parent.chat_box.append(u"|B|R>> |r玩家|c0000ffff|B%s|r已进入游戏\n" % player)

            if not self.ready and full and orig_players != curr_players:
                from utils import notify

                notify(u"东方符斗祭 - 满员提醒", u"房间已满员,请准备。")
Esempio n. 2
0
def handle_chat(_type, args):
    if _type == 'chat_msg':
        uname, msg = args[0]
        uname = uname.replace('|', '||')
        return u'|cff0000ff%s|r: %s\n' % (uname, msg)

    elif _type == 'ob_msg':
        uname, msg = args[0]
        uname = uname.replace('|', '||')
        return u'|c9f5f9fff%s|r: %s\n' % (uname, msg)

    elif _type == 'speaker_msg':
        node, uname, msg = args[0]
        from utils.notify import notify, SPEAKER
        notify(u'东方符斗祭 - 『文々。新闻』',
               u'%s: %s' % (uname, msg), level=SPEAKER)
        node = node and '|G%s' % ServerNames.get(node, node)
        uname = uname.replace('|', '||')
        return u'%s|ccc3299ff『文々。新闻』|cff0000ff%s|r: %s\n' % (node, uname, msg)

    elif _type == 'system_msg':
        _, msg = args[0]
        return u'|B|R%s|r\n' % msg

    else:
        return None
Esempio n. 3
0
    def on_message(self, _type, *args):
        if _type == "server_dropped":
            ConfirmBox(u"已经与服务器断开链接,请重新启动游戏!", parent=Screen.cur_overlay)

        elif _type == "invite_request":
            uid, uname, gid, gtype = args[0]
            from gamepack import gamemodes as modes

            gtype = modes.get(gtype, None)
            gtype = gtype and gtype.ui_meta.name

            invite_text = u"%s 邀请你一起玩 %s 模式" % (uname, gtype)

            from utils import notify

            notify(u"东方符斗祭 - 邀请提醒", invite_text)

            box = ConfirmBox(invite_text, parent=self, buttons=((u"确定", True), (u"取消", False)), default=False)

            @box.event
            def on_confirm(val, uid=uid):
                Executive.call("invite_grant", ui_message, [gid, val])

        else:
            Overlay.on_message(self, _type, *args)
Esempio n. 4
0
def handle_chat(_type, args):
    if _type == "chat_msg":
        uname, msg = args[0]
        uname = uname.replace("|", "||")
        return u"|cff0000ff%s|r: %s\n" % (uname, msg)

    elif _type == "ob_msg":
        uname, msg = args[0]
        uname = uname.replace("|", "||")
        return u"|c9f5f9fff%s|r: %s\n" % (uname, msg)

    elif _type == "speaker_msg":
        node, uname, msg = args[0]
        from utils.notify import notify, SPEAKER

        notify(u"东方符斗祭 - 『文々。新闻』", u"%s: %s" % (uname, msg), level=SPEAKER)
        node = node and "|G%s" % ServerNames.get(node, node)
        uname = uname.replace("|", "||")
        return u"%s|ccc3299ff『文々。新闻』|cff0000ff%s|r: %s\n" % (node, uname, msg)

    elif _type == "system_msg":
        _, msg = args[0]
        return u"|B|R%s|r\n" % msg

    else:
        return None
Esempio n. 5
0
def handle_chat(_type, args):
    if _type == 'chat_msg':
        uname, msg = args[0]
        uname = uname.replace('|', '||')
        return u'|cff0000ff%s|r: %s\n' % (uname, msg)

    elif _type == 'ob_msg':
        uname, msg = args[0]
        uname = uname.replace('|', '||')
        return u'|c9f5f9fff%s|r: %s\n' % (uname, msg)

    elif _type == 'speaker_msg':
        node, uname, msg = args[0]
        from utils.notify import notify, SPEAKER
        notify(u'东方符斗祭 - 『文々。新闻』',
               u'%s: %s' % (uname, msg), level=SPEAKER)
        node = node and '|G%s' % ServerNames.get(node, node)
        uname = uname.replace('|', '||')
        return u'%s|ccc3299ff『文々。新闻』|cff0000ff%s|r: %s\n' % (node, uname, msg)

    elif _type == 'system_msg':
        _, msg = args[0]
        return u'|B|R%s|r\n' % msg

    else:
        return None
Esempio n. 6
0
    def on_message(self, _type, *args):
        if _type == 'server_dropped':
            ConfirmBox(u'已经与服务器断开链接,请重新启动游戏!', parent=Screen.cur_overlay)

        elif _type == 'invite_request':
            uid, uname, gid, gtype = args[0]
            from gamepack import gamemodes as modes

            gtype = modes.get(gtype, None)
            gtype = gtype and gtype.ui_meta.name

            invite_text = u'%s 邀请你一起玩 %s 模式' % (uname, gtype)

            from utils import notify
            notify(u'东方符斗祭 - 邀请提醒', invite_text)

            box = ConfirmBox(
                invite_text,
                parent=self, buttons=((u'确定', True), (u'取消', False)), default=False
            )

            @box.event
            def on_confirm(val, uid=uid):
                Executive.call('invite_grant', ui_message, [gid, val])

        else:
            Overlay.on_message(self, _type, *args)
Esempio n. 7
0
def main(argv):
    if len(argv) >= 1:
        util = argv[0]
        
        if util == "notify":
            print "processando utilitário..."
            notify()
            print "fim do processamento..."
        #elif util == "***"
        else:
            print_usage()
    else:
        print_usage()
Esempio n. 8
0
async def check_cookies():
    """
    检查配置中的cookies是否已过期, 过期则发送通知
    :return:
    """
    println('开始检查账号cookies状态, 共{}个!'.format(len(JD_COOKIES)))
    title = '\n======📣【过期cookies列表】📣======\n'
    message = ''
    need_notify = False
    for cookies in JD_COOKIES:
        account = unquote(cookies['pt_pin'])
        ok = await async_check_cookie(cookies)
        if not ok:
            message += ' ' * 6 + account + '\n'
            println('{}, cookies已过期!'.format(account))
            need_notify = True
        else:
            println('{}, cookies正常!'.format(account))
    if need_notify:
        notify(title=title, content=message)
Esempio n. 9
0
        def update_portrait(self, pl):
            def players():
                return {
                    p.account.username
                    for p in self.portraits
                    if p.account
                }

            orig_players = players()
            full = True

            for i, p in enumerate(pl):
                accdata = p['account']
                acc = Account.parse(accdata) if accdata else None
                if not accdata: full = False

                port = self.portraits[i]
                port.account = acc
                port.ready = (p['state'] == 'ready')

                port.update()

            curr_players = players()

            for player in (orig_players - curr_players):
                self.parent.chat_box.append(
                    u'|B|R>> |r玩家|c0000ffff|B%s|r已离开游戏\n' % player
                )

            for player in (curr_players - orig_players):
                self.parent.chat_box.append(
                    u'|B|R>> |r玩家|c0000ffff|B%s|r已进入游戏\n' % player
                )

            if not self.ready and full and orig_players != curr_players:
                from utils import notify
                notify(u'东方符斗祭 - 满员提醒', u'房间已满员,请准备。')
Esempio n. 10
0
        def update_portrait(self, pl):
            def players():
                return {
                    p.account.username
                    for p in self.portraits
                    if p.account
                }

            orig_players = players()
            full = True

            for i, p in enumerate(pl):
                accdata = p['account']
                acc = Account.parse(accdata) if accdata else None
                if not accdata: full = False

                port = self.portraits[i]
                port.account = acc
                port.ready = (p['state'] == 'ready')

                port.update()

            curr_players = players()

            for player in (orig_players - curr_players):
                self.parent.chat_box.append(
                    u'|B|R>> |r玩家|c0000ffff|B%s|r已离开游戏\n' % player
                )

            for player in (curr_players - orig_players):
                self.parent.chat_box.append(
                    u'|B|R>> |r玩家|c0000ffff|B%s|r已进入游戏\n' % player
                )

            if not self.ready and full and orig_players != curr_players:
                from utils import notify
                notify(u'东方符斗祭 - 满员提醒', u'房间已满员,请准备。')
Esempio n. 11
0
    def on_message(self, _type, *args):
        rst = handle_chat(_type, args)
        if rst:
            self.chat_box.append(rst)
            return

        elif _type == 'game_started':
            from utils import notify
            notify(u'东方符斗祭 - 游戏提醒', u'游戏已开始,请注意。')
            self.remove_control(self.panel)
            self.gameui.init()
            self.add_control(self.gameui)
            self.game.start()

        elif _type == 'end_game':
            self.remove_control(self.gameui)
            self.add_control(self.panel)
            g = args[0]

        elif _type == 'client_game_finished':
            g = args[0]
            g.ui_meta.ui_class.show_result(g)

        elif _type in ('game_left', 'fleed'):
            GameHallScreen().switch()

        elif _type == 'game_joined':
            # last game ended, this is the auto
            # created game
            self.game = args[0]
            self.panel.btn_getready.state = Button.NORMAL
            self.gameui = self.ui_class(
                parent=False, game=self.game,
                **r2d((0, 0, 820, 720))
            )
            SoundManager.switch_bgm(common_res.bgm_hall)
            self.backdrop = common_res.bg_ingame
            self.set_color(Colors.green)
            self.events_box.clear()

        elif _type == 'game_crashed':
            ConfirmBox(
                u'游戏逻辑已经崩溃,请退出房间!\n'
                u'这是不正常的状态,你可以报告bug。\n'
                u'游戏ID:%d' % self.game.gameid,
                parent=self
            )
            from __main__ import do_crashreport
            do_crashreport()

        elif _type == 'observe_request':
            uid, uname = args[0]
            box = ConfirmBox(
                u'玩家 %s 希望旁观你的游戏,是否允许?\n'
                u'旁观玩家可以看到你的手牌。' % uname,
                parent=self, buttons=((u'允许', True), (u'不允许', False)), default=False
            )

            @box.event
            def on_confirm(val, uid=uid):
                Executive.call('observe_grant', ui_message, [uid, val])

        elif _type == 'observer_enter':
            obuid, obname, uname = args[0]
            self.chat_box.append(
                u'|B|R>> |r|c0000ffff%s|r[|c9100ffff%d|r]|r趴在了|c0000ffff%s|r身后\n' % (obname, obuid, uname)
            )

        elif _type == 'observer_leave':
            obuid, obname, uname = args[0]
            self.chat_box.append(
                u'|B|R>> |r|c0000ffff%s|r飘走了\n' % obname
            )

        else:
            Screen.on_message(self, _type, *args)
Esempio n. 12
0
def process_start(scripts_cls, name='', process_num=None, help=True, code_key=None):
    """
    从配置中读取JD_COOKIES,开启多进程执行func。
    :param code_key:
    :param help:
    :param scripts_cls: 脚本类
    :param process_num: 进程数量
    :param name: 活动名称
    :return:
    """
    multiprocessing.freeze_support()
    process_count = multiprocessing.cpu_count()

    if process_count < PROCESS_NUM:
        process_count = PROCESS_NUM

    if process_count > len(JD_COOKIES):
        process_count = len(JD_COOKIES)

    if process_num:
        process_count = process_num

    if process_count < 1:
        println('未配置jd_cookie, 脚本无法运行, 请在conf/config.yaml中配置jd_cookie!')
        return

    pool = multiprocessing.Pool(process_count)  # 进程池
    process_list = []  # 进程列表

    println("开始执行{}, 共{}个账号, 启动{}个进程!\n".format(name, len(JD_COOKIES), process_count), style='bold green')

    kwargs_list = []

    for i in range(len(JD_COOKIES)):
        jd_cookie = JD_COOKIES[i]

        account = jd_cookie.pop('remark')
        if not account:
            account = unquote(jd_cookie['pt_pin'])

        if jd_cookie.get('ws_key'):  # 使用ws_key
            jd_cookie['pt_key'] = ws_key_to_pt_key(jd_cookie.get('pt_pin'), jd_cookie.get('ws_key'))
            if not jd_cookie['pt_key']:
                println('{}.账号:{}, ws_key已过期, 无法执行'.format(i+1, account, name))
                continue
        else:
            ok = sync_check_cookie(jd_cookie)
            if not ok:  # 检查cookies状态, 这里不通知, 有定时任务会通知cookies过期!
                println('{}.账号:{}, cookie已过期, 无法执行:{}!'.format(i+1, account, name))
                continue
        kwargs = {
            'name': name,
            'sort': i,   # 排序, 影响助力码顺序
            'account': account
        }
        kwargs.update(jd_cookie)
        kwargs_list.append(kwargs)
        process = pool.apply_async(start, args=(scripts_cls, ), kwds=kwargs)
        process_list.append(process)

    pool.close()
    pool.join()  # 等待进程结束

    notify_message = ''   # 消息通知内容

    for process in process_list:   # 获取通知
        try:
            message = process.get()
        except Exception as e:
            logger.error(e.args)
            continue
        if not message:
            continue
        notify_message += message + '\n'

    if code_key:
        timeout = random.random() * 10
        println('正在提交助力码, 随机等待{}秒!'.format(timeout))
        time.sleep(timeout)
        if type(code_key) == list:
            for key in code_key:
                post_code_list(key)
                time.sleep(random.random())
        else:
            post_code_list(code_key)

    if hasattr(scripts_cls, 'run_help') and help:
        pool = multiprocessing.Pool(process_count)  # 进程池
        for kwargs in kwargs_list:
            pool.apply_async(start_help, args=(scripts_cls,), kwds=kwargs)

        pool.close()
        pool.join()  # 等待进程结束

    if notify_message != '':
        title = '\n======📣{}📣======\n'.format(name)
        notify(title, notify_message)

    println('\n所有账号均执行完{}, 退出程序\n'.format(name))
Esempio n. 13
0
    def on_message(self, _type, *args):
        rst = handle_chat(_type, args)
        if rst:
            self.chat_box.append(rst)
            return

        elif _type == 'game_started':
            from utils import notify
            notify(u'东方符斗祭 - 游戏提醒', u'游戏已开始,请注意。')
            self.remove_control(self.panel)
            self.add_control(self.gameui)
            self.gameui.init()
            self.game.start()

        elif _type == 'end_game':
            self.remove_control(self.gameui)
            self.add_control(self.panel)
            g = args[0]

        elif _type == 'client_game_finished':
            g = args[0]
            g.ui_meta.ui_class.show_result(g)

        elif _type in ('game_left', 'fleed'):
            GameHallScreen().switch()

        elif _type == 'game_joined':
            # last game ended, this is the auto
            # created game
            self.game = args[0]
            self.panel.btn_getready.state = Button.NORMAL
            self.gameui = self.ui_class(
                parent=False, game=self.game,
                **r2d((0, 0, 820, 720))
            )
            SoundManager.switch_bgm(common_res.bgm_hall)
            self.backdrop = common_res.bg_ingame.get()
            self.set_color(Colors.green)
            self.events_box.clear()

        elif _type == 'game_crashed':
            ConfirmBox(
                u'游戏逻辑已经崩溃,请退出房间!\n'
                u'这是不正常的状态,你可以报告bug。\n'
                u'游戏ID:%d' % self.game.gameid,
                parent=self
            )
            from __main__ import do_crashreport
            do_crashreport()

        elif _type == 'observe_request':
            uid, uname = args[0]
            box = ConfirmBox(
                u'玩家 %s 希望旁观你的游戏,是否允许?\n'
                u'旁观玩家可以看到你的手牌。' % uname,
                parent=self, buttons=((u'允许', True), (u'不允许', False)), default=False
            )

            @box.event
            def on_confirm(val, uid=uid):
                Executive.call('observe_grant', ui_message, [uid, val])

        elif _type == 'observer_enter':
            obuid, obname, uname = args[0]
            self.chat_box.append(
                u'|B|R>> |r|c0000ffff%s|r[|c9100ffff%d|r]|r趴在了|c0000ffff%s|r身后\n' % (obname, obuid, uname)
            )

        elif _type == 'observer_leave':
            obuid, obname, uname = args[0]
            self.chat_box.append(
                u'|B|R>> |r|c0000ffff%s|r飘走了\n' % obname
            )

        else:
            Screen.on_message(self, _type, *args)