From 4826760d732518f120ff7534006295ca891b2529 Mon Sep 17 00:00:00 2001 From: Jonas Date: Sun, 8 Mar 2026 21:45:05 +0100 Subject: [PATCH] Support player names and online join flow Move SignalR group join into GameManager and add support for player names and improved online join flow. - Moved Groups.AddToGroupAsync call out of GameHubSocket into GameManager (hubContext.Groups.AddToGroupAsync) so group membership is handled when adding players to a game. - GUI: added player name input to GameJoinMenu and updated JoinGameObject to include playerName and use string gameCode. - OnlineMode & LocalMode: constructors updated to instantiate games without passing settings; removed WaitingForOpponent state and cleaned up event bindings. - OnlineGame: rewrote to handle onGameCreated/onGameJoined/onGameStarted/onFieldUpdated/onGameEnded/onError, added joinGame validation (expects 6-digit code), join flow (connect + join), state updates, drop forwarding to player.drop(gameId, index) and place description updates. - LocalGame: constructor signature simplified to no-arg. These changes centralize group management, add player identification, validate join codes, and improve game state/event handling for online play. --- API/Controllers/GameHubSocket.cs | 2 - API/Services/GameManager/GameManager.cs | 3 + GUI/src/components/GameJoinMenu.vue | 5 ++ GUI/src/routes/LocalMode.vue | 2 +- GUI/src/routes/OnlineMode.vue | 28 ++++++-- GUI/src/scripts/interfaces/JoinGameObject.ts | 3 +- GUI/src/scripts/logic/localMode/LocalGame.ts | 2 +- .../scripts/logic/onlineMode/OnlineGame.ts | 72 +++++++++++++++++-- 8 files changed, 100 insertions(+), 17 deletions(-) diff --git a/API/Controllers/GameHubSocket.cs b/API/Controllers/GameHubSocket.cs index d284cea..f014114 100644 --- a/API/Controllers/GameHubSocket.cs +++ b/API/Controllers/GameHubSocket.cs @@ -42,8 +42,6 @@ public class GameHubSocket(IGameManager gameManager) : Hub return; } - await Groups.AddToGroupAsync(Context.ConnectionId, result); - await Clients.Caller.SendAsync("GameJoined", new { GameId = result, diff --git a/API/Services/GameManager/GameManager.cs b/API/Services/GameManager/GameManager.cs index c64a9d6..81b9677 100644 --- a/API/Services/GameManager/GameManager.cs +++ b/API/Services/GameManager/GameManager.cs @@ -3,6 +3,7 @@ using API.Models.DataClasses; using API.Models.Game; using API.Repository.GameRepo; using Microsoft.AspNetCore.SignalR; +using System.Text.RegularExpressions; namespace API.Services.GameManager; @@ -27,6 +28,8 @@ public class GameManager(IGameRepository gameRepository, IHubContext('joinGameObject', { dein Freund gegeben hat. + ({ }); var currentState = ref(CurrentState.CreatingGame); -const game = ref(new LocalGame(settings.value)); +const game = ref(new LocalGame()); const gameField = ref([]); const currentSelectionIndex = ref(null); const gameEndedInformation = ref(null); diff --git a/GUI/src/routes/OnlineMode.vue b/GUI/src/routes/OnlineMode.vue index 4cfabbf..7282855 100644 --- a/GUI/src/routes/OnlineMode.vue +++ b/GUI/src/routes/OnlineMode.vue @@ -1,5 +1,7 @@