Firebase from Scratch, pt II: Diving In
In a series of posts we’ll do “Firebase From Scratch”, an introduction to Firebase and its concepts and ideas. Hopefully, reading this series will give you a firm grasp of what Firebase is and what it can do.
- Part 1: Introduction
- Part 2: Diving In
- Part 3: A Maven Interlude
- Part 4: Games, Services and Tournaments
- Part 5: What’s In a Server Game Anyway?
- Part 6: Activating Games
- Part 7: Actions On The Table
- Part 8: Services
- Part 9: Custom Authentication
So, you want to write a multi-player game? And perhaps you’re considering Cubeia Firebase as your platform? Then we’ll take a good look at what you actually need to know, and need to do to get going. We’re going to keep it short, and then expand on the different items in later posts.
You need a game client, and should decide what language or platform you’ll be using. If you want to deploy it to the web, perhaps flex would be suitable. If you want a heavier client, you should probably go for C++ or Java. For the rest of these posts we’ll assume you went the Flex / Flash track, but Firebase supports Flex and Flash, Java, C++ and C# so it is really your choice!
The Firebase Protocol
The client API of your choice comes with ready made command objects for a number of actions that are taken care of by Firebase, and that you don’t have to do yourself! They are taken care of by the platform, and include:
- login / logout
- join / leave game
- watch / unwatch game
- query / subscribe lobby
- send action to game / service
In most cases, the Firebase commands are request / response. You will, for example, send a “login” command to the Firebase servers, and then wait for an answer which will be either a “yes” or a “no” (we’ll discuss Firebase and authentication / login later). The “send action to game” is how you communicate with your game, which is running inside Firebase, and for more on that, see below.
The Firebase protocol takes care of many “generic” actions for you, but you will need to have a protocol specific to your game.These are the actions your players can make, such as:
- fire weapon
- place bet
- do the macarena
the actions you actually need will be apparent when you start writing your game, but at this point you should figure out what form the commands will take. Firebase will treat your own commands as binary data, that is to say, you can use any format you want. Many will use XML or JSON which are widely supported in all languages. For larger projects though, we’d recommend you to look at protocol generation schemes such as Google’s Protobuf as it scales better and nicely separates your protocol from your code which is something that becomes important as the game grows in size. You can even use the protocol generation used by Firebase, called Styx; This generator takes a specification in XML and produces serialization factories and command objects in a variety of languages.
Building Server Code
How you build your client code is very much up to you and what IDE you’re using. But for the server side code we strongly recommend use Apache Maven for building, simply because there’s some neat plugins and tools already built for you to simplify your life. It is still your choice though and you can use anything from Ant to batch scripts.
You probably want to store results and data somewhere. Firebase will not impose any choice on you and you’re free to use whatever data storage you like best. Firebase contains build in support for most relations databases, such as MySQL or Oracle, via JDBC and JPA, but you can equally well use column databases or simple text files, the choice is entirely up to you!
Ready. Set. Go!
So download what you need. If you went with the Flex/Java route you will need a Java SDK installed together with Apache Maven. Strictly speaking you don’t need an IDE, you could use a simple text editor, but normally you will want to install IDE:s such as Eclipse before going on. And with that done you should be ready to dive in head first in the traditional “hello world” tutorial on our wiki. Or if your feeling brave, the “quickstart extreme – not for the faint hearted“!
Next installment will look closer at the server game itself, its components and functions. Stay tuned!