Example #1
0
        public async Task StartChat()
        {
            if (!IsNetworkConnected())
            {
                NetworkErrorMessage.Show();
                return;
            }
            _chatHub               = new HubConnection("http://trycatch2017.azurewebsites.net");
            _chat                  = _chatHub.CreateHubProxy("ChatHub");
            _chatHub.Error        += ChatHub_Error;
            _chatHub.Reconnecting += () =>
            {
                Toast.MakeText(this, "Connection has been lost.", ToastLength.Short).Show();
            };

            _chatHub.ConnectionSlow += () => { Toast.MakeText(this, "Slow connection.", ToastLength.Short).Show(); };

            try
            {
                await _chatHub.Start();

                SendConnectionMessage();
            }
            catch (Exception ex)
            {
                Toast.MakeText(this, "Server error.", ToastLength.Long).Show();
            }
            _chatHub.Received += message => RunOnUiThread(() => ResiveMessage(message));
        }
Example #2
0
        public async void SendMessage()
        {
            if (!IsNetworkConnected())
            {
                NetworkErrorMessage.Show();
                return;
            }

            if (_chatHub == null || _chat == null)
            {
                return;
            }

            var messageTxt = FindViewById <EditText>(Resource.Id.Chat_MessageTxt);
            var imm        = (InputMethodManager)GetSystemService(InputMethodService);

            imm.HideSoftInputFromWindow(messageTxt.WindowToken, 0);

            if (messageTxt.Text.Length > 0)
            {
                await _chat.Invoke("Send", User.Username, messageTxt.Text);

                messageTxt.Text = "";
            }
            else
            {
                Toast.MakeText(this, "Empty message.", ToastLength.Short).Show();
            }
        }
Example #3
0
        public static string ToMessageString(this NetworkErrorMessage networkErrorMessage)
        {
            string res = "";

            switch (networkErrorMessage)
            {
            case NetworkErrorMessage.ClientLeft:
                res = "You left the game.";
                break;

            case NetworkErrorMessage.NotEnoughPlayers:
                res = "Not enough players to continue the game.";
                break;

            case NetworkErrorMessage.ServerDisconnected:
                res = "You were disconnected from server.";
                break;

            case NetworkErrorMessage.StopServer:
                res = "The server was stopped.";
                break;

            case NetworkErrorMessage.None:
                res = "You were disconnected form server.";
                break;
            }
            return(res);
        }
 /// <summary>
 /// Called when the host is stopped. Destroy the gameManager, display an error message and reset the default lobby scene
 /// </summary>
 public override void OnStopHost()
 {
     if (!_isMatchmaking && GameManager.singleton != null)
     {
         errorMessage = NetworkErrorMessage.StopServer;
         GameObject.Destroy(GameManager.singleton.gameObject);
         NetworkServer.Destroy(GameManager.singleton.gameObject);
         infoPanel.Display(errorMessage.ToMessageString(), "OK", null);
         CustomNetworkLobbyManager.networkSceneName = this.onlineScene;
     }
     base.OnStopHost();
 }
        /// <summary>
        /// Called when the server is stopped. Destroy the gameManager, display an error message and reset the default lobby scene
        /// </summary>
        public override void OnStopServer()
        {
            if (!_isMatchmaking && GameManager.singleton != null)
            {
                GameObject.Destroy(GameManager.singleton.gameObject);
                NetworkServer.Destroy(GameManager.singleton.gameObject);
                // LobbyManager bug fix
                foreach (var playerInfo in GameObject.FindObjectsOfType <LobbyPlayer> ())
                {
                    GameObject.Destroy(playerInfo.gameObject);
                }
                errorMessage = NetworkErrorMessage.StopServer;
                infoPanel.Display(errorMessage.ToMessageString(), "OK", null);
                CustomNetworkLobbyManager.networkSceneName = this.onlineScene;
            }
            this.GetComponent <WebGLCustomServer> ().Stop();

            base.OnStopServer();
        }
Example #6
0
 void RpcNetworkErrorMessage(NetworkErrorMessage networkErrorMessage)
 {
     ((CustomNetworkLobbyManager)(CustomNetworkLobbyManager.singleton)).errorMessage = networkErrorMessage;
 }