PalworldのサーバにRCON接続して一定時間毎にコマンドを使用してログイン情報をポーリングします。プレイヤのログインやログアウトを検知するとDiscordに通知を送信します。
PalWorldゲームサーバと同一のサーバで動作させる場合の手順です。
「サーバー設定」 > 「アプリ/連携サービス」 > 「ウェブフック」 > 「新しいウェブフック」よりWebフックを作成し、URLをコピーする。
PalWorldのサーバアプリケーションの設定パラメータでRCONEnabled
とRCONPort
を設定し、RCONを有効化します。
設定項目 | 設定例 |
---|---|
RCONEnabled | True |
RCONPort | 25575 |
Dockerを使用してコンテナで動作させます。下記を参考にDockerをインストールしておく必要があります。いくつかインストール方法がありますが、aptなどのパッケージ管理システムを使用してインストールすることをお勧めします。インストール後は、Linux-postinstallを参考にユーザに権限を付与します。
compose.yaml
の環境変数に値を入力します。
environment:
DGLN_DISCORD_WEBHOOK_URL: https://discord-webhook-url
DGLN_RCON_ADDRESS: 192.168.1.50
DGLN_RCON_PORT: 25575
DGLN_RCON_PASSWORD: adminPassword
DGLN_LOOP_INTERVAL_SEC: 5
DGLN_LOG_FILEPATH: player_log.json
docker compose up -d
docker compose logs
RCONが正常に接続されると下記のログが表示されます。
connected to rcon
DiscordGameLoginNotifierをサーバにクローンします。
git clone --depth=1 https://github.com/Mizunanari/DiscordGameLoginNotifier.git
cd DiscordGameLoginNotifier
example.envを元に、.envファイルを作成します。
cp example.env .env
ファイルの中は下記のようになっています。
DGLN_DISCORD_WEBHOOK_URL=''
DGLN_RCON_ADDRESS='127.0.0.1'
DGLN_RCON_PORT='25575'
DGLN_RCON_PASSWORD=''
DGLN_LOOP_INTERVAL_SEC='5'
DGLN_LOG_FILEPATH='player_log.json'
変数 | 説明 |
---|---|
DGLN_DISCORD_WEBHOOK_URL | Discordで発行したWebHookのURLを指定する |
DGLN_RCON_ADDRESS | RCONのアドレスを指定する |
DGLN_RCON_PORT | RCONのポートを指定する |
DGLN_RCON_PASSWORD | RCONのAdmin Passwordを指定する |
DGLN_LOOP_INTERVAL_SEC | RCONから取得するプレイヤ情報のポーリング間隔(秒)を指定する |
DGLN_LOG_FILEPATH | 出力するログイン中プレイヤのJSONファイルの名前を指定する |
必要に応じてPythonパッケージをインストールする。
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
下記の例ではtmux経由で実行し、バックグラウンドでも動作すようにしている。
tmux new -s DiscordGameLoginNotifier
python3 ./discord-game-login-notifier/main.py
Unitファイルの例
[Unit]
Description=Discord Game Login Notifier
[Service]
ExecStart=/home/steam/DiscordGameLoginNotifier/venv/bin/python3 /home/steam/DiscordGameLoginNotifier/discord-game-login-notifier/main.py
ExecStop=/bin/kill -INT ${MAINPID}
[Install]
WantedBy=multi-user.target