ace/Source/ACE.Database/DatabaseManager.cs

89 lines
3.4 KiB
C#
Raw Permalink Normal View History

Step 3. Convert ShardDatabase/WorldObjects biota from the ACE.Database model to the new ACE.Entity model (#2731) * Step 1. Add new adapter classes and models All classes and objects added are in new namespaces. This add has 0 interraction on existing ACE code. This sets the groundwork for Step 2. Moving World DB caching to the new models * first part of the world entity usage * almost there * final part * update WeenieExtensions * fix * merge fixes and improvements * ACE.Database new code * it compiles * InitializePropertyDictionaries * WOrldDatabaseWithEntityCache cleanup * ShardDatabaseWithCaching * ShardDatabase Cleanup * todo * cache counts reported in serverstatus * House InitializePropertyDictionaries * improve ServerStatus * BiotaModel change HousePermissions to Dictionary<uint, bool> * PropertiesAllegiance to dictionary * BiotaUpdater improvements * Shard Database Cache Reporting * More code ported from Step 3 * Remove stub CharacterCache * Update WorldDatabaseWithEntityCache.cs * build fixes * code audit * Remove non-callback functions from SerializedShardDatabase * BiotaUpdater progress.. only emote left * Emotes done... now need to test * fix * Burden/Value fix for containers * fat fingered EncumbranceVal * add some safety * Don't cache player biotas for initial PlayerManager load * fix null spellbook * Add another null check This is redundant as the check is also upstream. This is to prevent an exception in the future if this function is called from another source.
2020-04-02 22:40:27 -05:00
using System;
using System.Collections.Concurrent;
using Microsoft.EntityFrameworkCore;
using log4net;
namespace ACE.Database
{
public static class DatabaseManager
{
private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public static AuthenticationDatabase Authentication { get; } = new AuthenticationDatabase();
public static WorldDatabaseWithEntityCache World { get; } = new WorldDatabaseWithEntityCache();
private static SerializedShardDatabase serializedShardDb;
public static SerializedShardDatabase Shard { get; private set; }
public static ShardConfigDatabase ShardConfig { get; } = new ShardConfigDatabase();
public static bool InitializationFailure = false;
public static void Initialize(bool autoRetry = true)
{
Authentication.Exists(true);
if (Authentication.GetListofAccountsByAccessLevel(ACE.Entity.Enum.AccessLevel.Admin).Count == 0)
{
log.Warn("Authentication Database does not contain any admin accounts. The next account to be created will automatically be promoted to an Admin account.");
AutoPromoteNextAccountToAdmin = true;
}
else
AutoPromoteNextAccountToAdmin = false;
World.Exists(true);
if (!World.IsWorldDatabaseGuidRangeValid())
{
log.Fatal("World Database contains instance GUIDs outside of static range which will prevent GuidManager from properly assigning GUIDs and can result in GUID exhaustion prematurely.");
InitializationFailure = true;
return;
}
var playerWeenieLoadTest = World.GetCachedWeenie("human");
if (playerWeenieLoadTest == null)
{
log.Fatal("World Database does not contain the weenie for human (1). Characters cannot be created or logged into until the missing weenie is restored.");
InitializationFailure = true;
return;
}
Step 3. Convert ShardDatabase/WorldObjects biota from the ACE.Database model to the new ACE.Entity model (#2731) * Step 1. Add new adapter classes and models All classes and objects added are in new namespaces. This add has 0 interraction on existing ACE code. This sets the groundwork for Step 2. Moving World DB caching to the new models * first part of the world entity usage * almost there * final part * update WeenieExtensions * fix * merge fixes and improvements * ACE.Database new code * it compiles * InitializePropertyDictionaries * WOrldDatabaseWithEntityCache cleanup * ShardDatabaseWithCaching * ShardDatabase Cleanup * todo * cache counts reported in serverstatus * House InitializePropertyDictionaries * improve ServerStatus * BiotaModel change HousePermissions to Dictionary<uint, bool> * PropertiesAllegiance to dictionary * BiotaUpdater improvements * Shard Database Cache Reporting * More code ported from Step 3 * Remove stub CharacterCache * Update WorldDatabaseWithEntityCache.cs * build fixes * code audit * Remove non-callback functions from SerializedShardDatabase * BiotaUpdater progress.. only emote left * Emotes done... now need to test * fix * Burden/Value fix for containers * fat fingered EncumbranceVal * add some safety * Don't cache player biotas for initial PlayerManager load * fix null spellbook * Add another null check This is redundant as the check is also upstream. This is to prevent an exception in the future if this function is called from another source.
2020-04-02 22:40:27 -05:00
// By default, we hold on to player biotas a little bit longer to help with offline updates like pass-up xp, allegiance updates, etc...
var shardDb = new ShardDatabaseWithCaching(TimeSpan.FromMinutes(Common.ConfigManager.Config.Server.ShardPlayerBiotaCacheTime), TimeSpan.FromMinutes(Common.ConfigManager.Config.Server.ShardNonPlayerBiotaCacheTime));
serializedShardDb = new SerializedShardDatabase(shardDb);
Shard = serializedShardDb;
shardDb.Exists(true);
}
public static bool AutoPromoteNextAccountToAdmin { get; set; }
public static void Start()
{
serializedShardDb.Start();
}
public static void Stop()
{
if (serializedShardDb != null)
serializedShardDb.Stop();
}
private static readonly ConcurrentDictionary<string, ServerVersion> cachedServerVersions = new();
public static ServerVersion CachedServerVersionAutoDetect(string database, string connectionString)
{
if (!cachedServerVersions.TryGetValue(database, out ServerVersion serverVersion))
{
serverVersion = ServerVersion.AutoDetect(connectionString);
cachedServerVersions[database] = serverVersion;
}
return serverVersion;
}
}
}