In this article we are going to learn how to use App42 with AppWarp S2. We will integrate App42’s user service with AppWarp S2, to implement a custom server side logic for authentication. Players will only be allowed to join application only if he/she is a registered user.
Custom Authentication with App42
AppWarp requires that every username should be unique while connecting to server. There might be cases, when you want to allow only those players that are registered users of your game. Appwarp S2 facilitates such functionality through custom authentication mechanism.
But to maintain list of players who are registered with your game, you will need some third party tool. For which we are going to use App42’s user management service. This service allows developers to implement register, authenticate and other related tasks without writing any server side code or maintaining and hosting a server.
Implementing Custom Authentication
Whenever a user tries to connect to AppWarp S2, handleAddUserRequest is invoked in Zone Adaptor. Here you can decide whether you want to fail or success that user’s connect request.
public void handleAddUserRequest(final IUser user, String authData, HandlingResult result)
Here `authData` is a special parameter that was sent from the `user` during connecting to the server along with username. `result` is the parameter where you will define whether you are going to fail or success this request.
Since we are going to communicate with App42 service, we will use asynchronous callback for App42 APIs. If we don’t use asynchronous method, we will block the AppWarp S2’s message processing thread. Hence we should always use asynchronous method. For asynchronous methods, AppWarp S2 provides a special result code WarpResponseResultCode.AUTH_PENDING. This will let the AppWarp S2 server know, we are waiting for our third party API to respond.
Once we have received the response, we can fail or success the connect request through `sendAddUserResponse ` method. This method belongs to `IZone`. Here is a sample code snippet.
userService.authenticate(user.getName(), authData, new App42CallBack() {
@Override
public void onSuccess(Object response) {
System.out.println("Successfully Authenticated");
zone.sendAddUserResponse(user, WarpResponseResultCode.SUCCESS, "Auth success on server");
}
@Override
public void onException(Exception ex) {
System.out.println("Failure in Authenticating");
zone.sendAddUserResponse(user, WarpResponseResultCode.AUTH_ERROR, "Auth failed on server");
}
});
Sample
To make you understand better, we have created a sample for you. The sample is an extension to HTML5 Chat Sample. To register user, we have used HTML5 App42 SDK. You can grab the sample from here.
Conclusion
This sample will let you know how to integrate AppWarp S2 with App42. You can similarly integrate any other third party service with AppWarp S2 for example Facebook.
If you have any question or need further assistance, please feel free to write to us at support@shephertz.com
Leave A Reply