first commit

This commit is contained in:
mikx 2024-09-22 09:03:36 -04:00
commit c4bfb721c1
20 changed files with 2162 additions and 0 deletions

261
.gitignore vendored Normal file
View File

@ -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

73
LICENSE Normal file
View File

@ -0,0 +1,73 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

25
MxWDB.sln Normal file
View File

@ -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}") = "MxWDB", "MxWDB\MxWDB.csproj", "{2A1363E5-1109-45EF-8CDE-DBCAAD71189B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2A1363E5-1109-45EF-8CDE-DBCAAD71189B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A1363E5-1109-45EF-8CDE-DBCAAD71189B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A1363E5-1109-45EF-8CDE-DBCAAD71189B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A1363E5-1109-45EF-8CDE-DBCAAD71189B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {313DB768-CA78-45DF-9194-3ECB9431F002}
EndGlobalSection
EndGlobal

22
MxWDB/App.config Normal file
View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.1" newVersion="8.0.0.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

193
MxWDB/JSON/AHDump.cs Normal file
View File

@ -0,0 +1,193 @@
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using static MxWDB.JSON.AHDump;
namespace MxWDB.JSON
{
internal class AHDump
{
public class Item
{
public int id { get; set; }
}
public class RootAuctions
{
public int id { get; set; }
public Item item { get; set; }
public int quantity { get; set; }
public Int64 unit_price { get; set; }
public Int64 buyout { get; set; }
public string time_left { get; set; }
}
public static DataSet aucds = new DataSet();
public static DataSet aucdscom = new DataSet();
public static void GenTable()
{
/*
var jf = File.ReadAllText(string.Format("{0}_{1}-dump.json", Server.region, Server.realm));
var root = JObject.Parse(jf).SelectToken("auctions").ToString();
File.WriteAllText("root.json", root);
DataSet ds = JsonConvert.DeserializeObject<DataSet>(root);
DataTable table = ds.Tables["auctions"];
DataTable auctb = new DataTable("auclist");
auctb.Columns.Add(new DataColumn("auc", typeof(Int64)));
auctb.Columns.Add(new DataColumn("item", typeof(Int64)));
auctb.Columns.Add(new DataColumn("owner", typeof(string)));
auctb.Columns.Add(new DataColumn("value", typeof(Int64)));
auctb.Columns.Add(new DataColumn("qty", typeof(int)));
auctb.Columns.Add(new DataColumn("time", typeof(string)));
foreach (DataRow dr in table.Rows)
{
Int64 buy = Convert.ToInt64(dr["buyout"]);
if (buy > 0)
{
DataRow nr = auctb.NewRow();
nr["auc"] = Convert.ToInt32(dr["auc"]);
nr["item"] = Convert.ToInt32(dr["item"]);
nr["owner"] = dr["owner"];
nr["qty"] = Convert.ToInt32(dr["quantity"]);
int qty = Convert.ToInt32(dr["quantity"]);
if (qty == 1)
{
nr["value"] = buy;
}
else
{
nr["value"] = buy / qty;
}
auctb.Rows.Add(nr);
}
}
aucds.Tables.Add(auctb);
*/
var jf = File.ReadAllText(string.Format("json/ah.dump.json"));
var root = JObject.Parse(jf).SelectToken("auctions").ToString();
var RootAuctions = JsonConvert.DeserializeObject<List<RootAuctions>>(root);
DataTable auctb = new DataTable("auclist");
auctb.Columns.Add(new DataColumn("aid", typeof(int)));
auctb.Columns.Add(new DataColumn("iid", typeof(int)));
auctb.Columns.Add(new DataColumn("qty", typeof(int)));
auctb.Columns.Add(new DataColumn("uv", typeof(Int64)));
foreach (var r in RootAuctions)
{
DataRow nr = auctb.NewRow();
/*if (!Utilities.DB.CheckItemInfoExists(r.item.id))
{
Utilities.DB.GenItemInfo(r.item.id);
}*/
nr["aid"] = r.id;
nr["iid"] = r.item.id;
nr["qty"] = r.quantity;
if (r.unit_price > 0)
{
nr["uv"] = r.unit_price;
}
if (r.buyout > 0)
{
nr["uv"] = r.buyout;
}
auctb.Rows.Add(nr);
}
aucds.Tables.Add(auctb);
}
public static void GenTableCom()
{
/*
var jf = File.ReadAllText(string.Format("{0}_{1}-dump.json", Server.region, Server.realm));
var root = JObject.Parse(jf).SelectToken("auctions").ToString();
File.WriteAllText("root.json", root);
DataSet ds = JsonConvert.DeserializeObject<DataSet>(root);
DataTable table = ds.Tables["auctions"];
DataTable auctb = new DataTable("auclist");
auctb.Columns.Add(new DataColumn("auc", typeof(Int64)));
auctb.Columns.Add(new DataColumn("item", typeof(Int64)));
auctb.Columns.Add(new DataColumn("owner", typeof(string)));
auctb.Columns.Add(new DataColumn("value", typeof(Int64)));
auctb.Columns.Add(new DataColumn("qty", typeof(int)));
auctb.Columns.Add(new DataColumn("time", typeof(string)));
foreach (DataRow dr in table.Rows)
{
Int64 buy = Convert.ToInt64(dr["buyout"]);
if (buy > 0)
{
DataRow nr = auctb.NewRow();
nr["auc"] = Convert.ToInt32(dr["auc"]);
nr["item"] = Convert.ToInt32(dr["item"]);
nr["owner"] = dr["owner"];
nr["qty"] = Convert.ToInt32(dr["quantity"]);
int qty = Convert.ToInt32(dr["quantity"]);
if (qty == 1)
{
nr["value"] = buy;
}
else
{
nr["value"] = buy / qty;
}
auctb.Rows.Add(nr);
}
}
aucds.Tables.Add(auctb);
*/
var jf = File.ReadAllText(string.Format("json/ah.com.dump.json"));
var root = JObject.Parse(jf).SelectToken("auctions").ToString();
var RootAuctions = JsonConvert.DeserializeObject<List<RootAuctions>>(root);
DataTable auctbcom = new DataTable("auclistcom");
auctbcom.Columns.Add(new DataColumn("aid", typeof(int)));
auctbcom.Columns.Add(new DataColumn("iid", typeof(int)));
auctbcom.Columns.Add(new DataColumn("qty", typeof(int)));
auctbcom.Columns.Add(new DataColumn("uv", typeof(Int64)));
foreach (var r in RootAuctions)
{
DataRow nr = auctbcom.NewRow();
nr["aid"] = r.id;
nr["iid"] = r.item.id;
nr["qty"] = r.quantity;
nr["uv"] = r.unit_price;
auctbcom.Rows.Add(nr);
}
aucdscom.Tables.Add(auctbcom);
}
}
}

43
MxWDB/JSON/AHUrl.cs Normal file
View File

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace MxWDB.JSON
{
class AHUrl
{
public class JSON
{
public string url { get; set; }
public long lastModified { get; set; }
}
public class RootObject
{
public List<JSON> files { get; set; }
}
public static void GetDump(string key, string secret, string token)
{
using (WebClient wc = new WebClient())
{
ServicePointManager.ServerCertificateValidationCallback += (p1, p2, p3, p4) => true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Utilities.Web.DownloadFileNoAsync($"https://us.api.blizzard.com/data/wow/connected-realm/{Settings.GetRID()}/auctions?namespace=dynamic-us&locale=en_US&access_token={token}", "json/ah.dump.json");
}
}
public static void GetDumpCom(string key, string secret, string token)
{
using (WebClient wc = new WebClient())
{
ServicePointManager.ServerCertificateValidationCallback += (p1, p2, p3, p4) => true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Utilities.Web.DownloadFileNoAsync($"https://us.api.blizzard.com/data/wow/auctions/commodities?namespace=dynamic-us&access_token={token}", "json/ah.com.dump.json");
}
}
}
}

89
MxWDB/JSON/GenSpecial.cs Normal file
View File

@ -0,0 +1,89 @@
using MySqlConnector;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace MxWDB.JSON
{
public class Special
{
public List<string> special { get; set; }
}
public class SpecialObject
{
public List<object> Data { get; set; }
}
class SpecialGen
{
internal static void GenSpecial(string special)
{
StringBuilder sb = new StringBuilder("INSERT INTO ah_special_data (itemid,specialid,value) VALUES ");
List<string> Rows = new List<string>();
List<string> ind = new List<string>();
Special ji = JsonConvert.DeserializeObject<Special>(File.ReadAllText(special));
foreach (var i in ji.special)
{
ind.Add(i);
}
int sid = 1;
int itemid = 0;
foreach (var e in ind)
{
SpecialObject j = JsonConvert.DeserializeObject<SpecialObject>(File.ReadAllText(string.Format("json/special/special_{0}.json", e)));
if (j.Data.Count > 0)
{
foreach (var d in j.Data)
{
itemid = Convert.ToInt32(d);
Rows.Add(string.Format("('{0}','{1}','{2}')", itemid, sid, GetItemValue(itemid)));
}
}
sid = sid + 1;
}
sb.Append(string.Join(",", Rows));
sb.Append(";");
InsertIndex(sb.ToString());
}
public static Int64 GetItemValue(int id)
{
//string d = "nB3qJHOVPH";
Int64 v = 0;
string stm = string.Format("SELECT * FROM ah_items WHERE itemid='{0}'", id);
MySqlConnection mc = Utilities.DB.ItemDB();
MySqlCommand cmd = new MySqlCommand(stm, mc);
mc.Open();
MySqlDataReader result = cmd.ExecuteReader();
if (result.Read())
{
v = Convert.ToInt64(result["minimum"]);
}
mc.Close();
return v;
}
private static void InsertIndex(string cmd)
{
MySqlConnection mc = Utilities.DB.ItemDB();
MySqlCommand command = mc.CreateCommand();
command.CommandText = cmd;
mc.Open();
command.ExecuteNonQuery();
mc.Close();
}
}
}

187
MxWDB/JSON/IndexGen.cs Normal file
View File

@ -0,0 +1,187 @@
using MySqlConnector;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace MxWDB.JSON
{
public class Index
{
public List<string> index { get; set; }
}
public class RootObject
{
public List<object> Misc { get; set; }
public List<object> Jewelcrafting { get; set; }
public List<int> Tailoring { get; set; }
public List<int> Skinning { get; set; }
public List<int> Herbalism { get; set; }
public List<int> Mining { get; set; }
public List<int> Enchanting { get; set; }
public List<int> Fishing { get; set; }
}
class IndexGen
{
internal static void GenIndex(string index)
{
StringBuilder sb = new StringBuilder("INSERT INTO ah_index (itemid,contentid,catid,value,qty) VALUES ");
List<string> Rows = new List<string>();
List<string> ind = new List<string>();
Index ji = JsonConvert.DeserializeObject<Index>(File.ReadAllText(index));
foreach (var i in ji.index)
{
ind.Add(i);
}
int cid = 0;
int catid = 0;
int itemid = 0;
foreach (var e in ind)
{
cid = Convert.ToInt32(e);
RootObject j = JsonConvert.DeserializeObject<RootObject>(File.ReadAllText(string.Format("json/index/index_{0}.json", e)));
if (j.Misc.Count > 0)
{
foreach (var d in j.Misc)
{
catid = 1;
itemid = Convert.ToInt32(d);
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
}
}
if (j.Jewelcrafting.Count > 0)
{
foreach (var d in j.Jewelcrafting)
{
catid = 2;
itemid = Convert.ToInt32(d);
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
}
}
if (j.Tailoring.Count > 0)
{
foreach (var d in j.Tailoring)
{
catid = 3;
itemid = Convert.ToInt32(d);
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
}
}
if (j.Skinning.Count > 0)
{
foreach (var d in j.Skinning)
{
catid = 4;
itemid = Convert.ToInt32(d);
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
}
}
if (j.Herbalism.Count > 0)
{
foreach (var d in j.Herbalism)
{
catid = 5;
itemid = Convert.ToInt32(d);
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
}
}
if (j.Mining.Count > 0)
{
foreach (var d in j.Mining)
{
catid = 6;
itemid = Convert.ToInt32(d);
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
}
}
if (j.Enchanting.Count > 0)
{
foreach (var d in j.Enchanting)
{
catid = 7;
itemid = Convert.ToInt32(d);
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
}
}
if (j.Fishing.Count > 0)
{
foreach (var d in j.Fishing)
{
catid = 8;
itemid = Convert.ToInt32(d);
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", itemid, cid, catid, GetItemValue(itemid), GetItemQuantity(itemid)));
}
}
cid = cid + 1;
}
sb.Append(string.Join(",", Rows));
sb.Append(";");
InsertIndex(sb.ToString());
}
public static int GetItemValue(int id)
{
int v = 0;
string stm = string.Format("SELECT * FROM ah_items WHERE itemid='{0}'", id);
MySqlConnection mc = Utilities.DB.ItemDB();
MySqlCommand cmd = new MySqlCommand(stm, mc);
mc.Open();
MySqlDataReader result = cmd.ExecuteReader();
if (result.Read())
{
v = Convert.ToInt32(result["minimum"]);
}
mc.Close();
return v;
}
public static int GetItemQuantity(int id)
{
int v = 0;
string stm = string.Format("SELECT * FROM ah_items WHERE itemid='{0}'", id);
MySqlConnection mc = Utilities.DB.ItemDB();
MySqlCommand cmd = new MySqlCommand(stm, mc);
mc.Open();
MySqlDataReader result = cmd.ExecuteReader();
if (result.Read())
{
v = Convert.ToInt32(result["quantity"]);
}
mc.Close();
return v;
}
private static void InsertIndex(string cmd)
{
MySqlConnection mc = Utilities.DB.ItemDB();
MySqlCommand command = mc.CreateCommand();
command.CommandText = cmd;
mc.Open();
command.ExecuteNonQuery();
mc.Close();
}
}
}

68
MxWDB/JSON/Settings.cs Normal file
View File

@ -0,0 +1,68 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MxWDB.JSON
{
internal class Settings
{
public class SETTINGS
{
public string apikey { get; set; }
public string apisecret { get; set; }
public string region { get; set; }
public int realmid { get; set; }
public string dbname { get; set; }
public string dbhost { get; set; }
public string dbport { get; set; }
public string dbuser { get; set; }
public string dbpass { get; set; }
public bool debug { get; set; }
}
///<summary>
///Load the Database Host from the Settings Json.
///</summary>
public static string GetDBHost() => JsonConvert.DeserializeObject<SETTINGS>(File.ReadAllText("json/settings.json")).dbhost;
///<summary>
///Load the Database Port from the Settings Json.
///</summary>
public static string GetDBPort() => JsonConvert.DeserializeObject<SETTINGS>(File.ReadAllText("json/settings.json")).dbport;
///<summary>
///Load the Database Name from the Settings Json.
///</summary>
public static string GetDBName() => JsonConvert.DeserializeObject<SETTINGS>(File.ReadAllText("json/settings.json")).dbname;
///<summary>
///Load the Database User from the Settings Json.
///</summary>
public static string GetDBUser() => JsonConvert.DeserializeObject<SETTINGS>(File.ReadAllText("json/settings.json")).dbuser;
///<summary>
///Load the Database Password from the Settings Json.
///</summary>
public static string GetDBPass() => JsonConvert.DeserializeObject<SETTINGS>(File.ReadAllText("json/settings.json")).dbpass;
///<summary>
///Load the Blizzard Dev API Key from the Settings Json.
///</summary>
public static string GetAPIKey() => JsonConvert.DeserializeObject<SETTINGS>(File.ReadAllText("json/settings.json")).apikey;
///<summary>
///Load the Blizzard Dev API Secret from the Settings Json.
///</summary>
public static string GetAPISecret() => JsonConvert.DeserializeObject<SETTINGS>(File.ReadAllText("json/settings.json")).apisecret;
///<summary>
///Load the Realm Region from the Settings Json.
///</summary>
public static string GetRegion() => JsonConvert.DeserializeObject<SETTINGS>(File.ReadAllText("json/settings.json")).region;
///<summary>
///Load the Realm ID from the Settings Json.
///</summary>
public static int GetRID() => JsonConvert.DeserializeObject<SETTINGS>(File.ReadAllText("json/settings.json")).realmid;
///<summary>
///Used for developper. So far, it prevent the software from downloading a new dump, saving a lot of time for testing.
///</summary>
public static bool GetDebug() => JsonConvert.DeserializeObject<SETTINGS>(File.ReadAllText("json/settings.json")).debug;
}
}

42
MxWDB/JSON/Token.cs Normal file
View File

@ -0,0 +1,42 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace MxWDB.JSON
{
internal class Token
{
public class Links
{
public Self self { get; set; }
}
public class Root
{
public Links _links { get; set; }
public long last_updated_timestamp { get; set; }
public int price { get; set; }
}
public class Self
{
public string href { get; set; }
}
public static void GetToken(string token)
{
using (WebClient wc = new WebClient())
{
ServicePointManager.ServerCertificateValidationCallback += (p1, p2, p3, p4) => true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Utilities.Web.DownloadFileNoAsync($"https://us.api.blizzard.com/data/wow/token/index?namespace=dynamic-us&locale=en_US&access_token={token}", "json/token.json");
}
}
public static int GetTokenValue() => JsonConvert.DeserializeObject<Root>(File.ReadAllText("json/settings.json")).price;
}
}

137
MxWDB/MxWDB.csproj Normal file
View File

@ -0,0 +1,137 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2A1363E5-1109-45EF-8CDE-DBCAAD71189B}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>MxWDB</RootNamespace>
<AssemblyName>MxWDB</AssemblyName>
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="BouncyCastle.Cryptography, Version=2.0.0.0, Culture=neutral, PublicKeyToken=072edcf4a5328938, processorArchitecture=MSIL">
<HintPath>..\packages\BouncyCastle.Cryptography.2.3.1\lib\net461\BouncyCastle.Cryptography.dll</HintPath>
</Reference>
<Reference Include="Google.Protobuf, Version=3.26.1.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL">
<HintPath>..\packages\Google.Protobuf.3.26.1\lib\net45\Google.Protobuf.dll</HintPath>
</Reference>
<Reference Include="K4os.Compression.LZ4, Version=1.3.8.0, Culture=neutral, PublicKeyToken=2186fa9121ef231d, processorArchitecture=MSIL">
<HintPath>..\packages\K4os.Compression.LZ4.1.3.8\lib\net462\K4os.Compression.LZ4.dll</HintPath>
</Reference>
<Reference Include="K4os.Compression.LZ4.Streams, Version=1.3.8.0, Culture=neutral, PublicKeyToken=2186fa9121ef231d, processorArchitecture=MSIL">
<HintPath>..\packages\K4os.Compression.LZ4.Streams.1.3.8\lib\net462\K4os.Compression.LZ4.Streams.dll</HintPath>
</Reference>
<Reference Include="K4os.Hash.xxHash, Version=1.0.8.0, Culture=neutral, PublicKeyToken=32cd54395057cec3, processorArchitecture=MSIL">
<HintPath>..\packages\K4os.Hash.xxHash.1.0.8\lib\net462\K4os.Hash.xxHash.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=7.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Logging.Abstractions.7.0.1\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
</Reference>
<Reference Include="MySqlConnector, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d33d3e53aa5f8c92, processorArchitecture=MSIL">
<HintPath>..\packages\MySqlConnector.2.3.7\lib\net48\MySqlConnector.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="RestSharp, Version=111.4.1.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
<HintPath>..\packages\RestSharp.111.4.1\lib\net48\RestSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Configuration" />
<Reference Include="System.Configuration.ConfigurationManager, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Configuration.ConfigurationManager.8.0.0\lib\net462\System.Configuration.ConfigurationManager.dll</HintPath>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Diagnostics.DiagnosticSource, Version=8.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Diagnostics.DiagnosticSource.8.0.1\lib\net462\System.Diagnostics.DiagnosticSource.dll</HintPath>
</Reference>
<Reference Include="System.IO.Pipelines, Version=5.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.IO.Pipelines.5.0.2\lib\net461\System.IO.Pipelines.dll</HintPath>
</Reference>
<Reference Include="System.Management" />
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Text.Encodings.Web, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Encodings.Web.8.0.0\lib\net462\System.Text.Encodings.Web.dll</HintPath>
</Reference>
<Reference Include="System.Text.Json, Version=8.0.0.4, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Json.8.0.4\lib\net462\System.Text.Json.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Transactions" />
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="ZstdSharp, Version=0.8.0.0, Culture=neutral, PublicKeyToken=8d151af33a4ad5cf, processorArchitecture=MSIL">
<HintPath>..\packages\ZstdSharp.Port.0.8.0\lib\net462\ZstdSharp.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="JSON\AHDump.cs" />
<Compile Include="JSON\AHUrl.cs" />
<Compile Include="JSON\GenSpecial.cs" />
<Compile Include="JSON\IndexGen.cs" />
<Compile Include="JSON\Settings.cs" />
<Compile Include="JSON\Token.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utilities\DB.cs" />
<Compile Include="Utilities\IO.cs" />
<Compile Include="Utilities\MSG.cs" />
<Compile Include="Utilities\OAuth.cs" />
<Compile Include="Utilities\Web.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

159
MxWDB/Program.cs Normal file
View File

@ -0,0 +1,159 @@
//// MxWDB
//// 1st Gen MxW Database Generator
//// BY MIKX
//// https://mxgit.ovh/mikx/MxWDB
//// https://dev.mxwow.ovh
//// License: GNU General Public License 3.0
using MxWDB.JSON;
using MxWDB.Utilities;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
namespace MxWDB
{
internal class Program
{
public static string version = "1.0.0_WoW11.0";
public static int line = 0;
public static bool serverloop = true;
public static string state = "init";
public static string oauth_token = "";
static void Main(string[] args)
{
//// Main Server Loop
while (serverloop)
{
switch (state)
{
case "init":
MSG.Splash();
if (IO.FirstRun())
{
IO.CreateDirectory("json");
IO.CreateDirectory("logs");
MSG.CMW($"[{state}] Initializing the ecosystem...", true, 1);
MSG.CMW($"[{state}] Open \"json/settings.json\" and edit it with your own informations.", true, 1);
MSG.CMW($"[{state}] Press any key to exit...", true, 1);
serverloop = false;
Console.ReadKey();
} else
{
if (IO.SettingsValid())
{
MSG.CMW($"[{state}] Your Settings appears to be valid.", true, 2);
MSG.CMW($"[{state}] DBHost: {JSON.Settings.GetDBHost()}", true, 2);
MSG.CMW($"[{state}] DBPort: {JSON.Settings.GetDBPort()}", true, 2);
MSG.CMW($"[{state}] DBName: {JSON.Settings.GetDBName()}", true, 2);
MSG.CMW($"[{state}] DBUser: {JSON.Settings.GetDBUser()}", true, 2);
MSG.CMW($"[{state}] Region: {JSON.Settings.GetRegion()}", true, 2);
MSG.CMW($"[{state}] RealmID: {JSON.Settings.GetRID()}", true, 2);
state = "oauth";
} else
{
MSG.CMW($"[{state}] Your Settings appears to be invalid.", true, 3);
MSG.CMW($"[{state}] Open \"json/settings.json\" and edit it with your own informations.", true, 3);
MSG.CMW($"[{state}] Press any key to exit...", true, 3);
serverloop = false;
Console.ReadKey();
}
}
break;
case "oauth":
MSG.CMW($"[{state}] Getting an access token from BNET...", true, 1);
oauth_token = OAuth.GetAccessToken(JSON.Settings.GetAPIKey(), JSON.Settings.GetAPISecret());
MSG.CMW($"[{state}] Access Token: {oauth_token}.", true, 2);
if (args.Contains("--token")) { state = "token"; } else { state = "dump"; }
break;
/// ARGS - WoW Token
case "token":
MSG.CMW($"[{state}] Getting the latest Token info from BNET...", true, 1);
Token.GetToken(oauth_token);
int v = JsonConvert.DeserializeObject<Token.Root>(File.ReadAllText("json/token.json")).price;
DB.UpdateTokenValue(v);
int copper = v % 100;
v = (v - copper) / 100;
int silver = v % 100;
int gold = (v - silver) / 100;
MSG.CMW($"[{state}] WoW Token from region {Settings.GetRegion()} is worth {gold}g.", true, 1);
serverloop =false;
break;
case "dump":
if (!JSON.Settings.GetDebug())
{
MSG.CMW($"[{state}] Downloading the latest AH dump from BNet...", true, 1);
JSON.AHUrl.GetDump(JSON.Settings.GetAPIKey(), JSON.Settings.GetAPISecret(), oauth_token);
MSG.CMW($"[{state}] Downloading the latest AH Commodities dump from BNet...", true, 1);
JSON.AHUrl.GetDumpCom(JSON.Settings.GetAPIKey(), JSON.Settings.GetAPISecret(), oauth_token);
if (IO.FileIsDownloaded("json/ah.dump.json") && IO.FileIsDownloaded("json/ah.com.dump.json"))
{
MSG.CMW($"[{state}] Both Dump appears to be correctly downloaded.", true, 2);
state = "checkdb";
}
else
{
MSG.CMW($"[{state}] One or both of the dump failed to download. Retrying in 10 seconds...", true, 3);
Thread.Sleep(10000);
state = "dump";
}
} else
{
MSG.CMW($"[{state}] Debug Enabled. Skipping Dump.", true, 2);
state = "checkdb";
}
break;
case "checkdb":
MSG.CMW($"[{state}] Checking if we can connect to the DB...", true, 1);
if (DB.DatabaseConnected())
{
MSG.CMW($"[{state}] We can connect to the DB.", true, 2);
MSG.CMW($"[{state}] Cleaning the DB...", true, 1);
DB.CleanDB();
state = "genintable";
} else
{
MSG.CMW($"[{state}] We can't connect to the DB.", true, 3);
MSG.CMW($"[{state}] Open \"json/settings.json\" and edit the DB informations.", true, 3);
MSG.CMW($"[{state}] Press any key to exit...", true, 3);
serverloop = false;
Console.ReadKey();
}
break;
case "genintable":
MSG.CMW($"[{state}] Generating the internal table from Auctions Data...", true, 1);
JSON.AHDump.GenTable();
MSG.CMW($"[{state}] Generating the internal table from Commodities Data...", true, 1);
JSON.AHDump.GenTableCom();
state = "gendbtable";
break;
case "gendbtable":
MSG.CMW($"[{state}] Generating the DB tables from Auctions Data...", true, 1);
DB.GenItemsTable();
DB.GenListingTable();
MSG.CMW($"[{state}] Generating the DB tables from Commodities Data...", true, 1);
DB.GenItemsTableCom();
DB.GenListingTableCom();
state = "genweb";
break;
case "genweb":
MSG.CMW($"[{state}] Generating the Index Table...", true, 1);
JSON.IndexGen.GenIndex("json/index.json");
MSG.CMW($"[{state}] Generating the Special Table...", true, 1);
JSON.SpecialGen.GenSpecial("json/special.json");
serverloop=false;
break;
}
}
}
}
}

View File

@ -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("MxWDB")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MxWDB")]
[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("2a1363e5-1109-45ef-8cde-dbcaad71189b")]
// 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")]

516
MxWDB/Utilities/DB.cs Normal file
View File

@ -0,0 +1,516 @@
using MxWDB.JSON;
using MySqlConnector;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Web.Management;
using System.Xml.Serialization;
using static MxWDB.JSON.AHDump;
namespace MxWDB.Utilities
{
[XmlRoot(ElementName = "quality")]
public class XMLQuality
{
[XmlAttribute(AttributeName = "id")]
public int Id { get; set; }
[XmlText]
public string Text { get; set; }
}
public class Appearance
{
public Key key { get; set; }
public int id { get; set; }
}
public class AttackSpeed
{
public int value { get; set; }
public string display_string { get; set; }
}
public class Binding
{
public string type { get; set; }
public string name { get; set; }
}
public class Color
{
public int r { get; set; }
public int g { get; set; }
public int b { get; set; }
public double a { get; set; }
}
public class Damage
{
public int min_value { get; set; }
public int max_value { get; set; }
public string display_string { get; set; }
public DamageClass damage_class { get; set; }
}
public class DamageClass
{
public string type { get; set; }
public string name { get; set; }
}
public class Display
{
public string display_string { get; set; }
public Color color { get; set; }
}
public class DisplayStrings
{
public string header { get; set; }
public string gold { get; set; }
public string silver { get; set; }
public string copper { get; set; }
}
public class Dps
{
public double value { get; set; }
public string display_string { get; set; }
}
public class Durability
{
public int value { get; set; }
public string display_string { get; set; }
}
public class InventoryType
{
public string type { get; set; }
public string name { get; set; }
}
public class Item
{
public Key key { get; set; }
public int id { get; set; }
}
public class ItemClass
{
public Key key { get; set; }
public string name { get; set; }
public int id { get; set; }
}
public class ItemSubclass
{
public Key key { get; set; }
public string name { get; set; }
public int id { get; set; }
}
public class Key
{
public string href { get; set; }
}
public class Level
{
public int value { get; set; }
public string display_string { get; set; }
}
public class Links
{
public Self self { get; set; }
}
public class Media
{
public Key key { get; set; }
public int id { get; set; }
}
public class PreviewItem
{
public Item item { get; set; }
public int context { get; set; }
public List<int> bonus_list { get; set; }
public Quality quality { get; set; }
public string name { get; set; }
public Media media { get; set; }
public ItemClass item_class { get; set; }
public ItemSubclass item_subclass { get; set; }
public InventoryType inventory_type { get; set; }
public Binding binding { get; set; }
public Weapon weapon { get; set; }
public List<Stat> stats { get; set; }
public SellPrice sell_price { get; set; }
public Requirements requirements { get; set; }
public Level level { get; set; }
public Durability durability { get; set; }
}
public class Quality
{
public string type { get; set; }
public string name { get; set; }
}
public class Requirements
{
public Level level { get; set; }
}
public class Root
{
public Links _links { get; set; }
public int id { get; set; }
public string name { get; set; }
public Quality quality { get; set; }
public int level { get; set; }
public int required_level { get; set; }
public Media media { get; set; }
public ItemClass item_class { get; set; }
public ItemSubclass item_subclass { get; set; }
public InventoryType inventory_type { get; set; }
public int purchase_price { get; set; }
public int sell_price { get; set; }
public int max_count { get; set; }
public bool is_equippable { get; set; }
public bool is_stackable { get; set; }
public PreviewItem preview_item { get; set; }
public int purchase_quantity { get; set; }
public List<Appearance> appearances { get; set; }
}
public class Self
{
public string href { get; set; }
}
public class SellPrice
{
public int value { get; set; }
public DisplayStrings display_strings { get; set; }
}
public class Stat
{
public Type type { get; set; }
public int value { get; set; }
public bool is_negated { get; set; }
public Display display { get; set; }
}
public class Type
{
public string type { get; set; }
public string name { get; set; }
}
public class Weapon
{
public Damage damage { get; set; }
public AttackSpeed attack_speed { get; set; }
public Dps dps { get; set; }
}
internal class DB
{
public static MySqlConnection ItemDB()
{
MySqlConnection conn;
string myConnectionString;
myConnectionString = string.Format("server={0};port={1};uid={2};pwd={3};database={4};", JSON.Settings.GetDBHost(), JSON.Settings.GetDBPort(), JSON.Settings.GetDBUser(), JSON.Settings.GetDBPass(), JSON.Settings.GetDBName());
conn = new MySqlConnection();
conn.ConnectionString = myConnectionString;
return conn;
}
public static bool DatabaseConnected()
{
MySqlConnection mcc = ItemDB();
try
{
mcc.Open();
var temp = mcc.State.ToString();
MSG.CMW(temp, true,4);
if (mcc.State == ConnectionState.Open && temp == "Open")
{
mcc.Close();
return true;
}
else
{
return false;
}
}
catch (MySqlException ex)
{
MSG.CMW($"[db] {ex.Message}", true, 3);
return false;
}
}
public static void GenItemsTable()
{
string stm = "SELECT * FROM items";
MySqlConnection mc = ItemDB();
MySqlCommand cmd = new MySqlCommand(stm, mc);
mc.Open();
DataTable data = new DataTable();
data.Load(cmd.ExecuteReader());
using (MySqlConnection mcc = ItemDB())
{
StringBuilder sCommand = new StringBuilder("INSERT INTO ah_items (itemid,maximum,median,minimum,quantity) VALUES ");
List<string> Rows = new List<string>();
DataRow[] result = JSON.AHDump.aucds.Tables["auclist"].Select("iid is not null");
foreach (DataRow row in data.Rows)
{
Int64 median = 0;
Int64 maximum = 0;
Int64 minimum = 0;
int i = Convert.ToInt32(row["id"]);
int ie = JSON.AHDump.aucds.Tables[0].Select(string.Format("iid = '{0}'", i)).Length;
if (ie >= 1)
{
if (JSON.AHDump.aucds.Tables["auclist"].Compute("AVG(uv)", string.Format("iid = '{0}'", i)) != DBNull.Value)
{
median = Convert.ToInt64(JSON.AHDump.aucds.Tables["auclist"].Compute("AVG(uv)", string.Format("iid = '{0}'", i)));
}
if (JSON.AHDump.aucds.Tables["auclist"].Compute("MAX(uv)", string.Format("iid = '{0}'", i)) != DBNull.Value)
{
maximum = Convert.ToInt64(JSON.AHDump.aucds.Tables["auclist"].Compute("MAX(uv)", string.Format("iid = '{0}'", i)));
}
if (JSON.AHDump.aucds.Tables["auclist"].Compute("MIN(uv)", string.Format("iid = '{0}'", i)) != DBNull.Value)
{
minimum = Convert.ToInt64(JSON.AHDump.aucds.Tables["auclist"].Compute("MIN(uv)", string.Format("iid = '{0}'", i)));
}
int qty = JSON.AHDump.aucds.Tables["auclist"].Select(string.Format("iid = '{0}'", i)).Length;
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", i, maximum, median, minimum, qty));
}
}
sCommand.Append(string.Join(",", Rows));
sCommand.Append(";");
mcc.Open();
using (MySqlCommand myCmd = new MySqlCommand(sCommand.ToString(), mcc))
{
myCmd.CommandType = CommandType.Text;
myCmd.ExecuteNonQuery();
}
}
}
public static void GenItemsTableCom()
{
using (MySqlConnection mcc = ItemDB())
{
StringBuilder sCommand = new StringBuilder("INSERT INTO ah_items (itemid,maximum,median,minimum,quantity) VALUES ");
List<string> Rows = new List<string>();
DataRow[] result = JSON.AHDump.aucdscom.Tables["auclistcom"].Select("iid is not null");
for (int il = 1; il < 300000; il++)
{
Int64 median = 0;
Int64 maximum = 0;
Int64 minimum = 0;
int ie = JSON.AHDump.aucdscom.Tables[0].Select(string.Format("iid = '{0}'", il)).Length;
if (ie >= 1)
{
if (JSON.AHDump.aucdscom.Tables["auclistcom"].Compute("AVG(uv)", string.Format("iid = '{0}'", il)) != DBNull.Value)
{
median = Convert.ToInt64(JSON.AHDump.aucdscom.Tables["auclistcom"].Compute("AVG(uv)", string.Format("iid = '{0}'", il)));
}
if (JSON.AHDump.aucdscom.Tables["auclistcom"].Compute("MAX(uv)", string.Format("iid = '{0}'", il)) != DBNull.Value)
{
maximum = Convert.ToInt64(JSON.AHDump.aucdscom.Tables["auclistcom"].Compute("MAX(uv)", string.Format("iid = '{0}'", il)));
}
if (JSON.AHDump.aucdscom.Tables["auclistcom"].Compute("MIN(uv)", string.Format("iid = '{0}'", il)) != DBNull.Value)
{
minimum = Convert.ToInt64(JSON.AHDump.aucdscom.Tables["auclistcom"].Compute("MIN(uv)", string.Format("iid = '{0}'", il)));
}
int qty = JSON.AHDump.aucdscom.Tables["auclistcom"].Select(string.Format("iid = '{0}'", il)).Length;
Rows.Add(string.Format("('{0}','{1}','{2}','{3}','{4}')", il, maximum, median, minimum, qty));
}
}
sCommand.Append(string.Join(",", Rows));
sCommand.Append(";");
mcc.Open();
using (MySqlCommand myCmd = new MySqlCommand(sCommand.ToString(), mcc))
{
myCmd.CommandType = CommandType.Text;
myCmd.ExecuteNonQuery();
}
}
}
public static void GenListingTable()
{
using (MySqlConnection mcc = ItemDB())
{
StringBuilder sCommand = new StringBuilder("INSERT INTO ah_listing (itemid,quantity,uvalue,tvalue) VALUES ");
List<string> Rows = new List<string>();
DataRow[] result = JSON.AHDump.aucds.Tables["auclist"].Select("iid is not null");
foreach (DataRow alr in result)
{
Int64 uvalue = 0;
Int64 tvalue = 0;
int i = Convert.ToInt32(alr["iid"]);
int quantity = Convert.ToInt32(alr["qty"]);
if (alr["uv"] != DBNull.Value)
{
uvalue = Convert.ToInt64(alr["uv"]);
tvalue = Convert.ToInt64(alr["uv"]) * Convert.ToInt64(alr["qty"]);
}
Rows.Add(string.Format("('{0}','{1}','{2}','{3}')", i, quantity, uvalue, tvalue));
}
sCommand.Append(string.Join(",", Rows));
sCommand.Append(";");
mcc.Open();
using (MySqlCommand myCmd = new MySqlCommand(sCommand.ToString(), mcc))
{
myCmd.CommandType = CommandType.Text;
myCmd.ExecuteNonQuery();
}
}
}
public static void GenListingTableCom()
{
using (MySqlConnection mcc = ItemDB())
{
StringBuilder sCommand = new StringBuilder("INSERT INTO ah_listing (itemid,quantity,uvalue,tvalue) VALUES ");
List<string> Rows = new List<string>();
DataRow[] result = JSON.AHDump.aucdscom.Tables["auclistcom"].Select("iid is not null");
foreach (DataRow alr in result)
{
Int64 uvalue = 0;
Int64 tvalue = 0;
int i = Convert.ToInt32(alr["iid"]);
int quantity = Convert.ToInt32(alr["qty"]);
if (alr["uv"] != DBNull.Value)
{
uvalue = Convert.ToInt64(alr["uv"]);
tvalue = Convert.ToInt64(alr["uv"]) * Convert.ToInt64(alr["qty"]);
}
Rows.Add(string.Format("('{0}','{1}','{2}','{3}')", i, quantity, uvalue, tvalue));
}
sCommand.Append(string.Join(",", Rows));
sCommand.Append(";");
mcc.Open();
using (MySqlCommand myCmd = new MySqlCommand(sCommand.ToString(), mcc))
{
myCmd.CommandType = CommandType.Text;
myCmd.ExecuteNonQuery();
}
}
}
public static bool CheckItemInfoExists(int id)
{
MySqlConnection con = ItemDB();
string cmdText = $"SELECT * FROM items WHERE id = '{id}'";
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 void GenItemInfo(int id)
{
int itemrarity = 0;
if (!File.Exists($"json/items/{id}.json"))
{
using (WebClient wc = new WebClient())
{
ServicePointManager.ServerCertificateValidationCallback += (p1, p2, p3, p4) => true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Web.DownloadFileNoAsync($"https://www.wowhead.com/classic/item={id}&xml", $"xml/items/{id}.xml");
}
XmlSerializer serializer = new XmlSerializer(typeof(XMLQuality));
using (StreamReader reader = new StreamReader($"xml/items/{id}.xml"))
{
itemrarity = Convert.ToInt32((XMLQuality)serializer.Deserialize(reader));
}
if (itemrarity > 0)
{
MSG.CMW($"[db] Item \"{id}\" doesn't exists in our Item Info table. We will add it.", true, 4);
using (WebClient wc = new WebClient())
{
ServicePointManager.ServerCertificateValidationCallback += (p1, p2, p3, p4) => true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Web.DownloadFileNoAsync($"https://us.api.blizzard.com/data/wow/item/{id}?namespace=static-us&locale=fr_FR&access_token={Program.oauth_token}", $"json/items/{id}.json");
}
}
} else
{
Root ij = JsonConvert.DeserializeObject<Root>($"json/items/{id}.json");
string name = ij.name;
MSG.CMW($"[db] {name}", true, 4);
}
}
public static void CleanDB()
{
string stm2 = string.Format("DELETE FROM ah_items");
MySqlConnection mc2 = ItemDB();
MySqlCommand cmd2 = new MySqlCommand(stm2, mc2);
mc2.Open();
cmd2.ExecuteNonQuery();
mc2.Close();
string stm3 = string.Format("DELETE FROM ah_listing");
MySqlConnection mc3 = ItemDB();
MySqlCommand cmd3 = new MySqlCommand(stm3, mc3);
mc3.Open();
cmd3.ExecuteNonQuery();
mc3.Close();
string stm5 = string.Format("DELETE FROM ah_index");
MySqlConnection mc5 = ItemDB();
MySqlCommand cmd5 = new MySqlCommand(stm5, mc5);
mc5.Open();
cmd5.ExecuteNonQuery();
mc5.Close();
string stm6 = string.Format("DELETE FROM ah_special_data");
MySqlConnection mc6 = ItemDB();
MySqlCommand cmd6 = new MySqlCommand(stm6, mc6);
mc6.Open();
cmd6.ExecuteNonQuery();
mc6.Close();
}
public static void UpdateTokenValue(int v)
{
string stm2 = string.Format($"DELETE FROM mxw_token WHERE region='{Settings.GetRegion()}'");
MySqlConnection mc2 = ItemDB();
MySqlCommand cmd2 = new MySqlCommand(stm2, mc2);
mc2.Open();
cmd2.ExecuteNonQuery();
mc2.Close();
using (MySqlConnection mcc = ItemDB())
{
StringBuilder sCommand = new StringBuilder($"INSERT INTO mxw_token (region,value) VALUES ('{Settings.GetRegion()}','{v}')");
mcc.Open();
using (MySqlCommand myCmd = new MySqlCommand(sCommand.ToString(), mcc))
{
myCmd.CommandType = CommandType.Text;
myCmd.ExecuteNonQuery();
}
}
}
}
}

75
MxWDB/Utilities/IO.cs Normal file
View File

@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MxWDB.Utilities
{
internal class IO
{
/// <summary>
/// Create a directory at the specified path.
/// </summary>
/// <param name="path">The path where to create a new directory.</param>
/// <returns></returns>
public static void CreateDirectory(string path)
{
Directory.CreateDirectory(path);
}
///<summary>
///Check by manipulating/scanning the disk if MxWDB is ran for the first time.
///</summary>
public static bool FirstRun()
{
if (Directory.Exists("json"))
{
return false;
} else
{
return true;
}
}
///<summary>
///Check if the settings json is valid.
///</summary>
public static bool SettingsValid()
{
if (JSON.Settings.GetAPIKey() == "" || JSON.Settings.GetAPISecret() == "" || JSON.Settings.GetRegion() == "" || JSON.Settings.GetRID() == 0 || JSON.Settings.GetDBName() == "" || JSON.Settings.GetDBHost() == "" || JSON.Settings.GetDBPort() == "" || JSON.Settings.GetDBName() == "" || JSON.Settings.GetDBUser() == "" || JSON.Settings.GetDBPass() == "")
{
return false;
}
else
{
return true;
}
}
/// <summary>
/// Check if a file has been correctly downloaded.
/// </summary>
/// <param name="path">The path to the file.</param>
/// <returns></returns>
public static bool FileIsDownloaded(string path)
{
if (File.Exists(path))
{
long lenght = new FileInfo(path).Length;
if (lenght > 0)
{
return true;
} else
{
return false;
}
}
else
{
return false;
}
}
}
}

96
MxWDB/Utilities/MSG.cs Normal file
View File

@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MxWDB.Utilities
{
class MSG
{
public static void CMW(string msg, bool time, int color)
{
Program.line++;
string seconds = "";
string minutes = "";
string hours = "";
if (DateTime.Now.Second < 10)
{
seconds = String.Format("0{0}", DateTime.Now.Second);
}
else
{
seconds = DateTime.Now.Second.ToString();
}
if (DateTime.Now.Minute < 10)
{
minutes = String.Format("0{0}", DateTime.Now.Minute);
}
else
{
minutes = DateTime.Now.Minute.ToString();
}
if (DateTime.Now.Hour < 10)
{
hours = String.Format("0{0}", DateTime.Now.Hour);
}
else
{
hours = DateTime.Now.Hour.ToString();
}
string date = String.Format("{0}:{1}:{2}", hours, minutes, seconds);
File.AppendAllText(@"logs/message.logs", String.Format("[{0}] {1}", date, msg) + Environment.NewLine);
//color switch
ConsoleColor cc = ConsoleColor.White;
switch (color)
{
case 0:
//nothing
break;
case 1:
cc = ConsoleColor.Cyan;
break;
case 2:
cc = ConsoleColor.Green;
break;
case 3:
cc = ConsoleColor.Red;
break;
case 4:
cc = ConsoleColor.Yellow;
break;
}
if (time)
{
Console.ForegroundColor = cc;
Console.WriteLine(String.Format("[{0}] {1}", date, msg));
}
else
{
Console.ForegroundColor = cc;
Console.WriteLine(String.Format(""));
}
Console.ForegroundColor = ConsoleColor.White;
}
public static void Splash()
{
Program.line = Program.line + 4;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("");
Console.WriteLine("#### MxWDB");
Console.WriteLine(string.Format("#### VERSION: {0}", Program.version));
Console.WriteLine("#### DEV: mikx");
Console.WriteLine("");
Console.ForegroundColor = ConsoleColor.White;
}
}
}

52
MxWDB/Utilities/OAuth.cs Normal file
View File

@ -0,0 +1,52 @@
using Google.Protobuf.WellKnownTypes;
using Newtonsoft.Json;
using Org.BouncyCastle.Asn1.Cmp;
using Org.BouncyCastle.Asn1.Crmf;
using Org.BouncyCastle.Asn1.Ocsp;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace MxWDB.Utilities
{
class OAuth
{
public class OAuthRoot
{
public string access_token { get; set; }
}
/// <summary>
/// Get an access token from BNET using a registered application Client ID and Secret ID.
/// </summary>
/// <param name="key">Your registered application Client ID.</param>
/// <param name="secret">Your registered application Secret ID.</param>
/// <returns></returns>
public static string GetAccessToken(string key, string secret)
{
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
RestClient client = new RestClient($"https://{JSON.Settings.GetRegion()}.battle.net/oauth/token");
var request = new RestRequest
{
Method = RestSharp.Method.Post
};
var by = Encoding.UTF8.GetBytes($"{key}:{secret}");
var b64 = Convert.ToBase64String(by);
request.AddParameter("grant_type", "client_credentials");
request.AddHeader("Authorization", $"Basic {b64}");
request.AddHeader("Content-type", "application/x-www-form-urlencoded");
RestResponse response = client.Execute(request);
var tokenResponse = JsonConvert.DeserializeObject<OAuthRoot>(response.Content);
return tokenResponse.access_token;
}
}
}

60
MxWDB/Utilities/Web.cs Normal file
View File

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace MxWDB.Utilities
{
class Web
{
public static void DownloadFileAsync(string url, string file)
{
using (WebClient wc = new WebClient())
{
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
wc.DownloadProgressChanged += DownloadProgressChanged;
var syncObject = new object();
lock (syncObject)
{
Uri uri = new Uri(url);
wc.DownloadFileAsync(uri, file);
Monitor.Wait(syncObject);
}
}
}
private static void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
Console.SetCursorPosition(0, Program.line+4);
Console.Write($"DL: ");
Console.SetCursorPosition(3, Program.line + 4);
Console.Write($"{e.BytesReceived/1024}");
}
public static void DownloadFileNoAsync(string url, string file)
{
using (WebClient wc = new WebClient())
{
try
{
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
Uri uri = new Uri(url);
wc.DownloadFile(uri, file);
}
catch (WebException ex)
{
MSG.CMW($"[web] {ex.Message}", true, 3);
MSG.CMW($"[web] URL: {url}", true, 3);
}
catch (Exception ex)
{
MSG.CMW($"[web] {ex.Message}", true, 3);
}
}
}
}
}

25
MxWDB/packages.config Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="BouncyCastle.Cryptography" version="2.3.1" targetFramework="net481" />
<package id="Google.Protobuf" version="3.26.1" targetFramework="net481" />
<package id="K4os.Compression.LZ4" version="1.3.8" targetFramework="net481" />
<package id="K4os.Compression.LZ4.Streams" version="1.3.8" targetFramework="net481" />
<package id="K4os.Hash.xxHash" version="1.0.8" targetFramework="net481" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="8.0.0" targetFramework="net481" />
<package id="Microsoft.Extensions.Logging.Abstractions" version="7.0.1" targetFramework="net481" />
<package id="MySqlConnector" version="2.3.7" targetFramework="net481" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net481" />
<package id="RestSharp" version="111.4.1" targetFramework="net481" />
<package id="System.Buffers" version="4.5.1" targetFramework="net481" />
<package id="System.Configuration.ConfigurationManager" version="8.0.0" targetFramework="net481" />
<package id="System.Diagnostics.DiagnosticSource" version="8.0.1" targetFramework="net481" />
<package id="System.IO.Pipelines" version="5.0.2" targetFramework="net481" />
<package id="System.Memory" version="4.5.5" targetFramework="net481" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net481" />
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net481" />
<package id="System.Text.Encodings.Web" version="8.0.0" targetFramework="net481" />
<package id="System.Text.Json" version="8.0.4" targetFramework="net481" />
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net481" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net481" />
<package id="ZstdSharp.Port" version="0.8.0" targetFramework="net481" />
</packages>

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# MxWDB
World of Warcraft AH & Simulation Website Backend.