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!"); } } }
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(); }
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; }
public Api(BattlEyeClient client, ISettings settings) { _db = new DB(); _beclient = client; _settings = settings; _beclient.BattlEyeConnected += BattlEyeConnected; _beclient.BattlEyeDisconnected += BattlEyeDisconnected; _beclient.BattlEyeMessageReceived += BattlEyeMessageReceived; _getPlayersTimer.Interval = 1000; _getPlayersTimer.Elapsed += getPlayersTimer_Elapsed; _getPlayersTimer.Enabled = true; }
public override void Execute(BattlEyeClient beClient, int timeoutSecs = 10) { for (int i = 0; i <= 100; i++) { string cmd = string.Format( CultureInfo.InvariantCulture, "Kick {0} {1}", i, this.KickReason); this.Log.InfoFormat("Sending command: '{0}'", cmd); this.SendCommandPacket(beClient, cmd); } while (beClient.CommandQueue > 0) { /* wait until server received all packets */ } }
/* 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); } }
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 */ } }
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() }
public override bool ExecAwaitResponse(BattlEyeClient beClient, int timeoutSecs = 10) { if (base.ExecAwaitResponse(beClient, timeoutSecs)) { // let's do the db access one at a time shall we? lock (SyncRoot) { try { this.UpdateDatabase(); } catch (Exception e) { throw new RConException("ERROR: Could not update database.", e); } } return true; } return false; }
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(); }
private void InitClients() { _log.Info(string.Format("{0}:{1} Update client - InitClients", _host, _port)); lock (_lock) { if (_battlEyeClient != null) ReleaseClient(); var credentials = new BattlEyeLoginCredentials(IPAddress.Parse(_host), _port, _password); _battlEyeClient = new BattlEyeClient(credentials); _battlEyeClient.ReconnectOnPacketLoss = true; _battlEyeClient.BattlEyeConnected += battlEyeClient_BattlEyeConnected; _battlEyeClient.BattlEyeDisconnected += _battlEyeClient_BattlEyeDisconnected; _battlEyeClient.BattlEyeMessageReceived += battlEyeClient_BattlEyeMessageReceived; } }
public void Dispose() { try { Disposed = true; ReleaseClient(); if (_thread != null) _thread.Abort(); GC.SuppressFinalize(this); } finally { _battlEyeClient = null; } }
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(); }
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(); }
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(); }
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(); }
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(); }
private BattlEyeClient BEClient() { AppConsole.Log("Loading BEClient..."); var login = new BattlEyeLoginCredentials { Host = _settings.Address, Port = _settings.Port, Password = _settings.RconPass }; var beclient = new BattlEyeClient(login) {ReconnectOnPacketLoss = true}; beclient.BattlEyeConnected += BattlEyeConnected; beclient.BattlEyeDisconnected += BattlEyeDisconnected; return beclient; }
private void ReleaseClient() { _log.Info(string.Format("{0}:{1} Update client - ReleaseClient", _host, _port)); lock (_lock) { if (_battlEyeClient != null) { try { if (_battlEyeClient.Connected) _battlEyeClient.Disconnect(); _battlEyeClient.BattlEyeConnected -= battlEyeClient_BattlEyeConnected; _battlEyeClient.BattlEyeDisconnected -= _battlEyeClient_BattlEyeDisconnected; _battlEyeClient.BattlEyeMessageReceived -= battlEyeClient_BattlEyeMessageReceived; } finally { _battlEyeClient = null; } } } }
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(); }
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(); }
public void Run(string[] args) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Console.Title = "MBCon - Connecting..."; #if DEBUG AppConsole.Log(String.Format("MBCon - WARNING THIS IS A DEBUG APP!!!"), ConsoleColor.Red); AppConsole.Log(String.Format("MBCon - WARNING THIS IS A DEBUG APP!!!"), ConsoleColor.Red); AppConsole.Log(String.Format("MBCon - WARNING THIS IS A DEBUG APP!!!"), ConsoleColor.Red); AppConsole.Log(String.Format("MBCon - WARNING THIS IS A DEBUG APP!!!"), ConsoleColor.Red); AppConsole.Log(String.Format("MBCon - WARNING THIS IS A DEBUG APP!!!"), ConsoleColor.Red); #else AppConsole.Log(String.Format("=========================="), ConsoleColor.DarkCyan); AppConsole.Log(String.Format("MBCon - by maca134"), ConsoleColor.Cyan); AppConsole.Log(String.Format("*****@*****.**"), ConsoleColor.Gray); AppConsole.Log(String.Format("=========================="), ConsoleColor.DarkCyan); AppConsole.Log(""); Thread.Sleep(4000); #endif _args.Setup<string>("config") .Callback(val => _configPath = val) .SetDefault(Path.Combine(BasePath, "config.ini")); _args.Setup<int>("delay") .Callback(val => _startupDelay = val) .SetDefault(0); _args.Parse(args); if (!File.Exists(_configPath)) { throw new CoreException(String.Format("Config file \"{0}\" was not found.", _configPath)); } AppConsole.Log("Config file found, continuing to load..."); var ini = new IniParser(_configPath); try { _settings = new Settings(ini); } catch (SettingsException ex) { throw new CoreException(String.Format("Error Loading Settings: {0}", ex.Message)); } if (_startupDelay > 0) { AppConsole.Log(string.Format("Waiting for {0} seconds", _startupDelay)); Thread.Sleep(_startupDelay * 1000); } _beclient = BEClient(); _pluginManager = new PluginManager(PluginPath); _api = new Api(_beclient, _settings); _pluginManager.Init(_api); AppConsole.Log("Connecting to server..."); Connect(); }
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; } }