From 9e08b88d81d3bc527763fd3471a438d36fbb2ba7 Mon Sep 17 00:00:00 2001 From: mikx Date: Sat, 28 Jun 2025 15:38:37 -0400 Subject: [PATCH] first commit --- .gitignore | 261 +++++++++++++++ PoEco.Net.sln | 25 ++ PoEco.Net/App.config | 18 + PoEco.Net/DB/ClassGen.cs | 133 ++++++++ PoEco.Net/DB/Item.cs | 87 +++++ PoEco.Net/DB/Stash.cs | 174 ++++++++++ PoEco.Net/DB/User.cs | 216 ++++++++++++ PoEco.Net/JSON/Classes/Divination.cs | 80 +++++ PoEco.Net/JSON/Currency.cs | 76 +++++ PoEco.Net/JSON/Settings.cs | 49 +++ PoEco.Net/JSON/Stash.cs | 476 +++++++++++++++++++++++++++ PoEco.Net/PoEco.Net.csproj | 125 +++++++ PoEco.Net/Program.cs | 421 +++++++++++++++++++++++ PoEco.Net/Properties/AssemblyInfo.cs | 36 ++ PoEco.Net/Utilities/Draw.cs | 112 +++++++ PoEco.Net/Utilities/Message.cs | 151 +++++++++ PoEco.Net/Web/PoBLua.cs | 30 ++ PoEco.Net/Web/PoENinja.cs | 283 ++++++++++++++++ PoEco.Net/Web/PoEPrices.cs | 65 ++++ PoEco.Net/Web/Stash.cs | 57 ++++ PoEco.Net/packages.config | 20 ++ README.md | 15 + 22 files changed, 2910 insertions(+) create mode 100644 .gitignore create mode 100644 PoEco.Net.sln create mode 100644 PoEco.Net/App.config create mode 100644 PoEco.Net/DB/ClassGen.cs create mode 100644 PoEco.Net/DB/Item.cs create mode 100644 PoEco.Net/DB/Stash.cs create mode 100644 PoEco.Net/DB/User.cs create mode 100644 PoEco.Net/JSON/Classes/Divination.cs create mode 100644 PoEco.Net/JSON/Currency.cs create mode 100644 PoEco.Net/JSON/Settings.cs create mode 100644 PoEco.Net/JSON/Stash.cs create mode 100644 PoEco.Net/PoEco.Net.csproj create mode 100644 PoEco.Net/Program.cs create mode 100644 PoEco.Net/Properties/AssemblyInfo.cs create mode 100644 PoEco.Net/Utilities/Draw.cs create mode 100644 PoEco.Net/Utilities/Message.cs create mode 100644 PoEco.Net/Web/PoBLua.cs create mode 100644 PoEco.Net/Web/PoENinja.cs create mode 100644 PoEco.Net/Web/PoEPrices.cs create mode 100644 PoEco.Net/Web/Stash.cs create mode 100644 PoEco.Net/packages.config create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c4efe2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,261 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +#*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc \ No newline at end of file diff --git a/PoEco.Net.sln b/PoEco.Net.sln new file mode 100644 index 0000000..c0a869c --- /dev/null +++ b/PoEco.Net.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.35122.118 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoEco.Net", "PoEco.Net\PoEco.Net.csproj", "{EB540AAD-F925-4C2E-913E-2891408DB5A3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EB540AAD-F925-4C2E-913E-2891408DB5A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EB540AAD-F925-4C2E-913E-2891408DB5A3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EB540AAD-F925-4C2E-913E-2891408DB5A3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EB540AAD-F925-4C2E-913E-2891408DB5A3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DF8181D7-9955-49D7-A201-362E5B3863BD} + EndGlobalSection +EndGlobal diff --git a/PoEco.Net/App.config b/PoEco.Net/App.config new file mode 100644 index 0000000..c878244 --- /dev/null +++ b/PoEco.Net/App.config @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PoEco.Net/DB/ClassGen.cs b/PoEco.Net/DB/ClassGen.cs new file mode 100644 index 0000000..670a09b --- /dev/null +++ b/PoEco.Net/DB/ClassGen.cs @@ -0,0 +1,133 @@ +using MySql.Data.MySqlClient; +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.IO; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace PoEco.Net.DB +{ + internal class ClassGen + { + 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 AddClass(int id, string name) + { + MySqlConnection con = MxPoEDB(); + string cmdText = $"INSERT INTO poeco_classes(cid, name) VALUES ('{id}','{name}')"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + cmd.ExecuteNonQuery(); + con.Close(); + } + + public static void AddBase(string querycmd) + { + MySqlConnection con = MxPoEDB(); + //string cmdText = $"INSERT INTO poeco_bases(bid, cid, name) VALUES ('{bid}', '{cid}', '{MySql.Data.MySqlClient.MySqlHelper.EscapeString(name)}')"; + string cmdText = querycmd; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + cmd.ExecuteNonQuery(); + con.Close(); + } + + public static void AddImplicit(string querycmd) + { + MySqlConnection con = MxPoEDB(); + //string cmdText = $"INSERT INTO poeco_implicit(bid, imp) VALUES ('{bid}', '{MySql.Data.MySqlClient.MySqlHelper.EscapeString(imp)}')"; + string cmdText = querycmd; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + cmd.ExecuteNonQuery(); + con.Close(); + } + + public static void DeleteClass() + { + MySqlConnection con = MxPoEDB(); + string cmdText = $"DELETE FROM poeco_classes"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + cmd.ExecuteNonQuery(); + con.Close(); + } + + public static void DeleteBase() + { + MySqlConnection con = MxPoEDB(); + string cmdText = $"DELETE FROM poeco_bases"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + cmd.ExecuteNonQuery(); + con.Close(); + } + + public static void DeleteImplicit() + { + MySqlConnection con = MxPoEDB(); + string cmdText = $"DELETE FROM poeco_implicit"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + cmd.ExecuteNonQuery(); + con.Close(); + } + + public static void GenClass() + { + DeleteClass(); + DeleteBase(); + DeleteImplicit(); + DirectoryInfo dir = new DirectoryInfo("data/lua"); + int cid = 1; + int bid = 1; + StringBuilder sCommandBase = new StringBuilder("INSERT INTO poeco_bases(bid, cid, name) VALUES "); + List RowsBase = new List(); + StringBuilder sCommandImp = new StringBuilder("INSERT INTO poeco_implicit(bid, imp) VALUES "); + List RowsImp = new List(); + foreach (var f in dir.GetFiles()) + { + var fnp = Path.GetFileNameWithoutExtension(f.FullName); + var fnpUp = char.ToUpper(f.Name[0]) + fnp.Substring(1); + AddClass(cid, fnpUp); + Utilities.Message.drawProgress(cid, dir.EnumerateFiles().Count()); + foreach (var l in File.ReadLines(@"data/lua/" + f.Name)) + { + int ll = l.Length; + + if (l.Contains("itemBases[")) + { + RowsBase.Add($"('{bid}','{cid}','{MySql.Data.MySqlClient.MySqlHelper.EscapeString(l.Split('"', '"')[1])}')"); + } + if (l.Contains("\timplicit = \"")) + { + RowsImp.Add($"('{bid}','{MySql.Data.MySqlClient.MySqlHelper.EscapeString(l.Split('"', '"')[1])}')"); + bid++; + } + } + cid++; + } + sCommandBase.Append(string.Join(",", RowsBase)); + sCommandBase.Append(";"); + AddBase(sCommandBase.ToString()); + sCommandImp.Append(string.Join(",", RowsImp)); + sCommandImp.Append(";"); + AddImplicit(sCommandImp.ToString()); + sCommandBase.Clear(); + sCommandImp.Clear(); + } + } +} diff --git a/PoEco.Net/DB/Item.cs b/PoEco.Net/DB/Item.cs new file mode 100644 index 0000000..00c8a2d --- /dev/null +++ b/PoEco.Net/DB/Item.cs @@ -0,0 +1,87 @@ +using MySql.Data.MySqlClient; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PoEco.Net.DB +{ + internal class Item + { + 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 bool CheckItemExistsByUIID(string uuid) + { + MySqlConnection con = MxPoEDB(); + string cmdText = $"SELECT * FROM poeco_items WHERE uiid = '{uuid}'"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + var row = cmd.ExecuteReader(); + if (row.HasRows) + { + con.Close(); + return true; + } else + { + con.Close(); + return false; + } + } + + public static int CountItemByUID(int uid, int tid) + { + MySqlConnection con = MxPoEDB(); + string cmdText = $"SELECT COUNT(*) FROM poeco_items WHERE uid = '{uid}' AND tid = '{tid}'"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + int count = Convert.ToInt32(cmd.ExecuteScalar()); + return count; + } + + public static List EnumerateItemByUID(int uid, int tid) + { + List i = new List(); + MySqlConnection con = MxPoEDB(); + string cmdText = $"SELECT * FROM poeco_items WHERE uid = '{uid}' AND tid = '{tid}'"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + MySqlDataReader DR = cmd.ExecuteReader(); + while (DR.Read()) + { + i.Add(DR.GetString(2)); + } + con.Close(); + return i; + } + + public static void DeleteItemByUIID(int uid, int tid, string uiid) + { + MySqlConnection con = MxPoEDB(); + string cmdText = $"DELETE FROM poeco_items WHERE uid = '{uid}' AND tid = '{tid}' AND uiid = '{uiid}'"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + cmd.ExecuteNonQuery(); + con.Close(); + } + + public static void DeleteAllItemsByUID(int uid) + { + MySqlConnection con = MxPoEDB(); + string cmdText = $"DELETE FROM poeco_items WHERE uid = '{uid}'"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + cmd.ExecuteNonQuery(); + con.Close(); + } + } +} diff --git a/PoEco.Net/DB/Stash.cs b/PoEco.Net/DB/Stash.cs new file mode 100644 index 0000000..f88edcf --- /dev/null +++ b/PoEco.Net/DB/Stash.cs @@ -0,0 +1,174 @@ +using MySql.Data.MySqlClient; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace PoEco.Net.DB +{ + internal class Stash + { + 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()};;max pool size=200"; + conn = new MySqlConnection(); + conn.ConnectionString = myConnectionString; + return conn; + } + + public static List EnumerateTabByUID(int uid, string type) + { + List t = new List(); + MySqlConnection con = MxPoEDB(); + string cmdText = $"SELECT * FROM poeco_tabs WHERE uid = '{uid}' AND type = '{type}'"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + MySqlDataReader DR = cmd.ExecuteReader(); + while (DR.Read()) + { + t.Add(DR.GetInt32(1)); + } + con.Close(); + return t; + } + + public static int GetClassIDByBase(string ibase) + { + MySqlConnection con = MxPoEDB(); + string cmdText = $"SELECT * FROM poeco_bases WHERE name LIKE '%{MySqlHelper.EscapeString(ibase)}%'"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + var row = cmd.ExecuteReader(); + if (row.HasRows) + { + row.Read(); + int user = row.GetInt32(1); + con.Close(); + return user; + } + else + { + con.Close(); + return 0; + } + } + + public static string GetClassByID(int iclass) + { + using (var con = MxPoEDB()) + { + string cmdText = $"SELECT * FROM poeco_classes WHERE cid = '{iclass}'"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + var row = cmd.ExecuteReader(); + if (row.HasRows) + { + row.Read(); + string user = row.GetString(1); + con.Close(); + return user; + } + else + { + con.Close(); + return null; + } + } + + } + + public static int GetBaseIDByName(string ibase) + { + using (var con = MxPoEDB()) + { + string cmdText = $"SELECT * FROM poeco_bases WHERE name LIKE '%{MySql.Data.MySqlClient.MySqlHelper.EscapeString(ibase)}%'"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + var row = cmd.ExecuteReader(); + if (row.HasRows) { row.Read(); return row.GetInt32(0); } else { return 0; } + } + } + + public static void AddItemTable(int uid, int ti, string uiid, int ilvl, int cid, int bid, string name, string mods, string img, string txt, string b64, double min, double max) + { + using (var con = MxPoEDB()) + { + string cmdText = $"INSERT INTO poeco_items(uid, tid, uiid, ilvl, cid, bid, name, mods, img, txt, b64, min, max) VALUES ('{uid}','{ti}','{uiid}','{ilvl}','{cid}','{bid}','{name}','{mods}','{img}','{txt}','{b64}','{min}','{max}')"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + cmd.ExecuteNonQuery(); + con.Close(); + } + } + + public static void AddProfitTable(int uid, string uiid, string type, string name, int stack, double value) + { + using (var con = MxPoEDB()) + { + string cmdText = $"INSERT INTO poeco_profits(uid, uiid, type, name, stack, cvalue) VALUES ('{uid}','{uiid}','{type}','{name}','{stack}','{value}')"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + cmd.ExecuteNonQuery(); + con.Close(); + } + } + + public static void SetTabNameByTID(int uid, int tid, string name) + { + MySqlConnection con = MxPoEDB(); + string cmdText = $"UPDATE poeco_tabs SET name = '{name}' WHERE uid = '{uid}' AND tid = '{tid}'"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + cmd.ExecuteNonQuery(); + con.Close(); + } + + public static void SetTabRGBByTID(int uid, int tid, string rgb) + { + MySqlConnection con = MxPoEDB(); + string cmdText = $"UPDATE poeco_tabs SET rgb = '{rgb}' WHERE uid = '{uid}' AND tid = '{tid}'"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + cmd.ExecuteNonQuery(); + con.Close(); + } + + 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(); + string cmdText = $"DELETE FROM poeco_items WHERE uid = '{userid}'"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + cmd.ExecuteNonQuery(); + con.Close(); + } + } +} diff --git a/PoEco.Net/DB/User.cs b/PoEco.Net/DB/User.cs new file mode 100644 index 0000000..3ea72a8 --- /dev/null +++ b/PoEco.Net/DB/User.cs @@ -0,0 +1,216 @@ +using MySql.Data.MySqlClient; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PoEco.Net.DB +{ + internal class User + { + 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 bool CheckUserExists(string user, string discriminator) + { + MySqlConnection con = MxPoEDB(); + string cmdText = $"SELECT * FROM poeco_user WHERE account = '{user}|{discriminator}'"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + var row = cmd.ExecuteReader(); + if (row.HasRows) { con.Close(); return true; } else { con.Close(); return false; } + } + + public static int GetUserID(string user) + { + using (var 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["uid"]); } else { return 0; } + } + } + + public static string[] GetUserNameByID(int uid) + { + using (var con = MxPoEDB()) + { + string cmdText = $"SELECT * FROM poeco_user WHERE uid = '{uid}'"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + var row = cmd.ExecuteReader(); + if (row.HasRows) + { + row.Read(); + string[] user = row["account"].ToString().Split('|'); + con.Close(); + return user; + } else + { + con.Close(); + return null; + } + } + } + + public static string GetUserTokenByID(int uid) + { + using (var con = MxPoEDB()) + { + string cmdText = $"SELECT * FROM poeco_user WHERE uid = '{uid}'"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + var row = cmd.ExecuteReader(); + if (row.HasRows) + { + row.Read(); + string user = row["token"].ToString(); + con.Close(); + return user; + } + else + { + con.Close(); + return null; + } + } + } + + public static int GetUserTabIndex(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(); con.Close(); return Convert.ToInt32(row["rareindex"]); } else { con.Close(); return 0; } + } + + public static int GetUserProfitTabIndex(int uid) + { + MySqlConnection con = MxPoEDB(); + string cmdText = $"SELECT * FROM poeco_tabs WHERE type = 'profit'"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + var row = cmd.ExecuteReader(); + if (row.HasRows) { row.Read(); return Convert.ToInt32(row["tid"]); } 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 int GetTabValueByTID(int uid, int tid) + { + int tv = 0; + MySqlConnection con = MxPoEDB(); + string cmdText = $"SELECT * FROM poeco_items WHERE uid = '{uid}' AND tid = '{tid}'"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + MySqlDataReader DR = cmd.ExecuteReader(); + while (DR.Read()) + { + tv = tv + DR.GetInt32(12); + } + return tv; + } + + public static int CountTabByUID(int uid) + { + MySqlConnection con = MxPoEDB(); + string cmdText = $"SELECT COUNT(*) FROM poeco_tabs WHERE uid = '{uid}'"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + int count = Convert.ToInt32(cmd.ExecuteScalar()); + con.Close(); + return count; + } + + public static void SetUserItemCount(int uid, int count, int index) + { + MySqlConnection con = MxPoEDB(); + string cmdText = $"UPDATE poeco_tabs SET count = '{count}' WHERE uid = '{uid}' AND tid = '{index}'"; + 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(int uid, int ti, double value) + { + MySqlConnection con = MxPoEDB(); + string cmdText = $"UPDATE poeco_tabs SET cvalue = '{value}' WHERE uid = '{uid}' AND tid = '{ti}'"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + cmd.ExecuteNonQuery(); + con.Close(); + } + + public static void DeleteProfits(int uid) + { + MySqlConnection con = MxPoEDB(); + string cmdText = $"DELETE FROM poeco_profits WHERE uid = '{uid}'"; + MySqlCommand cmd = new MySqlCommand(cmdText, con); + con.Open(); + cmd.ExecuteNonQuery(); + con.Close(); + } + } +} diff --git a/PoEco.Net/JSON/Classes/Divination.cs b/PoEco.Net/JSON/Classes/Divination.cs new file mode 100644 index 0000000..8ca3277 --- /dev/null +++ b/PoEco.Net/JSON/Classes/Divination.cs @@ -0,0 +1,80 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PoEco.Net.JSON.Classes +{ + internal class Divination + { + public class Sparkline + { + [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + public List data { get; set; } + public double? totalChange { get; set; } + } + + public class LowConfidenceSparkline + { + public List 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 implicitModifiers { get; set; } + public List 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 lines { get; set; } + public Language language { get; set; } + } + } +} diff --git a/PoEco.Net/JSON/Currency.cs b/PoEco.Net/JSON/Currency.cs new file mode 100644 index 0000000..cbad17d --- /dev/null +++ b/PoEco.Net/JSON/Currency.cs @@ -0,0 +1,76 @@ +using MySql.Data.MySqlClient; +using Newtonsoft.Json; +using PoEco.Net.DB; +using System; +using System.Collections.Generic; +using System.Diagnostics.Metrics; +using System.IO; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; +using static PoEco.Net.JSON.Stash; +using static System.Net.Mime.MediaTypeNames; + +namespace PoEco.Net.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(File.ReadAllText($@"data/stash/{user}.tab.{tab}.json")); + foreach (Stash.Item i in stash.items) + { + if (columnname == "divvalue") + { + //Console.WriteLine(MySqlHelper.EscapeString(i.typeLine)+" "+GetCurrencyValueByName(MySqlHelper.EscapeString(curName), table)); + MySqlConnection cond = MxPoEDB(); + string cmdTextd = $"INSERT INTO poeco_tab_div(uid, uiid, name, stack, cvalue) VALUES ('{uid}','{i.id}','{MySqlHelper.EscapeString(i.typeLine)}','{i.stackSize}','{GetCurrencyValueByName(MySqlHelper.EscapeString(curName), table)}')"; + MySqlCommand cmdd = new MySqlCommand(cmdTextd, cond); + cond.Open(); + cmdd.ExecuteNonQuery(); + cond.Close(); + } + curName = i.typeLine; + chaosValue = chaosValue + (GetCurrencyValueByName(MySqlHelper.EscapeString(curName), table) * i.stackSize); + } + 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 double 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 (name == "Chaos Orb") + { + return 1.0; + } else + { + if (row.HasRows) { row.Read(); return Convert.ToDouble(row["vchaos"]); } else { return 0; } + } + } + } + } +} diff --git a/PoEco.Net/JSON/Settings.cs b/PoEco.Net/JSON/Settings.cs new file mode 100644 index 0000000..b1d3d41 --- /dev/null +++ b/PoEco.Net/JSON/Settings.cs @@ -0,0 +1,49 @@ +using Newtonsoft.Json; +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PoEco.Net.JSON +{ + internal class Settings + { + public class SETTINGS + { + public string dbHost { get; set; } + public string dbPort { get; set; } + public string dbName { get; set; } + public string dbUser { get; set; } + public string dbPass { get; set; } + public string league { get; set; } + public bool web { get; set; } + public string webpath { get; set; } + } + + public static string GetdbHost() => JsonConvert.DeserializeObject(File.ReadAllText("data/settings.json")).dbHost; + public static string GetdbPort() => JsonConvert.DeserializeObject(File.ReadAllText("data/settings.json")).dbPort; + public static string GetdbName() => JsonConvert.DeserializeObject(File.ReadAllText("data/settings.json")).dbName; + public static string GetdbUser() => JsonConvert.DeserializeObject(File.ReadAllText("data/settings.json")).dbUser; + public static string GetdbPass() => JsonConvert.DeserializeObject(File.ReadAllText("data/settings.json")).dbPass; + public static string GetLeague() => JsonConvert.DeserializeObject(File.ReadAllText("data/settings.json")).league; + public static bool GetWeb() => JsonConvert.DeserializeObject(File.ReadAllText("data/settings.json")).web; + public static string GetWebPath() => JsonConvert.DeserializeObject(File.ReadAllText("data/settings.json")).webpath; + + public static void WriteSection(string section) + { + SETTINGS settings = JsonConvert.DeserializeObject(File.ReadAllText("data/gui.settings.json")); + File.WriteAllText("data/gui.settings.json", JsonConvert.SerializeObject((object)new SETTINGS() + { + dbHost = settings.dbHost, + dbPort = settings.dbPort, + dbName = settings.dbName, + dbUser = settings.dbUser, + dbPass = settings.dbPass, + league = settings.league + }, Formatting.Indented)); + } + } +} diff --git a/PoEco.Net/JSON/Stash.cs b/PoEco.Net/JSON/Stash.cs new file mode 100644 index 0000000..6a84589 --- /dev/null +++ b/PoEco.Net/JSON/Stash.cs @@ -0,0 +1,476 @@ +using MySql.Data.MySqlClient; +using MySqlX.XDevAPI.Relational; +using Newtonsoft.Json; +using PoEco.Net.DB; +using PoEco.Net.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; +using System.Text; +using System.Threading.Tasks; + +namespace PoEco.Net.JSON +{ + internal class Stash + { + public static void GenStashHash(string user) + { + List itemsID = new List(); + StringBuilder stashHash = new StringBuilder(); + StashRoot stash = JsonConvert.DeserializeObject(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 itemsID = new List(); + StringBuilder stashHash = new StringBuilder(); + StashRoot stash = JsonConvert.DeserializeObject(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, int tid) + { + StashRoot stash = JsonConvert.DeserializeObject(File.ReadAllText($@"data/stash/{user}.rare.{tid}.json")); + return stash.items.Count; + } + public static int GetUserProfitCount(string user, int tid) + { + StashRoot stash = JsonConvert.DeserializeObject(File.ReadAllText($@"data/stash/{user}.profit.{tid}.json")); + return stash.items.Count; + } + public static void UpdateUserTabRGB(string user, int tabindex) + { + StashRoot stash = JsonConvert.DeserializeObject(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(File.ReadAllText($"data/stash/{user}.tab{tabindex}.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, int tid, string uuid) + { + bool exists = false; + List items = new List(); + StashRoot stash = JsonConvert.DeserializeObject(File.ReadAllText($"data/stash/{user}.rare.{tid}.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 stringItemTxt = new List(); + List stringItemMod = new List(); + StashRoot stash = JsonConvert.DeserializeObject(File.ReadAllText($@"data/stash/{user}.json")); + int curitem = 1; + double chaosValue = 0; + int guid = 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 Rows = new List(); + int itemcount = stash.items.Count(); + foreach ( var file in tmpfiles ) { File.Delete(file); } + foreach (Item obj in stash.items) + { + if (!DB.Stash.CheckItemExistsDB(obj.id)) + { + itemcount--; + } + if (obj.typeLine != "" && obj.frameType == 2 && obj.identified && !DB.Stash.CheckItemExistsDB(obj.id)) + { + //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)}"); + stringItemTxt.Add("Rarity: Rare"); + stringItemTxt.Add(obj.name ?? ""); + stringItemTxt.Add(obj.typeLine ?? ""); + stringItemTxt.Add("--------"); + if (obj.properties != null && obj.properties.Count() > 0) + { + foreach (Property property in obj.properties) + { + if (property.name == "Quality") + stringItemTxt.Add(string.Format("Quality: {0}", property.values[0][0])); + if (property.name == "Armour") + stringItemTxt.Add(string.Format("Armour: {0}", property.values[0][0])); + if (property.name == "Energy Shield") + stringItemTxt.Add(string.Format("Energy Shield: {0}", property.values[0][0])); + if (property.name == "Evasion Rating") + stringItemTxt.Add(string.Format("Evasion Rating: {0}", property.values[0][0])); + if (property.values.Count>() == 0) + stringItemTxt.Add(property.name ?? ""); + if (property.name == "Physical Damage") + stringItemTxt.Add(string.Format("Physical Damage: {0}", property.values[0][0])); + if (property.name == "Elemental Damage") + stringItemTxt.Add(string.Format("Elemental Damage: {0}", property.values[0][0])); + if (property.name == "Critical Strike Chance") + stringItemTxt.Add(string.Format("Critical Strike Chance: {0}", property.values[0][0])); + if (property.name == "Attacks per Second") + stringItemTxt.Add(string.Format("Attacks per Second: {0}", property.values[0][0])); + if (property.name == "Weapon Range") + stringItemTxt.Add(string.Format("Weapon Range: {0}", property.values[0][0])); + } + stringItemTxt.Add("--------"); + } + stringItemTxt.Add("Requirements:"); + if (obj.requirements != null) + { + foreach (Requirement requirement in obj.requirements) + { + if (requirement.name == "Level") + stringItemTxt.Add(string.Format("Level: {0}", requirement.values[0][0])); + if (requirement.name == "Str") + stringItemTxt.Add(string.Format("Str: {0}", requirement.values[0][0])); + if (requirement.name == "Dex") + stringItemTxt.Add(string.Format("Dex: {0}", requirement.values[0][0])); + if (requirement.name == "Int") + stringItemTxt.Add(string.Format("Int: {0}", requirement.values[0][0])); + } + } + stringItemTxt.Add("--------"); + if (obj.sockets != null) + { + List stringList2 = new List(); + List stringList3 = new List(); + List stringList4 = new List(); + List stringList5 = new List(); + List stringList6 = new List(); + List stringList7 = new List(); + foreach (Socket socket in obj.sockets) + { + if (socket.group == 0) + stringList2.Add(socket.sColour.ToString()); + if (socket.group == 1) + stringList3.Add(socket.sColour.ToString()); + if (socket.group == 2) + stringList4.Add(socket.sColour.ToString()); + if (socket.group == 3) + stringList5.Add(socket.sColour.ToString()); + if (socket.group == 4) + stringList6.Add(socket.sColour.ToString()); + if (socket.group == 5) + stringList7.Add(socket.sColour.ToString()); + } + string str1 = string.Join("-", (IEnumerable)stringList2); + string str2 = string.Join("-", (IEnumerable)stringList3); + string str3 = string.Join("-", (IEnumerable)stringList4); + string str4 = string.Join("-", (IEnumerable)stringList5); + string str5 = string.Join("-", (IEnumerable)stringList6); + string str6 = string.Join("-", (IEnumerable)stringList7); + stringItemTxt.Add("Sockets: " + str1 + " " + str2 + " " + str3 + " " + str4 + " " + str5 + " " + str6); + } + stringItemTxt.Add("--------"); + stringItemTxt.Add(string.Format("Item Level: {0}", (object)obj.ilvl)); + stringItemTxt.Add("--------"); + if (obj.implicitMods != null) + { + foreach (string implicitMod in obj.implicitMods) + { + stringItemTxt.Add(implicitMod ?? ""); + stringItemMod.Add(implicitMod + "/n"); + } + stringItemTxt.Add("--------"); + stringItemMod.Add("--------/n"); + } + if (obj.explicitMods != null) + { + foreach (string explicitMod in obj.explicitMods) + { + stringItemTxt.Add(explicitMod ?? ""); + stringItemMod.Add(explicitMod + "/n"); + } + } + + File.WriteAllLines("tmp/" + obj.id + ".txt", (IEnumerable)stringItemTxt); + File.WriteAllLines("tmp/" + obj.id + ".mod.txt", (IEnumerable)stringItemMod); + string ib64 = Convert.ToBase64String(File.ReadAllBytes("tmp/" + obj.id + ".txt")); + Web.PoEPrices.GetItemJson(obj.id, ib64); + int tabindex = DB.User.GetUserTabIndex(user); + Rows.Add( + $"(" + + $"'{DB.User.GetUserID(user)}'," + + $"'{stash.tabs[tabindex].i}'," + + $"'{stash.tabs[tabindex].n}'," + + $"'{stash.tabs[tabindex].colour.r}:{stash.tabs[tabindex].colour.g}:{stash.tabs[tabindex].colour.b}'," + + $"'{icid}'," + + $"'{DB.Stash.GetBaseIDByName(obj.typeLine)}'," + + $"'{obj.id}'," + + $"'{MySql.Data.MySqlClient.MySqlHelper.EscapeString(File.ReadAllText("tmp/" + obj.id + ".mod.txt"))}'," + + $"'{DB.Stash.GetClassByID(icid)}:{MySql.Data.MySqlClient.MySqlHelper.EscapeString(obj.typeLine)}:{MySql.Data.MySqlClient.MySqlHelper.EscapeString(obj.name)}:{obj.ilvl}'," + + $"'{obj.icon}'," + + $"'{MySql.Data.MySqlClient.MySqlHelper.EscapeString(File.ReadAllText("tmp/" + obj.id + ".txt"))}'," + + $"'{ib64}'," + + $"'{Web.PoEPrices.GetCurType(obj.id)}'," + + $"'{Web.PoEPrices.GetMin(obj.id)}'," + + $"'{Web.PoEPrices.GetMax(obj.id)}'" + + $")"); + stringItemTxt.Clear(); + stringItemMod.Clear(); + curitem++; + Utilities.Message.CMW(chaosValue.ToString(),true,1); + } + } + sCommand.Append(string.Join(",", Rows)); + //Message.CMW(sCommand.ToString(),true,3); + sCommand.Append(";"); + 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 + { + public int r { get; set; } + + public int g { get; set; } + + public int b { get; set; } + } + + public class Tab + { + public string n { get; set; } + + public int i { get; set; } + + public string id { get; set; } + + public string type { get; set; } + + public bool selected { get; set; } + + public Colour colour { get; set; } + + public string srcL { get; set; } + + public string srcC { get; set; } + + public string srcR { get; set; } + } + + public class Socket + { + public int group { get; set; } + + public string attr { get; set; } + + public string sColour { get; set; } + } + + public class Property + { + public string name { get; set; } + + public List> values { get; set; } + + public int displayMode { get; set; } + + public int? type { get; set; } + } + + public class Requirement + { + public string name { get; set; } + + public List> values { get; set; } + + public int displayMode { get; set; } + + public string suffix { get; set; } + } + + public class AdditionalProperty + { + public string name { get; set; } + + public List> values { get; set; } + + public int displayMode { get; set; } + + public double progress { get; set; } + + public int type { get; set; } + } + + public class NextLevelRequirement + { + public string name { get; set; } + + public List> values { get; set; } + + public int displayMode { get; set; } + } + + public class SocketedItem + { + public bool verified { get; set; } + + public int w { get; set; } + + public int h { get; set; } + + public string icon { get; set; } + + public bool support { get; set; } + + public string id { get; set; } + + public string name { get; set; } + + public string typeLine { get; set; } + + public bool identified { get; set; } + + public int ilvl { get; set; } + + public List properties { get; set; } + + public List requirements { get; set; } + + public List additionalProperties { get; set; } + + public List nextLevelRequirements { get; set; } + + public string secDescrText { get; set; } + + public List explicitMods { get; set; } + + public string descrText { get; set; } + + public int frameType { get; set; } + + public int socket { get; set; } + + public string colour { get; set; } + } + + public class Item + { + public bool verified { get; set; } + + public int w { get; set; } + + public int h { get; set; } + + 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; } + + public List sockets { get; set; } + + public string name { get; set; } + + public string typeLine { get; set; } + + public bool identified { get; set; } + + public int ilvl { get; set; } + + public bool corrupted { get; set; } + + public int frameType { get; set; } + + public int x { get; set; } + + public int y { get; set; } + + public string inventoryId { get; set; } + + public List socketedItems { get; set; } + + public List properties { get; set; } + + public List requirements { get; set; } + + public List implicitMods { get; set; } + + public List explicitMods { get; set; } + + public List craftedMods { get; set; } + + public bool? support { get; set; } + + public List additionalProperties { get; set; } + + public string secDescrText { get; set; } + + public string descrText { get; set; } + + public List flavourText { get; set; } + + public bool? fractured { get; set; } + + public List fracturedMods { get; set; } + + public List enchantMods { get; set; } + + public int? talismanTier { get; set; } + } + + public class StashRoot + { + public int numTabs { get; set; } + + public List tabs { get; set; } + + public bool quadLayout { get; set; } + + public List items { get; set; } + } + } +} diff --git a/PoEco.Net/PoEco.Net.csproj b/PoEco.Net/PoEco.Net.csproj new file mode 100644 index 0000000..ff9b320 --- /dev/null +++ b/PoEco.Net/PoEco.Net.csproj @@ -0,0 +1,125 @@ + + + + + Debug + AnyCPU + {EB540AAD-F925-4C2E-913E-2891408DB5A3} + Exe + PoEco.Net + PoEco + v4.8.1 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\BouncyCastle.Cryptography.2.2.1\lib\net461\BouncyCastle.Cryptography.dll + + + ..\packages\Google.Protobuf.3.21.9\lib\net45\Google.Protobuf.dll + + + ..\packages\K4os.Compression.LZ4.1.3.5\lib\net462\K4os.Compression.LZ4.dll + + + ..\packages\K4os.Compression.LZ4.Streams.1.3.5\lib\net462\K4os.Compression.LZ4.Streams.dll + + + ..\packages\K4os.Hash.xxHash.1.0.8\lib\net462\K4os.Hash.xxHash.dll + + + ..\packages\Microsoft.Bcl.AsyncInterfaces.5.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll + + + ..\packages\MySql.Data.8.2.0\lib\net48\MySql.Data.dll + + + ..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll + + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + + ..\packages\System.Configuration.ConfigurationManager.4.4.1\lib\net461\System.Configuration.ConfigurationManager.dll + + + + ..\packages\System.Diagnostics.DiagnosticSource.7.0.2\lib\net462\System.Diagnostics.DiagnosticSource.dll + + + + ..\packages\System.IO.Pipelines.5.0.2\lib\net461\System.IO.Pipelines.dll + + + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + + + + + + + + + + ..\packages\ZstdSharp.Port.0.7.1\lib\net461\ZstdSharp.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PoEco.Net/Program.cs b/PoEco.Net/Program.cs new file mode 100644 index 0000000..bd4e5da --- /dev/null +++ b/PoEco.Net/Program.cs @@ -0,0 +1,421 @@ +using MySql.Data.MySqlClient; +using MySqlX.XDevAPI.Relational; +using Newtonsoft.Json; +using PoEco.Net.DB; +using PoEco.Net.Utilities; +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 PoEco.Net.JSON.Stash; +using static PoEco.Net.Web.PoEPrices; + +namespace PoEco.Net +{ + internal class Program + { + public static string version = "1.0.0"; + static void Main(string[] args) + { + if (!args.Contains("--gui")) { Utilities.Message.Splash("PoEco.Net", "mikx"); } + int a = args.Length; + if (a < 1) + { + Utilities.Message.CMW("Usage: poeco.exe ", true, 1); + Utilities.Message.CMW("--debug Skip parts of the logics for debuging.", true, 1); + Utilities.Message.CMW("--lua Generate up to date classes and bases.", true, 1); + Utilities.Message.CMW("--gen Generate up to date currencies value.", true, 1); + Utilities.Message.CMW("--usergen-rare Generate up to date user rare tab.", true, 1); + Utilities.Message.CMW("--usergen-tab Generate up to date user tabs.", true, 1); + } else + { + if (args.Contains("--lua")) + { + Message.CMW("Generating the latest Classes and Bases from PoB Lua...", true, 1); + Web.PoBLua.GetLatestLUA(); + DB.ClassGen.GenClass(); + Message.CMW("Generation done.", true, 2); + } + if (args.Contains("--gen")) + { + 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("--usergen-rare")) + { + if (args.Length > 1) + { + int uid = Convert.ToInt16(args[1]); + string user = DB.User.GetUserNameByID(uid)[0]; + string discriminator = DB.User.GetUserNameByID(uid)[1]; + Message.CMW($"User \"{user}\" processing...", true, 1); + Message.CMW($"Checking the database for user \"{user}\"...", true, 1); + if (DB.User.CheckUserExists(user, discriminator)) + { + Message.CMW($"User \"{user}\" exists with ID \"{uid}\".", true, 2); + foreach (var png in Directory.GetFiles("data/tabmap")) { File.Delete(png); } + File.Copy(@"data/StashTab_Quad.png", $@"data/tabmap/{user}#{discriminator}.png"); + if (args.Contains("--clean")) { DB.Item.DeleteAllItemsByUID(uid); } + int uct = DB.User.CountTabByUID(uid); + foreach (int ti in DB.Stash.EnumerateTabByUID(uid, "rare")) + { + Message.CMW($"Processing tab \"{ti}\" from user \"{user}\".", true, 2); + string token = DB.User.GetUserTokenByID(uid); + if (!args.Contains("--debug")) + { + Web.Stash.DownloadStash(token, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={ti}&accountName={user}%23{discriminator}", $"data/stash/{user}.rare.{ti}.json"); + } + StashRoot stash = JsonConvert.DeserializeObject(File.ReadAllText($@"data/stash/{user}.rare.{ti}.json")); + int stashitemcount = JSON.Stash.GetUserItemCount(user, ti); + int stashitemleft = stashitemcount; + List stringItemTxt = new List(); + List stringItemMod = new List(); + List Rows = new List(); + StringBuilder sCommand = new StringBuilder("INSERT INTO poeco_items(uid, tabindex, tabname, tabrgb, cid, bid, uiid, imod, var, img, txt, b64, ctype, min, max) VALUES "); + double chaosValue = 0; + while (stashitemleft > 0) + { + int idel = 0; + foreach (string i in DB.Item.EnumerateItemByUID(uid, ti)) + { + if (!JSON.Stash.CheckItemExistsStash(user, ti, i)) + { + DB.Item.DeleteItemByUIID(uid, ti, i); + idel++; + } + } + if (idel > 0) { Message.CMW($"Cleaned Item(s) Database. Deleted {idel} Item(s).", true, 2); } + idel = 0; + foreach (var i in stash.items) + { + if (!DB.Item.CheckItemExistsByUIID(i.id)) + { + if (i.frameType == 2) + { + Message.CMW($"[{stashitemleft}][{i.id.Substring(0,5)}] Processing {i.name} {i.typeLine}.", true, 2); + int icid = DB.Stash.GetClassIDByBase(i.typeLine); + string itemclass = DB.Stash.GetClassByID(icid); + stringItemTxt.Add($"Item Class: {char.ToUpper(itemclass[0]) + itemclass.Substring(1)}"); + stringItemTxt.Add("Rarity: Rare"); + stringItemTxt.Add(i.name ?? ""); + stringItemTxt.Add(i.typeLine ?? ""); + stringItemTxt.Add("--------"); + if (i.properties != null && i.properties.Count() > 0) + { + foreach (Property property in i.properties) + { + if (property.name == "Quality") + stringItemTxt.Add(string.Format("Quality: {0}", property.values[0][0])); + if (property.name == "Armour") + stringItemTxt.Add(string.Format("Armour: {0}", property.values[0][0])); + if (property.name == "Energy Shield") + stringItemTxt.Add(string.Format("Energy Shield: {0}", property.values[0][0])); + if (property.name == "Evasion Rating") + stringItemTxt.Add(string.Format("Evasion Rating: {0}", property.values[0][0])); + if (property.values.Count>() == 0) + stringItemTxt.Add(property.name ?? ""); + if (property.name == "Physical Damage") + stringItemTxt.Add(string.Format("Physical Damage: {0}", property.values[0][0])); + if (property.name == "Elemental Damage") + stringItemTxt.Add(string.Format("Elemental Damage: {0}", property.values[0][0])); + if (property.name == "Critical Strike Chance") + stringItemTxt.Add(string.Format("Critical Strike Chance: {0}", property.values[0][0])); + if (property.name == "Attacks per Second") + stringItemTxt.Add(string.Format("Attacks per Second: {0}", property.values[0][0])); + if (property.name == "Weapon Range") + stringItemTxt.Add(string.Format("Weapon Range: {0}", property.values[0][0])); + } + stringItemTxt.Add("--------"); + } + stringItemTxt.Add("Requirements:"); + if (i.requirements != null) + { + foreach (Requirement requirement in i.requirements) + { + if (requirement.name == "Level") + stringItemTxt.Add(string.Format("Level: {0}", requirement.values[0][0])); + if (requirement.name == "Str") + stringItemTxt.Add(string.Format("Str: {0}", requirement.values[0][0])); + if (requirement.name == "Dex") + stringItemTxt.Add(string.Format("Dex: {0}", requirement.values[0][0])); + if (requirement.name == "Int") + stringItemTxt.Add(string.Format("Int: {0}", requirement.values[0][0])); + } + } + stringItemTxt.Add("--------"); + if (i.sockets != null) + { + List stringList2 = new List(); + List stringList3 = new List(); + List stringList4 = new List(); + List stringList5 = new List(); + List stringList6 = new List(); + List stringList7 = new List(); + foreach (Socket socket in i.sockets) + { + if (socket.group == 0) + stringList2.Add(socket.sColour.ToString()); + if (socket.group == 1) + stringList3.Add(socket.sColour.ToString()); + if (socket.group == 2) + stringList4.Add(socket.sColour.ToString()); + if (socket.group == 3) + stringList5.Add(socket.sColour.ToString()); + if (socket.group == 4) + stringList6.Add(socket.sColour.ToString()); + if (socket.group == 5) + stringList7.Add(socket.sColour.ToString()); + } + string str1 = string.Join("-", (IEnumerable)stringList2); + string str2 = string.Join("-", (IEnumerable)stringList3); + string str3 = string.Join("-", (IEnumerable)stringList4); + string str4 = string.Join("-", (IEnumerable)stringList5); + string str5 = string.Join("-", (IEnumerable)stringList6); + string str6 = string.Join("-", (IEnumerable)stringList7); + stringItemTxt.Add("Sockets: " + str1 + " " + str2 + " " + str3 + " " + str4 + " " + str5 + " " + str6); + } + stringItemTxt.Add("--------"); + stringItemTxt.Add(string.Format("Item Level: {0}", (object)i.ilvl)); + stringItemTxt.Add("--------"); + if (i.implicitMods != null) + { + foreach (string implicitMod in i.implicitMods) + { + stringItemTxt.Add(implicitMod ?? ""); + stringItemMod.Add(implicitMod + "/n"); + } + stringItemTxt.Add("--------"); + stringItemMod.Add("--------/n"); + } + if (i.explicitMods != null) + { + foreach (string explicitMod in i.explicitMods) + { + stringItemTxt.Add(explicitMod ?? ""); + stringItemMod.Add(explicitMod + "/n"); + } + } + + File.WriteAllLines("tmp/" + i.id + ".txt", (IEnumerable)stringItemTxt); + File.WriteAllLines("tmp/" + i.id + ".mod.txt", (IEnumerable)stringItemMod); + string ib64 = Convert.ToBase64String(File.ReadAllBytes("tmp/" + i.id + ".txt")); + if (!args.Contains("--debug")) { Web.PoEPrices.GetItemJson(i.id, ib64); } + if (File.Exists($"tmp/" + i.id + ".json")) + { + string type = ""; + int tabindex = DB.User.GetUserTabIndex(user); + double min = Web.PoEPrices.GetMin(i.id); + double max = Web.PoEPrices.GetMax(i.id); + type = "c"; + if (JsonConvert.DeserializeObject(File.ReadAllText("tmp/" + i.id + ".json")).currency == "divine") + { + //min = min * JSON.Currency.GetCurrencyValueByName(MySqlHelper.EscapeString("Divine Orb"), "poeco_currency"); + //max = max * JSON.Currency.GetCurrencyValueByName(MySqlHelper.EscapeString("Divine Orb"), "poeco_currency"); + type = "d"; + } + Draw.GenQuad(i.w, i.h, i.x, i.y, i.icon, Math.Round(min, 1), Math.Round(max, 1), type, user, discriminator); + DB.Stash.AddItemTable(uid, ti, i.id, i.ilvl, icid, DB.Stash.GetBaseIDByName(i.typeLine), i.name, MySqlHelper.EscapeString(File.ReadAllText("tmp/" + i.id + ".mod.txt")), i.icon, MySqlHelper.EscapeString(File.ReadAllText("tmp/" + i.id + ".txt")), ib64, min, max); + chaosValue = chaosValue + max; + stringItemTxt.Clear(); + stringItemMod.Clear(); + stashitemleft--; + } + } + else + { + Message.CMW($"[{i.id}] Skipping {i.name} {i.typeLine}.", true, 3); + stashitemleft--; + } + stringItemTxt.Clear(); + stringItemMod.Clear(); + } + else + { + stashitemleft--; + } + } + int uic = DB.Item.CountItemByUID(uid, ti); + DB.User.SetUserItemCount(uid, uic, ti); + chaosValue = chaosValue + DB.User.GetTabValueByTID(uid, ti); + DB.User.SetUserTabValue(uid, ti, chaosValue); + DB.Stash.SetTabNameByTID(uid,ti, stash.tabs[ti].n); + DB.Stash.SetTabRGBByTID(uid, ti, $"{stash.tabs[ti].colour.r}:{stash.tabs[ti].colour.g}:{stash.tabs[ti].colour.b}"); + } + Message.CMW($"Processed all item(s) in the rare tab.", true, 2); + } + } + } + } + + if (args.Contains("--usergen-pro")) + { + int uid = Convert.ToInt16(args[1]); + string user = DB.User.GetUserNameByID(uid)[0]; + string discriminator = DB.User.GetUserNameByID(uid)[1]; + int proindex = DB.User.GetUserProfitTabIndex(uid); + string token = DB.User.GetUserToken(user); + DB.User.DeleteProfits(uid); + if (!args.Contains("--debug")) + { + Web.Stash.DownloadStash(token, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={proindex}&accountName={user}%23{discriminator}", $"data/stash/{user}.profit.{proindex}.json"); + } + StashRoot stash = JsonConvert.DeserializeObject(File.ReadAllText($"data/stash/{user}.profit.{proindex}.json")); + + int currencyIndex = 0; + int divIndex = 0; + int essenceIndex = 0; + int fragIndex = 0; + int fossilIndex = 0; + + foreach (var t in stash.tabs) + { + switch (t.type) + { + case "CurrencyStash": + if (t.n.Length == 1) + { + currencyIndex = t.i; + } + break; + case "DivinationCardStash": + divIndex = t.i; + break; + case "EssenceStash": + essenceIndex = t.i; + break; + case "FragmentStash": + fragIndex = t.i; + break; + case "DelveStash": + fossilIndex = t.i; + break; + } + } + + double pvalue = 0; + int pcount = JSON.Stash.GetUserProfitCount(user, proindex); + DB.Stash.SetTabRGBByTID(uid, proindex, $"{stash.tabs[proindex].colour.r}:{stash.tabs[proindex].colour.g}:{stash.tabs[proindex].colour.b}"); + DB.Stash.SetTabNameByTID(uid, proindex, stash.tabs[proindex].n); + Message.CMW($"Processing {pcount} items in Profit tab...", true, 2); + foreach (var i in stash.items) + { + if (i.frameType == 5) // Currency + { + pvalue = pvalue + (JSON.Currency.GetCurrencyValueByName(MySqlHelper.EscapeString(i.typeLine), "poeco_currency")*i.stackSize); + DB.Stash.AddProfitTable(uid, i.id, "currency", MySqlHelper.EscapeString(i.typeLine), i.stackSize, (JSON.Currency.GetCurrencyValueByName(MySqlHelper.EscapeString(i.typeLine), "poeco_currency") * i.stackSize)); + } + if (i.frameType == 0) // Fragment + { + pvalue = pvalue + (JSON.Currency.GetCurrencyValueByName(MySqlHelper.EscapeString(i.typeLine), "poeco_fragment") * i.stackSize); + DB.Stash.AddProfitTable(uid, i.id, "fragment", MySqlHelper.EscapeString(i.typeLine), i.stackSize, (JSON.Currency.GetCurrencyValueByName(MySqlHelper.EscapeString(i.typeLine), "poeco_fragment") * i.stackSize)); + } + if (i.frameType == 6) // Div + { + pvalue = pvalue + (JSON.Currency.GetCurrencyValueByName(MySqlHelper.EscapeString(i.typeLine), "poeco_divination") * i.stackSize); + DB.Stash.AddProfitTable(uid, i.id, "divination", MySqlHelper.EscapeString(i.typeLine), i.stackSize, (JSON.Currency.GetCurrencyValueByName(MySqlHelper.EscapeString(i.typeLine), "poeco_divination") * i.stackSize)); + } + } + DB.User.SetUserItemCount(uid, pcount, proindex); + DB.User.SetUserTabValue(uid, proindex, pvalue); + } + + if (args.Contains("--usergen-tab")) + { + int uid = Convert.ToInt16(args[1]); + string user = DB.User.GetUserNameByID(uid)[0]; + string discriminator = DB.User.GetUserNameByID(uid)[1]; + int rareindex = DB.User.GetUserTabIndex(user); + string token = DB.User.GetUserToken(user); + if (!args.Contains("--debug")) + { + Web.Stash.DownloadStash(token, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={rareindex}&accountName={user}%23{discriminator}", $"data/stash/{user}.json"); + } + StashRoot stash = JsonConvert.DeserializeObject(File.ReadAllText($@"data/stash/{user}.json")); + int currencyIndex = 0; + int divIndex = 0; + int essenceIndex = 0; + int fragIndex = 0; + int fossilIndex = 0; + + foreach (var t in stash.tabs) + { + switch (t.type) + { + case "CurrencyStash": + if (t.n.Length == 1) + { + currencyIndex = t.i; + } + break; + case "DivinationCardStash": + divIndex = t.i; + break; + case "EssenceStash": + essenceIndex = t.i; + break; + case "FragmentStash": + fragIndex = t.i; + break; + case "DelveStash": + fossilIndex = t.i; + break; + } + } + + if (DB.User.GetUserCurrencyIndex(user, "curindex") != -1) + { + Message.CMW($"Processing Currency tab...", true, 2); + Web.Stash.DownloadStash(token, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={currencyIndex}&accountName={user}%23{discriminator}", $"data/stash/{user}.tab.{currencyIndex}.json"); + JSON.Currency.GenCurrencyTab(user, currencyIndex, "curvalue", "poeco_currency"); + } + if (DB.User.GetUserCurrencyIndex(user, "divindex") != -1) + { + Message.CMW($"Processing Divination tab...", true, 2); + Web.Stash.DownloadStash(token, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={divIndex}&accountName={user}%23{discriminator}", $"data/stash/{user}.tab.{divIndex}.json"); + JSON.Currency.GenCurrencyTab(user, divIndex, "divvalue", "poeco_divination"); + } + if (DB.User.GetUserCurrencyIndex(user, "essindex") != -1) + { + Message.CMW($"Processing Essence tab...", true, 2); + Web.Stash.DownloadStash(token, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={essenceIndex}&accountName={user}%23{discriminator}", $"data/stash/{user}.tab.{essenceIndex}.json"); + JSON.Currency.GenCurrencyTab(user, essenceIndex, "essvalue", "poeco_essence"); + } + if (DB.User.GetUserCurrencyIndex(user, "fraindex") != -1) + { + Message.CMW($"Processing Fragment tab...", true, 2); + Web.Stash.DownloadStash(token, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={fragIndex}&accountName={user}%23{discriminator}", $"data/stash/{user}.tab.{fragIndex}.json"); + JSON.Currency.GenCurrencyTab(user, fragIndex, "fravalue", "poeco_fragment"); + } + if (DB.User.GetUserCurrencyIndex(user, "fosindex") != -1) + { + Message.CMW($"Processing Fossil tab...", true, 2); + Web.Stash.DownloadStash(token, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={fossilIndex}&accountName={user}%23{discriminator}", $"data/stash/{user}.tab.{fossilIndex}.json"); + JSON.Currency.GenCurrencyTab(user, fossilIndex, "fosvalue", "poeco_fossil"); + } + } + } + } + } +} diff --git a/PoEco.Net/Properties/AssemblyInfo.cs b/PoEco.Net/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..af19b1a --- /dev/null +++ b/PoEco.Net/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("PoEco.Net")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("PoEco.Net")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("eb540aad-f925-4c2e-913e-2891408db5a3")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/PoEco.Net/Utilities/Draw.cs b/PoEco.Net/Utilities/Draw.cs new file mode 100644 index 0000000..cba1a77 --- /dev/null +++ b/PoEco.Net/Utilities/Draw.cs @@ -0,0 +1,112 @@ +using Org.BouncyCastle.Asn1.Cms; +using PoEco.Net.JSON; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.IO.Ports; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using static System.Net.Mime.MediaTypeNames; +using Image = System.Drawing.Image; + +namespace PoEco.Net.Utilities +{ + internal class Draw + { + public static void GenQuad(int w, int h, int x, int y, string imgUrl, double min, double max, string type, string user, string discriminator) + { + int fontsize = 16; + + int calculatedW = w * 47; + int calculatedH = h * 47; + + int calculatedX = x * 47; + int calculatedY = y * 47; + + Color cborder = Color.FromArgb(61,235,52); + + // Adjust font size by item size + // w == item width + // h == item height + switch (w) + { + case 1: + switch (h) + { + case 1: + fontsize = 12; + break; + case 3: + fontsize = 12; + break; + } + break; + } + + ColorConverter cc = new ColorConverter(); + Color fontc = (Color)cc.ConvertFromString("#3d3d3b"); + switch (type) + { + case "c": + if (min < 10) { fontc = (Color)cc.ConvertFromString("#fc0303"); } + if (min >= 10 && min < 20) { fontc = (Color)cc.ConvertFromString("#fc5e03"); } + if (min >= 20 && min < 50) { fontc = (Color)cc.ConvertFromString("#fcce03"); } + if (min >= 50) { fontc = (Color)cc.ConvertFromString("#29f705"); } + break; + case "d": + fontc = (Color)cc.ConvertFromString("#29f705"); + break; + } + + var fontFamily = new FontFamily("Verdana"); + var vfont = new Font(fontFamily, fontsize, FontStyle.Regular, GraphicsUnit.Pixel); + Image imageFile = Image.FromFile($@"data/tabmap/{user}#{discriminator}.png"); + Graphics newGraphics = Graphics.FromImage(imageFile); + + Pen border = new Pen(cborder, 2); + Pen backPen = new Pen(cborder, 0); + SolidBrush back = new SolidBrush((Color)cc.ConvertFromString("#3d3d3b")); + SolidBrush font = new SolidBrush(fontc); + + Rectangle rect = new Rectangle(calculatedX, calculatedY, calculatedW, calculatedH); + Rectangle backgroundRect = new Rectangle(calculatedX, calculatedY, calculatedW-5, calculatedH-5); + + newGraphics.DrawRectangle(border, rect); + newGraphics.FillRectangle(back, rect); + newGraphics.DrawRectangle(border, rect); + + WebClient wc = new WebClient(); + byte[] bytes = wc.DownloadData(imgUrl); + MemoryStream ms = new MemoryStream(bytes); + Image itemIcon = Image.FromStream(ms); + + Bitmap bmp = new Bitmap(itemIcon.Width, itemIcon.Height); + ColorMatrix matrix = new ColorMatrix(); + + matrix.Matrix33 = 0.3f; + + ImageAttributes attributes = new ImageAttributes(); + + attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); + + newGraphics.DrawImage(itemIcon, new Rectangle(x * 47, y * 47, bmp.Width, bmp.Height), 0 , 0, itemIcon.Width, itemIcon.Height, GraphicsUnit.Pixel, attributes); + + StringFormat stringFormatMin = new StringFormat(); + stringFormatMin.Alignment = StringAlignment.Center; + stringFormatMin.LineAlignment = StringAlignment.Near; + newGraphics.DrawString(min.ToString() + type, vfont, font, rect, stringFormatMin); + + StringFormat stringFormatMax = new StringFormat(); + stringFormatMax.Alignment = StringAlignment.Center; + stringFormatMax.LineAlignment = StringAlignment.Far; + newGraphics.DrawString(max.ToString() + type, vfont, font, rect, stringFormatMax); + + imageFile.Save($@"data/tabmap/{user}#{discriminator}.png", ImageFormat.Bmp); + if (Settings.GetWeb()) { File.Copy($@"data/tabmap/{user}#{discriminator}.png", $@"{Settings.GetWebPath()}/{user}#{discriminator}.png", true); } + } + } +} diff --git a/PoEco.Net/Utilities/Message.cs b/PoEco.Net/Utilities/Message.cs new file mode 100644 index 0000000..fe1e376 --- /dev/null +++ b/PoEco.Net/Utilities/Message.cs @@ -0,0 +1,151 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PoEco.Net.Utilities +{ + internal class Message + { + public static void CMW(string msg, bool time, int color) + { + DateTime now; + string str1; + int num; + if (DateTime.Now.Second < 10) + { + now = DateTime.Now; + str1 = string.Format("0{0}", (object)now.Second); + } + else + { + num = DateTime.Now.Second; + str1 = num.ToString(); + } + now = DateTime.Now; + string str2; + if (now.Minute < 10) + { + now = DateTime.Now; + str2 = string.Format("0{0}", (object)now.Minute); + } + else + { + now = DateTime.Now; + num = now.Minute; + str2 = num.ToString(); + } + now = DateTime.Now; + string str3; + if (now.Hour < 10) + { + now = DateTime.Now; + str3 = string.Format("0{0}", (object)now.Hour); + } + else + { + now = DateTime.Now; + num = now.Hour; + str3 = num.ToString(); + } + string str4 = string.Format("{0}:{1}:{2}", (object)str3, (object)str2, (object)str1); + File.AppendAllText("mxfiltergen.logs", string.Format("[{0}] {1}", (object)str4, (object)msg) + Environment.NewLine); + ConsoleColor consoleColor = ConsoleColor.White; + switch (color) + { + case 1: + consoleColor = ConsoleColor.Cyan; + break; + case 2: + consoleColor = ConsoleColor.Green; + break; + case 3: + consoleColor = ConsoleColor.Red; + break; + } + if (time) + { + Console.ForegroundColor = consoleColor; + Console.WriteLine(string.Format("[{0}] {1}", (object)str4, (object)msg)); + } + else + { + Console.ForegroundColor = consoleColor; + Console.WriteLine(string.Format("")); + } + Console.ForegroundColor = ConsoleColor.White; + } + + public static void drawProgress(int progress, int total) + { + DateTime now; + string str1; + int num; + if (DateTime.Now.Second < 10) + { + now = DateTime.Now; + str1 = string.Format("0{0}", (object)now.Second); + } + else + { + num = DateTime.Now.Second; + str1 = num.ToString(); + } + now = DateTime.Now; + string str2; + if (now.Minute < 10) + { + now = DateTime.Now; + str2 = string.Format("0{0}", (object)now.Minute); + } + else + { + now = DateTime.Now; + num = now.Minute; + str2 = num.ToString(); + } + now = DateTime.Now; + string str3; + if (now.Hour < 10) + { + now = DateTime.Now; + str3 = string.Format("0{0}", (object)now.Hour); + } + else + { + now = DateTime.Now; + num = now.Hour; + str3 = num.ToString(); + } + string str4 = string.Format("[{0}] [", (object)string.Format("{0}:{1}:{2}", (object)str3, (object)str2, (object)str1)); + Console.ForegroundColor = ConsoleColor.Cyan; + if (progress == 1) + { + Console.Write(str4); + Console.CursorLeft = total + str4.Length; + Console.Write("]"); + } + Console.CursorLeft = progress + str4.Length - 1; + Console.Write("#"); + Console.CursorLeft = str4.Length + total + 2; + Console.Write(string.Format("{0}/{1}", (object)progress, (object)total)); + if (progress != total) + return; + Console.WriteLine(); + } + + public static void Splash(string progname, string dev) + { + Console.ForegroundColor = ConsoleColor.Cyan; + Console.WriteLine(""); + Console.WriteLine($"#### {progname}"); + Console.WriteLine(string.Format("#### VERSION: {0}", (object)Program.version)); + Console.WriteLine($"#### DEV: {dev}"); + Console.WriteLine("#### POWERED BY: poe.ninja / poeprices.info"); + Console.WriteLine(""); + Console.ForegroundColor = ConsoleColor.White; + } + } +} diff --git a/PoEco.Net/Web/PoBLua.cs b/PoEco.Net/Web/PoBLua.cs new file mode 100644 index 0000000..1d6fa28 --- /dev/null +++ b/PoEco.Net/Web/PoBLua.cs @@ -0,0 +1,30 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace PoEco.Net.Web +{ + internal class PoBLua + { + public class LuaRoot + { + public List lua { get; set; } + } + public static void GetLatestLUA() + { + if (!Directory.Exists(@"data\lua")) { Directory.CreateDirectory(@"data\lua"); } + WebClient wc = new WebClient(); + LuaRoot lr = JsonConvert.DeserializeObject(File.ReadAllText(@"data\lua.json")); + foreach (var l in lr.lua) + { + if(File.Exists($@"data\lua\{l}.lua")) { File.Delete($@"data\lua\{l}.lua"); } + wc.DownloadFile($"https://github.com/PathOfBuildingCommunity/PathOfBuilding/raw/dev/src/Data/Bases/{l}.lua", $@"data\lua\{l}.lua"); + } + } + } +} diff --git a/PoEco.Net/Web/PoENinja.cs b/PoEco.Net/Web/PoENinja.cs new file mode 100644 index 0000000..2f615e9 --- /dev/null +++ b/PoEco.Net/Web/PoENinja.cs @@ -0,0 +1,283 @@ +using MySql.Data.MySqlClient; +using Newtonsoft.Json; +using PoEco.Net.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 PoEco.Net.JSON.Classes.Divination; + +namespace PoEco.Net.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) + { + Utilities.Message.CMW(ex.Message, true, 3); + Utilities.Message.CMW("URL: " + url, true, 3); + } + catch (Exception ex) + { + Utilities.Message.CMW(ex.Message, true, 3); + } + } + + public static void GenCurrency() + { + DeleteCurrencies(); + int curID = 1; + double divineValue = 0; + string cmdText = ""; + RootCurrency rcur = JsonConvert.DeserializeObject(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(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,10)}','{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(File.ReadAllText("data/ninja/divination.json", Encoding.UTF8)); + foreach (LineDivination line in JsonConvert.DeserializeObject(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(File.ReadAllText("data/ninja/essence.json", Encoding.UTF8)); + foreach (LineDivination line in JsonConvert.DeserializeObject(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(File.ReadAllText("data/ninja/scarab.json", Encoding.UTF8)); + foreach (LineDivination line in JsonConvert.DeserializeObject(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(File.ReadAllText("data/ninja/fossil.json", Encoding.UTF8)); + foreach (LineDivination line in JsonConvert.DeserializeObject(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 data { get; set; } + public double totalChange { get; set; } + } + + public class LowConfidenceReceiveSparkLine + { + public List 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 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 data { get; set; } + public double totalChange { get; set; } + } + + public class RootCurrency + { + public List lines { get; set; } + public List currencyDetails { get; set; } + public LanguageCurrency language { get; set; } + } + + public class TranslationsCurrency + { + } +} + diff --git a/PoEco.Net/Web/PoEPrices.cs b/PoEco.Net/Web/PoEPrices.cs new file mode 100644 index 0000000..d268171 --- /dev/null +++ b/PoEco.Net/Web/PoEPrices.cs @@ -0,0 +1,65 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Security.Policy; +using System.Text; +using System.Threading.Tasks; + +namespace PoEco.Net.Web +{ + internal class PoEPrices + { + public static void GetItemJson(string iid, string b64) + { + ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; + string url = $"https://www.poeprices.info/api?l={JSON.Settings.GetLeague()}&i={b64}"; + WebClient webClient = new WebClient(); + try + { + webClient.DownloadFile(url, "tmp/" + iid + ".json"); + } + catch (WebException ex) + { + if (ex.Message.Contains("The remote server returned an error: (504) Gateway Time-out.")) + { + Utilities.Message.CMW("Failed. Retrying...", true, 3); + GetItemJson(iid, b64); + } + //Utilities.Message.CMW(ex.Message, true, 3); + //Utilities.Message.CMW("URL: " + url, true, 3); + } + catch (Exception ex) + { + Utilities.Message.CMW(ex.Message, true, 3); + } + } + + public static double GetMin(string iid) + { + return JsonConvert.DeserializeObject(File.ReadAllText("tmp/" + iid + ".json")).min; + } + + public static double GetMax(string iid) + { + return JsonConvert.DeserializeObject(File.ReadAllText("tmp/" + iid + ".json")).max; + } + + public static string GetCurType(string iid) + { + return JsonConvert.DeserializeObject(File.ReadAllText("tmp/" + iid + ".json")).currency; + } + + public class PoEPricesRoot + { + public double min { get; set; } + + public double max { get; set; } + + public string currency { get; set; } + } + } +} diff --git a/PoEco.Net/Web/Stash.cs b/PoEco.Net/Web/Stash.cs new file mode 100644 index 0000000..34afd0f --- /dev/null +++ b/PoEco.Net/Web/Stash.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace PoEco.Net.Web +{ + internal class Stash + { + public static void DownloadStash(string token, string url, string path) + { + WebClient webClient = new WebClient(); + webClient.Encoding = Encoding.UTF8; + webClient.Headers.Add(HttpRequestHeader.Cookie, "POESESSID=" + token); + webClient.Headers.Add("user-agent", $"PoEcoDB/{Program.version} (poeco@mxpoe.ovh)"); + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; + try + { + Uri address = new Uri(url); + webClient.DownloadFile(address, path); + } + catch (WebException ex) + { + Utilities.Message.CMW(ex.Message, true, 3); + Utilities.Message.CMW("URL: " + url, true, 3); + } + catch (Exception ex) + { + Utilities.Message.CMW(ex.Message,true,3); + } + } + + public static void GetStash(string token, string url, string path) + { + WebClient webClient = new WebClient(); + webClient.Encoding = Encoding.UTF8; + webClient.Headers.Add("Authorization", "Bearer " + token); + ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; + try + { + Uri address = new Uri(url); + webClient.DownloadFile(address, path); + } + catch (WebException ex) + { + Utilities.Message.CMW(ex.Message, true, 3); + Utilities.Message.CMW("URL: " + url, true, 3); + } + catch (Exception ex) + { + Utilities.Message.CMW(ex.Message, true, 3); + } + } + } +} diff --git a/PoEco.Net/packages.config b/PoEco.Net/packages.config new file mode 100644 index 0000000..0a3955e --- /dev/null +++ b/PoEco.Net/packages.config @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..be81350 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +## PoEco.Net + Path of Exile Economy Backend developped in C#. + +## Features +- Generate a database of Bases and Classes from PoB lua files. +- Generate up to date currency economy value. +- Price specialized tabs. +- Price identified rare in a tab using PoEPrices.Info API. +- Use MySQL (­­­­­>=5.7.42) for storing the data. +- Can be used on Linux using Mono. (>=6.8.0) + +## Credtis +- poe.ninja +- Path of Building +- GGG for his amazing PoE API \ No newline at end of file