Пример #1
0
 public override void SendUpdate(PlayerEntity player, AbstractPacketOut packet)
 {
     if (Driver == null || Driver.EID != player.EID)
     {
         base.SendUpdate(player, packet);
     }
 }
Пример #2
0
 /// <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);
     }
 }
Пример #3
0
 /// <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);
         }
     }
 }
Пример #4
0
        /// <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);
                }
            }
        }
Пример #5
0
 /// <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");
         }
     }
 }
Пример #6
0
 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));
                 }
             }
         }
     }
 }
Пример #7
0
 public virtual void SendUpdate(PlayerEntity player, AbstractPacketOut packet)
 {
     player.Network.SendPacket(packet);
 }
Пример #8
0
        //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;
            }
        }