static void Main(string[] args) { RconClient networkClient = new RconClient("127.0.0.1", 2310, "local"); networkClient.Connected += NetworkClient_Connected; networkClient.Disconnected += NetworkClient_Disconnected; networkClient.MessageReceived += NetworkClient_MessageReceived; networkClient.PlayerConnected += NetworkClient_PlayerConnected; networkClient.PlayerDisconnected += NetworkClient_PlayerDisconnected; networkClient.PlayerRemoved += NetworkClient_PlayerRemoved; networkClient.Connect(); networkClient.WaitUntilConnected(); bool requestSuccess = networkClient.Fetch( command: new GetPlayersRequest(), timeout: 5000, result: out List <Player> onlinePlayers); if (requestSuccess) { Console.WriteLine($"Players online: {onlinePlayers.Count}"); } var bansFetchSuccess = networkClient.Fetch(new GetBansRequest(), 5000, out List <PlayerBan> bans); if (bansFetchSuccess) { Console.WriteLine($"{bans.Count} bans"); } networkClient.Send(new SendMessageCommand("This is a global message")); Console.ReadLine(); }
private static void Main() { try { // Create a new instance of RconClient var rconClient = new RconClient(); // Connect to the server at localhost:25575 rconClient.Connect("localhost"); // Login with password rconClient.Login("password"); // Send command and get its output var cmdOutput = rconClient.SendCommand("list"); // Print command output Console.WriteLine(cmdOutput); } catch (IncorrectPasswordException) { Console.WriteLine("Incorrect RCON password."); } catch (SocketException) { Console.WriteLine("A connection with the RCON server could not be established."); } // Keep console open until user presses any key Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
public void ConnectTestWrongHost() { RconClient client = new RconClient(); Assert.IsTrue(client.Connect("google.de", Port, Password)); Assert.IsTrue(client.IsConnected); client.Disconnect(); }
public void ConnectTestInvalidHost() { RconClient client = new RconClient(); Assert.IsTrue(client.Connect("InvalidHost", Port, Password)); Assert.IsTrue(client.IsConnected); client.Disconnect(); }
public void ConnectTestWrongPassword() { RconClient client = new RconClient(); Assert.IsTrue(client.Connect(Host, Port, "password")); Assert.IsTrue(client.IsConnected); client.Disconnect(); }
public void DisconnectTest() { RconClient client = new RconClient(); Assert.IsTrue(client.Connect(Host, Port, Password)); Assert.IsTrue(client.IsConnected); client.Disconnect(); Assert.IsFalse(client.IsConnected); }
public void ExecuteLowPrioCommandAsyncTest() { RconClient client = new RconClient(); Assert.IsTrue(client.Connect(Host, Port, Password)); Assert.IsTrue(client.IsConnected); client.ExecuteLowPrioCommandAsync(new Rcon.Commands.ListPlayers(), (s, e) => Assert.IsTrue(e.Successful)); client.Disconnect(); }
public bool Connect(string host, int port, string password) { try { client.Connect(host, port, password); return client.IsConnected; } catch (Exception ex) { Log.LogErrorToConsole(ex.Message); } return false; }
private async void DoConnect() { if (RconClient != null) { RconClient.Dispose(); } Dispatcher.Invoke(() => Players.Clear()); RconClient = new RconClient(); RconClient.Disconnected += RconClientOnDisconnected; RconClient.PlayerListCommand.PlayerJoined += RconClientOnPlayerJoined; RconClient.PlayerListCommand.PlayerLeft += RconClientOnPlayerLeft; RconClient.ServerInfoCommand.RoundStart += ServerInfoCommandOnRoundStart; RconClient.Connected += RconClientOnConnected; await RconClient.Connect(Config.RconServerAddress, Config.RconServerPort, Config.RconServerPassword); }
public static bool IsServerResponding(ArkServerInfo Server) { bool serverIsRunning = false; RconClient client = new RconClient(); try { client.Connect(Server.IPAddress, Int32.Parse(Server.RCONPort), Server.ServerPassword); if (client.IsConnected) { serverIsRunning = true; } } catch (Exception ex) { serverIsRunning = false; //Console.WriteLine(DateTime.Now + ": " + Server.Name + " Exception:" + ex.Message); Methods.Log(Server, DateTime.Now + ": " + Server.Name + " Exception:" + ex.Message); } client.Disconnect(); return(serverIsRunning); }
public void ConnectTestNullHost() { RconClient client = new RconClient(); client.Connect(null, Port, Password); }
public void ConnectTestEmptyPassword() { RconClient client = new RconClient(); client.Connect(Host, Port, ""); }
public void ConnectTestEmptyHost() { RconClient client = new RconClient(); client.Connect("", Port, Password); }
public void ConnectTestNegativePort() { RconClient client = new RconClient(); client.Connect(Host, -1, Password); }
static void Main(string[] args) { // Check if some settings not set in the app.config if (string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["RCONServerIP"]) || string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["RCONServerPort"]) || string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["RCONServerPassword"]) || string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["WebservicePort"]) || string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["WebserviceAdminUsername"]) || string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["WebserviceAdminPassword"]) || string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["WebserviceHost"])) { Console.WriteLine("Some settings in app.config is not set"); Console.WriteLine(">> Press any key to quit <<"); Console.ReadLine(); } else { // Get server settings from app.config serverIP = System.Configuration.ConfigurationManager.AppSettings["RCONServerIP"]; serverPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["RCONServerPort"]); serverPassword = System.Configuration.ConfigurationManager.AppSettings["RCONServerPassword"]; webserviceHost = System.Configuration.ConfigurationManager.AppSettings["WebserviceHost"]; webservicePort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["WebservicePort"]); // Setup the rcon client with events etc and connect rconClient = new RconClient(); rconClient.Address = serverIP; rconClient.Port = serverPort; rconClient.Connected += new EventHandler(rconClient_Connected); rconClient.ConnectError += new EventHandler<ConnectErrorEventArgs>(rconClient_ConnectError); rconClient.Disconnected += new EventHandler<DisconnectedEventArgs>(rconClient_Disconnected); rconClient.LevelLoaded += new EventHandler<LevelLoadedEventArgs>(rconClient_LevelLoaded); rconClient.LoggedOn += new EventHandler(rconClient_LoggedOn); rconClient.PlayerAuthenticated += new EventHandler<PlayerAuthenticatedEventArgs>(rconClient_PlayerAuthenticated); rconClient.PlayerChat += new EventHandler<PlayerChatEventArgs>(rconClient_PlayerChat); rconClient.PlayerJoined += new EventHandler<PlayerEventArgs>(rconClient_PlayerJoined); rconClient.PlayerJoining += new EventHandler<PlayerJoiningEventArgs>(rconClient_PlayerJoining); rconClient.PlayerKilled += new EventHandler<PlayerKilledEventArgs>(rconClient_PlayerKilled); rconClient.PlayerLeft += new EventHandler<PlayerEventArgs>(rconClient_PlayerLeft); //rconClient.PlayerMoved += new EventHandler<PlayerMovedEventArgs>(rconClient_PlayerMoved); rconClient.PlayerSpawned += new EventHandler<PlayerEventArgs>(rconClient_PlayerSpawned); rconClient.PunkBusterMessage += new EventHandler<PunkBusterMessageEventArgs>(rconClient_PunkBusterMessage); rconClient.RawRead += new EventHandler<RawReadEventArgs>(rconClient_RawRead); rconClient.Response += new EventHandler<ResponseEventArgs>(rconClient_Response); rconClient.RoundOver += new EventHandler(rconClient_RoundOver); rconClient.Connect(); // Setup a timer for every 5 seconds to run the listplayers function that do stuff with the players, like commands etc. aTimer = new System.Timers.Timer(5000); aTimer.Elapsed += new ElapsedEventHandler(DoPlayerCommands); aTimer.Enabled = true; // Start the webservice/HTTP Listener to listen on webservice port Webservice.Start(webserviceHost, webservicePort); // Add some handling of ctrl+c so we stoping the webservice right Console.TreatControlCAsInput = false; // Turn off the default system behavior when CTRL+C is pressed. Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs eventArgs) { Webservice.Stop(); }; Console.ReadLine(); } }
public void ConnectTestInvalidPort() { RconClient client = new RconClient(); client.Connect(Host, 66666, Password); }
public void ConnectTestNullPassword() { RconClient client = new RconClient(); client.Connect(Host, Port, null); }