-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclsPacketBuffer.cls
57 lines (46 loc) · 1.48 KB
/
clsPacketBuffer.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsPacketBuffer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' my little packet buffer
Option Base 0
Option Explicit
Option Compare Text
Public Buffer As String
'CopyMemory Functions
Private Function MakeMemory(ByVal Data As Long, ByVal Length As Long) As String
Dim strOut As String
strOut = String$(Length, vbNullChar)
CopyMemory ByVal strOut, Data, Length
MakeMemory = strOut
End Function
Public Sub InsertDWORD(ByVal Data As Long)
Buffer = Buffer & MakeMemory(Data, 4)
End Sub
Public Sub InsertWORD(ByVal Data As Long)
Buffer = Buffer & MakeMemory(Data, 2)
End Sub
Public Sub InsertSTRING(ByVal Data As String)
Buffer = Buffer & Data & vbNullChar
End Sub
Public Sub InsertVOID(ByVal Data As String)
Buffer = Buffer & Data
End Sub
Public Sub Send(ByVal WS As Winsock, ByVal PacketID As Long)
'AddChat "Send: " & WS.Name & " - " & Hex(PacketID) & " - " & StrToHex(Buffer)
If WS.State = sckConnected Then Call WS.SendData(Chr(&HFF) & Chr(PacketID) & MakeMemory(Len(Buffer) + 4, 2) & Buffer)
Buffer = vbNullString
End Sub
Public Sub SendRaw(ByVal WS As Winsock)
If WS.State = sckConnected Then Call WS.SendData(Buffer)
Buffer = vbNullString
End Sub