aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Server
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-02-09 20:32:53 -0500
committerMichael <[email protected]>2017-02-09 20:32:53 -0500
commitde14574800ed21765e1ac6bba1d19b774f477c29 (patch)
treeb9d5ce4ce01e4e930e546ff23fc70a7ad32356bf /ShiftOS.Server
parentd6b2b155264e7a4b576c956530915f66d97b3eac (diff)
downloadshiftos_thereturn-de14574800ed21765e1ac6bba1d19b774f477c29.tar.gz
shiftos_thereturn-de14574800ed21765e1ac6bba1d19b774f477c29.tar.bz2
shiftos_thereturn-de14574800ed21765e1ac6bba1d19b774f477c29.zip
Compress shop items on server-side.
Diffstat (limited to 'ShiftOS.Server')
-rw-r--r--ShiftOS.Server/Program.cs41
1 files changed, 35 insertions, 6 deletions
diff --git a/ShiftOS.Server/Program.cs b/ShiftOS.Server/Program.cs
index c468503..352214d 100644
--- a/ShiftOS.Server/Program.cs
+++ b/ShiftOS.Server/Program.cs
@@ -34,6 +34,7 @@ using Newtonsoft.Json;
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography;
+using System.IO.Compression;
namespace ShiftOS.Server
{
@@ -223,11 +224,39 @@ namespace ShiftOS.Server
File.WriteAllText(fPath, Encryption.Encrypt(contents));
}
- /// <summary>
- /// Interpret the specified msg.
- /// </summary>
- /// <param name="msg">Message.</param>
- public static void Interpret(ServerMessage msg)
+ public static string Compress(string s)
+ {
+ var bytes = Encoding.Unicode.GetBytes(s);
+ using (var msi = new MemoryStream(bytes))
+ using (var mso = new MemoryStream())
+ {
+ using (var gs = new GZipStream(mso, CompressionMode.Compress))
+ {
+ msi.CopyTo(gs);
+ }
+ return Convert.ToBase64String(mso.ToArray());
+ }
+ }
+
+ public static string Decompress(string s)
+ {
+ var bytes = Convert.FromBase64String(s);
+ using (var msi = new MemoryStream(bytes))
+ using (var mso = new MemoryStream())
+ {
+ using (var gs = new GZipStream(msi, CompressionMode.Decompress))
+ {
+ gs.CopyTo(mso);
+ }
+ return Encoding.Unicode.GetString(mso.ToArray());
+ }
+ }
+
+ /// <summary>
+ /// Interpret the specified msg.
+ /// </summary>
+ /// <param name="msg">Message.</param>
+ public static void Interpret(ServerMessage msg)
{
Dictionary<string, object> args = null;
@@ -465,7 +494,7 @@ Contents:
Contents = JsonConvert.SerializeObject(new
{
shop = shopName,
- itemdata = item
+ itemdata = Compress(Compress(JsonConvert.SerializeObject(item)))
})
}));
}