Esempio n. 1
0
        protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
        {
            if (spring.IsRunning)
            {
                context     = spring.StartContext;
                voteStarter = context.Players.FirstOrDefault(x => x.Name == e.UserName && !x.IsSpectator);
                if (voteStarter != null)
                {
                    question = string.Format("Resign team {0}?", voteStarter.AllyID + 1);
                    int cnt = 0;
                    foreach (var p in context.Players.Where(x => x.AllyID == voteStarter.AllyID && !x.IsSpectator))
                    {
                        if (p.IsIngame || tas.MyBattle.Users.ContainsKey(p.Name))
                        {
                            //Note: "ExistingUsers" is empty if users disconnected from lobby but still ingame.

                            bool afk = tas.ExistingUsers.ContainsKey(p.Name) && tas.ExistingUsers[p.Name].IsAway;
                            if (!afk)
                            {
                                cnt++;
                            }
                        }
                    }
                    winCount = cnt / 2 + 1;
                    return(true);
                }
            }
            AutoHost.Respond(tas, spring, e, "You cannot resign now");
            question = null;
            winCount = 0;
            return(false);
        }
Esempio n. 2
0
 protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
 {
     winCount = 0;
     question = null;
     if (spring.IsRunning)
     {
         question = "Exit this game?";
         int cnt = 0;
         context = spring.StartContext;
         foreach (var p in context.Players.Where(x => !x.IsSpectator))
         {
             if (p.IsIngame || tas.MyBattle.Users.ContainsKey(p.Name))
             {
                 if (!tas.ExistingUsers[p.Name].IsAway)
                 {
                     cnt++;
                 }
             }
         }
         winCount = cnt / 2 + 1;
         return(true);
     }
     else
     {
         AutoHost.Respond(tas, spring, e, "game not running");
         return(false);
     }
 }
Esempio n. 3
0
 protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
 {
     winCount = 0;
     question = null;
     if (words.Length == 0)
     {
         question = "Rehost this game?";
         return(true);
     }
     else
     {
         string[] mods;
         int[]    indexes;
         if (AutoHost.FilterMods(words, ah, out mods, out indexes) == 0)
         {
             AutoHost.Respond(tas, spring, e, "cannot find such mod");
             return(false);
         }
         else
         {
             modname  = mods[0];
             question = "Rehost this game to " + modname + "?";
             return(true);
         }
     }
 }
Esempio n. 4
0
 public void StopAutohost(AutoHost ah)
 {
     ah.Dispose();
     lock (autoHosts)
     {
         autoHosts.Remove(ah);
     }
 }
 public AutoManager(AutoHost ah, TasClient tas, Spring spring)
 {
   this.ah = ah;
   this.tas = tas;
   this.spring = spring;
   timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
   timer.Start();
 }
Esempio n. 6
0
 public void SpawnAutoHost(AhConfig config, SpawnConfig spawnData)
 {
     lock (autoHosts)
     {
         var ah = new AutoHost(MetaCache, config, GetFreeHostingPort(), spawnData);
         autoHosts.Add(ah);
         ah.ServerVerifyMap(true);
     }
 }
Esempio n. 7
0
        public AutoHost SpawnAutoHost(AhConfig config, SpawnConfig spawnData)
        {
            AutoHost ah;

            lock (autoHosts)
            {
                ah = new AutoHost(MetaCache, config, GetFreeHostingPort(), spawnData);
                autoHosts.Add(ah);
            }
            return(ah);
        }
Esempio n. 8
0
        public void Start()
        {
            if (config.AttemptToRecconnect)
            {
                recon          = new System.Timers.Timer(config.AttemptReconnectInterval * 1000);
                recon.Elapsed += new ElapsedEventHandler(recon_Elapsed);
            }

            recon.Enabled = false;

            try {
                spring = new Spring(config.SpringPath);
            } catch {
                MessageBox.Show("Spring not found in " + config.SpringPath, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                OpenFileDialog od = new OpenFileDialog();
                od.FileName         = Spring.ExecutableName;
                od.DefaultExt       = Path.GetExtension(Spring.ExecutableName);
                od.InitialDirectory = config.SpringPath;
                od.Title            = "Please select your spring installation";
                od.RestoreDirectory = true;
                od.CheckFileExists  = true;
                od.CheckPathExists  = true;
                od.AddExtension     = true;
                od.Filter           = "Executable (*.exe)|*.exe";
                DialogResult dr = od.ShowDialog();
                if (dr == DialogResult.OK)
                {
                    config.SpringPath = Path.GetDirectoryName(od.FileName);
                    SaveConfig();
                    spring = new Spring(config.SpringPath);
                }
                else
                {
                    throw new Exception("Spring not found");
                }
            }


            tas = new TasClient();
            tas.ConnectionLost   += new EventHandler <TasEventArgs>(tas_ConnectionLost);
            tas.Connected        += new EventHandler <TasEventArgs>(tas_Connected);
            tas.LoginDenied      += new EventHandler <TasEventArgs>(tas_LoginDenied);
            tas.LoginAccepted    += new EventHandler <TasEventArgs>(tas_LoginAccepted);
            tas.Said             += new EventHandler <TasSayEventArgs>(tas_Said);
            spring.SpringStarted += new EventHandler(spring_SpringStarted);
            spring.SpringExited  += new EventHandler(spring_SpringExited);
            spring.PlayerSaid    += new EventHandler <SpringLogEventArgs>(spring_PlayerSaid);
            autoHost              = new AutoHost(tas, spring, null);
            try {
                tas.Connect(config.ServerHost, config.ServerPort);
            } catch {
                recon.Start();
            }
        }
Esempio n. 9
0
 override protected bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
 {
     winCount = 0;
     question = null;
     if (spring.IsRunning)
     {
         question = "Force game?";
         return(true);
     }
     else
     {
         AutoHost.Respond(tas, spring, e, "battle not started yet");
         return(false);
     }
 }
Esempio n. 10
0
 protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
 {
     winCount = 0;
     question = null;
     if (spring.IsRunning)
     {
         question = "Exit this game?";
         return(true);
     }
     else
     {
         AutoHost.Respond(tas, spring, e, "game not running");
         return(false);
     }
 }
Esempio n. 11
0
        protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
        {
            winCount            = 0;
            question            = null;
            CountNoIntoWinCount = false;

            if (!spring.IsRunning)
            {
                var invalid = tas.MyBattle.Users.Values.Where(x => !x.IsSpectator && (x.SyncStatus != SyncStatuses.Synced || x.LobbyUser.IsAway)).ToList();
                if (invalid.Count > 0)
                {
                    foreach (var inv in invalid)
                    {
                        ah.ComRing(e, new[] { inv.Name });                                             // ring invalids ot notify them
                    }
                }
                // people wihtout map and spring map changed in last 2 minutes, dont allow start yet
                if (tas.MyBattle.Users.Values.Any(x => !x.IsSpectator && x.SyncStatus != SyncStatuses.Synced) && DateTime.Now.Subtract(ah.lastMapChange).TotalSeconds < MainConfig.MapChangeDownloadWait)
                {
                    var waitTime = (int)(MainConfig.MapChangeDownloadWait - DateTime.Now.Subtract(ah.lastMapChange).TotalSeconds);
                    AutoHost.Respond(tas, spring, e, string.Format("Map was changed and some players don't have it yet, please wait {0} more seconds", waitTime));
                    return(false);
                }

                question = "Start game? ";

                if (invalid.Count > 0)
                {
                    var invalids = string.Join(",", invalid);
                    ah.SayBattle(invalids + " will be forced spectators if they don't download their maps and stop being afk when vote ends");
                    question += string.Format("WARNING, SPECTATES: {0}", invalids);
                }
                if (tas.MyBattle.Users.Values.Count(x => !x.IsSpectator) >= 2)
                {
                    winCount = (tas.MyBattle.Users.Values.Count(x => !x.IsSpectator) + 1) / 2 + 1;
                }
                else
                {
                    winCount = 1;
                }
                return(true);
            }
            else
            {
                AutoHost.Respond(tas, spring, e, "battle already started");
                return(false);
            }
        }
Esempio n. 12
0
 protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
 {
     winCount = 0;
     question = null;
     if (!spring.IsRunning)
     {
         question = "Force start game?";
         winCount = tas.MyBattle.Users.Values.Count(x => !x.IsSpectator) / 2 + 1;
         return(true);
     }
     else
     {
         AutoHost.Respond(tas, spring, e, "battle already started");
         return(false);
     }
 }
Esempio n. 13
0
        public AutoHost SpawnAutoHost(AhConfig config, SpawnConfig spawnData)
        {
            AutoHost ah;

            lock (autoHosts)
            {
                ah = new AutoHost(MetaCache, config, GetFreeHostingPort(), spawnData);
                var otherClone = autoHosts.Where(x => x.config.Login == config.Login).Max(x => (int?)x.CloneNumber);
                if (otherClone.HasValue)
                {
                    ah.CloneNumber = otherClone.Value + 1;
                }

                autoHosts.Add(ah);
            }
            return(ah);
        }
Esempio n. 14
0
        public void FindLinks(string[] words, FileType type, TasClient tas, TasSayEventArgs e)
        {
            if (words.Length == 0)
            {
                var b = tas.GetBattle();
                if (b == null)
                {
                    return;
                }
                Program.main.AutoHost.Respond(e, string.Format("Getting SpringDownloader mirrors for currently hosted {0}", type));
                if (type == FileType.Map)
                {
                    RequestLink(new LinkRequest(b.Map.Checksum, e));
                }
                else
                {
                    RequestLink(new LinkRequest(b.Mod.Checksum, e));
                }
            }
            else
            {
                List <string> items;
                if (type == FileType.Map)
                {
                    items = new List <string>(Program.main.Spring.UnitSyncWrapper.MapList.Keys);
                }
                else
                {
                    items = new List <string>(Program.main.Spring.UnitSyncWrapper.ModList.Keys);
                }

                int[]    resultIndexes;
                string[] resultVals;
                int      cnt = AutoHost.Filter(items.ToArray(), words, out resultVals, out resultIndexes);
                if (cnt == 0)
                {
                    Program.main.AutoHost.Respond(e, string.Format("No such {0} found", type));
                }
                Program.main.AutoHost.Respond(e, string.Format("Getting SpringDownloader mirrors for {0}, please wait", resultVals[0]));

                int hash = type == FileType.Map ? Program.main.Spring.UnitSyncWrapper.MapList[resultVals[0]].Checksum : Program.main.Spring.UnitSyncWrapper.ModList[resultVals[0]].Checksum;

                RequestLink(new LinkRequest(hash, e));
            }
        }
Esempio n. 15
0
 protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
 {
     winCount = 0;
     question = null;
     if (spring.IsRunning)
     {
         AutoHost.Respond(tas, spring, e, "Cannot attack a different planet while the game is running");
         return(false);
     }
     else
     {
         if (words.Length > 0)
         {
             // FIXME get list of valid planets
             //string[] vals;
             //int[] indexes;
             //ah.FilterMaps(words, out vals, out indexes);
             if (true)   //(vals.Length > 0)
             {
                 try
                 {
                     planetID = System.Convert.ToInt32(words[0]);
                     question = string.Format("Attack planet {0} {2}/Planetwars/Planet/{1} ?", planetID, planetID, GlobalConst.BaseSiteUrl);   // FIXME get planet name
                     return(true);
                 }
                 catch (System.FormatException ex)
                 {
                     AutoHost.Respond(tas, spring, e, "Invalid planet ID");
                     return(false);
                 }
             }
             else
             {
                 AutoHost.Respond(tas, spring, e, "Invalid planet for attack");
                 return(false);
             }
         }
         else
         {
             AutoHost.Respond(tas, spring, e, "Please specify a planet");    // FIXME list possible planets
             return(false);
         }
     }
 }
Esempio n. 16
0
        protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
        {
            winCount = 0;
            question = null;
            if (words.Length == 0)
            {
                if (ah.BossName == "")
                {
                    ah.Respond(e, "there is currently no boss to remove");
                    return(false);
                }
                else
                {
                    player   = "";
                    question = "Remove current boss " + ah.BossName + "?";
                    return(true);
                }
            }

            string[] players;
            int[]    indexes;
            if (AutoHost.FilterUsers(words, tas, spring, out players, out indexes) > 0)
            {
                player = players[0];
                if (player == tas.UserName)
                {
                    ah.Respond(e, "you flatter me, but no");
                    return(false);
                }
                else
                {
                    question = "Elect " + player + " for the boss?";
                    return(true);
                }
            }
            else
            {
                AutoHost.Respond(tas, spring, e, "Cannot find such player");
                return(false);
            }
        }
Esempio n. 17
0
        public bool Start()
        {
            if (config.AttemptToRecconnect)
            {
                recon          = new Timer(config.AttemptReconnectInterval * 1000);
                recon.Elapsed += recon_Elapsed;
            }

            recon.Enabled = false;
            spring        = new Spring();


            tas = new TasClient();
            tas.ConnectionLost          += tas_ConnectionLost;
            tas.Connected               += tas_Connected;
            tas.LoginDenied             += tas_LoginDenied;
            tas.LoginAccepted           += tas_LoginAccepted;
            tas.Said                    += tas_Said;
            tas.MyStatusChangedToInGame += tas_MyStatusChangedToInGame;
            tas.ChannelUserAdded        += tas_ChannelUserAdded;
            spring.SpringExited         += spring_SpringExited;
            spring.SpringStarted        += spring_SpringStarted;
            spring.PlayerSaid           += spring_PlayerSaid;
            autoHost                     = new AutoHost(tas, spring, null);
            if (config.PlanetWarsEnabled)
            {
                InitializePlanetWarsServer();
            }
            autoUpdater = new AutoUpdater(spring, tas);

            if (config.StatsEnabledReal)
            {
                stats = new Stats(tas, spring);
            }
            try {
                tas.Connect(config.ServerHost, config.ServerPort);
            } catch {
                recon.Start();
            }
            return(true);
        }
Esempio n. 18
0
        public int FilterPlanets(string[] words, out string[] vals, out int[] indexes)
        {
            var options = server.GetAttackOptions(account);

            if (options != null)
            {
                var temp = new string[options.Count];
                int cnt  = 0;

                foreach (var planet in options)
                {
                    temp[cnt++] = string.Format("{0}|  {1}", planet.Name, Path.GetFileNameWithoutExtension(planet.MapName));
                }
                return(AutoHost.Filter(temp, words, out vals, out indexes));
            }
            else
            {
                vals    = null;
                indexes = null;
                return(0);
            }
        }
Esempio n. 19
0
        protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
        {
            question = null;
            winCount = 0;
            if (words.Length == 0)
            {
                ah.Respond(e, "You must specify player name");
                return(false);
            }

            string[] players;
            int[]    indexes;
            if (AutoHost.FilterUsers(new[] { words[0] }, tas, spring, out players, out indexes) > 0)
            {
                player = players[0];
                if (player == tas.UserName)
                {
                    ah.Respond(e, "won't kick myself, not in suicidal mood today");
                    return(false);
                }
                else
                {
                    string reason = (words.Length > 1 && words[1] != "for") ? " for" : "";
                    for (var i = 1; i < words.Length; i++)
                    {
                        reason += " " + words[i];
                    }
                    question = "Kick " + player + reason + "?";
                    return(true);
                }
            }
            else
            {
                AutoHost.Respond(tas, spring, e, "Cannot find such player");
                return(false);
            }
        }
 protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
 {
     winCount = 0;
     question = null;
     if (spring.IsRunning)
     {
         AutoHost.Respond(tas, spring, e, "Cannot set options while the game is running");
         return(false);
     }
     else
     {
         var wordFormat = Utils.Glue(words);
         scriptTagsFormat = ah.GetOptionsString(e, words);
         if (scriptTagsFormat == "")
         {
             return(false);
         }
         else
         {
             question = "Set option " + wordFormat + "?";
             return(true);
         }
     }
 }
Esempio n. 21
0
        protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
        {
            winCount = 0;
            question = null;
            if (words.Length == 0)
            {
                AutoHost.Respond(tas, spring, e, "You must specify player name");
                return(false);
            }

            string[] players;
            int[]    indexes;
            if (AutoHost.FilterUsers(words, tas, spring, out players, out indexes) > 0)
            {
                player   = players[0];
                question = "Spectate " + player + "?";
                return(true);
            }
            else
            {
                AutoHost.Respond(tas, spring, e, "Cannot find such player");
                return(false);
            }
        }
Esempio n. 22
0
 public VoteMove(TasClient tas, Spring spring, AutoHost ah): base(tas, spring, ah) {}
Esempio n. 23
0
 public VoteResetOptions(TasClient tas, Spring spring, AutoHost ah) : base(tas, spring, ah)
 {
 }
 public VoteSetOptions(TasClient tas, Spring spring, AutoHost ah): base(tas, spring, ah) {}
Esempio n. 25
0
 public VoteForceStart(TasClient tas, Spring spring, AutoHost ah) : base(tas, spring, ah)
 {
 }
Esempio n. 26
0
 public VotePlanet(TasClient tas, Spring spring, AutoHost ah): base(tas, spring, ah) {}
Esempio n. 27
0
        protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
        {
            winCount = 0;
            question = null;
            if (spring.IsRunning)
            {
                AutoHost.Respond(tas, spring, e, "Cannot change map while the game is running");
                return(false);
            }
            else
            {
                string[] vals;
                int[]    indexes;
                if (words.Length > 0)
                {
                    ah.FilterMaps(words, out vals, out indexes);
                    if (vals.Length > 0)
                    {
                        map = vals[0];
                        var resource = ah.cache.FindResourceData(new string[] { map }, ResourceType.Map);
                        question = string.Format("Change map to {0} {2}/Maps/Detail/{1} ?", map, resource[0].ResourceID, GlobalConst.BaseSiteUrl);
                        return(true);
                    }
                    else
                    {
                        AutoHost.Respond(tas, spring, e, "Cannot find such map");
                        return(false);
                    }
                }
                else
                {
                    try
                    {
                        if (tas.MyBattle != null && !spring.IsRunning)
                        {
                            var serv = GlobalConst.GetSpringieService();
                            Task.Factory.StartNew(() => {
                                RecommendedMapResult foundMap;
                                try {
                                    foundMap = serv.GetRecommendedMap(tas.MyBattle.GetContext(), true);
                                } catch (Exception ex) {
                                    Trace.TraceError(ex.ToString());
                                    return;
                                }
                                if (foundMap != null && foundMap.MapName != null && tas.MyBattle != null)
                                {
                                    if (tas.MyBattle.MapName != foundMap.MapName)
                                    {
                                        map = foundMap.MapName;
                                    }
                                }
                            });


                            // I have no idea why it can't just work like the above way
                            var resourceList = ah.cache.FindResourceData(new string[] { map }, ResourceType.Map);
                            var resource     = resourceList.Find(x => x.InternalName == map);
                            question = string.Format("Change map to {0} {2}/Maps/Detail/{1} ?", map, resource.ResourceID, GlobalConst.BaseSiteUrl);
                            return(true);
                        }
                    }
                    catch (System.Exception ex)
                    {
                        AutoHost.Respond(tas, spring, e, ex.ToString());
                        //System.Diagnostics.Trace.TraceError(ex.ToString());
                    }
                    return(false);
                }
            }
        }
Esempio n. 28
0
 public AbstractPoll(TasClient tas, Spring spring, AutoHost ah)
 {
     this.tas    = tas;
     this.spring = spring;
     this.ah     = ah;
 }
Esempio n. 29
0
 protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
 {
     winCount = 0;
     question = null;
     if (spring.IsRunning)
     {
         AutoHost.Respond(tas, spring, e, "Cannot change map while the game is running");
         return(false);
     }
     else
     {
         string[] vals;
         int[]    indexes;
         if (words.Length > 0)
         {
             ah.FilterMaps(words, out vals, out indexes);
             if (vals.Length > 0)
             {
                 map = vals[0];
                 var resource = ah.cache.FindResourceData(new string[] { map }, ResourceType.Map);
                 question = string.Format("Change map to {0} http://zero-k.info/Maps/Detail/{1} ?", map, resource[0].ResourceID);
                 return(true);
             }
             else
             {
                 AutoHost.Respond(tas, spring, e, "Cannot find such map");
                 return(false);
             }
         }
         else
         {
             try
             {
                 if (tas.MyBattle != null && !spring.IsRunning)
                 {
                     var serv = new PlasmaShared.SpringieInterfaceReference.SpringieService();
                     serv.Timeout = 15000;
                     serv.GetRecommendedMapCompleted += (sender, args) =>
                     {
                         if (!args.Cancelled && args.Error == null)
                         {
                             var foundMap = args.Result;
                             if (foundMap != null && foundMap.MapName != null && tas.MyBattle != null)
                             {
                                 if (tas.MyBattle.MapName != foundMap.MapName)
                                 {
                                     map = foundMap.MapName;
                                 }
                             }
                         }
                     };
                     serv.GetRecommendedMapAsync(tas.MyBattle.GetContext(), true);
                     // I have no idea why it can't just work like the above way
                     ResourceData[] resourceArray = ah.cache.FindResourceData(new string[] { map }, ResourceType.Map);
                     System.Collections.Generic.List <ResourceData> resourceList = new System.Collections.Generic.List <ResourceData>(resourceArray);
                     var resource = resourceList.Find(x => x.InternalName == map);
                     question = string.Format("Change map to {0} http://zero-k.info/Maps/Detail/{1} ?", map, resource.ResourceID);
                     return(true);
                 }
             }
             catch (System.Exception ex)
             {
                 AutoHost.Respond(tas, spring, e, ex.ToString());
                 //System.Diagnostics.Trace.TraceError(ex.ToString());
             }
             return(false);
         }
     }
 }
Esempio n. 30
0
 public VoteResign(TasClient tas, Spring spring, AutoHost ah) : base(tas, spring, ah)
 {
 }
 public AbstractPoll(TasClient tas, Spring spring, AutoHost ah) {
     this.tas = tas;
     this.spring = spring;
     this.ah = ah;
 }
 public VoteSplitPlayers(TasClient tas, Spring spring, AutoHost ah) : base(tas, spring, ah)
 {
 }
 public ResourceLinkProvider(AutoHost ah)
 {
     this.ah       = ah;
     plasmaService = new ContentService();
     plasmaService.DownloadFileCompleted += ps_DownloadFileCompleted;
 }
Esempio n. 34
0
 public VoteResign(TasClient tas, Spring spring, AutoHost ah): base(tas, spring, ah) {}
 public VoteForceStart(TasClient tas, Spring spring, AutoHost ah): base(tas, spring, ah) {}
Esempio n. 36
0
 public VotePlanet(TasClient tas, Spring spring, AutoHost ah) : base(tas, spring, ah)
 {
 }
 public VoteSplitPlayers(TasClient tas, Spring spring, AutoHost ah): base(tas, spring, ah) {}
Esempio n. 38
0
 public VoteMove(TasClient tas, Spring spring, AutoHost ah) : base(tas, spring, ah)
 {
 }