mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] 接入ET8服务端
[+] 接入ET8服务端
This commit is contained in:
8
Assets/GameScripts/DotNet/Model/Server/Module/AOI.meta
Normal file
8
Assets/GameScripts/DotNet/Model/Server/Module/AOI.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92fbb093186ec1742acdcadde9b344b2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,51 @@
|
||||
using System.Collections.Generic;
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
[ComponentOf(typeof(Unit))]
|
||||
public class AOIEntity: Entity, IAwake<int, float3>, IDestroy
|
||||
{
|
||||
public Unit Unit => this.GetParent<Unit>();
|
||||
|
||||
public int ViewDistance;
|
||||
|
||||
private EntityRef<Cell> cell;
|
||||
|
||||
public Cell Cell
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.cell;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.cell = value;
|
||||
}
|
||||
}
|
||||
|
||||
// 观察进入视野的Cell
|
||||
public HashSet<long> SubEnterCells = new HashSet<long>();
|
||||
|
||||
// 观察离开视野的Cell
|
||||
public HashSet<long> SubLeaveCells = new HashSet<long>();
|
||||
|
||||
// 观察进入视野的Cell
|
||||
public HashSet<long> enterHashSet = new HashSet<long>();
|
||||
|
||||
// 观察离开视野的Cell
|
||||
public HashSet<long> leaveHashSet = new HashSet<long>();
|
||||
|
||||
// 我看的见的Unit
|
||||
public Dictionary<long, AOIEntity> SeeUnits = new Dictionary<long, AOIEntity>();
|
||||
|
||||
// 看见我的Unit
|
||||
public Dictionary<long, AOIEntity> BeSeeUnits = new Dictionary<long, AOIEntity>();
|
||||
|
||||
// 我看的见的Player
|
||||
public Dictionary<long, AOIEntity> SeePlayers = new Dictionary<long, AOIEntity>();
|
||||
|
||||
// 看见我的Player单独放一个Dict,用于广播
|
||||
public Dictionary<long, AOIEntity> BeSeePlayers = new Dictionary<long, AOIEntity>();
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82e4e3a5d5dabb049bf406df3ec3dbd3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,17 @@
|
||||
namespace ET.Server
|
||||
{
|
||||
namespace EventType
|
||||
{
|
||||
public struct UnitEnterSightRange
|
||||
{
|
||||
public AOIEntity A;
|
||||
public AOIEntity B;
|
||||
}
|
||||
|
||||
public struct UnitLeaveSightRange
|
||||
{
|
||||
public AOIEntity A;
|
||||
public AOIEntity B;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2fb3b7c085835bc45b9bf319fb179f8b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
namespace ET.Server
|
||||
{
|
||||
[ComponentOf(typeof(Scene))]
|
||||
public class AOIManagerComponent: Entity, IAwake
|
||||
{
|
||||
public const int CellSize = 10 * 1000;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ac4abb8f844e8543b742c9eb837c9e0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
17
Assets/GameScripts/DotNet/Model/Server/Module/AOI/Cell.cs
Normal file
17
Assets/GameScripts/DotNet/Model/Server/Module/AOI/Cell.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
[ChildOf(typeof(AOIManagerComponent))]
|
||||
public class Cell: Entity, IAwake, IDestroy
|
||||
{
|
||||
// 处在这个cell的单位
|
||||
public Dictionary<long, AOIEntity> AOIUnits = new Dictionary<long, AOIEntity>();
|
||||
|
||||
// 订阅了这个Cell的进入事件
|
||||
public Dictionary<long, AOIEntity> SubsEnterEntities = new Dictionary<long, AOIEntity>();
|
||||
|
||||
// 订阅了这个Cell的退出事件
|
||||
public Dictionary<long, AOIEntity> SubsLeaveEntities = new Dictionary<long, AOIEntity>();
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a75cc6d8fbc87d4386d2159f6ac48f2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9310265e136b6074cac1754f44280871
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,16 @@
|
||||
using System.IO;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
// 知道对方的Id,使用这个类发actor消息
|
||||
[ChildOf(typeof(ActorLocationSenderOneType))]
|
||||
public class ActorLocationSender: Entity, IAwake, IDestroy
|
||||
{
|
||||
public ActorId ActorId;
|
||||
|
||||
// 最近接收或者发送消息的时间
|
||||
public long LastSendOrRecvTime;
|
||||
|
||||
public int Error;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f63a22fae23df55448bebaaa447e1bad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
|
||||
[ChildOf(typeof(ActorLocationSenderComponent))]
|
||||
public class ActorLocationSenderOneType: Entity, IAwake<int>, IDestroy
|
||||
{
|
||||
public const long TIMEOUT_TIME = 60 * 1000;
|
||||
|
||||
public long CheckTimer;
|
||||
|
||||
public int LocationType;
|
||||
}
|
||||
|
||||
|
||||
[ComponentOf(typeof(Scene))]
|
||||
public class ActorLocationSenderComponent: Entity, IAwake
|
||||
{
|
||||
public const long TIMEOUT_TIME = 60 * 1000;
|
||||
|
||||
public long CheckTimer;
|
||||
|
||||
public ActorLocationSenderOneType[] ActorLocationSenderComponents = new ActorLocationSenderOneType[LocationType.Max];
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe4c532cd914d4ad498b494298be81b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,43 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
[UniqueId(0, 100)]
|
||||
public static class LocationType
|
||||
{
|
||||
public const int Unit = 0;
|
||||
public const int Player = 1;
|
||||
public const int Friend = 2;
|
||||
public const int Chat = 3;
|
||||
public const int GateSession = 4;
|
||||
public const int Max = 100;
|
||||
}
|
||||
|
||||
[ChildOf(typeof(LocationOneType))]
|
||||
public class LockInfo: Entity, IAwake<ActorId, CoroutineLock>, IDestroy
|
||||
{
|
||||
public ActorId LockActorId;
|
||||
|
||||
public CoroutineLock CoroutineLock
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
[ChildOf(typeof(LocationManagerComoponent))]
|
||||
public class LocationOneType: Entity, IAwake<int>
|
||||
{
|
||||
public int LocationType;
|
||||
|
||||
public readonly Dictionary<long, ActorId> locations = new();
|
||||
|
||||
public readonly Dictionary<long, LockInfo> lockInfos = new();
|
||||
}
|
||||
|
||||
[ComponentOf(typeof(Scene))]
|
||||
public class LocationManagerComoponent: Entity, IAwake
|
||||
{
|
||||
public LocationOneType[] LocationOneTypes = new LocationOneType[LocationType.Max];
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15d2e4888958d964399187bc1a29f0ec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
[ComponentOf(typeof(Scene))]
|
||||
public class LocationProxyComponent: Entity, IAwake
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33a386a4a4fc3a1428c59a2e07be246c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/GameScripts/DotNet/Model/Server/Module/DB.meta
Normal file
8
Assets/GameScripts/DotNet/Model/Server/Module/DB.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce1b81735cfec4948a4652f0ac14d0ff
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,16 @@
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
/// <summary>
|
||||
/// 用来缓存数据
|
||||
/// </summary>
|
||||
[ChildOf(typeof(DBManagerComponent))]
|
||||
public class DBComponent: Entity, IAwake<string, string, int>
|
||||
{
|
||||
public const int TaskCount = 32;
|
||||
|
||||
public MongoClient mongoClient;
|
||||
public IMongoDatabase database;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aedf41755039b6542a26efbcd0b14745
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
[ComponentOf(typeof(Scene))]
|
||||
public class DBManagerComponent: Entity, IAwake
|
||||
{
|
||||
public DBComponent[] DBComponents = new DBComponent[IdGenerater.MaxZone];
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9064bf4ba5cdd044a80e66e16b3f07f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,6 @@
|
||||
namespace ET.Server
|
||||
{
|
||||
public interface IDBCollection
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 88b90ba479aa3b748b225bddc153ba6d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/GameScripts/DotNet/Model/Server/Module/Http.meta
Normal file
8
Assets/GameScripts/DotNet/Model/Server/Module/Http.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1be6139db3006b9419935261c3d0414e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
/// <summary>
|
||||
/// http请求分发器
|
||||
/// </summary>
|
||||
[ComponentOf(typeof(Scene))]
|
||||
public class HttpComponent: Entity, IAwake<string>, IDestroy
|
||||
{
|
||||
public HttpListener Listener;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0de2584d06993846b20ba44c51b8a0b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
public class HttpDispatcher: SingletonLock<HttpDispatcher>, ISingletonAwake
|
||||
{
|
||||
private readonly Dictionary<string, Dictionary<int, IHttpHandler>> dispatcher = new();
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
World.Instance.AddSingleton<HttpDispatcher>();
|
||||
}
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
HashSet<Type> types = EventSystem.Instance.GetTypes(typeof (HttpHandlerAttribute));
|
||||
|
||||
foreach (Type type in types)
|
||||
{
|
||||
object[] attrs = type.GetCustomAttributes(typeof(HttpHandlerAttribute), false);
|
||||
if (attrs.Length == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
HttpHandlerAttribute httpHandlerAttribute = (HttpHandlerAttribute)attrs[0];
|
||||
|
||||
object obj = Activator.CreateInstance(type);
|
||||
|
||||
IHttpHandler ihttpHandler = obj as IHttpHandler;
|
||||
if (ihttpHandler == null)
|
||||
{
|
||||
throw new Exception($"HttpHandler handler not inherit IHttpHandler class: {obj.GetType().FullName}");
|
||||
}
|
||||
|
||||
if (!this.dispatcher.TryGetValue(httpHandlerAttribute.Path, out var dict))
|
||||
{
|
||||
dict = new Dictionary<int, IHttpHandler>();
|
||||
this.dispatcher.Add(httpHandlerAttribute.Path, dict);
|
||||
}
|
||||
|
||||
dict.Add((int)httpHandlerAttribute.SceneType, ihttpHandler);
|
||||
}
|
||||
}
|
||||
|
||||
public IHttpHandler Get(SceneType sceneType, string path)
|
||||
{
|
||||
return this.dispatcher[path][(int)sceneType];
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f32ee5a97327b54dad8859600342649
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,15 @@
|
||||
namespace ET.Server
|
||||
{
|
||||
public class HttpHandlerAttribute: BaseAttribute
|
||||
{
|
||||
public SceneType SceneType { get; }
|
||||
|
||||
public string Path { get; }
|
||||
|
||||
public HttpHandlerAttribute(SceneType sceneType, string path)
|
||||
{
|
||||
this.SceneType = sceneType;
|
||||
this.Path = path;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 536bf765aeb46c44e9d0618fb418c76a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,9 @@
|
||||
using System.Net;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
public interface IHttpHandler
|
||||
{
|
||||
ETTask Handle(Scene scene, HttpListenerContext context);
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 850082c851b74ff419893672cb613cf3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 28793f12e3c15f140bd4d4d713d5782d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
[ComponentOf(typeof(Scene))]
|
||||
public class ActorOuterComponent: Entity, IAwake<IPEndPoint>, IUpdate, IDestroy
|
||||
{
|
||||
public const long TIMEOUT_TIME = 40 * 1000;
|
||||
|
||||
public int RpcId;
|
||||
|
||||
public readonly Dictionary<int, ActorMessageSender> requestCallback = new();
|
||||
|
||||
public AService AService;
|
||||
|
||||
public NetworkProtocol InnerProtocol = NetworkProtocol.KCP;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11d2abb5f986c5b44b5b58bfae58908f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ET
|
||||
{
|
||||
[ComponentOf(typeof(Scene))]
|
||||
public class ActorSenderComponent: Entity, IAwake, IDestroy
|
||||
{
|
||||
public const long TIMEOUT_TIME = 40 * 1000;
|
||||
|
||||
public int RpcId;
|
||||
|
||||
public readonly Dictionary<int, ActorMessageSender> requestCallback = new();
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ecc41a2013820624bbe9d11dc8940dc8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
public abstract class MessageHandler<Request, Response>: IMHandler where Request : MessageObject, IRequest where Response : MessageObject, IResponse
|
||||
{
|
||||
protected abstract ETTask Run(Session session, Request request, Response response);
|
||||
|
||||
public void Handle(Session session, object message)
|
||||
{
|
||||
HandleAsync(session, message).Coroutine();
|
||||
}
|
||||
|
||||
private async ETTask HandleAsync(Session session, object message)
|
||||
{
|
||||
try
|
||||
{
|
||||
Request request = message as Request;
|
||||
if (request == null)
|
||||
{
|
||||
throw new Exception($"消息类型转换错误: {message.GetType().FullName} to {typeof (Request).FullName}");
|
||||
}
|
||||
|
||||
int rpcId = request.RpcId;
|
||||
long instanceId = session.InstanceId;
|
||||
|
||||
Response response = ObjectPool.Instance.Fetch<Response>();
|
||||
|
||||
try
|
||||
{
|
||||
await this.Run(session, request, response);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception);
|
||||
response.Error = ErrorCore.ERR_RpcFail;
|
||||
response.Message = exception.ToString();
|
||||
}
|
||||
|
||||
// 等回调回来,session可以已经断开了,所以需要判断session InstanceId是否一样
|
||||
if (session.InstanceId != instanceId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
response.RpcId = rpcId; // 在这里设置rpcId是为了防止在Run中不小心修改rpcId字段
|
||||
session.Send(response);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception($"解释消息失败: {message.GetType().FullName}", e);
|
||||
}
|
||||
}
|
||||
|
||||
public Type GetMessageType()
|
||||
{
|
||||
return typeof (Request);
|
||||
}
|
||||
|
||||
public Type GetResponseType()
|
||||
{
|
||||
return typeof (Response);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3881ad9cfc7dc343a107f25d5659fb1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,16 @@
|
||||
using System.Net;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
public struct NetServerComponentOnRead
|
||||
{
|
||||
public Session Session;
|
||||
public object Message;
|
||||
}
|
||||
|
||||
[ComponentOf(typeof(Scene))]
|
||||
public class NetServerComponent: Entity, IAwake<IPEndPoint>, IDestroy, IUpdate
|
||||
{
|
||||
public AService AService;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d26c818710bffb459fecf60387869b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89b0725638d94c1e9c36b262da2e447c
|
||||
timeCreated: 1688535488
|
@@ -0,0 +1,75 @@
|
||||
using MemoryPack;
|
||||
|
||||
namespace ET
|
||||
{
|
||||
[Message(1)]
|
||||
public class A2NetInner_Message: MessageObject, IActorMessage
|
||||
{
|
||||
public static A2NetInner_Message Create()
|
||||
{
|
||||
return ObjectPool.Instance.Fetch(typeof(A2NetInner_Message)) as A2NetInner_Message;
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
this.FromAddress = default;
|
||||
this.ActorId = default;
|
||||
|
||||
ObjectPool.Instance.Recycle(this);
|
||||
}
|
||||
|
||||
public Address FromAddress;
|
||||
public ActorId ActorId;
|
||||
public IActorMessage MessageObject;
|
||||
}
|
||||
|
||||
[Message(2)]
|
||||
[ResponseType(nameof(A2NetInner_Response))]
|
||||
public class A2NetInner_Request: MessageObject, IActorRequest
|
||||
{
|
||||
public static A2NetInner_Request Create()
|
||||
{
|
||||
return ObjectPool.Instance.Fetch(typeof(A2NetInner_Request)) as A2NetInner_Request;
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
this.RpcId = default;
|
||||
this.ActorId = default;
|
||||
this.MessageObject = default;
|
||||
this.NeedException = default;
|
||||
|
||||
ObjectPool.Instance.Recycle(this);
|
||||
}
|
||||
|
||||
public int RpcId { get; set; }
|
||||
public ActorId ActorId;
|
||||
public bool NeedException;
|
||||
public IActorRequest MessageObject;
|
||||
}
|
||||
|
||||
[Message(3)]
|
||||
public class A2NetInner_Response: MessageObject, IActorResponse
|
||||
{
|
||||
public static A2NetInner_Response Create()
|
||||
{
|
||||
return ObjectPool.Instance.Fetch(typeof(A2NetInner_Response)) as A2NetInner_Response;
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
this.RpcId = default;
|
||||
this.Error = default;
|
||||
this.Message = default;
|
||||
|
||||
ObjectPool.Instance.Recycle(this);
|
||||
}
|
||||
|
||||
public int Error { get; set; }
|
||||
public string Message { get; set; }
|
||||
public int RpcId { get; set; }
|
||||
|
||||
public IActorResponse MessageObject;
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 49cfb0bef9f14131b988f817eff4313b
|
||||
timeCreated: 1688535429
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 45a2289132188ea4783d8a7858cf50ad
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
[ChildOf(typeof(RobotCaseComponent))]
|
||||
public class RobotCase: Entity, IAwake, IDestroy
|
||||
{
|
||||
public ETCancellationToken CancellationToken;
|
||||
public string CommandLine;
|
||||
public HashSet<long> Scenes { get; } = new HashSet<long>();
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9f8ce7fbba8b27458372ab3ff3c0e7f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
|
||||
[ComponentOf(typeof(Scene))]
|
||||
public class RobotCaseComponent: Entity, IAwake, IDestroy
|
||||
{
|
||||
public Dictionary<int, RobotCase> RobotCases = new Dictionary<int, RobotCase>();
|
||||
public int N = 10000;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75c6bd85c92893d4e82e087a5b65e8d8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
namespace ET.Server
|
||||
{
|
||||
public struct RobotInvokeArgs
|
||||
{
|
||||
public Fiber Fiber { get; set; }
|
||||
public string Content { get; set; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f570483ab9a6f8458ab9346fa863a63
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,27 @@
|
||||
namespace ET.Server
|
||||
{
|
||||
public static class RobotLog
|
||||
{
|
||||
#if DOTNET
|
||||
public static void Debug(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
|
||||
{
|
||||
Logger.Instance.Debug(message.ToStringAndClear());
|
||||
}
|
||||
|
||||
public static void Console(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
|
||||
{
|
||||
Logger.Instance.Console(message.ToStringAndClear());
|
||||
}
|
||||
#endif
|
||||
|
||||
public static void Debug(string msg)
|
||||
{
|
||||
Logger.Instance.Debug(msg);
|
||||
}
|
||||
|
||||
public static void Console(string msg)
|
||||
{
|
||||
Logger.Instance.Console(msg);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d2320c977663dc45b2fa20ca780ae4d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd01ac0fb84bbf64db1fcba8deb29db6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
|
||||
[ComponentOf(typeof(Scene))]
|
||||
public class RouterComponent: Entity, IAwake<IPEndPoint, string>, IDestroy, IUpdate
|
||||
{
|
||||
public Socket OuterSocket;
|
||||
public Socket InnerSocket;
|
||||
public EndPoint IPEndPoint = new IPEndPoint(IPAddress.Any, 0);
|
||||
|
||||
public byte[] Cache = new byte[1500];
|
||||
|
||||
public Dictionary<uint, RouterNode> ConnectIdNodes = new Dictionary<uint, RouterNode>();
|
||||
|
||||
// 已经连接成功的,虽然跟id一样,但是没有经过验证的不会加到这里
|
||||
public Dictionary<uint, RouterNode> OuterNodes = new Dictionary<uint, RouterNode>();
|
||||
|
||||
public long LastCheckTime = 0;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aedecff0d33048948a8204f5397a9530
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,36 @@
|
||||
using System.Net;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
public enum RouterStatus
|
||||
{
|
||||
Sync,
|
||||
Msg,
|
||||
}
|
||||
|
||||
[ChildOf(typeof(RouterComponent))]
|
||||
public class RouterNode: Entity, IDestroy, IAwake
|
||||
{
|
||||
public uint ConnectId;
|
||||
public string InnerAddress;
|
||||
public IPEndPoint InnerIpEndPoint;
|
||||
public IPEndPoint OuterIpEndPoint;
|
||||
public IPEndPoint SyncIpEndPoint;
|
||||
public uint OuterConn;
|
||||
public uint InnerConn;
|
||||
public long LastRecvOuterTime;
|
||||
public long LastRecvInnerTime;
|
||||
|
||||
public int RouterSyncCount;
|
||||
public int SyncCount;
|
||||
|
||||
#region 限制外网消息数量,一秒最多50个包
|
||||
|
||||
public long LastCheckTime;
|
||||
public int LimitCountPerSecond;
|
||||
|
||||
#endregion
|
||||
|
||||
public RouterStatus Status;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e639e9551604860489a87b4cc5642ba4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user