Simple Messaging System with Redis and Node.js

Hey all, been a while since I posted anything constructive, I’ve been so busy wasting my time creating games for Facebook Instant Games Messenger (I will do a proper write up with my analysis and final findings / thoughts on this very soon). Not all has been lost working on Instant Games however. Two of my games required an instant messaging system that enables me to send real-time messages between players which ironically the Instant Games SDK doesn’t cater for. So I created one using Node.js and Redis (these two bad boy pieces of tech together are like sweet music). You can grab the code from Github here.

Note that you will need to install this to your own server, I like to run most of my node modules using PM2. So to get the messaging system up and running just run pm2 msys. The server looks to the /msys endpoint, but you can change this in msys.js if you need it to go elsewhere. No, I don’t answer questions on how to set up servers and mess with Apache config files because I hate all that junk, it gets in the way of my actual coding which I do enjoy :). If you cannot do this stuff yourself then you probably should be paying someone else do this for you.

Oh word of warning, any messages sent will time out after 7 days (this is to keep Redis memory usage down), but you can extend this to whatever time limit you like. Messages are queued, when you collect the pending messages it collects them all and deletes them from the database.

Ok, how to use client side? Here is a simple class (erm I mean collection of functions) with an awesome original name that I ripped out of one of my games for you guys to use:

[sourcecode language=”js”]
var Backend = {};

Backend.SendMessage = function(data, done_callback)
{
var url = "https://yourdomain.com/msys?c=s&t=<your token>";
url += "&g=1";
url += "&u=" + data.to_id;
url += "&d=" + encodeURIComponent(JSON.stringify(data));
b5.Utils.SendGetRequest(url, function(response) {
if (done_callback !== undefined)
done_callback(response);
})
}

Backend.SendMessageMulti = function(recipients, data, done_callback)
{
var users = "";
var len = recipients.length;
for (var t = 0; t < len; t++)
{
users += recipients[t];
if (t < (len – 1))
users += "_";
}
var url = "https://yourdomain.com/msys?c=s&t=<your token>";
url += "&g=1";
url += "&m=" + users;
url += "&d=" + encodeURIComponent(JSON.stringify(data));
b5.Utils.SendGetRequest(url, function(response) {
if (done_callback !== undefined)
done_callback(response);
})
}

Backend.GetMessages = function(done_callback)
{
var url = "https://yourdomain.com/msys?c=g&t=<your token>";
url += "&g=1";
url += "&u=" + Social.GetPlayerID();
b5.Utils.SendGetRequest(url, function(response) {
if (response.status == 200)
{
var data = decodeURIComponent(response.responseText);
var obj = JSON.parse("[" + data + "]");

if (done_callback !== undefined)
done_callback(obj);
}
else
{
if (done_callback !== undefined)
done_callback();
}
})
}
[/sourcecode]

There are a few functions in here that you will need to implement yourself:

  • Social.GetPlayerID() – Replaced with your players user ID, if you are using Facebook Instants SDK then use FBInstant.player.getID()
  • b5.Utils.SendGetRequest() – Performs a GET request, e.g:

[sourcecode language=”js”]
b5.Utils.SendGetRequest = function(url, callback)
{
var req = new XMLHttpRequest();
req.onreadystatechange = function()
{
if (callback != undefined && req.readyState == 4)
callback(req);
}
req.open("GET", url, true);
req.send();
}
[/sourcecode]

Anyway, that’s it, hope you find more useful than I did. Happy coding :).

Lets Bounce Endless Bouncing Facebook Instants Game

Lets Bounce Facebook Instants Game
Lets Bounce Facebook Instants Game

Finally released the revamp of Friend Falls, this game centres purely around multiplayer, no single player functionality is available. I’m trying to test if multiplayer only games fair better than single or mixture of single / multiplayer game play.

In this game you play a ball called Ball (yes imaginative I know) that is forever bouncing, your task is to navigate a vertical world fraught with danger. You are powered by ether, but each bounce or knock you take uses up ether. Additional ether can be collected as you progress through the world. Ether is dual purpose, it gives you more energy to bounce and you can use it to buy silly hats form the hat shop to spice your character up a bit.

There is no single player component so you have to invite someone else to play. The game has a back-end for transferring results and invites around between players, so you do not need to exit and re-run the game from a message to continue play.

The game also has a mini game editor in there which allows you to create your own levels and share them with friends. Once a player plays your custom level the level is sent back to you as a challenge so you get to suffer your own creations too, so be nice :).

Anyway, check it but if you do, don’t forget to play again tomorrow or you will my day 1 retention :).

Multi-game Facebook Instant Games Bot (free code)

So, I decided to post the code to my Facebook Instant Games Bot to save other devs a lot of research and time. The bot is written using node.js, you will need to set up a hosting service that will run your bot. I chose Digital Ocean to host mine because Droplets are super simple to set up and cheap as chips. I service 5 games with the single bot and I never go over my $5 per month limit. If you do sign up with them then please use my referral link, you get $10 of free credit.

This bot server can handle many games at once, simply add new games to the pages.js source file. Click this link to download the bot.

Files in this archive include:

  • bot.js – The main bot which accepts requests and creates new players
  • bot_none_cluster.js – None cluster version of bot.js (can be used with pm2 -i option)
  • crawler – Crawls through the database checking for players that need to be messaged and messages them, also removes players that do not respond from the database
  • messaging.js – Sends messages out to players
  • pages.js – Stores page data

Usage:

  • node bot.js – Runs the bot which listens for connections and adds players to the database
  • node crawler.js – Periodically crawls through the database finding players that need to be messaged and sends them a message

Note that you will need to set up both node and redis on your server in order for the bot to work. Performance wise the bot is incredibly fast. I am servicing 5 games with mine and using only 1% CPU.

To help get you started see my other blogs:
Installing and running Node.js on a VPS
Installing Redis to Windows / Linux

Facebook Instant Games Category Breakdowns

I track all things Facebook Instant Games related, its a new little obsession of mine. I went ahead and calculated how many games are in each genre out of the current crop of just under 3000 available games. Below is a list of Facebook game genres along with how many games are in each:

  • Action – 577 games
  • Puzzle – 1035 games
  • Trivia & Word – 118 games
  • Simulation – 150 games
  • Board – 98 games
  • Sports – 282 games
  • Match 3 – 100 games
  • Card – 64 games
  • Slots – 43 games
  • Runner – 260 games
  • Strategy – 73 games
  • Role Playing – 91 games
  • MOBA – 4 games
  • Builders – 15 games
  • Bingo – 9 games
  • Poker & Table – 34 games
  • Card Battle – 4 games

Lets take a look at the list sorted by total MAU in those categories:

  • Puzzle – 1035 games (49116400 total MAU – avarage per game is 47455)
  • Sports – 282 games (44689600 total MAU – avarage per game is 158473)
  • Trivia & Word – 118 games (41406500 total MAU – avarage per game is 350902)
  • Action – 577 games (38617000 total MAU – avarage per game is 66927)
  • Board – 98 games (17343200 total MAU – avarage per game is 176971)
  • Simulation – 150 games (16033700 total MAU – avarage per game is 106891)
  • Runner – 260 games (14430399 total MAU – avarage per game is 55501)
  • Card – 64 games (10803200 total MAU – avarage per game is 168800)
  • Match 3 – 100 games (6334800 total MAU – avarage per game is 63348)
  • Role Playing – 91 games (4992400 total MAU – avarage per game is 54861)
  • Strategy – 73 games (4511700 total MAU – avarage per game is 61804)
  • Slots – 43 games (1562100 total MAU – avarage per game is 36327)
  • Bingo – 9 games (1474800 total MAU – avarage per game is 163866)
  • Poker & Table – 34 games (1464900 total MAU – avarage per game is 43085)
  • Card Battle – 4 games (924500 total MAU – avarage per game is 231125)
  • MOBA – 4 games (322000 total MAU – avarage per game is 80500)
  • Builders – 15 games (193300 total MAU – avarage per game is 12886)

What can we ascertain from these figures? Well, Puzzle games seem to be the most popular amongst developers, unfortunately users do not share that view with a very low average MAU per game. Trivia & Word is the leading category in terms of of average MAU per game whilst having far fewer games has an average MAU many times greater.

Introduction to Facebook Instant Game Development

Introduction to Facebook Instant Game Development

This is the first part of my tutorial series that covers Facebook Instant Game Development. Over the coming months I will be covering all areas of the IG SDK, providing information, examples and hopefully working code :). I will also be throwing in some back-end tutorials, showing how to write bots, messaging systems and so on.

Its the new developer craze, well sort of, its still a bit niche at the moment because compared to the app stores, users are very low and paid user acquisition is not yet an option.
Instant games (or minis) are small games that load more or less instantly within apps such as messenger apps (for example Facebook Messenger). They are created using HTML5 / Canvas / WebGL and JavaScript so they can be easily delivered to users without app store approval, although you do need to get Facebook approval which is sometimes much quicker.

So what are the advantages of developing and releasing products for platforms such as Facebook Instant Games? First and foremost is that it is quite easy to get something on there quickly, although delving deeper into the Facebook Instants technology does become a lot more complex when you start to create more social games, you will need to start thinking about writing your own back-ends for example. It is also fun, the bit I like about it the most. The platform is also good for testing iterative improvements out on very casual gamers as once your game is reviewed and approved further updates do not currently need any approval.

What are the downsides? Discovery and retention are bad, I’m talking single digit day 1 retention figures and players numbering in the hundreds per day in mainly none English speaking low revenue countries. The system is also currently winner takes all where a few games at the top take up most of the visibility so breaking through is incredibly difficult. My advice is do not think that you can dump any old game onto IG, for example simply porting an existing web game not designed for IG, it just doesn’t seem to work. The top games all feature integration at various levels to the IG SDK, this is your only source of retention and discovery.

Features

What sort of features does Facebook Instant Games have from a game developers perspective?

  • Its main and most important feature is that it enables social play between people and groups of people. To get to the basics you do not need to create a complex back-end, its all available from the SDK and handled by Facebook’s servers.
  • Important moments from within the game can be shared amongst friends and in other contexts such as groups.
  • Leaderboards are supported. Global, friends and context scoped leaderboards are all available.
  • Monetisation is available out of the box and easy to set up. You can show interstitial ads, rewarded video ads and offer in-app purchases, although IAP’s are limited to Android only. Ads are limited to mobile and not available on desktop.
  • Metadata support, almost everything you send anywhere can have some kind of meta data attached. For example, if I post my score to a messenger conversation I can attach some replay data which can be picked up by anyone that clicks on the message when the game is launched.
  • Bots – Whilst a blessing and a curse, chat bots can help to remind users to come back to your game and play increasing your retention. Not a fan of them but they have their uses. Its possible to build a complex back-end bot which practically becomes an extension of the game play itself.
  • Analytics – You can track various default events for your game as well as send custom events which you can view in the analytics section of the developer dashboard.

Context

Facebook Instant Games revolve very heavily around the concept of the context. What is a context? A context is basically a collection of players in some area of Facebook. A few examples:

  • Two people in a messenger chat. This is a context with two people
  • A Facebook post – This is a context with many people potentially on the same thread

Each context has its own unique ID that allows you to identify it and switch into it to perform operations in the context, What sort of operations? Once you are in the context your game can perform various operations such as get all of the players in the context, post messages to the context about the current state of the game. You can also store and retrieve leaderboard scores that are specific to that context only. Context ID’s are unique and persistent so you can store a context’s ID and come back to it at any time.

You generally post an update to a context when something important happens in your game. For example, you have just beaten a level and you want your friends to know. This helps with discovery because all players in the thread or chat or whatever context you are in will see the rich message (a message usually consists of an image from the game, a title, a sub title and a call to action button). The rich message can also contain hidden meta data about the game, this will be passed to the game when anyone clicks the posted call to action to launch the game. This enables information to be passed around from player to player in a none real-time / sort of turn based environment. I say sort of because you need to exit the game and run it from the other players message to take the next turn in the game. You can of course get around this by creating your own back-end to marshal the messages around.

Connected Players

Connected players are basically players that play your game and are connected to you on Messenger. This list is very useful because you can do things like show a list of familiar players that the player may wish to play, or maybe send a gift / ask for help.

Getting Started

You can get a hold of the Instants SDK from the Facebook developer website, note that you do need to be a Facebook developer to submit games, so you should sign up here.

Whats next?

In the next part of this tutorial series I will introduce you to an overview of the Facebook Instants SDK and show you how you can begin integrating your game into the Facebook Instants Game platform.

Wrapping up

Facebook Instants are an exciting new technology full of possibilities for game developers from all backgrounds and fun to play with as a gamer and game developer. Fingers crossed that Facebook Instant Games continues to grow and improve with each new iteration. It is still in its infancy however so be warned and do not invest crazy amounts of time and money into it like I did. Ease in gradually and try to re-use as much as possible of what you already have, but don’t just dump games that are not designed for IG onto the platform, its just messy and unprofessional.

Facebook Messenger Instant Games Charts

I’ve been tracking the positions and MAU of Facebook Messenger Instant Games for a while now. I track them for many reasons include:

  • Get an overall picture of where all IG games are at
  • Get an overall picture of how IG itself is performing
  • Analyse which games are rising / falling
  • Guess at how much developers are roughly earning
  • Spot clones and dodgy developers
  • See how my own games and performing

I use this information to improve my own games. Whilst its not offered much success for me it may do to some. With that in mind I am posting a much stripped down version of the charts here to enable other developers can utilise some of the information and help improve their own games / track where their games are at in the grand scheme of things.

Facebook Messenger Instant Game Charts 2018

Shuffle Match live on Facebook Instant Games in Messenger

Shuffle Match Facebook Instant Game
Shuffle Match Facebook Instant Game

My first HTML5 Facebook Instants games is now live on Messenger. I actually finished this games a couple of months back, but because of the Facebook privacy saga all further game reviews were put on hold, so hundreds (potentially thousands) of games have been sat in limbo. Its good to finally see a product live on the platform however.

Shuffle Match is basically a memory matching game where you are shown a bunch of numbered tiles, you memorise them then they slide off screen and you have to try and remember where they all were. The game is monetised by offering the player the ability to continue by watching an ad if they run out of lives. Its a simple, fun game that’s great to play against friends.

Play Shuffle Match on Messenger Now

Just released my latest cross platform game Idle Gangsters on iOS, Android and Facebook Gameroom. The game is an experiment o see if it was possible to mix Idle Incremental and Match-3 game play styles and it seems to have worked.

Rise through the ranks of the mafia in this fun, addictive idle incremental match-3 game.

Start out as a low life punk and work your way up through the mafia ranks to Godfather using every manner of lie, trick and scheme possible.
Muscle in on cities, launder goods, build up illegal rackets and generate cash, gaining the respect of your fellow mafians and rising through the ranks of the mafia. Hire bosses, kit them out, order hits, bribe cops, fight off rival gangs and the feds and much more.

  • Launder loot for the mob using Match-3 generating large amounts of cash and respect
  • Buy into 20 rackets to earn cash without lifting a finger
  • Free upgrades for all rackets
  • Smash your way through 10 ranks of the mafia from Punk to Godfather unlocking exciting new content
  • Muscle in on and take over 10 different cities from Brooklyn to Las Vegas
  • Hire upgradeable city bosses to increase cash flow, reduce racket costs, generate cash offline and use perks
  • Equip bosses with up to 16 perks to boost city rackets and laundering
  • 20 loot laundering boosts / hazards
  • 10 global powerups which affect time and cash flow
  • Unlimited missions for big cash boosts
  • Unlimited special missions for huge cash boosts which take place across 10 unique minigames
  • Extra 5 daily bonus minigames which generate cash, respect and diamonds
  • Stats tracking, over 150 individually tracked stats
  • Around 300 achievements to earn
  • Facebook connect with invites, gifting and leaderboards
  • Cloud save game backup and restore

Idle Gangsters is available for free on the App Store for iPhone and iPad

Idle Gangsters is available for free on the Google Play for Android

The game is also available for free on Facebook and Facebook Gameroom

Idle Gangsters Title Screen
Idle Gangsters Title Screen

Idle Gangsters Match-3
Idle Gangsters Match-3

Idle Gangsters Idle Incremental
Idle Gangsters Idle Incremental

Thinking of Making an Indie Game?


So, I’ve been making Indie games for years, with very little success, usually because I write obscure little games that don’t usually see much action. So I decided to write something that many gamers do love, an Idle Upgrade Cookie Clicker. I decided to go with the same format as the original by Orteil because IMO its the best and I much prefer the straight forward layout compared to modern idle games. I also decided to theme it around climate change as it’s something that I care about (hoping that it rubs off on a few others). I decided to make it free to play (because obtrusive ads are horrible and paid is DOA) with the option of video ads to generate coins for those that don’t want to spend any money on coins. I opted to integrate Facebook for backup / restore and the usual social features such as login, inviting friends, sharing, gifting, leaderboards.

So how does a cookie clicker perform these days? Lets take a look at some numbers since release a couple of months ago:

Note that the above mobile downloads required me to spend around $200 across Apple search ads and Google Adwords, so I’ve made quite a loss.

So the game wasn’t performing well, but was performing slightly better than most of my other games. With this I decided to put out a version on Kongregate and Newgrounds, (both great game portals with some pretty decent games) to boost the games visibility, which is ok as long as you can put up with the extremely toxic communities. Seriously some of the users (calling them gamers would be a serious stretch) on there were absolutely dropped on their heads at birth, if you are fine dealing with petulant kids then you can turn it into a pretty fun pass time.

Today I have:

After placing the game onto those portals I did see a nice jump in mobile installs, but it was very short lived (a couple of days), its just not an effective marketing tool, especially considering the toxicity of the community and the abuse that you will have to deal with. Also, take note, when you do place a game on a web portal, expect it to be lifted (without permission) and placed all over the place so that some blood sucker can earn ad revenue from your hard work (the word cunts springs to mind).

So in summary, paid ads do drive installs works, but you will need a LOT and I cannot stress this enough a HUGE AMOUNT of money to get your game noticed. Web portals like Kongregate and Newgrounds help the game initially but once the toxic community has done with you, your game will have 0 visibility, so any visibility gains will be short lived. Take a look at the ratings for my game:

  • iOS – 5 stars
  • Android – 4.5 stars
  • Facebook – 4.8 stars
  • Kongregate – 2.65 stars
  • Newgrounds – 2.68 stars

Indie game development for making money is dead, will I still continue to make indie games? It’s fun creating games, so maybe, do I expect to ever earn money from it? No, very unlikely.

If you are thinking of becoming an Indie game developer, I recommend only doing so if you get enjoyment from it, if you expect to earn a living then try something else.