diff --git a/src/engine/gameManager/PowersManager.java b/src/engine/gameManager/PowersManager.java index 0942cf6c..af4a4b93 100644 --- a/src/engine/gameManager/PowersManager.java +++ b/src/engine/gameManager/PowersManager.java @@ -28,7 +28,6 @@ import engine.net.client.msg.*; import engine.objects.*; import engine.powers.*; import engine.powers.poweractions.AbstractPowerAction; -import engine.powers.poweractions.TrackPowerAction; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; @@ -1382,122 +1381,6 @@ public enum PowersManager { } } - public static void trackWindow(TrackWindowMsg msg, ClientConnection origin) { - - PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter( - origin); - - if (playerCharacter == null) - return; - - if (MBServerStatics.POWERS_DEBUG) { - ChatManager.chatSayInfo( - playerCharacter, - "Using Power: " + Integer.toHexString(msg.getPowerToken()) - + " (" + msg.getPowerToken() + ')'); - Logger.info("Using Power: " - + Integer.toHexString(msg.getPowerToken()) + " (" - + msg.getPowerToken() + ')'); - } - - // get track power used - PowersBase pb = PowersManager.powersBaseByToken.get(msg.getPowerToken()); - - if (pb == null || !pb.isTrack()) - return; - - //check track threshold timer to prevent spam - long currentTime = System.currentTimeMillis(); - long timestamp = playerCharacter.getTimeStamp("trackWindow"); - long dif = currentTime - timestamp; - if (dif < MBServerStatics.TRACK_WINDOW_THRESHOLD) - return; - playerCharacter.setTimeStamp("trackWindow", currentTime); - - ArrayList ablist = pb.getActions(); - if (ablist == null) - return; - - TrackPowerAction tpa = null; - for (ActionsBase ab : ablist) { - AbstractPowerAction apa = ab.getPowerAction(); - if (apa != null && apa instanceof TrackPowerAction) - tpa = (TrackPowerAction) apa; - } - if (tpa == null) - return; - - // Check powers for normal users - if (playerCharacter.getPowers() == null || !playerCharacter.getPowers().containsKey(msg.getPowerToken())) - if (!playerCharacter.isCSR()) - if (!MBServerStatics.POWERS_DEBUG) { - // ChatManager.chatSayInfo(pc, "You may not cast that spell!"); - // this.logEXPLOIT("usePowerA(): Cheat attempted? '" + msg.getPowerToken() + "' was not associated with " + pc.getName()); - return; - } - - // Get search mask for track - int mask = 0; - if (pb.targetPlayer()) - if (tpa.trackVampire()) // track vampires - mask = MBServerStatics.MASK_PLAYER | MBServerStatics.MASK_UNDEAD; - else - // track all players - mask = MBServerStatics.MASK_PLAYER; - else if (pb.targetCorpse()) // track corpses - mask = MBServerStatics.MASK_CORPSE; - else if (tpa.trackNPC()) // Track NPCs - mask = MBServerStatics.MASK_NPC; - else if (tpa.trackUndead()) // Track Undead - mask = MBServerStatics.MASK_MOB | MBServerStatics.MASK_UNDEAD; - else - // Track All - mask = MBServerStatics.MASK_MOB | MBServerStatics.MASK_NPC; - - // Find characters in range - HashSet allTargets; - allTargets = WorldGrid.getObjectsInRangeContains(playerCharacter.getLoc(), - pb.getRange(), mask); - - //remove anyone who can't be tracked - Iterator it = allTargets.iterator(); - while (it.hasNext()) { - AbstractWorldObject awo = it.next(); - if (awo == null) - continue; - else if (!awo.isAlive()) - it.remove(); - else if (awo.getObjectType().equals(GameObjectType.PlayerCharacter)) { - PlayerBonuses bonus = ((PlayerCharacter) awo).getBonuses(); - if (bonus != null && bonus.getBool(ModType.CannotTrack, SourceType.NONE)) - it.remove(); - } - } - - // get max charcters for window - int maxTargets = 20; - PromotionClass promo = playerCharacter.getPromotionClass(); - if (promo != null) { - int tableID = promo.getObjectUUID(); - if (tableID == 2512 || tableID == 2514 || tableID == 2515) - maxTargets = 40; - } - - // create list of characters - HashSet trackChars = RangeBasedAwo.getTrackList( - allTargets, playerCharacter, maxTargets); - - TrackWindowMsg trackWindowMsg = new TrackWindowMsg(msg); - - // send track window - trackWindowMsg.setSource(playerCharacter); - trackWindowMsg.setCharacters(trackChars); - - Dispatch dispatch = Dispatch.borrow(playerCharacter, trackWindowMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - } - private static void sendRecyclePower(int token, ClientConnection origin) { RecyclePowerMsg recyclePowerMsg = new RecyclePowerMsg(token); diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 7721b052..db3aae62 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -129,9 +129,6 @@ public class ClientMessagePump implements NetMsgHandler { case ARCSUMMON: PowersManager.recvSummon((RecvSummonsRequestMsg) msg, origin); break; - case ARCTRACKINGLIST: - PowersManager.trackWindow((TrackWindowMsg) msg, origin); - break; case CHANNELMUTE: break; case KEEPALIVESERVERCLIENT: diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index f421f539..c9b47759 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -45,7 +45,7 @@ public enum Protocol { ARCSERVERSTATUS(0x87BA4462, null, null), //Update Server Status ARCSIEGESPIRE(0x36A49BC6, ArcSiegeSpireMsg.class, ArcSiegeSpireMsgHandler.class), // Activate/Deactivate Spires ARCSUMMON(0xFD816A0A, RecvSummonsRequestMsg.class, null), // Suspect Recv Summons Request - ARCTRACKINGLIST(0xC89CF08B, TrackWindowMsg.class, null), //Request/Send Track window + ARCTRACKINGLIST(0xC89CF08B, TrackWindowMsg.class, TrackWindowMsgHandler.class), //Request/Send Track window ARCTRACKOBJECT(0x609B6BA2, TrackArrowMsg.class, null), //Send Track Arrow ARCUNTRAINABILITY(0x548DBF83, RefineMsg.class, RefineMsgHandler.class), //Refine ARCUNTRAINLIST(0x38879E90, RefinerScreenMsg.class, RefinerScreenMsgHandler.class), //Refiner screen diff --git a/src/engine/net/client/handlers/TrackWindowMsgHandler.java b/src/engine/net/client/handlers/TrackWindowMsgHandler.java new file mode 100644 index 00000000..9abc6210 --- /dev/null +++ b/src/engine/net/client/handlers/TrackWindowMsgHandler.java @@ -0,0 +1,184 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.Enum; +import engine.Enum.DispatchChannel; +import engine.InterestManagement.WorldGrid; +import engine.exception.MsgSendException; +import engine.gameManager.ChatManager; +import engine.gameManager.PowersManager; +import engine.net.Dispatch; +import engine.net.DispatchMessage; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.TrackWindowMsg; +import engine.objects.*; +import engine.powers.ActionsBase; +import engine.powers.PowersBase; +import engine.powers.RangeBasedAwo; +import engine.powers.poweractions.AbstractPowerAction; +import engine.powers.poweractions.TrackPowerAction; +import engine.server.MBServerStatics; +import org.pmw.tinylog.Logger; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; + +public class TrackWindowMsgHandler extends AbstractClientMsgHandler { + + public TrackWindowMsgHandler() { + super(TrackWindowMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + TrackWindowMsg msg; + + // Member variable assignment + + msg = (TrackWindowMsg) baseMsg; + + if (playerCharacter == null) + return true; + + if (MBServerStatics.POWERS_DEBUG) { + ChatManager.chatSayInfo( + playerCharacter, + "Using Power: " + Integer.toHexString(msg.getPowerToken()) + + " (" + msg.getPowerToken() + ')'); + Logger.info("Using Power: " + + Integer.toHexString(msg.getPowerToken()) + " (" + + msg.getPowerToken() + ')'); + } + + // get track power used + + PowersBase pb = PowersManager.powersBaseByToken.get(msg.getPowerToken()); + + if (pb == null || !pb.isTrack()) + return true; + + //check track threshold timer to prevent spam + + long currentTime = System.currentTimeMillis(); + long timestamp = playerCharacter.getTimeStamp("trackWindow"); + long dif = currentTime - timestamp; + + if (dif < MBServerStatics.TRACK_WINDOW_THRESHOLD) + return true; + + playerCharacter.setTimeStamp("trackWindow", currentTime); + + ArrayList ablist = pb.getActions(); + + if (ablist == null) + return true; + + TrackPowerAction tpa = null; + + for (ActionsBase ab : ablist) { + AbstractPowerAction apa = ab.getPowerAction(); + if (apa != null && apa instanceof TrackPowerAction) + tpa = (TrackPowerAction) apa; + } + + if (tpa == null) + return true; + + // Check powers for normal users + if (playerCharacter.getPowers() == null || !playerCharacter.getPowers().containsKey(msg.getPowerToken())) + if (!playerCharacter.isCSR()) + if (!MBServerStatics.POWERS_DEBUG) { + // ChatManager.chatSayInfo(pc, "You may not cast that spell!"); + // this.logEXPLOIT("usePowerA(): Cheat attempted? '" + msg.getPowerToken() + "' was not associated with " + pc.getName()); + return true; + } + + // Get search mask for track + + int mask = 0; + + if (pb.targetPlayer()) + if (tpa.trackVampire()) // track vampires + mask = MBServerStatics.MASK_PLAYER | MBServerStatics.MASK_UNDEAD; + else + // track all players + mask = MBServerStatics.MASK_PLAYER; + else if (pb.targetCorpse()) // track corpses + mask = MBServerStatics.MASK_CORPSE; + else if (tpa.trackNPC()) // Track NPCs + mask = MBServerStatics.MASK_NPC; + else if (tpa.trackUndead()) // Track Undead + mask = MBServerStatics.MASK_MOB | MBServerStatics.MASK_UNDEAD; + else + // Track All + mask = MBServerStatics.MASK_MOB | MBServerStatics.MASK_NPC; + + // Find characters in range + + HashSet allTargets; + allTargets = WorldGrid.getObjectsInRangeContains(playerCharacter.getLoc(), + pb.getRange(), mask); + + //remove anyone who can't be tracked + + Iterator it = allTargets.iterator(); + + while (it.hasNext()) { + AbstractWorldObject awo = it.next(); + + if (awo == null) + continue; + + else if (!awo.isAlive()) + it.remove(); + + else if (awo.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { + PlayerBonuses bonus = ((PlayerCharacter) awo).getBonuses(); + + if (bonus != null && bonus.getBool(Enum.ModType.CannotTrack, Enum.SourceType.NONE)) + it.remove(); + } + } + + // get max characters for window + + int maxTargets = 20; + PromotionClass promo = playerCharacter.getPromotionClass(); + + if (promo != null) { + int tableID = promo.getObjectUUID(); + if (tableID == 2512 || tableID == 2514 || tableID == 2515) + maxTargets = 40; + } + + // create list of characters + HashSet trackChars = RangeBasedAwo.getTrackList( + allTargets, playerCharacter, maxTargets); + + TrackWindowMsg trackWindowMsg = new TrackWindowMsg(msg); + + // send track window + trackWindowMsg.setSource(playerCharacter); + trackWindowMsg.setCharacters(trackChars); + + Dispatch dispatch = Dispatch.borrow(playerCharacter, trackWindowMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + return true; + } + +} \ No newline at end of file