Push chat snapshots from all servers

This fixes an issue whereby the handler would not be able to see chat
 snapshots unless they begin the handling process whilst connected to
  the same server as the offender.
This commit is contained in:
Keir Nellyer 2016-07-08 23:22:55 -04:00
parent a0d046ab8b
commit d9288277d5
4 changed files with 91 additions and 10 deletions

View File

@ -0,0 +1,35 @@
package mineplex.core.chatsnap.command;
import mineplex.serverdata.commands.ServerCommand;
/**
* This command when executed will get all snapshots involving a particular account and push them to the database.
*/
public class PushSnapshotsCommand extends ServerCommand
{
private final int _accountId;
private final long _reportId;
public PushSnapshotsCommand(int accountId, long reportId)
{
super();
_accountId = accountId;
_reportId = reportId;
}
public int getAccountId()
{
return _accountId;
}
public long getReportId()
{
return _reportId;
}
@Override
public void run()
{
// Utilitizes a callback functionality to seperate dependencies
}
}

View File

@ -0,0 +1,46 @@
package mineplex.core.chatsnap.command;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import mineplex.core.chatsnap.Snapshot;
import mineplex.core.chatsnap.SnapshotManager;
import mineplex.serverdata.commands.CommandCallback;
import mineplex.serverdata.commands.ServerCommand;
/**
* Handles receiving of {@link PushSnapshotsCommand} instances.
*/
public class PushSnapshotsHandler implements CommandCallback
{
private final SnapshotManager _snapshotManager;
private final Logger _logger;
public PushSnapshotsHandler(SnapshotManager snapshotManager, Logger logger)
{
_snapshotManager = snapshotManager;
_logger = logger;
}
@Override
public void run(ServerCommand command)
{
if (command instanceof PushSnapshotsCommand)
{
PushSnapshotsCommand pushCommand = (PushSnapshotsCommand) command;
int accountId = pushCommand.getAccountId();
long reportId = pushCommand.getReportId();
Set<Snapshot> snapshots = _snapshotManager.getSnapshots(accountId);
if (snapshots.size() > 0)
{
_snapshotManager.getSnapshotRepository().insertSnapshots(reportId, snapshots)
.exceptionally(throwable -> {
_logger.log(Level.SEVERE, "Error whilst inserting snapshots into database (" + reportId + ").", throwable);
return null;
});
}
}
}
}

View File

@ -2,13 +2,13 @@ package mineplex.core.report;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.logging.Level; import java.util.logging.Level;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.chatsnap.Snapshot;
import mineplex.core.chatsnap.SnapshotManager; import mineplex.core.chatsnap.SnapshotManager;
import mineplex.core.chatsnap.command.PushSnapshotsCommand;
import mineplex.core.chatsnap.command.PushSnapshotsHandler;
import mineplex.core.command.CommandCenter; import mineplex.core.command.CommandCenter;
import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
@ -58,8 +58,11 @@ public class ReportManager
_reportProfileRepository = new ReportProfileRepository(javaPlugin); _reportProfileRepository = new ReportProfileRepository(javaPlugin);
ReportNotificationCallback callback = new ReportNotificationCallback(this); ServerCommandManager commandManager = ServerCommandManager.getInstance();
ServerCommandManager.getInstance().registerCommandType("ReportHandlerNotification", ReportHandlerNotification.class, callback); ReportNotificationCallback notificationCallback = new ReportNotificationCallback(this);
PushSnapshotsHandler pushHandler = new PushSnapshotsHandler(_snapshotManager, _javaPlugin.getLogger());
commandManager.registerCommandType("ReportHandlerNotification", ReportHandlerNotification.class, notificationCallback);
commandManager.registerCommandType("PushSnapshotsCommand", PushSnapshotsCommand.class, pushHandler);
} }
/** /**
@ -149,12 +152,8 @@ public class ReportManager
if (report.getCategory() == ReportCategory.CHAT_ABUSE) if (report.getCategory() == ReportCategory.CHAT_ABUSE)
{ {
Set<Snapshot> relatedSnapshots = _snapshotManager.getSnapshots(report.getSuspectId()); PushSnapshotsCommand pushCommand = new PushSnapshotsCommand(report.getSuspectId(), reportId);
_snapshotManager.getSnapshotRepository().insertSnapshots(reportId, relatedSnapshots) pushCommand.publish();
.exceptionally(throwable -> {
_javaPlugin.getLogger().log(Level.SEVERE, "Error whilst inserting snapshots into database.", throwable);
return null;
});
} }
_reportRepository.updateReport(report); _reportRepository.updateReport(report);

View File

@ -26,6 +26,7 @@ public class ReportNotification extends ServerCommand
return _notification; return _notification;
} }
@Override
public void run() public void run()
{ {
// Utilitizes a callback functionality to seperate dependencies // Utilitizes a callback functionality to seperate dependencies