{"id":25885150,"url":"https://github.com/blackvoidx/hokm-game","last_synced_at":"2025-03-02T17:28:58.166Z","repository":{"id":275486032,"uuid":"926202299","full_name":"blackvoidx/Hokm-game","owner":"blackvoidx","description":"Hokm Backend is a Go-based server application designed to manage the backend logic for a multiplayer card game called Hokm.♠️♥️♣️♦️","archived":false,"fork":false,"pushed_at":"2025-02-03T08:27:34.000Z","size":67,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-16T17:50:40.176Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/blackvoidx.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-02T19:39:18.000Z","updated_at":"2025-02-03T08:27:37.000Z","dependencies_parsed_at":"2025-02-16T17:50:44.013Z","dependency_job_id":"a746b8f4-1761-4907-9ddd-c60617193297","html_url":"https://github.com/blackvoidx/Hokm-game","commit_stats":null,"previous_names":["mamad-1999/hokm-game","blackvoidx/hokm-game"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blackvoidx%2FHokm-game","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blackvoidx%2FHokm-game/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blackvoidx%2FHokm-game/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blackvoidx%2FHokm-game/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blackvoidx","download_url":"https://codeload.github.com/blackvoidx/Hokm-game/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241544009,"owners_count":19979640,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-02T17:28:57.592Z","updated_at":"2025-03-02T17:28:58.156Z","avatar_url":"https://github.com/blackvoidx.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hokm Backend\n\n![istockphoto-1037693148-612x612](https://github.com/user-attachments/assets/037bf4a5-d5ac-4090-a7e7-9fd421d7e2cd)\n\n\n## Overview ♠️\n\nHokm Backend is a Go-based server application designed to manage the backend logic for a multiplayer card game called Hokm. The application provides a RESTful API for user authentication and a WebSocket-based real-time game management system. It supports user registration, login, game room creation, card dealing, trick management, and real-time player interactions.\n\n![2025-02-03_10-46_waifu2x_photo_noise2_scale](https://github.com/user-attachments/assets/447bf228-da1a-44b6-88e8-c0a90ccf5844)\n![SIMPLE](https://github.com/user-attachments/assets/427c1a14-b3f0-4ef6-9638-a7d4fd9884fc)\n\n\n## Features ♥️\n\n- **User Authentication**: Register and login with secure password hashing.\n- **Game Management**: Create and manage game rooms with up to 4 players.\n- **Real-Time Communication**: WebSocket-based communication for real-time game updates.\n- **Card Dealing**: Automated card dealing and shuffling.\n- **Trick Management**: Track and determine the winner of each trick.\n- **Player Replacement**: Handle player disconnections and replacements seamlessly.\n- **Game State Persistence**: Save and restore game state for disconnected players.\n\n## Project Structure ♣️\n\n```\nhokm-backend/\n├── config/               # Configuration management\n│   └── config.go         # Load environment variables\n├── game/                 # Game logic and models\n│   └── game.go           # Game state and management\n├── handlers/             # HTTP and WebSocket handlers\n│   ├── user.go           # User authentication handlers\n│   └── websocket.go      # WebSocket game handlers\n├── models/               # Database models\n│   ├── database.go       # Database connection and initialization\n│   └── user.go           # User model and password utilities\n├── utils/                # Utility functions\n│   ├── errors.go         # Custom error messages\n│   └── helpers.go        # Helper functions for game logic\n├── .env.example          # Example environment variables\n├── go.mod                # Go module dependencies\n├── go.sum                # Go dependency checksums\n├── main.go               # Main application entry point\n└── README.md             # Project documentation\n```\n\n## Getting Started ♦️\n\n### Prerequisites\n\n- Go 1.21.3 or higher\n- PostgreSQL database\n- Environment variables configured in `.env` file\n\n### Installation ♠️\n\n1. Clone the repository:\n\n   ```sh\n   git clone https://github.com/yourusername/hokm-backend.git\n   cd hokm-backend\n   ```\n\n2. Install dependencies:\n\n   ```sh\n   go mod download\n   ```\n\n3. Set up your `.env` file:\n\n   ```sh\n   cp .env.example .env\n   ```\n\n4. Update the `.env` file with your database credentials:\n\n   ```env\n   DB_HOST=your_db_host\n   DB_PORT=your_db_port\n   DB_USER=your_db_user\n   DB_PASSWORD=your_db_password\n   DB_NAME=your_db_name\n   ```\n\n5. Run the application:\n   ```sh\n   go run main.go\n   ```\n\n### API Endpoints ♥️\n\n- **POST /register**: Register a new user.\n- **POST /login**: Authenticate a user.\n- **GET /ws**: Establish a WebSocket connection for real-time game updates.\n\n### WebSocket Messages ♣️\n\n- **join_room**: Join a game room.\n- **play_card**: Play a card in the current trick.\n- **choose_trump**: Choose the trump suit.\n- **leave_game**: Leave the current game.\n\n### Example of messages ♥️\n```json\n{\"action\":\"choose_trump\",\"data\":\"clubs\"}\n{\"action\":\"choose_trump\",\"data\":\"diamonds\"}\n{\"action\":\"choose_trump\",\"data\":\"hearts\"}\n{\"action\":\"choose_trump\",\"data\":\"hearts\"}\n\n{\"action\": \"leave_game\"}\n\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"hearts\",\"Rank\":\"2\",\"Value\":2}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"hearts\",\"Rank\":\"3\",\"Value\":3}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"hearts\",\"Rank\":\"4\",\"Value\":4}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"hearts\",\"Rank\":\"5\",\"Value\":5}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"hearts\",\"Rank\":\"6\",\"Value\":6}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"hearts\",\"Rank\":\"7\",\"Value\":7}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"hearts\",\"Rank\":\"8\",\"Value\":8}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"hearts\",\"Rank\":\"9\",\"Value\":9}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"hearts\",\"Rank\":\"10\",\"Value\":10}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"hearts\",\"Rank\":\"J\",\"Value\":11}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"hearts\",\"Rank\":\"Q\",\"Value\":12}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"hearts\",\"Rank\":\"K\",\"Value\":13}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"hearts\",\"Rank\":\"A\",\"Value\":14}}\n\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"diamonds\",\"Rank\":\"2\",\"Value\":2}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"diamonds\",\"Rank\":\"3\",\"Value\":3}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"diamonds\",\"Rank\":\"4\",\"Value\":4}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"diamonds\",\"Rank\":\"5\",\"Value\":5}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"diamonds\",\"Rank\":\"6\",\"Value\":6}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"diamonds\",\"Rank\":\"7\",\"Value\":7}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"diamonds\",\"Rank\":\"8\",\"Value\":8}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"diamonds\",\"Rank\":\"9\",\"Value\":9}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"diamonds\",\"Rank\":\"10\",\"Value\":10}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"diamonds\",\"Rank\":\"J\",\"Value\":11}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"diamonds\",\"Rank\":\"Q\",\"Value\":12}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"diamonds\",\"Rank\":\"K\",\"Value\":13}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"diamonds\",\"Rank\":\"A\",\"Value\":14}}\n\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"clubs\",\"Rank\":\"2\",\"Value\":2}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"clubs\",\"Rank\":\"3\",\"Value\":3}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"clubs\",\"Rank\":\"4\",\"Value\":4}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"clubs\",\"Rank\":\"5\",\"Value\":5}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"clubs\",\"Rank\":\"6\",\"Value\":6}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"clubs\",\"Rank\":\"7\",\"Value\":7}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"clubs\",\"Rank\":\"8\",\"Value\":8}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"clubs\",\"Rank\":\"9\",\"Value\":9}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"clubs\",\"Rank\":\"10\",\"Value\":10}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"clubs\",\"Rank\":\"J\",\"Value\":11}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"clubs\",\"Rank\":\"Q\",\"Value\":12}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"clubs\",\"Rank\":\"K\",\"Value\":13}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"clubs\",\"Rank\":\"A\",\"Value\":14}}\n\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"spades\",\"Rank\":\"2\",\"Value\":2}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"spades\",\"Rank\":\"3\",\"Value\":3}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"spades\",\"Rank\":\"4\",\"Value\":4}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"spades\",\"Rank\":\"5\",\"Value\":5}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"spades\",\"Rank\":\"6\",\"Value\":6}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"spades\",\"Rank\":\"7\",\"Value\":7}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"spades\",\"Rank\":\"8\",\"Value\":8}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"spades\",\"Rank\":\"9\",\"Value\":9}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"spades\",\"Rank\":\"10\",\"Value\":10}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"spades\",\"Rank\":\"J\",\"Value\":11}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"spades\",\"Rank\":\"Q\",\"Value\":12}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"spades\",\"Rank\":\"K\",\"Value\":13}}\n{\"action\":\"play_card\",\"data\":{\"Suit\":\"spades\",\"Rank\":\"A\",\"Value\":14}}\n```\n\n## Dependencies ♦️\n\n- **Gin**: HTTP web framework.\n- **GORM**: ORM for database management.\n- **Viper**: Configuration management.\n- **Gorilla WebSocket**: WebSocket implementation.\n- **JWT**: JSON Web Tokens for authentication.\n\n## Contributing ♠️\n\nContributions are welcome! Please fork the repository and create a pull request with your changes.\n\n## License ♥️\n\nThis project is licensed under the GPL-3.0 License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblackvoidx%2Fhokm-game","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblackvoidx%2Fhokm-game","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblackvoidx%2Fhokm-game/lists"}