mirror of
https://github.com/GTNewHorizons/Opis.git
synced 2026-11-22 13:09:53 +00:00
Basic rcon server.
This commit is contained in:
1 parent
256643d671
commit
e96ae1bc4a
3 files changed
+92
-2
No files matched your search
@@ -79,6 +79,8 @@ public class modOpis {
|
||||
public static boolean profilerRun = false;
|
||||
public static boolean profilerRunClient = false;
|
||||
public static int profilerMaxTicks = 250;
|
||||
public static int rconport = 25566;
|
||||
public static boolean rconactive = false;
|
||||
public static boolean microseconds = true;
|
||||
private static int lagGenID = -1;
|
||||
public static CoordinatesBlock selectedBlock = null;
|
||||
@@ -99,7 +101,8 @@ public class modOpis {
|
||||
lagGenID = config.get(Configuration.CATEGORY_GENERAL, "laggenerator_id", -1).getInt();
|
||||
profilerMaxTicks = config.get(Configuration.CATEGORY_GENERAL, "profiler.maxpts", 250).getInt();
|
||||
microseconds = config.get(Configuration.CATEGORY_GENERAL, "display.microseconds", true).getBoolean(true);
|
||||
|
||||
rconport = config.get(Configuration.CATEGORY_GENERAL, "opisrcon.port", 25566).getInt();
|
||||
rconactive = config.get(Configuration.CATEGORY_GENERAL, "opisrcon.active", false).getBoolean(false);
|
||||
|
||||
String[] users = config.get("ACCESS_RIGHTS", "privileged", new String[]{}, commentPrivileged).getStringList();
|
||||
AccessLevel minTables = AccessLevel.PRIVILEGED;
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package mcp.mobius.opis.network.rconserver;
|
||||
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
|
||||
public class RConServer extends ChannelInboundHandlerAdapter implements Runnable {
|
||||
|
||||
public final static RConServer instance = new RConServer();
|
||||
private int port = -1;
|
||||
|
||||
|
||||
private RConServer(){
|
||||
this.port = modOpis.rconport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) {
|
||||
//((ByteBuf) msg).release();
|
||||
|
||||
try {
|
||||
// Do something with msg
|
||||
} finally {
|
||||
ReferenceCountUtil.release(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
cause.printStackTrace();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(){
|
||||
modOpis.log.info("Starting Opis remote control server.");
|
||||
|
||||
EventLoopGroup bossGroup = new NioEventLoopGroup(); // (1)
|
||||
EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||
try {
|
||||
ServerBootstrap b = new ServerBootstrap(); // (2)
|
||||
b.group(bossGroup, workerGroup)
|
||||
.channel(NioServerSocketChannel.class) // (3)
|
||||
.childHandler(new ChannelInitializer<SocketChannel>() { // (4)
|
||||
@Override
|
||||
public void initChannel(SocketChannel ch) throws Exception {
|
||||
ch.pipeline().addLast(RConServer.instance);
|
||||
}
|
||||
})
|
||||
.option(ChannelOption.SO_BACKLOG, 128) // (5)
|
||||
.childOption(ChannelOption.SO_KEEPALIVE, true); // (6)
|
||||
|
||||
// Bind and start to accept incoming connections.
|
||||
ChannelFuture f = b.bind(port).sync(); // (7)
|
||||
|
||||
// Wait until the server socket is closed.
|
||||
// In this example, this does not happen, but you can do that to gracefully
|
||||
// shut down your server.
|
||||
f.channel().closeFuture().sync();
|
||||
} catch (Exception e){
|
||||
modOpis.log.severe("Error in Opis remote control server.");
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
workerGroup.shutdownGracefully();
|
||||
bossGroup.shutdownGracefully();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,14 +3,22 @@ package mcp.mobius.opis.proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.api.IMessageHandler;
|
||||
import mcp.mobius.opis.gui.overlay.OverlayStatus;
|
||||
import mcp.mobius.opis.network.PacketBase;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.rconserver.RConServer;
|
||||
|
||||
public class ProxyServer implements IMessageHandler{
|
||||
|
||||
public void init(){}
|
||||
public void init(){
|
||||
if (modOpis.rconactive){
|
||||
Thread rconserver = new Thread(RConServer.instance);
|
||||
rconserver.setName("Opis Server");
|
||||
rconserver.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(Message msg, PacketBase rawdata) {
|
||||
|
||||
Reference in new issue
Block a user