# Diarkis サーバーを Windows 環境で起動する

## はじめに

Diarkis サーバーを Windows バイナリとしてビルドして動かすこともできます。

これにより、Windows マシン上で開発するクライアントエンジニアが WSL なしで Diarkis サーバーを動作させることが可能となり、開発作業の効率化に役立てる事ができます。

ただし、本番環境での利用は想定していないので、ローカル環境や開発環境での利用にとどめてください。

## 動作環境

2025-07-17 現在、以下の環境での動作を想定しております。

* Windows 10/11
* Go 1.24 以上
* （git でリポジトリを close する場合は git）

## 手順

### 必要なツールのインストール

Go 1.22 以上をインストールします。<https://go.dev/doc/install>

scoop などのパッケージマネージャーを使ってインストールすることも可能です。

```powershell
> scoop install go
```

### Diarkis Server Template のインストール

#### リポジトリをクローンする場合

<https://github.com/Diarkis/diarkis-server-template> をクローンします。

<pre class="language-powershell"><code class="lang-powershell"><strong>> git clone git@github.com:Diarkis/diarkis-server-template.git
</strong><strong>
</strong><strong>> cd .\diarkis-server-template\
</strong># 必要に応じて利用するバージョンのタグをチェックアウトします
> git checkout v1.1.0
</code></pre>

#### アセットをダウンロードする場合

<https://github.com/Diarkis/diarkis-server-template/releases> を開き、最新バージョンの Assets をダウンロードし、解凍して利用します。

### プロジェクトの生成

PowerShell から以下のコマンドを実行して、プロジェクトを生成します。

{% code overflow="wrap" %}

```powershell
# parameters: {project_id} {builder_token} {output}
> .\run-mage.bat init 12345678901 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ../server_bin
```

{% endcode %}

* `project_id`: 弊社が発行したプロジェクトID
* `builder_token`: 弊社が発行したBuilder Token
* `output`: 生成したプロジェクトの出力先。ここでは `../server_bin` として説明します

### プロジェクトの初期化

プロジェクトを出力したディレクトリに移動し、以下のコマンドを実行します。

```powershell
> cd ..\server_bin
> .\run-mage.bat init
```

### ビルド

以下のコマンドを実行して、Diarkis のサーバーバイナリをビルドします。

```powershell
> .\run-mage.bat build:local
```

ビルドが終了すると、 remote\_bin ディレクトリにバイナリが出力されます。

### 実行

mars, http, udp をそれぞれ起動します。それぞれ別の PowerShell のウィンドウで起動します。

```powershell
> .\run-mage.bat server mars
> .\run-mage.bat server http
> .\run-mage.bat server udp
```

### 動作確認

Go のテストクライアントを使って疎通確認ができます。

```powershell
# parameters: <HTTP address> <client user ID> <client key> <puffer enabled: true/false>
> .\run-mage.bat goCli 127.0.0.1:7000 user-1 key false
```

* HTTP address: Diarkis HTTP サーバーのアドレス
* client user ID: 認証するユーザーの ID。
* client Key: クライアントキー。開発環境では、`key` を指定します
* puffer enabled: Diarkis Puffer モジュールの利用可否。ここでは false を指定します

正常に認証できると、以下のような表示になり、コマンド待ち受け状態となります。

```
[UID: user-1][SID(UDP): 23942c034d8d4094b09ab7219d28cebc]
 > Connected UDP
```

接続後、 Room の作成をする場合は以下のコマンドを実行して作成することができます。

```
 > Connected UDP
room create
Enter for which protocol to a create a Room (TCP/UDP): (Default: UDP)
Invalid input. Set to default value: UDP
Enter max members [1 - 255] (uint16): (Default: 10)
Invalid input. Set to default value: 10
Enter if allow empty (y/n): (Default: no)
Invalid input. Set to default value: false
Enter if join on creation (y/n): (Default: yes)
Invalid input. Set to default value: true
Enter TTL (seconds) [10 - 65535] (uint16): (Default: 30)
Invalid input. Set to default value: 30
Enter broadcast interval (milliseconds) (uint16): (Default: 100)
Invalid input. Set to default value: 100
# UDP RoomID がプロンプトに表示されて Room に参加している状態となる
[UID: 1111][SID(UDP): c51ea8010bc44ea5b6cd6ef2bb788ad8][UDP RoomID: 580e3cef8588bd287f0000011fa5000000000000000000000000]
```

## 補足

### サンプルプロジェクト

`./run-mage.bat init` で生成されるプロジェクトは Diarkis の基本的な機能を一通り確認できる基本セットです。その他にも様々なサンプルプロジェクトがあります。詳しくは Diarkis Server Template リポジトリの examples ページを参照してください。

🔗 <https://github.com/Diarkis/diarkis-server-template/tree/develop/examples>

### テストクライアント

テストクライアントでは `room create` コマンド以外にも様々なビルトインコマンドを実行して確認することができます。詳細はヘルプセンターの以下ページをご確認ください。

{% embed url="<https://help.diarkis.io/getting-started/tutorial/test-client>" %}

### `magefile`

`.¥run-mage.bat` は内部で [magefile](https://magefile.org/) という Go のツールを利用しています。

make/rake などのようなビルドツールで、Go でビルドフローなどを記載することで、プラットフォームに依存しない管理ができるようになります。

他のターゲットを確認する場合は、以下のように引数なしで実行することで確認できます。

```
> .\run-mage.bat
Targets:
  build:linux              Build server binary for linux or container environment
  build:local              Build server binary for local use
  build:mac                Build server binary for mac use
  diarkis:changeVersion    Change diarkis version.
  diarkis:version          Print the version of diarkis currently used.
  goCli                    Starts Go test client.
  init                     Initialize project
  puffer:clean             Delete all generated protocol code files.
  puffer:gen               Generate go, cpp, and cs code files using puffer (Diarkis packet gen module) from packet definition written in json.
  server                   Start a server locally: Required 1 following argument: mars http udp tcp
```

#### **fakesignal**

diarkis は、SIGUSR1 や SIGUSR2 などの UNIX シグナルを用いてログレベルの切り替えやデバッグ機能の ON/OFF といった機能を提供していますが、Windows には SIGUSR1 などのシグナルが存在しません。

そこで、Windows 上でもテストを行えるよう、fakesignal というツールを diarkis-server-template に同梱させていただいております。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.diarkis.io/diarkis-server/setup-windows.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
