I´m playing around with AutoIt since a few Weeks, now I wanted to try to make a Bot for Ogame(yeah a another one...)
Well as the Theme says I have a few Prolems, which I couldn´t eliminate with Google and the Helpfile.
So hoping that someone of you can help me.
PHP Code:
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $loginButton
Global $name = GUICtrlRead($userField)
Global $pass = GUICtrlRead($passField)
Global $uni = GUICtrlRead($uniField)
Global $ip = getIP()
Global $post = getPost()
$html = TCPRequest($ip, "uni" & $uni & ".ogame.de", 0, "/game/reg/login2.php", $post, "", 'http://ogame.de/')
Global $cookies = GetCookies($html)
Global $session = getSession($html)
saveConfig()
login()
MsgBox("", "", "kein fehla")
listBuildings()
GUICtrlSetData($loginButton, "Logout")
; $html = FileOpen("html.txt")
GUISetState(@SW_SHOW, $mainForm)
GUIDelete($accountForm)
main()
EndSwitch
;If $loginButton And (GUICtrlRead($loginButton) = "Logout") Then
; logOut()
;EndIf
WEnd
Func main()
GUICtrlSetData($metalLabel, "Metal: " & getMetal())
GUICtrlSetData($crystalLabel, "Crystal: " &getCrystal())
GUICtrlSetData($deutLabel, "Deuterium: " & getDeut())
GUICtrlSetData($energyLabel, "Energy: " & getEnergy())
$Msg = GUIGetMsg()
While 1
Switch $Msg
Case $GUI_EVENT_CLOSE
Exit
Case $MenuItem3
GUISetState(@SW_SHOW,$accountForm)
EndSwitch
Sleep(300)
WEnd
EndFunc ;==>main
PHP Code:
Func GetCookies($html)
$sCookies = ''
$aCookies = _StringBetween($html, 'Set-Cookie: ', ';', 1)
For $i = 0 To UBound($aCookies) - 1
$sCookies &= $aCookies[$i] & ';'
Next
Return $sCookies
EndFunc ;==>GetCookies
Func TCPRequest($sIp, $sHost, $Msg = 0, $sSeite = "", $sPost = '', $sCookies = '', $sReferer = '', $iMaxTime = 10000)
Local $sPacket, $iSocket, $iTimer
If $sPost = '' Then
$sPacket = 'GET /' & $sSeite & ' HTTP/1.1' & @CRLF
Else
$sPacket = 'POST /' & $sSeite & ' HTTP/1.1' & @CRLF
EndIf
$sPacket &= 'Host: ' & $sHost & @CRLF & _
'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)' & @CRLF & _
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' & @CRLF & _
'Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3' & @CRLF & _
'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7' & @CRLF & _
'Keep-Alive: 300' & @CRLF & _
'Content-Type: application/x-www-form-urlencoded' & @CRLF & _
'Connection: keep-alive' & @CRLF
If $sReferer <> '' Then
$sPacket &= 'Referer: ' & $sReferer & @CRLF
EndIf
If $sCookies <> '' Then
$sCookies = StringStripCR($sCookies)
$sCookies = StringStripWS($sCookies, 8)
$sPacket &= 'Cookie: ' & $sCookies & @CRLF
EndIf
If $sPost <> '' Then
$sPacket &= 'Content-Length: ' & StringLen($sPost) & @CRLF
EndIf
$sPacket &= @CRLF
If $sPost <> '' Then
$sPacket &= $sPost
EndIf
If $Msg = 1 Then
MsgBox(0, "Packet", $sPacket)
EndIf
TCPStartup()
If @error Then Return SetError(1, 0, "")
$iSocket = TCPConnect($sIp, 80)
If @error Then Return SetError(2, 0, "")
TCPSend($iSocket, $sPacket)
If @error Then Return SetError(3, 0, "")
$iTimer = TimerInit()
Do
$sRecv = TCPRecv($iSocket, 1024)
If TimerDiff($iTimer) > $iMaxTime Then Return SetError(4, 0, "")
Until $sRecv <> ""
Do
$sRecv &= TCPRecv($iSocket, 1024)
Until @error Or StringInStr($sRecv, '</html>')
TCPCloseSocket($iSocket)
TCPShutdown()
Return $sRecv
EndFunc ;==>TCPRequest
Code:
D:\AutoIt Scripts\ogameBot0.1.au3(233,118) : ERROR: TCPRequest() called by a previous line with 1 arg(s). Min = 2. First previous line calling this Func is 65. Func TCPRequest($sIp, $sHost, $Msg = 0, $sSeite = "", $sPost = '', $sCookies = '', $sReferer = '', $iMaxTime = 10000) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
Erm, I modified the Code a little bit, before that I was able to comte to the Main Function and in the Labels the Metal was setted up.
But, I got the whole time a 0 from the getMetal function.
Then I modified the Code in getSession() and now there is an error thrown, but only in the Console.
Code:
Subscript used with non-Array variable.
But I know that StringBetween is deliviering a Array.
And why isn´t the window closing when I pressing the X-Button on the Main Frome? The Code should be correct.
It´s the same thing with the AccountForm, when I press on the MainFrame on the Taskbar to the MenuItem nothing happens.
And yes, the Variables are correct.
Ähh soll ich jetzt noch mal alles auf deutsch schreiben?






