Skip to content

Commit

Permalink
feat: 添加同一IP玩家登录跳过功能
Browse files Browse the repository at this point in the history
  • Loading branch information
shulng committed Jul 11, 2024
1 parent 5ed0920 commit 0929b98
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static boolean isRegister(String name) {
* @return 时间戳- 未注册为null
* @since 1.4.2
*/
public static Long getLastLoginTime(String name) {
public static boolean getLastLoginTime(String name) {
return LoginPlayerHelper.getLastLoginTime(name);
}

Expand Down
29 changes: 21 additions & 8 deletions src/main/java/cc/baka9/catseedlogin/bukkit/Config.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
package cc.baka9.catseedlogin.bukkit;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
Expand All @@ -8,14 +25,6 @@
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;

import java.io.*;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
* 加载/保存/重载 yml配置文件
* config.yml 玩家退出服务器的位置
Expand Down Expand Up @@ -75,6 +84,7 @@ public static class Settings {
public static Location SpawnLocation;
public static boolean LimitChineseID;
public static boolean BedrockLoginBypass;
public static boolean LoginwiththesameIP;
public static int MaxLengthID;
public static int MinLengthID;
public static boolean BeforeLoginNoDamage;
Expand All @@ -96,6 +106,7 @@ public static void load(){
LimitChineseID = config.getBoolean("LimitChineseID", resourceConfig.getBoolean("LimitChineseID"));
MinLengthID = config.getInt("MinLengthID", resourceConfig.getInt("MinLengthID"));
BedrockLoginBypass = config.getBoolean("BedrockLoginBypass", resourceConfig.getBoolean("BedrockLoginBypass"));
LoginwiththesameIP = config.getBoolean("LoginwiththesameIP", resourceConfig.getBoolean("LoginwiththesameIP"));
MaxLengthID = config.getInt("MaxLengthID", resourceConfig.getInt("MaxLengthID"));
BeforeLoginNoDamage = config.getBoolean("BeforeLoginNoDamage", resourceConfig.getBoolean("BeforeLoginNoDamage"));
ReenterInterval = config.getLong("ReenterInterval", resourceConfig.getLong("ReenterInterval"));
Expand All @@ -122,6 +133,7 @@ public static void save(){
config.set("SpawnWorld", null);
config.set("LimitChineseID", LimitChineseID);
config.set("BedrockLoginBypass",BedrockLoginBypass);
config.set("LoginwiththesameIP",LoginwiththesameIP);
config.set("MinLengthID", MinLengthID);
config.set("MaxLengthID", MaxLengthID);
config.set("BeforeLoginNoDamage", BeforeLoginNoDamage);
Expand Down Expand Up @@ -175,6 +187,7 @@ public static class Language {
public static String AUTO_KICK;
public static String REGISTER_MORE;
public static String BEDROCK_LOGIN_BYPASS;
public static String LOGIN_WITH_THE_SAME_IP;

public static void load(){
FileConfiguration resourceConfig = getResourceConfig("language.yml");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package cc.baka9.catseedlogin.bukkit.command;

import java.util.Optional;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import cc.baka9.catseedlogin.bukkit.CatSeedLogin;
import cc.baka9.catseedlogin.bukkit.Config;
import cc.baka9.catseedlogin.bukkit.database.Cache;
Expand All @@ -8,13 +16,6 @@
import cc.baka9.catseedlogin.bukkit.object.LoginPlayerHelper;
import cc.baka9.catseedlogin.util.Mail;
import cc.baka9.catseedlogin.util.Util;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.Optional;


public class CommandBindEmail implements CommandExecutor {
Expand All @@ -28,6 +29,9 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
if (Config.Settings.BedrockLoginBypass && LoginPlayerHelper.isFloodgatePlayer(player)){
return true;
}
if (Config.Settings.LoginwiththesameIP && LoginPlayerHelper.getLastLoginTime(player)){
return true;
}
LoginPlayer lp = Cache.getIgnoreCase(name);

if (lp == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
package cc.baka9.catseedlogin.bukkit.command;

import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import cc.baka9.catseedlogin.bukkit.CatSeedLogin;
import cc.baka9.catseedlogin.bukkit.Communication;
import cc.baka9.catseedlogin.bukkit.Config;
Expand All @@ -9,15 +19,6 @@
import cc.baka9.catseedlogin.bukkit.object.LoginPlayer;
import cc.baka9.catseedlogin.bukkit.object.LoginPlayerHelper;
import cc.baka9.catseedlogin.util.Util;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class CommandCatSeedLogin implements CommandExecutor {
@Override
Expand All @@ -28,6 +29,7 @@ public boolean onCommand(CommandSender sender, Command command, String lable, St
|| setIpCountLimit(sender, args)
|| limitChineseID(sender, args)
|| bedrockLoginBypass(sender, args)
|| LoginwiththesameIP(sender, args)
|| setIdLength(sender, args)
|| beforeLoginNoDamage(sender, args)
|| setReenterInterval(sender, args)
Expand Down Expand Up @@ -213,6 +215,16 @@ private boolean bedrockLoginBypass(CommandSender sender, String[] args){
return false;
}

private boolean LoginwiththesameIP(CommandSender sender, String[] args){
if (args.length > 0 && args[0].equalsIgnoreCase("LoginwiththesameIP")) {
Config.Settings.LoginwiththesameIP = !Config.Settings.LoginwiththesameIP;
Config.Settings.save();
sender.sendMessage("§e同一IP玩家登录跳过 " + (Config.Settings.LoginwiththesameIP ? "§a开启" : "§8关闭"));
return true;
}
return false;
}

private boolean setIpCountLimit(CommandSender sender, String[] args){
if (args.length > 1 && args[0].equalsIgnoreCase("setIpCountLimit")) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package cc.baka9.catseedlogin.bukkit.command;

import cc.baka9.catseedlogin.bukkit.CatSeedLogin;
import cc.baka9.catseedlogin.bukkit.Config;
import cc.baka9.catseedlogin.util.Crypt;
import cc.baka9.catseedlogin.util.Util;
import cc.baka9.catseedlogin.bukkit.database.Cache;
import cc.baka9.catseedlogin.bukkit.object.LoginPlayer;
import cc.baka9.catseedlogin.bukkit.object.LoginPlayerHelper;
import java.util.Objects;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.Objects;
import cc.baka9.catseedlogin.bukkit.CatSeedLogin;
import cc.baka9.catseedlogin.bukkit.Config;
import cc.baka9.catseedlogin.bukkit.database.Cache;
import cc.baka9.catseedlogin.bukkit.object.LoginPlayer;
import cc.baka9.catseedlogin.bukkit.object.LoginPlayerHelper;
import cc.baka9.catseedlogin.util.Crypt;
import cc.baka9.catseedlogin.util.Util;

public class CommandChangePassword implements CommandExecutor {
@Override
Expand All @@ -25,6 +26,9 @@ public boolean onCommand(CommandSender sender, Command command, String lable, St
if (Config.Settings.BedrockLoginBypass && LoginPlayerHelper.isFloodgatePlayer((Player) sender)){
return true;
}
if (Config.Settings.LoginwiththesameIP && LoginPlayerHelper.getLastLoginTime((Player) sender)){
return true;
}
LoginPlayer lp = Cache.getIgnoreCase(name);
if (lp == null) {
sender.sendMessage(Config.Language.CHANGEPASSWORD_NOREGISTER);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package cc.baka9.catseedlogin.bukkit.command;

import cc.baka9.catseedlogin.bukkit.Config;
import cc.baka9.catseedlogin.bukkit.database.Cache;
import cc.baka9.catseedlogin.bukkit.event.CatSeedPlayerLoginEvent;
import cc.baka9.catseedlogin.bukkit.object.LoginPlayer;
import cc.baka9.catseedlogin.bukkit.object.LoginPlayerHelper;
import cc.baka9.catseedlogin.util.Crypt;
import java.util.Objects;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.Objects;
import cc.baka9.catseedlogin.bukkit.Config;
import cc.baka9.catseedlogin.bukkit.database.Cache;
import cc.baka9.catseedlogin.bukkit.event.CatSeedPlayerLoginEvent;
import cc.baka9.catseedlogin.bukkit.object.LoginPlayer;
import cc.baka9.catseedlogin.bukkit.object.LoginPlayerHelper;
import cc.baka9.catseedlogin.util.Crypt;

public class CommandLogin implements CommandExecutor {
@Override
Expand All @@ -23,6 +24,9 @@ public boolean onCommand(CommandSender sender, Command command, String lable, St
if (Config.Settings.BedrockLoginBypass && LoginPlayerHelper.isFloodgatePlayer(player)){
return true;
}
if (Config.Settings.LoginwiththesameIP && LoginPlayerHelper.getLastLoginTime(player)){
return true;
}
if (LoginPlayerHelper.isLogin(name)) {
sender.sendMessage(Config.Language.LOGIN_REPEAT);
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package cc.baka9.catseedlogin.bukkit.command;

import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import cc.baka9.catseedlogin.bukkit.CatSeedLogin;
import cc.baka9.catseedlogin.bukkit.Config;
import cc.baka9.catseedlogin.bukkit.database.Cache;
import cc.baka9.catseedlogin.bukkit.event.CatSeedPlayerRegisterEvent;
import cc.baka9.catseedlogin.bukkit.object.LoginPlayer;
import cc.baka9.catseedlogin.bukkit.object.LoginPlayerHelper;
import cc.baka9.catseedlogin.util.Util;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.List;

public class CommandRegister implements CommandExecutor {

Expand All @@ -25,6 +26,9 @@ public boolean onCommand(CommandSender sender, Command command, String lable, St
if (Config.Settings.BedrockLoginBypass && LoginPlayerHelper.isFloodgatePlayer(player)){
return true;
}
if (Config.Settings.LoginwiththesameIP && LoginPlayerHelper.getLastLoginTime(player)){
return true;
}
if (LoginPlayerHelper.isLogin(name)) {
sender.sendMessage(Config.Language.REGISTER_AFTER_LOGIN_ALREADY);
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package cc.baka9.catseedlogin.bukkit.command;

import java.util.Optional;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import cc.baka9.catseedlogin.bukkit.CatSeedLogin;
import cc.baka9.catseedlogin.bukkit.Config;
import cc.baka9.catseedlogin.bukkit.database.Cache;
Expand All @@ -8,13 +16,6 @@
import cc.baka9.catseedlogin.bukkit.object.LoginPlayerHelper;
import cc.baka9.catseedlogin.util.Mail;
import cc.baka9.catseedlogin.util.Util;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.Optional;

public class CommandResetPassword implements CommandExecutor {
@Override
Expand All @@ -25,6 +26,9 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
if (Config.Settings.BedrockLoginBypass && LoginPlayerHelper.isFloodgatePlayer(player)){
return true;
}
if (Config.Settings.LoginwiththesameIP && LoginPlayerHelper.getLastLoginTime(player)){
return true;
}
LoginPlayer lp = Cache.getIgnoreCase(name);

if (lp == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public static boolean isLogin(String name){
if (Config.Settings.BedrockLoginBypass && isFloodgatePlayer(name)){
return true;
}
if (Config.Settings.LoginwiththesameIP && getLastLoginTime(name)){
return true;
}
for (LoginPlayer lp : set) {
if (lp.getName().equals(name)) {
return true;
Expand All @@ -74,10 +77,27 @@ public static boolean isRegister(String name){
if (Config.Settings.BedrockLoginBypass && isFloodgatePlayer(name)){
return true;
}
if (Config.Settings.LoginwiththesameIP && getLastLoginTime(name)){
return true;
}
return Cache.getIgnoreCase(name) != null;

}

public static boolean getLastLoginTime(String name) {
Player player = Bukkit.getPlayerExact(name);
return player != null && getLastLoginTime(player);
}

public static boolean getLastLoginTime(Player player) {
return Bukkit.getPluginManager().getPlugin("floodgate") != null && FloodgateApi.getInstance().isFloodgatePlayer(player.getUniqueId());
}






public static boolean isFloodgatePlayer(String name) {
Player player = Bukkit.getPlayerExact(name);
return player != null && isFloodgatePlayer(player);
Expand All @@ -87,12 +107,12 @@ public static boolean isFloodgatePlayer(Player player) {
return Bukkit.getPluginManager().getPlugin("floodgate") != null && FloodgateApi.getInstance().isFloodgatePlayer(player.getUniqueId());
}

public static Long getLastLoginTime(String name) {
public static boolean isLastLoginTime(String name) {
LoginPlayer loginPlayer = Cache.getIgnoreCase(name);
if (loginPlayer == null) {
return null;
return false;
}
return loginPlayer.getLastAction();
return loginPlayer.getLastAction() != 0;
}

// 记录登录IP
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/language.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ CHANGEPASSWORD_PASSWORD_CONFIRM_FAIL: "&c你两次输入的密码不一样!"
CHANGEPASSWORD_SUCCESS: "&a修改成功! 请重新登录~"
AUTO_KICK: "&a你因{time}秒内没有登陆,已被系统踢出服务器"
BEDROCK_LOGIN_BYPASS: "&a检测到基岩版玩家,已跳过登录"

LOGIN_WITH_THE_SAME_IP: "&a检测到同一IP地址的玩家,已跳过登录"
Loading

0 comments on commit 0929b98

Please sign in to comment.