Compare commits
6 Commits
2a19bfb6d3
...
93cbdab1f6
Author | SHA1 | Date | |
---|---|---|---|
93cbdab1f6 | |||
46c233d032 | |||
89053d2254 | |||
5932730744 | |||
3d89980065 | |||
21880c668a |
@ -23,4 +23,4 @@ Binaries
|
||||
--------
|
||||
Precompiled binaries are available for end users on [Jenkins](https://www.spigotmc.org/go/bungeecord-dl).
|
||||
|
||||
(c) 2012-2025 SpigotMC Pty. Ltd.
|
||||
(c) 2012-2024 SpigotMC Pty. Ltd.
|
||||
|
@ -6,12 +6,12 @@
|
||||
<parent>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-API</name>
|
||||
|
@ -16,7 +16,6 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.api.plugin.PluginManager;
|
||||
import net.md_5.bungee.api.scheduler.TaskScheduler;
|
||||
import net.md_5.bungee.protocol.channel.BungeeChannelInitializer;
|
||||
|
||||
public abstract class ProxyServer
|
||||
{
|
||||
@ -312,56 +311,4 @@ public abstract class ProxyServer
|
||||
*/
|
||||
public abstract Title createTitle();
|
||||
|
||||
/**
|
||||
* Get the unsafe methods of this class.
|
||||
*
|
||||
* @return the unsafe method interface
|
||||
*/
|
||||
public abstract Unsafe unsafe();
|
||||
|
||||
public interface Unsafe
|
||||
{
|
||||
|
||||
/**
|
||||
* Gets the frontend channel initializer
|
||||
*
|
||||
* @return the frontend channel initializer
|
||||
*/
|
||||
BungeeChannelInitializer getFrontendChannelInitializer();
|
||||
|
||||
/**
|
||||
* Set the frontend channel initializer of this proxy
|
||||
*
|
||||
* @param channelInitializer the frontend channelInitializer to set
|
||||
*/
|
||||
void setFrontendChannelInitializer(BungeeChannelInitializer channelInitializer);
|
||||
|
||||
/**
|
||||
* Gets the backend channel initializer
|
||||
*
|
||||
* @return the backend channel initializer
|
||||
*/
|
||||
BungeeChannelInitializer getBackendChannelInitializer();
|
||||
|
||||
/**
|
||||
* Set the backend channel initializer of this proxy
|
||||
*
|
||||
* @param channelInitializer the backend channelInitializer to set
|
||||
*/
|
||||
void setBackendChannelInitializer(BungeeChannelInitializer channelInitializer);
|
||||
|
||||
/**
|
||||
* Gets the server info channel initializer
|
||||
*
|
||||
* @return the server info channel initializer
|
||||
*/
|
||||
BungeeChannelInitializer getServerInfoChannelInitializer();
|
||||
|
||||
/**
|
||||
* Set the server info channel initializer of this proxy
|
||||
*
|
||||
* @param channelInitializer the server info channelInitializer to set
|
||||
*/
|
||||
void setServerInfoChannelInitializer(BungeeChannelInitializer channelInitializer);
|
||||
}
|
||||
}
|
||||
|
@ -84,15 +84,5 @@ public interface Connection
|
||||
* @param packet the packet to send
|
||||
*/
|
||||
void sendPacket(DefinedPacket packet);
|
||||
|
||||
/**
|
||||
* Queue a packet to this connection.
|
||||
* If the packet is not registered for the connections current encoder protocol, it will be queued until it is,
|
||||
* otherwise it will be sent immediately.
|
||||
*
|
||||
* @param packet the packet to be queued
|
||||
* @throws UnsupportedOperationException if used for a PendingConnection
|
||||
*/
|
||||
void sendPacketQueued(DefinedPacket packet);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package net.md_5.bungee.api.event;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
@ -11,7 +10,6 @@ import net.md_5.bungee.api.plugin.Event;
|
||||
* Called when somebody reloads BungeeCord
|
||||
*/
|
||||
@Getter
|
||||
@ToString(callSuper = false)
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class ProxyReloadEvent extends Event
|
||||
|
@ -23,10 +23,6 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.logging.Level;
|
||||
@ -63,9 +59,6 @@ public final class PluginManager
|
||||
private final Multimap<Plugin, Command> commandsByPlugin = ArrayListMultimap.create();
|
||||
private final Multimap<Plugin, Listener> listenersByPlugin = ArrayListMultimap.create();
|
||||
|
||||
private final ReadWriteLock commandsLock = new ReentrantReadWriteLock();
|
||||
private final Lock listenersLock = new ReentrantLock();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public PluginManager(ProxyServer proxy)
|
||||
{
|
||||
@ -100,19 +93,12 @@ public final class PluginManager
|
||||
*/
|
||||
public void registerCommand(Plugin plugin, Command command)
|
||||
{
|
||||
commandsLock.writeLock().lock();
|
||||
try
|
||||
commandMap.put( command.getName().toLowerCase( Locale.ROOT ), command );
|
||||
for ( String alias : command.getAliases() )
|
||||
{
|
||||
commandMap.put( command.getName().toLowerCase( Locale.ROOT ), command );
|
||||
for ( String alias : command.getAliases() )
|
||||
{
|
||||
commandMap.put( alias.toLowerCase( Locale.ROOT ), command );
|
||||
}
|
||||
commandsByPlugin.put( plugin, command );
|
||||
} finally
|
||||
{
|
||||
commandsLock.writeLock().unlock();
|
||||
commandMap.put( alias.toLowerCase( Locale.ROOT ), command );
|
||||
}
|
||||
commandsByPlugin.put( plugin, command );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -122,15 +108,8 @@ public final class PluginManager
|
||||
*/
|
||||
public void unregisterCommand(Command command)
|
||||
{
|
||||
commandsLock.writeLock().lock();
|
||||
try
|
||||
{
|
||||
while ( commandMap.values().remove( command ) );
|
||||
commandsByPlugin.values().remove( command );
|
||||
} finally
|
||||
{
|
||||
commandsLock.writeLock().unlock();
|
||||
}
|
||||
while ( commandMap.values().remove( command ) );
|
||||
commandsByPlugin.values().remove( command );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -140,18 +119,11 @@ public final class PluginManager
|
||||
*/
|
||||
public void unregisterCommands(Plugin plugin)
|
||||
{
|
||||
commandsLock.writeLock().lock();
|
||||
try
|
||||
for ( Iterator<Command> it = commandsByPlugin.get( plugin ).iterator(); it.hasNext(); )
|
||||
{
|
||||
for ( Iterator<Command> it = commandsByPlugin.get( plugin ).iterator(); it.hasNext(); )
|
||||
{
|
||||
Command command = it.next();
|
||||
while ( commandMap.values().remove( command ) );
|
||||
it.remove();
|
||||
}
|
||||
} finally
|
||||
{
|
||||
commandsLock.writeLock().unlock();
|
||||
Command command = it.next();
|
||||
while ( commandMap.values().remove( command ) );
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,14 +137,7 @@ public final class PluginManager
|
||||
return null;
|
||||
}
|
||||
|
||||
commandsLock.readLock().lock();
|
||||
try
|
||||
{
|
||||
return commandMap.get( commandLower );
|
||||
} finally
|
||||
{
|
||||
commandsLock.readLock().unlock();
|
||||
}
|
||||
return commandMap.get( commandLower );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -469,20 +434,13 @@ public final class PluginManager
|
||||
*/
|
||||
public void registerListener(Plugin plugin, Listener listener)
|
||||
{
|
||||
listenersLock.lock();
|
||||
try
|
||||
for ( Method method : listener.getClass().getDeclaredMethods() )
|
||||
{
|
||||
for ( Method method : listener.getClass().getDeclaredMethods() )
|
||||
{
|
||||
Preconditions.checkArgument( !method.isAnnotationPresent( Subscribe.class ),
|
||||
Preconditions.checkArgument( !method.isAnnotationPresent( Subscribe.class ),
|
||||
"Listener %s has registered using deprecated subscribe annotation! Please update to @EventHandler.", listener );
|
||||
}
|
||||
eventBus.register( listener );
|
||||
listenersByPlugin.put( plugin, listener );
|
||||
} finally
|
||||
{
|
||||
listenersLock.unlock();
|
||||
}
|
||||
eventBus.register( listener );
|
||||
listenersByPlugin.put( plugin, listener );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -492,15 +450,8 @@ public final class PluginManager
|
||||
*/
|
||||
public void unregisterListener(Listener listener)
|
||||
{
|
||||
listenersLock.lock();
|
||||
try
|
||||
{
|
||||
eventBus.unregister( listener );
|
||||
listenersByPlugin.values().remove( listener );
|
||||
} finally
|
||||
{
|
||||
listenersLock.unlock();
|
||||
}
|
||||
eventBus.unregister( listener );
|
||||
listenersByPlugin.values().remove( listener );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -510,17 +461,10 @@ public final class PluginManager
|
||||
*/
|
||||
public void unregisterListeners(Plugin plugin)
|
||||
{
|
||||
listenersLock.lock();
|
||||
try
|
||||
for ( Iterator<Listener> it = listenersByPlugin.get( plugin ).iterator(); it.hasNext(); )
|
||||
{
|
||||
for ( Iterator<Listener> it = listenersByPlugin.get( plugin ).iterator(); it.hasNext(); )
|
||||
{
|
||||
eventBus.unregister( it.next() );
|
||||
it.remove();
|
||||
}
|
||||
} finally
|
||||
{
|
||||
listenersLock.unlock();
|
||||
eventBus.unregister( it.next() );
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@ -531,14 +475,7 @@ public final class PluginManager
|
||||
*/
|
||||
public Collection<Map.Entry<String, Command>> getCommands()
|
||||
{
|
||||
commandsLock.readLock().lock();
|
||||
try
|
||||
{
|
||||
return Collections.unmodifiableCollection( commandMap.entrySet() );
|
||||
} finally
|
||||
{
|
||||
commandsLock.readLock().unlock();
|
||||
}
|
||||
return Collections.unmodifiableCollection( commandMap.entrySet() );
|
||||
}
|
||||
|
||||
boolean isTransitiveDepend(PluginDescription plugin, PluginDescription depend)
|
||||
|
@ -6,12 +6,12 @@
|
||||
<parent>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>bungeecord-bootstrap</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Bootstrap</name>
|
||||
|
@ -6,12 +6,12 @@
|
||||
<parent>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>bungeecord-chat</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Chat</name>
|
||||
|
@ -13,8 +13,7 @@ import net.md_5.bungee.api.chat.hover.content.Content;
|
||||
import net.md_5.bungee.api.chat.hover.content.Entity;
|
||||
import net.md_5.bungee.api.chat.hover.content.Item;
|
||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
||||
import net.md_5.bungee.chat.VersionedComponentSerializer;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@ -35,7 +34,6 @@ public final class HoverEvent
|
||||
* Returns whether this hover event is prior to 1.16
|
||||
*/
|
||||
@Setter
|
||||
@ApiStatus.Internal
|
||||
private boolean legacy = false;
|
||||
|
||||
/**
|
||||
@ -82,7 +80,7 @@ public final class HoverEvent
|
||||
return (BaseComponent[]) ( (Text) content ).getValue();
|
||||
}
|
||||
|
||||
TextComponent component = new TextComponent( VersionedComponentSerializer.getDefault().toString( content ) );
|
||||
TextComponent component = new TextComponent( ComponentSerializer.toString( content ) );
|
||||
return new BaseComponent[]
|
||||
{
|
||||
component
|
||||
|
@ -10,36 +10,27 @@ import com.google.gson.JsonSerializer;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.UUID;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.chat.BaseComponentSerializer;
|
||||
import net.md_5.bungee.chat.VersionedComponentSerializer;
|
||||
|
||||
public class EntitySerializer extends BaseComponentSerializer implements JsonSerializer<Entity>, JsonDeserializer<Entity>
|
||||
public class EntitySerializer implements JsonSerializer<Entity>, JsonDeserializer<Entity>
|
||||
{
|
||||
|
||||
public EntitySerializer(VersionedComponentSerializer serializer)
|
||||
{
|
||||
super( serializer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity deserialize(JsonElement element, Type type, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
JsonObject value = element.getAsJsonObject();
|
||||
|
||||
boolean newEntity = value.has( "uuid" );
|
||||
|
||||
String idString;
|
||||
JsonElement uuid = value.get( newEntity ? "uuid" : "id" );
|
||||
if ( uuid.isJsonArray() )
|
||||
JsonElement id = value.get( "id" );
|
||||
if ( id.isJsonArray() )
|
||||
{
|
||||
idString = parseUUID( context.deserialize( uuid, int[].class ) ).toString();
|
||||
idString = parseUUID( context.deserialize( id, int[].class ) ).toString();
|
||||
} else
|
||||
{
|
||||
idString = uuid.getAsString();
|
||||
idString = id.getAsString();
|
||||
}
|
||||
|
||||
return new Entity(
|
||||
( value.has( newEntity ? "id" : "type" ) ) ? value.get( newEntity ? "id" : "type" ).getAsString() : null,
|
||||
( value.has( "type" ) ) ? value.get( "type" ).getAsString() : null,
|
||||
idString,
|
||||
( value.has( "name" ) ) ? context.deserialize( value.get( "name" ), BaseComponent.class ) : null
|
||||
);
|
||||
@ -49,21 +40,8 @@ public class EntitySerializer extends BaseComponentSerializer implements JsonSer
|
||||
public JsonElement serialize(Entity content, Type type, JsonSerializationContext context)
|
||||
{
|
||||
JsonObject object = new JsonObject();
|
||||
|
||||
switch ( serializer.getVersion() )
|
||||
{
|
||||
case V1_21_5:
|
||||
object.addProperty( "id", ( content.getType() != null ) ? content.getType() : "minecraft:pig" );
|
||||
object.addProperty( "uuid", content.getId() );
|
||||
break;
|
||||
case V1_16:
|
||||
object.addProperty( "type", ( content.getType() != null ) ? content.getType() : "minecraft:pig" );
|
||||
object.addProperty( "id", content.getId() );
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException( "Unknown version " + serializer.getVersion() );
|
||||
}
|
||||
|
||||
object.addProperty( "type", ( content.getType() != null ) ? content.getType() : "minecraft:pig" );
|
||||
object.addProperty( "id", content.getId() );
|
||||
if ( content.getName() != null )
|
||||
{
|
||||
object.add( "name", context.serialize( content.getName() ) );
|
||||
|
@ -10,19 +10,15 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Locale;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentStyle;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.hover.content.Content;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class BaseComponentSerializer
|
||||
{
|
||||
|
||||
protected final VersionedComponentSerializer serializer;
|
||||
|
||||
protected void deserialize(JsonObject object, BaseComponent component, JsonDeserializationContext context)
|
||||
{
|
||||
component.applyStyle( context.deserialize( object, ComponentStyle.class ) );
|
||||
@ -34,64 +30,42 @@ public class BaseComponentSerializer
|
||||
}
|
||||
|
||||
//Events
|
||||
JsonObject clickEvent;
|
||||
boolean newClickEvent = ( clickEvent = object.getAsJsonObject( "click_event" ) ) != null;
|
||||
if ( !newClickEvent )
|
||||
{
|
||||
clickEvent = object.getAsJsonObject( "clickEvent" );
|
||||
}
|
||||
JsonObject clickEvent = object.getAsJsonObject( "clickEvent" );
|
||||
if ( clickEvent != null )
|
||||
{
|
||||
ClickEvent.Action action = ClickEvent.Action.valueOf( clickEvent.get( "action" ).getAsString().toUpperCase( Locale.ROOT ) );
|
||||
if ( newClickEvent )
|
||||
{
|
||||
switch ( action )
|
||||
{
|
||||
case OPEN_URL:
|
||||
component.setClickEvent( new ClickEvent( action, clickEvent.get( "url" ).getAsString() ) );
|
||||
break;
|
||||
case RUN_COMMAND:
|
||||
case SUGGEST_COMMAND:
|
||||
component.setClickEvent( new ClickEvent( action, clickEvent.get( "command" ).getAsString() ) );
|
||||
break;
|
||||
case CHANGE_PAGE:
|
||||
int page = clickEvent.get( "page" ).getAsInt();
|
||||
Preconditions.checkArgument( page >= 0, "Page number has to be positive" );
|
||||
component.setClickEvent( new ClickEvent( action, Integer.toString( page ) ) );
|
||||
break;
|
||||
default:
|
||||
component.setClickEvent( new ClickEvent( action, ( clickEvent.has( "value" ) ) ? clickEvent.get( "value" ).getAsString() : "" ) );
|
||||
break;
|
||||
}
|
||||
} else
|
||||
{
|
||||
component.setClickEvent( new ClickEvent( action, ( clickEvent.has( "value" ) ) ? clickEvent.get( "value" ).getAsString() : "" ) );
|
||||
}
|
||||
component.setClickEvent( new ClickEvent(
|
||||
ClickEvent.Action.valueOf( clickEvent.get( "action" ).getAsString().toUpperCase( Locale.ROOT ) ),
|
||||
( clickEvent.has( "value" ) ) ? clickEvent.get( "value" ).getAsString() : "" ) );
|
||||
}
|
||||
|
||||
JsonObject hoverEventJson;
|
||||
boolean newHoverEvent = ( hoverEventJson = object.getAsJsonObject( "hover_event" ) ) != null;
|
||||
if ( !newHoverEvent )
|
||||
{
|
||||
hoverEventJson = object.getAsJsonObject( "hoverEvent" );
|
||||
}
|
||||
|
||||
JsonObject hoverEventJson = object.getAsJsonObject( "hoverEvent" );
|
||||
if ( hoverEventJson != null )
|
||||
{
|
||||
HoverEvent hoverEvent = null;
|
||||
HoverEvent.Action action = HoverEvent.Action.valueOf( hoverEventJson.get( "action" ).getAsString().toUpperCase( Locale.ROOT ) );
|
||||
|
||||
if ( newHoverEvent || hoverEventJson.has( "contents" ) )
|
||||
JsonElement value = hoverEventJson.get( "value" );
|
||||
if ( value != null )
|
||||
{
|
||||
// value is only used for text in >= 1.21.5 (its inlined now)
|
||||
JsonElement contents = hoverEventJson.get( newHoverEvent ? "value" : "contents" );
|
||||
if ( contents != null || ( newHoverEvent && ( action == HoverEvent.Action.SHOW_ITEM || action == HoverEvent.Action.SHOW_ENTITY ) ) )
|
||||
|
||||
// Plugins previously had support to pass BaseComponent[] into any action.
|
||||
// If the GSON is possible to be parsed as BaseComponent, attempt to parse as so.
|
||||
BaseComponent[] components;
|
||||
if ( value.isJsonArray() )
|
||||
{
|
||||
if ( contents == null )
|
||||
components = context.deserialize( value, BaseComponent[].class );
|
||||
} else
|
||||
{
|
||||
components = new BaseComponent[]
|
||||
{
|
||||
// this is the new inline for SHOW_ITEM and SHOW_ENTITY
|
||||
contents = hoverEventJson;
|
||||
}
|
||||
context.deserialize( value, BaseComponent.class )
|
||||
};
|
||||
}
|
||||
hoverEvent = new HoverEvent( action, components );
|
||||
} else
|
||||
{
|
||||
JsonElement contents = hoverEventJson.get( "contents" );
|
||||
if ( contents != null )
|
||||
{
|
||||
Content[] list;
|
||||
if ( contents.isJsonArray() )
|
||||
{
|
||||
@ -105,26 +79,6 @@ public class BaseComponentSerializer
|
||||
}
|
||||
hoverEvent = new HoverEvent( action, new ArrayList<>( Arrays.asList( list ) ) );
|
||||
}
|
||||
} else
|
||||
{
|
||||
JsonElement value = hoverEventJson.get( "value" );
|
||||
if ( value != null )
|
||||
{
|
||||
// Plugins previously had support to pass BaseComponent[] into any action.
|
||||
// If the GSON is possible to be parsed as BaseComponent, attempt to parse as so.
|
||||
BaseComponent[] components;
|
||||
if ( value.isJsonArray() )
|
||||
{
|
||||
components = context.deserialize( value, BaseComponent[].class );
|
||||
} else
|
||||
{
|
||||
components = new BaseComponent[]
|
||||
{
|
||||
context.deserialize( value, BaseComponent.class )
|
||||
};
|
||||
}
|
||||
hoverEvent = new HoverEvent( action, components );
|
||||
}
|
||||
}
|
||||
|
||||
if ( hoverEvent != null )
|
||||
@ -143,15 +97,15 @@ public class BaseComponentSerializer
|
||||
protected void serialize(JsonObject object, BaseComponent component, JsonSerializationContext context)
|
||||
{
|
||||
boolean first = false;
|
||||
if ( VersionedComponentSerializer.serializedComponents.get() == null )
|
||||
if ( ComponentSerializer.serializedComponents.get() == null )
|
||||
{
|
||||
first = true;
|
||||
VersionedComponentSerializer.serializedComponents.set( Collections.newSetFromMap( new IdentityHashMap<BaseComponent, Boolean>() ) );
|
||||
ComponentSerializer.serializedComponents.set( Collections.newSetFromMap( new IdentityHashMap<BaseComponent, Boolean>() ) );
|
||||
}
|
||||
try
|
||||
{
|
||||
Preconditions.checkArgument( !VersionedComponentSerializer.serializedComponents.get().contains( component ), "Component loop" );
|
||||
VersionedComponentSerializer.serializedComponents.get().add( component );
|
||||
Preconditions.checkArgument( !ComponentSerializer.serializedComponents.get().contains( component ), "Component loop" );
|
||||
ComponentSerializer.serializedComponents.get().add( component );
|
||||
|
||||
ComponentStyleSerializer.serializeTo( component.getStyle(), object );
|
||||
|
||||
@ -164,38 +118,9 @@ public class BaseComponentSerializer
|
||||
if ( component.getClickEvent() != null )
|
||||
{
|
||||
JsonObject clickEvent = new JsonObject();
|
||||
String actionName = component.getClickEvent().getAction().toString().toLowerCase( Locale.ROOT );
|
||||
clickEvent.addProperty( "action", actionName.toLowerCase( Locale.ROOT ) );
|
||||
switch ( serializer.getVersion() )
|
||||
{
|
||||
case V1_21_5:
|
||||
ClickEvent.Action action = ClickEvent.Action.valueOf( actionName.toUpperCase( Locale.ROOT ) );
|
||||
switch ( action )
|
||||
{
|
||||
case OPEN_URL:
|
||||
clickEvent.addProperty( "url", component.getClickEvent().getValue() );
|
||||
break;
|
||||
case RUN_COMMAND:
|
||||
case SUGGEST_COMMAND:
|
||||
clickEvent.addProperty( "command", component.getClickEvent().getValue() );
|
||||
break;
|
||||
case CHANGE_PAGE:
|
||||
clickEvent.addProperty( "page", Integer.parseInt( component.getClickEvent().getValue() ) );
|
||||
break;
|
||||
default:
|
||||
clickEvent.addProperty( "value", component.getClickEvent().getValue() );
|
||||
break;
|
||||
}
|
||||
object.add( "click_event", clickEvent );
|
||||
break;
|
||||
case V1_16:
|
||||
clickEvent.addProperty( "value", component.getClickEvent().getValue() );
|
||||
object.add( "clickEvent", clickEvent );
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException( "Unknown version " + serializer.getVersion() );
|
||||
}
|
||||
|
||||
clickEvent.addProperty( "action", component.getClickEvent().getAction().toString().toLowerCase( Locale.ROOT ) );
|
||||
clickEvent.addProperty( "value", component.getClickEvent().getValue() );
|
||||
object.add( "clickEvent", clickEvent );
|
||||
}
|
||||
if ( component.getHoverEvent() != null )
|
||||
{
|
||||
@ -206,39 +131,10 @@ public class BaseComponentSerializer
|
||||
hoverEvent.add( "value", context.serialize( component.getHoverEvent().getContents().get( 0 ) ) );
|
||||
} else
|
||||
{
|
||||
switch ( serializer.getVersion() )
|
||||
{
|
||||
case V1_21_5:
|
||||
if ( component.getHoverEvent().getAction() == HoverEvent.Action.SHOW_ITEM || component.getHoverEvent().getAction() == HoverEvent.Action.SHOW_ENTITY )
|
||||
{
|
||||
JsonObject inlined = context.serialize( ( component.getHoverEvent().getContents().size() == 1 )
|
||||
? component.getHoverEvent().getContents().get( 0 ) : component.getHoverEvent().getContents() ).getAsJsonObject();
|
||||
inlined.entrySet().forEach( entry -> hoverEvent.add( entry.getKey(), entry.getValue() ) );
|
||||
} else
|
||||
{
|
||||
hoverEvent.add( "value", context.serialize( ( component.getHoverEvent().getContents().size() == 1 )
|
||||
? component.getHoverEvent().getContents().get( 0 ) : component.getHoverEvent().getContents() ) );
|
||||
}
|
||||
break;
|
||||
case V1_16:
|
||||
hoverEvent.add( "contents", context.serialize( ( component.getHoverEvent().getContents().size() == 1 )
|
||||
? component.getHoverEvent().getContents().get( 0 ) : component.getHoverEvent().getContents() ) );
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException( "Unknown version " + serializer.getVersion() );
|
||||
}
|
||||
}
|
||||
switch ( serializer.getVersion() )
|
||||
{
|
||||
case V1_21_5:
|
||||
object.add( "hover_event", hoverEvent );
|
||||
break;
|
||||
case V1_16:
|
||||
object.add( "hoverEvent", hoverEvent );
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException( "Unknown version " + serializer.getVersion() );
|
||||
hoverEvent.add( "contents", context.serialize( ( component.getHoverEvent().getContents().size() == 1 )
|
||||
? component.getHoverEvent().getContents().get( 0 ) : component.getHoverEvent().getContents() ) );
|
||||
}
|
||||
object.add( "hoverEvent", hoverEvent );
|
||||
}
|
||||
|
||||
if ( component.getExtra() != null )
|
||||
@ -247,10 +143,10 @@ public class BaseComponentSerializer
|
||||
}
|
||||
} finally
|
||||
{
|
||||
VersionedComponentSerializer.serializedComponents.get().remove( component );
|
||||
ComponentSerializer.serializedComponents.get().remove( component );
|
||||
if ( first )
|
||||
{
|
||||
VersionedComponentSerializer.serializedComponents.set( null );
|
||||
ComponentSerializer.serializedComponents.set( null );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
package net.md_5.bungee.chat;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public enum ChatVersion
|
||||
{
|
||||
V1_16,
|
||||
V1_21_5;
|
||||
}
|
@ -1,17 +1,52 @@
|
||||
package net.md_5.bungee.chat;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Set;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentStyle;
|
||||
import net.md_5.bungee.api.chat.ItemTag;
|
||||
import net.md_5.bungee.api.chat.KeybindComponent;
|
||||
import net.md_5.bungee.api.chat.ScoreComponent;
|
||||
import net.md_5.bungee.api.chat.SelectorComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.chat.TranslatableComponent;
|
||||
import net.md_5.bungee.api.chat.hover.content.Content;
|
||||
import net.md_5.bungee.api.chat.hover.content.Entity;
|
||||
import net.md_5.bungee.api.chat.hover.content.EntitySerializer;
|
||||
import net.md_5.bungee.api.chat.hover.content.Item;
|
||||
import net.md_5.bungee.api.chat.hover.content.ItemSerializer;
|
||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
||||
import net.md_5.bungee.api.chat.hover.content.TextSerializer;
|
||||
|
||||
public class ComponentSerializer implements JsonDeserializer<BaseComponent>
|
||||
{
|
||||
|
||||
private static final Gson gson = new GsonBuilder().
|
||||
registerTypeAdapter( BaseComponent.class, new ComponentSerializer() ).
|
||||
registerTypeAdapter( TextComponent.class, new TextComponentSerializer() ).
|
||||
registerTypeAdapter( TranslatableComponent.class, new TranslatableComponentSerializer() ).
|
||||
registerTypeAdapter( KeybindComponent.class, new KeybindComponentSerializer() ).
|
||||
registerTypeAdapter( ScoreComponent.class, new ScoreComponentSerializer() ).
|
||||
registerTypeAdapter( SelectorComponent.class, new SelectorComponentSerializer() ).
|
||||
registerTypeAdapter( ComponentStyle.class, new ComponentStyleSerializer() ).
|
||||
registerTypeAdapter( Entity.class, new EntitySerializer() ).
|
||||
registerTypeAdapter( Text.class, new TextSerializer() ).
|
||||
registerTypeAdapter( Item.class, new ItemSerializer() ).
|
||||
registerTypeAdapter( ItemTag.class, new ItemTag.Serializer() ).
|
||||
create();
|
||||
|
||||
public static final ThreadLocal<Set<BaseComponent>> serializedComponents = new ThreadLocal<Set<BaseComponent>>();
|
||||
|
||||
/**
|
||||
* Parse a JSON-compliant String as an array of base components. The input
|
||||
* can be one of either an array of components, or a single component
|
||||
@ -31,7 +66,18 @@ public class ComponentSerializer implements JsonDeserializer<BaseComponent>
|
||||
*/
|
||||
public static BaseComponent[] parse(String json)
|
||||
{
|
||||
return VersionedComponentSerializer.getDefault().parse( json );
|
||||
JsonElement jsonElement = JsonParser.parseString( json );
|
||||
|
||||
if ( jsonElement.isJsonArray() )
|
||||
{
|
||||
return gson.fromJson( jsonElement, BaseComponent[].class );
|
||||
} else
|
||||
{
|
||||
return new BaseComponent[]
|
||||
{
|
||||
gson.fromJson( jsonElement, BaseComponent.class )
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,7 +90,9 @@ public class ComponentSerializer implements JsonDeserializer<BaseComponent>
|
||||
*/
|
||||
public static BaseComponent deserialize(String json)
|
||||
{
|
||||
return VersionedComponentSerializer.getDefault().deserialize( json );
|
||||
JsonElement jsonElement = JsonParser.parseString( json );
|
||||
|
||||
return deserialize( jsonElement );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,7 +105,20 @@ public class ComponentSerializer implements JsonDeserializer<BaseComponent>
|
||||
*/
|
||||
public static BaseComponent deserialize(JsonElement jsonElement)
|
||||
{
|
||||
return VersionedComponentSerializer.getDefault().deserialize( jsonElement );
|
||||
if ( jsonElement instanceof JsonPrimitive )
|
||||
{
|
||||
JsonPrimitive primitive = (JsonPrimitive) jsonElement;
|
||||
if ( primitive.isString() )
|
||||
{
|
||||
return new TextComponent( primitive.getAsString() );
|
||||
}
|
||||
} else if ( jsonElement instanceof JsonArray )
|
||||
{
|
||||
BaseComponent[] array = gson.fromJson( jsonElement, BaseComponent[].class );
|
||||
return TextComponent.fromArray( array );
|
||||
}
|
||||
|
||||
return gson.fromJson( jsonElement, BaseComponent.class );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,7 +131,9 @@ public class ComponentSerializer implements JsonDeserializer<BaseComponent>
|
||||
*/
|
||||
public static ComponentStyle deserializeStyle(String json)
|
||||
{
|
||||
return VersionedComponentSerializer.getDefault().deserializeStyle( json );
|
||||
JsonElement jsonElement = JsonParser.parseString( json );
|
||||
|
||||
return deserializeStyle( jsonElement );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,17 +146,17 @@ public class ComponentSerializer implements JsonDeserializer<BaseComponent>
|
||||
*/
|
||||
public static ComponentStyle deserializeStyle(JsonElement jsonElement)
|
||||
{
|
||||
return VersionedComponentSerializer.getDefault().deserializeStyle( jsonElement );
|
||||
return gson.fromJson( jsonElement, ComponentStyle.class );
|
||||
}
|
||||
|
||||
public static JsonElement toJson(BaseComponent component)
|
||||
{
|
||||
return VersionedComponentSerializer.getDefault().toJson( component );
|
||||
return gson.toJsonTree( component );
|
||||
}
|
||||
|
||||
public static JsonElement toJson(ComponentStyle style)
|
||||
{
|
||||
return VersionedComponentSerializer.getDefault().toJson( style );
|
||||
return gson.toJsonTree( style );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,7 +167,7 @@ public class ComponentSerializer implements JsonDeserializer<BaseComponent>
|
||||
@Deprecated
|
||||
public static String toString(Object object)
|
||||
{
|
||||
return VersionedComponentSerializer.getDefault().toString( object );
|
||||
return gson.toJson( object );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -115,27 +178,54 @@ public class ComponentSerializer implements JsonDeserializer<BaseComponent>
|
||||
@Deprecated
|
||||
public static String toString(Content content)
|
||||
{
|
||||
return VersionedComponentSerializer.getDefault().toString( content );
|
||||
return gson.toJson( content );
|
||||
}
|
||||
|
||||
public static String toString(BaseComponent component)
|
||||
{
|
||||
return VersionedComponentSerializer.getDefault().toString( component );
|
||||
return gson.toJson( component );
|
||||
}
|
||||
|
||||
public static String toString(BaseComponent... components)
|
||||
{
|
||||
return VersionedComponentSerializer.getDefault().toString( components );
|
||||
if ( components.length == 1 )
|
||||
{
|
||||
return gson.toJson( components[0] );
|
||||
} else
|
||||
{
|
||||
return gson.toJson( new TextComponent( components ) );
|
||||
}
|
||||
}
|
||||
|
||||
public static String toString(ComponentStyle style)
|
||||
{
|
||||
return VersionedComponentSerializer.getDefault().toString( style );
|
||||
return gson.toJson( style );
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseComponent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
return VersionedComponentSerializer.getDefault().deserialize( json, typeOfT, context );
|
||||
if ( json.isJsonPrimitive() )
|
||||
{
|
||||
return new TextComponent( json.getAsString() );
|
||||
}
|
||||
JsonObject object = json.getAsJsonObject();
|
||||
if ( object.has( "translate" ) )
|
||||
{
|
||||
return context.deserialize( json, TranslatableComponent.class );
|
||||
}
|
||||
if ( object.has( "keybind" ) )
|
||||
{
|
||||
return context.deserialize( json, KeybindComponent.class );
|
||||
}
|
||||
if ( object.has( "score" ) )
|
||||
{
|
||||
return context.deserialize( json, ScoreComponent.class );
|
||||
}
|
||||
if ( object.has( "selector" ) )
|
||||
{
|
||||
return context.deserialize( json, SelectorComponent.class );
|
||||
}
|
||||
return context.deserialize( json, TextComponent.class );
|
||||
}
|
||||
}
|
||||
|
@ -13,11 +13,6 @@ import net.md_5.bungee.api.chat.KeybindComponent;
|
||||
public class KeybindComponentSerializer extends BaseComponentSerializer implements JsonSerializer<KeybindComponent>, JsonDeserializer<KeybindComponent>
|
||||
{
|
||||
|
||||
public KeybindComponentSerializer(VersionedComponentSerializer serializer)
|
||||
{
|
||||
super( serializer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeybindComponent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
|
@ -13,11 +13,6 @@ import net.md_5.bungee.api.chat.ScoreComponent;
|
||||
public class ScoreComponentSerializer extends BaseComponentSerializer implements JsonSerializer<ScoreComponent>, JsonDeserializer<ScoreComponent>
|
||||
{
|
||||
|
||||
public ScoreComponentSerializer(VersionedComponentSerializer serializer)
|
||||
{
|
||||
super( serializer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScoreComponent deserialize(JsonElement element, Type type, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
|
@ -13,11 +13,6 @@ import net.md_5.bungee.api.chat.SelectorComponent;
|
||||
public class SelectorComponentSerializer extends BaseComponentSerializer implements JsonSerializer<SelectorComponent>, JsonDeserializer<SelectorComponent>
|
||||
{
|
||||
|
||||
public SelectorComponentSerializer(VersionedComponentSerializer serializer)
|
||||
{
|
||||
super( serializer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SelectorComponent deserialize(JsonElement element, Type type, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
@ -32,7 +27,7 @@ public class SelectorComponentSerializer extends BaseComponentSerializer impleme
|
||||
JsonElement separator = object.get( "separator" );
|
||||
if ( separator != null )
|
||||
{
|
||||
component.setSeparator( serializer.deserialize( separator.getAsString() ) );
|
||||
component.setSeparator( ComponentSerializer.deserialize( separator.getAsString() ) );
|
||||
}
|
||||
|
||||
deserialize( object, component, context );
|
||||
@ -48,7 +43,7 @@ public class SelectorComponentSerializer extends BaseComponentSerializer impleme
|
||||
|
||||
if ( component.getSeparator() != null )
|
||||
{
|
||||
object.addProperty( "separator", serializer.toString( component.getSeparator() ) );
|
||||
object.addProperty( "separator", ComponentSerializer.toString( component.getSeparator() ) );
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
@ -13,11 +13,6 @@ import net.md_5.bungee.api.chat.TextComponent;
|
||||
public class TextComponentSerializer extends BaseComponentSerializer implements JsonSerializer<TextComponent>, JsonDeserializer<TextComponent>
|
||||
{
|
||||
|
||||
public TextComponentSerializer(VersionedComponentSerializer serializer)
|
||||
{
|
||||
super( serializer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextComponent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
|
@ -15,11 +15,6 @@ import net.md_5.bungee.api.chat.TranslatableComponent;
|
||||
public class TranslatableComponentSerializer extends BaseComponentSerializer implements JsonSerializer<TranslatableComponent>, JsonDeserializer<TranslatableComponent>
|
||||
{
|
||||
|
||||
public TranslatableComponentSerializer(VersionedComponentSerializer serializer)
|
||||
{
|
||||
super( serializer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatableComponent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
|
@ -1,269 +0,0 @@
|
||||
package net.md_5.bungee.chat;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Set;
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentStyle;
|
||||
import net.md_5.bungee.api.chat.ItemTag;
|
||||
import net.md_5.bungee.api.chat.KeybindComponent;
|
||||
import net.md_5.bungee.api.chat.ScoreComponent;
|
||||
import net.md_5.bungee.api.chat.SelectorComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.chat.TranslatableComponent;
|
||||
import net.md_5.bungee.api.chat.hover.content.Content;
|
||||
import net.md_5.bungee.api.chat.hover.content.Entity;
|
||||
import net.md_5.bungee.api.chat.hover.content.EntitySerializer;
|
||||
import net.md_5.bungee.api.chat.hover.content.Item;
|
||||
import net.md_5.bungee.api.chat.hover.content.ItemSerializer;
|
||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
||||
import net.md_5.bungee.api.chat.hover.content.TextSerializer;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public class VersionedComponentSerializer implements JsonDeserializer<BaseComponent>
|
||||
{
|
||||
|
||||
@Getter
|
||||
@ApiStatus.Internal
|
||||
private final Gson gson;
|
||||
@Getter
|
||||
@ApiStatus.Internal
|
||||
private final ChatVersion version;
|
||||
|
||||
public VersionedComponentSerializer(ChatVersion version)
|
||||
{
|
||||
this.version = version;
|
||||
this.gson = new GsonBuilder().
|
||||
registerTypeAdapter( BaseComponent.class, this ).
|
||||
registerTypeAdapter( TextComponent.class, new TextComponentSerializer( this ) ).
|
||||
registerTypeAdapter( TranslatableComponent.class, new TranslatableComponentSerializer( this ) ).
|
||||
registerTypeAdapter( KeybindComponent.class, new KeybindComponentSerializer( this ) ).
|
||||
registerTypeAdapter( ScoreComponent.class, new ScoreComponentSerializer( this ) ).
|
||||
registerTypeAdapter( SelectorComponent.class, new SelectorComponentSerializer( this ) ).
|
||||
registerTypeAdapter( ComponentStyle.class, new ComponentStyleSerializer() ).
|
||||
registerTypeAdapter( Entity.class, new EntitySerializer( this ) ).
|
||||
registerTypeAdapter( Text.class, new TextSerializer() ).
|
||||
registerTypeAdapter( Item.class, new ItemSerializer() ).
|
||||
registerTypeAdapter( ItemTag.class, new ItemTag.Serializer() ).
|
||||
create();
|
||||
}
|
||||
|
||||
private static final VersionedComponentSerializer v1_16 = new VersionedComponentSerializer( ChatVersion.V1_16 );
|
||||
private static final VersionedComponentSerializer v1_21_5 = new VersionedComponentSerializer( ChatVersion.V1_21_5 );
|
||||
|
||||
public static VersionedComponentSerializer forVersion(ChatVersion version)
|
||||
{
|
||||
switch ( version )
|
||||
{
|
||||
case V1_16:
|
||||
return v1_16;
|
||||
case V1_21_5:
|
||||
return v1_21_5;
|
||||
default:
|
||||
throw new IllegalArgumentException( "Unknown version " + version );
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@ApiStatus.Internal
|
||||
public static VersionedComponentSerializer getDefault()
|
||||
{
|
||||
return v1_16;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static final ThreadLocal<Set<BaseComponent>> serializedComponents = new ThreadLocal<Set<BaseComponent>>();
|
||||
|
||||
/**
|
||||
* Parse a JSON-compliant String as an array of base components. The input
|
||||
* can be one of either an array of components, or a single component
|
||||
* object. If the input is an array, each component will be parsed
|
||||
* individually and returned in the order that they were parsed. If the
|
||||
* input is a single component object, a single-valued array with the
|
||||
* component will be returned.
|
||||
* <p>
|
||||
* <strong>NOTE:</strong> {@link #deserialize(String)} is preferred as it
|
||||
* will parse only one component as opposed to an array of components which
|
||||
* is non- standard behavior. This method is still appropriate for parsing
|
||||
* multiple components at once, although such use case is rarely (if at all)
|
||||
* exhibited in vanilla Minecraft.
|
||||
*
|
||||
* @param json the component json to parse
|
||||
* @return an array of all parsed components
|
||||
*/
|
||||
public BaseComponent[] parse(String json)
|
||||
{
|
||||
JsonElement jsonElement = JsonParser.parseString( json );
|
||||
|
||||
if ( jsonElement.isJsonArray() )
|
||||
{
|
||||
return gson.fromJson( jsonElement, BaseComponent[].class );
|
||||
} else
|
||||
{
|
||||
return new BaseComponent[]
|
||||
{
|
||||
gson.fromJson( jsonElement, BaseComponent.class )
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize a JSON-compliant String as a single component.
|
||||
*
|
||||
* @param json the component json to parse
|
||||
* @return the deserialized component
|
||||
* @throws IllegalArgumentException if anything other than a valid JSON
|
||||
* component string is passed as input
|
||||
*/
|
||||
public BaseComponent deserialize(String json)
|
||||
{
|
||||
JsonElement jsonElement = JsonParser.parseString( json );
|
||||
|
||||
return deserialize( jsonElement );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize a JSON element as a single component.
|
||||
*
|
||||
* @param jsonElement the component json to parse
|
||||
* @return the deserialized component
|
||||
* @throws IllegalArgumentException if anything other than a valid JSON
|
||||
* component is passed as input
|
||||
*/
|
||||
public BaseComponent deserialize(JsonElement jsonElement)
|
||||
{
|
||||
if ( jsonElement instanceof JsonPrimitive )
|
||||
{
|
||||
JsonPrimitive primitive = (JsonPrimitive) jsonElement;
|
||||
if ( primitive.isString() )
|
||||
{
|
||||
return new TextComponent( primitive.getAsString() );
|
||||
}
|
||||
} else if ( jsonElement instanceof JsonArray )
|
||||
{
|
||||
BaseComponent[] array = gson.fromJson( jsonElement, BaseComponent[].class );
|
||||
return TextComponent.fromArray( array );
|
||||
}
|
||||
|
||||
return gson.fromJson( jsonElement, BaseComponent.class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize a JSON-compliant String as a component style.
|
||||
*
|
||||
* @param json the component style json to parse
|
||||
* @return the deserialized component style
|
||||
* @throws IllegalArgumentException if anything other than a valid JSON
|
||||
* component style string is passed as input
|
||||
*/
|
||||
public ComponentStyle deserializeStyle(String json)
|
||||
{
|
||||
JsonElement jsonElement = JsonParser.parseString( json );
|
||||
|
||||
return deserializeStyle( jsonElement );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize a JSON element as a component style.
|
||||
*
|
||||
* @param jsonElement the component style json to parse
|
||||
* @return the deserialized component style
|
||||
* @throws IllegalArgumentException if anything other than a valid JSON
|
||||
* component style is passed as input
|
||||
*/
|
||||
public ComponentStyle deserializeStyle(JsonElement jsonElement)
|
||||
{
|
||||
return gson.fromJson( jsonElement, ComponentStyle.class );
|
||||
}
|
||||
|
||||
public JsonElement toJson(BaseComponent component)
|
||||
{
|
||||
return gson.toJsonTree( component );
|
||||
}
|
||||
|
||||
public JsonElement toJson(ComponentStyle style)
|
||||
{
|
||||
return gson.toJsonTree( style );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object the object to serialize
|
||||
* @return the JSON string representation of the object
|
||||
* @deprecated Error-prone, be careful which object you input here
|
||||
*/
|
||||
@Deprecated
|
||||
public String toString(Object object)
|
||||
{
|
||||
return gson.toJson( object );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param content the content to serialize
|
||||
* @return the JSON string representation of the object
|
||||
* @deprecated for legacy internal use only
|
||||
*/
|
||||
@Deprecated
|
||||
public String toString(Content content)
|
||||
{
|
||||
return gson.toJson( content );
|
||||
}
|
||||
|
||||
public String toString(BaseComponent component)
|
||||
{
|
||||
return gson.toJson( component );
|
||||
}
|
||||
|
||||
public String toString(BaseComponent... components)
|
||||
{
|
||||
if ( components.length == 1 )
|
||||
{
|
||||
return gson.toJson( components[0] );
|
||||
} else
|
||||
{
|
||||
return gson.toJson( new TextComponent( components ) );
|
||||
}
|
||||
}
|
||||
|
||||
public String toString(ComponentStyle style)
|
||||
{
|
||||
return gson.toJson( style );
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseComponent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
if ( json.isJsonPrimitive() )
|
||||
{
|
||||
return new TextComponent( json.getAsString() );
|
||||
}
|
||||
JsonObject object = json.getAsJsonObject();
|
||||
if ( object.has( "translate" ) )
|
||||
{
|
||||
return context.deserialize( json, TranslatableComponent.class );
|
||||
}
|
||||
if ( object.has( "keybind" ) )
|
||||
{
|
||||
return context.deserialize( json, KeybindComponent.class );
|
||||
}
|
||||
if ( object.has( "score" ) )
|
||||
{
|
||||
return context.deserialize( json, ScoreComponent.class );
|
||||
}
|
||||
if ( object.has( "selector" ) )
|
||||
{
|
||||
return context.deserialize( json, SelectorComponent.class );
|
||||
}
|
||||
return context.deserialize( json, TextComponent.class );
|
||||
}
|
||||
}
|
@ -6,12 +6,12 @@
|
||||
<parent>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>bungeecord-config</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Config</name>
|
||||
|
@ -6,12 +6,12 @@
|
||||
<parent>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>bungeecord-event</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Event</name>
|
||||
|
@ -6,12 +6,12 @@
|
||||
<parent>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>bungeecord-log</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Log</name>
|
||||
|
@ -6,12 +6,12 @@
|
||||
<parent>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>bungeecord-native</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Native</name>
|
||||
|
@ -37,6 +37,9 @@ public class NativeCipher implements BungeeCipher
|
||||
@Override
|
||||
public void cipher(ByteBuf in, ByteBuf out) throws GeneralSecurityException
|
||||
{
|
||||
// Smoke tests
|
||||
in.memoryAddress();
|
||||
out.memoryAddress();
|
||||
Preconditions.checkState( ctx != 0, "Invalid pointer to AES key!" );
|
||||
|
||||
// Store how many bytes we can cipher
|
||||
|
@ -48,17 +48,14 @@ public class NativeZlib implements BungeeZlib
|
||||
@Override
|
||||
public void process(ByteBuf in, ByteBuf out) throws DataFormatException
|
||||
{
|
||||
// Smoke tests
|
||||
in.memoryAddress();
|
||||
out.memoryAddress();
|
||||
Preconditions.checkState( ctx != 0, "Invalid pointer to compress!" );
|
||||
|
||||
while ( !nativeCompress.finished && ( compress || in.isReadable() ) )
|
||||
{
|
||||
if ( compress )
|
||||
{
|
||||
out.ensureWritable( OUTPUT_BUFFER_SIZE );
|
||||
} else
|
||||
{
|
||||
Preconditions.checkArgument( out.isWritable(), "Output buffer overrun" );
|
||||
}
|
||||
out.ensureWritable( OUTPUT_BUFFER_SIZE );
|
||||
|
||||
int processed;
|
||||
try
|
||||
|
@ -64,7 +64,7 @@ public class NativeZlibTest
|
||||
|
||||
zlib.process( originalBuf, compressed );
|
||||
|
||||
ByteBuf uncompressed = Unpooled.directBuffer( dataBuf.length, dataBuf.length );
|
||||
ByteBuf uncompressed = Unpooled.directBuffer();
|
||||
|
||||
zlib.init( false, 0 );
|
||||
zlib.process( compressed, uncompressed );
|
||||
|
17
pom.xml
17
pom.xml
@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>BungeeCord-Parent</name>
|
||||
@ -71,7 +71,7 @@
|
||||
|
||||
<properties>
|
||||
<build.number>unknown</build.number>
|
||||
<lombok.version>1.18.36</lombok.version>
|
||||
<lombok.version>1.18.32</lombok.version>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@ -82,7 +82,7 @@
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-bom</artifactId>
|
||||
<version>4.1.119.Final</version>
|
||||
<version>4.1.115.Final</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
@ -156,7 +156,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>3.3.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>process-classes</phase>
|
||||
@ -274,15 +274,6 @@
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>jdk-21-proc</id>
|
||||
<activation>
|
||||
<jdk>[21,)</jdk>
|
||||
</activation>
|
||||
<properties>
|
||||
<maven.compiler.proc>full</maven.compiler.proc>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>dist</id>
|
||||
<build>
|
||||
|
@ -6,12 +6,12 @@
|
||||
<parent>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>bungeecord-protocol</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Protocol</name>
|
||||
|
@ -1,19 +0,0 @@
|
||||
package net.md_5.bungee.protocol;
|
||||
|
||||
import net.md_5.bungee.chat.ChatVersion;
|
||||
import net.md_5.bungee.chat.VersionedComponentSerializer;
|
||||
|
||||
public class ChatSerializer
|
||||
{
|
||||
|
||||
public static VersionedComponentSerializer forVersion(int protocolVersion)
|
||||
{
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_21_5 )
|
||||
{
|
||||
return VersionedComponentSerializer.forVersion( ChatVersion.V1_21_5 );
|
||||
} else
|
||||
{
|
||||
return VersionedComponentSerializer.forVersion( ChatVersion.V1_16 );
|
||||
}
|
||||
}
|
||||
}
|
@ -15,12 +15,12 @@ import java.util.Arrays;
|
||||
import java.util.BitSet;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiConsumer;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentStyle;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import se.llbit.nbt.ErrorTag;
|
||||
import se.llbit.nbt.NamedTag;
|
||||
import se.llbit.nbt.SpecificTag;
|
||||
@ -69,15 +69,6 @@ public abstract class DefinedPacket
|
||||
buf.writeBytes( b );
|
||||
}
|
||||
|
||||
public static <T> T readStringMapKey(ByteBuf buf, Map<String, T> map)
|
||||
{
|
||||
String string = readString( buf );
|
||||
T result = map.get( string );
|
||||
Preconditions.checkArgument( result != null, "Unknown string key %s", string );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String readString(ByteBuf buf)
|
||||
{
|
||||
return readString( buf, Short.MAX_VALUE );
|
||||
@ -119,12 +110,12 @@ public abstract class DefinedPacket
|
||||
SpecificTag nbt = (SpecificTag) readTag( buf, protocolVersion );
|
||||
JsonElement json = TagUtil.toJson( nbt );
|
||||
|
||||
return ChatSerializer.forVersion( protocolVersion ).deserialize( json );
|
||||
return ComponentSerializer.deserialize( json );
|
||||
} else
|
||||
{
|
||||
String string = readString( buf, maxStringLength );
|
||||
|
||||
return ChatSerializer.forVersion( protocolVersion ).deserialize( string );
|
||||
return ComponentSerializer.deserialize( string );
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,7 +124,7 @@ public abstract class DefinedPacket
|
||||
SpecificTag nbt = (SpecificTag) readTag( buf, protocolVersion );
|
||||
JsonElement json = TagUtil.toJson( nbt );
|
||||
|
||||
return ChatSerializer.forVersion( protocolVersion ).deserializeStyle( json );
|
||||
return ComponentSerializer.deserializeStyle( json );
|
||||
}
|
||||
|
||||
public static void writeEitherBaseComponent(Either<String, BaseComponent> message, ByteBuf buf, int protocolVersion)
|
||||
@ -151,13 +142,13 @@ public abstract class DefinedPacket
|
||||
{
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_3 )
|
||||
{
|
||||
JsonElement json = ChatSerializer.forVersion( protocolVersion ).toJson( message );
|
||||
JsonElement json = ComponentSerializer.toJson( message );
|
||||
SpecificTag nbt = TagUtil.fromJson( json );
|
||||
|
||||
writeTag( nbt, buf, protocolVersion );
|
||||
} else
|
||||
{
|
||||
String string = ChatSerializer.forVersion( protocolVersion ).toString( message );
|
||||
String string = ComponentSerializer.toString( message );
|
||||
|
||||
writeString( string, buf );
|
||||
}
|
||||
@ -165,7 +156,7 @@ public abstract class DefinedPacket
|
||||
|
||||
public static void writeComponentStyle(ComponentStyle style, ByteBuf buf, int protocolVersion)
|
||||
{
|
||||
JsonElement json = ChatSerializer.forVersion( protocolVersion ).toJson( style );
|
||||
JsonElement json = ComponentSerializer.toJson( style );
|
||||
SpecificTag nbt = TagUtil.fromJson( json );
|
||||
|
||||
writeTag( nbt, buf, protocolVersion );
|
||||
@ -291,31 +282,6 @@ public abstract class DefinedPacket
|
||||
}
|
||||
}
|
||||
|
||||
public static void setVarInt(int value, ByteBuf output, int pos, int len)
|
||||
{
|
||||
switch ( len )
|
||||
{
|
||||
case 1:
|
||||
output.setByte( pos, value );
|
||||
break;
|
||||
case 2:
|
||||
output.setShort( pos, ( value & 0x7F | 0x80 ) << 8 | ( value >>> 7 & 0x7F ) );
|
||||
break;
|
||||
case 3:
|
||||
output.setMedium( pos, ( value & 0x7F | 0x80 ) << 16 | ( value >>> 7 & 0x7F | 0x80 ) << 8 | ( value >>> 14 & 0x7F ) );
|
||||
break;
|
||||
case 4:
|
||||
output.setInt( pos, ( value & 0x7F | 0x80 ) << 24 | ( value >>> 7 & 0x7F | 0x80 ) << 16 | ( value >>> 14 & 0x7F | 0x80 ) << 8 | ( value >>> 21 & 0x7F ) );
|
||||
break;
|
||||
case 5:
|
||||
output.setInt( pos, ( value & 0x7F | 0x80 ) << 24 | ( value >>> 7 & 0x7F | 0x80 ) << 16 | ( value >>> 14 & 0x7F | 0x80 ) << 8 | ( value >>> 21 & 0x7F | 0x80 ) );
|
||||
output.setByte( pos + 4, value >>> 28 );
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException( "Invalid varint len: " + len );
|
||||
}
|
||||
}
|
||||
|
||||
public static int readVarShort(ByteBuf buf)
|
||||
{
|
||||
int low = buf.readUnsignedShort();
|
||||
|
@ -99,8 +99,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_19_4, 0x23 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x24 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x26 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x27 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x26 )
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x27 )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
Login.class,
|
||||
@ -118,8 +117,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_19_4, 0x28 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x29 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x2B ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x2C ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x2B )
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x2C )
|
||||
);
|
||||
TO_CLIENT.registerPacket( Chat.class,
|
||||
Chat::new,
|
||||
@ -151,8 +149,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x43 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_3, 0x45 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x47 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x4C ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x4B )
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x4C )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
BossBar.class,
|
||||
@ -163,8 +160,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_17, 0x0D ),
|
||||
map( ProtocolConstants.MINECRAFT_1_19, 0x0A ),
|
||||
map( ProtocolConstants.MINECRAFT_1_19_4, 0x0B ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x0A ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x09 )
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x0A )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
PlayerListItem.class, // PlayerInfo
|
||||
@ -195,8 +191,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_19, 0x0E ),
|
||||
map( ProtocolConstants.MINECRAFT_1_19_3, 0x0D ),
|
||||
map( ProtocolConstants.MINECRAFT_1_19_4, 0x0F ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x10 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x0F )
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x10 )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
ScoreboardObjective.class,
|
||||
@ -215,8 +210,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x5A ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_3, 0x5C ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x5E ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x64 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x63 )
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x64 )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
ScoreboardScore.class,
|
||||
@ -235,16 +229,14 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x5D ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_3, 0x5F ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x61 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x68 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x67 )
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x68 )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
ScoreboardScoreReset.class,
|
||||
ScoreboardScoreReset::new,
|
||||
map( ProtocolConstants.MINECRAFT_1_20_3, 0x42 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x44 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x49 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x48 )
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x49 )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
ScoreboardDisplay.class,
|
||||
@ -263,8 +255,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x53 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_3, 0x55 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x57 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x5C ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x5B )
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x5C )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
Team.class,
|
||||
@ -283,8 +274,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x5C ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_3, 0x5E ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x60 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x67 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x66 )
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x67 )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
PluginMessage.class,
|
||||
@ -302,8 +292,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_19_3, 0x15 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_19_4, 0x17 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x18 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x19 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x18 )
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x19 )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
Kick.class,
|
||||
@ -321,8 +310,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_19_3, 0x17 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_19_4, 0x1A ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x1B ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x1D ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x1C )
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x1D )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
Title.class,
|
||||
@ -342,8 +330,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x61 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_3, 0x63 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x65 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x6C ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x6B )
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x6C )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
ClearTitles.class,
|
||||
@ -352,8 +339,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_19, 0x0D ),
|
||||
map( ProtocolConstants.MINECRAFT_1_19_3, 0x0C ),
|
||||
map( ProtocolConstants.MINECRAFT_1_19_4, 0x0E ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x0F ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x0E )
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x0F )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
Subtitle.class,
|
||||
@ -366,8 +352,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x5F ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_3, 0x61 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x63 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x6A ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x69 )
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x6A )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
TitleTimes.class,
|
||||
@ -380,8 +365,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x62 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_3, 0x64 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x66 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x6D ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x6C )
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x6D )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
SystemChat.class,
|
||||
@ -393,8 +377,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x67 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_3, 0x69 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x6C ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x73 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x72 )
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x73 )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
PlayerListHeaderFooter.class,
|
||||
@ -417,8 +400,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x68 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_3, 0x6A ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x6D ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x74 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x73 )
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x74 )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
EntityStatus.class,
|
||||
@ -436,8 +418,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_19_3, 0x19 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_19_4, 0x1C ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x1D ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x1F ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x1E )
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x1F )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
Commands.class,
|
||||
@ -450,8 +431,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_19, 0x0F ),
|
||||
map( ProtocolConstants.MINECRAFT_1_19_3, 0x0E ),
|
||||
map( ProtocolConstants.MINECRAFT_1_19_4, 0x10 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x11 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x10 )
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x11 )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
GameState.class,
|
||||
@ -466,8 +446,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_19_4, 0x1F ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x20 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x22 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x23 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x22 )
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x23 )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
ViewDistance.class,
|
||||
@ -483,8 +462,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x51 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_3, 0x53 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x55 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x59 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x58 )
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x59 )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
ServerData.class,
|
||||
@ -496,8 +474,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x47 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_3, 0x49 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x4B ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x50 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x4F )
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x50 )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
PlayerListItemRemove.class,
|
||||
@ -506,8 +483,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_19_4, 0x39 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x3B ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x3D ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x3F ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x3E )
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x3F )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
PlayerListItemUpdate.class,
|
||||
@ -516,8 +492,7 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_19_4, 0x3A ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x3C ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x3E ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x40 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x3F )
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x40 )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
StartConfiguration.class,
|
||||
@ -525,21 +500,18 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x65 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_3, 0x67 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x69 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x70 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x6F )
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x70 )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
CookieRequest.class,
|
||||
CookieRequest::new,
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x16 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x15 )
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x16 )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
StoreCookie.class,
|
||||
StoreCookie::new,
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x6B ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x72 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_21_5, 0x71 )
|
||||
map( ProtocolConstants.MINECRAFT_1_21_2, 0x72 )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
Transfer.class,
|
||||
@ -993,8 +965,6 @@ public enum Protocol
|
||||
}
|
||||
|
||||
ProtocolData data = protocols.get( protocol );
|
||||
Preconditions.checkState( data.packetConstructors[mapping.packetID] == null, "Duplicate packet mapping (%s)", mapping.packetID );
|
||||
|
||||
data.packetMap.put( packetClass, mapping.packetID );
|
||||
data.packetConstructors[mapping.packetID] = constructor;
|
||||
}
|
||||
|
@ -49,7 +49,6 @@ public class ProtocolConstants
|
||||
public static final int MINECRAFT_1_21 = 767;
|
||||
public static final int MINECRAFT_1_21_2 = 768;
|
||||
public static final int MINECRAFT_1_21_4 = 769;
|
||||
public static final int MINECRAFT_1_21_5 = 770;
|
||||
public static final List<String> SUPPORTED_VERSIONS;
|
||||
public static final List<Integer> SUPPORTED_VERSION_IDS;
|
||||
|
||||
@ -113,14 +112,13 @@ public class ProtocolConstants
|
||||
ProtocolConstants.MINECRAFT_1_20_5,
|
||||
ProtocolConstants.MINECRAFT_1_21,
|
||||
ProtocolConstants.MINECRAFT_1_21_2,
|
||||
ProtocolConstants.MINECRAFT_1_21_4,
|
||||
ProtocolConstants.MINECRAFT_1_21_5
|
||||
ProtocolConstants.MINECRAFT_1_21_4
|
||||
);
|
||||
|
||||
if ( SNAPSHOT_SUPPORT )
|
||||
{
|
||||
// supportedVersions.add( "1.21.x" );
|
||||
// supportedVersionIds.add( ProtocolConstants.MINECRAFT_1_21_5 );
|
||||
// supportedVersionIds.add( ProtocolConstants.MINECRAFT_1_21_4 );
|
||||
}
|
||||
|
||||
SUPPORTED_VERSIONS = supportedVersions.build();
|
||||
|
@ -82,27 +82,13 @@ public final class TagUtil
|
||||
{
|
||||
List<JsonElement> jsonArray = ( (JsonArray) json ).asList();
|
||||
|
||||
Integer listType = null;
|
||||
|
||||
for ( JsonElement jsonEl : jsonArray )
|
||||
{
|
||||
int type = fromJson( jsonEl ).tagType();
|
||||
if ( listType == null )
|
||||
{
|
||||
listType = type;
|
||||
} else if ( listType != type )
|
||||
{
|
||||
listType = Tag.TAG_COMPOUND;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( listType == null )
|
||||
if ( jsonArray.isEmpty() )
|
||||
{
|
||||
return new ListTag( Tag.TAG_END, Collections.emptyList() );
|
||||
}
|
||||
|
||||
SpecificTag listTag;
|
||||
int listType = fromJson( jsonArray.get( 0 ) ).tagType();
|
||||
switch ( listType )
|
||||
{
|
||||
case Tag.TAG_BYTE:
|
||||
@ -138,7 +124,7 @@ public final class TagUtil
|
||||
for ( JsonElement jsonEl : jsonArray )
|
||||
{
|
||||
SpecificTag subTag = fromJson( jsonEl );
|
||||
if ( listType == Tag.TAG_COMPOUND && !( subTag instanceof CompoundTag ) )
|
||||
if ( !( subTag instanceof CompoundTag ) )
|
||||
{
|
||||
CompoundTag wrapper = new CompoundTag();
|
||||
wrapper.add( "", subTag );
|
||||
|
@ -0,0 +1,26 @@
|
||||
package net.md_5.bungee.protocol;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageEncoder;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Prepend length of the message as a Varint21 using an extra buffer for the
|
||||
* length, avoiding copying packet data
|
||||
*/
|
||||
@ChannelHandler.Sharable
|
||||
public class Varint21LengthFieldExtraBufPrepender extends MessageToMessageEncoder<ByteBuf>
|
||||
{
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception
|
||||
{
|
||||
int bodyLen = msg.readableBytes();
|
||||
ByteBuf lenBuf = ctx.alloc().ioBuffer( Varint21LengthFieldPrepender.varintSize( bodyLen ) );
|
||||
DefinedPacket.writeVarInt( bodyLen, lenBuf );
|
||||
out.add( lenBuf );
|
||||
out.add( msg.retain() );
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package net.md_5.bungee.protocol;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageEncoder;
|
||||
import java.util.List;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Prepend length of the message as a Varint21 by writing length and data to a
|
||||
* new buffer
|
||||
*/
|
||||
public class Varint21LengthFieldPrepender extends MessageToMessageEncoder<ByteBuf>
|
||||
{
|
||||
|
||||
@Setter
|
||||
private boolean compose = true;
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> list) throws Exception
|
||||
{
|
||||
int bodyLen = msg.readableBytes();
|
||||
int headerLen = varintSize( bodyLen );
|
||||
if ( compose )
|
||||
{
|
||||
ByteBuf buf = ctx.alloc().directBuffer( headerLen );
|
||||
DefinedPacket.writeVarInt( bodyLen, buf );
|
||||
list.add( ctx.alloc().compositeDirectBuffer( 2 ).addComponents( true, buf, msg.retain() ) );
|
||||
} else
|
||||
{
|
||||
ByteBuf buf = ctx.alloc().directBuffer( headerLen + bodyLen );
|
||||
DefinedPacket.writeVarInt( bodyLen, buf );
|
||||
buf.writeBytes( msg );
|
||||
list.add( buf );
|
||||
}
|
||||
}
|
||||
|
||||
static int varintSize(int paramInt)
|
||||
{
|
||||
if ( ( paramInt & 0xFFFFFF80 ) == 0 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if ( ( paramInt & 0xFFFFC000 ) == 0 )
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
if ( ( paramInt & 0xFFE00000 ) == 0 )
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
if ( ( paramInt & 0xF0000000 ) == 0 )
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
return 5;
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
package net.md_5.bungee.protocol.channel;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* This class hold a netty channel initializer that calls the given {@link ChannelAcceptor}.
|
||||
* Use {@link BungeeChannelInitializer#create(ChannelAcceptor)} to create a new instance.
|
||||
* <p>
|
||||
* Please note that this API is unsafe and doesn't provide any guarantees about
|
||||
* the stability of the channel pipeline or the API itself. Use at your own
|
||||
* risk.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public abstract class BungeeChannelInitializer
|
||||
{
|
||||
|
||||
public abstract ChannelAcceptor getChannelAcceptor();
|
||||
|
||||
public abstract ChannelInitializer<Channel> getChannelInitializer();
|
||||
|
||||
/**
|
||||
* Creates a new instance of BungeeChannelInitializer
|
||||
*
|
||||
* @param acceptor the {@link ChannelAcceptor} that will accept the channel
|
||||
* and initializer the pipeline
|
||||
* @return {@link BungeeChannelInitializer} containing a cached
|
||||
* {@link ChannelInitializer} that will call the acceptor
|
||||
*/
|
||||
public static BungeeChannelInitializer create(ChannelAcceptor acceptor)
|
||||
{
|
||||
return new BungeeChannelInitializer()
|
||||
{
|
||||
@Getter
|
||||
private final ChannelAcceptor channelAcceptor = acceptor;
|
||||
|
||||
@Getter // cache the ChannelInitializer
|
||||
private final ChannelInitializer<Channel> channelInitializer = new ChannelInitializer<Channel>()
|
||||
{
|
||||
@Override
|
||||
protected void initChannel(Channel channel) throws Exception
|
||||
{
|
||||
if ( !getChannelAcceptor().accept( channel ) )
|
||||
{
|
||||
channel.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package net.md_5.bungee.protocol.channel;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ChannelAcceptor
|
||||
{
|
||||
|
||||
/**
|
||||
* Inside this method the pipeline should be initialized.
|
||||
*
|
||||
* @param channel the channel to be accepted and initialized
|
||||
* @return if the channel was accepted
|
||||
*/
|
||||
boolean accept(Channel channel);
|
||||
}
|
@ -25,7 +25,6 @@ public class ClientChat extends DefinedPacket
|
||||
private boolean signedPreview;
|
||||
private ChatChain chain;
|
||||
private SeenMessages seenMessages;
|
||||
private byte checksum;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
@ -58,11 +57,6 @@ public class ClientChat extends DefinedPacket
|
||||
chain = new ChatChain();
|
||||
chain.read( buf, direction, protocolVersion );
|
||||
}
|
||||
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_21_5 )
|
||||
{
|
||||
checksum = buf.readByte();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -93,11 +87,6 @@ public class ClientChat extends DefinedPacket
|
||||
{
|
||||
chain.write( buf, direction, protocolVersion );
|
||||
}
|
||||
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_21_5 )
|
||||
{
|
||||
buf.writeByte( checksum );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,7 +28,6 @@ public class ClientCommand extends DefinedPacket
|
||||
private boolean signedPreview;
|
||||
private ChatChain chain;
|
||||
private SeenMessages seenMessages;
|
||||
private byte checksum;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
@ -69,11 +68,6 @@ public class ClientCommand extends DefinedPacket
|
||||
chain = new ChatChain();
|
||||
chain.read( buf, direction, protocolVersion );
|
||||
}
|
||||
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_21_5 )
|
||||
{
|
||||
checksum = buf.readByte();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -107,11 +101,6 @@ public class ClientCommand extends DefinedPacket
|
||||
{
|
||||
chain.write( buf, direction, protocolVersion );
|
||||
}
|
||||
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_21_5 )
|
||||
{
|
||||
buf.writeByte( checksum );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -313,7 +313,6 @@ public class Commands extends DefinedPacket
|
||||
private static final ArgumentSerializer[] IDS_1_19_4;
|
||||
private static final ArgumentSerializer[] IDS_1_20_3;
|
||||
private static final ArgumentSerializer[] IDS_1_20_5;
|
||||
private static final ArgumentSerializer[] IDS_1_21_5;
|
||||
private static final Map<Class<?>, ProperArgumentSerializer<?>> PROPER_PROVIDERS = new HashMap<>();
|
||||
//
|
||||
private static final ArgumentSerializer<Void> VOID = new ArgumentSerializer<Void>()
|
||||
@ -928,65 +927,6 @@ public class Commands extends DefinedPacket
|
||||
get( "minecraft:loot_predicate", VOID ),
|
||||
get( "minecraft:loot_modifier", VOID )
|
||||
};
|
||||
|
||||
IDS_1_21_5 = new ArgumentSerializer[]
|
||||
{
|
||||
get( "brigadier:bool", VOID ),
|
||||
get( "brigadier:float", FLOAT_RANGE ),
|
||||
get( "brigadier:double", DOUBLE_RANGE ),
|
||||
get( "brigadier:integer", INTEGER_RANGE ),
|
||||
get( "brigadier:long", LONG_RANGE ),
|
||||
get( "brigadier:string", STRING ),
|
||||
get( "minecraft:entity", BYTE ),
|
||||
get( "minecraft:game_profile", VOID ),
|
||||
get( "minecraft:block_pos", VOID ),
|
||||
get( "minecraft:column_pos", VOID ),
|
||||
get( "minecraft:vec3", VOID ),
|
||||
get( "minecraft:vec2", VOID ),
|
||||
get( "minecraft:block_state", VOID ),
|
||||
get( "minecraft:block_predicate", VOID ),
|
||||
get( "minecraft:item_stack", VOID ),
|
||||
get( "minecraft:item_predicate", VOID ),
|
||||
get( "minecraft:color", VOID ),
|
||||
get( "minecraft:component", VOID ),
|
||||
get( "minecraft:style", VOID ),
|
||||
get( "minecraft:message", VOID ),
|
||||
get( "minecraft:nbt_compound_tag", VOID ),
|
||||
get( "minecraft:nbt_tag", VOID ),
|
||||
get( "minecraft:nbt_path", VOID ),
|
||||
get( "minecraft:objective", VOID ),
|
||||
get( "minecraft:objective_criteria", VOID ),
|
||||
get( "minecraft:operation", VOID ),
|
||||
get( "minecraft:particle", VOID ),
|
||||
get( "minecraft:angle", VOID ),
|
||||
get( "minecraft:rotation", VOID ),
|
||||
get( "minecraft:scoreboard_slot", VOID ),
|
||||
get( "minecraft:score_holder", BYTE ),
|
||||
get( "minecraft:swizzle", VOID ),
|
||||
get( "minecraft:team", VOID ),
|
||||
get( "minecraft:item_slot", VOID ),
|
||||
get( "minecraft:item_slots", VOID ),
|
||||
get( "minecraft:resource_location", VOID ),
|
||||
get( "minecraft:function", VOID ),
|
||||
get( "minecraft:entity_anchor", VOID ),
|
||||
get( "minecraft:int_range", VOID ),
|
||||
get( "minecraft:float_range", VOID ),
|
||||
get( "minecraft:dimension", VOID ),
|
||||
get( "minecraft:gamemode", VOID ),
|
||||
get( "minecraft:time", INTEGER ),
|
||||
get( "minecraft:resource_or_tag", RAW_STRING ),
|
||||
get( "minecraft:resource_or_tag_key", RAW_STRING ),
|
||||
get( "minecraft:resource", RAW_STRING ),
|
||||
get( "minecraft:resource_key", RAW_STRING ),
|
||||
get( "minecraft:resource_selector", RAW_STRING ),
|
||||
get( "minecraft:template_mirror", VOID ),
|
||||
get( "minecraft:template_rotation", VOID ),
|
||||
get( "minecraft:uuid", VOID ),
|
||||
get( "minecraft:heightmap", VOID ),
|
||||
get( "minecraft:loot_table", VOID ),
|
||||
get( "minecraft:loot_predicate", VOID ),
|
||||
get( "minecraft:loot_modifier", VOID )
|
||||
};
|
||||
}
|
||||
|
||||
private static void register(String name, ArgumentSerializer serializer)
|
||||
@ -1406,10 +1346,7 @@ public class Commands extends DefinedPacket
|
||||
{
|
||||
key = readVarInt( buf );
|
||||
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_21_5 )
|
||||
{
|
||||
reader = IDS_1_21_5[(Integer) key];
|
||||
} else if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_5 )
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_5 )
|
||||
{
|
||||
reader = IDS_1_20_5[(Integer) key];
|
||||
} else if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_3 )
|
||||
|
@ -6,8 +6,8 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.ChatSerializer;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.Protocol;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
@ -26,7 +26,7 @@ public class Kick extends DefinedPacket
|
||||
{
|
||||
if ( protocol == Protocol.LOGIN )
|
||||
{
|
||||
message = ChatSerializer.forVersion( protocolVersion ).deserialize( readString( buf ) );
|
||||
message = ComponentSerializer.deserialize( readString( buf ) );
|
||||
} else
|
||||
{
|
||||
message = readBaseComponent( buf, protocolVersion );
|
||||
@ -38,7 +38,7 @@ public class Kick extends DefinedPacket
|
||||
{
|
||||
if ( protocol == Protocol.LOGIN )
|
||||
{
|
||||
writeString( ChatSerializer.forVersion( protocolVersion ).toString( message ), buf );
|
||||
writeString( ComponentSerializer.toString( message ), buf );
|
||||
} else
|
||||
{
|
||||
writeBaseComponent( message, buf, protocolVersion );
|
||||
|
@ -22,21 +22,19 @@ import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
public class PluginMessage extends DefinedPacket
|
||||
{
|
||||
|
||||
public static final String BUNGEE_CHANNEL_LEGACY = "BungeeCord";
|
||||
public static final String BUNGEE_CHANNEL_MODERN = "bungeecord:main";
|
||||
public static final Function<String, String> MODERNISE = new Function<String, String>()
|
||||
{
|
||||
@Override
|
||||
public String apply(String tag)
|
||||
{
|
||||
// Transform as per Bukkit
|
||||
if ( tag.equals( PluginMessage.BUNGEE_CHANNEL_LEGACY ) )
|
||||
if ( tag.equals( "BungeeCord" ) )
|
||||
{
|
||||
return PluginMessage.BUNGEE_CHANNEL_MODERN;
|
||||
return "bungeecord:main";
|
||||
}
|
||||
if ( tag.equals( PluginMessage.BUNGEE_CHANNEL_MODERN ) )
|
||||
if ( tag.equals( "bungeecord:main" ) )
|
||||
{
|
||||
return PluginMessage.BUNGEE_CHANNEL_LEGACY;
|
||||
return "BungeeCord";
|
||||
}
|
||||
|
||||
// Code that gets to here is UNLIKELY to be viable on the Bukkit side of side things,
|
||||
|
@ -1,15 +1,10 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
@ -31,8 +26,8 @@ public class Team extends DefinedPacket
|
||||
private Either<String, BaseComponent> displayName;
|
||||
private Either<String, BaseComponent> prefix;
|
||||
private Either<String, BaseComponent> suffix;
|
||||
private NameTagVisibility nameTagVisibility;
|
||||
private CollisionRule collisionRule;
|
||||
private String nameTagVisibility;
|
||||
private String collisionRule;
|
||||
private int color;
|
||||
private byte friendlyFire;
|
||||
private String[] players;
|
||||
@ -65,18 +60,10 @@ public class Team extends DefinedPacket
|
||||
displayName = readEitherBaseComponent( buf, protocolVersion, false );
|
||||
}
|
||||
friendlyFire = buf.readByte();
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_21_5 )
|
||||
nameTagVisibility = readString( buf );
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 )
|
||||
{
|
||||
nameTagVisibility = NameTagVisibility.BY_ID[readVarInt( buf )];
|
||||
collisionRule = CollisionRule.BY_ID[readVarInt( buf )];
|
||||
} else
|
||||
{
|
||||
nameTagVisibility = readStringMapKey( buf, NameTagVisibility.BY_NAME );
|
||||
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 )
|
||||
{
|
||||
collisionRule = readStringMapKey( buf, CollisionRule.BY_NAME );
|
||||
}
|
||||
collisionRule = readString( buf );
|
||||
}
|
||||
color = ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) ? readVarInt( buf ) : buf.readByte();
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
|
||||
@ -110,17 +97,10 @@ public class Team extends DefinedPacket
|
||||
writeEitherBaseComponent( suffix, buf, protocolVersion );
|
||||
}
|
||||
buf.writeByte( friendlyFire );
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_21_5 )
|
||||
writeString( nameTagVisibility, buf );
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 )
|
||||
{
|
||||
writeVarInt( nameTagVisibility.ordinal(), buf );
|
||||
writeVarInt( collisionRule.ordinal(), buf );
|
||||
} else
|
||||
{
|
||||
writeString( nameTagVisibility.getKey(), buf );
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 )
|
||||
{
|
||||
writeString( collisionRule.getKey(), buf );
|
||||
}
|
||||
writeString( collisionRule, buf );
|
||||
}
|
||||
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
|
||||
@ -148,66 +128,4 @@ public class Team extends DefinedPacket
|
||||
{
|
||||
handler.handle( this );
|
||||
}
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum NameTagVisibility
|
||||
{
|
||||
|
||||
ALWAYS( "always" ),
|
||||
NEVER( "never" ),
|
||||
HIDE_FOR_OTHER_TEAMS( "hideForOtherTeams" ),
|
||||
HIDE_FOR_OWN_TEAM( "hideForOwnTeam" ),
|
||||
// 1.9 (and possibly other versions) appear to treat unknown values differently (always render rather than subject to spectator mode, friendly invisibles, etc).
|
||||
// we allow the empty value to achieve this in case it is potentially useful even though this is unsupported and its usage may be a bug (#3780).
|
||||
UNKNOWN( "" );
|
||||
//
|
||||
private final String key;
|
||||
//
|
||||
private static final Map<String, NameTagVisibility> BY_NAME;
|
||||
private static final NameTagVisibility[] BY_ID;
|
||||
|
||||
static
|
||||
{
|
||||
NameTagVisibility[] values = NameTagVisibility.values();
|
||||
ImmutableMap.Builder<String, NameTagVisibility> builder = ImmutableMap.builderWithExpectedSize( values.length );
|
||||
|
||||
for ( NameTagVisibility e : values )
|
||||
{
|
||||
builder.put( e.key, e );
|
||||
}
|
||||
|
||||
BY_NAME = builder.build();
|
||||
BY_ID = Arrays.copyOf( values, values.length - 1 ); // Ignore dummy UNKNOWN value
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum CollisionRule
|
||||
{
|
||||
|
||||
ALWAYS( "always" ),
|
||||
NEVER( "never" ),
|
||||
PUSH_OTHER_TEAMS( "pushOtherTeams" ),
|
||||
PUSH_OWN_TEAM( "pushOwnTeam" );
|
||||
//
|
||||
private final String key;
|
||||
//
|
||||
private static final Map<String, CollisionRule> BY_NAME;
|
||||
private static final CollisionRule[] BY_ID;
|
||||
|
||||
static
|
||||
{
|
||||
CollisionRule[] values = BY_ID = CollisionRule.values();
|
||||
ImmutableMap.Builder<String, CollisionRule> builder = ImmutableMap.builderWithExpectedSize( values.length );
|
||||
|
||||
for ( CollisionRule e : values )
|
||||
{
|
||||
builder.put( e.key, e );
|
||||
}
|
||||
|
||||
BY_NAME = builder.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,20 +2,9 @@ package net.md_5.bungee.protocol;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import se.llbit.nbt.ByteArrayTag;
|
||||
import se.llbit.nbt.CompoundTag;
|
||||
import se.llbit.nbt.IntArrayTag;
|
||||
import se.llbit.nbt.IntTag;
|
||||
import se.llbit.nbt.ListTag;
|
||||
import se.llbit.nbt.LongArrayTag;
|
||||
import se.llbit.nbt.SpecificTag;
|
||||
import se.llbit.nbt.StringTag;
|
||||
import se.llbit.nbt.Tag;
|
||||
|
||||
public class TagUtilTest
|
||||
{
|
||||
@ -37,190 +26,4 @@ public class TagUtilTest
|
||||
{
|
||||
testDissembleReassemble( "{\"text\":\"\",\"extra\":[\"hello\",{\"text\":\"there\",\"color\":\"#ff0000\"},{\"text\":\"friend\",\"font\":\"minecraft:default\"}]}" );
|
||||
}
|
||||
|
||||
public void testCreateMixedList(JsonArray array)
|
||||
{
|
||||
SpecificTag tag = TagUtil.fromJson( array );
|
||||
assertInstanceOf( ListTag.class, tag );
|
||||
ListTag list = (ListTag) tag;
|
||||
assertEquals( SpecificTag.TAG_COMPOUND, list.getType() );
|
||||
assertEquals( array.size(), list.size() );
|
||||
|
||||
for ( int i = 0; i < list.size(); i++ )
|
||||
{
|
||||
assertTrue( i < array.size() );
|
||||
|
||||
Tag element = list.get( i );
|
||||
assertInstanceOf( CompoundTag.class, element );
|
||||
CompoundTag compound = (CompoundTag) element;
|
||||
|
||||
JsonElement expected = array.get( i );
|
||||
|
||||
if ( expected instanceof JsonObject )
|
||||
{
|
||||
assertEquals( TagUtil.fromJson( expected ), compound );
|
||||
} else
|
||||
{
|
||||
assertEquals( 1, compound.size() );
|
||||
Tag value = compound.get( "" );
|
||||
|
||||
if ( expected instanceof JsonPrimitive )
|
||||
{
|
||||
JsonPrimitive primitive = (JsonPrimitive) expected;
|
||||
|
||||
if ( primitive.isNumber() )
|
||||
{
|
||||
Number number = primitive.getAsNumber();
|
||||
|
||||
if ( number instanceof Integer )
|
||||
{
|
||||
assertInstanceOf( IntTag.class, value );
|
||||
|
||||
IntTag integer = (IntTag) value;
|
||||
assertEquals( array.get( i ).getAsInt(), integer.getData() );
|
||||
}
|
||||
|
||||
} else if ( primitive.isString() )
|
||||
{
|
||||
assertInstanceOf( StringTag.class, value );
|
||||
|
||||
StringTag string = (StringTag) value;
|
||||
assertEquals( array.get( i ).getAsString(), string.getData() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMixedListWithInt()
|
||||
{
|
||||
JsonArray array = new JsonArray();
|
||||
array.add( 1 );
|
||||
array.add( "a" );
|
||||
|
||||
testCreateMixedList( array );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMixedListWithString()
|
||||
{
|
||||
JsonArray array = new JsonArray();
|
||||
array.add( "a" );
|
||||
array.add( 1L );
|
||||
|
||||
testCreateMixedList( array );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMixedListWithObject()
|
||||
{
|
||||
JsonObject compound = new JsonObject();
|
||||
compound.addProperty( "a", "b" );
|
||||
|
||||
JsonArray array = new JsonArray();
|
||||
array.add( compound );
|
||||
array.add( 1L );
|
||||
|
||||
testCreateMixedList( array );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateEmptyList()
|
||||
{
|
||||
JsonArray array = new JsonArray();
|
||||
SpecificTag tag = TagUtil.fromJson( array );
|
||||
assertInstanceOf( ListTag.class, tag );
|
||||
ListTag list = (ListTag) tag;
|
||||
assertEquals( 0, list.size() );
|
||||
assertEquals( Tag.TAG_END, list.getType() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateByteArray()
|
||||
{
|
||||
JsonArray array = new JsonArray();
|
||||
array.add( ( (byte) 1 ) );
|
||||
array.add( ( (byte) 2 ) );
|
||||
|
||||
SpecificTag tag = TagUtil.fromJson( array );
|
||||
assertInstanceOf( ByteArrayTag.class, tag );
|
||||
ByteArrayTag byteArray = (ByteArrayTag) tag;
|
||||
assertEquals( 2, byteArray.getData().length );
|
||||
|
||||
for ( int i = 0; i < byteArray.getData().length; i++ )
|
||||
{
|
||||
assertTrue( i < array.size() );
|
||||
|
||||
byte item = byteArray.getData()[i];
|
||||
assertEquals( array.get( i ).getAsByte(), item );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateIntArray()
|
||||
{
|
||||
JsonArray array = new JsonArray();
|
||||
array.add( 1 );
|
||||
array.add( 2 );
|
||||
|
||||
SpecificTag tag = TagUtil.fromJson( array );
|
||||
assertInstanceOf( IntArrayTag.class, tag );
|
||||
IntArrayTag intArray = (IntArrayTag) tag;
|
||||
assertEquals( 2, intArray.getData().length );
|
||||
|
||||
for ( int i = 0; i < intArray.getData().length; i++ )
|
||||
{
|
||||
assertTrue( i < array.size() );
|
||||
|
||||
int item = intArray.getData()[i];
|
||||
assertEquals( array.get( i ).getAsInt(), item );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateLongArray()
|
||||
{
|
||||
JsonArray array = new JsonArray();
|
||||
array.add( 1L );
|
||||
array.add( 2L );
|
||||
|
||||
SpecificTag tag = TagUtil.fromJson( array );
|
||||
assertInstanceOf( LongArrayTag.class, tag );
|
||||
LongArrayTag intArray = (LongArrayTag) tag;
|
||||
assertEquals( 2, intArray.getData().length );
|
||||
|
||||
for ( int i = 0; i < intArray.getData().length; i++ )
|
||||
{
|
||||
assertTrue( i < array.size() );
|
||||
|
||||
long item = intArray.getData()[i];
|
||||
assertEquals( array.get( i ).getAsLong(), item );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateStringList()
|
||||
{
|
||||
JsonArray array = new JsonArray();
|
||||
array.add( "a" );
|
||||
array.add( "b" );
|
||||
|
||||
SpecificTag tag = TagUtil.fromJson( array );
|
||||
assertInstanceOf( ListTag.class, tag );
|
||||
ListTag list = (ListTag) tag;
|
||||
assertEquals( SpecificTag.TAG_STRING, list.getType() );
|
||||
assertEquals( 2, list.size() );
|
||||
|
||||
for ( int i = 0; i < list.size(); i++ )
|
||||
{
|
||||
assertTrue( i < array.size() );
|
||||
|
||||
Tag item = list.get( i );
|
||||
assertInstanceOf( StringTag.class, item );
|
||||
|
||||
StringTag string = (StringTag) item;
|
||||
assertEquals( array.get( i ).getAsString(), string.getData() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,8 @@ public class PluginMessageTest
|
||||
@Test
|
||||
public void testModerniseChannel()
|
||||
{
|
||||
assertEquals( PluginMessage.BUNGEE_CHANNEL_MODERN, PluginMessage.MODERNISE.apply( PluginMessage.BUNGEE_CHANNEL_LEGACY ) );
|
||||
assertEquals( PluginMessage.BUNGEE_CHANNEL_LEGACY, PluginMessage.MODERNISE.apply( PluginMessage.BUNGEE_CHANNEL_MODERN ) );
|
||||
assertEquals( "bungeecord:main", PluginMessage.MODERNISE.apply( "BungeeCord" ) );
|
||||
assertEquals( "BungeeCord", PluginMessage.MODERNISE.apply( "bungeecord:main" ) );
|
||||
assertEquals( "legacy:foo", PluginMessage.MODERNISE.apply( "FoO" ) );
|
||||
assertEquals( "foo:bar", PluginMessage.MODERNISE.apply( "foo:bar" ) );
|
||||
}
|
||||
|
@ -6,12 +6,12 @@
|
||||
<parent>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>bungeecord-proxy</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Proxy</name>
|
||||
|
@ -6,6 +6,8 @@ import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
@ -50,17 +52,31 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.Synchronized;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.Favicon;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.ReconnectHandler;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
import net.md_5.bungee.api.Title;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentStyle;
|
||||
import net.md_5.bungee.api.chat.KeybindComponent;
|
||||
import net.md_5.bungee.api.chat.ScoreComponent;
|
||||
import net.md_5.bungee.api.chat.SelectorComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.chat.TranslatableComponent;
|
||||
import net.md_5.bungee.api.config.ConfigurationAdapter;
|
||||
import net.md_5.bungee.api.config.ListenerInfo;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.api.plugin.PluginManager;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import net.md_5.bungee.chat.ComponentStyleSerializer;
|
||||
import net.md_5.bungee.chat.KeybindComponentSerializer;
|
||||
import net.md_5.bungee.chat.ScoreComponentSerializer;
|
||||
import net.md_5.bungee.chat.SelectorComponentSerializer;
|
||||
import net.md_5.bungee.chat.TextComponentSerializer;
|
||||
import net.md_5.bungee.chat.TranslatableComponentSerializer;
|
||||
import net.md_5.bungee.command.CommandBungee;
|
||||
import net.md_5.bungee.command.CommandEnd;
|
||||
import net.md_5.bungee.command.CommandIP;
|
||||
@ -78,7 +94,6 @@ import net.md_5.bungee.log.LoggingOutputStream;
|
||||
import net.md_5.bungee.netty.PipelineUtils;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
import net.md_5.bungee.protocol.channel.BungeeChannelInitializer;
|
||||
import net.md_5.bungee.protocol.packet.PluginMessage;
|
||||
import net.md_5.bungee.query.RemoteQuery;
|
||||
import net.md_5.bungee.scheduler.BungeeScheduler;
|
||||
@ -148,12 +163,22 @@ public class BungeeCord extends ProxyServer
|
||||
private final ConsoleReader consoleReader;
|
||||
@Getter
|
||||
private final Logger logger;
|
||||
public final Gson gson = new GsonBuilder()
|
||||
.registerTypeAdapter( BaseComponent.class, new ComponentSerializer() )
|
||||
.registerTypeAdapter( TextComponent.class, new TextComponentSerializer() )
|
||||
.registerTypeAdapter( TranslatableComponent.class, new TranslatableComponentSerializer() )
|
||||
.registerTypeAdapter( KeybindComponent.class, new KeybindComponentSerializer() )
|
||||
.registerTypeAdapter( ScoreComponent.class, new ScoreComponentSerializer() )
|
||||
.registerTypeAdapter( SelectorComponent.class, new SelectorComponentSerializer() )
|
||||
.registerTypeAdapter( ComponentStyle.class, new ComponentStyleSerializer() )
|
||||
.registerTypeAdapter( ServerPing.PlayerInfo.class, new PlayerInfoSerializer() )
|
||||
.registerTypeAdapter( Favicon.class, Favicon.getFaviconTypeAdapter() ).create();
|
||||
@Getter
|
||||
private ConnectionThrottle connectionThrottle;
|
||||
|
||||
{
|
||||
// TODO: Proper fallback when we interface the manager
|
||||
registerChannel( PluginMessage.BUNGEE_CHANNEL_LEGACY );
|
||||
registerChannel( "BungeeCord" );
|
||||
}
|
||||
|
||||
public static BungeeCord getInstance()
|
||||
@ -161,21 +186,6 @@ public class BungeeCord extends ProxyServer
|
||||
return (BungeeCord) ProxyServer.getInstance();
|
||||
}
|
||||
|
||||
private final Unsafe unsafe = new Unsafe()
|
||||
{
|
||||
@Getter
|
||||
@Setter
|
||||
private BungeeChannelInitializer frontendChannelInitializer;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private BungeeChannelInitializer backendChannelInitializer;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private BungeeChannelInitializer serverInfoChannelInitializer;
|
||||
};
|
||||
|
||||
@SuppressFBWarnings("DM_DEFAULT_ENCODING")
|
||||
public BungeeCord() throws IOException
|
||||
{
|
||||
@ -344,7 +354,7 @@ public class BungeeCord extends ProxyServer
|
||||
.channel( PipelineUtils.getServerChannel( info.getSocketAddress() ) )
|
||||
.option( ChannelOption.SO_REUSEADDR, true ) // TODO: Move this elsewhere!
|
||||
.childAttr( PipelineUtils.LISTENER, info )
|
||||
.childHandler( unsafe().getFrontendChannelInitializer().getChannelInitializer() )
|
||||
.childHandler( PipelineUtils.SERVER_CHILD )
|
||||
.group( eventLoops )
|
||||
.localAddress( info.getSocketAddress() )
|
||||
.bind().addListener( listener );
|
||||
@ -815,10 +825,4 @@ public class BungeeCord extends ProxyServer
|
||||
{
|
||||
return new BungeeTitle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Unsafe unsafe()
|
||||
{
|
||||
return unsafe;
|
||||
}
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ public class BungeeServerInfo implements ServerInfo
|
||||
new Bootstrap()
|
||||
.channel( PipelineUtils.getChannel( socketAddress ) )
|
||||
.group( BungeeCord.getInstance().eventLoops )
|
||||
.handler( ProxyServer.getInstance().unsafe().getServerInfoChannelInitializer().getChannelInitializer() )
|
||||
.handler( PipelineUtils.BASE_SERVERSIDE )
|
||||
.option( ChannelOption.CONNECT_TIMEOUT_MILLIS, BungeeCord.getInstance().getConfig().getRemotePingTimeout() )
|
||||
.remoteAddress( socketAddress )
|
||||
.connect()
|
||||
|
@ -156,7 +156,7 @@ public class BungeeTitle implements Title
|
||||
{
|
||||
if ( player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_17 )
|
||||
{
|
||||
player.unsafe().sendPacketQueued( packet.newPacket );
|
||||
( (UserConnection) player ).sendPacketQueued( packet.newPacket );
|
||||
} else
|
||||
{
|
||||
player.unsafe().sendPacket( packet.oldPacket );
|
||||
|
@ -14,7 +14,6 @@ import net.md_5.bungee.api.connection.Server;
|
||||
import net.md_5.bungee.netty.ChannelWrapper;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.Protocol;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
import net.md_5.bungee.protocol.packet.PluginMessage;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@ -41,18 +40,6 @@ public class ServerConnection implements Server
|
||||
{
|
||||
ch.write( packet );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacketQueued(DefinedPacket packet)
|
||||
{
|
||||
if ( ch.getEncodeVersion() >= ProtocolConstants.MINECRAFT_1_20_2 )
|
||||
{
|
||||
ServerConnection.this.sendPacketQueued( packet );
|
||||
} else
|
||||
{
|
||||
sendPacket( packet );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public void sendPacketQueued(DefinedPacket packet)
|
||||
@ -66,8 +53,6 @@ public class ServerConnection implements Server
|
||||
Protocol encodeProtocol = ch.getEncodeProtocol();
|
||||
if ( !encodeProtocol.TO_SERVER.hasPacket( packet.getClass(), ch.getEncodeVersion() ) )
|
||||
{
|
||||
// we should limit this so bad api usage won't oom the server.
|
||||
Preconditions.checkState( packetQueue.size() <= 4096, "too many queued packets" );
|
||||
packetQueue.add( packet );
|
||||
} else
|
||||
{
|
||||
|
@ -25,6 +25,7 @@ import net.md_5.bungee.api.score.Objective;
|
||||
import net.md_5.bungee.api.score.Score;
|
||||
import net.md_5.bungee.api.score.Scoreboard;
|
||||
import net.md_5.bungee.api.score.Team;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import net.md_5.bungee.connection.CancelSendSignal;
|
||||
import net.md_5.bungee.connection.DownstreamBridge;
|
||||
import net.md_5.bungee.connection.LoginResult;
|
||||
@ -103,7 +104,6 @@ public class ServerConnector extends PacketHandler
|
||||
@Override
|
||||
public void connected(ChannelWrapper channel) throws Exception
|
||||
{
|
||||
channel.setVersion( user.getPendingConnection().getVersion() );
|
||||
this.ch = channel;
|
||||
|
||||
this.handshakeHandler = new ForgeServerHandler( user, ch, target );
|
||||
@ -117,7 +117,7 @@ public class ServerConnector extends PacketHandler
|
||||
LoginResult profile = user.getPendingConnection().getLoginProfile();
|
||||
if ( profile != null && profile.getProperties() != null && profile.getProperties().length > 0 )
|
||||
{
|
||||
newHost += "\00" + LoginResult.GSON.toJson( profile.getProperties() );
|
||||
newHost += "\00" + BungeeCord.getInstance().gson.toJson( profile.getProperties() );
|
||||
}
|
||||
copiedHandshake.setHost( newHost );
|
||||
} else if ( !user.getExtraDataInHandshake().isEmpty() )
|
||||
@ -301,7 +301,7 @@ public class ServerConnector extends PacketHandler
|
||||
{
|
||||
user.unsafe().sendPacket( new ScoreboardObjective(
|
||||
objective.getName(),
|
||||
( user.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13 ) ? Either.right( user.getChatSerializer().deserialize( objective.getValue() ) ) : Either.left( objective.getValue() ),
|
||||
( user.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13 ) ? Either.right( ComponentSerializer.deserialize( objective.getValue() ) ) : Either.left( objective.getValue() ),
|
||||
ScoreboardObjective.HealthDisplay.fromString( objective.getType() ),
|
||||
(byte) 1, null )
|
||||
);
|
||||
|
@ -3,8 +3,10 @@ package net.md_5.bungee;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.util.internal.PlatformDependent;
|
||||
import java.net.InetSocketAddress;
|
||||
@ -38,7 +40,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.PermissionCheckEvent;
|
||||
import net.md_5.bungee.api.event.ServerConnectEvent;
|
||||
import net.md_5.bungee.api.score.Scoreboard;
|
||||
import net.md_5.bungee.chat.VersionedComponentSerializer;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import net.md_5.bungee.connection.InitialHandler;
|
||||
import net.md_5.bungee.entitymap.EntityMap;
|
||||
import net.md_5.bungee.forge.ForgeClientHandler;
|
||||
@ -47,8 +49,9 @@ import net.md_5.bungee.forge.ForgeServerHandler;
|
||||
import net.md_5.bungee.netty.ChannelWrapper;
|
||||
import net.md_5.bungee.netty.HandlerBoss;
|
||||
import net.md_5.bungee.netty.PipelineUtils;
|
||||
import net.md_5.bungee.protocol.ChatSerializer;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.MinecraftDecoder;
|
||||
import net.md_5.bungee.protocol.MinecraftEncoder;
|
||||
import net.md_5.bungee.protocol.PacketWrapper;
|
||||
import net.md_5.bungee.protocol.Protocol;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
@ -134,8 +137,6 @@ public final class UserConnection implements ProxiedPlayer
|
||||
private String displayName;
|
||||
@Getter
|
||||
private EntityMap entityRewrite;
|
||||
@Getter
|
||||
private VersionedComponentSerializer chatSerializer;
|
||||
private Locale locale;
|
||||
/*========================================================================*/
|
||||
@Getter
|
||||
@ -153,24 +154,11 @@ public final class UserConnection implements ProxiedPlayer
|
||||
{
|
||||
ch.write( packet );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacketQueued(DefinedPacket packet)
|
||||
{
|
||||
if ( pendingConnection.getVersion() >= ProtocolConstants.MINECRAFT_1_20_2 )
|
||||
{
|
||||
UserConnection.this.sendPacketQueued( packet );
|
||||
} else
|
||||
{
|
||||
sendPacket( packet );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public boolean init()
|
||||
{
|
||||
this.entityRewrite = EntityMap.getEntityMap( getPendingConnection().getVersion() );
|
||||
this.chatSerializer = ChatSerializer.forVersion( getPendingConnection().getVersion() );
|
||||
|
||||
this.displayName = name;
|
||||
|
||||
@ -207,8 +195,6 @@ public final class UserConnection implements ProxiedPlayer
|
||||
Protocol encodeProtocol = ch.getEncodeProtocol();
|
||||
if ( !encodeProtocol.TO_CLIENT.hasPacket( packet.getClass(), getPendingConnection().getVersion() ) )
|
||||
{
|
||||
// we should limit this so bad api usage won't oom the server.
|
||||
Preconditions.checkState( packetQueue.size() <= 4096, "too many queued packets" );
|
||||
packetQueue.add( packet );
|
||||
} else
|
||||
{
|
||||
@ -376,6 +362,17 @@ public final class UserConnection implements ProxiedPlayer
|
||||
|
||||
pendingConnects.add( target );
|
||||
|
||||
ChannelInitializer initializer = new ChannelInitializer()
|
||||
{
|
||||
@Override
|
||||
protected void initChannel(Channel ch) throws Exception
|
||||
{
|
||||
PipelineUtils.BASE_SERVERSIDE.initChannel( ch );
|
||||
ch.pipeline().addAfter( PipelineUtils.FRAME_DECODER, PipelineUtils.PACKET_DECODER, new MinecraftDecoder( Protocol.HANDSHAKE, false, getPendingConnection().getVersion() ) );
|
||||
ch.pipeline().addAfter( PipelineUtils.FRAME_PREPENDER, PipelineUtils.PACKET_ENCODER, new MinecraftEncoder( Protocol.HANDSHAKE, false, getPendingConnection().getVersion() ) );
|
||||
ch.pipeline().get( HandlerBoss.class ).setHandler( new ServerConnector( bungee, UserConnection.this, target ) );
|
||||
}
|
||||
};
|
||||
ChannelFutureListener listener = new ChannelFutureListener()
|
||||
{
|
||||
@Override
|
||||
@ -404,16 +401,13 @@ public final class UserConnection implements ProxiedPlayer
|
||||
{
|
||||
sendMessage( bungee.getTranslation( "fallback_kick", connectionFailMessage( future.cause() ) ) );
|
||||
}
|
||||
} else
|
||||
{
|
||||
future.channel().pipeline().get( HandlerBoss.class ).setHandler( new ServerConnector( bungee, UserConnection.this, target ) );
|
||||
}
|
||||
}
|
||||
};
|
||||
Bootstrap b = new Bootstrap()
|
||||
.channel( PipelineUtils.getChannel( target.getAddress() ) )
|
||||
.group( ch.getHandle().eventLoop() )
|
||||
.handler( bungee.unsafe().getBackendChannelInitializer().getChannelInitializer() )
|
||||
.handler( initializer )
|
||||
.option( ChannelOption.CONNECT_TIMEOUT_MILLIS, request.getConnectTimeout() )
|
||||
.remoteAddress( target.getAddress() );
|
||||
// Windows is bugged, multi homed users will just have to live with random connecting IPs
|
||||
@ -560,7 +554,7 @@ public final class UserConnection implements ProxiedPlayer
|
||||
sendPacketQueued( new SystemChat( message, position.ordinal() ) );
|
||||
} else
|
||||
{
|
||||
sendPacketQueued( new Chat( chatSerializer.toString( message ), (byte) position.ordinal(), sender ) );
|
||||
sendPacketQueued( new Chat( ComponentSerializer.toString( message ), (byte) position.ordinal(), sender ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,57 @@
|
||||
package net.md_5.bungee.compress;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageEncoder;
|
||||
import java.util.List;
|
||||
import java.util.zip.Deflater;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.md_5.bungee.jni.zlib.BungeeZlib;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
|
||||
public class PacketCompressor extends MessageToMessageEncoder<ByteBuf>
|
||||
{
|
||||
|
||||
@Getter
|
||||
private final BungeeZlib zlib = CompressFactory.zlib.newInstance();
|
||||
@Setter
|
||||
private int threshold = 256;
|
||||
@Setter
|
||||
private boolean compose = true;
|
||||
|
||||
@Override
|
||||
public void handlerAdded(ChannelHandlerContext ctx) throws Exception
|
||||
{
|
||||
zlib.init( true, Deflater.DEFAULT_COMPRESSION );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception
|
||||
{
|
||||
zlib.free();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception
|
||||
{
|
||||
int origSize = msg.readableBytes();
|
||||
if ( origSize < threshold )
|
||||
{
|
||||
if ( compose )
|
||||
{
|
||||
// create a virtual buffer to avoid copying of data
|
||||
out.add( ctx.alloc().compositeDirectBuffer( 2 ).addComponents( true, ctx.alloc().directBuffer( 1 ).writeByte( 0 ), msg.retain() ) );
|
||||
} else
|
||||
{
|
||||
out.add( ctx.alloc().directBuffer( origSize + 1 ).writeByte( 0 ).writeBytes( msg ) );
|
||||
}
|
||||
} else
|
||||
{
|
||||
ByteBuf buf = ctx.alloc().directBuffer( BungeeZlib.OUTPUT_BUFFER_SIZE );
|
||||
DefinedPacket.writeVarInt( origSize, buf );
|
||||
zlib.process( msg, buf );
|
||||
out.add( buf );
|
||||
}
|
||||
}
|
||||
}
|
@ -7,12 +7,10 @@ import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
import java.util.List;
|
||||
import net.md_5.bungee.jni.zlib.BungeeZlib;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.OverflowPacketException;
|
||||
|
||||
public class PacketDecompressor extends MessageToMessageDecoder<ByteBuf>
|
||||
{
|
||||
|
||||
private static final int MAX_DECOMPRESSED_LEN = 1 << 23;
|
||||
private final BungeeZlib zlib = CompressFactory.zlib.newInstance();
|
||||
|
||||
@Override
|
||||
@ -36,14 +34,8 @@ public class PacketDecompressor extends MessageToMessageDecoder<ByteBuf>
|
||||
out.add( in.retain() );
|
||||
} else
|
||||
{
|
||||
if ( size > MAX_DECOMPRESSED_LEN )
|
||||
{
|
||||
throw new OverflowPacketException( "Packet may not be larger than " + MAX_DECOMPRESSED_LEN + " bytes" );
|
||||
}
|
||||
ByteBuf decompressed = ctx.alloc().directBuffer();
|
||||
|
||||
// Do not use size as max capacity, as its possible that the entity rewriter increases the size afterwards
|
||||
// This would result in a kick (it happens rarely as the entity ids size must differ)
|
||||
ByteBuf decompressed = ctx.alloc().directBuffer( size, MAX_DECOMPRESSED_LEN );
|
||||
try
|
||||
{
|
||||
zlib.process( in, decompressed );
|
||||
|
@ -69,8 +69,6 @@ public class Configuration implements ProxyConfig
|
||||
private boolean preventProxyConnections;
|
||||
private boolean forgeSupport;
|
||||
private boolean rejectTransfers;
|
||||
private int maxPacketsPerSecond = 1 << 12;
|
||||
private int maxPacketDataPerSecond = 1 << 25;
|
||||
|
||||
public void load()
|
||||
{
|
||||
@ -107,8 +105,6 @@ public class Configuration implements ProxyConfig
|
||||
preventProxyConnections = adapter.getBoolean( "prevent_proxy_connections", preventProxyConnections );
|
||||
forgeSupport = adapter.getBoolean( "forge_support", forgeSupport );
|
||||
rejectTransfers = adapter.getBoolean( "reject_transfers", rejectTransfers );
|
||||
maxPacketsPerSecond = adapter.getInt( "max_packets_per_second", maxPacketsPerSecond );
|
||||
maxPacketDataPerSecond = adapter.getInt( "max_packets_data_per_second", maxPacketDataPerSecond );
|
||||
|
||||
disabledCommands = new CaseInsensitiveSet( (Collection<String>) adapter.getList( "disabled_commands", Arrays.asList( "disabledcommandhere" ) ) );
|
||||
|
||||
|
@ -189,9 +189,7 @@ public class YamlConfig implements ConfigurationAdapter
|
||||
@Override
|
||||
public int getInt(String path, int def)
|
||||
{
|
||||
// #3791: Sometimes third-party tools rewrite large ints into doubles
|
||||
Number number = get( path, def );
|
||||
return number.intValue();
|
||||
return get( path, def );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,6 +51,7 @@ import net.md_5.bungee.api.score.Position;
|
||||
import net.md_5.bungee.api.score.Score;
|
||||
import net.md_5.bungee.api.score.Scoreboard;
|
||||
import net.md_5.bungee.api.score.Team;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import net.md_5.bungee.entitymap.EntityMap;
|
||||
import net.md_5.bungee.netty.ChannelWrapper;
|
||||
import net.md_5.bungee.netty.PacketHandler;
|
||||
@ -200,7 +201,7 @@ public class DownstreamBridge extends PacketHandler
|
||||
switch ( objective.getAction() )
|
||||
{
|
||||
case 0:
|
||||
serverScoreboard.addObjective( new Objective( objective.getName(), ( objective.getValue().isLeft() ) ? objective.getValue().getLeft() : con.getChatSerializer().toString( objective.getValue().getRight() ), objective.getType().toString() ) );
|
||||
serverScoreboard.addObjective( new Objective( objective.getName(), ( objective.getValue().isLeft() ) ? objective.getValue().getLeft() : ComponentSerializer.toString( objective.getValue().getRight() ), objective.getType().toString() ) );
|
||||
break;
|
||||
case 1:
|
||||
serverScoreboard.removeObjective( objective.getName() );
|
||||
@ -209,7 +210,7 @@ public class DownstreamBridge extends PacketHandler
|
||||
Objective oldObjective = serverScoreboard.getObjective( objective.getName() );
|
||||
if ( oldObjective != null )
|
||||
{
|
||||
oldObjective.setValue( ( objective.getValue().isLeft() ) ? objective.getValue().getLeft() : con.getChatSerializer().toString( objective.getValue().getRight() ) );
|
||||
oldObjective.setValue( ( objective.getValue().isLeft() ) ? objective.getValue().getLeft() : ComponentSerializer.toString( objective.getValue().getRight() ) );
|
||||
oldObjective.setType( objective.getType().toString() );
|
||||
}
|
||||
break;
|
||||
@ -283,16 +284,13 @@ public class DownstreamBridge extends PacketHandler
|
||||
{
|
||||
if ( team.getMode() == 0 || team.getMode() == 2 )
|
||||
{
|
||||
t.setDisplayName( team.getDisplayName().getLeftOrCompute( (component) -> con.getChatSerializer().toString( component ) ) );
|
||||
t.setPrefix( team.getPrefix().getLeftOrCompute( (component) -> con.getChatSerializer().toString( component ) ) );
|
||||
t.setSuffix( team.getSuffix().getLeftOrCompute( (component) -> con.getChatSerializer().toString( component ) ) );
|
||||
t.setDisplayName( team.getDisplayName().getLeftOrCompute( ComponentSerializer::toString ) );
|
||||
t.setPrefix( team.getPrefix().getLeftOrCompute( ComponentSerializer::toString ) );
|
||||
t.setSuffix( team.getSuffix().getLeftOrCompute( ComponentSerializer::toString ) );
|
||||
t.setFriendlyFire( team.getFriendlyFire() );
|
||||
t.setNameTagVisibility( team.getNameTagVisibility().getKey() );
|
||||
t.setNameTagVisibility( team.getNameTagVisibility() );
|
||||
t.setCollisionRule( team.getCollisionRule() );
|
||||
t.setColor( team.getColor() );
|
||||
if ( team.getCollisionRule() != null )
|
||||
{
|
||||
t.setCollisionRule( team.getCollisionRule().getKey() );
|
||||
}
|
||||
}
|
||||
if ( team.getPlayers() != null )
|
||||
{
|
||||
@ -339,7 +337,7 @@ public class DownstreamBridge extends PacketHandler
|
||||
throw CancelSendSignal.INSTANCE;
|
||||
}
|
||||
|
||||
if ( pluginMessage.getTag().equals( PluginMessage.BUNGEE_CHANNEL_LEGACY ) )
|
||||
if ( pluginMessage.getTag().equals( "BungeeCord" ) )
|
||||
{
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
String subChannel = in.readUTF();
|
||||
@ -363,7 +361,7 @@ public class DownstreamBridge extends PacketHandler
|
||||
out.write( data );
|
||||
byte[] payload = out.toByteArray();
|
||||
|
||||
target.getServer().sendData( PluginMessage.BUNGEE_CHANNEL_LEGACY, payload );
|
||||
target.getServer().sendData( "BungeeCord", payload );
|
||||
}
|
||||
|
||||
// Null out stream, important as we don't want to send to ourselves
|
||||
@ -395,7 +393,7 @@ public class DownstreamBridge extends PacketHandler
|
||||
{
|
||||
if ( server != this.server.getInfo() )
|
||||
{
|
||||
server.sendData( PluginMessage.BUNGEE_CHANNEL_LEGACY, payload );
|
||||
server.sendData( "BungeeCord", payload );
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -404,7 +402,7 @@ public class DownstreamBridge extends PacketHandler
|
||||
{
|
||||
if ( server != this.server.getInfo() )
|
||||
{
|
||||
server.sendData( PluginMessage.BUNGEE_CHANNEL_LEGACY, payload, false );
|
||||
server.sendData( "BungeeCord", payload, false );
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -412,7 +410,7 @@ public class DownstreamBridge extends PacketHandler
|
||||
ServerInfo server = bungee.getServerInfo( target );
|
||||
if ( server != null )
|
||||
{
|
||||
server.sendData( PluginMessage.BUNGEE_CHANNEL_LEGACY, payload );
|
||||
server.sendData( "BungeeCord", payload );
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -560,7 +558,7 @@ public class DownstreamBridge extends PacketHandler
|
||||
case "MessageRaw":
|
||||
{
|
||||
String target = in.readUTF();
|
||||
BaseComponent[] message = con.getChatSerializer().parse( in.readUTF() );
|
||||
BaseComponent[] message = ComponentSerializer.parse( in.readUTF() );
|
||||
if ( target.equals( "ALL" ) )
|
||||
{
|
||||
for ( ProxiedPlayer player : bungee.getPlayers() )
|
||||
@ -627,7 +625,7 @@ public class DownstreamBridge extends PacketHandler
|
||||
ProxiedPlayer player = bungee.getPlayer( in.readUTF() );
|
||||
if ( player != null )
|
||||
{
|
||||
BaseComponent[] kickReason = con.getChatSerializer().parse( in.readUTF() );
|
||||
BaseComponent[] kickReason = ComponentSerializer.parse( in.readUTF() );
|
||||
player.disconnect( kickReason );
|
||||
}
|
||||
break;
|
||||
@ -640,7 +638,7 @@ public class DownstreamBridge extends PacketHandler
|
||||
byte[] b = out.toByteArray();
|
||||
if ( b.length != 0 )
|
||||
{
|
||||
server.sendData( PluginMessage.BUNGEE_CHANNEL_LEGACY, b );
|
||||
server.sendData( "BungeeCord", b );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package net.md_5.bungee.connection;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.Gson;
|
||||
import io.netty.channel.EventLoop;
|
||||
import java.math.BigInteger;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
@ -122,12 +121,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
{
|
||||
ch.write( packet );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacketQueued(DefinedPacket packet)
|
||||
{
|
||||
throw new UnsupportedOperationException( "Not supported" );
|
||||
}
|
||||
};
|
||||
@Getter
|
||||
private boolean onlineMode = BungeeCord.getInstance().config.isOnlineMode();
|
||||
@ -203,6 +196,12 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(PluginMessage pluginMessage) throws Exception
|
||||
{
|
||||
this.relayMessage( pluginMessage );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(LegacyHandshake legacyHandshake) throws Exception
|
||||
{
|
||||
@ -238,6 +237,11 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
@Override
|
||||
public void done(ProxyPingEvent result, Throwable error)
|
||||
{
|
||||
if ( ch.isClosing() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ServerPing legacy = result.getResponse();
|
||||
String kickMessage;
|
||||
|
||||
@ -261,7 +265,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
}
|
||||
};
|
||||
|
||||
bungee.getPluginManager().callEvent( new ProxyPingEvent( InitialHandler.this, result, eventLoopCallback( callback ) ) );
|
||||
bungee.getPluginManager().callEvent( new ProxyPingEvent( InitialHandler.this, result, callback ) );
|
||||
}
|
||||
};
|
||||
|
||||
@ -314,7 +318,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
@Override
|
||||
public void done(ProxyPingEvent pingResult, Throwable error)
|
||||
{
|
||||
Gson gson = PingHandler.gson;
|
||||
Gson gson = BungeeCord.getInstance().gson;
|
||||
unsafe.sendPacket( new StatusResponse( gson.toJson( pingResult.getResponse() ) ) );
|
||||
if ( bungee.getConnectionThrottle() != null )
|
||||
{
|
||||
@ -323,7 +327,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
}
|
||||
};
|
||||
|
||||
bungee.getPluginManager().callEvent( new ProxyPingEvent( InitialHandler.this, result, eventLoopCallback( callback ) ) );
|
||||
bungee.getPluginManager().callEvent( new ProxyPingEvent( InitialHandler.this, result, callback ) );
|
||||
}
|
||||
};
|
||||
|
||||
@ -482,6 +486,10 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
disconnect( ( reason != null ) ? reason : TextComponent.fromLegacy( bungee.getTranslation( "kick_message" ) ) );
|
||||
return;
|
||||
}
|
||||
if ( ch.isClosing() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ( !realName.equals( name ) )
|
||||
{
|
||||
// Floodgate changes the name attribute with reflexion
|
||||
@ -505,7 +513,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
};
|
||||
|
||||
// fire pre login event
|
||||
bungee.getPluginManager().callEvent( new PreLoginEvent( InitialHandler.this, eventLoopCallback( callback ) ) );
|
||||
bungee.getPluginManager().callEvent( new PreLoginEvent( InitialHandler.this, callback ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -518,7 +526,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
BungeeCipher decrypt = EncryptionUtil.getCipher( false, sharedKey );
|
||||
ch.addBefore( PipelineUtils.FRAME_DECODER, PipelineUtils.DECRYPT_HANDLER, new CipherDecoder( decrypt ) );
|
||||
BungeeCipher encrypt = EncryptionUtil.getCipher( true, sharedKey );
|
||||
ch.addBefore( PipelineUtils.FRAME_PREPENDER_AND_COMPRESS, PipelineUtils.ENCRYPT_HANDLER, new CipherEncoder( encrypt ) );
|
||||
ch.addBefore( PipelineUtils.FRAME_PREPENDER, PipelineUtils.ENCRYPT_HANDLER, new CipherEncoder( encrypt ) );
|
||||
// disable use of composite buffers if we use natives
|
||||
ch.updateComposite();
|
||||
|
||||
@ -544,7 +552,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
{
|
||||
if ( error == null )
|
||||
{
|
||||
LoginResult obj = LoginResult.GSON.fromJson( result, LoginResult.class );
|
||||
LoginResult obj = BungeeCord.getInstance().gson.fromJson( result, LoginResult.class );
|
||||
if ( obj != null && obj.getId() != null )
|
||||
{
|
||||
loginProfile = obj;
|
||||
@ -640,21 +648,35 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
disconnect( ( reason != null ) ? reason : TextComponent.fromLegacy( bungee.getTranslation( "kick_message" ) ) );
|
||||
return;
|
||||
}
|
||||
|
||||
userCon = new UserConnection( bungee, ch, getName(), InitialHandler.this );
|
||||
userCon.setCompressionThreshold( BungeeCord.getInstance().config.getCompressionThreshold() );
|
||||
|
||||
if ( getVersion() < ProtocolConstants.MINECRAFT_1_20_2 )
|
||||
if ( ch.isClosing() )
|
||||
{
|
||||
unsafe.sendPacket( new LoginSuccess( getRewriteId(), getName(), ( loginProfile == null ) ? null : loginProfile.getProperties() ) );
|
||||
ch.setProtocol( Protocol.GAME );
|
||||
return;
|
||||
}
|
||||
finish2();
|
||||
|
||||
ch.getHandle().eventLoop().execute( new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if ( !ch.isClosing() )
|
||||
{
|
||||
userCon = new UserConnection( bungee, ch, getName(), InitialHandler.this );
|
||||
userCon.setCompressionThreshold( BungeeCord.getInstance().config.getCompressionThreshold() );
|
||||
|
||||
if ( getVersion() < ProtocolConstants.MINECRAFT_1_20_2 )
|
||||
{
|
||||
unsafe.sendPacket( new LoginSuccess( getRewriteId(), getName(), ( loginProfile == null ) ? null : loginProfile.getProperties() ) );
|
||||
ch.setProtocol( Protocol.GAME );
|
||||
}
|
||||
finish2();
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
};
|
||||
|
||||
// fire login event
|
||||
bungee.getPluginManager().callEvent( new LoginEvent( InitialHandler.this, eventLoopCallback( complete ) ) );
|
||||
bungee.getPluginManager().callEvent( new LoginEvent( InitialHandler.this, complete ) );
|
||||
}
|
||||
|
||||
private void finish2()
|
||||
@ -685,12 +707,18 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
@Override
|
||||
public void done(PostLoginEvent result, Throwable error)
|
||||
{
|
||||
// #3612: Don't progress further if disconnected during event
|
||||
if ( ch.isClosing() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
userCon.connect( result.getTarget(), null, true, ServerConnectEvent.Reason.JOIN_PROXY );
|
||||
}
|
||||
};
|
||||
|
||||
// fire post-login event
|
||||
bungee.getPluginManager().callEvent( new PostLoginEvent( userCon, initialServer, eventLoopCallback( complete ) ) );
|
||||
bungee.getPluginManager().callEvent( new PostLoginEvent( userCon, initialServer, complete ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -703,9 +731,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
}
|
||||
Preconditions.checkState( future != null, "Unexpected custom LoginPayloadResponse" );
|
||||
future.complete( response.getData() );
|
||||
|
||||
// we should never pass this to the backend
|
||||
throw CancelSendSignal.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -972,32 +997,4 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
unsafe.sendPacket( new LoginPayloadRequest( id, channel, data ) );
|
||||
return future;
|
||||
}
|
||||
|
||||
// this method is used for event execution
|
||||
// if this connection is disconnected during an event-call, the original callback is not called
|
||||
// if the event was executed async, we execute the callback on the eventloop again
|
||||
// otherwise netty will schedule any pipeline related call by itself, this decreases performance
|
||||
private <T> Callback<T> eventLoopCallback(Callback<T> callback)
|
||||
{
|
||||
return (result, error) ->
|
||||
{
|
||||
EventLoop eventLoop = ch.getHandle().eventLoop();
|
||||
if ( eventLoop.inEventLoop() )
|
||||
{
|
||||
if ( !ch.isClosing() )
|
||||
{
|
||||
callback.done( result, error );
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
eventLoop.execute( () ->
|
||||
{
|
||||
if ( !ch.isClosing() )
|
||||
{
|
||||
callback.done( result, error );
|
||||
}
|
||||
} );
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package net.md_5.bungee.connection;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import net.md_5.bungee.protocol.Property;
|
||||
@ -10,8 +9,6 @@ import net.md_5.bungee.protocol.Property;
|
||||
public class LoginResult
|
||||
{
|
||||
|
||||
public static final Gson GSON = new Gson();
|
||||
//
|
||||
private String id;
|
||||
private String name;
|
||||
private Property[] properties;
|
||||
|
@ -3,14 +3,12 @@ package net.md_5.bungee.connection;
|
||||
import com.google.gson.Gson;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.BungeeServerInfo;
|
||||
import net.md_5.bungee.PlayerInfoSerializer;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.Favicon;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.chat.VersionedComponentSerializer;
|
||||
import net.md_5.bungee.netty.ChannelWrapper;
|
||||
import net.md_5.bungee.netty.PacketHandler;
|
||||
import net.md_5.bungee.netty.PipelineUtils;
|
||||
@ -28,9 +26,6 @@ import net.md_5.bungee.util.QuietException;
|
||||
public class PingHandler extends PacketHandler
|
||||
{
|
||||
|
||||
static final Gson gson = VersionedComponentSerializer.getDefault().getGson().newBuilder()
|
||||
.registerTypeAdapter( ServerPing.PlayerInfo.class, new PlayerInfoSerializer() )
|
||||
.registerTypeAdapter( Favicon.class, Favicon.getFaviconTypeAdapter() ).create();
|
||||
private final ServerInfo target;
|
||||
private final Callback<ServerPing> callback;
|
||||
private final int protocol;
|
||||
@ -43,7 +38,7 @@ public class PingHandler extends PacketHandler
|
||||
MinecraftEncoder encoder = new MinecraftEncoder( Protocol.HANDSHAKE, false, protocol );
|
||||
|
||||
channel.getHandle().pipeline().addAfter( PipelineUtils.FRAME_DECODER, PipelineUtils.PACKET_DECODER, new MinecraftDecoder( Protocol.STATUS, false, ProxyServer.getInstance().getProtocolVersion() ) );
|
||||
channel.getHandle().pipeline().addAfter( PipelineUtils.FRAME_PREPENDER_AND_COMPRESS, PipelineUtils.PACKET_ENCODER, encoder );
|
||||
channel.getHandle().pipeline().addAfter( PipelineUtils.FRAME_PREPENDER, PipelineUtils.PACKET_ENCODER, encoder );
|
||||
|
||||
channel.write( new Handshake( protocol, target.getAddress().getHostString(), target.getAddress().getPort(), 1 ) );
|
||||
|
||||
@ -70,6 +65,7 @@ public class PingHandler extends PacketHandler
|
||||
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
|
||||
public void handle(StatusResponse statusResponse) throws Exception
|
||||
{
|
||||
Gson gson = BungeeCord.getInstance().gson;
|
||||
ServerPing serverPing = gson.fromJson( statusResponse.getResponse(), ServerPing.class );
|
||||
( (BungeeServerInfo) target ).cachePing( serverPing );
|
||||
callback.done( serverPing, null );
|
||||
|
@ -103,7 +103,7 @@ public class UpstreamBridge extends PacketHandler
|
||||
if ( player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_19_3 )
|
||||
{
|
||||
// need to queue, because players in config state could receive it
|
||||
player.unsafe().sendPacketQueued( newPacket );
|
||||
( (UserConnection) player ).sendPacketQueued( newPacket );
|
||||
} else
|
||||
{
|
||||
player.unsafe().sendPacket( oldPacket );
|
||||
@ -132,7 +132,7 @@ public class UpstreamBridge extends PacketHandler
|
||||
@Override
|
||||
public boolean shouldHandle(PacketWrapper packet) throws Exception
|
||||
{
|
||||
return con.getServer() != null || packet.packet instanceof PluginMessage || packet.packet instanceof CookieResponse || packet.packet instanceof LoginPayloadResponse;
|
||||
return con.getServer() != null || packet.packet instanceof PluginMessage || packet.packet instanceof CookieResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -312,7 +312,7 @@ public class UpstreamBridge extends PacketHandler
|
||||
@Override
|
||||
public void handle(PluginMessage pluginMessage) throws Exception
|
||||
{
|
||||
if ( pluginMessage.getTag().equals( PluginMessage.BUNGEE_CHANNEL_LEGACY ) || pluginMessage.getTag().equals( PluginMessage.BUNGEE_CHANNEL_MODERN ) )
|
||||
if ( pluginMessage.getTag().equals( "BungeeCord" ) )
|
||||
{
|
||||
throw CancelSendSignal.INSTANCE;
|
||||
}
|
||||
|
@ -93,8 +93,6 @@ public abstract class EntityMap
|
||||
return EntityMap_1_16_2.INSTANCE_1_21_2;
|
||||
case ProtocolConstants.MINECRAFT_1_21_4:
|
||||
return EntityMap_1_16_2.INSTANCE_1_21_4;
|
||||
case ProtocolConstants.MINECRAFT_1_21_5:
|
||||
return EntityMap_1_16_2.INSTANCE_1_21_5;
|
||||
}
|
||||
throw new RuntimeException( "Version " + version + " has no entity map" );
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ class EntityMap_1_16_2 extends EntityMap
|
||||
static final EntityMap_1_16_2 INSTANCE_1_20_5 = new EntityMap_1_16_2( -1, 0x37 );
|
||||
static final EntityMap_1_16_2 INSTANCE_1_21_2 = new EntityMap_1_16_2( -1, 0x39 );
|
||||
static final EntityMap_1_16_2 INSTANCE_1_21_4 = new EntityMap_1_16_2( -1, 0x3B );
|
||||
static final EntityMap_1_16_2 INSTANCE_1_21_5 = new EntityMap_1_16_2( -1, 0x3C );
|
||||
//
|
||||
private final int spawnPlayerId;
|
||||
private final int spectateId;
|
||||
|
@ -11,6 +11,7 @@ import java.util.logging.Level;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.compress.PacketCompressor;
|
||||
import net.md_5.bungee.compress.PacketDecompressor;
|
||||
import net.md_5.bungee.netty.cipher.CipherEncoder;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
@ -18,6 +19,7 @@ import net.md_5.bungee.protocol.MinecraftDecoder;
|
||||
import net.md_5.bungee.protocol.MinecraftEncoder;
|
||||
import net.md_5.bungee.protocol.PacketWrapper;
|
||||
import net.md_5.bungee.protocol.Protocol;
|
||||
import net.md_5.bungee.protocol.Varint21LengthFieldPrepender;
|
||||
import net.md_5.bungee.protocol.packet.Kick;
|
||||
|
||||
public class ChannelWrapper
|
||||
@ -130,11 +132,6 @@ public class ChannelWrapper
|
||||
{
|
||||
if ( !closed )
|
||||
{
|
||||
if ( !closing )
|
||||
{
|
||||
ch.config().setAutoRead( false );
|
||||
}
|
||||
|
||||
closed = closing = true;
|
||||
|
||||
if ( packet != null && ch.isActive() )
|
||||
@ -153,7 +150,6 @@ public class ChannelWrapper
|
||||
if ( !closing )
|
||||
{
|
||||
closing = true;
|
||||
ch.config().setAutoRead( false );
|
||||
|
||||
// Minecraft client can take some time to switch protocols.
|
||||
// Sending the wrong disconnect packet whilst a protocol switch is in progress will crash it.
|
||||
@ -184,29 +180,26 @@ public class ChannelWrapper
|
||||
|
||||
public void setCompressionThreshold(int compressionThreshold)
|
||||
{
|
||||
LengthPrependerAndCompressor compressor = ch.pipeline().get( LengthPrependerAndCompressor.class );
|
||||
PacketDecompressor decompressor = ch.pipeline().get( PacketDecompressor.class );
|
||||
if ( ch.pipeline().get( PacketCompressor.class ) == null && compressionThreshold >= 0 )
|
||||
{
|
||||
addBefore( PipelineUtils.PACKET_ENCODER, "compress", new PacketCompressor() );
|
||||
}
|
||||
if ( compressionThreshold >= 0 )
|
||||
{
|
||||
if ( !compressor.isCompress() )
|
||||
{
|
||||
compressor.setCompress( true );
|
||||
}
|
||||
compressor.setThreshold( compressionThreshold );
|
||||
|
||||
if ( decompressor == null )
|
||||
{
|
||||
addBefore( PipelineUtils.PACKET_DECODER, "decompress", decompressor = new PacketDecompressor() );
|
||||
}
|
||||
ch.pipeline().get( PacketCompressor.class ).setThreshold( compressionThreshold );
|
||||
} else
|
||||
{
|
||||
compressor.setCompress( false );
|
||||
if ( decompressor != null )
|
||||
{
|
||||
ch.pipeline().remove( "decompress" );
|
||||
}
|
||||
ch.pipeline().remove( "compress" );
|
||||
}
|
||||
|
||||
if ( ch.pipeline().get( PacketDecompressor.class ) == null && compressionThreshold >= 0 )
|
||||
{
|
||||
addBefore( PipelineUtils.PACKET_DECODER, "decompress", new PacketDecompressor() );
|
||||
}
|
||||
if ( compressionThreshold < 0 )
|
||||
{
|
||||
ch.pipeline().remove( "decompress" );
|
||||
}
|
||||
// disable use of composite buffers if we use natives
|
||||
updateComposite();
|
||||
}
|
||||
@ -217,16 +210,26 @@ public class ChannelWrapper
|
||||
public void updateComposite()
|
||||
{
|
||||
CipherEncoder cipherEncoder = ch.pipeline().get( CipherEncoder.class );
|
||||
LengthPrependerAndCompressor prependerAndCompressor = ch.pipeline().get( LengthPrependerAndCompressor.class );
|
||||
PacketCompressor packetCompressor = ch.pipeline().get( PacketCompressor.class );
|
||||
Varint21LengthFieldPrepender prepender = ch.pipeline().get( Varint21LengthFieldPrepender.class );
|
||||
boolean compressorCompose = cipherEncoder == null || cipherEncoder.getCipher().allowComposite();
|
||||
boolean prependerCompose = compressorCompose && ( packetCompressor == null || packetCompressor.getZlib().allowComposite() );
|
||||
|
||||
if ( prependerAndCompressor != null )
|
||||
if ( prepender != null )
|
||||
{
|
||||
ProxyServer.getInstance().getLogger().log( Level.FINE, "set prepender compose to {0} for {1}", new Object[]
|
||||
{
|
||||
prependerCompose, ch
|
||||
} );
|
||||
prepender.setCompose( prependerCompose );
|
||||
}
|
||||
if ( packetCompressor != null )
|
||||
{
|
||||
ProxyServer.getInstance().getLogger().log( Level.FINE, "set packetCompressor compose to {0} for {1}", new Object[]
|
||||
{
|
||||
compressorCompose, ch
|
||||
} );
|
||||
prependerAndCompressor.setCompose( compressorCompose );
|
||||
packetCompressor.setCompose( compressorCompose );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,23 +7,17 @@ import io.netty.handler.codec.CorruptedFrameException;
|
||||
import io.netty.handler.codec.DecoderException;
|
||||
import io.netty.handler.codec.haproxy.HAProxyMessage;
|
||||
import io.netty.handler.timeout.ReadTimeoutException;
|
||||
import io.netty.handler.timeout.WriteTimeoutException;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.logging.Level;
|
||||
import lombok.Setter;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.connection.CancelSendSignal;
|
||||
import net.md_5.bungee.connection.InitialHandler;
|
||||
import net.md_5.bungee.connection.PingHandler;
|
||||
import net.md_5.bungee.connection.UpstreamBridge;
|
||||
import net.md_5.bungee.protocol.BadPacketException;
|
||||
import net.md_5.bungee.protocol.OverflowPacketException;
|
||||
import net.md_5.bungee.protocol.PacketWrapper;
|
||||
import net.md_5.bungee.protocol.Protocol;
|
||||
import net.md_5.bungee.protocol.packet.Kick;
|
||||
import net.md_5.bungee.util.PacketLimiter;
|
||||
import net.md_5.bungee.util.QuietException;
|
||||
|
||||
/**
|
||||
@ -34,8 +28,6 @@ import net.md_5.bungee.util.QuietException;
|
||||
public class HandlerBoss extends ChannelInboundHandlerAdapter
|
||||
{
|
||||
|
||||
@Setter
|
||||
private PacketLimiter limiter;
|
||||
private ChannelWrapper channel;
|
||||
private PacketHandler handler;
|
||||
private boolean healthCheck;
|
||||
@ -115,35 +107,20 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter
|
||||
}
|
||||
|
||||
PacketWrapper packet = (PacketWrapper) msg;
|
||||
|
||||
try
|
||||
if ( packet.packet != null )
|
||||
{
|
||||
// check if the player exceeds packet limits, put inside try final, so we always release.
|
||||
if ( limiter != null && !limiter.incrementAndCheck( packet.buf.readableBytes() ) )
|
||||
Protocol nextProtocol = packet.packet.nextProtocol();
|
||||
if ( nextProtocol != null )
|
||||
{
|
||||
// we shouldn't tell the player what limits he exceeds by default
|
||||
// but if someone applies custom message we should allow them to display counter and bytes
|
||||
channel.close( handler instanceof UpstreamBridge ? new Kick( TextComponent.fromLegacy( ProxyServer.getInstance().getTranslation( "packet_limit_kick", limiter.getCounter(), limiter.getDataCounter() ) ) ) : null );
|
||||
// but the server admin should know
|
||||
ProxyServer.getInstance().getLogger().log( Level.WARNING, "{0} exceeded packet limit ({1} packets and {2} bytes per second)", new Object[]
|
||||
{
|
||||
handler, limiter.getCounter(), limiter.getDataCounter()
|
||||
} );
|
||||
return;
|
||||
channel.setDecodeProtocol( nextProtocol );
|
||||
}
|
||||
}
|
||||
|
||||
if ( packet.packet != null )
|
||||
if ( handler != null )
|
||||
{
|
||||
boolean sendPacket = handler.shouldHandle( packet );
|
||||
try
|
||||
{
|
||||
Protocol nextProtocol = packet.packet.nextProtocol();
|
||||
if ( nextProtocol != null )
|
||||
{
|
||||
channel.setDecodeProtocol( nextProtocol );
|
||||
}
|
||||
}
|
||||
|
||||
if ( handler != null )
|
||||
{
|
||||
boolean sendPacket = handler.shouldHandle( packet );
|
||||
if ( sendPacket && packet.packet != null )
|
||||
{
|
||||
try
|
||||
@ -158,10 +135,10 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter
|
||||
{
|
||||
handler.handle( packet );
|
||||
}
|
||||
} finally
|
||||
{
|
||||
packet.trySingleRelease();
|
||||
}
|
||||
} finally
|
||||
{
|
||||
packet.trySingleRelease();
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,9 +154,6 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter
|
||||
if ( cause instanceof ReadTimeoutException )
|
||||
{
|
||||
ProxyServer.getInstance().getLogger().log( Level.WARNING, "{0} - read timed out", handler );
|
||||
} else if ( cause instanceof WriteTimeoutException )
|
||||
{
|
||||
ProxyServer.getInstance().getLogger().log( Level.WARNING, "{0} - write timed out", handler );
|
||||
} else if ( cause instanceof DecoderException )
|
||||
{
|
||||
if ( cause instanceof CorruptedFrameException )
|
||||
|
@ -1,196 +0,0 @@
|
||||
package net.md_5.bungee.netty;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageEncoder;
|
||||
import java.util.List;
|
||||
import java.util.zip.Deflater;
|
||||
import lombok.Setter;
|
||||
import net.md_5.bungee.compress.CompressFactory;
|
||||
import net.md_5.bungee.jni.zlib.BungeeZlib;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
|
||||
/**
|
||||
* prepends length of message and optionally compresses message beforehand
|
||||
* <br>
|
||||
* combining these operations allows to keep space infront of compressed data for length varint
|
||||
*/
|
||||
public class LengthPrependerAndCompressor extends MessageToMessageEncoder<ByteBuf>
|
||||
{
|
||||
// reasonable to not support length varints > 4 byte (268435455 byte > 268MB)
|
||||
// if ever changed to smaller than 4, also change varintSize method to check for that
|
||||
private static final byte MAX_SUPPORTED_VARINT_LENGTH_LEN = 4;
|
||||
private static final byte FLAG_COMPRESS = 0x01;
|
||||
/**
|
||||
* overridden by FLAG_TWO_BUFFERS if set
|
||||
*/
|
||||
private static final byte FLAG_COMPOSE = 0x02;
|
||||
/**
|
||||
* overwrites FLAG_COMPOSE if set
|
||||
*/
|
||||
private static final byte FLAG_TWO_BUFFERS = 0x04;
|
||||
|
||||
public LengthPrependerAndCompressor(boolean compose, boolean twoBuffers)
|
||||
{
|
||||
setCompose( compose );
|
||||
setTwoBuffers( twoBuffers );
|
||||
}
|
||||
|
||||
private BungeeZlib zlib;
|
||||
@Setter
|
||||
private int threshold = 256;
|
||||
private byte flags = FLAG_COMPOSE;
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception
|
||||
{
|
||||
int oldBodyLen = msg.readableBytes();
|
||||
final byte flags = this.flags;
|
||||
if ( ( flags & FLAG_COMPRESS ) != 0 )
|
||||
{
|
||||
if ( oldBodyLen < threshold )
|
||||
{
|
||||
byte lengthLen = varintSize( oldBodyLen + 1 );
|
||||
if ( ( flags & FLAG_TWO_BUFFERS ) != 0 )
|
||||
{
|
||||
ByteBuf lenBuf = ctx.alloc().directBuffer( lengthLen );
|
||||
DefinedPacket.writeVarInt( oldBodyLen + 1, lenBuf );
|
||||
lenBuf.writeByte( 0 ); // indicates uncompressed
|
||||
out.add( lenBuf );
|
||||
out.add( msg.retain() );
|
||||
} else if ( ( flags & FLAG_COMPOSE ) != 0 )
|
||||
{
|
||||
// create a virtual buffer to avoid copying of data
|
||||
ByteBuf pre = ctx.alloc().directBuffer( lengthLen + 1 );
|
||||
DefinedPacket.writeVarInt( oldBodyLen + 1, pre );
|
||||
pre.writeByte( 0 ); // indicates uncompressed
|
||||
|
||||
out.add( ctx.alloc().compositeDirectBuffer( 2 ).addComponents( true, pre, msg.retain() ) );
|
||||
} else
|
||||
{
|
||||
ByteBuf buf = ctx.alloc().directBuffer( lengthLen + 1 + oldBodyLen );
|
||||
DefinedPacket.writeVarInt( oldBodyLen + 1, buf );
|
||||
out.add( buf.writeByte( 0 ).writeBytes( msg ) ); // 0 indicates uncompressed
|
||||
}
|
||||
} else
|
||||
{
|
||||
ByteBuf buf = ctx.alloc().directBuffer( BungeeZlib.OUTPUT_BUFFER_SIZE + MAX_SUPPORTED_VARINT_LENGTH_LEN + varintSize( oldBodyLen ) );
|
||||
buf.writerIndex( MAX_SUPPORTED_VARINT_LENGTH_LEN ); // Reserve space for packet length varint
|
||||
DefinedPacket.writeVarInt( oldBodyLen, buf ); // write uncompressed length
|
||||
zlib.process( msg, buf ); // compress data to buf
|
||||
|
||||
// write varint length of compressed directly infront of compressed data
|
||||
// leaves potential unused bytes at buffer start
|
||||
int writerIndex = buf.writerIndex();
|
||||
int compressedLen = writerIndex - MAX_SUPPORTED_VARINT_LENGTH_LEN;
|
||||
byte lengthLen = varintSize( compressedLen );
|
||||
int lengthStart = MAX_SUPPORTED_VARINT_LENGTH_LEN - lengthLen;
|
||||
DefinedPacket.setVarInt( compressedLen, buf, lengthStart, lengthLen );
|
||||
|
||||
buf.readerIndex( lengthStart ); // set start of buffer to ignore potential unused bytes before length
|
||||
out.add( buf );
|
||||
}
|
||||
} else
|
||||
{
|
||||
byte lengthLen = varintSize( oldBodyLen );
|
||||
if ( ( flags & FLAG_TWO_BUFFERS ) != 0 )
|
||||
{
|
||||
ByteBuf lenBuf = ctx.alloc().directBuffer( lengthLen );
|
||||
DefinedPacket.writeVarInt( oldBodyLen, lenBuf );
|
||||
out.add( lenBuf );
|
||||
out.add( msg.retain() );
|
||||
} else if ( ( flags & FLAG_COMPOSE ) != 0 )
|
||||
{
|
||||
// create a virtual buffer to avoid copying of data
|
||||
ByteBuf pre = ctx.alloc().directBuffer( lengthLen );
|
||||
DefinedPacket.writeVarInt( oldBodyLen, pre );
|
||||
out.add( ctx.alloc().compositeDirectBuffer( 2 ).addComponents( true, pre, msg.retain() ) );
|
||||
} else
|
||||
{
|
||||
ByteBuf buf = ctx.alloc().directBuffer( lengthLen + oldBodyLen );
|
||||
DefinedPacket.writeVarInt( oldBodyLen, buf );
|
||||
out.add( buf.writeBytes( msg ) ); // 0 indicates uncompressed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception
|
||||
{
|
||||
if ( zlib != null )
|
||||
{
|
||||
zlib.free();
|
||||
zlib = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCompose(boolean compose)
|
||||
{
|
||||
if ( compose )
|
||||
{
|
||||
flags |= FLAG_COMPOSE;
|
||||
} else
|
||||
{
|
||||
flags &= ~FLAG_COMPOSE;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCompress()
|
||||
{
|
||||
return ( flags & FLAG_COMPRESS ) != 0;
|
||||
}
|
||||
|
||||
public void setCompress(boolean compress)
|
||||
{
|
||||
if ( compress )
|
||||
{
|
||||
BungeeZlib zlib = this.zlib;
|
||||
if ( zlib == null )
|
||||
{
|
||||
this.zlib = zlib = CompressFactory.zlib.newInstance();
|
||||
}
|
||||
zlib.init( true, Deflater.DEFAULT_COMPRESSION );
|
||||
flags |= FLAG_COMPRESS;
|
||||
} else
|
||||
{
|
||||
flags &= ~FLAG_COMPRESS;
|
||||
if ( zlib != null )
|
||||
{
|
||||
zlib.free();
|
||||
zlib = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setTwoBuffers(boolean twoBuffers)
|
||||
{
|
||||
if ( twoBuffers )
|
||||
{
|
||||
flags |= FLAG_TWO_BUFFERS;
|
||||
} else
|
||||
{
|
||||
flags &= ~FLAG_TWO_BUFFERS;
|
||||
}
|
||||
}
|
||||
|
||||
private static byte varintSize(int value)
|
||||
{
|
||||
if ( ( value & 0xFFFFFF80 ) == 0 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if ( ( value & 0xFFFFC000 ) == 0 )
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
if ( ( value & 0xFFE00000 ) == 0 )
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
if ( ( value & 0xF0000000 ) == 0 )
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
throw new IllegalArgumentException( "Packet length " + value + " longer than supported (max. 268435455 for 4 byte varint)" );
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
|
||||
import io.netty.buffer.PooledByteBufAllocator;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelException;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.ServerChannel;
|
||||
@ -23,7 +24,6 @@ import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import io.netty.channel.unix.DomainSocketAddress;
|
||||
import io.netty.handler.codec.haproxy.HAProxyMessageDecoder;
|
||||
import io.netty.handler.timeout.ReadTimeoutHandler;
|
||||
import io.netty.handler.timeout.WriteTimeoutHandler;
|
||||
import io.netty.incubator.channel.uring.IOUring;
|
||||
import io.netty.incubator.channel.uring.IOUringDatagramChannel;
|
||||
import io.netty.incubator.channel.uring.IOUringEventLoopGroup;
|
||||
@ -49,80 +49,59 @@ import net.md_5.bungee.protocol.MinecraftDecoder;
|
||||
import net.md_5.bungee.protocol.MinecraftEncoder;
|
||||
import net.md_5.bungee.protocol.Protocol;
|
||||
import net.md_5.bungee.protocol.Varint21FrameDecoder;
|
||||
import net.md_5.bungee.protocol.channel.BungeeChannelInitializer;
|
||||
import net.md_5.bungee.protocol.channel.ChannelAcceptor;
|
||||
import net.md_5.bungee.util.PacketLimiter;
|
||||
import net.md_5.bungee.protocol.Varint21LengthFieldExtraBufPrepender;
|
||||
import net.md_5.bungee.protocol.Varint21LengthFieldPrepender;
|
||||
|
||||
public class PipelineUtils
|
||||
{
|
||||
|
||||
public static final AttributeKey<ListenerInfo> LISTENER = AttributeKey.valueOf( "ListerInfo" );
|
||||
|
||||
private static void setChannelInitializerHolders()
|
||||
public static final ChannelInitializer<Channel> SERVER_CHILD = new ChannelInitializer<Channel>()
|
||||
{
|
||||
ProxyServer.getInstance().unsafe().setFrontendChannelInitializer( BungeeChannelInitializer.create( ch ->
|
||||
@Override
|
||||
protected void initChannel(Channel ch) throws Exception
|
||||
{
|
||||
SocketAddress remoteAddress = ( ch.remoteAddress() == null ) ? ch.parent().localAddress() : ch.remoteAddress();
|
||||
|
||||
if ( BungeeCord.getInstance().getConnectionThrottle() != null && BungeeCord.getInstance().getConnectionThrottle().throttle( remoteAddress ) )
|
||||
{
|
||||
return false;
|
||||
ch.close();
|
||||
return;
|
||||
}
|
||||
|
||||
ListenerInfo listener = ch.attr( LISTENER ).get();
|
||||
|
||||
if ( BungeeCord.getInstance().getPluginManager().callEvent( new ClientConnectEvent( remoteAddress, listener ) ).isCancelled() )
|
||||
{
|
||||
return false;
|
||||
ch.close();
|
||||
return;
|
||||
}
|
||||
|
||||
BASE.accept( ch );
|
||||
BASE.initChannel( ch );
|
||||
ch.pipeline().addBefore( FRAME_DECODER, LEGACY_DECODER, new LegacyDecoder() );
|
||||
ch.pipeline().addAfter( FRAME_DECODER, PACKET_DECODER, new MinecraftDecoder( Protocol.HANDSHAKE, true, ProxyServer.getInstance().getProtocolVersion() ) );
|
||||
ch.pipeline().addAfter( FRAME_PREPENDER_AND_COMPRESS, PACKET_ENCODER, new MinecraftEncoder( Protocol.HANDSHAKE, true, ProxyServer.getInstance().getProtocolVersion() ) );
|
||||
ch.pipeline().addBefore( FRAME_PREPENDER_AND_COMPRESS, LEGACY_KICKER, legacyKicker );
|
||||
ch.pipeline().addAfter( FRAME_PREPENDER, PACKET_ENCODER, new MinecraftEncoder( Protocol.HANDSHAKE, true, ProxyServer.getInstance().getProtocolVersion() ) );
|
||||
ch.pipeline().addBefore( FRAME_PREPENDER, LEGACY_KICKER, legacyKicker );
|
||||
ch.pipeline().get( HandlerBoss.class ).setHandler( new InitialHandler( BungeeCord.getInstance(), listener ) );
|
||||
|
||||
HandlerBoss handlerBoss = ch.pipeline().get( HandlerBoss.class );
|
||||
handlerBoss.setHandler( new InitialHandler( BungeeCord.getInstance(), listener ) );
|
||||
|
||||
int packetLimit = BungeeCord.getInstance().getConfig().getMaxPacketsPerSecond();
|
||||
int packetDataLimit = BungeeCord.getInstance().getConfig().getMaxPacketDataPerSecond();
|
||||
if ( packetLimit > 0 || packetDataLimit > 0 )
|
||||
{
|
||||
handlerBoss.setLimiter( new PacketLimiter( packetLimit, packetDataLimit ) );
|
||||
}
|
||||
if ( listener.isProxyProtocol() )
|
||||
{
|
||||
ch.pipeline().addFirst( new HAProxyMessageDecoder() );
|
||||
}
|
||||
|
||||
return true;
|
||||
} ) );
|
||||
|
||||
ProxyServer.getInstance().unsafe().setBackendChannelInitializer( BungeeChannelInitializer.create( ch ->
|
||||
{
|
||||
PipelineUtils.BASE_SERVERSIDE.accept( ch );
|
||||
ch.pipeline().addAfter( PipelineUtils.FRAME_DECODER, PipelineUtils.PACKET_DECODER, new MinecraftDecoder( Protocol.HANDSHAKE, false, ProxyServer.getInstance().getProtocolVersion() ) );
|
||||
ch.pipeline().addAfter( PipelineUtils.FRAME_PREPENDER_AND_COMPRESS, PipelineUtils.PACKET_ENCODER, new MinecraftEncoder( Protocol.HANDSHAKE, false, ProxyServer.getInstance().getProtocolVersion() ) );
|
||||
|
||||
return true;
|
||||
} ) );
|
||||
|
||||
ProxyServer.getInstance().unsafe().setServerInfoChannelInitializer( BungeeChannelInitializer.create( BASE_SERVERSIDE ) );
|
||||
}
|
||||
|
||||
private static final ChannelAcceptor BASE = new Base( false );
|
||||
private static final ChannelAcceptor BASE_SERVERSIDE = new Base( true );
|
||||
}
|
||||
};
|
||||
public static final Base BASE = new Base( false );
|
||||
public static final Base BASE_SERVERSIDE = new Base( true );
|
||||
private static final KickStringWriter legacyKicker = new KickStringWriter();
|
||||
private static final Varint21LengthFieldExtraBufPrepender serverFramePrepender = new Varint21LengthFieldExtraBufPrepender();
|
||||
public static final String TIMEOUT_HANDLER = "timeout";
|
||||
public static final String WRITE_TIMEOUT_HANDLER = "write-timeout";
|
||||
public static final String PACKET_DECODER = "packet-decoder";
|
||||
public static final String PACKET_ENCODER = "packet-encoder";
|
||||
public static final String BOSS_HANDLER = "inbound-boss";
|
||||
public static final String ENCRYPT_HANDLER = "encrypt";
|
||||
public static final String DECRYPT_HANDLER = "decrypt";
|
||||
public static final String FRAME_DECODER = "frame-decoder";
|
||||
public static final String FRAME_PREPENDER_AND_COMPRESS = "frame-prepender-compress";
|
||||
public static final String FRAME_PREPENDER = "frame-prepender";
|
||||
public static final String LEGACY_DECODER = "legacy-decoder";
|
||||
public static final String LEGACY_KICKER = "legacy-kick";
|
||||
|
||||
@ -158,8 +137,6 @@ public class PipelineUtils
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setChannelInitializerHolders();
|
||||
}
|
||||
|
||||
public static EventLoopGroup newEventLoopGroup(int threads, ThreadFactory factory)
|
||||
@ -202,13 +179,13 @@ public class PipelineUtils
|
||||
|
||||
@NoArgsConstructor // for backwards compatibility
|
||||
@AllArgsConstructor
|
||||
public static final class Base implements ChannelAcceptor
|
||||
public static final class Base extends ChannelInitializer<Channel>
|
||||
{
|
||||
|
||||
private boolean toServer = false;
|
||||
|
||||
@Override
|
||||
public boolean accept(Channel ch)
|
||||
public void initChannel(Channel ch) throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -222,14 +199,11 @@ public class PipelineUtils
|
||||
|
||||
ch.pipeline().addLast( FRAME_DECODER, new Varint21FrameDecoder() );
|
||||
ch.pipeline().addLast( TIMEOUT_HANDLER, new ReadTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS ) );
|
||||
ch.pipeline().addLast( WRITE_TIMEOUT_HANDLER, new WriteTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS ) );
|
||||
// No encryption bungee -> server, therefore use extra buffer to avoid copying everything for length prepending
|
||||
// Not used bungee -> client as header would need to be encrypted separately through expensive JNI call
|
||||
// TODO: evaluate difference compose vs two buffers
|
||||
ch.pipeline().addLast( FRAME_PREPENDER_AND_COMPRESS, new LengthPrependerAndCompressor( true, toServer ) );
|
||||
ch.pipeline().addLast( BOSS_HANDLER, new HandlerBoss() );
|
||||
ch.pipeline().addLast( FRAME_PREPENDER, ( toServer ) ? serverFramePrepender : new Varint21LengthFieldPrepender() );
|
||||
|
||||
return true;
|
||||
ch.pipeline().addLast( BOSS_HANDLER, new HandlerBoss() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,45 +0,0 @@
|
||||
package net.md_5.bungee.util;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class PacketLimiter
|
||||
{
|
||||
|
||||
// max amount of packets allowed per second
|
||||
private final int limit;
|
||||
// max amount of data allowed per second
|
||||
private final int dataLimit;
|
||||
|
||||
@Getter
|
||||
private int counter;
|
||||
@Getter
|
||||
private int dataCounter;
|
||||
private long nextSecond;
|
||||
|
||||
/**
|
||||
* Counts the received packet amount and size.
|
||||
*
|
||||
* @param size size of the packet
|
||||
* @return return false if the player should be kicked
|
||||
*/
|
||||
public boolean incrementAndCheck(int size)
|
||||
{
|
||||
counter++;
|
||||
dataCounter += size;
|
||||
|
||||
if ( ( limit > 0 && counter > limit ) || ( dataLimit > 0 && dataCounter > dataLimit ) )
|
||||
{
|
||||
long now = System.currentTimeMillis();
|
||||
if ( nextSecond > now )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
nextSecond = now + 1000;
|
||||
counter = 0;
|
||||
dataCounter = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -41,4 +41,3 @@ command_ip=\u00a79IP of {0} is {1}
|
||||
illegal_chat_characters=\u00a7cIllegal characters in chat ({0})
|
||||
kick_message=\u00a7cYou have been kicked off the proxy.
|
||||
reject_transfer=\u00a7cYour transfer was rejected.
|
||||
packet_limit_kick=\u00a7cYou have sent too many packets
|
||||
|
@ -6,12 +6,12 @@
|
||||
<parent>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>bungeecord-query</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Query</name>
|
||||
|
@ -6,12 +6,12 @@
|
||||
<parent>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>bungeecord-slf4j</artifactId>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-SLF4J</name>
|
||||
|
Loading…
Reference in New Issue
Block a user