Esempio n. 1
0
        private void bt_gen_Click(object sender, RoutedEventArgs e)
        {
            Win_mm wm     = new Win_mm(MW);
            string player = MW.player_list.ElementAt(0);

            for (int i = 0; i < tb_hist.LineCount; i++)
            {
                if (tb_hist.GetLineText(i).StartsWith("("))
                {
                    string rep = "mmid: " + (i + 1).ToString() + "; result: " + tb_hist.GetLineText(i);
                    wm.SendResult(rep, null);
                    //Thread.Sleep(20);
                }
            }
            Console.WriteLine("Sent games");

            //Thread.Sleep(20);
            string players = tb_player.Text;
            string matchup = wm.SendResult("Matchup: " + players, null);

            tb_best.Text = matchup;
            Console.WriteLine("Sent Matchup");

            string ladder = wm.SendResult("Ladder: 0", null);

            Console.WriteLine("Asking for ladder");

            if (ladder != null && ladder.Length > 0)
            {
                PresentLadder(ladder);
            }
            wm.Show();
        }
Esempio n. 2
0
 public Win_mmselect(MainWindow mw, Win_mm wm)  : this()
 {
     MW = mw;
     WM = wm;
     foreach (dsmmid id in WM.MMIDS.Values)
     {
         mmcb_mmids.Items.Add(id.MMID);
     }
     bt_load_Click(null, null);
 }
Esempio n. 3
0
        public string StartClient(Win_mm wm, string player, string result)
        {
            Socket sender = null;

            byte[] bytes    = new byte[1024];
            string response = null;

            try
            {
                // Connect to a Remote server
                // Get Host IP Address that is used to establish a connection
                // In this case, we get one IP address of localhost that is IP : 127.0.0.1
                // If a host has multiple addresses, you will get a list of addresses

                //IPHostEntry ipHostInfo = Dns.GetHostEntry("userver4");
                //IPAddress ipAddress = IPAddress.Parse("192.168.178.28");

                IPHostEntry ipHostInfo = Dns.GetHostEntry("pax77.org");
                IPAddress   ipAddress  = IPAddress.Parse("144.76.58.9");
                IPEndPoint  remoteEP   = new IPEndPoint(ipAddress, port);

                // Create a TCP/IP  socket.
                sender = new Socket(ipAddress.AddressFamily,
                                    SocketType.Stream, ProtocolType.Tcp);

                // Connect the socket to the remote endpoint. Catch any errors.
                try
                {
                    // Connect to Remote EndPoint
                    sender.Connect(remoteEP);

                    Console.WriteLine("Socket connected to {0}",
                                      sender.RemoteEndPoint.ToString());

                    // Create the preBuffer data.
                    string string1 = "Hello from [" + player + "]: " + result + ";" + "\r\n";
                    byte[] preBuf  = Encoding.UTF8.GetBytes(string1);

                    int bytesSent = sender.Send(preBuf);

                    // Receive the response from the remote device.
                    int bytesRec = sender.Receive(bytes);
                    Console.WriteLine("Echoed test = {0}",
                                      Encoding.UTF8.GetString(bytes, 0, bytesRec));

                    string pattern = @"^sc2dsmm: Result: (.*)";
                    string ent     = Encoding.UTF8.GetString(bytes, 0, bytesRec);
                    string elo     = null;
                    foreach (Match m in Regex.Matches(ent, pattern))
                    {
                        elo = m.Groups[1].Value.ToString();
                    }
                    if (elo != null)
                    {
                        //wm.Dispatcher.Invoke(() =>
                        //{
                        //wm.PresentResult(elo);
                        //});
                        response = elo;
                    }

                    string pattern1 = @"^sc2dsmm: Matchup: (.*)";
                    string ent1     = Encoding.UTF8.GetString(bytes, 0, bytesRec);
                    string matchup  = null;
                    foreach (Match m in Regex.Matches(ent1, pattern1))
                    {
                        matchup = m.Groups[1].Value.ToString();
                    }
                    if (matchup != null)
                    {
                        response = matchup;
                    }

                    string pattern2 = @"^sc2dsmm: Ladder: (.*)";
                    string ent2     = Encoding.UTF8.GetString(bytes, 0, bytesRec);
                    string ladder   = null;
                    foreach (Match m in Regex.Matches(ent2, pattern2))
                    {
                        ladder = m.Groups[1].Value.ToString();
                    }
                    if (ladder != null)
                    {
                        response = ladder;
                    }

                    // Create the preBuffer data.
                    string string2 = "Hello from [" + player + "]: " + "fin" + ";" + "\r\n";
                    byte[] preBuf1 = Encoding.UTF8.GetBytes(string2);

                    int bytesSent1 = sender.Send(preBuf1);

                    // Release the socket.
                    sender.Shutdown(SocketShutdown.Both);
                    sender.Close();
                }
                catch (ArgumentNullException ane)
                {
                    Console.WriteLine("ArgumentNullException : {0}", ane.ToString());
                }
                catch (SocketException se)
                {
                    Console.WriteLine("SocketException : {0}", se.ToString());
                }
                catch (Exception e)
                {
                    Console.WriteLine("Unexpected exception : {0}", e.ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            return(response);
        }
Esempio n. 4
0
 public dsmmclient(Win_mm mw) : this()
 {
     MW = mw;
 }
Esempio n. 5
0
        public Socket StartClient(Win_mm mw, string player, string mode, string num, string skill, string server)
        {
            STATUS = false;
            Socket sender = null;

            byte[] bytes = new byte[1024];

            try
            {
                // Connect to a Remote server
                // Get Host IP Address that is used to establish a connection
                // In this case, we get one IP address of localhost that is IP : 127.0.0.1
                // If a host has multiple addresses, you will get a list of addresses

                //IPHostEntry ipHostInfo = Dns.GetHostEntry("userver4");
                //IPAddress ipAddress = IPAddress.Parse("192.168.178.28");

                IPHostEntry ipHostInfo = Dns.GetHostEntry("pax77.org");
                IPAddress   ipAddress  = IPAddress.Parse("144.76.58.9");
                IPEndPoint  remoteEP   = new IPEndPoint(ipAddress, port);

                // Create a TCP/IP  socket.
                sender = new Socket(ipAddress.AddressFamily,
                                    SocketType.Stream, ProtocolType.Tcp);

                mw.Dispatcher.Invoke(() =>
                {
                    mw.CLIENT = sender;
                });

                // Connect the socket to the remote endpoint. Catch any errors.
                try
                {
                    // Connect to Remote EndPoint
                    sender.Connect(remoteEP);

                    Console.WriteLine("Socket connected to {0}",
                                      sender.RemoteEndPoint.ToString());

                    // Create the preBuffer data.
                    string string1 = "Hello from [" + player + "]: Letmeplay: " + mode + ";" + num + ";" + skill + ";" + server + ";" + "\r\n";
                    byte[] preBuf  = Encoding.UTF8.GetBytes(string1);

                    int bytesSent = sender.Send(preBuf);

                    // Receive the response from the remote device.
                    int bytesRec = sender.Receive(bytes);
                    Console.WriteLine("Echoed test = {0}",
                                      Encoding.UTF8.GetString(bytes, 0, bytesRec));

                    if (sender != null)
                    {
                        PingPong(Encoding.UTF8.GetString(bytes, 0, bytesRec), player, sender, "0");
                    }


                    // Release the socket.
                    //sender.Shutdown(SocketShutdown.Both);
                    //sender.Close();
                }
                catch (ArgumentNullException ane)
                {
                    Console.WriteLine("ArgumentNullException : {0}", ane.ToString());
                }
                catch (SocketException se)
                {
                    Console.WriteLine("SocketException : {0}", se.ToString());
                }
                catch (Exception e)
                {
                    Console.WriteLine("Unexpected exception : {0}", e.ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            return(sender);
        }
Esempio n. 6
0
 public Win_norep(Win_mm wm, string mmid) : this()
 {
     WM           = wm;
     tb_mmid.Text = mmid;
 }