protected void OnRecvMsg(Deserializer reader) { short num = reader.ReadInt16(); if (num >= _maxMsgId) { Debug.LogError($" send a Error msgType out of range {num}", Array.Empty <object>()); } else { try { DealNetMsg dealNetMsg = _allMsgDealFuncs[num]; ParseNetMsg parseNetMsg = _allMsgParsers[num]; if (dealNetMsg != null && parseNetMsg != null) { dealNetMsg(parseNetMsg(reader)); } else { Debug.LogError($" ErrorMsg type :no msg handler or parser {num}", Array.Empty <object>()); } } catch (Exception arg) { Debug.LogError($" Deal Msg Error :{(EMsgSC)num} " + arg, Array.Empty <object>()); } } }
public void Init(IRoomMsgHandler msgHandler) { _maxMsgId = (byte)System.Math.Min((int)EMsgSC.EnumCount, (int)byte.MaxValue); _allMsgDealFuncs = new DealNetMsg[_maxMsgId]; _allMsgParsers = new ParseNetMsg[_maxMsgId]; Debug = new DebugInstance("Client " + ": "); RegisterMsgHandlers(); _handler = msgHandler; }
public void Init(IRoomMsgHandler msgHandler) { _maxMsgId = (byte)System.Math.Min((int)EMsgSC.EnumCount, (int)byte.MaxValue); _allMsgDealFuncs = new DealNetMsg[_maxMsgId]; _allMsgParsers = new ParseNetMsg[_maxMsgId]; RegisterMsgHandlers(); _handler = msgHandler; _netUdp = _netTcp = new NetClient();//TODO Login _netTcp.DoStart(); _netTcp.NetMsgHandler = OnNetMsg; }
private void RegisterNetMsgHandler(EMsgSC type, DealNetMsg func, ParseNetMsg parseFunc) { allMsgDealFuncs[(int)type] = func; allMsgParsers[(int)type] = parseFunc; }
private void RegisterNetMsgHandler(EMsgCL type, DealNetMsg func) { allMsgDealFuncs[(int)type] = func; }