mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-07-15 08:24:39 +00:00
fix handling of empty and invalid item clobs
This commit is contained in:
parent
0d4a5ad40e
commit
60caf2c76b
1 changed files with 187 additions and 182 deletions
|
|
@ -380,14 +380,16 @@ class AvatarActor(
|
||||||
|
|
||||||
result.onComplete {
|
result.onComplete {
|
||||||
case Success((loadouts, implants, certs, locker)) =>
|
case Success((loadouts, implants, certs, locker)) =>
|
||||||
avatarCopy(avatar.copy(
|
avatarCopy(
|
||||||
|
avatar.copy(
|
||||||
loadouts = loadouts,
|
loadouts = loadouts,
|
||||||
// make sure we always have the base certifications
|
// make sure we always have the base certifications
|
||||||
certifications =
|
certifications =
|
||||||
certs.map(cert => Certification.withValue(cert.id)).toSet ++ Config.app.game.baseCertifications,
|
certs.map(cert => Certification.withValue(cert.id)).toSet ++ Config.app.game.baseCertifications,
|
||||||
implants = implants.map(implant => Some(Implant(implant.toImplantDefinition))).padTo(3, None),
|
implants = implants.map(implant => Some(Implant(implant.toImplantDefinition))).padTo(3, None),
|
||||||
locker = locker
|
locker = locker
|
||||||
))
|
)
|
||||||
|
)
|
||||||
// if we need to start stamina regeneration
|
// if we need to start stamina regeneration
|
||||||
tryRestoreStaminaForSession(stamina = 1) match {
|
tryRestoreStaminaForSession(stamina = 1) match {
|
||||||
case Some(_) =>
|
case Some(_) =>
|
||||||
|
|
@ -524,7 +526,8 @@ class AvatarActor(
|
||||||
if (certification == Certification.ReinforcedExoSuit) player.ExoSuit == ExoSuitType.Reinforced
|
if (certification == Certification.ReinforcedExoSuit) player.ExoSuit == ExoSuitType.Reinforced
|
||||||
else if (certification == Certification.InfiltrationSuit) player.ExoSuit == ExoSuitType.Infiltration
|
else if (certification == Certification.InfiltrationSuit) player.ExoSuit == ExoSuitType.Infiltration
|
||||||
else if (player.ExoSuit == ExoSuitType.MAX) {
|
else if (player.ExoSuit == ExoSuitType.MAX) {
|
||||||
lazy val subtype = InfantryLoadout.DetermineSubtypeA(ExoSuitType.MAX, player.Slot(slot = 0).Equipment)
|
lazy val subtype =
|
||||||
|
InfantryLoadout.DetermineSubtypeA(ExoSuitType.MAX, player.Slot(slot = 0).Equipment)
|
||||||
if (certification == Certification.UniMAX) true
|
if (certification == Certification.UniMAX) true
|
||||||
else if (certification == Certification.AAMAX) subtype == 1
|
else if (certification == Certification.AAMAX) subtype == 1
|
||||||
else if (certification == Certification.AIMAX) subtype == 2
|
else if (certification == Certification.AIMAX) subtype == 2
|
||||||
|
|
@ -692,8 +695,7 @@ class AvatarActor(
|
||||||
(
|
(
|
||||||
number + 15,
|
number + 15,
|
||||||
player.Zone.GUID(avatar.vehicle) match {
|
player.Zone.GUID(avatar.vehicle) match {
|
||||||
case Some(vehicle: Vehicle)
|
case Some(vehicle: Vehicle) if GlobalDefinitions.isBattleFrameVehicle(vehicle.Definition) =>
|
||||||
if GlobalDefinitions.isBattleFrameVehicle(vehicle.Definition) =>
|
|
||||||
storeVehicleLoadout(player, name, number + 5, vehicle)
|
storeVehicleLoadout(player, name, number + 5, vehicle)
|
||||||
case _ =>
|
case _ =>
|
||||||
throwLoadoutFailure(s"no owned battleframe found for ${player.Name}")
|
throwLoadoutFailure(s"no owned battleframe found for ${player.Name}")
|
||||||
|
|
@ -814,9 +816,11 @@ class AvatarActor(
|
||||||
} else if (implant.definition.implantType.disabledFor.contains(session.get.player.ExoSuit)) {
|
} else if (implant.definition.implantType.disabledFor.contains(session.get.player.ExoSuit)) {
|
||||||
// TODO can this really happen? can we prevent it?
|
// TODO can this really happen? can we prevent it?
|
||||||
} else {
|
} else {
|
||||||
avatarCopy(avatar.copy(
|
avatarCopy(
|
||||||
|
avatar.copy(
|
||||||
implants = avatar.implants.updated(slot, Some(implant.copy(active = true)))
|
implants = avatar.implants.updated(slot, Some(implant.copy(active = true)))
|
||||||
))
|
)
|
||||||
|
)
|
||||||
sessionActor ! SessionActor.SendResponse(
|
sessionActor ! SessionActor.SendResponse(
|
||||||
AvatarImplantMessage(session.get.player.GUID, ImplantAction.Activation, slot, 1)
|
AvatarImplantMessage(session.get.player.GUID, ImplantAction.Activation, slot, 1)
|
||||||
)
|
)
|
||||||
|
|
@ -835,7 +839,8 @@ class AvatarActor(
|
||||||
if (interval.toMillis > 0) {
|
if (interval.toMillis > 0) {
|
||||||
implantTimers(slot) = context.system.scheduler.scheduleWithFixedDelay(interval, interval)(() => {
|
implantTimers(slot) = context.system.scheduler.scheduleWithFixedDelay(interval, interval)(() => {
|
||||||
val player = session.get.player
|
val player = session.get.player
|
||||||
if (implantType match {
|
if (
|
||||||
|
implantType match {
|
||||||
case ImplantType.AdvancedRegen =>
|
case ImplantType.AdvancedRegen =>
|
||||||
//for every 1hp: 2sp (running), 1.5sp (standing), 1sp (crouched)
|
//for every 1hp: 2sp (running), 1.5sp (standing), 1sp (crouched)
|
||||||
// to simulate '1.5sp (standing)', find if 0.0...1.0 * 100 is an even number
|
// to simulate '1.5sp (standing)', find if 0.0...1.0 * 100 is an even number
|
||||||
|
|
@ -860,7 +865,8 @@ class AvatarActor(
|
||||||
}
|
}
|
||||||
case _ =>
|
case _ =>
|
||||||
!player.isAlive || !consumeThisMuchStamina(implant.definition.StaminaCost)
|
!player.isAlive || !consumeThisMuchStamina(implant.definition.StaminaCost)
|
||||||
}) {
|
}
|
||||||
|
) {
|
||||||
context.self ! DeactivateImplant(implantType)
|
context.self ! DeactivateImplant(implantType)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -1253,9 +1259,11 @@ class AvatarActor(
|
||||||
AvatarImplantMessage(session.get.player.GUID, ImplantAction.Initialization, index, 0)
|
AvatarImplantMessage(session.get.player.GUID, ImplantAction.Initialization, index, 0)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
avatarCopy(avatar.copy(
|
avatarCopy(
|
||||||
|
avatar.copy(
|
||||||
implants = avatar.implants.updated(index, Some(imp.copy(initialized = false, active = false)))
|
implants = avatar.implants.updated(index, Some(imp.copy(initialized = false, active = false)))
|
||||||
))
|
)
|
||||||
|
)
|
||||||
//restart initialization process
|
//restart initialization process
|
||||||
implantTimers.get(index).foreach(_.cancel())
|
implantTimers.get(index).foreach(_.cancel())
|
||||||
implantTimers(index) = context.scheduleOnce(
|
implantTimers(index) = context.scheduleOnce(
|
||||||
|
|
@ -1277,9 +1285,11 @@ class AvatarActor(
|
||||||
} match {
|
} match {
|
||||||
case Some((implant, slot)) =>
|
case Some((implant, slot)) =>
|
||||||
implantTimers.get(slot).foreach(_.cancel())
|
implantTimers.get(slot).foreach(_.cancel())
|
||||||
avatarCopy(avatar.copy(
|
avatarCopy(
|
||||||
|
avatar.copy(
|
||||||
implants = avatar.implants.updated(slot, Some(implant.copy(active = false)))
|
implants = avatar.implants.updated(slot, Some(implant.copy(active = false)))
|
||||||
))
|
)
|
||||||
|
)
|
||||||
// Deactivation sound / effect
|
// Deactivation sound / effect
|
||||||
session.get.zone.AvatarEvents ! AvatarServiceMessage(
|
session.get.zone.AvatarEvents ! AvatarServiceMessage(
|
||||||
session.get.zone.id,
|
session.get.zone.id,
|
||||||
|
|
@ -1434,8 +1444,7 @@ class AvatarActor(
|
||||||
val items: String = {
|
val items: String = {
|
||||||
val clobber: StringBuilder = new StringBuilder()
|
val clobber: StringBuilder = new StringBuilder()
|
||||||
//encode holsters
|
//encode holsters
|
||||||
vehicle
|
vehicle.Weapons
|
||||||
.Weapons
|
|
||||||
.collect {
|
.collect {
|
||||||
case (index, slot: EquipmentSlot) if slot.Equipment.nonEmpty =>
|
case (index, slot: EquipmentSlot) if slot.Equipment.nonEmpty =>
|
||||||
clobber.append(encodeLoadoutClobFragment(slot.Equipment.get, index))
|
clobber.append(encodeLoadoutClobFragment(slot.Equipment.get, index))
|
||||||
|
|
@ -1488,12 +1497,14 @@ class AvatarActor(
|
||||||
if (items.nonEmpty) {
|
if (items.nonEmpty) {
|
||||||
saveLockerFunc = storeLocker
|
saveLockerFunc = storeLocker
|
||||||
import ctx._
|
import ctx._
|
||||||
ctx.run(
|
ctx
|
||||||
|
.run(
|
||||||
query[persistence.Locker].insert(
|
query[persistence.Locker].insert(
|
||||||
_.avatarId -> lift(avatar.id),
|
_.avatarId -> lift(avatar.id),
|
||||||
_.items -> lift(items)
|
_.items -> lift(items)
|
||||||
)
|
)
|
||||||
).onComplete {
|
)
|
||||||
|
.onComplete {
|
||||||
case Success(_) =>
|
case Success(_) =>
|
||||||
log.debug(s"saving locker contents belonging to ${avatar.name}")
|
log.debug(s"saving locker contents belonging to ${avatar.name}")
|
||||||
case Failure(e) =>
|
case Failure(e) =>
|
||||||
|
|
@ -1595,7 +1606,8 @@ class AvatarActor(
|
||||||
}
|
}
|
||||||
|
|
||||||
def refreshLoadouts(loadouts: Iterable[(Option[Loadout], Int)]): Unit = {
|
def refreshLoadouts(loadouts: Iterable[(Option[Loadout], Int)]): Unit = {
|
||||||
loadouts.map {
|
loadouts
|
||||||
|
.map {
|
||||||
case (Some(loadout: InfantryLoadout), index) =>
|
case (Some(loadout: InfantryLoadout), index) =>
|
||||||
FavoritesMessage.Infantry(
|
FavoritesMessage.Infantry(
|
||||||
session.get.player.GUID,
|
session.get.player.GUID,
|
||||||
|
|
@ -1632,7 +1644,8 @@ class AvatarActor(
|
||||||
"",
|
"",
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
}.foreach { sessionActor ! SessionActor.SendResponse(_) }
|
}
|
||||||
|
.foreach { sessionActor ! SessionActor.SendResponse(_) }
|
||||||
}
|
}
|
||||||
|
|
||||||
def refreshLoadout(line: Int): Unit = {
|
def refreshLoadout(line: Int): Unit = {
|
||||||
|
|
@ -1646,8 +1659,7 @@ class AvatarActor(
|
||||||
InfantryLoadout.DetermineSubtypeB(loadout.exosuit, loadout.subtype)
|
InfantryLoadout.DetermineSubtypeB(loadout.exosuit, loadout.subtype)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
case Some(Some(loadout: VehicleLoadout))
|
case Some(Some(loadout: VehicleLoadout)) if GlobalDefinitions.isBattleFrameVehicle(loadout.vehicle_definition) =>
|
||||||
if GlobalDefinitions.isBattleFrameVehicle(loadout.vehicle_definition) =>
|
|
||||||
sessionActor ! SessionActor.SendResponse(
|
sessionActor ! SessionActor.SendResponse(
|
||||||
FavoritesMessage.Battleframe(
|
FavoritesMessage.Battleframe(
|
||||||
session.get.player.GUID,
|
session.get.player.GUID,
|
||||||
|
|
@ -1698,11 +1710,13 @@ class AvatarActor(
|
||||||
}
|
}
|
||||||
|
|
||||||
def buildContainedEquipmentFromClob(container: Container, clob: String): Unit = {
|
def buildContainedEquipmentFromClob(container: Container, clob: String): Unit = {
|
||||||
clob.split("/").foreach {
|
clob.split("/").filter(_.trim.nonEmpty).foreach { value =>
|
||||||
value =>
|
|
||||||
val (objectType, objectIndex, objectId, toolAmmo) = value.split(",") match {
|
val (objectType, objectIndex, objectId, toolAmmo) = value.split(",") match {
|
||||||
case Array(a, b: String, c: String) => (a, b.toInt, c.toInt, None)
|
case Array(a, b: String, c: String) => (a, b.toInt, c.toInt, None)
|
||||||
case Array(a, b: String, c: String, d) => (a, b.toInt, c.toInt, Some(d))
|
case Array(a, b: String, c: String, d) => (a, b.toInt, c.toInt, Some(d))
|
||||||
|
case _ =>
|
||||||
|
log.warn(s"ignoring invalid item string: '$value'")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
objectType match {
|
objectType match {
|
||||||
|
|
@ -1729,7 +1743,7 @@ class AvatarActor(
|
||||||
}
|
}
|
||||||
|
|
||||||
toolAmmo foreach { toolAmmo =>
|
toolAmmo foreach { toolAmmo =>
|
||||||
toolAmmo.toString.split("_").drop(1).foreach { value =>
|
toolAmmo.split("_").drop(1).foreach { value =>
|
||||||
val (ammoSlots, ammoTypeIndex, ammoBoxDefinition) = value.split("-") match {
|
val (ammoSlots, ammoTypeIndex, ammoBoxDefinition) = value.split("-") match {
|
||||||
case Array(a: String, b: String, c: String) => (a.toInt, b.toInt, c.toInt)
|
case Array(a: String, b: String, c: String) => (a.toInt, b.toInt, c.toInt)
|
||||||
}
|
}
|
||||||
|
|
@ -1770,17 +1784,12 @@ class AvatarActor(
|
||||||
def resolvePurchaseTimeName(faction: PlanetSideEmpire.Value, item: BasicDefinition): (BasicDefinition, String) = {
|
def resolvePurchaseTimeName(faction: PlanetSideEmpire.Value, item: BasicDefinition): (BasicDefinition, String) = {
|
||||||
val factionName: String = faction.toString.toLowerCase
|
val factionName: String = faction.toString.toLowerCase
|
||||||
val name = item match {
|
val name = item match {
|
||||||
case GlobalDefinitions.trhev_dualcycler |
|
case GlobalDefinitions.trhev_dualcycler | GlobalDefinitions.nchev_scattercannon |
|
||||||
GlobalDefinitions.nchev_scattercannon |
|
|
||||||
GlobalDefinitions.vshev_quasar =>
|
GlobalDefinitions.vshev_quasar =>
|
||||||
s"${factionName}hev_antipersonnel"
|
s"${factionName}hev_antipersonnel"
|
||||||
case GlobalDefinitions.trhev_pounder |
|
case GlobalDefinitions.trhev_pounder | GlobalDefinitions.nchev_falcon | GlobalDefinitions.vshev_comet =>
|
||||||
GlobalDefinitions.nchev_falcon |
|
|
||||||
GlobalDefinitions.vshev_comet =>
|
|
||||||
s"${factionName}hev_antivehicular"
|
s"${factionName}hev_antivehicular"
|
||||||
case GlobalDefinitions.trhev_burster |
|
case GlobalDefinitions.trhev_burster | GlobalDefinitions.nchev_sparrow | GlobalDefinitions.vshev_starfire =>
|
||||||
GlobalDefinitions.nchev_sparrow |
|
|
||||||
GlobalDefinitions.vshev_starfire =>
|
|
||||||
s"${factionName}hev_antiaircraft"
|
s"${factionName}hev_antiaircraft"
|
||||||
case _ =>
|
case _ =>
|
||||||
item.Name
|
item.Name
|
||||||
|
|
@ -1794,25 +1803,21 @@ class AvatarActor(
|
||||||
val faction = name.take(2)
|
val faction = name.take(2)
|
||||||
(if (faction.equals("nc")) {
|
(if (faction.equals("nc")) {
|
||||||
Seq(GlobalDefinitions.nchev_scattercannon, GlobalDefinitions.nchev_falcon, GlobalDefinitions.nchev_sparrow)
|
Seq(GlobalDefinitions.nchev_scattercannon, GlobalDefinitions.nchev_falcon, GlobalDefinitions.nchev_sparrow)
|
||||||
}
|
} else if (faction.equals("vs")) {
|
||||||
else if (faction.equals("vs")) {
|
|
||||||
Seq(GlobalDefinitions.vshev_quasar, GlobalDefinitions.vshev_comet, GlobalDefinitions.vshev_starfire)
|
Seq(GlobalDefinitions.vshev_quasar, GlobalDefinitions.vshev_comet, GlobalDefinitions.vshev_starfire)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Seq(GlobalDefinitions.trhev_dualcycler, GlobalDefinitions.trhev_pounder, GlobalDefinitions.trhev_burster)
|
Seq(GlobalDefinitions.trhev_dualcycler, GlobalDefinitions.trhev_pounder, GlobalDefinitions.trhev_burster)
|
||||||
}).zip(
|
}).zip(
|
||||||
Seq(s"${faction}hev_antipersonnel", s"${faction}hev_antivehicular", s"${faction}hev_antiaircraft")
|
Seq(s"${faction}hev_antipersonnel", s"${faction}hev_antivehicular", s"${faction}hev_antiaircraft")
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
definition match {
|
definition match {
|
||||||
case vdef: VehicleDefinition
|
case vdef: VehicleDefinition if GlobalDefinitions.isBattleFrameFlightVehicle(vdef) =>
|
||||||
if GlobalDefinitions.isBattleFrameFlightVehicle(vdef) =>
|
|
||||||
val bframe = name.substring(0, name.indexOf('_'))
|
val bframe = name.substring(0, name.indexOf('_'))
|
||||||
val gunner = bframe + "_gunner"
|
val gunner = bframe + "_gunner"
|
||||||
Seq((DefinitionUtil.fromString(gunner), gunner), (vdef, name))
|
Seq((DefinitionUtil.fromString(gunner), gunner), (vdef, name))
|
||||||
|
|
||||||
case vdef: VehicleDefinition
|
case vdef: VehicleDefinition if GlobalDefinitions.isBattleFrameGunnerVehicle(vdef) =>
|
||||||
if GlobalDefinitions.isBattleFrameGunnerVehicle(vdef) =>
|
|
||||||
val bframe = name.substring(0, name.indexOf('_'))
|
val bframe = name.substring(0, name.indexOf('_'))
|
||||||
val flight = bframe + "_flight"
|
val flight = bframe + "_flight"
|
||||||
Seq((vdef, name), (DefinitionUtil.fromString(flight), flight))
|
Seq((vdef, name), (DefinitionUtil.fromString(flight), flight))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue