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

https://github.com/zefir1990/mars-miners-server

Mars miners game server
https://github.com/zefir1990/mars-miners-server

Last synced: 6 days ago
JSON representation

Mars miners game server

Awesome Lists containing this project

README

          

# Mars Miners Server

A lightweight Node.js WebSocket server for managing battle sessions in Mars Miners.

## Features

- **WebSocket Communication**: Real-time bidirectional communication.
- **In-Memory Storage**: Fast session management (reset on restart).
- **Battle Sessions**: Create, join, and manage unique battle lobbies.
- **Broadcasting**: Real-time updates to all players in a session.
- **Docker Support**: Containerized deployment.

## WebSocket API

The server listens on **port 3001**.
All messages are text-based strings.

### Commands

| Command | Syntax | Description |
|---------|--------|-------------|
| **CREATE** | `[playerID] CREATE [sessionID]` | Creates a new battle session. |
| **JOIN** | `[playerID] JOIN [sessionID]` | Joins an existing battle session. |
| **WRITE** | `[playerID] WRITE [sessionID] [message]` | Adds a log entry and broadcasts it to all players. |
| **READFULL** | `[playerID] READFULL [sessionID]` | Requests the full command history of the session. |

### Responses

- **Success**: `OK: Created [sessionID]` or `OK: Joined [sessionID]`
- **Update**: `UPDATE ["log1", "log2", ...]` (Broadcasted JSON array)
- **Full Log**: `FULLLOG ["log1", "log2", ...]` (JSON array)
- **Error**: `ERROR: [Description]`

### Example Flow

1. **Client A** connects.
2. **Client A** sends: `Player1 CREATE BattleRoom1`
- Server: `OK: Created BattleRoom1`
3. **Client B** sends: `Player2 JOIN BattleRoom1`
- Server: `OK: Joined BattleRoom1`
4. **Client A** sends: `Player1 WRITE BattleRoom1 ATTACK_A`
- Server broadcasts to A and B: `UPDATE ["ATTACK_A"]`

## Docker Setup

### Pre-built Image

Pull the latest image from Docker Hub:

```bash
docker pull demensdeum/mars-miners-server:latest
```

### Quick Start

Run with Docker Compose:

```bash
docker-compose up --build
```

The server will be available at `ws://localhost:3001`.

### Build Manually

```bash
docker build -t mars-miners-server .
docker run -p 3001:3001 mars-miners-server
```

See [DOCKER.md](DOCKER.md) for detailed configuration options.

## Development

1. Install dependencies:
```bash
npm install
```
2. Start the server (autoreload):
```bash
npm run dev
```
3. Run tests:
```bash
node test-broadcast.js
```