Skip to content

Commit

Permalink
Merged pull request from Johnson and updated msdphandler
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavious committed Jun 3, 2017
1 parent f0b05cf commit 912f106
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 139 deletions.
Binary file modified mushclient_prefs.sqlite
Binary file not shown.
300 changes: 171 additions & 129 deletions worlds/plugins/LotJMSDPHandler.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE muclient>
<!-- Saved on Thursday, February 22, 2013, 1:59 PM -->
<!-- MuClient version 4.73 -->
<!DOCTYPE muclient>
<muclient>
<plugin name="LotJMSDPHandler" author="@Johnson" id="b3aae34498d5bf19b5b2e2af" language="Lua" purpose="Handle MSDP messages and broadcast data" save_state="y" requires="4.73" version="0.52">
<plugin name="LotJMSDPHandler" author="@Johnson" id="b3aae34498d5bf19b5b2e2af" language="Lua" purpose="Handle MSDP Communications" save_state="y" requires="4.73" version="0.55">
<description trim="y">
Legends of the Jedi MSDP Handler.

Purpose is to receive incoming MSDP messages and populate the global
table 'msdp' with the values as received so that MSDP under MUSHClient
can use partial refreshes of data.

This is based on GMCP_handler written by Lasher of AardwolfMud.
<![CDATA[
--Legends of the Jedi MSDP Handler--
This plugin handles all MSDP communications between the LotJ server and MUSHclient.
Upon login or plugin install, the plugin will send a request for the list of all
reportable variables, publish its plugin ID, and finally request all currently
available MSDP variables so that will be sent in pulses whenever their values change
and stored in a global table for other plugins to access.
To use this plugin to send MSDP variables to your plugin, enter this into the top of your plugin's code:
dofile(GetPluginInfo(GetPluginID(), 20) .. "LotJMSDPHelper.lua")
Then whenever you want to set a variable, use this syntax:
myVariable = getmsdp("VARIABLE NAME")
To see a particular MSDP variable use the syntax 'msdpshow <variable>'.
Parts of this plugin were based on GMCP_handler written by Lasher of AardwolfMud.
]]>
</description>

</plugin>
Expand All @@ -31,7 +33,8 @@ Then whenever you want to set a variable, use this syntax:

<aliases>
<alias script="msdpdebug" match="^msdpdebug (.*)?$" enabled="y" regexp="y" sequence="100" ignore_case="y" />
<alias script="MSDP_Alias" match="sendmsdp *" enabled="y" send_to="12" sequence="100" />
<alias script="MSDP_Alias" match="msdpsend *" enabled="y" send_to="12" sequence="100" />
<alias script="printMSDP" match="^msdpshow( +(.*))?$" enabled="y" regexp="y" ignore_case="y" sequence="100" />

</aliases>
<timers>
Expand All @@ -41,19 +44,44 @@ Then whenever you want to set a variable, use this syntax:
<script>
<![CDATA[
AUTHOR = GetPluginInfo(GetPluginID(), 2) -- author info
VERSION = string.format("%1.2f", GetPluginInfo(GetPluginID(), 19)) -- version info
local IAC, SB, SE, DO = 0xFF, 0xFA, 0xF0, 0xFD
local MSDP = 69
local MSDPDebug = tonumber(GetVariable("MSDPDebug")) or 0
msdp = {}
local sqldb = {}
local sqlfile = GetInfo(60) .. "\msdp.sqlite3"
require "tprint"
require "serialize"
function printMSDP(name, line, args)
local count = 0
if args[1] == "" then -- entered nothing, print everything
ColourNote("white","","Stored MSDP variable list. Use ","red","","'","white","","msdpshow <variable>","red","","'","white",""," to access a specific variable.")
for i, v in pairs(msdp) do
count = count + 1
ColourTell("white","","'","darkgray","",string.format("%-20s",i),"white","","'")
if math.fmod(count,3)==0 then
Note()
end
end
else -- entered something
v=Trim(args[1]:upper())
ColourNote("white","","MSDP Variable '","darkgray","",v,"white","","'")
if type(msdp[v])=="table" then
ColourNote("white","","msdp[","red","",v,"white","","]=")
for i, v in ipairs(msdp[v]) do
ColourNote("darkgray",""," "..v)
end
else
ColourNote("white","","msdp[","red","",v,"white","","]=","darkgray","",((msdp[v]~=nil and msdp[v]) or "Not Found."))
end
end
end
function msdpdebug(name, line, wildcards)
newval = tonumber(wildcards[1])
if not newval or newval > 2 or newval < 0 then
ColourNote("darkorange", "", "MSDPDebug valid values are: 0 - off, 1 - simple, 2 - verbose")
msdpmsg(-1, "MSDPDebug valid values are: 0 - off, 1 - simple, 2 - verbose")
return
end
MSDPDebug = newval
Expand All @@ -63,13 +91,13 @@ function msdpdebug(name, line, wildcards)
elseif MSDPDebug == 2 then
msg = "verbose"
end
ColourNote("darkorange", "", "MSDPDebug: " .. msg)
msdpmsg(-1, "MSDPDebug: " .. msg)
end
function MSDP_Alias(name, line, wildcards)
if (wildcards[1] ~= nil) then
Note("Send "..wildcards[1].." via MSDP frequency.")
Send_MSDP_Packet(wildcards[1]) -- will be in msdphelper TODO
msdpmsg(0, "Sent "..wildcards[1].." via MSDP frequency.")
Send_MSDP_Packet(wildcards[1])
end
end
Expand All @@ -79,145 +107,159 @@ end
function OnPluginTelnetSubnegotiation (type, data)
if type ~= MSDP then
return
end -- if not MSDP
if MSDPDebug > 1 then ColourNote ("darkorange", "", data) end
end
endpos = string.len(data)
bName = false
bValue = false
bTable = false
bIgnore = false
variable = nil
value = nil
for i=1,endpos,1 do
if string.byte(data,i) == 1 and bTable == false then
if variable ~= nil and value ~= nil then
StoreVariable(variable, value)
variable = nil
value = nil
end -- if
bName = true
bValue = false
elseif string.byte(data,i) == 2 and bTable == false then
if value ~= nil then
value = value.." "
end -- if
bName = false
bValue = true
elseif string.byte(data,i) == 3 then
bTable = true
bIgnore = true
elseif string.byte(data,i) == 4 then
bTable = false
elseif bIgnore == true then
bIgnore = false -- Just ignore one character.
elseif bName == true then
if variable == nil then
variable = ""
end -- if
variable = variable..string.sub(data,i,i)
elseif bValue == true then
if value == nil then
-- output full data in hex to preserve non-printable chars
if MSDPDebug > 1 then ColourNote ("darkorange", "", "hex="..utils.tohex(data)) end
local key, value, str = "", "", ""
local tTable, tList, tKey, tValue = false, false, false, false
local list = {}
for i=1,#data,1 do
b = string.byte(data, i)
if b==1 then -- 'START OF HEADING' MSDP_VAR '
if not tList then -- list member key start, ignore if tList seems to do nothing
--if MSDPDebug > 0 then ColourTell("white","","\'") end -- key start
tKey = true
end
elseif b==2 then -- 'START OF TEXT' MSDP_VAL , | '=
if tTable or tList then -- middle of a table
--if MSDPDebug > 0 then ColourTell("white","",",") end -- table or list member
if value ~= "" then -- avoid appending empty strings
list[#list+1] = value
value = ""
end -- if
value = value..string.sub(data,i,i)
end -- if
end -- for
if variable ~= nil then
if value == nil then
value = ""
end -- if
StoreVariable(variable, value)
end -- if
end -- function OnPluginTelnetSubnegotiation
end
elseif tKey then
--if MSDPDebug > 0 then ColourTell("white","","\'=") end -- key end
tKey = false
tValue = true
end
elseif b==3 then -- 'END OF TEXT' MSDP_TABLE_OPEN [
--if MSDPDebug > 0 then ColourTell("white","","[") end -- list start
tList = true
tValue = true
elseif b==4 then -- 'END OF TRANSMISSION' MSDP_TABLE_CLOSE ]
if tList then
tList = false
--if MSDPDebug > 0 then ColourTell("white","","]") end -- separated list end
if value ~= "" then -- avoid appending empty strings
list[#list+1] = value
end
value = list
end
elseif b==5 then -- 'ENQUIRY' MSDP_ARRAY_OPEN {
--if MSDPDebug > 0 then ColourTell("white","",'{') end
tTable = true
tValue = true
elseif b==6 then -- 'ACKNOWLEDGE' MSDP_ARRAY_CLOSE }
if tTable then
--if MSDPDebug > 0 then ColourNote("white","",'}') end
tTable = false
tValue = false
if value ~= "" then
list[#list+1] = value
end
value = list
end
elseif b==79 then -- 'O' CHARACTER ??? No idea why this is here.
if tList then -- middle of a separated list
-- do nothing, probably where a direction,vnum pair should be, but isn't!
else
if tKey then
key = key..string.char(b)
elseif tValue then
value = value..string.char(b)
end
--if MSDPDebug > 0 then ColourTell("darkgray","",string.char(b)) end
end
else -- not a special character, append it to key or value
--if MSDPDebug > 0 then ColourTell("darkgray","",string.char(b)) end
if tKey then
key = key..string.char(b)
elseif tValue then
value = value..string.char(b)
end
end
end
--if MSDPDebug > 0 then Note() end
StoreVariable(key, value)
end
function StoreVariable (MSDP_var, MSDP_val)
if MSDP_var == "SERVER_ID" then
SendPkt ("\255\250\69\1PLUGIN_ID\2LotJMSPDHandler MUSHclient plugin (version 0.49)\255\240")
else -- store the variable
-- To get MSDP variables in external plugins:
-- dofile(GetPluginInfo(GetPluginID(), 20) .. "LotJMSDPHelper.lua")
-- myVariable = getmsdp("VARIABLE NAME")
msdp[MSDP_var] = MSDP_val
BroadcastPlugin(91,MSDP_var) -- broadcasts variable name so other plugins can see if they need to update
if MSDPDebug > 0 then ColourNote ("darkorange", "", MSDP_var..":"..msdp[MSDP_var]) end
end -- if
end -- function StoreVariable
-- To get MSDP variables in external plugins:
-- dofile(GetPluginInfo(GetPluginID(), 20) .. "LotJMSDPHelper.lua")
-- myVariable = getmsdp("VARIABLE NAME")
msdp[MSDP_var] = (type(MSDP_val)=="table" and table.concat(MSDP_val, ",")) or MSDP_val
msdpmsg(0, "msdp["..MSDP_var.."]="..msdp[MSDP_var])
BroadcastPlugin(91,MSDP_var) -- broadcasts variable name so other plugins can see if they need to update
end
function Send_MSDP_Packet (what)
assert (what, "Send_MSDP_Packet passed a nil message.")
--SendPkt (string.char (IAC, SB, MSDP) ..
-- (string.gsub (what, "\255", "\255\255")) .. -- IAC becomes IAC IAC
-- string.char (IAC, SE))
SendPkt ("\255\250\69" .. what .. "\255\240")
end -- Send_MSDP_Packet
end
function OnPluginInstall()
BroadcastPlugin(1, "reload") -- tell other plugins to clear all msdp data
if IsConnected() then
-- pretend like we just logged in
Send_MSDP_Packet ("\1LIST\2COMMANDS")
Send_MSDP_Packet ("\1REPORT\2CHARACTERNAME\2SERVERID\2SERVERTIME\2SNIPPETVERSION\2AFFECTS\2ALIGNMENT\2HEALTH\2HEALTHMAX\2TOPLEVEL\2LEVELCOMBAT\2LEVELPILOTING\2LEVELENGINEERING\2LEVELHUNTING\2LEVELSMUGGLING\2LEVELDIPLOMACY\2LEVELLEADERSHIP\2LEVELFORCE\2LEVELESPIONAGE\2LEVELSLICER\2LEVELMEDIC\2LEVELSCIENCE\2COMMCHANNEL\2COMMENCRYPT\2OOCLIMIT\2OOCBREAK\2PLANET\2RACE\2CLAN\2PILOTING\2SHIPSPEED\2SHIPMAXSPEED\2SHIPHULL\2SHIPMAXHULL\2SHIPENERGY\2SHIPMAXENERGY\2SHIPSHIELD\2SHIPMAXSHIELD\2SHIPGALX\2SHIPGALY\2SHIPSYSX\2SHIPSYSY\2SHIPSYSZ\2SHIPHEADX\2SHIPHEADY\2SHIPHEADZ\2SHIPSYSNAME\2CLASS\2MANA\2MANAMAX\2WIMPY\2PRACTICE\2MONEYTOTAL\2MONEYINV\2MONEYBANK\2MOVEMENT\2MOVEMENTMAX\2HITROLL\2DAMROLL\2AC\2STR\2INT\2WIS\2DEX\2CON\2CHA\2STRPERM\2INTPERM\2WISPERM\2DEXPERM\2CONPERM\2CHAPERM\2OPPONENTHEALTH\2OPPONENTHEALTHMAX\2OPPONENT_LEVEL\2OPPONENTNAME\2AREA_NAME\2ROOMEXITS\2ROOMNAME\2ROOMVNUM\2WORLDTIME\2BOTTINGDELAY\2CURRENTAMMO\2MAXAMMO\2SHIELDENERGY\2LIGHTTIME\2MEDPACPOWER\2GRENADEROUNDS\2BLADEPOWER")
end
BroadcastPlugin(1, "reload") -- tell other plugins to clear all msdp data
if IsConnected() then
Send_MSDP_Packet ("\1LIST\2COMMANDS\2LISTS\2CONFIGURABLE_VARIABLES\2REPORTABLE_VARIABLES\2REPORTED_VARIABLES\2SENDABLE_VARIABLES\2GUI_VARIABLES")
Send_MSDP_Packet ("\1PLUGINID\2LotJMSDPHandler_v"..VERSION) -- Send our PLUGIN ID
waitForReply()
end
end
function waitForReply()
if msdp["REPORTABLE_VARIABLES"] ~= nil then -- variable list is populated
Send_MSDP_Packet("\1REPORT\2"..string.gsub(msdp["REPORTABLE_VARIABLES"], ",", "\2"))
else
DoAfterSpecial(0.5, 'waitForReply()', sendto.script)
end
end
function OnPluginSaveState()
SetVariable("MSDPDebug", MSDPDebug)
end
function OnPluginTelnetRequest (type, data)
if type == MSDP and data == "WILL" then
return true
end -- if
if type == MSDP and data == "SENT_DO" then
Note("Enabling MSDP.")
--=======================
-- check sql database exists/create it
--=======================
sqldb = sqlite3.open(sqlfile)
Send_MSDP_Packet ("\1LIST\2COMMANDS")
Send_MSDP_Packet ("\1REPORT\2CHARACTERNAME\2SERVERID\2SERVERTIME\2SNIPPETVERSION\2AFFECTS\2ALIGNMENT\2HEALTH\2HEALTHMAX\2TOPLEVEL\2LEVELCOMBAT\2LEVELPILOTING\2LEVELENGINEERING\2LEVELHUNTING\2LEVELSMUGGLING\2LEVELDIPLOMACY\2LEVELLEADERSHIP\2LEVELFORCE\2LEVELESPIONAGE\2LEVELSLICER\2LEVELMEDIC\2LEVELSCIENCE\2COMMCHANNEL\2COMMENCRYPT\2OOCLIMIT\2OOCBREAK\2PLANET\2RACE\2CLAN\2PILOTING\2SHIPSPEED\2SHIPMAXSPEED\2SHIPHULL\2SHIPMAXHULL\2SHIPENERGY\2SHIPMAXENERGY\2SHIPSHIELD\2SHIPMAXSHIELD\2SHIPGALX\2SHIPGALY\2SHIPSYSX\2SHIPSYSY\2SHIPSYSZ\2SHIPHEADX\2SHIPHEADY\2SHIPHEADZ\2SHIPSYSNAME\2CLASS\2MANA\2MANAMAX\2WIMPY\2PRACTICE\2MONEYTOTAL\2MONEYINV\2MONEYBANK\2MOVEMENT\2MOVEMENTMAX\2HITROLL\2DAMROLL\2AC\2STR\2INT\2WIS\2DEX\2CON\2CHA\2STRPERM\2INTPERM\2WISPERM\2DEXPERM\2CONPERM\2CHAPERM\2OPPONENTHEALTH\2OPPONENTHEALTHMAX\2OPPONENT_LEVEL\2OPPONENTNAME\2AREA_NAME\2ROOMEXITS\2ROOMNAME\2ROOMVNUM\2WORLDTIME\2BOTTINGDELAY\2CURRENTAMMO\2MAXAMMO\2SHIELDENERGY\2LIGHTTIME\2MEDPACPOWER\2GRENADEROUNDS\2BLADEPOWER")
return true
end -- if MSDP login needed (just sent DO)
return false
end -- function OnPluginTelnetRequest
-------------------------------------------------------------------------------
function init_msdpdata()
-- not used at the moment
end -- init_msdpdata
-------------------------------------------------------------------------------
if type == MSDP and data == "WILL" then
return true
end -- if
if type == MSDP and data == "SENT_DO" then
msdpmsg(-1, "Enabled MSDP")
OnPluginInstall()
return true
end
return false
end
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.")
EnablePlugin(GetPluginID(), true)
ColourNote("white", "blue", "You are not allowed to disable the "..
GetPluginInfo(GetPluginID(), 1).." plugin. It is necessary for other plugins.")
end
function msdpmsg(level, msg)
if MSDPDebug > level then
ColourNote("red","",">>>","darkgray","",((type(msg)=="table" and table.concat(msg, ","))or msg),"red","","<<<")
end
end
function msdpval(fieldname)
if not IsConnected() then
return ""
end
assert (fieldname, "nil fieldname passed to msdpval")
local result = msdp[fieldname]
assert (fieldname, "nil fieldname passed to msdpval")
local result = msdp[fieldname]
if result ~= nil then -- variable was found in local msdp table
return result
return result
else
return "" -- fail safely
end
return ""
return "" -- fail safely
end
return ""
end
Expand Down
Loading

0 comments on commit 912f106

Please sign in to comment.