40. 客户端支持Part 3: 管理客户端版本

Google Play、Apple App Store等手机发布环境是无法准确控制Client的发布时点的。例如,若想将从1.0版本升级到1.1版本的客户端发布到AppStore上,根据用户进行更新的时间差异,在特定时间内1.1版本和1.0版本是同时存在的。为了解决这一问题,游戏服务器就须要管理可兼容的客户端版本列表。

iFun引擎为了解决这问题,提供了对可访问的版本进行指定的功能。

40.1. 指定可兼容的客户端版本

可在MANIFEST.json的 AppInfo 会话中指定如下信息。

  • client_current_version: 指定用于指代最新client的version string。例: “7”

  • client_compatible_versions: 通过list来指定可兼容的client的version string。例: [“5”, “6”]

  • client_update_info: 不兼容的client进行登录时,为了相关通知而指定欲向client传输的字符串。

client_update_uri: 不兼容的client进行登录时,指定用于更新client的URI。

40.1.1. 示例

例如,将client更新到17版本,同时允许15和16版本访问,但不允许其他版本访问。

40.1.1.1. 设置MANIFEST.json

{
  "client_current_version": "17",
  "client_compatible_versions": ["15", "16"],
  "client_update_info": "new version available",
  "client_update_url": "https://play.google.com/store/apps/details?id=com.example.Game1"
}

40.1.1.2. 服务器端代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
...

void OnVersionMessage(const Ptr<Session> &session, const Json &message) {
  string client_version = ...  // from client

  if (not AppInfo::client_version().IsCompatible(client_version)) {
    string update_msg = AppInfo::client_version().client_update_info();
    string update_url = AppInfo::client_version().client_update_uri();

    session->SendMessage(...);

    return;
  }
}

...
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
...

void OnVersionMessage(Session session, JObject message)
{
  string client_version = ...  // from client

  if (!AppInfo.IsCompatibleVersion (client_version))
  {
    string update_msg = AppInfo.ClientUpdateInfo;
    string update_uri = AppInfo.ClientUpdateUri;

    session.SendMessage(...);

    return;
  }
}

...