Guest User

Untitled

a guest
Dec 9th, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9.  
  10. namespace RPTMaintenance
  11. {
  12.     public class Maintenance
  13.     {
  14.         string url;
  15.         string arguments;
  16.  
  17.         public int ServerStatus { get; set; }
  18.  
  19.         public void Init()
  20.         {
  21.             if (url == null && arguments == null)
  22.             {
  23.                 url = "http://www.thronum.com/launcher/launcher.php";
  24.                 arguments = "?v=4022";
  25.             }
  26.         }
  27.  
  28.         public bool ShouldIBeHappy()
  29.         {
  30.             return (this.ServerStatus == 1) ? false : true;
  31.         }
  32.  
  33.         public void SetMaintenance()
  34.         {
  35.             var request = WebRequest.Create(string.Concat(url, arguments));
  36.             var response = request.GetResponse();
  37.             var stream = response.GetResponseStream();
  38.  
  39.  
  40.             var reader = new StreamReader(stream);
  41.             var content = reader.ReadToEnd();
  42.  
  43.             reader.Close();
  44.             response.Close();
  45.  
  46.             // break
  47.             var parts = content.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  48.  
  49.             if(parts.Length >= 2)
  50.             {
  51.                 var status = parts[2].Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
  52.                 if(status.Length == 2)
  53.                 {
  54.                     this.ServerStatus = (status[1] == "0") ? 1 : 0;
  55.                    
  56.                     // if not online, exit all. already online. lazy
  57.                     if (this.ServerStatus == 0) Environment.Exit(1);
  58.                 }
  59.                 else
  60.                 {
  61.                     this.ServerStatus = -1;
  62.                 }
  63.             }
  64.             else
  65.             {
  66.                 this.ServerStatus = -1;
  67.             }
  68.         }
  69.  
  70.  
  71.  
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment