public void AddListener(string key, HandleMsg handle) { if (m_Handler.ContainsKey(key)) { m_Handler.Remove(key); } m_Handler.Add(key, handle); }
// 注册消息处理函数 public bool RegisterMsgHanle(UInt16 msgCmd, HandleMsg msgHandle) { if (msgHandle == null) { Trace.Assert(false, "msgHandle is null"); return(false); } if (msgHandleDic.ContainsKey(msgCmd)) { Trace.Assert(false, "reregister cmd" + msgCmd); return(false); } msgHandleDic.Add(msgCmd, msgHandle); return(true); }
// 网络层回调函数 #region public void HandleNetMessage(UInt16 msgCmd, INetSession netSession, byte[] msgBuffer, Int32 bufferOffset, Int32 msgLength) { if (netSession == null || msgBuffer == null) { return; } if (!msgHandleDic.ContainsKey(msgCmd)) { Trace.Assert(false, "Unregister cmd : " + msgCmd); return; } HandleMsg handleFunc = msgHandleDic[msgCmd]; if (handleFunc == null) { Trace.Assert(false, msgCmd + " MsgHandle is null"); return; } // 调用消息处理函数 handleFunc(netSession, msgBuffer, bufferOffset, msgLength); }
public ServerClientUdp(string _ip, int _uid, HandleMsg handleMsgDelegate) { clientIP = _ip; userUid = _uid; this.handleMsg = handleMsgDelegate; }