Esempio n. 1
0
File: Peer.cs Progetto: tolemwar/SP4
    public unsafe MemoryStream ReadBytes(int length, bool compressed)
    {
        Check();
        MemoryStream memoryStream = new MemoryStream();

        if (length == -1)
        {
            length = incomingBytesUnread;
        }
        if (memoryStream.Capacity < length)
        {
            memoryStream.Capacity = length + 32;
            fixed(byte *data = memoryStream.GetBuffer())
            {
                memoryStream.SetLength(memoryStream.Capacity);

                if (!RakNet_Native.NETRCV_ReadBytes(ptr, data, length))
                {
                    Debug.LogWarning("[RakNet] NETRCV_ReadBytes returned false");
                    return(null);
                }
                memoryStream.SetLength(length);
                return(memoryStream);
            }
    }
Esempio n. 2
0
 public bool Receive()
 {
     if (ptr == IntPtr.Zero)
     {
         return(false);
     }
     return(RakNet_Native.NET_Receive(ptr));
 }
Esempio n. 3
0
 public void Close()
 {
     if (ptr != IntPtr.Zero)
     {
         RakNet_Native.NET_Close(ptr);
         ptr = IntPtr.Zero;
     }
 }
Esempio n. 4
0
 public unsafe byte ReadByte()
 {
     Check();
     fixed(byte *data = ByteBuffer)
     {
         if (!RakNet_Native.NETRCV_ReadBytes(ptr, data, 1))
         {
             Debug.LogWarning("[RakNet] NETRCV_ReadBytes returned false");
             return(0);
         }
         return(ByteBuffer[0]);
     }
 }
Esempio n. 5
0
    public static Peer CreateServer(string ip, int port, int maxConnections)
    {
        Peer peer = new Peer();

        peer.ptr = RakNet_Native.NET_Create();

        if (RakNet_Native.NET_StartServer(peer.ptr, ip, port, maxConnections) == 0)
        {
            return(peer);
        }
        peer.Close();
        string text = StringFromPointer(RakNet_Native.NET_LastStartupError(peer.ptr));

        Debug.LogWarning("[RakNet] Couldn't create server on port " + port + " (" + text + ")");
        return(null);
    }
Esempio n. 6
0
    private unsafe byte *Read(int size, byte *data)
    {
        Check();
        if (size > ReadBuffer.Length)
        {
            throw new Exception("[RakNet] Size > ReadBuffer.Length");
        }

        if (RakNet_Native.NETRCV_ReadBytes(ptr, data, size))
        {
            return(data);
        }

        Debug.LogWarning("[RakNet] NETRCV_ReadBytes returned false");
        return(null);
    }
Esempio n. 7
0
    public static Peer CreateConnection(string hostname, int port, int retries, int retryDelay, int timeout)
    {
        Peer peer = new Peer();

        peer.ptr = RakNet_Native.NET_Create();

        if (RakNet_Native.NET_StartClient(peer.ptr, hostname, port, retries, retryDelay * 100, timeout * 100) == 0)
        {
            Debug.Log("[RakNet] Peer created connection to " + hostname + ":" + port + " with " + retries + " retry count [delay: " + retryDelay + "] [Timeout: " + timeout + "]");
            return(peer);
        }

        string text = StringFromPointer(RakNet_Native.NET_LastStartupError(peer.ptr));

        Debug.LogWarning("[RakNet] Couldn't connect to server " + hostname + ":" + port + " (" + text + ")");
        peer.Close();
        peer = null;
        return(null);
    }
Esempio n. 8
0
 protected unsafe virtual bool Read(byte *data, int length, bool compressed)
 {
     Check();
     return(RakNet_Native.NETRCV_ReadBytes(ptr, data, length));
 }
Esempio n. 9
0
 public virtual void SetReadPos(int bitsOffset)
 {
     Check();
     RakNet_Native.NETRCV_SetReadPointer(ptr, bitsOffset);
 }