Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.playfab.PlayFabMatchmakerAPI Maven / Gradle / Ivy
Go to download
PlayFab is the unified backend platform for games — everything you need to build and operate your game, all in one place, so you can focus on creating and delivering a great player experience.
package com.playfab;
import com.playfab.internal.*;
import com.playfab.PlayFabMatchmakerModels.*;
import com.playfab.PlayFabErrors.*;
import com.playfab.PlayFabSettings;
import java.util.concurrent.*;
import java.util.*;
import com.google.gson.*;
import com.google.gson.reflect.*;
/** Enables the use of an external match-making service in conjunction with PlayFab hosted Game Server instances */
public class PlayFabMatchmakerAPI {
private static Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").create();
/**
* Validates a user with the PlayFab service
* @param request AuthUserRequest
* @return Async Task will return AuthUserResponse
*/
@SuppressWarnings("unchecked")
public static FutureTask> AuthUserAsync(final AuthUserRequest request) {
return new FutureTask(new Callable>() {
public PlayFabResult call() throws Exception {
return privateAuthUserAsync(request);
}
});
}
/**
* Validates a user with the PlayFab service
* @param request AuthUserRequest
* @return AuthUserResponse
*/
@SuppressWarnings("unchecked")
public static PlayFabResult AuthUser(final AuthUserRequest request) {
FutureTask> task = new FutureTask(new Callable>() {
public PlayFabResult call() throws Exception {
return privateAuthUserAsync(request);
}
});
try {
task.run();
return task.get();
} catch(Exception e) {
PlayFabResult exceptionResult = new PlayFabResult();
exceptionResult.Error = PlayFabHTTP.GeneratePfError(-1, PlayFabErrorCode.Unknown, e.getMessage(), null);
return exceptionResult;
}
}
/** Validates a user with the PlayFab service */
@SuppressWarnings("unchecked")
private static PlayFabResult privateAuthUserAsync(final AuthUserRequest request) throws Exception {
if (PlayFabSettings.DeveloperSecretKey == null) throw new Exception ("Must have PlayFabSettings.DeveloperSecretKey set to call this method");
FutureTask task = PlayFabHTTP.doPost(PlayFabSettings.GetURL("/Matchmaker/AuthUser"), request, "X-SecretKey", PlayFabSettings.DeveloperSecretKey);
task.run();
Object httpResult = task.get();
if (httpResult instanceof PlayFabError) {
PlayFabError error = (PlayFabError)httpResult;
if (PlayFabSettings.GlobalErrorHandler != null)
PlayFabSettings.GlobalErrorHandler.callback(error);
PlayFabResult result = new PlayFabResult();
result.Error = error;
return result;
}
String resultRawJson = (String) httpResult;
PlayFabJsonSuccess resultData = gson.fromJson(resultRawJson, new TypeToken>(){}.getType());
AuthUserResponse result = resultData.data;
PlayFabResult pfResult = new PlayFabResult();
pfResult.Result = result;
return pfResult;
}
/**
* Informs the PlayFab game server hosting service that the indicated user has joined the Game Server Instance specified
* @param request PlayerJoinedRequest
* @return Async Task will return PlayerJoinedResponse
*/
@SuppressWarnings("unchecked")
public static FutureTask> PlayerJoinedAsync(final PlayerJoinedRequest request) {
return new FutureTask(new Callable>() {
public PlayFabResult call() throws Exception {
return privatePlayerJoinedAsync(request);
}
});
}
/**
* Informs the PlayFab game server hosting service that the indicated user has joined the Game Server Instance specified
* @param request PlayerJoinedRequest
* @return PlayerJoinedResponse
*/
@SuppressWarnings("unchecked")
public static PlayFabResult PlayerJoined(final PlayerJoinedRequest request) {
FutureTask> task = new FutureTask(new Callable>() {
public PlayFabResult call() throws Exception {
return privatePlayerJoinedAsync(request);
}
});
try {
task.run();
return task.get();
} catch(Exception e) {
PlayFabResult exceptionResult = new PlayFabResult();
exceptionResult.Error = PlayFabHTTP.GeneratePfError(-1, PlayFabErrorCode.Unknown, e.getMessage(), null);
return exceptionResult;
}
}
/** Informs the PlayFab game server hosting service that the indicated user has joined the Game Server Instance specified */
@SuppressWarnings("unchecked")
private static PlayFabResult privatePlayerJoinedAsync(final PlayerJoinedRequest request) throws Exception {
if (PlayFabSettings.DeveloperSecretKey == null) throw new Exception ("Must have PlayFabSettings.DeveloperSecretKey set to call this method");
FutureTask task = PlayFabHTTP.doPost(PlayFabSettings.GetURL("/Matchmaker/PlayerJoined"), request, "X-SecretKey", PlayFabSettings.DeveloperSecretKey);
task.run();
Object httpResult = task.get();
if (httpResult instanceof PlayFabError) {
PlayFabError error = (PlayFabError)httpResult;
if (PlayFabSettings.GlobalErrorHandler != null)
PlayFabSettings.GlobalErrorHandler.callback(error);
PlayFabResult result = new PlayFabResult();
result.Error = error;
return result;
}
String resultRawJson = (String) httpResult;
PlayFabJsonSuccess resultData = gson.fromJson(resultRawJson, new TypeToken>(){}.getType());
PlayerJoinedResponse result = resultData.data;
PlayFabResult pfResult = new PlayFabResult();
pfResult.Result = result;
return pfResult;
}
/**
* Informs the PlayFab game server hosting service that the indicated user has left the Game Server Instance specified
* @param request PlayerLeftRequest
* @return Async Task will return PlayerLeftResponse
*/
@SuppressWarnings("unchecked")
public static FutureTask> PlayerLeftAsync(final PlayerLeftRequest request) {
return new FutureTask(new Callable>() {
public PlayFabResult call() throws Exception {
return privatePlayerLeftAsync(request);
}
});
}
/**
* Informs the PlayFab game server hosting service that the indicated user has left the Game Server Instance specified
* @param request PlayerLeftRequest
* @return PlayerLeftResponse
*/
@SuppressWarnings("unchecked")
public static PlayFabResult PlayerLeft(final PlayerLeftRequest request) {
FutureTask> task = new FutureTask(new Callable>() {
public PlayFabResult call() throws Exception {
return privatePlayerLeftAsync(request);
}
});
try {
task.run();
return task.get();
} catch(Exception e) {
PlayFabResult exceptionResult = new PlayFabResult();
exceptionResult.Error = PlayFabHTTP.GeneratePfError(-1, PlayFabErrorCode.Unknown, e.getMessage(), null);
return exceptionResult;
}
}
/** Informs the PlayFab game server hosting service that the indicated user has left the Game Server Instance specified */
@SuppressWarnings("unchecked")
private static PlayFabResult privatePlayerLeftAsync(final PlayerLeftRequest request) throws Exception {
if (PlayFabSettings.DeveloperSecretKey == null) throw new Exception ("Must have PlayFabSettings.DeveloperSecretKey set to call this method");
FutureTask task = PlayFabHTTP.doPost(PlayFabSettings.GetURL("/Matchmaker/PlayerLeft"), request, "X-SecretKey", PlayFabSettings.DeveloperSecretKey);
task.run();
Object httpResult = task.get();
if (httpResult instanceof PlayFabError) {
PlayFabError error = (PlayFabError)httpResult;
if (PlayFabSettings.GlobalErrorHandler != null)
PlayFabSettings.GlobalErrorHandler.callback(error);
PlayFabResult result = new PlayFabResult();
result.Error = error;
return result;
}
String resultRawJson = (String) httpResult;
PlayFabJsonSuccess resultData = gson.fromJson(resultRawJson, new TypeToken>(){}.getType());
PlayerLeftResponse result = resultData.data;
PlayFabResult pfResult = new PlayFabResult();
pfResult.Result = result;
return pfResult;
}
/**
* Instructs the PlayFab game server hosting service to instantiate a new Game Server Instance
* @param request StartGameRequest
* @return Async Task will return StartGameResponse
*/
@SuppressWarnings("unchecked")
public static FutureTask> StartGameAsync(final StartGameRequest request) {
return new FutureTask(new Callable>() {
public PlayFabResult call() throws Exception {
return privateStartGameAsync(request);
}
});
}
/**
* Instructs the PlayFab game server hosting service to instantiate a new Game Server Instance
* @param request StartGameRequest
* @return StartGameResponse
*/
@SuppressWarnings("unchecked")
public static PlayFabResult StartGame(final StartGameRequest request) {
FutureTask> task = new FutureTask(new Callable>() {
public PlayFabResult call() throws Exception {
return privateStartGameAsync(request);
}
});
try {
task.run();
return task.get();
} catch(Exception e) {
PlayFabResult exceptionResult = new PlayFabResult();
exceptionResult.Error = PlayFabHTTP.GeneratePfError(-1, PlayFabErrorCode.Unknown, e.getMessage(), null);
return exceptionResult;
}
}
/** Instructs the PlayFab game server hosting service to instantiate a new Game Server Instance */
@SuppressWarnings("unchecked")
private static PlayFabResult privateStartGameAsync(final StartGameRequest request) throws Exception {
if (PlayFabSettings.DeveloperSecretKey == null) throw new Exception ("Must have PlayFabSettings.DeveloperSecretKey set to call this method");
FutureTask task = PlayFabHTTP.doPost(PlayFabSettings.GetURL("/Matchmaker/StartGame"), request, "X-SecretKey", PlayFabSettings.DeveloperSecretKey);
task.run();
Object httpResult = task.get();
if (httpResult instanceof PlayFabError) {
PlayFabError error = (PlayFabError)httpResult;
if (PlayFabSettings.GlobalErrorHandler != null)
PlayFabSettings.GlobalErrorHandler.callback(error);
PlayFabResult result = new PlayFabResult();
result.Error = error;
return result;
}
String resultRawJson = (String) httpResult;
PlayFabJsonSuccess resultData = gson.fromJson(resultRawJson, new TypeToken>(){}.getType());
StartGameResponse result = resultData.data;
PlayFabResult pfResult = new PlayFabResult();
pfResult.Result = result;
return pfResult;
}
/**
* Retrieves the relevant details for a specified user, which the external match-making service can then use to compute
* effective matches
* @param request UserInfoRequest
* @return Async Task will return UserInfoResponse
*/
@SuppressWarnings("unchecked")
public static FutureTask> UserInfoAsync(final UserInfoRequest request) {
return new FutureTask(new Callable>() {
public PlayFabResult call() throws Exception {
return privateUserInfoAsync(request);
}
});
}
/**
* Retrieves the relevant details for a specified user, which the external match-making service can then use to compute
* effective matches
* @param request UserInfoRequest
* @return UserInfoResponse
*/
@SuppressWarnings("unchecked")
public static PlayFabResult UserInfo(final UserInfoRequest request) {
FutureTask> task = new FutureTask(new Callable>() {
public PlayFabResult call() throws Exception {
return privateUserInfoAsync(request);
}
});
try {
task.run();
return task.get();
} catch(Exception e) {
PlayFabResult exceptionResult = new PlayFabResult();
exceptionResult.Error = PlayFabHTTP.GeneratePfError(-1, PlayFabErrorCode.Unknown, e.getMessage(), null);
return exceptionResult;
}
}
/**
* Retrieves the relevant details for a specified user, which the external match-making service can then use to compute
* effective matches
*/
@SuppressWarnings("unchecked")
private static PlayFabResult privateUserInfoAsync(final UserInfoRequest request) throws Exception {
if (PlayFabSettings.DeveloperSecretKey == null) throw new Exception ("Must have PlayFabSettings.DeveloperSecretKey set to call this method");
FutureTask task = PlayFabHTTP.doPost(PlayFabSettings.GetURL("/Matchmaker/UserInfo"), request, "X-SecretKey", PlayFabSettings.DeveloperSecretKey);
task.run();
Object httpResult = task.get();
if (httpResult instanceof PlayFabError) {
PlayFabError error = (PlayFabError)httpResult;
if (PlayFabSettings.GlobalErrorHandler != null)
PlayFabSettings.GlobalErrorHandler.callback(error);
PlayFabResult result = new PlayFabResult();
result.Error = error;
return result;
}
String resultRawJson = (String) httpResult;
PlayFabJsonSuccess resultData = gson.fromJson(resultRawJson, new TypeToken>(){}.getType());
UserInfoResponse result = resultData.data;
PlayFabResult pfResult = new PlayFabResult();
pfResult.Result = result;
return pfResult;
}
}