修改协议工具

This commit is contained in:
2025-07-27 23:46:43 +08:00
parent 743c1d2baa
commit be33e12b35
112 changed files with 1021 additions and 1119 deletions

View File

@@ -35,31 +35,31 @@
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Pool\Normal\Pool.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Runtime\Core\Pool\Normal\Pool.cs">
<Link>Core\Base\Pool.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Packages\Fantasy.ConfigTable\Net\Dictionary\IntDictionaryConfig.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Packages\Fantasy.ConfigTable\Net\Dictionary\IntDictionaryConfig.cs">
<Link>Core\Dictionary\IntDictionaryConfig.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Packages\Fantasy.ConfigTable\Net\Dictionary\StringDictionaryConfig.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Packages\Fantasy.ConfigTable\Net\Dictionary\StringDictionaryConfig.cs">
<Link>Core\Dictionary\StringDictionaryConfig.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Packages\Fantasy.ConfigTable\Net\Interface\IConfigTable.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Packages\Fantasy.ConfigTable\Net\Interface\IConfigTable.cs">
<Link>Core\Interface\IConfigTable.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\ProtoBufPackHelper\IProto.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\ProtoBufPackHelper\IProto.cs">
<Link>Core\Serialize\ProtoBufPackHelper\IProto.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Helper\TimeHelper.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Runtime\Core\Helper\TimeHelper.cs">
<Link>Excel\Base\TimeHelper.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Pool\Interface\IPool.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Runtime\Core\Pool\Interface\IPool.cs">
<Link>Excel\Base\IPool.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Assembly\AssemblyInfo.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Runtime\Core\Assembly\AssemblyInfo.cs">
<Link>Excel\Base\AssemblyInfo.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\DataStructure\Collection\OneToManyListPool.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Runtime\Core\DataStructure\Collection\OneToManyListPool.cs">
<Link>Excel\Base\OneToManyList.cs</Link>
</Compile>
<Compile Include="..\Fantasy.Tools.NetworkProtocol\Core\Base\ConsoleLog.cs">
@@ -68,37 +68,37 @@
<Compile Include="..\Fantasy.Tools.NetworkProtocol\Core\Base\ExportPlatform.cs">
<Link>Core\ExportPlatform.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Helper\FileHelper.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Runtime\Core\Helper\FileHelper.cs">
<Link>Core\FileHelper.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Helper\HashCodeHelper.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Runtime\Core\Helper\HashCodeHelper.cs">
<Link>Core\HashCodeHelper.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Helper\JsonHelper.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Runtime\Core\Helper\JsonHelper.cs">
<Link>Core\JsonHelper.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\BsonPack\BsonPackHelperNet.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\BsonPack\BsonPackHelperNet.cs">
<Link>Core\Serialize\BsonPack\BsonPackHelperNet.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\BsonPack\StructBsonSerialize.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\BsonPack\StructBsonSerialize.cs">
<Link>Core\Serialize\BsonPack\StructBsonSerialize.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\BsonPack\SupportInitializeChecker.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\BsonPack\SupportInitializeChecker.cs">
<Link>Core\Serialize\BsonPack\SupportInitializeChecker.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\Interface\ASerialize.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\Interface\ASerialize.cs">
<Link>Core\Serialize\Interface\ASerialize.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\Interface\ISerialize.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\Interface\ISerialize.cs">
<Link>Core\Serialize\Interface\ISerialize.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\SerializerManager.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\SerializerManager.cs">
<Link>Core\Serialize\SerializerManager.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\ProtoBufPackHelper\ProtoBufPackHelperNet.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\ProtoBufPackHelper\ProtoBufPackHelperNet.cs">
<Link>Core\Serialize\ProtoBufPackHelper\ProtoBufPackHelperNet.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\MemoryStreamBuffer.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\MemoryStreamBuffer.cs">
<Link>Excel\Base\MemoryStreamBuffer.cs</Link>
</Compile>
</ItemGroup>
@@ -115,9 +115,4 @@
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Fantasy.Net.csproj" />
<ProjectReference Include="..\..\..\Fantasy\Fantasy.Packages\Fantasy.ConfigTable\Net\Fantasy.ConfigTable.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,40 +0,0 @@
namespace Fantasy.Tools.ProtocalExporter;
public static class NetworkProtocolTemplate
{
public static readonly string Template ="""
#if SERVER
using ProtoBuf;
(UsingNamespace)
using System.Collections.Generic;
using MongoDB.Bson.Serialization.Attributes;
using Fantasy;
using Fantasy.Network.Interface;
using Fantasy.Serialize;
// ReSharper disable InconsistentNaming
// ReSharper disable RedundantUsingDirective
// ReSharper disable RedundantOverriddenMember
// ReSharper disable PartialTypeWithSinglePart
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable CheckNamespace
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
#pragma warning disable CS8618
namespace Fantasy
{
#else
using ProtoBuf;
(UsingNamespace)
using System.Collections.Generic;
using Fantasy;
using Fantasy.Network.Interface;
using Fantasy.Serialize;
#pragma warning disable CS8618
namespace Fantasy
{
#endif
(Content)}
""";
}

View File

@@ -4,6 +4,7 @@ using Fantasy.Helper;
using Fantasy.Network;
using OpCode = Fantasy.Network.OpCode;
using OpCodeType = Fantasy.Network.OpCodeType;
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
#pragma warning disable CS8602 // Dereference of a possibly null reference.
// ReSharper disable PossibleNullReferenceException
@@ -12,12 +13,14 @@ using OpCodeType = Fantasy.Network.OpCodeType;
#pragma warning disable CS8604 // Possible null reference argument.
namespace Fantasy.Tools.ProtocalExporter;
public enum NetworkProtocolOpCodeType
{
None = 0,
Outer = 1,
Inner = 2,
}
public sealed class OpcodeInfo
{
public uint Code;
@@ -35,12 +38,13 @@ public sealed class ProtocolExporter
private readonly string _networkProtocolServerDirectory;
private readonly string _networkProtocolDirectoryOuter;
private readonly string _networkProtocolDirectoryInner;
public ProtocolExporter()
{
Console.OutputEncoding = Encoding.UTF8;
if (ExporterSettingsHelper.NetworkProtocolDirectory == null || ExporterSettingsHelper.NetworkProtocolDirectory.Trim() == "")
if (ExporterSettingsHelper.NetworkProtocolDirectory == null ||
ExporterSettingsHelper.NetworkProtocolDirectory.Trim() == "")
{
Log.Info($"NetworkProtocolDirectory Can not be empty!");
return;
@@ -119,12 +123,12 @@ public sealed class ProtocolExporter
var errorCodeStr = new StringBuilder();
var usingNamespace = new HashSet<string>();
var saveDirectory = new Dictionary<string, string>();
OpcodeInfo opcodeInfo = null;
ProtocolOpCode protocolOpCode = null;
string[] protocolFiles = null;
_opcodes.Clear();
switch (opCodeType)
{
case NetworkProtocolOpCodeType.Outer:
@@ -133,12 +137,12 @@ public sealed class ProtocolExporter
{
saveDirectory.Add(_networkProtocolServerDirectory, _serverTemplate);
}
if (ExporterAges.Instance.ExportPlatform.HasFlag(ExportPlatform.Client))
{
saveDirectory.Add(_networkProtocolClientDirectory, _clientTemplate);
}
protocolOpCode = new ProtocolOpCode()
{
Message = OpCodeType.OuterMessage,
@@ -158,7 +162,8 @@ public sealed class ProtocolExporter
RoamingResponse = OpCodeType.OuterRoamingResponse,
};
opCodeName = "OuterOpcode";
protocolFiles = FileHelper.GetDirectoryFile(_networkProtocolDirectoryOuter, "*.proto", SearchOption.AllDirectories);
protocolFiles = FileHelper.GetDirectoryFile(_networkProtocolDirectoryOuter, "*.proto",
SearchOption.AllDirectories);
break;
}
case NetworkProtocolOpCodeType.Inner:
@@ -183,7 +188,8 @@ public sealed class ProtocolExporter
};
opCodeName = "InnerOpcode";
saveDirectory.Add(_networkProtocolServerDirectory, _serverTemplate);
protocolFiles = FileHelper.GetDirectoryFile(_networkProtocolDirectoryInner, "*.proto", SearchOption.AllDirectories);
protocolFiles = FileHelper.GetDirectoryFile(_networkProtocolDirectoryInner, "*.proto",
SearchOption.AllDirectories);
break;
}
}
@@ -192,7 +198,7 @@ public sealed class ProtocolExporter
{
return;
}
#region GenerateFiles
foreach (var filePath in protocolFiles)
@@ -221,7 +227,8 @@ public sealed class ProtocolExporter
if (currentLine.StartsWith("///"))
{
messageStr.AppendFormat(" /// <summary>\r\n" + " /// {0}\r\n" + " /// </summary>\r\n", currentLine.Substring("///".Length));
messageStr.AppendFormat(" /// <summary>\r\n" + " /// {0}\r\n" + " /// </summary>\r\n",
currentLine.Substring("///".Length));
continue;
}
@@ -256,6 +263,7 @@ public sealed class ProtocolExporter
Log.Error("Under Outer, /// does not support the Bson protocol!");
return;
}
protocolType = null;
protocolIgnore = "\t\t[BsonIgnore]";
protocolMember = null;
@@ -298,11 +306,12 @@ public sealed class ProtocolExporter
{
messageStr.AppendLine("\t[ProtoContract]");
}
if (splits.Length > 1)
{
hasOpCode = true;
var parameterArray = currentLine.Split(new[] { "//" }, StringSplitOptions.RemoveEmptyEntries)[1].Trim().Split(',');
var parameterArray = currentLine.Split(new[] { "//" }, StringSplitOptions.RemoveEmptyEntries)[1]
.Trim().Split(',');
parameter = parameterArray[0].Trim();
opcodeInfo = new OpcodeInfo()
{
@@ -330,12 +339,15 @@ public sealed class ProtocolExporter
break;
}
}
break;
}
case 3:
{
responseTypeStr = parameterArray[1].Trim();
customRouteType = parameter.Contains("IRoaming") ? $"Fantasy.RoamingType.{parameterArray[2].Trim()}" : $"Fantasy.RouteType.{parameterArray[2].Trim()}";
customRouteType = parameter.Contains("IRoaming")
? $"Fantasy.RoamingType.{parameterArray[2].Trim()}"
: $"Fantasy.RouteType.{parameterArray[2].Trim()}";
break;
}
}
@@ -353,6 +365,7 @@ public sealed class ProtocolExporter
{
messageStr.Append(", IProto");
}
continue;
}
@@ -367,15 +380,18 @@ public sealed class ProtocolExporter
{
messageStr.AppendLine("\n\t{");
messageStr.AppendLine($"\t\tpublic static {className} Create(Scene scene)");
messageStr.AppendLine($"\t\t{{\n\t\t\treturn scene.MessagePoolComponent.Rent<{className}>();\n\t\t}}");
messageStr.AppendLine(
$"\t\t{{\n\t\t\treturn scene.MessagePoolComponent.Rent<{className}>();\n\t\t}}");
messageStr.AppendLine($"\t\tpublic override void Dispose()");
messageStr.AppendLine($"\t\t{{");
messageStr.AppendLine($"<<<<Dispose>>>#if FANTASY_NET || FANTASY_UNITY\n\t\t\tGetScene().MessagePoolComponent.Return<{className}>(this);\n#endif");
messageStr.AppendLine(
$"<<<<Dispose>>>#if FANTASY_NET || FANTASY_UNITY\n\t\t\tGetScene().MessagePoolComponent.Return<{className}>(this);\n#endif");
messageStr.AppendLine($"\t\t}}");
if (parameter == "IMessage")
{
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.Message, protocolOpCode.AMessage++);
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.Message,
protocolOpCode.AMessage++);
messageStr.AppendLine($"\t\tpublic uint OpCode() {{ return {opCodeName}.{className}; }}");
}
else
@@ -397,7 +413,8 @@ public sealed class ProtocolExporter
if (hasOpCode)
{
messageStr.AppendLine($"\t\tpublic uint OpCode() {{ return {opCodeName}.{className}; }}");
messageStr.AppendLine(
$"\t\tpublic uint OpCode() {{ return {opCodeName}.{className}; }}");
}
if (customRouteType != null)
@@ -411,16 +428,19 @@ public sealed class ProtocolExporter
{
case "IRequest":
{
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.Request, protocolOpCode.ARequest++);
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.Request,
protocolOpCode.ARequest++);
break;
}
case "IResponse":
{
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.Response, protocolOpCode.AResponse++);
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.Response,
protocolOpCode.AResponse++);
if (!string.IsNullOrEmpty(protocolMember))
{
errorCodeStr.AppendLine($"\t\t[{protocolMember}(ErrorCodeKeyIndex)]");
}
errorCodeStr.AppendLine("\t\tpublic uint ErrorCode { get; set; }");
disposeStr.AppendLine($"\t\t\tErrorCode = default;");
break;
@@ -431,21 +451,28 @@ public sealed class ProtocolExporter
{
case "IAddressableRouteMessage":
{
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.AddressableMessage, protocolOpCode.AAddressableMessage++);
opcodeInfo.Code = OpCode.Create(protocolOpCodeType,
protocolOpCode.AddressableMessage,
protocolOpCode.AAddressableMessage++);
break;
}
case "IAddressableRouteRequest":
{
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.AddressableRequest, protocolOpCode.AAddressableRequest++);
opcodeInfo.Code = OpCode.Create(protocolOpCodeType,
protocolOpCode.AddressableRequest,
protocolOpCode.AAddressableRequest++);
break;
}
case "IAddressableRouteResponse":
{
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.AddressableResponse, protocolOpCode.AAddressableResponse++);
opcodeInfo.Code = OpCode.Create(protocolOpCodeType,
protocolOpCode.AddressableResponse,
protocolOpCode.AAddressableResponse++);
if (!string.IsNullOrEmpty(protocolMember))
{
errorCodeStr.AppendLine($"\t\t[{protocolMember}(ErrorCodeKeyIndex)]");
}
errorCodeStr.AppendLine("\t\tpublic uint ErrorCode { get; set; }");
disposeStr.AppendLine($"\t\t\tErrorCode = default;");
break;
@@ -454,31 +481,44 @@ public sealed class ProtocolExporter
{
if (opCodeType == NetworkProtocolOpCodeType.Inner)
{
throw new NotSupportedException("Under Inner, /// does not support the ICustomRouteMessage!");
throw new NotSupportedException(
"Under Inner, /// does not support the ICustomRouteMessage!");
}
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.CustomRouteMessage, protocolOpCode.ACustomRouteMessage++);
opcodeInfo.Code = OpCode.Create(protocolOpCodeType,
protocolOpCode.CustomRouteMessage,
protocolOpCode.ACustomRouteMessage++);
break;
}
case "ICustomRouteRequest":
{
if (opCodeType == NetworkProtocolOpCodeType.Inner)
{
throw new NotSupportedException("Under Inner, /// does not support the ICustomRouteMessage!");
throw new NotSupportedException(
"Under Inner, /// does not support the ICustomRouteMessage!");
}
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.CustomRouteRequest, protocolOpCode.ACustomRouteRequest++);
opcodeInfo.Code = OpCode.Create(protocolOpCodeType,
protocolOpCode.CustomRouteRequest,
protocolOpCode.ACustomRouteRequest++);
break;
}
case "ICustomRouteResponse":
{
if (opCodeType == NetworkProtocolOpCodeType.Inner)
{
throw new NotSupportedException("Under Inner, /// does not support the ICustomRouteMessage!");
throw new NotSupportedException(
"Under Inner, /// does not support the ICustomRouteMessage!");
}
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.CustomRouteResponse, protocolOpCode.ACustomRouteResponse++);
opcodeInfo.Code = OpCode.Create(protocolOpCodeType,
protocolOpCode.CustomRouteResponse,
protocolOpCode.ACustomRouteResponse++);
if (!string.IsNullOrEmpty(protocolMember))
{
errorCodeStr.AppendLine($"\t\t[{protocolMember}(ErrorCodeKeyIndex)]");
}
errorCodeStr.AppendLine("\t\tpublic uint ErrorCode { get; set; }");
disposeStr.AppendLine($"\t\t\tErrorCode = default;");
break;
@@ -489,7 +529,8 @@ public sealed class ProtocolExporter
// {
// throw new NotSupportedException("Under Inner, /// does not support the IRoamingMessage!");
// }
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.RoamingMessage, protocolOpCode.ARoamingMessage++);
opcodeInfo.Code = OpCode.Create(protocolOpCodeType,
protocolOpCode.RoamingMessage, protocolOpCode.ARoamingMessage++);
break;
}
case "IRoamingRequest":
@@ -498,7 +539,8 @@ public sealed class ProtocolExporter
// {
// throw new NotSupportedException("Under Inner, /// does not support the IRoamingRequest!");
// }
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.RoamingRequest, protocolOpCode.ARoamingRequest++);
opcodeInfo.Code = OpCode.Create(protocolOpCodeType,
protocolOpCode.RoamingRequest, protocolOpCode.ARoamingRequest++);
break;
}
case "IRoamingResponse":
@@ -507,11 +549,13 @@ public sealed class ProtocolExporter
// {
// throw new NotSupportedException("Under Inner, /// does not support the IRoamingResponse!");
// }
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.RoamingResponse, protocolOpCode.ARoamingResponse++);
opcodeInfo.Code = OpCode.Create(protocolOpCodeType,
protocolOpCode.RoamingResponse, protocolOpCode.ARoamingResponse++);
if (!string.IsNullOrEmpty(protocolMember))
{
errorCodeStr.AppendLine($"\t\t[{protocolMember}(ErrorCodeKeyIndex)]");
}
errorCodeStr.AppendLine("\t\tpublic uint ErrorCode { get; set; }");
disposeStr.AppendLine($"\t\t\tErrorCode = default;");
break;
@@ -520,31 +564,41 @@ public sealed class ProtocolExporter
{
if (opCodeType == NetworkProtocolOpCodeType.Outer)
{
throw new NotSupportedException("Under Inner, /// does not support the ICustomRouteMessage!");
throw new NotSupportedException(
"Under Inner, /// does not support the ICustomRouteMessage!");
}
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.RouteMessage, protocolOpCode.ARouteMessage++);
opcodeInfo.Code = OpCode.Create(protocolOpCodeType,
protocolOpCode.RouteMessage, protocolOpCode.ARouteMessage++);
break;
}
case "IRouteRequest":
{
if (opCodeType == NetworkProtocolOpCodeType.Outer)
{
throw new NotSupportedException("Under Inner, /// does not support the ICustomRouteMessage!");
throw new NotSupportedException(
"Under Inner, /// does not support the ICustomRouteMessage!");
}
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.RouteRequest, protocolOpCode.ARouteRequest++);
opcodeInfo.Code = OpCode.Create(protocolOpCodeType,
protocolOpCode.RouteRequest, protocolOpCode.ARouteRequest++);
break;
}
case "IRouteResponse":
{
if (opCodeType == NetworkProtocolOpCodeType.Outer)
{
throw new NotSupportedException("Under Inner, /// does not support the ICustomRouteMessage!");
throw new NotSupportedException(
"Under Inner, /// does not support the ICustomRouteMessage!");
}
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.RouteResponse, protocolOpCode.ARouteResponse++);
opcodeInfo.Code = OpCode.Create(protocolOpCodeType,
protocolOpCode.RouteResponse, protocolOpCode.ARouteResponse++);
if (!string.IsNullOrEmpty(protocolMember))
{
errorCodeStr.AppendLine($"\t\t[{protocolMember}(ErrorCodeKeyIndex)]");
}
errorCodeStr.AppendLine("\t\tpublic uint ErrorCode { get; set; }");
disposeStr.AppendLine($"\t\t\tErrorCode = default;");
break;
@@ -589,7 +643,8 @@ public sealed class ProtocolExporter
if (currentLine.StartsWith("//"))
{
messageStr.AppendFormat("\t\t///<summary>\r\n" + "\t\t/// {0}\r\n" + "\t\t///</summary>\r\n", currentLine.TrimStart('/', '/'));
messageStr.AppendFormat("\t\t///<summary>\r\n" + "\t\t/// {0}\r\n" + "\t\t///</summary>\r\n",
currentLine.TrimStart('/', '/'));
continue;
}
@@ -602,14 +657,14 @@ public sealed class ProtocolExporter
Members(messageStr, disposeStr, currentLine, protocolMember, ref keyIndex);
}
}
var namespaceBuilder = new StringBuilder();
foreach (var @namespace in usingNamespace)
{
namespaceBuilder.Append($"using {@namespace};\n");
}
var csName = $"{Path.GetFileNameWithoutExtension(filePath)}.cs";
foreach (var (directory, template) in saveDirectory)
{
@@ -618,9 +673,10 @@ public sealed class ProtocolExporter
content = content.Replace("(UsingNamespace)", namespaceBuilder.ToString());
await File.WriteAllTextAsync(csFile, content);
}
file.Clear();
}
#endregion
#region GenerateOpCode
@@ -635,7 +691,7 @@ public sealed class ProtocolExporter
{
file.AppendLine($"\t\t public const uint {opcode.Name} = {opcode.Code};");
}
_opcodes.Clear();
file.AppendLine("\t}");
file.AppendLine("}");
@@ -645,10 +701,12 @@ public sealed class ProtocolExporter
var csFile = Path.Combine(directory, $"{opCodeName}.cs");
await File.WriteAllTextAsync(csFile, file.ToString());
}
#endregion
}
private void Repeated(StringBuilder file, StringBuilder disposeStr, string newline, string protocolMember, ref int keyIndex)
private void Repeated(StringBuilder file, StringBuilder disposeStr, string newline, string protocolMember,
ref int keyIndex)
{
try
{
@@ -669,8 +727,9 @@ public sealed class ProtocolExporter
Log.Error($"{newline}\n {e}");
}
}
private void Members(StringBuilder file, StringBuilder disposeStr, string currentLine, string protocolMember, ref int keyIndex)
private void Members(StringBuilder file, StringBuilder disposeStr, string currentLine, string protocolMember,
ref int keyIndex)
{
try
{
@@ -685,6 +744,7 @@ public sealed class ProtocolExporter
{
file.AppendLine($"\t\t[{protocolMember}({keyIndex++})]");
}
file.AppendLine($"\t\tpublic {typeCs} {name} {{ get; set; }}");
disposeStr.AppendLine($"\t\t\t{name} = default;");
}
@@ -693,7 +753,7 @@ public sealed class ProtocolExporter
Log.Error($"{currentLine}\n {e}");
}
}
private string ConvertType(string type)
{
return type switch
@@ -763,9 +823,10 @@ public sealed class ProtocolExporter
{
roamingTypeFileSb.AppendLine($"\t\t\t\tyield return {roamingType};");
}
roamingTypeFileSb.AppendLine("\t\t\t}\n\t\t}");
}
roamingTypeFileSb.AppendLine("\t}\n}");
var file = roamingTypeFileSb.ToString();
@@ -780,7 +841,7 @@ public sealed class ProtocolExporter
await File.WriteAllTextAsync($"{_networkProtocolClientDirectory}RoamingType.cs", file);
}
}
private async Task RouteType()
{
var routeTypeFile = $"{_networkProtocolDirectory}RouteType.Config";
@@ -794,6 +855,7 @@ public sealed class ProtocolExporter
{
protoFileText = await File.ReadAllTextAsync(routeTypeFile);
}
var routeTypeFileSb = new StringBuilder();
routeTypeFileSb.AppendLine("namespace Fantasy\n{");
routeTypeFileSb.AppendLine("\t// Route协议定义(需要定义1000以上、因为1000以内的框架预留)\t");
@@ -835,10 +897,16 @@ public sealed class ProtocolExporter
await File.WriteAllTextAsync($"{_networkProtocolClientDirectory}RouteType.cs", file);
}
}
private void LoadTemplate()
{
string[] lines = NetworkProtocolTemplate.Template.Split(["\r\n", "\n"], StringSplitOptions.None);
// 获取当前运行根目录(即应用程序的工作目录)
string currentDirectory = Directory.GetCurrentDirectory();
string filePath = Path.Combine(currentDirectory, "Template.txt");
// 读取文件所有行
string[] lines = File.ReadAllLines(filePath);
StringBuilder serverSb = new StringBuilder();
StringBuilder clientSb = new StringBuilder();
@@ -853,12 +921,14 @@ public sealed class ProtocolExporter
flag = 1;
continue;
}
else if (trim.StartsWith("#else"))
if (trim.StartsWith("#else"))
{
flag = 2;
continue;
}
else if (trim.StartsWith($"#endif"))
if (trim.StartsWith($"#endif"))
{
flag = 0;
continue;

View File

@@ -1,15 +1,15 @@
{
"Export": {
"NetworkProtocolDirectory": {
"Value": "../../../Examples/Config/NetworkProtocol/",
"Value": "../../../Config/NetworkProtocol/",
"Comment": "ProtoBuf文件所在的文件夹位置"
},
"NetworkProtocolServerDirectory": {
"Value": "../../../Examples/Server/Entity/Generate/NetworkProtocol/",
"Value": "../../../Entity/Generate/NetworkProtocol/",
"Comment": "ProtoBuf生成到服务端的文件夹位置"
},
"NetworkProtocolClientDirectory": {
"Value": "../../../Examples/Client/Unity/Assets/Scripts/Hotfix/Generate/NetworkProtocol/",
"Value": "../../../../Fishing2/Assets/Scripts/Generate/NetworkProtocol/",
"Comment": "ProtoBuf生成到客户端的文件夹位置"
},
"Serializes": {

View File

@@ -32,16 +32,16 @@
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Helper\FileHelper.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Runtime\Core\Helper\FileHelper.cs">
<Link>Core\FileHelper.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Helper\HashCodeHelper.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Runtime\Core\Helper\HashCodeHelper.cs">
<Link>Core\HashCodeHelper.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Helper\JsonHelper.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Runtime\Core\Helper\JsonHelper.cs">
<Link>Core\JsonHelper.cs</Link>
</Compile>
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Network\Message\PacketParser\OpCode.cs">
<Compile Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Runtime\Core\Network\Message\PacketParser\OpCode.cs">
<Link>ProtocalExporter\OpCode.cs</Link>
</Compile>
<Compile Update="ExporterSettingsHelper.cs">
@@ -59,10 +59,9 @@
<None Update="Run.sh">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Fantasy\Fantasy.Net\Fantasy.Net\Fantasy.Net.csproj" />
<None Update="Template.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,33 @@
#if SERVER
using ProtoBuf;
(UsingNamespace)
using System.Collections.Generic;
using MongoDB.Bson.Serialization.Attributes;
using Fantasy;
using Fantasy.Network.Interface;
using Fantasy.Serialize;
// ReSharper disable InconsistentNaming
// ReSharper disable RedundantUsingDirective
// ReSharper disable RedundantOverriddenMember
// ReSharper disable PartialTypeWithSinglePart
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable CheckNamespace
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
#pragma warning disable CS8618
namespace NBC
{
#else
using ProtoBuf;
(UsingNamespace)
using System.Collections.Generic;
using Fantasy;
using Fantasy.Network.Interface;
using Fantasy.Serialize;
#pragma warning disable CS8618
namespace Fantasy
{
#endif
(Content)}

View File

@@ -12,12 +12,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fantasy.Tools.ExporterConfi
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SourceCode", "SourceCode", "{A402EB74-8BF8-4A53-82F2-F77E59D9F4C6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fantasy.Net", "..\..\Fantasy\Fantasy.Net\Fantasy.Net\Fantasy.Net.csproj", "{0D68E07B-F631-4BC9-A9F3-94367E81AAA6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Fantasy", "Fantasy", "{14CA88F5-2827-4302-B522-9E19CD9F65BE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fantasy.ConfigTable", "..\..\Fantasy\Fantasy.Packages\Fantasy.ConfigTable\Net\Fantasy.ConfigTable.csproj", "{C0AB5238-D911-4BB2-B732-54572A3DF0DF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -40,21 +34,11 @@ Global
{5A236869-283F-4046-860B-E295963139AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5A236869-283F-4046-860B-E295963139AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5A236869-283F-4046-860B-E295963139AB}.Release|Any CPU.Build.0 = Release|Any CPU
{0D68E07B-F631-4BC9-A9F3-94367E81AAA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0D68E07B-F631-4BC9-A9F3-94367E81AAA6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0D68E07B-F631-4BC9-A9F3-94367E81AAA6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0D68E07B-F631-4BC9-A9F3-94367E81AAA6}.Release|Any CPU.Build.0 = Release|Any CPU
{C0AB5238-D911-4BB2-B732-54572A3DF0DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C0AB5238-D911-4BB2-B732-54572A3DF0DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C0AB5238-D911-4BB2-B732-54572A3DF0DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C0AB5238-D911-4BB2-B732-54572A3DF0DF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E0F9231E-F057-4121-B167-7AC47D48E7E3} = {CCF6F6B1-50D8-4B0D-91B9-035CDCC4B1CA}
{5A236869-283F-4046-860B-E295963139AB} = {CCF6F6B1-50D8-4B0D-91B9-035CDCC4B1CA}
{F01BD146-FDEA-46D6-9A08-F3CCF05D817E} = {A402EB74-8BF8-4A53-82F2-F77E59D9F4C6}
{72D45E2D-EF78-4D80-8BFC-ED95FA8543C7} = {A402EB74-8BF8-4A53-82F2-F77E59D9F4C6}
{0D68E07B-F631-4BC9-A9F3-94367E81AAA6} = {14CA88F5-2827-4302-B522-9E19CD9F65BE}
{C0AB5238-D911-4BB2-B732-54572A3DF0DF} = {14CA88F5-2827-4302-B522-9E19CD9F65BE}
EndGlobalSection
EndGlobal

View File

@@ -10,6 +10,7 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ALicenseContext_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5127915f4e764e0285562916e9114ab3411610_003F47_003Fcbc79ab6_003FLicenseContext_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMemoryPackableAttribute_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F958e054c967b40b3a108913205d36c4933400_003Fcd_003Fa95eada9_003FMemoryPackableAttribute_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMemoryPackFormatter_00601_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F958e054c967b40b3a108913205d36c4933400_003F7e_003F8f320c8b_003FMemoryPackFormatter_00601_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AParserResultExtensions_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fc453ace1e4574cfe83f15ca8c8f735bf37000_003F04_003Fdce32804_003FParserResultExtensions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AParser_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fc453ace1e4574cfe83f15ca8c8f735bf37000_003F47_003F09aa3821_003FParser_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AProtoReader_002EState_002EReadMethods_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F37c1347d9c665a9c38de996b994b62177561c4c4515e4d49fdf93cd848fe49b_003FProtoReader_002EState_002EReadMethods_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ARunResults_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fe923221d2ee660ba5d21ad70b29da65ed3a69653ab6311336652dc91242cb_003FRunResults_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>