#2259: Have proxy handle keepalives
This commit is contained in:
parent
61cb2df9f3
commit
23554239d0
@ -25,6 +25,12 @@ public class ServerConnection implements Server
|
||||
private boolean isObsolete;
|
||||
@Getter
|
||||
private final boolean forgeServer = false;
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean pingFailed;
|
||||
@Getter
|
||||
@Setter
|
||||
private long sentPingId;
|
||||
|
||||
private final Unsafe unsafe = new Unsafe()
|
||||
{
|
||||
|
@ -91,9 +91,6 @@ public final class UserConnection implements ProxiedPlayer
|
||||
/*========================================================================*/
|
||||
@Getter
|
||||
@Setter
|
||||
private long sentPingId;
|
||||
@Getter
|
||||
@Setter
|
||||
private long sentPingTime;
|
||||
@Getter
|
||||
@Setter
|
||||
|
@ -106,7 +106,7 @@ public class DownstreamBridge extends PacketHandler
|
||||
@Override
|
||||
public void handle(KeepAlive alive) throws Exception
|
||||
{
|
||||
con.setSentPingId( alive.getRandomId() );
|
||||
server.setSentPingId( alive.getRandomId() );
|
||||
con.setSentPingTime( System.currentTimeMillis() );
|
||||
}
|
||||
|
||||
|
@ -116,11 +116,22 @@ public class UpstreamBridge extends PacketHandler
|
||||
@Override
|
||||
public void handle(KeepAlive alive) throws Exception
|
||||
{
|
||||
if ( alive.getRandomId() == con.getSentPingId() )
|
||||
if ( alive.getRandomId() == con.getServer().getSentPingId() )
|
||||
{
|
||||
int newPing = (int) ( System.currentTimeMillis() - con.getSentPingTime() );
|
||||
con.getTabListHandler().onPingChange( newPing );
|
||||
con.setPing( newPing );
|
||||
} else
|
||||
{
|
||||
if ( con.getServer().getSentPingId() != 0 && !con.getServer().isPingFailed() )
|
||||
{
|
||||
alive.setRandomId( con.getServer().getSentPingId() );
|
||||
con.getServer().unsafe().sendPacket( alive );
|
||||
|
||||
con.getServer().setPingFailed( true );
|
||||
}
|
||||
|
||||
throw CancelSendSignal.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user