diff --git a/common/src/main/scala/net/psforever/objects/serverobject/resourcesilo/ResourceSilo.scala b/common/src/main/scala/net/psforever/objects/serverobject/resourcesilo/ResourceSilo.scala index 9e653c31..d62dccb0 100644 --- a/common/src/main/scala/net/psforever/objects/serverobject/resourcesilo/ResourceSilo.scala +++ b/common/src/main/scala/net/psforever/objects/serverobject/resourcesilo/ResourceSilo.scala @@ -56,7 +56,6 @@ object ResourceSilo { final case class Use(player: Player, msg : UseItemMessage) final case class UpdateChargeLevel(amount: Int) final case class LowNtuWarning(enabled: Int) - final case class SyncStateWithClient() sealed trait Exchange final case class ChargeEvent() extends Exchange final case class ResourceSiloMessage(player: Player, msg : UseItemMessage, response : Exchange) diff --git a/common/src/main/scala/net/psforever/objects/serverobject/resourcesilo/ResourceSiloControl.scala b/common/src/main/scala/net/psforever/objects/serverobject/resourcesilo/ResourceSiloControl.scala index 18e38fde..9e711958 100644 --- a/common/src/main/scala/net/psforever/objects/serverobject/resourcesilo/ResourceSiloControl.scala +++ b/common/src/main/scala/net/psforever/objects/serverobject/resourcesilo/ResourceSiloControl.scala @@ -24,7 +24,7 @@ class ResourceSiloControl(resourceSilo : ResourceSilo) extends Actor with Factio def receive : Receive = { case "startup" => - ServiceManager.serviceManager ! Lookup("avatar") //ask for a resolver to deal with the GUID system + ServiceManager.serviceManager ! Lookup("avatar") case ServiceManager.LookupResult("avatar", endpoint) => avatarService = endpoint @@ -69,10 +69,6 @@ class ResourceSiloControl(resourceSilo : ResourceSilo) extends Actor with Factio } //todo: Shut down base power and make base neutral if silo hits zero NTU - case ResourceSilo.SyncStateWithClient() => - avatarService ! AvatarServiceMessage(resourceSilo.Owner.asInstanceOf[Building].Zone.Id, AvatarAction.PlanetsideAttribute(PlanetSideGUID(resourceSilo.Owner.asInstanceOf[Building].ModelId), 47, resourceSilo.LowNtuWarningOn)) - avatarService ! AvatarServiceMessage(resourceSilo.Owner.asInstanceOf[Building].Zone.Id, AvatarAction.PlanetsideAttribute(resourceSilo.GUID, 45, resourceSilo.CapacitorDisplay)) - case _ => ; } diff --git a/common/src/main/scala/services/galaxy/GalaxyAction.scala b/common/src/main/scala/services/galaxy/GalaxyAction.scala new file mode 100644 index 00000000..7bb9c794 --- /dev/null +++ b/common/src/main/scala/services/galaxy/GalaxyAction.scala @@ -0,0 +1,10 @@ +// Copyright (c) 2017 PSForever +package services.galaxy + +import net.psforever.packet.game.{BuildingInfoUpdateMessage} + +object GalaxyAction { + trait Action + + final case class MapUpdate(msg: BuildingInfoUpdateMessage) extends Action +} diff --git a/common/src/main/scala/services/galaxy/GalaxyResponse.scala b/common/src/main/scala/services/galaxy/GalaxyResponse.scala new file mode 100644 index 00000000..8026085f --- /dev/null +++ b/common/src/main/scala/services/galaxy/GalaxyResponse.scala @@ -0,0 +1,10 @@ +// Copyright (c) 2017 PSForever +package services.galaxy + +import net.psforever.packet.game.{BuildingInfoUpdateMessage} + +object GalaxyResponse { + trait Response + + final case class MapUpdate(msg: BuildingInfoUpdateMessage) extends Response +} diff --git a/common/src/main/scala/services/galaxy/GalaxyService.scala b/common/src/main/scala/services/galaxy/GalaxyService.scala new file mode 100644 index 00000000..2e83802e --- /dev/null +++ b/common/src/main/scala/services/galaxy/GalaxyService.scala @@ -0,0 +1,50 @@ +// Copyright (c) 2017 PSForever +package services.galaxy + +import akka.actor.{Actor, Props} +import net.psforever.packet.game.BuildingInfoUpdateMessage +import services.local.support.{DoorCloseActor, HackClearActor} +import services.{GenericEventBus, Service} + +class GalaxyService extends Actor { + private [this] val log = org.log4s.getLogger + + override def preStart = { + log.info("Starting...") + } + + val GalaxyEvents = new GenericEventBus[GalaxyServiceResponse] + + def receive = { + // Service.Join requires a channel to be passed in normally but GalaxyService is an exception in that messages go to ALL connected players + case Service.Join(_) => + val path = s"/Galaxy" + val who = sender() + log.info(s"$who has joined $path") + GalaxyEvents.subscribe(who, path) + + case Service.Leave(None) => + GalaxyEvents.unsubscribe(sender()) + + case Service.Leave(_) => + val path = s"/Galaxy" + val who = sender() + log.info(s"$who has left $path") + GalaxyEvents.unsubscribe(who, path) + + case Service.LeaveAll() => + GalaxyEvents.unsubscribe(sender()) + + case GalaxyServiceMessage(action) => + action match { + case GalaxyAction.MapUpdate(msg: BuildingInfoUpdateMessage) => + log.warn(s"Publishing msg ${msg}") + GalaxyEvents.publish( + GalaxyServiceResponse(s"/Galaxy", GalaxyResponse.MapUpdate(msg)) + ) + case _ => ; + } + case msg => + log.info(s"Unhandled message $msg from $sender") + } +} diff --git a/common/src/main/scala/services/galaxy/GalaxyServiceMessage.scala b/common/src/main/scala/services/galaxy/GalaxyServiceMessage.scala new file mode 100644 index 00000000..a013af5e --- /dev/null +++ b/common/src/main/scala/services/galaxy/GalaxyServiceMessage.scala @@ -0,0 +1,4 @@ +// Copyright (c) 2017 PSForever +package services.galaxy + +final case class GalaxyServiceMessage(actionMessage : GalaxyAction.Action) diff --git a/common/src/main/scala/services/galaxy/GalaxyServiceResponse.scala b/common/src/main/scala/services/galaxy/GalaxyServiceResponse.scala new file mode 100644 index 00000000..28125a89 --- /dev/null +++ b/common/src/main/scala/services/galaxy/GalaxyServiceResponse.scala @@ -0,0 +1,9 @@ +// Copyright (c) 2017 PSForever +package services.galaxy + +import net.psforever.packet.game.PlanetSideGUID +import services.GenericEventBusMsg + +final case class GalaxyServiceResponse(toChannel : String, + replyMessage : GalaxyResponse.Response + ) extends GenericEventBusMsg diff --git a/pslogin/src/main/scala/PsLogin.scala b/pslogin/src/main/scala/PsLogin.scala index e689aa9e..469ed631 100644 --- a/pslogin/src/main/scala/PsLogin.scala +++ b/pslogin/src/main/scala/PsLogin.scala @@ -19,6 +19,7 @@ import org.fusesource.jansi.Ansi._ import org.fusesource.jansi.Ansi.Color._ import services.ServiceManager import services.avatar._ +import services.galaxy.GalaxyService import services.local._ import services.vehicle.VehicleService @@ -209,7 +210,8 @@ object PsLogin { serviceManager ! ServiceManager.Register(Props[AvatarService], "avatar") serviceManager ! ServiceManager.Register(Props[LocalService], "local") serviceManager ! ServiceManager.Register(Props[VehicleService], "vehicle") - serviceManager ! ServiceManager.Register(Props(classOf[InterstellarCluster], continentList), "galaxy") + serviceManager ! ServiceManager.Register(Props[GalaxyService], "galaxy") + serviceManager ! ServiceManager.Register(Props(classOf[InterstellarCluster], continentList), "cluster") //attach event bus entry point to each zone import akka.pattern.ask diff --git a/pslogin/src/main/scala/WorldSessionActor.scala b/pslogin/src/main/scala/WorldSessionActor.scala index b7c1ac86..c0d5dde0 100644 --- a/pslogin/src/main/scala/WorldSessionActor.scala +++ b/pslogin/src/main/scala/WorldSessionActor.scala @@ -40,6 +40,7 @@ import net.psforever.packet.game.objectcreate._ import net.psforever.types._ import services._ import services.avatar.{AvatarAction, AvatarResponse, AvatarServiceMessage, AvatarServiceResponse} +import services.galaxy.{GalaxyResponse, GalaxyServiceResponse} import services.local.{LocalAction, LocalResponse, LocalServiceMessage, LocalServiceResponse} import services.vehicle.VehicleAction.UnstowEquipment import services.vehicle.{VehicleAction, VehicleResponse, VehicleServiceMessage, VehicleServiceResponse} @@ -59,8 +60,9 @@ class WorldSessionActor extends Actor with MDCContextAware { var avatarService : ActorRef = ActorRef.noSender var localService : ActorRef = ActorRef.noSender var vehicleService : ActorRef = ActorRef.noSender + var galaxyService : ActorRef = ActorRef.noSender var taskResolver : ActorRef = Actor.noSender - var galaxy : ActorRef = Actor.noSender + var cluster : ActorRef = Actor.noSender var continent : Zone = Zone.Nowhere var player : Player = null var avatar : Avatar = null @@ -104,6 +106,7 @@ class WorldSessionActor extends Actor with MDCContextAware { localService ! Service.Leave() vehicleService ! Service.Leave() avatarService ! Service.Leave() + galaxyService ! Service.Leave() LivePlayerList.Remove(sessionId) if(player != null && player.HasGUID) { @@ -217,6 +220,7 @@ class WorldSessionActor extends Actor with MDCContextAware { ServiceManager.serviceManager ! Lookup("local") ServiceManager.serviceManager ! Lookup("vehicle") ServiceManager.serviceManager ! Lookup("taskResolver") + ServiceManager.serviceManager ! Lookup("cluster") ServiceManager.serviceManager ! Lookup("galaxy") case _ => @@ -238,8 +242,11 @@ class WorldSessionActor extends Actor with MDCContextAware { taskResolver = endpoint log.info("ID: " + sessionId + " Got task resolver service " + endpoint) case ServiceManager.LookupResult("galaxy", endpoint) => - galaxy = endpoint + galaxyService = endpoint log.info("ID: " + sessionId + " Got galaxy service " + endpoint) + case ServiceManager.LookupResult("cluster", endpoint) => + cluster = endpoint + log.info("ID: " + sessionId + " Got cluster service " + endpoint) case ControlPacket(_, ctrl) => handleControlPkt(ctrl) @@ -409,6 +416,13 @@ class WorldSessionActor extends Actor with MDCContextAware { case _ => ; } + case GalaxyServiceResponse(_, reply) => + reply match { + case GalaxyResponse.MapUpdate(msg) => + log.warn(s"Client ${player.GUID} Updating map ${msg}") + sendResponse(msg) + } + case LocalServiceResponse(_, guid, reply) => val tplayer_guid = if(player.HasGUID) { player.GUID} else { PlanetSideGUID(0) } reply match { @@ -1385,7 +1399,7 @@ class WorldSessionActor extends Actor with MDCContextAware { reviveTimer.cancel if(spawn_group == 2) { sendResponse(ChatMsg(ChatMessageType.CMT_OPEN, false, "", "No friendly AMS is deployed in this region.", None)) - galaxy ! Zone.Lattice.RequestSpawnPoint(zone_number, player, 0) + cluster ! Zone.Lattice.RequestSpawnPoint(zone_number, player, 0) } else { RequestSanctuaryZoneSpawn(player, zone_number) @@ -1401,7 +1415,7 @@ class WorldSessionActor extends Actor with MDCContextAware { sendResponse(ReplicationStreamMessage(5, Some(6), Vector(SquadListing()))) //clear squad list sendResponse(FriendsResponse(FriendAction.InitializeFriendList, 0, true, true, Nil)) sendResponse(FriendsResponse(FriendAction.InitializeIgnoreList, 0, true, true, Nil)) - galaxy ! InterstellarCluster.GetWorld("z6") + cluster ! InterstellarCluster.GetWorld("z6") case InterstellarCluster.GiveWorld(zoneId, zone) => log.info(s"Zone $zoneId will now load") @@ -1544,12 +1558,8 @@ class WorldSessionActor extends Actor with MDCContextAware { vehicle.Capacitor -= chargeToDeposit silo.Actor ! ResourceSilo.UpdateChargeLevel(chargeToDeposit) - log.warn(AvatarServiceMessage(continent.Id, AvatarAction.PlanetsideAttribute(silo_guid, 45, 1L)).toString) -// avatarService ! AvatarServiceMessage(continent.Id, AvatarAction.PlanetsideAttribute(silo_guid, 45, 1L)) // set silo ntu level avatarService ! AvatarServiceMessage(continent.Id, AvatarAction.PlanetsideAttribute(silo_guid, 49, 1L)) // panel glow on & orb particles on - sendResponse(PlanetsideAttributeMessage(vehicle.GUID, 45, scala.math.round((vehicle.Capacitor.toFloat / vehicle.Definition.MaximumCapacitor.toFloat) * 10))) // set ntu on vehicle UI -// avatarService ! AvatarServiceMessage(continent.Id, AvatarAction.PlanetsideAttribute(silo_guid, 45, scala.math.round((silo.ChargeLevel.toFloat / silo.MaximumCharge.toFloat) * 10))) // set ntu on silo bar //todo: grant BEP to user //todo: grant BEP to squad in range @@ -1723,7 +1733,7 @@ class WorldSessionActor extends Actor with MDCContextAware { //TODO check if can spawn on last continent/location from player? //TODO if yes, get continent guid accessors //TODO if no, get sanctuary guid accessors and reset the player's expectations - galaxy ! InterstellarCluster.RequestClientInitialization() + cluster ! InterstellarCluster.RequestClientInitialization() case default => log.error("Unsupported " + default + " in " + msg) } @@ -1738,6 +1748,7 @@ class WorldSessionActor extends Actor with MDCContextAware { avatarService ! Service.Join(continent.Id) localService ! Service.Join(continent.Id) vehicleService ! Service.Join(continent.Id) + galaxyService ! Service.Join("galaxy") configZone(continent) sendResponse(TimeOfDayMessage(1191182336)) //custom @@ -1935,7 +1946,7 @@ class WorldSessionActor extends Actor with MDCContextAware { case msg @ SpawnRequestMessage(u1, u2, u3, u4, u5) => log.info(s"SpawnRequestMessage: $msg") //TODO just focus on u5 and u2 for now - galaxy ! Zone.Lattice.RequestSpawnPoint(u5.toInt, player, u2.toInt) + cluster ! Zone.Lattice.RequestSpawnPoint(u5.toInt, player, u2.toInt) case msg @ SetChatFilterMessage(send_channel, origin, whitelist) => log.info("SetChatFilters: " + msg) @@ -2038,7 +2049,7 @@ class WorldSessionActor extends Actor with MDCContextAware { else if(trimContents.equals("!ams")) { makeReply = false if(player.isBackpack) { //player is on deployment screen (either dead or deconstructed) - galaxy ! Zone.Lattice.RequestSpawnPoint(continent.Number, player, 2) + cluster ! Zone.Lattice.RequestSpawnPoint(continent.Number, player, 2) } } // TODO: Depending on messagetype, may need to prepend sender's name to contents with proper spacing @@ -3410,7 +3421,7 @@ class WorldSessionActor extends Actor with MDCContextAware { def TaskBeforeZoneChange(priorTask : TaskResolver.GiveTask, zoneId : String) : TaskResolver.GiveTask = { TaskResolver.GiveTask( new Task() { - private val localService = galaxy + private val localService = cluster private val localMsg = InterstellarCluster.GetWorld(zoneId) override def isComplete : Task.Resolution.Value = priorTask.task.isComplete @@ -4278,7 +4289,8 @@ class WorldSessionActor extends Actor with MDCContextAware { def initFacility(continentNumber : Int, buildingNumber : Int, building : Building) : Unit = { var ntuLevel = 0 building.Amenities.filter(x => (x.Definition == GlobalDefinitions.resource_silo)).headOption.asInstanceOf[Option[ResourceSilo]] match { - case Some(obj: ResourceSilo) => ntuLevel = obj.CapacitorDisplay.toInt + case Some(obj: ResourceSilo) => + ntuLevel = obj.CapacitorDisplay.toInt case _ => ; } @@ -4410,7 +4422,7 @@ class WorldSessionActor extends Actor with MDCContextAware { import scala.concurrent.duration._ import scala.concurrent.ExecutionContext.Implicits.global - reviveTimer = context.system.scheduler.scheduleOnce(respawnTimer milliseconds, galaxy, Zone.Lattice.RequestSpawnPoint(Zones.SanctuaryZoneNumber(tplayer.Faction), tplayer, 7)) + reviveTimer = context.system.scheduler.scheduleOnce(respawnTimer milliseconds, cluster, Zone.Lattice.RequestSpawnPoint(Zones.SanctuaryZoneNumber(tplayer.Faction), tplayer, 7)) } /** @@ -4575,7 +4587,7 @@ class WorldSessionActor extends Actor with MDCContextAware { sendResponse(DisconnectMessage("Player failed to load on faction's sanctuary continent. Please relog.")) } else { - galaxy ! Zone.Lattice.RequestSpawnPoint(sanctNumber, tplayer, 7) + cluster ! Zone.Lattice.RequestSpawnPoint(sanctNumber, tplayer, 7) } }