# Installing Matchbox Signaling Server

## Step 1: Install Rust (if not already installed)

```bash
# Install Rust using rustup (recommended)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Follow the prompts, then restart your shell or run:
source "$HOME/.cargo/env"

# Verify installation
cargo --version
```

## Step 2: Install Matchbox Server

```bash
# Install matchbox_server
cargo install matchbox_server

# This will take a few minutes to compile
```

## Step 3: Run Matchbox Server

```bash
# Run on default port (3536)
matchbox_server

# Or specify a port
matchbox_server --port 3536

# Run in background with nohup
nohup matchbox_server --port 3536 > matchbox.log 2>&1 &

# Or with systemd (recommended for production)
# See systemd service example below
```

## Step 4: Configure Godot to Use Matchbox

Update `network_manager.gd` to connect to your matchbox server.

## Alternative: Use Pre-built Binary

If you don't want to install Rust, download a pre-built binary:

```bash
# Download latest release
wget https://github.com/johanhelsing/matchbox/releases/download/v0.9.0/matchbox_server-x86_64-unknown-linux-gnu.tar.gz

# Extract
tar -xzf matchbox_server-x86_64-unknown-linux-gnu.tar.gz

# Make executable
chmod +x matchbox_server

# Run it
./matchbox_server --port 3536
```

## Systemd Service (Production)

Create `/etc/systemd/system/matchbox.service`:

```ini
[Unit]
Description=Matchbox WebRTC Signaling Server
After=network.target

[Service]
Type=simple
User=oldcan
WorkingDirectory=/home/oldcan
ExecStart=/home/oldcan/.cargo/bin/matchbox_server --port 3536
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
```

Then:

```bash
# Reload systemd
sudo systemctl daemon-reload

# Start service
sudo systemctl start matchbox

# Enable on boot
sudo systemctl enable matchbox

# Check status
sudo systemctl status matchbox

# View logs
sudo journalctl -u matchbox -f
```

## Testing

Once running, test the connection:

```bash
# Check if it's listening
netstat -tulpn | grep 3536

# Or
ss -tulpn | grep 3536
```

Your matchbox server will be available at:
- `ws://ruinborn.thefirstboss.com:3536`

## Firewall Configuration

Make sure port 3536 is open:

```bash
# UFW
sudo ufw allow 3536/tcp

# Or iptables
sudo iptables -A INPUT -p tcp --dport 3536 -j ACCEPT
```

## Quick Start Commands

```bash
# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"

# Install Matchbox
cargo install matchbox_server

# Run Matchbox
matchbox_server --port 3536
```
