forked from mike347/ATSPlugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GMCP_handler.xml
115 lines (100 loc) · 3.45 KB
/
GMCP_handler.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="GMCP_handler"
author="Nick Gammon"
id="74f8c420df7d59ad5aa66246"
language="Lua"
purpose="Handle GMCP messages and broadcast data"
save_state="y"
date_written="2015-05-06"
requires="4.59"
version="1.0"
>
<description trim="y">
GMCP handler for Aardwolf and IRE MUDs.
Type: 'gmcpdebug 1' for debugging info.
Type: 'gmcpdebug 0' to turn debugging off.
</description>
</plugin>
<aliases>
<alias
script="gmcpdebug"
match="^gmcpdebug (.*)?$"
enabled="y"
regexp="y"
sequence="100"
ignore_case="y"
></alias>
</aliases>
<script>
<![CDATA[
local IAC, SB, SE, DO = 0xFF, 0xFA, 0xF0, 0xFD
local GMCP = 201
local GMCPDebug = tonumber(GetVariable("GMCPDebug")) or 0
function gmcpdebug(name, line, wildcards)
newval = tonumber(wildcards[1])
if not newval or newval > 2 or newval < 0 then
ColourNote("darkorange", "", "GMCPDebug valid values are: 0 - off, 1 - simple, 2 - verbose")
return
end
GMCPDebug = newval
local msg = "off"
if GMCPDebug == 1 then
msg = "simple"
elseif GMCPDebug == 2 then
msg = "verbose"
end
ColourNote ("darkorange", "", "GMCPDebug: " .. msg)
end
---------------------------------------------------------------------------------------------------
-- Mushclient callback function when telnet SB data received.
---------------------------------------------------------------------------------------------------
function OnPluginTelnetSubnegotiation (msg_type, data)
if msg_type ~= GMCP then
return
end -- if not GMCP
-- debugging
if GMCPDebug > 0 then
ColourNote ("darkorange", "", data)
end
message, params = string.match (data, "([%a.]+)%s+(.*)")
-- if valid format, broadcast to all interested plugins
if message then
BroadcastPlugin(1, data)
end -- if
end -- function OnPluginTelnetSubnegotiation
function OnPluginSaveState()
SetVariable("GMCPDebug", GMCPDebug)
end
function OnPluginTelnetRequest (msg_type, data)
if msg_type == GMCP and data == "WILL" then
return true
end -- if
if msg_type == GMCP and data == "SENT_DO" then
Note ("Enabling GMCP.")
-- This hard-coded block may need to be made into a config table as we add more message types.
Send_GMCP_Packet (string.format ('Core.Hello { "client": "MUSHclient", "version": "%s" }', Version()))
Send_GMCP_Packet ('Core.Supports.Set [ "Char 1", "Comm 1", "Room 1" ]')
return true
end -- if GMCP login needed (just sent DO)
return false
end -- function OnPluginTelnetRequest
function OnPluginDisable()
EnablePlugin(GetPluginID(), true)
ColourNote("white", "blue", "You are not allowed to disable the "..
GetPluginInfo(GetPluginID(), 1).." plugin. It is necessary for other plugins.")
end
---------------------------------------------------------------------------------------------------
-- Helper function to send GMCP data.
---------------------------------------------------------------------------------------------------
function Send_GMCP_Packet (what)
assert (what, "Send_GMCP_Packet passed a nil message.")
SendPkt (string.char (IAC, SB, GMCP) ..
(string.gsub (what, "\255", "\255\255")) .. -- IAC becomes IAC IAC
string.char (IAC, SE))
end -- Send_GMCP_Packet
]]>
</script>
</muclient>