2014-09-21 01:20:43 +03:00
|
|
|
-- Buildat: client/packet.lua
|
|
|
|
-- http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
-- Copyright 2014 Perttu Ahola <celeron55@gmail.com>
|
2014-09-19 14:50:25 +03:00
|
|
|
local log = buildat.Logger("__client/packet")
|
2014-09-19 10:30:49 +03:00
|
|
|
|
2014-09-19 21:45:44 +03:00
|
|
|
local packet_subs = {}
|
2014-09-19 10:30:49 +03:00
|
|
|
|
2014-09-19 21:45:44 +03:00
|
|
|
function __buildat_handle_packet(name, data)
|
|
|
|
local cb = packet_subs[name]
|
|
|
|
if cb then
|
|
|
|
cb(data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function buildat.sub_packet(name, cb)
|
|
|
|
packet_subs[name] = cb
|
2014-09-19 10:30:49 +03:00
|
|
|
end
|
2014-09-19 21:45:44 +03:00
|
|
|
function buildat.unsub_packet(cb)
|
2014-09-19 10:30:49 +03:00
|
|
|
for name, cb1 in pairs(buildat.packet_subs) do
|
|
|
|
if cb1 == cb then
|
2014-09-19 21:45:44 +03:00
|
|
|
packet_subs[cb] = nil
|
2014-09-19 10:30:49 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-19 21:45:44 +03:00
|
|
|
function buildat.send_packet(name, data)
|
2014-09-19 10:30:49 +03:00
|
|
|
__buildat_send_packet(name, data)
|
|
|
|
end
|
2014-09-24 15:13:49 +03:00
|
|
|
-- vim: set noet ts=4 sw=4:
|