Skip to content

Commit

Permalink
Merge pull request #218 from timiimit/stop-editing-attributes
Browse files Browse the repository at this point in the history
Stop editing attributes
  • Loading branch information
timiimit authored Mar 15, 2023
2 parents d8531b3 + d6dd7ec commit 17c23bf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
15 changes: 2 additions & 13 deletions UT4MasterServer.Models/Database/GameServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public class GameServer
#if DEBUG
[JsonPropertyName("UT4MS__LAST_KNOWN_MATCH_START_TIME__DEBUG_ONLY_VALUE")]
#endif
[BsonElement("LastKnownMatchStartTime")]
public DateTime LastKnownMatchStartTime { get; set; } = DateTime.UtcNow;
[BsonElement("LastKnownMatchStartTime"), BsonIgnoreIfDefault]
public DateTime LastKnownMatchStartTime { get; set; } = default;

#if DEBUG
[BsonElement("SessionAccessToken")]
Expand Down Expand Up @@ -220,12 +220,6 @@ public void Update(GameServer update)
// Update custom properties
SessionID = update.SessionID;
OwningClientID = update.OwningClientID;

var matchDuration = (int?)update.Attributes.Get("UT_MATCHDURATION_i");
if (matchDuration is not null)
{
LastKnownMatchStartTime = DateTime.UtcNow - TimeSpan.FromSeconds(matchDuration.Value);
}
}

public JsonObject ToJson(bool isResponseToClient)
Expand All @@ -234,10 +228,6 @@ public JsonObject ToJson(bool isResponseToClient)

// Do some preprocessing on attributes
var attrs = Attributes.ToJObject();
if (attrs["UT_MATCHSTATE_s"]?.ToString() == "InProgress" && attrs.ContainsKey("UT_MATCHDURATION_i"))
{
attrs["UT_MATCHDURATION_i"] = (int)(DateTime.UtcNow - LastKnownMatchStartTime).TotalSeconds;
}

// build json
var obj = new List<KeyValuePair<string, JsonNode?>>();
Expand All @@ -247,7 +237,6 @@ public JsonObject ToJson(bool isResponseToClient)
obj.Add(new("UT4MS__SESSION_ID__DEBUG_ONLY_VALUE", SessionID.ToString()));
obj.Add(new("UT4MS__SESSION_TOKEN__DEBUG_ONLY_VALUE", SessionAccessToken));
obj.Add(new("UT4MS__OWNING_CLIENT_ID__DEBUG_ONLY_VALUE", OwningClientID.ToString()));
obj.Add(new("UT4MS__LAST_KNOWN_MATCH_START_TIME__DEBUG_ONLY_VALUE", LastKnownMatchStartTime.ToStringISO()));
#endif
obj.Add(new("ownerId", OwnerID.ToString().ToUpper()));
obj.Add(new("ownerName", OwnerName));
Expand Down
2 changes: 1 addition & 1 deletion UT4MasterServer/Controllers/UT/MatchmakingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public async Task<IActionResult> CreateGameServer([FromBody] GameServer server)
throw new Exception("This should never happen");
}

var serverName = server.Attributes.Get(GameServerAttributes.UT_SERVERNAME_s) as string;
var serverName = server.Attributes.Get(GameServerAttributes.UT_SERVERNAME_s) as string ?? string.Empty;
var isRanked = (int?)server.Attributes.Get(GameServerAttributes.UT_RANKED_i) == 1;
if (trust != GameServerTrust.Epic && !isRanked && serverName.Trim() != client.Name.Trim())
{
Expand Down

0 comments on commit 17c23bf

Please sign in to comment.