123456789101112131415161718192021222324252627282930 |
- using System;
- using Cysharp.Threading.Tasks;
- namespace KYFramework.Network
- {
- public abstract class AMHandler<Message> : IMHandler where Message : class
- {
- protected abstract UniTask Run(Session session, Message message);
- public Type GetMessageType()
- {
- return typeof(Message);
- }
- public void Handle(Session session, object msg)
- {
- Message message = msg as Message;
- if (message == null)
- {
- Log.Error($"消息类型转换错误: {msg.GetType().Name} to {typeof(Message).Name}");
- return;
- }
- if (session.IsDisposed)
- {
- Log.Error($"session disconnect {msg}");
- return;
- }
- this.Run(session, message).Forget();
- }
- }
- }
|