public void Clear()
 {
     srl     = null;
     raceIRC = null;
     if (liveSplitChannel != null)
     {
         liveSplitChannel.MessageReceived -= LiveSplitChannel_MessageReceived;
     }
     UserName         = null;
     liveSplitChannel = null;
     if (raceClient != null)
     {
         raceClient.LocalUser.MessageSent -= LiveSplitChannel_MessageReceived;
     }
     raceClient = null;
     RaceSplits.Clear();
     hooked = false;
 }
        public void CheckRace()
        {
            try {
                if ((srl != null && (srl.IsDisposed || !srl.Visible)))
                {
                    Clear();
                }

                if (raceIRC == null || liveSplitChannel == null || raceClient == null)
                {
                    foreach (var form in Application.OpenForms)
                    {
                        SpeedRunsLiveForm srlForm = form as SpeedRunsLiveForm;

                        if (srlForm != null && !srlForm.IsDisposed && srlForm.Visible)
                        {
                            srl = srlForm;

                            PropertyInfo[] fields = typeof(SpeedRunsLiveForm).GetProperties(BindingFlags.Instance | BindingFlags.NonPublic);
                            PropertyInfo   field  = null;
                            for (int i = 0; i < fields.Length; i++)
                            {
                                if (fields[i].Name.IndexOf("SRLClient", StringComparison.OrdinalIgnoreCase) >= 0 && fields[i].PropertyType == typeof(SpeedRunsLiveIRC))
                                {
                                    field = fields[i];
                                    break;
                                }
                            }

                            if (field != null)
                            {
                                raceIRC = (SpeedRunsLiveIRC)field.GetValue(srl);
                            }

                            if (raceIRC != null)
                            {
                                fields = typeof(SpeedRunsLiveIRC).GetProperties(BindingFlags.Instance | BindingFlags.NonPublic);
                                field  = null;
                                for (int i = 0; i < fields.Length; i++)
                                {
                                    if (fields[i].Name.IndexOf("LiveSplitChannel", StringComparison.OrdinalIgnoreCase) >= 0 && fields[i].PropertyType == typeof(IrcChannel))
                                    {
                                        field = fields[i];
                                        break;
                                    }
                                }
                                if (field != null)
                                {
                                    liveSplitChannel = (IrcChannel)field.GetValue(raceIRC);
                                }

                                field = null;
                                for (int i = 0; i < fields.Length; i++)
                                {
                                    if (fields[i].Name.IndexOf("Client", StringComparison.OrdinalIgnoreCase) >= 0 && fields[i].PropertyType == typeof(IrcClient))
                                    {
                                        field = fields[i];
                                        break;
                                    }
                                }
                                if (field != null)
                                {
                                    raceClient = (IrcClient)field.GetValue(raceIRC);
                                }
                            }
                            break;
                        }
                    }
                }

                if (raceIRC != null && liveSplitChannel != null && raceClient != null)
                {
                    UserName = raceIRC.Username;
                    if (!hooked)
                    {
                        liveSplitChannel.MessageReceived += LiveSplitChannel_MessageReceived;
                        raceClient.LocalUser.MessageSent += LiveSplitChannel_MessageReceived;
                    }
                    hooked = true;
                }
            } catch { }
        }