version: "3.9"

services:
  db:
    image: mariadb:10.11
    container_name: l2-db
    environment:
      MARIADB_ROOT_PASSWORD: rootpass
      MARIADB_DATABASE: interlude
      MARIADB_USER: l2juser
      MARIADB_PASSWORD: "143700"
      TZ: Europe/Riga
    volumes:
      - dbdata:/var/lib/mysql
      - ./db-init/01-init.sql:/docker-entrypoint-initdb.d/01-init.sql:ro
      - /srv/l2server/interlude_backup_20260113_082432.sql:/docker-entrypoint-initdb.d/10-interlude.sql:ro
    healthcheck:
      test: ["CMD-SHELL", "mariadb-admin ping -uroot -p$$MARIADB_ROOT_PASSWORD --silent"]
      interval: 5s
      timeout: 3s
      retries: 40
    ports:
      # Если доступ к БД извне НЕ нужен — убери строку ниже.
      - "3306:3306"
    networks:
      - l2net
    restart: unless-stopped

  authserver:
    image: eclipse-temurin:8-jre
    container_name: l2-authserver
    working_dir: /srv/l2server/authserver
    volumes:
      - /srv/l2server/authserver:/srv/l2server/authserver
    depends_on:
      db:
        condition: service_healthy
    environment:
      TZ: Europe/Riga
    # ВАЖНО: запускаем ровно то, чем ты реально поднимаешь сервер
    command: ["bash", "-lc", "chmod +x ./AuthServer_loop.sh ./StartAuthServer.sh 2>/dev/null || true; exec ./AuthServer_loop.sh"]
    ports:
      - "2106:2106"
      # оставляю открытым, как у тебя в мануале (GS2AS_PORT=9014)
      - "9014:9014"
    networks:
      - l2net
    restart: unless-stopped
    mem_limit: 384m

  gameserver:    
    image: eclipse-temurin:8-jre
    container_name: l2-gameserver
    working_dir: /srv/l2server/gameserver
    volumes:
      - /srv/l2server/gameserver:/srv/l2server/gameserver
    depends_on:
      db:
        condition: service_healthy
      authserver:
        condition: service_started
    environment:
      TZ: Europe/Riga
    command: ["bash", "-lc", "chmod +x ./GameServer_loop.sh ./StartGameServer.sh 2>/dev/null || true; exec ./GameServer_loop.sh"]
    ports:
      - "7777:7777"
    networks:
      - l2net
    restart: unless-stopped
    mem_limit: 1600m

networks:
  l2net:
    driver: bridge

volumes:
  dbdata:

