public override void SendUpdate(PlayerEntity player, AbstractPacketOut packet) { if (Driver == null || Driver.EID != player.EID) { base.SendUpdate(player, packet); } }
/// <summary> /// Sends a packet to all players. /// </summary> /// <param name="packet">The packet to send.</param> public void SendToAll(AbstractPacketOut packet) { for (int i = 0; i < Players.Count; i++) { Players[i].Network.SendPacket(packet); } }
/// <summary> /// Sends a packet to all players that can see a chunk location. /// Note that this still uses the standard network path, not the chunk network path. /// </summary> /// <param name="packet">The packet to send.</param> /// <param name="cpos">The chunk location.</param> public void ChunkSendToAll(AbstractPacketOut packet, Vector3i cpos) { for (int i = 0; i < Players.Count; i++) { if (Players[i].CanSeeChunk(cpos)) { Players[i].Network.SendPacket(packet); } } }
/// <summary> /// Sends a packet to all players that can see a location. /// </summary> /// <param name="pos">The position.</param> /// <param name="packet">The packet to send.</param> public void SendToVisible(Location pos, AbstractPacketOut packet) { Vector3i cpos = ChunkLocFor(pos); foreach (PlayerEntity pe in Players) { if (pe.CanSeeChunk(cpos)) { pe.Network.SendPacket(packet); } } }
/// <summary> /// Send a packet along the secondary socket. /// </summary> /// <param name="packet">The packet to send</param> public void SendToSecondary(AbstractPacketOut packet) { try { byte[] data = new byte[packet.Data.Length + 5]; BitConverter.GetBytes(packet.Data.Length).CopyTo(data, 0); data[4] = packet.ID; packet.Data.CopyTo(data, 5); ChunkNetwork.InternalSocket.Send(data); } catch (Exception ex) { if (!tdisco) { SysConsole.Output(OutputType.ERROR, "Error sending packet to player (secondary): " + ex.ToString()); Kick("Error sending secondary packet"); } } }
void NetworkTick() { if (NetworkMe) { bool sme = needNetworking; needNetworking = false; // TODO: Timer of some form, to prevent packet flood on a speedy server? if (Body != null && (Body.ActivityInformation.IsActive || (netpActive && !Body.ActivityInformation.IsActive))) { netpActive = Body.ActivityInformation.IsActive; sme = true; } if (!netpActive && GetMass() > 0) { netdeltat += TheRegion.Delta; if (netdeltat > 2.0) { netdeltat -= 2.0; sme = true; } } Location pos = GetPosition(); if (!TransmitMe) { sme = false; } AbstractPacketOut physupd = sme ? GetUpdatePacket() : null; foreach (PlayerEntity player in TheRegion.Players) { if (player == this) { continue; } bool shouldseec = player.ShouldSeePosition(pos); bool shouldseel = player.ShouldSeePositionPreviously(lPos); if (shouldseec && !shouldseel) { player.Network.SendPacket(GetSpawnPacket()); foreach (InternalBaseJoint joint in Joints) { if (player.ShouldSeePosition(joint.One.GetPosition()) && player.ShouldSeePosition(joint.Two.GetPosition())) { player.Network.SendPacket(new AddJointPacketOut(joint)); } } } if (shouldseel && !shouldseec) { player.Network.SendPacket(new DespawnEntityPacketOut(EID)); } if (sme && shouldseec) { player.Network.SendPacket(physupd); } if (!shouldseec) { bool shouldseelongc = player.ShouldLoadPosition(pos); bool shouldseelongl = player.ShouldLoadPositionPreviously(lPos); if (shouldseelongc && !shouldseelongl) { AbstractPacketOut lod = GetLODSpawnPacket(); if (lod != null) { player.Network.SendPacket(lod); } } if (shouldseelongl && !shouldseelongc) { player.Network.SendPacket(new DespawnEntityPacketOut(EID)); } } } } }
public virtual void SendUpdate(PlayerEntity player, AbstractPacketOut packet) { player.Network.SendPacket(packet); }
//bool wasEverVis = false; void NetworkTick() { if (ShouldNetwork) { bool sme = needNetworking; needNetworking = false; // TODO: Timer of some form, to prevent packet flood on a speedy server? if (Body != null && (Body.ActivityInformation.IsActive || (netpActive && !Body.ActivityInformation.IsActive))) { netpActive = Body.ActivityInformation.IsActive; sme = true; } if (!netpActive && GetMass() > 0) { netdeltat += TheRegion.Delta; if (netdeltat > 2.0) { netdeltat -= 2.0; sme = true; } } Location pos = GetPosition(); if (!TransmitMe) { sme = false; } AbstractPacketOut physupd = sme ? GetUpdatePacket() : null; foreach (PlayerEntity player in TheRegion.Players) { if (player == this) { continue; } bool shouldseec = player.ShouldSeePosition(pos) || player.ShouldNetworkAnyway(this); bool shouldseel = player.Known.Contains(EID); // player.ShouldSeePositionPreviously(lPos) && wasEverVis; if (shouldseec && !shouldseel) { player.Known.Add(EID); SendSpawnPacket(player); } if (shouldseel && !shouldseec) { player.Known.Remove(EID); SendDespawnPacket(player); } if (sme && shouldseec) { SendUpdate(player, physupd); } // TODO /* * if (!shouldseec) * { * bool shouldseelongc = player.ShouldLoadPosition(pos); * bool shouldseelongl = player.ShouldLoadPositionPreviously(lPos); * if (shouldseelongc && !shouldseelongl) * { * AbstractPacketOut lod = GetLODSpawnPacket(); * if (lod != null) * { * player.Network.SendPacket(lod); * } * } * if (shouldseelongl && !shouldseelongc) * { * player.Network.SendPacket(new DespawnEntityPacketOut(EID)); * } * } */ } //wasEverVis = true; } }