forked from Th3ClosetG33k/OGame-Planet-Builder-V2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.cs
143 lines (135 loc) · 5.63 KB
/
http.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using System;
using System.IO;
using System.Net;
using System.Threading;
using System.Windows.Forms;
namespace OGPB
{
public class http
{
public bool development = false;
public string version = "2.0.18", status = "beta";
public GUI gui;
public Encryption encrypt = new Encryption();
private HttpWebRequest httpRequest;
private CookieContainer httpCookies = new CookieContainer();
private IWebProxy httpProxy = new WebProxy("128.208.04.198", 3124);
public string server = "http://uni42.ogame.org/game/";
public string referer = "http://ogame.org";
public string session = "";
public string token = "";
public int currentPlanet = 0;
public bool allPlanetsIDed = false;
private HttpWebRequest PrepareRequest(string URL)
{
if (URL.IndexOf("http") != 0)
{
URL = server + URL;
}
httpRequest = (HttpWebRequest)WebRequest.Create(URL);
httpRequest.CookieContainer = httpCookies;
//httpRequest.Proxy = httpProxy;
httpRequest.UserAgent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2";
httpRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
httpRequest.Headers.Add("Accept-Language", "en-us,en;q=0.5");
httpRequest.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
httpRequest.Referer = referer;
return httpRequest;
}
private string ReadResponseContent(WebResponse response)
{
if (response.ResponseUri.ToString().Contains("&ajax=1") == false)
{
referer = response.ResponseUri.ToString();
}
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string content = reader.ReadToEnd();
reader.Close();
response.Close();
if (content.Contains("<script>document.location.href='http://ogame.org';</script>") == true)
{
gui.ChangeStatus("We have been logged out!");
Application.ExitThread();
}
return content;
}
public string Login(string Username, string Password)
{
PrepareRequest("reg/login2.php?&login=" + Username + "&pass=" + Password + "&v=2&is_utf8=0");
WebResponse response = httpRequest.GetResponse();
string location = ((HttpWebResponse)response).ResponseUri.ToString();
if (location.IndexOf("session=") != -1)
{
session = location.Substring(location.IndexOf("session=") + "session=".Length);
session = session.Remove(session.Length - 6);
return ReadResponseContent(response);
}
else
{
referer = "http://ogame.org";
return "";
}
}
public string DownloadFile(string URL)
{
PrepareRequest(URL);
WebResponse response = httpRequest.GetResponse();
return ReadResponseContent(response);
}
public string PostFile(string URL, string post)
{
PrepareRequest(URL);
httpRequest.Method = "POST";
httpRequest.ContentType = "application/x-www-form-urlencoded";
httpRequest.ContentLength = post.Length;
using (StreamWriter writer = new StreamWriter(httpRequest.GetRequestStream(), System.Text.Encoding.ASCII))
{
writer.Write(post);
}
WebResponse response = httpRequest.GetResponse();
return ReadResponseContent(response);
}
public string CommunicateWithServer(string page, string toSend)
{
PrepareRequest("http://ogpbv2.vndv.com/secure/" + page + ".php");
toSend = "data=" + toSend;
httpRequest.Method = "POST";
httpRequest.ContentType = "application/x-www-form-urlencoded";
httpRequest.ContentLength = toSend.Length;
using (StreamWriter writer = new StreamWriter(httpRequest.GetRequestStream(), System.Text.Encoding.ASCII))
{
writer.Write(toSend);
}
WebResponse response = httpRequest.GetResponse();
return ReadResponseContent(response);
}
public bool NeedUpdate()
{
string response = CommunicateWithServer("update", "version=" + version + ";status=" + status);
gui.AddToLog("Currently running " + version + " " + status);
gui.AddToLog("Update check: " + response);
if (response == "OK") {
return false;
}
else if (response.Contains("UPDATE-") == true)
{
DialogResult runUpdate = MessageBox.Show("There is an update available! Would you like to download it now?", "Update Available", MessageBoxButtons.YesNo);
if (runUpdate == DialogResult.Yes)
{
System.Diagnostics.Process.Start(response.Substring("UPDATE-".Length));
return true;
}
else
{
return false;
}
}
else
{
MessageBox.Show("The OGPB servers are offline or have moved. All paid and remote management features will be disabled! Please check to see if there is a new version!");
return false;
}
}
}
}