clrghouz/app/Classes/FTN/Process/Netmail/Ping.php

66 lines
1.8 KiB
PHP
Raw Normal View History

<?php
namespace App\Classes\FTN\Process\Netmail;
use Carbon\Carbon;
use Carbon\CarbonInterface;
use Illuminate\Support\Facades\Log;
use App\Classes\FTN\{Message,Process};
use App\Models\{Netmail,Setup};
/**
* Process messages to Ping
*
* @package App\Classes\FTN\Process
*/
final class Ping extends Process
{
2021-08-19 06:59:12 +00:00
private const LOGKEY = 'RP-';
private static array $logo = [
'ÚÄ¿þÚÄ¿ÚÄ¿',
'³ ³Â³ ³Àij',
'ÃÄÙÁÁ ÁÄÄÙ'
];
public static function handle(Message $msg): bool
{
if (strtolower($msg->user_to) !== 'ping')
return FALSE;
2021-08-19 06:59:12 +00:00
Log::info(sprintf('%s:- Processing PING message from (%s) [%s]',self::LOGKEY,$msg->user_from,$msg->fftn));
2021-08-08 13:53:56 +00:00
$ftns = Setup::findOrFail(config('app.id'))->system->match($msg->fftn_o->zone)->first();
$reply = sprintf("Your ping was received here on %s and it looks like you sent it on %s. If that is correct, then it took %s to get here.\r",
Carbon::now()->utc()->toDateTimeString(),
$msg->date->utc()->toDateTimeString(),
$msg->date->diffForHumans(['parts'=>3,'syntax'=>CarbonInterface::DIFF_ABSOLUTE])
);
2021-07-17 05:48:07 +00:00
$reply .= "\r";
$reply .= "Your message travelled along this path on the way here:\r";
foreach ($msg->via as $path)
2021-07-17 05:48:07 +00:00
$reply .= sprintf(" * %s\r",$path);
2021-07-17 05:48:07 +00:00
$o = new Netmail;
$o->to = $msg->user_from;
$o->from = Setup::PRODUCT_NAME;
$o->subject = 'Ping Reply';
$o->datetime = Carbon::now();
$o->tzoffset = $o->datetime->utcOffset();
2022-01-01 05:59:35 +00:00
$o->replyid = $msg->msgid;
2021-08-08 13:53:56 +00:00
$o->fftn_id = $ftns->id;
$o->tftn_id = ($x=$msg->fftn_o) ? $x->id : NULL;
$o->flags = Message::FLAG_LOCAL;
$o->cost = 0;
$o->msg = static::format_msg($reply,self::$logo);
$o->tagline = 'My ping pong opponent was not happy with my serve. He kept returning it.';
$o->tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);
$o->save();
return TRUE;
}
}