Exemple #1
0
        void Awake()
        {
            // logging
            if (debugLog)
            {
                Log.Info = Debug.Log;
            }
            Log.Warning = Debug.LogWarning;
            Log.Error   = Debug.LogError;

            // TODO simplify after converting Mirror Transport events to Action
            client = new KcpClient(
                () => OnClientConnected.Invoke(),
                (message) => OnClientDataReceived.Invoke(message, Channels.DefaultReliable),
                () => OnClientDisconnected.Invoke()
                );
            // TODO simplify after converting Mirror Transport events to Action
            server = new KcpServer(
                (connectionId) => OnServerConnected.Invoke(connectionId),
                (connectionId, message) => OnServerDataReceived.Invoke(connectionId, message, Channels.DefaultReliable),
                (connectionId) => OnServerDisconnected.Invoke(connectionId),
                NoDelay,
                Interval,
                FastResend,
                CongestionWindow,
                SendWindowSize,
                ReceiveWindowSize
                );
            Debug.Log("KcpTransport initialized!");
        }
        public override void Awake()
        {
            KCPConfig conf = new KCPConfig();

            if (!File.Exists("KCPConfig.json"))
            {
                File.WriteAllText("KCPConfig.json", JsonConvert.SerializeObject(conf, Formatting.Indented));
            }
            else
            {
                conf = JsonConvert.DeserializeObject <KCPConfig>(File.ReadAllText("KCPConfig.json"));
            }

            NoDelay           = conf.NoDelay;
            Interval          = conf.Interval;
            FastResend        = conf.FastResend;
            CongestionWindow  = conf.CongestionWindow;
            SendWindowSize    = conf.SendWindowSize;
            ReceiveWindowSize = conf.ReceiveWindowSize;
            ConnectionTimeout = conf.ConnectionTimeout;

            // 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 = Console.WriteLine;
            }
            else
            {
                Log.Info = _ => { }
            };
            Log.Warning = Console.WriteLine;
            Log.Error   = Console.WriteLine;

            // client
            client = new KcpClient(
                () => OnClientConnected.Invoke(),
                (message) => OnClientDataReceived.Invoke(message, 0),
                () => OnClientDisconnected.Invoke()
                );

            // server
            server = new KcpServer(
                (connectionId) => OnServerConnected.Invoke(connectionId),
                (connectionId, message) => OnServerDataReceived.Invoke(connectionId, message, 0),
                (connectionId) => OnServerDisconnected.Invoke(connectionId),
                NoDelay,
                Interval,
                FastResend,
                CongestionWindow,
                SendWindowSize,
                ReceiveWindowSize
                );


            Console.WriteLine("KcpTransport initialized!");
        }
Exemple #3
0
        public override void OnAwake()
        {
            base.OnAwake();
            // 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;

            // client
            client = new KcpClient(
                () => OnClientConnected.Invoke(),
                (message) => OnClientDataReceived.Invoke(message, Channels.DefaultReliable),
                () => OnClientDisconnected.Invoke()
                );

            // server
            server = new KcpServer(
                (connectionId) => OnServerConnected.Invoke(connectionId),
                (connectionId, message) => OnServerDataReceived.Invoke(connectionId, message, Channels.DefaultReliable),
                (connectionId) => OnServerDisconnected.Invoke(connectionId),
                NoDelay,
                Interval,
                FastResend,
                CongestionWindow,
                SendWindowSize,
                ReceiveWindowSize
                );

            if (statisticsLog)
            {
                Task.Run(async() => {
                    await Task.Delay(100);
                    OnLogStatistics();
                    await Task.Delay(100);
                });
                //InvokeRepeating(nameof(OnLogStatistics), 1, 1);
            }


            Debug.Log("KcpTransport initialized!");
        }
Exemple #4
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;

            // client
            client = new KcpClient(
                () => OnClientConnected.Invoke(),
                (message) => OnClientDataReceived.Invoke(message, Channels.DefaultReliable),
                () => OnClientDisconnected.Invoke()
                );

            // server
            server = new KcpServer(
                (connectionId) => OnServerConnected.Invoke(connectionId),
                (connectionId, message) => OnServerDataReceived.Invoke(connectionId, message, Channels.DefaultReliable),
                (connectionId) => OnServerDisconnected.Invoke(connectionId),
                NoDelay,
                Interval,
                FastResend,
                CongestionWindow,
                SendWindowSize,
                ReceiveWindowSize
                );

            // scene change message will disable transports.
            // kcp processes messages in an internal loop which should be
            // stopped immediately after scene change (= after disabled)
            client.OnCheckEnabled = () => enabled;
            server.OnCheckEnabled = () => enabled;

            Debug.Log("KcpTransport initialized!");
        }
Exemple #5
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;

            // client
            client = new KcpClient(
                () => OnClientConnected.Invoke(),
                (message) => OnClientDataReceived.Invoke(message, Channels.DefaultReliable),
                () => OnClientDisconnected.Invoke()
                );

            // server
            server = new KcpServer(
                (connectionId) => OnServerConnected.Invoke(connectionId),
                (connectionId, message) => OnServerDataReceived.Invoke(connectionId, message, Channels.DefaultReliable),
                (connectionId) => OnServerDisconnected.Invoke(connectionId),
                NoDelay,
                Interval,
                FastResend,
                CongestionWindow,
                SendWindowSize,
                ReceiveWindowSize
                );

            if (statisticsLog)
            {
                InvokeRepeating(nameof(OnLogStatistics), 1, 1);
            }
        }
Exemple #6
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())
                : new KcpClient(
                () => OnClientConnected.Invoke(),
                (message, channel) => OnClientDataReceived.Invoke(message, FromKcpChannel(channel)),
                () => OnClientDisconnected.Invoke());

            // server
            server = NonAlloc
                ? new KcpServerNonAlloc(
                (connectionId) => OnServerConnected.Invoke(connectionId),
                (connectionId, message, channel) => OnServerDataReceived.Invoke(connectionId, message, FromKcpChannel(channel)),
                (connectionId) => OnServerDisconnected.Invoke(connectionId),
                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),
                DualMode,
                NoDelay,
                Interval,
                FastResend,
                CongestionWindow,
                SendWindowSize,
                ReceiveWindowSize,
                Timeout,
                MaxRetransmit,
                MaximizeSendReceiveBuffersToOSLimit);

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

            Debug.Log("KcpTransport initialized!");
        }
        public override void Awake()
        {
            KCPConfig conf = new KCPConfig();

            bool noConfig = bool.Parse(Environment.GetEnvironmentVariable("NO_CONFIG") ?? "false");

            if (!File.Exists("KCPConfig.json") && !noConfig)
            {
                File.WriteAllText("KCPConfig.json", JsonConvert.SerializeObject(conf, Formatting.Indented));
            }
            else
            {
                if (noConfig)
                {
                    conf                   = new KCPConfig();
                    conf.NoDelay           = bool.Parse(Environment.GetEnvironmentVariable("KCP_NODELAY") ?? "true");
                    conf.Interval          = uint.Parse(Environment.GetEnvironmentVariable("KCP_INTERVAL") ?? "10");
                    conf.FastResend        = int.Parse(Environment.GetEnvironmentVariable("KCP_FAST_RESEND") ?? "2");
                    conf.CongestionWindow  = bool.Parse(Environment.GetEnvironmentVariable("KCP_CONGESTION_WINDOW") ?? "false");
                    conf.SendWindowSize    = uint.Parse(Environment.GetEnvironmentVariable("KCP_SEND_WINDOW_SIZE") ?? "4096");
                    conf.ReceiveWindowSize = uint.Parse(Environment.GetEnvironmentVariable("KCP_RECEIVE_WINDOW_SIZE") ?? "4096");
                    conf.ConnectionTimeout = int.Parse(Environment.GetEnvironmentVariable("KCP_CONNECTION_TIMEOUT") ?? "10000");
                }
                else
                {
                    conf = JsonConvert.DeserializeObject <KCPConfig>(File.ReadAllText("KCPConfig.json"));
                }
            }

            NoDelay           = conf.NoDelay;
            Interval          = conf.Interval;
            FastResend        = conf.FastResend;
            CongestionWindow  = conf.CongestionWindow;
            SendWindowSize    = conf.SendWindowSize;
            ReceiveWindowSize = conf.ReceiveWindowSize;
            ConnectionTimeout = conf.ConnectionTimeout;

            // 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 = Console.WriteLine;
            }
            else
            {
                Log.Info = _ => { }
            };
            Log.Warning = Console.WriteLine;
            Log.Error   = Console.WriteLine;

            // client
            client = new KcpClient(
                () => OnClientConnected.Invoke(),
                (message) => OnClientDataReceived.Invoke(message, 0),
                () => OnClientDisconnected.Invoke()
                );

            // server
            server = new KcpServer(
                (connectionId) => OnServerConnected.Invoke(connectionId),
                (connectionId, message) => OnServerDataReceived.Invoke(connectionId, message, 0),
                (connectionId) => OnServerDisconnected.Invoke(connectionId),
                NoDelay,
                Interval,
                FastResend,
                CongestionWindow,
                SendWindowSize,
                ReceiveWindowSize
                );


            Console.WriteLine("KcpTransport initialized!");
        }