Game engine + FTP == awesome stuff
For a couple of days I was tossing an idea of integrating FTP into my game engine. Yeah, it totally sounds crazy, and this was my first thought too. But I have a very good reason why. The iOS game, I’m currently working on, has a level editor only on Windows. To test and tweak the level for a game I have to edit it with the editor on Windows, then commit to SVN, check out it on Mac, build the game, and run on iPhone. That’s quite a path and wastes a lot of time. All this makes quick iterations impossible, and the worst part is that all this repetition is very annoying and demotivating.
At first, an idea flashed in a head about doing it all myself , but I was smart enough to quickly reject it. So, I’ve went to see if there were any solutions ready, and googled for FTP server or client code. I guess my googling skills are dusting, as it took some time, but I finally came across ftplib. It’s a small and portable library implementing FTP client’s protocol. On Windows it worked without any modifications. On iOS I wasn’t so lucky, but the only problem was that Xcode’s compiler doesn’t define “__unix__”. So after modifying couple #ifdef’s it was ready to go. Overall it took me a couple of hours to get it working, mainly because the first FTP server I’ve tried was crashing. But then I came across ftpdmin, which worked flawlessly, and the best thing about it is that its distribution is only 1 exe file. Here’s a screenshot showing ftpdmin serving a level to the game engine:
Whole code for this takes just like 20 lines or so. Here’s the first hackish implementation (with a bonus buffer overflow!) that got the snowball running:
netbuf* control;
FtpInit();
if (FtpConnect("192.168.2.100", &control) == 1) {
LogInfo("Connected to ftp");
FtpLogin("game", "game", control);
netbuf* data;
if (FtpAccess(gLevels[mLevel].mFile, FTPLIB_FILE_READ, FTPLIB_IMAGE, control, &data) == 1) {
LogInfo("Ftp file open");
const int size = 102400;
char buf[size];
int read;
read = FtpRead(buf, size, data);
if (read == -1) {
LogWarning("Error reading ftp file");
} else {
buf[read] = 0;
LogInfo("Ftp file read");
}
FtpClose(data);
} else {
LogWarning("Couldn't open ftp file");
}
FtpQuit(control);
} else {
LogWarning("Couldn't connect to ftp");
}
So now when I’m working on levels I simply launch ftpdmin on my Windows machine, and the game on my iPod automatically downloads the levels. I play it, edit on Windows, save it, restart the level and it’s ready to be played again. Fast and effective. Yay for iterative development! The only thing I hate is that it has to use Wi-Fi… I wish iPods could access network through it’s USB cable.
The best thing about this is that you don’t need to stop with level editing. Just imagine editing and instantly downloading scripts.

