Punkbastard

SeafightAPI - VB.NET

Nov 15th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 9.72 KB | None | 0 0
  1. Imports System.IO
  2. Imports System.Net
  3. Imports System.Text
  4. Imports System.Text.RegularExpressions
  5.  
  6. Public Class SeafightAPI
  7.  
  8.     'Declarations:
  9.     Dim username, password, server, host, rtvt, reloadToken, gold, pearls, crystals As String
  10.     Dim sfCookies As New CookieContainer
  11.  
  12.     'Major Functions: (login, sendData)
  13.     Public Function login(ByVal usr As String, ByVal pass As String) As Boolean
  14.  
  15.         username = usr
  16.         password = pass
  17.        
  18.         Try
  19.             host = "seafight.bigpoint.com"
  20.             Dim homeRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create("http://" & host & "/"), HttpWebRequest)
  21.             homeRequest.Method = "GET"
  22.             homeRequest.CookieContainer = sfCookies
  23.             homeRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"
  24.  
  25.             Dim homeSource As String = String.Empty
  26.             Using homeReader As New StreamReader(homeRequest.GetResponse().GetResponseStream())
  27.                 homeSource = homeReader.ReadToEnd()
  28.             End Using
  29.             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("&amp;", "&")
  30.  
  31.             If Not (String.IsNullOrEmpty(loginLink) Or loginLink.Equals("https://")) Then
  32.                 String.Format("username={0}&password={1}", username, password)
  33.                 Dim loginData As String = ""
  34.                 Dim loginRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create(loginLink), HttpWebRequest)
  35.                 loginRequest.CookieContainer = sfCookies
  36.                 loginRequest.Method = "POST"
  37.                 loginRequest.KeepAlive = True
  38.                 loginRequest.ContentLength = loginData.Length
  39.                 loginRequest.ContentType = "application/x-www-form-urlencoded"
  40.                 loginRequest.AllowAutoRedirect = True
  41.                 loginRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"
  42.  
  43.                 Dim loginEncoding As New UTF8Encoding()
  44.                 Dim loginDataBytes As Byte() = loginEncoding.GetBytes(loginData)
  45.                 loginRequest.ContentLength = loginDataBytes.Length
  46.                 Dim loginStream As Stream = loginRequest.GetRequestStream()
  47.                 loginStream.Write(loginDataBytes, 0, loginDataBytes.Length)
  48.  
  49.                 Dim loginResponse As HttpWebResponse = DirectCast(loginRequest.GetResponse(), HttpWebResponse)
  50.                 Dim loginDataStream As Stream = loginResponse.GetResponseStream()
  51.                 Dim loginReader As New StreamReader(loginDataStream)
  52.  
  53.                 Dim loginSource As String = loginReader.ReadToEnd()
  54.  
  55.                 loginReader.Close()
  56.                 loginDataStream.Close()
  57.                 loginResponse.Close()
  58.                 loginStream.Close()
  59.  
  60.                 If Not (loginSource.Length > 200000) Then
  61.                     server = Regex.Match(loginSource, "<link rel=""meta"" href=""http\:\/\/(.*?)\.seafight\.bigpoint\.com\/sharedpages\/icra\/labels\.php""").Groups(1).Value
  62.                 Else
  63.                     Return False
  64.                 End If
  65.             Else
  66.                 Return False
  67.             End If
  68.  
  69.             Return True
  70.  
  71.         Catch ex As Exception
  72.             Return False
  73.         End Try
  74.  
  75.     End Function
  76.  
  77.     Public Function sendData(ByVal dataToSend As String) As Boolean
  78.         Try
  79.             Dim tokenRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create("http://" & server & ".seafight.bigpoint.com/index.es?action=internalHome"), HttpWebRequest)
  80.             tokenRequest.CookieContainer = sfCookies
  81.             tokenRequest.Method = "GET"
  82.             tokenRequest.KeepAlive = True
  83.             tokenRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"
  84.  
  85.             Dim homeSource As String = String.Empty
  86.             Using homeReader As New StreamReader(tokenRequest.GetResponse().GetResponseStream())
  87.                 homeSource = homeReader.ReadToEnd()
  88.             End Using
  89.             reloadToken = Regex.Match(homeSource, "(?<=reloadToken"" value="")(.*)(?="" />)").Groups(1).Value
  90.             rtvt = Regex.Match(homeSource, "(?:RTVT.+value=')(?<RTVT>[^']+)").Groups("RTVT").Value
  91.  
  92.             Dim sendDatas As String = dataToSend
  93.             Dim sendRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create("http://" & server & ".seafight.bigpoint.com/ajax.es"), HttpWebRequest)
  94.             sendRequest.CookieContainer = sfCookies
  95.             sendRequest.Method = "POST"
  96.             sendRequest.KeepAlive = True
  97.             sendRequest.ContentLength = sendDatas.Length
  98.             sendRequest.ContentType = "application/x-www-form-urlencoded"
  99.             sendRequest.AllowAutoRedirect = True
  100.             sendRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"
  101.             sendRequest.Referer = "http://" & server & ".seafight.bigpoint.com/index.es?action=internalMarketplace&subact=Elite"
  102.  
  103.             Dim sendEncoding As New UTF8Encoding()
  104.             Dim sendDataBytes As Byte() = sendEncoding.GetBytes(sendDatas)
  105.             sendRequest.ContentLength = sendDataBytes.Length
  106.             Dim sendStream As Stream = sendRequest.GetRequestStream()
  107.             sendStream.Write(sendDataBytes, 0, sendDataBytes.Length)
  108.  
  109.             sendRequest.Abort()
  110.             sendStream.Dispose()
  111.             sendStream.Close()
  112.  
  113.             Return True
  114.         Catch ex As Exception
  115.             Return False
  116.         End Try
  117.     End Function
  118.  
  119.     'Getters :
  120.     Public Function getUsername() As String
  121.         Return username
  122.     End Function
  123.  
  124.     Public Function getPassword() As String
  125.         Return password
  126.     End Function
  127.  
  128.     Public Function getServer() As String
  129.         Return server
  130.     End Function
  131.  
  132.     Public Function getValutas() As String
  133.         Dim valutaRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create("http://" & server & ".seafight.bigpoint.com/index.es?action=internalHome"), HttpWebRequest)
  134.         valutaRequest.CookieContainer = sfCookies
  135.         valutaRequest.Method = "GET"
  136.         valutaRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"
  137.  
  138.         Dim homeSource As String = String.Empty
  139.         Using homeReader As New StreamReader(valutaRequest.GetResponse().GetResponseStream())
  140.             homeSource = homeReader.ReadToEnd()
  141.         End Using
  142.  
  143.         gold = Regex.Match(homeSource, "<span id=""displayGold"">(.*?)</span>").Groups(1).Value
  144.         pearls = Regex.Match(homeSource, "<span id=""displayPearl"">(.*?)</span>").Groups(1).Value
  145.         crystals = Regex.Match(homeSource, "<span id=""displayCrystal"">(.*?)</span>").Groups(1).Value
  146.  
  147.         If (String.IsNullOrEmpty(gold) Or String.IsNullOrEmpty(pearls) Or String.IsNullOrEmpty(crystals)) Then
  148.             Return "N/A|N/A|N/A"
  149.         End If
  150.         'Return example: 20'690|1'001'672|6'230
  151.         'First is gold, second is pearls, third is crystals
  152.         Return String.Format("{0}|{1}|{2}", gold, pearls, crystals)
  153.     End Function
  154.  
  155.     Public Function getGold() As String
  156.         Dim goldRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create("http://" & server & ".seafight.bigpoint.com/index.es?action=internalHome"), HttpWebRequest)
  157.         goldRequest.CookieContainer = sfCookies
  158.         goldRequest.Method = "GET"
  159.         goldRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"
  160.  
  161.         Dim homeSource As String = String.Empty
  162.         Using homeReader As New StreamReader(goldRequest.GetResponse().GetResponseStream())
  163.             homeSource = homeReader.ReadToEnd()
  164.         End Using
  165.         gold = Regex.Match(homeSource, "<span id=""displayGold"">(.*?)</span>").Groups(1).Value
  166.         If Not (String.IsNullOrEmpty(gold)) Then
  167.             Return gold
  168.         Else
  169.             Return "Gold not found"
  170.         End If
  171.     End Function
  172.  
  173.     Public Function getPearls() As String
  174.         Dim pearlRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create("http://" & server & ".seafight.bigpoint.com/index.es?action=internalHome"), HttpWebRequest)
  175.         pearlRequest.CookieContainer = sfCookies
  176.         pearlRequest.Method = "GET"
  177.         pearlRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"
  178.  
  179.         Dim homeSource As String = String.Empty
  180.         Using homeReader As New StreamReader(pearlRequest.GetResponse().GetResponseStream())
  181.             homeSource = homeReader.ReadToEnd()
  182.         End Using
  183.         pearls = Regex.Match(homeSource, "<span id=""displayPearl"">(.*?)</span>").Groups(1).Value
  184.         If Not (String.IsNullOrEmpty(pearls)) Then
  185.             Return pearls
  186.         Else
  187.             Return "Pearls not found"
  188.         End If
  189.     End Function
  190.  
  191.     Public Function getCrystals() As String
  192.         Dim crystalRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create("http://" & server & ".seafight.bigpoint.com/index.es?action=internalHome"), HttpWebRequest)
  193.         crystalRequest.CookieContainer = sfCookies
  194.         crystalRequest.Method = "GET"
  195.         crystalRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"
  196.  
  197.         Dim homeSource As String = String.Empty
  198.         Using homeReader As New StreamReader(crystalRequest.GetResponse().GetResponseStream())
  199.             homeSource = homeReader.ReadToEnd()
  200.         End Using
  201.         crystals = Regex.Match(homeSource, "<span id=""displayCrystal"">(.*?)</span>").Groups(1).Value
  202.         If Not (String.IsNullOrEmpty(crystals)) Then
  203.             Return crystals
  204.         Else
  205.             Return "Crystals not found"
  206.         End If
  207.     End Function
  208.  
  209. End Class
Add Comment
Please, Sign In to add comment