mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-01 00:10:19 +01:00
Add ChatSession
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
915836f490
commit
0488915fda
18
src/main/java/net/minestom/server/crypto/ChatSession.java
Normal file
18
src/main/java/net/minestom/server/crypto/ChatSession.java
Normal file
@ -0,0 +1,18 @@
|
||||
package net.minestom.server.crypto;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public record ChatSession(@NotNull UUID sessionId, @NotNull PlayerPublicKey publicKey) implements NetworkBuffer.Writer {
|
||||
public ChatSession(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(NetworkBuffer.UUID), new PlayerPublicKey(reader));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(NetworkBuffer.UUID, sessionId);
|
||||
writer.write(publicKey);
|
||||
}
|
||||
}
|
@ -1927,7 +1927,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
List.of(new PlayerInfoUpdatePacket.Property("textures", skin.textures(), skin.signature())) :
|
||||
List.of();
|
||||
return new PlayerInfoUpdatePacket.Entry(getUuid(), getUsername(), prop,
|
||||
true, getLatency(), getGameMode(), displayName);
|
||||
true, getLatency(), getGameMode(), displayName, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,22 +1,17 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.crypto.PlayerPublicKey;
|
||||
import net.minestom.server.crypto.ChatSession;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public record ClientChatSessionUpdatePacket(@NotNull UUID sessionId,
|
||||
@Nullable PlayerPublicKey publicKey) implements ClientPacket {
|
||||
public record ClientChatSessionUpdatePacket(@NotNull ChatSession chatSession) implements ClientPacket {
|
||||
public ClientChatSessionUpdatePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(NetworkBuffer.UUID), new PlayerPublicKey(reader));
|
||||
this(new ChatSession(reader));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(NetworkBuffer.UUID, sessionId);
|
||||
writer.writeOptional(publicKey);
|
||||
writer.write(chatSession);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.crypto.MessageSignature;
|
||||
import net.minestom.server.crypto.FilterMask;
|
||||
import net.minestom.server.crypto.SignedMessageBody;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
@ -9,6 +10,7 @@ import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -19,26 +21,30 @@ import static net.minestom.server.network.NetworkBuffer.*;
|
||||
/**
|
||||
* Represents an outgoing chat message packet.
|
||||
*/
|
||||
public record PlayerChatMessagePacket(@NotNull Component signedContent, @Nullable Component unsignedContent,
|
||||
int type, @NotNull UUID uuid,
|
||||
@NotNull Component displayName, @Nullable Component teamDisplayName,
|
||||
@NotNull MessageSignature signature) implements ComponentHoldingServerPacket {
|
||||
public record PlayerChatMessagePacket(UUID sender, int index, byte @Nullable [] signature,
|
||||
SignedMessageBody.@NotNull Packed messageBody,
|
||||
@Nullable Component unsignedContent, FilterMask filterMask,
|
||||
int msgTypeId, Component msgTypeName,
|
||||
@Nullable Component msgTypeTarget) implements ComponentHoldingServerPacket {
|
||||
public PlayerChatMessagePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(COMPONENT), reader.readOptional(COMPONENT),
|
||||
reader.read(VAR_INT), reader.read(NetworkBuffer.UUID),
|
||||
reader.read(COMPONENT), reader.readOptional(COMPONENT),
|
||||
new MessageSignature(reader));
|
||||
this(reader.read(UUID), reader.read(VAR_INT), reader.readOptional(r -> r.readBytes(256)),
|
||||
new SignedMessageBody.Packed(reader),
|
||||
reader.readOptional(COMPONENT), new FilterMask(reader),
|
||||
reader.read(VAR_INT), reader.read(COMPONENT),
|
||||
reader.readOptional(COMPONENT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(COMPONENT, signedContent);
|
||||
writer.write(UUID, sender);
|
||||
writer.write(VAR_INT, index);
|
||||
writer.writeOptional(RAW_BYTES, signature);
|
||||
writer.write(messageBody);
|
||||
writer.writeOptional(COMPONENT, unsignedContent);
|
||||
writer.write(VAR_INT, type);
|
||||
writer.write(UUID, uuid);
|
||||
writer.write(COMPONENT, displayName);
|
||||
writer.writeOptional(COMPONENT, teamDisplayName);
|
||||
writer.write(signature);
|
||||
writer.write(filterMask);
|
||||
writer.write(VAR_INT, msgTypeId);
|
||||
writer.write(COMPONENT, msgTypeName);
|
||||
writer.writeOptional(COMPONENT, msgTypeTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -48,12 +54,19 @@ public record PlayerChatMessagePacket(@NotNull Component signedContent, @Nullabl
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<Component> components() {
|
||||
return List.of(signedContent);
|
||||
final ArrayList<Component> list = new ArrayList<>();
|
||||
list.add(msgTypeName);
|
||||
if (unsignedContent != null) list.add(unsignedContent);
|
||||
if (msgTypeTarget != null) list.add(msgTypeTarget);
|
||||
return List.copyOf(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ServerPacket copyWithOperator(@NotNull UnaryOperator<Component> operator) {
|
||||
return new PlayerChatMessagePacket(signedContent, unsignedContent, type,
|
||||
uuid, displayName, teamDisplayName, signature);
|
||||
return new PlayerChatMessagePacket(sender, index, signature,
|
||||
messageBody,
|
||||
operator.apply(unsignedContent), filterMask,
|
||||
msgTypeId, operator.apply(msgTypeName),
|
||||
operator.apply(msgTypeTarget));
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.crypto.ChatSession;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
@ -43,7 +44,7 @@ public record PlayerInfoUpdatePacket(@NotNull EnumSet<@NotNull Action> actions,
|
||||
|
||||
public record Entry(UUID uuid, String username, List<Property> properties,
|
||||
boolean listed, int latency, GameMode gameMode,
|
||||
@Nullable Component displayName) {
|
||||
@Nullable Component displayName, @Nullable ChatSession chatSession) {
|
||||
public Entry {
|
||||
properties = List.copyOf(properties);
|
||||
}
|
||||
@ -73,7 +74,7 @@ public record PlayerInfoUpdatePacket(@NotNull EnumSet<@NotNull Action> actions,
|
||||
writer.write(STRING, entry.username);
|
||||
writer.writeCollection(entry.properties);
|
||||
}),
|
||||
INITIALIZE_CHAT(null),
|
||||
INITIALIZE_CHAT((writer, entry) -> writer.writeOptional(entry.chatSession)),
|
||||
UPDATE_GAME_MODE((writer, entry) -> writer.write(VAR_INT, entry.gameMode.ordinal())),
|
||||
UPDATE_LISTED((writer, entry) -> writer.write(BOOLEAN, entry.listed)),
|
||||
UPDATE_LATENCY((writer, entry) -> writer.write(VAR_INT, entry.latency)),
|
||||
|
Loading…
Reference in New Issue
Block a user