From 7906f48262fb602858418a07d8ae4b295cbe8a68 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Thu, 18 Sep 2014 21:12:37 -1000 Subject: [PATCH] Updated CoreClientManager to pull all account data via name request. Cleaned up some code with pet administrator. added logging if 0 rows were being saved in CommitChanges --- .../core/account/CoreClientManager.java | 29 + .../customerSupport/CustomerSupport.java | 43 +- .../LOC.Website.Common/Contexts/Repository.cs | 9 +- .../Models/AccountAdministrator.cs | 5 - .../Models/PetAdministrator.cs | 14 +- .../Models/PvpAdministrator.cs | 5 +- .../LOC.Website.Web.Publish.xml | 842 +++++++++--------- 7 files changed, 509 insertions(+), 438 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java index fffa1202c..75cfb0a48 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java @@ -168,9 +168,38 @@ public class CoreClientManager extends MiniPlugin client.SetAccountId(token.AccountId); client.SetRank(Rank.valueOf(token.Rank)); + final RetrieveClientInformationEvent clientInformationEvent = new RetrieveClientInformationEvent(client.GetPlayerName(), uuid); + clientInformationEvent.incrementProcessingCount(); + + Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable() + { + public void run() + { + _mysqlRepository.login(uuid.toString(), client.GetPlayerName()); + + Bukkit.getServer().getPluginManager().callEvent(clientInformationEvent); + clientInformationEvent.decreaseProcessingCount(); + } + }); + // JSON sql response Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response)); + // Load client in miniplugins + Bukkit.getServer().getPluginManager().callEvent(new AsyncClientLoadEvent(token, client)); + + while (clientInformationEvent.processing()) + { + try + { + Thread.sleep(1); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + } + Bukkit.getServer().getScheduler().runTask(GetPlugin(), new Runnable() { public void run() diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/customerSupport/CustomerSupport.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/customerSupport/CustomerSupport.java index 4dcc23100..1edc83080 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/customerSupport/CustomerSupport.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/customerSupport/CustomerSupport.java @@ -19,6 +19,7 @@ import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClientManager; import mineplex.core.common.Rank; +import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.NautHashMap; @@ -99,21 +100,49 @@ public class CustomerSupport extends MiniPlugin caller.sendMessage(C.cDGreen + C.Strike + "============================================="); caller.sendMessage(C.cBlue + "Name : " + C.cYellow + playerName); caller.sendMessage(C.cBlue + "Rank : " + C.cYellow + (client.GetRank().Name.isEmpty() ? "Regular" : client.GetRank().Name)); - caller.sendMessage(C.cBlue + "Transactions : "); + caller.sendMessage(C.cBlue + "Coins : " + C.cYellow + donor.getCoins()); + caller.sendMessage(C.cBlue + "Gems : " + C.cYellow + donor.GetGems()); + int coinTransactionTotal = 0; + int enjinCoinsReceived = 0; + int coinSpentTotal = 0; + + int enjinBoostersReceived = 0; + for (CoinTransactionToken transaction : donor.getCoinTransactions()) { - if (transaction.Source.equalsIgnoreCase("Poll") || transaction.Source.equalsIgnoreCase("Coin Party Bomb Pickup") || transaction.Source.contains("Reward")) - continue; - - caller.sendMessage(C.cYellow + _date.format(transaction.Date) + C.cGray + " - " + C.cYellow + transaction.Amount + " Coins - Applied via " + transaction.Source); + if (transaction.Source.equalsIgnoreCase("Poll") || transaction.Source.equalsIgnoreCase("Coin Party Bomb Pickup") || transaction.Source.contains("Reward") || transaction.Source.contains("purchase")) + { + coinTransactionTotal += transaction.Amount; + + if (transaction.Source.contains("purchase")) + enjinCoinsReceived += transaction.Amount; + } } for (TransactionToken transaction : donor.getTransactions()) { - if (transaction.Coins == 0 && transaction.Gems == 0 && transaction.SalesPackageName.contains("Gem Booster")) - caller.sendMessage(C.cYellow + _date.format(transaction.Date) + C.cGray + " - " + C.cYellow + transaction.SalesPackageName); + coinSpentTotal += transaction.Coins; + + if (transaction.SalesPackageName.contains("Gem Booster")) + { + if (transaction.SalesPackageName.startsWith("Gem Booster") && transaction.Coins == 0 && transaction.Gems == 0 && transaction.SalesPackageName.split(" ").length == 3) + enjinBoostersReceived += Integer.parseInt(transaction.SalesPackageName.split(" ")[2]); + } } + + caller.sendMessage(C.cBlue + "Enjin Coin Total Received : " + C.cYellow + enjinCoinsReceived); + caller.sendMessage(C.cBlue + "Enjin Booster Total Received : " + C.cYellow + enjinBoostersReceived); + + int coinsMissing = coinTransactionTotal - (donor.getCoins() + coinSpentTotal); + + if (coinsMissing > 0) + { + caller.sendMessage(C.cRed + "Coins missing!"); + new JsonMessage("[").color("blue").extra(C.cGreen + "Apply Missing Coins").color("green").click("run_command", "/sales coin " + playerName + " " + coinsMissing) + .add("] ").color("blue").add("Missing Coins.").color("yellow").sendToPlayer(caller); + } + caller.sendMessage(C.cDGreen + C.Strike + "============================================="); _salesPackageManager.displaySalesPackages(caller, playerName); caller.sendMessage(C.cDGreen + C.Strike + "============================================="); diff --git a/Website/LOC.Website.Common/Contexts/Repository.cs b/Website/LOC.Website.Common/Contexts/Repository.cs index 9b19981d9..5a842faa1 100644 --- a/Website/LOC.Website.Common/Contexts/Repository.cs +++ b/Website/LOC.Website.Common/Contexts/Repository.cs @@ -52,7 +52,14 @@ const string PREFIX = "CommitChanges() failed because: "; try { - Context.SaveChanges(); + if (Context.SaveChanges() == 0) + Log("WARNING", "No entities to save: " + Environment.StackTrace); + /* + * List modifiedOrAddedEntities = context.ChangeTracker.Entries() + .Where(x => x.State == System.Data.EntityState.Modified + || x.State == System.Data.EntityState.Added) + .Select(x=>x.Entity).ToList(); + * */ } catch (DbEntityValidationException ex) { diff --git a/Website/LOC.Website.Common/Models/AccountAdministrator.cs b/Website/LOC.Website.Common/Models/AccountAdministrator.cs index 96a6b8824..d97655952 100644 --- a/Website/LOC.Website.Common/Models/AccountAdministrator.cs +++ b/Website/LOC.Website.Common/Models/AccountAdministrator.cs @@ -559,17 +559,12 @@ if (rank == null) return account.Rank.ToString(); - repository.Attach(account); - repository.Edit(account); - var expire = DateTime.Now.AddMonths(1).AddMilliseconds(-DateTime.Now.Millisecond); account.Rank = rank; account.RankExpire = expire; account.RankPerm = token.Perm; - repository.CommitChanges(); - repository.Edit(account); if ((rank.Name == "HERO" || rank.Name == "ULTRA") && token.Perm) diff --git a/Website/LOC.Website.Common/Models/PetAdministrator.cs b/Website/LOC.Website.Common/Models/PetAdministrator.cs index a4f23362d..15507f4c5 100644 --- a/Website/LOC.Website.Common/Models/PetAdministrator.cs +++ b/Website/LOC.Website.Common/Models/PetAdministrator.cs @@ -21,12 +21,15 @@ { using (var repository = _repositoryFactory.CreateRepository()) { + bool added = false; foreach (var item in petTokens.Where(item => !repository.Any(x => x.PetType == item.PetType))) { repository.Add(item); + added = true; } - repository.CommitChanges(); + if (added) + repository.CommitChanges(); return repository.GetAll().Include(x => x.SalesPackage).ToList(); } @@ -36,12 +39,15 @@ { using (var repository = _repositoryFactory.CreateRepository()) { + bool added = false; foreach (var item in petExtraTokens.Where(item => !repository.Any(x => x.Name == item.Name && x.Material == item.Material))) { repository.Add(item); + added = true; } - repository.CommitChanges(); + if (added) + repository.CommitChanges(); return repository.GetAll().Include(x => x.SalesPackage).ToList(); } @@ -72,10 +78,12 @@ return; var pet = account.Pets.FirstOrDefault(x => x.PetType.Equals(token.PetType)); - + if (pet == null) return; + account.Pets.RemoveAll(x => x.PetType.Equals(token.PetType) && x.OwnedPetId != pet.OwnedPetId); + pet.PetName = token.PetName; repository.Edit(pet); diff --git a/Website/LOC.Website.Common/Models/PvpAdministrator.cs b/Website/LOC.Website.Common/Models/PvpAdministrator.cs index 3f9854326..d14ee5e07 100644 --- a/Website/LOC.Website.Common/Models/PvpAdministrator.cs +++ b/Website/LOC.Website.Common/Models/PvpAdministrator.cs @@ -35,12 +35,15 @@ { using (var repository = RepositoryFactory.CreateRepository()) { + bool added = false; foreach (var skill in skills.Where(skill => !repository.Any(x => x.Name == skill.Name && x.Level == skill.Level))) { repository.Add(skill); + added = true; } - repository.CommitChanges(); + if (added) + repository.CommitChanges(); return repository.GetAll().Include(x => x.SalesPackage).ToList(); } diff --git a/Website/LOC.Website.Web/LOC.Website.Web.Publish.xml b/Website/LOC.Website.Web/LOC.Website.Web.Publish.xml index bdefbafe8..dc38d1feb 100644 --- a/Website/LOC.Website.Web/LOC.Website.Web.Publish.xml +++ b/Website/LOC.Website.Web/LOC.Website.Web.Publish.xml @@ -1,13 +1,11 @@  - - @@ -20,17 +18,15 @@ - - + + - - @@ -44,27 +40,25 @@ - - - - + - - + + + @@ -75,24 +69,25 @@ - - + - + + + - + + - @@ -100,7 +95,7 @@ - + @@ -108,40 +103,42 @@ + + + - - - + + - + + - - - + + + - @@ -152,19 +149,23 @@ - + - - + + + + + + @@ -173,6 +174,7 @@ + @@ -183,93 +185,91 @@ - + - + + - - - + - + - - + + - + - + - + + - + - + - - + - + - - + - - + + - + - - + + - - + + - + - + @@ -280,22 +280,24 @@ - + - + + - + + @@ -303,6 +305,7 @@ + @@ -310,18 +313,16 @@ - + - - @@ -332,21 +333,22 @@ + - - + + + - - + @@ -354,8 +356,6 @@ - - @@ -363,11 +363,13 @@ - + - + + + @@ -375,97 +377,94 @@ + - - + + + - - + + + - - + - - + - - - - + - - + - + - - - + - + - + - + + + - + @@ -473,329 +472,330 @@ - + - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + - + - + - - - + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -808,15 +808,15 @@ - + + - - + @@ -830,7 +830,6 @@ - @@ -838,8 +837,8 @@ - + @@ -849,7 +848,6 @@ - @@ -860,29 +858,30 @@ + - - + + - + + - - + @@ -890,17 +889,18 @@ - - + + + @@ -908,22 +908,23 @@ - - + - + - + + + - + @@ -934,65 +935,61 @@ - + - - - - + - - + - + + - - - + - + - + - - + + + - + @@ -1000,56 +997,59 @@ - - + + - + + - + + - + - + + - - + + - - + + - + - - - - - + + + + + - + \ No newline at end of file