예제 #1
0
 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 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);*/
        }
예제 #3
0
        public ConnectBar(TasClient tasClient) : this()
        {
            client = tasClient;


            client.ConnectionLost += (s, e) =>
            {
                canRegister = false;
                {
                    if (!client.WasDisconnectRequested)
                    {
                        lbState.Text = "disconnected due to network problem, autoreconnecting...";
                    }
                    else
                    {
                        lbState.Text           = "disconnected";
                        tasClientConnectCalled = false;
                    }
                    Program.NotifySection.AddBar(this);
                }
            };

            client.Connected += (s, e) =>
            {
                canRegister = false;
                Program.NotifySection.RemoveBar(this);
                lbState.Text = "Connected, logging in ...";
                if (string.IsNullOrEmpty(Program.Conf.LobbyPlayerName) || string.IsNullOrEmpty(Program.Conf.LobbyPlayerPassword))
                {
                    LoginWithDialog("Please enter your name and password", true);
                }
                else
                {
                    client.Login(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword);
                }
            };

            client.LoginAccepted += (s, e) => Program.NotifySection.RemoveBar(this);

            client.LoginDenied += (s, e) =>
            {
                if (e.Data.ResultCode == LoginResponse.Code.InvalidName && !string.IsNullOrEmpty(Program.Conf.LobbyPlayerPassword) && canRegister)
                {
                    lbState.Text = "Registering new account";
                    client.Register(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword);
                }
                else
                {
                    LoginWithDialog(string.Format("Login denied: {0} {1}", e.Data.ResultCode, e.Data.Reason), false);
                }
            };

            client.RegistrationDenied += (s, e) => LoginWithDialog(string.Format("Registration denied: {0} {1}", e.Data.ResultCode.Description(), e.Data.Reason), true);

            client.RegistrationAccepted += (s, e) => client.Login(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword);
        }
예제 #4
0
        public ConnectBar(TasClient tasClient): this() {
            client = tasClient;

            client.ConnectionLost += (s, e) =>
            {
                {
                    if (!client.WasDisconnectRequested) lbState.Text = "disconnected, reconnecting...";
                    else
                    {
                        lbState.Text = "disconnected";
                        tasClientConnectCalled = false;
                    }
                    Program.NotifySection.AddBar(this);
                }
            };

            client.Connected += (s, e) =>
            {
                lbState.Text = "Connected, logging in ...";
                if (string.IsNullOrEmpty(Program.Conf.LobbyPlayerName) || string.IsNullOrEmpty(Program.Conf.LobbyPlayerPassword)) LoginWithDialog("Please choose your name and password.\nThis will create a new account if it does not exist.");
                else client.Login(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword);
            };

            client.LoginAccepted += (s, e) =>
            {
                Program.NotifySection.RemoveBar(this);
                //Program.MainWindow.navigationControl.Path = "battles";
            };

            client.LoginDenied += (s, e) =>
            {
                if (e.ResultCode == LoginResponse.Code.InvalidName && !string.IsNullOrEmpty(Program.Conf.LobbyPlayerPassword))
                {
                    if (
                        MessageBox.Show(
                            string.Format("Account '{0}' does not exist yet, do you want to create it?", Program.Conf.LobbyPlayerName),
                            "Confirm account registration",
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        lbState.Text = "Registering a new account";
                        client.Register(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword);
                    } else LoginWithDialog(string.Format("Login denied: {0} {1}", e.ResultCode.Description(), e.Reason));
                } else
                {
                    LoginWithDialog(
                        string.Format("Login denied: {0} {1}\nChoose a different name to create new account.", e.ResultCode.Description(), e.Reason));
                }
            };

            client.RegistrationDenied +=
                (s, e) => LoginWithDialog(string.Format("Registration denied: {0} {1}", e.ResultCode.Description(), e.Reason));

            client.RegistrationAccepted += (s, e) => client.Login(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword);
        }
예제 #5
0
 void LoginWithDialog(string text, bool register = false)
 {
     do
     {
         var loginForm = new LoginForm(register);
         loginForm.InfoText = text;
         if (loginForm.ShowDialog() == DialogResult.Cancel)
         {
             tasClientConnectCalled = false;
             client.RequestDisconnect();
             lbState.Text = "Login cancelled, press button on left to login again";
             return;
         }
         canRegister = loginForm.CanRegister;
         Program.Conf.LobbyPlayerName     = loginForm.LoginValue;
         Program.Conf.LobbyPlayerPassword = loginForm.PasswordValue;
         if (string.IsNullOrEmpty(Program.Conf.LobbyPlayerName) || string.IsNullOrEmpty(Program.Conf.LobbyPlayerPassword))
         {
             MessageBox.Show("Please fill player name and password", "Missing information", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     } while (string.IsNullOrEmpty(Program.Conf.LobbyPlayerName) || string.IsNullOrEmpty(Program.Conf.LobbyPlayerPassword));
     Program.SaveConfig();
     if (canRegister)
     {
         client.Register(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword);
     }
     else
     {
         client.Login(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword);
     }
 }
예제 #6
0
	    public void Init(TasClient tasClient)
	    {
	        client = tasClient;

	        client.ConnectionLost += (s, e) => {
	            {
	                if (!client.WasDisconnectRequested) lbState.Text = "disconnected, reconnecting...";
	                else {
	                    lbState.Text = "disconnected";
	                    tasClientConnectCalled = false;
	                }
	            }
	        };

	        client.Connected += (s, e) => {
                btnLogout.Text = "Logout";
	            lbState.Text = "Connected, logging in ...";
	            if (string.IsNullOrEmpty(Program.Conf.LobbyPlayerName) || string.IsNullOrEmpty(Program.Conf.LobbyPlayerPassword)) LoginWithDialog("Please choose your name and password.\nThis will create a new account if it does not exist.");
	            else client.Login(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword);
	        };

	        client.LoginAccepted += (s, e) => {
	            lbState.Text = client.UserName;
	            pictureBox1.Image = Program.ServerImages.GetAvatarImage(client.MyUser);
	            playerItem = new PlayerListItem() { UserName = client.UserName };
	        };

	        client.LoginDenied += (s, e) => {
	            if (e.ResultCode == LoginResponse.Code.InvalidName && !string.IsNullOrEmpty(Program.Conf.LobbyPlayerPassword)) {
	                if (
	                    MessageBox.Show(string.Format("Account '{0}' does not exist yet, do you want to create it?", Program.Conf.LobbyPlayerName), "Confirm account registration",
	                        MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) {
	                    lbState.Text = "Registering a new account";
	                    client.Register(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword);
	                } else {
                        LoginWithDialog(string.Format("Login denied: {0} {1}", e.ResultCode.Description(), e.Reason));
	                }
	            } else {
	                LoginWithDialog(string.Format("Login denied: {0} {1}\nChoose a different name to create new account.", e.ResultCode.Description(), e.Reason));
	            }
	        };

	        client.RegistrationDenied += (s, e) => LoginWithDialog(string.Format("Registration denied: {0} {1}", e.ResultCode.Description(), e.Reason));

	        client.RegistrationAccepted += (s, e) => client.Login(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword);
	    }
예제 #7
0
		public ConnectBar(TasClient tasClient): this()
		{
			client = tasClient;

			
			client.ConnectionLost += (s, e) =>
				{
					canRegister = false;
					{
						if (!client.WasDisconnectRequested) lbState.Text = "disconnected due to network problem, autoreconnecting...";
						else
						{
							lbState.Text = "disconnected";
							tasClientConnectCalled = false;
						}
						Program.NotifySection.AddBar(this);
					}
				};

			client.Connected += (s, e) =>
				{
					canRegister = false;
					Program.NotifySection.RemoveBar(this);
					lbState.Text = "Connected, logging in ...";
                    if (string.IsNullOrEmpty(Program.Conf.LobbyPlayerName) || string.IsNullOrEmpty(Program.Conf.LobbyPlayerPassword)) LoginWithDialog("Please enter your name and password", true);
					else client.Login(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword);
				};

			client.LoginAccepted += (s, e) => Program.NotifySection.RemoveBar(this);

			client.LoginDenied += (s, e) =>
				{
                    if (e.Data.ResultCode == LoginResponse.Code.InvalidName && !string.IsNullOrEmpty(Program.Conf.LobbyPlayerPassword) && canRegister)
					{
						lbState.Text = "Registering new account";
						client.Register(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword);
					}
					else LoginWithDialog(string.Format("Login denied: {0} {1}",e.Data.ResultCode, e.Data.Reason), false);
				};

			client.RegistrationDenied += (s, e) => LoginWithDialog(string.Format("Registration denied: {0} {1}", e.Data.ResultCode.Description(), e.Data.Reason), true);

            client.RegistrationAccepted += (s, e) => client.Login(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword);

		}
예제 #8
0
        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);
        }
예제 #10
0
        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);*/
        }
예제 #11
0
 void tas_Connected(object sender, Welcome welcome)
 {
     tas.Login(config.AccountName, config.AccountPassword);
 }
예제 #12
0
 // im connected, let's login
 private void tas_Connected(object sender, TasEventArgs e)
 {
     tas.Login(config.AccountName, config.AccountPassword, MainConfig.SpringieVersion);
 }
예제 #13
0
        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();
        }
예제 #14
0
 void tas_Connected(object sender, TasEventArgs e)
 {
     tas.Login(config.AccountName, config.AccountPassword);
 }
예제 #15
0
        public ConnectBar(TasClient tasClient) : this()
        {
            client = tasClient;


            client.ConnectionLost += (s, e) =>
            {
                canRegister = false;
                {
                    if (client.ConnectionFailed)
                    {
                        lbState.Text = "disconnected due to network problem, autoreconnecting...";
                    }
                    else
                    {
                        lbState.Text           = "disconnected";
                        tasClientConnectCalled = false;
                    }
                    Program.NotifySection.AddBar(this);
                }
            };

            client.Connected += (s, e) =>
            {
                canRegister = false;
                Program.NotifySection.AddBar(this);
                lbState.Text = "Connected, logging in ...";
                if (string.IsNullOrEmpty(Program.Conf.LobbyPlayerName) || string.IsNullOrEmpty(Program.Conf.LobbyPlayerPassword))
                {
                    LoginWithDialog("Please enter your name and password", false);
                }
                else
                {
                    client.Login(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword);
                }
            };

            client.LoginAccepted += (s, e) => Program.NotifySection.RemoveBar(this);

            client.LoginDenied += (s, e) =>
            {
                if (e.ServerParams[0] == "Bad username/password" && !string.IsNullOrEmpty(Program.Conf.LobbyPlayerPassword) && canRegister)
                {
                    lbState.Text = "Registering new account";
                    client.Register(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword);
                }
                else
                {
                    LoginWithDialog("Login denied: " + e.ServerParams[0], false);
                }
            };

            client.RegistrationDenied += (s, e) => LoginWithDialog("Registration denied: " + e.ServerParams[0], true);

            client.RegistrationAccepted += (s, e) => client.Login(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword);

            client.AgreementRecieved += (s, e) =>
            {
                lbState.Text = "Waiting to accept agreement";
                var acceptForm = new AcceptAgreementForm {
                    AgreementText = e.Text
                };
                if (acceptForm.ShowDialog() == DialogResult.OK)
                {
                    lbState.Text = "Sending accept agreement";
                    client.AcceptAgreement();
                    PlasmaShared.Utils.SafeThread(() =>
                    {
                        Thread.Sleep(7000);
                        if (!Program.CloseOnNext)
                        {
                            client.Login(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword);
                        }
                    }).Start();
                }
                else
                {
                    lbState.Text = "did not accept agreement";
                    PlasmaShared.Utils.SafeThread(() =>
                    {
                        Thread.Sleep(2000);
                        if (!Program.CloseOnNext)
                        {
                            client.Disconnect();                                                       //server will re-ask AcceptAgreement if we re-connect
                        }
                    }).Start();
                }
            };
        }
예제 #16
0
        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);
        }
예제 #17
0
        public ConnectBar(TasClient tasClient) : this()
        {
            client = tasClient;

            client.ConnectionLost += (s, e) =>
            {
                {
                    if (!client.WasDisconnectRequested)
                    {
                        lbState.Text = "disconnected, reconnecting...";
                    }
                    else
                    {
                        lbState.Text           = "disconnected";
                        tasClientConnectCalled = false;
                    }
                    Program.NotifySection.AddBar(this);
                }
            };

            client.Connected += (s, e) =>
            {
                lbState.Text = "Connected, logging in ...";
                if (string.IsNullOrEmpty(Program.Conf.LobbyPlayerName) || string.IsNullOrEmpty(Program.Conf.LobbyPlayerPassword))
                {
                    LoginWithDialog("Please choose your name and password.\nThis will create a new account if it does not exist.");
                }
                else
                {
                    client.Login(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword);
                }
            };

            client.LoginAccepted += (s, e) => { Program.NotifySection.RemoveBar(this); };

            client.LoginDenied += (s, e) =>
            {
                if (e.ResultCode == LoginResponse.Code.InvalidName && !string.IsNullOrEmpty(Program.Conf.LobbyPlayerPassword))
                {
                    if (
                        MessageBox.Show(NavigationControl.Instance, //new Form { TopMost = true },
                                        string.Format("Account '{0}' does not exist yet, do you want to create it?", Program.Conf.LobbyPlayerName),
                                        "Confirm account registration",
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        lbState.Text = "Registering a new account";
                        client.Register(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword);
                    }
                    else
                    {
                        LoginWithDialog(string.Format("Login denied: {0} {1}", e.ResultCode.Description()));
                    }
                }
                else
                {
                    LoginWithDialog(
                        string.Format("Login denied: {0} {1}\nChoose a different name to create new account.", e.ResultCode.Description(), e));
                }
            };

            client.RegistrationDenied +=
                (s, e) => LoginWithDialog(string.Format("Registration denied: {0} {1}", e.ResultCode.Description()));

            client.RegistrationAccepted += (s, e) => client.Login(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword);
        }
예제 #18
0
        // login accepted - join channels

        // im connected, let's login
        void tas_Connected(object sender, Welcome welcome)
        {
            tas.Login(GetAccountName(), config.Password);
        }
예제 #19
0
        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 ?? GlobalConst.DefaultEngineOverride;

            springPaths = new SpringPaths(Program.main.paths.GetEngineFolderByVersion(version), Program.main.Config.DataDir);

            springPaths.SpringVersionChanged += (s, e) =>
            {
                if (!String.IsNullOrEmpty(requestedEngineChange) && requestedEngineChange == springPaths.SpringVersion)
                {
                    config.SpringVersion = requestedEngineChange;
                    springPaths.SetEnginePath(Program.main.paths.GetEngineFolderByVersion(requestedEngineChange));
                    requestedEngineChange = null;

                    tas.Say(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(MainConfig.SpringieVersion,
                                isManaged ? Login.ClientTypes.SpringieManaged : Login.ClientTypes.Springie,
                                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.BattleUserJoined   += tas_BattleUserJoined;
            tas.MyBattleMapChanged += tas_MyBattleMapChanged;
            tas.BattleOpened       += tas_BattleOpened;
            tas.UserAdded          += (o, u) => { if (u.Name == GetAccountName())
                                                  {
                                                      OpenBattleRoom(null, null);
                                                  }
            };

            tas.RegistrationDenied += (s, e) =>
            {
                Trace.TraceWarning("Registration denied: {0} {1}", e.ResultCode.Description(), e.Reason);
                CloneNumber++;
                tas.Login(GetAccountName(), config.Password);
            };

            tas.RegistrationAccepted += (s, e) => tas.Login(GetAccountName(), config.Password);

            tas.ConnectionLost  += tas_ConnectionLost;
            tas.Connected       += tas_Connected;
            tas.LoginDenied     += tas_LoginDenied;
            tas.LoginAccepted   += tas_LoginAccepted;
            tas.Said            += tas_Said;
            tas.MyBattleStarted += tas_MyStatusChangedToInGame;

            linkSpringieClient = new ResourceLinkSpringieClient(this);

            // queue autohost
            if (config != null && config.MinToJuggle != null && SpawnConfig == null)
            {
                queue = new MatchMakerQueue(this);
            }


            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);
                    }
                } catch (Exception ex) {
                    Trace.TraceError(ex.ToString());
                } finally {
                    timer.Start();
                }
            };
            timer.Start();
        }
예제 #20
0
        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 ?? GlobalConst.DefaultEngineOverride;
            springPaths = new SpringPaths(Program.main.paths.GetEngineFolderByVersion(version), Program.main.Config.DataDir);
            
            springPaths.SpringVersionChanged += (s, e) =>
                {
                    if (!String.IsNullOrEmpty(requestedEngineChange) && requestedEngineChange == springPaths.SpringVersion) {
                        config.SpringVersion = requestedEngineChange;
                        springPaths.SetEnginePath(Program.main.paths.GetEngineFolderByVersion(requestedEngineChange));
                        requestedEngineChange = null;

                        tas.Say(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(MainConfig.SpringieVersion,
                                isManaged ? Login.ClientTypes.SpringieManaged : Login.ClientTypes.Springie,
                                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.BattleUserJoined += tas_BattleUserJoined;
            tas.MyBattleMapChanged += tas_MyBattleMapChanged;
            tas.BattleOpened += tas_BattleOpened;
            tas.UserAdded += (o, u) => { if (u.Name == GetAccountName()) OpenBattleRoom(null, null); };

            tas.RegistrationDenied += (s, e) =>
                {
                    Trace.TraceWarning("Registration denied: {0} {1}", e.ResultCode.Description(), e.Reason);
                    CloneNumber++;
                    tas.Login(GetAccountName(), config.Password);
                };

            tas.RegistrationAccepted += (s, e) => tas.Login(GetAccountName(), config.Password);

            tas.ConnectionLost += tas_ConnectionLost;
            tas.Connected += tas_Connected;
            tas.LoginDenied += tas_LoginDenied;
            tas.LoginAccepted += tas_LoginAccepted;
            tas.Said += tas_Said;
            tas.MyBattleStarted += tas_MyStatusChangedToInGame;

            linkSpringieClient = new ResourceLinkSpringieClient(this);

            // queue autohost
            if (config != null && config.MinToJuggle != null && SpawnConfig == null)
            {
                queue = new MatchMakerQueue(this);
            }

            
            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);


                    } catch (Exception ex) {
                        Trace.TraceError(ex.ToString());
                    } finally {
                        timer.Start();
                    }
                };
            timer.Start();
           
        }