初始化
This commit is contained in:
41
UnityGame/Assets/Scripts/ThirdParty/ConsolePro/Remote/LiteNetLib/Layers/Crc32cLayer.cs
vendored
Normal file
41
UnityGame/Assets/Scripts/ThirdParty/ConsolePro/Remote/LiteNetLib/Layers/Crc32cLayer.cs
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
using FlyingWormConsole3.LiteNetLib.Utils;
|
||||
using System;
|
||||
using System.Net;
|
||||
|
||||
namespace FlyingWormConsole3.LiteNetLib.Layers
|
||||
{
|
||||
public sealed class Crc32cLayer : PacketLayerBase
|
||||
{
|
||||
public Crc32cLayer() : base(CRC32C.ChecksumSize)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void ProcessInboundPacket(IPEndPoint endPoint, ref byte[] data, ref int offset, ref int length)
|
||||
{
|
||||
if (length < NetConstants.HeaderSize + CRC32C.ChecksumSize)
|
||||
{
|
||||
NetDebug.WriteError("[NM] DataReceived size: bad!");
|
||||
//Set length to 0 to have netManager drop the packet.
|
||||
length = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
int checksumPoint = length - CRC32C.ChecksumSize;
|
||||
if (CRC32C.Compute(data, offset, checksumPoint) != BitConverter.ToUInt32(data, checksumPoint))
|
||||
{
|
||||
NetDebug.Write("[NM] DataReceived checksum: bad!");
|
||||
//Set length to 0 to have netManager drop the packet.
|
||||
length = 0;
|
||||
return;
|
||||
}
|
||||
length -= CRC32C.ChecksumSize;
|
||||
}
|
||||
|
||||
public override void ProcessOutBoundPacket(IPEndPoint endPoint, ref byte[] data, ref int offset, ref int length)
|
||||
{
|
||||
FastBitConverter.GetBytes(data, length, CRC32C.Compute(data, offset, length));
|
||||
length += CRC32C.ChecksumSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
UnityGame/Assets/Scripts/ThirdParty/ConsolePro/Remote/LiteNetLib/Layers/Crc32cLayer.cs.meta
vendored
Normal file
11
UnityGame/Assets/Scripts/ThirdParty/ConsolePro/Remote/LiteNetLib/Layers/Crc32cLayer.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03f6f2696c6e848c69a6af33539c5adc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
UnityGame/Assets/Scripts/ThirdParty/ConsolePro/Remote/LiteNetLib/Layers/PacketLayerBase.cs
vendored
Normal file
17
UnityGame/Assets/Scripts/ThirdParty/ConsolePro/Remote/LiteNetLib/Layers/PacketLayerBase.cs
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Net;
|
||||
|
||||
namespace FlyingWormConsole3.LiteNetLib.Layers
|
||||
{
|
||||
public abstract class PacketLayerBase
|
||||
{
|
||||
public readonly int ExtraPacketSizeForLayer;
|
||||
|
||||
protected PacketLayerBase(int extraPacketSizeForLayer)
|
||||
{
|
||||
ExtraPacketSizeForLayer = extraPacketSizeForLayer;
|
||||
}
|
||||
|
||||
public abstract void ProcessInboundPacket(IPEndPoint endPoint, ref byte[] data, ref int offset, ref int length);
|
||||
public abstract void ProcessOutBoundPacket(IPEndPoint endPoint, ref byte[] data, ref int offset, ref int length);
|
||||
}
|
||||
}
|
||||
11
UnityGame/Assets/Scripts/ThirdParty/ConsolePro/Remote/LiteNetLib/Layers/PacketLayerBase.cs.meta
vendored
Normal file
11
UnityGame/Assets/Scripts/ThirdParty/ConsolePro/Remote/LiteNetLib/Layers/PacketLayerBase.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 20d4d1cdad986436a8f2f4fcc8e3e47d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
60
UnityGame/Assets/Scripts/ThirdParty/ConsolePro/Remote/LiteNetLib/Layers/XorEncryptLayer.cs
vendored
Normal file
60
UnityGame/Assets/Scripts/ThirdParty/ConsolePro/Remote/LiteNetLib/Layers/XorEncryptLayer.cs
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
namespace FlyingWormConsole3.LiteNetLib.Layers
|
||||
{
|
||||
public class XorEncryptLayer : PacketLayerBase
|
||||
{
|
||||
private byte[] _byteKey;
|
||||
|
||||
public XorEncryptLayer() : base(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public XorEncryptLayer(byte[] key) : this()
|
||||
{
|
||||
SetKey(key);
|
||||
}
|
||||
|
||||
public XorEncryptLayer(string key) : this()
|
||||
{
|
||||
SetKey(key);
|
||||
}
|
||||
|
||||
public void SetKey(string key)
|
||||
{
|
||||
_byteKey = Encoding.UTF8.GetBytes(key);
|
||||
}
|
||||
|
||||
public void SetKey(byte[] key)
|
||||
{
|
||||
if (_byteKey == null || _byteKey.Length != key.Length)
|
||||
_byteKey = new byte[key.Length];
|
||||
Buffer.BlockCopy(key, 0, _byteKey, 0, key.Length);
|
||||
}
|
||||
|
||||
public override void ProcessInboundPacket(IPEndPoint endPoint, ref byte[] data, ref int offset, ref int length)
|
||||
{
|
||||
if (_byteKey == null)
|
||||
return;
|
||||
var cur = offset;
|
||||
for (var i = 0; i < length; i++, cur++)
|
||||
{
|
||||
data[cur] = (byte)(data[cur] ^ _byteKey[i % _byteKey.Length]);
|
||||
}
|
||||
}
|
||||
|
||||
public override void ProcessOutBoundPacket(IPEndPoint endPoint, ref byte[] data, ref int offset, ref int length)
|
||||
{
|
||||
if (_byteKey == null)
|
||||
return;
|
||||
var cur = offset;
|
||||
for (var i = 0; i < length; i++, cur++)
|
||||
{
|
||||
data[cur] = (byte)(data[cur] ^ _byteKey[i % _byteKey.Length]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
UnityGame/Assets/Scripts/ThirdParty/ConsolePro/Remote/LiteNetLib/Layers/XorEncryptLayer.cs.meta
vendored
Normal file
11
UnityGame/Assets/Scripts/ThirdParty/ConsolePro/Remote/LiteNetLib/Layers/XorEncryptLayer.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ee39ab3e39a742f59665fde4e2c4f27
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user