use of com.gamebuster19901.excite.UnknownPlayer in project ExciteBot by TheGameCommunity.
the class Player method addPlayer.
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Player addPlayer(MessageContext context, boolean automatic, int playerID, String friendCode, String name) throws SQLException {
if (context.getEvent() instanceof UnknownPlayer) {
UnknownPlayer player = (UnknownPlayer) context.getEvent();
player.name = name;
player.friendCode = friendCode;
}
PreparedStatement ps = Insertion.insertInto(PLAYERS).setColumns(PLAYER_ID, FRIEND_CODE, PLAYER_NAME).to(playerID, friendCode, name).prepare(ConsoleContext.INSTANCE);
ps.execute();
Player ret = getPlayerByID(context, playerID);
DiscoveryAudit.addProfileDiscovery(context, automatic, ret);
return ret;
}
use of com.gamebuster19901.excite.UnknownPlayer in project ExciteBot by TheGameCommunity.
the class Wiimmfi method updateOnlinePlayers.
@SuppressWarnings({ "rawtypes", "unchecked" })
public Player[] updateOnlinePlayers() throws SQLException, WiimmfiResponseException {
HashSet<Player> onlinePlayers = new HashSet<Player>();
if (JSON != null) {
JsonArray objects = null;
JsonElement object1;
HashMap<String, JsonElement> object1Entries = new HashMap<String, JsonElement>();
if (JSON.isJsonArray()) {
objects = JSON.getAsJsonArray();
object1 = objects.get(0);
} else {
object1 = JSON;
}
for (Entry<String, JsonElement> e : object1.getAsJsonObject().entrySet()) {
if (object1Entries.put(e.getKey(), e.getValue()) != null) {
throw new WiimmfiResponseException("Duplicate key in json response:" + e.getKey());
}
}
JsonElement typeJson = object1Entries.get("type");
JsonElement identifyJson = object1Entries.get("identify");
JsonElement gameJson = object1Entries.get("game_list");
String type = null;
String identify = null;
String game = null;
if (typeJson != null) {
type = typeJson.getAsString();
}
if (type == null) {
throw new WiimmfiResponseException("Unexpected response from wiimmfi api");
}
if (type.equals("error")) {
JsonElement errorJson = object1Entries.get("error");
JsonElement msgJson = object1Entries.get("msg");
String error = null;
String msg = null;
if (errorJson != null) {
error = errorJson.getAsString();
} else {
error = "No error type received from wiimmfi";
}
if (msgJson != null) {
msg = msgJson.getAsString();
}
throw new WiimmfiErrorResponse(error + ": " + msg);
}
if (identifyJson != null) {
identify = identifyJson.getAsString();
}
if (gameJson != null) {
if (gameJson.getAsJsonArray().size() > 0) {
game = gameJson.getAsJsonArray().get(0).getAsString();
} else {
throw new WiimmfiResponseException("No game data response");
}
}
if (!"games".equals(identify)) {
throw new WiimmfiResponseException("Unexpected response of type: " + identify);
}
if (!"exciteracewii".equals(game)) {
throw new WiimmfiResponseException("Wiimmfi sent player list from incorrect game: " + game);
}
elementFinder: for (int i = 1; i < objects.size(); i++) {
// should be safe to access w/o null check as it should error before now
JsonElement obj = objects.get(i);
HashMap<String, JsonElement> entries = new HashMap<String, JsonElement>();
for (Entry<String, JsonElement> e : obj.getAsJsonObject().entrySet()) {
if (entries.put(e.getKey(), e.getValue()) != null) {
throw new WiimmfiResponseException("Duplicate key in json response:" + e.getKey());
}
}
if ("game-stats".equals(entries.get("type").getAsString())) {
JsonArray playerList = entries.get("list").getAsJsonArray();
for (JsonElement e : playerList) {
HashMap<String, JsonElement> playerDataEntries = new HashMap<String, JsonElement>();
for (Entry<String, JsonElement> e2 : e.getAsJsonObject().entrySet()) {
playerDataEntries.put(e2.getKey(), e2.getValue());
}
int pid = playerDataEntries.get("pid").getAsInt();
String fc = playerDataEntries.get("fc").getAsString();
int status = playerDataEntries.get("online_status").getAsInt();
int host = playerDataEntries.get("hoststate").getAsInt();
String name = playerDataEntries.get("name").getAsJsonArray().get(0).getAsString();
Player player = Player.getPlayerByID(ConsoleContext.INSTANCE, pid);
if (player instanceof UnknownPlayer) {
player = Player.addPlayer(new MessageContext(player), true, pid, fc, name);
} else {
player.setName(name);
player.setOnlineStatus(status);
player.setHost(host);
}
onlinePlayers.add(player);
}
;
break elementFinder;
}
}
}
for (Player player : onlinePlayers) {
if (PREV_ONLINE_PLAYERS.contains(player)) {
if (!(player.isPrivate() || player.isSearching() || player.isFriendsList())) {
player.updateSecondsPlayed();
}
player.updateLastOnline();
} else {
LogInAudit.addLoginAudit(new MessageContext(player), player);
player.updateLastOnline();
}
PREV_ONLINE_PLAYERS.remove(player);
}
for (Player player : PREV_ONLINE_PLAYERS) {
LogOutAudit.addLogOutAudit(new MessageContext(player), player);
}
ONLINE_PLAYERS = onlinePlayers;
PREV_ONLINE_PLAYERS = ONLINE_PLAYERS;
return onlinePlayers.toArray(new Player[] {});
}
use of com.gamebuster19901.excite.UnknownPlayer in project ExciteBot by TheGameCommunity.
the class BanCommand method banProfileForever.
@SuppressWarnings("rawtypes")
private static int banProfileForever(MessageContext context, Player[] profile, String reason) {
if (profile.length != 1) {
context.sendMessage("Ambigious name, enter a PID or FC");
return 0;
}
if (context.isAdmin()) {
if (profile[0] instanceof UnknownPlayer) {
context.sendMessage("There is no profile known as " + profile);
return 0;
}
Duration duration = ChronoUnit.FOREVER.getDuration();
profile[0].ban(context, duration, parseReason(duration, reason));
} else {
context.sendMessage("You do not have permission to execute this command");
}
return 0;
}
Aggregations