Adding Custom Server Side Authentication to your Game Server

Last week we released AppWarpS2, our on-premise game server. In this post, I will 14 Adding Custom Server Side Authentication to your Game Serverdescribe how developers can customize admission control in the game server via our server side adaptors.
Authentication involves two things – client sending its credentials and the server validating and authorizing admission. From the client-side, you can simply pass the user’s name and authentication data in the connect request as follows

1
public void connectWithUserName(String userName, String authData);

On the server the default behavior is to not do any validation and ignore the authentication data and allow the client admission. To alter this behavior, you will need to override the following method in the application zone’s adaptor

1
2
@Override
public void handleAddUserRequest(IUser user, String authData, HandlingResult result)

The outcome of your logic is communicated to the server (success/failure) by setting the code field of the HandlingResult parameter.

1
2
3
4
5
6
7
8
9
@Override
public void handleAddUserRequest(IUser user, String authData, HandlingResult result){
        if(isUserValid(user.getName(), authData)){
            result.code = WarpResponseResultCode.SUCCESS;
        }
        else{
            result.code = WarpResponseResultCode.AUTH_ERROR;
        }
}

Above is an example of synchronous authentication. This is easy to use but the method isUserValid can potentially block the server thread if its going to validate using a 3rd party REST call for example. This way of handling is not ideal in such cases where the validation can block the thread. For such cases, AppWarpS2 also supports asynchronous authentication. In this technique, you will return from the override method right away with a pending result code which will instruct the server to hold the client’s request and hence not block the server thread. On a separate thread the application will validate the user and once the result is known will instruct the server to send the response back to the client. Below is an illustration on how to do this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@Override
public void handleAddUserRequest(IUser user, String authData, HandlingResult result){
 
        // perform the validation in a separate thread.
        new Thread(new Runnable() {
            @Override
            public void run() {               
                if(isUserValid(user.getName(), authData)){
                    izone.sendAddUserResponse(user, WarpResponseResultCode.SUCCESS, "Auth success on server");
                }
                else{
                    izone.sendAddUserResponse(user, WarpResponseResultCode.AUTH_ERROR, "Auth failed on server");
                }                
            }
        }).start();
        // don't block the AppWarpS2 thread and return pending immediately.
        result.code = WarpResponseResultCode.AUTH_PENDING;
}

This technique is also illustrated in our AppWarpS2 Rummy card game sample which allows client to connect via facebook. The authentication data passed by the client in the sample is the facebook token. The server uses facebook graph API to validate the token for the connecting user. In the sample we the authorization is done using the asynchronous technique described above.

Visit the AppWarpS2 page to sign-up, login and download the setup. Please send your questions and comment to support@shephertz.com

twitter Adding Custom Server Side Authentication to your Game Serverfacebook Adding Custom Server Side Authentication to your Game Servergoogle Adding Custom Server Side Authentication to your Game Serverlinkedin Adding Custom Server Side Authentication to your Game Serverpinterest Adding Custom Server Side Authentication to your Game Serverreddit Adding Custom Server Side Authentication to your Game Serverstumbleupon Adding Custom Server Side Authentication to your Game Servertumblr Adding Custom Server Side Authentication to your Game Server

Leave a Reply

Your email address will not be published. Required fields are marked *


− 3 = three

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>