The One Man MMO Project: International Cascade of Fail
I like to do little features in the evening, separate from the bigger stuff I work on during the day. Sunday evening I thought a Terms of Service (TOS) screen would be a nice easy feature.
Little did I suspect I would encounter an international cascade of fail trying to get the TOS to actually work.
An easy solution just wasn't going to make the lawyers happy. We need secure storage and transit for the TOS document to the player. Sigh.
So I coded a TOS step into the login sequence, added a packet to send the full TOS text to the client, modified the login server to be able to load the TOS from the database, created TosTool to load the TOS from a file and store it in a database table, added support for multiple TOS documents and versioning, added a page handler for the TOS form to the client, and I was ready to give it a go. Most of that was done Sunday before I went to bed.
Monday morning, I needed a sample document for debugging so I grabbed a copy of the TOS from Turbine's Lord of the Rings online. A lawyer will write the real TOS for my game sometime later. I pasted the text into the HTML page design for the TOS screen and did a couple of little edits. Then I tried to load the file into the database. TosTool ran for ages, and ages, and ages. Hmmm.
Fail #1: The class that reads text files, which I haven't touched in a year, has a bug where if the last line of the text file it is reading doesn't have a trailing carriage return, it loops back to the beginning of the file and reads the whole thing again, over and over and over. Fixed bug #1.
Fail #2: TosTool was now able to read the file and write the TOS text into the database. Looking at the results in the mysql client, there were long sequences of junk characters sprinkled throughout the document. Ewwww... Taking a closer look at the input file, it is UTF-8 encoded and includes the trademark symbol and directional quotations -- lots of non-ascii characters in otherwise English text. Internally my game uses UCS-2, so once data is into the game, there isn't much danger of it messing up - at least for EFIGS languages. The game was correctly identifying the input file as UTF-8, but it turns out the code that converts the UTF-8 to UCS-2 (which I wrote ages ago and probably never used) is all sorts of broken. Fixed bug #2.
Fail #3: Ran the fixed UTF-8 code, and it is still all sorts of broken. Looking at the character comparisons I notice that visual studio is displaying the char constants as negative. Ack! So I learned that Visual Studio defaults to signed char -- a default I've never found particularly helpful. Added the /J switch to the project. That fixed the comparisons, but Visual Studio still stubbornly displays the character constants as negative in the debug view. Boo.
Fail #4: Ok, so the TOS text is loading nicely into TosTool and writing neatly to the database. Looking at the database in the mysql client, it looks good now. The MySQL client prints out a few junk characters, so it obviously doesn't support UTF-8, but at least the strings of junk are the right length now.
Fail #5: Next up was to load the TOS from the database into the service that manages logins. I run that. ASSERT. In a function called AsciiToUnicode. Huh? The data is supposed to be UTF-8! It turns out that the database classes have support for UTF-8 while writing to the database, but the reading routines don't, they think everything coming from the database is ASCII. I've never used anything but ASCII in any of the data I've written before so I never noticed this oversight.
Fail #6: Looking closely at the loaded TOS again, there were still some anomolies. MySQL has certain characters it doesn't like in queries. These characters are where SQL injection attacks come from. Checking into it, strings were being escaped while going to the database, but not unescaped coming back. Again, I haven't put a lot of fancy text into the game's database, so I never noticed.
So at this point, I'm thinking I need to do some more work on my unit tests. But, no time for that now, I've got a broken game to fix. Soldiering on...
Fail #7: With the TOS now downloading to the client, I notice it takes foreverrrrrrrrrr to do it. Looking at the debug trace, the data is coming down fine, one K, every second. Hey! Transmission rate limiting works! Kinda sucks when transferring a 21K TOS document though. So I modified the server to increase the transmission rate limit while sending the TOS so it takes just a couple of seconds.
Success. It is Wednesday afternoon and I have a working TOS screen. And a whole whack of good bugs fixed. Never underestimate the amount of work required for an easy little feature.
Copyright (C)2009-2013 onemanmmo.com. All Rights Reserved