Skip to content

Implement backend cheat validation#155

Open
Zheaver wants to merge 2 commits into
developmentfrom
feature/cheat-validation
Open

Implement backend cheat validation#155
Zheaver wants to merge 2 commits into
developmentfrom
feature/cheat-validation

Conversation

@Zheaver

@Zheaver Zheaver commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Overview

Implemented the backend logic for the cheat functionality.

Features

  • Added cheat validation in GameManager
  • Added CheatCardMessage and CheatResult
  • Added useCheat() to GameService
  • Added /cheat websocket endpoint in GameSocketController
  • Added SYSTEM chat messages
  • Added persistence of cheat usage state
  • Added recovery support for cheat flags

Validation Rules

  • Only operatives can use the cheat
  • Cheat only works during the operative phase
  • Each team can use the cheat only once per match
  • At least one card must be selected
  • Invalid or already guessed cards are ignored
  • If at least one selected card belongs to the team, one correct card is returned
  • Otherwise a message indicating that none of the selected cards are correct is returned
  • The cheat result is sent only to the requesting player

Closes #123

@sonarqubecloud

Copy link
Copy Markdown

@the-only-queen-anna the-only-queen-anna left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grundsätzlich würde ich sagen, das passt so, ich hab dir ein paar Vorschläge noch kommentiert, eventuell findest du ja was davon sinnvoll. Besonders das Logik in den Service verschieben wäre glaub ich besser.

result.message(),
ChatMessageType.SYSTEM);

messagingTemplate.convertAndSendToUser(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hast du getestet, ob das so funktioniert? Ich hatte mit sendToUser schon öfters Probleme

* @param message the cheat request containing lobby, username and selected cards
*/
@MessageMapping("/cheat")
public void useCheat(CheatCardMessage message) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Für einen Controller ist hier ziemlich viel Logik drin. Am besten das meiste in den GameService verschieben, dann brauchst du auch nicht die zusätzliche Dependency zum LobbyService.

*
* @param message private message for the player
*/
public record CheatResult(String message) {} No newline at end of file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wenn du nur einen String drin hast, könntest du theoretisch auch die Wrapper-Klasse weglassen. Vor allem, weil das ja rein backend-intern ist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants