Skip to content

Commit

Permalink
Added basic standing mode
Browse files Browse the repository at this point in the history
  • Loading branch information
BitBaboonSteve committed Dec 17, 2017
1 parent bfd8a53 commit 5a9565b
Show file tree
Hide file tree
Showing 5 changed files with 421 additions and 96 deletions.
187 changes: 186 additions & 1 deletion EVEData/Character.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
Expand All @@ -15,6 +16,10 @@ public class Character

public string ID { get; set; }

public string CorporationID { get; set; }

public string AllianceID { get; set; }

public string LocalChatFile { get; set; }

public string Location { get; set; }
Expand All @@ -32,11 +37,24 @@ public class Character

public override string ToString()
{
return Name;
string toStr = Name;
if(ESILinked)
{
toStr += " (ESI)";
}
return toStr;
}

[XmlIgnoreAttribute]
public Dictionary<string, float> Standings;



public Character()
{
Standings = new Dictionary<string, float>();
CorporationID = string.Empty;
AllianceID = string.Empty;
}

public void Update()
Expand All @@ -45,6 +63,7 @@ public void Update()
if (ts.Minutes < 0)
{
RefreshAccessToken();
UpdateInfoFromESI();
}

UpdatePositionFromESI();
Expand Down Expand Up @@ -157,6 +176,170 @@ private void UpdatePositionFromESI()
catch { }
}

public void UpdateInfoFromESI()
{
if (string.IsNullOrEmpty(ID) || !ESILinked)
{
return;
}

try
{
if (string.IsNullOrEmpty(CorporationID))
{
string url = @"https://esi.tech.ccp.is/latest/characters/" + ID + "/?datasource=tranquility";

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = WebRequestMethods.Http.Get;
request.Timeout = 20000;
request.Proxy = null;

HttpWebResponse esiResult = (HttpWebResponse)request.GetResponse();

if (esiResult.StatusCode != HttpStatusCode.OK)
{
return;
}

Stream responseStream = esiResult.GetResponseStream();
using (StreamReader sr = new StreamReader(responseStream))
{
// Need to return this response
string strContent = sr.ReadToEnd();

JsonTextReader jsr = new JsonTextReader(new StringReader(strContent));
while (jsr.Read())
{
if (jsr.TokenType == JsonToken.StartObject)
{
JObject obj = JObject.Load(jsr);
string corpID = obj["corporation_id"].ToString();
CorporationID = corpID;
}
}
}
}

if (string.IsNullOrEmpty(AllianceID) && !string.IsNullOrEmpty(CorporationID))
{
string url = @"https://esi.tech.ccp.is/latest/corporations/" + CorporationID + "/?datasource=tranquility";


HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = WebRequestMethods.Http.Get;
request.Timeout = 20000;
request.Proxy = null;

HttpWebResponse esiResult = (HttpWebResponse)request.GetResponse();

if (esiResult.StatusCode != HttpStatusCode.OK)
{
return;
}

Stream responseStream = esiResult.GetResponseStream();
using (StreamReader sr = new StreamReader(responseStream))
{
// Need to return this response
string strContent = sr.ReadToEnd();

JsonTextReader jsr = new JsonTextReader(new StringReader(strContent));
while (jsr.Read())
{
if (jsr.TokenType == JsonToken.StartObject)
{
JObject obj = JObject.Load(jsr);
string allianceID = obj["alliance_id"].ToString();
AllianceID = allianceID;
}
}
}
}



if (!string.IsNullOrEmpty(AllianceID))
{
int page = 0;
int maxPageCount = 1;
do
{
page++;
//

//string url = @"https://esi.tech.ccp.is/latest/alliances/" + AllianceID + "/contacts/?datasource=tranquility&page=" + page;

UriBuilder urlBuilder = new UriBuilder(@"https://esi.tech.ccp.is/latest/alliances/" + AllianceID + "/contacts/");
var esiQuery = HttpUtility.ParseQueryString(urlBuilder.Query);
esiQuery["page"] = page.ToString();
esiQuery["datasource"] = "tranquility";
esiQuery["token"] = ESIAccessToken;


urlBuilder.Query = esiQuery.ToString();

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlBuilder.ToString());
request.Method = WebRequestMethods.Http.Get;
request.ContentType = "application/json";
request.Timeout = 20000;
request.Proxy = null;

try
{
HttpWebResponse esiResult = (HttpWebResponse)request.GetResponse();
maxPageCount = int.Parse(esiResult.Headers["X-Pages"].ToString());


if (esiResult.StatusCode != HttpStatusCode.OK)
{
return;
}

Stream responseStream = esiResult.GetResponseStream();
using (StreamReader sr = new StreamReader(responseStream))
{
// Need to return this response
string strContent = sr.ReadToEnd();

JsonTextReader jsr = new JsonTextReader(new StringReader(strContent));
while (jsr.Read())
{
if (jsr.TokenType == JsonToken.StartObject)
{
JObject obj = JObject.Load(jsr);
string contactID = obj["contact_id"].ToString();
string contactType = obj["contact_type"].ToString();
float standing = float.Parse(obj["standing"].ToString());

Standings[contactID] = standing;
}
}
}
}
catch (Exception ex)
{

}



} while (page < maxPageCount);




}

if (!string.IsNullOrEmpty(AllianceID) && !string.IsNullOrEmpty(CorporationID))
{

}
}
catch (Exception ex)
{

}
}

public void AddDestination(string SystemID, bool Clear)
{
Expand Down Expand Up @@ -217,6 +400,8 @@ public Character(string name, string lcf, string location)
ESIAuthCode = string.Empty;
ESIAccessToken = string.Empty;
ESIRefreshToken = string.Empty;

Standings = new Dictionary<string, float>();
}
}
}
4 changes: 2 additions & 2 deletions EVEData/EveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ public string GetESILogonURL()
esiQuery["response_type"] = "code";
esiQuery["client_id"] = EveAppConfig.CLIENT_ID;
esiQuery["redirect_uri"] = EveAppConfig.CALLBACK_URL;
esiQuery["scope"] = "publicData esi-location.read_location.v1 esi-ui.write_waypoint.v1 esi-characters.read_standings.v1 esi-location.read_online.v1";
esiQuery["scope"] = "publicData esi-location.read_location.v1 esi-ui.write_waypoint.v1 esi-characters.read_standings.v1 esi-location.read_online.v1 esi-alliances.read_contacts.v1";


esiQuery["state"] = Process.GetCurrentProcess().Id.ToString();
Expand Down Expand Up @@ -1343,7 +1343,7 @@ public void StartUpdateCharacterThread()
c.Update();
}
}
Thread.Sleep(5000);
Thread.Sleep(8000);
}
}).Start();
}
Expand Down
2 changes: 1 addition & 1 deletion MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<xcad:LayoutRoot>
<xcad:LayoutRoot.RootPanel>
<xcad:LayoutPanel>
<xcad:LayoutDocumentPane>
<xcad:LayoutDocumentPane ShowHeader="False">
<xcad:LayoutDocument x:Name="MapDocument" Title="Map" CanClose="False" CanFloat="False" ContentId="MapContentID">
<Grid x:Name="MainCanvasGrid" ClipToBounds="True">
<zoombox1:ZoomControl x:Name="MainZoomControl" MinZoom="0.2" MaxZoom="10" Margin="10,10,-10,-10" >
Expand Down
Loading

0 comments on commit 5a9565b

Please sign in to comment.