Skip to content

touficbatache/SecretHitlerFirebase

Repository files navigation

Secret Hitler - Firebase API

This project is the backend for the Secret Hitler game, intended to be deployed to Firebase Functions. It is designed to work with the frontend implemented using SvelteKit, deployed to Firebase Hosting.

Secret Hitler Svelte : https://github.com/touficbatache/SecretHitlerSvelte

Flow sheet

flowsheet

How to install?

git clone https://github.com/touficbatache/SecretHitlerFirebase.git
cd SecretHitlerFirebase
npm install

This API is supposed to be deployed to a Firebase project.

I - First, you will need to install the Firebase CLI using the following command:

npm install -g firebase-tools

Note: The -g flag installs a package (here Firebase CLI) globally, which allows you to call it from any command line on your local computer.

II - Then, you'll have to create a Firebase project with the following features turned on:

  • Authentication
  • Functions
  • Realtime Database

and login:

firebase login

III - Link the project you just created by running the following command:

npm run link --project=[PROJECTNAME]

Run in dev mode

Inside to the functions/ directory, make sure to set the correct environment variable values for development in .env.

Then execute the following command, which listens to code changes when building and runs the Firebase Emulator locally:

npm run serve

The Emulator UI can be accessed using the URL shown in the terminal, usually http://localhost:4002/.

Deploy to production

Inside to the functions/ directory, make sure to set the correct environment variable values for production in .env.[PROJECTNAME], then deploy:

cd functions/
npm run deploy

API description

http://127.0.0.1:5001/[project-id]/us-central1/api/[route]/

==== Create a new game ====

Request:

POST /newGame/

NO BODY

Response:

HTTP/1.1 201 Created
content-type: application/json

{ "code": "[GAMECODE]" }

==== Join a game ====

Request:

POST /joinGame/

{
  "code": "[GAMECODE]"
}

Response:

HTTP/1.1 200 OK
content-type: application/json

{ "code": "[GAMECODE]" }

==== Game owner: start the game ====

⚠️ GAME OWNER ONLY ⚠️

Request:

POST /startGame/

{
  "code": "[GAMECODE]",
  "hidePicsGameInfo": "[BOOLEAN]",
  "skipLongIntro": "[BOOLEAN]"
}

Response:

HTTP/1.1 200 OK
content-type: application/json

{ "code": "[GAMECODE]" }

==== President: choose a chancellor ====

⚠️ PRESIDENT ONLY ⚠️

Request:

POST /chooseChancellor/

{
  "code": "[GAMECODE]",
  "chancellorId": "[PLAYER_ID]"
}

Response:

HTTP/1.1 200 OK
content-type: application/json

{ "code": "[GAMECODE]" }

==== Vote: cast a ballot ====

Request:

POST /vote/

{
  "code": "[GAMECODE]",
  "vote": "[BOOLEAN]"
}

Response:

HTTP/1.1 200 OK
content-type: application/json

{ "code": "[GAMECODE]" }

==== President: discard a policy ====

⚠️ PRESIDENT ONLY ⚠️

Request:

POST /presidentDiscardPolicy/

{
  "code": "[GAMECODE]",
  "policy": "[POLICY]"
}

Response:

HTTP/1.1 200 OK
content-type: application/json

{ "code": "[GAMECODE]" }

==== Chancellor: discard a policy ====

⚠️ CHANCELLOR ONLY ⚠️

Request:

POST /chancellorDiscardPolicy/

{
  "code": "[GAMECODE]",
  "policy": "[POLICY]"
}

Response:

HTTP/1.1 200 OK
content-type: application/json

{ "code": "[GAMECODE]" }

==== Presidential Power: Policy Peek ====

⚠️ PRESIDENT ONLY ⚠️

Request:

POST /presidentialPower/

{
  "code": "[GAMECODE]"
}

Response:

HTTP/1.1 200 OK
content-type: application/json

{
    "code": "[GAMECODE]",
    "policies": "[POLICY],[POLICY],[POLICY]"
}

❗ Call again to continue game progress ❗

==== Presidential Power: Investigation ====

⚠️ PRESIDENT ONLY ⚠️

Request:

{
  "code": "[GAMECODE]",
  "player": "[PLAYER_ID]"
}

Response:

HTTP/1.1 200 OK
content-type: application/json

{ "code": "[GAMECODE]" }

❗ Call again to continue game progress ❗

==== Presidential Power: Special Election ====

⚠️ PRESIDENT ONLY ⚠️

Request:

{
  "code": "[GAMECODE]",
  "player": "[PLAYER_ID]"
}

Response:

HTTP/1.1 200 OK
content-type: application/json

{ "code": "[GAMECODE]" }

==== Presidential Power: Execution ====

⚠️ PRESIDENT ONLY ⚠️

Request:

{
  "code": "[GAMECODE]",
  "player": "[PLAYER_ID]"
}

Response:

HTTP/1.1 200 OK
content-type: application/json

{ "code": "[GAMECODE]" }

==== Chancellor: ask for a veto ====

⚠️ CHANCELLOR ONLY ⚠️

Request:

POST /askForVeto/

{
  "code": "[GAMECODE]"
}

Response:

HTTP/1.1 200 OK
content-type: application/json

{ "code": "[GAMECODE]" }

==== President: answer the veto ====

⚠️ PRESIDENT ONLY ⚠️

Request:

POST /answerVeto/

{
  "code": "[GAMECODE]",
  "refuseVeto": "[BOOLEAN]"
}

Response:

HTTP/1.1 200 OK
content-type: application/json

{ "code": "[GAMECODE]" }

==== GAME END ====

Game will end automatically and a team will win depending on one of these conditions:

Liberal team:

  • 5 liberal policies have been enacted, or
  • Hitler is executed

Fascist team:

  • 6 fascist policies have been enacted, or
  • Hitler is elected Chancellor after 3 or more fascist policies are enacted

Error responses

Unauthorized

HTTP/1.1 401 Unauthorized
content-type: application/json

{ "message": "401 - Unauthorized" }

Forbidden

HTTP/1.1 403 Forbidden
content-type: application/json

{ "message": "403 - Forbidden" }

Missing fields

HTTP/1.1 422 Missing fields
content-type: application/json

{ "message": "422 - Missing fields" }

Game not found

HTTP/1.1 452 Unknown
content-type: application/json

{ "message": "452 - Game not found" }

Player already in game

HTTP/1.1 453 Unknown
content-type: application/json

{ "message": "453 - Player already in game" }

Player not in game

HTTP/1.1 454 Unknown
content-type: application/json

{ "message": "454 - Player not in game" }

Not enough players

HTTP/1.1 455 Unknown
content-type: application/json

{ "message": "455 - Not enough players" }

Game has already started

HTTP/1.1 456 Unknown
content-type: application/json

{ "message": "456 - Game has already started" }

Game progress tampering: illegal action

HTTP/1.1 457 Unknown
content-type: application/json

{ "message": "457 - Game progress can't be tampered with" }

Ineligible player

HTTP/1.1 458 Unknown
content-type: application/json

{ "message": "458 - Player is ineligible" }

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published