1. Diarkis サーバーをローカル環境で起動する
はじめに
本ページでは Diarkis サーバーテンプレート を利用して Diarkis サーバーをローカル環境で起動する手順を解説します。Diarkis での開発を始める前にこちらの手順を一通り試すことをおすすめいたします。
環境準備
サーバー・テンプレートを導入するには Go 1.22 以降が必要です。
インストール方法はプラットフォーム毎に異なりますので、公式ドキュメントに従ってインストールします。 https://go.dev/doc/install
Diarkis のサーバー開発は、macOS, Linux, Windows で行うことができます。
Windows 環境でサーバーを起動する場合は Diarkis サーバーを Windows 環境で起動する をご覧ください。
サーバー・テンプレートからプロジェクトを生成する
まずは任意の PATH で
git clone https://github.com/Diarkis/diarkis-server-template.git
として、repository をクローンします。以下のコマンドを実行して、プロジェクトを生成します。出力先は
output
に指定した絶対パスとなります。
make init project_id={project ID} builder_token={builder token} output={absolute path to install}
# 例
make init project_id=00000000000 builder_token=xxxx-yyyy-zzzz output=../server_bin
project_id
: 弊社が発行したプロジェクトIDbuilder_token
: 弊社が発行したBuilder Tokenoutput
: 生成したプロジェクトの出力先。ここでは../server_bin
として説明します
過去バージョンが必要な場合は、任意のバージョンの tag をチェックアウトするか、リリース一覧からダウンロードすることでご利用いただけます。
プロジェクト生成の詳細については、以下も参照してください。
🔗 https://github.com/Diarkis/diarkis-server-template/blob/develop/README.md
セットアップ
生成したプロジェクトにて以下コマンドを実行します。
cd path/to/project
make init
これにより、開発に必要な各種リソース (コード補完を利用するためのリファレンス など)がダウンロードされます。
サーバー・バイナリの生成
ローカル向けにバイナリを生成する際は、以下の make タスクを実行します。
make build-local
上記を実行すると、 remote_bin
配下に、diarkis のバイナリが生成されます。
% ls remote_bin
health-check http mars ms tcp testcli udp
サーバーの起動
MARS, HTTP, UDP の各サーバーを起動します。
make server target=mars
make server target=http
make server target=udp
# 本チュートリアルでは利用しませんが、TCP サーバーは以下コマンドで起動できます。
# make server target=tcp
# make コマンドを利用せずに以下のコマンドでも同様に起動可能です
./remote_bin/mars ./configs/mars/main.json
./remote_bin/http
./remote_bin/udp
接続情報の取得
mars, http, udp が起動していれば、curl で以下のように接続情報を取得することができます。これでサーバーの起動は完了です。
% curl -X POST http://127.0.0.1:7000/endpoint/type/UDP/user/test
{"encryptionMacKey":"xxxxxxxxxx","serverType":"UDP","serverHost":"127.0.0.1","serverPort":7100,"sid":"xxxxxxxxxx","encryptionKey":"xxxxxxxxxx","encryptionIV":"xxxxxxxxxx"}%
上記の HTTP エンドポイントは UDP サーバーに対して uid test
で認証したことを意味します。ここから返却された情報を各種クライアント・ライブラリから利用して、パケットのやり取りが可能となります。
最終更新
役に立ちましたか?