Skip to content

Commit b3719f1

Browse files
author
Paul Gilmore
authored
* Automated pf-main build from Jenkins * PlayFab/SDKGenerator@a549733 * Automated pf-main build from Jenkins * Automated build from Jenkins * Automated build from Jenkins * Automated pf-main build from Jenkins * PlayFab/SDKGenerator@5789b15 * Automated build from Jenkins * PlayFab/SDKGenerator@d4bf0dd * Automated build from Jenkins * Automated pf-main build from Jenkins * PlayFab/SDKGenerator@9c61ecd * PlayFab/SDKGenerator@db13b86 * Automated pf-main build from Jenkins * Automated pf-main build from Jenkins * Automated pf-main build from Jenkins
1 parent 27f82f7 commit b3719f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1126
-134
lines changed

PlayFabClientSample/Assets/PlayFabSDK/Internal/PlayFabWww.cs

+70-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
using System.Collections.Generic;
44
using System.Net;
55
using System.Text;
6+
#if !UNITY_WSA && !UNITY_WP8
7+
using System.IO;
8+
using Ionic.Zlib;
9+
#endif
610

711
namespace PlayFab.Internal
812
{
@@ -28,20 +32,40 @@ private IEnumerator MakeRequestViaUnity(CallRequestContainer requestContainer)
2832
{
2933
_pendingWwwMessages += 1;
3034
string fullUrl = PlayFabSettings.GetFullUrl(requestContainer.UrlPath);
31-
byte[] bData = Encoding.UTF8.GetBytes(requestContainer.Data);
35+
byte[] payload = Encoding.UTF8.GetBytes(requestContainer.Data);
3236

3337
#if UNITY_4_4 || UNITY_4_3 || UNITY_4_2 || UNITY_4_2 || UNITY_4_0 || UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
3438
// Using hashtable for compatibility with Unity < 4.5
3539
Hashtable headers = new Hashtable ();
3640
#else
3741
Dictionary<string, string> headers = new Dictionary<string, string>();
3842
#endif
43+
44+
#if !UNITY_WSA && !UNITY_WP8
45+
if (PlayFabSettings.CompressApiData)
46+
{
47+
headers.Add("Content-Encoding", "GZIP");
48+
headers.Add("Accept-Encoding", "GZIP");
49+
50+
using (var stream = new MemoryStream())
51+
{
52+
using (
53+
GZipStream zipstream = new GZipStream(stream, CompressionMode.Compress,
54+
CompressionLevel.BestCompression))
55+
{
56+
zipstream.Write(payload, 0, payload.Length);
57+
}
58+
payload = stream.ToArray();
59+
}
60+
}
61+
#endif
62+
3963
headers.Add("Content-Type", "application/json");
4064
if (requestContainer.AuthType != null)
4165
headers.Add(requestContainer.AuthType, requestContainer.AuthKey);
4266
headers.Add("X-ReportErrorAsSuccess", "true");
4367
headers.Add("X-PlayFabSDK", PlayFabSettings.VersionString);
44-
WWW www = new WWW(fullUrl, bData, headers);
68+
WWW www = new WWW(fullUrl, payload, headers);
4569

4670
PlayFabSettings.InvokeRequest(requestContainer.UrlPath, requestContainer.CallId, requestContainer.Request, requestContainer.CustomData);
4771

@@ -50,9 +74,52 @@ private IEnumerator MakeRequestViaUnity(CallRequestContainer requestContainer)
5074
requestContainer.ResultStr = null;
5175
requestContainer.Error = null;
5276
if (!string.IsNullOrEmpty(www.error))
77+
{
5378
requestContainer.Error = PlayFabHttp.GeneratePfError(HttpStatusCode.ServiceUnavailable, PlayFabErrorCode.ServiceUnavailable, www.error);
79+
}
5480
else
55-
requestContainer.ResultStr = www.text;
81+
{
82+
string finalWwwText = "";
83+
84+
#if !UNITY_WSA && !UNITY_WP8
85+
if (PlayFabSettings.CompressApiData)
86+
{
87+
try
88+
{
89+
var stream = new MemoryStream(www.bytes);
90+
using (var gZipStream = new GZipStream(stream, CompressionMode.Decompress, false))
91+
{
92+
var buffer = new byte[4096];
93+
using (var output = new MemoryStream())
94+
{
95+
var read = 0;
96+
while ((read = gZipStream.Read(buffer, 0, buffer.Length)) > 0)
97+
{
98+
output.Write(buffer, 0, read);
99+
}
100+
output.Seek(0, SeekOrigin.Begin);
101+
var streamReader = new System.IO.StreamReader(output);
102+
finalWwwText = streamReader.ReadToEnd();
103+
}
104+
}
105+
}
106+
catch
107+
{
108+
// if this was not a valid GZip response, then send the message back as text to the call back.
109+
requestContainer.Error = PlayFabHttp.GeneratePfError(HttpStatusCode.PreconditionFailed, PlayFabErrorCode.Unknown, www.text);
110+
finalWwwText = www.text;
111+
}
112+
}
113+
else
114+
{
115+
#endif
116+
finalWwwText = www.text;
117+
#if !UNITY_WSA && !UNITY_WP8
118+
}
119+
#endif
120+
121+
requestContainer.ResultStr = finalWwwText;
122+
}
56123

57124
requestContainer.InvokeCallback();
58125

PlayFabClientSample/Assets/PlayFabSDK/Internal/SimpleJson.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,11 @@ static bool SerializeValue(IJsonSerializerStrategy jsonSerializerStrategy, objec
10481048
IDictionary<string, object> dict = value as IDictionary<string, object>;
10491049
Type type = value.GetType();
10501050
Type[] genArgs = ReflectionUtils.GetGenericTypeArguments(type);
1051+
#if NETFX_CORE
1052+
var isStringKeyDictionary = type.GetTypeInfo().IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<,>) && genArgs[0] == typeof(string);
1053+
#else
10511054
var isStringKeyDictionary = type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<,>) && genArgs[0] == typeof(string);
1055+
#endif
10521056
if (isStringKeyDictionary)
10531057
{
10541058
var strDictValue = value as IDictionary;
@@ -1437,7 +1441,11 @@ public virtual object DeserializeObject(object value, Type type)
14371441
if (nullableType != null && PlayFabSimpleJson.NumberTypes.IndexOf(nullableType) != -1)
14381442
type = nullableType; // Just use the regular type for the conversion
14391443
bool isNumberType = PlayFabSimpleJson.NumberTypes.IndexOf(type) != -1;
1440-
bool isEnumType = type.IsEnum;
1444+
#if NETFX_CORE
1445+
bool isEnumType = type.GetTypeInfo().IsEnum;
1446+
#else
1447+
bool isEnumType = type.IsEnum; //type.GetType;
1448+
#endif
14411449
if ((valueIsLong && type == typeof(long)) || (valueIsUlong && type == typeof(ulong)) || (valueIsDouble && type == typeof(double)))
14421450
return value;
14431451
if ((valueIsLong || valueIsUlong || valueIsDouble) && isEnumType)

PlayFabClientSample/Assets/PlayFabSDK/Internal/Testing/JsonUnitTests.cs

+11
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,17 @@ public void ArrayAsObject(UUnitTestContext testContext)
253253

254254
testContext.EndTest(UUnitFinishState.PASSED, null);
255255
}
256+
257+
[UUnitTest]
258+
public void TimeSpanJson(UUnitTestContext testContext)
259+
{
260+
TimeSpan span = TimeSpan.FromSeconds(5);
261+
string actualJson = JsonWrapper.SerializeObject(span, PlayFabUtil.ApiSerializerStrategy);
262+
string expectedJson = "5";
263+
testContext.StringEquals(expectedJson, actualJson, actualJson);
264+
265+
testContext.EndTest(UUnitFinishState.PASSED, null);
266+
}
256267
}
257268
}
258269

PlayFabClientSample/Assets/PlayFabSDK/Internal/Util.cs

+11
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ public override object DeserializeObject(object value, Type type)
8383
if (result)
8484
return output;
8585
}
86+
else if (type == typeof(TimeSpan))
87+
{
88+
double seconds;
89+
if (double.TryParse(valueStr, out seconds))
90+
return TimeSpan.FromSeconds(seconds);
91+
}
8692
return base.DeserializeObject(value, type);
8793
}
8894

@@ -110,6 +116,11 @@ protected override bool TrySerializeKnownTypes(object input, out object output)
110116
output = ((DateTimeOffset)input).ToString(_defaultDateTimeFormats[DEFAULT_UTC_OUTPUT_INDEX], CultureInfo.CurrentCulture);
111117
return true;
112118
}
119+
else if (input is TimeSpan)
120+
{
121+
output = ((TimeSpan)input).TotalSeconds;
122+
return true;
123+
}
113124
return base.TrySerializeKnownTypes(input, out output);
114125
}
115126
}

PlayFabClientSample/Assets/PlayFabSDK/Ionic.Zlib/CRC32.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if !UNITY_WSA && !UNITY_WP8
12
// CRC32.cs
23
// ------------------------------------------------------------------
34
//
@@ -811,4 +812,5 @@ public override void Close()
811812

812813
}
813814

814-
}
815+
}
816+
#endif

PlayFabClientSample/Assets/PlayFabSDK/Ionic.Zlib/Deflate.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if !UNITY_WSA && !UNITY_WP8
12
// Deflate.cs
23
// ------------------------------------------------------------------
34
//
@@ -1876,4 +1877,5 @@ internal int Deflate(FlushType flush)
18761877
}
18771878

18781879
}
1879-
}
1880+
}
1881+
#endif

PlayFabClientSample/Assets/PlayFabSDK/Ionic.Zlib/DeflateStream.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if !UNITY_WSA && !UNITY_WP8
12
// DeflateStream.cs
23
// ------------------------------------------------------------------
34
//
@@ -310,7 +311,7 @@ public DeflateStream(System.IO.Stream stream, CompressionMode mode, CompressionL
310311
_baseStream = new ZlibBaseStream(stream, mode, level, ZlibStreamFlavor.DEFLATE, leaveOpen);
311312
}
312313

313-
#region Zlib properties
314+
#region Zlib properties
314315

315316
/// <summary>
316317
/// This property sets the flush behavior on the stream.
@@ -400,9 +401,9 @@ virtual public long TotalOut
400401
}
401402
}
402403

403-
#endregion
404+
#endregion
404405

405-
#region System.IO.Stream methods
406+
#region System.IO.Stream methods
406407
/// <summary>
407408
/// Dispose the stream.
408409
/// </summary>
@@ -616,7 +617,7 @@ public override void Write(byte[] buffer, int offset, int count)
616617
if (_disposed) throw new ObjectDisposedException("DeflateStream");
617618
_baseStream.Write(buffer, offset, count);
618619
}
619-
#endregion
620+
#endregion
620621

621622

622623

@@ -737,4 +738,4 @@ public static byte[] UncompressBuffer(byte[] compressed)
737738
}
738739

739740
}
740-
741+
#endif

PlayFabClientSample/Assets/PlayFabSDK/Ionic.Zlib/GZipStream.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if !UNITY_WSA && !UNITY_WP8
12
// GZipStream.cs
23
// ------------------------------------------------------------------
34
//
@@ -539,7 +540,7 @@ public GZipStream(Stream stream, CompressionMode mode, CompressionLevel level, b
539540
_baseStream = new ZlibBaseStream(stream, mode, level, ZlibStreamFlavor.GZIP, leaveOpen);
540541
}
541542

542-
#region Zlib properties
543+
#region Zlib properties
543544

544545
/// <summary>
545546
/// This property sets the flush behavior on the stream.
@@ -606,9 +607,9 @@ virtual public long TotalOut
606607
}
607608
}
608609

609-
#endregion
610+
#endregion
610611

611-
#region Stream methods
612+
#region Stream methods
612613

613614
/// <summary>
614615
/// Dispose the stream.
@@ -849,7 +850,7 @@ public override void Write(byte[] buffer, int offset, int count)
849850

850851
_baseStream.Write(buffer, offset, count);
851852
}
852-
#endregion
853+
#endregion
853854

854855

855856
internal static readonly System.DateTime _unixEpoch = new System.DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
@@ -1027,3 +1028,4 @@ public static byte[] UncompressBuffer(byte[] compressed)
10271028

10281029
}
10291030
}
1031+
#endif

PlayFabClientSample/Assets/PlayFabSDK/Ionic.Zlib/InfTree.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if !UNITY_WSA && !UNITY_WP8
12
// Inftree.cs
23
// ------------------------------------------------------------------
34
//
@@ -433,4 +434,5 @@ private void initWorkArea(int vsize)
433434
}
434435
}
435436
}
436-
}
437+
}
438+
#endif

PlayFabClientSample/Assets/PlayFabSDK/Ionic.Zlib/Inflate.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if !UNITY_WSA && !UNITY_WP8
12
// Inflate.cs
23
// ------------------------------------------------------------------
34
//
@@ -1793,4 +1794,5 @@ internal int SyncPoint(ZlibCodec z)
17931794
return blocks.SyncPoint();
17941795
}
17951796
}
1796-
}
1797+
}
1798+
#endif

PlayFabClientSample/Assets/PlayFabSDK/Ionic.Zlib/ParallelDeflateOutputStream.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if !UNITY_WSA && !UNITY_WP8
12
//#define Trace
23

34
// ParallelDeflateOutputStream.cs
@@ -1381,5 +1382,4 @@ public override void SetLength(long value)
13811382
}
13821383

13831384
}
1384-
1385-
1385+
#endif

PlayFabClientSample/Assets/PlayFabSDK/Ionic.Zlib/ZTree.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if !UNITY_WSA && !UNITY_WP8
12
// Tree.cs
23
// ------------------------------------------------------------------
34
//
@@ -420,4 +421,5 @@ internal static int bi_reverse(int code, int len)
420421
return res >> 1;
421422
}
422423
}
423-
}
424+
}
425+
#endif

PlayFabClientSample/Assets/PlayFabSDK/Ionic.Zlib/Zlib.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if !UNITY_WSA && !UNITY_WP8
12
// Zlib.cs
23
// ------------------------------------------------------------------
34
//
@@ -543,4 +544,5 @@ public static uint Adler32(uint adler, byte[] buf, int index, int len)
543544

544545
}
545546

546-
}
547+
}
548+
#endif

PlayFabClientSample/Assets/PlayFabSDK/Ionic.Zlib/ZlibBaseStream.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if !UNITY_WSA && !UNITY_WP8
12
// ZlibBaseStream.cs
23
// ------------------------------------------------------------------
34
//
@@ -625,3 +626,4 @@ public static byte[] UncompressBuffer(byte[] compressed, Stream decompressor)
625626

626627

627628
}
629+
#endif

PlayFabClientSample/Assets/PlayFabSDK/Ionic.Zlib/ZlibCodec.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if !UNITY_WSA && !UNITY_WP8
12
// ZlibCodec.cs
23
// ------------------------------------------------------------------
34
//
@@ -81,7 +82,7 @@ namespace Ionic.Zlib
8182
/// </remarks>
8283
[Interop.GuidAttribute("ebc25cf6-9120-4283-b972-0e5520d0000D")]
8384
[Interop.ComVisible(true)]
84-
#if !NETCF
85+
#if !NETCF
8586
[Interop.ClassInterface(Interop.ClassInterfaceType.AutoDispatch)]
8687
#endif
8788
sealed public class ZlibCodec
@@ -714,4 +715,5 @@ internal int read_buf(byte[] buf, int start, int size)
714715
}
715716

716717
}
717-
}
718+
}
719+
#endif

0 commit comments

Comments
 (0)