-
Notifications
You must be signed in to change notification settings - Fork 0
Implement backend cheat validation #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
49a10b3
Implement backend cheat functionality
Zheaver 1f8862b
Implement backend cheat validation tests
Zheaver 27bbbfe
Merge branch 'development' into feature/cheat-validation
Zheaver f5ebb29
Resolve merge conflicts and refactor cheat handling
Zheaver 7878e5c
Persist cheat flags for game state recovery
Zheaver 51dcfc2
Fix Sonar issues
Zheaver 1ca23e3
Add migration for cheat flags
Zheaver 19dee71
Merge branch 'development' into feature/cheat-validation
Zheaver a193523
Merge branch 'development' into feature/cheat-validation
Zheaver be8ae70
Fix cheat system message handling
Zheaver 5b9c0d4
Merge branch 'feature/cheat-validation' of https://github.com/SS26-SE…
Zheaver File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,5 +4,6 @@ | |
| * Enum representing the type of chat message. | ||
| */ | ||
| public enum ChatMessageType { | ||
| CHAT | ||
| } | ||
| CHAT, | ||
| SYSTEM | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/codenames/codenames/backend/game/api/dto/CheatCardMessage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package com.codenames.codenames.backend.game.api.dto; | ||
|
|
||
| import java.util.List; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| /** | ||
| * WebSocket message for requesting a cheat check on selected cards. | ||
| */ | ||
| @Getter | ||
| @Setter | ||
| public class CheatCardMessage { | ||
| private String lobbyCode; | ||
| private String username; | ||
| private List<Integer> positions; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/com/codenames/codenames/backend/game/application/CheatService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package com.codenames.codenames.backend.game.application; | ||
|
|
||
| import com.codenames.codenames.backend.game.domain.CheatResult; | ||
| import com.codenames.codenames.backend.lobby.application.LobbyService; | ||
| import com.codenames.codenames.backend.lobby.domain.Role; | ||
| import com.codenames.codenames.backend.lobby.domain.Team; | ||
| import java.util.List; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| /** Service responsible for validating and executing cheat requests. */ | ||
| @Service | ||
| public class CheatService { | ||
|
|
||
| private final GameService gameService; | ||
| private final LobbyService lobbyService; | ||
|
|
||
| /** | ||
| * Creates a new cheat service. | ||
| * | ||
| * @param gameService service responsible for game logic | ||
| * @param lobbyService service responsible for lobby/player data | ||
| */ | ||
| public CheatService(GameService gameService, LobbyService lobbyService) { | ||
| this.gameService = gameService; | ||
| this.lobbyService = lobbyService; | ||
| } | ||
|
|
||
| /** | ||
| * Performs a cheat request for a player. | ||
| * | ||
| * @param lobbyCode the lobby code | ||
| * @param username the requesting username | ||
| * @param positions selected card positions | ||
| * @return the cheat result or null if the request is invalid | ||
| */ | ||
| public CheatResult useCheat(String lobbyCode, String username, List<Integer> positions) { | ||
| Team team = lobbyService.getPlayerTeam(username, lobbyCode); | ||
| Role role = lobbyService.getPlayerRole(username, lobbyCode); | ||
|
|
||
| if (team == null || role != Role.OPERATIVE) { | ||
| return null; | ||
| } | ||
|
|
||
| return gameService.useCheat(lobbyCode, positions, team); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/codenames/codenames/backend/game/domain/CheatResult.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.codenames.codenames.backend.game.domain; | ||
|
|
||
| import com.codenames.codenames.backend.lobby.domain.Team; | ||
| /** | ||
| * Result of a cheat attempt. | ||
| * | ||
| * @param message private message for the player | ||
| * @param team the team that used the cheat | ||
| */ | ||
| public record CheatResult( | ||
| String message, | ||
| Team team) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.