#!/usr/bin/env bash
set -e

echo "=== Opening Lineage 2 ports ==="

# ---- ensure ufw installed ----
if ! command -v ufw >/dev/null 2>&1; then
  echo "Installing ufw..."
  apt update -y
  apt install -y ufw
fi

# ---- reset rules (optional but clean) ----
echo "Resetting UFW rules..."
ufw --force reset

# ---- default policy ----
ufw default deny incoming
ufw default allow outgoing

# ---- SSH (НЕ ЗАБУДЬ!) ----
ufw allow OpenSSH

# ---- Lineage 2 ----
echo "Allowing Lineage 2 ports..."
ufw allow 2106/tcp    # Login Server
ufw allow 7777/tcp    # Game Server
ufw allow 9014/tcp    # GS status (optional)
# ufw allow 12345/tcp # admin / telnet (если используешь)

# ---- Web (если нужен) ----
ufw allow 80/tcp
ufw allow 443/tcp

# ---- enable firewall ----
ufw --force enable

echo ""
echo "Firewall rules:"
ufw status numbered

