protected override void ServerRead(VRage.Library.Collections.BitStream stream, ulong clientId, uint timestamp) { base.ServerRead(stream, clientId, timestamp); bool clientHasCharacter = stream.ReadBool(); if (clientHasCharacter) { MyEntity support; if (stream.ReadBool()) { bool apply = MyEntities.TryGetEntityById(stream.ReadInt64(), out support); if (m_character != null) { var physGroup = MyExternalReplicable.FindByObject(m_character).FindStateGroup<MyCharacterPhysicsStateGroup>(); if (physGroup != null && apply) { physGroup.SetSupport(MySupportHelper.FindPhysics(support)); } } } Vector3 move = new Vector3(); move.X = stream.ReadHalf(); move.Y = stream.ReadHalf(); move.Z = stream.ReadHalf(); Vector2 rotate = new Vector2(); rotate.X = stream.ReadFloat(); rotate.Y = stream.ReadFloat(); float roll = stream.ReadFloat(); MyCharacterMovementEnum MovementState = (MyCharacterMovementEnum)stream.ReadUInt16(); MyCharacterMovementFlags MovementFlag = (MyCharacterMovementFlags)stream.ReadUInt16(); bool Jetpack = stream.ReadBool(); bool Dampeners = stream.ReadBool(); bool Lights = stream.ReadBool(); // TODO: Remove bool Ironsight = stream.ReadBool(); bool Broadcast = stream.ReadBool(); // TODO: Remove bool TargetFromCamera = stream.ReadBool(); float headXAngle = stream.ReadFloat(); float headYAngle = stream.ReadFloat(); Quaternion rotation = Quaternion.Identity; if (Jetpack == false) { rotation = stream.ReadQuaternionNorm(); } if(m_character == null) { return; } if (m_character.IsDead || m_character.IsUsing != null) { return; } var jetpack = m_character.JetpackComp; if (jetpack != null) { if (Jetpack != jetpack.TurnedOn) { jetpack.TurnOnJetpack(Jetpack, true); } if (Dampeners != jetpack.DampenersTurnedOn) { jetpack.EnableDampeners(Dampeners, false); } } if (Lights != m_character.LightEnabled) { m_character.EnableLights(Lights); } if (m_character.RadioBroadcaster != null && Broadcast != m_character.RadioBroadcaster.Enabled) { m_character.EnableBroadcasting(Broadcast); } m_character.TargetFromCamera = TargetFromCamera; // Set client movement state directly and don't perform other operations // that may have side-effects to let server side Character.UpdateAfterSimulation() // perform exactly same operations as on client m_character.MovementFlags = MovementFlag; m_character.SetCurrentMovementState(MovementState); m_character.HeadLocalXAngle = headXAngle; m_character.HeadLocalYAngle = headYAngle; m_character.CacheMove(ref move, ref rotate, ref roll); if (Jetpack == false) { m_character.CacheRotation(ref rotation); } } }
protected virtual void ServerRead(VRage.Library.Collections.BitStream stream, ulong clientId,uint timestamp) { m_clientUpdateFlag[clientId] = true; ClientData data = new ClientData(); data.TimeStamp = timestamp; data.Transform = new MyTransformD(); data.Transform.Rotation = stream.ReadQuaternionNorm(); data.Transform.Position = stream.ReadVector3D(); m_serverClientData[clientId] = data; }
void ClientRead(VRage.Library.Collections.BitStream stream) { uint timeStamp = stream.ReadUInt32(); if(m_lastRecievedTimeStamp > timeStamp) { return; } m_lastRecievedTimeStamp = timeStamp; MyTimeStampValues serverPositionAndOrientation = new MyTimeStampValues(); serverPositionAndOrientation.Transform = new MyTransformD(); serverPositionAndOrientation.Transform.Position = stream.ReadVector3D(); serverPositionAndOrientation.Transform.Rotation = stream.ReadQuaternionNorm(); serverPositionAndOrientation.LinearVelocity = stream.ReadVector3(); serverPositionAndOrientation.AngularVelocity = stream.ReadVector3(); serverPositionAndOrientation.LinearVelocity /= MyEntityPhysicsStateGroup.EffectiveSimulationRatio; serverPositionAndOrientation.AngularVelocity /= MyEntityPhysicsStateGroup.EffectiveSimulationRatio; CustomClientRead(timeStamp, ref serverPositionAndOrientation, stream); }