CapsAdmin

Untitled

Dec 29th, 2011
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.99 KB | None | 0 0
  1. netmsg = netmsg or {}
  2.  
  3. netmsg.Hooks = {}
  4.  
  5. function netmsg.Hook(tag, callback)
  6.     netmsg.Hooks[tag] = callback
  7. end
  8.  
  9. if CLIENT then
  10.     function netmsg.Send(id, ...)
  11.         netmsg.RawSend(glon.encode(id, ...))
  12.     end
  13.  
  14.     function netmsg.NetHook(str)
  15.         local args = glon.decode(str)
  16.         if args then
  17.             local id = args[1]
  18.             if id and netmsg.Hooks[id] then
  19.                 table.remove(args, 1)
  20.                 printf("NETMSG %q FROM SERVER RECEIEVED : %s", id, str)
  21.                 netmsg.Hooks[id](unpack(args))
  22.             end
  23.         end
  24.     end
  25. end
  26.  
  27. if SERVER then
  28.     function netmsg.Send(id, ply, ...)
  29.         netmsg.RawSend(glon.encode(id, ...), ply)
  30.     end
  31.  
  32.     function netmsg.NetHook(str, ply)
  33.         if ply then
  34.             local args = glon.decode(str)
  35.             if args then
  36.                 local id = args[1]
  37.                 if id and netmsg.Hooks[id] then
  38.                     table.remove(args, 1)
  39.                     printf("NETMSG %q FROM %s RECEIEVED : %s", id, tostring(ply), str)
  40.                     netmsg.Hooks[id](ply, unpack(args))
  41.                 end
  42.             end
  43.         end
  44.     end
  45. end
  46.  
  47. hook.Add("OnNetMsgReceived", "netmsg", netmsg.NetHook, print)
Advertisement
Add Comment
Please, Sign In to add comment