public void HandleMessage(IMessageData messageData) { var msgData = messageData as VesselDockMsgData; if (msgData == null) { return; } LunaLog.Log("[LMP]: Docking message received!"); if (FlightGlobals.ActiveVessel?.id == msgData.WeakVesselId) { LunaLog.Log("[LMP]: Docking NOT detected. We DON'T OWN the dominant vessel"); SystemsContainer.Get <VesselRemoveSystem>().AddToKillList(FlightGlobals.ActiveVessel, true); SystemsContainer.Get <VesselSwitcherSystem>().SwitchToVessel(msgData.DominantVesselId); } if (FlightGlobals.ActiveVessel?.id == msgData.DominantVesselId && !VesselCommon.IsSpectating) { var newProto = VesselSerializer.DeserializeVessel(msgData.FinalVesselData); if (VesselCommon.ProtoVesselHasChanges(FlightGlobals.ActiveVessel.protoVessel, newProto)) { LunaLog.Log("[LMP]: Docking NOT detected. We OWN the dominant vessel"); //We own the dominant vessel and dind't detected the docking event so we need to reload our OWN vessel //so if we send our own protovessel later, we send the updated definition SystemsContainer.Get <VesselProtoSystem>().VesselLoader.ReloadVessel(newProto); } } //Some other 2 players docked so just remove the weak vessel. SystemsContainer.Get <VesselRemoveSystem>().AddToKillList(FlightGlobals.FindVessel(msgData.WeakVesselId), true); SystemsContainer.Get <VesselProtoSystem>().HandleVesselProtoData(msgData.FinalVesselData, msgData.DominantVesselId); }
/// <summary> /// In this method we get the new vessel data and set it to the dictionary of all the player vessels. /// We set it as UNLOADED as perhaps vessel data has changed. /// </summary> public void HandleVesselProtoData(byte[] vesselData, Guid vesselId) { TaskFactory.StartNew(() => { UniverseSyncCache.QueueToCache(vesselData); var vesselNode = ConfigNodeSerializer.Deserialize(vesselData); if (vesselNode != null && vesselId == Common.ConvertConfigStringToGuid(vesselNode.GetValue("pid"))) { var vesselProtoUpdate = new VesselProtoUpdate(vesselNode, vesselId); if (vesselProtoUpdate.ProtoVessel == null) { return; } if (!AllPlayerVessels.TryGetValue(vesselId, out var existingProtoData)) { AllPlayerVessels.TryAdd(vesselId, vesselProtoUpdate); } else if (VesselCommon.ProtoVesselHasChanges(existingProtoData.ProtoVessel, vesselProtoUpdate.ProtoVessel)) { //Vessel exists and contain changes so replace it AllPlayerVessels.TryUpdate(vesselId, vesselProtoUpdate, existingProtoData); } } }); }