private Post PostParser(HtmlNode postNode) { var post = new Post(); var contentQuery = @".//div[contains(concat(' ', normalize-space(@class), ' '), ' js-post__content-text')]"; post.Content = postNode.SelectSingleNode(contentQuery).InnerHtml.Trim(); var accountQuery = @".//div[contains(concat(' ', normalize-space(@class), ' '), 'author ')]"; var vbName = postNode.SelectSingleNode(accountQuery).InnerText.Trim(); ForumAccount acc = _db.Accounts.Where(a => a.VbName == vbName).SingleOrDefault(); post.ForumAccount = acc; var postIdQuery = @".//a[contains(concat(' ', normalize-space(@class), ' '), 'b-post__count')]"; var postHref = postNode.SelectSingleNode(postIdQuery).Attributes["href"].Value; var matchedNumbers = Regex.Matches(postHref, @"\d+"); var postId = matchedNumbers[matchedNumbers.Count - 1].Value; post.PostId = int.Parse(postId); var timeString = postNode.SelectSingleNode(@".//time").Attributes["datetime"].Value.Trim(); post.PostDate = DateTime.Parse(timeString); post.Hash = _hashProvider.Compute(post.Content); return(post); }
/// <summary> /// If Login successfully send user data to MainForm /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Timers.ElapsedEventArgs"/> instance containing the event data.</param> private void Timer1Elapsed(object sender, ElapsedEventArgs e) { this.timer1.Enabled = false; ((MainForm)this.Owner).cameThroughCorrectLogin = true; if (CacheController.Instance().UserSettings.ForumsAccount.Any(item => item.ForumURL == CacheController.Instance().UserSettings.CurrentForumUrl)) { CacheController.Instance().UserSettings.ForumsAccount.RemoveAll( item => item.ForumURL == CacheController.Instance().UserSettings.CurrentForumUrl); } var forumsAccount = new ForumAccount { ForumURL = CacheController.Instance().UserSettings.CurrentForumUrl, UserName = this.UserNameField.Text, UserPassWord = this.PasswordField.Text, GuestAccount = this.GuestLogin.Checked }; CacheController.Instance().UserSettings.ForumsAccount.Add(forumsAccount); CacheController.Instance().UserSettings.CurrentUserName = this.UserNameField.Text; this.Close(); }
public ActionResult DeleteConfirmed(int id) { ForumAccount forumaccount = db.Accounts.Find(id); db.Accounts.Remove(forumaccount); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Delete(int id = 0) { ForumAccount forumaccount = db.Accounts.Find(id); if (forumaccount == null) { return(HttpNotFound()); } return(View(forumaccount)); }
public ActionResult Edit(ForumAccount forumaccount) { if (ModelState.IsValid) { db.Entry(forumaccount).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(forumaccount)); }
public ActionResult Create(ForumAccount forumaccount) { if (ModelState.IsValid) { db.Accounts.Add(forumaccount); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(forumaccount)); }
// // GET: /ForumAccounts/Details/5 public ActionResult Details(int id = 0, int page = 0) { ForumAccount forumaccount = db.Accounts.Find(id); if (forumaccount == null) { return(HttpNotFound()); } var pageSize = Settings.Default.PostsPerPage; var posts = forumaccount.Posts.OrderByDescending(p => p.PostDate); var totalPages = (int)Math.Ceiling(posts.Count() / (float)pageSize); if (totalPages == 0) { totalPages = 1; } if (page == 0) { page = 1; } ViewBag.AccountId = forumaccount.Id; ViewBag.Title = forumaccount.Name; ViewBag.selectedSidebarEntry = forumaccount.Name; ViewBag.Paginator = new PaginatorViewModel { PageIndex = page, TotalPages = totalPages, MaximumSpread = 3, Action = "Details", Controller = "Accounts", ContentId = id }; var selectedPosts = posts.Skip((page - 1) * pageSize) .Take(pageSize) .ToViewModels() .OrderByDescending(p => p.PostDate) .ToList(); return(View(selectedPosts)); }
private void OnForumCommand(BotShell bot, CommandArgs e) { string username = e.Sender; if (e.Args.Length > 0) { username = Format.UppercaseFirst(e.Args[0]); } ForumAccount account = this.GetAccount(username); if (account == null) { bot.SendReply(e, "Unable to locate " + HTML.CreateColorString(bot.ColorHeaderHex, username + "'s") + " forum account"); return; } RichTextWindow window = new RichTextWindow(bot); window.AppendTitle(username + "'s Forum Account"); window.AppendHighlight("Name: "); window.AppendNormal(account.Realname); window.AppendLineBreak(); window.AppendHighlight("Primary Group: "); if (account.PrimaryGroup != string.Empty) { window.AppendNormal(account.PrimaryGroup); } else { window.AppendNormal("N/A"); } window.AppendLineBreak(); window.AppendHighlight("E-mail Address: "); window.AppendNormal(account.Email); window.AppendLineBreak(); window.AppendHighlight("Post Count: "); window.AppendNormal(account.Posts.ToString()); if (account.Rank != string.Empty) { window.AppendNormal(" (" + account.Rank + ")"); } window.AppendLineBreak(); window.AppendHighlight("Epeen: "); window.AppendNormal(account.Karma.ToString()); window.AppendLineBreak(); window.AppendHighlight("Enabled: "); if (account.Enabled) { window.AppendColorString(RichTextWindow.ColorGreen, "Yes"); } else { window.AppendColorString(RichTextWindow.ColorRed, "No"); if (username == e.Sender) { window.AppendNormal(" ["); window.AppendBotCommand("Activate", "forum activate"); window.AppendNormal("]"); } } window.AppendLineBreak(); window.AppendHighlight("Registered On: "); window.AppendNormal(Format.DateTime(account.Registered, FormatStyle.Medium)); window.AppendLineBreak(); if (account.Seen > 0) { window.AppendHighlight("Last Seen: "); TimeSpan span = TimeStamp.ToDateTime(TimeStamp.Now) - TimeStamp.ToDateTime(account.Seen); window.AppendNormal(Format.Time(span, FormatStyle.Large) + " ago"); window.AppendLineBreak(); } if (account.Groups.Count > 0) { window.AppendLineBreak(); window.AppendHeader("Additional Groups"); foreach (string group in account.Groups.Values) { window.AppendHighlight(group); window.AppendLineBreak(); } } bot.SendReply(e, username + "'s Forum Account »» " + window.ToString()); }
public ForumAccount GetAccount(string username) { ForumAccount account = null; lock (this._database.Connection) { using (IDbCommand command = this._database.Connection.CreateCommand()) { command.CommandText = "SELECT ID_MEMBER, memberName, dateRegistered, posts, ID_GROUP, lastLogin, instantMessages, unreadMessages, emailAddress, "; command.CommandText += "showOnline, karmaBad, karmaGood, memberIP, memberIP2, is_activated, additionalGroups, ID_POST_GROUP, totalTimeLoggedIn, realName, passwd "; command.CommandText += "FROM smf_members WHERE memberName = '" + Config.EscapeString(username) + "'"; IDataReader reader = command.ExecuteReader(); if (reader.Read()) { account = new ForumAccount(); account.ID = reader.GetInt32(0); account.Username = reader.GetString(1); account.Registered = reader.GetInt32(2); account.Posts = reader.GetInt32(3); account.PrimaryGroupID = reader.GetInt32(4); account.Seen = reader.GetInt32(5); account.Messages = reader.GetInt32(6); account.MessagesUnread = reader.GetInt32(7); account.Email = reader.GetString(8); account.ShowOnline = (reader.GetInt32(9) > 0); account.KarmaBad = reader.GetInt32(10); account.KarmaGood = reader.GetInt32(11); account.IP = reader.GetString(12); account.IP2 = reader.GetString(13); account.Enabled = (reader.GetInt32(14) == 1); account.RankID = reader.GetInt32(16); account.TotalTime = reader.GetInt32(17); account.Realname = reader.GetString(18); account.Password = reader.GetString(19); account.Groups = new Dictionary <string, string>(); foreach (string group in reader.GetString(15).Split(',')) { account.Groups.Add(group.Trim().Trim(','), ""); } reader.Close(); if (account.PrimaryGroupID > 0) { command.CommandText = "SELECT groupName FROM smf_membergroups WHERE ID_GROUP = " + account.PrimaryGroupID; reader = command.ExecuteReader(); if (reader.Read()) { account.PrimaryGroup = reader.GetString(0); } reader.Close(); } if (account.RankID > 0) { command.CommandText = "SELECT groupName FROM smf_membergroups WHERE ID_GROUP = " + account.RankID; reader = command.ExecuteReader(); if (reader.Read()) { account.Rank = reader.GetString(0); } reader.Close(); } Dictionary <string, string> groups = new Dictionary <string, string>(); foreach (string group in account.Groups.Keys) { command.CommandText = "SELECT groupName FROM smf_membergroups WHERE ID_GROUP = '" + Config.EscapeString(group) + "'"; reader = command.ExecuteReader(); if (reader.Read()) { groups.Add(group, reader.GetString(0)); } reader.Close(); } account.Groups = groups; } else { reader.Close(); } } } return(account); }
private void OnActivateCommand(BotShell bot, CommandArgs e) { // Beta process only allows clan, tl7, vhanet member if (bot.Dimension != AoLib.Net.Server.RubiKa) { bot.SendReply(e, "The activation process is currently disabled on this dimension. For more information read the public beta information on: http://www.vhabot.net/static.php?id=register"); return; } if (e.SenderWhois == null) { bot.SendReply(e, "Unable to download the required information about your character"); return; } if (!e.SenderWhois.Stats.Faction.Equals("clan", StringComparison.CurrentCultureIgnoreCase)) { bot.SendReply(e, "Gridnet beta accounts are currently only available for members of the clan faction"); return; } if (e.SenderWhois.Stats.Level < 205) { bot.SendReply(e, "Your character is required to be at least level 205 in order to participate in this beta"); return; } if (this._host.IsAlt(e.Sender)) { bot.SendReply(e, "Gridnet beta accounts can only be created using your registered main character"); return; } if (!this._host.IsMember(e.Sender)) { bot.SendReply(e, "Gridnet beta accounts are currently only available for members of the vhanet raid system"); return; } // Validate input if (e.Args.Length < 2) { bot.SendReply(e, "Correct Usage: activate [forum account] [forum password]"); return; } ForumAccount account = this.GetAccount(e.Args[0]); if (account == null) { bot.SendReply(e, "Unable to locate the specified forum account"); return; } if (!account.Enabled) { bot.SendReply(e, "Your forum account hasn't been verified yet. Please follow the instructions the forum gave you in order to verify your forum account"); return; } // Validate password if (this.Sha1(e.Args[0].ToLower() + e.Args[1]) != account.Password) { bot.SendReply(e, "The password you supplied doesn't match the password of the specified forum account"); return; } // Prepare account string dimension = null; switch (bot.Dimension) { case AoLib.Net.Server.RubiKa: dimension = "rk5"; break; default: bot.SendReply(e, "Gridnet accounts are not available for characters on your dimension"); return; } string gridnetAccount = e.Sender + " [" + dimension + "]"; if (account.Username != account.Realname) { bot.SendReply(e, "Your forum account has already been modified and can't be used for this activation process"); return; } // Check for duplicate accounts lock (this._database.Connection) { using (IDbCommand command = this._database.Connection.CreateCommand()) { command.CommandText = "SELECT memberName FROM smf_members WHERE realName = '" + Config.EscapeString(gridnetAccount) + "'"; IDataReader reader = command.ExecuteReader(); if (reader.Read()) { bot.SendReply(e, "Your character already has been linked to the following forum account: " + HTML.CreateColorString(bot.ColorHeaderHex, reader.GetString(0))); reader.Close(); return; } reader.Close(); } } // Activate gridnet account this._database.ExecuteNonQuery("UPDATE smf_members SET realName = '" + Config.EscapeString(gridnetAccount) + "' WHERE memberName = '" + Config.EscapeString(account.Username) + "'"); bot.SendReply(e, "Your gridnet account " + HTML.CreateColorString(bot.ColorHeaderHex, gridnetAccount) + " has been activated"); }
/// <summary> /// Tries to Login to the Forums /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void LoginBtnClick(object sender, EventArgs e) { if (this.ForumUrl.Text.StartsWith("http://")) { if (!this.ForumUrl.Text.EndsWith("/")) { this.ForumUrl.Text += "/"; } CacheController.Instance().UserSettings.CurrentForumUrl = this.ForumUrl.Text; } string welcomeString = this.rm.GetString("lblWelcome"), lblFailed = this.rm.GetString("lblFailed"); if (this.GuestLogin.Checked) { this.UserNameField.Text = "Guest"; this.PasswordField.Text = "Guest"; this.label3.Text = string.Format("{0}{1}", welcomeString, this.UserNameField.Text); this.label3.ForeColor = Color.Green; this.LoginButton.Enabled = false; if ( CacheController.Instance().UserSettings.ForumsAccount.Any( item => item.ForumURL == CacheController.Instance().UserSettings.CurrentForumUrl)) { CacheController.Instance().UserSettings.ForumsAccount.RemoveAll( item => item.ForumURL == CacheController.Instance().UserSettings.CurrentForumUrl); } var forumsAccount = new ForumAccount { ForumURL = CacheController.Instance().UserSettings.CurrentForumUrl, UserName = this.UserNameField.Text, UserPassWord = this.PasswordField.Text, GuestAccount = false }; CacheController.Instance().UserSettings.ForumsAccount.Add(forumsAccount); CacheController.Instance().UserSettings.CurrentUserName = this.UserNameField.Text; this.timer1.Enabled = true; } else { // Encrypt Password this.PasswordField.Text = Utility.EncodePassword(this.PasswordField.Text).Replace("-", string.Empty).ToLower(); var loginManager = new LoginManager(this.UserNameField.Text, this.PasswordField.Text); if (loginManager.DoLogin(CacheController.Instance().UserSettings.CurrentForumUrl)) { this.label3.Text = string.Format("{0}{1}", welcomeString, this.UserNameField.Text); this.label3.ForeColor = Color.Green; this.LoginButton.Enabled = false; if ( CacheController.Instance().UserSettings.ForumsAccount.Any( item => item.ForumURL == CacheController.Instance().UserSettings.CurrentForumUrl)) { CacheController.Instance().UserSettings.ForumsAccount.RemoveAll( item => item.ForumURL == CacheController.Instance().UserSettings.CurrentForumUrl); } var forumsAccount = new ForumAccount { ForumURL = CacheController.Instance().UserSettings.CurrentForumUrl, UserName = this.UserNameField.Text, UserPassWord = this.PasswordField.Text, GuestAccount = false }; CacheController.Instance().UserSettings.ForumsAccount.Add(forumsAccount); CacheController.Instance().UserSettings.CurrentUserName = this.UserNameField.Text; this.timer1.Enabled = true; } else { this.label3.Text = lblFailed; this.label3.ForeColor = Color.Red; } } }
private IEnumerable <Post> GetNewPosts(ForumAccount account, List <Thread> threads) { try { var url = string.Format(Settings.Default.ProfileUrl, account.ForumId); var req = (HttpWebRequest)WebRequest.Create(url); req.Method = "GET"; req.ContentType = "application/x-www-form-urlencoded"; req.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2"; req.CookieContainer = new CookieContainer(); req.CookieContainer.Add(new Cookie(".YAFNET_Authentication", Settings.Default.AuthToken, "/", "forums.white-wolf.com")); var responseStream = req.GetResponse().GetResponseStream(); var document = new HtmlDocument(); if (responseStream == null) { throw new NoNullAllowedException(); } using (var reader = new StreamReader(responseStream)) { using (var memoryStream = new MemoryStream()) { using (var writer = new StreamWriter(memoryStream)) { writer.Write(reader.ReadToEnd()); memoryStream.Position = 0; document.Load(memoryStream, new UTF8Encoding()); } } } document = CleanHtml(document); var postsCollection = new List <Post>(); const string placeholderFragment = "id('MasterPageContentPlaceHolder_forum_ctl01_ProfileTabs_Last10PostsTab')//table//tr["; const string anchorSelectorFragment = "]//td/a/@href"; const string titleSelectorFragment = "]//td/a/text()"; const string dateSelectorFragment = "]//td/text()[4]"; foreach (int i in Enumerable.Range(0, 10)) { var tableRow = 1 + (2 * i); var threadIdSelector = String.Format("{0}{1}{2}", placeholderFragment, tableRow, anchorSelectorFragment); var titleSelector = String.Format("{0}{1}{2}", placeholderFragment, tableRow, titleSelectorFragment); var dateSelector = String.Format("{0}{1}{2}", placeholderFragment, tableRow, dateSelectorFragment); var threadHref = document.DocumentNode.SelectSingleNode(threadIdSelector).Attributes[0].Value; var threadId = int.Parse(Regex.Match(threadHref, @"(\d+)$").Groups[0].Value); var threadTitle = document.DocumentNode.SelectSingleNode(titleSelector).InnerHtml.Trim(); var postDate = DateTime.Parse(document.DocumentNode.SelectSingleNode(dateSelector).InnerHtml.Trim()); var postContent = document.DocumentNode.SelectSingleNode( "id('MasterPageContentPlaceHolder_forum_ctl01_ProfileTabs_Last10PostsTab_LastPosts_MessagePost_" + i + "')").InnerHtml; Thread thread = threads.SingleOrDefault(s => s.ThreadId == threadId); if (thread == null) { thread = new Thread { ThreadId = threadId, Title = threadTitle }; threads.Add(thread); } postsCollection.Add(new Post { Content = postContent, Hash = _hashProvider.Compute(postContent), PostDate = postDate, Thread = thread }); } return(postsCollection.Where(newPost => !account.Posts.Select(p => p.Hash).Contains(newPost.Hash))); } catch (Exception ex) { Debug.WriteLine(ex.Message + "\n----\n" + ex.StackTrace); return(new Post[0]); } }