public override void DoTask(MainWindow mw) { Channel ch; bool channelBad = !Sender.ChannelList.TryGetValue(ChannelHash, out ch) || !ch.Joined; // GameSurge may send info about client with channel name: *.. so we try to process all these messages Client c = null; string lowerName = ClientName.ToLower(); if (!Sender.Clients.TryGetValue(lowerName, out c)) { if (!channelBad) { c = new Client(ClientName, Sender, Clan); } else // we don't have any common channel with this client { return; } } c.OnlineStatus = Client.Status.Online; if (!c.TusActive) { c.Country = Country; c.Rank = RanksClass.GetRankByInt(Rank); } c.GreatSnooper = ClientGreatSnooper; c.ClientApp = ClientApp; // This is needed, because when we join a channel we get information about the channel users using the WHO command if (!channelBad && !c.Channels.Contains(ch)) { ch.Clients.Add(c); } if (c.AddToChannel.Count > 0) { foreach (Channel channel in c.AddToChannel) { if (!c.Channels.Contains(ch)) { channel.Clients.Add(c); } } c.AddToChannel.Clear(); } }
private void TUSLoginWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Cancelled) { this.Close(); return; } switch (tusState) { case TUSStates.TUSError: MessageBox.Show(this, "An error occoured! Please try again!", "Fail", MessageBoxButton.OK, MessageBoxImage.Error); break; case TUSStates.OK: GlobalManager.User = new Client(nickName, null, nickClan); GlobalManager.User.Country = nickCountry; GlobalManager.User.Rank = RanksClass.GetRankByInt(nickRank); GlobalManager.User.GreatSnooper = true; GlobalManager.User.TusNick = tusNickStr; if (Properties.Settings.Default.ChangeWormsNick) { Properties.Settings.Default.WormsNick = nickName; Properties.Settings.Default.Save(); } // Initialize the WormNet Communicator wormNetC = new IRCCommunicator(serverAddress, serverPort); wormNetC.ConnectionState += ConnectionState; wormNetC.Connect(); return; case TUSStates.UserError: MessageBox.Show(this, "The given username or password was incorrent!", "Wrong username or password", MessageBoxButton.OK, MessageBoxImage.Error); break; case TUSStates.ConnectionError: MessageBox.Show(this, "The communication with TUS has failed. Please try again!", "Fail", MessageBoxButton.OK, MessageBoxImage.Error); break; } Container.IsEnabled = true; LoadingRing.IsActive = false; }
private void TUSLoaded(Task <string[]> tusTask) { if (tusTask.IsCanceled || tusCTS.Token.IsCancellationRequested) { this.Close(); return; } if (tusTask.IsFaulted) { return; } for (int i = 0; i < tusTask.Result.Length; i++) { string[] data = tusTask.Result[i].Split(new char[] { ' ' }); if (data.Length == 6 && Uri.IsWellFormedUriString(data[4], UriKind.Absolute)) { string lowerName = data[0].ToLower(); Client c; for (int j = 0; j < Servers.Count; j++) { if (Servers[j].IsRunning && Servers[j].Clients.TryGetValue(lowerName, out c)) { if (c.TusActive == false) { c.TusActive = true; c.TusNick = data[1]; int rank; if (int.TryParse(data[2].Substring(1), out rank)) { c.Rank = RanksClass.GetRankByInt(rank - 1); } c.Country = CountriesClass.GetCountryByCC(data[3].ToUpper()); c.TusLink = data[4]; if (c.Clan != data[5]) { c.Clan = data[5]; } } } } } } }
// Constructor public Client(string name, IRCCommunicator server, string clan = "") { this.Name = name; this.LowerName = name.ToLower(); this.Clan = clan; this.Rank = RanksClass.GetRankByInt(0); this.Channels = new List <Channel>(); this.PMChannels = new List <Channel>(); this.AddToChannel = new List <Channel>(); UserGroup group = null; if (UserGroups.Users.TryGetValue(this.LowerName, out group)) { Group = group; } if (server != null) { this.IsBanned = GlobalManager.BanList.ContainsKey(this.LowerName); server.Clients.Add(this.LowerName, this); } }
private void LogIn() { serverAddress = Server.Text.Trim().ToLower(); if (serverAddress.Length == 0) { MakeErrorTooltip(Server, "Please choose a server!"); return; } int colon; if ((colon = serverAddress.IndexOf(':')) != -1) { string portstr = serverAddress.Substring(colon + 1); if (!int.TryParse(portstr, out serverPort)) { serverPort = 6667; } else { serverAddress = serverAddress.Substring(0, colon); } } else { serverPort = 6667; } switch (LoginTypeChooser.SelectedIndex) { // Simple login case 0: if (clanRegex == null) { clanRegex = new Regex(@"^[a-z0-9]*$", RegexOptions.IgnoreCase); } nickName = Nick.Text.Trim(); nickClan = Clan.Text.Trim(); if (nickName.Length == 0) { MakeErrorTooltip(Nick, "Please enter your nickname!"); } else if (!nickRegex.IsMatch(nickName)) { MakeErrorTooltip(Nick, "Your nickname should begin with a character" + Environment.NewLine + "of the English aplhabet or with ` character!"); } else if (!nickRegex2.IsMatch(nickName)) { MakeErrorTooltip(Nick, "Your nickname contains one or more" + Environment.NewLine + "forbidden characters! Use characters from" + Environment.NewLine + "the English alphabet, numbers, - or `!"); } else if (!clanRegex.IsMatch(nickClan)) { MakeErrorTooltip(Clan, "Your clan can contain only characters" + Environment.NewLine + "from the English alphabet or numbers"); } else { Container.IsEnabled = false; LoadingRing.IsActive = true; nickCountry = Country.SelectedValue as CountryClass; nickRank = Rank.SelectedIndex; Properties.Settings.Default.LoginType = "simple"; Properties.Settings.Default.ServerAddress = Server.Text.Trim().ToLower(); Properties.Settings.Default.AutoLogIn = AutoLogIn.IsChecked.Value; Properties.Settings.Default.UserName = nickName; Properties.Settings.Default.UserClan = nickClan; Properties.Settings.Default.UserCountry = nickCountry.ID; Properties.Settings.Default.UserRank = nickRank; if (Properties.Settings.Default.ChangeWormsNick) { Properties.Settings.Default.WormsNick = nickName; } Properties.Settings.Default.Save(); GlobalManager.User = new Client(nickName, null, nickClan); GlobalManager.User.Country = nickCountry; GlobalManager.User.Rank = RanksClass.GetRankByInt(nickRank); // Initialize the WormNet Communicator wormNetC = new IRCCommunicator(serverAddress, serverPort); wormNetC.ConnectionState += ConnectionState; wormNetC.Connect(); } break; // TUS login case 1: nickName = TUSNick.Text.Trim(); tusPassword = TUSPass.Password.Trim(); if (nickName.Length == 0) { MakeErrorTooltip(TUSNick, "Please enter your nickname!"); } else if (!nickRegex.IsMatch(nickName)) { MakeErrorTooltip(TUSNick, "Your nickname should begin with a character" + Environment.NewLine + "of the English aplhabet or with ` character!"); } else if (!nickRegex2.IsMatch(nickName)) { MakeErrorTooltip(TUSNick, "Your nickname contains one or more" + Environment.NewLine + "forbidden characters! Use characters from" + Environment.NewLine + "the English alphabet, numbers, - or `!"); } else if (tusPassword.Length == 0) { MakeErrorTooltip(TUSPass, "Please enter your password!"); } else { Container.IsEnabled = false; LoadingRing.IsActive = true; Properties.Settings.Default.LoginType = "tus"; Properties.Settings.Default.ServerAddress = serverAddress; Properties.Settings.Default.AutoLogIn = AutoLogIn.IsChecked.Value; Properties.Settings.Default.TusNick = nickName; Properties.Settings.Default.TusPass = tusPassword; Properties.Settings.Default.Save(); tusState = TUSStates.TUSError; if (tusLoginWorker == null) { tusLoginWorker = new BackgroundWorker(); tusLoginWorker.WorkerSupportsCancellation = true; tusLoginWorker.DoWork += TUSLoginWorker_DoWork; tusLoginWorker.RunWorkerCompleted += TUSLoginWorker_RunWorkerCompleted; } tusLoginWorker.RunWorkerAsync(); } break; } }