Pardon the above puns. I’ve recently spent the better part of the past 4 hours hacking away at python and xchat’s annoying-as-hell python plugin system.
Don’t get me wrong, i like xchat, and i have a great amount of admiration for the features of the python language, but, the xchat scripting interface seriously lacks some features (such as the ability to test whether a module has been loaded or not), and the python language seriously lacks some features (such as the ability to test whether a module has been loaded or not, if def’s have been def’d or not…).
The problem exists as such: I have a script that launches on freenode-connect, that sets up some user commands that i find useful, such as shorthand raw removes, auto-voice granting and multi-channel joins on successful hostmask application. This is all written in python, because the alternatives were perl and TCL. I’m unfamiliar with TCL, and i’d sooner write in python than in perl (i may start reconsidering this last statement…). It seems however, that many of the networks i regularly connect to are unstable, such that over the course of a day, i might get disconnected a few times. When IRC detects that the network is available again, it’ll auto-reconnect me to the server, auto-launches the launcher script, and then tries to rejoin me to all the channels that i was in.
This causes several problems:
First, now i’ve rejoined all my old channels, except my hostmask is no longer in place. This is uncool to high degrees, as there are reasons why people get these hostmasks. Secondly, since some of my channels require my hostmask be set in order to join, i’m only in about half the channels i thought i was in. If for some odd reason i was afk over the course of the disconnect, then i’ll find myself missing out on portions of valid discussion. Thirdly, since xchat reloaded the auto-launch script, i now have a dual-map of all my shortcut commands, so typing something like /music or /camel will yield small-scale floods, especially after 4 or 5 disconnects. Not cool.
So, this evening, i decided to find a way to solve each of these problems. The third problem was easiest to solve, which was simply to have a wrapper loader that tries to unload any existing command modules and then, on success or fail, loads the command module, so that there can only be one in existence at a time. However, this didn’t solve my first two problems, which basically required that i somehow leave persistent data across disconnects, but preferably not by writing to file, because that would leave persistent data across chat sessions, where i might log into a different network (say, home vs school vs work) and not want the same settings to autoload. (security related)
But, since you can’t ifdef a variable in python, and python tosses errors like hardballs if you try accessing a not-explicitly-instantiated variable, this is impossible outside of having some external scope. I toyed around with this for a while and discovered that each script is loaded in it’s own separate scope, which is not capable of talking to others.
So at this point, i’ve resigned myself to the fact that i’m going to need to write a global-level script (Rather than server-specific) because it’s pretty much the only way to hack around these problems, ie, having data survive disconnects. Of course, this opens me up to one specific kind of exploit, something i really don’t like to have to do… but hopefully nobody will ever figure out exactly what that exploit is…. humm ho….
I wrote a midterm today. I got halfway through the last question when the time ran out. At the bottom i scribbled:
“The rest of this computation is left as an exercise to the marker”
After that, I returned to the common room where i spent the better part of an hour or more discussion with Jeremy and a couple others, the implications of adding a necromancer and zombies to the game “Mafia” that some of you may be familiar with. For a halloween, i suppose that was somehow… appropriate, despite all the weird looks our conversation drew.
braaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaains.
Currently Listening to:
[ Final Fantasy 8 Soundtrack ] Nobuo Uematsu - Find Your Way