Esempio n. 1
0
        private void Client(CancellationToken cancellationToken)
        {
            string temporaryIP = string.Empty;

            Client.Client client = new Client.Client();

            while (searchActivity.ip == string.Empty)
            {
                // Poll on this property if you have to do
                // other cleanup before throwing.
                if (cancellationToken.IsCancellationRequested)
                {
                    // Clean up here, then...
                    cancellationToken.ThrowIfCancellationRequested();
                }

                temporaryIP = client.Input(new string[] { "-u" });

                int temporaryInt;

                if (int.TryParse(temporaryIP.Split(new char[] { '.' })[0], out temporaryInt))
                {
                    searchActivity.ip = temporaryIP;
                }

                if (searchActivity.ip != string.Empty)
                {
                    try
                    {
                        client.Input(new string[] { "-t", "-i", searchActivity.ip, "test", "123" });

                        int.Parse(Regex.Split(client.Input(new string[] { "-t", "-i", searchActivity.ip, "test" }), ": ")[1]);
                    }
                    catch (Exception ex)
                    {
#if DEBUG
                        //This prints to the screen an error message
                        Console.WriteLine("ERROR: " + ex.ToString());
#endif

                        searchActivity.ip = string.Empty;
                    }
                }

                Thread.Sleep(1000);
            }

            searchActivity.playerPosition = int.Parse(Regex.Split(client.Input(new string[] { "-t", "-i", searchActivity.ip, "numberOfPlayers" }), ": ")[1]) + 1;

            searchActivity.numberOfPlayers = searchActivity.playerPosition;

            client.Input(new string[] { "-t", "-i", searchActivity.ip, "numberOfPlayers", searchActivity.numberOfPlayers.ToString() });

            searchActivity.RunOnUiThread(() => searchActivity.searchTextView.Text = context.Resources.GetString(Resource.String.JoinSearchTitleConnected) + " " + context.Resources.GetString(Resource.String.JoinSearchTitleWaiting));

            while (true)
            {
                // Poll on this property if you have to do
                // other cleanup before throwing.
                if (cancellationToken.IsCancellationRequested)
                {
                    // Clean up here, then...
                    cancellationToken.ThrowIfCancellationRequested();
                }

                if (Regex.Split(client.Input(new string[] { "-t", "-i", searchActivity.ip, "start" }), ": ")[1] == "true")
                {
                    searchActivity.GoToGameActivity(searchActivity.searchType);
                }

                Thread.Sleep(1000);
            }
        }
Esempio n. 2
0
        private void Client(CancellationToken cancellationToken)
        {
            bool notStartedBool = true;

            Client.Client client = new Client.Client();

            while (notStartedBool)
            {
                // Poll on this property if you have to do
                // other cleanup before throwing.
                if (cancellationToken.IsCancellationRequested)
                {
                    // Clean up here, then...
                    cancellationToken.ThrowIfCancellationRequested();
                }

                notStartedBool = false;

                try
                {
                    client.Input(new string[] { "-t", "test", "123" });

                    int.Parse(Regex.Split(client.Input(new string[] { "-t", "test" }), ": ")[1]);
                }
                catch (Exception ex)
                {
#if DEBUG
                    //This prints to the screen an error message
                    Console.WriteLine("ERROR: " + ex.ToString());
#endif

                    notStartedBool = true;
                }

                Thread.Sleep(1000);
            }

            client.Input(new string[] { "-t", "start", "false" });
            client.Input(new string[] { "-t", "numberOfPlayers", "1" });

            searchActivity.playerPosition  = 1;
            searchActivity.numberOfPlayers = 1;

            searchActivity.RunOnUiThread(() => searchActivity.searchButton.Text = context.Resources.GetString(Resource.String.HostSearchButtonLabelPlay) + " " + searchActivity.numberOfPlayers + " " + context.Resources.GetString(Resource.String.HostSearchButtonLabelPlayers));

            int temporaryNumberOfPlayers;

            while (true)
            {
                // Poll on this property if you have to do
                // other cleanup before throwing.
                if (cancellationToken.IsCancellationRequested)
                {
                    // Clean up here, then...
                    cancellationToken.ThrowIfCancellationRequested();
                }

                try
                {
                    temporaryNumberOfPlayers = int.Parse(Regex.Split(client.Input(new string[] { "-t", "numberOfPlayers" }), ": ")[1]);

                    if (temporaryNumberOfPlayers > searchActivity.numberOfPlayers)
                    {
                        searchActivity.numberOfPlayers = temporaryNumberOfPlayers;

                        searchActivity.RunOnUiThread(() => searchActivity.searchButton.Text = context.Resources.GetString(Resource.String.HostSearchButtonLabelPlay) + " " + searchActivity.numberOfPlayers + " " + context.Resources.GetString(Resource.String.HostSearchButtonLabelPlayers));
                    }
                }
                catch (Exception ex)
                {
#if DEBUG
                    //This prints to the screen an error message
                    Console.WriteLine("ERROR: " + ex.ToString());
#endif
                }

                Thread.Sleep(1000);
            }
        }