/** * Builds initial new block from raw data. */ public DataBlock(ushort version, long time, DataBlockFunction function, string body) { this.version = version; this.time = time; this.function = function; this.body = body; }
private void DatablockProcess(string[] data, DataBlock dataBlock) { // -- Function DataBlockFunction function = dataBlock.function; switch (function) { case DataBlockFunction.Event_4001_Spawn: Logger.Log(LogLevel.L2_Info, "Event_4001_Spawn", "GameState.Function.Event"); long eventTime = long.Parse(data[1]); uint reqId = uint.Parse(data[2]); uint id = uint.Parse(data[4]); string obj = data[5]; float x = float.Parse(data[6]); float y = float.Parse(data[7]); float rot = float.Parse(data[8]); ushort player = ushort.Parse(data[9]); float health = float.Parse(data[10]); ushort munitions = ushort.Parse(data[11]); float fuel = float.Parse(data[12]); Unit networkObject = new Unit(id); networkObject.TimelinePositionX.Add(eventTime, x); networkObject.TimelinePositionY.Add(eventTime, y); networkObject.TimelineRotation.Add(eventTime, rot); NetworkObjectAdded(networkObject); return; } }
/** * Builds a new data block from an array of bytes gotten from GetBytes(). */ public DataBlock(byte[] datablockBytes) { /* * 2 bytes - Version * 8 bytes - Time (Timeline) * 2 bytes - Function * 2 bytes - Size (Body) * size bytes - Body */ version = BitConverter.ToUInt16(datablockBytes, 0); time = BitConverter.ToInt64(datablockBytes, 2); function = (DataBlockFunction)BitConverter.ToUInt16(datablockBytes, 10); ushort size = BitConverter.ToUInt16(datablockBytes, 12); char[] chars = new char[size]; int bytesUsed; int charsUsed; bool completed; Decoder decoder = Encoding.ASCII.GetDecoder(); decoder.Convert(datablockBytes, HEADER_SIZE, size, chars, 0, chars.Length, true, out bytesUsed, out charsUsed, out completed); StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < chars.Length; i++) { stringBuilder.Append(chars[i]); } string charString = stringBuilder.ToString(); body = charString; }