Radicade Public Code

This commit is contained in:
JogmansonReal
2026-10-16 23:33:13 -07:00
commit 55175acdf6
832 changed files with 363261 additions and 0 deletions
@@ -0,0 +1,54 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Runtime.CompilerServices;
using RadicadeServer.API.Notifications;
using RadicadeServer.DB;
using RadicadeServer.Extensions;
using RadicadeServer.RecNet.Enums.Messages;
using RadicadeServer.RecNet.Messages;
using RadicadeServer.RecNet.Notifications;
using RadicadeServer.RecNet.Relationships;
namespace RadicadeServer.API.Relationships
{
public static class RelationshipsShared
{
internal static IDbContextFactory<RecDBContext> DbFactory = null!;
internal static async Task<RealRelationship> GetOrCreate(RecDBContext db, long accountId, long playerId)
{
var rel = await db.Relationships.FirstOrDefaultAsync(x => x.AccountId == accountId && x.PlayerId == playerId);
if (rel == null)
{
rel = new RealRelationship { AccountId = accountId, PlayerId = playerId };
await db.Relationships.AddAsync(rel);
}
await db.SaveChangesAsync();
return rel;
}
internal static void SetReciprocalStatus(
RealRelationship mine, RealRelationship theirs,
Func<RealRelationship, ReciprocalStatus> getter,
Action<RealRelationship, ReciprocalStatus> setter,
bool enabling)
{
if (enabling)
{
var theirStatus = getter(theirs);
bool theyHaveIt = theirStatus == ReciprocalStatus.Local || theirStatus == ReciprocalStatus.Mutual;
setter(mine, theyHaveIt ? ReciprocalStatus.Mutual : ReciprocalStatus.Local);
setter(theirs, theyHaveIt ? ReciprocalStatus.Mutual : ReciprocalStatus.Remote);
}
else
{
var theirStatus = getter(theirs);
setter(mine, ReciprocalStatus.None);
setter(theirs, theirStatus == ReciprocalStatus.Mutual ? ReciprocalStatus.Remote : ReciprocalStatus.None);
}
}
}
}