-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): implement bedrock server type
- Adds [bedrock](https://minecraft.gamepedia.com/Bedrock_Edition) server support for both CLI and lib - Adds file preset for bedrock's `server.properties` format - Adds integration suites for installing, configuring, and running bedrock servers
- Loading branch information
1 parent
c43f267
commit b12828c
Showing
20 changed files
with
628 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
install: | ||
kind: bedrock | ||
version: "latest" | ||
|
||
configs: | ||
bedrock: | ||
gamemode: creative | ||
player-movement-distance-threshold: 0.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
# setup.sh | ||
|
||
set -e | ||
|
||
mcsm config > server.config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env bash | ||
# verify.sh | ||
|
||
if [[ "$(cat server.config | jq -r .Install.Kind)" != "bedrock" ]]; then | ||
echo "expected install kind to be bedrock" && exit 1 | ||
fi | ||
|
||
if [[ "$(cat server.config | jq -r .Configs.vanilla)" != "null" ]]; then | ||
echo "expected vanilla config to be null" && exit 1 | ||
fi | ||
|
||
if [[ "$(cat server.config | jq -r .Configs.bedrock.gamemode)" != "creative" ]]; then | ||
echo "expected gamemode to be creative" && exit 1 | ||
fi | ||
|
||
if [[ "$(cat server.config | jq -r '.Configs.bedrock."player-movement-distance-threshold"')" != "0.9" ]]; then | ||
echo "expected player movement distance threshold to be 0.9" && exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
install: | ||
kind: bedrock | ||
version: "latest" | ||
|
||
run: | ||
initialmemory: 1G | ||
maxmemory: 1G | ||
|
||
configs: | ||
eula: | ||
vanilla: | ||
spigot: | ||
bukkit: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
# setup.sh | ||
|
||
set -e | ||
|
||
mcsm install server.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
# verify.sh | ||
|
||
if [[ ! -f "bedrock_server" ]]; then | ||
echo "expected bedrock_server to be present" && exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
install: | ||
kind: bedrock | ||
version: "latest" | ||
|
||
run: | ||
initialmemory: 1G | ||
maxmemory: 1G | ||
|
||
configs: | ||
bedrock: | ||
gamemode: creative | ||
level-name: test-world |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
# setup.sh | ||
|
||
set -e | ||
|
||
mcsm install server.yaml | ||
|
||
function runAndStopServer { | ||
SERVER_STARTUP_DONE_MESSAGE='Server started.' | ||
mcsm run server.yaml 2>&1 > server.out & | ||
PID="${!}" | ||
while ! grep "${SERVER_STARTUP_DONE_MESSAGE}" server.out; do | ||
sleep 3 | ||
echo "Waiting for server to finish startup" | ||
done | ||
|
||
echo "Server startup complete -- stopping now" | ||
kill "${PID}" && sleep 2 | ||
} | ||
export -f runAndStopServer | ||
|
||
timeout 90 bash -c runAndStopServer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env bash | ||
# verify.sh | ||
|
||
EXPECTED_DIRS="\ | ||
resource_packs | ||
minecraftpe | ||
worlds | ||
" | ||
|
||
for d in ${EXPECTED_DIRS}; do | ||
if [[ ! -d "${d}" ]]; then | ||
echo "expected '${d}' to be present" && exit 1 | ||
fi | ||
done | ||
|
||
EXPECTED_FILES="\ | ||
server.properties | ||
bedrock_server | ||
whitelist.json | ||
permissions.json | ||
" | ||
|
||
for f in ${EXPECTED_FILES}; do | ||
if [[ ! -f "${f}" ]]; then | ||
echo "expected '${f}' to be present" && exit 3 | ||
fi | ||
done | ||
|
||
if ! grep 'Difficulty: 1 EASY' server.out; then | ||
echo 'Expected easy difficulty setting log' && exit 4 | ||
fi | ||
|
||
if ! grep 'Game mode: 1 Creative' server.out; then | ||
echo 'Expected creative game mode setting log' && exit 5 | ||
fi | ||
|
||
if ! grep 'Level Name: test-world' server.out; then | ||
echo 'Expected test-level level name setting log' && exit 6 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,3 @@ for f in ${EXPECTED_FILES}; do | |
echo "expected '${f}' to be present" && exit 2 | ||
fi | ||
done | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package presets | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"path/filepath" | ||
|
||
"github.com/loksonarius/mcsm/pkg/config" | ||
"github.com/loksonarius/mcsm/pkg/config/properties" | ||
) | ||
|
||
type BedrockServerProperties struct { | ||
ServerName string `properties:"key:server-name,default:Dedicated Server"` | ||
Gamemode string `properties:"key:gamemode,default:survival"` | ||
Difficulty string `properties:"key:difficulty,default:easy"` | ||
AllowCheats bool `properties:"key:allow-cheats,default:false"` | ||
MaxPlayers uint `properties:"key:max-players,default:10"` | ||
OnlineMode bool `properties:"key:online-mode,default:true"` | ||
Whitelist bool `properties:"key:white-list,default:false"` | ||
ServerPort uint `properties:"key:server-port,default:19132"` | ||
ServerPortV6 uint `properties:"key:server-portv6,default:19133"` | ||
ViewDistance uint `properties:"key:view-distance,default:32"` | ||
TickDistance uint `properties:"key:tick-distance,default:4"` | ||
PlayerIdleTimeout uint `properties:"key:player-idle-timeout,default:30"` | ||
MaxThreads uint `properties:"key:max-threads,default:8"` | ||
LevelName string `properties:"key:level-name,default:Bedrock level"` | ||
LevelSeed string `properties:"key:level-seed,default:"` | ||
DefaultPlayerPermissionLevel string `properties:"key:default-player-permission-level,default:member"` | ||
TexturepackRequired bool `properties:"key:texturepack-required,default:false"` | ||
ContentLogFileEnabled bool `properties:"key:content-log-file-enabled,default:false"` | ||
CompressionThreshold uint `properties:"key:compression-threshold,default:1"` | ||
ServerAuthoritativeMovement string `properties:"key:server-authoritative-movement,default:server-auth"` | ||
PlayerMovementScoreThreshold uint `properties:"key:player-movement-score-threshold,default:20"` | ||
PlayerMovementDistanceThreshold float64 `properties:"key:player-movement-distance-threshold,default:0.3"` | ||
PlayerMovementDurationThresholdInMs uint `properties:"key:player-movement-duration-threshold-in-ms,default:500"` | ||
CorrectPlayerMovement bool `properties:"key:correct-player-movement,default:false"` | ||
} | ||
|
||
func BedrockServerPropertiesFromConfig(configs map[string]config.ConfigDict) config.ConfigFile { | ||
cfg := config.ConfigDict{} | ||
if c, ok := configs["bedrock"]; ok { | ||
cfg = c | ||
} | ||
|
||
var s BedrockServerProperties | ||
properties.Unmarshal(cfg, &s) | ||
return &s | ||
} | ||
|
||
func (p *BedrockServerProperties) Path() string { | ||
return "server.properties" | ||
} | ||
|
||
func (p *BedrockServerProperties) Validate() error { | ||
e := func(s string, v ...interface{}) error { | ||
return fmt.Errorf(s, v...) | ||
} | ||
|
||
switch gm := p.Gamemode; gm { | ||
case "survival", "creative", "adventure": | ||
default: | ||
return e("gamemode %s not valid", gm) | ||
} | ||
|
||
switch d := p.Difficulty; d { | ||
case "peaceful", "easy", "normal", "hard": | ||
default: | ||
return e("difficulty %s not valid", d) | ||
} | ||
|
||
ports := []struct { | ||
n string | ||
v uint | ||
}{ | ||
{"server-port", p.ServerPort}, | ||
{"server-portv6", p.ServerPortV6}, | ||
} | ||
for _, p := range ports { | ||
if p.v < 1 || p.v > 65535 { | ||
return e("port %s not in range [1,65535]", p.n) | ||
} | ||
} | ||
|
||
if p.TickDistance < 4 || p.TickDistance > 12 { | ||
return e("tick distance outside of range [4,12]") | ||
} | ||
|
||
if p.CompressionThreshold > 65535 { | ||
return e("compression threshold outside of range [0,65535]") | ||
} | ||
|
||
switch pl := p.DefaultPlayerPermissionLevel; pl { | ||
case "visitor", "member", "operator": | ||
default: | ||
return e("default player permission level %s not valid", pl) | ||
} | ||
|
||
switch sam := p.ServerAuthoritativeMovement; sam { | ||
case "client-auth", "server-auth": | ||
default: | ||
return e("server auth movement %s not valid", sam) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (p *BedrockServerProperties) Render() []byte { | ||
return properties.Marshal(p) | ||
} | ||
|
||
func (p *BedrockServerProperties) Write() error { | ||
path, err := filepath.Abs(p.Path()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return ioutil.WriteFile(path, p.Render(), 0644) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.