use of com.gamebuster19901.excite.Player 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.Player 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.Player in project ExciteBot by TheGameCommunity.
the class WhoIsCommand method sendResponse.
@SuppressWarnings("serial")
public static int sendResponse(MessageContext context, String lookingFor) {
if (context.isConsoleMessage() || context.isIngameEvent()) {
context.sendMessage("You cannot execute this command as " + context.getEvent().getClass().getSimpleName());
return 1;
}
Wiimmfi wiimmfi = Main.discordBot.getWiimmfi();
EmbedBuilder embed = new EmbedBuilder();
boolean hasMembers = context.isGuildMessage();
if (wiimmfi.getError() == null) {
if (!lookingFor.isEmpty()) {
HashSet<DiscordUser> users = new HashSet<DiscordUser>() {
{
this.addAll(Arrays.asList(DiscordUser.getDiscordUsersWithUsernameOrID(context, lookingFor)));
}
};
HashSet<Player> players = new HashSet<Player>() {
{
this.addAll(Arrays.asList(Player.getPlayersByAnyIdentifier(context, lookingFor)));
}
};
HashSet<Named> matches = new HashSet<Named>();
matches.addAll(users);
matches.addAll(players);
SimpleDateFormat date = new SimpleDateFormat("yyyy/MM/dd HH:mm z", Locale.ENGLISH);
if (matches.size() == 1) {
Named match = matches.iterator().next();
embed.setTitle("Information about " + match.getIdentifierName());
if (match instanceof DiscordUser) {
DiscordUser user = (DiscordUser) match;
Member member;
embed.setColor(Color.WHITE);
Wii[] wiis = user.getRegisteredWiis();
Set<Player> profiles = user.getProfiles(context);
Duration timeOnline = Duration.ZERO;
Instant lastOnline = TimeUtils.PLAYER_EPOCH;
String profileList = "";
String wiiList = "";
for (Player profile : profiles) {
profileList = profileList + profile.toEmbedstring() + "\n";
timeOnline = timeOnline.plus(profile.getOnlineDuration());
Instant profileLastOnline = profile.getLastOnline();
if (profileLastOnline.isAfter(lastOnline)) {
lastOnline = profileLastOnline;
}
}
for (Wii wii : wiis) {
wiiList = wiiList + wii.getName() + "\n";
}
if (hasMembers && (member = user.getMember(context.getServer())) != null) {
embed.setColor(member.getColor());
embed.setThumbnail(user.getJDAUser().getEffectiveAvatarUrl());
embed.addField("Username:", user.getJDAUser().getName(), false);
embed.addField("Discriminator", user.getJDAUser().getDiscriminator(), false);
// embed.addField("Badges:", "", false);
embed.addField("ID:", "" + user.getID(), false);
embed.addField("Nickname:", member.getNickname() != null ? member.getNickname() : "##Not Nicknamed##", false);
embed.addField("Joined Discord:", date.format(member.getTimeCreated().toInstant().toEpochMilli()), false);
embed.addField("Joined " + context.getServer().getName() + ":", date.format(member.getTimeJoined().toInstant().toEpochMilli()), false);
embed.addField("Member for:", readableDuration(TimeUtils.since(member.getTimeJoined().toInstant()), false), false);
embed.addField("Time Online:", readableDuration(timeOnline, true), false);
embed.addField(profiles.size() + " registered Profiles:", profileList, false);
embed.addField(wiis.length + " registered Wiis:", wiiList, false);
} else {
embed.setThumbnail(user.getJDAUser().getEffectiveAvatarUrl());
embed.addField("Username:", user.getJDAUser().getName(), false);
embed.addField("Discriminator", user.getJDAUser().getDiscriminator(), false);
embed.addField("ID:", "" + user.getID(), false);
embed.addField("Time Online:", readableDuration(timeOnline, true), false);
embed.addField(profiles.size() + " registered Profiles:", profileList, false);
embed.addField(wiis.length + " registered Wiis:", wiiList, false);
embed.appendDescription("For more information, execute this command in a server the user is in.");
}
} else if (match instanceof Player) {
Player profile = (Player) match;
DiscordUser user = DiscordUser.getDiscordUserTreatingUnknownsAsNobody(context, profile.getDiscord());
embed.addField("Name:", profile.getName(), false);
embed.addField("ID:", profile.getID() + "", false);
embed.addField("FC:", profile.getFriendCode(), false);
embed.addField("Owner:", user.toDetailedString(), false);
embed.addField("Time Online:", readableDuration(profile.getOnlineDuration(), true), false);
embed.addField("First Seen:", date.format(profile.getFirstSeen().toEpochMilli()), false);
embed.addField("Last Seen:", date.format(profile.getLastOnline().toEpochMilli()), false);
}
} else if (matches.size() == 0) {
embed.setColor(Color.RED);
embed.setTitle("Target not found");
embed.addField("Target:", lookingFor, true);
} else {
embed.setTitle("Ambigious target string, supply an ID");
embed.setColor(Color.RED);
embed.addField("Target", lookingFor, true);
embed.addField("Ambiguities", "" + matches.size(), true);
if (users.size() > 0) {
embed.appendDescription("Discord users:\n");
String userList = "";
for (DiscordUser user : users) {
Member member;
if (hasMembers && (member = user.getMember(context.getServer())) != null && member.getNickname() != null) {
userList = userList + user.toDetailedString() + " AKA " + member.getEffectiveName() + "#" + member.getIdLong() + "\n";
} else {
userList = userList + user.toDetailedString() + "\n";
}
}
embed.addField("Ambiguous Users:", userList, false);
}
if (players.size() > 0) {
String playerList = "";
for (Player player : players) {
playerList = playerList + player.toFullString() + "\n";
}
embed.addField("Ambiguous Profiles:", playerList, false);
}
}
embed.setTimestamp(Instant.now());
context.sendMessage(embed.build());
}
}
return 1;
}
use of com.gamebuster19901.excite.Player in project ExciteBot by TheGameCommunity.
the class LogOutAudit method addLogOutAudit.
public static LogOutAudit addLogOutAudit(MessageContext context, Player player) {
Audit parent = Audit.addAudit(context, AuditType.LOG_OUT_AUDIT, getMessage(player));
PreparedStatement st;
try {
st = Insertion.insertInto(Table.AUDIT_PROFILE_LOGOUTS).setColumns(AUDIT_ID).to(parent.getID()).prepare(context, true);
st.execute();
LogOutAudit ret = getLogOutAuditByAuditID(ConsoleContext.INSTANCE, parent.getID());
ret.parentData = parent;
return ret;
} catch (SQLException e) {
throw new IOError(e);
}
}
use of com.gamebuster19901.excite.Player in project ExciteBot by TheGameCommunity.
the class LogInAudit method addLoginAudit.
public static LogInAudit addLoginAudit(MessageContext context, Player player) {
Audit parent = Audit.addAudit(context, AuditType.LOG_IN_AUDIT, getMessage(player));
PreparedStatement st;
try {
st = Insertion.insertInto(Table.AUDIT_PROFILE_LOGINS).setColumns(AUDIT_ID).to(parent.getID()).prepare(context, true);
st.execute();
LogInAudit ret = getLoginAuditByAuditID(ConsoleContext.INSTANCE, parent.getID());
ret.parentData = parent;
return ret;
} catch (SQLException e) {
throw new IOError(e);
}
}
Aggregations