예제 #1
0
        void LoadPlayer(string userid)
        {
            if (!storedData.knownPlayers.Contains(userid))
            {
                storedData.knownPlayers.Add(userid);
            }
            string path = subDirectory + userid;

            if (datafile.ExistsDatafile(path))
            {
            }

            object profile;

            try
            {
                profile = datafile.ReadObject <Dictionary <string, Dictionary <string, object> > >(path);
            }
            catch (Exception exception) {
                profile = new Dictionary <string, object>();
                datafile.WriteObject <Dictionary <string, Dictionary <string, object> > >(path, new Dictionary <string, Dictionary <string, object> >());
            }

            playersData[userid] = profile as Dictionary <string, Dictionary <string, object> >;
        }
예제 #2
0
        protected bool LoadProfile(ulong playerID, bool reload = false)
        {
            if (playerID == 0)
            {
                return(false);
            }
            string path = "bank_" + playerID.ToString();

            BankProfile profile = datafile.ReadObject <BankProfile> (path);

            if (!(profile is BankProfile))
            {
                return(false);
            }

            if (profile.Count == 0)
            {
                return(false);
            }

            if (banks.ContainsKey(playerID))
            {
                banks [playerID] = profile;
            }
            else
            {
                banks.Add(playerID, profile);
            }

            return(true);
        }
 private void Init()
 {
     if (!CFile.Persist)
     {
         Unsubscribe(nameof(OnServerSave));
     }
     else
     {
         Entities = DFS.ReadObject <Dictionary <uint, int> >(Name);
     }
     permission.RegisterPermission(BypassPerm, this);
 }
예제 #4
0
        void Init()
        {
            Unsubscribe(nameof(CanNetworkTo));
            Unsubscribe(nameof(OnEntityTakeDamage));
            ////Unsubscribe(nameof(OnItemAddedToContainer));

            configFile = new DataFileSystem(Interface.Oxide.ConfigDirectory);
            itemLimits = configFile.ReadObject <Dictionary <string, object> > ("Bank_ItemLimits");
            permission.RegisterPermission("bank.use", this);

            CheckConfig();

            datafile = new DataFileSystem(Interface.Oxide.DataDirectory + "\\" + this.GetConfig <string> ("subDirectory", "banks"));

            boxPrefabs = GetConfig("Settings", "boxes", GetDefaultBoxes());
            boxSlots   = GetConfig("Settings", "slots", GetDefaultSlots());

            defaultBoxPrefab = GetConfig("Settings", "defaultBox", "assets/prefabs/deployable/woodenbox/woodbox_deployed.prefab");
            defaultSlots     = GetConfig("Settings", "defaultSlots", 4);

            cooldownMinutes = GetConfig("Settings", "cooldownMinutes", 5f);
            radiationMax    = GetConfig("Settings", "radiationMax", 1f);
            allowSafeZone   = GetConfig("Settings", "allowSafeZone", true);

            npconly = GetConfig("Settings", "NPCBankersOnly", false);
            List <object> lnpcids = GetConfig("Settings", "NPCIDs", new List <object> ());

            foreach (object id in lnpcids)
            {
                npcids.Add(id.ToString());
            }

            keyring = GetConfig("Settings", "Keyring", true);

            foreach (KeyValuePair <string, object> kvp in boxPrefabs)
            {
                permission.RegisterPermission(kvp.Key, this);
            }

            foreach (KeyValuePair <string, object> kvp in boxSlots)
            {
                if (!boxPrefabs.ContainsKey(kvp.Key))
                {
                    permission.RegisterPermission(kvp.Key, this);
                }
            }

            foreach (BasePlayer player in BasePlayer.activePlayerList)
            {
                LoadProfile(player.userID);
            }
        }
예제 #5
0
        void Loaded()
        {
            configFile = new DataFileSystem(Interface.Oxide.ConfigDirectory);
            itemLimits = configFile.ReadObject <Dictionary <string, object> >("Bank_ItemLimits");
            permission.RegisterPermission("bank.use", this);

            CheckConfig();
            LoadMessages();

            datafile = new DataFileSystem(Interface.Oxide.DataDirectory + "\\" + this.GetConfig <string>("subDirectory", "banks"));


            boxPrefabs = GetConfig("Settings", "boxes", GetDefaultBoxes());
            boxSlots   = GetConfig("Settings", "slots", GetDefaultSlots());

            defaultBoxPrefab = GetConfig("Settings", "defaultBox", "assets/prefabs/deployable/woodenbox/woodbox_deployed.prefab");
            defaultSlots     = GetConfig("Settings", "defaultSlots", 4);

            cooldownMinutes = GetConfig("Settings", "cooldownMinutes", 5f);
            radiationMax    = GetConfig("Settings", "radiationMax", 1f);


            npconly = GetConfig("Settings", "NPCBankersOnly", false);
            npcids  = GetConfig("Settings", "NPCIDs", new List <object>());



            keyring = GetConfig("Settings", "Keyring", true);

            foreach (KeyValuePair <string, object> kvp in boxPrefabs)
            {
                permission.RegisterPermission(kvp.Key, this);
            }

            foreach (KeyValuePair <string, object> kvp in boxSlots)
            {
                if (!boxPrefabs.ContainsKey(kvp.Key))
                {
                    permission.RegisterPermission(kvp.Key, this);
                }
            }

            foreach (BasePlayer player in BasePlayer.activePlayerList)
            {
                LoadProfile(player.userID);
            }
        }
예제 #6
0
        protected bool LoadProfile(ulong playerID, bool reload = false)
        {
#if DEBUG
            Puts($"Loading Bank {playerID}");
#endif

            if (playerID == 0)
            {
                return(false);
            }

            //if (banks.ContainsKey (playerID)) {
            //    return true;
            //}

            string path = "bank_" + playerID.ToString();

            BankProfile profile = datafile.ReadObject <BankProfile> (path);

            if (!(profile is BankProfile))
            {
                return(false);
            }

            if (profile.Count == 0)
            {
                return(false);
            }

            if (banks.ContainsKey(playerID))
            {
                banks [playerID] = profile;
            }
            else
            {
                banks.Add(playerID, profile);
            }

            return(true);
        }
예제 #7
0
 private PlayerInfo LoadPlayerInfo(string playerId)
 {
     return(dataFile.ReadObject <PlayerInfo>($"playerInfo_{playerId}"));
 }
예제 #8
0
        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());
                        }
                    }
                }
            }
        }