Esempio n. 1
0
        public override void Initialize()
        {
            AssetPath = "file:///";
            Caching.expirationDelay = 1;
            Caching.CleanCache();
            Hooks.OnModulesLoaded += OnModulesLoaded;
            if (!File.Exists(Util.GetRootFolder() + "\\Save\\WorldEditorServer\\ClientSideAssets.txt"))
            {
                File.Create(Util.GetRootFolder() + "\\Save\\WorldEditorServer\\ClientSideAssets.txt").Dispose();
            }
            AssetPath = AssetPath + @Util.GetRootFolder() + "\\Save\\WorldEditorServer\\myasset.unity3d";
            RustBuster2016Server.API.AddFileToDownload(new RBDownloadable("WorldEditor\\", Util.GetRootFolder() + "\\Save\\WorldEditorServer\\myasset.unity3d"));
            RustBuster2016Server.API.AddFileToDownload(new RBDownloadable("WorldEditor\\", Util.GetRootFolder() + "\\Save\\WorldEditorServer\\ClientSideAssets.txt"));

            MainHolder = new GameObject();
            Handler    = MainHolder.AddComponent <LoadingHandler>();
            UnityEngine.Object.DontDestroyOnLoad(Handler);
            try
            {
                Handler.StartCoroutine(Handler.LoadAsset());
            }
            catch (Exception ex)
            {
                Logger.LogError("Couroutine failed. " + ex);
            }

            if (_FoundRB)
            {
                RustBuster2016Server.API.OnRustBusterUserMessage += OnRustBusterUserMessage;
            }
        }
        public override void Initialize()
        {
            RustPP = new RustPPExtension();

            var AssetPath_ = "file:///";

            Caching.expirationDelay = 1;
            Caching.CleanCache();

            Hooks.OnModulesLoaded      += OnModulesLoaded;
            Hooks.OnPlayerConnected    += OnPlayerConnected;
            Hooks.OnPlayerDisconnected += OnPlayerDisconnected;
            Hooks.OnPlayerSpawned      += OnPlayerSpawned;
            Hooks.OnPlayerKilled       += OnPlayerKilled;
            Hooks.OnCommand            += OnCommand;

            #region Settings

            if (!File.Exists(Util.GetRootFolder() + "\\Save\\WorldEditorServer\\ClientSideAssets.txt"))
            {
                File.Create(Util.GetRootFolder() + "\\Save\\WorldEditorServer\\ClientSideAssets.txt").Dispose();
            }

            if (!File.Exists(Util.GetRootFolder() + "\\Save\\WorldEditorServer\\Settings.ini"))
            {
                File.Create(Util.GetRootFolder() + "\\Save\\WorldEditorServer\\Settings.ini").Dispose();
                SettingsParser = new IniParser(Util.GetRootFolder() + "\\Save\\WorldEditorServer\\Settings.ini");
                SettingsParser.AddSetting("Settings", "AssetBundles");
                SettingsParser.AddSetting("Settings", "TimedSpawns");
                SettingsParser.AddSetting("Settings", "PerformanceLog", "false");
                SettingsParser.AddSetting("Settings", "BundlesToTransfer");
                SettingsParser.AddSetting("Settings", "BundleDownloadLink");
                SettingsParser.Save();
            }

            if (SettingsParser == null)
            {
                SettingsParser = new IniParser(Util.GetRootFolder() + "\\Save\\WorldEditorServer\\Settings.ini");
            }

            #endregion

            #region AssetBundles

            var bundlesString = SettingsParser.GetSetting("Settings", "AssetBundles");
            if (!string.IsNullOrEmpty(bundlesString))
            {
                foreach (var bundle in bundlesString.Split(','))
                {
                    if (string.IsNullOrEmpty(bundle))
                    {
                        continue;
                    }

                    Bundles.Add(bundle + "|" + AssetPath_ + Util.GetRootFolder() + "\\Save\\WorldEditorServer\\" +
                                bundle + ".unity3d");
                }
            }

            #endregion

            PerformanceLog = SettingsParser.GetBoolSetting("Settings", "PerformanceLog");

            #region ZoneSpawnAndDestroy

            var s = SettingsParser.GetSetting("Settings", "ZoneSpawnAndDestroy");
            if (!string.IsNullOrEmpty(s))
            {
                var dasEntries = s.Split('|');
                foreach (var dasEntry in dasEntries)
                {
                    if (string.IsNullOrEmpty(dasEntry))
                    {
                        continue;
                    }
                    var     dasEntrySplitted = dasEntry.Split('/');
                    Vector3 location         = Utils.StringToVector3(dasEntrySplitted[0]);
                    int     secondsToDestroy = int.Parse(dasEntrySplitted[1]);
                    int     radius           = int.Parse(dasEntrySplitted[2]);
                    string  prefab           = dasEntrySplitted[3];

                    _zones.Add(new Zone(location, radius, secondsToDestroy, prefab));
                }
            }

            #endregion

//            var bundlesToTransferString = SettingsParser.GetSetting("Settings", "BundlesToTransfer");
//            if (!string.IsNullOrEmpty(bundlesToTransferString))
//            {
//                var bundlesToTransfer = bundlesToTransferString.Split(',');
//                foreach (var bundleToTransfer in bundlesToTransfer)
//                {
//                    if (string.IsNullOrEmpty(bundleToTransfer))
//                        continue;

//                    RustBuster2016Server.API.AddFileToDownload(new RBDownloadable("WorldEditor\\", Util.GetRootFolder() + "\\Save\\WorldEditorServer\\" + bundleToTransfer + ".unity3d"));
//                }
//            }

//            TODO: AutoSpawn
//            var autoSpawnString = SettingsParser.GetSetting("Settings", "AutoSpawn");
//            if (!string.IsNullOrEmpty(autoSpawnString))
//            {
//                _autoSpawnGameObject = new GameObject();
//                var spawnBehaviour = _autoSpawnGameObject.AddComponent<AutoSpawnBehaviour>();
//                Object.DontDestroyOnLoad(_autoSpawnGameObject);
//
//                foreach (var autoSpawnEntryString in autoSpawnString.Split('|'))
//                {
//                    if (string.IsNullOrEmpty(autoSpawnEntryString))
//                    {
//                        continue;
//                    }
//
//                    if (!autoSpawnEntryString.Contains("/"))
//                    {
//                        string[] autoSpawnEntrySplit = autoSpawnEntryString.Split(':');
//
//                        var seconds = float.Parse(autoSpawnEntrySplit[0]);
//                        var destroySeconds = float.Parse(autoSpawnEntrySplit[1]);
//                        var bundle = autoSpawnEntrySplit[2];
//                        var name = autoSpawnEntrySplit[3];
//
//                        var locationString = autoSpawnEntrySplit[4].Split(',');
//                        Vector3 location = new Vector3(float.Parse(locationString[0]), float.Parse(locationString[1]),
//                            float.Parse(locationString[2]));
//
//                        var rotationString = autoSpawnEntrySplit[5].Split(',');
//                        Quaternion rotation = new Quaternion(float.Parse(rotationString[0]),
//                            float.Parse(rotationString[1]),
//                            float.Parse(rotationString[2]), float.Parse(rotationString[3]));
//
//                        var sizeString = autoSpawnEntrySplit[6].Split(',');
//                        Vector3 size = new Vector3(float.Parse(sizeString[0]), float.Parse(sizeString[1]),
//                            float.Parse(sizeString[2]));
//
//                        spawnBehaviour.StartCoroutine(
//                            spawnBehaviour.WaitAndSpawn(new AutoSpawnManager.SpawnedObject(seconds, destroySeconds,
//                                name,
//                                bundle, location,
//                                rotation,
//                                size)));
//
//                        Logger.Log("[WorldEditor] Started AutoSpawn Coroutine for " + name);
//                    }
//                    else
//                    {
//                        List<AutoSpawnManager.SpawnedObject>
//                            objectsToSpawn = new List<AutoSpawnManager.SpawnedObject>();
//                        foreach (var multiEntry in autoSpawnEntryString.Split('/'))
//                        {
//                            string[] autoSpawnEntrySplit = multiEntry.Split(':');
//
//                            var seconds = float.Parse(autoSpawnEntrySplit[0]);
//                            var destroySeconds = float.Parse(autoSpawnEntrySplit[1]);
//                            var bundle = autoSpawnEntrySplit[2];
//                            var name = autoSpawnEntrySplit[3];
//
//                            var locationString = autoSpawnEntrySplit[4].Split(',');
//                            Vector3 location = new Vector3(float.Parse(locationString[0]),
//                                float.Parse(locationString[1]),
//                                float.Parse(locationString[2]));
//
//                            var rotationString = autoSpawnEntrySplit[5].Split(',');
//                            Quaternion rotation = new Quaternion(float.Parse(rotationString[0]),
//                                float.Parse(rotationString[1]),
//                                float.Parse(rotationString[2]), float.Parse(rotationString[3]));
//
//                            var sizeString = autoSpawnEntrySplit[6].Split(',');
//                            Vector3 size = new Vector3(float.Parse(sizeString[0]), float.Parse(sizeString[1]),
//                                float.Parse(sizeString[2]));
//
//                            objectsToSpawn.Add(new AutoSpawnManager.SpawnedObject(seconds, destroySeconds, name, bundle,
//                                location, rotation, size));
//                        }
//
//                        spawnBehaviour.StartCoroutine(spawnBehaviour.WaitAndSpawn(objectsToSpawn));
//
//                        Logger.Log("[WorldEditor] Started multi AutoSpawn Coroutine for " + objectsToSpawn.Count +
//                                   " objects");
//                    }
//                }
//            }

//            API.AddFileToDownload(new RBDownloadable("WorldEditor\\",
//                Util.GetRootFolder() + "\\Save\\WorldEditorServer\\Settings.ini"));
//            API.AddFileToDownload(new RBDownloadable("WorldEditor\\",
//                Util.GetRootFolder() + "\\Save\\WorldEditorServer\\ClientSideAssets.txt"));
//            API.AddFileToDownload(new RBDownloadable("WorldEditor\\",
//                Util.GetRootFolder() + "\\Save\\WorldEditorServer\\Splash.png"));
//            API.AddFileToDownload(new RBDownloadable("WorldEditor\\",
//                Util.GetRootFolder() + "\\Save\\WorldEditorServer\\Hud.png"));

            MainHolder = new GameObject();
            Handler    = MainHolder.AddComponent <LoadingHandler>();
            Object.DontDestroyOnLoad(MainHolder);
            try
            {
                Handler.StartCoroutine(Handler.LoadAsset());
            }
            catch (Exception ex)
            {
                Logger.LogError("Couroutine failed. " + ex);
            }

            if (_FoundRB)
            {
                API.OnRustBusterUserMessage += OnRustBusterUserMessage;
            }
        }