protected override void Setup() { LBLogger.InitLogger(this.ApplicationRootPath, this.BinaryPath); RegisterPeerHandler(); RegisterProtocolsSerialize(); mHeartbeatFiber = new ThreadFiber(); mHeartbeatFiber.ScheduleOnInterval(UpdateTick, 0, 1); mHeartbeatFiber.Start(); mLastTick = TimeManager.Instance.CurrentTimeMs; }
public static void RegisterHandlerFunc(RqId requestId, System.Action <MyPeer, OperationRequest> invokeFunc) { byte rqIdByte = (byte)requestId; if (mPeerHandlerDic.ContainsKey(rqIdByte)) { LBLogger.Error(LogTag, "注册重复的事件处理 " + requestId.ToString()); return; } mPeerHandlerDic[rqIdByte] = invokeFunc; }
protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters) { System.Action <MyPeer, OperationRequest> invokeAction; if (mPeerHandlerDic.TryGetValue(operationRequest.OperationCode, out invokeAction)) { LBLogger.Info(LogTag, "OnOperationRequest " + ((RqId)operationRequest.OperationCode).ToString()); invokeAction.Invoke(this, operationRequest); } else { LBLogger.Error(LogTag, "消息处理没有注册 " + operationRequest.OperationCode); } }
protected override void TearDown() { LBLogger.Info("MyApplication", "游戏服务器关闭"); mHeartbeatFiber.Dispose(); mHeartbeatFiber = null; }
protected override void OnMessage(object message, SendParameters sendParameters) { LBLogger.Info(LogTag, "连接 OnMessage"); base.OnMessage(message, sendParameters); }
protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail) { LBLogger.Info(LogTag, "连接 关闭 " + ConnectionId.ToString()); LBPeerManager.Instance.RemovePeer(ConnectionId); }
public MyPeer(InitRequest initRequest) : base(initRequest) { LBLogger.Info(LogTag, "游戏服务器创建连接 " + ConnectionId.ToString()); LBPeerManager.Instance.AddPeer(ConnectionId, this); }