Skip to content
Open
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
20 changes: 20 additions & 0 deletions GenOnlineService/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2029,9 +2029,24 @@ public class TURNResponse
public static class S3CredentialManager
{
private static AmazonS3Client m_s3client = null;
private static bool s_uploadsEnabled = false;

public static void Initialize()
{
if (Program.g_Config == null)
{
throw new Exception("Config not loaded");
}

s_uploadsEnabled = Program.g_Config.GetSection("MatchData").GetValue<bool?>("upload_match_data") ?? false;

// When uploads are disabled, the S3 settings are intentionally optional.
if (!s_uploadsEnabled)
{
Console.WriteLine("MatchData: upload_match_data is false, replay and screenshot uploads are disabled.");
return;
}

GetS3Config(out int TTL, out string access_key, out string secret_key, out string bucket_name, out string client_endpoint);

var config = new AmazonS3Config
Expand Down Expand Up @@ -2103,6 +2118,11 @@ private static void GetS3Config(out int TTL, out string access_key, out string s

public static async Task<string?> GetPresignedURL(EMetadataFileType fileType, EScreenshotType screenshotTypeIfScreenshot, UInt64 matchID, Int64 userID, int slotIndex, DateTime matchStartTime)
{
if (!s_uploadsEnabled || m_s3client == null)
{
return null;
}

GetS3Config(out int TTL, out string access_key, out string secret_key, out string bucket_name, out string client_endpoint);
TimeSpan expiresIn = TimeSpan.FromMinutes(TTL);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,10 @@ public async Task<APIResult> Post_InternalHandler(string jsonData, string ipAddr
}

// full login (known clients)
if (Enum.TryParse(typeof(KnownClients.EKnownClients), clientID, ignoreCase: true, out object knownClientIDObj))
// Enum.TryParse also accepts "unknown" and arbitrary numeric strings, neither of which is mapped.
if (Enum.TryParse(clientID, ignoreCase: true, out KnownClients.EKnownClients knownClientID)
&& KnownClients.KnownClientSessionTypes.TryGetValue(knownClientID, out EUserSessionType sessionType))
{
KnownClients.EKnownClients knownClientID = (KnownClients.EKnownClients)knownClientIDObj;
EUserSessionType sessionType = KnownClients.KnownClientSessionTypes[knownClientID];

// Game clients should register the user device
if (sessionType == EUserSessionType.GameClient)
{
Expand Down
4 changes: 2 additions & 2 deletions GenOnlineService/Controllers/Lobby/LobbyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ public async Task<APIResult> Delete(Int64 lobbyID)
DailyStatsManager.RegisterOutcome(army, won);

// give them back signed URLs they need
result.screenshot_url = await S3CredentialManager.GetPresignedURL(EMetadataFileType.FILE_TYPE_SCREENSHOT, EScreenshotType.SCREENSHOT_TYPE_SCORESCREEN, match_id, user_id, slotIndexInLobby, LobbyCreationTime);
result.replay_url = await S3CredentialManager.GetPresignedURL(EMetadataFileType.FILE_TYPE_REPLAY, EScreenshotType.NONE, match_id, user_id, slotIndexInLobby, LobbyCreationTime);
result.screenshot_url = await S3CredentialManager.GetPresignedURL(EMetadataFileType.FILE_TYPE_SCREENSHOT, EScreenshotType.SCREENSHOT_TYPE_SCORESCREEN, match_id, user_id, slotIndexInLobby, LobbyCreationTime) ?? String.Empty;
result.replay_url = await S3CredentialManager.GetPresignedURL(EMetadataFileType.FILE_TYPE_REPLAY, EScreenshotType.NONE, match_id, user_id, slotIndexInLobby, LobbyCreationTime) ?? String.Empty;

// store in DB
await using var db = await _dbFactory.CreateDbContextAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ private async Task ProcessWSMessage(UserWebSocketInstance sourceWS, UserSession
// response
WebSocketMessage_StartMatch startCommand = new WebSocketMessage_StartMatch();
startCommand.msg_id = (int)EWebSocketMessageID.START_GAME;
startCommand.screenshot_url = await S3CredentialManager.GetPresignedURL(EMetadataFileType.FILE_TYPE_SCREENSHOT, EScreenshotType.SCREENSHOT_TYPE_LOADSCREEN, lobbyInfo.MatchID, lobbyMember.UserID, lobbyMember.SlotIndex, lobbyInfo.TimeCreated);
startCommand.screenshot_url = await S3CredentialManager.GetPresignedURL(EMetadataFileType.FILE_TYPE_SCREENSHOT, EScreenshotType.SCREENSHOT_TYPE_LOADSCREEN, lobbyInfo.MatchID, lobbyMember.UserID, lobbyMember.SlotIndex, lobbyInfo.TimeCreated) ?? String.Empty;

// Serialize once before broadcasting
byte[] bytesJSON = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(startCommand));
Expand Down
Loading