From ff32764f9a072c71bc034ebbfc79a21273d3eb18 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 28 Apr 2013 11:19:19 +1000 Subject: [PATCH] Encapsulate ping fields --- .../main/java/net/md_5/bungee/UserConnection.java | 12 ++++++++---- .../net/md_5/bungee/connection/DownstreamBridge.java | 4 ++-- .../net/md_5/bungee/connection/UpstreamBridge.java | 8 ++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index d24ce99b1..7519faabd 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -54,14 +54,18 @@ public final class UserConnection implements ProxiedPlayer // reconnect stuff public int clientEntityId; public int serverEntityId; - // ping stuff - public int trackingPingId; - public long pingTime; @Getter private String displayName; + /*========================================================================*/ @Getter @Setter - private int ping = 1000; + private int sentPingId; + @Getter + @Setter + private long sentPingTime; + @Getter + @Setter + private int ping = 100; /*========================================================================*/ private final Collection groups = new HashSet<>(); private final Collection permissions = new HashSet<>(); diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java index f79bb7333..c0d177707 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java @@ -78,8 +78,8 @@ public class DownstreamBridge extends PacketHandler @Override public void handle(Packet0KeepAlive alive) throws Exception { - con.trackingPingId = alive.id; - con.pingTime = System.currentTimeMillis(); + con.setSentPingId( alive.id ); + con.setSentPingTime( System.currentTimeMillis() ); } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java index 82060e900..7ecb736df 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -31,12 +31,12 @@ public class UpstreamBridge extends PacketHandler BungeeCord.getInstance().connections.put( con.getName(), con ); bungee.getTabListHandler().onConnect( con ); - con.sendPacket(BungeeCord.getInstance().registerChannels() ); + con.sendPacket( BungeeCord.getInstance().registerChannels() ); TexturePackInfo texture = con.getPendingConnection().getListener().getTexturePack(); if ( texture != null ) { - con.sendPacket(new PacketFAPluginMessage( "MC|TPack", ( texture.getUrl() + "\00" + texture.getSize() ).getBytes() ) ); + con.sendPacket( new PacketFAPluginMessage( "MC|TPack", ( texture.getUrl() + "\00" + texture.getSize() ).getBytes() ) ); } } @@ -74,9 +74,9 @@ public class UpstreamBridge extends PacketHandler @Override public void handle(Packet0KeepAlive alive) throws Exception { - if ( alive.id == con.trackingPingId ) + if ( alive.id == con.getSentPingId() ) { - int newPing = (int) ( System.currentTimeMillis() - con.pingTime ); + int newPing = (int) ( System.currentTimeMillis() - con.getSentPingTime() ); bungee.getTabListHandler().onPingChange( con, newPing ); con.setPing( newPing ); }