/// <summary> /// Do not use, for interfacing with Water Mod /// </summary> private void ModHandler(object data) { if (data == null) { return; } if (data is byte[]) { Waters = MyAPIGateway.Utilities.SerializeFromBinary <List <Water> >((byte[])data); if (Waters == null) { Waters = new List <Water>(); } else { foreach (var water in Waters) { MyEntity entity = MyEntities.GetEntityById(water.planetID); if (entity != null) { water.planet = MyEntities.GetEntityById(water.planetID) as MyPlanet; } } } int count = Waters.Count; RecievedData?.Invoke(); if (count > Waters.Count) { WaterCreatedEvent?.Invoke(); } if (count < Waters.Count) { WaterRemovedEvent?.Invoke(); } } if (!Registered) { Registered = true; OnRegisteredEvent?.Invoke(); } if (data is int && (int)data != ModAPIVersion) { MyLog.Default.WriteLine("Water API V" + ModAPIVersion + " for " + ModName + " is outdated, expected V" + (int)data); MyAPIGateway.Utilities.ShowMessage(ModName, "Water API V" + ModAPIVersion + " is outdated, expected V" + (int)data); } }
private async void ListenForData() { byte[] buffer = new byte[256]; while (client.Connected) { int nBytesRead = await stream.ReadAsync(buffer); int available = client.Available; byte[] data = new byte[available + nBytesRead]; Array.Copy(buffer, data, nBytesRead); if (stream.DataAvailable) { _ = await stream.ReadAsync(data, nBytesRead, available); } byte[] decryptedData = DecryptByte(data, _Key); RecievedData?.Invoke(this, decryptedData); } }