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!"); }
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!"); }