Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore game build version when matching #588

Merged
merged 1 commit into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Refresh.GameServer/Endpoints/Game/MatchingEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Response Match(
[GameEndpoint("enterLevel/{slotType}/{id}", HttpMethods.Post)]
public Response EnterLevel(RequestContext context, Token token, MatchService matchService, string slotType, int id)
{
GameRoom room = matchService.GetOrCreateRoomByPlayer(token.User, token.TokenPlatform, token.TokenGame, NatType.Strict, null, false);
GameRoom room = matchService.GetOrCreateRoomByPlayer(token.User, token.TokenPlatform, token.TokenGame, NatType.Strict, false);

// User slot ID of 0 means pod/moon level
if (id == 0 && slotType == "user")
Expand Down
17 changes: 7 additions & 10 deletions Refresh.GameServer/Services/MatchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ public GameRoom GetOrCreateRoomByPlayer(
GameUser player,
TokenPlatform platform,
TokenGame game,
NatType natType,
int? buildVersion,
NatType natType,
bool? passedNoJoinPoint = null)
{
GameRoom? room = this.RoomAccessor.GetRoomByUser(player, platform, game);

// ReSharper disable once ConvertIfStatementToNullCoalescingExpression
if (room == null)
room = this.CreateRoomByPlayer(player, platform, game, natType, buildVersion, passedNoJoinPoint);
room = this.CreateRoomByPlayer(player, platform, game, natType, passedNoJoinPoint);

return room;
}
Expand All @@ -43,11 +42,10 @@ public GameRoom CreateRoomByPlayer(
GameUser player,
TokenPlatform platform,
TokenGame game,
NatType natType,
int? buildVersion,
NatType natType,
bool? passedNoJoinPoint = null)
{
GameRoom room = new(player, platform, game, natType, buildVersion, passedNoJoinPoint);
GameRoom room = new(player, platform, game, natType, passedNoJoinPoint);
this.RoomAccessor.AddRoom(room);
return room;
}
Expand All @@ -56,22 +54,21 @@ public GameRoom SplitUserIntoNewRoom(
GameUser player,
TokenPlatform platform,
TokenGame game,
NatType natType,
int? buildVersion,
NatType natType,
bool? passedNoJoinPoint = null)
{
GameRoom? room = this.RoomAccessor.GetRoomByUser(player, platform, game);
if (room == null)
{
return this.CreateRoomByPlayer(player, platform, game, natType, buildVersion, passedNoJoinPoint);
return this.CreateRoomByPlayer(player, platform, game, natType, passedNoJoinPoint);
}

// Remove player from old room
room.PlayerIds.RemoveAll(i => i.Id == player.UserId);
// Update the room on the room accessor
this.RoomAccessor.UpdateRoom(room);

return this.CreateRoomByPlayer(player, platform, game, natType, buildVersion, passedNoJoinPoint);
return this.CreateRoomByPlayer(player, platform, game, natType, passedNoJoinPoint);
}

public int GetPlayerCountForLevel(RoomSlotType type, int id)
Expand Down
6 changes: 2 additions & 4 deletions Refresh.GameServer/Types/Matching/GameRoom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ namespace Refresh.GameServer.Types.Matching;

public class GameRoom
{
public GameRoom(GameUser host, TokenPlatform platform, TokenGame game, NatType natType, int? buildVersion, bool? passedNoJoinPoint)
public GameRoom(GameUser host, TokenPlatform platform, TokenGame game, NatType natType, bool? passedNoJoinPoint)
{
this.PlayerIds.Add(new GameRoomPlayer(host.Username, host.UserId));
this.Platform = platform;
this.Game = game;
this.NatType = natType;
this.BuildVersion = buildVersion;
this.PassedNoJoinPoint = passedNoJoinPoint ?? false;
}

Expand All @@ -29,8 +28,7 @@ public GameRoom(GameUser host, TokenPlatform platform, TokenGame game, NatType n
public readonly NatType NatType;

public DateTimeOffset LastContact;

public int? BuildVersion;

public bool PassedNoJoinPoint;

public List<GameUser?> GetPlayers(GameDatabaseContext database) =>
Expand Down
6 changes: 3 additions & 3 deletions Refresh.GameServer/Types/Matching/IRoomAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,17 @@ public IEnumerable<GameRoom> GetRoomsInLevel(GameLevel level) => this.GetRoomsIn
/// <param name="platform">The platform to check for</param>
/// <param name="game">The game to check for</param>
/// <returns>The found room, or null if not found</returns>
public GameRoom? GetRoomByUser(GameUser user, TokenPlatform? platform = null, TokenGame? game = null, int? buildVersion = null) => this.GetRoomByUserUuid(user.UserId, platform, game, buildVersion);
public GameRoom? GetRoomByUser(GameUser user, TokenPlatform? platform = null, TokenGame? game = null) => this.GetRoomByUserUuid(user.UserId, platform, game);
/// <summary>
/// Gets a room by a user's UUID.
/// </summary>
/// <param name="uuid">The user UUID to search for</param>
/// <returns>The found room, or null if not found</returns>
public GameRoom? GetRoomByUserUuid(ObjectId uuid, TokenPlatform? platform = null, TokenGame? game = null, int? buildVersion = null);
public GameRoom? GetRoomByUserUuid(ObjectId uuid, TokenPlatform? platform = null, TokenGame? game = null);
/// <summary>
/// Gets a room by a user's username.
/// </summary>
/// <param name="username">The username to search for</param>
/// <returns>The found room, or null if not found</returns>
public GameRoom? GetRoomByUsername(string username, TokenPlatform? platform = null, TokenGame? game = null, int? buildVersion = null);
public GameRoom? GetRoomByUsername(string username, TokenPlatform? platform = null, TokenGame? game = null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public class CreateRoomMethod : IMatchMethod
public Response Execute(DataContext dataContext, SerializedRoomData body, GameServerConfig gameServerConfig)
{
NatType natType = body.NatType == null ? NatType.Open : body.NatType[0];
GameRoom room = dataContext.Match.GetOrCreateRoomByPlayer(dataContext.User!, dataContext.Platform, dataContext.Game, natType, body.BuildVersion, body.PassedNoJoinPoint);
GameRoom room = dataContext.Match.GetOrCreateRoomByPlayer(dataContext.User!, dataContext.Platform, dataContext.Game, natType, body.PassedNoJoinPoint);
if (room.HostId.Id != dataContext.User!.UserId)
{
room = dataContext.Match.SplitUserIntoNewRoom(dataContext.User, dataContext.Platform, dataContext.Game, natType, body.BuildVersion, body.PassedNoJoinPoint);
room = dataContext.Match.SplitUserIntoNewRoom(dataContext.User, dataContext.Platform, dataContext.Game, natType, body.PassedNoJoinPoint);
}

if (body.RoomState != null) room.RoomState = body.RoomState.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ public Response Execute(DataContext dataContext, SerializedRoomData body, GameSe
(userLevelIds.Count == 0 || r.LevelType != RoomSlotType.Online || userLevelIds.Contains(r.LevelId)) &&
(developerLevelIds.Count == 0 || r.LevelType != RoomSlotType.Story || developerLevelIds.Contains(r.LevelId)) &&
// Make sure that we don't try to match the player into a full room, or a room which won't fit the user's current room
usersRoom.PlayerIds.Count + r.PlayerIds.Count <= 4 &&
// Match the build version of the rooms, or dont match build versions if the game doesnt specify it
(body.BuildVersion == null || (r.BuildVersion ?? 0) == body.BuildVersion))
usersRoom.PlayerIds.Count + r.PlayerIds.Count <= 4)
// Shuffle the rooms around before sorting, this is because the selection is based on a weighted average towards the top of the range,
// so there would be a bias towards longer lasting rooms without this shuffle
.OrderBy(r => Random.Shared.Next())
Expand Down Expand Up @@ -117,9 +115,8 @@ public Response Execute(DataContext dataContext, SerializedRoomData body, GameSe

foreach (GameRoom logRoom in allRooms)
dataContext.Logger.LogInfo(BunkumCategory.Matching,
"Room {0}: Nat Type {1}, Level {2} ({3}), Build Version {4}",
logRoom.RoomId, logRoom.NatType, logRoom.LevelId, logRoom.LevelType,
logRoom.BuildVersion ?? 0);
"Room {0}: Nat Type {1}, Level {2} ({3})",
logRoom.RoomId, logRoom.NatType, logRoom.LevelId, logRoom.LevelType);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class UpdatePlayersInRoomMethod : IMatchMethod
public Response Execute(DataContext dataContext, SerializedRoomData body, GameServerConfig gameServerConfig)
{
if (body.Players == null) return BadRequest;
GameRoom room = dataContext.Match.GetOrCreateRoomByPlayer(dataContext.User!, dataContext.Platform, dataContext.Game, body.NatType == null ? NatType.Open : body.NatType[0], body.BuildVersion, body.PassedNoJoinPoint);
GameRoom room = dataContext.Match.GetOrCreateRoomByPlayer(dataContext.User!, dataContext.Platform, dataContext.Game, body.NatType == null ? NatType.Open : body.NatType[0], body.PassedNoJoinPoint);

foreach (string playerUsername in body.Players)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class UpdateRoomDataMethod : IMatchMethod

public Response Execute(DataContext dataContext, SerializedRoomData body, GameServerConfig gameServerConfig)
{
GameRoom room = dataContext.Match.GetOrCreateRoomByPlayer(dataContext.User!, dataContext.Platform, dataContext.Game, body.NatType == null ? NatType.Open : body.NatType[0], body.BuildVersion, body.PassedNoJoinPoint);
GameRoom room = dataContext.Match.GetOrCreateRoomByPlayer(dataContext.User!, dataContext.Platform, dataContext.Game, body.NatType == null ? NatType.Open : body.NatType[0], body.PassedNoJoinPoint);
if (room.HostId.Id != dataContext.User!.UserId) return Unauthorized;

if (body.RoomState != null) room.RoomState = body.RoomState.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,30 +149,28 @@ public IEnumerable<GameRoom> GetRoomsByGameAndPlatform(TokenGame game, TokenPlat
}

/// <inheritdoc/>
public GameRoom? GetRoomByUserUuid(ObjectId uuid, TokenPlatform? platform = null, TokenGame? game = null, int? buildVersion = null)
public GameRoom? GetRoomByUserUuid(ObjectId uuid, TokenPlatform? platform = null, TokenGame? game = null)
{
lock (this._rooms)
{
this.RemoveExpiredRooms();
return this._rooms.FirstOrDefault(r =>
r.PlayerIds.Any(p => p.Id == uuid) &&
(platform == null || r.Platform == platform) &&
(game == null || r.Game == game) &&
(buildVersion == null || r.BuildVersion == buildVersion));
(game == null || r.Game == game));
}
}

/// <inheritdoc/>
public GameRoom? GetRoomByUsername(string username, TokenPlatform? platform = null, TokenGame? game = null, int? buildVersion = null)
public GameRoom? GetRoomByUsername(string username, TokenPlatform? platform = null, TokenGame? game = null)
{
lock (this._rooms)
{
this.RemoveExpiredRooms();
return this._rooms.FirstOrDefault(r =>
r.PlayerIds.Any(p => p.Username == username) &&
(platform == null || r.Platform == platform) &&
(game == null || r.Game == game) &&
(buildVersion == null || r.BuildVersion == buildVersion));
(game == null || r.Game == game));
}
}
}
4 changes: 2 additions & 2 deletions Refresh.GameServer/Types/Matching/SerializedRoomData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public class SerializedRoomData
[JsonProperty("Language")]
public byte? Language { get; set; }

[JsonProperty("BuildVersion")]
public int? BuildVersion { get; set; }
// [JsonProperty("BuildVersion")]
// public int? BuildVersion { get; set; }

[JsonProperty("Search")]
public string? Search { get; set; }
Expand Down
Loading