genvalue + user tabs

This commit is contained in:
mikx 2024-01-16 19:09:34 -05:00
parent 986e9d6900
commit ca7c26bb4f
10 changed files with 723 additions and 34 deletions

View File

@ -67,6 +67,28 @@ namespace PoEcoDB.DB
}
}
public static bool CheckItemExistsDB(string iid)
{
using (var con = MxPoEDB())
{
string cmdText = $"SELECT * FROM poeco_items WHERE uiid = '{iid}'";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
var row = cmd.ExecuteReader();
return row.HasRows;
}
}
public static void DeleteSpecificItem(int userid, string uuid)
{
MySqlConnection con = MxPoEDB();
string cmdText = $"DELETE FROM poeco_items WHERE uid = '{userid}' AND uiid = '{uuid}'";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
public static void DeleteItems(int userid)
{
MySqlConnection con = MxPoEDB();

View File

@ -38,20 +38,10 @@ namespace PoEcoDB.DB
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
var row = cmd.ExecuteReader();
if (row.HasRows) { row.Read(); return row.GetInt32(0); } else { return 0; }
if (row.HasRows) { row.Read(); return Convert.ToInt32(row["uid"]); } else { return 0; }
}
}
public static string GetUserSessionID(string user)
{
MySqlConnection con = MxPoEDB();
string cmdText = $"SELECT * FROM poeco_user WHERE account = '{user}'";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
var row = cmd.ExecuteReader();
if (row.HasRows) { row.Read(); return row.GetString(3); } else { return "null"; }
}
public static int GetUserTabIndex(string user)
{
MySqlConnection con = MxPoEDB();
@ -59,7 +49,77 @@ namespace PoEcoDB.DB
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
var row = cmd.ExecuteReader();
if (row.HasRows) { row.Read(); return row.GetInt32(2); } else { return 0; }
if (row.HasRows) { row.Read(); return Convert.ToInt32(row["tabindex"]); } else { return 0; }
}
public static int GetUserCurrencyIndex(string user, string column)
{
MySqlConnection con = MxPoEDB();
string cmdText = $"SELECT * FROM poeco_user WHERE account = '{user}'";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
var row = cmd.ExecuteReader();
if (row.HasRows) { row.Read(); return Convert.ToInt32(row[column]); } else { return 0; }
}
public static int GetUserItemCount(string user)
{
MySqlConnection con = MxPoEDB();
string cmdText = $"SELECT * FROM poeco_user WHERE account = '{user}'";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
var row = cmd.ExecuteReader();
if (row.HasRows) { row.Read(); return Convert.ToInt32(row["itemcount"]); } else { return 0; }
}
public static string GetUserStashHash(string user)
{
MySqlConnection con = MxPoEDB();
string cmdText = $"SELECT * FROM poeco_user WHERE account = '{user}'";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
var row = cmd.ExecuteReader();
if (row.HasRows) { row.Read(); return row["stashb64"].ToString(); } else { return ""; }
}
public static string GetUserToken(string user)
{
MySqlConnection con = MxPoEDB();
string cmdText = $"SELECT * FROM poeco_user WHERE account = '{user}'";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
var row = cmd.ExecuteReader();
if (row.HasRows) { row.Read(); return row["token"].ToString(); } else { return ""; }
}
public static void SetUserItemCount(string user, int count)
{
MySqlConnection con = MxPoEDB();
string cmdText = $"UPDATE poeco_user SET itemcount = '{count}' WHERE account = '{user}'";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
public static void SetUserStashHash(string user, string b64)
{
MySqlConnection con = MxPoEDB();
string cmdText = $"UPDATE poeco_user SET stashb64 = '{b64}' WHERE account = '{user}'";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
public static void SetUserTabValue(string user, double value)
{
MySqlConnection con = MxPoEDB();
string cmdText = $"UPDATE poeco_user SET tabvalue = '{value}' WHERE account = '{user}'";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}

View File

@ -0,0 +1,80 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PoEcoDB.JSON.Classes
{
internal class Divination
{
public class Sparkline
{
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public List<double?> data { get; set; }
public double? totalChange { get; set; }
}
public class LowConfidenceSparkline
{
public List<double?> data { get; set; }
public double? totalChange { get; set; }
}
public class ExplicitModifier
{
public string text { get; set; }
public bool? optional { get; set; }
}
public class LineDivination
{
public int? id { get; set; }
public string name { get; set; }
public string icon { get; set; }
public int? mapTier { get; set; }
public int? levelRequired { get; set; }
public string baseType { get; set; }
public int? stackSize { get; set; }
public object variant { get; set; }
public object prophecyText { get; set; }
public object artFilename { get; set; }
public int? links { get; set; }
public int? itemClass { get; set; }
public Sparkline sparkline { get; set; }
public LowConfidenceSparkline lowConfidenceSparkline { get; set; }
public List<object> implicitModifiers { get; set; }
public List<ExplicitModifier> explicitModifiers { get; set; }
public string flavourText { get; set; }
public bool? corrupted { get; set; }
public int? gemLevel { get; set; }
public int? gemQuality { get; set; }
public string itemType { get; set; }
public double chaosValue { get; set; }
public double exaltedValue { get; set; }
public double divineValue { get; set; }
public int count { get; set; }
public string detailsId { get; set; }
public object tradeInfo { get; set; }
public object mapRegion { get; set; }
public int? listingCount { get; set; }
}
public class Translations
{
}
public class Language
{
public string name { get; set; }
public Translations translations { get; set; }
}
public class RootDivination
{
public List<LineDivination> lines { get; set; }
public Language language { get; set; }
}
}
}

58
PoEcoDB/JSON/Currency.cs Normal file
View File

@ -0,0 +1,58 @@
using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using PoEcoDB.DB;
using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static PoEcoDB.JSON.Stash;
namespace PoEcoDB.JSON
{
internal class Currency
{
public static MySqlConnection MxPoEDB()
{
MySqlConnection conn;
string myConnectionString;
myConnectionString = $"server={JSON.Settings.GetdbHost()};port={JSON.Settings.GetdbPort()};uid={JSON.Settings.GetdbUser()};pwd={JSON.Settings.GetdbPass()};database={JSON.Settings.GetdbName()};";
conn = new MySqlConnection();
conn.ConnectionString = myConnectionString;
return conn;
}
public static void GenCurrencyTab(string user, int tab, string columnname, string table)
{
int uid = DB.User.GetUserID(user);
double chaosValue = 0;
string curName = "";
StashRoot stash = JsonConvert.DeserializeObject<StashRoot>(File.ReadAllText($@"data/stash/{user}.tab.{tab.ToString()}.json"));
foreach (Item i in stash.items)
{
curName = i.typeLine;
chaosValue = chaosValue + (GetCurrencyValueByName(MySqlHelper.EscapeString(curName),table) * i.stackSize);
}
Message.CMW(chaosValue.ToString(),true,2);
MySqlConnection con = MxPoEDB();
string cmdText = $"UPDATE poeco_user SET {columnname} = '{chaosValue}' WHERE account = '{user}'";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
public static int GetCurrencyValueByName(string name, string table)
{
using (var con = MxPoEDB())
{
string cmdText = $"SELECT * FROM {table} WHERE name = '{name}'";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
var row = cmd.ExecuteReader();
if (row.HasRows) { row.Read(); return Convert.ToInt32(row["vchaos"]); } else { return 0; }
}
}
}
}

View File

@ -1,6 +1,12 @@
using Newtonsoft.Json;
using MySql.Data.MySqlClient;
using MySqlX.XDevAPI.Relational;
using Newtonsoft.Json;
using PoEcoDB.DB;
using PoEcoDB.Web;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Diagnostics.Metrics;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
@ -11,22 +17,109 @@ namespace PoEcoDB.JSON
{
internal class Stash
{
public static void GenItemTable(string user)
public static void GenStashHash(string user)
{
List<string> itemsID = new List<string>();
StringBuilder stashHash = new StringBuilder();
StashRoot stash = JsonConvert.DeserializeObject<StashRoot>(File.ReadAllText($@"data/stash/{user}.json"));
foreach (var i in stash.items)
{
itemsID.Add(i.id);
}
stashHash.Append(string.Join(":", itemsID));
string sb64 = Convert.ToBase64String(Encoding.ASCII.GetBytes(stashHash.ToString()));
DB.User.SetUserStashHash(user, sb64);
}
public static string GetStashHash(string user)
{
List<string> itemsID = new List<string>();
StringBuilder stashHash = new StringBuilder();
StashRoot stash = JsonConvert.DeserializeObject<StashRoot>(File.ReadAllText($@"data/stash/{user}.json"));
foreach (var i in stash.items)
{
itemsID.Add(i.id);
}
stashHash.Append(string.Join(":", itemsID));
string sb64 = Convert.ToBase64String(Encoding.ASCII.GetBytes(stashHash.ToString()));
return sb64;
}
public static int GetUserItemCount(string user)
{
StashRoot stash = JsonConvert.DeserializeObject<StashRoot>(File.ReadAllText($@"data/stash/{user}.json"));
return stash.items.Count;
}
public static void UpdateUserTabRGB(string user, int tabindex)
{
StashRoot stash = JsonConvert.DeserializeObject<StashRoot>(File.ReadAllText($@"data/stash/{user}.json"));
MySqlConnection con = DB.Stash.MxPoEDB();
string cmdText = $"UPDATE poeco_user SET tabrgb = '{stash.tabs[tabindex].colour.r}:{stash.tabs[tabindex].colour.g}:{stash.tabs[tabindex].colour.b}' WHERE account = '{user}'";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
public static void UpdateUserTabName(string user, int tabindex)
{
StashRoot stash = JsonConvert.DeserializeObject<StashRoot>(File.ReadAllText($@"data/stash/{user}.json"));
MySqlConnection con = DB.Stash.MxPoEDB();
string cmdText = $"UPDATE poeco_user SET tabname = '{stash.tabs[tabindex].n}' WHERE account = '{user}'";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
public static void CleanDB(string user, int userid)
{
MySqlConnection con = DB.Stash.MxPoEDB();
string cmdText = $"SELECT * FROM poeco_items WHERE uid = '{userid}'";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
MySqlDataReader mdata = cmd.ExecuteReader();
while (mdata.Read())
{
if (!CheckItemExistsStash(user, mdata.GetString(6)))
{
DB.Stash.DeleteSpecificItem(userid, mdata.GetString(6));
}
}
}
public static bool CheckItemExistsStash(string user, string uuid)
{
bool exists = false;
List<string> items = new List<string>();
StashRoot stash = JsonConvert.DeserializeObject<StashRoot>(File.ReadAllText($@"data/stash/{user}.json"));
foreach (var s in stash.items)
{
items.Add(s.id);
}
if (items.Contains(uuid))
{
exists = true;
}
return exists;
}
public static void GenItemTable(string user)
{
List<string> stringItemTxt = new List<string>();
List<string> stringItemMod = new List<string>();
StashRoot stash = JsonConvert.DeserializeObject<StashRoot>(File.ReadAllText($@"data\stash\{user}.json"));
StashRoot stash = JsonConvert.DeserializeObject<StashRoot>(File.ReadAllText($@"data/stash/{user}.json"));
int curitem = 1;
DB.Stash.DeleteItems(DB.User.GetUserID(user));
double chaosValue = 0;
//DB.Stash.DeleteItems(DB.User.GetUserID(user));
var tmpfiles = Directory.GetFiles("tmp");
StringBuilder sCommand = new StringBuilder("INSERT INTO poeco_items(uid, tabindex, tabname, tabrgb, cid, bid, uiid, imod, var, img, txt, b64, ctype, min, max) VALUES ");
List<string> Rows = new List<string>();
int itemcount = stash.items.Count();
foreach ( var file in tmpfiles ) { File.Delete(file); }
foreach (Item obj in stash.items)
{
if (obj.typeLine != "" && obj.frameType == 2 && obj.identified)
{
if (!DB.Stash.CheckItemExistsDB(obj.id))
{
itemcount--;
}
if (obj.typeLine != "" && obj.frameType == 2 && obj.identified && !DB.Stash.CheckItemExistsDB(obj.id))
{
Message.drawProgress(curitem, stash.items.Count());
//Message.drawProgress(curitem, itemcount);
int icid = DB.Stash.GetClassIDByBase(obj.typeLine);
string itemclass = DB.Stash.GetClassByID(icid);
stringItemTxt.Add($"Item Class: {char.ToUpper(itemclass[0]) + itemclass.Substring(1)}");
@ -156,12 +249,18 @@ namespace PoEcoDB.JSON
stringItemTxt.Clear();
stringItemMod.Clear();
curitem++;
chaosValue = chaosValue + Web.PoEPrices.GetMax(obj.id);
Message.CMW(chaosValue.ToString(),true,1);
}
}
DB.User.SetUserTabValue(user, chaosValue);
sCommand.Append(string.Join(",", Rows));
//Message.CMW(sCommand.ToString(),true,3);
sCommand.Append(";");
DB.Stash.AddItemTable(sCommand.ToString());
if (sCommand.ToString() != "INSERT INTO poeco_items(uid, tabindex, tabname, tabrgb, cid, bid, uiid, imod, var, img, txt, b64, ctype, min, max) VALUES ;")
{
DB.Stash.AddItemTable(sCommand.ToString());
}
}
public class Colour
@ -255,7 +354,7 @@ namespace PoEcoDB.JSON
public int h { get; set; }
public string icon { get; set; }
public string icon { get; set; }
public bool support { get; set; }
@ -300,6 +399,10 @@ namespace PoEcoDB.JSON
public string icon { get; set; }
public int stackSize { get; set; }
public int maxStackSize { get; set; }
public string league { get; set; }
public string id { get; set; }

View File

@ -233,6 +233,8 @@
<Compile Include="DB\ClassGen.cs" />
<Compile Include="DB\Stash.cs" />
<Compile Include="DB\User.cs" />
<Compile Include="JSON\Classes\Divination.cs" />
<Compile Include="JSON\Currency.cs" />
<Compile Include="JSON\Settings.cs" />
<Compile Include="JSON\Stash.cs" />
<Compile Include="Message.cs" />
@ -240,6 +242,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utilities\Encode.cs" />
<Compile Include="Web\PoBLua.cs" />
<Compile Include="Web\PoENinja.cs" />
<Compile Include="Web\PoEPrices.cs" />
<Compile Include="Web\Stash.cs" />
</ItemGroup>

View File

@ -1,10 +1,12 @@
using System;
using PoEcoDB.DB;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using static PoEcoDB.JSON.Stash;
namespace PoEcoDB
{
@ -23,10 +25,34 @@ namespace PoEcoDB
Message.CMW("Getting the latest PoB Community LUA...", true, 1);
Web.PoBLua.GetLatestLUA();
Message.CMW("Generating the latest classes and bases...", true, 1);
DB.ClassGen. ();
DB.ClassGen.GenClass();
Message.CMW("Generation done.", true, 2);
return;
}
if (args.Contains("--genvalue"))
{
Message.CMW("Getting the latest PoE.Ninja Currency Data...", true, 1);
if (File.Exists("data/ninja/currency.json")) { File.Delete("data/ninja/currency.json"); }
Web.PoENinja.SaveData("https://poe.ninja/api/data/" + "currencyoverview?league=" + JSON.Settings.GetLeague() + "&type=Currency&language=en", "data/ninja/currency.json");
Web.PoENinja.GenCurrency();
Message.CMW("Getting the latest PoE.Ninja Divination Data...", true, 1);
if (File.Exists("data/ninja/divination.json")) { File.Delete("data/ninja/divination.json"); }
Web.PoENinja.SaveData("https://poe.ninja/api/data/" + "itemoverview?league=" + JSON.Settings.GetLeague() + "&type=DivinationCard&language=en", "data/ninja/divination.json");
Web.PoENinja.GenDivination();
Message.CMW("Getting the latest PoE.Ninja Essence Data...", true, 1);
if (File.Exists("data/ninja/essence.json")) { File.Delete("data/ninja/essence.json"); }
Web.PoENinja.SaveData("https://poe.ninja/api/data/" + "itemoverview?league=" + JSON.Settings.GetLeague() + "&type=Essence&language=en", "data/ninja/essence.json");
Web.PoENinja.GenEssence();
Message.CMW("Getting the latest PoE.Ninja Scarab Data...", true, 1);
if (File.Exists("data/ninja/scarab.json")) { File.Delete("data/ninja/scarab.json"); }
Web.PoENinja.SaveData("https://poe.ninja/api/data/" + "itemoverview?league=" + JSON.Settings.GetLeague() + "&type=Scarab&language=en", "data/ninja/scarab.json");
Web.PoENinja.GenFragment();
Message.CMW("Getting the latest PoE.Ninja Fossil Data...", true, 1);
if (File.Exists("data/ninja/fossil.json")) { File.Delete("data/ninja/fossil.json"); }
Web.PoENinja.SaveData("https://poe.ninja/api/data/" + "itemoverview?league=" + JSON.Settings.GetLeague() + "&type=Fossil&language=en", "data/ninja/fossil.json");
Web.PoENinja.GenFossil();
return;
}
if (args.Contains("--user"))
{
if (args.Length > 1)
@ -38,7 +64,35 @@ namespace PoEcoDB
{
var uid = DB.User.GetUserID(user);
Message.CMW($"User \"{user}\" exists with ID \"{uid}\".", true, 2);
string sessionid = DB.User.GetUserSessionID(user);
if (args.Contains("--tabs"))
{
string token = DB.User.GetUserToken(user);
if (DB.User.GetUserCurrencyIndex(user, "curindex") != -1)
{
Web.Stash.DownloadStash(token, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={DB.User.GetUserCurrencyIndex(user, "curindex")}&accountName={user}", $"data/stash/{user}.tab.{DB.User.GetUserCurrencyIndex(user, "curindex").ToString()}.json");
JSON.Currency.GenCurrencyTab(user, DB.User.GetUserCurrencyIndex(user, "curindex"), "curvalue", "poeco_currency");
}
if (DB.User.GetUserCurrencyIndex(user, "divindex") != -1)
{
Web.Stash.DownloadStash(token, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={DB.User.GetUserCurrencyIndex(user, "divindex")}&accountName={user}", $"data/stash/{user}.tab.{DB.User.GetUserCurrencyIndex(user, "divindex").ToString()}.json");
JSON.Currency.GenCurrencyTab(user, DB.User.GetUserCurrencyIndex(user, "divindex"), "divvalue", "poeco_divination");
}
if (DB.User.GetUserCurrencyIndex(user, "essindex") != -1)
{
Web.Stash.DownloadStash(token, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={DB.User.GetUserCurrencyIndex(user, "essindex")}&accountName={user}", $"data/stash/{user}.tab.{DB.User.GetUserCurrencyIndex(user, "essindex").ToString()}.json");
JSON.Currency.GenCurrencyTab(user, DB.User.GetUserCurrencyIndex(user, "essindex"), "essvalue", "poeco_essence");
}
if (DB.User.GetUserCurrencyIndex(user, "fraindex") != -1)
{
Web.Stash.DownloadStash(token, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={DB.User.GetUserCurrencyIndex(user, "fraindex")}&accountName={user}", $"data/stash/{user}.tab.{DB.User.GetUserCurrencyIndex(user, "fraindex").ToString()}.json");
JSON.Currency.GenCurrencyTab(user, DB.User.GetUserCurrencyIndex(user, "fraindex"), "fravalue", "poeco_fragment");
}
if (DB.User.GetUserCurrencyIndex(user, "fosindex") != -1)
{
Web.Stash.DownloadStash(token, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={DB.User.GetUserCurrencyIndex(user, "fosindex")}&accountName={user}", $"data/stash/{user}.tab.{DB.User.GetUserCurrencyIndex(user, "fosindex").ToString()}.json");
JSON.Currency.GenCurrencyTab(user, DB.User.GetUserCurrencyIndex(user, "fosindex"), "fosvalue", "poeco_fossil");
}
}
int tabindex = 0;
if (args.Contains("--tabindex"))
{
@ -46,9 +100,34 @@ namespace PoEcoDB
} else
{
tabindex = DB.User.GetUserTabIndex(user);
}
Web.Stash.DownloadStash(sessionid, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={tabindex}&accountName={user}", $@"data\stash\{user}.json");
JSON.Stash.GenItemTable(user);
}
if (args.Contains("--token"))
{
Web.Stash.DownloadStash(args[3], $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={tabindex}&accountName={user}", $"data/stash/{user}.json");
}
int useritemcount = DB.User.GetUserItemCount(user);
int stashitemcount = JSON.Stash.GetUserItemCount(user);
JSON.Stash.UpdateUserTabRGB(user, tabindex);
JSON.Stash.UpdateUserTabName(user, tabindex);
if (stashitemcount == 0)
{
DB.User.SetUserItemCount(user, 0);
DB.Stash.DeleteItems(uid);
Message.CMW($"This tab is empty. Use a different index. (--tabindex <index>)", true, 3);
} else
{
if (JSON.Stash.GetUserItemCount(user) != useritemcount || DB.User.GetUserStashHash(user) != JSON.Stash.GetStashHash(user))
{
DB.User.SetUserItemCount(user, JSON.Stash.GetUserItemCount(user));
JSON.Stash.GenStashHash(user);
JSON.Stash.CleanDB(user, uid);
JSON.Stash.GenItemTable(user);
}
else
{
Message.CMW($"We detected no change in user stash \"{user}\".", true, 3);
}
}
} else
{
Message.CMW($"User \"{ user}\" doesn't exists.", true, 3);

283
PoEcoDB/Web/PoENinja.cs Normal file
View File

@ -0,0 +1,283 @@
using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using PoEcoDB.DB;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using static PoEcoDB.JSON.Classes.Divination;
namespace PoEcoDB.Web
{
internal class PoENinja
{
public static void SaveData(string url, string path)
{
WebClient webClient = new WebClient();
webClient.Encoding = Encoding.UTF8;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
try
{
Uri address = new Uri(url);
string contents = webClient.DownloadString(address);
System.IO.File.AppendAllText(path, contents, Encoding.UTF8);
}
catch (WebException ex)
{
Message.CMW(ex.Message, true, 3);
Message.CMW("URL: " + url, true, 3);
}
catch (Exception ex)
{
Message.CMW(ex.Message, true, 3);
}
}
public static void GenCurrency()
{
DeleteCurrencies();
int curID = 1;
double divineValue = 0;
string cmdText = "";
RootCurrency rcur = JsonConvert.DeserializeObject<RootCurrency>(File.ReadAllText("data/ninja/currency.json", Encoding.UTF8));
foreach (var c in rcur.lines)
{
if (c.currencyTypeName == "Divine Orb") { divineValue = Convert.ToInt32(Math.Round(c.chaosEquivalent)); }
}
foreach (LineCurrency line in JsonConvert.DeserializeObject<RootCurrency>(File.ReadAllText("data/ninja/currency.json", Encoding.UTF8)).lines)
{
string curType = line.currencyTypeName;
MySqlConnection con = DB.User.MxPoEDB();
cmdText = $"INSERT INTO poeco_currency(curid,name,vchaos,vdivine) VALUES ('{curID}','{MySql.Data.MySqlClient.MySqlHelper.EscapeString(line.currencyTypeName)}','{Math.Round(line.chaosEquivalent,2)}','{Math.Round(line.chaosEquivalent / divineValue, 2, MidpointRounding.AwayFromZero)}')";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
curID++;
}
}
public static void GenDivination()
{
DeleteDivinations();
int divID = 1;
string cmdText = "";
RootCurrency rcur = JsonConvert.DeserializeObject<RootCurrency>(File.ReadAllText("data/ninja/divination.json", Encoding.UTF8));
foreach (LineDivination line in JsonConvert.DeserializeObject<RootDivination>(File.ReadAllText("data/ninja/divination.json", Encoding.UTF8)).lines)
{
string curType = line.name;
MySqlConnection con = DB.User.MxPoEDB();
cmdText = $"INSERT INTO poeco_divination(divid,name,vchaos,vdivine) VALUES ('{divID}','{MySqlHelper.EscapeString(line.name)}','{Math.Round(line.chaosValue,2)}','{line.divineValue}')";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
divID++;
}
}
public static void GenEssence()
{
DeleteEssences();
int divID = 1;
string cmdText = "";
RootCurrency rcur = JsonConvert.DeserializeObject<RootCurrency>(File.ReadAllText("data/ninja/essence.json", Encoding.UTF8));
foreach (LineDivination line in JsonConvert.DeserializeObject<RootDivination>(File.ReadAllText("data/ninja/essence.json", Encoding.UTF8)).lines)
{
string curType = line.name;
MySqlConnection con = DB.User.MxPoEDB();
cmdText = $"INSERT INTO poeco_essence(essid,name,vchaos,vdivine) VALUES ('{divID}','{MySqlHelper.EscapeString(line.name)}','{Math.Round(line.chaosValue)}','{line.divineValue}')";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
divID++;
}
}
public static void GenFragment()
{
DeleteFragments();
int divID = 1;
string cmdText = "";
RootCurrency rcur = JsonConvert.DeserializeObject<RootCurrency>(File.ReadAllText("data/ninja/scarab.json", Encoding.UTF8));
foreach (LineDivination line in JsonConvert.DeserializeObject<RootDivination>(File.ReadAllText("data/ninja/scarab.json", Encoding.UTF8)).lines)
{
string curType = line.name;
MySqlConnection con = DB.User.MxPoEDB();
cmdText = $"INSERT INTO poeco_fragment(fraid,name,vchaos,vdivine) VALUES ('{divID}','{MySqlHelper.EscapeString(line.name)}','{Math.Round(line.chaosValue)}','{line.divineValue}')";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
divID++;
}
}
public static void GenFossil()
{
DeleteFossils();
int divID = 1;
string cmdText = "";
RootCurrency rcur = JsonConvert.DeserializeObject<RootCurrency>(File.ReadAllText("data/ninja/fossil.json", Encoding.UTF8));
foreach (LineDivination line in JsonConvert.DeserializeObject<RootDivination>(File.ReadAllText("data/ninja/fossil.json", Encoding.UTF8)).lines)
{
string curType = line.name;
MySqlConnection con = DB.User.MxPoEDB();
cmdText = $"INSERT INTO poeco_fossil(fosid,name,vchaos,vdivine) VALUES ('{divID}','{MySqlHelper.EscapeString(line.name)}','{Math.Round(line.chaosValue)}','{line.divineValue}')";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
divID++;
}
}
public static void DeleteCurrencies()
{
MySqlConnection con = DB.User.MxPoEDB();
string cmdText = $"DELETE FROM poeco_currency";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
public static void DeleteDivinations()
{
MySqlConnection con = DB.User.MxPoEDB();
string cmdText = $"DELETE FROM poeco_divination";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
public static void DeleteEssences()
{
MySqlConnection con = DB.User.MxPoEDB();
string cmdText = $"DELETE FROM poeco_essence";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
public static void DeleteFragments()
{
MySqlConnection con = DB.User.MxPoEDB();
string cmdText = $"DELETE FROM poeco_fragment";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
public static void DeleteFossils()
{
MySqlConnection con = DB.User.MxPoEDB();
string cmdText = $"DELETE FROM poeco_fossil";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
public class CurrencyDetail
{
public int id { get; set; }
public string icon { get; set; }
public string name { get; set; }
public string tradeId { get; set; }
}
public class LanguageCurrency
{
public string name { get; set; }
public TranslationsCurrency translations { get; set; }
}
public class LineCurrency
{
public string currencyTypeName { get; set; }
public Pay pay { get; set; }
public Receive receive { get; set; }
public double chaosEquivalent { get; set; }
public LowConfidencePaySparkLine lowConfidencePaySparkLine { get; set; }
public LowConfidenceReceiveSparkLine lowConfidenceReceiveSparkLine { get; set; }
public string detailsId { get; set; }
}
public class LowConfidencePaySparkLine
{
public List<object> data { get; set; }
public double totalChange { get; set; }
}
public class LowConfidenceReceiveSparkLine
{
public List<double?> data { get; set; }
public double totalChange { get; set; }
}
public class Pay
{
public int id { get; set; }
public int league_id { get; set; }
public int pay_currency_id { get; set; }
public int get_currency_id { get; set; }
public DateTime sample_time_utc { get; set; }
public int count { get; set; }
public double value { get; set; }
public int data_point_count { get; set; }
public bool includes_secondary { get; set; }
public int listing_count { get; set; }
}
public class PaySparkLine
{
public List<object> data { get; set; }
public double totalChange { get; set; }
}
public class Receive
{
public int id { get; set; }
public int league_id { get; set; }
public int pay_currency_id { get; set; }
public int get_currency_id { get; set; }
public DateTime sample_time_utc { get; set; }
public int count { get; set; }
public double value { get; set; }
public int data_point_count { get; set; }
public bool includes_secondary { get; set; }
public int listing_count { get; set; }
}
public class ReceiveSparkLine
{
public List<double> data { get; set; }
public double totalChange { get; set; }
}
public class RootCurrency
{
public List<LineCurrency> lines { get; set; }
public List<CurrencyDetail> currencyDetails { get; set; }
public LanguageCurrency language { get; set; }
}
public class TranslationsCurrency
{
}
}

View File

@ -14,15 +14,16 @@ namespace PoEcoDB.Web
public static WebClient web = new WebClient();
public static void GetItemJson(string iid, string b64)
{
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
web.DownloadFile($"https://www.poeprices.info/api?l={JSON.Settings.GetLeague()}&i={b64}", "tmp/" + iid + ".json");
}
public static Decimal GetMin(string iid)
public static double GetMin(string iid)
{
return JsonConvert.DeserializeObject<PoEPricesRoot>(File.ReadAllText("tmp/" + iid + ".json")).min;
}
public static Decimal GetMax(string iid)
public static double GetMax(string iid)
{
return JsonConvert.DeserializeObject<PoEPricesRoot>(File.ReadAllText("tmp/" + iid + ".json")).max;
}
@ -34,9 +35,9 @@ namespace PoEcoDB.Web
public class PoEPricesRoot
{
public Decimal min { get; set; }
public double min { get; set; }
public Decimal max { get; set; }
public double max { get; set; }
public string currency { get; set; }
}

View File

@ -9,12 +9,12 @@ namespace PoEcoDB.Web
{
internal class Stash
{
public static void DownloadStash(string sessionid, string url, string path)
public static void DownloadStash(string token, string url, string path)
{
WebClient webClient = new WebClient();
webClient.Encoding = Encoding.UTF8;
webClient.Headers.Add(HttpRequestHeader.Cookie, "POESESSID=" + sessionid);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
webClient.Headers.Add("Authorization", "Bearer " + token);
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
try
{
Uri address = new Uri(url);