From c4a9d9184a322a1933c01726bd2f60f9401e4f45 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Mon, 27 Jun 2016 01:19:07 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E6=9B=B4=E6=96=B0=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=B1=BB=20=E5=AE=89=E5=85=A8=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- .../java/pw/yumc/Yum/commands/YumCommand.java | 7 ++++- .../Yum/listeners/PluginNetworkListener.java | 30 +++++++++++++++---- .../yumc/Yum/listeners/SecurityListener.java | 20 ++++++++----- .../pw/yumc/Yum/managers/ConfigManager.java | 4 +-- .../pw/yumc/Yum/managers/NetworkManager.java | 2 +- src/main/resources/config.yml | 8 ++--- src/main/resources/network.yml | 8 ++++- src/main/resources/setop.yml | 3 ++ 8 files changed, 59 insertions(+), 23 deletions(-) diff --git a/src/main/java/pw/yumc/Yum/commands/YumCommand.java b/src/main/java/pw/yumc/Yum/commands/YumCommand.java index 3d27ba9..01e96c6 100644 --- a/src/main/java/pw/yumc/Yum/commands/YumCommand.java +++ b/src/main/java/pw/yumc/Yum/commands/YumCommand.java @@ -26,6 +26,7 @@ import cn.citycraft.PluginHelper.commands.InvokeSubCommand; import cn.citycraft.PluginHelper.utils.StrKit; import pw.yumc.Yum.Yum; import pw.yumc.Yum.api.YumAPI; +import pw.yumc.Yum.managers.ConfigManager; import pw.yumc.Yum.managers.PluginsManager; import pw.yumc.Yum.managers.RepositoryManager; import pw.yumc.Yum.models.RepoSerialization.Repositories; @@ -207,9 +208,13 @@ public class YumCommand implements HandlerCommands, Listener { } } - @HandlerCommand(name = "reload", aliases = { "re" }, minimumArguments = 1, description = "重载插件", possibleArguments = "<插件名称|all|*>") + @HandlerCommand(name = "reload", aliases = { "re" }, description = "重载插件", possibleArguments = "<插件名称|all|*>") public void reload(final InvokeCommandEvent e) { final CommandSender sender = e.getSender(); + if (e.getArgs().length == 0) { + ConfigManager.i().reload(); + sender.sendMessage("§6重载: §a配置文件已重载!"); + } final String pluginname = e.getArgs()[0]; if (pluginname.equalsIgnoreCase("all") || pluginname.equalsIgnoreCase("*")) { plugman.reloadAll(sender); diff --git a/src/main/java/pw/yumc/Yum/listeners/PluginNetworkListener.java b/src/main/java/pw/yumc/Yum/listeners/PluginNetworkListener.java index 7e3a790..ad117c9 100644 --- a/src/main/java/pw/yumc/Yum/listeners/PluginNetworkListener.java +++ b/src/main/java/pw/yumc/Yum/listeners/PluginNetworkListener.java @@ -12,27 +12,45 @@ import pw.yumc.Yum.managers.ConfigManager; public class PluginNetworkListener implements Listener { public String prefix = "§6[§bYum §a网络管理§6] "; + public String warnMain = "§c插件 §6%s §c尝试在主线程访问网络 §4可能会导致服务器卡顿或无响应!"; + public String warn = "§c插件 §6%s §c尝试访问网络 §4请注意服务器网络安全!"; + public String breaked = "§4已阻止黑名单插件 §b%s §4访问网络!"; + public String url = "§4地址: %s"; public PluginNetworkListener(final Yum yum) { Bukkit.getPluginManager().registerEvents(this, yum); } + public void breakNetwork(final PluginNetworkEvent e) { + PluginKit.sc(String.format(prefix + breaked, e.getPlugin().getName())); + PluginKit.sc(String.format(url, e.getUrl().toString())); + e.setCancelled(true); + } + @EventHandler public void onPluginNetworkConect(final PluginNetworkEvent e) { final Plugin plugin = e.getPlugin(); final String urlinfo = e.getUrl().toString(); + if (urlinfo.startsWith("socket")) { + return; + } + if (urlinfo.contains("yumc")) { + final String 大神你好 = "反编译的大神们我知道你们又要说了这货有后门"; + 大神你好.isEmpty(); + return; + } final boolean isPrimaryThread = e.isPrimaryThread(); - final String str = prefix + (isPrimaryThread ? "§c插件 §6%s §c尝试在主线程访问 §e%s §4可能会导致服务器卡顿或无响应!" : "§c插件 §6%s §c尝试访问 §e%s §c请注意服务器网络安全!"); if (plugin != null) { if (ConfigManager.i().getNetworkBlackList().contains(plugin.getName())) { - PluginKit.sc(prefix + "§4已阻止黑名单插件 §b" + plugin.getName() + " §4访问网络!"); - PluginKit.sc(prefix + "§4地址: " + urlinfo); + breakNetwork(e); return; } - PluginKit.sc(String.format(str, plugin.getName(), urlinfo)); + if (ConfigManager.i().getNetworkIgnoreList().contains(plugin.getName())) { + return; + } + PluginKit.sc(String.format(prefix + (isPrimaryThread ? warnMain : warn), plugin.getName(), urlinfo)); if (!ConfigManager.i().isAllowPrimaryThread() && isPrimaryThread) { - PluginKit.sc(prefix + "§4已阻止插件 §b" + plugin.getName() + " §4在主线程访问网络!"); - e.setCancelled(true); + breakNetwork(e); } } } diff --git a/src/main/java/pw/yumc/Yum/listeners/SecurityListener.java b/src/main/java/pw/yumc/Yum/listeners/SecurityListener.java index 84310aa..fd0d1cb 100644 --- a/src/main/java/pw/yumc/Yum/listeners/SecurityListener.java +++ b/src/main/java/pw/yumc/Yum/listeners/SecurityListener.java @@ -7,6 +7,7 @@ import org.bukkit.plugin.Plugin; import cn.citycraft.PluginHelper.kit.PluginKit; import pw.yumc.Yum.Yum; +import pw.yumc.Yum.managers.ConfigManager; import pw.yumc.injected.event.SetOpEvent; /** @@ -15,22 +16,27 @@ import pw.yumc.injected.event.SetOpEvent; * @author 喵♂呜 */ public class SecurityListener implements Listener { - public String warn = "§6[§bYum §a安全系统§6] §c插件 §e%s §c已设置玩家 §a%s §c为OP §4请注意服务器安全!"; - public String prevent = "§6[§bYum §a安全系统§6] §c黑名单插件 §e%s §c尝试设置玩家 §a%s §c为OP §a安全系统已成功拦截!"; + private final String prefix = "§6[§bYum §a安全系统§6] "; + private final String warn = "§c插件 §e%s §c已设置玩家 §a%s §c为OP §4请注意服务器安全!"; + private final String prevent = "§c黑名单插件 §e%s §c尝试设置玩家 §a%s §c为OP §a安全系统已成功拦截!"; public SecurityListener(final Yum yum) { Bukkit.getPluginManager().registerEvents(this, yum); } @EventHandler - public void setop(final SetOpEvent event) { + public void setop(final SetOpEvent e) { final Plugin plugin = PluginKit.getOperatePlugin(); if (plugin != null) { - if (plugin.getName().equalsIgnoreCase("BukkitInjectedTools")) { - Bukkit.getConsoleSender().sendMessage(String.format(prevent, plugin, event.getOfflinePlayer().getName())); - } else { - Bukkit.getConsoleSender().sendMessage(String.format(warn, plugin, event.getOfflinePlayer().getName())); + if (ConfigManager.i().getSetOpBlackList().contains(plugin.getName())) { + PluginKit.sc(String.format(prefix + prevent, plugin, e.getOfflinePlayer().getName())); + e.setCancelled(true); + return; } + if (ConfigManager.i().getSetOpIgnoreList().contains(plugin.getName())) { + return; + } + Bukkit.getConsoleSender().sendMessage(String.format(prefix + warn, plugin, e.getOfflinePlayer().getName())); } } } diff --git a/src/main/java/pw/yumc/Yum/managers/ConfigManager.java b/src/main/java/pw/yumc/Yum/managers/ConfigManager.java index 2f939ed..46de988 100644 --- a/src/main/java/pw/yumc/Yum/managers/ConfigManager.java +++ b/src/main/java/pw/yumc/Yum/managers/ConfigManager.java @@ -53,11 +53,11 @@ public class ConfigManager { } public boolean isAllowPrimaryThread() { - return config.getBoolean("AllowPrimaryThread", false); + return network.getBoolean("AllowPrimaryThread", false); } public boolean isNetworkDebug() { - return config.getBoolean("NetworkDebug", false); + return network.getBoolean("NetworkDebug", false); } public boolean isNetworkEnable() { diff --git a/src/main/java/pw/yumc/Yum/managers/NetworkManager.java b/src/main/java/pw/yumc/Yum/managers/NetworkManager.java index 1217b78..cbd8cb1 100644 --- a/src/main/java/pw/yumc/Yum/managers/NetworkManager.java +++ b/src/main/java/pw/yumc/Yum/managers/NetworkManager.java @@ -55,7 +55,7 @@ public class NetworkManager { final PluginNetworkEvent pne = new PluginNetworkEvent(PluginKit.getOperatePlugin(), uri, Bukkit.isPrimaryThread()); Bukkit.getPluginManager().callEvent(pne); if (pne.isCancelled()) { - ExceptionKit.throwException(new IOException("[Yum 网络防护] 已开启网络防护 不允许在主线程访问网络!")); + ExceptionKit.throwException(new IOException("[Yum 网络防护] 已开启网络防护 并被联网规则拦截!")); } return defaultSelector.select(uri); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 2240b76..b2b873a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,14 +1,12 @@ -Version: 2.1 +#配置版本号 请勿修改!!! +Version: 2.2 + #是否只允许控制台执行插件仓库命令 onlyCommandConsole: false #是否只允许控制台执行插件网络管理命令 onlyNetCommandConsole: false #是否只允许控制台执行插件文件管理命令 onlyFileCommandConsole: true -#网络调试模式 -NetworkDebug: false -#是否允许插件主线程访问网络 -AllowPrimaryThread: false #禁止rm -rf的文件夹列表 blacklist: - 'plugins' diff --git a/src/main/resources/network.yml b/src/main/resources/network.yml index c39e0cc..b1dca47 100644 --- a/src/main/resources/network.yml +++ b/src/main/resources/network.yml @@ -1,3 +1,6 @@ +#配置版本号 请勿修改!!! +Version: 1.0 + #是否开启 Enable: true #黑名单列表 @@ -6,4 +9,7 @@ Black: - FeatherBoard #忽略检测列表 Ignore: -- Essentials \ No newline at end of file +- Essentials +#URL白名单网址 +WhiteKeyList: +- yum \ No newline at end of file diff --git a/src/main/resources/setop.yml b/src/main/resources/setop.yml index 67027da..c94beca 100644 --- a/src/main/resources/setop.yml +++ b/src/main/resources/setop.yml @@ -1,3 +1,6 @@ +#配置版本号 请勿修改!!! +Version: 1.0 + #是否开启 Enable: true #黑名单列表