Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Plugins ➜ trying to make atcp2 plugin to work

trying to make atcp2 plugin to work

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1 2  3  4  5  6  7  8  9  

Posted by Maxhrk   USA  (76 posts)  Bio
Date Fri 18 Jun 2010 05:39 PM (UTC)

Amended on Fri 18 Jun 2010 05:49 PM (UTC) by Maxhrk

Message
since atcp2 has came out for lusternia and achaea as well.. so i am trying to make it work but with no success. Athough i did study Nick's atcp plugin to see how he does communicate with the server.


anyway.. here the code(and it does look dirty for now..)



local CLIENT_ID = "MUSHclient " .. Version ()
local IAC, SB, SE, DO = 0xFF, 0xFA, 0xF0, 0xFD
local ATCP2 = 201

function OnPluginTelnetRequest (type, data)
	Note("TYPE: " .. tostring(type) .. "\nDATA:" .. tostring(data))
	if type== ATCP2 and data == "WILL" then
		SendPkt(string.char(IAC, DO, ATCP2))
		return
	end
	if type == ATCP2 and data == "SENT_DO" then
	ColourNote("blue", "black", "attempting to enable ATCP2\n")
	ColourNote("white", "black", "\n")
	SendPkt(string.char(IAC, SB, ATCP2) .. 
			[[ Core.Hello { "client" : "Mushclient", "version": "4.51"} ]] ..
			string.char(IAC, SE))
			
	SendPkt(string.char(IAC, SB, ATCP2) .. 
			' Core.Supports.Set [ "Char 1", "Char.Skills 1", "Char.Items 1" ] ' .. 
			string.char(IAC, SE))
	end
			
end

function OnPluginTelnetSubnegotiation (type, option)
	Echo("Telnet Subnegotiation [ TYPE: " .. tostring(type) .. "\n" ..
		"OPTION" .. tostring(option) .. "]")
end


telnetsubnegotation function is just there to see what server will send with all the cool stuff i am going to see.

so far when i tried to see what server will send after negotated with it. It didn't send any message with no degree of success on my part.

:\

So is there a problem with my code?
Top

Posted by Maxhrk   USA  (76 posts)  Bio
Date Reply #1 on Fri 18 Jun 2010 05:48 PM (UTC)

Amended on Fri 18 Jun 2010 06:08 PM (UTC) by Maxhrk

Message
ah, i found a problem, i forgot to define the variables.. bah.. i added it now, for some reason it cause untrapped error for achaea.

edit: for all that are interested in GMCP document, here.

[url]http://www.ironrealms.com/gmcp-doc[/url]
Top

Posted by Maxhrk   USA  (76 posts)  Bio
Date Reply #2 on Fri 18 Jun 2010 06:27 PM (UTC)
Message
i learned something more about how to communicate with the achaea server.. it seem that i just need to ignore the next 'SEND_DO' otherwise i will end up responding the same handshake repeatedly.

i did it by letting my plugin respond when its connected then disable it then enabled it(after login) and got telnet subnegotiation afterward that displays vitals and all that

weird anyway.
Top

Posted by Maxhrk   USA  (76 posts)  Bio
Date Reply #3 on Fri 18 Jun 2010 06:45 PM (UTC)

Amended on Fri 18 Jun 2010 06:54 PM (UTC) by Maxhrk

Message
ok that was interesting... it seem that i managed to fix some bugs on my side and i managed to root up the bug that cause massive lag to the server by my mere plugin.

anyway, here is a workable code using GMCP(or ATCP 2) that you can play with in your plugin.. again, here dirty and a updated code:


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="ATCP2"
   author="Richard M"
   id="29a4c0721bef6ae11c3e9a82"
   language="Lua"
   purpose="Richard's dirty GMCP plugin"
   date_written="2010-03-09 10:04:32"
   requires="4.50"
   version="1.0"
   >
<description trim="y">
<![CDATA[

]]>
</description>

</plugin>


<!--  Script  -->


<script>
<![CDATA[

local CLIENT_ID = "MUSHclient " .. Version ()
local IAC, SB, SE, DO = 0xFF, 0xFA, 0xF0, 0xFD
local ATCP2 = 201
local ATTEMPTED = false

function OnPluginTelnetRequest (type, data)
	Note("TYPE: " .. tostring(type) .. "\nDATA:" .. tostring(data))
	if type== ATCP2 and data == "WILL" and ATTEMPTED == false then
		SendPkt(string.char(IAC, DO, ATCP2))
		return
	end
	if type == ATCP2 and data == "SENT_DO" and ATTEMPTED == false then
		ColourNote("blue", "black", "attempting to enable ATCP2\n")
		ColourNote("white", "black", "\n")
		SendPkt(string.char(IAC, SB, ATCP2) .. 
			[[ Core.Hello { "client" : "Mushclient", "version": "4.51"} ]] ..
			string.char(IAC, SE))
			
	SendPkt(string.char(IAC, SB, ATCP2) .. 
			' Core.Supports.Set [ "Char 1", "Char.Skills 1", "Char.Items 1" ] ' .. 
			string.char(IAC, SE))
	ATTEMPTED = true
	end
			
end

function OnPluginTelnetSubnegotiation (type, option)
	Note("Telnet Subnegotiation [ TYPE: " .. tostring(type) .. "\n" ..
		"OPTION" .. tostring(option) .. "]")
end

function OnPluginTelnetOption (data)
  Note ("Received option string ", tostring(data))
end -- function OnPluginTelnetOption


]]>
</script>


</muclient>



Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #4 on Fri 18 Jun 2010 07:33 PM (UTC)
Message
Keep up the good work. :) You'll need to use some kind of JSON parser to get at the data, though. LuaJSON is a decent pure-Lua library. Fast on decoding, but slow on encoding.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Maxhrk   USA  (76 posts)  Bio
Date Reply #5 on Fri 18 Jun 2010 07:39 PM (UTC)
Message
thanks... after i has fun with it, then i shall clean up codes and use it with PluginBroadcast to send the gmcp message to other plugins that will need it.

fun fun fun.
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #6 on Fri 18 Jun 2010 07:42 PM (UTC)
Message
Maxhrk said:

thanks... after i has fun with it, then i shall clean up codes and use it with PluginBroadcast to send the gmcp message to other plugins that will need it.

fun fun fun.


As an alternative, you could use my PPI library and let other plugins register callbacks with your plugin. Then you can just convert the message data from JSON to a Lua table, then call the plugin callbacks with it.

That's not really a shameless plug. I just don't like using PluginBroadcast.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Maxhrk   USA  (76 posts)  Bio
Date Reply #7 on Fri 18 Jun 2010 07:48 PM (UTC)
Message
okay, i will keep that in my mind to use PPI.
Top

Posted by Maxhrk   USA  (76 posts)  Bio
Date Reply #8 on Fri 18 Jun 2010 08:07 PM (UTC)
Message

function OnPluginTelnetSubnegotiation (type, option)
	local decodedtable
	decodedtable = json.decode(tostring(option))
	tprint(decodedtable)



this code seem don't work too well... The given error message is 'Invalid JSON data'.
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #9 on Fri 18 Jun 2010 08:13 PM (UTC)
Message
Maxhrk said:


function OnPluginTelnetSubnegotiation (type, option)
	local decodedtable
	decodedtable = json.decode(tostring(option))
	tprint(decodedtable)



this code seem don't work too well... The given error message is 'Invalid JSON data'.


Yes, that's because you're getting "Module.Message JSONdata" and you're passing all of that in, rather than just the JSONdata. You should split it at the space and take everything right of it.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Maxhrk   USA  (76 posts)  Bio
Date Reply #10 on Fri 18 Jun 2010 08:37 PM (UTC)
Message
okay this seem to be one of my few moment of 'doh' moment. :p


okay, i got it all working.. so far i noticed that char.vitals will always results in a string, not table. for score.status, items, etc usually results in table. interesting stuff!
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #11 on Fri 18 Jun 2010 08:42 PM (UTC)
Message
Sometimes it's an object (table) or array, sometimes it's raw data. That's one of the things I don't really agree with in this protocol, since it makes it a little harder to deal with generically, and it depends on how strictly your JSON parser conforms to the JSON standard. The standard requires that all data be inside an array or an object (i.e. the top-level item), but some parsers - and note that this isn't really a bad thing, per se - allow any data type to be the top-level item.

The most cross-parser way to do it would be to check the first character of the JSON data. If it's anything but a [ or {, wrap the whole thing in [ ] first, then decode it, then get the [1] element of the resulting table. If your parser allows it though, it's not a big deal.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Maxhrk   USA  (76 posts)  Bio
Date Reply #12 on Fri 18 Jun 2010 09:35 PM (UTC)

Amended on Fri 18 Jun 2010 09:36 PM (UTC) by Maxhrk

Message
Twisol, where is your PPI library link? So, I can look up the information about it and how to use it. Thanks!
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #13 on Fri 18 Jun 2010 10:03 PM (UTC)

Amended on Fri 18 Jun 2010 10:04 PM (UTC) by Twisol

Message
It comes with any of my ATCP-based plugins; I'll put it in a pastebin for you though [1]. I don't have much documentation on it, sadly, but you can get my ATCP plugin and any of the ATCP-based plugins to see how it works on both sides. [2]

Save it as 'ppi.lua'. I recommend using a structured-plugin approach, so you can keep the library packaged with the GMCP plugin. You can look at the ATCP plugin's structure, and see [3] and [4] for details.

[1] http://mushclient.pastebin.com/ELsmEDzb
[2] http://jonathan.com/?page_id=29
[3] http://www.gammon.com.au/forum/?id=10011&page=999
[4] http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=10081

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Nick Gammon   Australia  (23,099 posts)  Bio   Forum Administrator
Date Reply #14 on Fri 18 Jun 2010 10:39 PM (UTC)
Message
Quote:

Sometimes it's an object (table) or array, sometimes it's raw data. That's one of the things I don't really agree with in this protocol, ...


Yes and this is where I started tuning out of the design process. In order to "make it easier" the protocol does not actually send standard JSON.

According to the JSON spec (at: http://json.org/)


JSON is built on two structures:


  • A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.

  • An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.



So, a message (from the GMCP spec) like this:


Core.Ping 120


The "120" isn't JSON (it is neither a name/value pair, nor is it an ordered list of values). Sorry guys.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


295,835 views.

This is page 1, subject is 9 pages long: 1 2  3  4  5  6  7  8  9  [Next page]

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.