GameRoomController - xEdziu/RPG-Handy-Helper GitHub Wiki

GameRoomController

This page documents the GameRoomController, responsible for managing game room creation, history tracking, and retrieving active room information.

Basic Information

Base Path: /api/v1/authorized/gameRoom
Package: dev.goral.rpghandyhelper.chat

Authentication

All endpoints require a valid XSRF token in headers:

headers: {
  "X-XSRF-TOKEN": "<csrfToken>"
}

Endpoint Summary

HTTP Method Path Description
POST /create Create a new game room (GameMaster only)
GET /gameIdForRoomId/{roomId} Retrieve game ID for a given room ID
GET /history Retrieve game room history
GET /active Retrieve currently active rooms for a specific game

Field Descriptions

Request Parameters

  • gameId (Long): ID of the game. Required in /create and /active.

Path Variables

  • roomId (String): ID of the room. Used in /gameIdForRoomId/{roomId}.

Response Fields

  • message (String): Operation status message.
  • error (Integer): HTTP status code.
  • timestamp (String): Response timestamp.
  • Additional fields like roomId, url, gameId, history, activeRooms depending on endpoint.

Example Objects

Example history Entry

{
  "gameId": 1,
  "durationMinutes": 5,
  "gameName": "game name",
  "createdBy": "user1",
  "endedAt": "...",
  "startedAt": "...",
  "roomId": "A1B2C3D4",
  "participants": [
    "user1"
  ]
}

Example activeRooms entry

{
  "gameId": 1,
  "createdAt": "...",
  "creatorId": 1,
  "connectedUsers": [
    "user1"
  ],
  "roomId": "A1B2C3D4"
}

Endpoint Details

Create a New Game Room

Method: POST
Path: /create

Request Parameters

  • gameId (Long): ID of the game to create room for.

Response Example

{
  "message": "Stworzono pokój gry.",
  "error": 200,
  "timestamp": "...",
  "roomId": "A1B2C3D4",
  "url": "/room/A1B2C3D4"
}

Possible Errors

  • 400 Bad Request: Invalid request or user not authorized.
  • 403 Forbidden: User is not the GameMaster or game is not active.
  • 404 Not Found: Game not found.

Get Game ID from Room ID

Method: GET
Path: /gameIdForRoomId/{roomId}

Path Parameters

  • roomId (String): Room identifier.

Response Example

{
  "message": "Znaleziono ID gry dla podanego pokoju.",
  "error": 200,
  "timestamp": "...",
  "gameId": 1
}

Possible Errors

  • 404 Not Found: Room not found.

Get Game Room History

Method: GET
Path: /history

Response Example

{
  "history": [ ... ],
  "message": "Historia pokoi gry.",
  "error": 200,
  "timestamp": "..."
}

Possible Errors

  • 401 Unauthorized: User not authenticated.

Get Active Rooms for a Game

Method: GET
Path: /active

Request Parameters

  • gameId (Long): ID of the game.

Response Example

{
  "message": "Znaleziono aktywne pokoje.",
  "error": 200,
  "activeRooms": [ ... ],
  "timestamp": "..."
}

Possible Errors

  • 403 Forbidden: User is not a participant of the game.
  • 404 Not Found: Game not found.

Common Troubleshooting Tips

  • Game Master Requirement: Only GameMasters can create game rooms.
  • Room Not Found: Double-check the room ID when using /gameIdForRoomId/{roomId}.
  • No Active Rooms: Games without active players will not have any active rooms.
⚠️ **GitHub.com Fallback** ⚠️