监控配置变量更改

Note: The content on this page pertains to Game Server Hosting (Multiplay) available on the Unity Cloud Dashboard. If you’re using Game Server Hosting (Clanforge), refer to the Game Server Hosting (Clanforge) documentation.

每个游戏服务器构建都必须监控 server.json 文件 以了解 配置变量 的更改。例如,当您 分配服务器实例 时,IP 地址、端口号和游戏模式可能包含与上次分配不同的值。

监控分配 ID 更改

每个游戏服务器实例都必须通过监控 server.json 文件中 allocatedID 配置变量的值来检测其分配 ID。每次分配或释放服务器实例时,allocatedID 变量值都会发生变化。游戏服务器构建还会监控 server.json 文件以检测其分配状态及其分配 ID。

Note: The server start and server stop actions don't impact the allocation status of the server instance or the allocation ID.

容器构建

如果您使用的是 容器构建server.json 文件已挂载到您的容器中。您可以通过检查容器的家庭环境变量找到 server.json 文件位置。

  • 对于 Linux 容器,它位于 $HOME 环境变量中。
  • 对于 Windows 容器,它位于 $HOMEPATH 环境变量中。

最佳实践

监控 server.json 文件更改的推荐方法取决于您构建游戏所使用的游戏引擎。

游戏引擎最佳实践
Unity 引擎适用于 Unity 的游戏服务器 SDK
虚幻引擎适用于虚幻引擎的游戏服务器 SDK
自定义引擎inotify

Unity 引擎

如果您的游戏使用 Unity 构建,则监控配置变量更改的推荐方法是使用 游戏服务器 SDK

虚幻引擎

如果您的游戏使用虚幻引擎构建,则监控配置变量更改的推荐方法是使用游戏服务器 SDK。

自定义引擎

如果您使用的是自定义游戏引擎,则推荐的方法是使用 inotify 来检测 CLOSE_WRITE 事件。有关 CLOSE_WRITE 事件示例,请参考以下 inotify 日志样本。

MODIFY server.json
OPEN server.json
OPEN server.json
CLOSE_NOWRITE,CLOSE server.json
MODIFY server.json
CLOSE_WRITE,CLOSE server.json
OPEN server.json
ACCESS server.json
CLOSE_NOWRITE,CLOSE server.json