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); }
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); }
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. }
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); }
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(); }
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)); }
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)); }
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)); }
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); }
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)); }
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); }
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); } }
public static void Send(ref Event netEvent, ENet.Packet packet) { netEvent.Peer.Send(Server.ChannelID, ref packet); }
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); }
public static void Broadcast(Host server, ENet.Packet packet, params Peer[] peers) { server.Broadcast(Server.channelID, ref packet, peers); }
public static void Broadcast(Host server, ENet.Packet packet) { server.Broadcast(Server.channelID, ref packet); }
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(); }
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; }
public bool Send(byte channelID, Packet packet) { CheckCreated(); packet.CheckCreated(); return Native.enet_peer_send(_peer, channelID, packet.NativeData) >= 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; }
public static void Broadcast(Host server, ENet.Packet packet, Peer excludedPeer) { server.Broadcast(Server.channelID, ref packet, excludedPeer); }
public void SendReliable(byte[] message) { ENet.Packet packet = new ENet.Packet(); packet.Initialize(message, ENet.PacketFlags.Reliable); server.Send(1, packet); }