using System; using System.Collections.Generic; using System.Net.Sockets; using System.Reflection; using DotRecast.Core.Collections; using Google.Protobuf; using Plugins.JNGame.Network.Entity; using Plugins.JNGame.Network.Util; using Plugins.JNGame.System; using Plugins.JNGame.Util; namespace Plugins.JNGame.Network { public class JNServerParam { public string Client; public byte[] Message; } /// /// 基础服务端网络类 /// public abstract class JNServerBase : SystemBase { //消息Id protected int _id = 0; //创建通知 protected EventDispatcher _event = new(); //计入字节大小 protected Dictionary _byteSize = new(); /// /// 监听服务端事件 /// /// /// public void AddListener(int hId,Action listener) { _event.AddListener($"{hId}",listener); } /// /// 发送消息 /// /// /// public void Dispatch(int hId,JNServerParam data) { _event.Dispatch($"{hId}",data); } //获取字节大小 public int GetByteSize(int hId = 0) { if (hId == 0) { int size = 0; try { _byteSize.ForEach(child => { size += child.Value; }); } catch (Exception e) { // ignored } return size; } return _byteSize.GetValueOrDefault(hId, 0); } } }