mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-12-12 08:41:00 -05:00
Ensure channel is set before returning from connect().
This commit is contained in:
parent
310de7c490
commit
34c2a5c291
4 changed files with 16 additions and 10 deletions
|
@ -93,13 +93,20 @@ public class TcpClientSession extends TcpSession {
|
||||||
future.addListener(new ChannelFutureListener() {
|
future.addListener(new ChannelFutureListener() {
|
||||||
@Override
|
@Override
|
||||||
public void operationComplete(ChannelFuture future) throws Exception {
|
public void operationComplete(ChannelFuture future) throws Exception {
|
||||||
System.err.println("Future start.");
|
|
||||||
if(!future.isSuccess()) {
|
if(!future.isSuccess()) {
|
||||||
exceptionCaught(null, future.cause());
|
exceptionCaught(null, future.cause());
|
||||||
}
|
}
|
||||||
System.err.println("Future end.");
|
|
||||||
}
|
}
|
||||||
}).await();
|
}).await();
|
||||||
|
|
||||||
|
if(future.isSuccess()) {
|
||||||
|
while(!isConnected()) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(5);
|
||||||
|
} catch(InterruptedException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch(Throwable t) {
|
} catch(Throwable t) {
|
||||||
exceptionCaught(null, t);
|
exceptionCaught(null, t);
|
||||||
}
|
}
|
||||||
|
@ -108,7 +115,6 @@ public class TcpClientSession extends TcpSession {
|
||||||
|
|
||||||
if(wait) {
|
if(wait) {
|
||||||
connectTask.run();
|
connectTask.run();
|
||||||
System.err.println("Connect completed.");
|
|
||||||
} else {
|
} else {
|
||||||
new Thread(connectTask).start();
|
new Thread(connectTask).start();
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,8 +85,6 @@ public class TcpConnectionListener implements ConnectionListener {
|
||||||
pipeline.addLast("sizer", new TcpPacketSizer(session));
|
pipeline.addLast("sizer", new TcpPacketSizer(session));
|
||||||
pipeline.addLast("codec", new TcpPacketCodec(session));
|
pipeline.addLast("codec", new TcpPacketCodec(session));
|
||||||
pipeline.addLast("manager", session);
|
pipeline.addLast("manager", session);
|
||||||
|
|
||||||
server.addSession(session);
|
|
||||||
}
|
}
|
||||||
}).group(this.group).localAddress(this.host, this.port).bind();
|
}).group(this.group).localAddress(this.host, this.port).bind();
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,13 @@ public class TcpServerSession extends TcpSession {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
super.channelActive(ctx);
|
||||||
|
|
||||||
|
this.server.addSession(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||||
super.channelInactive(ctx);
|
super.channelInactive(ctx);
|
||||||
|
|
|
@ -308,18 +308,13 @@ public abstract class TcpSession extends SimpleChannelInboundHandler<Packet> imp
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||||
System.err.println("Channel active?");
|
|
||||||
if(this.disconnected || this.channel != null) {
|
if(this.disconnected || this.channel != null) {
|
||||||
ctx.channel().close();
|
ctx.channel().close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.err.println("Channel active.");
|
|
||||||
|
|
||||||
this.channel = ctx.channel();
|
this.channel = ctx.channel();
|
||||||
|
|
||||||
System.err.println("Channel set.");
|
|
||||||
|
|
||||||
this.packetHandleThread = new Thread(new Runnable() {
|
this.packetHandleThread = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
Loading…
Reference in a new issue