From 0287cfb2f6a8ba2cee6eff69344cbe3a3e6d429b Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Fri, 27 Jun 2014 20:24:44 -0700 Subject: [PATCH] Refactored Punish a bit so punishments don't expire early or jack up based on server's time. --- .../core/account/CoreClientManager.java | 2 +- .../account/repository/token/ClientToken.java | 1 + .../src/mineplex/core/punish/Punish.java | 53 +++--------------- .../core/punish/PunishRepository.java | 3 +- .../core/punish/Tokens/PunishClientToken.java | 1 + Website/LOC.Core/Tokens/Client/ClientToken.cs | 3 + .../Models/AccountAdministrator.cs | 14 ++--- Website/LOCWebsite.suo | Bin 474624 -> 474624 bytes 8 files changed, 18 insertions(+), 59 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java index 8760e1e7d..a6715061c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java @@ -155,7 +155,7 @@ public class CoreClientManager implements Listener client.SetAccountId(token.AccountId); client.SetRank(Rank.valueOf(token.Rank)); - + // JSON sql response Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response)); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/token/ClientToken.java b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/token/ClientToken.java index 3de776eb6..28c64e80c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/token/ClientToken.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/token/ClientToken.java @@ -8,4 +8,5 @@ public class ClientToken public int EconomyBalance; public AccountToken AccountToken; + public long LastLogin; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/punish/Punish.java b/Plugins/Mineplex.Core/src/mineplex/core/punish/Punish.java index 30b473719..4ee2bfc91 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/punish/Punish.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/punish/Punish.java @@ -58,49 +58,6 @@ public class Punish extends MiniPlugin @EventHandler public void OnClientWebResponse(ClientWebResponseEvent event) { - /* - JsonReader reader = null; - - try - { - while (reader.hasNext()) - { - if (reader.nextName().equalsIgnoreCase("Punish")) - { - reader.beginObject(); - - // TODO Parse infractions/punishments here - // PunishClient client = new PunishClient(); - // client.AddInfraction(token.Category, new Infraction(token.Reason, token.Admin, token.Time)); - // client.AddPunishment(token.Category, new Punishment(token.PunishmentSentence, token.Reason, token.Admin, token.Hours, token.Time)); - // _punishClients.put(event.GetClient().GetPlayerName(), client); - - break; - } - - reader.endObject(); - } - } - catch (IOException e) - { - e.printStackTrace(); - } - finally - { - if (reader != null) - { - try - { - reader.close(); - } - catch (IOException e) - { - e.printStackTrace(); - } - } - } - */ - PunishClientToken token = new Gson().fromJson(event.GetResponse(), PunishClientToken.class); LoadClient(token); } @@ -121,7 +78,7 @@ public class Punish extends MiniPlugin if (client.IsBanned()) { Punishment punishment = client.GetPunishment(PunishmentSentence.Ban); - String time = F.time(UtilTime.convertString((long)(punishment.GetHours() * 3600000), 0, TimeUnit.FIT)); + String time = F.time(UtilTime.convertString(punishment.GetRemaining(), 0, TimeUnit.FIT)); if (punishment.GetHours() == -1) time = C.cRed + "Permanent"; @@ -234,16 +191,20 @@ public class Punish extends MiniPlugin } } } - }, playerName, category.toString(), sentence, reason, duration, caller == null ? "Mineplex Anti-Cheat" : caller.getName(), severity, System.currentTimeMillis()); + }, playerName, category.toString(), sentence, reason, duration, caller == null ? "Mineplex Anti-Cheat" : caller.getName(), severity); } public void LoadClient(PunishClientToken token) { PunishClient client = new PunishClient(); + long timeDifference = System.currentTimeMillis() - token.Time; + + System.out.println("TimeDifference : " + timeDifference); + for (PunishmentToken punishment : token.Punishments) { - client.AddPunishment(Category.valueOf(punishment.Category), new Punishment(punishment.PunishmentId, PunishmentSentence.valueOf(punishment.Sentence), Category.valueOf(punishment.Category), punishment.Reason, punishment.Admin, punishment.Duration, punishment.Severity, punishment.Time, punishment.Active, punishment.Removed, punishment.RemoveAdmin, punishment.RemoveReason)); + client.AddPunishment(Category.valueOf(punishment.Category), new Punishment(punishment.PunishmentId, PunishmentSentence.valueOf(punishment.Sentence), Category.valueOf(punishment.Category), punishment.Reason, punishment.Admin, punishment.Duration, punishment.Severity, punishment.Time + timeDifference, punishment.Active, punishment.Removed, punishment.RemoveAdmin, punishment.RemoveReason)); } _punishClients.put(token.Name.toLowerCase(), client); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/punish/PunishRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/punish/PunishRepository.java index 50ce7761f..ee4159867 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/punish/PunishRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/punish/PunishRepository.java @@ -20,7 +20,7 @@ public class PunishRepository _webAddress = webServerAddress; } - public void Punish(Callback callback, String target, String category, PunishmentSentence punishment, String reason, double duration, String admin, int severity, long time) + public void Punish(Callback callback, String target, String category, PunishmentSentence punishment, String reason, double duration, String admin, int severity) { PunishToken token = new PunishToken(); token.Target = target; @@ -29,7 +29,6 @@ public class PunishRepository token.Reason = reason; token.Duration = duration; token.Admin = admin; - token.Time = time; token.Severity = severity; new AsyncJsonWebCall(_webAddress + "PlayerAccount/Punish").Execute(String.class, callback, token); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/punish/Tokens/PunishClientToken.java b/Plugins/Mineplex.Core/src/mineplex/core/punish/Tokens/PunishClientToken.java index 875409afd..73582dbbf 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/punish/Tokens/PunishClientToken.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/punish/Tokens/PunishClientToken.java @@ -5,5 +5,6 @@ import java.util.List; public class PunishClientToken { public String Name; + public long Time; public List Punishments; } diff --git a/Website/LOC.Core/Tokens/Client/ClientToken.cs b/Website/LOC.Core/Tokens/Client/ClientToken.cs index d8498947d..2fd313543 100644 --- a/Website/LOC.Core/Tokens/Client/ClientToken.cs +++ b/Website/LOC.Core/Tokens/Client/ClientToken.cs @@ -20,6 +20,7 @@ Name = account.Name; Uuid = account.Uuid; Rank = account.Rank.Name; + Time = (long)TimeUtil.GetCurrentMilliseconds(); EconomyBalance = account.EconomyBalance; @@ -118,6 +119,8 @@ public string Rank { get; set; } + public long Time { get; set; } + public int EconomyBalance { get; set; } public List Punishments { get; set; } diff --git a/Website/LOC.Website.Common/Models/AccountAdministrator.cs b/Website/LOC.Website.Common/Models/AccountAdministrator.cs index 093dd1297..dd218fd49 100644 --- a/Website/LOC.Website.Common/Models/AccountAdministrator.cs +++ b/Website/LOC.Website.Common/Models/AccountAdministrator.cs @@ -69,7 +69,7 @@ { var account = repository.Where(x => x.Uuid == loginToken.Uuid).FirstOrDefault() ?? CreateAccount(loginToken, repository); account.LoadNavigationProperties(repository.Context); - var edited = false; + account.LastLogin = (long)TimeUtil.GetCurrentMilliseconds(); // Expire punishments if (account.Punishments != null) @@ -77,7 +77,6 @@ foreach (var expiredPunishment in account.Punishments.Where(x => x.Active && (x.Duration - 0d) > 0 && TimeUtil.GetCurrentMilliseconds() > (x.Time + (x.Duration * 3600000)))) { expiredPunishment.Active = false; - edited = true; } } @@ -85,7 +84,6 @@ if (String.IsNullOrEmpty(account.Uuid) && !String.IsNullOrEmpty(loginToken.Uuid)) { account.Uuid = loginToken.Uuid; - edited = true; } // Expire ranks @@ -93,13 +91,9 @@ { account.Rank = repository.Where(x => x.Name == "ALL").First(); repository.Attach(account.Rank); - edited = true; } - if (edited) - { - repository.CommitChanges(); - } + repository.CommitChanges(); return account; } @@ -268,7 +262,7 @@ Admin = punish.Admin, Category = punish.Category, Sentence = punish.Sentence, - Time = punish.Time, + Time = (long)TimeUtil.GetCurrentMilliseconds(), Reason = punish.Reason, Duration = punish.Duration, Severity = punish.Severity, @@ -308,7 +302,7 @@ punishment.Active = false; punishment.Removed = true; punishment.RemoveAdmin = token.Admin; - punishment.RemoveTime = DateTime.Now.Ticks; + punishment.RemoveTime = (long)TimeUtil.GetCurrentMilliseconds(); punishment.RemoveReason = token.Reason; repository.Edit(punishment); diff --git a/Website/LOCWebsite.suo b/Website/LOCWebsite.suo index ba1321b065e2fdeec79204b0781bd4175fd3bafe..9f62e8a48b5b783c529d1f3f4d74a0395c3df0fb 100644 GIT binary patch delta 525 zcmZqpBh&ClWPj{ZnXw?37Gb0c)0WtITubWwTdS057(FG{u1(V%gGN09-d$M!1;q))7KziMQGJy!$ z)vV{mI2oLP0!j=}Cu}b{#CnEl@H$sMj&PaV&?5%HnYfN2zIbD zFth=2I}rc-|NsBL?TRw2O7WZwmP`x`)<8U+(TPc8dPy~_|77QA!|h*y3^qW9?+Z~RvGP8or*j{p))rXm} zZ~DP$tfiALWO6Z105hj={)N?j!7C4laqo&rms_B7J;ZspZ@MQqsI0LH(8&E z@H7K`zXfO!2uyp&sxp0vCX)h(E71A?n44Jpfoe`o4-{k5pPnGbCNufKR-Wk>-m@Bj zcnV-*vH=SVNO(I?*ut3u7@A-(UBH;_2^Wmlz&^dMh*533iV5429V{j=