Skip to content

Commit

Permalink
Fix server's vessel count, ensure intial sync only happens after flig…
Browse files Browse the repository at this point in the history
…ht scene fully ready, always handle updates during initial sync fully

Fixes #605
  • Loading branch information
TehGimp committed Mar 14, 2014
1 parent eb4525f commit d3f4b67
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
14 changes: 10 additions & 4 deletions KMPManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1970,7 +1970,7 @@ private void applyVesselUpdate(KMPVesselUpdate vessel_update, KMPVessel vessel)
if (vessel_update.getProtoVesselNode() != null) serverVessels_ProtoVessels[vessel_update.id] = vessel_update.getProtoVesselNode();

//Apply update if able
if (isInFlightOrTracking)
if (isInFlightOrTracking || syncing)
{
if (vessel_update.relativeTo == Guid.Empty && (vessel_update.id != FlightGlobals.ActiveVessel.id || (serverVessels_InUse[vessel_update.id] || (serverVessels_IsPrivate[vessel_update.id] && !serverVessels_IsMine[vessel_update.id]))))
{
Expand Down Expand Up @@ -2683,7 +2683,7 @@ private void addRemoteVessel(ProtoVessel protovessel, Guid vessel_id, KMPVessel
if (protovessel.vesselType == VesselType.Flag) {
Invoke("ClearFlagLock", 5f);
}
if (!vesselUpdatesLoaded.Contains(vessel_id))
if (!vesselUpdatesLoaded.Contains(vessel_id)) //This can be moved elsewhere in addRemoteVessel (or applyVesselUpdate) to help track issues with loading a specific vessel
{
vesselUpdatesLoaded.Add(vessel_id);
}
Expand Down Expand Up @@ -3416,13 +3416,19 @@ private void OnFirstFlightReady()
GameEvents.onFlightReady.Add(this.OnFlightReady);
MapView.EnterMapView();
MapView.MapCamera.SetTarget("Kerbin");
StartCoroutine(sendSubspaceSyncRequest(-1,true));
Invoke("sendInitialSyncRequest",0.5f);
Invoke("handleSyncTimeout",300f);
docking = false;
}
delayForceQuit = false;
}


private void sendInitialSyncRequest()
{
if (isInFlightOrTracking) StartCoroutine(sendSubspaceSyncRequest(-1,true));
else Invoke("sendInitialSyncRequest",0.25f);
}

private void OnFlightReady()
{
removeKMPControlLocks ();
Expand Down
11 changes: 9 additions & 2 deletions KMPServer/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -906,8 +906,15 @@ record =>

private int countShipsInDatabase()
{
int count = Convert.ToInt32(Database.ExecuteScalar("SELECT COUNT(*) FROM kmpVessel WHERE Destroyed IS NULL;"));
Log.Debug("Vessel count: {0}", count);
int count = Convert.ToInt32(Database.ExecuteScalar("SELECT COUNT(*)" +
" FROM kmpVesselUpdate vu" +
" INNER JOIN kmpVessel v ON v.Guid = vu.Guid AND v.Destroyed IS NULL" +
" INNER JOIN kmpSubspace s ON s.ID = vu.Subspace" +
" INNER JOIN" +
" (SELECT vu.Guid, MAX(s.LastTick) AS LastTick" +
" FROM kmpVesselUpdate vu" +
" INNER JOIN kmpSubspace s ON s.ID = vu.Subspace" +
" GROUP BY vu.Guid) t ON t.Guid = vu.Guid AND t.LastTick = s.LastTick"));
return count; // TODO: @NeverCast, Give ExecuteScalar a generic overload
}

Expand Down

0 comments on commit d3f4b67

Please sign in to comment.