2024-05-01 02:55:43 -04:00
|
|
|
|
using FSO.Common.Domain.Shards;
|
|
|
|
|
using FSO.Server.Database.DA;
|
|
|
|
|
using FSO.Server.Protocol.CitySelector;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace FSO.Server.Domain
|
|
|
|
|
{
|
|
|
|
|
public class Shards : IShardsDomain
|
|
|
|
|
{
|
|
|
|
|
private List<ShardStatusItem> _Shards = new List<ShardStatusItem>();
|
|
|
|
|
private IDAFactory _DbFactory;
|
|
|
|
|
private DateTime _LastPoll;
|
|
|
|
|
|
|
|
|
|
public Shards(IDAFactory factory)
|
|
|
|
|
{
|
|
|
|
|
_DbFactory = factory;
|
|
|
|
|
Poll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ShardStatusItem> All
|
|
|
|
|
{
|
2024-05-01 03:50:54 -04:00
|
|
|
|
get
|
|
|
|
|
{
|
2024-05-01 02:55:43 -04:00
|
|
|
|
return _Shards;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int? CurrentShard
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2024-05-01 03:50:54 -04:00
|
|
|
|
throw new Exception("CurrentShard not available in server domain");
|
2024-05-01 02:55:43 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AutoUpdate()
|
|
|
|
|
{
|
|
|
|
|
Task.Delay(60000).ContinueWith(x =>
|
|
|
|
|
{
|
2024-05-01 03:50:54 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
2024-05-01 02:55:43 -04:00
|
|
|
|
Poll();
|
2024-05-01 03:50:54 -04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-05-01 02:55:43 -04:00
|
|
|
|
}
|
|
|
|
|
AutoUpdate();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Poll()
|
|
|
|
|
{
|
|
|
|
|
_LastPoll = DateTime.UtcNow;
|
2024-05-01 03:50:54 -04:00
|
|
|
|
|
2024-05-01 02:55:43 -04:00
|
|
|
|
using (var db = _DbFactory.Get())
|
|
|
|
|
{
|
|
|
|
|
_Shards = db.Shards.All().Select(x => new ShardStatusItem()
|
|
|
|
|
{
|
|
|
|
|
Id = x.shard_id,
|
|
|
|
|
Name = x.name,
|
|
|
|
|
Map = x.map,
|
|
|
|
|
Rank = x.rank,
|
|
|
|
|
Status = (Server.Protocol.CitySelector.ShardStatus)(byte)x.status,
|
|
|
|
|
PublicHost = x.public_host,
|
|
|
|
|
InternalHost = x.internal_host,
|
|
|
|
|
VersionName = x.version_name,
|
|
|
|
|
VersionNumber = x.version_number,
|
|
|
|
|
UpdateID = x.update_id
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ShardStatusItem GetById(int id)
|
|
|
|
|
{
|
|
|
|
|
return _Shards.FirstOrDefault(x => x.Id == id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ShardStatusItem GetByName(string name)
|
|
|
|
|
{
|
|
|
|
|
return _Shards.FirstOrDefault(x => x.Name == name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|