#2259: Have proxy handle keepalives

This commit is contained in:
md_5 2017-09-23 13:18:43 +10:00
parent 61cb2df9f3
commit 23554239d0
4 changed files with 19 additions and 5 deletions

View File

@ -25,6 +25,12 @@ public class ServerConnection implements Server
private boolean isObsolete; private boolean isObsolete;
@Getter @Getter
private final boolean forgeServer = false; private final boolean forgeServer = false;
@Getter
@Setter
private boolean pingFailed;
@Getter
@Setter
private long sentPingId;
private final Unsafe unsafe = new Unsafe() private final Unsafe unsafe = new Unsafe()
{ {

View File

@ -91,9 +91,6 @@ public final class UserConnection implements ProxiedPlayer
/*========================================================================*/ /*========================================================================*/
@Getter @Getter
@Setter @Setter
private long sentPingId;
@Getter
@Setter
private long sentPingTime; private long sentPingTime;
@Getter @Getter
@Setter @Setter

View File

@ -106,7 +106,7 @@ public class DownstreamBridge extends PacketHandler
@Override @Override
public void handle(KeepAlive alive) throws Exception public void handle(KeepAlive alive) throws Exception
{ {
con.setSentPingId( alive.getRandomId() ); server.setSentPingId( alive.getRandomId() );
con.setSentPingTime( System.currentTimeMillis() ); con.setSentPingTime( System.currentTimeMillis() );
} }

View File

@ -116,11 +116,22 @@ public class UpstreamBridge extends PacketHandler
@Override @Override
public void handle(KeepAlive alive) throws Exception 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() ); int newPing = (int) ( System.currentTimeMillis() - con.getSentPingTime() );
con.getTabListHandler().onPingChange( newPing ); con.getTabListHandler().onPingChange( newPing );
con.setPing( 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;
} }
} }