-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
154 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientCommandSigned.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package net.md_5.bungee.protocol.packet; | ||
|
||
import com.google.common.base.Preconditions; | ||
import io.netty.buffer.ByteBuf; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
import net.md_5.bungee.protocol.AbstractPacketHandler; | ||
import net.md_5.bungee.protocol.ChatChain; | ||
import net.md_5.bungee.protocol.DefinedPacket; | ||
import net.md_5.bungee.protocol.ProtocolConstants; | ||
import net.md_5.bungee.protocol.SeenMessages; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@EqualsAndHashCode(callSuper = false) | ||
public class ClientCommandSigned extends DefinedPacket | ||
{ | ||
|
||
private String command; | ||
private long timestamp; | ||
private long salt; | ||
private Map<String, byte[]> signatures; | ||
private boolean signedPreview; | ||
private ChatChain chain; | ||
private SeenMessages seenMessages; | ||
|
||
@Override | ||
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) | ||
{ | ||
command = readString( buf, 256 ); | ||
timestamp = buf.readLong(); | ||
salt = buf.readLong(); | ||
|
||
int cnt = readVarInt( buf ); | ||
Preconditions.checkArgument( cnt <= 8, "Too many signatures" ); | ||
signatures = new HashMap<>( cnt ); | ||
for ( int i = 0; i < cnt; i++ ) | ||
{ | ||
String name = readString( buf, 16 ); | ||
byte[] signature; | ||
|
||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_3 ) | ||
{ | ||
signature = new byte[ 256 ]; | ||
buf.readBytes( signature ); | ||
} else | ||
{ | ||
signature = readArray( buf ); | ||
} | ||
signatures.put( name, signature ); | ||
} | ||
|
||
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_19_3 ) | ||
{ | ||
signedPreview = buf.readBoolean(); | ||
} | ||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_3 ) | ||
{ | ||
seenMessages = new SeenMessages(); | ||
seenMessages.read( buf, direction, protocolVersion ); | ||
} else if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 ) | ||
{ | ||
chain = new ChatChain(); | ||
chain.read( buf, direction, protocolVersion ); | ||
} | ||
} | ||
|
||
@Override | ||
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) | ||
{ | ||
writeString( command, buf ); | ||
buf.writeLong( timestamp ); | ||
buf.writeLong( salt ); | ||
|
||
writeVarInt( signatures.size(), buf ); | ||
for ( Map.Entry<String, byte[]> entry : signatures.entrySet() ) | ||
{ | ||
writeString( entry.getKey(), buf ); | ||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_3 ) | ||
{ | ||
buf.writeBytes( entry.getValue() ); | ||
} else | ||
{ | ||
writeArray( entry.getValue(), buf ); | ||
} | ||
} | ||
|
||
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_19_3 ) | ||
{ | ||
buf.writeBoolean( signedPreview ); | ||
} | ||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_3 ) | ||
{ | ||
seenMessages.write( buf, direction, protocolVersion ); | ||
} else if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 ) | ||
{ | ||
chain.write( buf, direction, protocolVersion ); | ||
} | ||
} | ||
|
||
@Override | ||
public void handle(AbstractPacketHandler handler) throws Exception | ||
{ | ||
handler.handle( this ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters