Skip to content

Commit 13a9315

Browse files
authored
Fixes and additions
1 parent 75b1c67 commit 13a9315

21 files changed

+9915
-1793
lines changed

README.md

+21
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,24 @@
22

33
## Getting Started
44

5+
```bash
6+
docker pull yz89122/screeps
7+
8+
```
9+
10+
11+
### Run
12+
```bash
13+
docker run -it --rm -v "$PWD/screeps-data:/app" screeps npx screeps init
14+
```
15+
16+
17+
### Start
18+
```bash
19+
docker run -d -v "$PWD/screeps-data:/app" -p "21025:21025" screeps
20+
```
21+
22+
23+
24+
// "screeps:init": "docker run -it --rm -v `$PWD/screeps-data:/app` screeps npx screeps init",
25+
// "screeps:start": "npx screeps start --logdir ./logs --port 21025 --steam_api_key 8D9C6AFD0CFB8803DA9AABBB519CCC65"

package-lock.json

+8,550-1,761
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+18-7
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
11
{
2-
"name": "screeps-template",
2+
"name": "template-screeps",
33
"version": "1.0.0",
44
"description": "",
55
"main": "src/index.ts",
66
"scripts": {
7-
"test": "npx jest"
7+
"test": "npx jest",
8+
"test:watch": "npx jest --watchAll"
89
},
910
"repository": {
1011
"type": "git",
1112
"url": "git+https://github.com/TylerGarlick/screeps-template.git"
1213
},
13-
"keywords": ["screeps", "template", "typescript"],
14+
"keywords": [
15+
"screeps",
16+
"template",
17+
"typescript"
18+
],
1419
"author": "Tyler Garlick",
1520
"license": "ISC",
1621
"bugs": {
1722
"url": "https://github.com/TylerGarlick/screeps-template/issues"
1823
},
1924
"homepage": "https://github.com/TylerGarlick/screeps-template#readme",
2025
"devDependencies": {
21-
"@types/jest": "^27.4.1",
22-
"jest": "^27.5.1",
23-
"ts-jest": "^27.1.4",
24-
"typescript": "^4.6.3"
26+
"@types/jest": "^28.1.1",
27+
"@types/node": "^17.0.41",
28+
"jest": "^28.1.1",
29+
"screeps-server-mockup": "^1.5.1",
30+
"screeps-server-test": "github:screepers/screeps-server-test",
31+
"ts-jest": "^28.0.4",
32+
"typescript": "^4.7.3"
33+
},
34+
"engines": {
35+
"node": ">=12.x"
2536
}
2637
}

server/Dockerfile

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
FROM debian:jessie AS gosu
2+
3+
RUN apt-get update && apt-get -y --no-install-recommends install \
4+
ca-certificates \
5+
curl \
6+
wget
7+
8+
ARG GOSU_VERSION=1.11
9+
RUN dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')" \
10+
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch" \
11+
&& chmod +x /usr/local/bin/gosu \
12+
&& gosu nobody true
13+
14+
FROM node:10.16.3-stretch AS screeps
15+
ENV SCREEPS_VERSION 4.2.3
16+
WORKDIR /screeps
17+
RUN yarn add screeps@"$SCREEPS_VERSION"
18+
RUN yarn add screepsmod-mongo screepsmod-admin-utils screepsmod-auth screeps-bot-tooangel
19+
20+
FROM node:10.16.3-stretch
21+
VOLUME /screeps
22+
WORKDIR /screeps
23+
24+
COPY --from=screeps /screeps /screeps.base
25+
26+
ENV DB_PATH=/screeps/db.json \
27+
ASSET_DIR=/screeps/assets \
28+
MODFILE=/screeps/custom_mods.json \
29+
GAME_PORT=21025 \
30+
GAME_HOST=0.0.0.0 \
31+
CLI_PORT=21026 \
32+
CLI_HOST=0.0.0.0 \
33+
DRIVER_MODULE="@screeps/driver"
34+
35+
COPY --from=gosu /usr/local/bin/gosu /usr/local/bin/gosu
36+
COPY config.yml /screeps.base
37+
COPY custom_mods.json /screeps.base
38+
COPY start.sh /usr/local/bin/
39+
COPY entrypoint.sh /usr/local/bin/
40+
41+
RUN chmod +x /usr/local/bin/entrypoint.sh /usr/local/bin/start.sh
42+
43+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
44+
HEALTHCHECK CMD curl -sSLf http://localhost:21025 >/dev/null || exit 1
45+
46+
CMD ["run"]

server/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 B. van Wetten
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

server/README.md

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Screeps Server <!-- omit in toc -->
2+
3+
- [Create the world](#create-the-world)
4+
- [Running the server](#running-the-server)
5+
- [Additional setup steps](#additional-setup-steps)
6+
- [Managing the server](#managing-the-server)
7+
- [Stopping and starting the server](#stopping-and-starting-the-server)
8+
- [Updating](#updating)
9+
- [Troubleshooting](#troubleshooting)
10+
11+
There are two different ways to start a screeps server.
12+
* [without a world](#create-the-world)
13+
* [with a world already created](#running-the-server)
14+
15+
## Create the world
16+
If you do not have an existing server directory, just start the Docker container with the command line argument `init`, and everything gets done for you. The `LOCAL_UID` environment variable ensures that the files that are created in the mounted volume have the correct owner set. You can enter any valid (host) uid here. When omitted the default uid is `9001`.
17+
18+
```bash
19+
docker run --rm -it -v ${PWD}/screeps:/screeps -e LOCAL_UID=$(id -u) -e STEAM_KEY=YOUR_STEAM_KEY_HERE qnimbus/docker-screeps init
20+
```
21+
Now it's all set to run the Screeps server.
22+
23+
## Running the server
24+
Make sure you have a server directory (from aprevious installations or by running the 'init' command above).
25+
26+
You can use 'docker-compose' to start the screeps server, create the screeps_net bridged network and start the redis and mongodb instances.
27+
28+
```bash
29+
docker-compose -f docker-compose.yml up -d
30+
```
31+
32+
If you want to start each container manually follow the steps below.
33+
34+
1. Make sure you are in the server directory
35+
2. [Create the custom bridged network](#creating-network)
36+
3. [Start mongo & redis containers](#mongo-redis)
37+
4. Run the server
38+
```bash
39+
docker run --rm -it --name screeps --network screeps_net -v ${PWD}/screeps:/screeps -p 21025:21025 -p 21026:21026 -d -e LOCAL_UID=$(id -u) qnimbus/docker-screeps
40+
```
41+
42+
## Additional setup steps
43+
44+
### Build your own container
45+
46+
To build your own (customized) container locally, run the following command:
47+
48+
```bash
49+
docker build . -t qnimbus/docker-screeps
50+
```
51+
52+
### Getting Steam API key
53+
54+
Navigate to [https://steamcommunity.com/dev/apikey](https://steamcommunity.com/dev/apikey) and generate or copy your Steam API key.
55+
56+
### <a name="creating-network"></a>Creating a bridged network for MongoDB and Redis
57+
58+
You need to add the screeps, mongo and redis containers to a custom bridged network so the container names are resolvable via DNS on the individual containers. If you do not have a separate custom bridged network you can create one as follows:
59+
60+
```bash
61+
docker network create --attachable -d "bridge" --subnet 172.28.0.0/16 screeps_net
62+
```
63+
64+
*Note: The subnet can be changed to your individual needs as well as the network name ('screeps_net')*
65+
66+
### Starting and running MongoDB and Redis
67+
68+
```bash
69+
docker run --rm --name redis --network screeps_net -d -v redis-volume:/data redis
70+
```
71+
72+
```bash
73+
docker run --rm --name mongo --network screeps_net -d -v mongo-volume:/data/db mongo
74+
```
75+
76+
### Creating a password
77+
78+
In order to push your code to your private server you need a password (using `screepsmod-auth`) for your user. You can configure a password by pointing your browser at
79+
[http://127.0.0.1:21025/authmod/password/](http://127.0.0.1:21025/authmod/password/) or by typing `setPassword('your_password')` into the screeps console when logged in on the screeps client.
80+
81+
## Managing the server
82+
83+
### Mods
84+
85+
Mods can be installed by running:
86+
```bash
87+
docker run --rm -v ${PWD}:/screeps -e LOCAL_UID=$(id -u) qnimbus/docker-screeps yarn add screepsmod-auth
88+
```
89+
### CLI
90+
91+
The CLI can be accessed by running:
92+
93+
```bash
94+
docker exec -it screeps npx screeps cli
95+
```
96+
97+
### Useful CLI commands
98+
99+
To reset server state & data:
100+
101+
```bash
102+
system.resetAllData()
103+
```
104+
105+
You can create autonomous NPC bot players on your private server. They work as regular players, but you can specify their AI scripts in bots option at your mods.json file. Initially there is one AI loaded into your server, called simplebot, but you can always add more, and share with other players.
106+
107+
To view all bot related command and list current active bots, type:
108+
109+
```bash
110+
> help(bots);
111+
```
112+
113+
```bash
114+
> bots.removeUser('JackBot'); // Take note: this is the actual bot instance name, not 'bot-tooangel' for example.
115+
```
116+
117+
## Stopping and starting the server
118+
Stop:
119+
```docker stop screeps```
120+
Start:
121+
```docker start screeps```
122+
123+
## Updating
124+
125+
1. Stop the server:
126+
```docker stop screeps```
127+
2. Remove the server:
128+
```docker rm screeps```
129+
3. Remove current image
130+
```docker rmi qnimbus/docker-screeps```
131+
4. Follow [Running the server](#running-the-server)
132+
133+
## Troubleshooting
134+
135+
When running the docker commands from a Windows Git Bash shell (MSYS) you may need to prepend the `MSYS_NO_PATHCONV=1` environment variable to the commands, like so:
136+
137+
```bash
138+
MSYS_NO_PATHCONV=1 docker run --rm -it -v ${PWD}:/screeps -e LOCAL_UID=$(id -u) -e STEAM_KEY=YOUR_STEAM_KEY_HERE qnimbus/docker-screeps init
139+
```

server/config.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
serverConfig: # This section requires screepsmod-admin-utils to work
3+
welcomeText: |
4+
<h1 style="text-align: center; font-variant: small-caps;">welcome</h1>
5+
<div style="text-align: center;">Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quaerat unde architecto distinctio recusandae quis, laboriosam modi officia nostrum ipsam at?</div>
6+
<div style="text-align: center; font-variant: small-caps; font-size: 14px; margin-top: 30px;">powered by screepsmod-admin-utils</div>
7+
tickRate: 1000 # In milliseconds

server/custom_mods.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"mods": [
3+
"node_modules/screepsmod-mongo/index.js",
4+
"node_modules/screepsmod-auth/index.js",
5+
"node_modules/screepsmod-admin-utils/index.js"
6+
],
7+
"bots": {
8+
"simplebot": "node_modules/@screeps/simplebot/src",
9+
"bot-tooangel": "node_modules/screeps-bot-tooangel/src"
10+
}
11+
}

server/docker-compose.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
version: "3.7"
2+
services:
3+
screeps:
4+
container_name: screeps
5+
image: qnimbus/docker-screeps
6+
build: ./
7+
networks:
8+
- screeps
9+
volumes:
10+
- ./screeps:/screeps
11+
ports:
12+
- 21025:21025
13+
- 21026:21026
14+
environment:
15+
- LOCAL_UID=197609
16+
- GAME_PORT=21025
17+
- CLI_PORT=21026
18+
restart: unless-stopped
19+
depends_on:
20+
- mongo
21+
- redis
22+
mongo:
23+
container_name: mongo
24+
image: mongo
25+
networks:
26+
- screeps
27+
volumes:
28+
- mongo-data:/data/db
29+
- mongo-config:/data/configdb
30+
restart: unless-stopped
31+
redis:
32+
container_name: redis
33+
image: redis
34+
networks:
35+
- screeps
36+
volumes:
37+
- redis-data:/data
38+
restart: unless-stopped
39+
40+
volumes:
41+
mongo-data:
42+
mongo-config:
43+
redis-data:
44+
45+
networks:
46+
screeps:
47+
name: screeps_net
48+
driver: bridge

server/entrypoint.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
# Add local user
4+
# Either use the LOCAL_UID if passed in at runtime or fallback to uid 9001
5+
6+
USER_ID=${LOCAL_UID:-9001}
7+
8+
# Create user if it doesn't already exist
9+
id -u ${USER_ID} >/dev/null 2>&1 || useradd --shell /bin/bash -u ${USER_ID} -o -c "" -m screeps
10+
11+
echo "Starting with UID : ${USER_ID} (screeps)"
12+
export HOME=/home/screeps
13+
14+
# Exit when error is encountered
15+
set -e
16+
17+
# Set ownership of volume to user
18+
chown -R screeps /screeps
19+
20+
cd /screeps
21+
exec /usr/local/bin/gosu screeps start.sh "$@"

server/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"screepsmod-auth": "^2.6.2"
4+
}
5+
}

server/screeps/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore all files in this dir...
2+
*
3+
4+
# except .gitignore
5+
!.gitignore

0 commit comments

Comments
 (0)