public void RunNub(int num) { var tas = new TasClient("Nubotron"); var name = "TestNub" + num; var ord = num / 16; var batname = "Test " + ord; //tas.Input += (sender, args) => { Console.WriteLine(" < {0}", args); }; //tas.Output += (sender, args) => { Console.WriteLine(" > {0}", args); }; tas.Connected += (sender, args) => { tas.Login(name, "dummy"); }; tas.ConnectionLost += (sender, args) => { tas.Connect(GlobalConst.LobbyServerHost, GlobalConst.LobbyServerPort); Console.WriteLine("disconnected"); }; tas.LoginAccepted += (sender, args) => { Console.WriteLine(name + " accepted"); }; tas.LoginDenied += (sender, args) => { tas.Register(name, "dummy"); }; tas.RegistrationAccepted += (sender, args) => { tas.Login(name, "dummy"); }; tas.RegistrationDenied += (sender, response) => { Console.WriteLine(name + "registration denied"); }; tas.UserAdded += (sender, args) => { if (args.Name == name) { tas.JoinChannel("bots"); if (num%16 == 0) tas.OpenBattle(new BattleHeader() { Title = batname, MaxPlayers = 16, }); else { var bat = tas.ExistingBattles.Values.FirstOrDefault(x => x.Title == batname); if (bat != null) tas.JoinBattle(bat.BattleID); } } }; tas.BattleFound += (sender, args) => { if (args.Title == batname) { //await Task.Delay(200); tas.JoinBattle(args.BattleID); } }; tas.Connect(GlobalConst.LobbyServerHost, GlobalConst.LobbyServerPort); /*Task.Factory.StartNew(async () => { while (true) { await Task.Delay(rand.Next(400000)); tas.Say(SayPlace.Channel, "zk", sent.GetNext(), false); } }, TaskCreationOptions.LongRunning);*/ }
public bool Start() { tas.Connected += tas_Connected; tas.LoginDenied += tas_LoginDenied; tas.LoginAccepted += tas_LoginAccepted; using (var db = new ZkDataContext()) { var acc = db.Accounts.FirstOrDefault(x => x.Name == GlobalConst.NightwatchName); if (acc != null) { acc.SetPasswordPlain(config.AccountPassword); acc.IsBot = true; acc.IsZeroKAdmin = true; db.SaveChanges(); } } Auth = new AuthService(tas); adminCommands = new AdminCommands(tas); offlineMessages = new OfflineMessages(tas); playerMover = new PlayerMover(tas); SteamHandler = new NwSteamHandler(tas, new Secrets().GetSteamWebApiKey()); chatRelay = new ChatRelay(tas, new Secrets().GetNightwatchPassword(), new List <string>() { "zkdev", "sy", "moddev" }); PayPalInterface = new PayPalInterface(); PayPalInterface.Error += (e) => { tas.Say(SayPlace.Channel, "zkdev", "PAYMENT ERROR: " + e.ToString(), true); }; PayPalInterface.NewContribution += (c) => { tas.Say(SayPlace.Channel, "zkdev", string.Format("WOOHOO! {0:d} New contribution of {1:F2}€ by {2} - for the jar {3}", c.Time, c.Euros, c.Name.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(), c.ContributionJar.Name), true); if (c.AccountByAccountID == null) { tas.Say(SayPlace.Channel, "zkdev", string.Format("Warning, user account unknown yet, payment remains unassigned. If you know user name, please assign it manually {0}/Contributions", GlobalConst.BaseSiteUrl), true); } else { tas.Say(SayPlace.Channel, "zkdev", string.Format("It is {0} {2}/Users/Detail/{1}", c.AccountByAccountID.Name, c.AccountID, GlobalConst.BaseSiteUrl), true); } }; tas.Connect(config.ServerHost, config.ServerPort); return(true); }
private void recon_Elapsed(object sender, ElapsedEventArgs e) { recon.Stop(); try { tas.Connect(config.ServerHost, config.ServerPort); } catch { recon.Start(); } }
void SetupSpringTasConnection(string password) { springTas.LoginDenied += (sender, args) => Utils.StartAsync(() => { Thread.Sleep(5000); springTas.Login(GlobalConst.NightwatchName, password); }); springTas.Connect(GlobalConst.OldSpringLobbyHost, GlobalConst.OldSpringLobbyPort); springTas.Connected += (sender, args) => springTas.Login(GlobalConst.NightwatchName, password); }
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(); } }
public void TryToConnectTasClient() { lock (tryConnectLocker) { if (!tasClientConnectCalled && !client.IsConnected && !client.IsLoggedIn) { Program.NotifySection.AddBar(this); tasClientConnectCalled = true; lbState.Text = "Trying to connect ..."; client.Connect(Program.Conf.SpringServerHost, Program.Conf.SpringServerPort); } } }
public void RunNub(int num) { var tas = new TasClient("Nubotron"); var name = "TestNub" + num; var ord = num / 16; var batname = "Test " + ord; //tas.Input += (sender, args) => { Console.WriteLine(" < {0}", args); }; //tas.Output += (sender, args) => { Console.WriteLine(" > {0}", args); }; tas.Connected += (sender, args) => { tas.Login(name, "dummy"); }; tas.ConnectionLost += (sender, args) => { Console.WriteLine("disconnected"); }; tas.LoginAccepted += (sender, args) => { Console.WriteLine(name + " accepted"); }; tas.LoginDenied += (sender, args) => { tas.Register(name, "dummy"); }; tas.UserAdded += (sender, args) => { if (args.Name == name) { tas.JoinChannel("bots"); if (num % 16 == 0) { tas.OpenBattle(new Battle("91.0", null, 4955, 16, "SmallDivide", "Test " + ord, "Zero-K v1.3.1.15")); } else { var bat = tas.ExistingBattles.Values.FirstOrDefault(x => x.Title == batname); if (bat != null) { tas.JoinBattle(bat.BattleID); } } } }; tas.BattleFound += (sender, args) => { if (args.Title == batname) { //await Task.Delay(200); tas.JoinBattle(args.BattleID); } }; tas.Connect(GlobalConst.LobbyServerHost, GlobalConst.LobbyServerPort); }
public void RunNub(int num) { var tas = new TasClient("Nubotron"); var name = "TestNub" + num; var ord = num / 16; var batname = "Test " + ord; //tas.Input += (sender, args) => { Console.WriteLine(" < {0}", args); }; //tas.Output += (sender, args) => { Console.WriteLine(" > {0}", args); }; tas.Connected += (sender, args) => { tas.Login(name, "dummy"); }; tas.ConnectionLost += (sender, args) => { Console.WriteLine("disconnected"); }; tas.LoginAccepted += (sender, args) => { Console.WriteLine(name + " accepted"); }; tas.LoginDenied += (sender, args) => { tas.Register(name, "dummy"); }; tas.UserAdded += (sender, args) => { if (args.Name == name) { tas.JoinChannel("bots"); if (num%16 == 0) tas.OpenBattle(new BattleHeader() { Engine = "91.0", Game = "Zero-K v1.3.1.15", Title = "test" + ord, Map = "SmallDivide", MaxPlayers = 16, }); else { var bat = tas.ExistingBattles.Values.FirstOrDefault(x => x.Title == batname); if (bat != null) tas.JoinBattle(bat.BattleID); } } }; tas.BattleFound += (sender, args) => { if (args.Title == batname) { //await Task.Delay(200); tas.JoinBattle(args.BattleID); } }; tas.Connect(GlobalConst.LobbyServerHost, GlobalConst.LobbyServerPort); }
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 Start() { tas.Connect(Program.main.Config.ServerHost, Program.main.Config.ServerPort); }
public void RunNub(int num) { var tas = new TasClient("Nubotron"); var maps = AutoRegistrator.RegistratorRes.campaignMaps.Split('\n'); var name = "TestNub" + num; var ord = num / 16; //tas.Input += (sender, args) => { Console.WriteLine(" < {0}", args); }; //tas.Output += (sender, args) => { Console.WriteLine(" > {0}", args); }; tas.Connected += (sender, args) => { tas.Login(name, "dummy"); }; tas.ConnectionLost += (sender, args) => { tas.Connect(GlobalConst.LobbyServerHost, GlobalConst.LobbyServerPort); Console.WriteLine("disconnected"); }; tas.LoginAccepted += (sender, args) => { Console.WriteLine(name + " accepted"); }; tas.LoginDenied += (sender, args) => { tas.Register(name, "dummy"); }; tas.RegistrationAccepted += (sender, args) => { tas.Login(name, "dummy"); }; tas.RegistrationDenied += (sender, response) => { Console.WriteLine(name + "registration denied"); }; tas.Connect(GlobalConst.LobbyServerHost, GlobalConst.LobbyServerPort); Task.Factory.StartNew(async() => { while (true) { await Task.Delay(rand.Next(10000)); if (tas.IsLoggedIn) { await tas.LeaveBattle(); if (tas.ExistingBattles.Count < 20) { await tas.OpenBattle(new BattleHeader() { Title = "" + name, MaxPlayers = 16, Mode = AutohostMode.None, Engine = tas.ServerWelcome.Engine, Game = tas.ServerWelcome.Game, Map = maps[rand.Next(maps.Length)], }); } else { var bats = tas.ExistingBattles.Values.ToList(); if (bats.Count > 0) { var bat = bats[rand.Next(bats.Count)]; if (bat != null) { tas.JoinBattle(bat.BattleID); } } } } } }, TaskCreationOptions.LongRunning); Task.Factory.StartNew(async() => { while (true) { await Task.Delay(rand.Next(50000)); if (tas.IsLoggedIn) { tas.Say(SayPlace.Channel, "zk", sent.GetNext(), false); } } }, TaskCreationOptions.LongRunning); Task.Factory.StartNew(async() => { bool cycler = false; while (true) { await Task.Delay(rand.Next(5000)); if (tas.IsLoggedIn) { await tas.ChangeMyUserStatus(cycler, cycler); //await tas.ChangeMyBattleStatus(cycler, SyncStatuses.Synced, 1); cycler = !cycler; } } }, TaskCreationOptions.LongRunning); }
public bool Start() { if (config.AttemptToRecconnect) { recon = new Timer(config.AttemptReconnectInterval * 1000); recon.AutoReset = true; recon.Elapsed += recon_Elapsed; } recon.Enabled = false; tas.ConnectionLost += tas_ConnectionLost; tas.Connected += tas_Connected; tas.LoginDenied += tas_LoginDenied; tas.LoginAccepted += tas_LoginAccepted; Auth = new AuthService(tas); adminCommands = new AdminCommands(tas); offlineMessages = new OfflineMessages(tas); playerMover = new PlayerMover(tas); MumbleMover = new MumbleMover(tas); PayPalInterface = new PayPalInterface(); PayPalInterface.Error += (e) => { tas.Say(TasClient.SayPlace.Channel, "zkdev", "PAYMENT ERROR: " + e.ToString(), true); }; PayPalInterface.NewContribution += (c) => { tas.Say(TasClient.SayPlace.Channel, "zkdev", string.Format("WOOHOO! {0:d} New contribution of {1:F2}€ by {2} - for the jar {3}", c.Time, c.Euros, c.Name.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(), c.ContributionJar.Name), true); if (c.AccountByAccountID == null) { tas.Say(TasClient.SayPlace.Channel, "zkdev", "Warning, user account unknown yet, payment remains unassigned. If you know user name, please assign it manually http://zero-k.info/Contributions", true); } else { tas.Say(TasClient.SayPlace.Channel, "zkdev", string.Format("It is {0} http://zero-k.info/Users/Detail/{1}", c.AccountByAccountID.Name, c.AccountID), true); } }; try { tas.Connect(config.ServerHost, config.ServerPort); } catch { recon.Start(); } return(true); }
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); } } if (config.PlanetWarsEnabled) { InitializePlanetWarsServer(); } 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.StatsEnabledReal) { stats = new Stats(tas, spring); } try { tas.Connect(config.ServerHost, config.ServerPort); } catch { recon.Start(); } return(true); }
public AutoHost(MetaDataCache cache, AhConfig config, int hostingPort, SpawnConfig spawn) { this.config = config; Commands = new CommandList(config); this.cache = cache; SpawnConfig = spawn; this.hostingPort = hostingPort; string version = config.SpringVersion ?? Program.main.Config.SpringVersion ?? tas.ServerSpringVersion; // tas empty at this point! Possible null exception springPaths = new SpringPaths(Program.main.paths.GetEngineFolderByVersion(version), writableFolderOverride: Program.main.Config.DataDir); Program.main.paths.SpringVersionChanged += (s, e) => { if (!String.IsNullOrEmpty(requestedEngineChange) && requestedEngineChange == Program.main.paths.SpringVersion) { config.SpringVersion = requestedEngineChange; springPaths.SetEnginePath(Program.main.paths.GetEngineFolderByVersion(requestedEngineChange)); requestedEngineChange = null; tas.Say(TasClient.SayPlace.Battle, "", "rehosting to engine version " + springPaths.SpringVersion, true); ComRehost(TasSayEventArgs.Default, new string[] { }); } }; spring = new Spring(springPaths) { UseDedicatedServer = true }; bool isManaged = SpawnConfig == null && config.Mode != AutohostMode.None; tas = new TasClient(null, MainConfig.SpringieVersion, isManaged ? GlobalConst.ZkSpringieManagedCpu : GlobalConst.ZkLobbyUserCpu, false, Program.main.Config.IpOverride); pollTimer = new Timer(PollTimeout * 1000); pollTimer.Enabled = false; pollTimer.AutoReset = false; pollTimer.Elapsed += pollTimer_Elapsed; spring.SpringExited += spring_SpringExited; spring.GameOver += spring_GameOver; spring.SpringExited += spring_SpringExited; spring.SpringStarted += spring_SpringStarted; spring.PlayerSaid += spring_PlayerSaid; spring.BattleStarted += spring_BattleStarted; tas.BattleUserLeft += tas_BattleUserLeft; tas.UserStatusChanged += tas_UserStatusChanged; tas.BattleUserStatusChanged += TasOnBattleUserStatusChanged; tas.BattleUserJoined += tas_BattleUserJoined; tas.MyBattleMapChanged += tas_MyBattleMapChanged; tas.BattleLockChanged += tas_BattleLockChanged; tas.BattleOpened += tas_BattleOpened; tas.UserAdded += (o, u) => { if (u.Data.Name == GetAccountName()) { Start(null, null); } }; tas.RegistrationDenied += (s, e) => { ErrorHandling.HandleException(null, "Registration denied: " + e.ServerParams[0]); CloneNumber++; tas.Login(GetAccountName(), config.Password); }; tas.RegistrationAccepted += (s, e) => tas.Login(GetAccountName(), config.Password); tas.AgreementRecieved += (s, e) => { tas.AcceptAgreement(); PlasmaShared.Utils.SafeThread(() => { Thread.Sleep(7000); tas.Login(GetAccountName(), config.Password); }).Start(); }; tas.ConnectionLost += tas_ConnectionLost; tas.Connected += tas_Connected; tas.LoginDenied += tas_LoginDenied; tas.LoginAccepted += tas_LoginAccepted; tas.Said += tas_Said; tas.MyBattleStarted += tas_MyStatusChangedToInGame; linkProvider = new ResourceLinkProvider(this); tas.Connect(Program.main.Config.ServerHost, Program.main.Config.ServerPort); Program.main.Downloader.PackagesChanged += Downloader_PackagesChanged; timer = new Timer(15000); timer.Elapsed += (s, e) => { try { timer.Stop(); timerTick++; // auto update engine branch if (!String.IsNullOrEmpty(config.AutoUpdateSpringBranch) && timerTick % 4 == 0) { CheckEngineBranch(); } // auto verify pw map if (!spring.IsRunning && config.Mode != AutohostMode.None) { if (SpawnConfig == null && config.Mode == AutohostMode.Planetwars) { ServerVerifyMap(false); } } // auto start split vote if (!spring.IsRunning && config.SplitBiggerThan != null && tas.MyBattle != null && config.SplitBiggerThan < tas.MyBattle.NonSpectatorCount) { if (DateTime.Now.Subtract(spring.GameExited).TotalSeconds >= GameExitSplitDelay) { ComSplitPlayers(TasSayEventArgs.Default, new string[] {}); } /* * int cnt = tas.MyBattle.NonSpectatorCount; * if (cnt > lastSplitPlayersCountCalled && cnt%2 == 0) { * StartVote(new VoteSplitPlayers(tas, spring, this), TasSayEventArgs.Default, new string[] { }); * lastSplitPlayersCountCalled = cnt; * }*/ } // auto rehost to latest mod version if (!string.IsNullOrEmpty(config.AutoUpdateRapidTag) && SpawnConfig == null) { UpdateRapidMod(config.AutoUpdateRapidTag); } if (lockedUntil != DateTime.MinValue && lockedUntil < DateTime.Now) { ComUnlock(TasSayEventArgs.Default, new string[] {}); } } catch (Exception ex) { Trace.TraceError(ex.ToString()); } finally { timer.Start(); } }; timer.Start(); }
public void RunNub(int num) { var tas = new TasClient("Nubotron"); var name = "TestNub" + num; var ord = num / 16; var batname = "Test " + ord; //tas.Input += (sender, args) => { Console.WriteLine(" < {0}", args); }; //tas.Output += (sender, args) => { Console.WriteLine(" > {0}", args); }; tas.Connected += (sender, args) => { tas.Login(name, "dummy"); }; tas.ConnectionLost += (sender, args) => { tas.Connect(GlobalConst.LobbyServerHost, GlobalConst.LobbyServerPort); Console.WriteLine("disconnected"); }; tas.LoginAccepted += (sender, args) => { Console.WriteLine(name + " accepted"); }; tas.LoginDenied += (sender, args) => { tas.Register(name, "dummy"); }; tas.RegistrationAccepted += (sender, args) => { tas.Login(name, "dummy"); }; tas.RegistrationDenied += (sender, response) => { Console.WriteLine(name + "registration denied"); }; tas.UserAdded += (sender, args) => { if (args.Name == name) { tas.JoinChannel("bots"); if (num % 16 == 0) { tas.OpenBattle(new BattleHeader() { Title = batname, MaxPlayers = 16, }); } else { var bat = tas.ExistingBattles.Values.FirstOrDefault(x => x.Title == batname); if (bat != null) { tas.JoinBattle(bat.BattleID); } } } }; tas.BattleFound += (sender, args) => { if (args.Title == batname) { //await Task.Delay(200); tas.JoinBattle(args.BattleID); } }; tas.Connect(GlobalConst.LobbyServerHost, GlobalConst.LobbyServerPort); /*Task.Factory.StartNew(async () => * { * while (true) * { * await Task.Delay(rand.Next(400000)); * tas.Say(SayPlace.Channel, "zk", sent.GetNext(), false); * } * }, TaskCreationOptions.LongRunning);*/ }