Connect() public method

public Connect ( ) : BattlEyeConnectionResult
return BattlEyeConnectionResult
Example #1
0
        private static void Main(string[] args)
        {
            BattlEyeLoginCredentials loginCredentials = new BattlEyeLoginCredentials();
            #region
            loginCredentials.Host = args[0];
            loginCredentials.Port = Convert.ToInt32(args[1]);
            loginCredentials.Password = args[2];
            #endregion

            IBattleNET b = new BattlEyeClient(loginCredentials);
            b.MessageReceivedEvent += DumpMessage;
            b.DisconnectEvent += Disconnected;
            b.ReconnectOnPacketLoss(true);
            b.Connect();

            if (b.IsConnected() == false)
            {
                Console.WriteLine("Couldnt connect to server");
                Console.WriteLine("Failed to reload bans");
                return;
            }

            b.SendCommandPacket(EBattlEyeCommand.loadBans);
            Thread.Sleep(1000); // wait 1 second  for no reason...
            b.Disconnect();
        }
Example #2
0
        /* Public methods */
        public void Listen(BattlEyeLoginCredentials pCredentials)
        {
            BEClient = new BattleNET.BattlEyeClient(pCredentials)
            {
                ReconnectOnPacketLoss = true
            };

            BEClient.BattlEyeMessageReceived += new BattlEyeMessageEventHandler(MessageReceived);
            BEClient.BattlEyeDisconnected    += new BattlEyeDisconnectEventHandler(Disconnected);
            BEClient.BattlEyeConnected       += new BattlEyeConnectEventHandler(Connected);

            while (BEClient.Connect() != BattlEyeConnectionResult.Success)
            {
                Thread.Sleep(Timeout);
                Console.WriteLine("Retrying RCON connection to {0}:{1}", pCredentials.Host, pCredentials.Port);
            }
        }
Example #3
0
        public virtual bool ExecuteSingle()
        {
            var beClient = new BattlEyeClient(this.Context.Server.LoginCredentials)
                               {
                                   ReconnectOnPacketLoss = true,
                                   DiscardConsoleMessages = true
                               };

            var connect = beClient.Connect();
            if (connect != BattlEyeConnectionResult.Success)
            {
                beClient.Disconnect();
                throw new RConException("ERROR: Could not connect to the server: " + connect);
            }

            this.Execute(beClient);
            beClient.Disconnect();
            return true;

            // ~beClient()
        }
        private static void Main(string[] args)
        {
            BattlEyeLoginCredentials loginCredentials = new BattlEyeLoginCredentials();
            #region
            if (args.Length == 3)
            {
                loginCredentials.Host = args[0];
                loginCredentials.Port = Convert.ToInt32(args[1]);
                loginCredentials.Password = args[2];
            }
            else
            {
                Console.WriteLine("Wrong Number of Args");
                Thread.Sleep(5000);
                Environment.Exit(0);
            }
            #endregion

            BattlEyeClient b = new BattlEyeClient(loginCredentials);
            b.BattlEyeMessageReceived += BattlEyeMessageReceived;
            b.BattlEyeConnected += BattlEyeConnected;
            b.BattlEyeDisconnected += BattlEyeDisconnected;
            b.ReconnectOnPacketLoss = true;
            b.Connect();

            if (b.Connected)
            {
                b.SendCommand(BattlEyeCommand.LoadBans);
                while (b.CommandQueue > 0) { /* wait until server received packet */ };
                Thread.Sleep(1000); // wait 1 second  for no reason...
            }
            else
            {
                Console.WriteLine("Couldnt connect to server");
                Console.WriteLine("Failed to reload bans");
                Environment.Exit(0);
            }
            b.Disconnect();
        }
Example #5
0
        private static void Main(string[] args)
        {
            Console.WriteLine(
                "BattleNET v1.3.3 - BattlEye Library and Client\n\n" +
                "Copyright (C) 2015 by it's authors.\n" +
                "Some rights reserved. See license.txt, authors.txt.\n"
            );

            BattlEyeLoginCredentials loginCredentials;
            string command = "";

            Console.OutputEncoding = Encoding.UTF8;

            if (args.Length > 0)
            {
                loginCredentials = GetLoginCredentials(args);

                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i] == "-command")
                    {
                        try
                        {
                            command = args[i + 1];
                        }
                        catch
                        {
                            Console.WriteLine("No command given!");
                            loginCredentials.Host = null;
                        }
                    }
                }

                if (loginCredentials.Host == null || loginCredentials.Port == 0 || loginCredentials.Password == "")
                {
                    Console.WriteLine("BattleNET client usage:");
                    Console.WriteLine("BattleNET client.exe -host 127.0.0.1 -port 2302 -password admin [-command shutdown]");
                    Console.Read();
                    Environment.Exit(0);
                }
            }
            else
            {
                loginCredentials = GetLoginCredentials();
            }

            Console.Title = string.Format("BattleNET client v1.3.3 - {0}:{1}", loginCredentials.Host, loginCredentials.Port);

            BattlEyeClient b = new BattlEyeClient(loginCredentials);
            b.BattlEyeMessageReceived += BattlEyeMessageReceived;
            b.BattlEyeConnected += BattlEyeConnected;
            b.BattlEyeDisconnected += BattlEyeDisconnected;
            b.ReconnectOnPacketLoss = true;
            b.Connect();

            if (command != "")
            {
                b.SendCommand(command);
                while (b.CommandQueue > 0) { /* wait until server received packet */ };
            }
            else
            {
                while (true)
                {
                    string cmd = Console.ReadLine();

                    if (cmd == "exit" || cmd == "logout")
                    {
                        break;
                    }

                    if (b.Connected)
                    {
                        b.SendCommand(cmd);
                    }
                    else
                    {
                        Environment.Exit(0);
                    }
                }
            }

            b.Disconnect();
        }
Example #6
0
        static void Main(string[] args)
        {
            string line;
            bool error = false;
            Console.ResetColor();
            CommandLineArgs CommandLine = new CommandLineArgs(args);

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("====================================");
            Console.WriteLine("ZEDAR.COM.AR // RCon Kicker Started!");
            Console.WriteLine("====================================");
            Console.ForegroundColor = ConsoleColor.Red;

            BattlEyeLoginCredentials loginCredentials;
            loginCredentials = GetLoginCredentials(args);

            if (CommandLine["ip"] == null)
            {
                Console.WriteLine("IP is missing!");
                error = true;
            }

            if (CommandLine["port"] == null)
            {
                Console.WriteLine("Port is missing!");
                error = true;
            }

            if (CommandLine["password"] == null)
            {
                Console.WriteLine("Password is missing!");
                error = true;
            }

            if (CommandLine["kickall"] != null)
            {
                string kam = "Restarting, reconnect in 2 minutes!";
                int kamin = 2;

                if (CommandLine["kickallmsg"] != null)
                {
                    kam = CommandLine["kickallmsg"];
                }
                else
                {
                    Console.WriteLine("kickall message is missing, using the default: " + kam);

                }

                if (CommandLine["kickallmin"] != null)
                {
                    kamin = Convert.ToInt32(CommandLine["kickallmin"]);
                }
                else
                {
                    Console.WriteLine("Minutes of ban missing, using the default: " + kamin);

                }

                if (!error)
                {
                    BattlEyeClient b = new BattlEyeClient(loginCredentials);
                    b.BattlEyeMessageReceived += BattlEyeMessageReceived;
                    b.ReconnectOnPacketLoss = true;
                    b.Connect();
                    // :)
                    for (int i = 0; i <= 100; i++)
                    {
                        //b.SendCommandPacket(EBattlEyeCommand.Kick, Convert.ToString(i));
                        b.SendCommand("ban " + Convert.ToString(i) + " " + kamin + " " + kam);
                    }
                    b.Disconnect();

                }

                Environment.Exit(0);
            }

            Console.ResetColor();

            if (CommandLine["file"] != null)
            {
                if (!error)
                {
                    try
                    {
                        System.IO.StreamReader file = new System.IO.StreamReader(CommandLine["file"]);

                        BattlEyeClient b = new BattlEyeClient(loginCredentials);
                        b.BattlEyeMessageReceived += BattlEyeMessageReceived;
                        b.ReconnectOnPacketLoss = true;
                        b.Connect();

                        while ((line = file.ReadLine()) != null)
                        {
                            Console.WriteLine(line);
                            b.SendCommand("#kick " + line);

                        }
                        b.Disconnect();
                        file.Close();

                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Error: " + ex);
                        Console.ResetColor();

                    }
                }

            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("File path is missing!");
                error = true;
                Console.ResetColor();
            }

            // Console.ReadLine();
        }
Example #7
0
        private static void Main(string[] args)
        {
            BattlEyeLoginCredentials loginCredentials;
            string command = "";

            Console.OutputEncoding = Encoding.UTF8;

            if (args.Length > 0)
            {
                loginCredentials = GetLoginCredentials(args);

                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i] == "-command")
                    {
                        try
                        {
                            command = args[i + 1];
                        }
                        catch
                        {
                            Console.WriteLine("No command given!");
                            loginCredentials.Host = null;
                        }
                    }
                }

                if (loginCredentials.Host == null || loginCredentials.Port == 0 || loginCredentials.Password == "")
                {
                    Console.Read();
                    Environment.Exit(0);
                }
            }
            else
            {
                loginCredentials = GetLoginCredentials();
            }

            Console.Title = string.Format("BattleNET client v1.2 - {0}:{1}", loginCredentials.Host, loginCredentials.Port);

            BattlEyeClient b = new BattlEyeClient(loginCredentials);
            b.MessageEvent += Message;
            b.ConnectEvent += Connect;
            b.DisconnectEvent += Disconnect;
            b.ReconnectOnPacketLoss = true;
            b.Connect();

            if (command != "")
            {
                b.SendCommandPacket(command);
                while (b.CommandQueue > 0) { /* wait until server received packet */ };
            }
            else
            {
                while (true)
                {
                    string cmd = Console.ReadLine();

                    if (cmd == "exit" || cmd == "logout")
                    {
                        break;
                    }

                    if (b.Connected)
                    {
                        b.SendCommandPacket(cmd);
                    }
                    else
                    {
                        Environment.Exit(0);
                    }
                }
            }

            b.Disconnect();
        }
Example #8
0
        private static void Main(string[] args)
        {
            Console.Title = "BattleNET Client";

            BattlEyeLoginCredentials loginCredentials = GetLoginCredentials();

            Console.Title += string.Format(" - {0}:{1}", loginCredentials.Host, loginCredentials.Port);

            IBattleNET b = new BattlEyeClient(loginCredentials);
            b.MessageReceivedEvent += DumpMessage;
            b.DisconnectEvent += Disconnected;
            b.ReconnectOnPacketLoss(true);
            b.Connect();

            while (true)
            {
                string cmd = Console.ReadLine();

                if (cmd == "exit" || cmd == "logout")
                {
                    Environment.Exit(0);
                }

                if (b.IsConnected())
                {
                    b.SendCommandPacket(cmd);
                }
                else
                {
                    Console.WriteLine("Not connected!");
                }
            }
        }
Example #9
0
        public void Connect(IPAddress host, int port, string password)
        {
            _credentials = new BattlEyeLoginCredentials
            {
                Host = host,
                Port = port,
                Password = password
            };

            _client = new BattlEyeClient(_credentials);
            _client.BattlEyeMessageReceived += HandleMessage;
            _client.BattlEyeConnected += HandleConnect;
            _client.BattlEyeDisconnected += HandleDisconnect;
            _client.ReconnectOnPacketLoss = false;

            _initialized = true;
            _client.Connect();
        }
Example #10
0
 private void BEConnect()
 {
     if (loginCredentials.Host == null || loginCredentials.Password == "" || loginCredentials.Port == 0)
     {
         return;
     }
     LogDebug(string.Format("RCON Attempting connection to {0}:{1}", loginCredentials.Host, loginCredentials.Port));
     beClient = new BattlEyeClient(loginCredentials);
     beClient.BattlEyeMessageReceived += BattlEyeMessageReceived;
     beClient.BattlEyeConnected += BattlEyeConnected;
     beClient.BattlEyeDisconnected += BattlEyeDisconnected;
     beClient.ReconnectOnPacketLoss = false;
     beClient.Connect();
 }
Example #11
0
        private void ExecCustomCmd(CommandExecContext commandCtx)
        {
            string command = commandCtx.CommandString;
            var beClient = new BattlEyeClient(commandCtx.Server.LoginCredentials)
                               {
                                   ReconnectOnPacketLoss
                                       = true,
                                   DiscardConsoleMessages
                                       = true
                               };

            beClient.DisconnectEvent += this.Disconnected;
            beClient.Connect();

            this.Log.Info("> " + command);
            BattlEyeCommandResult result = beClient.SendCommandPacket(command, false);
            this.Log.Info(result.ToString());

            while (beClient.CommandQueue > 0)
            {
                /* wait until server received all packets */
            }

            beClient.Disconnect();

            // ~beClient();
        }
Example #12
0
        private void Connect()
        {
            _beClient = new BattlEyeClient(new BattlEyeLoginCredentials(IPAddress.Parse(IP), Port, Password));

            //_beClient.ReconnectOnPacketLoss = true;
            _beClient.BattlEyeConnected += _beClient_BattlEyeConnected;
            _beClient.BattlEyeMessageReceived += MessageFromServerEvent;
            _beClient.BattlEyeDisconnected += ServerDisconnectEvent;

            //_isConnecting = true;

            _beClient.Connect();
        }
Example #13
0
        static void Main(string[] args)
        {
            string cfgFile;
            Boolean goodFile = false;
            BattlEyeLoginCredentials loginCredentials;
            Config cfg = new Config();

            Dictionary<string, string> ArgPairs = new Dictionary<string, string>();

            if (args.Length == 1)
            {
                string arg1 = args[0];
                // validate we have arguments
                if (arg1.Contains("--configfile=") && arg1.Contains(".xml"))
                {
                    string[] ArgSplit = arg1.Split('=');
                    if (ArgSplit.Length == 2)
                    {
                        // get cfg file
                        cfgFile = ArgSplit[1];

                        // get data from cfg file
                        goodFile = cfg.GetSettingsFromXML(cfgFile);

                    }

                }

            }
            // cli specified args
            // usage: ServerRestartDeluxe.exe server=127.0.0.1 port=2302 password=pw
            else if (args.Length > 1)
            {

                // split up args
                foreach (string inputArg in args)
                {
                    if (inputArg.Contains("="))
                    {
                        string[] pair = inputArg.Split('=');
                        ArgPairs.Add(pair[0], pair[1]);
                    }

                }

                // parse argpairs
                foreach (KeyValuePair<string, string> argPair in ArgPairs)
                {
                    switch (argPair.Key)
                    {
                        case "server":
                            cfg.IP = argPair.Value.ToString();
                            break;
                        case "port":
                            cfg.Port = argPair.Value.ToString();
                            break;
                        case "password":
                            cfg.Password = argPair.Value.ToString();
                            break;
                    }
                }

                // assume good - Fix Later - JG
                goodFile = true;
            }
            if (goodFile == true)
            {
                // establish connection
                loginCredentials = new BattlEyeLoginCredentials();
                loginCredentials.Host = cfg.IP;
                loginCredentials.Password = cfg.Password;
                loginCredentials.Port = Convert.ToInt32(cfg.Port);

                IBattleNET b = new BattlEyeClient(loginCredentials);
                b.MessageReceivedEvent += DumpMessage;
                b.DisconnectEvent += Disconnected;
                b.ReconnectOnPacketLoss(true);
                b.Connect();

                // validate connection
                if (b.IsConnected() == false)
                {
                    Console.WriteLine("No connection starting server");
                    // Process.Start(processPath);

                    // exit
                    return;
                }
                else
                {
                    Console.Title = "DayZ Ultra Server Restart 15 min warning";
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 15 min.");
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 15 min.");
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 15 min.");
                    Thread.Sleep(600000);

                    Console.Title = "DayZ Ultra Server Restart 5 minute warning";
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 5 minutes.");
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 5 minutes.");
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 5 minutes.");
                    Thread.Sleep(60000);
                    Console.Title = "DayZ Ultra Server Restart 4 minute warning";
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 4 minutes.");
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 4 minutes.");
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 4 minutes.");
                    Thread.Sleep(60000); // wait 1 min
                    Console.Title = "DayZ Ultra Server Restart 3 minute warning";
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 3 minutes.");
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 3 minutes.");
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 3 minutes.");
                    Thread.Sleep(60000); // wait 1 min
                    Console.Title = "DayZ Ultra Server Restart 2 minute warning";
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 2 minutes.");
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 2 minutes.");
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 2 minutes.");
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 2 minutes.");
                    Thread.Sleep(60000); // wait 1 min
                    Console.Title = "DayZ Ultra Server Restart 1 minute warning";
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 1 minute.  Log off now");
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 1 minute.  Log off now");
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 1 minute.  Log off now");
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 1 minute.  Log off now");
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 1 minute.  Log off now");
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset in 1 minute.  Log off now");

                    // lock server
                    b.SendCommandPacket(EBattlEyeCommand.Lock);

                    Thread.Sleep(60000); // wait 1 min
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset NOW!");
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset NOW!");
                    b.SendCommandPacket(EBattlEyeCommand.Say, "-1 Server going down for reset NOW!");
                    Console.WriteLine("Shutdown cmd");
                    //b.SendCommandPacket(EBattlEyeCommand.Shutdown);
                    System.Environment.Exit(0);
                }

                // warnings
            }
            else
            {
                // exit
                Console.WriteLine("Error reading config file. exiting now...");
                return;
            }
        }