SendCommandPacket() приватный Метод

private SendCommandPacket ( BattlEyeCommand command, string parameters = "" ) : int
command BattlEyeCommand
parameters string
Результат int
Пример #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();
        }
Пример #2
0
        public virtual void Execute(BattlEyeClient beClient, int timeoutSecs = 10)
        {
            this.RawResponse = null;

            this.Log.DebugFormat("Sending command: '{0}'", this.Metadata.Name);
            BattlEyeCommandResult result = beClient.SendCommandPacket(
                this.RConCommandText,
                handler: (o, args) => this.RawResponse = args.Message,
                timeOutInSecs: timeoutSecs);
            if (result != BattlEyeCommandResult.Success)
            {
                throw new RConException("Error sending command '" + this.RConCommandText + "': " + result);
            }

            while (beClient.CommandQueue > 0)
            {
                /* wait until server acknowledged all commands */
            }
        }
Пример #3
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();
        }
Пример #4
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!");
                }
            }
        }
Пример #5
0
        protected BattlEyeCommandResult SendCommandPacket(BattlEyeClient beClient, string commandText)
        {
            var result = beClient.SendCommandPacket(commandText);
            this.Log.Info(result);

            if (result != BattlEyeCommandResult.Success)
            {
                throw new RConException(
                    "ERROR: There was an error sending command '" + commandText + "': " + result);
            }

            return result;
        }
Пример #6
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();
        }
Пример #7
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;
            }
        }