Ping stuffs, doesnt seem to work for some reason though

This commit is contained in:
md_5 2013-10-12 13:51:33 +11:00
parent e0ebf1af21
commit 1551bf6f3a
3 changed files with 42 additions and 33 deletions

View File

@ -1,33 +1,38 @@
package net.md_5.bungee.api; package net.md_5.bungee.api;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
/** /**
* Represents the standard list data returned by opening a server in the * Represents the standard list data returned by opening a server in the
* Minecraft client server list, or hitting it with a packet 0xFE. * Minecraft client server list, or hitting it with a packet 0xFE.
*/ */
@Data @Data
@NoArgsConstructor
@AllArgsConstructor
public class ServerPing public class ServerPing
{ {
/** private Protocol version;
* Numeric protocol version supported by the server.
*/ @Data
private final int protocolVersion; @AllArgsConstructor
/** public static class Protocol
* Human readable game version. {
*/
private final String gameVersion; private String name;
/** private int version;
* Server MOTD. }
*/ private Players players;
private final String motd;
/** @Data
* Current amount of players on the server. @AllArgsConstructor
*/ public static class Players
private final int currentPlayers; {
/**
* Max amount of players the server will allow. private int max;
*/ private int online;
private final int maxPlayers; }
private String description;
} }

View File

@ -50,6 +50,7 @@ import net.md_5.bungee.protocol.packet.LoginRequest;
import net.md_5.bungee.protocol.packet.LoginSuccess; import net.md_5.bungee.protocol.packet.LoginSuccess;
import net.md_5.bungee.protocol.packet.PingPacket; import net.md_5.bungee.protocol.packet.PingPacket;
import net.md_5.bungee.protocol.packet.StatusRequest; import net.md_5.bungee.protocol.packet.StatusRequest;
import net.md_5.bungee.protocol.packet.StatusResponse;
@RequiredArgsConstructor @RequiredArgsConstructor
public class InitialHandler extends PacketHandler implements PendingConnection public class InitialHandler extends PacketHandler implements PendingConnection
@ -102,8 +103,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection
@Override @Override
public void handle(PacketWrapper packet) throws Exception public void handle(PacketWrapper packet) throws Exception
{ {
int len = DefinedPacket.readVarInt( packet.buf ); // int len = DefinedPacket.readVarInt( packet.buf );
int id = DefinedPacket.readVarInt( packet.buf ); // int id = DefinedPacket.readVarInt( packet.buf );
// throw new UnsupportedOperationException( "Cannot handle unknown packet at login!" ); // throw new UnsupportedOperationException( "Cannot handle unknown packet at login!" );
} }
@ -129,6 +130,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection
@Override @Override
public void handle(StatusRequest statusRequest) throws Exception public void handle(StatusRequest statusRequest) throws Exception
{ {
Preconditions.checkState( thisState == State.STATUS, "Not expecting STATUS" );
ServerInfo forced = AbstractReconnectHandler.getForcedHost( this ); ServerInfo forced = AbstractReconnectHandler.getForcedHost( this );
final String motd = ( forced != null ) ? forced.getMotd() : listener.getMotd(); final String motd = ( forced != null ) ? forced.getMotd() : listener.getMotd();
@ -139,18 +142,13 @@ public class InitialHandler extends PacketHandler implements PendingConnection
{ {
if ( error != null ) if ( error != null )
{ {
result = new ServerPing( (byte) -1, "-1", "Error pinging remote server: " + Util.exception( error ), -1, -1 ); result = new ServerPing();
result.setDescription( "Error pinging remote server: " + Util.exception( error ) );
} }
result = bungee.getPluginManager().callEvent( new ProxyPingEvent( InitialHandler.this, result ) ).getResponse(); result = bungee.getPluginManager().callEvent( new ProxyPingEvent( InitialHandler.this, result ) ).getResponse();
String kickMessage = ChatColor.DARK_BLUE
+ "\00" + result.getProtocolVersion()
+ "\00" + result.getGameVersion()
+ "\00" + result.getMotd()
+ "\00" + result.getCurrentPlayers()
+ "\00" + result.getMaxPlayers();
BungeeCord.getInstance().getConnectionThrottle().unthrottle( getAddress().getAddress() ); BungeeCord.getInstance().getConnectionThrottle().unthrottle( getAddress().getAddress() );
disconnect( kickMessage ); unsafe.sendPacket( new StatusResponse( BungeeCord.getInstance().gson.toJson( result ) ) );
} }
}; };
@ -159,8 +157,14 @@ public class InitialHandler extends PacketHandler implements PendingConnection
forced.ping( pingBack ); forced.ping( pingBack );
} else } else
{ {
pingBack.done( new ServerPing( bungee.getProtocolVersion(), bungee.getGameVersion(), motd, bungee.getOnlineCount(), listener.getMaxPlayers() ), null ); pingBack.done( new ServerPing(
new ServerPing.Protocol( bungee.getGameVersion(), bungee.getProtocolVersion() ),
new ServerPing.Players( bungee.getOnlineCount(), listener.getMaxPlayers() ),
motd ),
null );
} }
thisState = State.PING;
} }
@Override @Override

View File

@ -37,8 +37,8 @@ public class PingHandler extends PacketHandler
public void handle(Kick kick) throws Exception public void handle(Kick kick) throws Exception
{ {
String[] split = kick.getMessage().split( "\00" ); String[] split = kick.getMessage().split( "\00" );
ServerPing ping = new ServerPing( Byte.parseByte( split[1] ), split[2], split[3], Integer.parseInt( split[4] ), Integer.parseInt( split[5] ) ); // ServerPing ping = new ServerPing( Byte.parseByte( split[1] ), split[2], split[3], Integer.parseInt( split[4] ), Integer.parseInt( split[5] ) );
callback.done( ping, null ); // callback.done( ping, null );
} }
@Override @Override