diff --git a/common/src/main/scala/net/psforever/objects/serverobject/hackable/Hackable.scala b/common/src/main/scala/net/psforever/objects/serverobject/hackable/Hackable.scala new file mode 100644 index 000000000..1ffb34f6f --- /dev/null +++ b/common/src/main/scala/net/psforever/objects/serverobject/hackable/Hackable.scala @@ -0,0 +1,41 @@ +package net.psforever.objects.serverobject.hackable + +import net.psforever.objects.Player +import net.psforever.packet.game.PlanetSideGUID +import net.psforever.types.Vector3 + +trait Hackable { + /** An entry that maintains a reference to the `Player`, and the player's GUID and location when the message was received. */ + private var hackedBy : Option[(Player, PlanetSideGUID, Vector3)] = None + + def HackedBy : Option[(Player, PlanetSideGUID, Vector3)] = hackedBy + + def HackedBy_=(agent : Player) : Option[(Player, PlanetSideGUID, Vector3)] = HackedBy_=(Some(agent)) + + /** + * Set the hack state of this object by recording important information about the player that caused it. + * Set the hack state if there is no current hack state. + * Override the hack state with a new hack state if the new user has different faction affiliation. + * @param agent a `Player`, or no player + * @return the player hack entry + */ + def HackedBy_=(agent : Option[Player]) : Option[(Player, PlanetSideGUID, Vector3)] = { + hackedBy match { + case None => + //set the hack state if there is no current hack state + if(agent.isDefined) { + hackedBy = Some(agent.get, agent.get.GUID, agent.get.Position) + } + case Some(_) => + //clear the hack state + if(agent.isEmpty) { + hackedBy = None + } + //override the hack state with a new hack state if the new user has different faction affiliation + else if(agent.get.Faction != hackedBy.get._1.Faction) { + hackedBy = Some(agent.get, agent.get.GUID, agent.get.Position) + } + } + HackedBy + } +} diff --git a/common/src/main/scala/net/psforever/objects/serverobject/locks/IFFLock.scala b/common/src/main/scala/net/psforever/objects/serverobject/locks/IFFLock.scala index 8142fd9af..b22ae76db 100644 --- a/common/src/main/scala/net/psforever/objects/serverobject/locks/IFFLock.scala +++ b/common/src/main/scala/net/psforever/objects/serverobject/locks/IFFLock.scala @@ -1,10 +1,8 @@ // Copyright (c) 2017 PSForever package net.psforever.objects.serverobject.locks -import net.psforever.objects.Player +import net.psforever.objects.serverobject.hackable.Hackable import net.psforever.objects.serverobject.structures.Amenity -import net.psforever.packet.game.PlanetSideGUID -import net.psforever.types.Vector3 /** * A structure-owned server object that is a "door lock."
@@ -15,43 +13,7 @@ import net.psforever.types.Vector3 * The `IFFLock` is ideally associated with a server map object - a `Door` - to which it acts as a gatekeeper. * @param idef the `ObjectDefinition` that constructs this object and maintains some of its immutable fields */ -class IFFLock(private val idef : IFFLockDefinition) extends Amenity { - /** - * An entry that maintains a reference to the `Player`, and the player's GUID and location when the message was received. - */ - private var hackedBy : Option[(Player, PlanetSideGUID, Vector3)] = None - - def HackedBy : Option[(Player, PlanetSideGUID, Vector3)] = hackedBy - - def HackedBy_=(agent : Player) : Option[(Player, PlanetSideGUID, Vector3)] = HackedBy_=(Some(agent)) - - /** - * Set the hack state of this object by recording important information about the player that caused it. - * Set the hack state if there is no current hack state. - * Override the hack state with a new hack state if the new user has different faction affiliation. - * @param agent a `Player`, or no player - * @return the player hack entry - */ - def HackedBy_=(agent : Option[Player]) : Option[(Player, PlanetSideGUID, Vector3)] = { - hackedBy match { - case None => - //set the hack state if there is no current hack state - if(agent.isDefined) { - hackedBy = Some(agent.get, agent.get.GUID, agent.get.Position) - } - case Some(_) => - //clear the hack state - if(agent.isEmpty) { - hackedBy = None - } - //override the hack state with a new hack state if the new user has different faction affiliation - else if(agent.get.Faction != hackedBy.get._1.Faction) { - hackedBy = Some(agent.get, agent.get.GUID, agent.get.Position) - } - } - HackedBy - } - +class IFFLock(private val idef : IFFLockDefinition) extends Amenity with Hackable { def Definition : IFFLockDefinition = idef } diff --git a/common/src/main/scala/net/psforever/objects/serverobject/mblocker/Locker.scala b/common/src/main/scala/net/psforever/objects/serverobject/mblocker/Locker.scala index d614b53a8..39906ac74 100644 --- a/common/src/main/scala/net/psforever/objects/serverobject/mblocker/Locker.scala +++ b/common/src/main/scala/net/psforever/objects/serverobject/mblocker/Locker.scala @@ -3,9 +3,10 @@ package net.psforever.objects.serverobject.mblocker import akka.actor.{ActorContext, Props} import net.psforever.objects.GlobalDefinitions +import net.psforever.objects.serverobject.hackable.Hackable import net.psforever.objects.serverobject.structures.Amenity -class Locker extends Amenity { +class Locker extends Amenity with Hackable { def Definition : LockerDefinition = GlobalDefinitions.mb_locker } diff --git a/common/src/main/scala/net/psforever/objects/serverobject/mblocker/LockerControl.scala b/common/src/main/scala/net/psforever/objects/serverobject/mblocker/LockerControl.scala index 2e037e644..75df57309 100644 --- a/common/src/main/scala/net/psforever/objects/serverobject/mblocker/LockerControl.scala +++ b/common/src/main/scala/net/psforever/objects/serverobject/mblocker/LockerControl.scala @@ -2,6 +2,7 @@ package net.psforever.objects.serverobject.mblocker import akka.actor.Actor +import net.psforever.objects.serverobject.CommonMessages import net.psforever.objects.serverobject.affinity.{FactionAffinity, FactionAffinityBehavior} /** @@ -12,6 +13,11 @@ class LockerControl(locker : Locker) extends Actor with FactionAffinityBehavior. def FactionObject : FactionAffinity = locker def receive : Receive = checkBehavior.orElse { + case CommonMessages.Hack(player) => + locker.HackedBy = player + + case CommonMessages.ClearHack() => + locker.HackedBy = None case _ => ; } } diff --git a/common/src/main/scala/net/psforever/objects/serverobject/terminals/ProximityTerminalControl.scala b/common/src/main/scala/net/psforever/objects/serverobject/terminals/ProximityTerminalControl.scala index 753cdb65c..540da72b1 100644 --- a/common/src/main/scala/net/psforever/objects/serverobject/terminals/ProximityTerminalControl.scala +++ b/common/src/main/scala/net/psforever/objects/serverobject/terminals/ProximityTerminalControl.scala @@ -2,6 +2,7 @@ package net.psforever.objects.serverobject.terminals import akka.actor.Actor +import net.psforever.objects.serverobject.CommonMessages import net.psforever.objects.serverobject.affinity.{FactionAffinity, FactionAffinityBehavior} /** @@ -18,6 +19,11 @@ class ProximityTerminalControl(term : Terminal with ProximityUnit) extends Actor def receive : Receive = checkBehavior .orElse(proximityBehavior) .orElse { + case CommonMessages.Hack(player) => + term.HackedBy = player + + case CommonMessages.ClearHack() => + term.HackedBy = None case _ => ; } diff --git a/common/src/main/scala/net/psforever/objects/serverobject/terminals/Terminal.scala b/common/src/main/scala/net/psforever/objects/serverobject/terminals/Terminal.scala index 7a8676bbc..03323cc50 100644 --- a/common/src/main/scala/net/psforever/objects/serverobject/terminals/Terminal.scala +++ b/common/src/main/scala/net/psforever/objects/serverobject/terminals/Terminal.scala @@ -3,48 +3,17 @@ package net.psforever.objects.serverobject.terminals import net.psforever.objects.Player import net.psforever.objects.definition.VehicleDefinition +import net.psforever.objects.serverobject.hackable.Hackable import net.psforever.objects.serverobject.structures.Amenity -import net.psforever.packet.game.{ItemTransactionMessage, PlanetSideGUID} -import net.psforever.types.{TransactionType, Vector3} +import net.psforever.packet.game.{ItemTransactionMessage} +import net.psforever.types.{TransactionType} /** * A structure-owned server object that is a "terminal" that can be accessed for amenities and services. * @param tdef the `ObjectDefinition` that constructs this object and maintains some of its immutable fields */ -class Terminal(tdef : TerminalDefinition) extends Amenity { - /** An entry that maintains a reference to the `Player`, and the player's GUID and location when the message was received. */ - private var hackedBy : Option[(Player, PlanetSideGUID, Vector3)] = None +class Terminal(tdef : TerminalDefinition) extends Amenity with Hackable { - def HackedBy : Option[(Player, PlanetSideGUID, Vector3)] = hackedBy - - def HackedBy_=(agent : Player) : Option[(Player, PlanetSideGUID, Vector3)] = HackedBy_=(Some(agent)) - - /** - * Set the hack state of this object by recording important information about the player that caused it. - * Set the hack state if there is no current hack state. - * Override the hack state with a new hack state if the new user has different faction affiliation. - * @param agent a `Player`, or no player - * @return the player hack entry - */ - def HackedBy_=(agent : Option[Player]) : Option[(Player, PlanetSideGUID, Vector3)] = { - hackedBy match { - case None => - //set the hack state if there is no current hack state - if(agent.isDefined) { - hackedBy = Some(agent.get, agent.get.GUID, agent.get.Position) - } - case Some(_) => - //clear the hack state - if(agent.isEmpty) { - hackedBy = None - } - //override the hack state with a new hack state if the new user has different faction affiliation - else if(agent.get.Faction != hackedBy.get._1.Faction) { - hackedBy = Some(agent.get, agent.get.GUID, agent.get.Position) - } - } - HackedBy - } //the following fields and related methods are neither finalized nor integrated; GOTO Request private var health : Int = 100 //TODO not real health value diff --git a/common/src/main/scala/net/psforever/objects/serverobject/terminals/TerminalControl.scala b/common/src/main/scala/net/psforever/objects/serverobject/terminals/TerminalControl.scala index 4efa324e1..e226fad6b 100644 --- a/common/src/main/scala/net/psforever/objects/serverobject/terminals/TerminalControl.scala +++ b/common/src/main/scala/net/psforever/objects/serverobject/terminals/TerminalControl.scala @@ -2,6 +2,7 @@ package net.psforever.objects.serverobject.terminals import akka.actor.Actor +import net.psforever.objects.serverobject.CommonMessages import net.psforever.objects.serverobject.affinity.{FactionAffinity, FactionAffinityBehavior} /** @@ -15,6 +16,12 @@ class TerminalControl(term : Terminal) extends Actor with FactionAffinityBehavio case Terminal.Request(player, msg) => sender ! Terminal.TerminalMessage(player, msg, term.Request(player, msg)) + case CommonMessages.Hack(player) => + term.HackedBy = player + + case CommonMessages.ClearHack() => + term.HackedBy = None + case _ => ; }