Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace RPTMaintenance
- {
- public class Maintenance
- {
- string url;
- string arguments;
- public int ServerStatus { get; set; }
- public void Init()
- {
- if (url == null && arguments == null)
- {
- url = "http://www.thronum.com/launcher/launcher.php";
- arguments = "?v=4022";
- }
- }
- public bool ShouldIBeHappy()
- {
- return (this.ServerStatus == 1) ? false : true;
- }
- public void SetMaintenance()
- {
- var request = WebRequest.Create(string.Concat(url, arguments));
- var response = request.GetResponse();
- var stream = response.GetResponseStream();
- var reader = new StreamReader(stream);
- var content = reader.ReadToEnd();
- reader.Close();
- response.Close();
- // break
- var parts = content.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
- if(parts.Length >= 2)
- {
- var status = parts[2].Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
- if(status.Length == 2)
- {
- this.ServerStatus = (status[1] == "0") ? 1 : 0;
- // if not online, exit all. already online. lazy
- if (this.ServerStatus == 0) Environment.Exit(1);
- }
- else
- {
- this.ServerStatus = -1;
- }
- }
- else
- {
- this.ServerStatus = -1;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment