[+] TEngineServer

[+] TEngineServer
This commit is contained in:
ALEXTANG
2023-07-13 17:17:26 +08:00
parent a69f53592e
commit 0c8f3a5f92
790 changed files with 52737 additions and 2533 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9d91af67c28edce489bc064458254a30
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,49 @@
#if TENGINE_NET
using System.Text;
using TEngine.Core;
namespace TEngine.Model;
public sealed class SceneTypeConfigToEnum : ACustomExport
{
public override void Run()
{
var serverSceneType = new HashSet<string>();
var instanceList = SceneConfigData.Instance.List;
foreach (var sceneConfig in instanceList)
{
serverSceneType.Add(sceneConfig.SceneType);
}
if (serverSceneType.Count > 0)
{
Write(CustomExportType.Server, serverSceneType);
}
}
private void Write(CustomExportType customExportType, HashSet<string> sceneTypes)
{
var index = 0;
var strBuilder = new StringBuilder();
var dicBuilder = new StringBuilder();
strBuilder.AppendLine("namespace TEngine\n{");
strBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑。");
strBuilder.AppendLine("\tpublic class SceneType\n\t{");
dicBuilder.AppendLine("\n\t\tpublic static readonly Dictionary<string, int> SceneDic = new Dictionary<string, int>()\n\t\t{");
foreach (var str in sceneTypes)
{
index++;
dicBuilder.AppendLine($"\t\t\t{{ \"{str}\", {index} }},");
strBuilder.AppendLine($"\t\tpublic const int {str} = {index};");
}
dicBuilder.AppendLine("\t\t};");
strBuilder.Append(dicBuilder);
strBuilder.AppendLine("\t}\n}");
Write("SceneType.cs", strBuilder.ToString(), customExportType);
}
}
#endif

View File

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

View File

@@ -0,0 +1,11 @@
#if TENGINE_NET
namespace TEngine.Logic;
public static class Entry
{
public static async FTask Start()
{
await FTask.CompletedTask;
}
}
#endif

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1b8404cea481db34c91f2ba7567620db
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bc782e6aee9c7654a85ff3e8178e1f53
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,88 @@
using System;
using ProtoBuf;
using TEngine.Core;
using System.Linq;
using System.Collections.Generic;
// ReSharper disable CollectionNeverUpdated.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
#pragma warning disable CS0169
#pragma warning disable CS8618
#pragma warning disable CS8625
#pragma warning disable CS8603
namespace TEngine
{
[ProtoContract]
public sealed partial class MachineConfigData : AProto, IConfigTable, IDisposable
{
[ProtoMember(1)]
public List<MachineConfig> List { get; set; } = new List<MachineConfig>();
[ProtoIgnore]
private readonly Dictionary<uint, MachineConfig> _configs = new Dictionary<uint, MachineConfig>();
private static MachineConfigData _instance;
public static MachineConfigData Instance
{
get { return _instance ??= ConfigTableManage.Load<MachineConfigData>(); }
private set => _instance = value;
}
public MachineConfig Get(uint id, bool check = true)
{
if (_configs.ContainsKey(id))
{
return _configs[id];
}
if (check)
{
throw new Exception($"MachineConfig not find {id} Id");
}
return null;
}
public bool TryGet(uint id, out MachineConfig config)
{
config = null;
if (!_configs.ContainsKey(id))
{
return false;
}
config = _configs[id];
return true;
}
public override void AfterDeserialization()
{
for (var i = 0; i < List.Count; i++)
{
MachineConfig config = List[i];
_configs.Add(config.Id, config);
config.AfterDeserialization();
}
base.AfterDeserialization();
}
public void Dispose()
{
Instance = null;
}
}
[ProtoContract]
public sealed partial class MachineConfig : AProto
{
[ProtoMember(1, IsRequired = true)]
public uint Id { get; set; } // Id
[ProtoMember(2, IsRequired = true)]
public string OuterIP { get; set; } // 外网IP
[ProtoMember(3, IsRequired = true)]
public string OuterBindIP { get; set; } // 外网绑定IP
[ProtoMember(4, IsRequired = true)]
public string InnerBindIP { get; set; } // 内网绑定IP
[ProtoMember(5, IsRequired = true)]
public int ManagementPort { get; set; } // 管理端口
}
}

View File

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

View File

@@ -0,0 +1,94 @@
using System;
using ProtoBuf;
using TEngine.Core;
using System.Linq;
using System.Collections.Generic;
// ReSharper disable CollectionNeverUpdated.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
#pragma warning disable CS0169
#pragma warning disable CS8618
#pragma warning disable CS8625
#pragma warning disable CS8603
namespace TEngine
{
[ProtoContract]
public sealed partial class SceneConfigData : AProto, IConfigTable, IDisposable
{
[ProtoMember(1)]
public List<SceneConfig> List { get; set; } = new List<SceneConfig>();
[ProtoIgnore]
private readonly Dictionary<uint, SceneConfig> _configs = new Dictionary<uint, SceneConfig>();
private static SceneConfigData _instance;
public static SceneConfigData Instance
{
get { return _instance ??= ConfigTableManage.Load<SceneConfigData>(); }
private set => _instance = value;
}
public SceneConfig Get(uint id, bool check = true)
{
if (_configs.ContainsKey(id))
{
return _configs[id];
}
if (check)
{
throw new Exception($"SceneConfig not find {id} Id");
}
return null;
}
public bool TryGet(uint id, out SceneConfig config)
{
config = null;
if (!_configs.ContainsKey(id))
{
return false;
}
config = _configs[id];
return true;
}
public override void AfterDeserialization()
{
for (var i = 0; i < List.Count; i++)
{
SceneConfig config = List[i];
_configs.Add(config.Id, config);
config.AfterDeserialization();
}
base.AfterDeserialization();
}
public void Dispose()
{
Instance = null;
}
}
[ProtoContract]
public sealed partial class SceneConfig : AProto
{
[ProtoMember(1, IsRequired = true)]
public uint Id { get; set; } // ID
[ProtoMember(2, IsRequired = true)]
public long EntityId { get; set; } // 实体Id
[ProtoMember(3, IsRequired = true)]
public uint RouteId { get; set; } // 路由Id
[ProtoMember(4, IsRequired = true)]
public uint WorldId { get; set; } // 世界Id
[ProtoMember(5, IsRequired = true)]
public string SceneType { get; set; } // Scene类型
[ProtoMember(6, IsRequired = true)]
public string Name { get; set; } // 名称
[ProtoMember(7, IsRequired = true)]
public string NetworkProtocol { get; set; } // 协议类型
[ProtoMember(8, IsRequired = true)]
public int OuterPort { get; set; } // 外网端口
}
}

View File

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

View File

@@ -0,0 +1,86 @@
using System;
using ProtoBuf;
using TEngine.Core;
using System.Linq;
using System.Collections.Generic;
// ReSharper disable CollectionNeverUpdated.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
#pragma warning disable CS0169
#pragma warning disable CS8618
#pragma warning disable CS8625
#pragma warning disable CS8603
namespace TEngine
{
[ProtoContract]
public sealed partial class ServerConfigData : AProto, IConfigTable, IDisposable
{
[ProtoMember(1)]
public List<ServerConfig> List { get; set; } = new List<ServerConfig>();
[ProtoIgnore]
private readonly Dictionary<uint, ServerConfig> _configs = new Dictionary<uint, ServerConfig>();
private static ServerConfigData _instance;
public static ServerConfigData Instance
{
get { return _instance ??= ConfigTableManage.Load<ServerConfigData>(); }
private set => _instance = value;
}
public ServerConfig Get(uint id, bool check = true)
{
if (_configs.ContainsKey(id))
{
return _configs[id];
}
if (check)
{
throw new Exception($"ServerConfig not find {id} Id");
}
return null;
}
public bool TryGet(uint id, out ServerConfig config)
{
config = null;
if (!_configs.ContainsKey(id))
{
return false;
}
config = _configs[id];
return true;
}
public override void AfterDeserialization()
{
for (var i = 0; i < List.Count; i++)
{
ServerConfig config = List[i];
_configs.Add(config.Id, config);
config.AfterDeserialization();
}
base.AfterDeserialization();
}
public void Dispose()
{
Instance = null;
}
}
[ProtoContract]
public sealed partial class ServerConfig : AProto
{
[ProtoMember(1, IsRequired = true)]
public uint Id { get; set; } // 路由Id
[ProtoMember(2, IsRequired = true)]
public uint MachineId { get; set; } // 机器ID
[ProtoMember(3, IsRequired = true)]
public int InnerPort { get; set; } // 内网端口
[ProtoMember(4, IsRequired = true)]
public bool ReleaseMode { get; set; } // Release下运行
}
}

View File

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

View File

@@ -0,0 +1,90 @@
using System;
using ProtoBuf;
using TEngine.Core;
using System.Linq;
using System.Collections.Generic;
// ReSharper disable CollectionNeverUpdated.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
#pragma warning disable CS0169
#pragma warning disable CS8618
#pragma warning disable CS8625
#pragma warning disable CS8603
namespace TEngine
{
[ProtoContract]
public sealed partial class WorldConfigData : AProto, IConfigTable, IDisposable
{
[ProtoMember(1)]
public List<WorldConfig> List { get; set; } = new List<WorldConfig>();
[ProtoIgnore]
private readonly Dictionary<uint, WorldConfig> _configs = new Dictionary<uint, WorldConfig>();
private static WorldConfigData _instance;
public static WorldConfigData Instance
{
get { return _instance ??= ConfigTableManage.Load<WorldConfigData>(); }
private set => _instance = value;
}
public WorldConfig Get(uint id, bool check = true)
{
if (_configs.ContainsKey(id))
{
return _configs[id];
}
if (check)
{
throw new Exception($"WorldConfig not find {id} Id");
}
return null;
}
public bool TryGet(uint id, out WorldConfig config)
{
config = null;
if (!_configs.ContainsKey(id))
{
return false;
}
config = _configs[id];
return true;
}
public override void AfterDeserialization()
{
for (var i = 0; i < List.Count; i++)
{
WorldConfig config = List[i];
_configs.Add(config.Id, config);
config.AfterDeserialization();
}
base.AfterDeserialization();
}
public void Dispose()
{
Instance = null;
}
}
[ProtoContract]
public sealed partial class WorldConfig : AProto
{
[ProtoMember(1, IsRequired = true)]
public uint Id { get; set; } // Id
[ProtoMember(2, IsRequired = true)]
public string WorldName { get; set; } // 名称
[ProtoMember(3, IsRequired = true)]
public string DbConnection { get; set; } // 连接字符串
[ProtoMember(4, IsRequired = true)]
public string DbName { get; set; } // 数据库名称
[ProtoMember(5, IsRequired = true)]
public string DbType { get; set; } // 数据库类型
[ProtoMember(6, IsRequired = true)]
public bool IsGameWorld { get; set; } // 是否游戏服
}
}

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 34d6b1a4a6ca2eb4390f6ce02c611461
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
using System.Collections.Generic;
namespace TEngine
{
// 生成器自动生成,请不要手动编辑。
public class SceneType
{
public const int Gate = 1;
public const int Addressable = 2;
public const int Map = 3;
public const int Chat = 4;
public static readonly Dictionary<string, int> SceneDic = new Dictionary<string, int>()
{
{ "Gate", 1 },
{ "Addressable", 2 },
{ "Map", 3 },
{ "Chat", 4 },
};
}
}

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fb7989dfa4f501845a696744157d57b2
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
using ProtoBuf;
using Unity.Mathematics;
using System.Collections.Generic;
using TEngine.Core.Network;
#pragma warning disable CS8618
namespace TEngine
{
}

View File

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

View File

@@ -0,0 +1,6 @@
namespace TEngine
{
public static partial class InnerBsonOpcode
{
}
}

View File

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

View File

@@ -0,0 +1,31 @@
using ProtoBuf;
using Unity.Mathematics;
using System.Collections.Generic;
using TEngine.Core.Network;
#pragma warning disable CS8618
namespace TEngine
{
/// <summary>
/// Gate跟Map服务器进行通讯、注册Address协议
/// </summary>
[ProtoContract]
public partial class I_G2M_LoginAddressRequest : AProto, IRouteRequest
{
[ProtoIgnore]
public I_M2G_LoginAddressResponse ResponseType { get; set; }
public uint OpCode() { return InnerOpcode.I_G2M_LoginAddressRequest; }
public long RouteTypeOpCode() { return CoreRouteType.Route; }
[ProtoMember(1)]
public long AddressId { get; set; }
[ProtoMember(2)]
public long GateRouteId { get; set; }
}
[ProtoContract]
public partial class I_M2G_LoginAddressResponse : AProto, IRouteResponse
{
public uint OpCode() { return InnerOpcode.I_M2G_LoginAddressResponse; }
[ProtoMember(91, IsRequired = true)]
public int ErrorCode { get; set; }
}
}

View File

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

View File

@@ -0,0 +1,8 @@
namespace TEngine
{
public static partial class InnerOpcode
{
public const int I_G2M_LoginAddressRequest = 220001001;
public const int I_M2G_LoginAddressResponse = 260001001;
}
}

View File

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

View File

@@ -0,0 +1,157 @@
using ProtoBuf;
using Unity.Mathematics;
using System.Collections.Generic;
using TEngine.Core.Network;
#pragma warning disable CS8618
namespace TEngine
{
/// <summary>
/// 发送一个消息到Gate服务器
/// </summary>
[ProtoContract]
public partial class H_C2G_Message : AProto, IMessage
{
public uint OpCode() { return OuterOpcode.H_C2G_Message; }
[ProtoMember(1)]
public string Message { get; set; }
}
/// <summary>
/// 发送一个RPC消息到Gate服务器
/// </summary>
[ProtoContract]
public partial class H_C2G_MessageRequest : AProto, IRequest
{
[ProtoIgnore]
public H_G2C_MessageResponse ResponseType { get; set; }
public uint OpCode() { return OuterOpcode.H_C2G_MessageRequest; }
[ProtoMember(1)]
public string Message { get; set; }
}
[ProtoContract]
public partial class H_G2C_MessageResponse : AProto, IResponse
{
public uint OpCode() { return OuterOpcode.H_G2C_MessageResponse; }
[ProtoMember(91, IsRequired = true)]
public int ErrorCode { get; set; }
[ProtoMember(1)]
public string Message { get; set; }
}
/// <summary>
/// 发送一个消息通知服务器给客户端推送一个消息
/// </summary>
[ProtoContract]
public partial class H_C2G_PushMessageToClient : AProto, IMessage
{
public uint OpCode() { return OuterOpcode.H_C2G_PushMessageToClient; }
[ProtoMember(1)]
public string Message { get; set; }
}
/// <summary>
/// 客户端接收服务器推送的一条消息
/// </summary>
[ProtoContract]
public partial class H_G2C_ReceiveMessageToServer : AProto, IMessage
{
public uint OpCode() { return OuterOpcode.H_G2C_ReceiveMessageToServer; }
[ProtoMember(1)]
public string Message { get; set; }
}
/// <summary>
/// 注册Address消息
/// </summary>
[ProtoContract]
public partial class H_C2G_LoginAddressRequest : AProto, IRequest
{
[ProtoIgnore]
public H_G2C_LoginAddressResponse ResponseType { get; set; }
public uint OpCode() { return OuterOpcode.H_C2G_LoginAddressRequest; }
[ProtoMember(1)]
public string Message { get; set; }
}
[ProtoContract]
public partial class H_G2C_LoginAddressResponse : AProto, IResponse
{
public uint OpCode() { return OuterOpcode.H_G2C_LoginAddressResponse; }
[ProtoMember(91, IsRequired = true)]
public int ErrorCode { get; set; }
}
/// <summary>
/// 发送一个Address消息给Map
/// </summary>
[ProtoContract]
public partial class H_C2M_Message : AProto, IAddressableRouteMessage
{
public uint OpCode() { return OuterOpcode.H_C2M_Message; }
public long RouteTypeOpCode() { return CoreRouteType.Addressable; }
[ProtoMember(1)]
public string Message { get; set; }
}
/// <summary>
/// 发送一个AddressRPC消息给Map
/// </summary>
[ProtoContract]
public partial class H_C2M_MessageRequest : AProto, IAddressableRouteRequest
{
[ProtoIgnore]
public H_M2C_MessageResponse ResponseType { get; set; }
public uint OpCode() { return OuterOpcode.H_C2M_MessageRequest; }
public long RouteTypeOpCode() { return CoreRouteType.Addressable; }
[ProtoMember(1)]
public string Message { get; set; }
}
[ProtoContract]
public partial class H_M2C_MessageResponse : AProto, IAddressableRouteResponse
{
public uint OpCode() { return OuterOpcode.H_M2C_MessageResponse; }
[ProtoMember(91, IsRequired = true)]
public int ErrorCode { get; set; }
[ProtoMember(1)]
public string Message { get; set; }
}
/// <summary>
/// 发送一个消息通知服务器给客户端推送一个Address消息
/// </summary>
[ProtoContract]
public partial class H_C2M_PushAddressMessageToClient : AProto, IAddressableRouteMessage
{
public uint OpCode() { return OuterOpcode.H_C2M_PushAddressMessageToClient; }
public long RouteTypeOpCode() { return CoreRouteType.Addressable; }
[ProtoMember(1)]
public string Message { get; set; }
}
/// <summary>
/// 客户端接收服务器推送的一条Address消息
/// </summary>
[ProtoContract]
public partial class H_M2C_ReceiveAddressMessageToServer : AProto, IAddressableRouteMessage
{
public uint OpCode() { return OuterOpcode.H_M2C_ReceiveAddressMessageToServer; }
public long RouteTypeOpCode() { return CoreRouteType.Addressable; }
[ProtoMember(1)]
public string Message { get; set; }
}
/// <summary>
/// 客户端发送消息请求登录服务器
/// </summary>
[ProtoContract]
public partial class H_C2G_LoginRequest : AProto, IRequest
{
[ProtoIgnore]
public H_G2C_LoginResponse ResponseType { get; set; }
public uint OpCode() { return OuterOpcode.H_C2G_LoginRequest; }
[ProtoMember(1)]
public string UserName { get; set; }
[ProtoMember(2)]
public string Password { get; set; }
}
[ProtoContract]
public partial class H_G2C_LoginResponse : AProto, IResponse
{
public uint OpCode() { return OuterOpcode.H_G2C_LoginResponse; }
[ProtoMember(91, IsRequired = true)]
public int ErrorCode { get; set; }
[ProtoMember(1)]
public string Text { get; set; }
}
}

View File

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

View File

@@ -0,0 +1,20 @@
namespace TEngine
{
public static partial class OuterOpcode
{
public const int H_C2G_Message = 100000001;
public const int H_C2G_MessageRequest = 110000001;
public const int H_G2C_MessageResponse = 160000001;
public const int H_C2G_PushMessageToClient = 100000002;
public const int H_G2C_ReceiveMessageToServer = 100000003;
public const int H_C2G_LoginAddressRequest = 110000002;
public const int H_G2C_LoginAddressResponse = 160000002;
public const int H_C2M_Message = 190000001;
public const int H_C2M_MessageRequest = 200000001;
public const int H_M2C_MessageResponse = 250000001;
public const int H_C2M_PushAddressMessageToClient = 190000002;
public const int H_M2C_ReceiveAddressMessageToServer = 190000003;
public const int H_C2G_LoginRequest = 110000003;
public const int H_G2C_LoginResponse = 160000003;
}
}

View File

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

View File

@@ -0,0 +1,8 @@
namespace TEngine.Core.Network
{
// Route协议定义(需要定义1000以上、因为1000以内的框架预留)
public enum RouteType : long
{
ChatRoute = 1001, // 聊天服协议
}
}

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b1677506e5cd7b347b38dd75ee4d0706
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f4621a08083c52d4a8b1a1b81e8cbef7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
#if TENGINE_NET
using TEngine.Core.Network;
using TEngine.Core;
namespace TEngine.Logic;
public class H_C2M_MessageHandler : Addressable<Unit,H_C2M_Message>
{
protected override async FTask Run(Unit unit, H_C2M_Message message)
{
Log.Debug($"接收到一个Address消息 Unit:{unit.Id} message:{message.ToJson()}");
await FTask.CompletedTask;
}
}
#endif

View File

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

View File

@@ -0,0 +1,16 @@
#if TENGINE_NET
using TEngine.Core.Network;
using TEngine.Core;
namespace TEngine.Logic;
public class H_C2M_MessageRequestHandler : AddressableRPC<Unit, H_C2M_MessageRequest, H_M2C_MessageResponse>
{
protected override async FTask Run(Unit unit, H_C2M_MessageRequest request, H_M2C_MessageResponse response, Action reply)
{
Log.Debug($"接收到一个AddressRPC消息 Unit:{unit.Id} message:{request.ToJson()}");
response.Message = "来自MAP服务器发送的消息";
await FTask.CompletedTask;
}
}
#endif

View File

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

View File

@@ -0,0 +1,21 @@
#if TENGINE_NET
using TEngine.Core.Network;
using TEngine.Core;
namespace TEngine.Logic;
public class H_C2M_PushAddressMessageToClientHandler : Addressable<Unit, H_C2M_PushAddressMessageToClient>
{
protected override async FTask Run(Unit unit, H_C2M_PushAddressMessageToClient message)
{
Log.Debug($"接收到一个Address消息 Unit:{unit.Id} message:{message.ToJson()}");
// 发过主动推送给客户端、首先要只要Unit在Gate的RouteId、然后才可以发送
// 这个Route在I_G2M_LoginAddressRequest、也就是注册Address的时候已经记录了
MessageHelper.SendInnerRoute(unit.Scene, unit.GateRouteId, new H_M2C_ReceiveAddressMessageToServer()
{
Message = message.Message
});
await FTask.CompletedTask;
}
}
#endif

View File

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

View File

@@ -0,0 +1,55 @@
#if TENGINE_NET
using TEngine.Core.Network;
namespace TEngine.Logic;
public class H_C2G_LoginAddressRequestHandler : MessageRPC<H_C2G_LoginAddressRequest, H_G2C_LoginAddressResponse>
{
protected override async FTask Run(Session session, H_C2G_LoginAddressRequest request, H_G2C_LoginAddressResponse response, Action reply)
{
// 什么是可寻址消息
// 此服务器是一个分布式框架、所以肯定会有多个服务器相互通信
// 游戏里一个玩家这里统称Unit、随着游戏场景的越来越多、为了让游戏服务器能承载更多人
// 所以大家都会把服务器给分成多个、比如一个地图一个服务器、从而能提升服务器的负载能力、也更方便开发、类似微服务
// 但这样就会有几个问题出现了:
// 1、客户端是直接连接到服务器、如果切换服务器的时候客户端就会掉线、怎么解决不让用户掉线
// 2、从A服务器到B服务器后、如果能正常发送到B服务器而不是发送到A服务器中
// 为了解决上面的问题、大多服务器架构都采用了一个中专服务器Gate来收发消息
// 比如客户端一直连接的一个服务器这里统称Gate
// 那网络通讯的管道模型是客户端->Gate->其他服务器、客户端接收消息是其他服务器->Gate->客户端
// 这样的好处是无论玩家在什么服务器只需要改变Gate到其他服务器的连接就可以了、中间客户端是一直连接到Gate的所以客户端不会掉线
// 这个问题解决了、但还有一个问题就是Gate跟其他服务器的连接会随着玩家的逻辑变动
// 所以框架提供的可寻址消息Address消息、使用Address消息后会自动寻找到Unit的正确位置并发送到、不需要开发者再处理这个逻辑了
// 下面就是一个例子
// 1、首选分配一个可用、负载比较低的服务器给这个Unit、我这里就在ServerConfig.xsl表里拿一个MAP了、但实际开发过程可能比这个要复杂
// 我这里就简单些一个做为演示、其实这些逻辑开发者完全可以自己封装一个接口来做。
// 在ServerConfig.xsl里找到MAP的进程、看到ID是3072通过这个Id在SceneConfig.xsl里找到对应的Scene的EntityId
var sceneEntityId = 0L;
foreach (var sceneConfig in SceneConfigData.Instance.List)
{
if (sceneConfig.RouteId == 3072)
{
sceneEntityId = sceneConfig.EntityId;
break;
}
continue;
}
// 2、在InnerMessage里定义一个协议、用于Gate跟Map通讯的协议I_G2M_LoginAddress
var loginAddressResponse = (I_M2G_LoginAddressResponse)await MessageHelper.CallInnerRoute(session.Scene,
sceneEntityId,
new I_G2M_LoginAddressRequest()
{
AddressId = session.Id,
GateRouteId = session.RuntimeId,
});
if (loginAddressResponse.ErrorCode != 0)
{
Log.Error($"注册到Map的Address发生错误 ErrorCode:{loginAddressResponse.ErrorCode}");
return;
}
// 3、可寻址消息组件、挂载了这个组件可以接收和发送Addressable消息
session.AddComponent<AddressableRouteComponent>();
}
}
#endif

View File

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

View File

@@ -0,0 +1,18 @@
#if TENGINE_NET
using System;
using TEngine.Core.Network;
using TEngine.Core;
namespace TEngine.Logic
{
public class H_C2G_LoginRequestHandler : MessageRPC<H_C2G_LoginRequest,H_G2C_LoginResponse>
{
protected override async FTask Run(Session session, H_C2G_LoginRequest request, H_G2C_LoginResponse response, Action reply)
{
Log.Debug($"收到请求登录的消息 request:{request.ToJson()}");
response.Text = "登录成功";
await FTask.CompletedTask;
}
}
}
#endif

View File

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

View File

@@ -0,0 +1,16 @@
#if TENGINE_NET
using TEngine.Core.Network;
using TEngine.Core;
namespace TEngine.Logic
{
public class H_C2G_MessageHandler : Message<H_C2G_Message>
{
protected override async FTask Run(Session session, H_C2G_Message message)
{
Log.Debug($"接收到消息 H_C2G_Message:{message.ToJson()}");
await FTask.CompletedTask;
}
}
}
#endif

View File

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

View File

@@ -0,0 +1,18 @@
#if TENGINE_NET
using TEngine.Core.Network;
using TEngine.Core;
namespace TEngine.Logic;
public class H_C2G_MessageRequestHandler : MessageRPC<H_C2G_MessageRequest,H_G2C_MessageResponse>
{
protected override async FTask Run(Session session, H_C2G_MessageRequest request, H_G2C_MessageResponse response, Action reply)
{
// 这里是接收到客户端发送的消息
Log.Debug($"接收到RPC消息 H_C2G_MessageRequest:{request.ToJson()}");
// response是要给客户端返回的消息、数据结构是在proto文件里定义的
response.Message = "Hello world您现在收到的消息是一个RPC消息";
await FTask.CompletedTask;
}
}
#endif

View File

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

View File

@@ -0,0 +1,20 @@
#if TENGINE_NET
using TEngine.Core.Network;
using TEngine.Core;
namespace TEngine.Logic;
public class H_C2G_PushMessageToClientHandler : Message<H_C2G_PushMessageToClient>
{
protected override async FTask Run(Session session, H_C2G_PushMessageToClient message)
{
Log.Debug($"接收到客户端发送给服务器的请求推送消息:{message.ToJson()}");
// 服务器主动推送给客户端消息
session.Send(new H_G2C_ReceiveMessageToServer()
{
Message = "这个是服务器推送给客户端的消息"
});
await FTask.CompletedTask;
}
}
#endif

View File

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

View File

@@ -0,0 +1,46 @@
#if TENGINE_NET
using System;
using System.Collections.Generic;
using TEngine.Core.Network;
namespace TEngine.Logic
{
public class Unit : Entity
{
public long GateRouteId;
}
public static class AddressManage
{
public static readonly Dictionary<long, Unit> Units = new Dictionary<long, Unit>();
public static Unit Add(Scene scene, long addressId, long gateRouteId)
{
var unit = Entity.Create<Unit>(scene, addressId);
unit.GateRouteId = gateRouteId;
Units.Add(unit.Id, unit);
return unit;
}
public static Unit? Get(long addressId)
{
return Units.TryGetValue(addressId, out var unit) ? unit : null;
}
}
public class I_G2M_LoginAddressRequestHandler : RouteRPC<Scene,I_G2M_LoginAddressRequest,I_M2G_LoginAddressResponse>
{
protected override async FTask Run(Scene scene, I_G2M_LoginAddressRequest request, I_M2G_LoginAddressResponse response, Action reply)
{
// 现在这里是MAP服务器了、玩家进入这里如果是首次进入会有玩家的所有信息
// 一般这个信息是数据库里拿到或者其他服务器给传递过来了、这里主要演示怎么注册Address、所以这些步骤这里就不做了
// 这里我就模拟一个假的Unit数据使用
// 1、首先创建一个Unit
var unit = AddressManage.Add(scene, request.AddressId, request.GateRouteId);
// 2、挂在AddressableMessageComponent组件、让这个Unit支持Address、并且会自动注册到网格中
await unit.AddComponent<AddressableMessageComponent>().Register();
await FTask.CompletedTask;
}
}
}
#endif

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9b231e7229fc3744cbe27ad320c6fb4f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
#if TENGINE_NET
using TEngine.Core;
#pragma warning disable CS8603
namespace TEngine;
/// <summary>
/// 整个框架使用的程序集、有几个程序集就定义集。这里定义是为了后面方面使用
/// </summary>
public static class AssemblyName
{
public const int Hotfix = 1;
}
public static class AssemblySystem
{
public static void Init()
{
LoadHotfix();
}
public static void LoadHotfix()
{
AssemblyManager.Load(AssemblyName.Hotfix, typeof(AssemblySystem).Assembly);
}
}
#endif

View File

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

View File

@@ -0,0 +1,139 @@
#if TENGINE_NET
using TEngine.Core;
using TEngine.Core.DataBase;
#pragma warning disable CS8603
namespace TEngine.Logic;
public static class ConfigTableSystem
{
public static void Bind()
{
// 框架需要一些的配置文件来启动服务器和创建网络服务所以需要ServerConfig.xlsx和MachineConfig.xlsx的配置
// 由于配置表的代码是生成在框架外面的、框架没办法直接获取到配置文件
// 考虑到这两个配置文件开发者可能会修改结构、所以提供了一个委托来让开发者开自己定义如何获取框架需要的东西
// 本来想提供一个接口让玩家把ServerConfig和MachineConfig添加到框架中、但这样就不支持热更
// 提供委托方式就可以支持配置表热更。因为配置表读取本就是支持热更的
// 虽然这块稍微麻烦点、但好在配置一次以后基本不会改动、后面有更好的办法我会把这个给去掉
ConfigTableManage.ServerConfig = serverId =>
{
if (!ServerConfigData.Instance.TryGet(serverId, out var serverConfig))
{
return null;
}
return new ServerConfigInfo()
{
Id = serverConfig.Id,
InnerPort = serverConfig.InnerPort,
MachineId = serverConfig.MachineId
};
};
ConfigTableManage.MachineConfig = machineId =>
{
if (!MachineConfigData.Instance.TryGet(machineId, out var machineConfig))
{
return null;
}
return new MachineConfigInfo()
{
Id = machineConfig.Id,
OuterIP = machineConfig.OuterIP,
OuterBindIP = machineConfig.OuterBindIP,
InnerBindIP = machineConfig.InnerBindIP,
ManagementPort = machineConfig.ManagementPort
};
};
ConfigTableManage.WorldConfigInfo = worldId =>
{
if (!WorldConfigData.Instance.TryGet(worldId, out var worldConfig))
{
return null;
}
return new WorldConfigInfo()
{
Id = worldConfig.Id,
WorldName = worldConfig.WorldName,
DbConnection = worldConfig.DbConnection,
DbName = worldConfig.DbName,
DbType = worldConfig.DbType
};
};
ConfigTableManage.SceneConfig = sceneId =>
{
if (!SceneConfigData.Instance.TryGet(sceneId, out var sceneConfig))
{
return null;
}
return new SceneConfigInfo()
{
Id = sceneConfig.Id,
SceneType = sceneConfig.SceneType,
Name = sceneConfig.Name,
NetworkProtocol = sceneConfig.NetworkProtocol,
RouteId = sceneConfig.RouteId,
WorldId = sceneConfig.WorldId,
OuterPort = sceneConfig.OuterPort
};
};
ConfigTableManage.AllServerConfig = () =>
{
var list = new List<ServerConfigInfo>();
foreach (var serverConfig in ServerConfigData.Instance.List)
{
list.Add(new ServerConfigInfo()
{
Id = serverConfig.Id,
InnerPort = serverConfig.InnerPort,
MachineId = serverConfig.MachineId
});
}
return list;
};
ConfigTableManage.AllMachineConfig = () =>
{
var list = new List<MachineConfigInfo>();
foreach (var machineConfig in MachineConfigData.Instance.List)
{
list.Add(new MachineConfigInfo()
{
Id = machineConfig.Id,
OuterIP = machineConfig.OuterIP,
OuterBindIP = machineConfig.OuterBindIP,
InnerBindIP = machineConfig.InnerBindIP,
ManagementPort = machineConfig.ManagementPort
});
}
return list;
};
ConfigTableManage.AllSceneConfig = () =>
{
var list = new List<SceneConfigInfo>();
foreach (var sceneConfig in SceneConfigData.Instance.List)
{
list.Add(new SceneConfigInfo()
{
Id = sceneConfig.Id,
EntityId = sceneConfig.EntityId,
SceneType = sceneConfig.SceneType,
Name = sceneConfig.Name,
NetworkProtocol = sceneConfig.NetworkProtocol,
RouteId = sceneConfig.RouteId,
WorldId = sceneConfig.WorldId,
OuterPort = sceneConfig.OuterPort
});
}
return list;
};
}
}
#endif

View File

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

View File

@@ -0,0 +1,32 @@
#if TENGINE_NET
using TEngine.Core.Network;
namespace TEngine.Logic;
/// <summary>
/// 当Scene创建时需要干什么
/// </summary>
public class OnCreateScene : AsyncEventSystem<TEngine.OnCreateScene>
{
public override async FTask Handler(TEngine.OnCreateScene self)
{
// 服务器是以Scene为单位的、所以Scene下有什么组件都可以自己添加定义
// OnCreateScene这个事件就是给开发者使用的
// 比如Address协议这里、我就是做了一个管理Address地址的一个组件挂在到Address这个Scene下面了
// 比如Map下你需要一些自定义组件、你也可以在这里操作
var sceneConfigInfo = self.SceneInfo;
switch (sceneConfigInfo.SceneType)
{
case "Addressable":
{
sceneConfigInfo.Scene.AddComponent<AddressableManageComponent>();
break;
}
}
Log.Info($"scene create: {self.SceneInfo.SceneType} {self.SceneInfo.Name} SceneId:{self.SceneInfo.Id} ServerId:{self.SceneInfo.RouteId} WorldId:{self.SceneInfo.WorldId}");
await FTask.CompletedTask;
}
}
#endif

View File

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