From 30b68bcf6820c73bb210205de145ed3f100053d7 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 21 Jan 2021 00:29:57 +0100 Subject: [PATCH] add discord --- classen/discord.php | 19 +++++++++++++++++++ cron/regionChecker.php | 28 +++++++++++++++++++++------- index.php | 1 + style/discordMessage.json | 9 +++++++++ 4 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 classen/discord.php create mode 100644 style/discordMessage.json diff --git a/classen/discord.php b/classen/discord.php new file mode 100644 index 0000000..9a8db41 --- /dev/null +++ b/classen/discord.php @@ -0,0 +1,19 @@ + [ + 'method' => 'POST', + 'header' => 'Content-Type: application/json', + 'timeout' => 3, + 'content' => $RAWmessage + ] + ]; + + $result = file_get_contents($webhook, false, stream_context_create($options)); + } +?> \ No newline at end of file diff --git a/cron/regionChecker.php b/cron/regionChecker.php index 5d45063..91f0a1d 100644 --- a/cron/regionChecker.php +++ b/cron/regionChecker.php @@ -1,5 +1,5 @@ prepare("CREATE TABLE IF NOT EXISTS `regions_info` (`regionID` VARCHAR(36) NOT NULL COLLATE 'utf8_unicode_ci', `RegionVersion` VARCHAR(128) NOT NULL DEFAULT '' COLLATE 'utf8_unicode_ci', `ProcMem` INT(11) NOT NULL, `Prims` INT(11) NOT NULL, `SimFPS` INT(11) NOT NULL, `PhyFPS` INT(11) NOT NULL, PRIMARY KEY (`regionID`) USING BTREE) COLLATE='utf8_unicode_ci' ENGINE=InnoDB;"); + $createStatement = $RUNTIME['PDO']->prepare("CREATE TABLE IF NOT EXISTS `regions_info` (`regionID` VARCHAR(36) NOT NULL COLLATE 'utf8_unicode_ci', `RegionVersion` VARCHAR(128) NOT NULL DEFAULT '' COLLATE 'utf8_unicode_ci', `ProcMem` INT(11) NOT NULL, `Prims` INT(11) NOT NULL, `SimFPS` INT(11) NOT NULL, `PhyFPS` INT(11) NOT NULL, `OfflineTimer` INT(11) NOT NULL DEFAULT '0', PRIMARY KEY (`regionID`) USING BTREE) COLLATE='utf8_unicode_ci' ENGINE=InnoDB;"); $createStatement->execute(); $statement = $RUNTIME['PDO']->prepare("SELECT * FROM regions"); @@ -19,16 +19,30 @@ if($result == FALSE || $result == "") { - sendInworldIM("00000000-0000-0000-0000-000000000000", $row['owner_uuid'], "Inventory", $RUNTIME['GRID']['HOMEURL'], "WARNUNG: Deine Region '".$row['regionName']."' ist nicht erreichbar und wurde deshalb aus dem Grid entfernt."); echo "Die Region ".$row['regionName']." von ".$RUNTIME['OPENSIM']->getUserName($row['owner_uuid'])." ist nicht erreichbar.\n"; - $statementUpdate = $RUNTIME['PDO']->prepare('DELETE FROM regions WHERE uuid = :uuid'); - $statementUpdate->execute(['uuid' => $row['uuid']]); + $infoStatement = $RUNTIME['PDO']->prepare("SELECT * FROM regions_info WHERE regionID = :regionID"); + $infoStatement->execute(['regionID' => $row['uuid']]); + + if($infoRow = $infoStatement->fetch()) + { + if(($infoRow['OfflineTimer'] + 3600) <= time()) + { + echo "Die Region ".$row['regionName']." von ".$RUNTIME['OPENSIM']->getUserName($row['owner_uuid'])." ist seit über eine Stunde nicht erreichbar!\n"; + + //sendInworldIM("00000000-0000-0000-0000-000000000000", $row['owner_uuid'], "Region", $RUNTIME['GRID']['HOMEURL'], "WARNUNG: Deine Region '".$row['regionName']."' ist nicht erreichbar und wurde deshalb aus dem Grid entfernt."); + + //$statementUpdate = $RUNTIME['PDO']->prepare('DELETE FROM regions WHERE uuid = :uuid'); + //$statementUpdate->execute(['uuid' => $row['uuid']]); + }else{ + //sendInworldIM("00000000-0000-0000-0000-000000000000", $row['owner_uuid'], "Region", $RUNTIME['GRID']['HOMEURL'], "WARNUNG: Deine Region '".$row['regionName']."' ist nicht erreichbar!"); + } + } }else{ $regionData = json_decode($result); - $statementAccounts = $RUNTIME['PDO']->prepare('REPLACE INTO `regions_info` (`regionID`, `RegionVersion`, `ProcMem`, `Prims`, `SimFPS`, `PhyFPS`) VALUES (:regionID, :RegionVersion, :ProcMem, :Prims, :SimFPS, :PhyFPS)'); - $statementAccounts->execute(['regionID' => $row['uuid'], 'RegionVersion' => $regionData->Version, 'ProcMem' => $regionData->ProcMem, 'Prims' => $regionData->Prims, 'SimFPS' => $regionData->SimFPS, 'PhyFPS' => $regionData->PhyFPS]); + $statementAccounts = $RUNTIME['PDO']->prepare('REPLACE INTO `regions_info` (`regionID`, `RegionVersion`, `ProcMem`, `Prims`, `SimFPS`, `PhyFPS`, `OfflineTimer`) VALUES (:regionID, :RegionVersion, :ProcMem, :Prims, :SimFPS, :PhyFPS, :OfflineTimer)'); + $statementAccounts->execute(['regionID' => $row['uuid'], 'RegionVersion' => $regionData->Version, 'ProcMem' => $regionData->ProcMem, 'Prims' => $regionData->Prims, 'SimFPS' => $regionData->SimFPS, 'PhyFPS' => $regionData->PhyFPS, 'OfflineTimer' => time()]); } - } + } ?> \ No newline at end of file diff --git a/index.php b/index.php index e7bf656..75e5266 100644 --- a/index.php +++ b/index.php @@ -11,6 +11,7 @@ include_once("classen/utils.php"); include_once("classen/HTML.php"); include_once("classen/GoogleAuthenticator.php"); include_once("classen/OpenSim.php"); +include_once("classen/discord.php"); $RUNTIME = array(); $RUNTIME['OPENSIM'] = new OpenSim(); diff --git a/style/discordMessage.json b/style/discordMessage.json new file mode 100644 index 0000000..dba8593 --- /dev/null +++ b/style/discordMessage.json @@ -0,0 +1,9 @@ +{ + "embeds": [ + { + "title": "%%title%%", + "description": "%%message%%", + "color": 13359655 + } + ] + } \ No newline at end of file