I suppose I could post what I have so far, though I've found an authentication routine in that proxy from Imperian that I want to try out,
and there's still a weird issue with parsing - it sometimes screws up in some unknown to me way,
resulting in prompt triggers not matching. There's also the problem with the "unsupported client" message,
but I am hoping that solving the authentication puzzle will remove that problem also.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="ATCP"
author="Keldar"
id="a2a6350d9144c09a8a7c4636"
language="Lua"
purpose="Enabling the ATCP protocol"
date_written="2006-10-15"
requires="3.81"
version="1.0"
>
<description trim="y">
<![CDATA[
sdf
]]>
</description>
</plugin>
<variables>
<variable name="NexusVer">3.0.0</variable>
</variables>
<!-- Get our standard constants -->
<include name="constants.lua"/>
<!-- Script -->
<script>
<![CDATA[
require "tprint"
client_id = "Muclient 3.8.1"--"Nexus 3.0.9" --
nexus_opts = {
{"hello", client_id},
--{"auth", "1"},
--{"composer", "1"},
--{"keepalive", "1"},
--{"char_name", "1"},
--{"filestore", "1"},
--{"topvote", "1"},
{"char_vitals", "1"},
{"room_brief", "1"},
{"room_exits", "1"},
--{"mediapak", "1"},
--{"wiz", "1"}
}
codes = {
IAC_WILL_ATCP = "\255\251\200",
IAC_WONT_ATCP = "\255\252\200",
IAC_DO_ATCP = "\255\253\200",
IAC_DONT_ATCP = "\255\254\200",
IAC_SB_ATCP = "\255\250\200",
IAC_SE = "\255\240",
IAC_DO_EOR = "\255\253\025",
IAC_WILL_EOR = "\255\251\025",
IAC_GA = "\255\249"
}
leftovers = nil
PAT = "^(.-)" .. codes.IAC_SB_ATCP .. "(.-)" .. codes.IAC_SE .. "(.-)$"
UNSUP_MSG = "\r\n\r\n==================================================================\r\n You are using an unsupported version of the client software.\r\n\r\n Please update by forcing a reload of the page and reconnect.\r\n==================================================================\r\n\r\n"
function SendATCP(msg)
SendPkt(codes.IAC_SB_ATCP .. msg .. codes.IAC_SE)
end
function OnPluginConnect()
local msg = ""
for _,v in ipairs(nexus_opts) do
msg = msg .. v[1] .. " " .. v[2] .. "\10"
end
msg = string.sub(msg, 1, -2)
print(msg)
SendPkt(codes.IAC_DO_ATCP .. codes.IAC_SB_ATCP .. msg .. codes.IAC_SE)
end
function OnPluginPacketReceived(packet)
if string.find(packet, codes.IAC_WILL_ATCP) then
Note("IAC WILL ATCP")
packet = string.gsub(packet, "(.-)" .. codes.IAC_WILL_ATCP .. "(.-)", "%1%2")
end
local s,e = string.find(packet, UNSUP_MSG, 1, true)
if s then
Note("Unsupported client message gagged.")
return string.sub(packet, e+1)
end
if string.find(packet, codes.IAC_WILL_EOR) then
Note("IAC WILL EOR")
packet = string.gsub(packet, "(.-)" .. codes.IAC_WILL_EOR .. "(.-)", "%1%2")
end
if string.find(packet, "Enter an option or enter your character's name.") then
Note("Login:")
-- If auth option is specified then this is where we send the name and password
--
end
local packet, atcp, parsed = parseATCP(packet)
if atcp[1] and string.find(atcp[1], "^Auth.Request CH") then
SendPkt(codes.IAC_DO_EOR .. codes.IAC_DO_ATCP)
end
--tprint(atcp)
--print(parsed["Char.Vitals"])
return packet
end
function parseATCP(packet)
local packet = packet
local s,e,prev,msg,nxt, asplit
local atcp,parsed = {}, {}
if leftovers then
s,e,msg = string.find(leftovers .. packet, "^" .. codes.IAC_SB_ATCP .. "(.-)" .. codes.IAC_SE)
if s then
asplit = utils.split(msg, "\10")
parsed[asplit[1] ] = asplit[2]
table.insert(atcp, msg)
packet = string.sub(leftovers .. packet, e+1)
end
leftovers = nil
end
local new_packet = ""
local lastend, lastnxt
local pat = PAT
s,e,prev,msg,nxt = string.find(packet, pat)
while s do
new_packet = new_packet .. prev
lastend = e
lastnxt = nxt
asplit = utils.split(msg, "\10")
parsed[asplit[1] ] = asplit[2]
table.insert(atcp, msg)
s,e,prev,msg,nxt = string.find(lastnxt, pat)
end
if not lastnxt then
lastnxt = packet
end
s,e,prev,msg = string.find(lastnxt, "^(.-)(\255\250?\200?.*)")
if s then
leftovers = msg
new_packet = new_packet .. prev
else
new_packet = new_packet .. lastnxt
end
if #new_packet > 0 then
packet = new_packet
end
return packet, atcp, parsed
end
]]>
</script>
<!-- Plugin help -->
<aliases>
<alias
script="OnHelp"
match="ATCP:help"
enabled="y"
>
</alias>
</aliases>
<script>
<![CDATA[
function OnHelp ()
world.Note (world.GetPluginInfo (world.GetPluginID (), 3))
end
]]>
</script>
</muclient>
|