« I opened a can of whoop-ass on that pesky laptop... | Main | Geourl »

Online dice rolling

When we play D&D on Friday nights we need to roll dice. When you’re playing over the Internet it would be nice if everyone could actually see the roll. The solution we came up with a while back was to write a chat program  that had a built-in “roll” command. You could say d20, which means roll a 20–sided die and tell me the result. Or, roll 2d6 which rolls a 6–sided die twice and adds the result.

Writing a chat program is like network programming 101, but I still never got motivated to do it.  So we’ve been using the honor system so far.

Last night I got motivated to be lazy and productive at the same time. I googled for “python chat program” and came up with a Python chat client called Nekkid chat written by Jari Rytilahti. It’s a chat program written in Python (duh) that works with the Naken chat server written by Michael Kohn.

I downloaded and installed the Naken chat server and installed it on my Debian linux server. I use a New Moon dedicated server by Dreamhost. The server is written in straight C and took, oh, about 0.5 seconds to compile and run. It took me longer to review the supplied configuration file than it did to download it and get it running.

Once it was running, I fired up the Nekkid chat client and connected to the server with no problems. I looked at the source code (the beauty of having it written in Python) and saw where I could peek at the client chat input text.

I detected the first word, “roll” and parsed out nds, where n = the number of dice (which can be omitted) and s is the number of sides on the die. I replaced the input text with the result of the evaluation and sent it to the server.

Obviously this is not a “secure” change. A better change would be to detect the command on the server and output text that couldn’t otherwise be faked by a client.

I’ll probably make incremental enhancements from here on out, but it works and that’s probably good enough.

 

 

TrackBack

TrackBack URL for this entry:
http://www.primordia.com/blog/mt-tb.cgi/259