private static int OnSynchronizeAccountFileToVault(string AccountName, string CharacterFile, IntPtr Data, IntPtr Length, IntPtr Context)
{
try
{
//
// Pass through to the default implementation if the connection
// string is not defined in the database.
//
if (String.IsNullOrEmpty(StoreConnectionString))
return 1;
try
{
if (Length == IntPtr.Zero)
return 0;
//
// Canonicalize names to lowercase as the file store may be
// case sensitive and maintaining a mapping table in the
// database is problematic since the first save for a new
// account may be observed before the players record for
// that player is created (and a player could log in to two
// servers simultaneously and create orphaned records that
// way, or similarly during a database outage, etc.).
//
// The original filename is stored as metadata to keep local
// filesystems case preserving on servers.
//
string OriginalFileName = AccountName + "/" + CharacterFile;
AccountName = AccountName.ToLowerInvariant();
CharacterFile = CharacterFile.ToLowerInvariant();
//
// Get the file store file for the character file and
// replace it with the new character file.
//
FileStoreDirectory StoreDirectory = Container.GetDirectoryReference(AccountName);
FileStoreFile StoreFile = StoreDirectory.GetFileReference(CharacterFile);
byte[] CharacterData = new byte[(int)Length];
Marshal.Copy(Data, CharacterData, 0, CharacterData.Length);
StoreFile.Metadata["OriginalFileName"] = OriginalFileName;
StoreFile.Write(new MemoryStream(CharacterData));
if (VerboseLoggingEnabled)
{
Logger.Log("ServerVaultConnector.OnSynchronizeAccountFileToVault: Uploaded vault file '{0}\\{1}'.",
AccountName,
CharacterFile);
}
return 1;
}
catch (Exception e)
{
Logger.Log("ServerVaultConnector.OnSynchronizeAccountFileToVault('{0}', '{1}'): Exception: {2}",
AccountName,
CharacterFile,
e);
throw;
}
}
catch
{
return 0;
}
}