private void RidSelfOfMainWindow()
 {
     RunningMain = false;
     App.Current.MainWindow = this;
     mw.Disconnect();
     mw.GoAway();
     mw.Close();
     mw = null;
 }
        public void OnNetworkMessage(object sender, NewNetworkMessageEventArgs e)
        {
            if (!this.Dispatcher.CheckAccess())
            {
                this.Dispatcher.Invoke(new Action<object, NewNetworkMessageEventArgs>(OnNetworkMessage), sender, e);
                return;
            }

            string message = e.NetworkMessage;

            if (message == "&CONN")
            {
                SetStatusLabel("Logging in...");
            }
            else if (message == "&LOGGEDIN")
            {
                mw = new MainWindow(this.m, this, this.NetJungleProto, (MapMode)int.Parse(((ComboBoxItem)this.GameMap.SelectedItem).Tag as string));
                mw.SpectatorModeActive = UseSpectatorMode;
                TextToSpeech.Instance.Enabled = mw.UseSpeechSynth = (SpeechSynth.IsChecked.HasValue && (bool)SpeechSynth.IsChecked);
                App.Current.MainWindow = mw;
                NetJungleProto.NewNetworkMessage -= new NewNetworkMessageHandler(this.OnNetworkMessage);
                mw.Show();

                SaveLastConnectedSettings();
                SetStatusLabel("Ready! The timer UI should now appear in game.\nEnsure you are in BORDERLESS or WINDOWED mode.");

                RunningMain = true;
                // woo

                ActionButton.Content = UseLocalMode ? "Stop" : "Disconnect";
                SetFormFieldsEnabled(false, true);
            }
            else if (message == "&BADPASS")
            {
                RunningMain = false;

                NetJungleProto.Stop();
                NetJungleProto = null;

                SetStatusLabel("Error: password incorrect");
                ActionButton.Content = "Connect";
                SetFormFieldsEnabled(true, true);

                ServerPassword.Background = new SolidColorBrush(Colors.PaleVioletRed);
                ServerPassword.Focus();
            }
            else if (message == "!BADLINEVER")
            {
                RunningMain = false;

                NetJungleProto.Stop();
                NetJungleProto = null;

                SetStatusLabel("Error: that room requires a different client version.");
                ActionButton.Content = "Connect";
                SetFormFieldsEnabled(true, true);
            }
            else if (message == "!RECONNECT 4")
            {
                RunningMain = false;

                NetJungleProto.Stop();
                NetJungleProto = null;

                SetStatusLabel("Error: couldn't connect to server");
                ActionButton.Content = "Connect";
                SetFormFieldsEnabled(true, true);

            }
        }