Exemplo n.º 1
0
 public bool Send(byte channelID, byte[] data, int offset, int length)
 {
     if (data == null)
     {
         throw new ArgumentNullException("data");
     }
     bool ret;
     using (var packet = new Packet())
     {
         packet.Create(data, offset, length);
         ret = Send(channelID, packet);
     }
     return ret;
 }
Exemplo n.º 2
0
        public static bool Send(this Peer peer, ChannelID channel, byte[] data,
                                bool reliable = true, bool unsequenced = false)
        {
            var packet = new ENet.Packet();
            var flags  = PacketFlags.None;

            if (reliable)
            {
                flags |= PacketFlags.Reliable;
            }
            if (unsequenced)
            {
                flags |= PacketFlags.Unsequenced;
            }
            packet.Create(data, 0, data.Length, flags);
            return(peer.Send((byte)channel, packet));
        }
Exemplo n.º 3
0
        public bool BroadcastPacket(byte[] data, Channel channelNo, PacketFlags flag = PacketFlags.Reliable)
        {
            byte[] temp;
            if (data.Length >= 8)
            {
                temp = _blowfish.Encrypt(data);
            }
            else
            {
                temp = data;
            }

            var packet = new ENet.Packet();

            packet.Create(temp);
            _server.Broadcast((byte)channelNo, ref packet);
            return(true);
        }
Exemplo n.º 4
0
        public bool broadcastPacket(byte[] data, Channel channelNo, PacketFlags flag = PacketFlags.Reliable)
        {
            ////PDEBUG_LOG_LINE(Logging," Broadcast packet:\n");
            //printPacket(data, "Broadcast: ");
            byte[] temp;
            if (data.Length >= 8)
            {
                temp = _blowfish.Encrypt(data);
            }
            else
            {
                temp = data;
            }

            var packet = new ENet.Packet();

            packet.Create(temp);
            _server.Broadcast((byte)channelNo, ref packet);
            return(true);
        }
Exemplo n.º 5
0
        public bool BroadcastPacket(byte[] data, Channel channelNo, PacketFlags flag = PacketFlags.Reliable)
        {
            if (data.Length >= 8)
            {
                // send packet to all peers and save failed ones
                List <KeyValuePair <ulong, Peer> > failedPeers = _peers.Where(x => !x.Value.Send((byte)channelNo, _blowfishes[x.Key].Encrypt(data))).ToList();

                if (failedPeers.Count() > 0)
                {
                    Debug.WriteLine($"Broadcasting packet failed for {failedPeers.Count()} peers.");
                    return(false);
                }
                return(true);
            }
            else
            {
                var packet = new ENet.Packet();
                packet.Create(data);
                _server.Broadcast((byte)channelNo, ref packet);
                return(true);
            }
        }
Exemplo n.º 6
0
 public bool Send(byte channelID, byte[] data, int offset, int length)
 {
     if (data == null)
     {
         throw new ArgumentNullException("data");
     }
     bool ret;
     using (var packet = new Packet())
     {
         packet.Create(data, offset, length);
         ret = Send(channelID, packet);
     }
     return ret;
 }