private void CreateGame(object sender, RoutedEventArgs e) { if (!PassRegex.IsMatch(GamePassword.Text)) { MessageBox.Show(this, "Password can contain only characters from the English alphabet!", "Wrong characters", MessageBoxButton.OK, MessageBoxImage.Error); return; } string WN = "0"; if (WormNat2.IsChecked.Value) { WN = "1"; MessageBox.Show( "Greetings WormNAT2 user!" + Environment.NewLine + Environment.NewLine + "This is a reminder message to remind you that WormNAT2" + Environment.NewLine + "is a free service. Using WormNAT2 tunnels all data" + Environment.NewLine + "through a proxy server hosted by the community, thus" + Environment.NewLine + "consuming bandwidth and other resources. Therefore," + Environment.NewLine + "we''d like to ask you to only use WormNAT2 when you" + Environment.NewLine + "have already tried configuring hosting the proper way." + Environment.NewLine + Environment.NewLine + "Don''t forget that you can find instructions on how" + Environment.NewLine + "to set up hosting here:" + Environment.NewLine + Environment.NewLine + "http://worms2d.info/Hosting", "A friendly reminder", MessageBoxButton.OK, MessageBoxImage.Information); } // A stringbuilder, because we want to modify the game name StringBuilder sb = new StringBuilder(GameName.Text.Trim()); // Remove illegal characters for (int i = 0; i < sb.Length; i++) { char ch = sb[i]; if (!WormNetCharTable.EncodeGame.ContainsKey(ch)) { sb.Remove(i, 1); i -= 1; } } string tmp = sb.ToString().Trim(); sb.Clear(); sb.Append(tmp); // Save settings Properties.Settings.Default.HostGameName = tmp; Properties.Settings.Default.HostUseWormnat = WormNat2.IsChecked.Value; Properties.Settings.Default.HostInfoToChannel = InfoToChannel.IsChecked.Value; Properties.Settings.Default.Save(); // Encode the Game name text for (int i = 0; i < sb.Length; i++) { char ch = sb[i]; if (ch == '"' || ch == '&' || ch == '\'' || ch == '<' || ch == '>' || ch == '\\') { sb.Remove(i, 1); sb.Insert(i, "%" + WormNetCharTable.EncodeGame[ch].ToString("X")); i += 2; } else if (ch == '#' || ch == '+' || ch == '%') { sb.Remove(i, 1); sb.Insert(i, "%" + WormNetCharTable.EncodeGame[ch].ToString("X")); i += 2; } else if (ch == ' ') { sb.Remove(i, 1); sb.Insert(i, "%A0"); i += 2; } else if (WormNetCharTable.EncodeGame[ch] >= 0x80) { sb.Remove(i, 1); sb.Insert(i, "%" + WormNetCharTable.EncodeGame[ch].ToString("X")); i += 2; } } Container.IsEnabled = false; if (e != null) { e.Handled = true; } string highPriority = Properties.Settings.Default.WAHighPriority ? "1" : "0"; GameHostedEventArgs args = new GameHostedEventArgs(ServerAddress + " \"" + Properties.Settings.Default.WaExe + "\" " + GlobalManager.User.Name + " \"" + sb.ToString() + "\" \"" + GamePassword.Text + "\" " + ChannelName + " " + ChannelScheme + " " + GlobalManager.User.Country.ID.ToString() + " " + CC + " " + WN + " " + highPriority, ExitSnooper.IsChecked.Value); GameHosted.BeginInvoke(this, args, null, null); }
private void Handle(GameHosted message) { this.log.Debug("Game hosted message handled by games collection proxy"); this.ModelUpdaterResolver.GetUpdater <IUpdatableGames, GamesChanged>().Update(this.model, message); }