SHARE
TWEET

Untitled

a guest Aug 25th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.IO;
  2. using System.Net;
  3. using System.Text;
  4.  
  5. namespace ConsoleApp1
  6. {
  7.     internal interface IBedrockConsole
  8.     {
  9.         void TurnOff();
  10.         void TurnOn();
  11.         void Restart();
  12.         void Kill();
  13.  
  14.     }
  15.  
  16.     internal class BedrockConsole : IBedrockConsole
  17.     {
  18.         private string SendRequest(HttpWebRequest request)
  19.         {
  20.             HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  21.             StreamReader stream = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  22.             return stream.ReadToEnd();
  23.         }
  24.  
  25.         private HttpWebRequest RequestCreate(string requestStr, string method)
  26.         {
  27.             Utils.CheckRequestMethod(method);
  28.             HttpWebRequest request = (HttpWebRequest) WebRequest.Create(+ requestStr);
  29.             request.Headers.Add();
  30.             request.Headers.Add();
  31.             request.Headers.Add();
  32.             request.Method = method;
  33.             return request;
  34.         }
  35.  
  36.         private void PowerSignalSend(string signal)
  37.         {
  38.             HttpWebRequest request = RequestCreate("power", "POST");
  39.             string postData = "{ \"signal\": \"" + signal + "\" }";
  40.             byte[] data = Encoding.ASCII.GetBytes(postData);
  41.             request.ContentLength = data.Length;
  42.             using (Stream stream = request.GetRequestStream())
  43.             {
  44.                 stream.Write(data, 0, data.Length);
  45.             }
  46.  
  47.             SendRequest(request);
  48.         }
  49.  
  50.         public void TurnOff()
  51.         {
  52.             PowerSignalSend("stop");
  53.         }
  54.  
  55.         public void TurnOn()
  56.         {
  57.             PowerSignalSend("start");
  58.         }
  59.  
  60.         public void Restart()
  61.         {
  62.             PowerSignalSend("restart");
  63.         }
  64.         public void Kill()
  65.         {
  66.             PowerSignalSend("kill");
  67.         }
  68.  
  69.         public string GetConsole()
  70.         {
  71.             return "";
  72.         }
  73.  
  74.         public string SendToConsole(string command)
  75.         {
  76.             return "";
  77.         }
  78.  
  79.        
  80.     }
  81. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top