Example #1
0
        public static void CreateMatch(ClientObject client1, ClientObject client2, string MatchType)
        {
            string connString       = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=Users;Integrated Security=True;Connect Timeout=30;MultipleActiveResultSets=True";
            string createMatchEntry = "INSERT INTO UserMatch(IP1, IP2, Score1, Score2, MatchType) VALUES ('" + client1.IP + "', '" + client2.IP + "', 0, 0, " + MatchType + ")";
            string getMatchId       = "SELECT MatchID FROM UserMatch WHERE IP1 = '" + client1.IP + "' AND IP2 = '" + client2.IP + "'";

            using (SqlConnection connection = new SqlConnection(connString))
            {
                connection.Open();
                SqlCommand createTable = new SqlCommand(createMatchEntry, connection);
                createTable.ExecuteReader();
            }
            using (SqlConnection connection1 = new SqlConnection(connString))
            {
                connection1.Open();
                SqlCommand findMatchId = new SqlCommand(getMatchId, connection1);

                SqlDataReader reader = findMatchId.ExecuteReader();

                while (reader.Read())
                {
                    string matchID = Convert.ToString(reader.GetInt32(0));
                    ClientNotifier.ClientCall(client1, matchID);
                    ClientNotifier.ClientCall(client2, matchID);
                }
            }
        }
Example #2
0
        public static void GetMatchScores(ClientObject client)
        {
            string score1 = "";
            string score2 = "";
            string IP1    = "";
            string IP2    = "";

            string connString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=Users;Integrated Security=True;Connect Timeout=30;MultipleActiveResultSets=True";

            string getScores = "SELECT Score1, Score2, IP1, IP2 FROM UserMatch WHERE MatchID = '" + client.MatchID;

            ClientObject client2 = new ClientObject();

            using (SqlConnection connection = new SqlConnection(connString))
            {
                connection.Open();

                SqlCommand getScoreCommand = new SqlCommand(getScores, connection);

                SqlDataReader reader = getScoreCommand.ExecuteReader();

                while (reader.Read())
                {
                    score1 = Convert.ToString(reader.GetInt32(0));
                    score2 = Convert.ToString(reader.GetInt32(1));
                    IP1    = reader.GetString(2);
                    IP2    = reader.GetString(3);
                }



                if (score1 == "0" || score2 == "0")
                {
                    Thread.Sleep(5000);
                    GetMatchScores(client);
                }
                else
                {
                    if (client.IP.Equals(IP1))
                    {
                        client2.IP    = IP2;
                        client2.Score = score2;

                        ClientNotifier.ClientCall(client2, client.Score);
                        ClientNotifier.ClientCall(client, client2.Score);
                    }
                    else
                    {
                        client2.IP    = IP1;
                        client2.Score = score1;

                        ClientNotifier.ClientCall(client2, client.Score);
                        ClientNotifier.ClientCall(client, client2.Score);
                    }
                }
            }
        }