mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交Unity 联机Pro
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace BestHTTP.Forms
|
||||
{
|
||||
/// <summary>
|
||||
/// This class represents a HTTP Form's field.
|
||||
/// </summary>
|
||||
public class HTTPFieldData
|
||||
{
|
||||
/// <summary>
|
||||
/// The form's field.
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Filename of the field. Optional.
|
||||
/// </summary>
|
||||
public string FileName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Mime-type of the field. Optional
|
||||
/// </summary>
|
||||
public string MimeType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Encoding of the data. Optional
|
||||
/// </summary>
|
||||
public Encoding Encoding { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The field's textual data.
|
||||
/// </summary>
|
||||
public string Text { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The field's binary data.
|
||||
/// </summary>
|
||||
public byte[] Binary { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Will return with the binary data, or if it's not present the textual data will be decoded to binary.
|
||||
/// </summary>
|
||||
public byte[] Payload
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Binary != null)
|
||||
return Binary;
|
||||
|
||||
if (Encoding == null)
|
||||
Encoding = Encoding.UTF8;
|
||||
|
||||
return Binary = Encoding.GetBytes(Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bdf9d0d59653fa8418a86f22360ff91e
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
141
JNFrame2/Assets/Plugins/Best HTTP/Source/Forms/HTTPFormBase.cs
Normal file
141
JNFrame2/Assets/Plugins/Best HTTP/Source/Forms/HTTPFormBase.cs
Normal file
@@ -0,0 +1,141 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace BestHTTP.Forms
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class of a concrete implementation. Don't use it to create a form, use instead one of the already wrote implementation(HTTPMultiPartForm, HTTPUrlEncodedForm), or create a new one by inheriting from this base class.
|
||||
/// </summary>
|
||||
public class HTTPFormBase
|
||||
{
|
||||
const int LongLength = 256;
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// A list that holds the form's fields.
|
||||
/// </summary>
|
||||
public List<HTTPFieldData> Fields { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the Fields has no element.
|
||||
/// </summary>
|
||||
public bool IsEmpty { get { return Fields == null || Fields.Count == 0; } }
|
||||
|
||||
/// <summary>
|
||||
/// True if new fields has been added to our list.
|
||||
/// </summary>
|
||||
public bool IsChanged { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// True if there are at least one form-field with binary data.
|
||||
/// </summary>
|
||||
public bool HasBinary { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// True if there are at least one form-field with a long textual data.
|
||||
/// </summary>
|
||||
public bool HasLongValue { get; protected set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Field Management
|
||||
|
||||
public void AddBinaryData(string fieldName, byte[] content)
|
||||
{
|
||||
AddBinaryData(fieldName, content, null, null);
|
||||
}
|
||||
|
||||
public void AddBinaryData(string fieldName, byte[] content, string fileName)
|
||||
{
|
||||
AddBinaryData(fieldName, content, fileName, null);
|
||||
}
|
||||
|
||||
public void AddBinaryData(string fieldName, byte[] content, string fileName, string mimeType)
|
||||
{
|
||||
if (Fields == null)
|
||||
Fields = new List<HTTPFieldData>();
|
||||
|
||||
HTTPFieldData field = new HTTPFieldData();
|
||||
field.Name = fieldName;
|
||||
|
||||
if (fileName == null)
|
||||
field.FileName = fieldName + ".dat";
|
||||
else
|
||||
field.FileName = fileName;
|
||||
|
||||
if (mimeType == null)
|
||||
field.MimeType = "application/octet-stream";
|
||||
else
|
||||
field.MimeType = mimeType;
|
||||
|
||||
field.Binary = content;
|
||||
|
||||
Fields.Add(field);
|
||||
|
||||
HasBinary = IsChanged = true;
|
||||
}
|
||||
|
||||
public void AddField(string fieldName, string value)
|
||||
{
|
||||
AddField(fieldName, value, System.Text.Encoding.UTF8);
|
||||
}
|
||||
|
||||
public void AddField(string fieldName, string value, System.Text.Encoding e)
|
||||
{
|
||||
if (Fields == null)
|
||||
Fields = new List<HTTPFieldData>();
|
||||
|
||||
HTTPFieldData field = new HTTPFieldData();
|
||||
field.Name = fieldName;
|
||||
field.FileName = null;
|
||||
if (e != null)
|
||||
field.MimeType = "text/plain; charset=" + e.WebName;
|
||||
field.Text = value;
|
||||
field.Encoding = e;
|
||||
|
||||
Fields.Add(field);
|
||||
|
||||
IsChanged = true;
|
||||
|
||||
HasLongValue |= value.Length > LongLength;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Virtual Functions
|
||||
|
||||
/// <summary>
|
||||
/// It should 'clone' all the data from the given HTTPFormBase object.
|
||||
/// Called after the form-implementation created.
|
||||
/// </summary>
|
||||
public virtual void CopyFrom(HTTPFormBase fields)
|
||||
{
|
||||
this.Fields = new List<HTTPFieldData>(fields.Fields);
|
||||
this.IsChanged = true;
|
||||
|
||||
this.HasBinary = fields.HasBinary;
|
||||
this.HasLongValue = fields.HasLongValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prepares the request to sending a form. It should set only the headers.
|
||||
/// </summary>
|
||||
public virtual void PrepareRequest(HTTPRequest request)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prepares and returns with the form's raw data.
|
||||
/// </summary>
|
||||
public virtual byte[] GetData()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d275ec92441f18449bffc98e08d44e8
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace BestHTTP.Forms
|
||||
{
|
||||
public enum HTTPFormUsage
|
||||
{
|
||||
/// <summary>
|
||||
/// The plugin will try to choose the best form sending method.
|
||||
/// </summary>
|
||||
Automatic,
|
||||
|
||||
/// <summary>
|
||||
/// The plugin will use the Url-Encoded form sending.
|
||||
/// </summary>
|
||||
UrlEncoded,
|
||||
|
||||
/// <summary>
|
||||
/// The plugin will use the Multipart form sending.
|
||||
/// </summary>
|
||||
Multipart
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc8643409dcf53d4db0bf0f654ad8500
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: acc326f47252d77498d6489dce7ff997
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,78 @@
|
||||
using BestHTTP.Extensions;
|
||||
|
||||
namespace BestHTTP.Forms
|
||||
{
|
||||
/// <summary>
|
||||
/// A HTTP Form implementation to send textual and binary values.
|
||||
/// </summary>
|
||||
public sealed class HTTPMultiPartForm : HTTPFormBase
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
/// <summary>
|
||||
/// A random boundary generated in the constructor.
|
||||
/// </summary>
|
||||
private string Boundary;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private byte[] CachedData;
|
||||
|
||||
#endregion
|
||||
|
||||
public HTTPMultiPartForm()
|
||||
{
|
||||
this.Boundary = "BestHTTP_HTTPMultiPartForm_" + this.GetHashCode().ToString("X");
|
||||
}
|
||||
|
||||
#region IHTTPForm Implementation
|
||||
|
||||
public override void PrepareRequest(HTTPRequest request)
|
||||
{
|
||||
// Set up Content-Type header for the request
|
||||
request.SetHeader("Content-Type", "multipart/form-data; boundary=" + Boundary);
|
||||
}
|
||||
|
||||
public override byte[] GetData()
|
||||
{
|
||||
if (CachedData != null)
|
||||
return CachedData;
|
||||
|
||||
using (var ms = new BufferPoolMemoryStream())
|
||||
{
|
||||
for (int i = 0; i < Fields.Count; ++i)
|
||||
{
|
||||
HTTPFieldData field = Fields[i];
|
||||
|
||||
// Set the boundary
|
||||
ms.WriteLine("--" + Boundary);
|
||||
|
||||
// Set up Content-Disposition header to our form with the name
|
||||
ms.WriteLine("Content-Disposition: form-data; name=\"" + field.Name + "\"" + (!string.IsNullOrEmpty(field.FileName) ? "; filename=\"" + field.FileName + "\"" : string.Empty));
|
||||
|
||||
// Set up Content-Type head for the form.
|
||||
if (!string.IsNullOrEmpty(field.MimeType))
|
||||
ms.WriteLine("Content-Type: " + field.MimeType);
|
||||
|
||||
ms.WriteLine();
|
||||
|
||||
// Write the actual data to the MemoryStream
|
||||
ms.Write(field.Payload, 0, field.Payload.Length);
|
||||
|
||||
ms.Write(HTTPRequest.EOL, 0, HTTPRequest.EOL.Length);
|
||||
}
|
||||
|
||||
// Write out the trailing boundary
|
||||
ms.WriteLine("--" + Boundary + "--");
|
||||
|
||||
IsChanged = false;
|
||||
|
||||
// Set the RawData of our request
|
||||
return CachedData = ms.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
};
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f9390c7b6f72b845805363b01dfbba9
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using BestHTTP.PlatformSupport.Text;
|
||||
|
||||
namespace BestHTTP.Forms
|
||||
{
|
||||
/// <summary>
|
||||
/// A HTTP Form implementation to send textual values.
|
||||
/// </summary>
|
||||
public sealed class HTTPUrlEncodedForm : HTTPFormBase
|
||||
{
|
||||
private const int EscapeTreshold = 256;
|
||||
|
||||
private byte[] CachedData;
|
||||
|
||||
public override void PrepareRequest(HTTPRequest request)
|
||||
{
|
||||
request.SetHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
}
|
||||
|
||||
public override byte[] GetData()
|
||||
{
|
||||
if (CachedData != null && !IsChanged)
|
||||
return CachedData;
|
||||
|
||||
StringBuilder sb = PlatformSupport.Text.StringBuilderPool.Get(Fields.Count * 4);
|
||||
|
||||
// Create a "field1=value1&field2=value2" formatted string
|
||||
for (int i = 0; i < Fields.Count; ++i)
|
||||
{
|
||||
var field = Fields[i];
|
||||
|
||||
if (i > 0)
|
||||
sb.Append("&");
|
||||
|
||||
sb.Append(EscapeString(field.Name));
|
||||
sb.Append("=");
|
||||
|
||||
if (!string.IsNullOrEmpty(field.Text) || field.Binary == null)
|
||||
sb.Append(EscapeString(field.Text));
|
||||
else
|
||||
// If forced to this form type with binary data, we will create a base64 encoded string from it.
|
||||
sb.Append(Convert.ToBase64String(field.Binary, 0, field.Binary.Length));
|
||||
}
|
||||
|
||||
IsChanged = false;
|
||||
return CachedData = Encoding.UTF8.GetBytes(PlatformSupport.Text.StringBuilderPool.ReleaseAndGrab(sb));
|
||||
}
|
||||
|
||||
public static string EscapeString(string originalString)
|
||||
{
|
||||
if (originalString.Length < EscapeTreshold)
|
||||
return Uri.EscapeDataString(originalString);
|
||||
else
|
||||
{
|
||||
int loops = originalString.Length / EscapeTreshold;
|
||||
StringBuilder sb = StringBuilderPool.Get(loops); //new StringBuilder(loops);
|
||||
|
||||
for (int i = 0; i <= loops; i++)
|
||||
sb.Append(i < loops ?
|
||||
Uri.EscapeDataString(originalString.Substring(EscapeTreshold * i, EscapeTreshold)) :
|
||||
Uri.EscapeDataString(originalString.Substring(EscapeTreshold * i)));
|
||||
return StringBuilderPool.ReleaseAndGrab(sb);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 023a00e6d3a980b4babe8c70a7d00088
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user