备份CatanBuilding瘦身独立工程

This commit is contained in:
JSD\13999
2026-05-26 16:15:54 +08:00
commit 2d0e6a61b7
12001 changed files with 2431925 additions and 0 deletions

View File

@@ -0,0 +1,108 @@
using System;
using System.IO;
using System.Collections.Generic;
namespace com.fpnn.proto
{
public class Answer : Message
{
private static readonly byte[] FPNNBasicAnswerHeader = { 0x46, 0x50, 0x4e, 0x4e, 0x1, 0x80, 0x2 };
private static readonly byte[] fakePayloadLength = { 0, 0, 0, 0 };
private bool errorAnswer;
private UInt32 seqNum;
public Answer(Quest quest): this(quest.SeqNum())
{
}
public Answer(UInt32 seqNum)
{
errorAnswer = false;
this.seqNum = seqNum;
}
public Answer(UInt32 seqNum, bool error, Dictionary<object, object> payload)
: base(payload)
{
errorAnswer = error;
this.seqNum = seqNum;
}
public UInt32 SeqNum()
{
return seqNum;
}
public bool IsException()
{
return errorAnswer;
}
public int ErrorCode()
{
return (int)Get("code", 0);
}
public string Ex()
{
return (string)Get("ex", "");
}
public void FillErrorCode(int code)
{
errorAnswer = true;
Param("code", code);
}
public void FillErrorInfo(int code, string ex)
{
errorAnswer = true;
Param("code", code);
Param("ex", ex);
}
private void BuildFPNNPackage(Stream stream)
{
stream.Write(FPNNBasicAnswerHeader, 0, 7);
if (errorAnswer)
stream.WriteByte(0x1);
else
stream.WriteByte(0x0);
//-- payload size
stream.Write(fakePayloadLength, 0, 4);
//-- seq num
byte[] seqBuffer = BitConverter.GetBytes(seqNum);
if (BitConverter.IsLittleEndian == false)
Array.Reverse(seqBuffer);
stream.Write(seqBuffer, 0, 4);
}
new public byte[] Raw()
{
byte[] rawData;
using (MemoryStream stream = new MemoryStream())
{
BuildFPNNPackage(stream);
base.Raw(stream);
rawData = stream.ToArray();
}
Int32 payloadLength = rawData.Length - 16; //-- 16: Answer heander length.
byte[] payloadLengthBuffer = BitConverter.GetBytes(payloadLength);
if (BitConverter.IsLittleEndian == false)
Array.Reverse(payloadLengthBuffer);
Array.Copy(payloadLengthBuffer, 0, rawData, 8, 4);
return rawData;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b355061098e6549cc81fd05e63407130
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,74 @@
using System;
using System.IO;
using System.Collections.Generic;
using com.fpnn.msgpack;
namespace com.fpnn.proto
{
public class Message
{
private Dictionary<object, object> payload;
public Message()
{
payload = new Dictionary<object, object>();
}
public Message(Dictionary<object, object> payload)
{
this.payload = payload;
}
//-----------------[ Data Accessing Functions ]-------------------
public void Param(string key, object value)
{
payload.Add(key, value);
}
public object Get(string key, object defValue = null)
{
if (payload.TryGetValue(key, out object value))
{
return value;
}
return defValue;
}
public T Get<T>(string key, T defValue)
{
if (payload.TryGetValue(key, out object value))
{
return (T)Convert.ChangeType(value, typeof(T));
}
return defValue;
}
public object Want(string key)
{
return payload[key];
}
public T Want<T>(string key)
{
object obj = payload[key];
return (T)Convert.ChangeType(obj, typeof(T));
}
//-----------------[ To Bytes Array Functions ]-------------------
protected void Raw(Stream stream)
{
MsgPacker.Pack(stream, payload);
}
public byte[] Raw()
{
using (MemoryStream stream = new MemoryStream())
{
MsgPacker.Pack(stream, payload);
return stream.ToArray();
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3f32b2cf0b56c4ac692d21d23aeab592
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,145 @@
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
namespace com.fpnn.proto
{
public class Quest : Message
{
private static readonly byte[] FPNNBasicHeader = { 0x46, 0x50, 0x4e, 0x4e, 0x1, 0x80 };
private static readonly byte[] fakePayloadLength = { 0, 0, 0, 0 };
private UInt32 seqNum;
private bool isOneWay;
private String method;
private static class SeqNumGenerator
{
static private object interLocker;
static private int count;
static SeqNumGenerator()
{
interLocker = new object();
count = (int)(GetCurrentMilliseconds() % 1000000);
}
static public Int64 GetCurrentMilliseconds()
{
DateTime originDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
TimeSpan span = DateTime.UtcNow - originDateTime;
return (Int64)Math.Floor(span.TotalMilliseconds);
}
static public int Gen()
{
lock (interLocker)
{
return ++count;
}
}
}
public Quest(string method): this(method, false)
{
}
public Quest(string method, bool isOneWay)
{
this.method = method;
this.isOneWay = isOneWay;
seqNum = 0;
}
public Quest(string method, bool isOneWay, UInt32 seqNum, Dictionary<object, object> payload)
: base(payload)
{
this.method = method;
this.isOneWay = isOneWay;
this.seqNum = seqNum;
}
public UInt32 SeqNum()
{
return seqNum;
}
public String Method()
{
return method;
}
public bool IsOneWay()
{
return isOneWay;
}
public bool IsTwoWay()
{
return !isOneWay;
}
private int BuildFPNNPackage(Stream stream)
{
UTF8Encoding utf8Encoding = new UTF8Encoding(); //-- NO BOM.
byte[] methodData = utf8Encoding.GetBytes(method);
if (seqNum == 0)
seqNum = (UInt32)SeqNumGenerator.Gen();
stream.Write(FPNNBasicHeader, 0, 6);
if (isOneWay)
stream.WriteByte(0x0);
else
stream.WriteByte(0x1);
stream.WriteByte((byte)methodData.Length);
//-- payload size
stream.Write(fakePayloadLength, 0, 4);
//-- seq num
if (isOneWay == false)
{
byte[] seqBuffer = BitConverter.GetBytes(seqNum);
if (BitConverter.IsLittleEndian == false)
Array.Reverse(seqBuffer);
stream.Write(seqBuffer, 0, 4);
}
//-- method
stream.Write(methodData, 0, methodData.Length);
return methodData.Length;
}
new public byte[] Raw()
{
byte[] rawData;
int methodUTF8Length;
using (MemoryStream stream = new MemoryStream())
{
methodUTF8Length = BuildFPNNPackage(stream);
base.Raw(stream);
rawData = stream.ToArray();
}
Int32 payloadLength = rawData.Length - 12 - methodUTF8Length;
if (!isOneWay)
payloadLength -= 4;
byte[] payloadLengthBuffer = BitConverter.GetBytes(payloadLength);
if (BitConverter.IsLittleEndian == false)
Array.Reverse(payloadLengthBuffer);
Array.Copy(payloadLengthBuffer, 0, rawData, 8, 4);
return rawData;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6bdb7f6b5f826456b9c33fed503c27dc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: