Select Changes from My Original Securities Branch (#286)

* select changes from my original securities branch

* nanoTime -> currentTimeMillis
This commit is contained in:
Fate-JH 2019-10-23 17:21:16 -04:00 committed by pschord
parent 21b17b7649
commit ad29bfe16a
10 changed files with 154 additions and 124 deletions

View file

@ -90,6 +90,7 @@ class WorldSessionActor extends Actor with MDCContextAware {
var progressBarValue : Option[Float] = None
var shooting : Option[PlanetSideGUID] = None //ChangeFireStateMessage_Start
var prefire : Option[PlanetSideGUID] = None //if WeaponFireMessage precedes ChangeFireStateMessage_Start
var shotsWhileDead : Int = 0
var accessedContainer : Option[PlanetSideGameObject with Container] = None
var flying : Boolean = false
var speed : Float = 1.0f
@ -149,6 +150,8 @@ class WorldSessionActor extends Actor with MDCContextAware {
var timeDL : Long = 0
var timeSurge : Long = 0
lazy val unsignedIntMaxValue : Long = Int.MaxValue.toLong * 2L + 1L
var serverTime : Long = 0
var amsSpawnPoints : List[SpawnPoint] = Nil
var clientKeepAlive : Cancellable = DefaultCancellable.obj
@ -166,6 +169,7 @@ class WorldSessionActor extends Actor with MDCContextAware {
* @param b `true` or `false` (or `null`)
* @return 1 for `true`; 0 for `false`
*/
import scala.language.implicitConversions
implicit def boolToInt(b : Boolean) : Int = if(b) 1 else 0
override def postStop() : Unit = {
@ -1406,7 +1410,7 @@ class WorldSessionActor extends Actor with MDCContextAware {
sendResponse(PlanetsideAttributeMessage(guid, attribute_type, attribute_value))
}
case AvatarResponse.PlayerState(msg, spectating, weaponInHand) =>
case AvatarResponse.PlayerState(pos, vel, yaw, pitch, yaw_upper, seq_time, is_crouching, is_jumping, jump_thrust, is_cloaking, spectating, weaponInHand) =>
if(tplayer_guid != guid) {
val now = System.currentTimeMillis()
val (location, time, distanceSq) : (Vector3, Long, Float) = if(spectating) {
@ -1414,30 +1418,30 @@ class WorldSessionActor extends Actor with MDCContextAware {
}
else {
val before = player.lastSeenStreamMessage(guid.guid)
val dist = Vector3.DistanceSquared(player.Position, msg.pos)
(msg.pos, now - before, dist)
val dist = Vector3.DistanceSquared(player.Position, pos)
(pos, now - before, dist)
}
if(spectating ||
((distanceSq < 900 || weaponInHand) && time > 200) ||
(distanceSq < 10000 && time > 500) ||
(distanceSq < 160000 && (
(msg.is_jumping || time < 200)) ||
((msg.vel.isEmpty || Vector3.MagnitudeSquared(msg.vel.get).toInt == 0) && time > 2000) ||
(is_jumping || time < 200)) ||
((vel.isEmpty || Vector3.MagnitudeSquared(vel.get).toInt == 0) && time > 2000) ||
(time > 1000)) ||
(distanceSq > 160000 && time > 5000)) {
sendResponse(
PlayerStateMessage(
guid,
location,
msg.vel,
msg.facingYaw,
msg.facingPitch,
msg.facingYawUpper,
vel,
yaw,
pitch,
yaw_upper,
timestamp = 0,
msg.is_crouching,
msg.is_jumping,
msg.jump_thrust,
msg.is_cloaked
is_crouching,
is_jumping,
jump_thrust,
is_cloaking
)
)
player.lastSeenStreamMessage(guid.guid) = now
@ -3388,8 +3392,9 @@ class WorldSessionActor extends Actor with MDCContextAware {
pkt match {
case sync @ ControlSync(diff, _, _, _, _, _, fa, fb) =>
log.trace(s"SYNC: $sync")
val serverTick = Math.abs(System.nanoTime().toInt) // limit the size to prevent encoding error
sendResponse(ControlSyncResp(diff, serverTick, fa, fb, fb, fa))
val nextDiff = if(diff == 65535) { 0 } else { diff + 1 }
val serverTick = ServerTick
sendResponse(ControlSyncResp(nextDiff, serverTick, fa, fb, fb, fa))
case TeardownConnection(_) =>
log.info("Good bye")
@ -3399,6 +3404,19 @@ class WorldSessionActor extends Actor with MDCContextAware {
}
}
/**
* Return a measure of server time as an unsigned 32-bit integer.
* The server time started at 0 back at the beginning (POSIX time).
* The server time will loop around to 0 again to maintain datatype integrity.
* @see `Int.MaxValue`
* @see `System.nanoTime`
* @return a number that indicates server tick time
*/
def ServerTick : Long = {
serverTime = System.currentTimeMillis() & unsignedIntMaxValue
serverTime
}
def handleGamePkt(pkt : PlanetSideGamePacket) = pkt match {
case ConnectToWorldRequestMessage(server, token, majorVersion, minorVersion, revision, buildDate, unk) =>
val clientVersion = s"Client Version: $majorVersion.$minorVersion.$revision, $buildDate"
@ -3805,7 +3823,7 @@ class WorldSessionActor extends Actor with MDCContextAware {
self ! SetCurrentAvatar(player)
case msg @ PlayerStateMessageUpstream(avatar_guid, pos, vel, yaw, pitch, yaw_upper, seq_time, unk3, is_crouching, is_jumping, unk4, is_cloaking, unk5, unk6) =>
case msg @ PlayerStateMessageUpstream(avatar_guid, pos, vel, yaw, pitch, yaw_upper, seq_time, unk3, is_crouching, is_jumping, jump_thrust, is_cloaking, unk5, unk6) =>
if(deadState == DeadState.Alive) {
if (timeDL != 0) {
if (System.currentTimeMillis() - timeDL > 500) {
@ -3891,7 +3909,7 @@ class WorldSessionActor extends Actor with MDCContextAware {
case Some(item) => item.Definition == GlobalDefinitions.bolt_driver
case None => false
}
avatarService ! AvatarServiceMessage(continent.Id, AvatarAction.PlayerState(avatar_guid, msg, spectator, wepInHand))
avatarService ! AvatarServiceMessage(continent.Id, AvatarAction.PlayerState(avatar_guid, player.Position, player.Velocity, yaw, pitch, yaw_upper, seq_time, is_crouching, is_jumping, jump_thrust, is_cloaking, spectator, wepInHand))
updateSquad()
}
else {
@ -3918,7 +3936,7 @@ class WorldSessionActor extends Actor with MDCContextAware {
//log.warn(s"ChildObjectState: player $player not related to anything with a controllable agent")
}
case msg @ VehicleStateMessage(vehicle_guid, unk1, pos, ang, vel, flight, unk6, unk7, wheels, unk9, is_cloaked) =>
case msg @ VehicleStateMessage(vehicle_guid, unk1, pos, ang, vel, flying, unk6, unk7, wheels, unk9, is_cloaked) =>
if(deadState == DeadState.Alive) {
GetVehicleAndSeat() match {
case (Some(obj), Some(0)) =>
@ -3933,11 +3951,15 @@ class WorldSessionActor extends Actor with MDCContextAware {
if(obj.MountedIn.isEmpty) {
obj.Velocity = vel
if(obj.Definition.CanFly) {
obj.Flying = flight.nonEmpty //usually Some(7)
obj.Flying = flying.nonEmpty //usually Some(7)
}
obj.Cloaked = obj.Definition.CanCloak && is_cloaked
vehicleService ! VehicleServiceMessage(continent.Id, VehicleAction.VehicleState(player.GUID, vehicle_guid, unk1, pos, ang, vel, flight, unk6, unk7, wheels, unk9, is_cloaked))
}
else {
obj.Velocity = None
obj.Flying = false
}
vehicleService ! VehicleServiceMessage(continent.Id, VehicleAction.VehicleState(player.GUID, vehicle_guid, unk1, obj.Position, ang, obj.Velocity, if(obj.Flying) { flying } else { None }, unk6, unk7, wheels, unk9, obj.Cloaked))
updateSquad()
case (None, _) =>
//log.error(s"VehicleState: no vehicle $vehicle_guid found in zone")
@ -5387,6 +5409,12 @@ class WorldSessionActor extends Actor with MDCContextAware {
prefire = None
EmptyMagazine(weapon_guid, tool)
}
else if(!player.isAlive) { //proper internal accounting, but no projectile
prefire = shooting.orElse(Some(weapon_guid))
tool.Discharge
projectiles(projectile_guid.guid - Projectile.BaseUID) = None
shotsWhileDead += 1
}
else { //shooting
if (tool.FireModeIndex == 1 && (tool.Definition.Name == "anniversary_guna" || tool.Definition.Name == "anniversary_gun" || tool.Definition.Name == "anniversary_gunb")) {
player.Stamina = 0
@ -7634,6 +7662,10 @@ class WorldSessionActor extends Actor with MDCContextAware {
case None =>
avatarService ! AvatarServiceMessage(continent.Id, AvatarAction.DestroyDisplay(pentry, pentry, 0))
}
if(shotsWhileDead > 0) {
log.warn(s"KillPlayer/SHOTS_WHILE_DEAD: client of ${avatar.name} fired $shotsWhileDead rounds while character was dead on server")
shotsWhileDead = 0
}
import scala.concurrent.ExecutionContext.Implicits.global
reviveTimer = context.system.scheduler.scheduleOnce(respawnTimer milliseconds, cluster, Zone.Lattice.RequestSpawnPoint(Zones.SanctuaryZoneNumber(tplayer.Faction), tplayer, 7))