ItsMods

Full Version: Read command output
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
on request of @iAegle here is the C# code from my (not released yet) RCON plugin which reads the output from the console after you've executed a command.
This is not perfect, because it waits 1 sec which makes command processing not really fast. You can change it to something lower however i do not recommend it

Function
CSHARP Code
  1. string readResponse(string identifier)
  2. {
  3. string[] content = File.ReadAllLines("addon\\logs\\console.log");
  4. bool add = false;
  5. string output = "";
  6. foreach (string z in content)
  7. {
  8. string r = "";
  9. try { r = z.Substring(11); } catch { }
  10. if(add) { output += r; output += "\n"; }
  11. if (r == identifier) add = true;
  12. }
  13. return output;
  14. }


Usage example
CSHARP Code
  1. Random random = new Random();
  2. string id = Convert.ToString(random.Next(1, 99999));
  3. ServerPrint("]" + cmd.Replace("\r\n", "").Replace("\n", ""));
  4. ServerLog(LogType.LogConsole, id);
  5. ServerCommand(cmd);
  6. Thread.Sleep(1000); //wait for the command to process
  7. string lulz = readResponse(id);
  8. return lulz;
<3 5char