From 9e99dc75e312fdc1296bcd4dde98799be13432a9 Mon Sep 17 00:00:00 2001 From: Mazo Date: Fri, 29 Nov 2019 16:00:30 +0000 Subject: [PATCH] Cancel jacking if a vehicle is moving (#290) * Add Medical / Adv Medical / Expert Electronics to default certs * Cancel jacking when object is moving more than a small amount --- .../psforever/packet/game/HackMessage.scala | 2 +- .../src/main/scala/WorldSessionActor.scala | 45 ++++++++++++------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/common/src/main/scala/net/psforever/packet/game/HackMessage.scala b/common/src/main/scala/net/psforever/packet/game/HackMessage.scala index 72cc53bed..498aec43e 100644 --- a/common/src/main/scala/net/psforever/packet/game/HackMessage.scala +++ b/common/src/main/scala/net/psforever/packet/game/HackMessage.scala @@ -21,7 +21,7 @@ object HackState extends Enumeration { val Unknown0, Start, - Unknown2, + Cancelled, Ongoing, Finished, Unknown5, diff --git a/pslogin/src/main/scala/WorldSessionActor.scala b/pslogin/src/main/scala/WorldSessionActor.scala index c5dee0daf..d2459aa85 100644 --- a/pslogin/src/main/scala/WorldSessionActor.scala +++ b/pslogin/src/main/scala/WorldSessionActor.scala @@ -3186,30 +3186,43 @@ class WorldSessionActor extends Actor with MDCContextAware { def HandleHackingProgress(progressType : Int, tplayer : Player, target : PlanetSideServerObject, tool_guid : PlanetSideGUID, delta : Float, completeAction : ()=>Unit, tickAction : Option[()=>Unit]) : Unit = { progressBarUpdate.cancel if(progressBarValue.isDefined) { - val progressBarVal : Float = progressBarValue.get + delta + val progressBarVal : Float = if (progressBarValue.get + delta > 100) { 100f } else { progressBarValue.get + delta } + val vis = if(progressBarVal == 0L) { //hack state for progress bar visibility HackState.Start } - else if(progressBarVal > 100L) { + else if(progressBarVal >= 100L) { HackState.Finished } + else if(target.Velocity.isDefined && Vector3.Distance(Vector3.Zero, target.Velocity.get) > 1f) { + // If the object is moving (more than slightly to account for things like magriders rotating, or the last velocity reported being the magrider dipping down on dismount) then cancel the hack + HackState.Cancelled + } else { HackState.Ongoing } - sendResponse(HackMessage(progressType, target.GUID, player.GUID, progressBarVal.toInt, 0L, vis, 8L)) - if(progressBarVal > 100) { - //done - progressBarValue = None - // sendResponse(HackMessage(0, target.GUID, player.GUID, 100, 1114636288L, HackState.Hacked, 8L)) - completeAction() + + if(vis == HackState.Cancelled) { + // Object moved. Cancel the hack (e.g. vehicle drove away) + sendResponse(HackMessage(progressType, target.GUID, player.GUID, 0, 0L, vis, 8L)) } - else { - //continue next tick - tickAction.getOrElse(() => Unit)() - progressBarValue = Some(progressBarVal) - import scala.concurrent.ExecutionContext.Implicits.global - progressBarUpdate = context.system.scheduler.scheduleOnce(250 milliseconds, self, HackingProgress(progressType, tplayer, target, tool_guid, delta, completeAction)) + else + { + sendResponse(HackMessage(progressType, target.GUID, player.GUID, progressBarVal.toInt, 0L, vis, 8L)) + + if(progressBarVal >= 100) { + //done + progressBarValue = None + completeAction() + } + else { + //continue next tick + tickAction.getOrElse(() => Unit)() + progressBarValue = Some(progressBarVal) + import scala.concurrent.ExecutionContext.Implicits.global + progressBarUpdate = context.system.scheduler.scheduleOnce(250 milliseconds, self, HackingProgress(progressType, tplayer, target, tool_guid, delta, completeAction)) + } } } } @@ -3452,7 +3465,6 @@ class WorldSessionActor extends Actor with MDCContextAware { avatar.Certifications += ReinforcedExoSuit avatar.Certifications += ATV avatar.Certifications += Harasser - // avatar.Certifications += InfiltrationSuit avatar.Certifications += Sniping avatar.Certifications += AntiVehicular @@ -3479,6 +3491,9 @@ class WorldSessionActor extends Actor with MDCContextAware { avatar.Certifications += AssaultEngineering avatar.Certifications += Hacking avatar.Certifications += AdvancedHacking + avatar.Certifications += ElectronicsExpert + avatar.Certifications += Medical + avatar.Certifications += AdvancedMedical avatar.CEP = 6000001 this.avatar = avatar