From b3739521c1dcaed9bd451e00067b7d304521745f Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Wed, 22 Jan 2025 01:00:49 +0500 Subject: feat: player direction is now calculated by server --- .../java/kz/ilotterytea/frogartha/server/FrogarthaServer.java | 3 +++ .../java/kz/ilotterytea/frogartha/server/ServerHandlers.java | 11 +++++++++++ 2 files changed, 14 insertions(+) (limited to 'server') diff --git a/server/src/main/java/kz/ilotterytea/frogartha/server/FrogarthaServer.java b/server/src/main/java/kz/ilotterytea/frogartha/server/FrogarthaServer.java index c141bd9..1a94970 100644 --- a/server/src/main/java/kz/ilotterytea/frogartha/server/FrogarthaServer.java +++ b/server/src/main/java/kz/ilotterytea/frogartha/server/FrogarthaServer.java @@ -2,6 +2,7 @@ package kz.ilotterytea.frogartha.server; import com.github.czyzby.websocket.serialization.impl.ManualSerializer; import kz.ilotterytea.frogartha.domain.Identity; +import kz.ilotterytea.frogartha.domain.client.ChangedDirectionAction; import kz.ilotterytea.frogartha.domain.client.PlayerJumpAction; import kz.ilotterytea.frogartha.exceptions.PlayerKickException; import kz.ilotterytea.frogartha.utils.Logger; @@ -81,6 +82,8 @@ public class FrogarthaServer extends WebSocketServer { ServerHandlers.handleIdentity(player, (Identity) obj); } else if (obj instanceof PlayerJumpAction) { ServerHandlers.handlePlayerJumpAction(player, (PlayerJumpAction) obj); + } else if (obj instanceof ChangedDirectionAction) { + ServerHandlers.handleChangedDirectionAction(player, (ChangedDirectionAction) obj); } else { throw PlayerKickException.internalServerError(); } diff --git a/server/src/main/java/kz/ilotterytea/frogartha/server/ServerHandlers.java b/server/src/main/java/kz/ilotterytea/frogartha/server/ServerHandlers.java index 44162ae..b6dcc3c 100644 --- a/server/src/main/java/kz/ilotterytea/frogartha/server/ServerHandlers.java +++ b/server/src/main/java/kz/ilotterytea/frogartha/server/ServerHandlers.java @@ -4,8 +4,10 @@ import com.badlogic.gdx.math.Vector3; import kz.ilotterytea.frogartha.FrogarthaConstants; import kz.ilotterytea.frogartha.domain.Identity; import kz.ilotterytea.frogartha.domain.PlayerState; +import kz.ilotterytea.frogartha.domain.client.ChangedDirectionAction; import kz.ilotterytea.frogartha.domain.client.PlayerJumpAction; import kz.ilotterytea.frogartha.domain.server.Acknowledge; +import kz.ilotterytea.frogartha.events.ChangedDirectionEvent; import kz.ilotterytea.frogartha.events.PlayerJumpEvent; import kz.ilotterytea.frogartha.exceptions.PlayerKickException; import kz.ilotterytea.frogartha.utils.Logger; @@ -59,4 +61,13 @@ public class ServerHandlers { )); log.log("{} jumped from {} to {} with strength {}", player, startPosition, endPosition, action.getJumpStrength()); } + + public static void handleChangedDirectionAction(PlayerConnection player, ChangedDirectionAction action) { + PlayerState state = player.getState(); + Vector3 direction = action.getDirection(); + + state.setDirection(direction.x, state.getPosition().y, direction.z); + + player.send(new ChangedDirectionEvent(player.getId(), state.getDirection())); + } } -- cgit v1.2.3