Skip to content

Commit

Permalink
Zone Setup (#1208)
Browse files Browse the repository at this point in the history
* zone entity setup code has been moved from an instance method to a class function

* port address bind to socket and request to join game world address are different
  • Loading branch information
Fate-JH authored Jul 1, 2024
1 parent 00a6f2a commit 6d1530c
Show file tree
Hide file tree
Showing 4 changed files with 354 additions and 303 deletions.
14 changes: 9 additions & 5 deletions src/main/scala/net/psforever/actors/net/LoginActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import scala.concurrent.duration._
import scala.util.matching.Regex
import scala.util.{Failure, Success}



object LoginActor {
sealed trait Command

Expand Down Expand Up @@ -56,7 +58,7 @@ class LoginActor(middlewareActor: typed.ActorRef[MiddlewareActor.Command], conne
var port: Int = 0

val serverName: String = Config.app.world.serverName
val publicAddress = new InetSocketAddress(InetAddress.getByName(Config.app.public), Config.app.world.port)
val gameTestServerAddress = new InetSocketAddress(InetAddress.getByName(Config.app.public), Config.app.world.port)

private val bcryptRounds = 12

Expand Down Expand Up @@ -87,8 +89,10 @@ class LoginActor(middlewareActor: typed.ActorRef[MiddlewareActor.Command], conne
case packet: PlanetSideGamePacket =>
handleGamePkt(packet)

case SocketPane.NextPort(_, address, portNum) =>
val response = ConnectToWorldMessage(serverName, address.getHostAddress, portNum)
case SocketPane.NextPort(_, _, portNum) =>
val address = gameTestServerAddress.getAddress.getHostAddress
log.info(s"Connecting to ${address.toLowerCase}: $portNum ...")
val response = ConnectToWorldMessage(serverName, address, portNum)
middlewareActor ! MiddlewareActor.Send(response)
middlewareActor ! MiddlewareActor.Close()

Expand All @@ -109,7 +113,7 @@ class LoginActor(middlewareActor: typed.ActorRef[MiddlewareActor.Command], conne
requestAccountLogin(username, password, token)

case ConnectToWorldRequestMessage(name, _, _, _, _, _, _, _) =>
log.info(s"Connect to world request for '$name'")
log.info(s"Request to connect to world '$name' ...")
sockets ! SocketPane.GetNextPort("world", context.self)

case _ =>
Expand Down Expand Up @@ -440,7 +444,7 @@ class LoginActor(middlewareActor: typed.ActorRef[MiddlewareActor.Command], conne
serverName,
WorldStatus.Up,
Config.app.world.serverType,
Vector(WorldConnectionInfo(publicAddress)), //todo ideally, ask for info from SocketPane
Vector(WorldConnectionInfo(gameTestServerAddress)), //todo ideally, ask for info from SocketPane
PlanetSideEmpire.VS
)
)
Expand Down
37 changes: 29 additions & 8 deletions src/main/scala/net/psforever/actors/zone/ZoneActor.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.psforever.actors.zone

import akka.actor.typed.{ActorRef, Behavior, SupervisorStrategy}
import akka.actor.typed.scaladsl.{AbstractBehavior, ActorContext, Behaviors}
import akka.actor.typed.{ActorRef, Behavior, PostStop, SupervisorStrategy}
import akka.actor.typed.scaladsl.{ActorContext, Behaviors}
import net.psforever.objects.ce.Deployable
import net.psforever.objects.equipment.Equipment
import net.psforever.objects.serverobject.structures.{StructureType, WarpGate}
Expand Down Expand Up @@ -29,7 +29,7 @@ object ZoneActor {
def apply(zone: Zone): Behavior[Command] =
Behaviors
.supervise[Command] {
Behaviors.setup(context => new ZoneActor(context, zone))
Behaviors.setup(context => new ZoneActor(context, zone).onMessage())
}
.onFailure[Exception](SupervisorStrategy.resume)

Expand Down Expand Up @@ -80,8 +80,10 @@ object ZoneActor {
final case class RewardOurSupporters(target: SourceEntry, history: Iterable[InGameActivity], kill: Kill, bep: Long) extends Command
}

class ZoneActor(context: ActorContext[ZoneActor.Command], zone: Zone)
extends AbstractBehavior[ZoneActor.Command](context) {
class ZoneActor(
context: ActorContext[ZoneActor.Command],
zone: Zone
) {

import ZoneActor._
import ctx._
Expand Down Expand Up @@ -116,59 +118,78 @@ class ZoneActor(context: ActorContext[ZoneActor.Command], zone: Zone)
case Failure(e) => log.error(e.getMessage)
}

def onMessage(msg: Command): Behavior[Command] = {
msg match {
def onMessage(): Behavior[Command] = {
Behaviors.receiveMessagePartial[Command] {
case GetZone(replyTo) =>
replyTo ! ZoneResponse(zone)
Behaviors.same

case AddPlayer(player) =>
players.addOne(player)
Behaviors.same

case RemovePlayer(player) =>
players.filterInPlace(p => p.CharId == player.CharId)
Behaviors.same

case DropItem(item, position, orientation) =>
zone.Ground ! Zone.Ground.DropItem(item, position, orientation)
Behaviors.same

case PickupItem(guid) =>
zone.Ground ! Zone.Ground.PickupItem(guid)
Behaviors.same

case BuildDeployable(obj, _) =>
zone.Deployables ! Zone.Deployable.Build(obj)
Behaviors.same

case DismissDeployable(obj) =>
zone.Deployables ! Zone.Deployable.Dismiss(obj)
Behaviors.same

case SpawnVehicle(vehicle) =>
zone.Transport ! Zone.Vehicle.Spawn(vehicle)
Behaviors.same

case DespawnVehicle(vehicle) =>
zone.Transport ! Zone.Vehicle.Despawn(vehicle)
Behaviors.same

case AddToBlockMap(target, toPosition) =>
zone.blockMap.addTo(target, toPosition)
Behaviors.same

case UpdateBlockMap(target, toPosition) =>
zone.blockMap.move(target, toPosition)
Behaviors.same

case RemoveFromBlockMap(target) =>
zone.blockMap.removeFrom(target)
Behaviors.same

case HotSpotActivity(defender, attacker, location) =>
zone.Activity ! Zone.HotSpot.Activity(defender, attacker, location)
Behaviors.same

case RewardThisDeath(entity) =>
experience ! ExperienceCalculator.RewardThisDeath(entity)
Behaviors.same

case RewardOurSupporters(target, history, kill, bep) =>
supportExperience ! SupportExperienceCalculator.RewardOurSupporters(target, history, kill, bep)
Behaviors.same

case ZoneMapUpdate() =>
zone.Buildings
.filter(_._2.BuildingType == StructureType.Facility)
.values
.foreach(_.Actor ! BuildingActor.MapUpdate())
Behaviors.same
}
.receiveSignal {
case (_, PostStop) =>
Behaviors.same
}
this
}
}
Loading

0 comments on commit 6d1530c

Please sign in to comment.