public async Task GameMode(string input) { MemoryStream ms = new MemoryStream(); using (var client = CmSsh.CreateSftpClient(_config)) { try { client.Connect(); var lines = client.ReadAllLines($"/srv/steam/hlserver/csgo/cfg/gamemode_{input}.cfg"); foreach (var line in lines) { for (int i = 0; i < 10; i++) { if (TryRunRconCommand(line, out string response)) { break; } await Task.Delay(500); } } client.Disconnect(); } catch (Exception ex) { } } }
public async Task RestartServer() { using (var client = CmSsh.CreateSshClient(_config)) { try { SshCommand cmd = null; client.Connect(); cmd = client.RunCommand("sudo /bin/systemctl stop csgo"); if (cmd.ExitStatus != 0) { await ReplyAsync(cmd.Error); return; } cmd = client.RunCommand("sudo /bin/systemctl start csgo"); if (cmd.ExitStatus != 0) { await ReplyAsync(cmd.Error); return; } client.Disconnect(); await ReplyAsync("Restarting server"); } catch (Exception ex) { } } }
public async Task SshCommand(string message) { using (var client = CmSsh.CreateSshClient(_config)) { try { client.Connect(); var cmd = client.RunCommand(message); await ReplyAsync(cmd.Result); client.Disconnect(); } catch (Exception ex) { } } }
public async Task GameModes() { using (var client = CmSsh.CreateSshClient(_config)) { string runCommand = @"ls /srv/steam/hlserver/csgo/cfg/gamemode*.cfg -1 | grep -oP 'gamemode_\K\w+'"; string seperator = "\n"; string fileStartsWith = "gamemode_"; string fileEndsWith = ".cfg"; string joinSeperator = ", "; client.Connect(); var cmd = client.RunCommand(runCommand); var result = cmd.Result .Split(seperator) .ToArray(); await ReplyAsync(String.Join(joinSeperator, result)); } }