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);

            }
        }
        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.StartsWith("NETTIMER ") || message.StartsWith("MUSEBOTNP "))
            {
                foreach (UI.IUIElement iui in uiElements)
                {
                    if (message.StartsWith("NETTIMER ") && !(iui is NetworkedTimer))
                        continue;
                    else if (message.StartsWith("^MUSEBOTNP ") && !(iui is MuseBotNP))
                        continue;

                    iui.GotMessage(message);
                }
            }
            else if (message.StartsWith("!DISCONNECT"))
            {
                SetStatusLine("Connection lost");
            }
            else if (message.StartsWith("!RECONNECT"))
            {
                String[] messageSplit = message.Split(new[] { ' ' });
                SetStatusLine(String.Format("Connect attempt #{0}", messageSplit[1]));
            }
            else if (message == "!BADLINEVER")
            {
                welWin.mainWindowAbort("Bad NetJungleTimer version for room.");
            }
            else if (message.StartsWith("CONN") && netJungleProto.IsMaster)
            {
                SyncData();
            }

            if (!message.StartsWith("!")) // internal message
            {
                SetStatusLine("Connected");
            }
        }