mirror of
https://e.coding.net/circlecloud/CTZLoginServer.git
synced 2025-01-07 12:39:01 +00:00
change depend fix listen...
This commit is contained in:
parent
59169ad42d
commit
4fc551baeb
@ -1,15 +1,13 @@
|
|||||||
package cn.citycraft.CTZLoginServer;
|
package cn.citycraft.CTZLoginServer;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.plugin.PluginManager;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import cn.citycraft.CTZLoginServer.Socket.CTZLoginServerSocket;
|
||||||
import cn.citycraft.CTZLoginServer.config.Config;
|
import cn.citycraft.CTZLoginServer.config.Config;
|
||||||
|
|
||||||
|
public class CTZLoginServer extends JavaPlugin {
|
||||||
public class CTZLoginServer extends JavaPlugin{
|
|
||||||
public String version;
|
public String version;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
getLogger().info("已卸载!");
|
getLogger().info("已卸载!");
|
||||||
@ -17,17 +15,18 @@ public class CTZLoginServer extends JavaPlugin{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
PluginManager pm = Bukkit.getPluginManager();
|
// PluginManager pm = Bukkit.getPluginManager();
|
||||||
version = this.getServer().getBukkitVersion().substring(0, 5);
|
version = this.getServer().getBukkitVersion().substring(0, 5);
|
||||||
this.getLogger().info("Bukkit 版本: " + version);
|
this.getLogger().info("Bukkit 版本: " + version);
|
||||||
if (pm.isPluginEnabled("AuthMe")) {
|
// if (pm.isPluginEnabled("AuthMe")) {
|
||||||
this.getLogger().info("发现前置插件 AuthMe 载入API...");
|
// this.getLogger().info("发现前置插件 AuthMe 载入API...");
|
||||||
} else {
|
// } else {
|
||||||
this.getLogger().info("未发现 前置插件 AuthMe 关闭插件...");
|
// this.getLogger().info("未发现 前置插件 AuthMe 关闭插件...");
|
||||||
pm.disablePlugin(this);
|
// pm.disablePlugin(this);
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
this.getServer().getScheduler()
|
||||||
|
.runTaskAsynchronously(this, new CTZLoginServerSocket(this, 2000));
|
||||||
getLogger().info("已加载!");
|
getLogger().info("已加载!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,8 +35,3 @@ public class CTZLoginServer extends JavaPlugin{
|
|||||||
Config.load(this, "1.0");
|
Config.load(this, "1.0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,53 +8,68 @@ import java.io.PrintWriter;
|
|||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
|
||||||
public class CTZLoginServerSocket {
|
import cn.citycraft.CTZLoginServer.CTZLoginServer;
|
||||||
|
import fr.xephi.authme.api.API;
|
||||||
|
|
||||||
public static int PORT = 8080;
|
public class CTZLoginServerSocket implements Runnable {
|
||||||
public static void main(String[] agrs) {
|
|
||||||
|
public int PORT = 8080;
|
||||||
|
public CTZLoginServer plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化服务端口
|
||||||
|
*/
|
||||||
|
public CTZLoginServerSocket(CTZLoginServer plugin, int port) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
PORT = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
ServerSocket s = null;
|
ServerSocket s = null;
|
||||||
Socket socket = null;
|
Socket socket = null;
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
PrintWriter pw = null;
|
PrintWriter pw = null;
|
||||||
try {
|
try {
|
||||||
//设定服务端的端口号
|
// 设定服务端的端口号
|
||||||
s = new ServerSocket(PORT);
|
s = new ServerSocket(PORT);
|
||||||
System.out.println("ServerSocket Start:"+s);
|
System.out.println("CTZL服务器开始监听:" + s);
|
||||||
//等待请求,此方法会一直阻塞,直到获得请求才往下走
|
// 等待请求,此方法会一直阻塞,直到获得请求才往下走
|
||||||
socket = s.accept();
|
while (true) {
|
||||||
System.out.println("Connection accept socket:"+socket);
|
socket = s.accept();
|
||||||
//用于接收客户端发来的请求
|
// 用于接收客户端发来的请求
|
||||||
br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
//用于发送返回信息,可以不需要装饰这么多io流使用缓冲流时发送数据要注意调用.flush()方法
|
// 用于发送返回信息,可以不需要装饰这么多io流使用缓冲流时发送数据要注意调用.flush()方法
|
||||||
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);
|
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
|
||||||
while(true){
|
socket.getOutputStream())), true);
|
||||||
String str = br.readLine();
|
while (true) {
|
||||||
if(str.equals("END")){
|
if (socket.isClosed()) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
String str = br.readLine();
|
||||||
|
if (str.equals("END")) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Thread.sleep(1000);
|
||||||
|
API.isRegistered(str);
|
||||||
|
pw.println("Message Received");
|
||||||
|
pw.flush();
|
||||||
}
|
}
|
||||||
System.out.println("Client Socket Message:"+str);
|
|
||||||
Thread.sleep(1000);
|
|
||||||
pw.println("Message Received");
|
|
||||||
pw.flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
System.out.println("CTZL服务器崩溃...");
|
||||||
e.printStackTrace();
|
} finally {
|
||||||
}finally{
|
System.out.println("关闭连接");
|
||||||
System.out.println("Close.....");
|
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
pw.close();
|
pw.close();
|
||||||
socket.close();
|
socket.close();
|
||||||
s.close();
|
s.close();
|
||||||
} catch (Exception e2) {
|
} catch (Exception e2) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
name: CTZLoginServer
|
name: CTZLoginServer
|
||||||
main: cn.citycraft.CTZLoginServer.CTZLoginServer
|
main: cn.citycraft.CTZLoginServer.CTZLoginServer
|
||||||
version: 0.0.1
|
version: 0.0.1
|
||||||
depended: [Authme]
|
depend: [AuthMe]
|
||||||
commands:
|
commands:
|
||||||
ctzl:
|
ctzl:
|
||||||
description: CTZLoginServer Reload.
|
description: CTZLoginServer Reload.
|
||||||
|
Loading…
Reference in New Issue
Block a user