public bool Receive()
 {
     if (ptr == IntPtr.Zero)
     {
         return(false);
     }
     return(RakNetNative.NET_Receive(ptr));
 }
 public void Close()
 {
     if (!(ptr != IntPtr.Zero))
     {
         return;
     }
     RakNetNative.NET_Close(ptr);
     ptr = IntPtr.Zero;
 }
 public unsafe void WriteFloat(float val, bool compressed)
 {
     if (compressed)
     {
         RakNetNative.NETSND_WriteCompressedFloat(ptr, val);
     }
     else
     {
         Write((byte *)&val, 4);
     }
 }
        public unsafe float ReadFloat(bool compressed)
        {
            if (compressed)
            {
                return(RakNetNative.NETSND_ReadCompressedFloat(ptr));

                fixed(byte *data = &ReadBuffer[0])
                {
                    return(*(float *)Read(4, data));
                }
        }
 public unsafe byte ReadByte()
 {
     Check();
     fixed(byte *data = ByteBuffer)
     {
         if (!RakNetNative.NETRCV_ReadBytes(ptr, data, 1))
         {
             Console.WriteLine((object)"NETRCV_ReadBytes returned false");
             return(0);
         }
         return(ByteBuffer[0]);
     }
 }
 private unsafe byte *Read(int size, byte *data)
 {
     Check();
     if (size > ReadBuffer.Length)
     {
         throw new Exception("Size > ReadBuffer.Length");
     }
     if (RakNetNative.NETRCV_ReadBytes(ptr, data, size))
     {
         return(data);
     }
     Console.WriteLine((object)"NETRCV_ReadBytes returned false");
     return(null);
 }
 public unsafe int Read(byte[] buffer, int offset, int length)
 {
     if ((uint)offset > 0U)
     {
         throw new NotImplementedException("Offset != 0");
         fixed(byte *data = buffer)
         {
             if (!RakNetNative.NETRCV_ReadBytes(ptr, data, length))
             {
                 Console.WriteLine("NETRCV_ReadBytes returned false");
                 return(0);
             }
             return(length);
         }
 }
        public static RakNetPeer CreateConnection(string hostname, int port, int retries, int retryDelay, int timeout)
        {
            var peer = new RakNetPeer();

            peer.ptr = RakNetNative.NET_Create();
            if (RakNetNative.NET_StartClient(peer.ptr, hostname, port, retries, retryDelay, timeout) == 0)
            {
                return(peer);
            }
            var str = StringFromPointer(RakNetNative.NET_LastStartupError(peer.ptr));

            Console.WriteLine((object)("Couldn't connect to server " + hostname + ":" + port + " (" + str + ")"));
            peer.Close();
            return(null);
        }
        public static RakNetPeer CreateServer(string ip, int port, int maxConnections)
        {
            var peer = new RakNetPeer();

            peer.ptr = RakNetNative.NET_Create();
            if (RakNetNative.NET_StartServer(peer.ptr, ip, port, maxConnections) == 0)
            {
                return(peer);
            }
            peer.Close();
            var str = StringFromPointer(RakNetNative.NET_LastStartupError(peer.ptr));

            Console.WriteLine((object)("Couldn't create server on port " + port + " (" + str + ")"));
            return(null);
        }
Exemple #10
0
 public unsafe MemoryStream ReadBytes(int length)
 {
     Check();
     if (length == -1)
     {
         length = incomingBytesUnread;
     }
     if (memoryStream.Capacity < length)
     {
         memoryStream.Capacity = length + 32;
         fixed(byte *data = memoryStream.GetBuffer())
         {
             memoryStream.SetLength(memoryStream.Capacity);
             if (!RakNetNative.NETRCV_ReadBytes(ptr, data, length))
             {
                 Console.WriteLine((object)"NETRCV_ReadBytes returned false");
                 return(null);
             }
             memoryStream.SetLength(length);
             return(memoryStream);
         }
 }
Exemple #11
0
 public void SendStart()
 {
     Check();
     RakNetNative.NETSND_Start(ptr);
 }
Exemple #12
0
 public void SetReadPos(int bitsOffset)
 {
     RakNetNative.NETRCV_SetReadPointer(ptr, bitsOffset);
 }