public void SendReceiveTest() { RconBase client = new RconBase(); client.Connect(Host, Port); client.Authenticate(Password); RconPacket request = new RconPacket(PacketType.ServerdataExeccommand, new Rcon.Commands.ListPlayers().ToString()); RconPacket response = client.SendReceive(request); Assert.IsInstanceOfType(response, typeof(RconPacket)); Assert.AreEqual(request.Id, response.Id); client.Disconnect(); }
public static void ShutdownServer(ArkServerInfo Server) { try { RconBase client = new RconBase(); client.Connect(Server.IPAddress, Int32.Parse(Server.RCONPort)); if (client.Connected) { client.Authenticate(Server.ServerPassword); RconPacket request = new RconPacket(PacketType.ServerdataExeccommand, new Rcon.Commands.DoExit().ToString()); RconPacket response = client.SendReceive(request); Console.WriteLine(response?.Body.Trim()); Methods.Log(Server, response?.Body.Trim()); } client.Disconnect(); } catch (Exception ex) { //Console.WriteLine(DateTime.Now + ": Exception occured when trying to send a Ark Server Shutdown Command. Exception: " + ex.Message); Methods.Log(Server, DateTime.Now + ": Exception occured when trying to send a Ark Server Shutdown Command. Exception: " + ex.Message); } }
public static bool WorldSave(ArkServerInfo Server) { RconBase client = new RconBase(); client.Connect(Server.IPAddress, Int32.Parse(Server.RCONPort)); if (client.Connected) { client.Authenticate(Server.ServerPassword); RconPacket request = new RconPacket(PacketType.ServerdataExeccommand, new Rcon.Commands.SaveWorld().ToString()); RconPacket response = client.SendReceive(request); string stringResponse = response?.Body.Trim(); if (stringResponse.Contains("World Saved")) { Console.WriteLine(DateTime.Now + ": Server " + Server.Name + "- World Saved!"); Methods.Log(Server, DateTime.Now + ": Server " + Server.Name + "- World Saved!"); client.Disconnect(); return(true); } } client.Disconnect(); return(false); }
public static void GlobalNotification(ArkServerInfo Server, string message) { try { RconBase client = new RconBase(); client.Connect(Server.IPAddress, Int32.Parse(Server.RCONPort)); if (client.Connected) { client.Authenticate(Server.ServerPassword); RconPacket request = new RconPacket(PacketType.ServerdataExeccommand, new Rcon.Commands.Broadcast(message).ToString()); RconPacket response = client.SendReceive(request); //Console.WriteLine(DateTime.Now + ": Broadcast sent to " + Server.Name + " Server Message: " + message); Methods.Log(Server, DateTime.Now + ": Broadcast sent to " + Server.Name + " Server Message: " + message); } client.Disconnect(); } catch (Exception ex) { //Console.WriteLine(DateTime.Now + ": Exception occured when trying to send an Ark Server Global Notification. Exception: " + ex.Message); Methods.Log(Server, DateTime.Now + ": Exception occured when trying to send an Ark Server Global Notification. Exception: " + ex.Message); } }