Waiving player goodbye – signing off

Feature that’s missing in Raim is – once player gets into game he or she cannot go out. Well, technically – he/she can, by closing the page or navigating to different page. But other players won’t know since they will not get any info. And figuring it out just because player hasn’t moved for past ten minutes does not work great as user experience goes.

Solution is simple: notify all players that player has signed off, moved to do something less fun than play this awesome game. Once chance to do that is to subscribe to beforeunload event of browser window. Once the event is raised page can potentially ask viewer to stay on the page a while longer (which most of the time makes people more angry than happy; that’s why it can be blocked by browser so don’t count on it working). I don’t want player to stay longer that way – I want to notify other players that there is one less person to play against.

(function () {
    var raim = $.connection.raimHub;

    raim.client.signedOff = gameArena.removePlayer;

    function signOff() {

    $.connection.hub.start().done(function () {
        var name = Date.now().toString();

        window.addEventListener("beforeunload", signOff);

And passing info that player signed off to players list:

var removePlayer = function (player) {
    var playerIndex = _players.findIndex(function (p) { return p.Name === player; });
    _players.splice(playerIndex, 1);

Of course there is server handling missing, from RaimHub.cs:

public void SignOff(string name)

And this way if player goes to different page everyone will get notified and player will disappear from game screen.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s