> For the complete documentation index, see [llms.txt](https://docs.edgegap.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.edgegap.com/ko/docs/tools-and-integrations/ugs.md).

# UGS에서 배포

이 가이드는 Unity Matchmaker를 유지하고 서버를 Edgegap에 배포하려는 경우 따르세요.

{% hint style="success" %}
대안을 찾고 계신가요? 관리형 서비스를 고려해 보세요 [매치메이킹](/ko/learn/matchmaking.md) 와 [SDK 통합 및 예제](/ko/unity/matchmaking.md).
{% endhint %}

### 시작하기

{% embed url="<https://youtu.be/IwgOm2nmD9s>" %}

이 가이드는 다음을 전제로 Edgegap 서버 호스팅을 호스팅 제공업체로 추가하는 데 중점을 둡니다:

* 작동하는 Unity Matchmaking 설정이 있고,
* Edgegap에 등록되어 있고 [Unity 서버 빌드를 업로드했으며](/ko/unity.md).

를 참조하세요 [Unity의 Matchmaking 문서](https://docs.unity.com/en-us/matchmaker) 에서 매치메이킹 관련 주제를 확인하세요.

{% hint style="info" %}
참조하세요 [Multiplay에서 전환](/ko/docs/tools-and-integrations/multiplay.md) 에서 Multiplay 개념을 Edgegap 호스팅과 비교하고 매핑하는 방법을 확인하세요.
{% endhint %}

[서버에 적합한 위치를 선택하면 평균적으로 지연 시간을 최대 58%까지 줄일 수 있습니다!](/ko/learn/orchestration/deployments.md#server-placement)

이 가이드에서는 다음을 다룹니다:

* 빌드 및 배포 `EdgegapAllocator` Matchmaker용 클라우드 스크립트 모듈,
* 최적의 서버 배치를 위해 사용되는 플레이어의 공용 IP 주소 가져오기,
* UGS 클라우드 스크립트에 웹훅 리스너를 구현하고 서버 할당을 가져오기.

### Edgegap Allocator

다음부터 시작하세요 [호스팅 제공업체 저장소의](https://github.com/Unity-Technologies/matchmaker-hosting-providers/tree/main) 와 `EdgegapAllocator` 소스 코드를 다운로드합니다.

이것은 [당사의 클라우드 스크립트](https://github.com/Unity-Technologies/matchmaker-hosting-providers/blob/main/modules/EdgegapAllocator/CONFIGURATION.md) 로, 매치가 구성되면 Unity matchmaker가 새 서버를 시작하기 위해 호출합니다. 이는 Unity에서 공식적으로 승인한 통합입니다.

#### 필수 비밀 값

먼저, 다음 비밀 값을 [Unity Dashboard](https://cloud.unity.com/) 에서 **Administration** > **Secrets**:

* `EDGEGAP_API_TOKEN` - Edgegap API 토큰입니다.

토큰은 다음에서 찾을 수 있습니다. [Edgegap Dashboard](https://app.edgegap.com/user-settings?tab=tokens).

#### 필수 코드 변경

편집하세요 `Project/EdgegapAllocator.cs` 를 수정하고 다음 상수를 업데이트하세요:

다음의 Edgegap 애플리케이션 이름으로 바꾸세요. [Applications List](https://app.edgegap.com/application-management/applications/list).

{% code title="ApplicationName (34행)" %}

```csharp
private const string ApplicationName = "MyApp"; // TODO: 실제 애플리케이션 이름으로 바꾸세요
```

{% endcode %}

사용하려는 Edgegap 애플리케이션의 버전 이름으로 바꾸세요.

{% code title="VersionName (35행)" %}

```csharp
private const string VersionName = "MyVersion"; // TODO: 실제 버전 이름으로 바꾸세요
```

{% endcode %}

플레이어가 연결할 때 사용할 Edgegap 애플리케이션 버전의 포트 이름으로 바꾸세요.

{% code title="PortName (36행)" %}

```csharp
private const string PortName = "gameport"; // TODO: 실제 포트 이름으로 바꾸세요
```

{% endcode %}

#### 모듈 배포

[CLI 또는 Editor를 사용하여 사용자 지정 모듈을 배포하는 공식 Unity 지침을 따르세요.](https://github.com/Unity-Technologies/matchmaker-hosting-providers/tree/main#deploy-the-module)

### 플레이어 IP 가져오기

{% hint style="warning" %}
**플레이어 IP 주소가 제공되지 않으면 배포는 Los Alamos 위치로 대체됩니다.**
{% endhint %}

각 매치에 대해 요청 시 최적의 서버 위치를 제공하려면, 배포를 요청할 때 플레이어 IP 주소를 제공해야 합니다. Unity는 이 기능을 제공하지 않지만, 무료 서비스 [ipify](https://ipify.org):

{% code title="PlayerNetworkBehaviour.cs" %}

```csharp
public class PlayerNetworkBehaviour : MonoBehaviour {
    public IEnumerator GetPublicIP(Action<string> callback)
    {
        UnityWebRequest request = UnityWebRequest.Get("https://api.ipify.org?format=json");
        yield return request.SendWebRequest();
    
        if (request.result == UnityWebRequest.Result.Success)
        {
            string responseText = request.downloadHandler.text;
            string clientIp = JObject.Parse(responseText)["ip"].ToString();
            callback(clientIp);
        }
        그렇지 않으면
        {
            공용 IP 주소를 가져오지 못했습니다.
        }
        request.Dispose();
    }
}
```

{% endcode %}

모든 플레이어는 티켓의 사용자 지정 데이터를 사용하여 공용 IP 주소를 제공해야 합니다:

```csharp
CreateTicketOptions ticketOptions = new CreateTicketOptions(
    queueName: "my-queue", 
    attributes: new Dictionary<string, object>
    {
        { "player_ip": "<insert-ip>" },
    }
);
```

### 할당 받기

할당은 표준 Unity 매치메이킹 방법을 사용하여 가져올 수 있습니다.

예시에서는 다음을 사용해 할당을 처리합니다. [**Status API, 초당 20 요청으로 속도 제한**](https://docs.edgegap.com/docs/api/dedicated-servers#get-v1-status-deployment_id)**.**

이는 대부분의 게임에 충분합니다. CCU가 50,000명 이상일 것으로 예상되면 대체 방법을 고려하세요.

#### 대체 할당

{% hint style="info" %}
대규모 전 세계 출시의 경우, 다음을 사용하는 더 확장성 있는 대안이 [웹훅](/ko/learn/orchestration/deployments.md#webhooks) 에서 제공됩니다.
{% endhint %}

매치가 만들어지고 클라우드 스크립트가 새 배포를 요청하면, 응답에는 아직 연결 세부 정보가 포함되지 않습니다. 대신, 일종의 영수증인 배포 ID를 받게 됩니다.

할당자 함수는 이 배포 ID를 매칭된 플레이어의 ID와 함께 UGS Game Data에 저장해야 하므로, 나중에 플레이어를 조회하고 연결 세부 정보를 제공할 수 있습니다.

이제 또 다른 클라우드 스크립트 함수를 만들어야 합니다 `AssignmentProcessor`  공개 URL과 함께. 이 URL은 Allocator의 배포 요청에 다음으로 포함되어야 합니다. `webhook_on_ready` .

Edgegap이 게임 서버를 배포하면 FQDN(URL)과 클라이언트 연결용 외부 포트와 같은 모든 연결 세부 정보를 포함한 웹훅 HTTP 이벤트를 새 클라우드 스크립트로 다시 보냅니다. 귀하의 `AssignmentProcessor`  는 배포 ID를 조회하고, 그와 함께 연결 세부 정보를 저장해야 합니다.

게임 클라이언트는 이 게임 데이터를 폴링하고 FQDN과 외부 포트가 검색되는 즉시 연결을 시도해야 합니다.

<figure><img src="/files/f3270de151e8eceaa6d419ebf33f379d5efe98f7" alt=""><figcaption></figcaption></figure>
