Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.47 KB | None | 0 0
  1. local IAC, SB, SE = 0xFF, 0xFA, 0xF0
  2. local GMCP = 201
  3.  
  4. function gmcp_send(data)
  5.   SendPkt(string.char(IAC, SB, GMCP) .. string.gsub(data, "\255", "\255\255") .. string.char(IAC, SE))
  6. end
  7.  
  8. function gmcp_handshake()
  9.   gmcp_send('Core.Hello {"client": "MUSHclient", "version": "'..Version()..'"}')
  10.   gmcp_send('Core.Supports.Set ["Char 1", "Char.Skills 1", "Char.Items 1", "Char.Defences 1", "Char.Afflictions 1", "Comm.Channel 1", "Room 1", "Redirect 1", "IRE.Rift 1", "IRE.Composer 1", "IRE.Time 1", "IRE.Target 1"]')
  11. end
  12.  
  13.  
  14. function OnPluginTelnetRequest(protocol, cmd)
  15.   if (protocol == GMCP) and (cmd == "WILL") then
  16.     return true
  17.   end
  18.  
  19.   if (protocol == GMCP) and (cmd == "SENT_DO") then
  20.     gmcp_handshake()
  21.     return true
  22.   end
  23.  
  24.   return false
  25. end
  26.  
  27.  
  28. function OnPluginTelnetSubnegotiation(protocol, data)
  29.   if (protocol ~= GMCP) then
  30.     return
  31.   end
  32.  
  33.   local cmd, jd = string.match(data, "^([A-za-z%.]+)%s*(.*)$")
  34.  
  35.   if not cmd then
  36.     return
  37.   end
  38.  
  39.   if jd then
  40.     if not string.match(jd, "^[%[%{]") then
  41.       jd = "["..jd.."]"
  42.     end
  43.   end
  44.  
  45.   -- The following line has been commented out so as to allow you to handle the data as you wish (and to prevent accidentally spamming yourself out of your gourd in an infinite Char.Vitals loop as has happened to us all).
  46.   -- Instead, I've added in echoes to display the data.
  47.   -- Execute("parsegmcp "..cmd.." "..jd)
  48.   Note("GMCP command: "..cmd)
  49.   Note("GMCP data: "..jd)
  50.   return false
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement