RconThread.java
net.minecraft.server.rcon.thread.RconThread
信息
- 全限定名:net.minecraft.server.rcon.thread.RconThread
- 类型:public class
- 包:net.minecraft.server.rcon.thread
- 源码路径:src/main/java/net/minecraft/server/rcon/thread/RconThread.java
- 起始行号:L16
- 继承:GenericThread
- 职责:
TODO
字段/常量
-
LOGGER- 类型:
Logger - 修饰符:
private static final - 源码定位:
L17 - 说明:
TODO
- 类型:
-
socket- 类型:
ServerSocket - 修饰符:
private final - 源码定位:
L18 - 说明:
TODO
- 类型:
-
rconPassword- 类型:
String - 修饰符:
private final - 源码定位:
L19 - 说明:
TODO
- 类型:
-
clients- 类型:
List<RconClient> - 修饰符:
private final - 源码定位:
L20 - 说明:
TODO
- 类型:
-
serverInterface- 类型:
ServerInterface - 修饰符:
private final - 源码定位:
L21 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
private RconThread(ServerInterface serverInterface, ServerSocket socket, String rconPassword) @ L23
- 构造器名:RconThread
- 源码定位:L23
- 修饰符:private
参数:
- serverInterface: ServerInterface
- socket: ServerSocket
- rconPassword: String
说明:
TODO
方法
下面的方法块按源码顺序生成。
private void clearClients() @ L30
- 方法名:clearClients
- 源码定位:L30
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
public void run() @ L34
- 方法名:run
- 源码定位:L34
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public static RconThread create(ServerInterface serverInterface) @ L57
- 方法名:create
- 源码定位:L57
- 返回类型:RconThread
- 修饰符:public static
参数:
- serverInterface: ServerInterface
说明:
TODO
public void stop() @ L92
- 方法名:stop
- 源码定位:L92
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
private void closeSocket(ServerSocket socket) @ L107
- 方法名:closeSocket
- 源码定位:L107
- 返回类型:void
- 修饰符:private
参数:
- socket: ServerSocket
说明:
TODO
代码
public class RconThread extends GenericThread {
private static final Logger LOGGER = LogUtils.getLogger();
private final ServerSocket socket;
private final String rconPassword;
private final List<RconClient> clients = Lists.newArrayList();
private final ServerInterface serverInterface;
private RconThread(ServerInterface serverInterface, ServerSocket socket, String rconPassword) {
super("RCON Listener");
this.serverInterface = serverInterface;
this.socket = socket;
this.rconPassword = rconPassword;
}
private void clearClients() {
this.clients.removeIf(client -> !client.isRunning());
}
@Override
public void run() {
try {
while (this.running) {
try {
Socket client = this.socket.accept();
RconClient rconClient = new RconClient(this.serverInterface, this.rconPassword, client);
rconClient.start();
this.clients.add(rconClient);
this.clearClients();
} catch (SocketTimeoutException var7) {
this.clearClients();
} catch (IOException var8) {
if (this.running) {
LOGGER.info("IO exception: ", (Throwable)var8);
}
}
}
} finally {
this.closeSocket(this.socket);
}
}
public static @Nullable RconThread create(ServerInterface serverInterface) {
DedicatedServerProperties settings = serverInterface.getProperties();
String serverIp = serverInterface.getServerIp();
if (serverIp.isEmpty()) {
serverIp = "0.0.0.0";
}
int port = settings.rconPort;
if (0 < port && 65535 >= port) {
String password = settings.rconPassword;
if (password.isEmpty()) {
LOGGER.warn("No rcon password set in server.properties, rcon disabled!");
return null;
} else {
try {
ServerSocket socket = new ServerSocket(port, 0, InetAddress.getByName(serverIp));
socket.setSoTimeout(500);
RconThread result = new RconThread(serverInterface, socket, password);
if (!result.start()) {
return null;
} else {
LOGGER.info("RCON running on {}:{}", serverIp, port);
return result;
}
} catch (IOException var7) {
LOGGER.warn("Unable to initialise RCON on {}:{}", serverIp, port, var7);
return null;
}
}
} else {
LOGGER.warn("Invalid rcon port {} found in server.properties, rcon disabled!", port);
return null;
}
}
@Override
public void stop() {
this.running = false;
this.closeSocket(this.socket);
super.stop();
for (RconClient rconClient : this.clients) {
if (rconClient.isRunning()) {
rconClient.stop();
}
}
this.clients.clear();
}
private void closeSocket(ServerSocket socket) {
LOGGER.debug("closeSocket: {}", socket);
try {
socket.close();
} catch (IOException var3) {
LOGGER.warn("Failed to close socket", (Throwable)var3);
}
}
}引用的其他类
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
RconClient()
- 引用位置: