|
You last visited: Today at 18:50
Advertisement
DarkOrbit API Class by Requi and Fluttershy
Discussion on DarkOrbit API Class by Requi and Fluttershy within the DarkOrbit forum part of the Browsergames category.
08/05/2013, 15:02
|
#16
|
elite*gold: 200
Join Date: Apr 2012
Posts: 620
Received Thanks: 1,370
|
Excellent job guys! You two again show us how must to work in this forum and again helped with anything that possible to everyone else. Respect for your skills and efforts
|
|
|
08/06/2013, 06:40
|
#17
|
elite*gold: 3570
Join Date: Dec 2012
Posts: 13,044
Received Thanks: 8,252
|
Finally finished the C# Class.
Code:
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
}
You can use it on the same way, like in VB
|
|
|
08/06/2013, 18:31
|
#18
|
elite*gold: 0
Join Date: Feb 2011
Posts: 16
Received Thanks: 3
|
What is to be the "content"?
|
|
|
08/06/2013, 21:07
|
#19
|
elite*gold: 0
Join Date: May 2012
Posts: 868
Received Thanks: 947
|
Code:
if ((static_GetResponse_cookiecoll == null))
{
static_GetResponse_cookiecoll = new CookieCollection();
}
if ((static_GetResponse_cookiecontainer == null))
{
static_GetResponse_cookiecontainer = new CookieContainer();
}
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;
}
}
should be:
Code:
static readonly UTF8Encoding utf = new UTF8Encoding();
public static string EncodeUsername(string string0)
{
byte[] stringdata = utf.GetBytes(string0);
StringBuilder temp = new StringBuilder(stringdata.Length * 2 + 1);
foreach (var b in stringdata)
temp.Append("%" + BitConverter.ToString(new [] { b }));
return temp.ToString();
}
...
static_GetResponse_cookiecontainer = static_GetResponse_cookiecontainer ?? new CookieContainer();
That's just a little modification for cleaner syntax, you can learn these because you're new to C# my friend
|
|
|
08/07/2013, 01:51
|
#20
|
elite*gold: 3570
Join Date: Dec 2012
Posts: 13,044
Received Thanks: 8,252
|
Quote:
Originally Posted by sunnyline
What is to be the "content"?
|
content is the site content. You need to call the site first.
Example:
Code:
Dim content As String = GetResponse(Link to the site)
GetCredits(content)
MsgBox(sCredits)
|
|
|
08/07/2013, 02:47
|
#21
|
elite*gold: 50
Join Date: Sep 2012
Posts: 3,841
Received Thanks: 1,462
|
Quote:
Originally Posted by Requi
content is the site content. You need to call the site first.
Example:
Code:
Dim content As String = GetResponse(Link to the site)
GetCredits(content)
MsgBox(sCredits)
|
Source code of the website.
@chichi011
i think that requi dont coded the c# code. its from a converter but i dont know if this right
@requi:
tomorrow i will give you new funcs to implement in you code
Updates:
-read some more stuff from darkorbit page source
-fixx some bugs
-web navigate func
when my bot need it i will implement that later :
buy from shop
-bit on auction
-galaxy gate clicker (autoit but async mayby  )
|
|
|
08/07/2013, 03:23
|
#22
|
elite*gold: 3570
Join Date: Dec 2012
Posts: 13,044
Received Thanks: 8,252
|
I made it with converter, because I was too lazy xDD.
But I needed to fix much things.
|
|
|
08/10/2013, 05:45
|
#23
|
elite*gold: 3570
Join Date: Dec 2012
Posts: 13,044
Received Thanks: 8,252
|
I'll upload a new version asap, because of the new login.
|
|
|
08/10/2013, 09:42
|
#24
|
elite*gold: 237
Join Date: Sep 2010
Posts: 1,152
Received Thanks: 4,910
|
For now if anyone needs login code, I've got my code on GitHub.
-jD
|
|
|
08/10/2013, 09:43
|
#25
|
elite*gold: 3570
Join Date: Dec 2012
Posts: 13,044
Received Thanks: 8,252
|
Quote:
Originally Posted by »jD«
For now if anyone needs login code, I've got my code on GitHub.
-jD
|
I've already seen that
I'll implement it asap.
Thanks for it.
|
|
|
08/10/2013, 09:47
|
#26
|
elite*gold: 50
Join Date: Sep 2012
Posts: 3,841
Received Thanks: 1,462
|
AutoShit wont let me do that 
New login is **** for that (me too) ^^
First i want to get it with trapdoor.dll because i need that myself
@Requi
Nice Thanks / posts balance ^^
|
|
|
08/10/2013, 09:52
|
#27
|
elite*gold: 237
Join Date: Sep 2010
Posts: 1,152
Received Thanks: 4,910
|
WTF is Trapdoor.dll?
-jD
|
|
|
08/10/2013, 09:57
|
#28
|
elite*gold: 3570
Join Date: Dec 2012
Posts: 13,044
Received Thanks: 8,252
|
Quote:
Originally Posted by »FlutterShy™
@Requi
Nice Thanks / posts balance ^^
|
Thanks
Quote:
Originally Posted by »jD«
WTF is Trapdoor.dll?
-jD
|
Trapdoor.dll is a project by a user here.
PS: You thanked it and you don't know it
|
|
|
08/10/2013, 09:57
|
#29
|
elite*gold: 0
Join Date: Jul 2012
Posts: 66
Received Thanks: 32
|
Quote:
Originally Posted by »jD«
WTF is Trapdoor.dll?
-jD
|
Sorry, I couldn't resist. :3
|
|
|
All times are GMT +1. The time now is 18:52.
|
|