mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-01 19:01:33 +00:00
Theoretically move friend/blocked data to Redis
Untested due to shenanigans with Redis.
This commit is contained in:
parent
82091c6d8b
commit
bd41997aae
11 changed files with 166 additions and 133 deletions
|
@ -1,24 +1,21 @@
|
||||||
<component name="ProjectRunConfigurationManager">
|
<component name="ProjectRunConfigurationManager">
|
||||||
<configuration default="false" name="Lighthouse API" type="DotNetProject" factoryName=".NET Project">
|
<configuration default="false" name="Lighthouse API" type="DotNetProject" factoryName=".NET Project">
|
||||||
<option name="EXE_PATH"
|
<option name="EXE_PATH" value="$PROJECT_DIR$/ProjectLighthouse.Servers.API/bin/Debug/net6.0/LBPUnion.ProjectLighthouse.Servers.API" />
|
||||||
value="$PROJECT_DIR$/ProjectLighthouse.API/bin/Debug/net6.0/LBPUnion.ProjectLighthouse.API"/>
|
<option name="PROGRAM_PARAMETERS" value="" />
|
||||||
<option name="PROGRAM_PARAMETERS" value=""/>
|
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/ProjectLighthouse" />
|
||||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/ProjectLighthouse"/>
|
<option name="PASS_PARENT_ENVS" value="1" />
|
||||||
<option name="PASS_PARENT_ENVS" value="1"/>
|
<option name="USE_EXTERNAL_CONSOLE" value="0" />
|
||||||
<option name="USE_EXTERNAL_CONSOLE" value="0"/>
|
<option name="USE_MONO" value="0" />
|
||||||
<option name="USE_MONO" value="0"/>
|
<option name="RUNTIME_ARGUMENTS" value="" />
|
||||||
<option name="RUNTIME_ARGUMENTS" value=""/>
|
<option name="PROJECT_PATH" value="$PROJECT_DIR$/ProjectLighthouse.Servers.API/ProjectLighthouse.Servers.API.csproj" />
|
||||||
<option name="PROJECT_PATH"
|
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
|
||||||
value="$PROJECT_DIR$/ProjectLighthouse.Servers.API/ProjectLighthouse.Servers.API.csproj"/>
|
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
|
||||||
<option name="PROJECT_EXE_PATH_TRACKING" value="1"/>
|
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
|
||||||
<option name="PROJECT_ARGUMENTS_TRACKING" value="1"/>
|
<option name="PROJECT_KIND" value="DotNetCore" />
|
||||||
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0"/>
|
<option name="PROJECT_TFM" value="net6.0" />
|
||||||
<option name="PROJECT_KIND" value="DotNetCore"/>
|
|
||||||
<option name="PROJECT_TFM" value="net6.0"/>
|
|
||||||
<method v="2">
|
<method v="2">
|
||||||
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Development Database"
|
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Development Databases" run_configuration_type="docker-deploy" />
|
||||||
run_configuration_type="docker-deploy"/>
|
<option name="Build" />
|
||||||
<option name="Build"/>
|
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
</component>
|
</component>
|
|
@ -1,24 +1,21 @@
|
||||||
<component name="ProjectRunConfigurationManager">
|
<component name="ProjectRunConfigurationManager">
|
||||||
<configuration default="false" name="Lighthouse Gameserver" type="DotNetProject" factoryName=".NET Project">
|
<configuration default="false" name="Lighthouse Gameserver" type="DotNetProject" factoryName=".NET Project">
|
||||||
<option name="EXE_PATH"
|
<option name="EXE_PATH" value="$PROJECT_DIR$/ProjectLighthouse.Servers.GameServer/bin/Debug/net6.0/LBPUnion.ProjectLighthouse.Servers.GameServer" />
|
||||||
value="$PROJECT_DIR$/ProjectLighthouse.Servers.GameServer/bin/Debug/net6.0/LBPUnion.ProjectLighthouse.Servers.GameServer"/>
|
<option name="PROGRAM_PARAMETERS" value="" />
|
||||||
<option name="PROGRAM_PARAMETERS" value=""/>
|
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/ProjectLighthouse" />
|
||||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/ProjectLighthouse"/>
|
<option name="PASS_PARENT_ENVS" value="1" />
|
||||||
<option name="PASS_PARENT_ENVS" value="1"/>
|
<option name="USE_EXTERNAL_CONSOLE" value="0" />
|
||||||
<option name="USE_EXTERNAL_CONSOLE" value="0"/>
|
<option name="USE_MONO" value="0" />
|
||||||
<option name="USE_MONO" value="0"/>
|
<option name="RUNTIME_ARGUMENTS" value="" />
|
||||||
<option name="RUNTIME_ARGUMENTS" value=""/>
|
<option name="PROJECT_PATH" value="$PROJECT_DIR$/ProjectLighthouse.Servers.GameServer/ProjectLighthouse.Servers.GameServer.csproj" />
|
||||||
<option name="PROJECT_PATH"
|
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
|
||||||
value="$PROJECT_DIR$/ProjectLighthouse.Servers.GameServer/ProjectLighthouse.Servers.GameServer.csproj"/>
|
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
|
||||||
<option name="PROJECT_EXE_PATH_TRACKING" value="1"/>
|
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
|
||||||
<option name="PROJECT_ARGUMENTS_TRACKING" value="1"/>
|
<option name="PROJECT_KIND" value="DotNetCore" />
|
||||||
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0"/>
|
<option name="PROJECT_TFM" value="net6.0" />
|
||||||
<option name="PROJECT_KIND" value="DotNetCore"/>
|
|
||||||
<option name="PROJECT_TFM" value="net6.0"/>
|
|
||||||
<method v="2">
|
<method v="2">
|
||||||
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Development Database"
|
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Development Databases" run_configuration_type="docker-deploy" />
|
||||||
run_configuration_type="docker-deploy"/>
|
<option name="Build" />
|
||||||
<option name="Build"/>
|
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
</component>
|
</component>
|
|
@ -1,24 +1,21 @@
|
||||||
<component name="ProjectRunConfigurationManager">
|
<component name="ProjectRunConfigurationManager">
|
||||||
<configuration default="false" name="Lighthouse Website" type="DotNetProject" factoryName=".NET Project">
|
<configuration default="false" name="Lighthouse Website" type="DotNetProject" factoryName=".NET Project">
|
||||||
<option name="EXE_PATH"
|
<option name="EXE_PATH" value="$PROJECT_DIR$/ProjectLighthouse.Servers.Website/bin/Debug/net6.0/LBPUnion.ProjectLighthouse.Servers.Website" />
|
||||||
value="$PROJECT_DIR$/ProjectLighthouse.Servers.Website/bin/Debug/net6.0/LBPUnion.ProjectLighthouse.Servers.Website"/>
|
<option name="PROGRAM_PARAMETERS" value="" />
|
||||||
<option name="PROGRAM_PARAMETERS" value=""/>
|
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/ProjectLighthouse" />
|
||||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/ProjectLighthouse"/>
|
<option name="PASS_PARENT_ENVS" value="1" />
|
||||||
<option name="PASS_PARENT_ENVS" value="1"/>
|
<option name="USE_EXTERNAL_CONSOLE" value="0" />
|
||||||
<option name="USE_EXTERNAL_CONSOLE" value="0"/>
|
<option name="USE_MONO" value="0" />
|
||||||
<option name="USE_MONO" value="0"/>
|
<option name="RUNTIME_ARGUMENTS" value="" />
|
||||||
<option name="RUNTIME_ARGUMENTS" value=""/>
|
<option name="PROJECT_PATH" value="$PROJECT_DIR$/ProjectLighthouse.Servers.Website/ProjectLighthouse.Servers.Website.csproj" />
|
||||||
<option name="PROJECT_PATH"
|
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
|
||||||
value="$PROJECT_DIR$/ProjectLighthouse.Servers.Website/ProjectLighthouse.Servers.Website.csproj"/>
|
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
|
||||||
<option name="PROJECT_EXE_PATH_TRACKING" value="1"/>
|
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
|
||||||
<option name="PROJECT_ARGUMENTS_TRACKING" value="1"/>
|
<option name="PROJECT_KIND" value="DotNetCore" />
|
||||||
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0"/>
|
<option name="PROJECT_TFM" value="net6.0" />
|
||||||
<option name="PROJECT_KIND" value="DotNetCore"/>
|
|
||||||
<option name="PROJECT_TFM" value="net6.0"/>
|
|
||||||
<method v="2">
|
<method v="2">
|
||||||
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Development Database"
|
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Development Databases" run_configuration_type="docker-deploy" />
|
||||||
run_configuration_type="docker-deploy"/>
|
<option name="Build" />
|
||||||
<option name="Build"/>
|
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
</component>
|
</component>
|
|
@ -1,22 +1,21 @@
|
||||||
<component name="ProjectRunConfigurationManager">
|
<component name="ProjectRunConfigurationManager">
|
||||||
<configuration default="false" name="Lighthouse" type="DotNetProject" factoryName=".NET Project">
|
<configuration default="false" name="Lighthouse" type="DotNetProject" factoryName=".NET Project">
|
||||||
<option name="EXE_PATH" value="$PROJECT_DIR$/ProjectLighthouse/bin/Debug/net6.0/LBPUnion.ProjectLighthouse"/>
|
<option name="EXE_PATH" value="$PROJECT_DIR$/ProjectLighthouse/bin/Debug/net6.0/LBPUnion.ProjectLighthouse" />
|
||||||
<option name="PROGRAM_PARAMETERS" value=""/>
|
<option name="PROGRAM_PARAMETERS" value="" />
|
||||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/ProjectLighthouse"/>
|
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/ProjectLighthouse" />
|
||||||
<option name="PASS_PARENT_ENVS" value="1"/>
|
<option name="PASS_PARENT_ENVS" value="1" />
|
||||||
<option name="USE_EXTERNAL_CONSOLE" value="0"/>
|
<option name="USE_EXTERNAL_CONSOLE" value="0" />
|
||||||
<option name="USE_MONO" value="0"/>
|
<option name="USE_MONO" value="0" />
|
||||||
<option name="RUNTIME_ARGUMENTS" value=""/>
|
<option name="RUNTIME_ARGUMENTS" value="" />
|
||||||
<option name="PROJECT_PATH" value="$PROJECT_DIR$/ProjectLighthouse/ProjectLighthouse.csproj"/>
|
<option name="PROJECT_PATH" value="$PROJECT_DIR$/ProjectLighthouse/ProjectLighthouse.csproj" />
|
||||||
<option name="PROJECT_EXE_PATH_TRACKING" value="1"/>
|
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
|
||||||
<option name="PROJECT_ARGUMENTS_TRACKING" value="1"/>
|
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
|
||||||
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1"/>
|
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
|
||||||
<option name="PROJECT_KIND" value="Unloaded"/>
|
<option name="PROJECT_KIND" value="Unloaded" />
|
||||||
<option name="PROJECT_TFM" value="net6.0"/>
|
<option name="PROJECT_TFM" value="net6.0" />
|
||||||
<method v="2">
|
<method v="2">
|
||||||
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Development Database"
|
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Development Databases" run_configuration_type="docker-deploy" />
|
||||||
run_configuration_type="docker-deploy"/>
|
<option name="Build" />
|
||||||
<option name="Build"/>
|
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
</component>
|
</component>
|
|
@ -53,14 +53,13 @@ public class FriendsController : ControllerBase
|
||||||
blockedUsers.Add(blockedUser.UserId);
|
blockedUsers.Add(blockedUser.UserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FriendHelper.FriendIdsByUserId.ContainsKey(user.UserId))
|
UserFriendStore? friendStore = Redis.GetUserFriendStore(user.UserId);
|
||||||
{
|
if (friendStore == null) friendStore = Redis.CreateUserFriendStore(user.UserId);
|
||||||
FriendHelper.FriendIdsByUserId.Remove(user.UserId);
|
|
||||||
FriendHelper.BlockedIdsByUserId.Remove(user.UserId);
|
|
||||||
}
|
|
||||||
|
|
||||||
FriendHelper.FriendIdsByUserId.Add(user.UserId, friends.Select(u => u.UserId).ToArray());
|
friendStore.FriendIds = friends.Select(u => u.UserId).ToList();
|
||||||
FriendHelper.BlockedIdsByUserId.Add(user.UserId, blockedUsers.ToArray());
|
friendStore.BlockedIds = blockedUsers;
|
||||||
|
|
||||||
|
Redis.UpdateFriendStore(friendStore);
|
||||||
|
|
||||||
string friendsSerialized = friends.Aggregate(string.Empty, (current, user1) => current + LbpSerializer.StringElement("npHandle", user1.Username));
|
string friendsSerialized = friends.Aggregate(string.Empty, (current, user1) => current + LbpSerializer.StringElement("npHandle", user1.Username));
|
||||||
|
|
||||||
|
@ -78,11 +77,13 @@ public class FriendsController : ControllerBase
|
||||||
User user = userAndToken.Value.Item1;
|
User user = userAndToken.Value.Item1;
|
||||||
GameToken gameToken = userAndToken.Value.Item2;
|
GameToken gameToken = userAndToken.Value.Item2;
|
||||||
|
|
||||||
if (!FriendHelper.FriendIdsByUserId.TryGetValue(user.UserId, out int[]? friendIds) || friendIds == null)
|
UserFriendStore? friendStore = Redis.GetUserFriendStore(user.UserId);
|
||||||
|
|
||||||
|
if (friendStore == null)
|
||||||
return this.Ok(LbpSerializer.BlankElement("myFriends"));
|
return this.Ok(LbpSerializer.BlankElement("myFriends"));
|
||||||
|
|
||||||
string friends = "";
|
string friends = "";
|
||||||
foreach (int friendId in friendIds)
|
foreach (int friendId in friendStore.FriendIds)
|
||||||
{
|
{
|
||||||
User? friend = await this.database.Users.Include(u => u.Location).FirstOrDefaultAsync(u => u.UserId == friendId);
|
User? friend = await this.database.Users.Include(u => u.Location).FirstOrDefaultAsync(u => u.UserId == friendId);
|
||||||
if (friend == null) continue;
|
if (friend == null) continue;
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Helpers;
|
|
||||||
|
|
||||||
[NotMapped]
|
|
||||||
[SuppressMessage("ReSharper", "CollectionNeverQueried.Global")]
|
|
||||||
public static class FriendHelper
|
|
||||||
{
|
|
||||||
public static readonly Dictionary<int, int[]> FriendIdsByUserId = new();
|
|
||||||
public static readonly Dictionary<int, int[]> BlockedIdsByUserId = new();
|
|
||||||
}
|
|
|
@ -8,22 +8,22 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3"/>
|
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
||||||
<PackageReference Include="DDSReader" Version="1.0.8-pre"/>
|
<PackageReference Include="DDSReader" Version="1.0.8-pre" />
|
||||||
<PackageReference Include="Discord.Net.Webhook" Version="3.6.1"/>
|
<PackageReference Include="Discord.Net.Webhook" Version="3.6.1" />
|
||||||
<PackageReference Include="InfluxDB.Client" Version="4.1.0"/>
|
<PackageReference Include="InfluxDB.Client" Version="4.1.0" />
|
||||||
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0"/>
|
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.5"/>
|
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.5" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.5"/>
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.5" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.5">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.5">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.1"/>
|
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.1" />
|
||||||
<PackageReference Include="Redis.OM" Version="0.1.9"/>
|
<PackageReference Include="Redis.OM" Version="0.1.9" />
|
||||||
<PackageReference Include="SharpZipLib" Version="1.3.3"/>
|
<PackageReference Include="SharpZipLib" Version="1.3.3" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.1"/>
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.1" />
|
||||||
<PackageReference Include="YamlDotNet" Version="11.2.1"/>
|
<PackageReference Include="YamlDotNet" Version="11.2.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -39,28 +39,29 @@
|
||||||
<EmbeddedResource Include="gitRemotes.txt">
|
<EmbeddedResource Include="gitRemotes.txt">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<None Remove="gitUnpushed.txt"/>
|
<None Remove="gitUnpushed.txt" />
|
||||||
<EmbeddedResource Include="gitUnpushed.txt">
|
<EmbeddedResource Include="gitUnpushed.txt">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<None Remove="chatCensoredList.txt"/>
|
<None Remove="chatCensoredList.txt" />
|
||||||
<EmbeddedResource Include="chatCensoredList.txt">
|
<EmbeddedResource Include="chatCensoredList.txt">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Remove="Extensions\SerializationExtensions.cs"/>
|
<Compile Remove="Extensions\SerializationExtensions.cs" />
|
||||||
|
<Compile Remove="Helpers\FriendHelper.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Startup\Middlewares"/>
|
<Folder Include="Startup\Middlewares" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
||||||
<Exec Command="git describe --long --always --dirty --exclude=\* --abbrev=8 > "$(ProjectDir)/gitVersion.txt""/>
|
<Exec Command="git describe --long --always --dirty --exclude=\* --abbrev=8 > "$(ProjectDir)/gitVersion.txt"" />
|
||||||
<Exec Command="git branch --show-current > "$(ProjectDir)/gitBranch.txt""/>
|
<Exec Command="git branch --show-current > "$(ProjectDir)/gitBranch.txt"" />
|
||||||
<Exec Command="git remote -v > "$(ProjectDir)/gitRemotes.txt""/>
|
<Exec Command="git remote -v > "$(ProjectDir)/gitRemotes.txt"" />
|
||||||
<Exec Command="git log --branches --not --remotes --oneline > "$(ProjectDir)/gitUnpushed.txt""/>
|
<Exec Command="git log --branches --not --remotes --oneline > "$(ProjectDir)/gitUnpushed.txt"" />
|
||||||
</Target>
|
</Target>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
|
#nullable enable
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using LBPUnion.ProjectLighthouse.Helpers;
|
||||||
using LBPUnion.ProjectLighthouse.Logging;
|
using LBPUnion.ProjectLighthouse.Logging;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Match;
|
using LBPUnion.ProjectLighthouse.Types.Match;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Settings;
|
using LBPUnion.ProjectLighthouse.Types.Settings;
|
||||||
using Redis.OM;
|
using Redis.OM;
|
||||||
|
@ -18,7 +22,7 @@ public static class Redis
|
||||||
provider = new RedisConnectionProvider(ServerConfiguration.Instance.RedisConnectionString);
|
provider = new RedisConnectionProvider(ServerConfiguration.Instance.RedisConnectionString);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool initialized = false;
|
private static bool initialized;
|
||||||
public static async Task Initialize()
|
public static async Task Initialize()
|
||||||
{
|
{
|
||||||
if (initialized) throw new InvalidOperationException("Redis has already been initialized.");
|
if (initialized) throw new InvalidOperationException("Redis has already been initialized.");
|
||||||
|
@ -26,6 +30,7 @@ public static class Redis
|
||||||
IRedisConnection connection = getConnection();
|
IRedisConnection connection = getConnection();
|
||||||
|
|
||||||
await connection.CreateIndexAsync(typeof(Room));
|
await connection.CreateIndexAsync(typeof(Room));
|
||||||
|
await connection.CreateIndexAsync(typeof(UserFriendStore));
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
Logger.LogSuccess("Initialized Redis.", LogArea.Redis);
|
Logger.LogSuccess("Initialized Redis.", LogArea.Redis);
|
||||||
|
@ -38,4 +43,25 @@ public static class Redis
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IRedisCollection<Room> GetRooms() => provider.RedisCollection<Room>();
|
public static IRedisCollection<Room> GetRooms() => provider.RedisCollection<Room>();
|
||||||
|
|
||||||
|
private static IRedisCollection<UserFriendStore> userFriendStoreCollection => provider.RedisCollection<UserFriendStore>();
|
||||||
|
|
||||||
|
public static UserFriendStore? GetUserFriendStore(int userId) =>
|
||||||
|
userFriendStoreCollection.FirstOrDefault(s => s.UserId == userId);
|
||||||
|
|
||||||
|
public static UserFriendStore CreateUserFriendStore(int userId)
|
||||||
|
{
|
||||||
|
UserFriendStore friendStore = new()
|
||||||
|
{
|
||||||
|
UserId = userId,
|
||||||
|
};
|
||||||
|
|
||||||
|
userFriendStoreCollection.Insert(friendStore);
|
||||||
|
return friendStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void UpdateFriendStore(UserFriendStore friendStore)
|
||||||
|
{
|
||||||
|
userFriendStoreCollection.UpdateSync(friendStore);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -32,7 +32,7 @@ public static class StartupTasks
|
||||||
// Referencing ServerSettings.Instance here loads the config, see ServerSettings.cs for more information
|
// Referencing ServerSettings.Instance here loads the config, see ServerSettings.cs for more information
|
||||||
Logger.LogSuccess("Loaded config file version " + ServerConfiguration.Instance.ConfigVersion, LogArea.Startup);
|
Logger.LogSuccess("Loaded config file version " + ServerConfiguration.Instance.ConfigVersion, LogArea.Startup);
|
||||||
|
|
||||||
Logger.LogInfo("Determining if the database is available...", LogArea.Startup);
|
Logger.LogInfo("Connecting to the database...", LogArea.Startup);
|
||||||
bool dbConnected = ServerStatics.DbConnected;
|
bool dbConnected = ServerStatics.DbConnected;
|
||||||
if (!dbConnected)
|
if (!dbConnected)
|
||||||
{
|
{
|
||||||
|
@ -40,7 +40,7 @@ public static class StartupTasks
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Logger.LogSuccess("Connected to the database.", LogArea.Startup);
|
Logger.LogSuccess("Connected!", LogArea.Startup);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dbConnected) Environment.Exit(1);
|
if (!dbConnected) Environment.Exit(1);
|
||||||
|
|
|
@ -170,7 +170,7 @@ public class ServerConfiguration
|
||||||
public string ApiListenUrl { get; set; } = "http://localhost:10062";
|
public string ApiListenUrl { get; set; } = "http://localhost:10062";
|
||||||
|
|
||||||
public string DbConnectionString { get; set; } = "server=127.0.0.1;uid=root;pwd=lighthouse;database=lighthouse";
|
public string DbConnectionString { get; set; } = "server=127.0.0.1;uid=root;pwd=lighthouse;database=lighthouse";
|
||||||
public string RedisConnectionString { get; set; } = "";
|
public string RedisConnectionString { get; set; } = "redis://localhost:6379";
|
||||||
public string ExternalUrl { get; set; } = "http://localhost:10060";
|
public string ExternalUrl { get; set; } = "http://localhost:10060";
|
||||||
public bool ConfigReloading { get; set; }
|
public bool ConfigReloading { get; set; }
|
||||||
public string EulaText { get; set; } = "";
|
public string EulaText { get; set; } = "";
|
||||||
|
|
28
ProjectLighthouse/Types/UserFriendStore.cs
Normal file
28
ProjectLighthouse/Types/UserFriendStore.cs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Redis.OM.Modeling;
|
||||||
|
|
||||||
|
namespace LBPUnion.ProjectLighthouse.Types;
|
||||||
|
|
||||||
|
[SuppressMessage("ReSharper", "CollectionNeverQueried.Global")]
|
||||||
|
[Document(StorageType = StorageType.Json)]
|
||||||
|
public class UserFriendStore
|
||||||
|
{
|
||||||
|
private int userId;
|
||||||
|
public int UserId {
|
||||||
|
get => this.userId;
|
||||||
|
set {
|
||||||
|
this.RedisId = value.ToString();
|
||||||
|
this.userId = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[RedisIdField]
|
||||||
|
public string RedisId { get; set; }
|
||||||
|
|
||||||
|
[Indexed]
|
||||||
|
public List<int> FriendIds { get; set; }
|
||||||
|
|
||||||
|
[Indexed]
|
||||||
|
public List<int> BlockedIds { get; set; }
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue