clrghouz/app/Classes/FTN.php

66 lines
1.3 KiB
PHP
Raw Normal View History

2019-03-03 14:29:35 +00:00
<?php
namespace App\Classes;
use App\Models\{Address,Zone};
2021-06-29 10:43:29 +00:00
2019-03-03 14:29:35 +00:00
abstract class FTN
{
protected ?Zone $zone; // Zone the packet is from
2023-09-05 09:57:34 +00:00
public function __get(string $key)
2021-06-29 10:43:29 +00:00
{
switch ($key) {
case 'fftn_t':
2021-06-29 10:43:29 +00:00
return sprintf('%d:%d/%d.%d',
$this->fz,
$this->fn,
$this->ff,
$this->fp,
).($this->zone ? sprintf('@%s',$this->zone->domain->name) : '');
2021-06-29 10:43:29 +00:00
case 'tftn_t':
2021-06-29 10:43:29 +00:00
return sprintf('%d:%d/%d.%d',
$this->tz,
$this->tn,
$this->tf,
$this->tp,
).($this->zone ? sprintf('@%s',$this->zone->domain->name) : '');
2021-06-29 10:43:29 +00:00
case 'fftn':
return Address::findFTN($this->fftn_t);
case 'tftn':
return Address::findFTN($this->tftn_t);
2021-06-29 10:43:29 +00:00
default:
throw new \Exception('Unknown key: '.$key);
}
}
2019-03-03 14:29:35 +00:00
/**
* This function creates our unpack header
2021-06-29 10:43:29 +00:00
*
* @param array $pack
2019-03-03 14:29:35 +00:00
* @return string
2023-06-27 07:39:11 +00:00
* @throws \Exception
2019-03-03 14:29:35 +00:00
*/
protected static function unpackheader(array $pack): string
2019-03-03 14:29:35 +00:00
{
// Check that our header is correct
if (app()->environment('local')) {
$c = 0;
foreach (collect($pack) as $item) {
if ($c !== $item[0])
throw new \Exception('Invalid header');
$c += $item[2];
}
}
return collect($pack)
->sortBy(function($k,$v) {return $k[0];})
->transform(function($k,$v) {return $k[1].$v;})
->values()
->join('/');
2019-03-03 14:29:35 +00:00
}
}