diff --git a/SplinterTools/Helpers/SplinterData.cs b/SplinterTools/Helpers/SpDataHelper.cs similarity index 84% rename from SplinterTools/Helpers/SplinterData.cs rename to SplinterTools/Helpers/SpDataHelper.cs index 3452ff3..8baaa0c 100644 --- a/SplinterTools/Helpers/SplinterData.cs +++ b/SplinterTools/Helpers/SpDataHelper.cs @@ -2,7 +2,7 @@ namespace SplinterTools.Helpers { - public static class SplinterData + public static class SpDataHelper { public static SplinterlandsSetting splinterlandsSetting = new(); public static BattlesModel battles = new(); diff --git a/SplinterTools/MainWindow.xaml b/SplinterTools/MainWindow.xaml index 9cbe513..bd24ae1 100644 --- a/SplinterTools/MainWindow.xaml +++ b/SplinterTools/MainWindow.xaml @@ -142,12 +142,12 @@ Width="100" > - 10 (sec) - 30 (sec) - 1 (min) - 5 (min) - 10 (min) - + 1 (min) + 5 (min) + 10 (min) + 30 (min) + 1 (hour) + diff --git a/SplinterTools/MainWindow.xaml.cs b/SplinterTools/MainWindow.xaml.cs index 7ea6574..63b0458 100644 --- a/SplinterTools/MainWindow.xaml.cs +++ b/SplinterTools/MainWindow.xaml.cs @@ -1,4 +1,5 @@  +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; @@ -6,63 +7,53 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; -using System.Windows.Media; using System.Windows.Threading; - namespace SplinterTools { - /// - /// Interaction logic for MainWindow.xaml - /// + public partial class MainWindow : Window { - public string fileOfReportInXML = Directory.GetCurrentDirectory() + "/Files/AppConfig.json"; - public string warningMessageTotal = ""; public string sentWhatsUpMessage = ""; - public DispatcherTimer dispatcherTimer = new(); public int TestValue; - public Boolean enableWhatsup = false; - - public MainWindow() { InitializeComponent(); ApiHelper.InitializeClient(); } - public void Window_Loaded(object sender, RoutedEventArgs e) { - Helpers.SplinterData.splinterlandsSetting = Task.Run(() => new Processors.Splinterlands().GetSplinterlandsSetting()).Result; + bool checkSecurity = Processors.MessageProcessor.CheckSecurityDetails(); + + if (checkSecurity) + { + BtnEnableWhatsUp.IsEnabled = false; + }; + + + Helpers.SpDataHelper.splinterlandsSetting = Task.Run(() => new Processors.SplinterProcessor().LoadSplinterlandsSetting()).Result; GetSplinterData(0); } List UserModelList = new List(); - - public async void GetSplinterData(int testr) { - - - + var accountDetails = Processors.AccountDetailsProcessor.LoadAccountsObject(); - UserModelList.Clear(); - - for (int i = 0; i < accountDetails.Count; i++) { @@ -75,8 +66,8 @@ public async void GetSplinterData(int testr) var RentalInfo = await Processors.SplinterProcessor.LoadRentalInformation(accountDetails[i].AccName); - int baseRshares = Helpers.SplinterData.splinterlandsSetting.loot_chests.quest[QuestInfo[0].chest_tier].@base; - double multiplier = Helpers.SplinterData.splinterlandsSetting.loot_chests.quest[QuestInfo[0].chest_tier].step_multiplier; + int baseRshares = Helpers.SpDataHelper.splinterlandsSetting.loot_chests.quest[QuestInfo[0].chest_tier].@base; + double multiplier = Helpers.SpDataHelper.splinterlandsSetting.loot_chests.quest[QuestInfo[0].chest_tier].step_multiplier; int chests = 0; int fp_limit = baseRshares; @@ -87,59 +78,48 @@ public async void GetSplinterData(int testr) fp_limit = Convert.ToInt32(baseRshares + fp_limit * multiplier); } - - - string leagueWildName = Helpers.SplinterData.splinterlandsSetting.leagues.modern[SplinterInfo.league].name; - string leagueModernName = Helpers.SplinterData.splinterlandsSetting.leagues.modern[SplinterInfo.modern_league].name; - string splinter = Helpers.SplinterData.splinterlandsSetting.daily_quests.Where(x => x.active == true && x.name == QuestInfo[0].name).FirstOrDefault().data.value; + string leagueWildName = Helpers.SpDataHelper.splinterlandsSetting.leagues.modern[SplinterInfo.league].name; + string leagueModernName = Helpers.SpDataHelper.splinterlandsSetting.leagues.modern[SplinterInfo.modern_league].name; + string splinter = Helpers.SpDataHelper.splinterlandsSetting.daily_quests.Where(x => x.active == true && x.name == QuestInfo[0].name).FirstOrDefault().data.value; string questItems = QuestInfo[0].completed_items.ToString(); - - //Last 50 Matches Win rate modern - - Helpers.SplinterData.battles = Task.Run(() => new Processors.Splinterlands().GetRateSetting(accountDetails[i].AccName, "modern")).Result; + Helpers.SpDataHelper.battles = Task.Run(() => new Processors.SplinterProcessor().LoadBattleHiistory(accountDetails[i].AccName, "modern")).Result; int totalmodernWins = 0; - int totalmoderngames = Helpers.SplinterData.battles.battles.Length; + int totalmoderngames = Helpers.SpDataHelper.battles.battles.Length; - - if (Helpers.SplinterData.battles != null) + if (Helpers.SpDataHelper.battles != null) { for (int it = 0; it < totalmoderngames; it++) { - if (Helpers.SplinterData.battles.battles[it].winner == accountDetails[i].AccName) + if (Helpers.SpDataHelper.battles.battles[it].winner == accountDetails[i].AccName) { totalmodernWins++; } } } - //Last 50 Matches Win rate wild - - Helpers.SplinterData.battles = Task.Run(() => new Processors.Splinterlands().GetRateSetting(accountDetails[i].AccName, "wild")).Result; + Helpers.SpDataHelper.battles = Task.Run(() => new Processors.SplinterProcessor().LoadBattleHiistory(accountDetails[i].AccName, "wild")).Result; int totalWildnWins = 0; - int totalWildgames = Helpers.SplinterData.battles.battles.Length; + int totalWildgames = Helpers.SpDataHelper.battles.battles.Length; - - if (Helpers.SplinterData.battles != null) + if (Helpers.SpDataHelper.battles != null) { for (int it = 0; it < totalWildgames; it++) { - if (Helpers.SplinterData.battles.battles[it].winner == accountDetails[i].AccName) + if (Helpers.SpDataHelper.battles.battles[it].winner == accountDetails[i].AccName) { totalWildnWins++; } } } - - //rental check int rentCancelNumber = 0; @@ -149,16 +129,11 @@ public async void GetSplinterData(int testr) { if (RentalInfo[it].cancel_date != null) { - //System.Diagnostics.Debug.Print(RentalInfo[it].cancel_date.ToString()); - //System.Diagnostics.Debug.Print(it.ToString()); rentCancelNumber++; } } } - - - if (SplinterInfo.collection_power < accountDetails[i].Power) { @@ -187,8 +162,6 @@ public async void GetSplinterData(int testr) warningMessageTotal = warningMessageTotal + SplinterInfo.name + ":\n" + warningMessage + "\n"; } - - OneListItem.Content = new Helpers.UserModel() { RentCancel = rentCancelNumber, @@ -215,16 +188,10 @@ public async void GetSplinterData(int testr) }; - - - - UserModelList.Add(OneListItem); } - - if (warningMessageTotal.Length > 0) { @@ -240,7 +207,6 @@ public async void GetSplinterData(int testr) sentWhatsUpMessage = warningMessageTotal; } - //clear the message warningMessageTotal = ""; @@ -249,12 +215,8 @@ public async void GetSplinterData(int testr) SplinterList.ItemsSource = UserModelList; SplinterList.Items.Refresh(); - } - - - private void BtnRefresh_Click(object sender, RoutedEventArgs e) { sentWhatsUpMessage = ""; @@ -273,17 +235,11 @@ private void BtnRefresh_Click(object sender, RoutedEventArgs e) } - - - - BtnRefresh.IsEnabled = false; cmbRefresh.IsEnabled = false; } - - protected void DispatcherTimer_Tick(object sender, EventArgs e) { TestValue += 1; diff --git a/SplinterTools/Model/SplinterlandsSettings.cs b/SplinterTools/Model/SpSettingsModel.cs similarity index 100% rename from SplinterTools/Model/SplinterlandsSettings.cs rename to SplinterTools/Model/SpSettingsModel.cs diff --git a/SplinterTools/Processors/AccountDetailsProcessor.cs b/SplinterTools/Processors/AccountDetailsProcessor.cs index 2545104..9bb37ea 100644 --- a/SplinterTools/Processors/AccountDetailsProcessor.cs +++ b/SplinterTools/Processors/AccountDetailsProcessor.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.IO; - - namespace SplinterTools.Processors { public class AccountDetailsProcessor @@ -11,14 +9,10 @@ public class AccountDetailsProcessor public static List LoadAccountsObject() { - - string json = Directory.GetCurrentDirectory() + "/Files/AppConfig.json"; var SplinterAccounts = JsonConvert.DeserializeObject>(File.ReadAllText(json)); return SplinterAccounts; - - } public static void updateAccounts(string account, int power) @@ -40,15 +34,6 @@ public static void updateAccounts(string account, int power) jsonData = JsonConvert.SerializeObject(SplinterAccounts); System.IO.File.WriteAllText(json, jsonData); - - - } - - } - - - - } diff --git a/SplinterTools/Processors/MessageProcessor.cs b/SplinterTools/Processors/MessageProcessor.cs index f4c4efb..bc2a8cf 100644 --- a/SplinterTools/Processors/MessageProcessor.cs +++ b/SplinterTools/Processors/MessageProcessor.cs @@ -2,9 +2,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Twilio; using Twilio.Rest.Api.V2010.Account; @@ -22,6 +19,22 @@ public class Security } + public static bool CheckSecurityDetails () + + { + using (StreamReader r = new StreamReader(Directory.GetCurrentDirectory() + "/Files/SecurityConfig.json")) + { + string json = r.ReadToEnd(); + List items = JsonConvert.DeserializeObject>(json); + if (items[0].accountSid == "") + { + return true; + } + + return false; + } + } + public static void SendMessage(string Message) @@ -34,9 +47,14 @@ public static void SendMessage(string Message) string json = r.ReadToEnd(); List items = JsonConvert.DeserializeObject>(json); - TwilioClient.Init(items[0].accountSid, items[0].authToken); - var message = MessageResource.Create(from: new Twilio.Types.PhoneNumber("whatsapp:" + items[0].from), body: Message, to: new Twilio.Types.PhoneNumber("whatsapp:" + items[0].to)); - Console.WriteLine(message.Sid); + if (items[0].accountSid != "") + { + TwilioClient.Init(items[0].accountSid, items[0].authToken); + var message = MessageResource.Create(from: new Twilio.Types.PhoneNumber("whatsapp:" + items[0].from), body: Message, to: new Twilio.Types.PhoneNumber("whatsapp:" + items[0].to)); + Console.WriteLine(message.Sid); + } + + } diff --git a/SplinterTools/Processors/RefreshProcessor.cs b/SplinterTools/Processors/RefreshProcessor.cs index 4f58d4c..5893903 100644 --- a/SplinterTools/Processors/RefreshProcessor.cs +++ b/SplinterTools/Processors/RefreshProcessor.cs @@ -8,35 +8,31 @@ namespace SplinterTools.Processors { public class RefreshProcessor { - - - public static int GetTimerSeconds(int SelectedCmbRefresh) { - int timerTicker = 0; if (SelectedCmbRefresh == 0) { - timerTicker = 10; + timerTicker = 60; } else if (SelectedCmbRefresh == 1) { - timerTicker = 30; + timerTicker = 300; } else if (SelectedCmbRefresh == 2) { - timerTicker = 60; + timerTicker = 600; } else if (SelectedCmbRefresh == 3) { - timerTicker = 300; + timerTicker = 1800; } else if (SelectedCmbRefresh == 4) { - timerTicker = 600; + timerTicker = 3600; } return timerTicker; diff --git a/SplinterTools/Processors/SplinterProcessor.cs b/SplinterTools/Processors/SplinterProcessor.cs index a61030c..2e8699c 100644 --- a/SplinterTools/Processors/SplinterProcessor.cs +++ b/SplinterTools/Processors/SplinterProcessor.cs @@ -1,6 +1,7 @@ using System; using System.Net.Http; using System.Threading.Tasks; +using Newtonsoft.Json; using SplinterTools.Model; @@ -11,6 +12,18 @@ public class SplinterProcessor const string ApiUrl = "https://api2.splinterlands.com"; + + public async Task LoadSplinterlandsSetting() + { + string result = ""; + HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(ApiUrl + "/settings"); + if (response.IsSuccessStatusCode) + { + result = await response.Content.ReadAsStringAsync(); + } + return JsonConvert.DeserializeObject(result); + } + public static async Task LoadSplinterInformation(string Name) { @@ -55,7 +68,6 @@ public static async Task LoadQuestInformation(string Name) public static async Task LoadRentalInformation(string Name) { - string url = ApiUrl + "/market/active_rentals?renter=" + Name + "&offset=0&limit=5000"; using HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(url); @@ -73,26 +85,23 @@ public static async Task LoadRentalInformation(string Name) } } - - public static async Task LoadWinRateInformation(string Name) + public async Task LoadBattleHiistory(string username, string format) { - - - string url = "https://api2.splinterlands.com/battle/history?player=" + Name + "&format=modern"; - - using HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(url); + string result = ""; + HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(ApiUrl + "/battle/history?player=" + username + "&format=" + format); + if (response.IsSuccessStatusCode) { - if (response.IsSuccessStatusCode) - { - BattlesModel[] result = await response.Content.ReadAsAsync(); + result = await response.Content.ReadAsStringAsync(); - return result; - } - else - { - throw new Exception(response.ReasonPhrase); - } } + else + { + throw new Exception(response.ReasonPhrase); + } + return JsonConvert.DeserializeObject(result); } + + + } } diff --git a/SplinterTools/Processors/Splinterlands.cs b/SplinterTools/Processors/Splinterlands.cs deleted file mode 100644 index d022401..0000000 --- a/SplinterTools/Processors/Splinterlands.cs +++ /dev/null @@ -1,105 +0,0 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using SplinterTools.Model; - -using System.Net.Http; -using System.Threading.Tasks; - -namespace SplinterTools.Processors -{ - public class Splinterlands - { - - - const string API_URL = "https://api2.splinterlands.com"; - const string SP_USER_DATA = "/players/details?name="; - const string SP_QUEST_DATA = "/players/quests?username="; - const string SP_CARDS_COLLECTION = "/cards/collection/@@_username_@@?v=@@_timestamp_@@&token=@@_accessToken_@@&username=@@_username_@@"; - const string SP_OUTSTANGING_MATCH = "/players/outstanding_match?username="; - const string SP_AIRDROP_DATA = "/players/sps?v=1638714545572&token=@@_accessToken_@@&username=@@_username_@@"; - const string SP_PlAYER_BALANCE = "/players/balances?username="; - const string SP_CLAIM_SEASON_REWARDS = "/players/login?name=@@_username_@@&ref=&browser_id=@@_browserid_@@&session_id=@@_sessionid_@@&sig=@@_signature_@@&ts=@@_timestamp_@@"; - const string SP_TRANSACTION_DETAILS = "/transactions/lookup?trx_id="; - const string SP_MATCH_DETAILS = "/battle/status?id="; - const string SP_MATCH_ENEMY_PICK = "/players/outstanding_match?username="; - const string SP_MATCH_RESULTS = "/battle/history?player="; - const string SP_ACCESS_TOKEN = "/players/login?name=@@_username_@@&ref=&browser_id=@@_bid_@@&session_id=@@_sid_@@&sig=@@_signature_@@&ts=@@_timestamp_@@"; - const string SP_SPLINTERLANDS_CARDS = "/cards/get_details"; - const string SP_SPLINTERLANDS_SETTINGS = "/settings"; - - public async Task GetSplinterlandsSetting() - { - string result = ""; - HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(API_URL + SP_SPLINTERLANDS_SETTINGS); - if (response.IsSuccessStatusCode) - { - result = await response.Content.ReadAsStringAsync(); - } - return JsonConvert.DeserializeObject(result); - } - - - public async Task GetRateSetting(string username, string format) - { - string result = ""; - HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(API_URL + SP_MATCH_RESULTS + username + "&format=" + format); - if (response.IsSuccessStatusCode) - { - result = await response.Content.ReadAsStringAsync(); - } - return JsonConvert.DeserializeObject(result); - } - - - - - - - public async Task GetUserAccesToken(string username, string bid, string sid, string signature, string ts) - { - string result = ""; - HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(API_URL + SP_ACCESS_TOKEN.Replace("@@_username_@@", username).Replace("@@_bid_@@", bid).Replace("@@_sid_@@", sid).Replace("@@_signature_@@", signature).Replace("@@_timestamp_@@", ts)); - if (response.IsSuccessStatusCode) - { - result = await response.Content.ReadAsStringAsync(); - } - return result; - } - - public async Task GetOutstandingMatch(string username) - { - string result = ""; - - HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(API_URL + SP_OUTSTANGING_MATCH + username); - if (response.IsSuccessStatusCode) - { - result = await response.Content.ReadAsStringAsync(); - } - - return result; - } - public async Task GetTransactionDetails(string tx) - { - string result = ""; - - HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(API_URL + SP_TRANSACTION_DETAILS + tx); - if (response.IsSuccessStatusCode) - { - result = await response.Content.ReadAsStringAsync(); - } - - return result; - } - public async Task GetSeasonDetails(string username, string bid, string sid, string sig, string ts) - { - string result = ""; - HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(API_URL + SP_CLAIM_SEASON_REWARDS.Replace("@@_username_@@", username).Replace("@@_browserid_@@", bid).Replace("@@_sessionid_@@", sid).Replace("@@_signature_@@", sig).Replace("@@_timestamp_@@", ts)); - if (response.IsSuccessStatusCode) - { - result = await response.Content.ReadAsStringAsync(); - } - return result; - } - - } -} \ No newline at end of file diff --git a/SplinterTools/Resources/whatsup.png b/SplinterTools/Resources/whatsup.png deleted file mode 100644 index b41db7f..0000000 Binary files a/SplinterTools/Resources/whatsup.png and /dev/null differ diff --git a/SplinterTools/SplinterTools.csproj b/SplinterTools/SplinterTools.csproj index 06253f0..adbe3b1 100644 --- a/SplinterTools/SplinterTools.csproj +++ b/SplinterTools/SplinterTools.csproj @@ -40,4 +40,8 @@ + + + + diff --git a/SplinterTools/Views/AddAccount.xaml.cs b/SplinterTools/Views/AddAccount.xaml.cs index 769778e..da94a6b 100644 --- a/SplinterTools/Views/AddAccount.xaml.cs +++ b/SplinterTools/Views/AddAccount.xaml.cs @@ -26,9 +26,18 @@ public void ShowAddWindow() private void BtnOk_Click(object sender, RoutedEventArgs e) { - Processors.AccountDetailsProcessor.updateAccounts(txtAccount.Text, Convert.ToInt32(txtPOwer.Text)); - SaveData.Invoke(this); - this.Close(); + if (txtAccount.Text == "" || txtPOwer.Text == "") + { + this.Close(); + } + else + { + Processors.AccountDetailsProcessor.updateAccounts(txtAccount.Text, Convert.ToInt32(txtPOwer.Text)); + SaveData.Invoke(this); + this.Close(); + } + + } } }