An open API service indexing awesome lists of open source software.

https://github.com/chrisrobison/bj

Safe, secure and fair crypto blackjack server and client
https://github.com/chrisrobison/bj

Last synced: 20 days ago
JSON representation

Safe, secure and fair crypto blackjack server and client

Awesome Lists containing this project

README

          

# ๐ŸŽฐ Real-Time Multiplayer Blackjack

A modern, secure, real-time multiplayer Blackjack game implementation using WebSocket technology and Node.js. This project features a responsive web interface, secure authentication, and real-time game state management.

## โœจ Features

- ๐ŸŽฎ Real-time multiplayer gameplay using WebSocket
- ๐Ÿ” Secure user authentication with JWT
- ๐Ÿ“ฑ Responsive web interface with modern design
- ๐ŸŽฒ Multiple table support with configurable rules
- ๐Ÿ’ฐ Transaction management system
- ๐Ÿ”„ Continuous game state synchronization
- ๐Ÿ”Œ Automatic reconnection handling with exponential backoff
- ๐Ÿ”’ SSL/TLS encryption for secure communication

## ๐Ÿ› ๏ธ Technology Stack

- **Frontend**:
- ๐ŸŒ HTML5, CSS3, and vanilla JavaScript
- ๐Ÿ“ก WebSocket for real-time communication
- ๐Ÿ‘ท Web Workers for background processing
- ๐Ÿ“ฑ Responsive design for mobile compatibility

- **Backend**:
- โšก Node.js
- ๐Ÿš€ Express.js for REST API
- ๐Ÿ“ก WebSocket (ws) for real-time communication
- ๐Ÿ—„๏ธ MySQL database with connection pooling
- ๐Ÿ”‘ JWT for authentication

## ๐Ÿ—๏ธ Architecture

The application follows a client-server architecture with several key components:

- **Client-Side**:
- ๐ŸŽจ Game UI (`game.html`)
- ๐ŸŽฎ Game Controller (`gameController.js`)
- ๐Ÿ”„ WebSocket Worker (`gameWorker.js`)
- ๐Ÿ” Authentication handling (`login.html`, `signup.html`)

- **Server-Side**:
- ๐Ÿ–ฅ๏ธ Main server (`app.js`)
- ๐Ÿ”‘ Authentication service (`auth.js`)
- ๐ŸŽฒ Game state management (`gameStateManager.js`)
- ๐ŸŽฏ Table management (`table.js`)
- ๐Ÿ’ณ Transaction handling (`transactions.js`)

## ๐Ÿš€ Setup

1. Clone the repository:
```bash
git clone https://github.com/yourusername/blackjack-multiplayer.git
cd blackjack-multiplayer
```

2. Install dependencies:
```bash
npm install
```

3. Set up environment variables:
```bash
cp .env.example .env
```
Edit `.env` with your configuration:
```
PORT=4444
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_NAME=blackjack
JWT_SECRET=your_jwt_secret
```

4. Set up SSL certificates (required for secure WebSocket):
- Place your SSL certificates in the appropriate directory
- Update the paths in `app.js`

5. Start the server:
```bash
npm start
```

## ๐Ÿ“‹ Game Rules

- โ™ ๏ธ Standard Blackjack rules apply
- ๐ŸŽด Configurable number of decks (default: 6)
- ๐Ÿ‘ฅ Dealer must hit on soft 17
- ๐Ÿ’ซ Double down allowed on any two cards
- โœŒ๏ธ Split allowed (including split aces)
- ๐Ÿ’ฐ Minimum bet: $1, Maximum bet: $500
- ๐Ÿ‘ฅ Maximum 5 players per table

## ๐Ÿ”’ Security Features

- ๐Ÿ” SSL/TLS encryption for all communications
- ๐ŸŽซ JWT-based authentication
- ๐Ÿ”‘ Password hashing using SHA-256
- ๐Ÿ”Œ Database connection pooling
- โœ… Input validation and sanitization
- ๐Ÿ” Secure session management

## ๐Ÿ’ป Development

To run the project in development mode:

```bash
npm run dev
```

This will start the server with nodemon for automatic reloading during development.

## ๐Ÿงช Testing

A test client is included (`test.html`) for debugging and testing the WebSocket functionality. To use it:

1. Start the server
2. Open `test.html` in your browser
3. Use the provided interface to test different game actions

## ๐Ÿค Contributing

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

## ๐Ÿ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

## ๐Ÿ‘ Acknowledgments

- ๐ŸŽฐ Inspired by classic casino Blackjack games
- ๐ŸŒŸ Built with modern web technologies
- ๐Ÿš€ Designed for scalability and performance