针对unity版本比赛功能的调整

This commit is contained in:
suntao committed 2021-07-07 09:49:36 +08:00
1 parent b9bb485a2d
commit c380654041
10 files changed
+393 -74

No files matched your search

+39
View File
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Security.Cryptography;
using System.Text;
using TurfCS;
@@ -23,5 +25,42 @@ namespace OnlineUserPool.Unility
new RNGCryptoServiceProvider().GetBytes(randomNumberBuffer);
return new Random(BitConverter.ToInt32(randomNumberBuffer, 0)).Next(min, max);
}
public static byte[] Compress(string text)
{
var bytes = Encoding.UTF8.GetBytes(text);
return Compress(bytes);
}
public static byte[] Compress(byte[] bytes)
{
//var bytes = Encoding.Unicode.GetBytes(text);
using (var mso = new MemoryStream())
{
using (var gs = new GZipStream(mso, CompressionMode.Compress))
{
gs.Write(bytes, 0, bytes.Length);
}
return mso.ToArray();
}
}
public static string Decompress(byte[] data)
{
// Read the last 4 bytes to get the length
byte[] lengthBuffer = new byte[4];
Array.Copy(data, data.Length - 4, lengthBuffer, 0, 4);
int uncompressedSize = BitConverter.ToInt32(lengthBuffer, 0);
var buffer = new byte[uncompressedSize];
using (var ms = new MemoryStream(data))
{
using (var gzip = new GZipStream(ms, CompressionMode.Decompress))
{
gzip.Read(buffer, 0, uncompressedSize);
}
}
return Encoding.UTF8.GetString(buffer);
}
}
}