Skip to content

Commit

Permalink
Avoid deserializing RemoteLogv3 log messages
Browse files Browse the repository at this point in the history
- Only deserialize the log if it contains
    the CUSTOMIZATION_METRICS_PAYLOAD message.
- Build regex patterns at compile time.
  • Loading branch information
thesprockee committed Jan 27, 2024
1 parent ff0f881 commit 338c113
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion EchoRelay.Core/Game/XPlatformId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public override int GetHashCode()
/// <returns>A string representation of the platform identifier.</returns>
public override string ToString()
{
return $"{PlatformCode.GetPrefix()}-{AccountId}";
return PlatformCode.GetPrefix() + "-" + AccountId.ToString();
}
#endregion
}
Expand Down
18 changes: 13 additions & 5 deletions EchoRelay.Core/Server/Services/Login/LoginService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace EchoRelay.Core.Server.Services.Login
/// <summary>
/// The login service is used to sign in, obtain a session, obtain logged in/other user profiles, update logged in profile, etc.
/// </summary>
public class LoginService : Service
public partial class LoginService : Service
{
#region Fields
/// <summary>
Expand Down Expand Up @@ -151,6 +151,9 @@ private async Task ProcessRemoteLogSetv3(Peer sender, RemoteLogSetv3 request)
{
try
{
// Avoid parsing the log if it doesn't contain the CUSTOMIZATION_METRICS_PAYLOAD message.
if (log.Contains("CUSTOMIZATION_METRICS_PAYLOAD") == false) continue;

dynamic? logJson = JsonConvert.DeserializeObject(log);

if (logJson == null) continue;
Expand All @@ -159,10 +162,10 @@ private async Task ProcessRemoteLogSetv3(Peer sender, RemoteLogSetv3 request)
if (logJson["[item_name]"] == null) continue;
string itemName = logJson["[item_name]"].ToString();

var regex1 = new System.Text.RegularExpressions.Regex(@"^(.*?)_.*$");
var regex2 = new System.Text.RegularExpressions.Regex(@"^rwd_(.*?)_.*$");
var match1 = regex1.Match(itemName);
var match2 = regex2.Match(itemName);
var itemRegex = ItemNameRegex();
var rewardRegex = RewardNameRegex();
var match1 = itemRegex.Match(itemName);
var match2 = rewardRegex.Match(itemName);

string itemType = match1.Groups[1].Value;
if (match2.Groups.Count > 1)
Expand Down Expand Up @@ -556,6 +559,11 @@ private async Task ProcessDocumentRequestv2(Peer sender, DocumentRequestv2 reque
await sender.Send(new DocumentSuccess(nameSymbol.Value, resource));
await sender.Send(new TcpConnectionUnrequireEvent());
}

[System.Text.RegularExpressions.GeneratedRegex("^(.*?)_.*$")]
private static partial System.Text.RegularExpressions.Regex ItemNameRegex();
[System.Text.RegularExpressions.GeneratedRegex("^rwd_(.*?)_.*$")]
private static partial System.Text.RegularExpressions.Regex RewardNameRegex();
#endregion
}
}

0 comments on commit 338c113

Please sign in to comment.