《数字服务法案》通知

SDK 最低版本:3.3.0

为了遵守 2024 年 2 月 17 日全面生效的《数字服务法案》,您必须集成新的 Notifications API。请参阅我们的 DSA 合规工作页面以了解更多信息。

本文介绍如何与 Notification API 集成来执行以下操作:

  • 检查已登录的玩家的新通知。
  • 检查被封禁的玩家的新通知。

已登录的玩家的通知

每次玩家成功登录时,Authentication SDK 都会验证该玩家是否有任何新的通知,并在 LastNotificationDate 字段中填充最新通知的创建日期(自 Unix 纪元以来的毫秒数)。您必须:

  1. 每次成功登录后确认 LastNotificationDate 字段不为 null,这意味着该玩家有新的通知。该通知的示例:“您的帐户或内容已受到 DSA 措施的影响。请在以下位置获取详细信息和提出上诉:[链接](需要 Case ID [插入] 和 Player ID [插入])。”
    1. 开发者负责向玩家显示文本。
  2. 确认 LastNotificationDate 大于玩家阅读最后一条通知的日期值(先前存储)。
  3. 通过调用 GetNotificationsAsync 方法来获取玩家的通知。
  4. 向玩家显示通知。(这些通知会出现在 GetNotificationsAsync 方法的返回值中,也会缓存在 Notifications 字段中。)
  5. 当玩家阅读通知时,您必须存储以下两个日期之间的较大值:该通知的 CreatedAt 值和玩家阅读最后一条通知的日期值(先前存储)。

被限制的玩家的通知

当玩家尝试登录并由于受到限制(例如,已被封禁或禁用)而失败时,会抛出 AuthenticationException。它包含一个 Notifications 字段,其中包含该玩家的所有新通知,如果没有新的通知,则为 null。您必须:

  1. 每次登录失败后,确认异常是否为 AuthenticationException
  2. 确认 Notifications 字段是否不为 null。
  3. 向玩家显示通知。

值得注意的通知字段:

  • CaseId:表示案例标识符,可供玩家用于获取有关该通知的更多详细信息。
  • ProjectId:表示 Cloud Project 标识符,可供玩家用于获取有关该通知的更多详细信息。
  • Message:向玩家显示的通知内容,例如“您的帐户或内容已受到 DSA 措施的影响。请在以下位置获取详细信息和提出上诉:[链接](需要 Case ID [插入] 和 Player ID [插入])。”
  • CreatedAt:创建通知的时间戳。用于确定玩家是否有新的通知。
async Task SignInWithNotifications()
{
    List<Notification> notifications = null;
    try
    {
        // Sign the Player In, Anonymously in this example
        await AuthenticationService.Instance.SignInAnonymouslyAsync();
        // Verify the LastNotificationDate
        var lastNotificationDate = AuthenticationService.Instance.LastNotificationDate;
        long storedNotificationDate = // Retrieve the last notification read createdAt date from storage using GetLastNotificationReadDate();
        // Verify if the LastNotification date is available and greater than the last read notifications
        if (lastNotificationDate != null && long.Parse(lastNotificationDate) > storedNotificationDate)
        {
            // Retrieve the notifications from the backend
            notifications = await AuthenticationService.Instance.GetNotificationsAsync();
        }
    }
    catch (AuthenticationException e)
    {
    	// Read notifications from the banned player exception
        notifications = e.Notifications;
        // Notify the player with the proper error message
        Debug.LogException(e);
    }
    catch (Exception e)
    {
        // Notify the player with the proper error message
        Debug.LogException(e);
    }

    if (notifications != null)
    {
        // Display notifications
    }
}

void OnNotificationRead(Notification notification)
{
    long storedNotificationDate = // Retrieve the last notification read createdAt date from storage GetLastNotificationReadDate();
    var notificationDate = long.Parse(notification.CreatedAt);
    if (notificationDate > storedNotificationDate)
    {
        SaveNotificationReadDate(notificationDate);
    }
}

void SaveNotificationReadDate(notificationReadDate) {
    // Store the notificationReadDate, e.g.: PlayerPrefs
}

long GetLastNotificationReadDate() {
    // Retrieve the notificationReadDate that was stored in SaveNotificationReadDate, e.g.: PlayerPrefs
    ...
}