예제 #1
0
        public ENetHost(IPEndPoint address, int peers, byte channels, long incomingBandwidth, long outgoingBandwidth)
        {
            if (incomingBandwidth < uint.MinValue || incomingBandwidth > uint.MaxValue)
            {
                throw new ArgumentOutOfRangeException("incomingBandwidth");
            }

            if (outgoingBandwidth < uint.MinValue || outgoingBandwidth > uint.MaxValue)
            {
                throw new ArgumentOutOfRangeException("outgoingBandwidth");
            }

            if (peers < uint.MinValue || peers > LibENet.ENET_PROTOCOL_MAXIMUM_PEER_ID)
            {
                throw new ArgumentOutOfRangeException(string.Format("Maximum peers count is {0}", LibENet.ENET_PROTOCOL_MAXIMUM_PEER_ID));
            }

            var enetAddress = Native.ENetAddress.FromEndPoint(address);

            Pointer = LibENet.HostCreate(&enetAddress, (UIntPtr)peers, (UIntPtr)channels, (uint)incomingBandwidth, (uint)outgoingBandwidth);
            if (Pointer == IntPtr.Zero)
            {
                throw new Exception("Failed to create ENet host.");
            }

            m_pInterceptCallback    = (IntPtr *)IntPtr.Add(Pointer, Native.ENetHostOffset.InterceptOffset);
            m_pChecksumCallback     = (IntPtr *)IntPtr.Add(Pointer, Native.ENetHostOffset.ChecksumOffset);
            m_pTotalSentData        = (uint *)IntPtr.Add(Pointer, Native.ENetHostOffset.TotalSentDataOffset);
            m_pTotalSentPackets     = (uint *)IntPtr.Add(Pointer, Native.ENetHostOffset.TotalSentPacketsOffset);
            m_pTotalReceivedData    = (uint *)IntPtr.Add(Pointer, Native.ENetHostOffset.TotalReceivedDataOffset);
            m_pTotalReceivedPackets = (uint *)IntPtr.Add(Pointer, Native.ENetHostOffset.TotalReceivedPacketsOffset);
            m_pReceivedAddress      = (Native.ENetAddress *)IntPtr.Add(Pointer, Native.ENetHostOffset.ReceivedAddressOffset);
            m_pReceivedData         = (IntPtr *)IntPtr.Add(Pointer, Native.ENetHostOffset.ReceivedDataOffset);
            m_pReceivedDataLength   = (UIntPtr *)IntPtr.Add(Pointer, Native.ENetHostOffset.ReceivedDataLengthOffset);
            m_pConnectedPeers       = (UIntPtr *)IntPtr.Add(Pointer, Native.ENetHostOffset.ConnectedPeersOffset);

            ChecksumDelegate    = new Native.ENetChecksumCallback(ChecksumCallback);
            m_InterceptDelegate = new Native.ENetInterceptCallback(InterceptCallback);
        }
예제 #2
0
 public virtual ENetInterceptionResult Intercept(Native.ENetAddress *address, byte **buffer, UIntPtr *count, Native.ENetEvent *e)
 {
     throw new NotImplementedException();
 }