Ejemplo n.º 1
0
            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)
                    {
                    }
                }
            }
Ejemplo n.º 2
0
            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)
                    {
                    }
                }
            }
Ejemplo n.º 3
0
            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)
                    {
                    }
                }
            }
Ejemplo n.º 4
0
            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));
                }
            }