forked from LittleBigRefresh/Refresh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModerationEndpoints.cs
More file actions
98 lines (87 loc) · 3.72 KB
/
Copy pathModerationEndpoints.cs
File metadata and controls
98 lines (87 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using Bunkum.Core;
using Bunkum.Core.Endpoints;
using Bunkum.Core.RateLimit;
using Bunkum.Listener.Protocol;
using Bunkum.Protocols.Http;
using Refresh.Core.Authentication.Permission;
using Refresh.Core.Services;
using Refresh.Core.Types.Commands;
using Refresh.Core.Types.Data;
using Refresh.Database;
using Refresh.Database.Models.Authentication;
using Refresh.Database.Models.Users;
using Refresh.Interfaces.Game.Types.UserData;
using Refresh.Interfaces.Game.Types.UserData.Filtering;
namespace Refresh.Interfaces.Game.Endpoints;
public class ModerationEndpoints : EndpointGroup
{
[GameEndpoint("showModeratedSlots", HttpMethods.Post, ContentType.Xml)]
public SerializedModeratedSlotList ModerateSlots(RequestContext context, SerializedModeratedSlotList body)
{
return new SerializedModeratedSlotList
{
Ids = new List<int>(),
};
}
[GameEndpoint("showModerated", HttpMethods.Post, ContentType.Xml)]
public SerializedModeratedResourceList ModerateResources(RequestContext context, SerializedModeratedResourceList body, DataContext dataContext)
{
return new SerializedModeratedResourceList
{
Resources = dataContext.Database.FilterOutAllowedAssets(body.Resources).ToList(),
};
}
/// <summary>
/// Censor ("filter") strings sent by the client. Used for chat messages, speech bubble contents, etc.
/// </summary>
/// <param name="context">The request context.</param>
/// <param name="commandService">The command service.</param>
/// <param name="body">The string to censor.</param>
/// <param name="user">The user saying the string. Used for logging and commands</param>
/// <param name="token">The token of the user saying the string.</param>
/// <param name="database">The database. Used for commands</param>
/// <returns>The string shown in-game.</returns>
[GameEndpoint("filter", HttpMethods.Post)]
[AllowEmptyBody]
[RateLimitSettings(180, 100, 120, "filter")]
public string Filter(RequestContext context, CommandService commandService, string body, GameUser user, Token token, GameDatabaseContext database)
{
// TODO: Add actual filtering/censoring
//If the user has enabled unescaping of XML sequences, lets unescape all the XML tags in the body
if (user.UnescapeXmlSequences)
{
body = body.Replace("'", "'");
body = body.Replace(""", "\"");
body = body.Replace(">", ">");
body = body.Replace("<", "<");
body = body.Replace("&", "&");
}
context.Logger.LogInfo(BunkumCategory.Filter, $"<{user}>: {body}");
//If the text starts with a `/`, its a command, also only allow verified users to use commands
if (body.StartsWith('/') && user.EmailAddressVerified)
{
try
{
CommandInvocation command = commandService.ParseCommand(body);
context.Logger.LogInfo(BunkumCategory.Commands, $"User used command '{command.Name.ToString()}' with args '{command.Arguments.ToString()}'");
commandService.HandleCommand(command, database, user, token);
return "(Command)";
}
catch(Exception ex)
{
context.Logger.LogWarning(BunkumCategory.Commands, $"Error running command {body}. ex {ex}");
//do nothing
}
}
return body;
}
[GameEndpoint("filter/batch", HttpMethods.Post, ContentType.Xml)]
[RequireEmailVerified]
public SerializedTextList BatchFilter(RequestContext context, SerializedTextList body)
{
return new SerializedTextList
{
AllOk = true,
};
}
}