mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-02-13 19:53:38 +00:00
Rename existing galaxy service to cluster and add GalaxyService to send map updates to all connected clients
This commit is contained in:
parent
aa81116260
commit
86bb83dc09
9 changed files with 114 additions and 22 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 _ => ;
|
||||
}
|
||||
|
||||
|
|
|
|||
10
common/src/main/scala/services/galaxy/GalaxyAction.scala
Normal file
10
common/src/main/scala/services/galaxy/GalaxyAction.scala
Normal file
|
|
@ -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
|
||||
}
|
||||
10
common/src/main/scala/services/galaxy/GalaxyResponse.scala
Normal file
10
common/src/main/scala/services/galaxy/GalaxyResponse.scala
Normal file
|
|
@ -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
|
||||
}
|
||||
50
common/src/main/scala/services/galaxy/GalaxyService.scala
Normal file
50
common/src/main/scala/services/galaxy/GalaxyService.scala
Normal file
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
package services.galaxy
|
||||
|
||||
final case class GalaxyServiceMessage(actionMessage : GalaxyAction.Action)
|
||||
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue