示例#1
0
        public PlanetWarsHandler(string host, int port, AutoHost autoHost, TasClient tas, MainConfig config)
        {
            this.autoHost = autoHost;
            this.tas      = tas;
            this.host     = host;
            account       = new AuthInfo(config.AccountName, config.PlanetWarsServerPassword);

            server = (ISpringieServer)Activator.GetObject(typeof(ISpringieServer), String.Format("tcp://{0}:{1}/IServer", host, port));
            // fill factions for channel monitoring and join channels
            planetWarsChannels = new List <string>();
            var factions = server.GetFactions(account);

            foreach (var fact in factions)
            {
                string name = fact.Name.ToLower();
                planetWarsChannels.Add(name);
                if (!config.JoinChannels.Contains(name))
                {
                    var list = new List <string>(config.JoinChannels);
                    list.Add(name);
                    config.JoinChannels = list.ToArray();
                    if (tas != null && tas.IsConnected && tas.IsLoggedIn)
                    {
                        tas.JoinChannel(name);
                    }
                }
            }
            timer.Interval  = 2000;
            timer.Elapsed  += timer_Elapsed;
            timer.AutoReset = true;
            timer.Start();
        }
        public PlanetWarsHandler(string host, int port, AutoHost autoHost, TasClient tas, MainConfig config)
        {
            this.autoHost = autoHost;
            this.tas = tas;
            this.host = host;
            account = new AuthInfo(config.AccountName, config.PlanetWarsServerPassword);

            server = (ISpringieServer) Activator.GetObject(typeof (ISpringieServer), String.Format("tcp://{0}:{1}/IServer", host, port));
            // fill factions for channel monitoring and join channels
            planetWarsChannels = new List<string>();
            var factions = server.GetFactions(account);
            foreach (var fact in factions) {
                string name = fact.Name.ToLower();
                planetWarsChannels.Add(name);
                if (!config.JoinChannels.Contains(name)) {
                    var list = new List<string>(config.JoinChannels);
                    list.Add(name);
                    config.JoinChannels = list.ToArray();
                    if (tas != null && tas.IsConnected && tas.IsLoggedIn) tas.JoinChannel(name);
                }
            }
            timer.Interval = 2000;
            timer.Elapsed += timer_Elapsed;
            timer.AutoReset = true;
            timer.Start();
        }
示例#3
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);
            }
        }