# 在游戏中使用 Moderation SDK

> 如何在游戏中使用 Moderation SDK。

## 举报玩家##report-a-player

设置完成后，即可使用玩家的 UAS ID 并提供举报原因来举报玩家。

举报玩家后，您可以导航到 Unity Dashboard（Unity 后台）查看事件以及附加的举报信息。

如果您使用的是 Vivox v16.0.0 或更高版本的包，则举报者和被举报者所在频道的最后 15 分钟对话内容将附加到举报中。

一个提交举报的示例如下：

```cs
using Unity.Services.Moderation;
using Unity.Services.Moderation.Models;
using Unity.Services.Moderation.Exceptions;

public async void Report(string userId)
{
    // userId should be the UAS id of the reported player
    // eg: the currently logged in user id is accessible with
    // var MyUserId = AuthenticationService.Instance.PlayerId

    try {
        var report = Moderation.Instance.NewReport(userId,
            new ReportReason(ReportReason.Threat));
        await Moderation.Instance.ReportPlayer(report);
        Debug.Log("Report submitted!");
    } catch (ModerationServiceException e){
        if (e.Reason == ModerationServiceExceptionReason.SelfReportError) {
            Debug.Log("Error: you can’t report yourself");
        } else {
            Debug.Log($"Error: {e.Reason}");
        }
    }
}
```

## 举报原因##report-reason

原因由 Unity 定义，并以数组的形式显示在游戏中：

```cs
using Unity.Services.Moderation.Models;

public ListReasons()
{
  foreach (var reason in ReportReason.PossibleReasons)
  {
      Debug.Log(reason);
  }
}
```

每个原因的常量位于 **Moderation（审核）> Runtime（运行时）> Models（模型）> ReportReasons.cs** 中。

| 常量                                          | 原因                           |
| ------------------------------------------- | ---------------------------- |
| public const string AimSnapping             | = "aim snapping";            |
| public const string Boosting                | = "boosting";                |
| public const string Exploiting              | = "exploiting";              |
| public const string Hacking                 | = "hacking";                 |
| public const string Smurfing                | = "smurfing";                |
| public const string UnrealisticMovement     | = "unrealistic movement";    |
| public const string CollusionWithOpponent   | = "collusion with opponent"; |
| public const string LeftMatch               | = "left the match";          |
| public const string Inactive                | = "inactive";                |
| public const string Sabotage                | = "sabotage";                |
| public const string Spamming                | = "spamming";                |
| public const string HateSpeech              | = "hate speech";             |
| public const string PredatoryBehavior       | = "predatory behavior";      |
| public const string NoiseDisruption         | = "noise disruption";        |
| public const string Scamming                | = "scamming";                |
| public const string Ads                     | = "ads";                     |
| public const string Threat                  | = "threat";                  |
| public const string VerbalAbuse             | = "verbal abuse";            |
| public const string InappropriatePlayerName | = "player name";             |

## 操作##actions

在审查事件时通过后台执行操作。

当执行操作后，被执行操作的用户登录时，您将从与 Moderation 服务集成的不同 UGS 包收到各种错误消息。错误将遵循[错误响应](/services/access-control.md#error-responses)中描述的访问控制约定。这是预期的行为。

一些 SDK 将提供一种机制，将这些错误包装成自己的异常，例如，当策略阻止用户访问通信时，Vivox SDK 将发出 `MintException`。

支持的制裁错误列表：

| 包名称                               | 异常                     | 用例                                                             |
| --------------------------------- | ---------------------- | -------------------------------------------------------------- |
| com.unity.services.authentication | RequestFailedException | 当玩家被封禁时，您将收到此异常，并在其 innerException 中显示一条 ACCOUNT\_DISABLED 消息。 |
| com.unity.services.vivox          | MintException          | 如果玩家被阻止访问通信频道，则会抛出此异常并提供 403 状态代码。                             |

## 证据管理##evidence-management

如果在项目中使用的是 Vivox 16.0.0 或更高版本，SDK 会自动包含举报者和被举报玩家所在的频道列表。此外，还包括加入了这些频道的额外玩家名单。

此信息用于向举报中的[证据](./evidence.md)添加详细信息。

为了更好地控制举报上下文，您可以在发送举报之前更改举报中包含的频道和玩家列表。

```cs
 var report = Moderation.Instance.NewReport(userId, new ReportReason(ReportReason.Threat));

report.Players = new List<PlayerContext>(); // The list of extra players you want to include in screenings.
report.VivoxChannels = new List<VivoxChannel>(); // The list of channels to be screened.
```
