private static NetMessage CreateRequestMessage(NetStream stream, NetMessage netMessage, List <Type> paramTypes) { int requestIndex = -1; for (int i = 0; i < paramTypes.Count; i++) { if (paramTypes[i].IsGenericType && paramTypes[i].GetGenericTypeDefinition() == typeof(NetRequest <>)) { requestIndex = i; netMessage.Parameters[i] = null; continue; } netMessage.Parameters[i] = ReadParam(stream, paramTypes[i]); } if (!stream.CanRead(16)) { return(netMessage); } ushort requestId = stream.ReadUShort(); if (requestIndex != -1) { netMessage.Parameters[requestIndex] = Activator.CreateInstance(paramTypes[requestIndex], netMessage.ViewId, requestId, stream.Connection); } else { object[] newParams = new object[paramTypes.Count + 1]; netMessage.Parameters.CopyTo(newParams, 0); newParams[newParams.Length - 1] = requestId; netMessage.Parameters = newParams; } return(netMessage); }
internal static bool CanReadMessage(NetStream stream) { return(stream.CanRead(12)); }