さくらVPSのスタートアップスクリプトでマインクラフトサーバー構築

マイクラサーバーをさくらVPSで構築して、iOS(iPhone, iPad)でプレイできる環境を構築したときのメモ。

マニュアル

さくらのGaming script:Minecraft Server(統合版) に必要な手順がすべて載っている。ほかにもマニュアルがあったが、これが必要手順をすべて網羅されていた。
# さくらインターネットさんはどれを見てもマニュアルがわかりやすい

初期構築〜オペレータ権限付与

マニュアルをもとに、「オペレータ権限の設定」まで進める。

なお、オペレータ権限の設定の箇所でのハマリポイントは、権限付与するユーザーがマイクラサーバーに接続していないといけない、ということ。

ubuntu@:~$ screen -ls
There is a screen on:
        687.minecraft   (04/19/2020 01:24:15 PM)        (Detached)
1 Socket in /run/screen/S-ubuntu.

screenコマンドでマイクラのセッション名が表示される。
「$ screen -r minecraft」だけで接続できた。

ubuntu@:~$ screen -r minecraft

NO LOG FILE! - setting up server logging...
[2020-04-19 13:24:16 INFO] Starting Server
[2020-04-19 13:24:16 INFO] Version 1.14.60.5
[2020-04-19 13:24:16 INFO] Session ID e35268cf-9718-4153-a8be-14cc4abbc8b8
[2020-04-19 13:24:16 INFO] Level Name: Bedrock level
[2020-04-19 13:24:16 INFO] Game mode: 1 Creative
[2020-04-19 13:24:16 INFO] Difficulty: 1 EASY
[2020-04-19 13:24:16 INFO] opening worlds/Bedrock level/db
[2020-04-19 13:24:18 INFO] IPv4 supported, port: xxxxx
[2020-04-19 13:24:18 INFO] IPv6 not supported
[2020-04-19 13:24:18 INFO] IPv4 supported, port: xxxxx
[2020-04-19 13:24:18 INFO] IPv6 not supported
[2020-04-19 13:24:19 INFO] Server started.
op MyAuthor
No targets matched selector

「MyAuthor」というユーザー名にオペレータ権限を付与したところ、「No targets matched selector」(対象がいません)と表示されてしまった。

「MyAuthor」というユーザーで今回さくらVPSで構築したマイクラサーバーの世界に接続してMap上に放置した状態で再度コマンドを実行。

[2020-04-19 13:25:42 INFO] Player connected: MyAuthor, xuid: xxxxxxxxxxx

op MyAuthor

Opped: MyAuthor

「Opped: MyAuthor」と表示され、無事に権限付与完了。

サバイバル→クリエイティブに設定変更

オペレータ権限のあるMyAuthorユーザーの設定メニューから、ゲームモードを変更するだけ。

その他設定ファイル

さくらVPSのMinecraft Server(統合版)のスタートアップスクリプトで構築すると、「/opt/minecraft/server.properties」にマイクラの設定ファイルが設置される。

中身は以下のような形でゲームモードなど諸々の設定が変更できる。設定変更後は「$ sudo systemctl restart minecraft.service」で反映できる。面倒だったらサーバー再起動の「$ sudo reboot」でも大丈夫。

ubuntu@:~$ cat /opt/minecraft/server.properties

server-name=Dedicated Server
# Used as the server name
# Allowed values: Any string

gamemode=survival
# Sets the game mode for new players.
# Allowed values: "survival", "creative", or "adventure"

difficulty=easy
# Sets the difficulty of the world.
# Allowed values: "peaceful", "easy", "normal", or "hard"

allow-cheats=false
# If true then cheats like commands can be used.
# Allowed values: "true" or "false"

max-players=10
# The maximum number of players that can play on the server.
# Allowed values: Any positive integer

online-mode=true
# If true then all connected players must be authenticated to Xbox Live.
# Clients connecting to remote (non-LAN) servers will always require Xbox Live authentication regardless of this setting.
# If the server accepts connections from the Internet, then it's highly recommended to enable online-mode.
# Allowed values: "true" or "false"

white-list=false
# If true then all connected players must be listed in the separate whitelist.jsonfile.
# Allowed values: "true" or "false"

server-port=19132
# Which IPv4 port the server should listen to.
# Allowed values: Integers in the range [1, 65535]

server-portv6=19133
# Which IPv6 port the server should listen to.
# Allowed values: Integers in the range [1, 65535]

view-distance=32
# The maximum allowed view distance in number of chunks.
# Allowed values: Any positive integer.

tick-distance=4
# The world will be ticked this many chunks away from any player.
# Allowed values: Integers in the range [4, 12]

player-idle-timeout=30
# After a player has idled for this many minutes they will be kicked. If set to 0 then players can idle indefinitely.
# Allowed values: Any non-negative integer.

max-threads=8
# Maximum number of threads the server will try to use. If set to 0 or removed then it will use as many as possible.
# Allowed values: Any positive integer.

level-name=Bedrock level
# Allowed values: Any string

level-seed=
# Use to randomize the world
# Allowed values: Any string

default-player-permission-level=member
# Permission level for new players joining for the first time.
# Allowed values: "visitor", "member", "operator"

texturepack-required=false
# Force clients to use texture packs in the current world
# Allowed values: "true" or "false"

content-log-file-enabled=false
# Enables logging content errors to a file
# Allowed values: "true" or "false"

compression-threshold=1
# Determines the smallest size of raw network payload to compress
# Allowed values: 0-65535

server-authoritative-movement=true
# Enables server authoritative movement. If true, the server will replay local user input on
# the server and send down corrections when the client's position doesn't match the server's.
# Corrections will only happen if correct-player-movement is set to true.

player-movement-score-threshold=20
# The number of incongruent time intervals needed before abnormal behavior is reported.
# Disabled by server-authoritative-movement.

player-movement-distance-threshold=0.3
# The difference between server and client positions that needs to be exceeded before abnormal behavior is detected.
# Disabled by server-authoritative-movement.

player-movement-duration-threshold-in-ms=500
# The duration of time the server and client positions can be out of sync (as defined by player-movement-distance-threshold)
# before the abnormal movement score is incremented. This value is defined in milliseconds.
# Disabled by server-authoritative-movement.

correct-player-movement=false
# If true, the client position will get corrected to the server position if the movement score exceeds the threshold.

世界に接続できない問題

「世界に接続できませんでした」

自前マイクラサーバーに接続して以下メッセージが表示される場合、スマホ側でマイクラを再起動すると直る。

世界に接続できませんでした

挙動を正確に掴めていないが、自前マイクラサーバーの設定変更をした場合に、このエラー表示が出る確率が高いように思える。

「他のデバイスでこの世界を現在プレイしています」

おそらく、ログインセッションがサーバー側に残ってしまっているために発生する現象と思われる。

世界に参加できません。サインインしているアカウントは、他のデバイスでこの世界を現在プレイしています。

マイクラサービスを再起動する必要があるため、サーバーにログインして以下コマンドを打つと直る。

$ sudo systemctl restart minecraft.service