Ejemplo n.º 1
0
 public int OpenConnection()
 {
     _busy = true;
     lock (_lock)
     {
         var result = _client.Connect();
         if (result != 0)
         {
             Task.Run(() =>
             {
                 _busy = true;
                 Console.WriteLine("Connection to the server could not be established...\n Will try to reconnect now!");
                 for (int tries = 0; tries < _settings.repeat; tries++)
                 {
                     Console.WriteLine($"Try {tries}/{_settings.repeat}");
                     result = _client.Connect();
                     if (result == 0)
                     {
                         Console.WriteLine("Connection established...");
                         _busy = false;
                         return;
                     }
                     Console.WriteLine("Connection could not be established...");
                     Task.Delay(5 * 1000).Wait();
                 }
                 Environment.Exit(1);
             });
         }
         _busy = false;
         return((int)result);
     }
 }
Ejemplo n.º 2
0
        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...
        }
Ejemplo n.º 3
0
        private static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            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!");
                }
            }
        }
Ejemplo n.º 4
0
        public void Connect()
        {
            for (var tries = 1; tries <= _maxtries; tries++)
            {
                try
                {
                    _beclient.Connect();
                    if (!_beclient.Connected)
                    {
                        throw new CoreException();
                    }
                    break;
                }
                catch
                {
                    AppConsole.Log(String.Format("Failed to connect to server. Attempt {0}/{1}", tries, _maxtries), ConsoleColor.Red);
                }
                Thread.Sleep(1000);
            }

            if (!_beclient.Connected)
            {
                throw new CoreException("Failed to connect to server.");
            }
            _connected = true;
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            try
            {
                IPAddress host     = IPAddress.Parse("127.0.0.1"); // Адрес Arma 2 OA сервера для подключения
                int       sport    = 2302;                         // Порт Arma 2 OA
                string    password = "******";                       // Пароль BEServer
                BattlEyeLoginCredentials loginCredentials = new BattlEyeLoginCredentials
                {
                    Host     = host,
                    Port     = sport,
                    Password = password,
                };
                b = new BattlEyeClient(loginCredentials);
                b.BattlEyeMessageReceived += BattlEyeMessageReceived;
                b.BattlEyeConnected       += BattlEyeConnected;
                b.BattlEyeDisconnected    += BattlEyeDisconnected;
                b.ReconnectOnPacketLoss    = true;
                b.Connect();
                listener = new TcpListener(IPAddress.Parse("0.0.0.0"), port); // Адрес сервера для прослушивания
                listener.Start();
                if (ClientObject.debug)
                {
                    Console.WriteLine("Ожидание подключений...");
                }
                b.SendCommand("Players");
                Thread reloadthread = new Thread(new ThreadStart(bereload));
                reloadthread.Start();
                while (true)
                {
                    TcpClient    client       = listener.AcceptTcpClient();
                    ClientObject clientObject = new ClientObject(client);

                    // создаем новый поток для обслуживания нового клиента
                    Thread clientThread = new Thread(new ThreadStart(clientObject.Process));
                    clientThread.Start();
                }
            }
            catch (Exception ex)
            {
                if (ClientObject.debug)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            finally
            {
                if (listener != null)
                {
                    listener.Stop();
                }
            }
        }
Ejemplo n.º 6
0
        private static void beloop()
        {
            client = new BattlEyeClient(creds);
            client.BattlEyeMessageReceived += BattlEyeMessageReceived;
            client.BattlEyeConnected       += BattlEyeConnected;
            client.BattlEyeDisconnected    += BattlEyeDisconnected;
            client.ReconnectOnPacketLoss    = true;

            do
            {
                if (client.Connected == false)
                {
                    client.Connect();
                }
                Thread.Sleep(1000 * 10);
            }while(true);
        }
Ejemplo n.º 7
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();
        }
Ejemplo n.º 8
0
        /*
         * Primary connect and disconnect handlers
         */
        #region CXN_MAIN

        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (isConnected)
            {
                handleDisconnect();
                b.Disconnect();
            }
            else
            {
                loginCredentials = GetLoginCredentials();
                b = new BattlEyeClient(loginCredentials);
                b.BattlEyeMessageReceived += BattlEyeMessageReceived;
                b.BattlEyeConnected       += BattlEyeConnected;
                b.BattlEyeDisconnected    += BattlEyeDisconnected;
                b.ReconnectOnPacketLoss    = true;
                b.Connect();

                //handleConnect();
            }
        }
Ejemplo n.º 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();
            string[] strArray = new string[Settings.Default.hilight.Count];
            Settings.Default.hilight.CopyTo(strArray, 0);

            _hilight = strArray;
        }
Ejemplo n.º 10
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;
            }
        }
Ejemplo n.º 11
0
        private static void Main(string[] args)
        {
            Console.WriteLine(
                "BattleNET v1.3 - BattlEye Library and Client\n\n" +
                "Copyright (C) 2013 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 - {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 */ } {
                ;
        }
Ejemplo n.º 12
0
 public BattlEyeConnectionResult Connect()
 {
     _log.Info($"{_serverName}: Connect called");
     return(_battlEyeClient.Connect());
 }
Ejemplo n.º 13
0
 public BattlEyeConnectionResult Connect()
 {
     return(_battlEyeClient.Connect());
 }