Exemplo n.º 1
0
        public void Connect()
        {
            client_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            try
            {
                client_socket.Connect(new IPEndPoint(IPAddress.Parse(IP), port));
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not connect to server!");

                lobby.Invoke(() =>
                {
                    lobby.Close();
                });
                return;
            }

            if (client_socket.Connected)
            {
                Packet pack = new Packet();
                pack.Type         = JoinMessage;
                pack.PlayerStatus = new player();

                pack.PlayerStatus.Name = lobby.player_name;

                SendPacket(pack);
            }

            while (client_socket.IsConnected())
            {
                process_packet.ReadData(client_socket);
            }

            lobby.Invoke(() =>
            {
                lobby.Close();
            });
        }
Exemplo n.º 2
0
        private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (PlayerName == null)
            {
                MessageBox.Show("You need to set the Player Options up first!");
                return;
            }

            string ServerName = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
            DataGridViewCellCollection cells = dataGridView1.Rows[e.RowIndex].Cells;

            if (lobby != null)
            {
                lobby.Close();
            }
            Server_Browser.ActiveForm.Hide();

            var net_address = cells[5].Value.ToString().Split(':');


            lobby = new Lobby(ServerName, this, net_address[0], Convert.ToInt32(net_address[1].ToString()), false);
            lobby.Show();
        }