mirror of
https://github.com/CarmJos/cn2b2t-project.git
synced 2026-06-04 18:17:19 +08:00
移除服务器自动添加
This commit is contained in:
@@ -12,7 +12,6 @@ import org.cn2b2t.core.managers.users.UserValueManager;
|
|||||||
import org.cn2b2t.core.managers.utils.ConfigManager;
|
import org.cn2b2t.core.managers.utils.ConfigManager;
|
||||||
import org.cn2b2t.core.managers.utils.DataManager;
|
import org.cn2b2t.core.managers.utils.DataManager;
|
||||||
import org.cn2b2t.core.managers.utils.MessagerManager;
|
import org.cn2b2t.core.managers.utils.MessagerManager;
|
||||||
import org.cn2b2t.core.managers.utils.ServersManager;
|
|
||||||
import org.cn2b2t.core.utils.ColorParser;
|
import org.cn2b2t.core.utils.ColorParser;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@@ -38,18 +37,6 @@ public class Main extends JavaPlugin {
|
|||||||
log("&7├ &f启用Messager系统...");
|
log("&7├ &f启用Messager系统...");
|
||||||
MessagerManager.enable();
|
MessagerManager.enable();
|
||||||
MessagerManager.registerChannel("chat");
|
MessagerManager.registerChannel("chat");
|
||||||
//
|
|
||||||
log("&7├ &f启用跨服管理器...");
|
|
||||||
ServersManager.init();
|
|
||||||
if (Main.getInstance().getConfig().getBoolean("Servers.auto-register", true)) {
|
|
||||||
log("&7├ &f检测到启用自动注册,即将尝试向 SYSTEM.CONENCTION 注册。");
|
|
||||||
ServersManager.registerServer(
|
|
||||||
"single-" + Integer.toHexString(Bukkit.getPort()),
|
|
||||||
(Bukkit.getServer().getIp() == null || Bukkit.getServer().getIp().equalsIgnoreCase("") ? "127.0.0.1" : Bukkit.getServer().getIp()),
|
|
||||||
Bukkit.getPort(),
|
|
||||||
"cn2b2t"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
log("&7├ &f启用用户Value管理器....");
|
log("&7├ &f启用用户Value管理器....");
|
||||||
UserValueManager.init();
|
UserValueManager.init();
|
||||||
@@ -72,10 +59,7 @@ public class Main extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
log("&c&LGhost &f" + this.getName().substring(5) + " &7开始卸载...");
|
log(this.getName() + " &7开始卸载...");
|
||||||
|
|
||||||
log("&7├ &f移除服务器");
|
|
||||||
ServersManager.unregisterServer();
|
|
||||||
|
|
||||||
log("&7├ &f卸载监听器...");
|
log("&7├ &f卸载监听器...");
|
||||||
Bukkit.getServicesManager().unregisterAll(this);
|
Bukkit.getServicesManager().unregisterAll(this);
|
||||||
|
|||||||
@@ -1,23 +1,15 @@
|
|||||||
package org.cn2b2t.core.managers.utils;
|
package org.cn2b2t.core.managers.utils;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.cn2b2t.core.Main;
|
import org.cn2b2t.core.Main;
|
||||||
import org.cn2b2t.core.listener.ServersUpdateListener;
|
|
||||||
import org.cn2b2t.core.modules.DataServerInfo;
|
|
||||||
import org.cn2b2t.core.modules.LocalServerInfo;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -25,94 +17,6 @@ public class ServersManager {
|
|||||||
|
|
||||||
public static List<Player> requests = new ArrayList<>();
|
public static List<Player> requests = new ArrayList<>();
|
||||||
|
|
||||||
public static String databaseTable = "game_servers";
|
|
||||||
public static String messageChannel = "serversmanager";
|
|
||||||
|
|
||||||
private static LocalServerInfo localRegisteredServer;
|
|
||||||
|
|
||||||
private static Map<String/*serverID*/, DataServerInfo> dataServers = new HashMap<>();
|
|
||||||
|
|
||||||
private static BukkitRunnable updateRunnable;
|
|
||||||
|
|
||||||
public static void init() {
|
|
||||||
Main.regListener(new ServersUpdateListener());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
updateRunnable = new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (Bukkit.getOnlinePlayers().size() > 0) updateDataServers();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
getUpdateRunnable().runTaskTimer(Main.getInstance(), 20L, 100L);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void registerServer(String serverID, String hostName, int port, String serverGroup) {
|
|
||||||
localRegisteredServer = new LocalServerInfo(serverID, hostName, port, serverGroup);
|
|
||||||
localRegisteredServer.register();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void unregisterServer() {
|
|
||||||
if (getLocalRegisteredServer() != null) {
|
|
||||||
getLocalRegisteredServer().unregister();
|
|
||||||
localRegisteredServer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void updateDataServers() {
|
|
||||||
Map<String, DataServerInfo> tempDataServers = new HashMap<>();
|
|
||||||
ResultSet rs = DataManager.getConnection().SQLqueryInTable(ServersManager.databaseTable);
|
|
||||||
try {
|
|
||||||
if (rs != null) {
|
|
||||||
while (rs.next()) {
|
|
||||||
String serverID = rs.getString("serverid");
|
|
||||||
String hostName = rs.getString("hostname");
|
|
||||||
String serverGroup = rs.getString("servergroup");
|
|
||||||
int players = rs.getInt("players");
|
|
||||||
int port = rs.getInt("port");
|
|
||||||
tempDataServers.put(serverID, new DataServerInfo(serverID, hostName, port, serverGroup, players));
|
|
||||||
}
|
|
||||||
rs.close();
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
DataManager.getConnection().info(e.getLocalizedMessage());
|
|
||||||
Bukkit.getLogger().log(Level.WARNING, "code: {0}", rs);
|
|
||||||
}
|
|
||||||
dataServers = tempDataServers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String, DataServerInfo> getDataServers() {
|
|
||||||
return dataServers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Integer getPlayers(String serverName) {
|
|
||||||
return getPlayers(serverName, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Integer getPlayers(String server, boolean isGroup) {
|
|
||||||
if (server.equalsIgnoreCase("#ALL") || server.equalsIgnoreCase("#AII")) {
|
|
||||||
return getDataServers().keySet().stream()
|
|
||||||
.mapToInt(s -> getDataServers().getOrDefault(s, new DataServerInfo(null, null, -1, null, 0)).getPlayers())
|
|
||||||
.sum();
|
|
||||||
} else {
|
|
||||||
if (isGroup) {
|
|
||||||
return getDataServers().keySet().stream()
|
|
||||||
.filter(s -> getDataServers().get(s).getServerGroup().equalsIgnoreCase(server))
|
|
||||||
.mapToInt(s -> getDataServers().getOrDefault(s, new DataServerInfo(null, null, -1, null, 0)).getPlayers())
|
|
||||||
.sum();
|
|
||||||
} else {
|
|
||||||
return getDataServers().getOrDefault(server, new DataServerInfo(null, null, -1, null, 0)).getPlayers();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BukkitRunnable getUpdateRunnable() {
|
|
||||||
return updateRunnable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void teleport(Player p, String server) {
|
public static void teleport(Player p, String server) {
|
||||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||||
DataOutputStream out = new DataOutputStream(b);
|
DataOutputStream out = new DataOutputStream(b);
|
||||||
@@ -147,36 +51,11 @@ public class ServersManager {
|
|||||||
|
|
||||||
|
|
||||||
public static void goAFK(Player p) {
|
public static void goAFK(Player p) {
|
||||||
|
teleport(p, "LIMBO");
|
||||||
DataServerInfo targetServer = getServerInfo("LIMBO");
|
|
||||||
if (targetServer != null) {
|
|
||||||
teleport(p, targetServer.getServerID());
|
|
||||||
} else {
|
|
||||||
p.sendMessage("§7暂无可用挂机服务器。");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static DataServerInfo getServerInfo(String name) {
|
|
||||||
if (getDataServers().containsKey(name)) {
|
|
||||||
return getDataServers().get(name);
|
|
||||||
} else {
|
|
||||||
for (DataServerInfo info : getDataServers().values()) {
|
|
||||||
if (info.getServerGroup().equalsIgnoreCase(name)) {
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static LocalServerInfo getLocalRegisteredServer() {
|
|
||||||
return localRegisteredServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void switchServer(Player p, String targetServerIp) {
|
public static void switchServer(Player p, String targetServerIp) {
|
||||||
p.sendPluginMessage(Main.getInstance(), "BeeSwitch", targetServerIp.getBytes(StandardCharsets.UTF_8));
|
p.sendPluginMessage(Main.getInstance(), "BeeSwitch", targetServerIp.getBytes(StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,48 +12,10 @@ public class Config {
|
|||||||
public static List<String> illegalWords;
|
public static List<String> illegalWords;
|
||||||
|
|
||||||
|
|
||||||
public static FileConfig yamen;
|
|
||||||
|
|
||||||
public static String database_SQLhost;
|
|
||||||
public static int database_SQLport;
|
|
||||||
public static String database_SQLdata;
|
|
||||||
public static String database_user;
|
|
||||||
public static String database_password;
|
|
||||||
|
|
||||||
public static String reason_default;
|
|
||||||
|
|
||||||
public static Map<String/*Layout*/, String/*Value*/> layouts = new HashMap<>();
|
|
||||||
|
|
||||||
public static List<String> servers;
|
|
||||||
|
|
||||||
|
|
||||||
public static void load() {
|
public static void load() {
|
||||||
|
|
||||||
illegalWords = new FileConfig(Main.getInstance(), "illegalWords.yml").getStringList("words");
|
illegalWords = new FileConfig(Main.getInstance(), "illegalWords.yml").getStringList("words");
|
||||||
|
|
||||||
|
|
||||||
//yamen
|
|
||||||
yamen = new FileConfig(Main.getInstance(), "yamen.yml");
|
|
||||||
|
|
||||||
database_SQLhost = yamen.getString("Database.SQLhost");
|
|
||||||
database_SQLport = yamen.getInt("Database.SQLport");
|
|
||||||
database_SQLdata = yamen.getString("Database.SQLdata");
|
|
||||||
database_user = yamen.getString("Database.user");
|
|
||||||
database_password = yamen.getString("Database.password");
|
|
||||||
|
|
||||||
reason_default = yamen.getString("DefaultReason").replace("&", "§");
|
|
||||||
|
|
||||||
yamen.getSection("Layouts").getKeys().forEach((s) -> {
|
|
||||||
StringBuilder layoutBuilder = new StringBuilder();
|
|
||||||
yamen.getStringList("Layouts." + s).forEach((layout) -> {
|
|
||||||
layoutBuilder.append(layout);
|
|
||||||
layoutBuilder.append("\n");
|
|
||||||
});
|
|
||||||
layouts.put(s, layoutBuilder.toString().replace("&", "§").replace("%(space)", "\n "));
|
|
||||||
});
|
|
||||||
|
|
||||||
servers = yamen.getStringList("Servers");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import net.md_5.bungee.api.plugin.Listener;
|
|||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||||
import org.cn2b2t.proxy.functions.DatabaseConfig;
|
import org.cn2b2t.proxy.functions.DatabaseConfig;
|
||||||
import org.cn2b2t.proxy.functions.permission.PermissionMain;
|
|
||||||
import org.cn2b2t.proxy.functions.serverinfo.ServerInfoMain;
|
import org.cn2b2t.proxy.functions.serverinfo.ServerInfoMain;
|
||||||
import org.cn2b2t.proxy.listeners.LoginListener;
|
import org.cn2b2t.proxy.listeners.LoginListener;
|
||||||
import org.cn2b2t.proxy.listeners.QuitListener;
|
import org.cn2b2t.proxy.listeners.QuitListener;
|
||||||
@@ -42,7 +41,6 @@ public class Main extends Plugin {
|
|||||||
loadConfigs();
|
loadConfigs();
|
||||||
|
|
||||||
DataManager.init();
|
DataManager.init();
|
||||||
PermissionMain.init();
|
|
||||||
ServerInfoMain.init();
|
ServerInfoMain.init();
|
||||||
UserValueManager.init();
|
UserValueManager.init();
|
||||||
|
|
||||||
|
|||||||
@@ -1,71 +0,0 @@
|
|||||||
package org.cn2b2t.proxy.commands;
|
|
||||||
|
|
||||||
|
|
||||||
import org.cn2b2t.proxy.functions.permission.PermissionManager;
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author cam
|
|
||||||
*/
|
|
||||||
public class ProxyPermdog extends Command {
|
|
||||||
|
|
||||||
public ProxyPermdog(final String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(final CommandSender sender, final String[] args) {
|
|
||||||
|
|
||||||
if (!sender.hasPermission("moci.admin")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.length > 0) {
|
|
||||||
if (args[0].equalsIgnoreCase("user")) {
|
|
||||||
if (args.length == 2) {
|
|
||||||
ProxiedPlayer p = getPlayer(args[1]);
|
|
||||||
if (p != null) {
|
|
||||||
sender.sendMessage("§8----------------------------------------");
|
|
||||||
sender.sendMessage("§7UUID §e" + p.getUUID());
|
|
||||||
|
|
||||||
sender.sendMessage("§8----------------------------------------");
|
|
||||||
} else {
|
|
||||||
sender.sendMessage("玩家" + args[1] + "不存在");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (args[0].equalsIgnoreCase("uuid")) {
|
|
||||||
if (args.length == 2) {
|
|
||||||
ProxiedPlayer p = getPlayer(args[1]);
|
|
||||||
if (p != null) {
|
|
||||||
sender.sendMessage("UUID:" + p.getUUID());
|
|
||||||
sender.sendMessage("RealPerm:"
|
|
||||||
+ Arrays.toString(p.getPermissions().toArray()));
|
|
||||||
} else {
|
|
||||||
sender.sendMessage("玩家" + args[1] + "不存在");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (args[0].equalsIgnoreCase("update")) {
|
|
||||||
|
|
||||||
PermissionManager.updateAll();
|
|
||||||
|
|
||||||
sender.sendMessage("权限狗数据已更新");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private ProxiedPlayer getPlayer(String name) {
|
|
||||||
for (ProxiedPlayer p : ProxyServer.getInstance().getPlayers()) {
|
|
||||||
if (p.getName().equals(name)) {
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
package org.cn2b2t.proxy.functions;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
|
|
||||||
public class PlayerCounter {
|
|
||||||
|
|
||||||
private static HashMap<String, Integer> counts = new HashMap<>();
|
|
||||||
|
|
||||||
|
|
||||||
// public static void count() {
|
|
||||||
// if (BungeeCord.getInstance().getPlayers().size() < 1) return;
|
|
||||||
// BungeeCord.getInstance().getServers().forEach((s, serverInfo) -> {
|
|
||||||
// int player = serverInfo.getPlayers().size();
|
|
||||||
// new BungeeScheduler().runAsync(Main.getInstance(), () -> {
|
|
||||||
//
|
|
||||||
// ResultSet query = DataManager.getTempConnection().SQLquery("countplayer", "server", s);
|
|
||||||
// try {
|
|
||||||
// if (query != null) {
|
|
||||||
// if (query.next()) {
|
|
||||||
// DataManager.getTempConnection().update("countplayer", "players", player,
|
|
||||||
// "server", s);
|
|
||||||
// } else {
|
|
||||||
// DataManager.getTempConnection().insert("countplayer",
|
|
||||||
// new String[]{"server", "players"},
|
|
||||||
// new Object[]{s, player});
|
|
||||||
// }
|
|
||||||
// query.close();
|
|
||||||
// }
|
|
||||||
// } catch (SQLException e) {
|
|
||||||
// e.printStackTrace();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// update();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public static Integer get(String serverName) {
|
|
||||||
// return get(serverName, false);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public static Integer get(String serverName, boolean isMultiServer) {
|
|
||||||
// if (isMultiServer) {
|
|
||||||
// return (!counts.isEmpty() && serverName.equalsIgnoreCase("#ALL") || serverName.equalsIgnoreCase("#AII")) ?
|
|
||||||
// counts.keySet().stream().mapToInt(s -> counts.getOrDefault(s, 0)).sum()
|
|
||||||
// : counts.entrySet().stream().filter(entry -> entry.getKey().startsWith(serverName)).mapToInt(Map.Entry::getValue).sum();
|
|
||||||
// } else {
|
|
||||||
// return (!counts.isEmpty() && serverName.equalsIgnoreCase("#ALL") || serverName.equalsIgnoreCase("#AII")) ?
|
|
||||||
// counts.keySet().stream().mapToInt(s -> counts.getOrDefault(s, 0)).sum()
|
|
||||||
// : counts.getOrDefault(serverName, 0);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public static void update() {
|
|
||||||
// counts.clear();
|
|
||||||
// Connection temp = DataManager.getTempConnection();
|
|
||||||
// ResultSet rs = temp.SQLqueryInTable("countplayer");
|
|
||||||
// try {
|
|
||||||
// if (rs != null) {
|
|
||||||
// while (rs.next()) {
|
|
||||||
// counts.put(rs.getString("server"), rs.getInt("players"));
|
|
||||||
// }
|
|
||||||
// rs.close();
|
|
||||||
// }
|
|
||||||
// } catch (SQLException e) {
|
|
||||||
// cn.moci.kettle.managers.utils.DataManager.getKettleConnection().info(e.getLocalizedMessage());
|
|
||||||
// Bukkit.getLogger().log(Level.WARNING, "code: {0}", rs);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package org.cn2b2t.proxy.functions.permission;
|
|
||||||
|
|
||||||
public class DataPermission {
|
|
||||||
|
|
||||||
public String perm;
|
|
||||||
public String base;
|
|
||||||
|
|
||||||
public DataPermission(String perm, String base) {
|
|
||||||
this.perm = perm;
|
|
||||||
this.base = base;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-16
@@ -1,16 +0,0 @@
|
|||||||
package org.cn2b2t.proxy.functions.permission;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class DataPermissionGroup {
|
|
||||||
|
|
||||||
public final int id;
|
|
||||||
public final List<Integer> extend;
|
|
||||||
public final List<DataPermission> perms;
|
|
||||||
|
|
||||||
public DataPermissionGroup(int id, List<Integer> extend, List<DataPermission> perms) {
|
|
||||||
this.id = id;
|
|
||||||
this.extend = extend;
|
|
||||||
this.perms = perms;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package org.cn2b2t.proxy.functions.permission;
|
|
||||||
|
|
||||||
import org.cn2b2t.proxy.Main;
|
|
||||||
import org.cn2b2t.proxy.utils.FileConfig;
|
|
||||||
import net.md_5.bungee.config.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author cam
|
|
||||||
*/
|
|
||||||
public class PermConfig {
|
|
||||||
|
|
||||||
// 只加载"@"和“Bungee"库权限
|
|
||||||
|
|
||||||
public static Configuration permConfig;
|
|
||||||
|
|
||||||
|
|
||||||
public static void load() {
|
|
||||||
permConfig = null;
|
|
||||||
PermConfig.permConfig = new FileConfig(Main.getInstance(), "perm.yml").getConfig();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-63
@@ -1,63 +0,0 @@
|
|||||||
package org.cn2b2t.proxy.functions.permission;
|
|
||||||
|
|
||||||
import org.cn2b2t.proxy.Main;
|
|
||||||
import org.cn2b2t.proxy.managers.DataManager;
|
|
||||||
import org.cn2b2t.proxy.utils.data.Connection;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author cam
|
|
||||||
*/
|
|
||||||
public class PermissionDataManager {
|
|
||||||
|
|
||||||
public static Connection permdogConnection;
|
|
||||||
public static Connection websiteConnection;
|
|
||||||
|
|
||||||
public static void init() {
|
|
||||||
permdogConnection = DataManager.getKettleConnection();
|
|
||||||
websiteConnection = DataManager.getWebsiteConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getUniqueID(int inkID) {
|
|
||||||
ResultSet query = permdogConnection.SQLquery("nl2_users", "id", inkID);
|
|
||||||
try {
|
|
||||||
if (query != null) {
|
|
||||||
String uuid = null;
|
|
||||||
if (query.next()) {
|
|
||||||
uuid = query.getString("uuid");
|
|
||||||
}
|
|
||||||
query.close();
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
throw new NullPointerException("不存在InkID" + inkID);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
permdogConnection.info(e.getLocalizedMessage());
|
|
||||||
Main.getInstance().getLogger().log(Level.WARNING, "code: {0}", query);
|
|
||||||
}
|
|
||||||
throw new NullPointerException("不存在InkID" + inkID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getInkID(String uuid) {
|
|
||||||
ResultSet query = permdogConnection.SQLquery("nl2_users", "uuid", uuid.replace("-", ""));
|
|
||||||
try {
|
|
||||||
if (query != null) {
|
|
||||||
int id = -1;
|
|
||||||
if (query.next()) {
|
|
||||||
id = query.getInt("id");
|
|
||||||
}
|
|
||||||
query.close();
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
permdogConnection.info(e.getLocalizedMessage());
|
|
||||||
Main.getInstance().getLogger().log(Level.WARNING, "code: {0}", query);
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
package org.cn2b2t.proxy.functions.permission;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class PermissionLoader {
|
|
||||||
|
|
||||||
public static Integer[] getIntArray(String s) {
|
|
||||||
if (s == null || s.isEmpty()) return new Integer[0];
|
|
||||||
if (s.startsWith("[") && s.endsWith("]")) {
|
|
||||||
String inner = s.substring(1, s.length() - 1);
|
|
||||||
String[] split = inner.split(",");
|
|
||||||
Integer[] result = new Integer[split.length];
|
|
||||||
for (int i = 0; i < split.length; i++) {
|
|
||||||
String sec = split[i];
|
|
||||||
int num;
|
|
||||||
if (sec.startsWith("\"") && sec.endsWith("\"")) {
|
|
||||||
sec = sec.substring(1, sec.length() - 1);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
num = Integer.parseInt(sec);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
ProxyServer.getInstance().getLogger().info("Illegal Array: " + s + "(index=" + i + ")");
|
|
||||||
num = -1;
|
|
||||||
}
|
|
||||||
result[i] = num;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
} else {
|
|
||||||
ProxyServer.getInstance().getLogger().info("Illegal Array: " + s);
|
|
||||||
return new Integer[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String toString(Integer[] arr) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("[");
|
|
||||||
for (int index = 0; index < arr.length; index++) {
|
|
||||||
int group_id = arr[index];
|
|
||||||
sb.append("\"").append(group_id).append("\"");
|
|
||||||
if (index != arr.length - 1) {
|
|
||||||
sb.append(",");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sb.append("]");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<DataPermissionGroup> getPermGroups(List<Integer> group_ids) {
|
|
||||||
return group_ids.stream().map(PermissionLoader::getPermGroup).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DataPermissionGroup getPermGroup(int group_id) {
|
|
||||||
ResultSet result = PermissionDataManager.websiteConnection.SQLquery("game_perms_group", "group_id", group_id);
|
|
||||||
try {
|
|
||||||
if (result != null) {
|
|
||||||
List<DataPermission> perms = new ArrayList<>();
|
|
||||||
List<Integer> extend = new ArrayList<>();
|
|
||||||
while (result.next()) {
|
|
||||||
String type = result.getString("type");
|
|
||||||
String value = result.getString("value");
|
|
||||||
String base = result.getString("base");
|
|
||||||
if (type.equalsIgnoreCase("perm")) {
|
|
||||||
perms.add(new DataPermission(value, base));
|
|
||||||
} else if (type.equalsIgnoreCase("extend")) {
|
|
||||||
try {
|
|
||||||
extend.add(Integer.valueOf(value));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
ProxyServer.getInstance().getLogger().log(Level.WARNING, "In table `game_perms_group`: id=" + result.getInt("id") +
|
|
||||||
">value must be integer, not \"" + value + "\"");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result.close();
|
|
||||||
return new DataPermissionGroup(group_id, extend, perms);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
PermissionDataManager.websiteConnection.info(e.getLocalizedMessage());
|
|
||||||
ProxyServer.getInstance().getLogger().log(Level.WARNING, "PermissionLoader.");
|
|
||||||
}
|
|
||||||
return new DataPermissionGroup(group_id, new ArrayList<>(), new ArrayList<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void loadGroupPermission(ProxiedPlayer p, List<DataPermissionGroup> groups) {
|
|
||||||
for (DataPermissionGroup group : groups) {
|
|
||||||
loadUserPermission(p, group.perms);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void loadUserPermission(ProxiedPlayer p, List<DataPermission> perms) {
|
|
||||||
for (DataPermission perm : perms) {
|
|
||||||
String base = perm.base;
|
|
||||||
if (base.equals("@")) {
|
|
||||||
p.setPermission(perm.perm, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package org.cn2b2t.proxy.functions.permission;
|
|
||||||
|
|
||||||
import org.cn2b2t.proxy.Main;
|
|
||||||
import org.cn2b2t.proxy.commands.ProxyPermdog;
|
|
||||||
import org.cn2b2t.proxy.listeners.OveridePermissionsListener;
|
|
||||||
|
|
||||||
public class PermissionMain {
|
|
||||||
|
|
||||||
public static void init() {
|
|
||||||
PermConfig.load();
|
|
||||||
PermissionDataManager.init();
|
|
||||||
|
|
||||||
Main.regListener(new OveridePermissionsListener());
|
|
||||||
Main.regCommmand(new ProxyPermdog("proxypermdog"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void disable() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-360
@@ -1,360 +0,0 @@
|
|||||||
package org.cn2b2t.proxy.functions.permission;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 玩家的权限管理
|
|
||||||
* 除加入游戏时的加载,读取和写入都是同步运行,如果如要异步运行,请注意线程安全。
|
|
||||||
*
|
|
||||||
* @Author LSeng
|
|
||||||
*/
|
|
||||||
public class PermissionManager {
|
|
||||||
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * 卸载玩家的所有权限
|
|
||||||
// */
|
|
||||||
// public void unloadPermission(){
|
|
||||||
// for(Map.Entry<String, Boolean> perm : new HashMap<>(permissionAttachment.getPermissions()).entrySet()){
|
|
||||||
// permissionAttachment.unsetPermission(perm.getKey());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void loadPermission() {
|
|
||||||
// List<PermGroup> groups = getUserGroup(getUser().getInkID());
|
|
||||||
// this.maxOrder = getMaxOrder(groups);
|
|
||||||
// PermissionLoader.loadGroupPermission(this, groups);//加载玩家的组权限
|
|
||||||
// PermissionLoader.loadUserPermission(this, getPermsIgnoreGroup(getUser().getInkID()));//加载玩家单独权限
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 由ID获取组
|
|
||||||
*
|
|
||||||
* @param group_id 组id
|
|
||||||
* @return 组
|
|
||||||
*/
|
|
||||||
public static DataPermissionGroup getGroupByID(int group_id) {
|
|
||||||
return PermissionLoader.getPermGroup(group_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得组下的所有玩家
|
|
||||||
*
|
|
||||||
* @param group_id 组ID
|
|
||||||
* @return 玩家的inkID和临时名字
|
|
||||||
*/
|
|
||||||
public static Map<Integer, String> getGroupMember(int group_id) {
|
|
||||||
ResultSet userResult = PermissionDataManager.websiteConnection.SQLquery("select * from nl2_users");
|
|
||||||
Map<Integer, String> map = new HashMap<>();
|
|
||||||
try {
|
|
||||||
if (userResult != null) {
|
|
||||||
while (userResult.next()) {
|
|
||||||
int target_id = userResult.getInt("group_id");
|
|
||||||
Integer[] secondary_groups = PermissionLoader.getIntArray(userResult.getString("secondary_groups"));
|
|
||||||
List<Integer> groups = new ArrayList<>(secondary_groups.length + 1);
|
|
||||||
groups.add(target_id);
|
|
||||||
groups.addAll(Arrays.asList(secondary_groups));
|
|
||||||
if (groups.contains(group_id)) {
|
|
||||||
map.put(userResult.getInt("id"), userResult.getString("username"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
userResult.close();
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得玩家所在的组列表,不会顺便把继承的组也一起加载进去(但可以获得继承组的id)
|
|
||||||
* 假设玩家在组 MVP 中,组MVP继承VIP,则会获得组列表[MVP]
|
|
||||||
*
|
|
||||||
* @return 玩家所在的组列表
|
|
||||||
*/
|
|
||||||
public static List<DataPermissionGroup> getUserGroupsIgnoreExtend(int inkid) {
|
|
||||||
ResultSet userResult = PermissionDataManager.websiteConnection.SQLquery("nl2_users", "id", inkid);
|
|
||||||
try {
|
|
||||||
if (userResult != null) {
|
|
||||||
if (userResult.next()) {
|
|
||||||
int group_id = userResult.getInt("group_id");
|
|
||||||
Integer[] secondary_groups = PermissionLoader.getIntArray(userResult.getString("secondary_groups"));
|
|
||||||
List<Integer> groups = new ArrayList<>(secondary_groups.length + 1);
|
|
||||||
groups.add(group_id);
|
|
||||||
groups.addAll(Arrays.asList(secondary_groups));
|
|
||||||
|
|
||||||
return PermissionLoader.getPermGroups(groups);
|
|
||||||
}
|
|
||||||
userResult.close();
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
PermissionDataManager.permdogConnection.info(e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得玩家的主组
|
|
||||||
*
|
|
||||||
* @param inkid 玩家的inkID
|
|
||||||
* @return 玩家的主组
|
|
||||||
*/
|
|
||||||
public static DataPermissionGroup getMainGroup(int inkid) {
|
|
||||||
ResultSet groupResult = PermissionDataManager.websiteConnection.SQLquery("nl2_users", "id", inkid);
|
|
||||||
try {
|
|
||||||
if (groupResult != null) {
|
|
||||||
if (groupResult.next()) {
|
|
||||||
int group_id = groupResult.getInt("group_id");
|
|
||||||
|
|
||||||
return PermissionLoader.getPermGroup(group_id);
|
|
||||||
}
|
|
||||||
groupResult.close();
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
PermissionDataManager.permdogConnection.info(e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 加载玩家的副组
|
|
||||||
*
|
|
||||||
* @param inkid 玩家的inkID
|
|
||||||
* @return 玩家的副组列表
|
|
||||||
*/
|
|
||||||
public static List<DataPermissionGroup> getSecondaryGroups(int inkid) {
|
|
||||||
ResultSet groupResult = PermissionDataManager.websiteConnection.SQLquery("nl2_users", "id", inkid);
|
|
||||||
try {
|
|
||||||
if (groupResult != null) {
|
|
||||||
if (groupResult.next()) {
|
|
||||||
Integer[] secondary_groups = PermissionLoader.getIntArray(groupResult.getString("secondary_groups"));
|
|
||||||
List<Integer> groups = new ArrayList<>(secondary_groups.length);
|
|
||||||
groups.addAll(Arrays.asList(secondary_groups));
|
|
||||||
|
|
||||||
return PermissionLoader.getPermGroups(groups);
|
|
||||||
}
|
|
||||||
groupResult.close();
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
PermissionDataManager.permdogConnection.info(e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得玩家所在的组列表,顺便把继承的组也一起加载进去
|
|
||||||
* 假设玩家在组 MVP 中,组MVP继承VIP,则会获得组列表[MVP, VIP]
|
|
||||||
*
|
|
||||||
* @return 玩家所在的组列表
|
|
||||||
*/
|
|
||||||
public static List<DataPermissionGroup> getUserGroup(int inkid) {
|
|
||||||
List<DataPermissionGroup> permGroups = getUserGroupsIgnoreExtend(inkid);
|
|
||||||
//加载继承组
|
|
||||||
for (DataPermissionGroup group : new ArrayList<>(permGroups)) {
|
|
||||||
if (!group.extend.isEmpty()) {//有继承的组
|
|
||||||
//检测是否有重复组
|
|
||||||
label:
|
|
||||||
for (int i : group.extend) {
|
|
||||||
for (DataPermissionGroup temp : permGroups) {
|
|
||||||
if (temp.id == i) {
|
|
||||||
continue label;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
permGroups.add(PermissionLoader.getPermGroup(i));//若无重复,则添加组
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return permGroups;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得玩家的单独权限,不获得组权限
|
|
||||||
* 比如玩家拥有权限 kar.abc ,玩家在组 VIP 中,组VIP有权限 kar.vip ,则会获得权限列表[kar.abc]
|
|
||||||
*
|
|
||||||
* @return 玩家的权限列表
|
|
||||||
*/
|
|
||||||
public static List<DataPermission> getPermsIgnoreGroup(int inkid) {
|
|
||||||
ResultSet userResult = PermissionDataManager.websiteConnection.SQLquery("game_perms_user", "inkid", inkid);
|
|
||||||
try {
|
|
||||||
if (userResult != null) {
|
|
||||||
List<DataPermission> perms = new ArrayList<>();
|
|
||||||
while (userResult.next()) {
|
|
||||||
String perm = userResult.getString("perm");
|
|
||||||
String base = userResult.getString("base");
|
|
||||||
|
|
||||||
perms.add(new DataPermission(perm, base));
|
|
||||||
}
|
|
||||||
|
|
||||||
userResult.close();
|
|
||||||
|
|
||||||
return perms;
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
PermissionDataManager.permdogConnection.info(e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得玩家的所有权限,包括组权限
|
|
||||||
* 比如玩家拥有权限 kar.abc ,玩家在组 VIP 中,组VIP有权限 kar.vip ,则会获得权限列表[kar.abc, kar.vip]
|
|
||||||
*
|
|
||||||
* @return 玩家的权限列表
|
|
||||||
*/
|
|
||||||
public static List<DataPermission> getAllPerms(int inkid) {
|
|
||||||
List<DataPermission> list = new ArrayList<>(getPermsIgnoreGroup(inkid));
|
|
||||||
for (DataPermissionGroup group : getUserGroup(inkid)) {
|
|
||||||
list.addAll(group.perms);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新某玩家的权限
|
|
||||||
*
|
|
||||||
* @param p 玩家
|
|
||||||
*/
|
|
||||||
public static void updatePermission(ProxiedPlayer p) {
|
|
||||||
int inkid = PermissionDataManager.getInkID(p.getUniqueId().toString());
|
|
||||||
if (inkid != -1) {
|
|
||||||
List<DataPermissionGroup> groups = getUserGroup(inkid);
|
|
||||||
PermissionLoader.loadGroupPermission(p, groups);//加载玩家的组权限
|
|
||||||
PermissionLoader.loadUserPermission(p, getPermsIgnoreGroup(inkid));//加载玩家单独权限
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void unloadPermission(ProxiedPlayer p) {
|
|
||||||
for (String s : new ArrayList<>(p.getPermissions())) {
|
|
||||||
p.setPermission(s, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新所有玩家的权限
|
|
||||||
*/
|
|
||||||
public static void updateAll() {
|
|
||||||
for (ProxiedPlayer p : ProxyServer.getInstance().getPlayers()) {
|
|
||||||
updatePermission(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取存在的组
|
|
||||||
*
|
|
||||||
* @return 得到一个Map,Key为group_id,Value为组名
|
|
||||||
*/
|
|
||||||
public static Map<Integer, String> getExistedGroups() {
|
|
||||||
Map<Integer, String> map = new HashMap<>();
|
|
||||||
ResultSet result = PermissionDataManager.permdogConnection.SQLquery("select * from nl2_groups");
|
|
||||||
try {
|
|
||||||
if (result != null) {
|
|
||||||
while (result.next()) {
|
|
||||||
int group_id = result.getInt("id");
|
|
||||||
String name = result.getString("name");
|
|
||||||
map.put(group_id, name);
|
|
||||||
}
|
|
||||||
result.close();
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
PermissionDataManager.permdogConnection.info(e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得组列表中order最高的order值
|
|
||||||
*/
|
|
||||||
public static int getMaxOrder(List<DataPermissionGroup> list) {
|
|
||||||
int maxOrder = -1;
|
|
||||||
ResultSet result = PermissionDataManager.permdogConnection.SQLquery("select * from nl2_groups");
|
|
||||||
try {
|
|
||||||
if (result != null) {
|
|
||||||
while (result.next()) {
|
|
||||||
int group_id = result.getInt("id");
|
|
||||||
for (DataPermissionGroup group : list) {
|
|
||||||
if (group.id == group_id) {
|
|
||||||
int order = result.getInt("order");
|
|
||||||
if (order > maxOrder) {
|
|
||||||
maxOrder = order;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result.close();
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
PermissionDataManager.permdogConnection.info(e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
return maxOrder;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据groupID获取组名
|
|
||||||
*
|
|
||||||
* @param group_id 组ID
|
|
||||||
* @return 组名
|
|
||||||
*/
|
|
||||||
public static String getGroupName(int group_id) {
|
|
||||||
return getGroupName(new int[]{group_id})[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据groupID批量获取组名
|
|
||||||
*
|
|
||||||
* @param group_ids 批量获取的组的组ID
|
|
||||||
* @return 组名
|
|
||||||
*/
|
|
||||||
public static String[] getGroupName(int[] group_ids) {
|
|
||||||
String[] result = new String[group_ids.length];
|
|
||||||
Map<Integer, String> map = getExistedGroups();
|
|
||||||
for (int index = 0; index < group_ids.length; index++) {
|
|
||||||
int group_id = group_ids[index];
|
|
||||||
result[index] = map.get(group_id);
|
|
||||||
if (result[index] == null) {
|
|
||||||
result[index] = "Unknown";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据组名获取组ID
|
|
||||||
*
|
|
||||||
* @param name 组名
|
|
||||||
* @return 组ID
|
|
||||||
*/
|
|
||||||
public static int getGroupID(String name) {
|
|
||||||
return getGroupID(new String[]{name})[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据组名批量获取组ID
|
|
||||||
*
|
|
||||||
* @param names 批量获取的组的组名
|
|
||||||
* @return 组ID
|
|
||||||
*/
|
|
||||||
public static int[] getGroupID(String[] names) {
|
|
||||||
int[] result = new int[names.length];
|
|
||||||
Map<Integer, String> map = getExistedGroups();
|
|
||||||
for (int index = 0; index < names.length; index++) {
|
|
||||||
String name = names[index];
|
|
||||||
int value = -1;
|
|
||||||
for (Map.Entry<Integer, String> entry : map.entrySet()) {
|
|
||||||
if (entry.getValue().equals(name)) {
|
|
||||||
value = entry.getKey();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result[index] = value;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,25 +1,20 @@
|
|||||||
package org.cn2b2t.proxy.functions.proxyuser;
|
package org.cn2b2t.proxy.functions.proxyuser;
|
||||||
|
|
||||||
import org.cn2b2t.proxy.Main;
|
|
||||||
import org.cn2b2t.proxy.functions.Account;
|
|
||||||
import org.cn2b2t.proxy.functions.permission.DataPermissionGroup;
|
|
||||||
import org.cn2b2t.proxy.functions.permission.PermissionLoader;
|
|
||||||
import org.cn2b2t.proxy.functions.permission.PermissionManager;
|
|
||||||
import org.cn2b2t.proxy.functions.serverinfo.ServerInfoConfig;
|
|
||||||
import org.cn2b2t.proxy.managers.DataManager;
|
|
||||||
import org.cn2b2t.proxy.managers.UserValueManager;
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
import net.md_5.bungee.BungeeCord;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
import net.md_5.bungee.scheduler.BungeeScheduler;
|
import net.md_5.bungee.scheduler.BungeeScheduler;
|
||||||
|
import org.cn2b2t.proxy.Main;
|
||||||
|
import org.cn2b2t.proxy.functions.Account;
|
||||||
|
import org.cn2b2t.proxy.functions.serverinfo.ServerInfoConfig;
|
||||||
|
import org.cn2b2t.proxy.managers.DataManager;
|
||||||
|
import org.cn2b2t.proxy.managers.UserValueManager;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class ProxyUser {
|
public class ProxyUser {
|
||||||
|
|
||||||
@@ -50,7 +45,6 @@ public class ProxyUser {
|
|||||||
this.version = version;
|
this.version = version;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
isRegistered = Account.isRegistered(userName);
|
isRegistered = Account.isRegistered(userName);
|
||||||
if (isRegistered) {
|
if (isRegistered) {
|
||||||
inkID = Account.getInkID(name);
|
inkID = Account.getInkID(name);
|
||||||
@@ -72,8 +66,6 @@ public class ProxyUser {
|
|||||||
|
|
||||||
new BungeeScheduler().runAsync(Main.getInstance(), this::createTempUser);
|
new BungeeScheduler().runAsync(Main.getInstance(), this::createTempUser);
|
||||||
|
|
||||||
new BungeeScheduler().runAsync(Main.getInstance(), this::updatePermission);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getGameUUID() {
|
public UUID getGameUUID() {
|
||||||
@@ -88,16 +80,6 @@ public class ProxyUser {
|
|||||||
return isRegistered;
|
return isRegistered;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePermission() {
|
|
||||||
new BungeeScheduler().runAsync(Main.getInstance(), () -> {
|
|
||||||
List<DataPermissionGroup> groups = PermissionManager.getUserGroup(inkID);
|
|
||||||
new BungeeScheduler().schedule(Main.getInstance(), () -> {
|
|
||||||
BungeeCord.getInstance().getConsole().sendMessage("loading perms of " + name);
|
|
||||||
PermissionLoader.loadGroupPermission(BungeeCord.getInstance().getPlayer(name), groups);//加载玩家的组权限
|
|
||||||
PermissionLoader.loadUserPermission(BungeeCord.getInstance().getPlayer(name), PermissionManager.getPermsIgnoreGroup(inkID));
|
|
||||||
}, 0, TimeUnit.MILLISECONDS);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, String> getValues() {
|
public Map<String, String> getValues() {
|
||||||
return values;
|
return values;
|
||||||
@@ -165,9 +147,5 @@ public class ProxyUser {
|
|||||||
return hasTarget;
|
return hasTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadPermission() {
|
|
||||||
PermissionManager.updatePermission(BungeeCord.getInstance().getPlayer(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ public class UserManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static long lastCheck;
|
private static long lastCheck;
|
||||||
|
|
||||||
private static void antiMemoryFlow() {
|
private static void antiMemoryFlow() {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
if (now - lastCheck > 60000) {
|
if (now - lastCheck > 60000) {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.cn2b2t.proxy.functions.serverinfo;
|
package org.cn2b2t.proxy.functions.serverinfo;
|
||||||
|
|
||||||
import org.cn2b2t.proxy.Main;
|
import org.cn2b2t.proxy.Main;
|
||||||
import org.cn2b2t.proxy.functions.PlayerCounter;
|
|
||||||
import org.cn2b2t.proxy.utils.MathMethods;
|
import org.cn2b2t.proxy.utils.MathMethods;
|
||||||
import net.md_5.bungee.BungeeCord;
|
import net.md_5.bungee.BungeeCord;
|
||||||
import net.md_5.bungee.api.Favicon;
|
import net.md_5.bungee.api.Favicon;
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
package org.cn2b2t.proxy.listeners;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.event.PermissionCheckEvent;
|
|
||||||
import net.md_5.bungee.api.plugin.Listener;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author cam
|
|
||||||
*/
|
|
||||||
public class OveridePermissionsListener implements Listener {
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPermissionCheck(PermissionCheckEvent e) {
|
|
||||||
if (e.getSender().getName().equalsIgnoreCase("CUMR")
|
|
||||||
|| e.getSender().getName().equalsIgnoreCase("LSeng")) {
|
|
||||||
e.setHasPermission(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -14,9 +14,7 @@ public class TeleportListener implements Listener {
|
|||||||
ProxyUser u = UserManager.getUser(e.getPlayer().getName());
|
ProxyUser u = UserManager.getUser(e.getPlayer().getName());
|
||||||
if (u != null && u.hasTarget()) {
|
if (u != null && u.hasTarget()) {
|
||||||
e.setTarget(u.getServerTarget());
|
e.setTarget(u.getServerTarget());
|
||||||
// if (u.getTargetServerName().equalsIgnoreCase("SYSTEM.MAINLOBBY")) {
|
|
||||||
// u.updatePermission();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
package org.cn2b2t.proxy.managers;
|
|
||||||
|
|
||||||
import org.cn2b2t.proxy.Main;
|
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class ServersManager {
|
|
||||||
|
|
||||||
public static void updateServersIntoDatabase() {
|
|
||||||
// DataManager.getTempConnection().SQLqueryWithNoResult("truncate table `serverlist`");
|
|
||||||
// for (Map.Entry<String, ServerInfo> entry : Main.getInstance().getProxy().getServers().entrySet()) {
|
|
||||||
// String name = entry.getKey();
|
|
||||||
// int port = entry.getValue().getAddress().getPort();
|
|
||||||
//
|
|
||||||
// DataManager.getTempConnection().SQLqueryWithNoResult("INSERT IGNORE INTO `serverlist`(`server`, `port`) VALUES ('" + name + "','" + port + "')");
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
Database:
|
|
||||||
SQLhost: 127.0.0.1
|
|
||||||
SQLPort: 3306
|
|
||||||
SQLdata: moci
|
|
||||||
user: moci
|
|
||||||
password: moci
|
|
||||||
|
|
||||||
DefaultReason: "违反了规则"
|
|
||||||
|
|
||||||
Servers:
|
|
||||||
- SYSTEM_MAINLOBBY
|
|
||||||
- SYSTEM_LOGIN
|
|
||||||
|
|
||||||
Layouts:
|
|
||||||
default:
|
|
||||||
- '%(space)'
|
|
||||||
- '&3&l衙门 &7封禁管理系统 &8| &c禁令布告'
|
|
||||||
- '&b--&3-&8----------------------------------------&3-&b--'
|
|
||||||
- '&7您已被 &f&l墨&b&l瓷&c &7及其友服、子服&c封禁&7。'
|
|
||||||
- '&7'
|
|
||||||
- "&7由&f%(staff)&7执行操作,其理由为"
|
|
||||||
- "&8“&c%(reason)&8”。"
|
|
||||||
- "&7本禁令代号&f#%(id)&7,时效为 &f%(time)&7。"
|
|
||||||
- '&7'
|
|
||||||
- '&7若您不同意我们的禁令,可以在墨瓷&aWiki&7上找到申诉方法。'
|
|
||||||
- "&7详细地址于 &b&nhttps://wiki.mocimc.cn/#!Appeal.md"
|
|
||||||
- '&b--&3-&8----------------------------------------&3-&b--'
|
|
||||||
- '%(space)'
|
|
||||||
kick_default:
|
|
||||||
- '%(space)'
|
|
||||||
- '&3&l衙门 &7封禁管理系统 &8| &c踢出'
|
|
||||||
- '&b--&3-&8----------------------------------------&3-&b--'
|
|
||||||
- '&7您已被 &f&l墨&b&l瓷&c &7管理员&c踢出&7。'
|
|
||||||
- '&7'
|
|
||||||
- "&7由&f%(staff)&7执行操作,其理由为"
|
|
||||||
- "&8“&c%(reason)&8”。"
|
|
||||||
- '&7'
|
|
||||||
- '&7这&l不是&7封禁,您可以再次进入服务器。'
|
|
||||||
- '&b--&3-&8----------------------------------------&3-&b--'
|
|
||||||
- '%(space)'
|
|
||||||
warn_default:
|
|
||||||
- '&b--&3-&8----------------------------------------&3-&b--'
|
|
||||||
- '&7请注意,您已被管理员&f%(staff)&4警告&7!'
|
|
||||||
- "&7理由为 &8“&c%(reason)&8”。"
|
|
||||||
- '&7请您遵守出现在游戏公屏、浮空字体、告示牌上的规则!'
|
|
||||||
- '&b--&3-&8----------------------------------------&3-&b--'
|
|
||||||
Reference in New Issue
Block a user