some fixes
This commit is contained in:
@@ -9,6 +9,10 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
|
||||
|
||||
namespace ReallifeGamemode.Server.Managers
|
||||
{
|
||||
@@ -751,7 +755,9 @@ namespace ReallifeGamemode.Server.Managers
|
||||
|
||||
public static void VehicleTimerTick()
|
||||
{
|
||||
NAPI.Pools.GetAllVehicles().ForEach(v =>
|
||||
NAPI.Task.Run(() =>
|
||||
{
|
||||
NAPI.Pools.GetAllVehicles().ForEach(v =>
|
||||
{
|
||||
if (v.Handle.Value == 0 || v.Handle == default)
|
||||
{
|
||||
@@ -782,29 +788,31 @@ namespace ReallifeGamemode.Server.Managers
|
||||
v.SetSharedData("drivenDistance", (float)distanceDriven);
|
||||
});
|
||||
|
||||
if (DateTime.UtcNow.Subtract(lastSave).Seconds >= 30)
|
||||
{
|
||||
lastSave = DateTime.UtcNow;
|
||||
// save to db
|
||||
using (var dbContext = new DatabaseContext())
|
||||
|
||||
if (DateTime.UtcNow.Subtract(lastSave).Seconds >= 30)
|
||||
{
|
||||
foreach (var key in lastPositions.Keys.ToList())
|
||||
lastSave = DateTime.UtcNow;
|
||||
// save to db
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
Vehicle v = key.Entity<Vehicle>();
|
||||
if (v == null) continue;
|
||||
if (!v.HasSharedData("drivenDistance")) continue;
|
||||
foreach (var key in lastPositions.Keys.ToList())
|
||||
{
|
||||
Vehicle v = key.Entity<Vehicle>();
|
||||
if (v == null) continue;
|
||||
if (!v.HasSharedData("drivenDistance")) continue;
|
||||
|
||||
ServerVehicle sVeh = VehicleManager.GetServerVehicleFromVehicle(v, dbContext);
|
||||
ServerVehicle sVeh = VehicleManager.GetServerVehicleFromVehicle(v, dbContext);
|
||||
|
||||
if (sVeh == null) continue;
|
||||
if (sVeh == null) continue;
|
||||
|
||||
sVeh.DistanceDriven = (float)v.GetSharedData<dynamic>("drivenDistance");
|
||||
sVeh.DistanceDriven = (float)v.GetSharedData<dynamic>("drivenDistance");
|
||||
}
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static void AddVehicle(ServerVehicle serverVehicle, Vehicle vehicle)
|
||||
{
|
||||
if (_serverVehicles.ContainsKey(serverVehicle.Id))
|
||||
|
||||
Reference in New Issue
Block a user