public void ClientInstantCast(byte skillId, Vector3 hitPoint, uLink.NetworkMessageInfo info) { // TODO: Security checks // TODO: Stagger / stun check // Invalid skill ID? if (skillId < 0 || skillId >= skills.Count) { LogWarning("InstantCastRejected: " + CastError.InvalidSkillId.ToString()); networkView.RPC("InstantCastRejected", info.sender, CastError.InvalidSkillId); return; } // Can't cast while casting already if (currentSkill != null) { LogWarning("InstantCastRejected: " + CastError.CurrentSkillNotNull.ToString()); networkView.RPC("InstantCastRejected", info.sender, CastError.CurrentSkillNotNull); return; } // Select skill currentSkill = skills[skillId]; // Check if it's insta-castable if (currentSkill.currentStage.castDuration != 0f) { LogWarning("InstantCastRejected: " + CastError.CastSpeedHack.ToString()); networkView.RPC("InstantCastRejected", info.sender, CastError.CastSpeedHack); return; } // We transform time backwards for cooldown calculation to prevent // false cooldown hack messages. var lastUsage = (float)(uLink.Network.time) - info.GetPacketArrivalTime(); // Use the skill UseSkill(currentSkill, hitPoint, -1, lastUsage); // Let others know networkView.RPC("InstantCast", uLink.RPCMode.OthersExceptOwner, skillId, hitPoint); // Animation if (animator != null) { animator.SetBool(interruptedHash, false); animator.SetBool(skillEndedHash, false); } SetCastAnimationState(0, 1); // Anim duration DelayedEndSkill(info.timestamp); }
protected void M(Vector3 newPosition, Vector3 direction, ushort rotationY, byte newBitMask, uLink.NetworkMessageInfo info) { if (info.timestamp <= ignoreNewPositionEarlierThanTimestamp) { LogSpam("Server position packet outdated, dropped!"); return; } if (networkViewIsProxy) { serverPosition = newPosition + direction * moveSpeed * info.GetPacketArrivalTime() * Config.instance.serverPositionPredictionFactor; movementKeysPressed = (newBitMask & 1) != 0; jumping = (newBitMask & 2) != 0; proxyInterpolationTime = 0f; interpolationStartPosition = myTransform.position; //moveVector = newMoveVector; animator.SetBool("Moving", movementKeysPressed); animator.SetBool("Jump", jumping); } else { serverPosition = newPosition; } // Rotation serverRotationY = rotationY * Cache.rotationShortToFloat; // Visualization if (Debugger.instance.showServerPosition) { if (!serverPositionVisualization.gameObject.activeSelf) { serverPositionVisualization.gameObject.SetActive(Debugger.instance.showServerPosition); } serverPositionVisualization.position = serverPosition; serverPositionVisualization.rotation = Quaternion.AngleAxis(serverRotationY, Vector3.up); } // Track time //Debug.Log(info.timestampInMillis - lastPositionReceived + " ms"); //lastPositionReceived = info.timestampInMillis; }
void S(Vector3 nClientPosition, Vector3 newMoveVector, byte nBitMask, uLink.NetworkMessageInfo info) { // Make sure we throw away messages from the wrong client if (info.sender != networkView.owner) { return; } if (info.timestamp <= ltsClientVelocity || info.timestamp <= ignoreNewPositionEarlierThanTimestamp) { return; } //camPosition = nCamPosition; bool nMovementKeysPressed = (nBitMask & 1) != 0; bool nJumping = (nBitMask & 2) != 0; clientGrounded = (nBitMask & 4) != 0; // Always accept client position coordinates clientPosition = nClientPosition; // Can't move while stunned if (stunned > 0 || immobilized > 0 || slept > 0 || !canAct) { return; } if (newMoveVector.sqrMagnitude > 1) { newMoveVector.Normalize(); } // Predict client's current position if he just started running PredictClientPosition(info.GetPacketArrivalTime(), newMoveVector); //float directionAngle = directionAngleAsUShort * rotationShortToFloat * degToRad; //horizontalMovement = newMoveVector.x; //Mathf.Sin(directionAngle); //verticalMovement = newMoveVector.z; //Mathf.Cos(directionAngle); movementKeysPressed = nMovementKeysPressed; lastMovementKeysPressedReceived = nMovementKeysPressed; jumping = nJumping; ltsClientVelocity = info.timestamp; }
protected void M(Vector3 position, Vector3 direction, ushort rotationY, uLink.NetworkMessageInfo info) { direction.Normalize(); var extraPolationOffset = direction * moveSpeed * info.GetPacketArrivalTime(); //if(id == 0) // Debug.Log(direction + ", " + this.moveSpeed + ", " + info.GetPacketArrivalTime() + ", " + extraPolationOffset); serverPosition = position + extraPolationOffset; serverRotationY = rotationY * Cache.rotationShortToFloat; interpolationStartPosition = myTransform.position; proxyInterpolationTime = 0f; // Animation animator.SetBool("Moving", direction != Cache.vector3Zero); }
public void ClientEndCast(Vector3 hitPoint, uLink.NetworkMessageInfo info) { // Make sure we throw away late and duplicate RPC messages, or from the wrong client if (info.sender != networkView.owner) { return; } /*if(info.timestamp <= ltsClientEndCast) { * DLogWarning("Old ClientEndCast message arrived"); * //networkView.RPC("EndCastRejected", info.sender, CastError.); * return; * }*/ // Did we start a cast and are we still casting it? if (currentSkill == null) { LogWarning("EndCastRejected: " + CastError.CurrentSkillNull); networkView.RPC("EndCastRejected", uLink.RPCMode.Others, CastError.CurrentSkillNull); return; } // Can't end casts while stunned if (stagger > 0 || stunned > 0 || slept > 0 || !isAlive || blocking) { LogWarning("EndCastRejected: " + CastError.NoControl); networkView.RPC("EndCastRejected", uLink.RPCMode.Others, CastError.NoControl); EndSkill(); return; } // Anti cast speed hack double castDuration = uLink.Network.time - startedSkillCast; if (castDuration + 0.1f < currentSkill.currentStage.castDuration * attackSpeedMultiplier) { LogWarning("Detected cast speed hack: " + currentSkill.skillName + " with " + castDuration + " / " + (currentSkill.currentStage.castDuration * attackSpeedMultiplier)); networkView.RPC("EndCastRejected", uLink.RPCMode.Others, CastError.CastSpeedHack); EndSkill(); return; //networkView.RPC("EndCast", uLink.RPCMode.Owner, hitPoint); //return; } else { LogSpam(currentSkill.skillStageName + " ended cast with cast duration: " + castDuration.ToString("0.00") + " / " + (currentSkill.currentStage.castDuration * attackSpeedMultiplier).ToString("0.00")); } // Instantiate it locally try { // We transform time backwards for cooldown calculation to prevent // false cooldown hack messages. var lastUsage = (float)(uLink.Network.time) - info.GetPacketArrivalTime(); // Finally we can activate the skill UseSkill(currentSkill, hitPoint, -1, lastUsage); } catch { throw; } finally { // Whatever happens, we want the client to finish the animation networkView.RPC("EndCast", uLink.RPCMode.OthersExceptOwner, hitPoint); // Reset to stage 1 currentSkill.currentStageIndex = 0; // Anim duration if (!currentSkill.canHold) { DelayedEndSkill(info.timestamp); } // Here currentSkill could be null already //ltsClientEndCast = info.timestamp; } }