Skip to content

Commit

Permalink
✨ Allow console commands interactions (#29)
Browse files Browse the repository at this point in the history
* 🐳 add console comand interaction, pass server args with command, removed useless entrypoint

* 🔥 remove useles dev exec script

* ✨ add dev attach script

* 📝 readme cleanup and update for server command

* 📝 server doc update regarding console command usage
  • Loading branch information
bgauduch authored Apr 27, 2020
1 parent 4a78e48 commit 7066032
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 70 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@

# manually include files that need to be copied
!bin/
!scripts/entrypoint.sh
12 changes: 3 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ RUN mv bin/libcod2_${COD2_VERSION}.so /lib/libcod2_${COD2_VERSION}.so
COPY bin/cod2_lnxded_1_3_nodelay_va_loc /bin/cod2_lnxded
RUN chmod +x /bin/cod2_lnxded

# Copy entrypoint and make it runnable
COPY scripts/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# Runtime stage
FROM alpine:3.11.6
ARG COD2_VERSION
Expand All @@ -53,9 +49,6 @@ COPY --from=build /lib/ld-linux.so.2 /lib/ld-linux.so.2
COPY --from=build /lib/libcod2_${COD2_VERSION}.so /lib/libcod2_${COD2_VERSION}.so
COPY --from=build /bin/cod2_lnxded /home/cod2/cod2_lnxded

# Copy the entrypoint from build stage
COPY --from=build /entrypoint.sh /entrypoint.sh

# setup the server non-root user
ENV SERVER_USER="cod2"
RUN addgroup -S ${SERVER_USER} && adduser -S -D -G ${SERVER_USER} ${SERVER_USER}
Expand All @@ -70,5 +63,6 @@ VOLUME [ "/home/${SERVER_USER}/main" ]
# Set the server dir
WORKDIR /home/${SERVER_USER}

# Launch server at container startup
ENTRYPOINT [ "/entrypoint.sh"]
# Launch server at container startup using libcod library
ENV LD_PRELOAD="/lib/libcod2_1_3.so"
ENTRYPOINT [ "./cod2_lnxded" ]
74 changes: 38 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,104 +2,106 @@
[![Docker Pulls](https://img.shields.io/docker/pulls/bgauduch/cod2server.svg)](https://hub.docker.com/r/bgauduch/cod2server/)

# Call of Duty 2 server meets docker
Launch a minimal & lightweight containarized [Call of Duty 2](https://en.wikipedia.org/wiki/Call_of_Duty_2) multiplayer game server.
Launch a minimal & lightweight containarized [Call of Duty 2](https://en.wikipedia.org/wiki/Call_of_Duty_2) multiplayer game server, including libcod.

## 📦 Supported tags and respective `Dockerfile` links
* `bgauduch/cod2server:latest` - [Dockerfile](https://github.com/bgauduch/call-of-duty-2-docker-server/blob/master/Dockerfile)
* `bgauduch/cod2server:1.0` - [Dockerfile](https://github.com/bgauduch/call-of-duty-2-docker-server/blob/v1.0/Dockerfile)

## 🔧 What's inside
Currently it use:
* The `cod2_lnxded_1_3_nodelay_va_loc` server binary from [Killtube](https://killtube.org/showthread.php?1719-Latest-cod2-linux-binaries-(1-0-1-2-1-3)) by [Kung Foo Man](https://github.com/kungfooman), [Mitch](https://github.com/M-itch) and anyone that contributed;
* The [custom `libcod`](https://github.com/voron00/libcod) from [Voron00](https://github.com/voron00), follow the repository forks for a complete list of creators and contributors.

Full credits goes to them for their awesome work !
> Full credits goes to them for their awesome work !
## 📝 Requirements
You will need the following things:

1. The orginal game, as it's contents are used by the dedicated server;
1. The orginal game, as it's content is used by the dedicated server;
1. A host machine of your choice with x86_64 architecture;
1. [Docker](https://docs.docker.com/install/linux/docker-ce/debian/) and [Docker Compose](https://docs.docker.com/compose/install/) installed and configured on your host machine, minimal knowledge in using both is recommended.
1. [Docker](https://docs.docker.com/install/linux/docker-ce/debian/) and [Docker Compose](https://docs.docker.com/compose/install/) installed and configured on your host machine.
Minimal knowledge in using both is recommended.

## 🚀 Usage

### Launch the server
Clone or download the repository and follow theses steps to get the server up and running:

### Setup the server
1. Clone or download this repository on your host machine;
1. Copy the required data from the game to the server:
1. Go in the `main` folder of your original game (install directory or retail DVD);
1. Copy all the `iw_XX.iwd` from 00 to 15 to the `cod2server/main` folder;
1. Copy all the localizations `localized_english_iwXX.iwd` to the `cod2server/main` (it might be another language).
1. Edit the config file located in `cod2server/main/config.cfg` to suits your needs:
* **[MANDATORY] Set the RCON password to something strong and private!**
* Tweak the rest as you see fit, don't forget to updated the placeholders (server name, admin, etc).
1. From the project root, Launch the server:
``` bash
docker-compose up -d
```
1. Depending on your setup, you might have some port-forwarding and firewalling to do in order to make your server publicly available (see required open ports in the `EXPOSE` section of the [Dockerfile](https://github.com/bgauduch/call-of-duty-2-docker-server/blob/master/Dockerfile)).
1. And "voila" ! Availables server commands are listed in [/doc/readme.md](doc/readme.md).

### Launch the server
From the project root:
``` bash
docker-compose up -d
```

### Server interactions
From the project root, you can:

* Restart the server (to pick up config change for instance):
```bash
```sh
docker-compose restart
```
* Tail the server logs:
```bash
```sh
# cod2_server refer to the name of the service in the compose file
docker-compose logs -f cod2_server
```
* Attach a shell to the server to run commands (see available commands in [/doc/readme.md](doc/readme.md)):
```sh
docker container attach call-of-duty-2-docker-server_cod2_server_1
# exemple commands
status
map_rotate
# Use the escape sequence to detach: `CTRL+P`, `CTRL+Q`
```
>
* Completely stop the server:
```bash
```sh
docker-compose down
```

## 💻 Development guidelines
If you wish to [contribute to and improve](#contribution) this project, you can do so by cloning it and then follow theses guidelines :
If you wish to contribute to and improve this project, you can do so by cloning it and then follow theses guidelines :

### Launch the server locally
In order to test your changes, you can use this script to build the local Docker image and launch the service:
### Start / restart the server locally
```sh
./scripts/dev-up.sh
```
> Remember that you will need the game files in the main folder, as specified in the ["Requirements"](#requirements) section.
> Note that you will need the game files in the main folder, as specified in the "Requirements" section.

### Show server logs
You can use this script to display and follow the server logs:
```sh
./scripts/dev-logs.sh
```

### Launch a shell in the container
You can use this script to launch a shell in the running container:
### Execute server commands
Attach a shell to the running server to run a command (see available commands in [/doc/readme.md](doc/readme.md)):
```sh
./scripts/dev-exec.sh
./scripts/dev-attach.sh
# Exemple commands
status
map_rotate
# Use the escape sequence to detach: `CTRL+P`, `CTRL+Q`
```

### Cleanup
You can use this script to remove everything once your tests are over:
Remove everything once your tests are over:
```sh
./scripts/dev-down.sh
```

## 🗂️ Notes & resources

* This setup was tested on an ubuntu server 18.04.3 LTS x86_64 and should work on any platform with the same architecture.
* Threads on setting up a cod2 server are availables on [Killtube](https://killtube.org/forum.php):
* [on ubuntu 14.04](https://killtube.org/showthread.php?2454-Work-in-progress-Setup-CoD2-on-your-ubuntu-14-04-server) by IzNoGoD
* [using Docker](https://killtube.org/showthread.php?3167-CoD2-Setup-CoD2-with-Docker) by Lonsofore
* There is a similar repository on github proposing a Call of Duty 2 server based on CentOS: [hberntsen/docker-cod2](https://github.com/hberntsen/docker-cod2)
* This setup was tested on an ubuntu server 18.04.3 LTS x86_64 and should work on any platform with the same architecture.
* You might want to use a separated user to launch your docker containers for security purpose. In this case do not forget to add him to the docker group. On Ubuntu for instance:
```sh
# add user to docker group
sudo gpasswd -a USER_NAME docker
# restart docker dameon
sudo service docker restart
```
* Original and cracked server binaries can be found in the [`bin`](https://github.com/bgauduch/call-of-duty-2-docker-server/tree/master/bin) folder, have a look at the `readme`
* If you need to use iptables in conjonction with Docker, please follow the [official documentation tips](https://docs.docker.com/network/iptables/)

Expand All @@ -109,7 +111,7 @@ Project roadmap & issues can be tracked on the [project page](https://github.com
## 🙏 Contribution
Any contribution to this project is welcome ! Feel free to [open an issue](https://github.com/bgauduch/call-of-duty-2-docker-server/issues/new) to ask for help or a new feature, and it will be discussed there.

If you wish to contribute to the code, start by reading the [development guidelines](#development-guidelines) and then feel free to [open a pull-request](https://github.com/bgauduch/call-of-duty-2-docker-server/pulls).
If you wish to contribute to the code, start by reading the development guidelines and then feel free to [open a pull-request](https://github.com/bgauduch/call-of-duty-2-docker-server/pulls).

## 📖 License
This project is under the [MIT License](https://choosealicense.com/licenses/mit/).
20 changes: 11 additions & 9 deletions doc/readme.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# Call Of Duty 2 - server documentation
Full credit goes to http://anarchyrules.co.uk/cod2/server%20commands.html

## Server config
* `set fs_basepath`: set the game folder.
* `set fs_homepath`: set the multiplayer log file and live config folder.

## Map Name
All maps are available in each gamemodes:
- `dm`: death match
Expand All @@ -29,13 +25,18 @@ Map name list:
- `mp_trainstation`

## Console Commands
Here are the available commands you can use in the server terminal.
Here are the available commands you can use to control your server.

You can use commands in-game from the console: add the `/rcon` prefix and allow in-game console in server configuration (`sv_disableClientConsole=0`).
Usage :
* from the server console: just type the command directly.
* from the in-game console:
* Enable in-game console in server configuration (`sv_disableClientConsole=0`);
* Log in using [`rcon login`](#rcon);
* add the `/rcon` prefix to the command.

### rcon
* `/rcon login [rconpassword]`:
Login to remote rcon. **Be carreful not leaking your password when using rcon login !**
Login to remote rcon. **Be VERY carreful not leaking your password when using rcon login !**

### Common
* `status`:
Expand Down Expand Up @@ -94,5 +95,6 @@ Kicks and temporarily bans player by client id from server
* `unban [name]`:
Unban every player banned with [name]. If you want to unban a single player whose name appears more than once, you should edit "ban.txt" manually.



## Server config
* `set fs_basepath`: set the game folder.
* `set fs_homepath`: set the multiplayer log file and live config folder.
7 changes: 6 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ version: '3.6'
services:
cod2_server:
image: bgauduch/cod2-server:latest
restart: unless-stopped
ports:
- "20500:20500/udp"
- "20510:20510/udp"
- "28960:28960/tcp"
- "28960:28960/udp"
volumes:
- ./cod2server/main:/home/cod2/main:ro
restart: unless-stopped
# load the config as an argument to the entrypoint
command: ["+exec", "config.cfg"]
# Allow server shell interaction
stdin_open: true
tty: true
5 changes: 5 additions & 0 deletions scripts/dev-attach.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
set -euo pipefail

# attach to the running server
docker container attach call-of-duty-2-docker-server_cod2_server_1
5 changes: 0 additions & 5 deletions scripts/dev-exec.sh

This file was deleted.

9 changes: 0 additions & 9 deletions scripts/entrypoint.sh

This file was deleted.

0 comments on commit 7066032

Please sign in to comment.