Example #1
0
        private void receive(string a_message)
        {
            MSG_TYPE msg_type = m_messageManager.parse(a_message);

            switch (msg_type)
            {
            case MSG_TYPE.MSG_CLIENT_INFO_TYPE:
                connectedBox.Invoke(new Action(() => connectedBox.Items.Add(m_messageManager.getClientLogin() + " - " + m_messageManager.getClientIP())));
                break;

            case MSG_TYPE.MSG_RESET_INFO_TYPE:
                m_tcpServer.send(a_message);
                connectedBox.Invoke(new Action(() => connectedBox.Items.Clear()));
                connectedBox.Invoke(new Action(() => connectedBox.Items.Add(Regex.Replace(File.ReadAllText("./login.txt"), @"\s+", "") + " - " + Regex.Replace(File.ReadAllText("./ipaddress.txt"), @"\s+", ""))));
                send(m_messageManager.buildClientInfo(File.ReadAllText("./login.txt"), File.ReadAllText("./ipaddress.txt")));
                break;

            case MSG_TYPE.MSG_SERVER_INFO_TYPE:
                m_udpClient.stop();
                m_tcpClient.start(tcp_client_received_callback, m_messageManager.getServerIP());
                send(m_messageManager.buildResetInfo());
                break;

            case MSG_TYPE.MSG_HOST_INFO_TYPE:
                if (!(File.ReadAllText("./ipaddress.txt").Contains(m_messageManager.getHostIP())))
                {
                    File.WriteAllText("./hostip.txt", m_messageManager.getHostIP());
                    if (m_messageManager.getHostGame() == GAME_TYPE.GAME_H3_NEW_TYPE)
                    {
                        try
                        {
                            var startInfo = new ProcessStartInfo();

                            startInfo.WorkingDirectory = Path.GetDirectoryName(File.ReadAllText("./h3.txt"));
                            startInfo.FileName         = File.ReadAllText("./h3.txt");

                            Process.Start(startInfo);
                            Process.Start("AutoIt3_x64.exe", "h3newjoin.au3").WaitForExit();
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("H3 start failed. Please detect H3 again.");
                        }
                    }
                    else if (m_messageManager.getHostGame() == GAME_TYPE.GAME_H3_LOAD_TYPE)
                    {
                        try
                        {
                            var startInfo = new ProcessStartInfo();

                            startInfo.WorkingDirectory = Path.GetDirectoryName(File.ReadAllText("./h3.txt"));
                            startInfo.FileName         = File.ReadAllText("./h3.txt");

                            Process.Start(startInfo);
                            Process.Start("AutoIt3_x64.exe", "h3loadjoin.au3").WaitForExit();
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("H3 start failed. Please detect H3 again.");
                        }
                    }
                }
                break;

            default:
                break;
            }
        }