private void Disconnect(System.Action <bool> onResult = null)
        {
            //Debug.Log("Closing stat");

            this.authTO = null;
            this.net.Close();
            this.connecting = false;
            if (onResult != null)
            {
                onResult.Invoke(true);
            }
        }
Example #2
0
        private void Disconnect(System.Action <bool> onResult = null)
        {
            //if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log("Closing stat");

            this.authTO = null;
            this.net.Close();
            this.connecting = false;
            if (onResult != null)
            {
                onResult.Invoke(true);
            }
        }
Example #3
0
        private void Connect(string key, System.Action <bool> onResult = null)
        {
            if (this.net.Connected() == true)
            {
                if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true)
                {
                    UnityEngine.Debug.Log("Stat, Is already connected");
                }
                if (onResult != null)
                {
                    onResult.Invoke(true);
                }
            }
            else if (connecting == true)
            {
                if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true)
                {
                    UnityEngine.Debug.LogError("Stat, Is already connecting");
                }
            }
            else
            {
                this.connectDT  = System.DateTime.UtcNow;
                this.connecting = true;
                this.net.Connect(host, port, (b) => {
                    var seconds = (System.DateTime.UtcNow - connectDT).TotalSeconds;
                    if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true)
                    {
                        UnityEngine.Debug.Log(string.Format("Stat connect to host: {0} r: {1} s: {2}", host, b, seconds));
                    }
                    reconnectDelay = b ? minDelay : System.Math.Min(reconnectDelay * 2, maxDelay);

                    if (b == true)
                    {
                        this.authTO = new AuthTO()
                        {
                            key = key
                        };
                        this.net.SendMsg(AuthTO.version, this.SerializeB(authTO));
                    }

                    this.connecting = false;
                    if (onResult != null)
                    {
                        onResult.Invoke(b);
                    }
                });
                this.net.onRecMsg = this.OnRecMsg;
            }
        }
Example #4
0
        private void Connect(string key, System.Action <bool> onResult = null)
        {
            if (this.net.Connected() == true)
            {
                if (onResult != null)
                {
                    onResult.Invoke(true);
                }
            }
            else
            {
                this.connectDT  = System.DateTime.UtcNow;
                this.connecting = true;
                this.net.Connect(host, port, (b) => {
                    this.connecting = false;

                    if (b == false)
                    {
                        if (onResult != null)
                        {
                            onResult.Invoke(false);
                        }
                    }
                    else
                    {
                        this.authTO = new AuthTO()
                        {
                            key = key
                        };
                        this.net.SendMsgSilently(AuthTO.version, this.SerializeB(authTO));
                        if (onResult != null)
                        {
                            onResult.Invoke(true);
                        }
                    }
                });
                this.net.onRecMsg = this.OnRecMsg;
            }
        }