public static string Serialize(GameObject rootOfTree)
    {
        LevelData ld;
        ld = new LevelData();
        UniqueIdentifier identifier = UniqueIdentifier.identifier;
        GameObject n = identifier.gameObject;
        ld.StoredObject = new StoredItem() { Name = identifier.Id, GameObjectName = n.name };
        Component[] toBeProcessed = UniqueIdentifier.identifier.gameObject.GetComponents<Component>();
        int i = toBeProcessed.Length;
        ld.StoredItem = new List<StoredData>();
        while (i-- > 0) {
            Component cp = toBeProcessed[i];
        #if UNITY_EDITOR
            if (cp is Transform) continue;
        #else
            if (cp is SaveObject || cp is Transform) continue;
        #endif
            StoredData sd = new StoredData() {
                Type = cp.GetType().FullName,
                Name = UniqueIdentifier.identifier.Id
            };
            if (CustomSerializers.ContainsKey(cp.GetType())) {
                sd.Data = Encoding.Default.GetString(CustomSerializers[cp.GetType()].Serialize(cp));
            } else {
                sd.Data = UnitySerializer.JSONSerializeForDeserializeInto(cp);
            }

            ld.StoredItem.Add(sd);
        }
        return UnitySerializer.JSONSerialize(ld);
    }
        void Loaded()
        {
            LoadDefaultConfig();
            storedData = Interface.GetMod().DataFileSystem.ReadObject<StoredData>("PortalsBackup");
            timer.Repeat(Convert.ToInt32(Config["TeleportTimer"]), 0, Portal);
            if(Config["Effects", "Enabled"].ToString() == "true") timer.Repeat(1.5F, 0, PortalFX);
            if(!permission.PermissionExists("portals.admin")) permission.RegisterPermission("portals.admin", this);

            foreach (var portal in Config)
            {
                string portalName = portal.Key.ToString();
                if(portalName == "TeleportTimer" || portalName == "Effects" ) continue;

                if(!permission.PermissionExists(Config[portalName, "Permission"].ToString())) permission.RegisterPermission(Config[portalName, "Permission"].ToString(), this);
            }
        }
Example #3
0
 // -------------------------- [ DATA FUNCTIONS ] -----------------------------
 void LoadData()
 {
     playerSetData = Interface.GetMod().DataFileSystem.ReadObject <StoredData>(this.Title);
     Puts("Loaded " + playerSetData.Players.Count + " players from /data/" + this.Title + ".json");
 }
Example #4
0
 private void Init()
 {
     storedData = Interface.Oxide.DataFileSystem.ReadObject <StoredData>(this.Name);
     permission.RegisterPermission(perm, this);
     LoadDefaultConfig();
 }
Example #5
0
 private void OnNewSave(string filename)
 {
     storedData = new StoredData();
     SaveData();
 }
 private void OnNewSave()
 {
     _pluginData = StoredData.Clear();
 }
Example #7
0
 void LoadData()
 {
     elevators.Clear();
     try
     {
         storedData = Interface.GetMod().DataFileSystem.ReadObject<StoredData>("Elevators");
     }
     catch
     {
         storedData = new StoredData();
     }
     foreach (var elevator in storedData.Elevators)
         elevators[elevator.Name] = elevator;
 }
Example #8
0
 public T Get <T>(string key)
 => !StoredData.TryGetValue(key, out var value) ? default : JsonSerializer.Deserialize <T>(value ?? string.Empty);
Example #9
0
        void Init()
        {
            permission.RegisterPermission("rewards.admin", this);
            permission.RegisterPermission("rewards.showrewards", this);

            storedData = Interface.Oxide.DataFileSystem.ReadObject <StoredData> (Name);

            Loadcfg();

            if (options.HappyHour_Enabled)
            {
                hhstart = new TimeSpan(Convert.ToInt32(rewardrates.HappyHour_BeginHour), 0, 0);
                hhend   = new TimeSpan(Convert.ToInt32(rewardrates.HappyHour_EndHour), 0, 0);
            }
            #region Activity Check
            if (options.ActivityReward_Enabled || options.HappyHour_Enabled)
            {
                timer.Repeat(60, 0, () => {
                    if (options.ActivityReward_Enabled)
                    {
                        foreach (var p in BasePlayer.activePlayerList)
                        {
                            if (Convert.ToDouble(p.secondsConnected) / 60 > rewardrates.ActivityRewardRate_minutes)
                            {
                                if (LastReward.ContainsKey(p))
                                {
                                    if (Convert.ToDouble(p.secondsConnected - LastReward [p]) / 60 > rewardrates.ActivityRewardRate_minutes)
                                    {
                                        RewardPlayer(p, rewardrates.ActivityReward);
                                        LastReward [p] = p.secondsConnected;
                                    }
                                }
                                else
                                {
                                    RewardPlayer(p, rewardrates.ActivityReward);
                                    LastReward.Add(p, p.secondsConnected);
                                }
                            }
                        }
                    }
                    if (options.HappyHour_Enabled)
                    {
                        var gameTime = GameTime();
                        if (!HappyHourActive)
                        {
                            if (gameTime >= rewardrates.HappyHour_BeginHour)
                            {
                                HappyHourActive = true;
                                Puts("Happy hour started. Ending at " + rewardrates.HappyHour_EndHour);
                                BroadcastMessage(Lang("HappyHourStart"), Lang("Prefix"));
                            }
                        }
                        else
                        {
                            if (gameTime > rewardrates.HappyHour_EndHour || gameTime < rewardrates.HappyHour_BeginHour)
                            {
                                HappyHourActive = false;
                                Puts("Happy hour ended");
                                BroadcastMessage(Lang("HappyHourEnd"), Lang("Prefix"));
                            }
                        }
                    }
                });
            }
            #endregion
        }
Example #10
0
 private void LoadData()
 {
     ZoneDefinitions.Clear();
     try
     {
         ZoneManagerData.Settings.NullValueHandling = NullValueHandling.Ignore;
         storedData = ZoneManagerData.ReadObject<StoredData>();
         Puts("Loaded {0} Zone definitions", storedData.ZoneDefinitions.Count);
     }
     catch
     {
         Puts("Failed to load StoredData");
         storedData = new StoredData();
     }
     ZoneManagerData.Settings.NullValueHandling = NullValueHandling.Include;
     foreach (var zonedef in storedData.ZoneDefinitions)
         ZoneDefinitions[zonedef.ID] = zonedef;
 }
Example #11
0
 void LoadData()
 {
     waypoints.Clear();
     try
     {
         storedData = Interface.GetMod().DataFileSystem.ReadObject<StoredData>("Waypoints");
     }
     catch
     {
         storedData = new StoredData();
     }
     foreach (var thewaypoint in storedData.WayPoints)
         waypoints[thewaypoint.Name] = thewaypoint;
 }
 void LoadData()
 {
     deadPlayers.Clear();
     try
     {
         storedData = Interface.GetMod().DataFileSystem.ReadObject<StoredData>("DeadPlayersList");
     }
     catch
     {
         storedData = new StoredData();
     }
     foreach (var dead_player in storedData.DeadPlayers)
         deadPlayers[dead_player.GetUserId()] = dead_player;
 }
Example #13
0
        private void LoadData()
        {
            storedData = Interface.GetMod().DataFileSystem.ReadObject<StoredData>("MyEvents");
            if (Convert.ToString(Config["Plugin", "Version"]) != version)
            {
                Puts("Uh oh! Not up to date! No Worries, lets update you!");
                switch(version)
                {
                    case "0.0.1":
                        Config["Plugin", "Version"] = version;
                        break;
                    case "0.0.2":
                        Config["Plugin", "Version"] = version;
                        Puts("Updating your Data File! Hang On!");
                        foreach (var storedEvent in storedData.Events)
                        {

                            if (storedEvent.CommandLine == null)
                            {
                                storedEvent.CommandLine = "";
                            }
                        }
                        Interface.GetMod().DataFileSystem.WriteObject("MyEvents", storedData);
                        break;
                    case "0.0.3":
                        Config["Plugin", "Version"] = version;
                        Puts("Updating your Data File! Hang On!");
                        foreach (var storedEvent in storedData.Events)
                        {

                            if (storedEvent.Schedule == null)
                            {
                                storedEvent.Schedule = "none";
                            }
                        }
                        Interface.GetMod().DataFileSystem.WriteObject("MyEvents", storedData);
                        break;
                    default:
                        Config["Plugin", "Version"] = version;
                        break;
                }
                SaveConfig();

            }
            permission.RegisterPermission("canplanevent", this);
            // Load Imformation from a Config file
            if (!PopupNotifications)
            {
                Puts("PopupNotifications not found! Using text based notifications!");
                PopUpNotifier = false;
            } else
            {
                
                if (Convert.ToBoolean(Config["Plugin", "EnablePopUps"]).ToString() != null)
                {
                    PopUpNotifier = Convert.ToBoolean(Config["Plugin", "EnablePopUps"]);
                }
            }
            string[] seperator = new string[] { "," };
            // Build array of events
            int tick;
            if (Convert.ToInt16(Config["Plugin", "TimeCheck"]) > 0)
            {
                tick = Convert.ToInt16(Config["Plugin", "TimeCheck"]);
            } else
            {
                tick = 10;
            }
            string daystring = Convert.ToString(Config["Events", "AllowedDays"]);
            days = daystring.Split(seperator, StringSplitOptions.RemoveEmptyEntries);
            timer.Repeat(tick, 0, () => EventCheck());
        }
Example #14
0
        void Loaded()
        {
            _timer = timer.Every(20, () => Messages());
            _timer = timer.Every(30, () => TOD_Sky.Instance.Cycle.Hour = 12);
            /*_timer = timer.Every(3600, () =>
            {
                BaseEntity entity = GameManager.server.CreateEntity("Assets/Prefabs/NPC/Patrol Helicopter/PatrolHelicopter.prefab", new Vector3(), new Quaternion(), true);
                if (entity != null)
                {
                    entity.GetComponent<PatrolHelicopterAI>().SetInitialDestination(new Vector3(0, 100, 0));
                    entity.Spawn(true);
                }
            });*/

            _timer = timer.Every(1, () =>
            {
                if (scoreboardRefresh <= 0)
                {
                    UpdateScoreboard();
                    scoreboardRefresh = 20;
                }
            });
            _timer = timer.Every(1, () => scoreboardRefresh = scoreboardRefresh - 1);

            storedData = Interface.GetMod().DataFileSystem.ReadObject<StoredData>("KillStats");
        }
Example #15
0
 private void Init()
 {
     permission.RegisterPermission(config.ChangeStatePermission, this);
     storedData = Interface.Oxide.DataFileSystem.ReadObject <StoredData>(Name);
     AddCovalenceCommand(config.Command, nameof(CommandFriendlyFire));
 }
 //
 // Clear StoredData
 //
 private void ClearData()
 {
     data = new StoredData();
     SaveData();
 }
Example #17
0
 public void Remove(string key)
 {
     StoredData.Remove(key);
     Write();
 }
        private void LoadData()
        {
            storedData = Interface.GetMod().DataFileSystem.ReadObject <StoredData>("MyEvents");
            if (Convert.ToString(Config["Plugin", "Version"]) != version)
            {
                Puts("Uh oh! Not up to date! No Worries, lets update you!");
                switch (version)
                {
                case "0.0.1":
                    Config["Plugin", "Version"] = version;
                    break;

                case "0.0.2":
                    Config["Plugin", "Version"] = version;
                    Puts("Updating your Data File! Hang On!");
                    foreach (var storedEvent in storedData.Events)
                    {
                        if (storedEvent.CommandLine == null)
                        {
                            storedEvent.CommandLine = "";
                        }
                    }
                    Interface.GetMod().DataFileSystem.WriteObject("MyEvents", storedData);
                    break;

                case "0.0.3":
                    Config["Plugin", "Version"] = version;
                    Puts("Updating your Data File! Hang On!");
                    foreach (var storedEvent in storedData.Events)
                    {
                        if (storedEvent.Schedule == null)
                        {
                            storedEvent.Schedule = "none";
                        }
                    }
                    Interface.GetMod().DataFileSystem.WriteObject("MyEvents", storedData);
                    break;

                default:
                    Config["Plugin", "Version"] = version;
                    break;
                }
                SaveConfig();
            }
            permission.RegisterPermission("canplanevent", this);
            // Load Imformation from a Config file
            if (!PopupNotifications)
            {
                Puts("PopupNotifications not found! Using text based notifications!");
                PopUpNotifier = false;
            }
            else
            {
                if (Convert.ToBoolean(Config["Plugin", "EnablePopUps"]).ToString() != null)
                {
                    PopUpNotifier = Convert.ToBoolean(Config["Plugin", "EnablePopUps"]);
                }
            }
            string[] seperator = new string[] { "," };
            // Build array of events
            int tick;

            if (Convert.ToInt16(Config["Plugin", "TimeCheck"]) > 0)
            {
                tick = Convert.ToInt16(Config["Plugin", "TimeCheck"]);
            }
            else
            {
                tick = 10;
            }
            string daystring = Convert.ToString(Config["Events", "AllowedDays"]);

            days = daystring.Split(seperator, StringSplitOptions.RemoveEmptyEntries);
            timer.Repeat(tick, 0, () => EventCheck());
        }
        /// <summary>
        /// Load bandit who already wear a mask
        /// </summary>
        void LoadConfigValues()
        {
            #region Use Logs
            string str = Config["Debug mode"] as string;
            if (str == null)
            {
                DebugMode            = false;
                Config["Debug mode"] = DebugMode.ToString();
            }
            else
            {
                DebugMode = (str.Equals("True") ? true : false);
            }
            if (DebugMode)
            {
                Puts("Debug mode enabled");
                Log("Debug mode enabled");
            }
            #endregion

            #region Bandit Names
            storedData = Interface.Oxide.DataFileSystem.ReadObject <StoredData>("BanditNames");
            if (DebugMode)
            {
                Log("Stored Data :");
                var enu = storedData.banditNames.GetEnumerator();
                while (enu.MoveNext())
                {
                    Log(enu.Current.Key + " => " + enu.Current.Value);
                }
            }
            #endregion

            #region Changed Name
            changedName = Config["Changed Name"] as string;
            if (changedName == null)
            {
                changedName            = DefaultChangedName;
                Config["Changed Name"] = changedName;
            }

            if (changedName.Equals(""))
            {
                changedName = " ";
            }

            if (DebugMode)
            {
                Log("Changed Name : " + changedName);
            }
            #endregion

            #region Masks
            List <Object> tmpmasks = Config["Masks"] as List <Object>;
            if (tmpmasks == null)
            {
                masks = new List <string> {
                    "mask", "burlap.headwrap"
                };
                Config["Masks"] = masks;
            }
            else
            {
                masks = new List <string>();
                foreach (Object mask in tmpmasks)
                {
                    masks.Add((string)mask);
                }
                Config["Masks"] = masks;
            }
            if (DebugMode)
            {
                foreach (string mk in masks)
                {
                    Log("Masks : " + mk);
                }
            }
            #endregion

            SaveConfig();
        }
Example #20
0
 private void btnLogOut_Click(object sender, RoutedEventArgs e)
 {
     StoredData.removeAllSavedData();
     this.Frame.Navigate(typeof(MainPage), null);
 }
Example #21
0
 void LoadData()
 {
     try { storedData = Interface.GetMod().DataFileSystem.ReadObject<StoredData>("PlayerDatabase"); }
     catch { storedData = new StoredData(); }
 }
Example #22
0
 private void Init()
 {
     permission.RegisterPermission("antinoobraid.admin", this);
     storedData = Interface.Oxide.DataFileSystem.ReadObject <StoredData>(this.Name);
     LoadDefaultConfig();
 }
 private void WriteToFile(object sender, EventArgs e)
 {
     SD = new StoredData(Income, Outcome);
         // Package data into one object for export
     XmlSerializer XSR = new XmlSerializer(typeof(StoredData));
     FileStream DataOut = new FileStream("Finances.xml", FileMode.Create);
     XSR.Serialize(DataOut, SD);
     DataOut.Close();
     HasData = true;
 }
        // Hooks
        // void OnEnterZone(string id, BasePlayer player)
        // void OnExitZone(string id, BasePlayer player)
        // void OnEnterZoneWithOptions(string id, BasePlayer player, Dictionary<string, string> options)
        // void OnExitZoneWithOptions(string id, BasePlayer player, Dictionary<string, string> options)

        // ----------------------------- UTILS -----------------------------
        // -----------------------------------------------------------------

        void LoadData()
        {
            data = Interface.GetMod().DataFileSystem.ReadObject <StoredData>(Title);
        }
Example #25
0
 void Loaded()
 {
     storedData = Interface.Oxide.DataFileSystem.ReadObject <StoredData>("CannibalsOnServer");
 }
Example #26
0
 void LoadData()
 {
     try { storedData = Interface.GetMod().DataFileSystem.ReadObject <StoredData>("PlayerDatabase"); }
     catch { storedData = new StoredData(); }
 }
Example #27
0
        private void Init()
        {
            // New permissions
            permission.RegisterPermission(permBalance, this);
            permission.RegisterPermission(permDeposit, this);
            permission.RegisterPermission(permSetMoney, this);
            permission.RegisterPermission(permTransfer, this);
            permission.RegisterPermission(permWithdraw, this);
            permission.RegisterPermission(permWipe, this);

            // Deprecated permissions
            permission.RegisterPermission(permAdmin, this);
            permission.RegisterPermission(permUse, this);

            AddLocalizedCommand("CommandBalance", "BalanceCommand");
            AddLocalizedCommand("CommandDeposit", "DepositCommand");
            AddLocalizedCommand("CommandSetMoney", "SetMoneyCommand");
            AddLocalizedCommand("CommandTransfer", "TransferCommand");
            AddLocalizedCommand("CommandWithdraw", "WithdrawCommand");
            AddLocalizedCommand("CommandWipe", "WipeCommand");

            data = Interface.Oxide.DataFileSystem.GetFile(Name);
            try
            {
                Dictionary <ulong, double> temp = data.ReadObject <Dictionary <ulong, double> >();
                try
                {
                    storedData = new StoredData();
                    foreach (KeyValuePair <ulong, double> old in temp.ToArray())
                    {
                        if (!storedData.Balances.ContainsKey(old.Key.ToString()))
                        {
                            storedData.Balances.Add(old.Key.ToString(), old.Value);
                        }
                    }
                    changed = true;
                }
                catch
                {
                    // Ignored
                }
            }
            catch
            {
                storedData = data.ReadObject <StoredData>();
                changed    = true;
            }

            string[] playerData = storedData.Balances.Keys.ToArray();

            if (config.MaximumBalance > 0)
            {
                foreach (string p in playerData.Where(p => storedData.Balances[p] > config.MaximumBalance))
                {
                    storedData.Balances[p] = config.MaximumBalance;
                    changed = true;
                }
            }

            if (config.RemoveUnused)
            {
                foreach (string p in playerData.Where(p => storedData.Balances[p].Equals(config.StartAmount)))
                {
                    storedData.Balances.Remove(p);
                    changed = true;
                }
            }

            SaveData();
        }
Example #28
0
 void ClearData()
 {
     storedData = new StoredData();
     SaveData();
 }
Example #29
0
 private void Init()
 {
     sData = Interface.Oxide.DataFileSystem.ReadObject <StoredData>(Name);
 }
 private void LoadData()
 {
     Data = Interface.GetMod().DataFileSystem.ReadObject <StoredData>("CraftOwnership");
 }
Example #31
0
		/*--------------------------------------------------------------//
		//			LoadSaveData - loads up the loot data				//
		//--------------------------------------------------------------*/
	    void LoadSavedData()
        {
            storedData = Interface.GetMod().DataFileSystem.ReadObject<StoredData>("HeliControlData");
			//Create a default data file if there was none:
			if (storedData == null)
			{
				PrintWarning("No Lootdrop Data!! Creating new file...");
				storedData = new StoredData();
				BoxInventory inv;
				inv = new BoxInventory("rifle.ak", 1);
				inv.lootBoxContents.Add(new ItemDef("ammo.rifle.hv", 128));
				storedData.HeliInventoryLists.Add(inv);
				
				inv = new BoxInventory("rifle.bolt", 1);
				inv.lootBoxContents.Add(new ItemDef("ammo.rifle.hv", 128));
				storedData.HeliInventoryLists.Add(inv);
				
				inv = new BoxInventory("explosive.timed", 3);
				inv.lootBoxContents.Add(new ItemDef("ammo.rocket.hv", 3));
				storedData.HeliInventoryLists.Add(inv);
				
				SaveData();
			}
        }
Example #32
0
 void LoadData()
 {
     var kits = Interface.Oxide.DataFileSystem.GetFile("Kits");
     try
     {
         kits.Settings.NullValueHandling = NullValueHandling.Ignore;
         storedData = kits.ReadObject<StoredData>();
     }
     catch
     {
         storedData = new StoredData();
     }
     kits.Settings.NullValueHandling = NullValueHandling.Include;
 }
Example #33
0
        public string Get(string key)

        => !StoredData.TryGetValue(key, out var value) ? default : JsonConvert.DeserializeObject <string>(value ?? string.Empty);
Example #34
0
 void OnNewSave()
 {
     storedData = new StoredData();
     SaveData();
 }
Example #35
0
    /// <summary>
    ///   Serializes the level to a byte array, with an optional root item. The root item
    ///   and its children, if specified, will be the only things saved
    /// </summary>
    /// <returns> The level data as a byte array </returns>
    /// <param name='urgent'> Whether to save even if serialization is suspended </param>
    /// <param name='id'> Identifier (or null) of an object to be the root of the data serialization </param>
    public static string SerializeLevel(bool urgent, string id)
    {
        LevelData ld;


        using (new Radical.Logging())
        {
            using (new UnitySerializer.ForceJSON())
            {
                //First we need to know the name of the last level loaded
                using (new UnitySerializer.SerializationScope())
                {
                    ld = new LevelData()
                    {
                        //The level to reload
                        Name = Application.loadedLevelName
                    };
                    //All of the currently active uniquely identified objects
                    ld.StoredObjectNames = UniqueIdentifier
                                           .AllIdentifiers
                                           .Where(i => string.IsNullOrEmpty(id) || i.Id == id || HasParent(i, id))
                                           .Select(i => i.gameObject)
                                           .Where(go => go != null)
                                           .Where(go =>
                    {
                        var shouldSerialize = go.FindInterface <IControlSerializationEx>();
                        return(shouldSerialize == null || shouldSerialize.ShouldSaveWholeObject());
                    })
                                           .Where(go =>
                    {
                        if (Store == null)
                        {
                            return(true);
                        }
                        var result = true;
                        Store(go, ref result);
                        return(result);
                    })
                                           .Select(n =>
                    {
                        try
                        {
                            var si = new StoredItem()
                            {
                                createEmptyObject = n.GetComponent <EmptyObjectIdentifier>() != null,
                                Active            = n.activeSelf,
                                layer             = n.layer,
                                tag          = n.tag,
                                setExtraData = true,

                                Components =
                                    n.GetComponents <Component>().Where(c => c != null).Select(
                                        c => c.GetType().FullName).Distinct().
                                    ToDictionary(v => v, v => true),
                                Name           = n.GetComponent <UniqueIdentifier>().Id,
                                GameObjectName = n.name,
                                ParentName     =
                                    (n.transform.parent == null ||
                                     n.transform.parent.GetComponent <UniqueIdentifier>() ==
                                     null)
                                                                         ? null
                                                                         : (n.transform.parent.GetComponent <UniqueIdentifier>().
                                                                            Id),
                                ClassId = n.GetComponent <PrefabIdentifier>() != null
                                                                               ? n.GetComponent <PrefabIdentifier>().ClassId
                                                                               : string.Empty
                            };
                            if (n.GetComponent <StoreInformation>())
                            {
                                n.SendMessage("OnSerializing", SendMessageOptions.DontRequireReceiver);
                            }
                            var pf = n.GetComponent <PrefabIdentifier>();
                            if (pf != null)
                            {
                                var components = GetComponentsInChildrenWithClause(n);
                                si.Children    = components.GroupBy(c => c.ClassId).ToDictionary(c => c.Key,
                                                                                                 c =>
                                                                                                 c.Select(
                                                                                                     i => i.Id)
                                                                                                 .ToList());
                            }
                            return(si);
                        }
                        catch (Exception e)
                        {
                            Debug.LogWarning("Failed to serialize status of " + n.name + " with error " +
                                             e.ToString());
                            return(null);
                        }
                    })
                                           .Where(si => si != null)
                                           .ToList();

                    //All of the data for the items to be stored

                    var toBeProcessed = UniqueIdentifier
                                        .AllIdentifiers
                                        .Where(o => o.GetComponent <StoreInformation>() != null || o.GetComponent <PrefabIdentifier>() != null)
                                        .Where(i => string.IsNullOrEmpty(id) || i.Id == id || HasParent(i, id))
                                        .Where(i => i != null)
                                        .Select(i => i.gameObject)
                                        .Where(i => i != null)
                                        .Where(go =>
                    {
                        var shouldSerialize = go.FindInterface <IControlSerializationEx>();
                        return(shouldSerialize == null || shouldSerialize.ShouldSaveWholeObject());
                    })
                                        .Distinct()
                                        .Where(go =>
                    {
                        if (Store == null)
                        {
                            return(true);
                        }
                        var result = true;
                        Store(go, ref result);

                        return(result);
                    })
                                        .SelectMany(o => o.GetComponents <Component>())
                                        .Where(c =>
                    {
                        if (c == null)
                        {
                            return(false);
                        }
                        var tp    = c.GetType();
                        var store = true;
                        StoreComponent(c, ref store);
                        return(store && (!(c is IControlSerialization) || (c as IControlSerialization).ShouldSave()) &&
                               !tp.IsDefined(typeof(DontStoreAttribute), true) &&
                               !IgnoreTypes.Contains(tp.FullName));
                    })
                                        .Select(c => new
                    {
                        Identifier =
                            (StoreInformation)c.gameObject.GetComponent(typeof(StoreInformation)),
                        Component = c
                    })
                                        .Where(cp =>
                                               (cp.Identifier.StoreAllComponents ||
                                                cp.Identifier.Components.Contains(cp.Component.GetType().FullName)))
                                        .OrderBy(cp => cp.Identifier.Id)
                                        .ThenBy(cp => cp.Component.GetType().FullName).ToList();
                    var processed = 0;
                    ld.StoredItems = toBeProcessed
                                     .Select(cp =>
                    {
                        try
                        {
                            if (Radical.IsLogging())
                            {
                                Radical.Log("<{0} : {1} - {2}>", cp.Component.gameObject.GetFullName(),
                                            cp.Component.GetType().Name,
                                            cp.Component.GetComponent <UniqueIdentifier>().Id);
                                Radical.IndentLog();
                            }
                            var sd = new StoredData()
                            {
                                Type    = cp.Component.GetType().FullName,
                                ClassId = cp.Identifier.ClassId,
                                Name    = cp.Component.GetComponent <UniqueIdentifier>().Id
                            };

                            if (CustomSerializers.ContainsKey(cp.Component.GetType()))
                            {
                                sd.Data = UnitySerializer.TextEncoding.GetString(CustomSerializers[cp.Component.GetType()].Serialize(cp.Component));
                            }
                            else
                            {
                                sd.Data = UnitySerializer.JSONSerializeForDeserializeInto(cp.Component);
                            }
                            if (Radical.IsLogging())
                            {
                                Radical.OutdentLog();
                                Radical.Log("</{0} : {1}>", cp.Component.gameObject.GetFullName(),
                                            cp.Component.GetType().Name);
                            }
                            processed++;
                            Progress("Storing", (float)processed / (float)toBeProcessed.Count);
                            return(sd);
                        }
                        catch (Exception e)
                        {
                            processed++;
                            Debug.LogWarning("Failed to serialize data (" +
                                             cp.Component.GetType().AssemblyQualifiedName + ") of " +
                                             cp.Component.name + " with error " + e.ToString());
                            return(null);
                        }
                    })
                                     .Where(s => s != null)
                                     .ToList();
                }
            }
        }
        var data = UnitySerializer.JSONSerialize(ld);

        return(data);
    }
Example #36
0
 private void LoadDefaultData() => _stored = new StoredData();
Example #37
0
 private void Loaded()
 {
     SaveConfig();
     storedData = Interface.Oxide.DataFileSystem.ReadObject <StoredData>(Name);
 }
Example #38
0
        private void OnServerInitialized()
        {
            if (!permission.PermissionExists(excludePermission))
            {
                permission.RegisterPermission(excludePermission, this);
            }
            playerConnections = Interface.GetMod().DataFileSystem.ReadObject <StoredData>(this.Title);
            foreach (BasePlayer player in BasePlayer.activePlayerList)
            {
                UpdatePlayer(player);
            }
            StoredData cleanedConnections = new StoredData();

            foreach (var pair in playerConnections.PlayerInfo)
            {
                if (UnixTimeStampUTC() - pair.Value.LastTime < removeRecordAfterDays * 86400)
                {
                    cleanedConnections.PlayerInfo.Add(pair.Key, pair.Value);
                }
                //cleanedConnections.PlayerInfo[pair.Key].LastDateTime = UnixTimeStampToDateTime(pair.Value.LastTime).ToString();
            }
            playerConnections = cleanedConnections;
            SaveData();
            cleanedConnections = null;
            if (excludeGroupOwner)
            {
                foreach (var user in ServerUsers.GetAll(ServerUsers.UserGroup.Owner).ToList())
                {
                    groupOwner.Add(user.steamid);
                }
            }
            if (excludeGroupModerator)
            {
                foreach (var user in ServerUsers.GetAll(ServerUsers.UserGroup.Moderator).ToList())
                {
                    groupModerator.Add(user.steamid);
                }
            }
            NextTick(() => {
                TimeSpan its = TimeSpan.FromSeconds(inactiveAfter);
                TimeSpan ts  = TimeSpan.FromSeconds(timerJob);
                if (timerEnabled)
                {
                    Puts($"Purge will be executed every: {ts.TotalHours.ToString("0")} hours ({ts.Days.ToString("0")}D | {ts.Hours.ToString("0")}H | {ts.Minutes.ToString("0")}M | {ts.Seconds.ToString("0")}S)");
                    Puts($"Players become inactive after: {its.TotalDays.ToString("0")} days ({its.Days.ToString("0")}D | {its.Hours.ToString("0")}H | {its.Minutes.ToString("0")}M | {its.Seconds.ToString("0")}S)");
                    timer.Every(timerJob, () => MainTimer(false));
                }
                else
                {
                    Puts("Timer function disabled by config. Purge needs to be started by command 'autopurge.run'");
                }

                if (Clans && useClansIO)
                {
                    clansEnabled = true;
                    Puts("Plugin 'Clans' found - Clan support activated");
                }
                if (!Clans && useClansIO)
                {
                    PrintWarning("Plugin 'Clans' not found - Clan support not active");
                }
                if (Friends && useFriendsApi)
                {
                    friendsEnabled = true;
                    Puts("Plugin 'Friends' found - Friends support activated");
                }
                if (!Friends && useFriendsApi)
                {
                    PrintWarning("Plugin 'Friends' not found - Friends support not active");
                }
                if (testMode)
                {
                    PrintWarning("Running in TestMode. Nothing will be purged");
                }
                if (purgeOnStart)
                {
                    MainTimer(true);
                }
            });
        }
Example #39
0
 public bool Exists(string key)
 => StoredData.ContainsKey(key);
Example #40
0
 private void LoadData() => storedData = Interface.GetMod().DataFileSystem.ReadObject <StoredData>(this.Name);
Example #41
0
 void LoadData()
 {
     var kits = Interface.Oxide.DataFileSystem.GetFile("Kits");
     try
     {
         kits.Settings.NullValueHandling = NullValueHandling.Ignore;
         storedData = kits.ReadObject<StoredData>();
         var update = new List<string>();
         foreach (var kit in storedData.Kits)
         {
             if (!kit.Key.Equals(kit.Key.ToLower()))
                 update.Add(kit.Key);
         }
         foreach (var key in update)
         {
             storedData.Kits[key.ToLower()] = storedData.Kits[key];
             storedData.Kits.Remove(key);
         }
     }
     catch
     {
         storedData = new StoredData();
     }
     kits.Settings.NullValueHandling = NullValueHandling.Include;
 }
Example #42
0
 void LoadPersistentData()
 {
     storedData = Interface.Oxide.DataFileSystem.ReadObject <StoredData>(Title);
 }
Example #43
0
 void LoadData()
 {
     zonedefinitions.Clear();
     try
     {
         storedData = Interface.GetMod().DataFileSystem.ReadObject<StoredData>("ZoneManager");
     }
     catch
     {
         storedData = new StoredData();
     }
     foreach (var zonedef in storedData.ZoneDefinitions)
         zonedefinitions[zonedef.ID] = zonedef;
 }
Example #44
0
 void ReadData() => storedData = Interface.Oxide.DataFileSystem.ReadObject <StoredData>(this.Title);
        private void Loaded()
        {
            this.storedData = Interface.GetMod().DataFileSystem.ReadObject<StoredData>(this.dataFile);

            if (this.storedData.Players == null) this.storedData.Players = new HashSet<PlayerGatherLevel>();
        }
 private void LoadData()
 {
     XmlSerializer XSR = new XmlSerializer(typeof(StoredData));
     //PopulateList:
     if (File.Exists("Finances.xml"))
     {
         FileStream FS = new FileStream("Finances.xml", FileMode.Open);
         if (FS.Length > 0)
         {
             SD = (StoredData)XSR.Deserialize(FS);
             HasData =true;
         }
         FS.Close();
         Income = SD.In;
         Outcome = SD.Out;
     }
     else
     {
         FileStream FS = new FileStream("Finances.xml", FileMode.CreateNew);
         FS.Close();
         //goto PopulateList;
     }
 }