The new commentary system in detail
Thursday, June 24 2010 @ 10:35 PM UTC
Hey, folks!
You'll have noticed by now that there's a new commentary system up and running on the Island. I thought I'd take a few minutes to explain what it does and why I wrote it.
The most obvious change is... well, obvious. There's an extra channel in Outpost chat areas, called "Banter." This is there so that casual everyday chat doesn't get mixed up in roleplaying, and vice-versa. There's little need for me to talk about this, since... well, you've seen it. :)
The bigger changes happen under the hood. Hit "Full Article" for the rest.
The old commentary system in place on Improbable Island was very close to how the original Legend of the Green Dragon commentary system worked. The icons for race, weapon and donation were added by a module after the commentary had been retrieved and styled; each time the page refreshed, all this information had to be looked up again.
The effect of this was that if you posted a message as a Midget (complete with the obligatory profanity and arse-scratching), then went and killed the Drive and came back as a Joker, the messages you posted would show you talking as a particularly unpleasant and foul-mouthed Joker. The same went for weapons.
Obviously the constant refreshing generated a massive amount of server load, too.
In the new commentary system, the message you post is passed through a hook before being added to the database. There's an "info" column which stores a serialized array containing whatever information we'd like to capture; clan, race, weapon, avatar and what-have-you. The comment you post is split up into the talkline (usually "says," but some clans use different talklines) and the comment itself. This makes it easier to take it apart again later, if we choose to.
When you view a page of commentary, a hook fires that runs through the commentary buffer (meaning the 25 or so messages retrieved from the database) and changes things based on what's in the $info array.
So, for example, the module that handles Race icons behaves like this. When you post a comment, if your Preferences are set to show your race, it'll check your Race and put the appropriate icon into $comment['info']['icons'], under ['race']. Then, when you view a commentary area, the module will first check to see if the you want to see race icons. If you do, it exits and lets the core commentary system process the Race icon as normal. If you don't, it just unsets $comment['info']['icons']['race'].
Other ideas came up, too. For example, a simple check to see if $info['skipcomment'] was set can give us more things like GREM and AFK; in the module, we just check to see if the comment is "afk" and then we set $comment['info']['skipcomment'] to true, so that the comment doesn't get entered into the database. Then, we do our fancy-pants processing of the command entered.
The functions that get commentary, style the individual commentary lines, and display the commentary, have all been separated out (they were all pretty much one function before). This means that we can do things like AJAX chat by just re-using the functions to get and style the commentary, and writing a new function to display it. (AJAX chat coming one day!)
This new system started off as just something to reduce server load, but it became a lot more flexible. For example, using the same commentbuffer processing hook, we can run through the comments and change them however we like. In my folder of "Ideas I'll Probably Never Use And With Good Reason Too," there's a module that does this:
function commentaryicons_paranoia_dohook($hookname,$args){
global $session;
switch($hookname){
case "commentbuffer-preformat":
foreach($args AS $key=>$vals){
$args[$key]['comment']="/me mutters "`#Bad things are coming for ".$session['user']['name']."...`0"";
}
break;
}
return $args;
}
That's right - if a player's eaten some dodgy mushrooms, he or she can have a really bad trip in which all their friends walk around muttering about how they're in for something terrible. :D
...yeah, there's a reason I have a separate folder for modules that would be a Bad Idea to actually go live with. ;)
You'll have noticed by now that there's a new commentary system up and running on the Island. I thought I'd take a few minutes to explain what it does and why I wrote it.
The most obvious change is... well, obvious. There's an extra channel in Outpost chat areas, called "Banter." This is there so that casual everyday chat doesn't get mixed up in roleplaying, and vice-versa. There's little need for me to talk about this, since... well, you've seen it. :)
The bigger changes happen under the hood. Hit "Full Article" for the rest.
The old commentary system in place on Improbable Island was very close to how the original Legend of the Green Dragon commentary system worked. The icons for race, weapon and donation were added by a module after the commentary had been retrieved and styled; each time the page refreshed, all this information had to be looked up again.
The effect of this was that if you posted a message as a Midget (complete with the obligatory profanity and arse-scratching), then went and killed the Drive and came back as a Joker, the messages you posted would show you talking as a particularly unpleasant and foul-mouthed Joker. The same went for weapons.
Obviously the constant refreshing generated a massive amount of server load, too.
In the new commentary system, the message you post is passed through a hook before being added to the database. There's an "info" column which stores a serialized array containing whatever information we'd like to capture; clan, race, weapon, avatar and what-have-you. The comment you post is split up into the talkline (usually "says," but some clans use different talklines) and the comment itself. This makes it easier to take it apart again later, if we choose to.
When you view a page of commentary, a hook fires that runs through the commentary buffer (meaning the 25 or so messages retrieved from the database) and changes things based on what's in the $info array.
So, for example, the module that handles Race icons behaves like this. When you post a comment, if your Preferences are set to show your race, it'll check your Race and put the appropriate icon into $comment['info']['icons'], under ['race']. Then, when you view a commentary area, the module will first check to see if the you want to see race icons. If you do, it exits and lets the core commentary system process the Race icon as normal. If you don't, it just unsets $comment['info']['icons']['race'].
Other ideas came up, too. For example, a simple check to see if $info['skipcomment'] was set can give us more things like GREM and AFK; in the module, we just check to see if the comment is "afk" and then we set $comment['info']['skipcomment'] to true, so that the comment doesn't get entered into the database. Then, we do our fancy-pants processing of the command entered.
The functions that get commentary, style the individual commentary lines, and display the commentary, have all been separated out (they were all pretty much one function before). This means that we can do things like AJAX chat by just re-using the functions to get and style the commentary, and writing a new function to display it. (AJAX chat coming one day!)
This new system started off as just something to reduce server load, but it became a lot more flexible. For example, using the same commentbuffer processing hook, we can run through the comments and change them however we like. In my folder of "Ideas I'll Probably Never Use And With Good Reason Too," there's a module that does this:
function commentaryicons_paranoia_dohook($hookname,$args){
global $session;
switch($hookname){
case "commentbuffer-preformat":
foreach($args AS $key=>$vals){
$args[$key]['comment']="/me mutters "`#Bad things are coming for ".$session['user']['name']."...`0"";
}
break;
}
return $args;
}
That's right - if a player's eaten some dodgy mushrooms, he or she can have a really bad trip in which all their friends walk around muttering about how they're in for something terrible. :D
...yeah, there's a reason I have a separate folder for modules that would be a Bad Idea to actually go live with. ;)