(1.2.0_WoW12.0.1) New OAuth Fix + Async Logic
This commit is contained in:
@@ -79,8 +79,9 @@ namespace MxWDB.JSON
|
|||||||
aucds.Tables.Add(auctb);
|
aucds.Tables.Add(auctb);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var jf = File.ReadAllText(string.Format("json/ah.dump.json"));
|
string rawContent = File.ReadAllText("json/ah.dump.json");
|
||||||
var root = JObject.Parse(jf).SelectToken("auctions").ToString();
|
string cleanJson = JsonConvert.DeserializeObject<string>(rawContent);
|
||||||
|
var root = JObject.Parse(cleanJson).SelectToken("auctions").ToString();
|
||||||
var RootAuctions = JsonConvert.DeserializeObject<List<RootAuctions>>(root);
|
var RootAuctions = JsonConvert.DeserializeObject<List<RootAuctions>>(root);
|
||||||
|
|
||||||
DataTable auctb = new DataTable("auclist");
|
DataTable auctb = new DataTable("auclist");
|
||||||
@@ -165,8 +166,9 @@ namespace MxWDB.JSON
|
|||||||
aucds.Tables.Add(auctb);
|
aucds.Tables.Add(auctb);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var jf = File.ReadAllText(string.Format("json/ah.com.dump.json"));
|
string rawContent = File.ReadAllText("json/ah.com.dump.json");
|
||||||
var root = JObject.Parse(jf).SelectToken("auctions").ToString();
|
string cleanJson = JsonConvert.DeserializeObject<string>(rawContent);
|
||||||
|
var root = JObject.Parse(cleanJson).SelectToken("auctions").ToString();
|
||||||
var RootAuctions = JsonConvert.DeserializeObject<List<RootAuctions>>(root);
|
var RootAuctions = JsonConvert.DeserializeObject<List<RootAuctions>>(root);
|
||||||
|
|
||||||
DataTable auctbcom = new DataTable("auclistcom");
|
DataTable auctbcom = new DataTable("auclistcom");
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
using System;
|
using Newtonsoft.Json;
|
||||||
|
using RestSharp;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using static MxWDB.JSON.AHDump;
|
||||||
|
using static MxWDB.JSON.Token;
|
||||||
|
|
||||||
namespace MxWDB.JSON
|
namespace MxWDB.JSON
|
||||||
{
|
{
|
||||||
@@ -20,24 +27,85 @@ namespace MxWDB.JSON
|
|||||||
public List<JSON> files { get; set; }
|
public List<JSON> files { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetDump(string key, string secret, string token)
|
public class Auction
|
||||||
{
|
{
|
||||||
using (WebClient wc = new WebClient())
|
public int id { get; set; }
|
||||||
{
|
public Item item { get; set; }
|
||||||
ServicePointManager.ServerCertificateValidationCallback += (p1, p2, p3, p4) => true;
|
public Int64 buyout { get; set; }
|
||||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
public int quantity { get; set; }
|
||||||
Utilities.Web.DownloadFileNoAsync($"https://us.api.blizzard.com/data/wow/connected-realm/{Settings.GetRID()}/auctions?namespace=dynamic-us&locale=en_US&access_token={token}", "json/ah.dump.json");
|
public string time_left { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetDumpCom(string key, string secret, string token)
|
public class Commodities
|
||||||
{
|
{
|
||||||
using (WebClient wc = new WebClient())
|
public string href { get; set; }
|
||||||
{
|
}
|
||||||
ServicePointManager.ServerCertificateValidationCallback += (p1, p2, p3, p4) => true;
|
|
||||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
public class ConnectedRealm
|
||||||
Utilities.Web.DownloadFileNoAsync($"https://us.api.blizzard.com/data/wow/auctions/commodities?namespace=dynamic-us&access_token={token}", "json/ah.com.dump.json");
|
{
|
||||||
}
|
public string href { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Item
|
||||||
|
{
|
||||||
|
public int id { get; set; }
|
||||||
|
public int context { get; set; }
|
||||||
|
public List<int> bonus_lists { get; set; }
|
||||||
|
public List<Modifier> modifiers { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Links
|
||||||
|
{
|
||||||
|
public Self self { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Modifier
|
||||||
|
{
|
||||||
|
public int type { get; set; }
|
||||||
|
public int value { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AuctionsRoot
|
||||||
|
{
|
||||||
|
public Links _links { get; set; }
|
||||||
|
public ConnectedRealm connected_realm { get; set; }
|
||||||
|
public List<Auction> auctions { get; set; }
|
||||||
|
public Commodities commodities { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Self
|
||||||
|
{
|
||||||
|
public string href { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly HttpClient client = new HttpClient();
|
||||||
|
|
||||||
|
public static async Task GetDump(string key, string secret, string token)
|
||||||
|
{
|
||||||
|
var ahRequest = new HttpRequestMessage(HttpMethod.Get, $"https://us.api.blizzard.com/data/wow/connected-realm/{Settings.GetRID()}/auctions?namespace=dynamic-us&locale=en_US");
|
||||||
|
|
||||||
|
// This is the critical part: Adding the token to the header
|
||||||
|
ahRequest.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||||
|
|
||||||
|
var ahResponse = await client.SendAsync(ahRequest);
|
||||||
|
var content = await ahResponse.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
|
string output = JsonConvert.SerializeObject(content, Formatting.Indented);
|
||||||
|
File.WriteAllText("json/ah.dump.json", output);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task GetDumpCom(string key, string secret, string token)
|
||||||
|
{
|
||||||
|
var ahRequest = new HttpRequestMessage(HttpMethod.Get, $"https://us.api.blizzard.com/data/wow/auctions/commodities?namespace=dynamic-us");
|
||||||
|
|
||||||
|
// This is the critical part: Adding the token to the header
|
||||||
|
ahRequest.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||||
|
|
||||||
|
var ahResponse = await client.SendAsync(ahRequest);
|
||||||
|
var content = await ahResponse.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
|
string output = JsonConvert.SerializeObject(content, Formatting.Indented);
|
||||||
|
File.WriteAllText("json/ah.com.dump.json", output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
97
MxWDB/JSON/AHUrl_Com.cs
Normal file
97
MxWDB/JSON/AHUrl_Com.cs
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using RestSharp;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using static MxWDB.JSON.AHDump;
|
||||||
|
using static MxWDB.JSON.Token;
|
||||||
|
|
||||||
|
namespace MxWDB.JSON
|
||||||
|
{
|
||||||
|
class AHUrl_Com
|
||||||
|
{
|
||||||
|
public class JSON
|
||||||
|
{
|
||||||
|
public string url { get; set; }
|
||||||
|
public long lastModified { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RootObject
|
||||||
|
{
|
||||||
|
public List<JSON> files { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Auction
|
||||||
|
{
|
||||||
|
public int id { get; set; }
|
||||||
|
public Item item { get; set; }
|
||||||
|
public int quantity { get; set; }
|
||||||
|
public Int64 unit_price { get; set; }
|
||||||
|
public string time_left { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Commodities
|
||||||
|
{
|
||||||
|
public string href { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ConnectedRealm
|
||||||
|
{
|
||||||
|
public string href { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Item
|
||||||
|
{
|
||||||
|
public int id { get; set; }
|
||||||
|
public int context { get; set; }
|
||||||
|
public List<int> bonus_lists { get; set; }
|
||||||
|
public List<Modifier> modifiers { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Links
|
||||||
|
{
|
||||||
|
public Self self { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Modifier
|
||||||
|
{
|
||||||
|
public int type { get; set; }
|
||||||
|
public int value { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AuctionsComRoot
|
||||||
|
{
|
||||||
|
public Links _links { get; set; }
|
||||||
|
public ConnectedRealm connected_realm { get; set; }
|
||||||
|
public List<Auction> auctions { get; set; }
|
||||||
|
public Commodities commodities { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Self
|
||||||
|
{
|
||||||
|
public string href { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly HttpClient client = new HttpClient();
|
||||||
|
|
||||||
|
public static async Task GetDumpCom(string key, string secret, string token)
|
||||||
|
{
|
||||||
|
var ahRequest = new HttpRequestMessage(HttpMethod.Get, $"https://us.api.blizzard.com/data/wow/auctions/commodities?namespace=dynamic-us");
|
||||||
|
|
||||||
|
// This is the critical part: Adding the token to the header
|
||||||
|
ahRequest.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||||
|
|
||||||
|
var ahResponse = await client.SendAsync(ahRequest);
|
||||||
|
var content = await ahResponse.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
|
string output = JsonConvert.SerializeObject(content, Formatting.Indented);
|
||||||
|
File.WriteAllText("json/ah.com.dump.json", output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using MySqlConnector;
|
using MySql.Data.MySqlClient;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using MySqlConnector;
|
using MySql.Data.MySqlClient;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -54,6 +54,7 @@ namespace MxWDB.JSON
|
|||||||
{
|
{
|
||||||
catid = 1;
|
catid = 1;
|
||||||
itemid = Convert.ToInt32(d);
|
itemid = Convert.ToInt32(d);
|
||||||
|
//Utilities.DB.GenHistoryTable(itemid, GetItemValue(itemid));
|
||||||
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
|
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,6 +65,7 @@ namespace MxWDB.JSON
|
|||||||
{
|
{
|
||||||
catid = 2;
|
catid = 2;
|
||||||
itemid = Convert.ToInt32(d);
|
itemid = Convert.ToInt32(d);
|
||||||
|
//Utilities.DB.GenHistoryTable(itemid, GetItemValue(itemid));
|
||||||
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
|
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,6 +76,7 @@ namespace MxWDB.JSON
|
|||||||
{
|
{
|
||||||
catid = 3;
|
catid = 3;
|
||||||
itemid = Convert.ToInt32(d);
|
itemid = Convert.ToInt32(d);
|
||||||
|
//Utilities.DB.GenHistoryTable(itemid, GetItemValue(itemid));
|
||||||
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
|
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,6 +87,7 @@ namespace MxWDB.JSON
|
|||||||
{
|
{
|
||||||
catid = 4;
|
catid = 4;
|
||||||
itemid = Convert.ToInt32(d);
|
itemid = Convert.ToInt32(d);
|
||||||
|
//Utilities.DB.GenHistoryTable(itemid, GetItemValue(itemid));
|
||||||
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
|
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,6 +98,7 @@ namespace MxWDB.JSON
|
|||||||
{
|
{
|
||||||
catid = 5;
|
catid = 5;
|
||||||
itemid = Convert.ToInt32(d);
|
itemid = Convert.ToInt32(d);
|
||||||
|
//Utilities.DB.GenHistoryTable(itemid, GetItemValue(itemid));
|
||||||
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
|
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,6 +109,7 @@ namespace MxWDB.JSON
|
|||||||
{
|
{
|
||||||
catid = 6;
|
catid = 6;
|
||||||
itemid = Convert.ToInt32(d);
|
itemid = Convert.ToInt32(d);
|
||||||
|
//Utilities.DB.GenHistoryTable(itemid, GetItemValue(itemid));
|
||||||
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
|
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,6 +120,7 @@ namespace MxWDB.JSON
|
|||||||
{
|
{
|
||||||
catid = 7;
|
catid = 7;
|
||||||
itemid = Convert.ToInt32(d);
|
itemid = Convert.ToInt32(d);
|
||||||
|
//Utilities.DB.GenHistoryTable(itemid, GetItemValue(itemid));
|
||||||
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
|
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,6 +131,7 @@ namespace MxWDB.JSON
|
|||||||
{
|
{
|
||||||
catid = 8;
|
catid = 8;
|
||||||
itemid = Convert.ToInt32(d);
|
itemid = Convert.ToInt32(d);
|
||||||
|
//Utilities.DB.GenHistoryTable(itemid, GetItemValue(itemid));
|
||||||
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
|
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ namespace MxWDB.JSON
|
|||||||
public string dbport { get; set; }
|
public string dbport { get; set; }
|
||||||
public string dbuser { get; set; }
|
public string dbuser { get; set; }
|
||||||
public string dbpass { get; set; }
|
public string dbpass { get; set; }
|
||||||
|
public int dump_day { get; set; }
|
||||||
|
public int dump_hour { get; set; }
|
||||||
|
public bool completed { get; set; }
|
||||||
public bool debug { get; set; }
|
public bool debug { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,8 +64,65 @@ namespace MxWDB.JSON
|
|||||||
///</summary>
|
///</summary>
|
||||||
public static int GetRID() => JsonConvert.DeserializeObject<SETTINGS>(File.ReadAllText("json/settings.json")).realmid;
|
public static int GetRID() => JsonConvert.DeserializeObject<SETTINGS>(File.ReadAllText("json/settings.json")).realmid;
|
||||||
///<summary>
|
///<summary>
|
||||||
|
///Load the Dump Day from the Settings Json.
|
||||||
|
///</summary>
|
||||||
|
public static int GetDDay() => JsonConvert.DeserializeObject<SETTINGS>(File.ReadAllText("json/settings.json")).dump_day;
|
||||||
|
///<summary>
|
||||||
|
///Load the Dump Hour from the Settings Json.
|
||||||
|
///</summary>
|
||||||
|
public static int GetDHour() => JsonConvert.DeserializeObject<SETTINGS>(File.ReadAllText("json/settings.json")).dump_hour;
|
||||||
|
///<summary>
|
||||||
|
///Used for the backend Hypervisor.
|
||||||
|
///</summary>
|
||||||
|
public static bool GetCompleted() => JsonConvert.DeserializeObject<SETTINGS>(File.ReadAllText("json/settings.json")).completed;
|
||||||
|
///<summary>
|
||||||
///Used for developper. So far, it prevent the software from downloading a new dump, saving a lot of time for testing.
|
///Used for developper. So far, it prevent the software from downloading a new dump, saving a lot of time for testing.
|
||||||
///</summary>
|
///</summary>
|
||||||
public static bool GetDebug() => JsonConvert.DeserializeObject<SETTINGS>(File.ReadAllText("json/settings.json")).debug;
|
public static bool GetDebug() => JsonConvert.DeserializeObject<SETTINGS>(File.ReadAllText("json/settings.json")).debug;
|
||||||
|
|
||||||
|
public static void SetSuccess(bool comp)
|
||||||
|
{
|
||||||
|
SETTINGS settings = JsonConvert.DeserializeObject<SETTINGS>(File.ReadAllText("json/settings.json"));
|
||||||
|
File.WriteAllText("json/settings.json", JsonConvert.SerializeObject((object)new SETTINGS()
|
||||||
|
{
|
||||||
|
apikey = settings.apikey,
|
||||||
|
apisecret = settings.apisecret,
|
||||||
|
dbname = settings.dbname,
|
||||||
|
region = settings.region,
|
||||||
|
realmid = settings.realmid,
|
||||||
|
dbhost = settings.dbhost,
|
||||||
|
dbport = settings.dbport,
|
||||||
|
dbuser = settings.dbuser,
|
||||||
|
dbpass = settings.dbpass,
|
||||||
|
dump_day = settings.dump_day,
|
||||||
|
dump_hour = settings.dump_hour,
|
||||||
|
completed = comp,
|
||||||
|
debug = settings.debug
|
||||||
|
}, (Formatting)1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetDumpPeriod()
|
||||||
|
{
|
||||||
|
DateTime now = DateTime.Now;
|
||||||
|
int day = now.Day;
|
||||||
|
int hour = now.Hour;
|
||||||
|
SETTINGS settings = JsonConvert.DeserializeObject<SETTINGS>(File.ReadAllText("json/settings.json"));
|
||||||
|
File.WriteAllText("json/settings.json", JsonConvert.SerializeObject((object)new SETTINGS()
|
||||||
|
{
|
||||||
|
apikey = settings.apikey,
|
||||||
|
apisecret = settings.apisecret,
|
||||||
|
dbname = settings.dbname,
|
||||||
|
region = settings.region,
|
||||||
|
realmid = settings.realmid,
|
||||||
|
dbhost = settings.dbhost,
|
||||||
|
dbport = settings.dbport,
|
||||||
|
dbuser = settings.dbuser,
|
||||||
|
dbpass = settings.dbpass,
|
||||||
|
dump_day = day,
|
||||||
|
dump_hour = hour,
|
||||||
|
completed = settings.completed,
|
||||||
|
debug = settings.debug
|
||||||
|
}, (Formatting)1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System.Net;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using RestSharp;
|
||||||
|
|
||||||
namespace MxWDB.JSON
|
namespace MxWDB.JSON
|
||||||
{
|
{
|
||||||
@@ -16,18 +17,18 @@ namespace MxWDB.JSON
|
|||||||
public Self self { get; set; }
|
public Self self { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Root
|
public class TokenRoot
|
||||||
{
|
{
|
||||||
public Links _links { get; set; }
|
public Links _links { get; set; }
|
||||||
public long last_updated_timestamp { get; set; }
|
public long last_updated_timestamp { get; set; }
|
||||||
public int price { get; set; }
|
public Int64 price { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Self
|
public class Self
|
||||||
{
|
{
|
||||||
public string href { get; set; }
|
public string href { get; set; }
|
||||||
}
|
}
|
||||||
public static void GetToken(string token)
|
/*public static void GetToken(string token)
|
||||||
{
|
{
|
||||||
using (WebClient wc = new WebClient())
|
using (WebClient wc = new WebClient())
|
||||||
{
|
{
|
||||||
@@ -35,8 +36,33 @@ namespace MxWDB.JSON
|
|||||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
||||||
Utilities.Web.DownloadFileNoAsync($"https://us.api.blizzard.com/data/wow/token/index?namespace=dynamic-us&locale=en_US&access_token={token}", "json/token.json");
|
Utilities.Web.DownloadFileNoAsync($"https://us.api.blizzard.com/data/wow/token/index?namespace=dynamic-us&locale=en_US&access_token={token}", "json/token.json");
|
||||||
}
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get an access token from BNET using a registered application Client ID and Secret ID.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">Your registered application Client ID.</param>
|
||||||
|
/// <param name="secret">Your registered application Secret ID.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static void GetToken(string token)
|
||||||
|
{
|
||||||
|
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
|
||||||
|
|
||||||
|
RestClient client = new RestClient($"https://{JSON.Settings.GetRegion()}.api.blizzard.com/data/wow/token/index?namespace=dynamic-us&locale=en_US");
|
||||||
|
var request = new RestRequest
|
||||||
|
{
|
||||||
|
Method = RestSharp.Method.Get
|
||||||
|
};
|
||||||
|
request.AddHeader("Authorization", $"Bearer {token}");
|
||||||
|
request.AddHeader("Content-type", "application/x-www-form-urlencoded");
|
||||||
|
RestResponse response = client.Execute(request);
|
||||||
|
|
||||||
|
var tokenResponse = JsonConvert.DeserializeObject<TokenRoot>(response.Content);
|
||||||
|
|
||||||
|
string output = JsonConvert.SerializeObject(tokenResponse, Formatting.Indented);
|
||||||
|
File.WriteAllText("json/token.json", output);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int GetTokenValue() => JsonConvert.DeserializeObject<Root>(File.ReadAllText("json/settings.json")).price;
|
public static Int64 GetTokenValue() => JsonConvert.DeserializeObject<TokenRoot>(File.ReadAllText("json/settings.json")).price;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,14 +54,14 @@
|
|||||||
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=7.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=7.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Microsoft.Extensions.Logging.Abstractions.7.0.1\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
|
<HintPath>..\packages\Microsoft.Extensions.Logging.Abstractions.7.0.1\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="MySqlConnector, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d33d3e53aa5f8c92, processorArchitecture=MSIL">
|
<Reference Include="MySql.Data, Version=9.0.0.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\MySqlConnector.2.3.7\lib\net48\MySqlConnector.dll</HintPath>
|
<HintPath>..\packages\MySql.Data.9.0.0\lib\net48\MySql.Data.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="RestSharp, Version=111.4.1.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
|
<Reference Include="RestSharp, Version=112.0.0.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\RestSharp.111.4.1\lib\net48\RestSharp.dll</HintPath>
|
<HintPath>..\packages\RestSharp.112.0.0\lib\net48\RestSharp.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
@@ -115,6 +115,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="JSON\AHDump.cs" />
|
<Compile Include="JSON\AHDump.cs" />
|
||||||
|
<Compile Include="JSON\AHUrl_Com.cs" />
|
||||||
<Compile Include="JSON\AHUrl.cs" />
|
<Compile Include="JSON\AHUrl.cs" />
|
||||||
<Compile Include="JSON\GenSpecial.cs" />
|
<Compile Include="JSON\GenSpecial.cs" />
|
||||||
<Compile Include="JSON\IndexGen.cs" />
|
<Compile Include="JSON\IndexGen.cs" />
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace MxWDB
|
|||||||
{
|
{
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
public static string version = "1.0.0_WoW11.0";
|
public static string version = "1.2.0_WoW12.0.1";
|
||||||
|
|
||||||
public static int line = 0;
|
public static int line = 0;
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ namespace MxWDB
|
|||||||
public static string state = "init";
|
public static string state = "init";
|
||||||
|
|
||||||
public static string oauth_token = "";
|
public static string oauth_token = "";
|
||||||
static void Main(string[] args)
|
static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
//// Main Server Loop
|
//// Main Server Loop
|
||||||
while (serverloop)
|
while (serverloop)
|
||||||
@@ -38,6 +38,7 @@ namespace MxWDB
|
|||||||
{
|
{
|
||||||
case "init":
|
case "init":
|
||||||
MSG.Splash();
|
MSG.Splash();
|
||||||
|
Settings.SetSuccess(false);
|
||||||
if (IO.FirstRun())
|
if (IO.FirstRun())
|
||||||
{
|
{
|
||||||
IO.CreateDirectory("json");
|
IO.CreateDirectory("json");
|
||||||
@@ -57,7 +58,7 @@ namespace MxWDB
|
|||||||
MSG.CMW($"[{state}] DBName: {JSON.Settings.GetDBName()}", true, 2);
|
MSG.CMW($"[{state}] DBName: {JSON.Settings.GetDBName()}", true, 2);
|
||||||
MSG.CMW($"[{state}] DBUser: {JSON.Settings.GetDBUser()}", true, 2);
|
MSG.CMW($"[{state}] DBUser: {JSON.Settings.GetDBUser()}", true, 2);
|
||||||
MSG.CMW($"[{state}] Region: {JSON.Settings.GetRegion()}", true, 2);
|
MSG.CMW($"[{state}] Region: {JSON.Settings.GetRegion()}", true, 2);
|
||||||
MSG.CMW($"[{state}] RealmID: {JSON.Settings.GetRID()}", true, 2);
|
MSG.CMW($"[{state}] RealmID: {JSON.Settings.GetRID()}", true, 2);
|
||||||
state = "oauth";
|
state = "oauth";
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
@@ -70,34 +71,47 @@ namespace MxWDB
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "oauth":
|
case "oauth":
|
||||||
|
DateTime now = DateTime.Now;
|
||||||
MSG.CMW($"[{state}] Getting an access token from BNET...", true, 1);
|
MSG.CMW($"[{state}] Getting an access token from BNET...", true, 1);
|
||||||
oauth_token = OAuth.GetAccessToken(JSON.Settings.GetAPIKey(), JSON.Settings.GetAPISecret());
|
oauth_token = await OAuth.GetAccessToken(Settings.GetAPIKey(), Settings.GetAPISecret());
|
||||||
MSG.CMW($"[{state}] Access Token: {oauth_token}.", true, 2);
|
MSG.CMW($"[{state}] Access Token: {oauth_token}.", true, 2);
|
||||||
if (args.Contains("--token")) { state = "token"; } else { state = "dump"; }
|
if (now.Day == Settings.GetDDay() && now.Hour == Settings.GetDHour())
|
||||||
|
{
|
||||||
|
MSG.CMW($"[{state}] No need to get a new dump. Skipping.", true, 1);
|
||||||
|
state = "checkdb";
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
state = "dump";
|
||||||
|
}
|
||||||
|
if (args.Contains("--token")) { state = "token"; }
|
||||||
break;
|
break;
|
||||||
/// ARGS - WoW Token
|
/// ARGS - WoW Token
|
||||||
case "token":
|
case "token":
|
||||||
MSG.CMW($"[{state}] Getting the latest Token info from BNET...", true, 1);
|
MSG.CMW($"[{state}] Getting the latest Token info from BNET...", true, 1);
|
||||||
Token.GetToken(oauth_token);
|
Token.GetToken(oauth_token);
|
||||||
int v = JsonConvert.DeserializeObject<Token.Root>(File.ReadAllText("json/token.json")).price;
|
Int64 v = JsonConvert.DeserializeObject<Token.TokenRoot>(File.ReadAllText("json/token.json")).price;
|
||||||
DB.UpdateTokenValue(v);
|
DB.UpdateTokenValue(v);
|
||||||
int copper = v % 100;
|
Int64 copper = v % 100;
|
||||||
v = (v - copper) / 100;
|
v = (v - copper) / 100;
|
||||||
int silver = v % 100;
|
Int64 silver = v % 100;
|
||||||
int gold = (v - silver) / 100;
|
Int64 gold = (v - silver) / 100;
|
||||||
MSG.CMW($"[{state}] WoW Token from region {Settings.GetRegion()} is worth {gold}g.", true, 1);
|
MSG.CMW($"[{state}] WoW Token from region {Settings.GetRegion()} is worth {gold}g.", true, 1);
|
||||||
|
Settings.SetSuccess(true);
|
||||||
serverloop =false;
|
serverloop =false;
|
||||||
break;
|
break;
|
||||||
case "dump":
|
case "dump":
|
||||||
if (!JSON.Settings.GetDebug())
|
if (!JSON.Settings.GetDebug())
|
||||||
{
|
{
|
||||||
|
if (File.Exists("json/ah.dump.json")) { File.Delete("json/ah.dump.json"); }
|
||||||
|
if (File.Exists("json/ah.com.dump.json")) { File.Delete("json/ah.com.dump.json"); }
|
||||||
MSG.CMW($"[{state}] Downloading the latest AH dump from BNet...", true, 1);
|
MSG.CMW($"[{state}] Downloading the latest AH dump from BNet...", true, 1);
|
||||||
JSON.AHUrl.GetDump(JSON.Settings.GetAPIKey(), JSON.Settings.GetAPISecret(), oauth_token);
|
await AHUrl.GetDump(JSON.Settings.GetAPIKey(), JSON.Settings.GetAPISecret(), oauth_token);
|
||||||
MSG.CMW($"[{state}] Downloading the latest AH Commodities dump from BNet...", true, 1);
|
MSG.CMW($"[{state}] Downloading the latest AH Commodities dump from BNet...", true, 1);
|
||||||
JSON.AHUrl.GetDumpCom(JSON.Settings.GetAPIKey(), JSON.Settings.GetAPISecret(), oauth_token);
|
await AHUrl_Com.GetDumpCom(JSON.Settings.GetAPIKey(), JSON.Settings.GetAPISecret(), oauth_token);
|
||||||
if (IO.FileIsDownloaded("json/ah.dump.json") && IO.FileIsDownloaded("json/ah.com.dump.json"))
|
if (IO.FileIsDownloaded("json/ah.dump.json") && IO.FileIsDownloaded("json/ah.com.dump.json"))
|
||||||
{
|
{
|
||||||
MSG.CMW($"[{state}] Both Dump appears to be correctly downloaded.", true, 2);
|
MSG.CMW($"[{state}] Both Dump appears to be correctly downloaded.", true, 2);
|
||||||
|
Settings.SetDumpPeriod();
|
||||||
state = "checkdb";
|
state = "checkdb";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -119,7 +133,7 @@ namespace MxWDB
|
|||||||
MSG.CMW($"[{state}] We can connect to the DB.", true, 2);
|
MSG.CMW($"[{state}] We can connect to the DB.", true, 2);
|
||||||
MSG.CMW($"[{state}] Cleaning the DB...", true, 1);
|
MSG.CMW($"[{state}] Cleaning the DB...", true, 1);
|
||||||
DB.CleanDB();
|
DB.CleanDB();
|
||||||
state = "genintable";
|
state = "gendb";
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
MSG.CMW($"[{state}] We can't connect to the DB.", true, 3);
|
MSG.CMW($"[{state}] We can't connect to the DB.", true, 3);
|
||||||
@@ -129,17 +143,14 @@ namespace MxWDB
|
|||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "genintable":
|
case "gendb":
|
||||||
MSG.CMW($"[{state}] Generating the internal table from Auctions Data...", true, 1);
|
MSG.CMW($"[{state}] Generating the internal table from Auctions Data...", true, 1);
|
||||||
JSON.AHDump.GenTable();
|
JSON.AHDump.GenTable();
|
||||||
MSG.CMW($"[{state}] Generating the internal table from Commodities Data...", true, 1);
|
|
||||||
JSON.AHDump.GenTableCom();
|
|
||||||
state = "gendbtable";
|
|
||||||
break;
|
|
||||||
case "gendbtable":
|
|
||||||
MSG.CMW($"[{state}] Generating the DB tables from Auctions Data...", true, 1);
|
MSG.CMW($"[{state}] Generating the DB tables from Auctions Data...", true, 1);
|
||||||
DB.GenItemsTable();
|
DB.GenItemsTable();
|
||||||
DB.GenListingTable();
|
DB.GenListingTable();
|
||||||
|
MSG.CMW($"[{state}] Generating the internal table from Commodities Data...", true, 1);
|
||||||
|
JSON.AHDump.GenTableCom();
|
||||||
MSG.CMW($"[{state}] Generating the DB tables from Commodities Data...", true, 1);
|
MSG.CMW($"[{state}] Generating the DB tables from Commodities Data...", true, 1);
|
||||||
DB.GenItemsTableCom();
|
DB.GenItemsTableCom();
|
||||||
DB.GenListingTableCom();
|
DB.GenListingTableCom();
|
||||||
@@ -149,8 +160,9 @@ namespace MxWDB
|
|||||||
MSG.CMW($"[{state}] Generating the Index Table...", true, 1);
|
MSG.CMW($"[{state}] Generating the Index Table...", true, 1);
|
||||||
JSON.IndexGen.GenIndex("json/index.json");
|
JSON.IndexGen.GenIndex("json/index.json");
|
||||||
MSG.CMW($"[{state}] Generating the Special Table...", true, 1);
|
MSG.CMW($"[{state}] Generating the Special Table...", true, 1);
|
||||||
JSON.SpecialGen.GenSpecial("json/special.json");
|
JSON.SpecialGen.GenSpecial("json/special.json");
|
||||||
serverloop=false;
|
Settings.SetSuccess(true);
|
||||||
|
serverloop =false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using MxWDB.JSON;
|
using MxWDB.JSON;
|
||||||
using MySqlConnector;
|
using MySql.Data.MySqlClient;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -244,7 +244,6 @@ namespace MxWDB.Utilities
|
|||||||
{
|
{
|
||||||
mcc.Open();
|
mcc.Open();
|
||||||
var temp = mcc.State.ToString();
|
var temp = mcc.State.ToString();
|
||||||
MSG.CMW(temp, true,4);
|
|
||||||
if (mcc.State == ConnectionState.Open && temp == "Open")
|
if (mcc.State == ConnectionState.Open && temp == "Open")
|
||||||
{
|
{
|
||||||
mcc.Close();
|
mcc.Close();
|
||||||
@@ -310,8 +309,9 @@ namespace MxWDB.Utilities
|
|||||||
myCmd.CommandType = CommandType.Text;
|
myCmd.CommandType = CommandType.Text;
|
||||||
myCmd.ExecuteNonQuery();
|
myCmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
mcc.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GenItemsTableCom()
|
public static void GenItemsTableCom()
|
||||||
{
|
{
|
||||||
@@ -327,7 +327,7 @@ namespace MxWDB.Utilities
|
|||||||
Int64 minimum = 0;
|
Int64 minimum = 0;
|
||||||
int ie = JSON.AHDump.aucdscom.Tables[0].Select(string.Format("iid = '{0}'", il)).Length;
|
int ie = JSON.AHDump.aucdscom.Tables[0].Select(string.Format("iid = '{0}'", il)).Length;
|
||||||
if (ie >= 1)
|
if (ie >= 1)
|
||||||
{
|
{
|
||||||
if (JSON.AHDump.aucdscom.Tables["auclistcom"].Compute("AVG(uv)", string.Format("iid = '{0}'", il)) != DBNull.Value)
|
if (JSON.AHDump.aucdscom.Tables["auclistcom"].Compute("AVG(uv)", string.Format("iid = '{0}'", il)) != DBNull.Value)
|
||||||
{
|
{
|
||||||
median = Convert.ToInt64(JSON.AHDump.aucdscom.Tables["auclistcom"].Compute("AVG(uv)", string.Format("iid = '{0}'", il)));
|
median = Convert.ToInt64(JSON.AHDump.aucdscom.Tables["auclistcom"].Compute("AVG(uv)", string.Format("iid = '{0}'", il)));
|
||||||
@@ -352,6 +352,32 @@ namespace MxWDB.Utilities
|
|||||||
myCmd.CommandType = CommandType.Text;
|
myCmd.CommandType = CommandType.Text;
|
||||||
myCmd.ExecuteNonQuery();
|
myCmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
mcc.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void GenHistoryTable(int itemid, Int64 value)
|
||||||
|
{
|
||||||
|
string hcolumn = "";
|
||||||
|
DateTime now = DateTime.Now;
|
||||||
|
if (now.Hour < 10)
|
||||||
|
{
|
||||||
|
hcolumn = $"h0{now.Hour}";
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
hcolumn = $"h{now.Hour}";
|
||||||
|
}
|
||||||
|
|
||||||
|
using (MySqlConnection mcc = ItemDB())
|
||||||
|
{
|
||||||
|
string cmd = $"INSERT INTO ah_history (itemid,day,month,year,{hcolumn}) VALUES ('{itemid}','{now.Day}','{now.Month}','{now.Year}','{value}')";
|
||||||
|
mcc.Open();
|
||||||
|
using (MySqlCommand myCmd = new MySqlCommand(cmd, mcc))
|
||||||
|
{
|
||||||
|
myCmd.CommandType = CommandType.Text;
|
||||||
|
myCmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
mcc.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,6 +409,8 @@ namespace MxWDB.Utilities
|
|||||||
myCmd.CommandType = CommandType.Text;
|
myCmd.CommandType = CommandType.Text;
|
||||||
myCmd.ExecuteNonQuery();
|
myCmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
mcc.Close();
|
||||||
|
JSON.AHDump.aucds.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -414,6 +442,8 @@ namespace MxWDB.Utilities
|
|||||||
myCmd.CommandType = CommandType.Text;
|
myCmd.CommandType = CommandType.Text;
|
||||||
myCmd.ExecuteNonQuery();
|
myCmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
mcc.Close();
|
||||||
|
JSON.AHDump.aucdscom.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -492,7 +522,7 @@ namespace MxWDB.Utilities
|
|||||||
mc6.Close();
|
mc6.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UpdateTokenValue(int v)
|
public static void UpdateTokenValue(Int64 v)
|
||||||
{
|
{
|
||||||
string stm2 = string.Format($"DELETE FROM mxw_token WHERE region='{Settings.GetRegion()}'");
|
string stm2 = string.Format($"DELETE FROM mxw_token WHERE region='{Settings.GetRegion()}'");
|
||||||
MySqlConnection mc2 = ItemDB();
|
MySqlConnection mc2 = ItemDB();
|
||||||
@@ -510,6 +540,7 @@ namespace MxWDB.Utilities
|
|||||||
myCmd.CommandType = CommandType.Text;
|
myCmd.CommandType = CommandType.Text;
|
||||||
myCmd.ExecuteNonQuery();
|
myCmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
mcc.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Google.Protobuf.WellKnownTypes;
|
using Google.Protobuf.WellKnownTypes;
|
||||||
|
using MySqlX.XDevAPI;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Org.BouncyCastle.Asn1.Cmp;
|
using Org.BouncyCastle.Asn1.Cmp;
|
||||||
using Org.BouncyCastle.Asn1.Crmf;
|
using Org.BouncyCastle.Asn1.Crmf;
|
||||||
@@ -7,19 +8,30 @@ using RestSharp;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace MxWDB.Utilities
|
namespace MxWDB.Utilities
|
||||||
{
|
{
|
||||||
class OAuth
|
class OAuth
|
||||||
{
|
{
|
||||||
public class OAuthRoot
|
public class BlizzardToken
|
||||||
{
|
{
|
||||||
public string access_token { get; set; }
|
[JsonPropertyName("access_token")]
|
||||||
|
public string AccessToken { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[JsonPropertyName("token_type")]
|
||||||
|
public string TokenType { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[JsonPropertyName("expires_in")]
|
||||||
|
public int ExpiresIn { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -28,25 +40,25 @@ namespace MxWDB.Utilities
|
|||||||
/// <param name="key">Your registered application Client ID.</param>
|
/// <param name="key">Your registered application Client ID.</param>
|
||||||
/// <param name="secret">Your registered application Secret ID.</param>
|
/// <param name="secret">Your registered application Secret ID.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string GetAccessToken(string key, string secret)
|
public static async Task<string> GetAccessToken(string key, string secret)
|
||||||
{
|
{
|
||||||
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
|
|
||||||
|
|
||||||
RestClient client = new RestClient($"https://{JSON.Settings.GetRegion()}.battle.net/oauth/token");
|
var client = new HttpClient();
|
||||||
var request = new RestRequest
|
var authHeader = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes($"{key}:{secret}"));
|
||||||
{
|
|
||||||
Method = RestSharp.Method.Post
|
|
||||||
};
|
|
||||||
var by = Encoding.UTF8.GetBytes($"{key}:{secret}");
|
|
||||||
var b64 = Convert.ToBase64String(by);
|
|
||||||
request.AddParameter("grant_type", "client_credentials");
|
|
||||||
request.AddHeader("Authorization", $"Basic {b64}");
|
|
||||||
request.AddHeader("Content-type", "application/x-www-form-urlencoded");
|
|
||||||
RestResponse response = client.Execute(request);
|
|
||||||
|
|
||||||
var tokenResponse = JsonConvert.DeserializeObject<OAuthRoot>(response.Content);
|
var request = new HttpRequestMessage(HttpMethod.Post, "https://oauth.battle.net/token");
|
||||||
|
request.Headers.Authorization = new AuthenticationHeaderValue("Basic", authHeader);
|
||||||
|
request.Content = new FormUrlEncodedContent(new[] {new KeyValuePair<string, string>("grant_type", "client_credentials")});
|
||||||
|
|
||||||
return tokenResponse.access_token;
|
var response = await client.SendAsync(request);
|
||||||
|
|
||||||
|
// Read the body as a string
|
||||||
|
string jsonContent = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
|
var doc = JsonDocument.Parse(jsonContent);
|
||||||
|
var tokenData = System.Text.Json.JsonSerializer.Deserialize<BlizzardToken>(doc);
|
||||||
|
return doc.RootElement.GetProperty("access_token").GetString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,9 @@
|
|||||||
<package id="K4os.Hash.xxHash" version="1.0.8" targetFramework="net481" />
|
<package id="K4os.Hash.xxHash" version="1.0.8" targetFramework="net481" />
|
||||||
<package id="Microsoft.Bcl.AsyncInterfaces" version="8.0.0" targetFramework="net481" />
|
<package id="Microsoft.Bcl.AsyncInterfaces" version="8.0.0" targetFramework="net481" />
|
||||||
<package id="Microsoft.Extensions.Logging.Abstractions" version="7.0.1" targetFramework="net481" />
|
<package id="Microsoft.Extensions.Logging.Abstractions" version="7.0.1" targetFramework="net481" />
|
||||||
<package id="MySqlConnector" version="2.3.7" targetFramework="net481" />
|
<package id="MySql.Data" version="9.0.0" targetFramework="net481" />
|
||||||
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net481" />
|
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net481" />
|
||||||
<package id="RestSharp" version="111.4.1" targetFramework="net481" />
|
<package id="RestSharp" version="112.0.0" targetFramework="net481" />
|
||||||
<package id="System.Buffers" version="4.5.1" targetFramework="net481" />
|
<package id="System.Buffers" version="4.5.1" targetFramework="net481" />
|
||||||
<package id="System.Configuration.ConfigurationManager" version="8.0.0" targetFramework="net481" />
|
<package id="System.Configuration.ConfigurationManager" version="8.0.0" targetFramework="net481" />
|
||||||
<package id="System.Diagnostics.DiagnosticSource" version="8.0.1" targetFramework="net481" />
|
<package id="System.Diagnostics.DiagnosticSource" version="8.0.1" targetFramework="net481" />
|
||||||
|
|||||||
Reference in New Issue
Block a user