Bunnies: Now With Chat
One of the hidden features of the Bunnies server was the ability to send and receive text messages. One of the hidden features of the Bunnies client was to receive text messages. So adding text chat to Bunnies was not that difficult. The main issue with the server was a gotcha in PHP. I’m sending up a byte that represents the message type. When switching based on that type you can’t use the numerical value of the byte. Say I send up byte 100 for a text message. I can’t check for the value 100 to process that text message. Instead you have to switch on the case chr(100). I’m guessing the issue is that PHP treats the case 100 like it’s the string “100″ and not the integer value.
Hooray for duck typing. Sometimes strongly typed languages are nice. Fortunatly languages like PHP provide ways to force things to operate the way you want.
On the client side there was already a switch case in place to handle text messages but it was commented out. In order to add messaging support I had to add in a message handler class which takes care of keeping track of all received messages and the current state of the user’s latest entry. I also had to add a new font for messages and allow the user to switch on text entry mode. Pressing the “~” (tilda) key will display the input area and the most recent received messages up to 10. It also switches the keyboard entry from moving around to text entry. Press it again to go back to game mode. The game doesn’t pause just because you’re in text entry mode.
One of the quirks I found with C# is that there are two keyboard handling events. key_up and key_down get you the integer value of the key you pressed (no real relation to ASCII) and key_press gets you the character. So if the user hits shift + “c” you get the char “C” which is really really nice. Bunnies now handles all three of those events since movement is based on the interger value and text input is based on the char value.
One of the features of Bunnies is that in order to send and receive messages other than your own you have to be logged in. That requires an account with the Bunnies web-site.
I’ll be doing some more testing to verify that all works and then hopefully I’ll have a new release of Bunnies out in less than a week. It may even include the ability to see other players who are in the same map as you.
Leave a comment
You must be logged in to post a comment.