commit 17198482bd85366b3c2ea86e45ccd4f7ff491657 Author: gered Date: Sat Dec 2 18:53:16 2023 -0500 initial commit diff --git a/.env b/.env new file mode 100644 index 0000000..b2bfd90 --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +UID=1000 +GID=1000 +GIT_REV_PHOSG=9bbec3b49e6c5852d444c6bb530a549d292c50bf +GIT_REV_NEWSERV=3160d86eaac05dd9b8b8a6d4e756d2fbe9540d75 \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d618eca --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/system \ No newline at end of file diff --git a/NOTES.md b/NOTES.md new file mode 100644 index 0000000..b0726d0 --- /dev/null +++ b/NOTES.md @@ -0,0 +1,98 @@ +# Random, Possibly Helpful Notes + +This is not supposed to be anything even approaching a proper `README.md` ;-) + +--- + +## Quick `config.json` Setup + +For a public server on the internet: + +* Set `AllowUnregisteredUsers` to `false` +* Leave `LocalAddress` configured to the interface name of your primary network + adapter, e.g. `en0` +* Set `ExternalAddress` to your server's public IP address +* Set `DNSServerPort` to 53 if you want to use this, or 0 to disable, in which + case you need to set up your own external DNS server (e.g. dnsmasq) +* Set `RunInteractiveShell` to `true` (technically not needed as it should + autodetect) +* Adjusting `LogLevels` is highly recommended. Most things should be set to `WARNING` + at the very least, otherwise there will be a **ton** of logging messages that + you don't need to see unless you're debugging issues / doing newserv development. +* Adjust the `ServerName` WelcomeMessage`, `PCPatchServerMessage` and + `BBPatchServerMessage` to have something personalized for your server. +* Set `CheatModeBehaviour` to `OffByDefault` + +## Adding Licenses (Player Accounts) + +With `AllowUnregisteredUsers` set to `false` in the `config.json` you **must** +manually add "licenses" which are player accounts in order for any client to +successfully connect. + +For Gamecube, this must be registered with a serial number and access key, as +well as a password. + +```text +add-license serial=1234567890 access-key=123456789012 gc-password=myPassword +``` + +For Blue Burst, this must be registered with a serial number, username, and +password. + +```text +add-license serial=1234567890 bb-username=myUsername bb-password=myPassword +``` + +**Serial numbers must be unique across licenses _AND_ client type!** + +For example, if you try to add a Gamecube license with the same serial number +as a Blue Burst license, the most recently added license with the duplicate +serial number will overwrite the existing license completely! + +### License/Account Privileges + +In the `add-license` command, simply add a `flags=xxx` option, where `xxx` +should be one of `normal` (default), `mod`, `admin`, `root` or numeric value. + +## PSO: BB Client Executable Patching + +The addresses to patch (hexedit) in `psobb.exe` to get it to connect to your +own server are: + +* Tethealla client v1.25.13 + * 0x56d70c + * 0x56d724 + * 0x56d750 + * 0x56d76c + * 0x56d788 + * 0x56d7a4 + +* Ephinea client + * 0x56d70c + * 0x56d724 + * 0x56d750 + * 0x56d76c + * 0x56d788 + +Each address should contain an ASCII string with an IP or hostname in it. Each +string has a maximum length of 24 bytes. + +Either patch all of these to the IP you put in the `ExternalAddress` in your +`config.json` or use a publicly resolvable DNS hostname that resolves to that +IP address. + +## Interactive Shell Usage in a Docker World + +The `docker-compose.yml` file has two options specified on the newserv container +that are important for this, which you don't normally see used in a Docker Compose +file, but you're probably familiar with these via `docker run` or `docker exec`: + +* `stdin_open: true` which is equivalent to the `-i` option +* `tty: true` which is equivalent to the `-t` option + +Finally, in `config.json` uncomment and set `RunInteractiveShell` to `true` just +to ensure that newserv's interactive shell feature is enabled. + +Then you can just `docker attach` to the newserv container and Ctrl+P, Ctrl+Q to +detach when done. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..d0988a2 --- /dev/null +++ b/README.md @@ -0,0 +1,53 @@ +# Fuzziqer "newserv" Docker Compose Scripts + +Docker Compose scripts for running the +[Fuzziqer Software "newserv" PSO server software](https://github.com/fuzziqersoftware/newserv) + +This repository is intended for my own personal use only. I take no responsibility +if you, the reader, happens to come across this and decide to use it and +have issues or lose data, or whatever else. Fuzziqer Software won't support +this either, obviously. + +## Usage + +It is assumed you have prior Docker / sys-admin experience. If not, you have +some learning to do first. Don't rush it. + +### Before First Run + +* Edit `.env` as appropriate. Set `UID` and `GID` to the ID's of the user/group + you want to run this server as. +* Create the `system` directory in the same directory as `docker-compose.yml` + and make sure it is owned by the aforementioned `UID` and `GID`. + +### First Run + +* Run `docker compose up` and let the image build and the container start. +* The container will abort because the `system` directory was initially empty. + But now it should be filled with the out-of-the-box newserv system contents + (copied un-altered from the newserv Git repo). Rename `config.example.json` + to `config.json` and edit it as needed (see [NOTES.md](NOTES.md) for + suggestions) + +### Second Run + +* Re-run `docker compose up` and newserv should start up now. + +### DNS + +I only use newserv with it's built-in DNS server functionality _disabled_ as +I prefer to use a separate DNS server like dnsmasq for this task. This means +I set `DNSServerPort` to 0 in `config.json` and the `docker-compose.yml` does +not have a mapping for UDP port 53 at all. + +See the sample dnsmasq configuration `dnsmasq.conf.example` for something that +should work. To connect console PSO clients, you'll need some sort of DNS +server set up for your server that the console PSO clients can use. + +### Connecting Clients + +I assume you're familiar with how to get each PSO client to connect to whatever +private server you like, and won't be detailing the process here. + +See [NOTES.md](NOTES.md) for patching/hexedit details for the PSO: BB client +executable which is quite a bit less straightforward otherwise. diff --git a/dnsmasq.conf.example b/dnsmasq.conf.example new file mode 100644 index 0000000..38a6e8b --- /dev/null +++ b/dnsmasq.conf.example @@ -0,0 +1,21 @@ +port=53 + +no-resolv +no-poll + +# PSO client DNS lookup rebinding to this server (for newserv) +address=/master.pso.dream-key.com/1.2.3.4 +address=/game01.st-pso.games.sega.net/1.2.3.4 +address=/game04.st-pso.games.sega.net/1.2.3.4 +address=/pso.dream-key.com/1.2.3.4 +address=/pso01.dricas.ne.jp/1.2.3.4 +address=/pso02.dricas.ne.jp/1.2.3.4 +address=/pso03.dricas.ne.jp/1.2.3.4 +address=/pso04.dricas.ne.jp/1.2.3.4 +address=/pso05.dricas.ne.jp/1.2.3.4 +address=/gc01.st-pso.games.sega.net/1.2.3.4 +address=/pso-gc1.pso.playsega.com/1.2.3.4 +address=/pso-gct01.sonic.isao.net/1.2.3.4 +address=/pso-kr06.sonic.isao.net/1.2.3.4 +address=/pso-gc01.sonic.isao.net/1.2.3.4 +address=/pso-ep3t.sonic.isao.net/1.2.3.4 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b01d62e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,58 @@ +version: "3" + +networks: + pso-net: + name: pso-net + +services: + + newserv: + build: + context: docker-image + dockerfile: Dockerfile + args: + UID: ${UID} + GID: ${GID} + GIT_REV_PHOSG: ${GIT_REV_PHOSG} + GIT_REV_NEWSERV: ${GIT_REV_NEWSERV} + container_name: pso-newserv + stdin_open: true + tty: true + ports: + # pso client ports + - 9000:9000 # gc-jp10 gc login_server + - 9001:9001 # gc-jp11 gc login_server + - 9002:9002 # gc-jp3te gc login_server + - 9003:9003 # gc-jp3 gc login_server + - 9064:9064 # gc-us12t1 gc login_server + - 9100:9100 # gc-us10 pc pc_console_detect + - 9103:9103 # gc-us3 gc login_server + - 9200:9200 # gc-eu10 gc login_server + - 9201:9201 # gc-eu11 gc login_server + - 9202:9202 # gc-eu3-50 gc login_server + - 9203:9203 # gc-eu3-60a gc login_server + - 9204:9204 # gc-eu3-60b gc login_server + - 9300:9300 # pc pc login_server + - 10000:10000 # pc-patch patch patch_server_pc + - 11000:11000 # bb-patch patch patch_server_bb + - 12000:12000 # bb-init bb login_server + - 9500:9500 # xb-login xb login_server + # newserv-defined ports (defaults from config.json) + - 5100:5100 # console-login gc login_server + - 5101:5101 # pc-login pc login_server + - 5102:5102 # xb-login xb login_server + - 5105:5105 # xb-lobby xb login_server + - 5110:5110 # console-lobby gc lobby_server + - 5111:5111 # pc-lobby pc lobby_server + - 5112:5112 # bb-lobby bb lobby_server + #- 5120:5120 # dc-proxy dc proxy_server + #- 5121:5121 # pc-proxy pc proxy_server + #- 5122:5122 # gc-proxy gc proxy_server + #- 5123:5123 # xb-proxy xb proxy_server + #- 5124:5124 # bb-proxy bb proxy_server + - 12004:12004 # bb-data1 bb login_server + - 12005:12005 # bb-data2 bb login_server + volumes: + - ./system:/opt/newserv/system + networks: + - pso-net diff --git a/docker-image/Dockerfile b/docker-image/Dockerfile new file mode 100644 index 0000000..e312a92 --- /dev/null +++ b/docker-image/Dockerfile @@ -0,0 +1,55 @@ +FROM ubuntu:22.04 as builder + +MAINTAINER Gered King + +ARG GIT_REV_PHOSG +ARG GIT_REV_NEWSERV + +# ------------------------------------------------------------------------------ + +RUN apt-get update && \ + apt-get install -y build-essential cmake git libevent-dev zlib1g-dev python3 + +# build and install phosg, a dependency of newserv +RUN mkdir /tmp/phosg && \ + cd /tmp/phosg && \ + git clone https://github.com/fuzziqersoftware/phosg.git . && \ + git checkout $GIT_REV_PHOSG && \ + cmake . && \ + make && \ + make install && \ + cd - + +# build newserv itself +RUN mkdir /tmp/newserv && \ + cd /tmp/newserv && \ + git clone https://github.com/fuzziqersoftware/newserv.git . && \ + git checkout $GIT_REV_NEWSERV && \ + cmake . && \ + make && \ + cd - + +# ------------------------------------------------------------------------------ + +FROM ubuntu:22.04 + +ARG UID +ARG GID + +USER root +RUN apt-get update && \ + apt-get install -y libevent-dev zlib1g-dev && \ + groupadd --gid $GID newserv && \ + useradd -m -d /opt/newserv -s /bin/bash --gid newserv --uid $UID newserv + +WORKDIR /opt/newserv + +COPY --chown=newserv:newserv --from=builder /tmp/newserv/newserv . +COPY --chown=newserv:newserv --from=builder /tmp/newserv/system ./new-system-template +COPY entrypoint.sh /entrypoint.sh + +USER newserv + +VOLUME /opt/newserv/system + +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/docker-image/entrypoint.sh b/docker-image/entrypoint.sh new file mode 100755 index 0000000..f54c7f0 --- /dev/null +++ b/docker-image/entrypoint.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +if [ "$(id -u)" -ne "$(stat -c '%u' $HOME/system)" ]; then + echo "The 'system' volume is not writable by newserv." + echo "Change the 'system' local volume mount user:group to $(id -u):$(id -g)." + exit 1 +fi + +if [ -d "$HOME/system" ] && test -n "$(find $HOME/system -maxdepth 0 -empty)" ; then + echo "Newserv system directory not initialized, will initialize one for you right now." + cp -r $HOME/new-system-template/* $HOME/system/ + mkdir -p $HOME/system/players # otherwise, bb clients crash on new char creation! + + echo + echo "********************************************************************************" + echo "This docker image will now abort for you to initially configure newserv!" + echo + echo "To proceed you must do the following:" + echo "- Copy 'system/config.example.json' to 'system/config.json'" + echo "- Edit 'system/config.json' to your liking" + echo "- Re-run this container" + echo "********************************************************************************" + echo + + exit 1 +fi + +if [ ! -f "$HOME/system/config.json" ]; then + echo "No 'system/config.json' found. Aborting." + echo "Did you forget to copy 'system/config.example.json' to 'system/config.json'?" + exit 1 +fi + +exec $HOME/newserv $@ \ No newline at end of file diff --git a/newserv_cli.sh b/newserv_cli.sh new file mode 100755 index 0000000..5570d6b --- /dev/null +++ b/newserv_cli.sh @@ -0,0 +1,5 @@ +#!/bin/bash +cd "$(dirname "$0")" + +echo "Use the sequence Ctrl+P, Ctrl+Q to detach." +docker attach pso-newserv