Colour suspect messages

This commit is contained in:
Keir Nellyer 2016-08-09 15:17:19 +01:00
parent 6294e66484
commit 31800ee1e7
2 changed files with 357 additions and 339 deletions

View File

@ -98,6 +98,10 @@ h2,h3,h4,h5,h6 {
padding-right: 10px;
}
.suspect-message {
color: #ED9898;
}
#test-bar {
align-content: center;
padding-top: 20px;

View File

@ -1,367 +1,367 @@
<?php
require_once('snapshot.php');
require_once('report.php');
require_once('message.php');
require_once('user.php');
require_once('user_report.php');
require_once('snapshot.php');
require_once('report.php');
require_once('message.php');
require_once('user.php');
require_once('user_report.php');
const collapsedMessageCount = 20;
const collapsedMessageCount = 20;
// In Java this is "DateTimeFormatter.ISO_LOCAL_DATE_TIME"
const jsonDateTimeFormat = 'Y-m-d\TH:i:s';
// In Java this is "DateTimeFormatter.ISO_LOCAL_DATE_TIME"
const jsonDateTimeFormat = 'Y-m-d\TH:i:s';
$dateTimeZone = new DateTimeZone('America/Chicago');
$dateTimeZone = new DateTimeZone('America/Chicago');
/** @var mysqli[] $connections */
$connections = array(); // String index = Connection name
/** @var mysqli[] $connections */
$connections = array(); // String index = Connection name
/** @var User[] $users */ // Account id index
$users = array();
/** @var User[] $users */ // Account id index
$users = array();
$categories = array(
1 => "Hacking",
2 => "Chat Abuse",
3 => "Gameplay"
);
$categories = array(
1 => 'Hacking',
2 => 'Chat Abuse',
3 => 'Gameplay'
);
/** PARSE DB CONNECTIONS */
/** PARSE DB CONNECTIONS */
$dbConfigFile = new SplFileObject('database-config.dat');
$dbConfigFile = new SplFileObject('database-config.dat');
if ($dbConfigFile->isFile())
{
while (!$dbConfigFile->eof())
if ($dbConfigFile->isFile())
{
$line = trim($dbConfigFile->fgets());
if ($line) // check not empty line
while (!$dbConfigFile->eof())
{
$parts = explode(' ', $line);
$fullUrl = $parts[1];
$urlParts = explode('/', $fullUrl);
$host = $urlParts[0];
$database = $urlParts[1];
$line = trim($dbConfigFile->fgets());
$name = $parts[0];
$username = $parts[2];
$password = $parts[3];
if ($line) // check not empty line
{
$parts = explode(' ', $line);
$fullUrl = $parts[1];
$urlParts = explode('/', $fullUrl);
$host = $urlParts[0];
$database = $urlParts[1];
$connection = new mysqli($host, $username, $password, $database);
$name = $parts[0];
$username = $parts[2];
$password = $parts[3];
if ($connection->connect_error) {
die("Connection \"$name\" failed: $connection->connect_error");
$connection = new mysqli($host, $username, $password, $database);
if ($connection->connect_error) {
die("Connection \"$name\" failed: $connection->connect_error");
}
$connections[$name] = $connection;
}
$connections[$name] = $connection;
}
}
}
else
{
die('database-config.dat does not exist or is not a file.');
}
else
{
die('database-config.dat does not exist or is not a file.');
}
/**
* @param String $name
* @return mysqli
*/
function getConnection($name)
{
global $connections;
return $connections[$name];
}
/**
* @param String $name
* @return mysqli
*/
function getConnection($name)
{
global $connections;
return $connections[$name];
}
/**
* @param Int $reportId
* @return Report
*/
function getReport($reportId)
{
$connection = getConnection("ACCOUNT");
$statement = $connection->prepare('SELECT reports.suspectId, reports.categoryId, reportHandlers.handlerId FROM reports
/**
* @param Int $reportId
* @return Report
*/
function getReport($reportId)
{
$connection = getConnection("ACCOUNT");
$statement = $connection->prepare('SELECT reports.suspectId, reports.categoryId, reportHandlers.handlerId FROM reports
LEFT JOIN reportHandlers ON reports.id = reportHandlers.reportId
LEFT JOIN reportResults ON reports.id = reportResults.reportId
WHERE reports.id = ?');
$statement->bind_param('i', $reportId);
$statement->execute();
$statement->store_result();
$statement->bind_result($suspectId, $categoryId, $handlerId);
$statement->bind_param('i', $reportId);
$statement->execute();
$statement->store_result();
$statement->bind_result($suspectId, $categoryId, $handlerId);
if ($statement->fetch())
{
$suspectUser = getUser($suspectId);
$reportReasons = getReporters($reportId);
$handlerUser = null;
if (!is_null($handlerId))
if ($statement->fetch())
{
$handlerUser = getUser($handlerId);
$suspectUser = getUser($suspectId);
$reportReasons = getReporters($reportId);
$handlerUser = null;
if (!is_null($handlerId))
{
$handlerUser = getUser($handlerId);
}
return new Report($reportId, $handlerUser, $suspectUser, $reportReasons, $categoryId);
}
return new Report($reportId, $handlerUser, $suspectUser, $reportReasons, $categoryId);
$statement->close();
return null;
}
$statement->close();
function getSnapshot($reportId)
{
/** @var $messages Message[] */
$messages = array();
return null;
}
function getSnapshot($reportId)
{
/** @var $messages Message[] */
$messages = array();
$connection = getConnection("ACCOUNT");
$statement = $connection->prepare("SELECT id, senderId, snapshotType, `server`, `time`, message FROM reportSnapshots, snapshots
$connection = getConnection("ACCOUNT");
$statement = $connection->prepare("SELECT id, senderId, snapshotType, `server`, `time`, message FROM reportSnapshots, snapshots
WHERE snapshots.id = reportSnapshots.snapshotId
AND reportSnapshots.reportId = ?");
$statement->bind_param('i', $reportId);
$statement->execute();
$statement->bind_result($snapshotId, $senderId, $snapshotType, $server, $time, $message);
$statement->store_result();
while ($statement->fetch())
{
$recipients = getUsers(getSnapshotRecipients($snapshotId));
$message = new Message(getUser($senderId), $recipients, $time, $snapshotType, $message, $server);
array_push($messages, $message);
}
$statement->close();
$snapshotUsers = array();
foreach ($messages as $message)
{
$sender = $message->getSender();
$snapshotUsers[$sender->getId()] = $sender;
foreach ($message->getRecipients() as $recipient)
{
$snapshotUsers[$recipient->getId()] = $recipient;
}
}
return new Snapshot($reportId, $messages, $snapshotUsers);
}
/**
* @param $snapshotId
* @return Integer[] array
*/
function getSnapshotRecipients($snapshotId)
{
$recipientIds = array();
$connection = getConnection("ACCOUNT");
$statement = $connection->prepare("SELECT recipientId FROM snapshotRecipients WHERE snapshotId = ?");
$statement->bind_param('i', $snapshotId);
$statement->execute();
$statement->bind_result($recipientId);
while ($statement->fetch())
{
array_push($recipientIds, $recipientId);
}
$statement->close();
return $recipientIds;
}
/**
* @param Integer[] $ids
* @return User[] array
*/
function getUsers($ids)
{
$users = array();
foreach ($ids as $id)
{
array_push($users, getUser($id));
}
return $users;
}
/**
* @param $id
* @return User
*/
function getUser($id)
{
if (isset($users[$id]))
{
return $users[$id];
}
else
{
$connection = getConnection("ACCOUNT");
$statement = $connection->prepare('SELECT uuid, `name`, rank FROM accounts WHERE id = ?');
$statement->bind_param('i', $id);
$statement->bind_param('i', $reportId);
$statement->execute();
$statement->bind_result($uuid, $name, $rank);
$statement->fetch();
$statement->bind_result($snapshotId, $senderId, $snapshotType, $server, $time, $message);
$statement->store_result();
while ($statement->fetch())
{
$recipients = getUsers(getSnapshotRecipients($snapshotId));
$message = new Message(getUser($senderId), $recipients, $time, $snapshotType, $message, $server);
array_push($messages, $message);
}
$statement->close();
$snapshotUsers = array();
foreach ($messages as $message)
{
$sender = $message->getSender();
$snapshotUsers[$sender->getId()] = $sender;
foreach ($message->getRecipients() as $recipient)
{
$snapshotUsers[$recipient->getId()] = $recipient;
}
}
return new Snapshot($reportId, $messages, $snapshotUsers);
}
/**
* @param $snapshotId
* @return Integer[] array
*/
function getSnapshotRecipients($snapshotId)
{
$recipientIds = array();
$connection = getConnection("ACCOUNT");
$statement = $connection->prepare("SELECT recipientId FROM snapshotRecipients WHERE snapshotId = ?");
$statement->bind_param('i', $snapshotId);
$statement->execute();
$statement->bind_result($recipientId);
while ($statement->fetch())
{
array_push($recipientIds, $recipientId);
}
$user = new User($id, $uuid, $name, parseRank($rank));
$users[$id] = $user;
$statement->close();
return $user;
return $recipientIds;
}
}
/**
* @param int $reportId
* @return UserReport[]
*/
function getReporters($reportId)
{
global $dateTimeZone;
$connection = getConnection("ACCOUNT");
$statement = $connection->prepare("SELECT reporterId, `time`, reason FROM reportReasons WHERE reportId = ?");
$reportReasons = array();
$statement->bind_param('i', $reportId);
$statement->execute();
$statement->bind_result($reporterId, $time, $reason);
$statement->store_result(); // prevents issues with other queries running before this statement is closed
while ($statement->fetch())
/**
* @param Integer[] $ids
* @return User[] array
*/
function getUsers($ids)
{
$reportReasons[$reporterId] = new UserReport(getUser($reporterId), new DateTime($time, $dateTimeZone), $reason);
$users = array();
foreach ($ids as $id)
{
array_push($users, getUser($id));
}
return $users;
}
$statement->close();
return $reportReasons;
}
/**
* @param Snapshot $snapshot
* @param Report $report
* @return User[]
*/
function getInvolvedUsers($snapshot, $report)
{
$involvedUsers = $snapshot->getPlayers();
$involvedUsers[$report->getSuspect()->getId()] = $report->getSuspect();
foreach ($report->getReporters() as $reporterReason) {
$reporter = $reporterReason->getUser();
$involvedUsers[$reporter->getId()] = $reporter;
}
return $involvedUsers;
}
/**
* @param string $dbRank
* @return string
*/
function parseRank($dbRank)
{
$rank = $dbRank;
if ($dbRank == 'ALL')
/**
* @param $id
* @return User
*/
function getUser($id)
{
$rank = 'PLAYER';
if (isset($users[$id]))
{
return $users[$id];
}
else
{
$connection = getConnection("ACCOUNT");
$statement = $connection->prepare('SELECT uuid, `name`, rank FROM accounts WHERE id = ?');
$statement->bind_param('i', $id);
$statement->execute();
$statement->bind_result($uuid, $name, $rank);
$statement->fetch();
$user = new User($id, $uuid, $name, parseRank($rank));
$users[$id] = $user;
$statement->close();
return $user;
}
}
return $rank;
}
/**
* @param int $reportId
* @return UserReport[]
*/
function getReporters($reportId)
{
global $dateTimeZone;
/**
* @param Message $messageA
* @param Message $messageB
* @return int
*/
function compareMessageTimes($messageA, $messageB)
{
return $messageA->getTimestamp()->getTimestamp() - $messageB->getTimestamp()->getTimestamp();
}
$connection = getConnection("ACCOUNT");
$statement = $connection->prepare("SELECT reporterId, `time`, reason FROM reportReasons WHERE reportId = ?");
$reportReasons = array();
/**
* @param String $dateTime
* @param DateTimeZone $timezone
* @return DateTime
*/
function parseDateTime($dateTime, $timezone)
{
return DateTime::createFromFormat(jsonDateTimeFormat, $dateTime, $timezone);
}
$statement->bind_param('i', $reportId);
$statement->execute();
$statement->bind_result($reporterId, $time, $reason);
$statement->store_result(); // prevents issues with other queries running before this statement is closed
/**
* Converts an interval to minutes, days or months, depending on the size.
*
* @param DateInterval $interval
* @return string
*/
function approximateHumanInterval($interval)
{
if ($interval->y > 0)
{
$humanString = $interval->y . ' year' . ($interval->y != 1 ? 's' : '');
} else if ($interval->m > 0)
{
$humanString = $interval->m . ' month' . ($interval->m != 1 ? 's' : '');
}
else if ($interval->d > 0)
{
$humanString = $interval->d . ' day' . ($interval->d != 1 ? 's' : '');
}
else if ($interval->h > 0)
{
$humanString = $interval->h . ' hour' . ($interval->h != 1 ? 's' : '');
}
else if ($interval->i > 0)
{
$humanString = $interval->i . ' minute' . ($interval->i != 1 ? 's' : '');
}
else
{
$humanString = $interval->s . ' second' . ($interval->s != 1 ? 's' : '');
while ($statement->fetch())
{
$reportReasons[$reporterId] = new UserReport(getUser($reporterId), new DateTime($time, $dateTimeZone), $reason);
}
$statement->close();
return $reportReasons;
}
return $humanString;
}
function getExpandedURL()
{
$vars = $_GET;
$vars['expanded'] = true;
return '?' . http_build_query($vars);
}
$validId = isset($_GET['id']);
$idError = "";
$id = null;
$expanded = null;
$report = null;
$snapshot = null;
if ($validId)
{
$id = $_GET['id'];
$expanded = isset($_GET['expanded']) && $_GET['expanded'];
$report = getReport($id);
if ($report)
/**
* @param Snapshot $snapshot
* @param Report $report
* @return User[]
*/
function getInvolvedUsers($snapshot, $report)
{
$snapshot = getSnapshot($id);
$involvedUsers = $snapshot->getPlayers();
$involvedUsers[$report->getSuspect()->getId()] = $report->getSuspect();
foreach ($report->getReporters() as $reporterReason) {
$reporter = $reporterReason->getUser();
$involvedUsers[$reporter->getId()] = $reporter;
}
return $involvedUsers;
}
else
/**
* @param string $dbRank
* @return string
*/
function parseRank($dbRank)
{
$validId = false;
$idError = "Invalid id.";
$rank = $dbRank;
if ($dbRank == 'ALL')
{
$rank = 'PLAYER';
}
return $rank;
}
/**
* @param Message $messageA
* @param Message $messageB
* @return int
*/
function compareMessageTimes($messageA, $messageB)
{
return $messageA->getTimestamp()->getTimestamp() - $messageB->getTimestamp()->getTimestamp();
}
/**
* @param String $dateTime
* @param DateTimeZone $timezone
* @return DateTime
*/
function parseDateTime($dateTime, $timezone)
{
return DateTime::createFromFormat(jsonDateTimeFormat, $dateTime, $timezone);
}
/**
* Converts an interval to minutes, days or months, depending on the size.
*
* @param DateInterval $interval
* @return string
*/
function approximateHumanInterval($interval)
{
if ($interval->y > 0)
{
$humanString = $interval->y . ' year' . ($interval->y != 1 ? 's' : '');
} else if ($interval->m > 0)
{
$humanString = $interval->m . ' month' . ($interval->m != 1 ? 's' : '');
}
else if ($interval->d > 0)
{
$humanString = $interval->d . ' day' . ($interval->d != 1 ? 's' : '');
}
else if ($interval->h > 0)
{
$humanString = $interval->h . ' hour' . ($interval->h != 1 ? 's' : '');
}
else if ($interval->i > 0)
{
$humanString = $interval->i . ' minute' . ($interval->i != 1 ? 's' : '');
}
else
{
$humanString = $interval->s . ' second' . ($interval->s != 1 ? 's' : '');
}
return $humanString;
}
function getExpandedURL()
{
$vars = $_GET;
$vars['expanded'] = true;
return '?' . http_build_query($vars);
}
$validId = isset($_GET['id']);
$idError = "";
$id = null;
$expanded = null;
$report = null;
$snapshot = null;
if ($validId)
{
$id = $_GET['id'];
$expanded = isset($_GET['expanded']) && $_GET['expanded'];
$report = getReport($id);
if ($report)
{
$snapshot = getSnapshot($id);
}
else
{
$validId = false;
$idError = "Invalid id.";
}
}
}
?>
<!DOCTYPE html>
<html>
@ -425,46 +425,60 @@ if ($validId)
<div id="log" class="text-muted ">
<?php
// INITIALIZE
// INITIALIZE
// Get messages and the amount that we are going to display
$messages = $snapshot->getMessages();
$messageCount = count($messages);
$displayAmount = $expanded || $messageCount <= collapsedMessageCount ? $messageCount : collapsedMessageCount;
// Get messages and the amount that we are going to display
$messages = $snapshot->getMessages();
$messageCount = count($messages);
$displayAmount = $expanded || $messageCount <= collapsedMessageCount ? $messageCount : collapsedMessageCount;
// Put all reporter usernames in array for easy access later
$reporterUsernames = array();
foreach ($report->getReporters() as $reporterReason)
{
$reporterUsernames[count($reporterUsernames)] = $reporterReason->getUser()->getUsername();
}
// Put all reporter usernames in array for easy access later
$reporterUsernames = array();
foreach ($report->getReporters() as $reporterReason)
{
$reporterUsernames[count($reporterUsernames)] = $reporterReason->getUser()->getUsername();
}
$involvedUsers = getInvolvedUsers($snapshot, $report);
$involvedUsers = getInvolvedUsers($snapshot, $report);
$reportCreationTime = $report->getTimeCreated();
$age = approximateHumanInterval($reportCreationTime->diff(new DateTime('now', $reportCreationTime->getTimezone())));
$reportCreationTime = $report->getTimeCreated();
$age = approximateHumanInterval($reportCreationTime->diff(new DateTime('now', $reportCreationTime->getTimezone())));
if ($displayAmount == 0): ?>
<span class="black">No chat log available for this report.</span>
<?php else:
for ($i = 0; $i < $displayAmount; $i++):
$message = $messages[$i];
$typeId = $message->getType();
$typeDisplayName = Message::$TYPE_DISPLAY_NAMES[$typeId];
$isPM = $typeId == Message::TYPE_PM;
if ($displayAmount == 0): ?>
<span class="black">No chat log available for this report.</span>
<?php else:
for ($i = 0; $i < $displayAmount; $i++):
$message = $messages[$i];
$typeId = $message->getType();
$typeDisplayName = Message::$TYPE_DISPLAY_NAMES[$typeId];
$isPM = $typeId == Message::TYPE_PM;
// If this is a PM, then the "-> <recipient>" suffix will be applied.
$involved = $message->getSender()->getUsername() . ($isPM ? " -> " . $message->getRecipients()[0]->getUsername() : "");
?>
if ($isPM): ?>
<span class="label label-primary chat pm" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><?= $typeDisplayName ?></span>
<?php else: ?>
<span class="label label-info chat" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><?= $typeDisplayName ?></span>
<?php endif; ?>
<span class="label <?= $isPM ? "label-primary chat pm" : "label-info chat" ?>" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><?= $typeDisplayName ?></span>
<span class="black"><?= $involved; ?>:</span> <?= $message->getMessage(); ?>
<span class="black">
<?php
echo $message->getSender()->getUsername();
<?php if ($i < $displayAmount - 1): // Don't break on the last element ?>
<br />
if ($isPM)
{
echo ' -> ' . $message->getRecipients()[0]->getUsername();
}
echo ': ';
?>
</span>
<span class="<?= ($message->getSender() == $report->getSuspect() ? 'suspect-message' : 'message') ?>"><?= $message->getMessage() ?></span>
<?php if ($i < $displayAmount - 1): // Don't break on the last element ?>
<br />
<?php endif; ?>
<?php endfor; ?>
<?php endif; ?>
<?php endfor; ?>
<?php endif; ?>
</div>
<?php if (!$expanded && $displayAmount < $messageCount): ?>