public HSession(string email, string password, HHotel hotel) { Email = email; Hotel = hotel; Password = password; _cookies = new CookieContainer(); _httpHotelUri = new Uri(Hotel.ToUrl(false)); _httpsHotelUri = new Uri(Hotel.ToUrl(true)); _inBuffer = new byte[1024]; _client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); }
public static string Juice(this HPage page, HHotel hotel) { switch (page) { case HPage.Profile: return(hotel.ToUrl(true) + "/profile/"); case HPage.Settings: return(hotel.ToUrl(true) + "/settings"); case HPage.Client: return(hotel.ToUrl(true) + "/api/client/clienturl"); default: return(string.Empty); } }
/// <summary> /// Returns the user's public profile information associated with the given unique indentifier using the specified <see cref="HHotel"/> in an asynchronous operation. /// </summary> /// <param name="uniqueId">The unique identifier of the user.</param> /// <param name="hotel">The hotel where the target user is from.</param> public static async Task <HProfile> GetProfileByUniqueIdAsync(string uniqueId, HHotel hotel) { string profileJson = await _hRequest.DownloadStringAsync( string.Format(PROFILE_API_FORMAT, hotel.ToUrl(true), uniqueId)).ConfigureAwait(false); return(HProfile.Create(profileJson)); }
/// <summary> /// Returns the <seealso cref="HProfile"/> from the specified hotel associated with the given unique identifier in an asynchronous operation. /// </summary> /// <param name="uniqueId">The unique identifier of the player you wish to retrieve the <see cref="HProfile"/> from.</param> /// <param name="hotel">The <seealso cref="HHotel"/> that the target user is located on.</param> /// <returns></returns> public static async Task <HProfile> GetProfileAsync(string uniqueId, HHotel hotel) { string profileJson = await _httpClient.GetStringAsync( string.Format(PROFILE_API_FORMAT, hotel.ToUrl(), uniqueId)); return(HProfile.Create(profileJson)); }
/// <summary> /// Returns the <seealso cref="HUser"/> from the specified hotel associated with the given name in an asynchronous operation. /// </summary> /// <param name="name">The name of the player you wish to retrieve the <seealso cref="HUser"/> from.</param> /// <param name="hotel">The <seealso cref="HHotel"/> that the target user is located on.</param> /// <returns></returns> public static async Task <HUser> GetUserAsync(string name, HHotel hotel) { string userJson = await _httpClient.GetStringAsync( hotel.ToUrl() + USER_API_SUFFIX + name); return(HUser.Create(userJson)); }
/// <summary> /// Returns the current online player count for the specified hotel. /// </summary> /// <param name="hotel">The hotel to retrieve the online player count from.</param> /// <returns></returns> public static int GetPlayersOnline(HHotel hotel) { using (var webClientEx = new WebClientEx()) { webClientEx.Proxy = null; webClientEx.Headers["Cookie"] = GetIpCookie(hotel); webClientEx.Headers["User-Agent"] = ChromeAgent; string body = webClientEx.DownloadString(hotel.ToUrl(false) + "/login_popup"); return(body.Contains("stats-fig") ? int.Parse(body.GetChild("<span class=\"stats-fig\">", '<')) : -1); } }
/// <summary> /// Returns the player figure id relative to the specified player name, and hotel. /// </summary> /// <param name="playerName">The name of the player of whom to grab the player figure id from.</param> /// <param name="hotel">The hotel where the specified player name exists on.</param> /// <returns></returns> public static string GetPlayerFigureId(string playerName, HHotel hotel) { using (var webClientEx = new WebClientEx()) { webClientEx.Proxy = null; webClientEx.Headers["Cookie"] = GetIpCookie(hotel); webClientEx.Headers["User-Agent"] = ChromeAgent; string body = webClientEx.DownloadString(hotel.ToUrl(false) + "/habblet/habbosearchcontent?searchString=" + playerName); return(body.Contains("habbo-imaging/avatar/") ? body.GetChild("habbo-imaging/avatar/", ',') : string.Empty); } }
/// <summary> /// Returns the player motto relative to the specified player name, and hotel. /// </summary> /// <param name="playerName">The name of the player of whom to grab the motto from.</param> /// <param name="hotel">The hotel where the specified player name exists on.</param> /// <returns></returns> public static string GetPlayerMotto(string playerName, HHotel hotel) { using (var webClientEx = new WebClientEx()) { webClientEx.Proxy = null; webClientEx.Headers["Cookie"] = GetIpCookie(hotel); webClientEx.Headers["User-Agent"] = ChromeAgent; string body = webClientEx.DownloadString(hotel.ToUrl(false) + "/habblet/habbosearchcontent?searchString=" + playerName); return(body.IndexOf(playerName, StringComparison.OrdinalIgnoreCase) != -1 ? body.GetChild("<b>" + playerName + "</b><br />", '<') : string.Empty); } }
public HSession(string email, string password, HHotel hotel) { Email = email; Hotel = hotel; Password = password; Triggers = new HTriggers(false); Cookies = new CookieContainer(); _disconnectLock = new object(); _hotelUri = new Uri(Hotel.ToUrl()); }
/// <summary> /// Returns your external Internet Protocol (IP) address that is required to successfully send GET/POST request to the specified <seealso cref="HHotel"/> in an asynchronous operation. /// </summary> /// <param name="hotel">The hotel you wish to retrieve the cookie containing your external Internet Protocol (IP) address from.</param> /// <returns></returns> public static async Task <string> GetIPCookieAsync(HHotel hotel) { if (!string.IsNullOrEmpty(_ipCookie)) { return(_ipCookie); } string body = await _httpClient.GetStringAsync(hotel.ToUrl()); return(_ipCookie = (body.Contains("setCookie")) ? IP_COOKIE_PREFIX + body.GetChilds("setCookie", '\'', false)[3] : string.Empty); }
/// <summary> /// Returns the player avatar relative to the specified player name, and hotel. /// </summary> /// <param name="playerName">The name of the player of whom to grab the avatar from.</param> /// <param name="hotel">The hotel where the specified player name exists on.</param> /// <returns></returns> public static Bitmap GetPlayerAvatar(string playerName, HHotel hotel) { using (var webClientEx = new WebClientEx()) { webClientEx.Proxy = null; webClientEx.Headers["Cookie"] = GetIpCookie(hotel); webClientEx.Headers["User-Agent"] = ChromeAgent; byte[] avatarData = webClientEx.DownloadData(hotel.ToUrl(false) + "/habbo-imaging/avatarimage?user="******"&action=&direction=&head_direction=&gesture=&size="); using (var memoryStream = new MemoryStream(avatarData)) return(new Bitmap(memoryStream)); } }
public HSession(string email, string password, HHotel hotel) { Email = email; Hotel = hotel; Password = password; Requester = new HRequest(); Triggers = new HTriggers(false); _disconnectLock = new object(); _hotelUri = new Uri(Hotel.ToUrl(true)); }
/// <summary> /// Returns a cookie containing your external IP address that is required by most hotels to retrieve a remote resource from their host. /// </summary> /// <returns></returns> public static string GetIpCookie(HHotel hotel) { if (!string.IsNullOrEmpty(_ipCookie)) { return(_ipCookie); } using (var webClientEx = new WebClientEx()) { webClientEx.Proxy = null; webClientEx.Headers["User-Agent"] = ChromeAgent; string body = webClientEx.DownloadString(hotel.ToUrl(false)); return(_ipCookie = (body.Contains(("setCookie")) ? "YPF8827340282Jdskjhfiw_928937459182JAX666=" + body.GetChilds("setCookie", '\'', false)[3] : string.Empty)); } }
/// <summary> /// Returns the user's basic information associated with the given name using the specified <see cref="HHotel"/> in an asynchronous operation. /// </summary> /// <param name="name">The name of the user.</param> /// <param name="hotel">The hotel where the target user is from.</param> public static async Task <HUser> GetUserAsync(string name, HHotel hotel) { string userJson = await _hRequest.DownloadStringAsync( string.Format(USER_API_FORMAT, hotel.ToUrl(true), name)).ConfigureAwait(false); var user = HUser.Create(userJson); if (!_uniqueIds.ContainsKey(hotel)) { _uniqueIds[hotel] = new Dictionary <string, string>(); } _uniqueIds[hotel][user.Name] = user.UniqueId; return(user); }
/// <summary> /// Returns the player's last online date relative to the specified player name, and hotel. /// </summary> /// <param name="playerName">The name of the player of whom to grab the player's last online date from.</param> /// <param name="hotel">The hotel where the specified player name exists on.</param> /// <param name="exact">true to return the time span; otherwise, false for the full date of when the player was last online.</param> /// <returns></returns> public static DateTime GetPlayerLastOnline(string playerName, HHotel hotel) { using (var webClientEx = new WebClientEx()) { webClientEx.Proxy = null; webClientEx.Headers["Cookie"] = GetIpCookie(hotel); webClientEx.Headers["User-Agent"] = ChromeAgent; string body = webClientEx.DownloadString(hotel.ToUrl(false) + "/habblet/habbosearchcontent?searchString=" + playerName); if (!body.Contains("lastlogin")) { return(DateTime.MinValue); } body = body.GetChild("<div class=\"lastlogin\">").GetChild("span title="); return(DateTime.Parse(body.Split('"')[1])); } }
/// <summary> /// Returns the player name relative to the specified player id, and hotel. /// </summary> /// <param name="playerId">The id of the player of whom to grab the name from.</param> /// <param name="hotel">The hotel where the specified player id exists on.</param> /// <returns></returns> public static string GetPlayerName(int playerId, HHotel hotel) { bool hotelColInitialized = _playerNames.ContainsKey(hotel); if (!hotelColInitialized) { _playerNames.Add(hotel, new Dictionary <int, string>()); } else if (_playerNames[hotel].ContainsKey(playerId)) { return(_playerNames[hotel][playerId]); } using (var webClientEx = new WebClientEx()) { webClientEx.Proxy = null; webClientEx.Headers["Cookie"] = GetIpCookie(hotel); webClientEx.Headers["User-Agent"] = ChromeAgent; string body = webClientEx.DownloadString(string.Format("{0}/rd/{1}", hotel.ToUrl(false), playerId)); string value = body.Contains("/home/") ? body.GetChild("<input type=\"hidden\" name=\"page\" value=\"/home/", '?') : string.Empty; if (!string.IsNullOrEmpty(value)) { _playerNames[hotel] = new Dictionary <int, string>() { { playerId, value } }; if (!_playerIds.ContainsKey(hotel)) { _playerIds.Add(hotel, new Dictionary <string, int>()); } if (!_playerIds[hotel].ContainsKey(value)) { _playerIds[hotel].Add(value, playerId); } } return(value); } }
/// <summary> /// Returns the player id relative to the specified player name, and hotel. /// </summary> /// <param name="playerName">The name of the player of whom to grab the id from.</param> /// <param name="hotel">The hotel where the specified player name exists on.</param> /// <returns></returns> public static int GetPlayerId(string playerName, HHotel hotel) { bool hotelColInitialized = _playerIds.ContainsKey(hotel); if (!hotelColInitialized) { _playerIds.Add(hotel, new Dictionary <string, int>()); } else if (_playerIds[hotel].ContainsKey(playerName)) { return(_playerIds[hotel][playerName]); } using (var webClientEx = new WebClientEx()) { webClientEx.Proxy = null; webClientEx.Headers["Cookie"] = GetIpCookie(hotel); webClientEx.Headers["User-Agent"] = ChromeAgent; string body = webClientEx.DownloadString(hotel.ToUrl(false) + "/habblet/ajax/new_habboid?habboIdName=" + playerName); int value = !body.Contains("rounded rounded-red") ? int.Parse(body.GetChild("<em>", '<').Replace(" ", string.Empty)) : -1; if (value != -1) { _playerIds[hotel] = new Dictionary <string, int>() { { playerName, value } }; if (!_playerNames.ContainsKey(hotel)) { _playerNames.Add(hotel, new Dictionary <int, string>()); } if (!_playerNames[hotel].ContainsKey(value)) { _playerNames[hotel].Add(value, playerName); } } return(value); } }
/// <summary> /// Returns the player id relative to the specified player name, and hotel. /// </summary> /// <param name="playerName">The name of the player of whom to grab the id from.</param> /// <param name="hotel">The hotel where the specified player name exists on.</param> /// <returns></returns> public static int GetPlayerId(string playerName, HHotel hotel) { if (_playerIds.ContainsKey(playerName)) { return(_playerIds[playerName][hotel]); } using (var webClientEx = new WebClientEx()) { webClientEx.Proxy = null; webClientEx.Headers["Cookie"] = GetIpCookie(); webClientEx.Headers["User-Agent"] = ChromeAgent; string body = webClientEx.DownloadString(hotel.ToUrl() + "/habblet/ajax/new_habboid?habboIdName=" + playerName); int value = !body.Contains("rounded rounded-red") ? int.Parse(body.GetChild("<em>", '<').Replace(" ", string.Empty)) : -1; _playerIds[playerName] = new Dictionary <HHotel, int>() { { hotel, value } }; return(value); } }
public static string Juice(this HPage page, HHotel hotel) { switch (page) { case HPage.Client: return(hotel.ToUrl() + "/client"); case HPage.Home: return(hotel.ToUrl() + "/home/"); case HPage.IdAvatars: return(hotel.ToUrl() + "/identity/avatars"); case HPage.IdSettings: return(hotel.ToUrl() + "/identity/settings"); case HPage.Me: return(hotel.ToUrl() + "/me"); case HPage.Profile: return(hotel.ToUrl() + "/profile"); default: return(string.Empty); } }
/// <summary> /// Returns the user's basic information associated with the given name using the specified <see cref="HHotel"/> in an asynchronous operation. /// </summary> /// <param name="name">The name of the user.</param> /// <param name="hotel">The hotel where the target user is from.</param> public static async Task <HUser> GetUserAsync(string name, HHotel hotel) { using (var client = new WebClient()) { client.Proxy = null; client.Headers[HttpRequestHeader.UserAgent] = ChromeAgent; client.Headers.Add(HttpRequestHeader.Cookie, "YPF8827340282Jdskjhfiw_928937459182JAX666=127.0.0.1"); string userJson = null; try { userJson = await client.DownloadStringTaskAsync(string.Format(USER_API_FORMAT, hotel.ToUrl(true), name)).ConfigureAwait(false); } catch (WebException ex) { using (WebResponse response = ex.Response) using (var responseReader = new StreamReader(response.GetResponseStream())) { userJson = await responseReader.ReadToEndAsync().ConfigureAwait(false); } } if (userJson.StartsWith("{\"error")) { return(null); } var user = HUser.Create(userJson); if (!_uniqueIds.ContainsKey(hotel)) { _uniqueIds[hotel] = new Dictionary <string, string>(); } _uniqueIds[hotel][user.Name] = user.UniqueId; return(user); } }
/// <summary> /// Returns the user's public profile information associated with the given unique indentifier using the specified <see cref="HHotel"/> in an asynchronous operation. /// </summary> /// <param name="uniqueId">The unique identifier of the user.</param> /// <param name="hotel">The hotel where the target user is from.</param> public static async Task <HProfile> GetProfileByUniqueIdAsync(string uniqueId, HHotel hotel) { using (var client = new WebClient()) { client.Proxy = null; client.Headers[HttpRequestHeader.UserAgent] = ChromeAgent; client.Headers.Add(HttpRequestHeader.Cookie, "YPF8827340282Jdskjhfiw_928937459182JAX666=127.0.0.1"); string profileJson = null; try { profileJson = await client.DownloadStringTaskAsync(string.Format(PROFILE_API_FORMAT, hotel.ToUrl(true), uniqueId)).ConfigureAwait(false); } catch (WebException ex) { using (WebResponse response = ex.Response) using (var responseReader = new StreamReader(response.GetResponseStream())) { profileJson = await responseReader.ReadToEndAsync().ConfigureAwait(false); } } if (profileJson.StartsWith("{\"error")) { return(null); } return(HProfile.Create(profileJson)); } }
/// <summary> /// Returns the player name relative to the specified player id, and hotel. /// </summary> /// <param name="playerId">The id of the player of whom to grab the name from.</param> /// <param name="hotel">The hotel where the specified player id exists on.</param> /// <returns></returns> public static string GetPlayerName(int playerId, HHotel hotel) { if (_playerNames.ContainsKey(playerId)) { return(_playerNames[playerId][hotel]); } using (var webClientEx = new WebClientEx()) { webClientEx.Proxy = null; webClientEx.Headers["Cookie"] = GetIpCookie(); webClientEx.Headers["User-Agent"] = ChromeAgent; string body = webClientEx.DownloadString(string.Format("{0}/rd/{1}", hotel.ToUrl(), playerId)); string value = body.Contains("/home/") ? body.GetChild("<input type=\"hidden\" name=\"page\" value=\"/home/", '?') : string.Empty; _playerNames[playerId] = new Dictionary <HHotel, string>() { { hotel, value } }; return(value); } }