Пример #1
0
        private void connectBtn_Click(object sender, EventArgs e) // Connect Button
        {
            if (isIngame)
            {
                MessageBox.Show("Please stay in/enter the main menu before starting a session!", "Error");
                return;
            }
            try
            {
                WriteToTABS("CONNECT|" + IPAddress.Parse(textBox1.Text).ToString());  // Send connect cmd + ip with parse checking
                button1.Enabled = false;                                              // Disable the host btn
                button2.Enabled = false;                                              // Disable the connection btn

                screenPartner = new IPEndPoint(IPAddress.Parse(textBox1.Text), 8042); // Connect to the other screenClient
                screenClient.Connect(screenPartner);
                new Thread(() => ScreenshotHandler.UdpThread()).Start();              // Start the udp listener
                ScreenshotHandler.WriteToUdp(StrToByte("HELLO"));                     // Send hello
            } catch (Exception)
            {
                MessageBox.Show("Invalid IP!", "Error");
            }
        }
Пример #2
0
        private static void TCPReceiver()
        {
            using (NetworkStream nStream = tcp.GetStream())             // Get the stream
            {
                using (BinaryReader reader = new BinaryReader(nStream)) // Read it
                {
                    uiWriter = new BinaryWriter(nStream);               // Set the writer

                    while (true)                                        // Permanently try to read
                    {
                        string newData = reader.ReadString();           // Unbelievably messy code for receiving commands (somebody else can improve it :)) )

                        if (newData.Equals("SHOWSAND"))
                        {
                            instance.Invoke(() => { MessageBox.Show("You can now start the Sandbox", "Connected!"); });
                        }
                        else if (newData.StartsWith("SHOWMSG"))
                        {
                            instance.Invoke(() => { MessageBox.Show(newData.Split('|')[1], "Message from TABS"); });
                        }
                        else if (newData.StartsWith("INGAME"))
                        {
                            isIngame = bool.Parse(newData.Split('|')[1]); // Change the ingame status
                        }
                        else if (newData.StartsWith("DEBUG"))
                        {
                            Console.WriteLine(newData.Split('|')[1]); // Print out debug text
                        }
                        else if (newData.StartsWith("WINH"))
                        {
                            ScreenshotHandler.unityWindow = new IntPtr(long.Parse(newData.Split('|')[1])); // Set the handle
                            new Thread(() => ScreenshotHandler.FramingThread()).Start();                   // Start the framing thread
                        }
                        else if (newData.StartsWith("GSTARTED"))
                        {
                            bool started = bool.Parse(newData.Split('|')[1]); // Is game started?
                            if (!isIngame)
                            {
                                continue;            // Continue if the player's in the main menu
                            }
                            if (!isHost)
                            {
                                if (started)
                                {
                                    screenshareForm.ArrangeWindow();
                                    screenshareForm.Visible = true;
                                    WinAPIs.SetForegroundWindow(screenshareForm.Handle);
                                    ScreenshotHandler.WriteToUdp(StrToByte("HELLO"));
                                    // Arrange and make the screenshare window ready for receiving
                                }
                                else
                                {
                                    screenshareForm.Visible = false;
                                    WinAPIs.SetForegroundWindow(ScreenshotHandler.unityWindow); // Hide the screenshare form
                                    // and set the game as the active one again
                                }
                            }
                            ScreenshotHandler.streaming = started;
                        }
                    }
                }
            }
        }