public ChatActions()
 {
     sock = SocketSingleton.getInstance();
 }
Example #2
0
        /// <summary>Handles connecting to the server and starting a game.</summary>
        void onConnecToServer()
        {
            EditText serverText = FindViewById <EditText>(Resource.Id.ServerText);
            EditText userText   = FindViewById <EditText>(Resource.Id.UserText);
            EditText oppText    = FindViewById <EditText> (Resource.Id.OpponentText);

            serverAddr = serverText.Text;
            uname      = userText.Text;

            sockInstance = new SocketSingleton(serverAddr, 8080);
            SocketSingleton.initSingleton();

            // On "Connect" button click, try to connect to a server.
            progress = ProgressDialog.Show(this, "Loading", "Please Wait...", true);

            if (progress != null)
            {
                progress.Hide();
            }
            if (!sockInstance.isConnected())
            {
                setError("Couldn't connect");
            }
            else
            {
                setError("Connected");
                Intent intent = new Intent(this, typeof(ChessActivity));
                ChessActions.socket    = sockInstance;
                ChessActivity.username = userText.Text;
                ChessActivity.opponent = oppText.Text;
                ChessActivity.actions  = new ChessActions(ChessActivity.username, ChessActivity.opponent);

                ChessActivity.actions.login();
                string read = SocketSingleton.getInstance().getIn().ReadLine();
                if (read == "TRUE")
                {
                    if (ChessActivity.actions.joinGame())
                    {
                        ChessActivity.myTurn  = false;
                        ChessActivity.newGame = false;
                        StartActivity(intent);
                    }
                    else
                    {
                        if (ChessActivity.actions.newGame())
                        {
                            ChessActivity.myTurn  = true;
                            ChessActivity.newGame = true;
                            StartActivity(intent);
                        }
                        else
                        {
                            setError("Username already in use for a game.");
                        }
                    }
                }
                else
                {
                    setError("Could not use username to login.");
                }
            }
        }