This project is a personal prototype of the original game Cards Against Humanity. All intellectual property rights, including design, branding, and game name, belong to them. You can view the original terms of use and the license CC BY-NC-SA
This project was developed to learn about WebSockets, web components, REST APIs, and authentication using JSON Web Tokens. If you want the text of game cards, you can get the texts contained in the SQL archive cartas_contra_humanidad, specifically in the tables cartas_blancas for white cards and cartas_negras for black cards, under the same license as this project/repository. This also applies to the UI design and code.
- User Account System: Users can register, log in, and manage their accounts.
- Real-Time Gameplay: The game is played in real-time using a REST API and WebSockets, ensuring a smooth and uninterrupted gaming experience.
- Custom Game Interface: Two distinct interfaces for the zar and regular players, tailored to their specific roles in the game.
- Game Creation and Lobby: Users can create new games and join existing lobbies, facilitating the organization and start of games.
- Points System: Implementation of a points system that tracks player scores and determines the winner of the game.
- React
- Node.js
- Socket.io
- Express
- JSON Web Token [JWT]
- Tailwind CSS
- MySQL
Change room information according to players within them
Rooms views
Games views
-
Clone the repository:
git clone https://github.com/JoseDHernandez/CHH -
Import
cartas_contra_humanidad.sqlto you SQL database. -
Modify the variables in
config.jsin the server folder or client folder. [client/scr/api/config.js]Server configuration In
config.jsfile:PORT Port on which the server listens secret Secret key for encrypting JSON Web Tokens (JWT) urlClient URL of the client, used for CORS permissions DB_HOST Database host DB_USER Database username DB_PASSWORD Password to access the database DB_NAME Database name DB_PORT Port of the databaseIn
index.jsfile:Cors for socket.io:
const io = new SocketServer(server, { cors: { origin: urlClient, methods: ["GET", "POST", "PUT", "DELETE"], }, });
Cors for Express:
app.use( cors({ origin: urlClient, methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"], }) );
Morgan format:
app.use(morgan("dev"));
Client configuration In
config.jsfile, content in the pathclient/scr/apiURLis the variable of url the server API, is similar to server (index.js) console information:console.log("Server running: " + DB_HOST + ":" + PORT);
-
You can use the demo accounts:
Username: UserTest
- Email: test@gmail.com
- Password: 12345678
Username: Test
- Email: test@test.com
- Password: 12345678
Username: Username
- Email: test@hotmail.com
- Password: 12345678
-
For the profile photo use a url of imgur o other picture link, you edit this in account settings (client IU) or the database: table
userand columnPhoto. -
Not forget execute the command
npm run devornpm run buildin the paths of client folder and server folder for use this project in a developer or build mode.
-
Black Cards
GET /cardsBlack- Get all black cards.POST /cardsBlack- Create a new black card (requires token and admin role).PUT /cardsBlack/:id- Update a black card (requires token and moderator role).GET /cardsBlack/:id- Get a specific black card by ID.DELETE /cardsBlack/:id- Delete a black card (requires token).
-
White Cards
GET /cardsWhite- Get all white cards.POST /cardsWhite- Create a new white card (requires token and admin role).PUT /cardsWhite/:id- Update a white card (requires token and admin role).GET /cardsWhite/:id- Get a specific white card by ID.DELETE /cardsWhite/:id- Delete a white card (requires token and admin role).
Tokens
Account token (is a header):
- [:token]
Tokenis a token by JWT with user information.
Sockets and the parameters :token and :code
-
[:code]
codePartyis de code of a game room. -
[:tokenParty]
tokenPartyis the token of information of game roomNOTE: view the code in
sockets.jsin server folder (server/routes) for view uses and the local items stored in the local storage of client ( client user context [pathclient/src/context/User.context.jsx]) and.jsxfiles for the behavior of the calls sockets, such us:sockets.jsin the pathserver/routesPartida.jsxandSalas.jsxin the pathclient/src/pagesGame.jsx,Zar.jsx,Player.jsxandchat.jsxin the pathclient/src/components
-
Lobby and Party Management
GET /Game- Verify token.GET /lobby/:code- Join a party (requires token).GET /party/:code- Enter party lobby (requires token).POST /party- Verify party password (requires token).PUT /party- Update party details (requires token).
-
Game Management
POST /game- Start the game (requires token).GET /game- Get the number of cards (requires token).GET /cards/:token- Get player’s deck (requires token).GET /cardsOther/:token- Get new reserve cards (requires token).POST /cards- Save player’s deck (requires token).GET /cartas/:token- Get selected cards by players (requires token).PUT /game- Update points and round (requires token).GET /points/:token- Get points (requires token).PUT /cards- Save selected cards on the server (requires token).DELETE /party- Delete a party (requires token).
POST /signup- Sign up a new user.POST /signin- Sign in an existing user.GET /info- Get general information.
Note: :id is the ID of an account from database.
GET /user/:id- Get user achievements (requires token).PUT /user- Update user information (requires token).
The view original game Cards Against Humanity
This project is developed by José Hernández.
CHH by José David Hernández Hortúa is licensed under CC BY-NC-SA 4.0












