CapsAdmin

Untitled

May 20th, 2011
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.07 KB | None | 0 0
  1. if SERVER then
  2.  
  3.     require("json")
  4.     require("oosocks")
  5.  
  6.     local socket = OOSock(IPPROTO_UDP)
  7.     local receiving = false
  8.  
  9.     socket:SetCallback(function(self, type, id, error, data, address, port)
  10.         if type == SCKCALL_SEND and error == SCKERR_OK and not receiving then
  11.             receiving = true
  12.             socket:ReceiveDatagram()
  13.             print("Sent first chat message")
  14.         elseif type == SCKCALL_REC_DATAGRAM then
  15.             if error == SCKERR_OK then
  16.                 hook.Call("RemotePlayerSay", nil, Json.Decode(data))
  17.                 self:ReceiveDatagram()
  18.             else
  19.                 Error("ERROR")
  20.             end
  21.         end
  22.     end)
  23.  
  24.     hook.Add("PlayerSay", "chat", function(player, text)
  25.         socket:Send(Json.Encode({nick = player:Nick(), text = text}), "morten.im", 8080)
  26.     end)
  27.  
  28.     hook.Add("RemotePlayerSay", "blah", function(data)
  29.         umsg.Start("RemotePlayerSay")
  30.             umsg.String(glon.encode(data)) -- :s
  31.         umsg.End()
  32.     end)
  33.  
  34. end
  35.  
  36. if CLIENT then
  37.  
  38.     usermessage.Hook("RemotePlayerSay", function(umr)
  39.         local data = glon.decode(umr:ReadString())
  40.        
  41.         chat.AddText("[", data.server.id, "] ", Color(100,100,100), data.nick, ,": " data.text)
  42.     end)
  43.  
  44. end
Advertisement
Add Comment
Please, Sign In to add comment