mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-24 03:05:49 +01:00
Ping stuffs, doesnt seem to work for some reason though
This commit is contained in:
parent
e0ebf1af21
commit
1551bf6f3a
@ -1,33 +1,38 @@
|
||||
package net.md_5.bungee.api;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Represents the standard list data returned by opening a server in the
|
||||
* Minecraft client server list, or hitting it with a packet 0xFE.
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ServerPing
|
||||
{
|
||||
|
||||
/**
|
||||
* Numeric protocol version supported by the server.
|
||||
*/
|
||||
private final int protocolVersion;
|
||||
/**
|
||||
* Human readable game version.
|
||||
*/
|
||||
private final String gameVersion;
|
||||
/**
|
||||
* Server MOTD.
|
||||
*/
|
||||
private final String motd;
|
||||
/**
|
||||
* Current amount of players on the server.
|
||||
*/
|
||||
private final int currentPlayers;
|
||||
/**
|
||||
* Max amount of players the server will allow.
|
||||
*/
|
||||
private final int maxPlayers;
|
||||
private Protocol version;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public static class Protocol
|
||||
{
|
||||
|
||||
private String name;
|
||||
private int version;
|
||||
}
|
||||
private Players players;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public static class Players
|
||||
{
|
||||
|
||||
private int max;
|
||||
private int online;
|
||||
}
|
||||
private String description;
|
||||
}
|
||||
|
@ -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.PingPacket;
|
||||
import net.md_5.bungee.protocol.packet.StatusRequest;
|
||||
import net.md_5.bungee.protocol.packet.StatusResponse;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
@ -102,8 +103,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
@Override
|
||||
public void handle(PacketWrapper packet) throws Exception
|
||||
{
|
||||
int len = DefinedPacket.readVarInt( packet.buf );
|
||||
int id = DefinedPacket.readVarInt( packet.buf );
|
||||
// int len = DefinedPacket.readVarInt( packet.buf );
|
||||
// int id = DefinedPacket.readVarInt( packet.buf );
|
||||
// throw new UnsupportedOperationException( "Cannot handle unknown packet at login!" );
|
||||
}
|
||||
|
||||
@ -129,6 +130,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
@Override
|
||||
public void handle(StatusRequest statusRequest) throws Exception
|
||||
{
|
||||
Preconditions.checkState( thisState == State.STATUS, "Not expecting STATUS" );
|
||||
|
||||
ServerInfo forced = AbstractReconnectHandler.getForcedHost( this );
|
||||
final String motd = ( forced != null ) ? forced.getMotd() : listener.getMotd();
|
||||
|
||||
@ -139,18 +142,13 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
{
|
||||
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();
|
||||
|
||||
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() );
|
||||
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 );
|
||||
} 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
|
||||
|
@ -37,8 +37,8 @@ public class PingHandler extends PacketHandler
|
||||
public void handle(Kick kick) throws Exception
|
||||
{
|
||||
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] ) );
|
||||
callback.done( ping, null );
|
||||
// ServerPing ping = new ServerPing( Byte.parseByte( split[1] ), split[2], split[3], Integer.parseInt( split[4] ), Integer.parseInt( split[5] ) );
|
||||
// callback.done( ping, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user