# 从 Gamelift 迁移

如果您打算从使用 AWS Gamelift 切换到 Edgegap，以下简单步骤可让您快速运行。在开始之前，我们预计：

* 您当前正在使用 AWS Gamelift
* 您当前在 Gamelift 上已有可用的游戏服务器构建
* 您已经 [创建了](/zh/learn/bian-pai/application-and-versions.md) 并且 [部署了](/zh/learn/bian-pai.md) 在 Edgegap 上的一个应用

{% hint style="info" %}
使用 Edgegap 解决方案，您将受益于更多的节点位置。
{% endhint %}

### 移除 AWS Gamelift SDK

切换到 Edgegap 的第一步是移除在您的游戏服务器中初始化 AWS Gamelift 的代码。这是为了减少开销并防止错误。您要移除的代码可能如下所示：

#### Unity (C#)

```cs
using UnityEngine;
using Aws.GameLift.Server;
using System.Collections.Generic;

public class GameLiftServerExampleBehavior : MonoBehaviour
{
    //这是与 GameLift 服务器 SDK 简单集成的示例，它会使游戏服务器进程在 GameLift 上变为活动状态！
    public void Start()
    {
        //识别端口号（此处为简单起见硬编码），游戏服务器在该端口监听玩家连接
        var listeningPort = 7777;

        //InitSDK 将与 GameLift 的代理建立本地连接以启用后续通信。
        var initSDKOutcome = GameLiftServerAPI.InitSDK();
        if (initSDKOutcome.Success)
        {
            ProcessParameters processParameters = new ProcessParameters(
                (gameSession) => {
                    //当创建游戏会话时，GameLift 会向游戏服务器发送激活请求并传递包含游戏属性和其他设置的游戏会话对象。
                    //游戏服务器应在此处根据游戏会话对象采取相应操作。
                    //一旦游戏服务器准备好接收进入的玩家连接，应调用 GameLiftServerAPI.ActivateGameSession()
                    GameLiftServerAPI.ActivateGameSession();
                },
                (updateGameSession) => {
                    //当游戏会话被更新（例如通过 FlexMatch 回填）时，GameLift 会向游戏
                    //服务器发送包含更新后游戏会话对象的请求。游戏服务器可以检查提供的
                    //matchmakerData 并适当地处理新的进入玩家。
                    //updateReason 是提供此更新的原因。
                },
                () => {
                    //OnProcessTerminate 回调。GameLift 会在关闭承载此游戏服务器的实例之前调用此回调。
                    //它给该游戏服务器一个机会在被关闭之前保存状态、与服务通信等。
                    //在此示例中，我们只是告诉 GameLift 我们确实要关闭。
                    GameLiftServerAPI.ProcessEnding();
                },
                () => {
                    //这是 HealthCheck 回调。
                    //GameLift 大约每 60 秒调用此回调一次。
                    //在这里，游戏服务器可能想检查其依赖项等的健康状态。
                    //如果健康则返回 true，否则返回 false。
                    //游戏服务器有 60 秒时间响应其健康状态。如果游戏服务器未及时响应，GameLift 将默认“false”。
                    //在本例中，我们始终健康！
                    return true;
                },
                listeningPort, //该游戏服务器告诉 GameLift 它将在端口 7777 上监听进入的玩家连接。
                new LogParameters(new List<string>()
                {
                    //在这里，游戏服务器告诉 GameLift 在游戏会话结束时要上传的一组文件。
                    //GameLift 将上传此处指定的所有内容，供开发者稍后获取。
                    "/local/game/logs/myserver.log"
                }));

            //调用 ProcessReady 告诉 GameLift 此游戏服务器已准备好接收进入的游戏会话！
            var processReadyOutcome = GameLiftServerAPI.ProcessReady(processParameters);
            if (processReadyOutcome.Success)
            {
                print("ProcessReady success.");
            }
            else
            {
                print("ProcessReady failure : " + processReadyOutcome.Error.ToString());
            }
        }
        else
        {
            print("InitSDK failure : " + initSDKOutcome.Error.ToString());
        }
    }

    void OnApplicationQuit()
    {
        //确保在应用退出时调用 GameLiftServerAPI.Destroy()。这将重置与 GameLift 代理的本地连接。
        GameLiftServerAPI.Destroy();
    }
}
```

#### Unreal Engine (C++)

```cpp
using UnrealBuildTool;

public class MyAwesomeGame : ModuleRules
{
	public MyAwesomeGame(TargetInfo Target)
	{
		PublicDependencyModuleNames.AddRange(
            // 移除 GameLiftServerSDK
            new string[] { "Core", "CoreUObject", "Engine", "InputCore", "GameLiftServerSDK" }
        );
        bEnableExceptions = true;
	}
}
```

```cpp
#include "GameLiftFPS.h"
#include "Engine.h"
#include "EngineGlobals.h"
#include "GameLiftFPSGameMode.h"
#include "GameLiftFPSHUD.h"
#include "GameLiftFPSCharacter.h"
#include "GameLiftServerSDK.h"

AGameLiftFPSGameMode::AGameLiftFPSGameMode()
	: Super()
{

//只有在启用 GAMELIFT 时运行此代码。仅限服务器目标！
#if WITH_GAMELIFT

	//首先获取模块。
	FGameLiftServerSDKModule* gameLiftSdkModule = &FModuleManager::LoadModuleChecked<FGameLiftServerSDKModule>(FName("GameLiftServerSDK"));

	//InitSDK 将与 GameLift 的代理建立本地连接以启用后续通信。
	gameLiftSdkModule->InitSDK();

	//当创建游戏会话时，GameLift 会向游戏服务器发送激活请求并传递包含游戏属性和其他设置的游戏会话对象。
	//游戏服务器应在此处根据游戏会话对象采取相应操作。
	//一旦游戏服务器准备好接收进入的玩家连接，应调用 GameLiftServerAPI.ActivateGameSession()
	auto onGameSession = [=](Aws::GameLift::Server::Model::GameSession gameSession)
	{
		gameLiftSdkModule->ActivateGameSession();
	};

	FProcessParameters* params = new FProcessParameters();
	params->OnStartGameSession.BindLambda(onGameSession);

	//OnProcessTerminate 回调。GameLift 会在关闭承载此游戏服务器的实例之前调用此回调。
	//它给该游戏服务器一个机会在被关闭之前保存状态、与服务通信等。
	//在此示例中，我们只是告诉 GameLift 我们确实要关闭。
	params->OnTerminate.BindLambda([=](){gameLiftSdkModule->ProcessEnding();});

	//这是 HealthCheck 回调。
	//GameLift 大约每 60 秒调用此回调一次。
	//在这里，游戏服务器可能想检查其依赖项等的健康状态。
	//如果健康则返回 true，否则返回 false。
	//游戏服务器有 60 秒时间响应其健康状态。如果游戏服务器未及时响应，GameLift 将默认“false”。
	//在本例中，我们始终健康！
	params->OnHealthCheck.BindLambda([](){return true; });

	//该游戏服务器告诉 GameLift 它将在端口 7777 上监听进入的玩家连接。
	params->port = 7777;

	//在这里，游戏服务器告诉 GameLift 在游戏会话结束时要上传的一组文件。
	//GameLift 将上传此处指定的所有内容，供开发者稍后获取。
	TArray<FString> logfiles;
	logfiles.Add(TEXT("aLogFile.txt"));
	params->logParameters = logfiles;

	//调用 ProcessReady 告诉 GameLift 此游戏服务器已准备好接收进入的游戏会话！
	gameLiftSdkModule->ProcessReady(*params);
#endif
}
```

### 将您的游戏服务器容器化

### 将您的容器推送到仓库

您需要将容器推送到一个仓库。您可以使用 Edgegap 的 [私有仓库](/zh/learn/advanced-features/edgegap-container-registry.md) 或任何其他选项。

### 在 Edgegap 上创建一个应用

现在您的容器已在仓库中，您需要 [在 Edgegap 上创建一个应用](/zh/learn/bian-pai/application-and-versions.md) 该应用将代表您的游戏服务器。通过此应用，您将能够部署您的服务器。

您现在可以 [按需部署](/zh/learn/bian-pai/deployments.md) 您的服务器以供玩家使用！


---

# 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://docs.edgegap.com/zh/docs/tools-and-integrations/gamelift-to-arbitrium.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.
