use of fr.glowstoner.fireapi.bigbrother.spy.BigBrotherSpyHistory in project FireAPI by FireBlade-Serv.
the class BigBrotherListener method onPacketReceive.
@Override
public void onPacketReceive(Packet packet) {
try {
ConnectionHandler server = packet.getConnection();
String name = (server.getName().equals("default-name")) ? server.getIP() : server.getName();
if (!(packet instanceof PacketPing)) {
if (!(packet instanceof PacketSpyAction)) {
System.out.println("[BigBrother] Packet reçu : " + name + " -> " + packet.getClass().getSimpleName());
} else {
System.out.println("[BigBrother] Packet reçu : " + name + " -> " + packet.getClass().getSimpleName() + " / " + ((PacketSpyAction) packet).getAction().name());
}
}
if (server.isLogged().equals(LoginResult.NOT_LOGGED)) {
if (packet instanceof PacketLogin) {
PacketLogin pl = (PacketLogin) packet;
try {
String cpass = pl.decryptPass(this.log.getKey());
System.out.println("[BigBrother] PacketLogin reçu, valeur du PASS (crypt) : " + pl.getCryptPassword());
System.out.println("[BigBrother] PacketLogin reçu, valeur du PASS (D_key) : " + cpass);
if (cpass.equals(this.log.getPassword())) {
server.sendPacket(new PacketText("[BigBrother] Connection réussie !"));
server.setLoginResult(LoginResult.LOGGED);
listeners.callOnConnectionSuccessfullServerListener(server);
} else {
server.sendMessage("[BigBrother] Mot de passe incorect !");
if (limit.containsKey(server)) {
limit.replace(server, limit.get(server) + 1);
if (limit.get(server) == 3) {
server.sendPacket(new PacketText("[BigBrother] Trop de tentatives ratées ! Déconnexion ..."));
server.close();
}
} else {
limit.put(server, 1);
}
}
} catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException | IOException e) {
return;
}
} else {
server.sendPacket(new PacketText("[BigBrother] Vous devez vous connecter !"));
return;
}
}
if (packet instanceof PacketCommand) {
this.listeners.callOnCommandServerListener((PacketCommand) packet);
} else if (packet instanceof PacketVersion) {
PacketVersion ver = (PacketVersion) packet;
if (!this.connectionstype.containsKey(VersionType.SPIGOT_VERSION)) {
if (ver.getType().equals(VersionType.SPIGOT_VERSION)) {
List<ConnectionHandler> list = new CopyOnWriteArrayList<>();
list.add(server);
this.connectionstype.put(VersionType.SPIGOT_VERSION, list);
}
} else {
if (ver.getType().equals(VersionType.SPIGOT_VERSION)) {
List<ConnectionHandler> list = this.connectionstype.get(VersionType.SPIGOT_VERSION);
list.add(server);
this.connectionstype.replace(VersionType.SPIGOT_VERSION, list);
}
}
if (!this.connectionstype.containsKey(VersionType.BUNGEECORD_VERSION)) {
if (ver.getType().equals(VersionType.BUNGEECORD_VERSION)) {
List<ConnectionHandler> list = new CopyOnWriteArrayList<>();
list.add(server);
this.connectionstype.put(VersionType.BUNGEECORD_VERSION, list);
}
} else {
if (ver.getType().equals(VersionType.BUNGEECORD_VERSION)) {
List<ConnectionHandler> list = this.connectionstype.get(VersionType.BUNGEECORD_VERSION);
list.add(server);
this.connectionstype.replace(VersionType.BUNGEECORD_VERSION, list);
}
}
} else if (packet instanceof PacketFriends) {
PacketFriends pf = (PacketFriends) packet;
if (pf.getAction() instanceof FriendsActionTransmetterGUI) {
FriendsActionTransmetterGUI fa = (FriendsActionTransmetterGUI) pf.getAction();
if (fa.to().equals(VersionType.SPIGOT_VERSION)) {
for (ConnectionHandler chs : this.connected) {
if (chs.getName().equals(fa.getServerDestination())) {
chs.sendPacket(packet);
}
}
}
}
} else if (packet instanceof PacketPlayerPing) {
PacketPlayerPing pp = (PacketPlayerPing) packet;
if (pp.getState().equals(PingState.INIT_SERVER)) {
pp.setState(PingState.BUNGEE_REQUEST);
try {
this.getServerConnectionByNameUnsafe(VersionType.BUNGEECORD_VERSION, "main-bungeecord").sendPacket(pp);
} catch (IOException e) {
e.printStackTrace();
}
}
} else if (packet instanceof PacketSpyAction) {
PacketSpyAction spy = (PacketSpyAction) packet;
Calendar cal = GregorianCalendar.getInstance();
cal.setTime(new Date());
if (this.gs.ifDataFileExists(spy.getPlayerName())) {
this.gs.updateDataFile(spy.getPlayerName(), BigBrotherSpyUtils.mergeHistory(this.gs.getHistory(spy.getPlayerName()), spy));
} else {
BigBrotherSpyHistory gh = new BigBrotherSpyHistory(spy.getPlayerName(), spy.getIP(), BigBrotherSpyUtils.toFireCalendar(cal));
gh.putMessage(BigBrotherSpyUtils.toFireCalendar(spy.getActionDate()), spy.getAction(), spy.getFormatedMsg(), spy.getRawMsg());
this.gs.createNewDataFile(spy.getPlayerName(), gh);
}
} else if (packet instanceof PacketSpyHistoryGetter) {
PacketSpyHistoryGetter get = (PacketSpyHistoryGetter) packet;
if (get.getState().equals(BigBrotherSpyHistoryGetterState.REQUEST)) {
get.setState(BigBrotherSpyHistoryGetterState.SEND);
get.setHistory(this.gs.getHistory(get.getPlayerName()));
server.sendPacket(get);
}
} else if (packet instanceof PacketBigBrotherAC) {
PacketBigBrotherAC gacp = (PacketBigBrotherAC) packet;
if (gacp.getType().equals(BigBrotherTypeAC.CHEAT_DETECTION)) {
if (gacp.getTODO().equals(BigBrotherActionAC.INFORM_STAFF)) {
this.getServerConnectionByNameUnsafe(VersionType.BUNGEECORD_VERSION, "main-bungeecord").sendPacket(gacp);
}
}
}
} catch (Exception e) {
return;
}
}
use of fr.glowstoner.fireapi.bigbrother.spy.BigBrotherSpyHistory in project FireAPI by FireBlade-Serv.
the class SpyCommand method execute.
@Override
public void execute(ConnectionHandler c, String command, String[] args) {
if (args.length == 0) {
c.sendMessageWithPrefix("Usage : /spy full <joueur>");
c.sendMessageWithPrefix("Usage : /spy search <joueur> <format>");
c.sendMessageWithPrefix("Usage : /spy chat <joueur>");
c.sendMessageWithPrefix("Usage : /spy list");
} else if (args.length == 1) {
if (args[0].equalsIgnoreCase("full")) {
c.sendMessageWithPrefix("Usage : /spy full <joueur>");
} else if (args[0].equalsIgnoreCase("search")) {
c.sendMessageWithPrefix("Usage : /spy search <joueur> <format>");
} else if (args[0].equalsIgnoreCase("chat")) {
c.sendMessageWithPrefix("Usage : /spy chat <joueur>");
} else if (args[0].equalsIgnoreCase("list")) {
c.sendMessageWithPrefix("Voici tout les fichiers de joueur répertoriés :");
for (File f : BigBrotherSpyUtils.getAllSpyFiles()) {
c.sendMessageWithPrefix("- " + f.getName());
}
} else {
c.sendMessageWithPrefix("Usage : /spy full <joueur>");
c.sendMessageWithPrefix("Usage : /spy search <joueur> <format>");
c.sendMessageWithPrefix("Usage : /spy chat <joueur>");
}
} else if (args.length == 2) {
if (args[0].equalsIgnoreCase("full")) {
try {
BigBrotherSpyUtils.sendInfosToClient(c, args[1]);
} catch (Exception e) {
c.sendMessageWithPrefix("Erreur, ce joueur n'a pas été trouvé ! " + e.getClass().getSimpleName());
}
} else if (args[0].equalsIgnoreCase("chat")) {
c.sendMessageWithPrefix("Veuillez patienter pendant la recherche. Cela peut prendre du temps ...");
try {
BigBrotherSpyUtils.sendInfosChatToClient(c, args[1]);
} catch (Exception e) {
c.sendMessageWithPrefix("Erreur, ce joueur n'a pas été trouvé ! " + e.getClass().getSimpleName());
}
} else if (args[0].equalsIgnoreCase("search")) {
c.sendMessageWithPrefix("Usage : /spy search <joueur> <format>");
} else {
c.sendMessageWithPrefix("Usage : /spy full <joueur>");
c.sendMessageWithPrefix("Usage : /spy search <joueur> <message>");
}
} else if (args.length == 3) {
if (args[0].equalsIgnoreCase("search")) {
c.sendMessageWithPrefix("Veuillez patienter pendant la recherche. Cela peut prendre du temps ...");
BigBrotherSpyHistory h = null;
try {
h = this.gs.getHistory(args[1]);
} catch (Exception e) {
h = null;
}
if (h == null) {
c.sendMessageWithPrefix("Erreur, ce joueur n'a pas été trouvé !");
} else {
List<BigBrotherSpyHistoryData> occ = BigBrotherSpyUtils.getAllMessagesContainsMessage(args[2], h);
if (occ.size() == 0) {
c.sendMessageWithPrefix("Terminé !");
c.sendMessageWithPrefix("Aucun message trouvé pour \"" + args[2] + "\".");
} else {
c.sendMessageWithPrefix("Terminé !");
c.sendMessageWithPrefix("Résulats trouvés : " + occ.size() + "\n");
for (BigBrotherSpyHistoryData hs : occ) {
c.sendMessageWithPrefix(hs.getFormatedMessage());
}
}
}
}
}
}
Aggregations