[+] 接入ET8服务端

[+] 接入ET8服务端
This commit is contained in:
ALEXTANG
2023-07-13 12:23:48 +08:00
parent e0be062006
commit 336d4b2eb9
1316 changed files with 130657 additions and 626 deletions

View File

@@ -0,0 +1,99 @@
using System;
namespace ET
{
public static partial class ActorHandleHelper
{
[EnableAccessEntiyChild]
public static async ETTask HandleMessage(Fiber fiber, ActorId actorId, MessageObject message)
{
await ETTask.CompletedTask;
/*
// 收到actor消息,放入actor队列
switch (message)
{
case IActorRequest iActorRequest:
{
switch (mailBoxComponent.MailboxType)
{
case MailboxType.OrderedMessage:
{
using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Mailbox, actorId.InstanceId))
{
if (entity.InstanceId != actorId.InstanceId)
{
IActorResponse response = ActorHelper.CreateResponse(iActorRequest, ErrorCore.ERR_NotFoundActor);
ActorMessageSenderComponent.Instance.Reply(actorId, response);
break;
}
await ActorMessageDispatcherComponent.Instance.Handle(entity, actorId, iActorRequest);
}
break;
}
case MailboxType.UnOrderMessageDispatcher:
{
await ActorMessageDispatcherComponent.Instance.Handle(entity, actorId, iActorRequest);
break;
}
default:
throw new Exception($"no mailboxtype: {mailBoxComponent.MailboxType} {iActorRequest}");
}
break;
}
case IActorMessage iActorMessage:
{
mailBoxComponent = Fiber.Instance.Mailboxes.Get(actorId.InstanceId);
if (mailBoxComponent == null)
{
Log.Error($"actor not found mailbox: {actorId} {iActorMessage}");
return;
}
mailBoxComponent.Add(iActorMessage as MessageObject);
switch (mailBoxComponent.MailboxType)
{
case MailboxType.OrderedMessage:
{
using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Mailbox, actorId.InstanceId))
{
if (entity.InstanceId != actorId.InstanceId)
{
break;
}
await ActorMessageDispatcherComponent.Instance.Handle(entity, actorId, iActorMessage);
}
break;
}
case MailboxType.UnOrderMessageDispatcher:
{
await ActorMessageDispatcherComponent.Instance.Handle(entity, actorId, iActorMessage);
break;
}
case MailboxType.GateSession:
{
if (entity is PlayerSessionComponent playerSessionComponent)
{
playerSessionComponent.Session?.Send(iActorMessage);
}
break;
}
default:
throw new Exception($"no mailboxtype: {mailBoxComponent.MailboxType} {iActorMessage}");
}
break;
}
}
*/
}
}
}

View File

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

View File

@@ -0,0 +1,104 @@
using System;
namespace ET
{
[EnableClass]
public abstract class ActorMessageHandler<E, Message>: IMActorHandler where E : Entity where Message : class, IActorMessage
{
protected abstract ETTask Run(E entity, Message message);
public async ETTask Handle(Entity entity, Address fromAddress, MessageObject actorMessage)
{
if (actorMessage is not Message msg)
{
Log.Error($"消息类型转换错误: {actorMessage.GetType().FullName} to {typeof (Message).Name}");
return;
}
if (entity is not E e)
{
Log.Error($"Actor类型转换错误: {entity.GetType().FullName} to {typeof (E).Name} --{typeof (Message).FullName}");
return;
}
await this.Run(e, msg);
}
public Type GetRequestType()
{
if (typeof (IActorLocationMessage).IsAssignableFrom(typeof (Message)))
{
Log.Error($"message is IActorLocationMessage but handler is AMActorHandler: {typeof (Message)}");
}
return typeof (Message);
}
public Type GetResponseType()
{
return null;
}
}
[EnableClass]
public abstract class ActorMessageHandler<E, Request, Response>: IMActorHandler where E : Entity where Request : MessageObject, IActorRequest where Response : MessageObject, IActorResponse
{
protected abstract ETTask Run(E unit, Request request, Response response);
public async ETTask Handle(Entity entity, Address fromAddress, MessageObject actorMessage)
{
try
{
if (actorMessage is not Request request)
{
Log.Error($"消息类型转换错误: {actorMessage.GetType().FullName} to {typeof (Request).Name}");
return;
}
if (entity is not E ee)
{
Log.Error($"Actor类型转换错误: {entity.GetType().FullName} to {typeof (E).FullName} --{typeof (Request).FullName}");
return;
}
int rpcId = request.RpcId;
Response response = ObjectPool.Instance.Fetch<Response>();
try
{
await this.Run(ee, request, response);
}
catch (Exception exception)
{
Log.Error(exception);
response.Error = ErrorCore.ERR_RpcFail;
response.Message = exception.ToString();
}
response.RpcId = rpcId;
entity.Root().GetComponent<ActorInnerComponent>().Reply(fromAddress, response);
}
catch (Exception e)
{
throw new Exception($"解释消息失败: {actorMessage.GetType().FullName}", e);
}
}
public Type GetRequestType()
{
if (typeof (IActorLocationRequest).IsAssignableFrom(typeof (Request)))
{
Log.Error($"message is IActorLocationMessage but handler is AMActorRpcHandler: {typeof (Request)}");
}
return typeof (Request);
}
public Type GetResponseType()
{
return typeof (Response);
}
}
}

View File

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

View File

@@ -0,0 +1,40 @@
namespace ET
{
[Invoke((long)MailBoxType.OrderedMessage)]
public class MailBoxType_OrderedMessageHandler: AInvokeHandler<MailBoxInvoker>
{
public override void Handle(MailBoxInvoker args)
{
HandleInner(args).Coroutine();
}
private static async ETTask HandleInner(MailBoxInvoker args)
{
MailBoxComponent mailBoxComponent = args.MailBoxComponent;
// 对象池回收
using MessageObject messageObject = args.MessageObject;
CoroutineLockComponent coroutineLockComponent = mailBoxComponent.CoroutineLockComponent;
if (coroutineLockComponent == null)
{
return;
}
long instanceId = mailBoxComponent.InstanceId;
using (await coroutineLockComponent.Wait(CoroutineLockType.Mailbox, mailBoxComponent.ParentInstanceId))
{
if (mailBoxComponent.InstanceId != instanceId)
{
if (messageObject is IActorRequest request)
{
IActorResponse resp = ActorHelper.CreateResponse(request, ErrorCore.ERR_NotFoundActor);
mailBoxComponent.Root().GetComponent<ActorInnerComponent>().Reply(args.FromAddress, resp);
}
return;
}
await ActorMessageDispatcherComponent.Instance.Handle(mailBoxComponent.Parent, args.FromAddress, messageObject);
}
}
}
}

View File

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

View File

@@ -0,0 +1,20 @@
namespace ET
{
[Invoke((long)MailBoxType.UnOrderedMessage)]
public class MailBoxType_UnOrderedMessageHandler: AInvokeHandler<MailBoxInvoker>
{
public override void Handle(MailBoxInvoker args)
{
HandleAsync(args).Coroutine();
}
private static async ETTask HandleAsync(MailBoxInvoker args)
{
MailBoxComponent mailBoxComponent = args.MailBoxComponent;
using MessageObject messageObject = args.MessageObject;
await ActorMessageDispatcherComponent.Instance.Handle(mailBoxComponent.Parent, args.FromAddress, messageObject);
}
}
}

View File

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