ace/Source/ACE.Server/Program.cs
Mag-nus eeaf9725e4
PlayerManager (#1103)
* PlayerManager initial checkin

* OfflinePlayer initial checkin

* More progress

* Comment out Console.WriteLine debug messages

* Add property dictionaries to OfflinePlayer

* IPlayer initial checkin

* Add allegiance vars to IPlayer

* Couple comments

* More progress

* Add more to IPlayer

* line endings fix

* More progress. Compiles. Friends list works again.

* Friend status updates now work (again)

* PlayerManager save OfflinePlayers every 1hr

* Bye bye legacy AllPlayers

* using cleanup

* Allegience switch to PlayerManager progress

* More Allegiance progress

* More progress

* More allegiance progress

* IPlayer adds

* Migrate inversefriends to PlayerManager

* Switch WorldManager GetPlayerByGuid over to PlayerManager

* WorldManager Find(ObjectGuid characterGuid) removed. Use PlayerManager instead

* WorldManager FindByPlayerName(string name) removed. Use PlayerManager instead

* PlayerManager thread safety switched to ReaderWriterLockSlim

* More progress

* ServerStatus added TotalAccountsCreated, TotalCharactersCreated

* No more Player access/management stuff in WorldManager. It's all in PlayerManager now

* Player.IsOnline is no more.

* Friends AppearOnline fix

* Handle dead session better to switch player from online to offline

* Remove adding the + to names in ChatChannels. Name property should be changed to not include +

* serverstatus total accounts and characters on same line

* Allegience initial fix, still more bugs though

* PlayerManager minor cleanup

uint should be faster key than ObjectGuid

Changed the dictionaries to private. We don't want anyone outside of this class referencing them.

* Thread safety added to LScape.get_landcell
2018-12-02 13:41:16 -06:00

158 lines
5.8 KiB
C#

using System;
using System.IO;
using System.Runtime.InteropServices;
using log4net;
using log4net.Config;
using ACE.Common;
using ACE.Database;
using ACE.DatLoader;
using ACE.Server.Command;
using ACE.Server.Managers;
using ACE.Server.Network.Managers;
namespace ACE.Server
{
class Program
{
/// <summary>
/// The timeBeginPeriod function sets the minimum timer resolution for an application or device driver. Used to manipulate the timer frequency.
/// https://docs.microsoft.com/en-us/windows/desktop/api/timeapi/nf-timeapi-timebeginperiod
/// Important note: This function affects a global Windows setting. Windows uses the lowest value (that is, highest resolution) requested by any process.
/// </summary>
[DllImport("winmm.dll", EntryPoint="timeBeginPeriod")]
public static extern uint MM_BeginPeriod(uint uMilliseconds);
/// <summary>
/// The timeEndPeriod function clears a previously set minimum timer resolution
/// https://docs.microsoft.com/en-us/windows/desktop/api/timeapi/nf-timeapi-timeendperiod
/// </summary>
[DllImport("winmm.dll", EntryPoint = "timeEndPeriod")]
public static extern uint MM_EndPeriod(uint uMilliseconds);
private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public static void Main(string[] args)
{
AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnProcessExit);
// Init our text encoding options. This will allow us to use more than standard ANSI text, which the client also supports.
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
var logRepository = LogManager.GetRepository(System.Reflection.Assembly.GetEntryAssembly());
XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
// Do system specific initializations here
try
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// On many windows systems, the default resolution for Thread.Sleep is 15.6ms. This allows us to command a tighter resolution
MM_BeginPeriod(1);
}
}
catch (Exception ex)
{
log.Error(ex.ToString());
}
log.Info("Starting ACEmulator...");
Console.Title = @"ACEmulator";
log.Info("Initializing ConfigManager...");
ConfigManager.Initialize();
log.Info("Initializing ServerManager...");
ServerManager.Initialize();
log.Info("Initializing DatManager...");
DatManager.Initialize(ConfigManager.Config.Server.DatFilesDirectory, true);
log.Info("Initializing DatabaseManager...");
DatabaseManager.Initialize();
log.Info("Starting DatabaseManager...");
DatabaseManager.Start();
log.Info("Starting PropertyManager...");
PropertyManager.Initialize();
log.Info("Initializing GuidManager...");
GuidManager.Initialize();
if (ConfigManager.Config.Server.WorldDatabasePrecaching)
{
log.Info("Precaching Weenies...");
DatabaseManager.World.CacheAllWeeniesInParallel();
log.Info("Precaching Points Of Interest...");
DatabaseManager.World.CacheAllPointsOfInterest();
log.Info("Precaching Cookbooks...");
DatabaseManager.World.CacheAllCookbooksInParallel();
log.Info("Precaching Spells...");
DatabaseManager.World.CacheAllSpells();
log.Info("Precaching Events...");
DatabaseManager.World.GetAllEvents();
log.Info("Precaching Death Treasures...");
DatabaseManager.World.CacheAllDeathTreasures();
log.Info("Precaching Wielded Treasures...");
DatabaseManager.World.CacheAllWieldedTreasuresInParallel();
}
else
log.Info("Precaching World Database Disabled...");
log.Info("Initializing PlayerManager...");
PlayerManager.Initialize();
log.Info("Initializing InboundMessageManager...");
InboundMessageManager.Initialize();
log.Info("Initializing SocketManager...");
SocketManager.Initialize();
log.Info("Initializing WorldManager...");
WorldManager.Initialize();
if (ConfigManager.Config.Server.LandblockPreloading)
{
log.Info("Preloading Landblocks...");
LandblockManager.PreloadConfigLandblocks();
}
else
{
log.Info("Preloading Landblocks Disabled...");
log.Warn("Events may not function correctly as Preloading of Landblocks has disabled.");
}
log.Info("Initializing EventManager...");
EventManager.Initialize();
// This should be last
log.Info("Initializing CommandManager...");
CommandManager.Initialize();
}
private static void OnProcessExit(object sender, EventArgs e)
{
if (!ServerManager.ShutdownInitiated)
log.Warn("Unsafe server shutdown detected! Data loss is possible!");
PropertyManager.StopUpdating();
DatabaseManager.Stop();
// Do system specific cleanup here
try
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
MM_EndPeriod(1);
}
}
catch (Exception ex)
{
log.Error(ex.ToString());
}
}
}
}