Пример #1
0
        /// <summary>
        /// This method uses a lot of memory so try to call it as less as possible and only when needed
        /// </summary>
        public void DeserializeVesselBytes()
        {
            lock (_vesselDataSyncLock)
            {
                _needToDeserializeData = false;
                var newVesselNode = ConfigNodeSerializer.Deserialize(_vesselData, _numBytes);
                if (!VesselCommon.VesselHasNaNPosition(newVesselNode))
                {
                    //In case there's a deserialization error skip it and keep the older node
                    _vesselNode = newVesselNode;
                }
                if (_vesselNode == null)
                {
                    LunaLog.LogError($"Received a malformed vessel from SERVER. Id {VesselId}");
                    VesselRemoveSystem.Singleton.KillVessel(VesselId);
                    VesselRemoveSystem.Singleton.AddToKillList(VesselId);
                    return;
                }

                var newProto = VesselCommon.CreateSafeProtoVesselFromConfigNode(_vesselNode, VesselId);

                //In case there's a deserialization error skip it and keep the older proto
                if (newProto != null)
                {
                    if (newProto.vesselID != VesselId)
                    {
                        LunaLog.LogError($"Tried to update the Vessel with a proto from a different vessel ID. Proto: {newProto.vesselID} CorrectId: {VesselId}");
                    }
                    else
                    {
                        _deserializedProtoVessel = newProto;
                    }
                }

                //If protovessel is still null then unfortunately we must remove that vessel as the server sent us a bad vessel
                if (_deserializedProtoVessel == null)
                {
                    LunaLog.LogError($"Received a malformed vessel from SERVER. Id {VesselId}");
                    VesselRemoveSystem.Singleton.KillVessel(VesselId);
                    VesselRemoveSystem.Singleton.AddToKillList(VesselId);
                }
                else
                {
                    _vesselParts.Clear();
                    foreach (var protoPart in _deserializedProtoVessel.protoPartSnapshots)
                    {
                        _vesselParts.TryAdd(protoPart.flightID, protoPart);
                    }
                }
            }
        }
Пример #2
0
        public static ProtoVessel DeserializeVessel(byte[] data)
        {
            try
            {
                var vesselNode = ConfigNodeSerializer.Deserialize(data);
                var configGuid = vesselNode?.GetValue("pid");

                return(VesselCommon.CreateSafeProtoVesselFromConfigNode(vesselNode, new Guid(configGuid)));
            }
            catch (Exception)
            {
                LunaLog.LogError("[LMP]: Error while deserializing vessel");
                return(null);
            }
        }
Пример #3
0
 public VesselProtoUpdate(ConfigNode vessel, Guid vesselId)
 {
     VesselId    = vesselId;
     ProtoVessel = VesselCommon.CreateSafeProtoVesselFromConfigNode(vessel, vesselId);
 }