コード例 #1
0
        public bool StartGame(TasSayEventArgs e)
        {
            try {
                if (!autoHost.ComFix(e, "silent"))
                {
                    autoHost.Respond(e, "Teams were not fixed, fixing");
                    return(false);
                }

                string currentMapName = tas.GetBattle().Map.Name;
                var    planet         = server.GetAttackOptions(account).Where(p => p.MapName == currentMapName).SingleOrDefault();

                if (planet == null)
                {
                    autoHost.SayBattle("This planet is not currently allowed, select another one");
                    return(false);
                }

                var factions = server.GetFactions(account);
                var actual   = new List <IPlayer>();
                foreach (var user in tas.GetBattle().Users)
                {
                    if (!user.IsSpectator)
                    {
                        var info = server.GetPlayerInfo(account, user.name);
                        actual.Add(info);
                        string side    = tas.GetBattle().Mod.Sides[user.Side];
                        string hisSide = factions.Where(f => f.Name == info.FactionName).Single().SpringSide;

                        if (!string.Equals(side, hisSide, StringComparison.InvariantCultureIgnoreCase))
                        {
                            autoHost.SayBattle(string.Format("{0} must switch to {1}", user.name, hisSide), false);
                            return(false);
                        }
                    }
                }


                string options = server.GetStartupModOptions(account, tas.GetBattle().Map.Name, actual);
                //SayBattle(Encoding.ASCII.GetString(Convert.FromBase64String(options.Replace("+", "="))));
                var b = tas.GetBattle();
                foreach (var o in b.Mod.Options)
                {
                    if (o.Key == "planetwars")
                    {
                        string res;
                        if (o.GetPair(options, out res))
                        {
                            tas.SetScriptTag(res);

                            var startEvent = server.GetPlayersToNotify(account, currentMapName, ReminderEvent.OnBattleStarted);
                            foreach (var s in startEvent)
                            {
                                tas.Say(TasClient.SayPlace.User, s, string.Format("PlanetWars battle for planet {0} owned by {1} is starting.", planet.Name, planet.OwnerName), false);
                            }

                            return(true);
                        }
                        else
                        {
                            autoHost.Respond(e, "Eror setting script tag");
                            return(false);
                        }
                    }
                }
                autoHost.Respond(e, "This mod does not support PlanetWars");
                return(false);
            } catch (Exception ex) {
                autoHost.SayBattle(string.Format("Error when checking PlanetWars teams: {0}", ex), false);
                return(false);
            }
        }
コード例 #2
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");
        }