Skip to content

Commit

Permalink
Issue #53: Remove DateToQWORD, rename QWORDToDate
Browse files Browse the repository at this point in the history
  • Loading branch information
carlbennett committed Feb 1, 2017
1 parent 7796fac commit e8ad7f1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 67 deletions.
Binary file modified .BNRBot.rbuistate
Binary file not shown.
100 changes: 37 additions & 63 deletions Modules/Globals.rbbas
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Protected Module Globals
ElseIf CountFields(Values(i), " ") = 2 And _
IsNumeric(NthField(Values(i), " ", 1)) = True And _
IsNumeric(NthField(Values(i), " ", 2)) = True Then
FieldDate = Globals.QWORDToDate(Val(NthField(Values(i), " ", 2)), Val(NthField(Values(i), " ", 1)))
FieldDate = Globals.WindowsFileTimeToDate(Val(NthField(Values(i), " ", 2)), Val(NthField(Values(i), " ", 1)))
If FieldDate <> Nil Then Values(i) = FieldDate.ShortDate + " " + FieldDate.LongTime
End If
w.fldRecord0LastGame.Text = Values(i)
Expand All @@ -80,7 +80,7 @@ Protected Module Globals
ElseIf CountFields(Values(i), " ") = 2 And _
IsNumeric(NthField(Values(i), " ", 1)) = True And _
IsNumeric(NthField(Values(i), " ", 2)) = True Then
FieldDate = Globals.QWORDToDate(Val(NthField(Values(i), " ", 2)), Val(NthField(Values(i), " ", 1)))
FieldDate = Globals.WindowsFileTimeToDate(Val(NthField(Values(i), " ", 2)), Val(NthField(Values(i), " ", 1)))
If FieldDate <> Nil Then Values(i) = FieldDate.ShortDate + " " + FieldDate.LongTime
End If
w.fldRecord1LastGame.Text = Values(i)
Expand Down Expand Up @@ -680,32 +680,6 @@ Protected Module Globals
End Sub
#tag EndMethod

#tag Method, Flags = &h0
Function DateToQWORD(Value As Date) As UInt64

Soft Declare Function SystemTimeToFileTime Lib "Kernel32" (lpSystemTime As Ptr, lpFileTime As Ptr) As Boolean

If Value = Nil Then Value = New Date()

Dim SystemTime As New MemoryBlock(16)
SystemTime.Short(0) = Value.Year
SystemTime.Short(2) = Value.Month
SystemTime.Short(4) = Value.DayOfWeek
SystemTime.Short(6) = Value.Day
SystemTime.Short(8) = Value.Hour
SystemTime.Short(10) = Value.Minute
SystemTime.Short(12) = Value.Second
SystemTime.Short(14) = 0 // Milliseconds

Dim FileTime As New MemoryBlock(8)

Call SystemTimeToFileTime(SystemTime, FileTime)

Return FileTime.UInt64Value(0)

End Function
#tag EndMethod

#tag Method, Flags = &h0
Function DecryptCDKey(CDKey As String, ClientToken As UInt32, ServerToken As UInt32) As String

Expand Down Expand Up @@ -1787,41 +1761,6 @@ Protected Module Globals
End Function
#tag EndMethod

#tag Method, Flags = &h0
Function QWORDToDate(LowValue As UInt32, HighValue As UInt32) As Date

Dim FileTime As New MemoryBlock(8)
FileTime.UInt32Value(0) = LowValue
FileTime.UInt32Value(4) = HighValue
Return Globals.QWORDToDate(FileTime.UInt64Value(0))

End Function
#tag EndMethod

#tag Method, Flags = &h0
Function QWORDToDate(Value As UInt64) As Date

// Converts Battle.net FileTime structures (that are really
// Windows FILETIME structs) to native Date objects.

Const WINDOWS_TICK = 10000000

Dim timestamp As New Date()

timestamp.Year = 1601
timestamp.Month = 1
timestamp.Day = 1
timestamp.Hour = 0
timestamp.Minute = 0
timestamp.Second = 0

timestamp.TotalSeconds = timestamp.TotalSeconds + (Value / WINDOWS_TICK)

Return timestamp

End Function
#tag EndMethod

#tag Method, Flags = &h0
Function QWORDToIP(Value As UInt64) As String

Expand Down Expand Up @@ -2243,6 +2182,41 @@ Protected Module Globals
End Function
#tag EndMethod

#tag Method, Flags = &h0
Function WindowsFileTimeToDate(LowValue As UInt32, HighValue As UInt32) As Date

Dim FileTime As New MemoryBlock(8)
FileTime.UInt32Value(0) = LowValue
FileTime.UInt32Value(4) = HighValue
Return Globals.WindowsFileTimeToDate(FileTime.UInt64Value(0))

End Function
#tag EndMethod

#tag Method, Flags = &h0
Function WindowsFileTimeToDate(Value As UInt64) As Date

// Converts Battle.net FileTime structures (that are really
// Windows FILETIME structs) to native Date objects.

Const WINDOWS_TICK = 10000000

Dim timestamp As New Date()

timestamp.Year = 1601
timestamp.Month = 1
timestamp.Day = 1
timestamp.Hour = 0
timestamp.Minute = 0
timestamp.Second = 0

timestamp.TotalSeconds = timestamp.TotalSeconds + (Value / WINDOWS_TICK)

Return timestamp

End Function
#tag EndMethod


#tag Property, Flags = &h1
Protected BNETs() As BNETSocket
Expand Down
8 changes: 4 additions & 4 deletions Modules/Packets.rbbas
Original file line number Diff line number Diff line change
Expand Up @@ -2041,7 +2041,7 @@ Protected Module Packets
Dim Status As Byte = MemClass.ReadBYTE(PktData, 5)
Dim ClanName As String = MemClass.ReadCString(PktData, 6)
Dim ClanRank As Byte = MemClass.ReadBYTE(PktData, 7 + LenB(ClanName))
Dim DateJoined As Date = Globals.QWORDToDate(_
Dim DateJoined As Date = Globals.WindowsFileTimeToDate(_
MemClass.ReadDWORD(PktData, 8 + LenB(ClanName)), _
MemClass.ReadDWORD(PktData, 12 + LenB(ClanName)))

Expand Down Expand Up @@ -2832,15 +2832,15 @@ Protected Module Packets
Dim oLastLogon As Date

If Len(sAccountCreated) > 0 Then
oAccountCreated = Globals.QWORDToDate(_
oAccountCreated = Globals.WindowsFileTimeToDate(_
Val(NthField(sAccountCreated, " ", 2)), Val(NthField(sAccountCreated, " ", 1)))
End If
If Len(sLastLogoff) > 0 Then
oLastLogoff = Globals.QWORDToDate(_
oLastLogoff = Globals.WindowsFileTimeToDate(_
Val(NthField(sLastLogoff, " ", 2)), Val(NthField(sLastLogoff, " ", 1)))
End If
If Len(sLastLogon) > 0 Then
oLastLogon = Globals.QWORDToDate(_
oLastLogon = Globals.WindowsFileTimeToDate(_
Val(NthField(sLastLogon, " ", 2)), Val(NthField(sLastLogon, " ", 1)))
End If
If Len(sTimeLogged) > 0 Then
Expand Down

0 comments on commit e8ad7f1

Please sign in to comment.