TCP Stream wird immer von BB geshlossen nach Lese operation

Übersicht BlitzBasic Allgemein

Neue Antwort erstellen

Xaymar

ehemals "Cgamer"

Betreff: TCP Stream wird immer von BB geshlossen nach Lese operation

BeitragFr, März 13, 2009 22:03
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich weiß nicht direkt wieso bb das macht aber der Server hält die verbindung noch offen. Das sehe ich am debug modus des servers:
MySQL 5.1.32 hat Folgendes geschrieben:
Connection closed by Client.

Weiß jemand was da schief läuft in BB

Code: [AUSKLAPPEN]
;MySQL Script Executor
;Create Custom Scripts that are executed in MySQL

Dir$ = CurrentDir()

ExtractPak("RuntimeFiles", GetEnv("Temp"))

ChangeDir Dir$



MainWindow = CreateWindow("MySQL ScriptE", GadgetWidth(Desktop())/2-400, GadgetHeight(Desktop())/2-330, 800, 600, Desktop(), 1+8+32)
TitleImgPa = CreatePanel(0, 0, 800, 100, MainWindow):SetPanelImage TitleImgPa, GetEnv("Temp")+"/RuntimeFiles/Title.png"

;Login Panel
UserField = CreateTextField(600, 0,200,20, TitleImgPa)
PassField = CreateTextField(600,20,200,20, TitleImgPa, 1)
HostField = CreateTextField(600,40,200,20, TitleImgPa)
PortField = CreateTextField(700,60, 90,20, TitleImgPa)
PortFieldS = CreateSlider(790,60,10,20, TitleImgPa, 2):SetSliderRange PortFieldS, 1, 100:SetSliderValue PortFieldS, 50
ConnectB = CreateButton("Connect",600,80,100,20,TitleImgPa, 4)
DisconnB = CreateButton("Disconnect",700,80,100,20,TitleImgPa, 5)
HelpP = CreatePanel(400, 0, 200, 100, TitleImgPa):SetPanelImage HelpP, GetEnv("Temp")+"/RuntimeFiles/Help.png":HideGadget HelpP
HelpB = CreateButton("Help", 600, 60, 100, 20, TitleImgPa)

;Console
Global Console
Console = CreateListBox(0, 100, 600, 500, MainWindow, 0)

;Ping timer
Global RespTimer
PingTimer = CreateTimer(.02)
LogTimer = CreateTimer(.1)
RespTimer = CreateTimer(10)

Port = 3306
SetGadgetText PortField, Port

;Variables
HelpState = 0

;Log Files
Global ConLog = CreateLog("Connect.txt")
Global QueryLog = CreateLog("Query.txt")
Global RespLog = CreateLog("Response.txt")
Global DebgLog = CreateLog("Debuglog.txt")

;MySQL globals
Global Connected, TCPS
Global MySQLV$, Flags, Charset, Status, ErrorCode, ErrorMsg$

Repeat
   Event = WaitEvent()
   If TCPS <> 0
      If ReadAvail(TCPS) > 0
         DebugLog ReadAvail(TCPS) + "|" + ReadByte(TCPS)
      EndIf
   EndIf
   Select Event
      Case $201
         DebugLog EventData()
         Select EventSource()
            Case UserField
               If TextFieldText = "Username" SetGadgetText UserField, ""
            Case PassField
               If TextFieldText = "Password" SetGadgetText PassField, ""
            Case HostField
               If TextFieldText = "Hostaddress" SetGadgetText HostField, ""
         End Select
      Case $401
         Select EventSource()
            Case PortFieldS
               Value = (100-SliderValue(PortFieldS))-50
               Port = Port + Value
               SetSliderValue PortFieldS, 50
            Case PortField
               Port = TextFieldText(PortField)
            Case ConnectB
               If Connected = 1
                  MySQL_Disconnect()
               EndIf
               PeekEvent()
               Result = MySQL_Connect(TextFieldText(HostField), TextFieldText(UserField), TextFieldText(PassField), TextFieldText(PortField))
            Case DisconnB
               If Connected = 1
                  MySQL_Disconnect()
               Else
                  AddGadgetItem Console, "[" + CurrentTime() + "]--Cant disconnect if not connected.", 1
               EndIf
            Case HelpB
               HelpState = 1 - HelpState
               If HelpState = 0
                  HideGadget HelpP
               Else
                  ShowGadget HelpP
               EndIf
         End Select
      Case $803
         MySQL_Disconnect()
         CloseLog(ConLog)
         CloseLog(QueryLog)
         CloseLog(RespLog)
         End
      Case $4001
         Select EventSource()
            Case LogTimer
               ConLog = SaveLog(ConLog, "Connect.txt")
               QueryLog = SaveLog(QueryLog, "Query.txt")
               RespLog = SaveLog(RespLog, "Response.txt")
               DebgLog = SaveLog(DebgLog, "Debuglog.txt")
            Case RespTimer
               If TCPS <> 0
                  If Eof(TCPS) > 0
                     MySQl_Response()
                  ElseIf Eof(TCPS) = -1
                     MySQL_Disconnect()
                  EndIf
               EndIf
            Case PingTimer
               MySQL_Query(14, "PING")
               AddLogLine(DebgLog, TCPS + " " + Connected)
         End Select
   End Select
   
   SetGadgetText PortField, Port
Forever



























;MySQL related
Function HASH________________HASH()
End Function

Function XOR_String$(Strng$, Salt$)
   For A = 1 To Len(Strng$)
      Bit = Asc(Mid(Strng$, A, 1))
      SaltBit = Asc(Mid(Salt$, 1+(A Mod Len(Salt$)-1), 1))
      Bit = Bit Xor SaltBit
      Out$ = Out$ + Chr(Bit)
   Next
   Return Out$
End Function

Global sha1_low
Global sha1_high
Global sha1_index
Global sha1_hash[4]
Global sha1_message[63]

;---------------------------------------------------------------------
;txt:    text string
;RETURN: sha1-fingerprint (20 byte)
;---------------------------------------------------------------------
Function sha1$(txt$)
  Local ascii
  Local i
  Local length

  sha1_reset()
  length=Len(txt$)

  For i=1 To length
    ascii=Asc(Mid$(txt$,i,1))
    sha1_message[sha1_index]=ascii
    sha1_index=sha1_index+1

    sha1_low=sha1_low+8
    If sha1_low=0 Then
      sha1_high=sha1_high+1
      If sha1_high=0 Then Return
    EndIf

    If sha1_index=64 Then sha1_process()
  Next

  Return sha1_result$()
End Function
;---------------------------------------------------------------------
Function sha1_pad()
  If sha1_index>55 Then

    sha1_message[sha1_index]=$80
    sha1_index=sha1_index+1

    While sha1_index<64
      sha1_message[sha1_index]=0
      sha1_index=sha1_index+1
    Wend

    sha1_process()

    While sha1_index<56
      sha1_message[sha1_index]=0
      sha1_index=sha1_index+1
    Wend

  Else

    sha1_message[sha1_index]=$80
    sha1_index=sha1_index+1

    While sha1_index<56
      sha1_message[sha1_index]=0
      sha1_index=sha1_index+1
    Wend

  EndIf

  sha1_message[56]=sha1_high Shr 24
  sha1_message[57]=sha1_high Shr 16
  sha1_message[58]=sha1_high Shr 8
  sha1_message[59]=sha1_high
  sha1_message[60]=sha1_low Shr 24
  sha1_message[61]=sha1_low Shr 16
  sha1_message[62]=sha1_low Shr 8
  sha1_message[63]=sha1_low

  sha1_process()
End Function
;---------------------------------------------------------------------
Function sha1_process()
  Local a
  Local b
  Local c
  Local d
  Local e
  Local k[3]
  Local t
  Local temp
  Local w[79]

  k[0]=$5A827999
  k[1]=$6ED9EBA1
  k[2]=$8F1BBCDC
  k[3]=$CA62C1D6

  For t=0 To 15
    w[t]=sha1_message[t*4] Shl 24
    w[t]=w[t] Or sha1_message[t*4+1] Shl 16
    w[t]=w[t] Or sha1_message[t*4+2] Shl 8
    w[t]=w[t] Or sha1_message[t*4+3]
  Next

  For t=16 To 79
    w[t]=sha1_rotateleft(w[t-3] Xor w[t-8] Xor w[t-14] Xor w[t-16],1)
  Next

  a=sha1_hash[0]
  b=sha1_hash[1]
  c=sha1_hash[2]
  d=sha1_hash[3]
  e=sha1_hash[4]

  For t=0 To 19
    temp=sha1_rotateleft(A,5) + ((B And C) Or ((~B) And D)) + E + W[t] + K[0]
    e=d
    d=c
    c=sha1_rotateleft(B,30)
    b=a
    a=temp
  Next

  For t=20 To 39
    temp=sha1_rotateleft(A,5) + (B Xor C Xor D) + E + W[t] + K[1]
    e=d
    d=c
    c=sha1_rotateleft(B,30)
    b=a
    a=temp
  Next

  For t=40 To 59
    temp=sha1_rotateleft(A,5) + ((B And C) Or (B And D) Or (C And D)) + E + W[t] + K[2]
    e=d
    d=c
    c=sha1_rotateleft(B,30)
    b=a
    a=temp
  Next

  For t=60 To 79
    temp=sha1_rotateleft(A,5) + (B Xor C Xor D) + E + W[t] + K[3]
    e=d
    d=c
    c=sha1_rotateleft(B,30)
    b=a
    a=temp
  Next

  sha1_hash[0]=sha1_hash[0]+a
  sha1_hash[1]=sha1_hash[1]+b
  sha1_hash[2]=sha1_hash[2]+c
  sha1_hash[3]=sha1_hash[3]+d
  sha1_hash[4]=sha1_hash[4]+e

  sha1_index=0
End Function
;---------------------------------------------------------------------
Function sha1_reset()
  Local i

  sha1_low=0
  sha1_high=0
  sha1_index=0

  sha1_hash[0]=$67452301
  sha1_hash[1]=$EFCDAB89
  sha1_hash[2]=$98BADCFE
  sha1_hash[3]=$10325476
  sha1_hash[4]=$C3D2E1F0

  For i=0 To 63
    sha1_message[i]=0
  Next
End Function

;---------------------------------------------------------------------
;RETURN: sha1-fingerprint
;---------------------------------------------------------------------
Function sha1_result$()
  Local byte
  Local i
  Local txt$

  sha1_pad()

  For i=0 To 19
    byte=sha1_hash[i Shr 2] Shr 8 * (3-(i And 3))
    txt$=txt$+Chr$(byte)
  Next

  Return txt$
End Function

;---------------------------------------------------------------------
;value:  integer value
;shift:  bit shift
;RETURN: shifted value
;---------------------------------------------------------------------
Function sha1_rotateleft(value,shift)
  Return ((value Shl shift) Or (value Shr (32-shift)))
End Function

Function NETWORK________NETWORK()
End Function
Function ReadStringNew$(Stream)
   If WaitOnData(Stream, 2500) = 1
      While Not Eof(TCPS)
         Byte = ReadByte(Stream)
         If Byte > 0
            Out$ = Out$ + Chr(Byte)
         Else
            Return Out$
         EndIf
      Wend
      Return ""
   EndIf
   Return ""
End Function

Function ReadInt32New(Stream)
   If WaitOnData(Stream, 2500) = 1
      Byte1 = ReadByte(Stream)
      Byte2 = ReadByte(Stream)
      Byte3 = ReadByte(Stream)
      Byte4 = ReadByte(Stream)
      Integ = (Byte4 Shr 24) Or (Byte3 Shr 16) Or (Byte2 Or 8) Or Byte1
      Return Integ
   EndIf
   Return 0
End Function

Function ReadInt24New(Stream)
   If WaitOnData(Stream, 2500) = 1
      Byte1 = ReadByte(Stream)
      Byte2 = ReadByte(Stream)
      Byte3 = ReadByte(Stream)
      Integ = (Byte3 Shr 16) Or (Byte2 Shr 8) Or Byte1
      Return Integ
   EndIf
   Return 0
End Function

Function ReadShortNew(Stream)
   If WaitOnData(Stream, 2500) = 1
      Byte1 = ReadByte(Stream)
      Byte2 = ReadByte(Stream)
      Short = (Byte2 Shr 8) Or Byte1
      Return Short
   EndIf
   Return 0
End Function

Function WaitOnData(Stream, TimeOut=1000)
   MSec = MilliSecs()
   While Eof(Stream)
      If MilliSecs()-MSec
         Return 0
      EndIf
      WaitTimer RespTimer
   Wend
   Return 1
End Function

Function WriteData(Stream, Dat$)
   For A = 1 To Len(Dat$)
      WriteByte Stream, Asc(Mid(Dat$, A, 1))
   Next
   Return 1
End Function

Function AddString$(Dat$, Txt$)
   Dat$ = Dat$ + Txt$ + Chr(0)
   Return Dat$
End Function

Function AddString2$(Dat$, Txt$)
   Dat$ = Dat$ + Txt$
   Return Dat$
End Function

Function AddInt$(Dat$, I)
   Byte1 = Int32 And $FF
   Byte2 = ((Int32 And $FF00) Shl 8)
   Byte3 = ((Int32 And $FF0000) Shl 16)
   Byte4 = ((Int32 And $FF000000) Shl 24)
   Dat$ = Dat$ + Chr(Byte1) + Chr(Byte2) + Chr(Byte3) + Chr(Byte4)
   Return Dat$
End Function

Function AddSmallInt$(Dat$, I)
   Byte1 = Int32 And $FF
   Byte2 = ((Int32 And $FF00) Shl 8)
   Byte3 = ((Int32 And $FF0000) Shl 16)
   Dat$ = Dat$ + Chr(Byte1) + Chr(Byte2) + Chr(Byte3)
   Return Dat$
End Function

Function AddShort$(Dat$, S)
   Byte1 = Int32 And $FF
   Byte2 = ((Int32 And $FF00) Shl 8)
   Dat$ = Dat$ + Chr(Byte1) + Chr(Byte2)
   Return Dat$
End Function

Function AddByte$(Dat$, B)
   Dat$ = Dat$ + Chr(B)
   Return Dat$
End Function

;Real MySQl Functions
Function MYSQL_____________MYSQL()
End Function

Function MySQL_Connect(Host$, User$, Pass$, Port=3306, TimeOut=10000)
   ErrorCode = 0
   ErrorMsg$ = ""
   Connected = 0

   AddGadgetItem Console, "[" + CurrentTime() + "]->Connecting to "+Host$+":"+Port
   PeekEvent()
   
   AddLogLine(ConLog, "Connect "+Host$ + ":" + Port)
   TCPS = OpenTCPStream(Host$, Port):Delay 25
   If TCPS <> 0
      
      PacketNr = 0
      
      ;Read Greeting
      BodyLength = ReadInt24New(TCPS)
      Packet     = ReadByte(TCPS):DebugLog "BodyLength: "+bodylength+"/"+ReadAvail(TCPS)
      Protocol   = ReadByte(TCPS)
      MySQLV$  = ReadStringNew(TCPS)
      ThreadID = ReadInt32New(TCPS)
      SaltP1$  = ReadStringNew(TCPS)
      Flags    = ReadShortNew(TCPS)
      Charset  = ReadByte(TCPS)
      Status   = ReadShortNew(TCPS)
      For A = 1 To 13:ReadByte(TCPS):Next
      SaltP2$  = ReadStringNew(TCPS)
      
      AddLogLine(ConLog, "READ: Body Length= "+BodyLength)
      AddLogLine(ConLog, "READ: Packet= "+Packet)
      AddLogLine(ConLog, "READ: Protocol= "+Protocol)
      AddLogLine(ConLog, "READ: MySQL Version= "+MySQLV$)
      AddLogLine(ConLog, "READ: Thread ID= "+ThreadID)
      AddLogLine(ConLog, "READ: Salt Part 1= "+SaltP1$)
      AddLogLine(ConLog, "READ: Flags= "+Flags)
      AddLogLine(ConLog, "READ: Charset= "+Charset)
      AddLogLine(ConLog, "READ: Status= "+Status)
      AddLogLine(ConLog, "READ: 13 unused Bytes")
      AddLogLine(ConLog, "READ: Salt Part 2= "+SaltP2$)
      AddGadgetItem Console, "[" + CurrentTime() + "]<-Server MySQL Ver: "+MySQLV$, 1
      PeekEvent()
      
      ;Password
      HashStage1$ = sha1(Pass$)
      HashStage2$ = sha1(HashStage1$)
      PW$ = Xor_String(HashStage1$, sha1(SaltPart1$+SaltPart2$))
      
      ;Authenticate
      D$ = AddSmallInt(D$, (4+4+1+23+Len(User$)+1+1+20))
      D$ = AddByte(D$, 1)
      D$ = AddInt(D$, (1+4+128+512+1024+8192+65536+131072))
      D$ = AddInt(D$, 16777216)
      D$ = AddByte(D$, 31)
      For A = 1 To 23
         D$ = AddByte(Dat$, 0)
      Next
      D$ = AddString(D$, User$)
      D$ = AddByte(D$, Len(PW$))
      ;For A = 1 To 20
      ;   M$ = Mid(pw$, A, 1)
      ;   Byte = Asc(M$)
      ;   WriteByte TCPS, Byte
      ;Next
      D$ = AddString2$(D$, PW$)
      WriteData(TCPS, D$)
      
      For A = 1 To Len(Pass$)
         PassH$ = PassH$ + "*"
      Next
      
      AddGadgetItem Console, "[" + CurrentTime() + "]->Username: "+User$ + " Password: " + PassH$, 1
      AddLogLine(ConLog, "WRITE: Login Data")
      PeekEvent()
      
      
      MSec = MilliSecs()
      While Eof(TCPS) = 1
         If MilliSecs()-MSec > TimeOut
            CloseTCPStream(TCPS)
            
            AddGadgetItem Console, "[" + CurrentTime() + "]--Connection timed out", 1
            AddLogLine(ConLog, "Connection timed out")
            
            TCPS = 0:Connected = 0
            
            Return 0
         EndIf
         WaitTimer RespTimer
      Wend
      
      BodyLength = ReadInt24New(TCPS)
      Packet = ReadByte(TCPS)
      Typ = ReadByte(TCPS)
      
      If Typ = 0
         AffectedRows = ReadByte(TCPS)
         InsertID = ReadByte(TCPS)
         Status = ReadShortNew(TCPS)
         WarningCount = ReadShortNew(TCPS)
         Connected = 1
         
         AddGadgetItem Console, "[" + CurrentTime() + "]<-Succesful", 1
         AddLogLine(ConLog, "Succesful")
         
         Return 1
      ElseIf Typ = 255
         ErrorCode = ReadShortNew(TCPS)
         ErrorMsg$ = ReadStringNew(TCPS)
         CloseTCPStream TCPS
         TCPS = 0

         AddGadgetItem Console, "[" + CurrentTime() + "]<-ERROR: "+ErrorMsg$ + " ERRORCODE: "+ErrorCode, 1
         AddLogLine(ConLog, "ERROR: ID="+ErrorCode+" Msg="+ErrorMsg$)

         Return 0
      EndIf
   Else
      AddGadgetItem Console, "[" + CurrentTime() + "]--Could not connect to "+Host$+":"+Port, 1
      AddLogLine(ConLog, "Could not connect to "+Host$+":"+Port)
      
      Return 0
   EndIf
End Function

Function MySQL_Disconnect()
   If TCPS <> 0 And Connected = 1
      D$ = AddSmallInt(D$, 1);WriteInt24New TCPS, 1
      D$ = AddByte(D$, 0);WriteByte TCPS, 0
      D$ = AddByte(D$, 1);WriteByte TCPS, 1
      WriteData(TCPS, D$)
      
      AddGadgetItem Console, "[" + CurrentTime() + "]--Disconnected.", 1
      CloseTCPStream TCPS
      TCPS = 0:Connected = 0
      
      AddLogLine(ConLog, "Disconnect")
      
      Return 1
   EndIf
   Return 0
End Function

Function MySQL_Query(QueryID, Query$="")
   If TCPS <> 0 And Connected = 1
      BodyLength = 4+1+Len(Query$)+1
      D$ = AddSmallInt(D$, BodyLength);WriteInt24New TCPS, BodyLength
      D$ = AddByte(D$, 0);WriteByte TCPS, 0
      D$ = AddByte(D$, QueryID);WriteByte TCPS, QueryID
      D$ = AddString2(D$, Query$);WriteStringNew TCPS, Query$
      
      WriteData(TCPS, D$)
      
      AddGadgetItem Console, "[" + CurrentTime() + "]->Query ID: "+QueryID+" Arguments:"+Query$, 1
      AddLogLine(QueryLog, "QUERY: ID="+QueryID+" ARGS="+Query$)
      
      Return 1
   EndIf
   Return 0
End Function

Function MySQL_Response()
   If TCPS <> 0 And Connected = 1
      While Not Eof(TCPS)
         BodyLength = ReadInt24New(TCPS)
         PacketNr = ReadByte(TCPS)
         Typ = ReadByte(TCPS)
         If Typ = 255
            ErrorCode = ReadShortNew(TCPS)
            ErrorMsg$ = ReadStringNew(TCPS)
            AddGadgetItem Console, "[" + CurrentTime() + "]<-ERROR: "+ErrorMsg$, 1
            
            AddLogLine(RespLog, "ERROR: ID="+ErrorCode+" Msg="+ErrorMsg$)
            
            Return 0
         ElseIf Typ = 0
            AffectedRows = ReadByte(TCPS)
            InsertID = ReadByte(TCPS)
            Status = ReadShortNew(TCPS)
            WarningCount = ReadShortNew(TCPS)
            AddGadgetItem Console, "[" + CurrentTime() + "]<-OK", 1
            
            AddLogLine(RespLog, "OK")
            
            Return 1
         Else
            AddLogLine(DebgLog, "Unknown Response")
            While Not Eof(TCPS)
               Byte = ReadByte(TCPS)
               If Byte = 0
                  AddLogLine(DebgLog, debl$)
                  debl$ = ""
               Else
                  debl$ = debl$ + Chr(Byte)
               EndIf
            Wend
         EndIf
      Wend
   EndIf
End Function

;Log
Function LOG__________________LOG()
End Function

Global Startmsec = MilliSecs()

Function CreateLog(File$)
   If FileType(File$) = 0
      Stream = WriteFile(File$)
      DebugLog "Created Log "+File$+"@"+Stream
   Else
      Stream = OpenFile(File$)
      SeekFile Stream, FileSize(File$)
      DebugLog "Opened Log "+File$+"@"+Stream
   EndIf
   Return Stream
End Function

Function AddLogLine(Stream, Txt$)
   WriteLine Stream, "[" + CurrentTime() + "](" + (MilliSecs()-Startmsec) + ") "+Txt$
   DebugLog "Added Logline to "+Stream+":"+Txt$
End Function

Function SaveLog(Stream, File$)
   CloseFile Stream
   DebugLog "Save Log "+File$+"@"+Stream
   Stream = OpenFile(File$)
   SeekFile Stream, FileSize(File$)
   Return Stream
End Function

Function CloseLog(Stream)
   DebugLog "Closed Log "+Stream
   CloseFile Stream
End Function

;Pak Files
Function PAK___________________PAK()
End Function

Function ExtractPak(Pak$, ToFolder$="")
   Stream = ReadFile(Pak$+".pak")
   If Stream
      PreFolder$ = CurrentDir()
      ChangeDir ToFolder$
      
      CreateDir Pak$
      ChangeDir Pak$+"/"
      While Not Eof(Stream)
         Typ = ReadByte(Stream)
         If Typ = 0         ;Folder
            ;Read Foldername
            Foldername$ = ReadString(Stream)
            
            ;Create and move to that Folder
            CreateDir Foldername$
            ChangeDir Foldername$+"/"
         ElseIf Typ = 1      ;File
            ;Read Filename and Length
            Filename$ = ReadString(Stream)
            Length = ReadInt(Stream)
            
            ;Create File
            Stream2 = WriteFile(Filename$)
            
            ;Start writing with 51 shift
            For Pos = 1 To Length
               Byte = ReadByte(Stream)
               Byte = Byte - 51
               If Byte < 0 Byte = Byte + 256
               WriteByte Stream2, Byte
            Next
            
            ;Save File
            CloseFile Stream2
         ElseIf Typ = 2      ;Leave Folder
            ChangeDir ".."
         EndIf
      Wend
      CloseFile Stream
      
      ChangeDir PreFolder$
      
      Return 1
   Else
      Return 0
   EndIf
End Function


Falls wer die Bildchen haben will: https://www.blitzforum.de/upload/file.php?id=5028

Die wichtige Funktion wäre also:
Code: [AUSKLAPPEN]
Function MySQL_Connect(Host$, User$, Pass$, Port=3306, TimeOut=10000)
   ErrorCode = 0
   ErrorMsg$ = ""
   Connected = 0

   AddGadgetItem Console, "[" + CurrentTime() + "]->Connecting to "+Host$+":"+Port
   PeekEvent()
   
   AddLogLine(ConLog, "Connect "+Host$ + ":" + Port)
   TCPS = OpenTCPStream(Host$, Port):Delay 25
   If TCPS <> 0
      
      PacketNr = 0
      
      ;Read Greeting
      BodyLength = ReadInt24New(TCPS)
      Packet     = ReadByte(TCPS):DebugLog "BodyLength: "+bodylength+"/"+ReadAvail(TCPS)
      Protocol   = ReadByte(TCPS)
      MySQLV$  = ReadStringNew(TCPS)
      ThreadID = ReadInt32New(TCPS)
      SaltP1$  = ReadStringNew(TCPS)
      Flags    = ReadShortNew(TCPS)
      Charset  = ReadByte(TCPS)
      Status   = ReadShortNew(TCPS)
      For A = 1 To 13:ReadByte(TCPS):Next
      SaltP2$  = ReadStringNew(TCPS)
      
      AddLogLine(ConLog, "READ: Body Length= "+BodyLength)
      AddLogLine(ConLog, "READ: Packet= "+Packet)
      AddLogLine(ConLog, "READ: Protocol= "+Protocol)
      AddLogLine(ConLog, "READ: MySQL Version= "+MySQLV$)
      AddLogLine(ConLog, "READ: Thread ID= "+ThreadID)
      AddLogLine(ConLog, "READ: Salt Part 1= "+SaltP1$)
      AddLogLine(ConLog, "READ: Flags= "+Flags)
      AddLogLine(ConLog, "READ: Charset= "+Charset)
      AddLogLine(ConLog, "READ: Status= "+Status)
      AddLogLine(ConLog, "READ: 13 unused Bytes")
      AddLogLine(ConLog, "READ: Salt Part 2= "+SaltP2$)
      AddGadgetItem Console, "[" + CurrentTime() + "]<-Server MySQL Ver: "+MySQLV$, 1
      PeekEvent()
      
      ;Password
      HashStage1$ = sha1(Pass$)
      HashStage2$ = sha1(HashStage1$)
      PW$ = Xor_String(HashStage1$, sha1(SaltPart1$+SaltPart2$))
      
      ;Authenticate
      D$ = AddSmallInt(D$, (4+4+1+23+Len(User$)+1+1+20))
      D$ = AddByte(D$, 1)
      D$ = AddInt(D$, (1+4+128+512+1024+8192+65536+131072))
      D$ = AddInt(D$, 16777216)
      D$ = AddByte(D$, 31)
      For A = 1 To 23
         D$ = AddByte(Dat$, 0)
      Next
      D$ = AddString(D$, User$)
      D$ = AddByte(D$, Len(PW$))
      ;For A = 1 To 20
      ;   M$ = Mid(pw$, A, 1)
      ;   Byte = Asc(M$)
      ;   WriteByte TCPS, Byte
      ;Next
      D$ = AddString2$(D$, PW$)
      WriteData(TCPS, D$)
      
      For A = 1 To Len(Pass$)
         PassH$ = PassH$ + "*"
      Next
      
      AddGadgetItem Console, "[" + CurrentTime() + "]->Username: "+User$ + " Password: " + PassH$, 1
      AddLogLine(ConLog, "WRITE: Login Data")
      PeekEvent()
      
      
      MSec = MilliSecs()
      While Eof(TCPS) = 1
         If MilliSecs()-MSec > TimeOut
            CloseTCPStream(TCPS)
            
            AddGadgetItem Console, "[" + CurrentTime() + "]--Connection timed out", 1
            AddLogLine(ConLog, "Connection timed out")
            
            TCPS = 0:Connected = 0
            
            Return 0
         EndIf
         WaitTimer RespTimer
      Wend
      
      BodyLength = ReadInt24New(TCPS)
      Packet = ReadByte(TCPS)
      Typ = ReadByte(TCPS)
      
      If Typ = 0
         AffectedRows = ReadByte(TCPS)
         InsertID = ReadByte(TCPS)
         Status = ReadShortNew(TCPS)
         WarningCount = ReadShortNew(TCPS)
         Connected = 1
         
         AddGadgetItem Console, "[" + CurrentTime() + "]<-Succesful", 1
         AddLogLine(ConLog, "Succesful")
         
         Return 1
      ElseIf Typ = 255
         ErrorCode = ReadShortNew(TCPS)
         ErrorMsg$ = ReadStringNew(TCPS)
         CloseTCPStream TCPS
         TCPS = 0

         AddGadgetItem Console, "[" + CurrentTime() + "]<-ERROR: "+ErrorMsg$ + " ERRORCODE: "+ErrorCode, 1
         AddLogLine(ConLog, "ERROR: ID="+ErrorCode+" Msg="+ErrorMsg$)

         Return 0
      EndIf
   Else
      AddGadgetItem Console, "[" + CurrentTime() + "]--Could not connect to "+Host$+":"+Port, 1
      AddLogLine(ConLog, "Could not connect to "+Host$+":"+Port)
      
      Return 0
   EndIf
End Function


Info: Das passiert auch bei http streams

Mfg
CGamer

[Edit] Schon seltsam wie sich die Titel anfangen zu ändern wenn man länger lädt
Warbseite

Neue Antwort erstellen


Übersicht BlitzBasic Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group