Code:
//<C> by Requi (Coding the API)
//<C> by FlutterShy (Code in Auto(sh)it)
//<C> by all e*pvp Users, for being our fans <3
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
public static class DarkOrbitAPI
{
#region "ToDo List"
//Importing Trapdoor.dll for more features
//[DllImport("Trapdoor.dll")]
//Public Function TrapiGetSize(ByVal sessionId As String, ByVal width As Integer, ByVal height As Integer) As Integer
//End Function
//
//Code more features
#endregion
#region "Variables"
public static string server;
public static string iGreen;
public static string iRed;
public static string iBlue;
public static string[] BootyArray = new string[3];
public static string sJackpot;
public static string sMain;
public static string iInfo;
public static string sHangar;
public static string iUID;
public static string sSID;
public static string sCredits;
public static string sUridium;
public static CookieContainer cookie;
#endregion
#region "HTTP"
public static string GetResponse(string sUrl, string sPost)
{
try
{
HttpWebRequest nRequest = (HttpWebRequest)WebRequest.Create(sUrl);
nRequest.Method = "POST";
nRequest.CookieContainer = cookie;
nRequest.ContentType = "application/x-www-form-urlencoded";
nRequest.Proxy = new WebProxy();
byte[] nbyteArray = Encoding.UTF8.GetBytes(sPost);
nRequest.ContentLength = nbyteArray.Length;
Stream nDataStream = nRequest.GetRequestStream();
nDataStream.Write(nbyteArray, 0, nbyteArray.Length);
nDataStream.Close();
nRequest.KeepAlive = true;
nRequest.AllowAutoRedirect = true;
nRequest.PreAuthenticate = true;
HttpWebResponse nResponse = (HttpWebResponse)nRequest.GetResponse();
nDataStream = nResponse.GetResponseStream();
StreamReader nreader = new StreamReader(nDataStream);
string nServerResponse = nreader.ReadToEnd();
nreader.Close();
nDataStream.Close();
nResponse.Close();
return nServerResponse;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return null;
}
}
static CookieContainer static_GetResponse_cookiecontainer;
static CookieCollection static_GetResponse_cookiecoll;
public static string GetResponse(string sUrl)
{
try
{
if ((static_GetResponse_cookiecoll == null))
{
static_GetResponse_cookiecoll = new CookieCollection();
}
if ((static_GetResponse_cookiecontainer == null))
{
static_GetResponse_cookiecontainer = new CookieContainer();
}
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(sUrl);
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E)";
req.Method = "GET";
req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
req.KeepAlive = true;
req.CookieContainer = new CookieContainer();
req.CookieContainer = static_GetResponse_cookiecontainer;
req.CookieContainer.Add(static_GetResponse_cookiecoll);
req.Proxy = new WebProxy();
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
string html = sr.ReadToEnd();
sr.Close();
response.Close();
return html;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return null;
}
}
public static string StringBetween(string content, string strStart, string strEnd)
{
try
{
int iPos = 0;
int startPos = 0;
int iEnd = 0;
int lenStart = strStart.Length;
string strResult = null;
strResult = string.Empty;
iPos = content.IndexOf(strStart, startPos);
iEnd = content.IndexOf(strEnd, iPos + lenStart);
if (iPos != -1 && iEnd != -1)
{
strResult = content.Substring(iPos + lenStart, iEnd - (iPos + lenStart));
}
return strResult;
}
catch
{
return Convert.ToString(false);
}
}
public static string StringRegExp(string content, string regstring)
{
string str4 = "";
string input = content;
Match match = Regex.Match(input, regstring, RegexOptions.Multiline);
if ((match.Groups.Count == 2))
{
str4 = match.Groups[1].Value;
}
return str4;
}
#endregion
#region "API"
public static bool Login(string username, string password, string server)
{
StringBuilder sb = new StringBuilder();
sb.Append("loginForm_default_username=");
sb.Append(EncodeUsername(username));
sb.Append("&loginForm_default_password=");
sb.Append(EncodeUsername(password));
sb.Append("&loginForm_default_login_submit=Login");
string sLogged = GetResponse("http://www.darkorbit.com/?locale=de&aid=0", sb.ToString());
if (sLogged.Contains("serverSelection_ini ini_active"))
{
GetResponse("http://" + server + ".darkorbit.bigpoint.com/GameAPI.php?" + StringBetween(sLogged, "http://" + server + ".darkorbit.bigpoint.com/GameAPI.php?", ((char)34).ToString() + " onclick=" + ((char)34).ToString() + "InstanceSelection.clickedIni(this);" + ((char)34).ToString() + ">"));
GetResponse("http://" + server + ".darkorbit.bigpoint.com/indexInternal.es?action=internalDock");
return true;
}
return false;
}
public static string[] GetBootys(string content)
{
GetResponse("http://" + server + ".darkorbit.bigpoint.com/indexInternal.es?action=internalDock");
iGreen = StringRegExp(content, "<span title=" + ((char)34).ToString() + "(\\d) ");
iRed = StringRegExp(content, "<span title=" + ((char)34).ToString() + "(\\d) ");
iBlue = StringRegExp(content, "<span title=" + ((char)34).ToString() + "(\\d) ");
BootyArray[0] = iGreen;
BootyArray[1] = iRed;
BootyArray[2] = iBlue;
return BootyArray;
}
public static string GetJackpot(string content)
{
sJackpot = StringBetween(content, "<div>", "</div>");
return sJackpot;
}
public static string GetMainInfos(string content)
{
GetResponse("http://" + server + ".darkorbit.bigpoint.com/indexInternal.es?action=internalStart");
sMain = StringBetween(content, "class=" + ((char)34).ToString() + "userInfo_right" + ((char)34).ToString() + ">", "</div><br");
return sMain;
}
public static string GetUserInfos(string content)
{
iInfo = StringBetween(content, "<span>", "</span>");
return iInfo;
}
public static string GetHangarInfos(string content)
{
GetResponse("http://" + server + ".darkorbit.bigpoint.com/indexInternal.es?action=internalDock");
sHangar = StringBetween(content, "<td class=" + ((char)34).ToString() + "values" + ((char)34).ToString() + ">", "</td>");
return sHangar;
}
public static string GetUID(string content)
{
iUID = StringRegExp(content, "userKeyId : '(.*?)',");
return iUID;
}
public static string GetSID(string content)
{
sSID = StringRegExp(content, "var SID='dosid=(.*?)';");
return sSID;
}
public static string GetCredits(string content)
{
sCredits = StringBetween(content, "class=" + ((char)34).ToString() + "header_money" + ((char)34).ToString() + ">", "</div>");
sCredits = sCredits.Replace(" ", "");
return sCredits;
}
public static string GetUri(string content)
{
sUridium = StringBetween(content, ";" + ((char)34).ToString() + " >", "</a>");
sUridium = sUridium.Trim(Convert.ToChar(">"));
sUridium = sUridium.Replace(" ", "");
return sUridium;
}
public static string EncodeUsername(string string0)
{
byte[] stringdata = new UTF8Encoding().GetBytes(string0);
string temp = "";
foreach (byte b in stringdata)
{
temp += "%" + BitConverter.ToString(new byte[] { b });
}
return temp;
}
#endregion
}