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() {
|
||||
@Override
|
||||
public void operationComplete(ChannelFuture future) throws Exception {
|
||||
System.err.println("Future start.");
|
||||
if(!future.isSuccess()) {
|
||||
exceptionCaught(null, future.cause());
|
||||
}
|
||||
System.err.println("Future end.");
|
||||
}
|
||||
}).await();
|
||||
|
||||
if(future.isSuccess()) {
|
||||
while(!isConnected()) {
|
||||
try {
|
||||
Thread.sleep(5);
|
||||
} catch(InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(Throwable t) {
|
||||
exceptionCaught(null, t);
|
||||
}
|
||||
|
@ -108,7 +115,6 @@ public class TcpClientSession extends TcpSession {
|
|||
|
||||
if(wait) {
|
||||
connectTask.run();
|
||||
System.err.println("Connect completed.");
|
||||
} else {
|
||||
new Thread(connectTask).start();
|
||||
}
|
||||
|
|
|
@ -85,8 +85,6 @@ public class TcpConnectionListener implements ConnectionListener {
|
|||
pipeline.addLast("sizer", new TcpPacketSizer(session));
|
||||
pipeline.addLast("codec", new TcpPacketCodec(session));
|
||||
pipeline.addLast("manager", session);
|
||||
|
||||
server.addSession(session);
|
||||
}
|
||||
}).group(this.group).localAddress(this.host, this.port).bind();
|
||||
|
||||
|
|
|
@ -21,6 +21,13 @@ public class TcpServerSession extends TcpSession {
|
|||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelActive(ctx);
|
||||
|
||||
this.server.addSession(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelInactive(ctx);
|
||||
|
|
|
@ -308,18 +308,13 @@ public abstract class TcpSession extends SimpleChannelInboundHandler<Packet> imp
|
|||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
System.err.println("Channel active?");
|
||||
if(this.disconnected || this.channel != null) {
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
|
||||
System.err.println("Channel active.");
|
||||
|
||||
this.channel = ctx.channel();
|
||||
|
||||
System.err.println("Channel set.");
|
||||
|
||||
this.packetHandleThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
Loading…
Reference in a new issue