Skip to content

Commit

Permalink
除了登录超时没完成外其他功能基本上暂无 bug) (#1)
Browse files Browse the repository at this point in the history
* fix
  • Loading branch information
shulng authored Aug 2, 2024
1 parent 7366fb9 commit a98d786
Show file tree
Hide file tree
Showing 24 changed files with 593 additions and 331 deletions.
26 changes: 17 additions & 9 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,27 @@ on:
push:
branches:
- '*' # 所有分支
tags:
- 'v*'
pull_request:
branches:
- '*' # 所有分支
- '*'

permissions:
contents: write
discussions: write

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
java-version: ['8', '11', '17', '21']

steps:
- uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.java-version }}
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
java-version: 8
distribution: 'temurin'
cache: maven
- name: Build with Maven
Expand All @@ -32,5 +34,11 @@ jobs:
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: CatSeedLogin-${{ matrix.java-version }}
path: target/*.jar
name: CatSeedLogin
path: target/CatSeedLogin*.jar

- name: Create Release and Upload Release Asset
uses: softprops/[email protected]
if: startsWith(github.ref, 'refs/tags/')
with:
files: target/CatSeedLogin*.jar
10 changes: 1 addition & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
{
"java.jdt.ls.java.home": "D:\\Program Files\\Java\\jdk-21",
"java.compile.nullAnalysis.mode": "automatic",
"java.configuration.runtimes": [
{
"name": "JavaSE-21",
"path": "D:\\Program Files\\Java\\jdk-21",
"default": true
},
],
"java.configuration.updateBuildConfiguration": "interactive"
"java.configuration.updateBuildConfiguration": "automatic"
}
15 changes: 10 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.5.0-b01</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>space.arim.morepaperlib</groupId>
<artifactId>morepaperlib</artifactId>
Expand All @@ -87,6 +87,11 @@
<version>2.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>cn.handyplus.lib.adapter</groupId>
<artifactId>FoliaLib</artifactId>
<version>1.1.5</version>
</dependency>
</dependencies>
<repositories>
<!-- Spigot -->
Expand Down
59 changes: 59 additions & 0 deletions src/main/java/cc/baka9/catseedlogin/bukkit/CatScheduler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package cc.baka9.catseedlogin.bukkit;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.bukkit.Location;
import org.bukkit.entity.Player;

import space.arim.morepaperlib.scheduling.ScheduledTask;

public class CatScheduler {
private static final boolean folia = CatSeedLogin.morePaperLib.scheduling().isUsingFolia();
private static final Method teleportAsync = initTeleportAsync();

private static Method initTeleportAsync() {
if (folia) {
try {
return Player.class.getMethod("teleportAsync", Location.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
return null;
}

public static void teleport(Player player, Location location) {
if (!folia) {
player.teleport(location);
return;
}
CatSeedLogin.morePaperLib.scheduling().entitySpecificScheduler(player).run(() -> {
try {
teleportAsync.invoke(player, location);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}, null);
}

public static void updateInventory(Player player) {
CatSeedLogin.morePaperLib.scheduling().entitySpecificScheduler(player).run(player::updateInventory, null);
}

public static ScheduledTask runTaskAsync(Runnable runnable) {
return CatSeedLogin.morePaperLib.scheduling().asyncScheduler().run(runnable);
}

public static ScheduledTask runTaskTimer(Runnable runnable, long delay, long period) {
return CatSeedLogin.morePaperLib.scheduling().globalRegionalScheduler().runAtFixedRate(runnable, delay == 0 ? 1 : delay, period);
}

public static ScheduledTask runTask(Runnable runnable) {
return CatSeedLogin.morePaperLib.scheduling().globalRegionalScheduler().run(runnable);
}

public static ScheduledTask runTaskLater(Runnable runnable, long delay) {
return CatSeedLogin.morePaperLib.scheduling().globalRegionalScheduler().runDelayed(runnable, delay);
}
}
45 changes: 28 additions & 17 deletions src/main/java/cc/baka9/catseedlogin/bukkit/CatSeedLogin.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
package cc.baka9.catseedlogin.bukkit;

import cc.baka9.catseedlogin.bukkit.command.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;

import cc.baka9.catseedlogin.bukkit.command.CommandBindEmail;
import cc.baka9.catseedlogin.bukkit.command.CommandCatSeedLogin;
import cc.baka9.catseedlogin.bukkit.command.CommandChangePassword;
import cc.baka9.catseedlogin.bukkit.command.CommandLogin;
import cc.baka9.catseedlogin.bukkit.command.CommandRegister;
import cc.baka9.catseedlogin.bukkit.command.CommandResetPassword;
import cc.baka9.catseedlogin.bukkit.database.Cache;
import cc.baka9.catseedlogin.bukkit.database.MySQL;
import cc.baka9.catseedlogin.bukkit.database.SQL;
import cc.baka9.catseedlogin.bukkit.database.SQLite;
import cc.baka9.catseedlogin.bukkit.object.LoginPlayerHelper;
import cc.baka9.catseedlogin.bukkit.task.Task;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import cn.handyplus.lib.adapter.HandySchedulerUtil;
import space.arim.morepaperlib.MorePaperLib;

public class CatSeedLogin extends JavaPlugin {

public static CatSeedLogin instance;
public static BukkitScheduler scheduler = Bukkit.getScheduler();
public static SQL sql;
public static boolean loadProtocolLib = false;
public static MorePaperLib morePaperLib;

@Override
public void onEnable(){
instance = this;
morePaperLib = new MorePaperLib(this);
HandySchedulerUtil.init(this);
//Config
try {
Config.load();
Expand All @@ -48,12 +57,14 @@ public void onEnable(){
getServer().getPluginManager().registerEvents(new Listeners(), this);

//ProtocolLibListeners
try {
Class.forName("com.comphenix.protocol.ProtocolLib");
ProtocolLibListeners.enable();
loadProtocolLib = true;
} catch (ClassNotFoundException e) {
getLogger().warning("服务器没有装载ProtocolLib插件,这将无法使用登录前隐藏背包");
if (Config.Settings.Emptybackpack) {
try {
Class.forName("com.comphenix.protocol.ProtocolLib");
ProtocolLibListeners.enable();
loadProtocolLib = true;
} catch (ClassNotFoundException e) {
getLogger().warning("服务器没有装载ProtocolLib插件,这将无法使用登录前隐藏背包");
}
}

// bc
Expand Down Expand Up @@ -141,7 +152,7 @@ public void onDisable(){
}

public void runTaskAsync(Runnable runnable){
scheduler.runTaskAsynchronously(this, runnable);
CatScheduler.runTaskAsync(runnable);
}


Expand Down
34 changes: 31 additions & 3 deletions src/main/java/cc/baka9/catseedlogin/bukkit/CatSeedLoginAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,42 @@

import cc.baka9.catseedlogin.bukkit.object.LoginPlayerHelper;

/**
* API
*
* @author handy
*/
public class CatSeedLoginAPI {
public static boolean isLogin(String name){

/**
* 是否登陆
*
* @param name 玩家名
* @return true 是
*/
public static boolean isLogin(String name) {
return LoginPlayerHelper.isLogin(name);
}

public static boolean isRegister(String name){

/**
* 是否注册
*
* @param name 玩家名
* @return true 注册
*/
public static boolean isRegister(String name) {
return LoginPlayerHelper.isRegister(name);
}

/**
* 获取最后登陆时间戳
*
* @param name 玩家名
* @return 时间戳- 未注册为null
* @since 1.4.2
*/
public static Long getLastLoginTime(String name) {
return LoginPlayerHelper.getLastLoginTime(name);
}

}
33 changes: 21 additions & 12 deletions src/main/java/cc/baka9/catseedlogin/bukkit/Communication.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package cc.baka9.catseedlogin.bukkit;

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.CommunicationAuth;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
Expand All @@ -15,6 +8,14 @@
import java.net.Socket;
import java.net.UnknownHostException;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

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.CommunicationAuth;

/**
* bukkit 与 bc 的通讯交流
*/
Expand Down Expand Up @@ -75,9 +76,13 @@ private static void socketServerStart() {
/**
* 处理请求
*/
private static void handleRequest(Socket socket) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
private static void handleRequest(Socket socket) throws IOException {
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()))) {
String requestType = bufferedReader.readLine();
if (requestType == null) {
socket.close();
return;
}
String playerName = bufferedReader.readLine();
switch (requestType) {
case "Connect":
Expand All @@ -87,19 +92,23 @@ private static void handleRequest(Socket socket) throws IOException {
String time = bufferedReader.readLine();
String sign = bufferedReader.readLine();
handleKeepLoggedInRequest(playerName, time, sign);
socket.close();
break;
default:
break;
}
} finally {
if (!socket.isClosed()) {
socket.close();
}
}
}

private static void handleKeepLoggedInRequest(String playerName, String time, String sign) {
// 验证请求的合法性
// 对比玩家名,时间戳,和authKey加密的结果(加密是因为如果登录服不在内网环境下,则可能会被人使用这个功能给发包来直接绕过登录)
if (CommunicationAuth.encryption(playerName, time, Config.BungeeCord.AuthKey).equals(sign)) {
// 切换主线程给予登录状态
Bukkit.getScheduler().runTask(CatSeedLogin.instance, () -> {
CatScheduler.runTask( () -> {
LoginPlayer lp = Cache.getIgnoreCase(playerName);
if (lp != null) {
LoginPlayerHelper.add(lp);
Expand All @@ -115,7 +124,7 @@ private static void handleKeepLoggedInRequest(String playerName, String time, St

private static void handleConnectRequest(Socket socket, String playerName) {
// 切换主线程获取是否已登录
Bukkit.getScheduler().runTask(CatSeedLogin.instance, () -> {
CatScheduler.runTask( () -> {
boolean result = LoginPlayerHelper.isLogin(playerName);

// 切换异步线程返回结果
Expand Down
Loading

0 comments on commit a98d786

Please sign in to comment.