I got a basic GMCP plugin working that simply notes the output of messages to the output window. It works as expected, except for one thing. The background color of ColourNote I use to show the GMCP messages is getting applied to some of the text that it shouldn't be.
Here is the relevant piece of the plugin..
Version 4.80
<script>
<![CDATA[
require("json")
require("tprint")
-- GMCP and Telnet Request/Subnegotiation info
local CLIENT_ID = {client="MUSHclient", version=Version()}
local codes = {
IAC_SB_GMCP = "\255\250\201", -- begins a GMCP packet
IAC_SE = "\255\240", -- ends a GMCP packet
GMCP = 201, -- GMCP protocol number
}
local SB_GMCP = codes.IAC_SB_GMCP .. "%s" .. codes.IAC_SE
-- GMCP modules supported by this plugin
local GMCP_options = {
"Core 1",
"Char 1",
"Char.Skills 1",
"Char.Items 1",
"Comm.Channel 1",
"Room 1",
"Redirect 1",
"IRE.Rift 1",
"IRE.Composer 1",
}
function SendGMCP(message, content)
if type(message) ~= "string" then
return nil, "Message name must be a string."
end
if content ~= nil then
content = json.encode({content})
if content == nil then
return nil, "Invalid input."
end
message = ("%s %s"):format(message, content:sub(2, #content-1))
end
SendPkt(SB_GMCP:format(message))
return true
end
function OnPluginTelnetRequest (opt, data)
if opt ~= 201 then
return false
end
if data == "SENT_DO" then
Note("GMCP enabled.\n")
SendGMCP("Core.Hello ", CLIENT_ID)
SendGMCP("Core.Supports.Set ", GMCP_options)
end
return true
end
function OnPluginTelnetSubnegotiation (opt, data)
if opt ~= codes.GMCP then
return
end
ColourNote ("blue", "white", data)
local msg, content = unpack(utils.split(data, " ", 1))
if not content or content:len() == 0 then
content = nil
else
-- Not every JSON parser allows any top-level value to be valid.
-- Ensuring that a non-object non-array value is at least within
-- an array makes this code parser-agnostic.
local err
content, err = json.decode(("[%s]"):format(content))
if content ~= nil then
content = content[1]
else
error("Invalid message: " .. err)
end
end
function toggle_debug()
gmcpdebug = not gmcpdebug
Note(("GMCP Debugging is %s"):format(gmcpdebug and "Enabled" or "Disabled"))
end
]]>
</script>
..how do I upload screenshots? |