summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-01-22 01:00:49 +0500
committerilotterytea <iltsu@alright.party>2025-01-22 01:00:49 +0500
commitb3739521c1dcaed9bd451e00067b7d304521745f (patch)
tree04403d23708e2cdfa35452243323c9f24cde5e26 /server/src
parenta7f77c115bc95eb8a667df1146cc26dc17367879 (diff)
feat: player direction is now calculated by server
Diffstat (limited to 'server/src')
-rw-r--r--server/src/main/java/kz/ilotterytea/frogartha/server/FrogarthaServer.java3
-rw-r--r--server/src/main/java/kz/ilotterytea/frogartha/server/ServerHandlers.java11
2 files changed, 14 insertions, 0 deletions
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()));
+ }
}