(Version 2.0) by Tieu Phuong
This document provides details of all messages supported in the MessageHandler
class. Each message type is detailed with their request (coming in) and response (returned by the handle functions).
The outermost field of a request is:
type
: The type of the message.data
: The data part of the message.
The outermost field of a response is:
status
: The status of the response (e.g., "success" or "error").data
: The data part of the response.
Request:
{
"type": "SIGN_UP",
"data": {
"username": "string",
"password": "string"
}
}
Response:
{
"status": "success",
"data": {
"message": "string"
}
}
Request:
{
"type": "SIGN_IN",
"data": {
"username": "string",
"password": "string"
}
}
Response:
{
"status": "success",
"data": {
"message": "You are signed in",
"user_type": "ADMIN" | "PLAYER",
"player_id": 5, // if user_type is PLAYER
"admin_id": 1 // if user_type is ADMIN
}
}
Request:
{
"type": "VIEW_ROOMS",
"data": {}
}
Response:
{
"status": "success",
"data": {
"message": "Rooms fetched successfully",
"rooms": [
{
"id": 2,
"created_by": 1,
"created_at": "time_t",
"max_players": 2,
"max_spectators": 2,
"current_players": 2,
"current_spectators": 2,
"status": "RoomStatus"
}
]
}
}
Request:
{
"type": "CREATE_ROOM",
"data": {
"player_id": 2,
"max_players": 2,
"max_spectators": 2
}
}
Response:
{
"status": "success",
"data": {
"message": "Room created successfully",
"room_id": 1
}
}
Request:
{
"type": "JOIN_ROOM",
"data": {
"player_id": 2,
"room_id": 2,
"participant_type": "PLAYER" | "PLAYER_SPECTATOR" | "ADMIN_SPECTATOR"
}
}
Response:
{
"status": "success",
"data": {
"message": "Joined room successfully",'
"room_id": 1
}
}
Request:
{
"type": "LEAVE_ROOM",
"data": {
"room_id": 2,
"participant_id": 2
}
}
Response:
{
"status": "success",
"data": {
"message": "Left room successfully"
}
}
Request:
{
"type": "START_GAME",
"data": {
"player_id": 2,
"room_id": 1
}
}
Response:
{
"status": "success",
"data": {
"message": "Game session started successfully",
"session": {
"id": 2,
"room_id": 2,
"player_id": 2,
"start_time": "time_t",
"end_time": "time_t",
"total_moves": 2,
"status": "STARTED" | "ENDED",
"initial_cube_state": "string",
}
}
}
Request:
{
"type": "END_GAME",
"data": {
"player_id": 2,
"game_session_id": 1
}
}
Response:
{
"status": "success",
"data": {
"message": "Game session ended",
"session": {
"id": 1,
"room_id": 2,
"player_id": 3,
"start_time": "time_t",
"end_time": "time_t",
"total_moves": 4,
"status": "ENDED",
"initial_cube_state": "string"
}
}
}
Request:
{
"type": "VIEW_USERS",
"data": {}
}
Response:
{
"status": "success",
"data": {
"message": "Player list retrieved successfully",
"players": [
{
"id": 1,
"username": "string",
"join_date": "time_t",
"total_games": 5,
"wins": 3,
"best_time": "float",
"avg_time": "float",
"status": "ACTIVE" | "BANNED" | "INACTIVE",
"ban_date": "time_t",
"ban_by": 5 //admin_id
}
]
}
}
Request:
{
"type": "BAN_PLAYER",
"data": {
"admin_id": 4,
"player_id": 3
}
}
Response:
{
"status": "success",
"data": {
"message": "Player banned successfully"
}
}
Request:
{
"type": "SPECTATE",
"data": {
"room_id": 2,
"participant_id": 3
}
}
Response:
{
"status": "success",
"data": {
"message": "Spectating started successfully"
}
}
Request:
{
"type": "UPDATE_CUBE",
"data": {
"player_id": 2,
"game_session_id": 2,
"new_cube_state": "string"
}
}
Response:
{
"status": "success",
"data": {
"message": "Cube state updated successfully"
}
}