From c21b723421c0c7f98da1c574829205fa59da18f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A4=E9=95=87=E5=A4=A9?= Date: Mon, 13 Apr 2020 22:31:35 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/ServerHelper/server_helper.py | 0 plugins/ServerReload/SeverReload-v0.3.2.py | 106 ----------------- plugins/Whitelist/Whitelist-v0.2.2.py | 126 --------------------- 3 files changed, 232 deletions(-) delete mode 100644 plugins/ServerHelper/server_helper.py delete mode 100644 plugins/ServerReload/SeverReload-v0.3.2.py delete mode 100644 plugins/Whitelist/Whitelist-v0.2.2.py diff --git a/plugins/ServerHelper/server_helper.py b/plugins/ServerHelper/server_helper.py deleted file mode 100644 index e69de29..0000000 diff --git a/plugins/ServerReload/SeverReload-v0.3.2.py b/plugins/ServerReload/SeverReload-v0.3.2.py deleted file mode 100644 index 0ae9d7a..0000000 --- a/plugins/ServerReload/SeverReload-v0.3.2.py +++ /dev/null @@ -1,106 +0,0 @@ -# -*- coding: utf-8 -*- -# Version 0.3.2 -import time -global RESTART_ABORTED -RESTART_ABORTED=False - -global IN_RESTARTING -IN_RESTARTING = False - -def stop_server(server,delay=15): - global RESTART_ABORTED - RESTART_ABORTED = False - server.execute('title @a times 0 200 0') - server.execute('title @a subtitle "§b请利用这段时间内暂停手上的工作,准备好关闭。"') - server.execute('tellraw @a ["",{"text":"服务器将在15秒后关闭"}]') - for i in range(delay,0,-1): - #server.logger.info(str("ABORT STATUS:{}".format(str(RESTART_ABORTED)))) - server.execute('title @a title "§e警告!服务器将在§4§l{}秒§r§e后关闭!"'.format(str(i))) - - server.logger.info("准备关闭服务器..({}s)".format(str(i))) - time.sleep(1) - server.execute('title @a clear') - server.execute('title @a times 0 200 0') - server.execute('title @a title "§c正在关闭服务器……"') - server.execute('title @a subtitle ""') - server.execute('stop') - -def reboot_server(server,delay=15,player="服务器终端"): - if player==None: - player='服务器终端' - global RESTART_ABORTED - RESTART_ABORTED = False - server.execute('title @a times 0 200 0') - server.execute('title @a subtitle "§b请利用这段时间内暂停手上的工作,准备好重启。"') - server.logger.info("{}秒后服务器将会重新启动,由{}发起".format(str(delay),player)) - server.execute('tellraw @a [{"text":""},{"text":"服务器将在§c§l'+str(delay)+'§r秒后重启(由§c'+player+'§r发起),请利用这段时间中断手上的工作,准备好重启。若要中断重启,请使用"},{"color":"white","text":"!!restart abort","underlined":true,"clickEvent":{"action":"suggest_command","value":"!!restart abort"}}]') - for i in range(delay,0,-1): - if RESTART_ABORTED: - RESTART_ABORTED = False - - global IN_RESTARTING - IN_RESTARTING = False - - server.execute('title @a clear') - server.execute('title @a reset') - time.sleep(0.1) - server.execute('title @a subtitle ""') - server.execute('title @a title "§c服务器重启已终止。"') - - return - #server.logger.info(str("ABORT STATUS:{}".format(str(RESTART_ABORTED)))) - server.execute('title @a title "§e警告!服务器将在§4§l{}秒§r§e后重启!"'.format(str(i))) - - server.logger.info("准备重新启动...({}s)".format(str(i))) - time.sleep(1) - server.execute('title @a clear') - server.execute('title @a times 0 200 0') - server.execute('title @a title "§c正在重新启动服务器……"') - server.execute('title @a subtitle ""') - server.restart() - IN_RESTARTING = False - - -def on_load(server,a2): - server.add_help_message('!!reload', '重新加载数据包') - #server.add_help_message('!!shutdown', '关闭服务器') - server.add_help_message('!!restart', '重启服务器') - -def on_info(server, info): - global IN_RESTARTING - if info.content == '!!reload': - if server.get_permission_level(info) ==None or server.get_permission_level(info) >= 2: - server.tell(info.player,"正在重新加载...") - server.say('服务器正在重新加载数据包,可能会出现冻结的情况。请在此时间内停止手上的工作,并等待恢复正常。') - server.execute('reload') - server.tell(info.player,"已重新加载!") - else: - server.tell(info.player,"§c权限不足") - if info.content == '!!restart': - if server.get_permission_level(info) ==None or server.get_permission_level(info) >= 2: - if IN_RESTARTING: - server.logger.info("服务器已在重新启动,无法再次重新启动") - server.tell(info.player,'§c服务器已经在重新启动!') - return - else: - IN_RESTARTING = True - reboot_server(server,15,info.player) - else: - server.tell(info.player,"§c权限不足") - if info.content == '!!restart abort': - if server.get_permission_level(info) ==None or server.get_permission_level(info) >= 2: - if IN_RESTARTING: - server.logger.info("重新启动已被终止") - global RESTART_ABORTED - RESTART_ABORTED = True - else: - if info.player==None: - server.logger.info('服务器未在重启!') - else: - server.tell(info.player,"§c服务器未在重启!") - else: - server.tell(info.player,"§c权限不足") -# if server.get_permission_level(info) ==None or server.get_permission_level(info) >= 3: -# if info.content == '!!shutdown': -# server.logger.info("准备关闭服务器...") -# stop_server(server) diff --git a/plugins/Whitelist/Whitelist-v0.2.2.py b/plugins/Whitelist/Whitelist-v0.2.2.py deleted file mode 100644 index 1eb0005..0000000 --- a/plugins/Whitelist/Whitelist-v0.2.2.py +++ /dev/null @@ -1,126 +0,0 @@ -# -*- coding: utf-8 -*- -import re -import traceback -import copy -# import requests as rq -import json - -HELP_INFO = ''' -============= Whitelist helper v0.2.3 ============= -§f!!whitelist add <玩家> §7将玩家添加至白名单 -§f!!whitelist remove <玩家> §7将玩家移出白名单 -§f!!whitelist search <玩家> §7判断玩家是否添加至白名单 -§f!!whitelist list §7列出所有在白名单内的玩家 -§f!!whitelist reload §7从白名单文件重新加载白名单 -§f!!whitelist on §7开启白名单 -§f!!whitelist off §7关闭白名单 -§f!!whitelist §7显示此帮助信息 -''' - -MLINE = '''''' - -MCDR_PREFFIX = "!!" -PROGRAM = "whitelist" -PLUGIN = PROGRAM -NOT_PERMITTED = "§c权限不足" - -def get_wl(): - with open("./server/whitelist.json") as wl: - return [item['name'] for item in json.load(wl)] - -def on_load(server, old_module): - server.add_help_message('!!whitelist', '白名单编辑') - -def on_info(server, info): - content = info.content.strip()[len(MCDR_PREFFIX):] - if not content.startswith(PLUGIN): - return - content = content[len(PLUGIN):].strip() - def generate_args(sub_cmd, msg_template): - pattern = '(?<={} )\S+'.format(sub_cmd) - for name in re.findall(pattern, content): - yield "{} {}".format(sub_cmd, name), msg_template.format(name) - - def execute(cmd, msg, error_msg, permission): - if server.get_permission_level(info) >= permission: - server.execute("{} {}".format(PROGRAM, cmd)) - server.tell(info.player, msg) - else: - server.tell(info.player, error_msg) - - def list_all(): - names = get_wl() - server.tell(info.player, "白名单中共有{}名玩家:{}".format(len(names), ", ".join(names))) - - def search(): - try: - target = info.content.split(" ")[2] - names = get_wl() - server.tell(info.player, "{}{}在白名单中".format(target, "" if target in names else "不")) - except: - server.tell(info.player,"命令错误!请使用!!whitelist查看帮助") - - - cmd_mappings = { - "add": (generate_args("add", "已将 {} 加入白名单"), NOT_PERMITTED, 2), - "remove": (generate_args("remove", "已将 {} 移出白名单"), NOT_PERMITTED, 2), - "reload": ([("reload", "已重新读取白名单")], NOT_PERMITTED, 2), - "on": ([("on","白名单已开启" )], NOT_PERMITTED, 3), - "off": ([("off", "白名单已关闭")], NOT_PERMITTED, 3), - "list": list_all, - "search": search, - } - - if not content: - server.tell(info.player, HELP_INFO) - else: - sub_cmd = content.split()[0] - if sub_cmd not in cmd_mappings: - server.tell(info.player, "unsupported sub cmd {}".format(sub_cmd)) - else: - config = cmd_mappings[sub_cmd] - if type(config) is tuple: - args, error_msg, permission = config - for cmd, msg in args: - execute(cmd, msg, error_msg, permission) - else: - config() - - -def __test__(): - from collections import namedtuple - Info = namedtuple("Info", ["content", "player"]) - - Server = type("FakeServer", (object,), { - "tell": lambda self, player, msg: print("[server tell msg]:\t" + " ".join([player, msg])), - "execute": lambda self, *args: print("[server execute]:\t" + " ".join(args)), - "get_permission_level": lambda self, info: 3, - }) - - server = Server() - global get_wl - get_wl = lambda: ["user1", "user2"] - - def fake_info(content, player="fake_user"): - return Info(content="{}{} {}".format(MCDR_PREFFIX, PLUGIN, content), player=player) - - tests = [ - "add user2", - "remove user1", - "reload", - "on", - "off", - "list", - "search user3", - "search user1", - "" - ] - for test in tests: - info = fake_info(test) - print("[test content]: ", info.content) - on_info(server, info) - -if __name__ == "__main__": - __test__() - - From 75a8e54718db2fd507dff24f9a7821f20681ab2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A4=E9=95=87=E5=A4=A9666?= <2308465862@qq.com> Date: Fri, 17 Apr 2020 11:36:01 +0800 Subject: [PATCH 2/6] whitelist --- Whitelist-v0.2.2.py | 126 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 Whitelist-v0.2.2.py diff --git a/Whitelist-v0.2.2.py b/Whitelist-v0.2.2.py new file mode 100644 index 0000000..1eb0005 --- /dev/null +++ b/Whitelist-v0.2.2.py @@ -0,0 +1,126 @@ +# -*- coding: utf-8 -*- +import re +import traceback +import copy +# import requests as rq +import json + +HELP_INFO = ''' +============= Whitelist helper v0.2.3 ============= +§f!!whitelist add <玩家> §7将玩家添加至白名单 +§f!!whitelist remove <玩家> §7将玩家移出白名单 +§f!!whitelist search <玩家> §7判断玩家是否添加至白名单 +§f!!whitelist list §7列出所有在白名单内的玩家 +§f!!whitelist reload §7从白名单文件重新加载白名单 +§f!!whitelist on §7开启白名单 +§f!!whitelist off §7关闭白名单 +§f!!whitelist §7显示此帮助信息 +''' + +MLINE = '''''' + +MCDR_PREFFIX = "!!" +PROGRAM = "whitelist" +PLUGIN = PROGRAM +NOT_PERMITTED = "§c权限不足" + +def get_wl(): + with open("./server/whitelist.json") as wl: + return [item['name'] for item in json.load(wl)] + +def on_load(server, old_module): + server.add_help_message('!!whitelist', '白名单编辑') + +def on_info(server, info): + content = info.content.strip()[len(MCDR_PREFFIX):] + if not content.startswith(PLUGIN): + return + content = content[len(PLUGIN):].strip() + def generate_args(sub_cmd, msg_template): + pattern = '(?<={} )\S+'.format(sub_cmd) + for name in re.findall(pattern, content): + yield "{} {}".format(sub_cmd, name), msg_template.format(name) + + def execute(cmd, msg, error_msg, permission): + if server.get_permission_level(info) >= permission: + server.execute("{} {}".format(PROGRAM, cmd)) + server.tell(info.player, msg) + else: + server.tell(info.player, error_msg) + + def list_all(): + names = get_wl() + server.tell(info.player, "白名单中共有{}名玩家:{}".format(len(names), ", ".join(names))) + + def search(): + try: + target = info.content.split(" ")[2] + names = get_wl() + server.tell(info.player, "{}{}在白名单中".format(target, "" if target in names else "不")) + except: + server.tell(info.player,"命令错误!请使用!!whitelist查看帮助") + + + cmd_mappings = { + "add": (generate_args("add", "已将 {} 加入白名单"), NOT_PERMITTED, 2), + "remove": (generate_args("remove", "已将 {} 移出白名单"), NOT_PERMITTED, 2), + "reload": ([("reload", "已重新读取白名单")], NOT_PERMITTED, 2), + "on": ([("on","白名单已开启" )], NOT_PERMITTED, 3), + "off": ([("off", "白名单已关闭")], NOT_PERMITTED, 3), + "list": list_all, + "search": search, + } + + if not content: + server.tell(info.player, HELP_INFO) + else: + sub_cmd = content.split()[0] + if sub_cmd not in cmd_mappings: + server.tell(info.player, "unsupported sub cmd {}".format(sub_cmd)) + else: + config = cmd_mappings[sub_cmd] + if type(config) is tuple: + args, error_msg, permission = config + for cmd, msg in args: + execute(cmd, msg, error_msg, permission) + else: + config() + + +def __test__(): + from collections import namedtuple + Info = namedtuple("Info", ["content", "player"]) + + Server = type("FakeServer", (object,), { + "tell": lambda self, player, msg: print("[server tell msg]:\t" + " ".join([player, msg])), + "execute": lambda self, *args: print("[server execute]:\t" + " ".join(args)), + "get_permission_level": lambda self, info: 3, + }) + + server = Server() + global get_wl + get_wl = lambda: ["user1", "user2"] + + def fake_info(content, player="fake_user"): + return Info(content="{}{} {}".format(MCDR_PREFFIX, PLUGIN, content), player=player) + + tests = [ + "add user2", + "remove user1", + "reload", + "on", + "off", + "list", + "search user3", + "search user1", + "" + ] + for test in tests: + info = fake_info(test) + print("[test content]: ", info.content) + on_info(server, info) + +if __name__ == "__main__": + __test__() + + From d70a5b6fdc6fd7e0c94c8b50f2cff9ec1f9b2818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A4=E9=95=87=E5=A4=A9666?= <2308465862@qq.com> Date: Fri, 17 Apr 2020 11:36:28 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=20Whitelist-v0.?= =?UTF-8?q?2.2.py=20=E4=B8=BA=20Whitelist.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Whitelist-v0.2.2.py => Whitelist.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Whitelist-v0.2.2.py => Whitelist.py (100%) diff --git a/Whitelist-v0.2.2.py b/Whitelist.py similarity index 100% rename from Whitelist-v0.2.2.py rename to Whitelist.py From f5b20c92d40f4649d9fa4294cdb80efab4439855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A4=E9=95=87=E5=A4=A9666?= <2308465862@qq.com> Date: Fri, 22 May 2020 17:54:30 +0800 Subject: [PATCH 4/6] update README.md. --- README.md | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 890e690..98655b4 100644 --- a/README.md +++ b/README.md @@ -1 +1,27 @@ -# MCDR-plugins MCDR插件集合 \ No newline at end of file +# Seed +[English](https://gitee.com/gu_zt666/MCDR-plugins/blob/Whitelist/README_EN.MD) + +> [MCDReforged](https://github.com/Fallen-Breath/MCDReforged) 种子查询插件 +> +> 这是一个种子查询插件 +> +> 它可以使玩家查询服务器种子 + +**MCDaemon** + +如果您拥有Linux环境并愿意将本插件移植至MCDaemon。 + +请创建一个Whitelist-MCD.py,我将很高兴接受Pull requests。 + +## 使用方法 + +| 命令 | 功能 | +|---|---| +| !!whitelist | 查看帮助 | +| !!whitelist add <玩家> | 将玩家添加至白名单 | +| !!whitelist remove <玩家> | 将玩家移出白名单 | +| !!whitelist search <玩家> | 判断玩家是否添加至白名单 | +| !!whitelist list | 列出所有在白名单内的玩家 | +| !!whitelist reload | 从白名单文件重新加载白名单 | +| !!whitelist on | 开启白名单 | +| !!whitelist off | 关闭白名单 | From 8a8dd36ffdbbac91cabcaacfbc2c924370d31954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A4=E9=95=87=E5=A4=A9666?= <2308465862@qq.com> Date: Fri, 22 May 2020 17:58:24 +0800 Subject: [PATCH 5/6] update README.md. --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 98655b4..cff2d0d 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# Seed +# Whitelist [English](https://gitee.com/gu_zt666/MCDR-plugins/blob/Whitelist/README_EN.MD) -> [MCDReforged](https://github.com/Fallen-Breath/MCDReforged) 种子查询插件 +> [MCDReforged](https://github.com/Fallen-Breath/MCDReforged) 白名单管理 > -> 这是一个种子查询插件 +> 这是一个白名单管理插件 > -> 它可以使玩家查询服务器种子 +> 它可以使管理员无OP情况下管理白名单 **MCDaemon** @@ -15,13 +15,13 @@ ## 使用方法 -| 命令 | 功能 | -|---|---| -| !!whitelist | 查看帮助 | -| !!whitelist add <玩家> | 将玩家添加至白名单 | -| !!whitelist remove <玩家> | 将玩家移出白名单 | -| !!whitelist search <玩家> | 判断玩家是否添加至白名单 | -| !!whitelist list | 列出所有在白名单内的玩家 | -| !!whitelist reload | 从白名单文件重新加载白名单 | -| !!whitelist on | 开启白名单 | -| !!whitelist off | 关闭白名单 | +| 命令 | 功能 | 权限 | +|---|---|---| +| !!whitelist | 查看帮助 | user | +| !!whitelist add <玩家> | 将玩家添加至白名单 | helper | +| !!whitelist remove <玩家> | 将玩家移出白名单 | helper | +| !!whitelist search <玩家> | 判断玩家是否添加至白名单 | user | +| !!whitelist list | 列出所有在白名单内的玩家 | user | +| !!whitelist reload | 从白名单文件重新加载白名单 | helper | +| !!whitelist on | 开启白名单 | admin | +| !!whitelist off | 关闭白名单 | admin | From 32a93dcb9c27d975865db397f5d4818fc524ccd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A4=E9=95=87=E5=A4=A9666?= <2308465862@qq.com> Date: Fri, 22 May 2020 18:17:51 +0800 Subject: [PATCH 6/6] update README.md. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cff2d0d..7b27359 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Whitelist [English](https://gitee.com/gu_zt666/MCDR-plugins/blob/Whitelist/README_EN.MD) -> [MCDReforged](https://github.com/Fallen-Breath/MCDReforged) 白名单管理 +> [MCDReforged](https://github.com/Fallen-Breath/MCDReforged) 白名单管理插件 > > 这是一个白名单管理插件 >