public AutoHost(TasClient tas, Spring spring, AutoHostConfig conf)
    {
      if (conf == null) LoadConfig(); else config = conf;
      SaveConfig();

      this.tas = tas;
      this.spring = spring;

      tas.Said += new EventHandler<TasSayEventArgs>(tas_Said);

      pollTimer = new Timer(PollTimeout * 1000);
      pollTimer.Enabled = false;
      pollTimer.AutoReset = false;
      pollTimer.Elapsed += new ElapsedEventHandler(pollTimer_Elapsed);

      spring.SpringExited += new EventHandler(spring_SpringExited);
      spring.GameOver += new EventHandler<SpringLogEventArgs>(spring_GameOver);

      tas.BattleUserLeft += new EventHandler<TasEventArgs>(tas_BattleUserLeft);
      tas.UserRemoved += new EventHandler<TasEventArgs>(tas_UserRemoved);
      tas.UserStatusChanged += new EventHandler<TasEventArgs>(tas_UserStatusChanged);
      tas.BattleUserJoined += new EventHandler<TasEventArgs>(tas_BattleUserJoined);
      tas.BattleMapChanged += new EventHandler<TasEventArgs>(tas_BattleMapChanged);
      tas.BattleUserStatusChanged += new EventHandler<TasEventArgs>(tas_BattleUserStatusChanged);
      tas.BattleLockChanged += new EventHandler<TasEventArgs>(tas_BattleLockChanged);

      mapLinker = new MapLinker(spring);
      mapDownloader = new MapDownloader(spring);
      mapDownloader.DownloadCompleted += new EventHandler<TasEventArgs>(mapDownloader_DownloadCompleted);
      mapDownloader.DownloadProgressChanged += new EventHandler<TasEventArgs>(mapDownloader_DownloadProgressChanged);

      tas.BattleFound += new EventHandler<TasEventArgs>(tas_BattleFound);
    }
 public UnSyncKicker(TasClient tas) {
   this.tas = tas;
   checkTimer.Elapsed += new ElapsedEventHandler(checkTimer_Elapsed);
   checkTimer.Enabled = true;
   tas.BattleUserJoined += new EventHandler<TasEventArgs>(tas_BattleUserJoined);
   tas.BattleUserLeft += new EventHandler<TasEventArgs>(tas_BattleUserLeft);
 }
        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 AutoManager(AutoHost ah, TasClient tas, Spring spring)
 {
   this.ah = ah;
   this.tas = tas;
   this.spring = spring;
   timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
   timer.Start();
 }
    internal static int FilterMaps(string[] words, TasClient tas, Spring spring, out string[] vals, out int[] indexes)
    {
      string[] temp = new string[spring.UnitSync.MapList.Keys.Count];
      int cnt = 0;
      foreach (string s in spring.UnitSync.MapList.Keys) { temp[cnt++] = s; }
      return Filter(temp, words, out vals, out indexes);

    }
    public BanList(AutoHost ah, TasClient tas)
    {
      this.tas = tas;
      this.ah = ah;

      tas.BattleUserIpRecieved += tas_BattleUserIpRecieved;
      tas.BattleUserJoined += tas_BattleUserJoined;
    }
    public BanList(AutoHost ah, TasClient tas)
    {
      this.tas = tas;
      this.ah = ah;

      tas.BattleUserIpRecieved += new EventHandler<TasEventArgs>(tas_BattleUserIpRecieved);
      tas.BattleUserJoined += new EventHandler<TasEventArgs>(tas_BattleUserJoined);
    }
 internal static int FilterUsers(string[] words, TasClient tas, Spring spring, out string[] vals, out int[] indexes)
 {
   TasClient.Battle b = tas.GetBattle();
   string[] temp = new string[b.Users.Count];
   int i = 0;
   foreach (TasClient.UserBattleStatus u in b.Users) {
     temp[i++] = u.name;
   }
   return Filter(temp, words, out vals, out indexes);
 }
 protected void KickUnsynced(TasClient tas) {
   for (int i = 0; i < users.Count; ++i) {
     TasClient.UserBattleStatus u;
     if (tas.IsConnected && tas.GetBattle().ContainsUser(users[i], out u)) {
       if (u.SyncStatus == TasClient.SyncStatuses.Unknown && (DateTime.Now - times[i]) > TimeSpan.FromSeconds(timeout)) {
         tas.Kick(users[i]);
       }
     }
   }
 }
    /************************************************************************/
    /*    PUBLIC METHODS                                                    */
    /************************************************************************/

    /// <summary>
    /// Initializes auto downloader
    /// </summary>
    public AutoUpdater(Spring spring, TasClient tas)
    {
      this.spring = spring;
      this.tas = tas;

      timer = new Timer();
      timer.Interval = updateCheckInterval*1000*60;
      timer.AutoReset = true;
      timer.Elapsed += timer_Elapsed;
      timer.Start();
      spring.SpringExited += spring_SpringExited;
    }
    /************************************************************************/
    /*    PUBLIC METHODS                                                    */
    /************************************************************************/
    /// <summary>
    /// Initializes auto downloader
    /// </summary>
    public AutoUpdater(Spring spring, TasClient tas)
    {
      this.spring = spring;
      this.tas = tas;

      timer = new System.Timers.Timer();
      timer.Interval = updateCheckInterval * 1000 * 60;
      timer.AutoReset = true;
      timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
      timer.Start();

      spring.SpringExited += new EventHandler(spring_SpringExited);
    }
Exemple #12
0
 public AbstractPoll(TasClient tas, Spring spring, AutoHost ah)
 {
   this.tas = tas;
   this.spring = spring;
   this.ah = ah;
   string[] usrs;
   int[] indexes;
   AutoHost.FilterUsers(new string[0], tas, spring, out usrs, out indexes);
   foreach (string s in usrs) {
     if (s != tas.UserName) {
       users.Add(s);
       votes.Add(0);
     }
   }
   initialUserCount = users.Count;
 }
Exemple #13
0
		public AbstractPoll(TasClient tas, Spring spring, AutoHost ah)
		{
			this.tas = tas;
			this.spring = spring;
			this.ah = ah;

			initialUserCount = 0;
			var b = tas.GetBattle();
			if (b != null) {
				foreach (var us in b.Users) {
					if (us.name != tas.UserName) {
						users.Add(us.name);
						votes.Add(0);
						if (!us.IsSpectator) initialUserCount++;
					}
				}
			}
		}
Exemple #14
0
    public Stats(TasClient tas, Spring spring)
    {
      this.tas = tas;
      this.spring = spring;

      LoadAccounts();

      tas.LoginAccepted += new EventHandler<TasEventArgs>(tas_LoginAccepted);
      if (Program.main.config.GargamelMode) {
        tas.UserRemoved += new EventHandler<TasEventArgs>(tas_UserRemoved);
        tas.BattleUserIpRecieved += new EventHandler<TasEventArgs>(tas_BattleUserIpRecieved);
        tas.UserStatusChanged += new EventHandler<TasEventArgs>(tas_UserStatusChanged);
      }
      spring.SpringStarted += new EventHandler(spring_SpringStarted);
      spring.PlayerJoined += new EventHandler<SpringLogEventArgs>(spring_PlayerJoined);
      spring.PlayerLeft += new EventHandler<SpringLogEventArgs>(spring_PlayerLeft);
      spring.PlayerLost += new EventHandler<SpringLogEventArgs>(spring_PlayerLost);
      spring.PlayerDisconnected += new EventHandler<SpringLogEventArgs>(spring_PlayerDisconnected);
      spring.GameOver += new EventHandler<SpringLogEventArgs>(spring_GameOver);
    }
Exemple #15
0
		public Stats(TasClient tas, Spring spring)
		{
			this.tas = tas;
			this.spring = spring;

			LoadAccounts();

			tas.LoginAccepted += tas_LoginAccepted;
			if (Program.main.config.GargamelMode) {
				tas.UserRemoved += tas_UserRemoved;
				tas.BattleUserIpRecieved += tas_BattleUserIpRecieved;
				tas.UserStatusChanged += tas_UserStatusChanged;
			}
			spring.SpringStarted += spring_SpringStarted;
			spring.PlayerJoined += spring_PlayerJoined;
			spring.PlayerLeft += spring_PlayerLeft;
			spring.PlayerLost += spring_PlayerLost;
			spring.PlayerDisconnected += spring_PlayerDisconnected;
			spring.GameOver += spring_GameOver;
		}
 private static int FilterMaps(string[] words, TasClient tas, Spring spring, Ladder ladder, out string[] vals, out int[] indexes)
 {
   string[] temp = new string[spring.UnitSync.MapList.Keys.Count];
   int cnt = 0;
   foreach (string s in spring.UnitSync.MapList.Keys) {
     if (ladder != null) {
       if (ladder.Maps.Contains(s.ToLower())) temp[cnt++] = s;
     } else {
       string[] limit = Program.main.AutoHost.config.LimitMaps;
       if (limit != null && limit.Length > 0) {
         bool allowed = false;
         for (int i = 0; i < limit.Length; ++i) {
           if (s.ToLower().Contains(limit[i].ToLower())) {
             allowed = true;
             break;
           }
         }
         if (allowed) temp[cnt++] = s;
       } else temp[cnt++] = s;
     }
   }
   return Filter(temp, words, out vals, out indexes);
 }
		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));
			}
		}
    public AutoHost(TasClient tas, Spring spring, AutoHostConfig conf)
    {
      banList = new BanList(this, tas);

      if (conf == null) LoadConfig(); else config = conf;
      SaveConfig();

      this.tas = tas;
      this.spring = spring;

      tas.Said += new EventHandler<TasSayEventArgs>(tas_Said);

      pollTimer = new System.Timers.Timer(PollTimeout * 1000);
      pollTimer.Enabled = false;
      pollTimer.AutoReset = false;
      pollTimer.Elapsed += new ElapsedEventHandler(pollTimer_Elapsed);

      spring.SpringExited += new EventHandler(spring_SpringExited);
      spring.GameOver += new EventHandler<SpringLogEventArgs>(spring_GameOver);

      tas.BattleUserLeft += new EventHandler<TasEventArgs>(tas_BattleUserLeft);
      tas.UserStatusChanged += new EventHandler<TasEventArgs>(tas_UserStatusChanged);
      tas.BattleUserJoined += new EventHandler<TasEventArgs>(tas_BattleUserJoined);
      tas.BattleMapChanged += new EventHandler<TasEventArgs>(tas_BattleMapChanged);
      tas.BattleUserStatusChanged += new EventHandler<TasEventArgs>(tas_BattleUserStatusChanged);
      tas.BattleLockChanged += new EventHandler<TasEventArgs>(tas_BattleLockChanged);
      tas.BattleOpened += new EventHandler<TasEventArgs>(tas_BattleOpened);

      linker = new UnknownFilesLinker(spring);
      fileDownloader = new FileDownloader(spring);
      fileDownloader.DownloadCompleted += new EventHandler<FileDownloader.DownloadEventArgs>(fileDownloader_DownloadCompleted);
      //fileDownloader.DownloadProgressChanged += new EventHandler<TasEventArgs>(fileDownloader_DownloadProgressChanged);

      tas.BattleFound += new EventHandler<TasEventArgs>(tas_BattleFound);

    }
Exemple #19
0
 public VoteKickSpec(TasClient tas, Spring spring, AutoHost ah) : base(tas, spring, ah) { }
 /// <summary>
 /// Performs map search and says result
 /// </summary>
 /// <param name="name">map to search for</param>
 /// <param name="tas">tasclient to recieve response</param>
 /// <param name="e">say parameters (for forming response)</param>
 public void SayResults(string name, FileType type, TasClient tas, TasSayEventArgs e)
 {
   SayLines(GetResults(name, type), tas, e);
 }
    /************************************************************************/
    /*   PRIVATE METHODS                                                    */
    /************************************************************************/

    private void SayLines(string text, TasClient tas, TasSayEventArgs e)
    {
      string[] lines = text.Split(new char[] {'\n'}, StringSplitOptions.RemoveEmptyEntries);
      foreach (string l in lines) tas.Say(TasClient.SayPlace.User, e.UserName, l, false);
    }
Exemple #22
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;
        }
    public void Apply(TasClient tas, Ladder ladder)
    {
      Battle b = tas.GetBattle();
      if (b == null) return;
      BattleDetails d = b.Details;

      if (startingMetal.HasValue) d.StartingMetal = startingMetal.Value;
      if (startingEnergy.HasValue) d.StartingEnergy = startingEnergy.Value;
      if (maxUnits.HasValue) d.MaxUnits = maxUnits.Value;
      if (startPos.HasValue) d.StartPos = startPos.Value;
      if (endCondition.HasValue) d.EndCondition = endCondition.Value;
      if (limitDgun.HasValue) d.LimitDgun = limitDgun.Value;
      if (diminishingMM.HasValue) d.DiminishingMM = diminishingMM.Value;
      if (ghostedBuildings.HasValue) d.GhostedBuildings = ghostedBuildings.Value;

      d.Validate();
      int mint, maxt;
      if (ladder != null) d = ladder.CheckBattleDetails(d, out mint, out maxt);
      tas.UpdateBattleDetails(d);

      if (enableAllUnits) tas.EnableAllUnits();
      if (disabledUnits.Length > 0) tas.DisableUnits(UnitInfo.ToStringList(disabledUnits));

      foreach (string s in perform) tas.Say(TasClient.SayPlace.Battle, "", s, false);
    }
Exemple #24
0
    public bool Start()
    {
      if (config.AttemptToRecconnect) {
        recon = new 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();
          try {
            spring = new Spring(config.SpringPath);
          } catch (Exception e) {
            MessageBox.Show(e.ToString(), "Error while checking spring, exiting");
            Application.Exit();
            return false;
          }
        } else {
          MessageBox.Show("Spring not found, exiting");
          Application.Exit();
          return false;
        }
      }

      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);
      tas.MyStatusChangedToInGame += new EventHandler<TasEventArgs>(tas_MyStatusChangedToInGame);
      spring.SpringExited += new EventHandler(spring_SpringExited);
      spring.SpringStarted += new EventHandler(spring_SpringStarted);
      spring.PlayerSaid += new EventHandler<SpringLogEventArgs>(spring_PlayerSaid);
      autoHost = new AutoHost(tas, spring, null);
      autoUpdater = new AutoUpdater(spring, tas);

      if (config.StatsEnabled) stats = new Stats(tas, spring);
      try {
        tas.Connect(config.ServerHost, config.ServerPort);
      } catch {
        recon.Start();
      }
      return true;
    }
		internal static int FilterUsers(string[] words, TasClient tas, Spring spring, out string[] vals, out int[] indexes)
		{
			var b = tas.GetBattle();
			var temp = new string[b.Users.Count];
			int i = 0;
			foreach (var u in b.Users) temp[i++] = u.name;
			return Filter(temp, words, out vals, out indexes);
		}
 public static void Respond(TasClient tas, Spring spring, TasSayEventArgs e, string text)
 {
   TasClient.SayPlace p = TasClient.SayPlace.User;
   bool emote = false;
   if (e.Place == TasSayEventArgs.Places.Battle) {
     p = TasClient.SayPlace.Battle;
     emote = true;
   }
   if (e.Place == TasSayEventArgs.Places.Game && spring.IsRunning) spring.SayGame(text);
   else tas.Say(p, e.UserName, text, emote);
 }
Exemple #27
0
 public VoteMap(TasClient tas, Spring spring, AutoHost ah) : base(tas, spring, ah) { }
Exemple #28
0
 public VoteForceStart(TasClient tas, Spring spring, AutoHost ah) : base(tas, spring, ah) { }
 public static void SayBattle(TasClient tas, Spring spring, string text, bool ingame)
 {
   tas.Say(TasClient.SayPlace.Battle, "", text, true);
   if (spring.IsRunning && ingame) spring.SayGame(text);
 }
        public AutoHost(TasClient tas, Spring spring, AutoHostConfig conf)
        {
            banList = new BanList(this, tas);

            if (conf == null) LoadConfig();
            else config = conf;
            SaveConfig();

            this.tas = tas;
            this.spring = spring;

            tas.Said += tas_Said;

            pollTimer = new Timer(PollTimeout*1000);
            pollTimer.Enabled = false;
            pollTimer.AutoReset = false;
            pollTimer.Elapsed += pollTimer_Elapsed;

            spring.SpringExited += spring_SpringExited;
            spring.GameOver += spring_GameOver;
            spring.NotifyModsChanged += spring_NotifyModsChanged;

            tas.BattleUserLeft += tas_BattleUserLeft;
            tas.UserStatusChanged += tas_UserStatusChanged;
            tas.BattleUserJoined += tas_BattleUserJoined;
            tas.BattleMapChanged += tas_BattleMapChanged;
            tas.BattleUserStatusChanged += tas_BattleUserStatusChanged;
            tas.BattleLockChanged += tas_BattleLockChanged;
            tas.BattleOpened += tas_BattleOpened;

            linkProvider = new ResourceLinkProvider();
            spring.UnitSyncWrapper.Downloader.LinksRecieved += linkProvider.Downloader_LinksRecieved;
        }