void SavePlayerDatabase() { foreach (string userid in changedPlayersData) { string path = subDirectory + userid; datafile.WriteObject <Dictionary <string, Dictionary <string, object> > >(path, playersData[userid]); } changedPlayersData.Clear(); }
protected override void LoadDefaultConfig() { Config["Settings", "boxes"] = GetDefaultBoxes(); Config["Settings", "slots"] = GetDefaultSlots(); Config["Settings", "defaultBox"] = "assets/prefabs/deployable/woodenbox/woodbox_deployed.prefab"; Config["Settings", "defaultSlots"] = 4; Config["Settings", "keyring"] = true; Config["Settings", "cooldownMinutes"] = 5; Config["Settings", "NPCBankersOnly"] = false; Config["Settings", "NPCIDs"] = new List <object>(); configFile.WriteObject <Dictionary <string, ItemLimit> >("Bank_ItemLimits", GetDefaultItemLimits()); Config["VERSION"] = Version.ToString(); }
protected override void LoadDefaultConfig() { Config ["Settings", "boxes"] = GetDefaultBoxes(); Config ["Settings", "slots"] = GetDefaultSlots(); Config ["Settings", "defaultBox"] = "assets/prefabs/deployable/woodenbox/woodbox_deployed.prefab"; Config ["Settings", "defaultSlots"] = 4; Config ["Settings", "keyring"] = true; Config ["Settings", "cooldownMinutes"] = 5; Config ["Settings", "radiationMax"] = 1; Config ["Settings", "NPCBankersOnly"] = false; Config ["Settings", "NPCIDs"] = new List <object> (); if (configFile == null) { configFile = new DataFileSystem(Interface.Oxide.ConfigDirectory); } configFile.WriteObject <Dictionary <string, object> > ("Bank_ItemLimits", GetDefaultItemLimits()); Config ["VERSION"] = Version.ToString(); }
void SaveProfile(ulong playerID, BankProfile profile = null) { if (profile == null) { if (!banks.ContainsKey(playerID)) { return; } profile = banks[playerID]; } string path = "bank_" + playerID.ToString(); int pc = profile.Count; datafile.WriteObject <BankProfile>(path, profile); profile.dirty = false; }
private void OnServerSave() => DFS.WriteObject(Name, Entities);
private void SavePlayerInfo(string playerId, PlayerInfo playerInfo) { dataFile.WriteObject <PlayerInfo>($"playerInfo_{playerId}", playerInfo); }
private void Worker() { Interface.Oxide.LogInfo("[DropBox] Initialized"); _Settings = _DataFileSystem.ReadObject <Settings>(Path.Combine(_ConfigDirectory, "DropBox")); if (_Settings.FileList == null) { _Settings = new Settings(); _Settings.BackupOxideConfig = true; _Settings.BackupOxideData = true; _Settings.BackupOxideLang = true; _Settings.BackupOxideLogs = true; _Settings.BackupOxidePlugins = true; _Settings.FileList = new List <string>(); _Settings.UserToken = ""; _Settings.UserSecret = ""; _Settings.BackupName = "Oxide DropBox Extension"; _Settings.BackupInterval = 3600; _Settings.DropboxApi = new Dictionary <string, string>(); _Settings.DropboxApi.Add("DropboxAppKey", ""); _Settings.DropboxApi.Add("DropboxAppSecret", ""); _DataFileSystem.WriteObject <Settings>(Path.Combine(_ConfigDirectory, "DropBox"), _Settings); } if (_Settings.BackupInterval < 3600) { Interface.Oxide.LogError("[DropBox] You can't set backup interval lower than 1 hour."); _Settings.BackupInterval = 3600; _DataFileSystem.WriteObject <Settings>(Path.Combine(_ConfigDirectory, "DropBox"), _Settings); } if ((string.IsNullOrEmpty(_Settings.DropboxApi["DropboxAppKey"])) || (string.IsNullOrEmpty(_Settings.DropboxApi["DropboxAppSecret"]))) { _running = false; Interface.Oxide.LogWarning("[DropBox] To able to use DropBox Extension you need to set DropboxAppKey and DropboxAppSecret in config file."); } if (_running) { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(_Settings.DropboxApi["DropboxAppKey"], _Settings.DropboxApi["DropboxAppSecret"], AccessLevel.Full); OAuthToken oauthAccessToken = null; bool Authorized = false; IDropbox dropbox = null; do { if ((_running) && (string.IsNullOrEmpty(_Settings.UserToken) || string.IsNullOrEmpty(_Settings.UserSecret))) { Interface.Oxide.LogInfo("[DropBox] Getting request token..."); OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestToken(null, null); Interface.Oxide.LogInfo("[DropBox] Done"); OAuth1Parameters parameters = new OAuth1Parameters(); string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthenticateUrl(oauthToken.Value, parameters); Interface.Oxide.LogInfo("[DropBox] Redirect user for authorization"); Interface.Oxide.LogInfo("[DropBox] {0}", authenticateUrl); while ((_running) && (Authorized == false)) { try { AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null); oauthAccessToken = dropboxServiceProvider.OAuthOperations.ExchangeForAccessToken(requestToken, null); Authorized = true; _Settings.UserToken = oauthAccessToken.Value; _Settings.UserSecret = oauthAccessToken.Secret; _DataFileSystem.WriteObject <Settings>(Path.Combine(_ConfigDirectory, "DropBox"), _Settings); } catch { Thread.Sleep(5000); } } } else if (_running) { oauthAccessToken = new OAuthToken(_Settings.UserToken, _Settings.UserSecret); } if (_running) { try { Interface.Oxide.LogInfo("[DropBox] Authorizing"); dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); Interface.Oxide.LogInfo("[DropBox] Authorization Succeed"); Authorized = true; } catch { Interface.Oxide.LogWarning("[DropBox] Authorization Failed"); _Settings.UserToken = ""; _Settings.UserSecret = ""; _DataFileSystem.WriteObject <Settings>(Path.Combine(_ConfigDirectory, "DropBox"), _Settings); Authorized = false; } } } while ((_running) && (Authorized == false)); if ((_running) && (dropbox != null) && (Authorized == true)) { DropboxProfile profile = dropbox.GetUserProfile(); Interface.Oxide.LogInfo("[DropBox] Current Dropbox User : {0}({1})", profile.DisplayName, profile.Email); DateTime NextUpdate = DateTime.Now.AddSeconds(60); Interface.Oxide.LogInfo("[DropBox] First Backup : {0}", NextUpdate.ToString()); while (_running) { if (DateTime.Now < NextUpdate) { Thread.Sleep(1000); } else { string BackUpRoot = Path.Combine(Interface.Oxide.RootDirectory, "OxideExtBackup"); string OxideBackUpRoot = Path.Combine(BackUpRoot, "Oxide"); string FileBackUpRoot = Path.Combine(BackUpRoot, "Files"); Directory.CreateDirectory(BackUpRoot); DirectoryInfo OxideExtBackup = new DirectoryInfo(BackUpRoot); foreach (FileInfo file in OxideExtBackup.GetFiles()) { file.Delete(); } foreach (DirectoryInfo subDirectory in OxideExtBackup.GetDirectories()) { subDirectory.Delete(true); } Directory.CreateDirectory(OxideBackUpRoot); Directory.CreateDirectory(FileBackUpRoot); if (_Settings.BackupOxideConfig) { DirectoryCopy(Interface.Oxide.ConfigDirectory, Path.Combine(OxideBackUpRoot, "config"), true); } if (_Settings.BackupOxideData) { DirectoryCopy(Interface.Oxide.DataDirectory, Path.Combine(OxideBackUpRoot, "data"), true); } if (_Settings.BackupOxideLang) { DirectoryCopy(Interface.Oxide.LangDirectory, Path.Combine(OxideBackUpRoot, "lang"), true); } if (_Settings.BackupOxideLogs) { DirectoryCopy(Interface.Oxide.LogDirectory, Path.Combine(OxideBackUpRoot, "logs"), true); } if (_Settings.BackupOxidePlugins) { DirectoryCopy(Interface.Oxide.PluginDirectory, Path.Combine(OxideBackUpRoot, "plugins"), true); } foreach (string Current in _Settings.FileList) { if (!string.IsNullOrEmpty(Current)) { string CurrentPath = Path.GetFullPath(Path.Combine(Interface.Oxide.RootDirectory, Current)); if (!CurrentPath.StartsWith(Interface.Oxide.RootDirectory, StringComparison.Ordinal)) { Interface.Oxide.LogError("[DropBox] You may only access game releated directories..."); } else if ((File.GetAttributes(CurrentPath) & FileAttributes.Directory) == FileAttributes.Directory) { if (CurrentPath != Interface.Oxide.RootDirectory) { DirectoryCopy(CurrentPath, Path.Combine(FileBackUpRoot, new DirectoryInfo(CurrentPath).Name), true); } } else { File.Copy(CurrentPath, Path.Combine(FileBackUpRoot, new FileInfo(CurrentPath).Name)); } } } string FileName = string.Format("{0}.{1}.{2}.{3}.{4}.{5}.zip", DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, DateTime.UtcNow.Hour, DateTime.UtcNow.Minute, DateTime.UtcNow.Second); FileStream fsOut = File.Create(Path.Combine(Interface.Oxide.RootDirectory, FileName)); ZipOutputStream zipStream = new ZipOutputStream(fsOut); zipStream.SetLevel(3); string folderName = Path.Combine(Interface.Oxide.RootDirectory, "OxideExtBackup"); int folderOffset = folderName.Length + (folderName.EndsWith("\\") ? 0 : 1); CompressFolder(folderName, zipStream, folderOffset); zipStream.IsStreamOwner = true; zipStream.Close(); Interface.Oxide.LogInfo("[DropBox] Uploading..."); Entry uploadFileEntry = dropbox.UploadFile(new FileResource(Path.Combine(Interface.Oxide.RootDirectory, FileName)), string.Format("/{0}/{1}", _Settings.BackupName, FileName), true, null); Directory.Delete(folderName, true); File.Delete(Path.Combine(Interface.Oxide.RootDirectory, FileName)); NextUpdate = NextUpdate.AddSeconds(_Settings.BackupInterval); Interface.Oxide.LogInfo("[DropBox] Uploading Complated.Next Backup : {0}", NextUpdate.ToString()); } } } } }