mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-10 05:48:39 +00:00
Make MatchHelper use ConcurrentDictionary
This commit is contained in:
parent
6f55ce3226
commit
d806664b62
1 changed files with 7 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
||||||
#nullable enable
|
#nullable enable
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
@ -10,18 +11,18 @@ namespace LBPUnion.ProjectLighthouse.Helpers;
|
||||||
|
|
||||||
public static partial class MatchHelper
|
public static partial class MatchHelper
|
||||||
{
|
{
|
||||||
public static readonly Dictionary<int, string?> UserLocations = new();
|
public static readonly ConcurrentDictionary<int, string?> UserLocations = new();
|
||||||
public static readonly Dictionary<int, List<int>?> UserRecentlyDivedIn = new();
|
public static readonly ConcurrentDictionary<int, List<int>?> UserRecentlyDivedIn = new();
|
||||||
|
|
||||||
public static void SetUserLocation(int userId, string location)
|
public static void SetUserLocation(int userId, string location)
|
||||||
{
|
{
|
||||||
if (UserLocations.TryGetValue(userId, out string? _)) UserLocations.Remove(userId);
|
if (UserLocations.TryGetValue(userId, out string? _)) UserLocations.TryRemove(userId, out _);
|
||||||
UserLocations.Add(userId, location);
|
UserLocations.TryAdd(userId, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddUserRecentlyDivedIn(int userId, int otherUserId)
|
public static void AddUserRecentlyDivedIn(int userId, int otherUserId)
|
||||||
{
|
{
|
||||||
if (!UserRecentlyDivedIn.TryGetValue(userId, out List<int>? recentlyDivedIn)) UserRecentlyDivedIn.Add(userId, recentlyDivedIn = new List<int>());
|
if (!UserRecentlyDivedIn.TryGetValue(userId, out List<int>? recentlyDivedIn)) UserRecentlyDivedIn.TryAdd(userId, recentlyDivedIn = new List<int>());
|
||||||
|
|
||||||
Debug.Assert(recentlyDivedIn != null, nameof(recentlyDivedIn) + " is null, somehow.");
|
Debug.Assert(recentlyDivedIn != null, nameof(recentlyDivedIn) + " is null, somehow.");
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ public static partial class MatchHelper
|
||||||
return recentlyDivedIn.Contains(otherUserId);
|
return recentlyDivedIn.Contains(otherUserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ClearUserRecentDiveIns(int userId) => UserRecentlyDivedIn.Remove(userId);
|
public static void ClearUserRecentDiveIns(int userId) => UserRecentlyDivedIn.TryRemove(userId, out _);
|
||||||
|
|
||||||
[GeneratedRegex("^\\[([^,]*),\\[(.*)\\]\\]")]
|
[GeneratedRegex("^\\[([^,]*),\\[(.*)\\]\\]")]
|
||||||
private static partial Regex MatchJsonRegex();
|
private static partial Regex MatchJsonRegex();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue