Skip to content

Commit

Permalink
MatchService + GameUser: Move force matches to GameUser (#322)
Browse files Browse the repository at this point in the history
This is in preparation of #282
  • Loading branch information
jvyden authored Jan 2, 2024
2 parents 0b8ee5b + 6070e81 commit 55465b6
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 26 deletions.
16 changes: 16 additions & 0 deletions Refresh.GameServer/Database/GameDatabaseContext.Users.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,22 @@ public void SetUserGriefReportRedirection(GameUser user, bool value)
user.RedirectGriefReportsToPhotos = value;
});
}

public void ClearForceMatch(GameUser user)
{
this._realm.Write(() =>
{
user.ForceMatch = null;
});
}

public void SetForceMatch(GameUser user, GameUser target)
{
this._realm.Write(() =>
{
user.ForceMatch = target.ForceMatch;
});
}

#if DEBUG
public void ForceUserTokenGame(Token token, TokenGame game)
Expand Down
2 changes: 1 addition & 1 deletion Refresh.GameServer/Database/GameDatabaseProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected GameDatabaseProvider(IDateTimeProvider time)
this._time = time;
}

protected override ulong SchemaVersion => 102;
protected override ulong SchemaVersion => 103;

protected override string Filename => "refreshGameServer.realm";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ public class AuthenticationEndpoints : EndpointGroup

Token token = database.GenerateTokenForUser(user, TokenType.Game, game.Value, platform.Value, GameDatabaseContext.GameTokenExpirySeconds); // 4 hours

//Clear the user's force match
database.ClearForceMatch(user);

if (game == TokenGame.LittleBigPlanetPSP)
{
return new TicketLoginResponse
Expand Down
4 changes: 2 additions & 2 deletions Refresh.GameServer/Services/CommandService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ public void HandleCommand(CommandInvocation command, GameDatabaseContext databas

if (target != null)
{
this._match.SetForceMatch(user.UserId, target.UserId);
database.SetForceMatch(user, target);
}

break;
}
case "clearforcematch":
{
this._match.ClearForceMatch(user.UserId);
database.ClearForceMatch(user);
break;
}
case "griefphotoson":
Expand Down
21 changes: 0 additions & 21 deletions Refresh.GameServer/Services/MatchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public partial class MatchService(Logger logger) : EndpointService(logger)
private FrozenSet<IMatchMethod> _matchMethods = null!; // initialized in Initialize()

public IRoomAccessor RoomAccessor { get; private set; } = null!; //initialized in Initialize()
private readonly Dictionary<ObjectId, ObjectId> _forceMatches = new();

public GameRoom GetOrCreateRoomByPlayer(GameUser player, TokenPlatform platform, TokenGame game, NatType natType)
{
Expand Down Expand Up @@ -120,24 +119,4 @@ public Response ExecuteMethod(string methodStr, SerializedRoomData roomData, Gam

return method.Execute(this, this.Logger, database, user, token, roomData);
}

public void SetForceMatch(ObjectId user, ObjectId target)
{
this._forceMatches[user] = target;
}

public ObjectId? GetForceMatch(ObjectId user)
{
if (this._forceMatches.TryGetValue(user, out ObjectId target))
{
return target;
}

return null;
}

public void ClearForceMatch(ObjectId user)
{
this._forceMatches.Remove(user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Response Execute(MatchService service, Logger logger, GameDatabaseContext
rooms = rooms.Where(r => r.NatType == NatType.Open).ToList();
}

ObjectId? forceMatch = service.GetForceMatch(user.UserId);
ObjectId? forceMatch = user.ForceMatch;

//If the user has a forced match
if (forceMatch != null)
Expand All @@ -68,7 +68,7 @@ public Response Execute(MatchService service, Logger logger, GameDatabaseContext
if (forceMatch != null)
{
//Clear the user's force match
service.ClearForceMatch(user.UserId);
database.ClearForceMatch(user);
}

GameRoom room = rooms[Random.Shared.Next(0, rooms.Count)];
Expand Down
5 changes: 5 additions & 0 deletions Refresh.GameServer/Types/UserData/GameUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public partial class GameUser : IRealmObject, IRateLimitUser
public bool ShouldResetPassword { get; set; }

public string IconHash { get; set; } = "0";

/// <summary>
/// The force match of the user, cleared on login
/// </summary>
public ObjectId? ForceMatch { get; set; }

/// <summary>
/// The <see cref="IconHash"/>, except only for PSP clients.
Expand Down

0 comments on commit 55465b6

Please sign in to comment.