-
Notifications
You must be signed in to change notification settings - Fork 5
/
data_packet.lua
49 lines (39 loc) · 1.42 KB
/
data_packet.lua
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
-------------------------------------------------------------------------------
--- AUTHOR: Nostrademous
--- GITHUB REPO: https://github.com/Nostrademous/Dota2-WebAI
-------------------------------------------------------------------------------
local dbg = require( GetScriptDirectory().."/debug" )
local DataPacket = {}
DataPacket.LastPacket = {}
DataPacket.TYPE_AUTH = "X"
DataPacket.TYPE_WORLD = "W"
DataPacket.TYPE_PLAYER = "P"
DataPacket.TYPE_ENEMIES = "E"
DataPacket.TYPE_ALLIES = "A"
function DataPacket:CreatePacket(key, packet)
--local seq = Round(RealTime(), 3) * 1000
if not DataPacket.LastPacket[key] then
DataPacket.LastPacket[key] = {}
end
--DataPacket.LastPacket[key].seq = seq
DataPacket.LastPacket[key].lastSent = packet
DataPacket.LastPacket[key].processed = false
end
function DataPacket:ProcessPacket(key, reply)
if DataPacket.LastPacket[key] then
--dbg.myPrint("Got Reply Key: ", key)
DataPacket.LastPacket[key].lastReply = reply
DataPacket.LastPacket[key].processed = true
DataPacket.LastPacket[key].reported = false
else
dbg.pause('Bad Reply Key:', key)
end
end
function DataPacket:GetLastReply(key)
if DataPacket.LastPacket[key] and not DataPacket.LastPacket[key].reported then
DataPacket.LastPacket[key].reported = true
return DataPacket.LastPacket[key].lastReply
end
return nil
end
return DataPacket