1
0
mirror of https://e.coding.net/circlecloud/CTZLoginServer.git synced 2024-11-16 01:08:49 +00:00

change depend fix listen...

This commit is contained in:
j502647092 2015-07-27 21:14:51 +08:00
parent 59169ad42d
commit 4fc551baeb
3 changed files with 59 additions and 50 deletions

View File

@ -1,15 +1,13 @@
package cn.citycraft.CTZLoginServer;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.CTZLoginServer.Socket.CTZLoginServerSocket;
import cn.citycraft.CTZLoginServer.config.Config;
public class CTZLoginServer extends JavaPlugin{
public class CTZLoginServer extends JavaPlugin {
public String version;
@Override
public void onDisable() {
getLogger().info("已卸载!");
@ -17,17 +15,18 @@ public class CTZLoginServer extends JavaPlugin{
@Override
public void onEnable() {
PluginManager pm = Bukkit.getPluginManager();
// PluginManager pm = Bukkit.getPluginManager();
version = this.getServer().getBukkitVersion().substring(0, 5);
this.getLogger().info("Bukkit 版本: " + version);
if (pm.isPluginEnabled("AuthMe")) {
this.getLogger().info("发现前置插件 AuthMe 载入API...");
} else {
this.getLogger().info("未发现 前置插件 AuthMe 关闭插件...");
pm.disablePlugin(this);
return;
}
// if (pm.isPluginEnabled("AuthMe")) {
// this.getLogger().info("发现前置插件 AuthMe 载入API...");
// } else {
// this.getLogger().info("未发现 前置插件 AuthMe 关闭插件...");
// pm.disablePlugin(this);
// return;
// }
this.getServer().getScheduler()
.runTaskAsynchronously(this, new CTZLoginServerSocket(this, 2000));
getLogger().info("已加载!");
}
@ -36,8 +35,3 @@ public class CTZLoginServer extends JavaPlugin{
Config.load(this, "1.0");
}
}

View File

@ -8,53 +8,68 @@ import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class CTZLoginServerSocket {
import cn.citycraft.CTZLoginServer.CTZLoginServer;
import fr.xephi.authme.api.API;
public static int PORT = 8080;
public static void main(String[] agrs) {
public class CTZLoginServerSocket implements Runnable {
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;
Socket socket = null;
BufferedReader br = null;
PrintWriter pw = null;
try {
//设定服务端的端口号
// 设定服务端的端口号
s = new ServerSocket(PORT);
System.out.println("ServerSocket Start:"+s);
//等待请求,此方法会一直阻塞,直到获得请求才往下走
socket = s.accept();
System.out.println("Connection accept socket:"+socket);
//用于接收客户端发来的请求
br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
//用于发送返回信息,可以不需要装饰这么多io流使用缓冲流时发送数据要注意调用.flush()方法
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);
while(true){
String str = br.readLine();
if(str.equals("END")){
break;
System.out.println("CTZL服务器开始监听:" + s);
// 等待请求,此方法会一直阻塞,直到获得请求才往下走
while (true) {
socket = s.accept();
// 用于接收客户端发来的请求
br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
// 用于发送返回信息,可以不需要装饰这么多io流使用缓冲流时发送数据要注意调用.flush()方法
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
socket.getOutputStream())), true);
while (true) {
if (socket.isClosed()) {
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) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
System.out.println("Close.....");
System.out.println("CTZL服务器崩溃...");
} finally {
System.out.println("关闭连接");
try {
br.close();
pw.close();
socket.close();
s.close();
} catch (Exception e2) {
}
}
}
}

View File

@ -1,7 +1,7 @@
name: CTZLoginServer
main: cn.citycraft.CTZLoginServer.CTZLoginServer
version: 0.0.1
depended: [Authme]
depend: [AuthMe]
commands:
ctzl:
description: CTZLoginServer Reload.