public void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer msg, float sendingTime) { if (correctionTimer > 0.0f) { StartDelayedCorrection(type, msg.ExtractBits(1), sendingTime); return; } IsActive = msg.ReadBoolean(); isActiveTickBox.Selected = IsActive; }
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime) { if (correctionTimer > 0.0f) { StartDelayedCorrection(type, msg.ExtractBits(5 + 1), sendingTime); return; } FlowPercentage = msg.ReadRangedInteger(-10, 10) * 10.0f; IsActive = msg.ReadBoolean(); }
public void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer msg, float sendingTime) { bool isDocked = msg.ReadBoolean(); for (int i = 0; i < 2; i++) { if (hulls[i] == null) { continue; } item.linkedTo.Remove(hulls[i]); hulls[i].Remove(); hulls[i] = null; } if (gap != null) { item.linkedTo.Remove(gap); gap.Remove(); gap = null; } if (isDocked) { ushort dockingTargetID = msg.ReadUInt16(); bool isLocked = msg.ReadBoolean(); Entity targetEntity = Entity.FindEntityByID(dockingTargetID); if (targetEntity == null || !(targetEntity is Item)) { DebugConsole.ThrowError("Invalid docking port network event (can't dock to " + targetEntity.ToString() + ")"); return; } DockingTarget = (targetEntity as Item).GetComponent <DockingPort>(); if (DockingTarget == null) { DebugConsole.ThrowError("Invalid docking port network event (" + targetEntity + " doesn't have a docking port component)"); return; } Dock(DockingTarget); if (isLocked) { Lock(isNetworkMessage: true, forcePosition: true); } } else { Undock(); } }
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { if (correctionTimer > 0.0f) { StartDelayedCorrection(type, msg.ExtractBits(4 + 8), sendingTime); return; } RechargeSpeed = msg.ReadRangedInteger(0, 10) / 10.0f * maxRechargeSpeed; Charge = msg.ReadRangedSingle(0.0f, 1.0f, 8) * capacity; }
public void ClientReadPosition(ServerNetObject type, NetBuffer msg, float sendingTime) { if (body == null) { DebugConsole.ThrowError("Received a position update for an item with no physics body (" + Name + ")"); return; } var posInfo = body.ClientRead(type, msg, sendingTime, parentDebugName: Name); msg.ReadPadBits(); if (posInfo != null) { int index = 0; while (index < positionBuffer.Count && sendingTime > positionBuffer[index].Timestamp) { index++; } positionBuffer.Insert(index, posInfo); } /*body.FarseerBody.Awake = awake; * if (body.FarseerBody.Awake) * { * if ((newVelocity - body.LinearVelocity).LengthSquared() > 8.0f * 8.0f) body.LinearVelocity = newVelocity; * } * else * { * try * { * body.FarseerBody.Enabled = false; * } * catch (Exception e) * { * DebugConsole.ThrowError("Exception in PhysicsBody.Enabled = false (" + body.PhysEnabled + ")", e); * if (body.UserData != null) DebugConsole.NewMessage("PhysicsBody UserData: " + body.UserData.GetType().ToString(), Color.Red); * if (GameMain.World.ContactManager == null) DebugConsole.NewMessage("ContactManager is null!", Color.Red); * else if (GameMain.World.ContactManager.BroadPhase == null) DebugConsole.NewMessage("Broadphase is null!", Color.Red); * if (body.FarseerBody.FixtureList == null) DebugConsole.NewMessage("FixtureList is null!", Color.Red); * } * } * * if ((newPosition - SimPosition).Length() > body.LinearVelocity.Length() * 2.0f) * { * if (body.SetTransform(newPosition, newRotation)) * { * Vector2 displayPos = ConvertUnits.ToDisplayUnits(body.SimPosition); * rect.X = (int)(displayPos.X - rect.Width / 2.0f); * rect.Y = (int)(displayPos.Y + rect.Height / 2.0f); * } * }*/ }
public override void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer msg, float sendingTime) { base.ClientRead(type, msg, sendingTime); bool open = msg.ReadBoolean(); bool forcedOpen = msg.ReadBoolean(); SetState(open, isNetworkMessage: true, sendNetworkMessage: false, forcedOpen: forcedOpen); Stuck = msg.ReadRangedSingle(0.0f, 100.0f, 8); PredictedState = null; }
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime) { deteriorationTimer = msg.ReadSingle(); deteriorateAlwaysResetTimer = msg.ReadSingle(); DeteriorateAlways = msg.ReadBoolean(); tinkeringDuration = msg.ReadSingle(); tinkeringStrength = msg.ReadSingle(); ushort currentFixerID = msg.ReadUInt16(); currentFixerAction = (FixActions)msg.ReadRangedInteger(0, 2); CurrentFixer = currentFixerID != 0 ? Entity.FindEntityByID(currentFixerID) as Character : null; item.MaxRepairConditionMultiplier = GetMaxRepairConditionMultiplier(CurrentFixer); }
public virtual void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { ushort pickerID = msg.ReadUInt16(); if (pickerID == 0) { StopPicking(activePicker); } else { Pick(Entity.FindEntityByID(pickerID) as Character); } }
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { List <Wire> prevWires = Connections.SelectMany(c => Array.FindAll(c.Wires, w => w != null)).ToList(); List <Wire> newWires = new List <Wire>(); foreach (Connection connection in Connections) { connection.ClearConnections(); } foreach (Connection connection in Connections) { int wireCount = msg.ReadRangedInteger(0, Connection.MaxLinked); for (int i = 0; i < wireCount; i++) { ushort wireId = msg.ReadUInt16(); Item wireItem = Entity.FindEntityByID(wireId) as Item; if (wireItem == null) { continue; } Wire wireComponent = wireItem.GetComponent <Wire>(); if (wireComponent == null) { continue; } newWires.Add(wireComponent); connection.Wires[i] = wireComponent; wireComponent.Connect(connection, false); } } foreach (Wire wire in prevWires) { if (wire.Connections[0] == null && wire.Connections[1] == null) { wire.Item.Drop(null); } //wires that are not in anyone's inventory (i.e. not currently being rewired) can never be connected to only one connection // -> someone must have dropped the wire from the connection panel else if (wire.Item.ParentInventory == null && (wire.Connections[0] != null ^ wire.Connections[1] != null)) { wire.Item.Drop(null); } } }
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { UInt16 projectileID = msg.ReadUInt16(); Item projectile = Entity.FindEntityByID(projectileID) as Item; if (projectile == null) { DebugConsole.ThrowError("Failed to launch a projectile - item with the ID \"" + projectileID + " not found"); return; } Launch(projectile); PlaySound(ActionType.OnUse, item.WorldPosition); }
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { if (GameMain.Client.MidRoundSyncing) { //delay reading the state until midround syncing is done //because some of the wires connected to the panel may not exist yet int bitsToRead = Connections.Count * Connection.MaxLinked * 16; StartDelayedCorrection(type, msg.ExtractBits(bitsToRead), sendingTime, waitForMidRoundSync: true); } else { ApplyRemoteState(msg); } }
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime) { Tainted = msg.ReadBoolean(); if (Tainted) { uint selectedTaintedEffectId = msg.ReadUInt32(); selectedTaintedEffect = AfflictionPrefab.Prefabs.Find(a => a.UIntIdentifier == selectedTaintedEffectId); } else { uint selectedEffectId = msg.ReadUInt32(); selectedEffect = AfflictionPrefab.Prefabs.Find(a => a.UIntIdentifier == selectedEffectId); } }
private IEnumerable <object> DoDelayedCorrection(ServerNetObject type, NetBuffer buffer, float sendingTime) { while (correctionTimer > 0.0f) { correctionTimer -= CoroutineManager.DeltaTime; yield return(CoroutineStatus.Running); } ((IServerSerializable)this).ClientRead(type, buffer, sendingTime); correctionTimer = 0.0f; delayedCorrectionCoroutine = null; yield return(CoroutineStatus.Success); }
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { for (int i = 0; i < customInterfaceElementList.Count; i++) { bool elementState = msg.ReadBoolean(); if (customInterfaceElementList[i].ContinuousSignal) { ((GUITickBox)uiElements[i]).Selected = elementState; TickBoxToggled(customInterfaceElementList[i], elementState); } else if (elementState) { ButtonClicked(customInterfaceElementList[i]); } } }
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime) { if (correctionTimer > 0.0f) { StartDelayedCorrection(type, msg.ExtractBits(5 + 16), sendingTime); return; } targetForce = msg.ReadRangedInteger(-10, 10) * 10.0f; UInt16 userID = msg.ReadUInt16(); if (userID != Entity.NullEntityID) { User = Entity.FindEntityByID(userID) as Character; } }
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime) { if (correctionTimer > 0.0f) { StartDelayedCorrection(type, msg.ExtractBits(4 + 8), sendingTime); return; } float rechargeRate = msg.ReadRangedInteger(0, 10) / 10.0f; RechargeSpeed = rechargeRate * MaxRechargeSpeed; #if CLIENT rechargeSpeedSlider.BarScroll = rechargeRate; #endif Charge = msg.ReadRangedSingle(0.0f, 1.0f, 8) * capacity; }
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { if (correctionTimer > 0.0f) { StartDelayedCorrection(type, msg.ExtractBits(16 + 1 + 15 + 8 + 8), sendingTime); return; } Temperature = msg.ReadRangedSingle(0.0f, 10000.0f, 16); AutoTemp = msg.ReadBoolean(); ShutDownTemp = msg.ReadRangedSingle(0.0f, 10000.0f, 15); CoolingRate = msg.ReadRangedSingle(0.0f, 100.0f, 8); FissionRate = msg.ReadRangedSingle(0.0f, 100.0f, 8); }
public override void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime) { base.ClientRead(type, msg, sendingTime); bool readAttachData = msg.ReadBoolean(); if (!readAttachData) { return; } bool shouldBeAttached = msg.ReadBoolean(); Vector2 simPosition = new Vector2(msg.ReadSingle(), msg.ReadSingle()); UInt16 submarineID = msg.ReadUInt16(); Submarine sub = Entity.FindEntityByID(submarineID) as Submarine; if (shouldBeAttached) { if (!attached) { Drop(false, null); item.SetTransform(simPosition, 0.0f); item.Submarine = sub; AttachToWall(); } } else { if (attached) { DropConnectedWires(null); if (body != null) { item.body = body; item.body.Enabled = true; } IsActive = false; DeattachFromWall(); } else { item.SetTransform(simPosition, 0.0f); item.Submarine = sub; } } }
public void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer msg, float sendingTime) { bool isDocked = msg.ReadBoolean(); if (isDocked) { ushort dockingTargetID = msg.ReadUInt16(); bool isLocked = msg.ReadBoolean(); if (isLocked) { hullIds[0] = msg.ReadUInt16(); hullIds[1] = msg.ReadUInt16(); gapId = msg.ReadUInt16(); } Entity targetEntity = Entity.FindEntityByID(dockingTargetID); if (targetEntity == null || !(targetEntity is Item)) { DebugConsole.ThrowError("Invalid docking port network event (can't dock to " + targetEntity.ToString() + ")"); return; } dockingTarget = (targetEntity as Item).GetComponent <DockingPort>(); if (dockingTarget == null) { DebugConsole.ThrowError("Invalid docking port network event (" + targetEntity + " doesn't have a docking port component)"); return; } Dock(dockingTarget); if (isLocked) { Lock(true); hulls[0].ID = (ushort)hullIds[0]; hulls[1].ID = (ushort)hullIds[1]; gap.ID = (ushort)gapId; } } else { Undock(); } }
public void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer msg, float sendingTime) { long msgStartPos = msg.Position; bool isActive = msg.ReadBoolean(); float zoomT = 1.0f; bool directionalPing = useDirectionalPing; float directionT = 0.0f; if (isActive) { zoomT = msg.ReadRangedSingle(0.0f, 1.0f, 8); directionalPing = msg.ReadBoolean(); if (directionalPing) { directionT = msg.ReadRangedSingle(0.0f, 1.0f, 8); } } if (correctionTimer > 0.0f) { int msgLength = (int)(msg.Position - msgStartPos); msg.Position = msgStartPos; StartDelayedCorrection(type, msg.ExtractBits(msgLength), sendingTime); return; } IsActive = isActive; if (isActive) { activeTickBox.Selected = true; zoomSlider.BarScroll = zoomT; zoom = MathHelper.Lerp(MinZoom, MaxZoom, zoomT); if (directionalPing) { directionalSlider.BarScroll = directionT; float pingAngle = MathHelper.Lerp(0.0f, MathHelper.TwoPi, directionalSlider.BarScroll); pingDirection = new Vector2((float)Math.Cos(pingAngle), (float)Math.Sin(pingAngle)); } useDirectionalPing = directionalTickBox.Selected = directionalPing; } else { passiveTickBox.Selected = true; } }
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime) { var posInfo = PhysicsBody.ClientRead(type, msg, sendingTime, parentDebugName: Name); msg.ReadPadBits(); if (posInfo != null) { int index = 0; while (index < subBody.PositionBuffer.Count && sendingTime > subBody.PositionBuffer[index].Timestamp) { index++; } subBody.PositionBuffer.Insert(index, posInfo); } }
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { int itemIndex = msg.ReadRangedInteger(-1, fabricableItems.Count - 1); if (itemIndex == -1) { CancelFabricating(); } else { //if already fabricating the selected item, return if (fabricatedItem != null && fabricableItems.IndexOf(fabricatedItem) == itemIndex) return; if (itemIndex < 0 || itemIndex >= fabricableItems.Count) return; SelectItem(null, fabricableItems[itemIndex]); StartFabricating(fabricableItems[itemIndex]); } }
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime) { deteriorationTimer = msg.ReadSingle(); deteriorateAlwaysResetTimer = msg.ReadSingle(); DeteriorateAlways = msg.ReadBoolean(); ushort currentFixerID = msg.ReadUInt16(); currentFixerAction = (FixActions)msg.ReadRangedInteger(0, 2); if (currentFixerID == 0) { CurrentFixer = null; } else { CurrentFixer = Entity.FindEntityByID(currentFixerID) as Character; } }
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime) { Health = msg.ReadRangedSingle(0, MaxHealth, 8); int startOffset = msg.ReadRangedInteger(-1, MaximumVines); if (startOffset > -1) { int vineCount = msg.ReadRangedInteger(0, VineChunkSize); List <VineTile> tiles = new List <VineTile>(); for (int i = 0; i < vineCount; i++) { VineTileType vineType = (VineTileType)msg.ReadRangedInteger(0b0000, 0b1111); int flowerConfig = msg.ReadRangedInteger(0, 0xFFF); int leafConfig = msg.ReadRangedInteger(0, 0xFFF); sbyte posX = (sbyte)msg.ReadByte(), posY = (sbyte)msg.ReadByte(); Vector2 pos = new Vector2(posX * VineTile.Size, posY * VineTile.Size); tiles.Add(new VineTile(this, pos, vineType, FoliageConfig.Deserialize(flowerConfig), FoliageConfig.Deserialize(leafConfig))); } // is this even needed?? lock (mutex) { for (var i = 0; i < vineCount; i++) { int index = i + startOffset; if (index >= Vines.Count) { Vines.Add(tiles[i]); continue; } VineTile oldVine = Vines[index]; VineTile newVine = tiles[i]; newVine.GrowthStep = oldVine.GrowthStep; Vines[index] = newVine; } } } UpdateBranchHealth(); ResetPlanterSize(); }
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { if (correctionTimer > 0.0f) { StartDelayedCorrection(type, msg.ExtractBits(1 + 1 + 8 + 8 + 8 + 8), sendingTime); return; } AutoTemp = msg.ReadBoolean(); shutDown = msg.ReadBoolean(); Temperature = msg.ReadRangedSingle(0.0f, 100.0f, 8); targetFissionRate = msg.ReadRangedSingle(0.0f, 100.0f, 8); targetTurbineOutput = msg.ReadRangedSingle(0.0f, 100.0f, 8); degreeOfSuccess = msg.ReadRangedSingle(0.0f, 1.0f, 8); fissionRateScrollBar.BarScroll = targetFissionRate / 100.0f; turbineOutputScrollBar.BarScroll = targetTurbineOutput / 100.0f; onOffSwitch.BarScroll = shutDown ? Math.Max(onOffSwitch.BarScroll, 0.55f) : Math.Min(onOffSwitch.BarScroll, 0.45f); }
public void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer message, float sendingTime) { if (GameMain.Server != null) { return; } bool remove = message.ReadBoolean(); if (remove) { ushort entityId = message.ReadUInt16(); var entity = FindEntityByID(entityId); if (entity != null) { DebugConsole.Log("Received entity removal message for \"" + entity.ToString() + "\"."); entity.Remove(); } else { DebugConsole.Log("Received entity removal message for ID " + entityId + ". Entity with a matching ID not found."); } } else { switch (message.ReadByte()) { case (byte)SpawnableType.Item: Item.ReadSpawnData(message, true); break; case (byte)SpawnableType.Character: Character.ReadSpawnData(message, true); break; default: DebugConsole.ThrowError("Received invalid entity spawn message (unknown spawnable type)"); break; } } }
public void ClientRead(ServerNetObject type, NetBuffer message, float sendingTime) { WaterVolume = message.ReadRangedSingle(0.0f, 1.5f, 8) * Volume; OxygenPercentage = message.ReadRangedSingle(0.0f, 100.0f, 8); bool hasFireSources = message.ReadBoolean(); int fireSourceCount = 0; if (hasFireSources) { fireSourceCount = message.ReadRangedInteger(0, 16); for (int i = 0; i < fireSourceCount; i++) { Vector2 pos = Vector2.Zero; float size = 0.0f; pos.X = MathHelper.Clamp(message.ReadRangedSingle(0.0f, 1.0f, 8), 0.05f, 0.95f); pos.Y = MathHelper.Clamp(message.ReadRangedSingle(0.0f, 1.0f, 8), 0.05f, 0.95f); size = message.ReadRangedSingle(0.0f, 1.0f, 8); pos = new Vector2( rect.X + rect.Width * pos.X, rect.Y - rect.Height + (rect.Height * pos.Y)); size = size * rect.Width; var newFire = i < fireSources.Count ? fireSources[i] : new FireSource(pos + Submarine.Position, null, true); newFire.Position = pos; newFire.Size = new Vector2(size, newFire.Size.Y); //ignore if the fire wasn't added to this room (invalid position)? if (!fireSources.Contains(newFire)) { newFire.Remove(); continue; } } } while (fireSources.Count > fireSourceCount) { fireSources[fireSources.Count - 1].Remove(); } }
public void ClientReadPosition(ServerNetObject type, NetBuffer msg, float sendingTime) { Vector2 newPosition = new Vector2(msg.ReadFloat(), msg.ReadFloat()); float newRotation = msg.ReadRangedSingle(0.0f, MathHelper.TwoPi, 7); bool awake = msg.ReadBoolean(); Vector2 newVelocity = Vector2.Zero; if (awake) { newVelocity = new Vector2( msg.ReadRangedSingle(-MaxVel, MaxVel, 12), msg.ReadRangedSingle(-MaxVel, MaxVel, 12)); } if (body == null) { DebugConsole.ThrowError("Received a position update for an item with no physics body (" + Name + ")"); return; } body.FarseerBody.Awake = awake; if (body.FarseerBody.Awake) { if ((newVelocity - body.LinearVelocity).Length() > 8.0f) { body.LinearVelocity = newVelocity; } } else { body.FarseerBody.Enabled = false; } if ((newPosition - SimPosition).Length() > body.LinearVelocity.Length() * 2.0f) { body.SetTransform(newPosition, newRotation); Vector2 displayPos = ConvertUnits.ToDisplayUnits(body.SimPosition); rect.X = (int)(displayPos.X - rect.Width / 2.0f); rect.Y = (int)(displayPos.Y + rect.Height / 2.0f); } }
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime) { byte sectionCount = msg.ReadByte(); if (sectionCount != Sections.Length) { string errorMsg = $"Error while reading a network event for the structure \"{Name}\". Section count does not match (server: {sectionCount} client: {Sections.Length})"; DebugConsole.NewMessage(errorMsg, Color.Red); GameAnalyticsManager.AddErrorEventOnce("Structure.ClientRead:SectionCountMismatch", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg); } for (int i = 0; i < sectionCount; i++) { float damage = msg.ReadRangedSingle(0.0f, 1.0f, 8) * Health; if (i < Sections.Length) { SetDamage(i, damage); } } }
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { UInt16 projectileID = msg.ReadUInt16(); //projectile removed, do nothing if (projectileID == 0) { return; } Item projectile = Entity.FindEntityByID(projectileID) as Item; if (projectile == null) { DebugConsole.ThrowError("Failed to launch a projectile - item with the ID \"" + projectileID + " not found"); return; } Launch(projectile); }