示例#1
0
        // max message size
        public override int GetMaxPacketSize(int channelId = Channels.Reliable)
        {
            // switch to kcp channel.
            // unreliable or reliable.
            // default to reliable just to be sure.
            switch (channelId)
            {
            case Channels.Unreliable:
                return(KcpConnection.UnreliableMaxMessageSize);

            default:
                return(KcpConnection.ReliableMaxMessageSize(ReceiveWindowSize));
            }
        }
示例#2
0
 private void OnValidate()
 {
     // show max message sizes in inspector for convenience
     ReliableMaxMessageSize   = KcpConnection.ReliableMaxMessageSize(ReceiveWindowSize);
     UnreliableMaxMessageSize = KcpConnection.UnreliableMaxMessageSize;
 }
示例#3
0
        void Awake()
        {
            // logging
            //   Log.Info should use Debug.Log if enabled, or nothing otherwise
            //   (don't want to spam the console on headless servers)
            if (debugLog)
            {
                Log.Info = Debug.Log;
            }
            else
            {
                Log.Info = _ => {}
            };
            Log.Warning = Debug.LogWarning;
            Log.Error   = Debug.LogError;

#if ENABLE_IL2CPP
            // NonAlloc doesn't work with IL2CPP builds
            NonAlloc = false;
#endif

            // client
            client = NonAlloc
                ? new KcpClientNonAlloc(
                () => OnClientConnected.Invoke(),
                (message, channel) => OnClientDataReceived.Invoke(message, FromKcpChannel(channel)),
                () => OnClientDisconnected.Invoke(),
                (error, reason) => OnClientError.Invoke(ToTransportError(error), reason))
                : new KcpClient(
                () => OnClientConnected.Invoke(),
                (message, channel) => OnClientDataReceived.Invoke(message, FromKcpChannel(channel)),
                () => OnClientDisconnected.Invoke(),
                (error, reason) => OnClientError.Invoke(ToTransportError(error), reason));

            // server
            server = NonAlloc
                ? new KcpServerNonAlloc(
                (connectionId) => OnServerConnected.Invoke(connectionId),
                (connectionId, message, channel) => OnServerDataReceived.Invoke(connectionId, message, FromKcpChannel(channel)),
                (connectionId) => OnServerDisconnected.Invoke(connectionId),
                (connectionId, error, reason) => OnServerError.Invoke(connectionId, ToTransportError(error), reason),
                DualMode,
                NoDelay,
                Interval,
                FastResend,
                CongestionWindow,
                SendWindowSize,
                ReceiveWindowSize,
                Timeout,
                MaxRetransmit,
                MaximizeSendReceiveBuffersToOSLimit)
                : new KcpServer(
                (connectionId) => OnServerConnected.Invoke(connectionId),
                (connectionId, message, channel) => OnServerDataReceived.Invoke(connectionId, message, FromKcpChannel(channel)),
                (connectionId) => OnServerDisconnected.Invoke(connectionId),
                (connectionId, error, reason) => OnServerError.Invoke(connectionId, ToTransportError(error), reason),
                DualMode,
                NoDelay,
                Interval,
                FastResend,
                CongestionWindow,
                SendWindowSize,
                ReceiveWindowSize,
                Timeout,
                MaxRetransmit,
                MaximizeSendReceiveBuffersToOSLimit);

            if (statisticsLog)
            {
                InvokeRepeating(nameof(OnLogStatistics), 1, 1);
            }

            Debug.Log("KcpTransport initialized!");
        }

        void OnValidate()
        {
            // show max message sizes in inspector for convenience
            ReliableMaxMessageSize   = KcpConnection.ReliableMaxMessageSize(ReceiveWindowSize);
            UnreliableMaxMessageSize = KcpConnection.UnreliableMaxMessageSize;
        }