public void _OnRPCReturn(_NetRPCReturn rpcReturn) { Debugger.Assert(rpcReturn._GetRPCID() != 0); /// Call the callback. _RPCRetHandler rpcRetHandler = _rpcRetHandlers[rpcReturn._GetRPCID()]; _rpcRetHandlers.Remove(rpcReturn._GetRPCID()); if (rpcRetHandler != null) { rpcReturn.type = rpcRetHandler._CallMessage.type; rpcRetHandler._HandleRPCReturn(rpcReturn, null); } else { string msg = string.Format("Received a RPC response, but the RPC_ID {0} is invalid (not in _rpcCallMap). " + "The RPC call may be timeout or RPC response corrupted!" , rpcReturn._GetRPCID()); Debugger.LogError(msg); } }
///------------ protected void _onData(byte[] data) { try { ByteBuffer buffer = new ByteBuffer(data); NetMessage netMessage = null; /// Read the headerType first to determine which message class to use buffer.position = NetMessage.LEN_SIZE; short headerType = buffer.FReadByte(); buffer.position = 0; if (HeaderType.RPCCall == headerType) { netMessage = new NetRPCCall(); } else if (HeaderType.RPCReturn == headerType) { netMessage = new _NetRPCReturn(); } else if (HeaderType.Notify == headerType) { netMessage = new NetNotify(); } else { throw NetMessage.INVALID_HEADER_TYPE; } netMessage.Deserialize(buffer); bool needFurtherProcess = true; if (NetMessageFilter != null) { needFurtherProcess = NetMessageFilter(netMessage); } if (needFurtherProcess) { if (HeaderType.RPCCall == headerType) { Debugger.Assert(false, "Has not implement!"); } else if (HeaderType.RPCReturn == headerType) { _netRPCComponent._OnRPCReturn(netMessage as _NetRPCReturn); } else if (HeaderType.Notify == headerType) { int handlerCount = _messageDispatcher.DispatchEvent(netMessage); if (0 == handlerCount) { Debugger.LogWarning("No message handler for message type: " + netMessage.type); } } else { Debugger.Assert(false); } } } catch (Exception e) { _onFatalError(e); } }