MCSM: указание парольной фразы в конфиге
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
group = 'asys'
|
||||
version = '0.7-SNAPSHOT'
|
||||
version = '0.7.1-SNAPSHOT'
|
||||
|
||||
apply plugin: 'osgi'
|
||||
|
||||
|
||||
@@ -39,9 +39,10 @@ public class Activator implements BundleActivator, ServiceListener {
|
||||
|
||||
String host = config.getString("asys.mcsmanager.host", "127.0.0.1");
|
||||
int port = config.getInt("asys.mcsmanager.port", 8779);
|
||||
String passcode = config.getString("asys.mcsmanager.passcode", "testpasscode");
|
||||
logger.debug("Start server manager: {}:{}", host, port);
|
||||
serverManager = new Server();
|
||||
serverManager.start(host, port);
|
||||
serverManager.start(host, port, passcode);
|
||||
serviceConfigTracker.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,10 @@ public class Server {
|
||||
1, CS_Ping.class
|
||||
);
|
||||
private EventLoopGroup bossGroup, workerGroup;
|
||||
static String passcode;
|
||||
|
||||
public void start(String host, int port) {
|
||||
public void start(String host, int port, String passcode) {
|
||||
Server.passcode = passcode;
|
||||
bossGroup = new NioEventLoopGroup(1);
|
||||
workerGroup = new NioEventLoopGroup();
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ class ServerPacketHandler extends ChannelInboundHandlerAdapter implements IPacke
|
||||
2, SC_HandshakeResult.class
|
||||
);
|
||||
private static Map<Class<? extends Packet>, IPacketHandler> handshakeHandlers;
|
||||
private static final String PASSCODE = "testpassphrase";
|
||||
|
||||
ServerPacketHandler() {
|
||||
if (handshakeHandlers == null) {
|
||||
@@ -46,7 +45,7 @@ class ServerPacketHandler extends ChannelInboundHandlerAdapter implements IPacke
|
||||
}
|
||||
|
||||
private void handleCSHandshake(CS_Handshake packet, ChannelHandlerContext context) {
|
||||
if (!packet.getPasscode().equalsIgnoreCase(PASSCODE)) {
|
||||
if (!packet.getPasscode().equalsIgnoreCase(Server.passcode)) {
|
||||
try {
|
||||
context.channel().writeAndFlush(HandshakeResult.INVALID_PASSCODE).sync().channel().close();
|
||||
} catch (InterruptedException ignore) {
|
||||
|
||||
Reference in New Issue
Block a user