From 7066032c15539f6999d52724f9ab2e63471bcb42 Mon Sep 17 00:00:00 2001 From: Baptiste Gauduchon Date: Mon, 27 Apr 2020 12:24:50 +0000 Subject: [PATCH] :sparkles: Allow console commands interactions (#29) * :whale: add console comand interaction, pass server args with command, removed useless entrypoint * :fire: remove useles dev exec script * :sparkles: add dev attach script * :pencil: readme cleanup and update for server command * :pencil: server doc update regarding console command usage --- .dockerignore | 1 - Dockerfile | 12 ++----- README.md | 74 ++++++++++++++++++++++--------------------- doc/readme.md | 20 ++++++------ docker-compose.yaml | 7 +++- scripts/dev-attach.sh | 5 +++ scripts/dev-exec.sh | 5 --- scripts/entrypoint.sh | 9 ------ 8 files changed, 63 insertions(+), 70 deletions(-) create mode 100755 scripts/dev-attach.sh delete mode 100755 scripts/dev-exec.sh delete mode 100644 scripts/entrypoint.sh diff --git a/.dockerignore b/.dockerignore index 656b39f..c89f3fd 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,4 +3,3 @@ # manually include files that need to be copied !bin/ -!scripts/entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 75ddf71..988b9a4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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} @@ -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" ] diff --git a/README.md b/README.md index e646201..23895aa 100644 --- a/README.md +++ b/README.md @@ -2,31 +2,28 @@ [![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; @@ -34,72 +31,77 @@ Clone or download the repository and follow theses steps to get the server up an 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/) @@ -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/). diff --git a/doc/readme.md b/doc/readme.md index 9d455dc..08a161a 100644 --- a/doc/readme.md +++ b/doc/readme.md @@ -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 @@ -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`: @@ -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. diff --git a/docker-compose.yaml b/docker-compose.yaml index 1f9bb7e..d74fe5b 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,6 +2,7 @@ version: '3.6' services: cod2_server: image: bgauduch/cod2-server:latest + restart: unless-stopped ports: - "20500:20500/udp" - "20510:20510/udp" @@ -9,4 +10,8 @@ services: - "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 diff --git a/scripts/dev-attach.sh b/scripts/dev-attach.sh new file mode 100755 index 0000000..4a2a073 --- /dev/null +++ b/scripts/dev-attach.sh @@ -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 diff --git a/scripts/dev-exec.sh b/scripts/dev-exec.sh deleted file mode 100755 index cacee0a..0000000 --- a/scripts/dev-exec.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env sh -set -euo pipefail - -# execute a shell in the server service -docker-compose exec cod2_server sh diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh deleted file mode 100644 index d7b0ac6..0000000 --- a/scripts/entrypoint.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -set -euo pipefail - -# launch server using libcod library -LD_PRELOAD='/lib/libcod2_1_3.so' ./cod2_lnxded +exec config.cfg -# +set fs_basepath "/server" +set fs_homepath "/server/home" - -# tail server logs in foreground -# tail -f -n 50 /home/main/games_mp.log