-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPollUpdaterContentHandler.cs
73 lines (68 loc) · 3.78 KB
/
PollUpdaterContentHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using PlayFab.ServerModels;
using PlayFab.Json;
using System.Collections.Generic;
using PlayFab.DataModels;
using System.Net.Http;
using Newtonsoft.Json;
using System.Net.Http.Headers;
using System.Net;
using Newtonsoft.Json;
using System.Text;
using PlayFab.Plugins.CloudScript;
using PlayFab.Samples;
using System.Text;
using SimpleJSON;
namespace PlayFab.AzureFunctions
{
public static class PollUpdaterContentHandler
{
[FunctionName("PollUpdaterContent")]
public static async Task<dynamic> PollUpdaterContent(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage req, ILogger log)
{
var context = await FunctionContext<dynamic>.Create(req);
if (context == null) return new { error = true };
var serverApi = new PlayFabServerInstanceAPI(context.ApiSettings, context.AuthenticationContext);
/* Gather JSON versions */
var titleDataResponse = await serverApi.GetTitleDataAsync(new GetTitleDataRequest { Keys = new List<string>() { "CurrentVersion" } });
var titleInternalDataResponse = await serverApi.GetTitleInternalDataAsync(new GetTitleDataRequest { Keys = new List<string>() { "Versions" } });
string newestVersionStr = titleDataResponse.Result.Data["CurrentVersion"];
if (newestVersionStr == null) return new { error = true, msg = "Incorrect 'CurrentVersion' in TitleData"};
JSONNode versions = null; // json of all versions existing in internal title data 'Versions'
JSONNode newestVersion = null; // newest version subchild of 'Version'
JSONNode currentVersion = null; // null if no exisitng version
versions = JSON.Parse(titleInternalDataResponse.Result.Data["Versions"]);
if (versions == null) return new { error = true, msg = "Incorrect 'Versions' in InternalTitleData" };
var userReadOnlyDataResponse = await serverApi.GetUserReadOnlyDataAsync(new GetUserDataRequest { PlayFabId = context.CallerEntityProfile.Lineage.MasterPlayerAccountId, Keys = new List<string>() { "Version" } });
foreach (JSONNode version in versions)
{
if (version["name"] == newestVersionStr) newestVersion = version;
if (userReadOnlyDataResponse.Result != null) if (userReadOnlyDataResponse.Result.Data != null) if (userReadOnlyDataResponse.Result.Data.ContainsKey("Version")) if (userReadOnlyDataResponse.Result.Data["Version"].Value == version["name"]) currentVersion = version;
}
if (newestVersion == null) return new { error = true, msg = "CurrentVersion '" + newestVersionStr + "' does not exist in Versions" };
if (currentVersion == null) return new { error = true, msg = "Player version not set yet" };
/* Gather filename, contentKey and name for each item in content*/
List<ReturnContent> content = new List<ReturnContent>();
for (int i = 0; i < currentVersion["content"].Count; i++)
{
content.Add(new ReturnContent
{
filename = currentVersion["content"][i]["filename"],
contentKey = currentVersion["name"] + "/" + currentVersion["content"][i]["contentKey"],
name = currentVersion["content"][i]["name"]
});
}
string cv = currentVersion["name"];
return new { currentVersion = cv, content = content };
}
}
public class ReturnContent
{
public string filename, contentKey, name;
}
}