Skip to content

Call of Duty 4 Dedicated Server based on COD4x 1.7a as Docker image

License

Notifications You must be signed in to change notification settings

Freekers/cod4-docker

 
 

Repository files navigation

COD4x 1.7a Dedicated Server in Docker

Build and Push Docker Image

Call of Duty 4 Dedicated Server based on COD4x 1.7a as Docker image

Docker Cod4

It is based on:

Requirements

  • COD4 Client game version 1.7
  • Original COD4 main and zone files required (from the client installation directory)

Features

  • Cod4x server features
  • Works with custom mods and maps (see the Mods section)
  • Easily configurable with docker-compose
  • Runs without root (safer)
  • Default cod4 configuration file server.cfg
    • Placed into ./main
    • Launched by default when not using mods with exec server.cfg
    • Easily changeable

Setup

We assume your call of duty 4 game is installed at /mycod4path

  1. On your host, create the directories ./main, ./zone, ./mods and ./usermaps.

  2. From your Call of Duty 4 installation directory:

    • Copy all the .iwd files from /mycod4path/main to ./main
    • Copy all the files from /mycod4path/zone to ./zone
    • (Optional) Copy the mods you want to use from /mycod4path/mods to ./mods
    • (Optional) Copy the maps you want to use from /mycod4path/usermaps to ./usermaps
  3. As the container runs as user ID 1000 by default, fix the ownership and permissions:

    chown -R 1000 main mods usermaps zone
    chmod -R 700 main mods zone usermaps

    You can also run the container with --user="root" (unadvised!)

  4. Run the following command as root user on your host:

    docker run -d --name=cod4 -p 28960:28960/udp -p 28960:28960/tcp \
        -v $(pwd)/main:/home/user/cod4/main \
        -v $(pwd)/zone:/home/user/cod4/zone:ro \
        -v $(pwd)/mods:/home/user/cod4/mods \
        -v $(pwd)/usermaps:/home/user/cod4/usermaps:ro \
        -e CHECK_PORT=28960 \
        -e CHECK_IP=127.0.0.1 \
        freekers/docker-cod4x17a +map mp_shipment

    The command line argument +map mp_shipment is optional and defaults to +set dedicated 2+set sv_cheats "1"+set sv_maxclients "64"+exec server.cfg+map_rotate

    You can also download and modify the docker-compose.yml file and run

    docker-compose up -d

Healthcheck and Server Restarts

There are two types of restarts:

  1. If the container would stop for some reason (e.g. ShutdownGame) - Docker will restart it automatically ('restart' part in docker-compose.yml)

  2. If for some reason the container would still run, but the healthcheck fails (e.g. the CoD4 server process is fronzen), the Docker container will be marked as 'unhealthy'. However, in this case, the container wouldn't be restarted automatically by Docker. For this you need an additional Docker image called autoheal. Here's a docker-compose.yml example for autoheal:

    version: '3.7'
      services:
        autoheal:
          image: willfarrell/autoheal
          container_name: autoheal
          restart: always
          volumes:
           - /var/run/docker.sock:/var/run/docker.sock
          environment:
           AUTOHEAL_CONTAINER_LABEL: "all"

AUTOHEAL_CONTAINER_LABEL with value "all" means that all unhealthy containers would be restarted.

If you change the default server port, i.e. 28960, then make sure the CHECK_PORT in your Docker run command or docker-compose matches your net_port.

If you change net_ip, then make sure the CHECK_IP in your Docker run command or docker-compose matches your net_ip.

Testing

  1. Launch the COD4 multiplayer game
  2. Click on Join Game
  3. Click on Source at the top until it's set on Favourites
  4. Click on New Favourite on the top right
  5. Enter your host LAN IP Address (i.e. 192.168.1.26)
    • Add the port if you run it on something else than port UDP 28960 (i.e. 192.168.1.26:28961)
  6. Click on Refresh and try to connect to the server in the list

COD4 screenshot

Mods

Assuming:

  • Your mod directory is ./mymod
  • Your main mod configuration file is ./mymod/server.cfg

Set the command line option to +set dedicated 2+set sv_cheats "1"+set sv_maxclients "64"+set fs_game mods/mymod+exec server.cfg +map_rotate

Write protected args

The following parameters are write protected and can't be placed in the server configuration file, and must be in the ARGS environment variable:

  • +set dedicated 2 - 2: open to internet, 1: LAN, 0: localhost
  • +set sv_cheats "1" - 1 to allow cheats, 0 otherwise
  • +set sv_maxclients "64" - number of maximum clients
  • +exec server.cfg if using a configuration file
  • +set fs_game mods/mymod if using a custom mod
  • +set com_hunkMegs "512" don't use if not needed
  • +set net_ip 127.0.0.1 don't use if not needed, requires host network mode
  • +set net_port 28961 don't use if not needed, requires host network mode
  • +map_rotate OR i.e. +map mp_shipment should be the last launch argument

Masterlist

In order for the server to show up on the Activision Masterlist, you need to use host network mode for the container so that it can bind to the WAN/Internet IP address of your server. Additionally, you need to set +set net_ip 123.123.123.123 +set net_port 28961 as ARGS environment variable.

If using bridge network mode, the container will bind to the IP address of the Docker network and therefore won't show up on the Activision Masterlist, as the heartbeat will send a 'local' IP-address to the Masterserver (e.g. 172.16.X.X.).

Note: This version of COD4x (1.7a) is no longer compatible with the COD4x Masterserver as it now requires a token to be listed, which has not been implemented/backported to COD4x version 1.7a.

Acknowledgements

About

Call of Duty 4 Dedicated Server based on COD4x 1.7a as Docker image

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 73.2%
  • Dockerfile 26.8%