The Twilight Sun

MUSHclient, cont.

by Jonathan C. on Mar.07, 2010, under Uncategorized

So… Lately, I’ve been playing around a lot with MUSHclient’s source code. It’s pretty interesting to see how a program I’ve used for a long time actually functions (even though he uses the Whitesmiths indentation style, which I cannot abide. I’ve always been a fan of the Allman style, myself). I’ve actually made a few relatively minor contributions, which I’m pretty happy about. :) I also contributed (and I suppose maintain?) a pair of Visual Studio 2005 solution and project files, and helped ease the compilation process under it. Nick uses VC6, which is really old these days, but it’s what he used when he first started, and he’s not exactly willing to shell out hundreds of dollars to update. (I can’t honestly blame him.)

At any rate, there was a discussion about a new protocol Nick had scratched out as a hidden-data-transfer medium for MUDs, similar to ATCP and ZMP. It came about that JSON was a perfect fit for the protocol’s semantics, so I modified MUSHclient to add a scripted interface to a previously-created JSON library (called json-c). I’m really happy with how it turned out. I mean, I only wrote the glue between Lua and the library, but it was pretty interesting designing the glue nonetheless. The interface hasn’t been officially added to MUSHclient (yet?), but it’s in my GitHub fork of MUSHclient. (You can find my additions here, if you’re into that sort of thing)

Here’s an example of the interface in action:

chunk = json.encode{1, 2, 3, {foo = "bar", baz = {10, 20, 30}}}
print(chunk.to_json())

Output: [ 1, 2, 3, { "foo": "bar", "baz": [ 10, 20, 30 ] } ]

Admittedly, that’s pretty boring. The glue code is more interesting, but the end result is still useful. In my (admittedly very brief and minor) tests, json.decode():to_lua() was faster by 2ms than loadstring()(), which was a little surprising. JSON also has the advantage of being rather well supported by many languages, at least indirectly. The protocol specification Nick originally proposed used Lua itself as the data format, which worked but brought along some odd issues like defining or calling functions within the data. I rewrote a Lua protocol snippet as JSON and compared the two, and they were nearly identical, so there’s really not much to lose by using JSON instead.

With that pretty much done, now I’m working on converting MUSHclient’s help files from .hlp to the .chm format. Is it a lot of work? You bet. But at some point, somebody has to do it… But I’m using an sqlite3 database, Lua, and ltp to autogenerate the files, so at least it’s entertaining.

~Jonathan

:, ,

2 Comments for this entry

  • Keneanung

    Hey Jonathan,

    I’ve been playing with the new hidden protocol now a little and I found another way to encode and decode JSON messages.
    There is a JSON library, that is native for LUA (found at http://json.luaforge.net/), which works pretty well too.
    I’m not sure what would be easier to implement for each supported Scripting language, but I thought I throw it in.

    Cheers
    Keneanung

  • I. N. Hubenthal (a.k.a. Jerminyn)

    Hi there, I was just wondering if you could give me a hand setting up some things with the MUSH Client. E-Mails there, the questions are kinda in-depth though, so I won’t fill your screen with mindless babble on a comment post.

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...