コード例 #1
4
 public void SendReliable(String message, ENet.Peer destination)
 {
     ENet.Packet packet = new ENet.Packet();
     byte[] buffer = Encoding.ASCII.GetBytes(message);
     packet.Initialize(buffer, ENet.PacketFlags.Reliable);
     destination.Send((byte)(clients.IndexOf(destination) * 2 + 1), packet);
 }
コード例 #2
0
 public void Send(String message)
 {
     ENet.Packet packet = new ENet.Packet();
     byte[] buffer = Encoding.ASCII.GetBytes(message);
     packet.Initialize(buffer, ENet.PacketFlags.UnreliableFragment);
     server.Send(0, packet);
 }
コード例 #3
0
ファイル: Host.cs プロジェクト: NitroXenon/Ignite
 public void Broadcast(byte channelID, ref Packet packet)
 {
     CheckCreated();
     packet.CheckCreated();
     Native.enet_host_broadcast(_host, channelID, packet.NativeData);
     packet.NativeData = null; // Broadcast automatically clears this.
 }
コード例 #4
0
 public void Send(String message)
 {
     ENet.Packet packet = new ENet.Packet();
     byte[] buffer = Encoding.ASCII.GetBytes(message);
     packet.Initialize(buffer, ENet.PacketFlags.UnreliableFragment);
     server.Broadcast(0 /*TODO: change channel ?*/,ref packet);
 }
コード例 #5
0
 public void Send(Object message, NetFrame.FrameType type)
 {
     ENet.Packet packet = new ENet.Packet();
     NetFrame f = new NetFrame(message, type);
     MemoryStream stream = new MemoryStream(512); // TODO : buffer size ?
     BinaryFormatter formater = new BinaryFormatter();
     formater.Serialize(stream, f);
     packet.Initialize(stream.GetBuffer(), ENet.PacketFlags.UnreliableFragment);
     server.Send(0, packet);
     client.Flush();
 }
コード例 #6
0
        public bool handlePacket(Peer peer, ENet.Packet packet, Channel channelID)
        {
            var data = new byte[(int)packet.Length];

            Marshal.Copy(packet.Data, data, 0, data.Length);

            if (data.Length >= 8)
            {
                if (_playerManager.GetPeerInfo(peer) != null)
                {
                    data = _blowfish.Decrypt(data);
                }
            }

            return(handlePacket(peer, data, channelID));
        }
コード例 #7
0
ファイル: LeagueServer.cs プロジェクト: zkitX/LeaguePackets
        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));
        }
コード例 #8
0
        public bool HandlePacket(Peer peer, ENet.Packet packet, Channel channelId)
        {
            var data = packet.GetBytes();

            // if channel id is HANDSHAKE we should initialize blowfish key and return
            if (channelId == Channel.CHL_HANDSHAKE)
            {
                return(HandleHandshake(peer, data));
            }

            // every packet that is not blowfish go here
            if (data.Length >= 8)
            {
                ulong playerId = _peers.First(x => x.Value.Address.Equals(peer.Address)).Key;
                data = _blowfishes[playerId].Decrypt(data);
            }
            return(HandlePacket(peer, data, channelId));
        }
コード例 #9
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);
        }
コード例 #10
0
        public bool HandlePacket(Peer peer, ENet.Packet packet, Channel channelId)
        {
            var data = packet.GetBytes();

            // if channel id is HANDSHAKE we should initialize blowfish key and return
            if (channelId == Channel.CHL_HANDSHAKE)
            {
                return(HandleHandshake(peer, data));
            }

            // every packet that is not blowfish go here
            if (data.Length >= 8)
            {
                // TODO: each user will have his unique key
                data = _blowfish.Decrypt(data);
            }
            return(HandlePacket(peer, data, channelId));
        }
コード例 #11
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);
        }
コード例 #12
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);
            }
        }
コード例 #13
0
 public static void Send(ref Event netEvent, ENet.Packet packet)
 {
     netEvent.Peer.Send(Server.ChannelID, ref packet);
 }
コード例 #14
0
 public void SendReliable(byte[] message, ENet.Peer destination)
 {
     ENet.Packet packet = new ENet.Packet();
     packet.Initialize(message, ENet.PacketFlags.Reliable);
     destination.Send((byte)(clients.IndexOf(destination) * 2 + 1), packet);
 }
コード例 #15
0
ファイル: Network.cs プロジェクト: bmjoy/Unity-ENet-Model
 public static void Broadcast(Host server, ENet.Packet packet, params Peer[] peers)
 {
     server.Broadcast(Server.channelID, ref packet, peers);
 }
コード例 #16
0
ファイル: Network.cs プロジェクト: bmjoy/Unity-ENet-Model
 public static void Broadcast(Host server, ENet.Packet packet)
 {
     server.Broadcast(Server.channelID, ref packet);
 }
コード例 #17
0
 public void SendReliable(Object message, NetFrame.FrameType type, ENet.Peer destination)
 {
     ENet.Packet packet = new ENet.Packet();
     NetFrame f = new NetFrame(message, type);
     MemoryStream stream = new MemoryStream(512); // TODO : buffer size ?
     BinaryFormatter formater = new BinaryFormatter();
     formater.Serialize(stream, f);
     packet.Initialize(stream.GetBuffer(), ENet.PacketFlags.Reliable);
     destination.Send((byte)(clients.IndexOf(destination) * 2 + 1), packet);
     server.Flush();
 }
コード例 #18
0
ファイル: Peer.cs プロジェクト: horato/IntWarsSharp
 public bool Receive(out byte channelID, out Packet packet)
 {
     CheckCreated();
     Native.ENetPacket* nativePacket;
     nativePacket = Native.enet_peer_receive(_peer, out channelID);
     if (nativePacket == null)
     {
         packet = new Packet();
         return false;
     }
     packet = new Packet(nativePacket);
     return true;
 }
コード例 #19
0
ファイル: Peer.cs プロジェクト: horato/IntWarsSharp
 public bool Send(byte channelID, Packet packet)
 {
     CheckCreated();
     packet.CheckCreated();
     return Native.enet_peer_send(_peer, channelID, packet.NativeData) >= 0;
 }
コード例 #20
0
ファイル: Peer.cs プロジェクト: horato/IntWarsSharp
 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;
 }
コード例 #21
0
 public static void Broadcast(Host server, ENet.Packet packet, Peer excludedPeer)
 {
     server.Broadcast(Server.channelID, ref packet, excludedPeer);
 }
コード例 #22
0
 public void SendReliable(byte[] message)
 {
     ENet.Packet packet = new ENet.Packet();
     packet.Initialize(message, ENet.PacketFlags.Reliable);
     server.Send(1, packet);
 }