private void Execute(object data) { _client1 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); string s = data as string; char[] b = { ';' }; Int32 count = 100; String[] strList = s.Split(b, count, StringSplitOptions.RemoveEmptyEntries); int port = 11001; if (strList.Length < 1) { return; } if (strList[0].Equals("loginok") == true) { form.Invoke((MethodInvoker) delegate { form.WindowState = FormWindowState.Maximized; form.ShowInTaskbar = true; LoginForm.Hide(); }); foreach (string item in strList) { if (item.Equals(strList[0]) != true) { form.Invoke((MethodInvoker) delegate { form.Room.Items.Add(item); }); } } if (strList.Length > 2) { char[] delimiter = { '#' }; String[] nameList = strList[strList.Length - 1].Split(delimiter, 100, StringSplitOptions.RemoveEmptyEntries); if (nameList.Length < 0 == false) { foreach (string item in nameList) { form.Invoke((MethodInvoker) delegate { form.Online.Items.Add(item); }); } } } } if (strList[0].Equals("login0ok") == true) { MessageBox.Show("Có người khác đang đăng nhập"); } if (strList[0].Equals("createok") == true) { string IpAdress = GetLocalIP(NetworkInterfaceType.Ethernet); while (true) { try { IPEndPoint ip = new IPEndPoint(IPAddress.Parse(IpAdress), port); _client1.Bind(ip); break; } catch { } port++; } Send("binded;" + port); form.Invoke((MethodInvoker) delegate { form.StartGame(); form.Buy.Enabled = true; form.Paint += new PaintEventHandler(form.Form1_Paint); }); _client1.Listen(1); Socket client_peer = _client1.Accept(); _client2 = client_peer; Thread listenPeer = new Thread(Receive_Peer); listenPeer.IsBackground = true; listenPeer.Start(client_peer); } if (strList[0].Equals("joinok") == true) { IPEndPoint ip = new IPEndPoint(IPAddress.Parse(strList[1]), int.Parse(strList[2])); _client1 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _client1.Connect(ip); form.Invoke((MethodInvoker) delegate { form.StartGame2(); form.Room.Dispose(); form.image.Dispose(); form.signal.Dispose(); form.Back.Enabled = false; form.CreateRoom.Enabled = false; form.Paint += new PaintEventHandler(form.Form1_Paint2); }); Thread listenPeer = new Thread(Receive_Peer); listenPeer.IsBackground = true; listenPeer.Start(null); } if (strList[0].Equals("enemysignal") == true) { form.Invoke((MethodInvoker) delegate { form.Back.Enabled = false; }); } if (strList[0].Equals("enemydis") == true) { MessageBox.Show("Your enemy has left this game, you are winner"); } if (strList[0].Equals("registerok") == true) { registorFrom.Invoke((MethodInvoker) delegate { registorFrom.Close(); }); MessageBox.Show("Đăng ký thành công, vui chơi thỏa thích :))", "Success", MessageBoxButtons.OK, MessageBoxIcon.None); } if (strList[0].Equals("register0ok") == true) { MessageBox.Show("Tên đăng nhập đã tồn tại, vui lòng dùng tên khác.", "Can not register", MessageBoxButtons.OK, MessageBoxIcon.None); } if (strList[0].Equals("yourtank") == true) { if (strList[1].Equals("1") == false) { form.Invoke((MethodInvoker) delegate { form.CreateRoom.Enabled = false; }); form.isDead = true; } if (strList[1].Equals("1") == true) { form.isDead = false; } } if (strList[0].Equals("buyok") == true) { form.Invoke((MethodInvoker) delegate { form.CreateRoom.Enabled = true; form.isDead = false; }); } if (strList[0].Equals("playagainok")) { form.Invoke((MethodInvoker) delegate { foreach (string item in strList) { if (item.Equals(strList[0]) != true && item.Equals(strList[strList.Length - 1]) != true) { form.Invoke((MethodInvoker) delegate { form.Room.Items.Add(item); }); } } form.Handle_Back_Click(); form.CreateRoom.Enabled = true; }); } }
private void btnCariHalamanAwal_Click(object sender, EventArgs e) { cari.Show(); lgn.Hide(); }