G'day! I'm an Indie developer, lone-wolf style! I'm a Christian, I'm Australian, and for some reason I live in Canada. KarBOOM is my debut title, coming out for Windows, Mac & Linux this Tuesday!

Report RSS Programming is easy

Posted by on

As I've been trying to get online play into KarBOOM, the first thing I've had to deal with is the hardships of setting up a server list. I'm often working away, watching my game/application/project come to life, and think: Programming is easy. Then I get stuck on something and get infuriated at how difficult it is. How terribly buggy can computers be? Why do I insist on working in such a frustrating field? Why did I stop working at that fast-food restaurant!?

Last night I was working on the server list, and all was looking fine and dandy. I need the lobby to be up 24/7, but I'm not on the kind of budget where I can have a dedicated server meeting that need, so the obvious choice is to have the server list on an online database on a free host, and have the game interact with the server list through http posts. There are plenty of free hosts that provide PHP and MySQL support -- I went with 000webhost.com. I've had no trouble with them so far, but until KarBOOM Online goes public it's not exactly under much stress.

I'd written a server list system using the same engine and the same host before, so I thought getting it working would take no time at all. In under an hour clients could request the server list and parse the resulting information into an interactive lobby system. Minutes later, servers could add themselves to the list.

But then came the heartbeat system.

Ideally any server that goes offline informs the server list when it does so. But I need to account for hosts being unexpectedly disconnected from the internet, resetting their computer, or ending KarBOOM improperly. To prevent a dead server being left on the server list with no one able to connect, each server sends a "heartbeat" every few seconds to the server list, letting it know that it's still alive. Then, when a client is looking for a host, the server list can eliminate any hosts that haven't sent a heartbeat in a while. This is also something that I'd done before, and so I knew it would work.

But it didn't. The heartbeat was sent, but the database wasn't updated. For the life of me, I could not see what was going wrong. I literally spent hours trying to figure it out, filling my code with printf's and inserting all sorts of tests into the PHP server -- all of which worked without trouble, but did nothing to show me what was going wrong.

I'd updated my engine since the last time I'd written such a system, so I began to blame the engine. Why won't you work? What have you done to break my perfect system!? Make it WORK!!

And then at 1 this morning I noticed it: I'd given the wrong name for the field that keeps the time of the last heartbeat. I changed one variable name, saved, and tested it; and everything just worked. Just like every time in the past when something had gone wrong, I was kicking myself for thinking that for once the software I was using was faulty -- for thinking that for once it wasn't my fault.

Today I'll be getting back to work, getting clients to connect to servers and getting them to communicate with each other properly. And the whole time I'll be thinking: Programming is easy, but it's not idiot-proof.

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: