mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-25 23:18:56 -07:00
Radicade Public Code
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user