Esempio n. 1
0
 void UpdateRapidMod(string tag)
 {
     if (!string.IsNullOrEmpty(delayedModChange) && !spring.IsRunning)
     {
         string latest = delayedModChange;
         delayedModChange = null;
         config.Mod       = latest;
         SayBattle("Updating to latest mod version: " + latest);
         ComRehost(TasSayEventArgs.Default, new[] { latest });
     }
     else
     {
         PackageDownloader.Version version = Program.main.Downloader.PackageDownloader.GetByTag(tag);
         if (version != null)
         {
             string latest = version.InternalName;
             if (!String.IsNullOrEmpty(latest) && (tas.MyBattle == null || tas.MyBattle.ModName != latest))
             {
                 if (cache.GetResourceDataByInternalName(latest) != null && !spring.IsRunning)
                 {
                     config.Mod = latest;
                     SayBattle("Updating to latest mod version: " + latest);
                     ComRehost(TasSayEventArgs.Default, new[] { latest });
                 }
                 else
                 {
                     delayedModChange = latest;
                 }
             }
         }
     }
 }
        public static void DeployAndResetConfigs(SpringPaths paths, PackageDownloader.Version ver)
        {
            if (ver != null)
            {
                var  oldVers  = LoadFromDisk(paths) ?? new ConfigVersions();
                var  newVers  = LoadFromChobby(ver, paths);
                bool hasError = false;

                if (newVers != null)
                {
                    foreach (
                        var versionEntry in newVers.Versions.Where(x => string.IsNullOrEmpty(x.Platform) || x.Platform == paths.Platform.ToString()))
                    {
                        try
                        {
                            var target = Path.Combine(paths.WritableDirectory, versionEntry.TargetPath);

                            if (
                                !oldVers.Versions.Any(
                                    x =>
                                    x.TargetPath == versionEntry.TargetPath && x.VersionNumber >= versionEntry.VersionNumber &&
                                    x.Platform == versionEntry.Platform) || !File.Exists(target))
                            {
                                var dirName = Path.GetDirectoryName(target);
                                if (!Directory.Exists(dirName))
                                {
                                    Directory.CreateDirectory(dirName);
                                }

                                var content = ver.ReadFile(paths, versionEntry.SourcePath);
                                if (content != null)
                                {
                                    var targetBytes = content.ToArray();

                                    if (!File.Exists(target) || !Hash.ByteArrayEquals(File.ReadAllBytes(target), targetBytes))
                                    {
                                        File.WriteAllBytes(target, targetBytes);
                                    }
                                }
                                else
                                {
                                    File.Delete(target);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            hasError = true;
                            Trace.TraceError("Error processing file deployment {0} : {1}", versionEntry.SourcePath, ex);
                        }
                    }
                }
                if (!hasError)
                {
                    (newVers ?? oldVers).SaveToDisk(paths);
                }
            }
        }
        private static ConfigVersions LoadFromChobby(PackageDownloader.Version ver, SpringPaths paths)
        {
            var ms = ver?.ReadFile(paths, FilePathInChobby);

            if (ms != null)
            {
                return(TryDeserialize(Encoding.UTF8.GetString(ms.ToArray())));
            }
            return(null);
        }
Esempio n. 4
0
 private dynamic ExtractEngineFromLua(PackageDownloader.Version ver)
 {
     if (ver != null)
     {
         var     mi            = ver.ReadFile(paths, "modinfo.lua");
         var     lua           = new Lua();
         var     luaEnv        = lua.CreateEnvironment();
         dynamic result        = luaEnv.DoChunk(new StreamReader(mi), "dummy.lua");
         var     engineVersion = result.engine;
         return(engineVersion);
     }
     return(null);
 }
Esempio n. 5
0
        public async Task <bool> Prepare()
        {
            try
            {
                PackageDownloader.Version ver = null;
                internalName = null;

                if (!isDev)
                {
                    if (!Debugger.IsAttached && !IsSteamFolder)
                    {
                        Status = "Checking for self-upgrade";
                        var selfUpdater = new SelfUpdater("Zero-K");
                        selfUpdater.ProgramUpdated += delegate
                        {
                            Process.Start(Application.ExecutablePath, string.Join(" ", Environment.GetCommandLineArgs().Skip(1)));
                            Environment.Exit(0);
                        };
                        var task = new Task <bool>(() => selfUpdater.CheckForUpdate());
                        task.Start();
                        await task;
                    }

                    if (!IsSteamFolder)
                    {
                        downloader.RapidHandling = RapidHandling.SdzNameHash;

                        if (!await downloader.DownloadFile("Checking for chobby update", DownloadType.RAPID, chobbyTag, Progress, 2))
                        {
                            return(false);
                        }
                        if (!await downloader.DownloadFile("Checking for game update", DownloadType.RAPID, GlobalConst.DefaultZkTag, Progress, 2))
                        {
                            return(false);
                        }

                        downloader.RapidHandling = RapidHandling.DefaultSdp;

                        ver          = downloader.PackageDownloader.GetByTag(chobbyTag);
                        internalName = ver.InternalName;
                    }
                    else
                    {
                        internalName = GetSteamChobby();
                        ver          = downloader.PackageDownloader.GetByInternalName(internalName) ?? downloader.PackageDownloader.GetByTag(chobbyTag);
                    }

                    if (ver == null)
                    {
                        Status = "Rapid package appears to be corrupted, please clear the folder";
                        return(false);
                    }
                }
                else
                {
                    internalName = "Chobby $VERSION";
                }


                engine = engine ?? GetSteamEngine() ?? QueryDefaultEngine() ?? GlobalConst.DefaultEngineOverride;

                try
                {
                    GameAnalytics.ConfigureGameEngineVersion(internalName);
                    GameAnalytics.ConfigureSdkGameEngineVersion(engine);
                }
                catch (Exception ex)
                {
                    Trace.TraceWarning("Game analytics failed to configure version: {0}", ex);
                }


                if (!IsSteamFolder)
                {
                    if (!await downloader.DownloadFile("Downloading engine", DownloadType.ENGINE, engine, Progress, 2))
                    {
                        return(false);
                    }

                    if (!await downloader.UpdateMissions(Progress))
                    {
                        Trace.TraceWarning("Mission update has failed");
                        Status = "Error updating missions";
                    }
                }
                else
                {
                    ClearSdp();
                }



                downloader.UpdatePublicCommunityInfo(Progress);

                if (!isDev)
                {
                    Status = "Reseting configs and deploying AIs";
                    ConfigVersions.DeployAndResetConfigs(paths, ver);
                }


                return(true);
            }
            catch (Exception ex)
            {
                Trace.TraceError("Unexpected error: {0}", ex);
                GameAnalytics.AddErrorEvent(EGAErrorSeverity.Error, $"Unexpected error {Status}: {ex}");
                Status = "Unexpected error preparing chobby launch: " + ex.Message;
                return(false);
            }
        }
Esempio n. 6
0
        public void OpenBattleRoom(string modname, string mapname, bool now = true)
        {
            if (!now && spring.IsRunning)
            {
                spring.WaitForExit();
            }
            Stop();

            bossName      = "";
            lastMapChange = DateTime.Now;

            if (String.IsNullOrEmpty(modname))
            {
                modname = config.Mod;
            }
            if (String.IsNullOrEmpty(mapname))
            {
                mapname = config.Map;
            }

            string title = config.Title.Replace("%1", MainConfig.SpringieVersion);

            string password = null;

            if (!string.IsNullOrEmpty(config.BattlePassword))
            {
                password = config.BattlePassword;
            }

            int    maxPlayers = config.MaxPlayers;
            string engine     = springPaths.SpringVersion;

            if (SpawnConfig != null)
            {
                modname = SpawnConfig.Mod;
                if (SpawnConfig.MaxPlayers > 0)
                {
                    maxPlayers = SpawnConfig.MaxPlayers;
                }
                if (!String.IsNullOrEmpty(SpawnConfig.Map))
                {
                    mapname = SpawnConfig.Map;
                }
                title = SpawnConfig.Title;
                if (!String.IsNullOrEmpty(SpawnConfig.Password))
                {
                    password = SpawnConfig.Password;
                }
                if (!String.IsNullOrEmpty(SpawnConfig.Engine))
                {
                    engine = SpawnConfig.Engine;
                }
                {
                    //Something needs to go here to properly tell Springie to use a specific engine version,
                    //attempted code below may or may not be responsible for recent springie drops, so commenting.

                    //the below may be causing a rehost
                    //requestedEngineChange = SpawnConfig.Engine;

                    //alternate attempt

                    /*
                     * Program.main.Downloader.GetAndSwitchEngine(SpawnConfig.Engine);
                     * config.SpringVersion = SpawnConfig.Engine;
                     * springPaths.SetEnginePath(Program.main.paths.GetEngineFolderByVersion(SpawnConfig.Engine));
                     */
                }
            }

            //title = title + string.Format(" [engine{0}]", springPaths.SpringVersion);

            // no mod was provided, auto update is on, check if newer version exists, if it does use that instead of config one
            if (string.IsNullOrEmpty(modname) && !String.IsNullOrEmpty(config.AutoUpdateRapidTag))
            {
                var ver = Program.main.Downloader.PackageDownloader.GetByTag(config.AutoUpdateRapidTag);

                if (ver != null && cache.GetResourceDataByInternalName(ver.InternalName) != null)
                {
                    modname = config.AutoUpdateRapidTag;
                }
            }

            PackageDownloader.Version version = Program.main.Downloader.PackageDownloader.GetByTag(modname);
            if (version != null && version.InternalName != null)
            {
                modname = version.InternalName;
            }

            hostedMod = new Mod()
            {
                Name = modname
            };
            cache.GetMod(modname, (m) => { hostedMod = m; }, (m) => {});
            if (hostedMod.IsMission && !String.IsNullOrEmpty(hostedMod.MissionMap))
            {
                mapname = hostedMod.MissionMap;
            }

            //Map mapi = null;
            //cache.GetMap(mapname, (m, x, y, z) => { mapi = m; }, (e) => { }, springPaths.SpringVersion);
            //int mint, maxt;
            if (!springPaths.HasEngineVersion(engine))
            {
                Program.main.Downloader.GetAndSwitchEngine(engine, springPaths);
            }
            else
            {
                springPaths.SetEnginePath(springPaths.GetEngineFolderByVersion(engine));
            }

            var b = new Battle(engine, password, hostingPort, maxPlayers, mapname, title, modname);

            b.Ip = Program.main.Config.IpOverride;
            tas.OpenBattle(b);
        }
Esempio n. 7
0
        public void Start(string modname, string mapname, bool now = true)
        {
            if (!now && spring.IsRunning)
            {
                spring.WaitForExit();
            }
            Stop();

            lastMapChange = DateTime.Now;

            if (String.IsNullOrEmpty(modname))
            {
                modname = config.Mod;
            }
            if (String.IsNullOrEmpty(mapname))
            {
                mapname = config.Map;
            }

            string title    = config.Title.Replace("%1", MainConfig.SpringieVersion);
            string password = "******";

            if (!string.IsNullOrEmpty(config.BattlePassword))
            {
                password = config.BattlePassword;
            }

            if (SpawnConfig != null)
            {
                modname = SpawnConfig.Mod;
                mapname = SpawnConfig.Map;
                title   = SpawnConfig.Title;
                if (!String.IsNullOrEmpty(SpawnConfig.Password))
                {
                    password = SpawnConfig.Password;
                }
                if (!String.IsNullOrEmpty(SpawnConfig.Engine))
                {
                    //Something needs to go here to properly tell Springie to use a specific engine version,
                    //attempted code below may or may not be responsible for recent springie drops, so commenting.

                    //the below may be causing a rehost
                    //requestedEngineChange = SpawnConfig.Engine;

                    //alternate attempt

                    /*
                     * Program.main.Downloader.GetAndSwitchEngine(SpawnConfig.Engine);
                     * config.SpringVersion = SpawnConfig.Engine;
                     * springPaths.SetEnginePath(Program.main.paths.GetEngineFolderByVersion(SpawnConfig.Engine));
                     */
                }
            }

            //title = title + string.Format(" [engine{0}]", springPaths.SpringVersion);

            // no mod was provided, auto update is on, check if newer version exists, if it does use that instead of config one
            if (string.IsNullOrEmpty(modname) && !String.IsNullOrEmpty(config.AutoUpdateRapidTag))
            {
                var ver = Program.main.Downloader.PackageDownloader.GetByTag(config.AutoUpdateRapidTag);

                if (ver != null && cache.GetResourceDataByInternalName(ver.InternalName) != null)
                {
                    modname = config.AutoUpdateRapidTag;
                }
            }

            PackageDownloader.Version version = Program.main.Downloader.PackageDownloader.GetByTag(modname);
            if (version != null && cache.GetResourceDataByInternalName(version.InternalName) != null)
            {
                modname = version.InternalName;
            }

            hostedMod = new Mod();
            cache.GetMod(modname, (m) => { hostedMod = m; }, (m) => { }, springPaths.SpringVersion);
            if (hostedMod.IsMission && !String.IsNullOrEmpty(hostedMod.MissionMap))
            {
                mapname = hostedMod.MissionMap;
            }

            Map mapi = null;

            cache.GetMap(mapname, (m, x, y, z) => { mapi = m; }, (e) => { }, springPaths.SpringVersion);
            //int mint, maxt;
            var b = new Battle(springPaths.SpringVersion, password, hostingPort, config.MaxPlayers, 0, mapi, title, hostedMod, new BattleDetails());

            // if hole punching enabled then we use it
            if (Program.main.Config.UseHolePunching)
            {
                b.Nat = Battle.NatMode.HolePunching;
            }
            else if (Program.main.Config.GargamelMode)
            {
                b.Nat = Battle.NatMode.FixedPorts;
            }
            else
            {
                b.Nat = Battle.NatMode.None;  // else either no nat or fixed ports (for gargamel fake - to get client IPs)
            }
            tas.OpenBattle(b);
            tas.SetScriptTag("GAME/hosttype=SPRINGIE");
        }