Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local packets = {}
- local nothing = ""
- local function _addPacket(identifier,name)
- packets[identifier] = name
- end
- function addPacket(identifier,name)
- assert(type(identifier) == "string", "String expected, got "..type(identifier))
- assert(type(name) == "string", "String expected, got "..type(name))
- _addPacket(identifier,name)
- end
- function setNotFoundPacket(name)
- nothing = name
- end
- function getPacket(msg)
- for k,v in pairs(packets) do
- if(string.sub(msg,1,#k) == k) then
- return v
- end
- end
- return nothing
- end
- function isPacket(id)
- return packets[id] == true
- end
- function buildPacket(id, ...)
- local args = {...}
- if (not packets[id]) then error("Invalid Packet ID",2) end
- return id .. " " .. table.concat(args, " ")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement