From 835c2fdb6c1f1064ebb0eece8816cd4edfee3ec8 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Tue, 28 Jan 2025 22:44:58 +0500 Subject: feat: set the server constants on connect --- .../domain/events/ServerOptionsEvent.java | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 shared/src/main/java/kz/ilotterytea/frogartha/domain/events/ServerOptionsEvent.java (limited to 'shared/src/main/java/kz/ilotterytea/frogartha/domain') diff --git a/shared/src/main/java/kz/ilotterytea/frogartha/domain/events/ServerOptionsEvent.java b/shared/src/main/java/kz/ilotterytea/frogartha/domain/events/ServerOptionsEvent.java new file mode 100644 index 0000000..7393375 --- /dev/null +++ b/shared/src/main/java/kz/ilotterytea/frogartha/domain/events/ServerOptionsEvent.java @@ -0,0 +1,83 @@ +package kz.ilotterytea.frogartha.domain.events; + +import com.github.czyzby.websocket.serialization.SerializationException; +import com.github.czyzby.websocket.serialization.Transferable; +import com.github.czyzby.websocket.serialization.impl.Deserializer; +import com.github.czyzby.websocket.serialization.impl.Serializer; +import kz.ilotterytea.frogartha.FrogarthaConstants; + +public class ServerOptionsEvent extends Event implements Transferable { + private final int chatMaxMessageLength, chatMessagePerMilliseconds; + private final float playerMaxJumpStrength, playerMaxJumpHeight, playerJumpSpeed; + + public ServerOptionsEvent() { + this.chatMaxMessageLength = FrogarthaConstants.Chat.MAX_MESSAGE_LENGTH; + this.chatMessagePerMilliseconds = FrogarthaConstants.Chat.MESSAGE_PER_MS; + this.playerMaxJumpStrength = FrogarthaConstants.Player.MAX_JUMP_STRENGTH; + this.playerMaxJumpHeight = FrogarthaConstants.Player.MAX_JUMP_HEIGHT; + this.playerJumpSpeed = FrogarthaConstants.Player.JUMP_SPEED; + } + + public ServerOptionsEvent( + int chatMaxMessageLength, int chatMessagePerMilliseconds, + float playerMaxJumpStrength, float playerMaxJumpHeight, float playerJumpSpeed + ) { + this.chatMaxMessageLength = chatMaxMessageLength; + this.chatMessagePerMilliseconds = chatMessagePerMilliseconds; + this.playerMaxJumpStrength = playerMaxJumpStrength; + this.playerMaxJumpHeight = playerMaxJumpHeight; + this.playerJumpSpeed = playerJumpSpeed; + } + + public int getChatMaxMessageLength() { + return chatMaxMessageLength; + } + + public int getChatMessagePerMilliseconds() { + return chatMessagePerMilliseconds; + } + + public float getPlayerMaxJumpStrength() { + return playerMaxJumpStrength; + } + + public float getPlayerMaxJumpHeight() { + return playerMaxJumpHeight; + } + + public float getPlayerJumpSpeed() { + return playerJumpSpeed; + } + + @Override + public void serialize(Serializer serializer) throws SerializationException { + serializer + .serializeInt(chatMaxMessageLength) + .serializeInt(chatMessagePerMilliseconds) + .serializeFloat(playerMaxJumpStrength) + .serializeFloat(playerMaxJumpHeight) + .serializeFloat(playerJumpSpeed); + } + + @Override + public ServerOptionsEvent deserialize(Deserializer deserializer) throws SerializationException { + return new ServerOptionsEvent( + deserializer.deserializeInt(), + deserializer.deserializeInt(), + deserializer.deserializeFloat(), + deserializer.deserializeFloat(), + deserializer.deserializeFloat() + ); + } + + @Override + public String toString() { + return "ServerOptionsEvent{" + + "chatMaxMessageLength=" + chatMaxMessageLength + + ", chatMessagePerMilliseconds=" + chatMessagePerMilliseconds + + ", playerMaxJumpStrength=" + playerMaxJumpStrength + + ", playerMaxJumpHeight=" + playerMaxJumpHeight + + ", playerJumpSpeed=" + playerJumpSpeed + + '}'; + } +} -- cgit v1.2.3