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

                fixed(byte *data = &ReadBuffer[0])
                {
                    return(*(float *)Read(4, data));
                }
        }
示例#5
0
 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]);
     }
 }
示例#6
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);
 }
示例#7
0
 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);
         }
 }
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#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);
         }
 }
示例#11
0
 public void SendStart()
 {
     Check();
     RakNetNative.NETSND_Start(ptr);
 }
示例#12
0
 public void SetReadPos(int bitsOffset)
 {
     RakNetNative.NETRCV_SetReadPointer(ptr, bitsOffset);
 }