static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); DiffContainer.Init(byte.Parse(ConfigurationSettings.AppSettings["quality"])); _connectionManager = new ConnectionManager { ServerIp = "localhost" }; _connectForm = new ConnectForm { ServerIp = _connectionManager.ServerIp }; _mainForm = new MainForm { ScreenshotScale = float.Parse(ConfigurationSettings.AppSettings["scale"]), ScreenshotTimeout = int.Parse(ConfigurationSettings.AppSettings["timeout"]), JpegQuality = byte.Parse(ConfigurationSettings.AppSettings["quality"]) }; _connectForm.VisibleChanged += (sender, eventArgs) => { if (!_connectForm.Visible) { _connectionManager.ServerIp = _connectForm.ServerIp; var clientWebSocketConnection = new ClientWebSocketConnection(_connectionManager.GetConnection()); _mainForm.ClientWebSocketConnection = clientWebSocketConnection; _mainForm.ConferenceId = _connectForm.ConferenceId; _mainForm.ClientName = _connectForm.ClientName; _connectionManager.Connect(); _mainForm.Show(); } else { _connectionManager.Disconnect(); } }; _mainForm.VisibleChanged += (sender, eventArgs) => { if (!_mainForm.Visible) { _connectForm.Show(); } }; Application.Run(_connectForm); }
private void ПодключитьсяtoolStripMenuItem_Click(object sender, EventArgs e) { ConnectForm cf = new ConnectForm(); DialogResult dr = cf.ShowDialog(); if (dr != DialogResult.OK) {//не подключились connected = false; return; } this.TcpListener = cf.tcpListener; ListenerPort = cf.MyPort; myIp = (IPAddress)cf.cmbClientIp.SelectedItem; ////////////////////// serverIp = cf.serverIp; serverPort = cf.serverPort; name = cf.tbName.Text; this.Text = "Клиент " + name + " " + myIp.ToString() + " " + ListenerPort.ToString(); //регистрируемся на сервере if (!registerMe(cf.tbName.Text)) { MessageBox.Show("Не удалось зарегаться!"); serverIp = ""; serverPort = 0; connected = false; return; } connected = true; //запускаем поток для TcpListenera Thread tcpListenerThread = new Thread(TcpListenerThread); tcpListenerThread.Start(); //запускаем поток пинга AsyncStartPing(); //эти операции асинхронные //загружаем список контактов AsyncGetContactListFromServer(); //загружаем список файлов //AsyncGetFileListFromServer(); UpdateConnectedD(); }
private void connectToolStripMenuItem_Click(object sender, EventArgs e) { if (clientState == ClientState.Disconnected) { try { using (ConnectForm connectForm = new ConnectForm()) { // THIS IS CONFIRMED TO WORK! //float playerBase = codeInjector.ReadFloat(codeInjector.ReadUInt(codeInjector.ReadUInt(codeInjector.ReadUInt(codeInjector.ReadUInt(codeInjector.ReadUInt(0x004C67BC) + 0x60) + 0xA8) + 0x114) + 0x40) + 0x130); //Console.WriteLine(playerBase); connectForm.ShowDialog(); participant.Nickname = connectForm.Nickname; client = new Client(); client.PacketReceived += client_PacketReceived; client.Connect(IPAddress.Parse(connectForm.Server), 3031, 3030); client.Send(ProtocolType.Tcp, new Packet() { PacketType = PacketType.Connect, Content = connectForm.Nickname }); clientState = ClientState.Connecting; /*if (connectForm.Server != null && connectForm.Nickname != null) * { * ipEndPoint = new IPEndPoint(IPAddress.Parse(connectForm.Server), 3030); * * tcpClient.Connect(new IPEndPoint(IPAddress.Parse(connectForm.Server), 3031)); * * stream = tcpClient.GetStream(); * * Packet packet = new Packet() * { * PacketType = PacketType.Connect, * Content = connectForm.Nickname * }; * * stream.Write(packet.ToBytes(), 0, packet.Length); * * listenerThread.Start(); * * /* * * client = new UdpClient(); * client.Connect(ipEndPoint); * * Packet packet = SendPacket(new Packet() * { * PacketType = PacketType.Nickname, * Content = connectForm.Nickname * }); * * if (packet.PacketType != PacketType.Nickname || packet.Content != "OK") * { * MessageBox.Show("An error occured during the handshake with the Server. A response was received, but the Server rejected your request. Please try again.", "Error while handshaking"); * } * else * { * participants = new List<Participant>(); * playerCount = 0; * participant.Nickname = connectForm.Nickname; * clientState = ClientState.Connected; * * SetStatus("Connected (" + connectForm.Server + ")"); * } * }*/ } } catch (Exception exc) { ErrorHandler.ShowDialog("Connect dialog failed to load", "The connect dialog failed to load.", exc); } } else { MessageBox.Show("Disconnect from the current game to connect to a new game.", "Already connected"); } }
private void _quitButton_Click(object sender, EventArgs e) { Instance = null; Environment.Exit(0); }
public ConnectForm() { InitializeComponent(); Instance = this; }
private void ConnectForm_FormClosing(object sender, FormClosingEventArgs e) { Instance = null; Environment.Exit(0); }
private void connectToolStripMenuItem_Click(object sender, EventArgs e) { if (clientState == ClientState.Disconnected) { try { using (ConnectForm connectForm = new ConnectForm()) { // THIS IS CONFIRMED TO WORK! //float playerBase = codeInjector.ReadFloat(codeInjector.ReadUInt(codeInjector.ReadUInt(codeInjector.ReadUInt(codeInjector.ReadUInt(codeInjector.ReadUInt(0x004C67BC) + 0x60) + 0xA8) + 0x114) + 0x40) + 0x130); //Console.WriteLine(playerBase); connectForm.ShowDialog(); participant.Nickname = connectForm.Nickname; client = new Client(); client.PacketReceived += client_PacketReceived; client.Connect(IPAddress.Parse(connectForm.Server), 3031, 3030); client.Send(ProtocolType.Tcp, new Packet() { PacketType = PacketType.Connect, Content = connectForm.Nickname }); clientState = ClientState.Connecting; /*if (connectForm.Server != null && connectForm.Nickname != null) { ipEndPoint = new IPEndPoint(IPAddress.Parse(connectForm.Server), 3030); tcpClient.Connect(new IPEndPoint(IPAddress.Parse(connectForm.Server), 3031)); stream = tcpClient.GetStream(); Packet packet = new Packet() { PacketType = PacketType.Connect, Content = connectForm.Nickname }; stream.Write(packet.ToBytes(), 0, packet.Length); listenerThread.Start(); /* client = new UdpClient(); client.Connect(ipEndPoint); Packet packet = SendPacket(new Packet() { PacketType = PacketType.Nickname, Content = connectForm.Nickname }); if (packet.PacketType != PacketType.Nickname || packet.Content != "OK") { MessageBox.Show("An error occured during the handshake with the Server. A response was received, but the Server rejected your request. Please try again.", "Error while handshaking"); } else { participants = new List<Participant>(); playerCount = 0; participant.Nickname = connectForm.Nickname; clientState = ClientState.Connected; SetStatus("Connected (" + connectForm.Server + ")"); } }*/ } } catch (Exception exc) { ErrorHandler.ShowDialog("Connect dialog failed to load", "The connect dialog failed to load.", exc); } } else { MessageBox.Show("Disconnect from the current game to connect to a new game.","Already connected"); } }
public void Connect() { if (isAlreadyConnecting) return; isAlreadyConnecting = true; // Empty list box CuCoForm = new ConnectingForm(); CoForm = new ConnectForm(); //this.treeView1.Nodes.Clear(); //lbUserList.Items.Clear(); this.dataGridView_users.Rows.Clear(); bool connected = false; bool firstrun = true; while (!connected) { if (!firstrun || (firstrun && !Program.AppConfig.AutoConnect) || hasTriedFirstConnection && WindowState != FormWindowState.Minimized) { if (CoForm.ShowDialog(this) != DialogResult.OK) { // Clean exit Application.Exit(); return; } } firstrun = false; // Create the player info Player = new PlayerCarac(); Player.Nick = Program.AppConfig.Nick; Player.Type = (PlayerClass)CoForm.lbClass.SelectedIndex; Player.TextColor = Program.AppConfig.TextColor; hasTriedFirstConnection = true; connected = (CuCoForm.ShowDialog(this) == DialogResult.OK); } // Change text color tbInput.ForeColor = Program.AppConfig.TextColor; isAlreadyConnecting = false; this.toolStripStatusLabel3.Text = Player.Nick; }