Skip to content

Instantly share code, notes, and snippets.

@Yonom
Created February 4, 2015 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yonom/526670516af50c602894 to your computer and use it in GitHub Desktop.
Save Yonom/526670516af50c602894 to your computer and use it in GitHub Desktop.
PlayerIO Android QuickConnect
package org.yonom.android.playerio;
import com.playerio.*;
import java.io.IOException;
import java.lang.reflect.*;
import java.util.ArrayList;
public class QuickConnect {
public static Client SimpleConnect(String gameId, String usernameOrEmail, String password)
throws InstantiationException, IllegalAccessException, IllegalArgumentException,
InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException, NoSuchFieldException
{
// Create request
Method req = Class.forName("com.playerio.PlayerIOChannelGenerated").getDeclaredMethod("simpleConnect", String.class, String.class, String.class, ArrayList.class, String.class, ArrayList.class);
req.setAccessible(true);
// Get the channel
Method m = PlayerIO.class.getDeclaredMethod("getChannel");
m.setAccessible(true);
Object channel = m.invoke(null);
// Login
Object o = req.invoke(channel, new Object[] {gameId, usernameOrEmail, password, null, null, null});
// Get variables
Object token = o.getClass().getDeclaredField("Token").get(o);
Object userId = o.getClass().getDeclaredField("UserId").get(o);
boolean showBranding = o.getClass().getDeclaredField("ShowBranding").getBoolean(o);
Object gameFSRedirectMap = o.getClass().getDeclaredField("GameFSRedirectMap").get(o);
Object partnerId = o.getClass().getDeclaredField("PartnerId").get(o);
Object playerInsightState = o.getClass().getDeclaredField("PlayerInsightState").get(o);
// Set token
Method setToken = channel.getClass().getDeclaredMethod("setToken", String.class);
setToken.setAccessible(true);
setToken.invoke(channel, token);
Constructor<Client> constructor = Client.class.getDeclaredConstructor(new Class[] {Class.forName("com.playerio.PlayerIOChannelGenerated"), String.class, String.class, boolean.class, String.class, Class.forName("com.playerio.PlayerIOChannelGenerated$PlayerInsightState")});
constructor.setAccessible(true);
return constructor.newInstance(new Object[] {channel, gameId, userId, showBranding, gameFSRedirectMap, playerInsightState});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment