public IPlayer RestorePlayer(string accountHandle, long charID)
{
IPlayer newPlayerToLoad = null;
try
{
var currentBackupDirectory = BaseDirectory + accountHandle + "/" + CurrentDirectoryName + charID.ToString() + "/";
//No backup directory? No live data.
if (!VerifyDirectory(currentBackupDirectory, false))
return null;
var playerDirectory = new DirectoryInfo(currentBackupDirectory);
var playerFilePath = playerDirectory + GetPlayerFilename(charID);
var fileData = ReadCurrentFileByPath(playerFilePath);
//no player file to load, derp
if (fileData.Length == 0)
return null;
var blankEntity = Activator.CreateInstance(typeof(IPlayer)) as IPlayer;
newPlayerToLoad = (IPlayer)blankEntity.FromBytes(fileData);
//bad load, dump it
if (newPlayerToLoad == null)
return null;
//abstract this out to a helper maybe?
var locationAssembly = Assembly.GetAssembly(typeof(ILocation));
//We have the player in live cache now so make it move to the right place
newPlayerToLoad.GetFromWorldOrSpawn();
newPlayerToLoad.UpsertToLiveWorldCache();
//We'll need one of these per container on players
if (Directory.Exists(playerDirectory + "Inventory/"))
{
var inventoryDirectory = new DirectoryInfo(playerDirectory + "Inventory/");
foreach (var file in inventoryDirectory.EnumerateFiles())
{
var blankObject = Activator.CreateInstance(typeof(IInanimate)) as IInanimate;
var newObj = (IInanimate)blankObject.FromBytes(ReadFile(file));
newObj.UpsertToLiveWorldCache();
newPlayerToLoad.MoveInto(newObj);
}
}
}
catch (Exception ex)
{
LoggingUtility.LogError(ex);
}
return newPlayerToLoad;
}