예제 #1
0
        /// <summary>
        /// Creates a <c>SectionThread</c>
        /// </summary>
        /// <param name="session"> Session that is used for sending the request </param>
        /// <param name="section"> Section under which the <c>SectionThread</c> is listed </param>
        /// <param name="startPost"> Represents the content and title of the <c>SectionThread</c> </param>
        /// <param name="settings"> Additional options that can be set </param>
        /// <param name="closed"> If true, the thread state is closed meaning that no one (except the staff) can answer to this thread </param>
        /// <returns> Freshly created <c>SectionThread</c> </returns>
        public static SectionThread Create <TUser>(AuthenticatedSession <TUser> session, Section section, SectionPost startPost,
                                                   SectionPost.Settings settings = SectionPost.Settings.ParseUrl | SectionPost.Settings.ShowSignature,
                                                   bool closed = false)
            where TUser : User
        {
            session.ThrowIfInvalid();

            session.Post("https://www.elitepvpers.com/forum/newthread.php?do=postthread&f=" + section.ID,
                         new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("subject", String.IsNullOrEmpty(startPost.Title) ? "-" : startPost.Title),
                new KeyValuePair <string, string>("message", startPost.Content.ToString()),
                new KeyValuePair <string, string>("wysiwyg", "0"),
                new KeyValuePair <string, string>("taglist", String.Empty),
                new KeyValuePair <string, string>("iconid", "0"),
                new KeyValuePair <string, string>("s", String.Empty),
                new KeyValuePair <string, string>("securitytoken", session.SecurityToken),
                new KeyValuePair <string, string>("f", section.ID.ToString()),
                new KeyValuePair <string, string>("do", "postthread"),
                new KeyValuePair <string, string>("posthash", "74532335f4d3a9f352db6af1b1c257f7"),
                new KeyValuePair <string, string>("poststarttime", "1389309192"),
                new KeyValuePair <string, string>("loggedinuser", session.User.ID.ToString()),
                new KeyValuePair <string, string>("sbutton", "Submit New Thread"),
                new KeyValuePair <string, string>("signature", settings.HasFlag(SectionPost.Settings.ShowSignature) ? "1" : "0"),
                new KeyValuePair <string, string>("parseurl", settings.HasFlag(SectionPost.Settings.ParseUrl) ? "1" : "0"),
                new KeyValuePair <string, string>("parseame", "1"),
                new KeyValuePair <string, string>("vbseo_retrtitle", "1"),
                new KeyValuePair <string, string>("vbseo_is_retrtitle", "1"),
                new KeyValuePair <string, string>("emailupdate", "9999"),
                new KeyValuePair <string, string>("polloptions", "4")
            });

            return(new SectionThread(0, section));
        }
        /// <summary>
        /// Sends a <c>PrivateMessage</c> using the given session
        /// </summary>
        /// <param name="session"> Session that is used for sending the request </param>
        /// <param name="settings"> Additional options that can be set </param>
        /// <remarks>
        /// The names of the recipients have to be given in order to send the message.
        /// Messages with a blank title will not be send. Therefore, '-' will be used as title if nothing was specified.
        /// Certain requirements must be fulfilled in order to send messages automatically without entering a captcha:
        /// - More than 20 posts OR the <c>User.Usergroup.Premium</c> rank OR the <c>User.Usergroup.EliteGoldTrader</c> rank
        /// </remarks>
        public void Send <TUser>(AuthenticatedSession <TUser> session, Settings settings = Settings.ParseUrl | Settings.ShowSignature) where TUser : User
        {
            session.ThrowIfInvalid();
            if (session.User.Posts <= 20 && !session.User.HasRank(Usergroup.Premium) && !session.User.HasRank(Usergroup.EliteGoldTrader))
            {
                throw new InsufficientAccessException("More than 20 posts or the premium / elite*gold trader badge is required for sending private messages without captchas");
            }

            foreach (var splittedRecipientList in Recipients.Split(5))
            {
                var recipients = String.Join(";", splittedRecipientList.Select(recipient => recipient.Name));

                session.Post("https://www.elitepvpers.com/forum/private.php?do=insertpm&pmid=",
                             new List <KeyValuePair <string, string> >()
                {
                    new KeyValuePair <string, string>("recipients", recipients),
                    new KeyValuePair <string, string>("bccrecipients", String.Empty),
                    new KeyValuePair <string, string>("title", String.IsNullOrEmpty(Title) ? "-" : Title),
                    new KeyValuePair <string, string>("message", Content.ToString()),
                    new KeyValuePair <string, string>("wysiwyg", "0"),
                    new KeyValuePair <string, string>("iconid", "0"),
                    new KeyValuePair <string, string>("s", String.Empty),
                    new KeyValuePair <string, string>("securitytoken", session.SecurityToken),
                    new KeyValuePair <string, string>("do", "insertpm"),
                    new KeyValuePair <string, string>("pmid", String.Empty),
                    new KeyValuePair <string, string>("forward", String.Empty),
                    new KeyValuePair <string, string>("sbutton", "submit"),
                    new KeyValuePair <string, string>("savecopy", settings.HasFlag(Settings.SaveCopy) ? "1" : "0"),
                    new KeyValuePair <string, string>("signature", settings.HasFlag(Settings.ShowSignature) ? "1" : "0"),
                    new KeyValuePair <string, string>("parseurl", settings.HasFlag(Settings.ParseUrl) ? "1" : "0")
                });
            }
        }
예제 #3
0
        /// <summary>
        /// Deletes the <c>SectionThread</c>
        /// </summary>
        /// <param name="session"> Session that is used for sending the request </param>
        /// <param name="reason"> Reason for the deletion </param>
        /// <remarks>
        /// Not tested yet!
        /// </remarks>
        public void Delete <TUser>(AuthenticatedSession <TUser> session, string reason) where TUser : User
        {
            if (session.User.GetHighestRank() < Usergroup.GlobalModerator)
            {
                throw new InsufficientAccessException("You don't have enough access rights to delete this thread");
            }
            if (ID == 0)
            {
                throw new ArgumentException("ID must not be empty");
            }
            session.ThrowIfInvalid();

            session.Post("https://www.elitepvpers.com/forum/postings.php",
                         new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("s", String.Empty),
                new KeyValuePair <string, string>("t", ID.ToString()),
                new KeyValuePair <string, string>("do", "dodeletethread"),
                new KeyValuePair <string, string>("deletetype", "1"),
                new KeyValuePair <string, string>("securitytoken", session.SecurityToken),
                new KeyValuePair <string, string>("deletereason", reason),
            });

            Deleted = true;
        }
예제 #4
0
        /// <summary>
        /// Creates the <c>Treasure</c> and makes it public
        /// </summary>
        /// <param name="session"> Session used for sending the request </param>
        public void Create <TUser>(AuthenticatedSession <TUser> session) where TUser : User
        {
            session.ThrowIfInvalid();
            if (Content.Length < 4)
            {
                throw new ArgumentException("The content is too short (4 characters minimum)");
            }
            if (Title.Length < 4)
            {
                throw new ArgumentException("The title is too short (4 characters minimum)");
            }
            if (Cost < 1)
            {
                throw new ArgumentException("The price is too low (at least 1 elite*gold)");
            }

            session.Post("http://www.elitepvpers.com/theblackmarket/treasures/",
                         new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("title", Title),
                new KeyValuePair <string, string>("content", Content),
                new KeyValuePair <string, string>("cost", Cost.ToString()),
                new KeyValuePair <string, string>("createtreasure", "Submit")
            });

            CreationDate = DateTime.Now;
            Seller       = session.User;
        }
예제 #5
0
        /// <summary>
        /// Creates a <c>SocialGroup</c>
        /// </summary>
        /// <param name="session"> Session that is used for sending the request </param>
        /// <param name="name"> Name of the group </param>
        /// <param name="description"> Description of the group </param>
        /// <param name="access"> Access restrictions of the group determining who can see- or who can enter the group </param>
        /// <param name="settings"> Additional options that can be set  </param>
        /// <returns> The just created SocialGroup </returns>
        public static SocialGroup Create <TUser>(AuthenticatedSession <TUser> session, string name, string description,
                                                 Access access    = Access.Public,
                                                 Options settings = Options.EnableGroupAlbums | Options.EnableGroupMessages)
            where TUser : User
        {
            session.ThrowIfInvalid();

            session.Post("https://www.elitepvpers.com/forum/group.php?do=docreate",
                         new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("s", String.Empty),
                new KeyValuePair <string, string>("securitytoken", session.SecurityToken),
                new KeyValuePair <string, string>("do", "docreate"),
                new KeyValuePair <string, string>("groupid", String.Empty),
                new KeyValuePair <string, string>("url", "https%3A%2F%2Fwww.elitepvpers.com%2Fforum%2Fgroups%2F"),
                new KeyValuePair <string, string>("socialgroupcategoryid", "1"),
                new KeyValuePair <string, string>("groupname", name),
                new KeyValuePair <string, string>("groupdescription", description),
                new KeyValuePair <string, string>("grouptype", access.ToString()),
                new KeyValuePair <string, string>("options%5Benable_group_albums%5D", settings.HasFlag(Options.EnableGroupAlbums) ? "1" : "0"),
                new KeyValuePair <string, string>("options%5Benable_group_messages%5D", settings.HasFlag(Options.EnableGroupMessages) ? "1" : "0")
            });

            return(new SocialGroup(0));
        }
예제 #6
0
        /// <summary>
        /// Edits the <c>SocialGroup</c> and applies the given options
        /// </summary>
        /// <param name="session"> Session that is used for sending the request </param>
        /// <param name="description"> Description of the group </param>
        /// <param name="access"> Access restrictions of the group determining who can see- or who can enter the group </param>
        /// <param name="settings"> Additional options that can be set  </param>
        public void Edit <TUser>(AuthenticatedSession <TUser> session, string description, Access access, Options settings) where TUser : User
        {
            if (ID == 0)
            {
                throw new ArgumentException("Group ID must not be zero");
            }
            session.ThrowIfInvalid();

            session.Post("https://www.elitepvpers.com/forum/group.php?do=doedit",
                         new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("securitytoken", session.SecurityToken),
                new KeyValuePair <string, string>("do", "doedit"),
                new KeyValuePair <string, string>("groupid", ID.ToString()),
                new KeyValuePair <string, string>("s", String.Empty),
                new KeyValuePair <string, string>("url", "https://www.elitepvpers.com/forum/groups/" + ID.ToString() + "--.html"),
                new KeyValuePair <string, string>("socialgroupcategoryid", "1"),
                new KeyValuePair <string, string>("groupdescription", description),
                new KeyValuePair <string, string>("grouptype", access.ToString()),
                new KeyValuePair <string, string>("options[enable_group_albums]", settings.HasFlag(Options.EnableGroupAlbums) ? "1" : "0"),
                new KeyValuePair <string, string>("options[enable_group_messages]", settings.HasFlag(Options.EnableGroupMessages) ? "1" : "0"),
                new KeyValuePair <string, string>("options[owner_mod_queue]", settings.HasFlag(Options.ApproveGroupMessages) ? "1" : "0"),
                new KeyValuePair <string, string>("options[join_to_view]", settings.HasFlag(Options.JoinToView) ? "1" : "0"),
                new KeyValuePair <string, string>("options[only_owner_discussions]", settings.HasFlag(Options.OnlyOwnerDiscussions) ? "1" : "0"),
            });

            Description = description;
            AccessMode  = access;
            Settings    = settings;
        }
예제 #7
0
        /// <summary>
        /// Deletes the <c>SocialGroupThread</c>
        /// </summary>
        /// <param name="session"> Session that is used for sending the request </param>
        /// <param name="reason"> Reason for the deletion </param>
        public void Delete <TUser>(AuthenticatedSession <TUser> session, string reason) where TUser : User
        {
            if (session.User.GetHighestRank() < Usergroup.GlobalModerator && session.User != SocialGroup.Maintainer)
            {
                throw new InsufficientAccessException("You don't have enough access rights to delete this social group post");
            }
            if (ID == 0)
            {
                throw new ArgumentException("ID must not be empty");
            }
            session.ThrowIfInvalid();

            session.Post("http://www.elitepvpers.com/forum/group_inlinemod.php?gmids=",
                         new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("securitytoken", session.SecurityToken),
                new KeyValuePair <string, string>("groupid", SocialGroup.ID.ToString()),
                new KeyValuePair <string, string>("messageids", ID.ToString()),
                new KeyValuePair <string, string>("do", "doinlinedelete"),
                new KeyValuePair <string, string>("url", "http://www.elitepvpers.com/forum/groups/" + SocialGroup.ID.ToString() + "--.html"),
                new KeyValuePair <string, string>("inline_discussion", "1"),
                new KeyValuePair <string, string>("deletetype", "1"),
                new KeyValuePair <string, string>("deletereason", reason)
            });
        }
예제 #8
0
        /// <summary>
        /// Sends a <c>VisitorMessage</c> using the given session
        /// </summary>
        /// <param name="session"> Session that is used for sending the request </param>
        /// <param name="settings"> Additional options that can be set </param>
        /// <remarks>
        /// The ID of the recipient has to be given in order to send the message
        /// </remarks>
        public void Send <TUser>(AuthenticatedSession <TUser> session, Settings settings = Settings.ParseUrl) where TUser : User
        {
            if (Receiver.ID == 0)
            {
                throw new ArgumentException("Receiver ID must not be empty");
            }
            session.ThrowIfInvalid();

            session.Post("http://www.elitepvpers.com/forum/visitormessage.php?do=message",
                         new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("ajax", "1"),
                new KeyValuePair <string, string>("wysiwyg", "0"),
                new KeyValuePair <string, string>("styleid", "0"),
                new KeyValuePair <string, string>("fromquickcomment", "1"),
                new KeyValuePair <string, string>("securitytoken", session.SecurityToken),
                new KeyValuePair <string, string>("do", "message"),
                new KeyValuePair <string, string>("u", Receiver.ID.ToString()),
                new KeyValuePair <string, string>("u2", String.Empty),
                new KeyValuePair <string, string>("loggedinuser", String.Empty),
                new KeyValuePair <string, string>("parseurl", (settings & Settings.ParseUrl).ToString()),
                new KeyValuePair <string, string>("lastcomment", "1381528657"),
                new KeyValuePair <string, string>("allow_ajax_qc", "1"),
                new KeyValuePair <string, string>("fromconverse", String.Empty),
                new KeyValuePair <string, string>("message", Content.Elements.ToString()),
            });
        }
예제 #9
0
        public async Task <IActionResult> CompleteAuthentication(int id)
        {
            AuthenticatedSession authenticatedSession = await authenticatedSessionRepository.Get(id);

            ProviderInstance providerInstance = await providerRepository.GetInstance(authenticatedSession.Provider.ID);

            if (providerInstance == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            IAuthenticationProvider <object> authenticationProvider = await providerMappingService.CreateProvider <IAuthenticationProvider <object> >(providerInstance);

            try
            {
                authenticationProvider.Initialize($"http://{Request.Host}/Authentication/CompleteAuthentication?id={id}", data => StoreSession(id, data));
                bool result = await authenticationProvider.Authenticate(Request.Query.ToDictionary(k => k.Key, v => v.Value.ToString()));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"Failed to complete authentication for '{authenticatedSession.Name}'.");
            }

            return(RedirectToAction("Index"));
        }
예제 #10
0
        /// <summary>
        /// Creates a <c>SocialGroupThread</c>
        /// </summary>
        /// <param name="session"> Session that is used for sending the request </param>
        /// <param name="socialGroup"> SocialGroup where to create the <c>SocialGroupThread</c></param>
        /// <param name="startPost"> Represents the content and title of the <c>SocialGroupThread</c> </param>
        /// <param name="settings"> Additional options that can be set </param>
        /// <returns> Freshly created <c>SocialGroupThread</c></returns>
        public static SocialGroupThread Create <TUser>(AuthenticatedSession <TUser> session, SocialGroup socialGroup, SocialGroupPost startPost,
                                                       Message.Settings settings = Message.Settings.ParseUrl)
            where TUser : User
        {
            session.ThrowIfInvalid();

            session.Post("http://www.elitepvpers.com/forum/group.php?do=message",
                         new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("subject", startPost.Title),
                new KeyValuePair <string, string>("message", startPost.Content.ToString()),
                new KeyValuePair <string, string>("wysiwyg", "0"),
                new KeyValuePair <string, string>("s", String.Empty),
                new KeyValuePair <string, string>("securitytoken", session.SecurityToken),
                new KeyValuePair <string, string>("do", "message"),
                new KeyValuePair <string, string>("gmid", String.Empty),
                new KeyValuePair <string, string>("posthash", String.Empty),
                new KeyValuePair <string, string>("loggedinuser", session.User.ID.ToString()),
                new KeyValuePair <string, string>("groupid", socialGroup.ID.ToString()),
                new KeyValuePair <string, string>("discussionid", String.Empty),
                new KeyValuePair <string, string>("sbutton", "Nachricht+speichern"),
                new KeyValuePair <string, string>("parseurl", settings.HasFlag(Message.Settings.ParseUrl) ? "1" : "0"),
                new KeyValuePair <string, string>("parseame", "1"),
            });

            var socialGroupThread = new SocialGroupThread(0, socialGroup)
            {
                Creator = session.User, Deleted = false
            };

            socialGroupThread.Posts.Insert(0, startPost);
            return(socialGroupThread);
        }
예제 #11
0
        /// <summary>
        /// Deletes the <c>SocialGroup</c>
        /// </summary>
        /// <param name="session"> Session that is used for sending the request </param>
        public void Delete <TUser>(AuthenticatedSession <TUser> session) where TUser : User
        {
            if (session.User.GetHighestRank() < Usergroup.GlobalModerator && session.User != Maintainer)
            {
                throw new InsufficientAccessException("You don't have enough access rights to delete this group");
            }

            if (ID == 0)
            {
                throw new ArgumentException("Group ID must not be zero");
            }
            session.ThrowIfInvalid();

            session.Post("https://www.elitepvpers.com/forum/group.php?do=delete",
                         new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("do", "dodelete"),
                new KeyValuePair <string, string>("groupid", ID.ToString()),
                new KeyValuePair <string, string>("pictureid", String.Empty),
                new KeyValuePair <string, string>("s", String.Empty),
                new KeyValuePair <string, string>("securitytoken", session.SecurityToken),
                new KeyValuePair <string, string>("url", "https%3A%2F%2Fwww.elitepvpers.com%2Fforum%2Fgroups%2F" + ID.ToString() + "--.html"),
                new KeyValuePair <string, string>("confirm", "++Yes++")
            });
        }
        public async Task <AuthenticatedSession> Get(int id)
        {
            AuthenticatedSession session = await context
                                           .AuthenticatedSessions
                                           .Include(a => a.Provider)
                                           .FirstOrDefaultAsync(a => a.ID == id);

            return(session);
        }
예제 #13
0
        /// <summary>
        /// Fetches all recorded transactions of the profile using the TBM API
        /// </summary>
        /// <param name="session"> Session used for sending the request </param>
        /// <param name="query">
        /// Indicates whether to retrieve all transactions, only the sent transactions or only the received transactions.
        /// Use the <c>Transaction.Query.Received</c> or <c>Transaction.Query.Sent</c> constant. You can also concatenate both constants to get all transactions
        /// </param>
        /// <returns> List of <c>Transaction</c> objects representing the Transactions </returns>
        public List <Transaction> GetTransactions <TUser>(AuthenticatedSession <TUser> session,
                                                          Transaction.Query query = Transaction.Query.Sent | Transaction.Query.Received) where TUser : User
        {
            var typeParameter = "all";

            if (query.HasFlag(Transaction.Query.Received) && !query.HasFlag(Transaction.Query.Sent))
            {
                typeParameter = "received";
            }
            else if (query.HasFlag(Transaction.Query.Sent) && !query.HasFlag(Transaction.Query.Received))
            {
                typeParameter = "sent";
            }

            var responseContent = session.Get("http://www.elitepvpers.com/theblackmarket/api/transactions.php?u=" + session.User.ID +
                                              "&type=" + typeParameter + "&secretword=" + SecretWord);

            if (String.IsNullOrEmpty(responseContent))
            {
                throw new InvalidAuthenticationException("The provided Secret Word was invalid");
            }

            try
            {
                var     receivedTransactions = new List <Transaction>();
                dynamic transactions         = JsonConvert.DeserializeObject(responseContent);
                foreach (var jsonTransaction in transactions)
                {
                    var transaction = new Transaction((jsonTransaction.eg_transactionid as object).To <int>())
                    {
                        Note      = jsonTransaction.note,
                        EliteGold = (jsonTransaction.amount as object).To <int>(),
                        Time      = (jsonTransaction.dateline as object).To <uint>().ToDateTime()
                    };

                    if (query.HasFlag(Transaction.Query.Received))
                    {
                        transaction.Receiver = session.User;
                        transaction.Sender   = new User((jsonTransaction.eg_fromusername as object).To <string>(), (jsonTransaction.eg_from as object).To <int>());
                    }

                    if (query.HasFlag(Transaction.Query.Sent))
                    {
                        transaction.Sender   = session.User;
                        transaction.Receiver = new User((jsonTransaction.eg_tousername as object).To <string>(), (jsonTransaction.eg_to as object).To <int>());
                    }

                    receivedTransactions.Add(transaction);
                }

                return(receivedTransactions);
            }
            catch (JsonException exception)
            {
                throw new ParsingFailedException("Could not parse received Transactions", exception);
            }
        }
예제 #14
0
        private async Task <object> GetAuthenticatedSessionClient(int authenticatedSessionId)
        {
            AuthenticatedSession session = await authenticatedSessionRepository.Get(authenticatedSessionId);

            string decryptedSessionData = await encryptionService.Decrypt <string>(session.SessionData);

            IAuthenticationProvider <object> authenticationProvider = await CreateProvider <IAuthenticationProvider <object> >(session.Provider.ID);

            return(authenticationProvider.GetAuthenticatedClient(decryptedSessionData));
        }
예제 #15
0
        /// <summary>
        /// Sets the Secret word
        /// </summary>
        /// <param name="session">Session used for sending the request</param>
        /// <param name="newSecretWord"> The new secret word that will be set </param>
        public void SetSecretWord(AuthenticatedSession <TUser> session, string newSecretWord)
        {
            session.ThrowIfInvalid();

            session.Post("http://www.elitepvpers.com/theblackmarket/api/secretword/",
                         new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("secretword", newSecretWord)
            });
        }
예제 #16
0
        /// <summary>
        /// Gets the current Secret word
        /// </summary>
        /// <param name="session">Session used for sending the request</param>
        /// <returns> Current Secret word as string </returns>
        public string GetSecretWord(AuthenticatedSession <TUser> session)
        {
            session.ThrowIfInvalid();

            var res = session.Get("http://www.elitepvpers.com/theblackmarket/api/secretword/");
            var doc = new HtmlDocument();

            doc.LoadHtml(res);

            return(doc.DocumentNode.Descendants().GetElementsByNameXHtml("secretword").FirstOrDefault().Attributes["value"].Value);
        }
        public async Task <AuthenticatedSession> Get(int id)
        {
            AuthenticatedSession session = await context
                                           .AuthenticatedSessions
                                           .Include(a => a.Provider)
                                           .ThenInclude(p => p.Provider)
                                           .Include(a => a.Provider)
                                           .ThenInclude(p => p.Values)
                                           .ThenInclude(v => v.Property)
                                           .FirstOrDefaultAsync(a => a.ID == id);

            return(session);
        }
예제 #18
0
        /// <summary>
        /// Gets an <c>User</c> by the username
        /// </summary>
        /// <param name="name"> The username of the user that will be looked up </param>
        /// <returns> The user that was found </returns>
        /// <exception cref="EpvpapiException"> Thrown if no user was found matching the specified username </exception>
        public static User ByName <TUser>(AuthenticatedSession <TUser> session, string name) where TUser : User
        {
            var results = epvpapi.User.Search(session, name)
                          .Where(x => x.Name == name)
                          .ToList();

            if (results.Count == 0)
            {
                throw new EpvpapiException(String.Format("No user with the given name '{0}' was found", name));
            }

            return(results[0]);
        }
예제 #19
0
        public static List <Section> GetSectionByShortname <TUser>(AuthenticatedSession <TUser> session, string shortname) where TUser : User
        {
            var sections = new List <Section>();

            var res = session.Get("https://www.elitepvpers.com/forum/main");
            var doc = new HtmlDocument();

            doc.LoadHtml(res.ToString());

            var selectElements = doc.DocumentNode
                                 .Descendants()
                                 .GetElementsByTagName("select")
                                 .GetElementsByAttribute("name", "f")
                                 .ToList();

            if (selectElements.Count != 1)
            {
                throw new ParsingFailedException("The goto selection dropbox could not be found");
            }

            var selectElement = selectElements.First();
            var forumsNode    = selectElement.SelectSingleNode("optgroup[2]");

            if (forumsNode == null)
            {
                throw new ParsingFailedException("The root node of the listed forums wasn't found");
            }

            foreach (var forum in forumsNode.ChildNodes.GetElementsByTagName("option"))
            {
                var forumName = forum.NextSibling.InnerText.Strip();
                forumName = Regex.Replace(forumName, "(&amp;)|(^ )|(')|((&nbsp; )+)", "");

                var forumShortname = Regex.Replace(forumName, @"(\bof\b)|(\bfor\b)|(\bthe\b)", "", RegexOptions.IgnoreCase);
                forumShortname = Regex.Replace(forumShortname, "[^a-zA-Z0-9']+", "-");
                forumShortname = Regex.Replace(forumShortname, "(-$)|(^-)", "");
                forumShortname = forumShortname.ToLower();

                if (forumShortname != shortname)
                {
                    continue;
                }

                sections.Add(new Section(forum.Attributes["value"].Value.To <int>(), forumShortname)
                {
                    Name = forumName
                });
            }

            return(sections);
        }
예제 #20
0
            /// <summary>
            /// Sends a message to the channel
            /// </summary>
            /// <param name="session"> Session used for sending the request </param>
            /// <param name="message"> The message text to send </param>
            public void Send <TUser>(AuthenticatedSession <TUser> session, string message) where TUser : User
            {
                session.ThrowIfInvalid();

                session.Post("http://www.elitepvpers.com/forum/mgc_cb_evo_ajax.php",
                             new List <KeyValuePair <string, string> >()
                {
                    new KeyValuePair <string, string>("do", "ajax_chat"),
                    new KeyValuePair <string, string>("channel_id", ID.ToString()),
                    new KeyValuePair <string, string>("chat", message),
                    new KeyValuePair <string, string>("securitytoken", session.SecurityToken),
                    new KeyValuePair <string, string>("s", String.Empty)
                });
            }
예제 #21
0
        /// <summary>
        /// Updates the user by requesting the profile
        /// </summary>
        /// <param name="session"> Session used for sending the request </param>
        public void Update <TUser>(AuthenticatedSession <TUser> session) where TUser : User
        {
            if (ID == 0)
            {
                throw new ArgumentException("User ID must not be 0");
            }
            session.ThrowIfInvalid();
            var res = session.Get(GetUrl());

            var doc = new HtmlDocument();

            doc.LoadHtml(res);
            new UserParser(this, (this == session.User)).Execute(doc);
        }
예제 #22
0
        /// <summary>
        /// Deletes the <c>Treasure</c> permanently
        /// </summary>
        /// <param name="session"> Session used for sending the request </param>
        public void Delete <TUser>(AuthenticatedSession <TUser> session) where TUser : User
        {
            session.ThrowIfInvalid();
            if (ID == 0)
            {
                throw new ArgumentException("ID must not be zero");
            }

            session.Post(GetUrl(),
                         new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("deletetreasure", "1")
            });
        }
        public async Task <int> Add(string name, byte[] sessionData, ProviderInstance providerInstance)
        {
            AuthenticatedSession session = new AuthenticatedSession();

            session.Name        = name;
            session.SessionData = sessionData;
            session.Provider    = providerInstance;

            await context.AuthenticatedSessions.AddAsync(session);

            await context.SaveChangesAsync();

            return(session.ID);
        }
        /// <summary>
        /// Report the private message
        /// </summary>
        /// <param name="session"> The session which will be used for the report </param>
        /// <param name="reason"> The resion for the report </param>
        public void Report <TUser>(AuthenticatedSession <TUser> session, string reason) where TUser : User
        {
            session.ThrowIfInvalid();

            session.Post("https://www.elitepvpers.com/forum/private.php?do=sendemail",
                         new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("s", String.Empty),
                new KeyValuePair <string, string>("securitytoken", session.SecurityToken),
                new KeyValuePair <string, string>("reason", reason),
                new KeyValuePair <string, string>("pmid", ID.ToString()),
                new KeyValuePair <string, string>("do", "sendemail"),
                new KeyValuePair <string, string>("url", "https://www.elitepvpers.com/forum/private.php?do=showpm&pmid=" + ID.ToString())
            });
        }
        public async Task <bool> StoreSession(int sessionId, byte[] sessionData)
        {
            AuthenticatedSession session = await context.AuthenticatedSessions.FirstOrDefaultAsync(api => api.ID == sessionId);

            if (session != null)
            {
                session.SessionData = sessionData;

                await context.SaveChangesAsync();

                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Retrieves information about the messages such as title, content and sender
        /// </summary>
        /// <param name="session"> Session used for sending the request </param>
        public void Update <TUser>(AuthenticatedSession <TUser> session) where TUser : User
        {
            session.ThrowIfInvalid();
            if (ID == 0)
            {
                throw new System.ArgumentException("ID must not be emtpy");
            }

            var res = session.Get("https://www.elitepvpers.com/forum/private.php?do=showpm&pmid=" + ID.ToString());
            var doc = new HtmlDocument();

            doc.LoadHtml(res);

            new PrivateMessageParser.SenderParser(Sender).Execute(doc.GetElementbyId("post"));
            new PrivateMessageParser.ContentParser(this).Execute(doc.GetElementbyId("td_post_"));
        }
예제 #27
0
        /// <summary>
        /// Logs in the user
        /// </summary>
        /// <param name="session">Session used for sending the request</param>
        /// <param name="md5Password"> Hashed (MD5) password of the session user </param>
        /// <remarks>
        /// In order for this function to work, either the real username or the e-mail address has to be set in the <c>User</c> property
        /// </remarks>
        public void Login(AuthenticatedSession <TUser> session, string md5Password)
        {
            session.Post("http://www.elitepvpers.com/forum/login.php?do=login&langid=1",
                         new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("vb_login_username", User.Name),
                new KeyValuePair <string, string>("cookieuser", "1"),
                new KeyValuePair <string, string>("s", String.Empty),
                new KeyValuePair <string, string>("securitytoken", "guest"),
                new KeyValuePair <string, string>("do", "login"),
                new KeyValuePair <string, string>("vb_login_md5password", md5Password),
                new KeyValuePair <string, string>("vb_login_md5password_utf", md5Password)
            });

            session.Update();
        }
예제 #28
0
        /// <summary>
        /// Sets the signature content
        /// </summary>
        /// <param name="session">Session used for sending the request</param>
        /// <param name="signatureContent"> Content to set as signature </param>
        public void SetSignature(AuthenticatedSession <TUser> session, Content signatureContent)
        {
            var content = new MultipartFormDataContent
            {
                // Encoding (SBCSCodePageEncoding) is important and required to transmit german characters such as Ä, Ü, Ö...
                { new StringContent(signatureContent.ToString(), System.Text.Encoding.GetEncoding("ISO-8859-1")), "message" },
                { new StringContent("0"), "wysiwyg" },
                { new StringContent("http://www.elitepvpers.com/forum/usercp.php"), "url" },
                { new StringContent(String.Empty), "s" },
                { new StringContent(session.SecurityToken), "securitytoken" },
                { new StringContent("updatesignature"), "do" },
                { new StringContent("52428800"), "MAX_FILE_SIZE" }
            };

            session.PostMultipartFormData("http://www.elitepvpers.com/forum/profile.php?do=updatesignature", content);
        }
예제 #29
0
        /// <summary>
        /// Sets the Avatar
        /// </summary>
        /// <param name="session">Session used for sending the request</param>
        /// <param name="image"> <c>Image</c> to set as new avatar </param>
        /// <param name="changeType"> 0 for uploading a new avatar, -1 for deleting the old one without uploading a new one </param>
        protected void SetAvatar(AuthenticatedSession <TUser> session, Image image, int changeType)
        {
            var content = new MultipartFormDataContent
            {
                {
                    new ByteArrayContent(image.Data), "upload",
                    (String.IsNullOrEmpty(image.Name)) ? "Unnamed.jpeg" : image.Name + image.Format
                },
                { new StringContent(String.Empty), "s" },
                { new StringContent(session.SecurityToken), "securitytoken" },
                { new StringContent("updateavatar"), "do" },
                { new StringContent(changeType.ToString()), "avatarid" }
            };

            session.PostMultipartFormData("http://www.elitepvpers.com/forum/profile.php?do=updateavatar", content);
        }
예제 #30
0
        /// <summary>
        /// Retrieves a list of all posts in the <c>SectionThread</c>
        /// </summary>
        /// <param name="session"> Session used for sending the request </param>
        /// <param name="firstPage"> Index of the first page to fetch </param>
        /// <param name="pageCount"> Amount of pages to get replies from. The higher this count, the more data will be generated and received </param>
        /// <returns> List of <c>SectionPost</c>s representing the replies </returns>
        public List <SectionPost> Replies <TUser>(AuthenticatedSession <TUser> session, uint pageCount, uint firstPage) where TUser : User
        {
            session.ThrowIfInvalid();
            if (ID == 0)
            {
                throw new ArgumentException("ID must not be empty");
            }

            var retrievedReplies = new List <SectionPost>();

            for (uint i = firstPage; i < (firstPage + pageCount); ++i)
            {
                var res          = session.Get(GetUrl(i));
                var htmlDocument = new HtmlDocument();
                htmlDocument.LoadHtml(res);

                var postsRootNode = htmlDocument.GetElementbyId("posts");
                if (postsRootNode == null)
                {
                    continue;
                }

                // for some reason, the lastpost container contains nothing and needs to be filtered out
                foreach (var postContainerNode in postsRootNode.ChildNodes.GetElementsByTagName("div").Where(element => element.Id != "lastpost"))
                {
                    // skip deleted posts, parsing them doesn't work (yet)
                    if (postContainerNode.SelectSingleNode("div[1]/div[1]/div[1]/table[1]/tr[1]/td[1]/a[1]/img[1]") == null)
                    {
                        continue;
                    }

                    var parsedPost = new SectionPost(0, this);
                    new SectionPostParser(parsedPost).Execute(postContainerNode);
                    retrievedReplies.Add(parsedPost);
                }

                // store the starting post and
                // remove it after storing since it is no reply
                if (i == 1 && retrievedReplies.Count != 0)
                {
                    InitialPost = retrievedReplies.First();
                    retrievedReplies.Remove(retrievedReplies.First());
                }
            }

            return(retrievedReplies);
        }
예제 #31
0
 public SoapEmulator(AuthenticatedSession session)
 {
     this.m_session = session;
 }