[AutoIt, Help] parse/login problem

04/06/2011 19:31 D3adlySil3nc3#1
Hey
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 
Methods:
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($sCookies8)
        
$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(10"")
    
$iSocket TCPConnect($sIp80)
    If @
error Then Return SetError(20"")
    
TCPSend($iSocket$sPacket)
    If @
error Then Return SetError(30"")
    
$iTimer TimerInit()
    Do
        
$sRecv TCPRecv($iSocket1024)
        If 
TimerDiff($iTimer) > $iMaxTime Then Return SetError(40"")
    
Until $sRecv <> ""
    
Do
        
$sRecv &= TCPRecv($iSocket1024)
    
Until @error Or StringInStr($sRecv'</html>')
    
TCPCloseSocket($iSocket)
    
TCPShutdown()
    Return 
$sRecv
EndFunc   
;==>TCPRequest 
At First I am getting this:

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)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
And the Programm exits when I am pressing the Login Button.

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.
The Line is the MSGBox in the getSession-Method.
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?
04/07/2011 20:21 derpo#2
Zum ersten Fehler : Überprüfe mal, ob du TCPRequest mit genügend Parametern aufrufst.
Zum zweiten Fehler : Nenn mir mal den Wert von @error nach dem Aufrufen von StringBetween
04/07/2011 21:54 D3adlySil3nc3#3
Also, beim Ersten kann ich bestätigen, das uni, post und ip von den Methoden zurückgeliefert werden.
Dabei muss ich anmerken, dass das gleiche Script läuft wenn ich die ganzen Getter weg schmeiße.

Und ich kann es eingenzen auf vor die login() Funktion.
Wenn ich dort eine msg ausgeben möchte gehts nicht.


Code:
!>21:30:51 AU3Check ended.rc:2
>Running:(3.3.6.1):C:autoit3_x64.exe "D:\AutoIt Scripts\ogameBot0.1.au3"    
D:\AutoIt Scripts\ogameBot0.1.au3 (195) : ==> Subscript used with non-Array variable.:
MsgBox("", "", "getsession" & $session[0])
MsgBox("", "", "getsession" & $session^ ERROR
->21:30:57 AutoIT3.exe ended.rc:1
Hmm error-handling hab ich micht nicht wirklich beschäftigt...

jedenfalls wenn ich schreibe @error=1 gibt er mir die MsgBox zw. der if-bedingung aus bei 2,3,4 usw nicht.
Und das Helpfile sagt mir jetzt auch net viel.
04/11/2011 16:04 D3adlySil3nc3#4
Hmm hat den keiner eine Ahnung wo ungefähr mein Fehler liegen könnte?
Langsam wirds frustrierend immer wieder Funktionen umzuschreiben und am Ende das gleiche Ergebnis zu erhalten.

Ich glaube, dass ich am Besten nochmal alles in einer Wurst runterschreibe.
04/11/2011 16:28 V8II#5
Quote:
Und ich kann es eingenzen auf vor die login() Funktion.
Wenn ich dort eine msg ausgeben möchte gehts nicht.
Weil die Variable vermutlich in der login-Funktion definiert wird.
04/11/2011 17:47 derpo#6
Quote:
Originally Posted by D3adlySil3nc3 View Post
jedenfalls wenn ich schreibe @error=1 gibt er mir die MsgBox zw. der if-bedingung aus bei 2,3,4 usw nicht.
Und das Helpfile sagt mir jetzt auch net viel.
@error wird automatisch gesetzt. Zum Beispiel :
PHP Code:
#include <String.au3>
StringBetween("blabla","1","2")
MsgBox(0,"Test","@error hat den Wert " & @error