Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO
- Imports System.Net
- Imports System.Text
- Imports System.Text.RegularExpressions
- Public Class SeafightAPI
- 'Declarations:
- Dim username, password, server, host, rtvt, reloadToken, gold, pearls, crystals As String
- Dim sfCookies As New CookieContainer
- 'Major Functions: (login, sendData)
- Public Function login(ByVal usr As String, ByVal pass As String) As Boolean
- username = usr
- password = pass
- Try
- host = "seafight.bigpoint.com"
- Dim homeRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create("http://" & host & "/"), HttpWebRequest)
- homeRequest.Method = "GET"
- homeRequest.CookieContainer = sfCookies
- homeRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"
- Dim homeSource As String = String.Empty
- Using homeReader As New StreamReader(homeRequest.GetResponse().GetResponseStream())
- homeSource = homeReader.ReadToEnd()
- End Using
- Dim loginLink As String = "https://" & Regex.Match(homeSource, "<form name=""bgcdw_login_form"" method=""post"" class=""bgcdw_login_form"" action=""https\:\/\/(.*?)"">").Groups(1).Value.Replace("&", "&")
- If Not (String.IsNullOrEmpty(loginLink) Or loginLink.Equals("https://")) Then
- String.Format("username={0}&password={1}", username, password)
- Dim loginData As String = ""
- Dim loginRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create(loginLink), HttpWebRequest)
- loginRequest.CookieContainer = sfCookies
- loginRequest.Method = "POST"
- loginRequest.KeepAlive = True
- loginRequest.ContentLength = loginData.Length
- loginRequest.ContentType = "application/x-www-form-urlencoded"
- loginRequest.AllowAutoRedirect = True
- loginRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"
- Dim loginEncoding As New UTF8Encoding()
- Dim loginDataBytes As Byte() = loginEncoding.GetBytes(loginData)
- loginRequest.ContentLength = loginDataBytes.Length
- Dim loginStream As Stream = loginRequest.GetRequestStream()
- loginStream.Write(loginDataBytes, 0, loginDataBytes.Length)
- Dim loginResponse As HttpWebResponse = DirectCast(loginRequest.GetResponse(), HttpWebResponse)
- Dim loginDataStream As Stream = loginResponse.GetResponseStream()
- Dim loginReader As New StreamReader(loginDataStream)
- Dim loginSource As String = loginReader.ReadToEnd()
- loginReader.Close()
- loginDataStream.Close()
- loginResponse.Close()
- loginStream.Close()
- If Not (loginSource.Length > 200000) Then
- server = Regex.Match(loginSource, "<link rel=""meta"" href=""http\:\/\/(.*?)\.seafight\.bigpoint\.com\/sharedpages\/icra\/labels\.php""").Groups(1).Value
- Else
- Return False
- End If
- Else
- Return False
- End If
- Return True
- Catch ex As Exception
- Return False
- End Try
- End Function
- Public Function sendData(ByVal dataToSend As String) As Boolean
- Try
- Dim tokenRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create("http://" & server & ".seafight.bigpoint.com/index.es?action=internalHome"), HttpWebRequest)
- tokenRequest.CookieContainer = sfCookies
- tokenRequest.Method = "GET"
- tokenRequest.KeepAlive = True
- tokenRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"
- Dim homeSource As String = String.Empty
- Using homeReader As New StreamReader(tokenRequest.GetResponse().GetResponseStream())
- homeSource = homeReader.ReadToEnd()
- End Using
- reloadToken = Regex.Match(homeSource, "(?<=reloadToken"" value="")(.*)(?="" />)").Groups(1).Value
- rtvt = Regex.Match(homeSource, "(?:RTVT.+value=')(?<RTVT>[^']+)").Groups("RTVT").Value
- Dim sendDatas As String = dataToSend
- Dim sendRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create("http://" & server & ".seafight.bigpoint.com/ajax.es"), HttpWebRequest)
- sendRequest.CookieContainer = sfCookies
- sendRequest.Method = "POST"
- sendRequest.KeepAlive = True
- sendRequest.ContentLength = sendDatas.Length
- sendRequest.ContentType = "application/x-www-form-urlencoded"
- sendRequest.AllowAutoRedirect = True
- sendRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"
- sendRequest.Referer = "http://" & server & ".seafight.bigpoint.com/index.es?action=internalMarketplace&subact=Elite"
- Dim sendEncoding As New UTF8Encoding()
- Dim sendDataBytes As Byte() = sendEncoding.GetBytes(sendDatas)
- sendRequest.ContentLength = sendDataBytes.Length
- Dim sendStream As Stream = sendRequest.GetRequestStream()
- sendStream.Write(sendDataBytes, 0, sendDataBytes.Length)
- sendRequest.Abort()
- sendStream.Dispose()
- sendStream.Close()
- Return True
- Catch ex As Exception
- Return False
- End Try
- End Function
- 'Getters :
- Public Function getUsername() As String
- Return username
- End Function
- Public Function getPassword() As String
- Return password
- End Function
- Public Function getServer() As String
- Return server
- End Function
- Public Function getValutas() As String
- Dim valutaRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create("http://" & server & ".seafight.bigpoint.com/index.es?action=internalHome"), HttpWebRequest)
- valutaRequest.CookieContainer = sfCookies
- valutaRequest.Method = "GET"
- valutaRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"
- Dim homeSource As String = String.Empty
- Using homeReader As New StreamReader(valutaRequest.GetResponse().GetResponseStream())
- homeSource = homeReader.ReadToEnd()
- End Using
- gold = Regex.Match(homeSource, "<span id=""displayGold"">(.*?)</span>").Groups(1).Value
- pearls = Regex.Match(homeSource, "<span id=""displayPearl"">(.*?)</span>").Groups(1).Value
- crystals = Regex.Match(homeSource, "<span id=""displayCrystal"">(.*?)</span>").Groups(1).Value
- If (String.IsNullOrEmpty(gold) Or String.IsNullOrEmpty(pearls) Or String.IsNullOrEmpty(crystals)) Then
- Return "N/A|N/A|N/A"
- End If
- 'Return example: 20'690|1'001'672|6'230
- 'First is gold, second is pearls, third is crystals
- Return String.Format("{0}|{1}|{2}", gold, pearls, crystals)
- End Function
- Public Function getGold() As String
- Dim goldRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create("http://" & server & ".seafight.bigpoint.com/index.es?action=internalHome"), HttpWebRequest)
- goldRequest.CookieContainer = sfCookies
- goldRequest.Method = "GET"
- goldRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"
- Dim homeSource As String = String.Empty
- Using homeReader As New StreamReader(goldRequest.GetResponse().GetResponseStream())
- homeSource = homeReader.ReadToEnd()
- End Using
- gold = Regex.Match(homeSource, "<span id=""displayGold"">(.*?)</span>").Groups(1).Value
- If Not (String.IsNullOrEmpty(gold)) Then
- Return gold
- Else
- Return "Gold not found"
- End If
- End Function
- Public Function getPearls() As String
- Dim pearlRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create("http://" & server & ".seafight.bigpoint.com/index.es?action=internalHome"), HttpWebRequest)
- pearlRequest.CookieContainer = sfCookies
- pearlRequest.Method = "GET"
- pearlRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"
- Dim homeSource As String = String.Empty
- Using homeReader As New StreamReader(pearlRequest.GetResponse().GetResponseStream())
- homeSource = homeReader.ReadToEnd()
- End Using
- pearls = Regex.Match(homeSource, "<span id=""displayPearl"">(.*?)</span>").Groups(1).Value
- If Not (String.IsNullOrEmpty(pearls)) Then
- Return pearls
- Else
- Return "Pearls not found"
- End If
- End Function
- Public Function getCrystals() As String
- Dim crystalRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create("http://" & server & ".seafight.bigpoint.com/index.es?action=internalHome"), HttpWebRequest)
- crystalRequest.CookieContainer = sfCookies
- crystalRequest.Method = "GET"
- crystalRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"
- Dim homeSource As String = String.Empty
- Using homeReader As New StreamReader(crystalRequest.GetResponse().GetResponseStream())
- homeSource = homeReader.ReadToEnd()
- End Using
- crystals = Regex.Match(homeSource, "<span id=""displayCrystal"">(.*?)</span>").Groups(1).Value
- If Not (String.IsNullOrEmpty(crystals)) Then
- Return crystals
- Else
- Return "Crystals not found"
- End If
- End Function
- End Class
Add Comment
Please, Sign In to add comment