diff --git a/app/Classes/FTN/Message.php b/app/Classes/FTN/Message.php index 5b37734..944bbef 100644 --- a/app/Classes/FTN/Message.php +++ b/app/Classes/FTN/Message.php @@ -200,9 +200,9 @@ class Message extends FTNBase * Parse a message from a packet * * @param string $msg - * @param Domain|null $domain + * @param Zone|null $zone * @return Message - * @throws InvalidPacketException + * @throws \Exception */ public static function parseMessage(string $msg,Zone $zone=NULL): self { @@ -402,34 +402,7 @@ class Message extends FTNBase */ public function __unserialize(array $values): void { - $properties = (new \ReflectionClass($this))->getProperties(); - - $class = get_class($this); - - foreach ($properties as $property) { - if ($property->isStatic()) { - continue; - } - - $name = $property->getName(); - $decode = in_array($name,self::cast_utf8); - - if ($property->isPrivate()) { - $name = "\0{$class}\0{$name}"; - } elseif ($property->isProtected()) { - $name = "\0*\0{$name}"; - } - - if (! array_key_exists($name, $values)) { - continue; - } - - $property->setAccessible(true); - - $property->setValue( - $this, $decode ? utf8_decode($values[$name]) : $values[$name] - ); - } + $this->decode($values); } /** diff --git a/app/Classes/FTN/Packet.php b/app/Classes/FTN/Packet.php index 629880a..7d4c14d 100644 --- a/app/Classes/FTN/Packet.php +++ b/app/Classes/FTN/Packet.php @@ -314,20 +314,15 @@ class Packet extends FTNBase implements \Iterator, \Countable */ public function __toString(): string { - // Cache the packet creation - static $return = NULL; + $return = $this->createHeader(); - if (is_null($return)) { - $return = $this->createHeader(); - - foreach ($this->messages as $o) { - if ($o->packed) - $return .= "\02\00".(string)$o; - } - - $return .= "\00\00"; + foreach ($this->messages as $o) { + if ($o->packed) + $return .= "\02\00".(string)$o; } + $return .= "\00\00"; + return $return; } @@ -337,7 +332,7 @@ class Packet extends FTNBase implements \Iterator, \Countable private function createHeader(): string { try { - $a = pack(collect(self::v2header)->pluck(1)->join(''), + $a = pack(collect(self::v2header)->merge(['password' => [0x1a,'a8',8]])->pluck(1)->join(''), $this->ff, $this->tf, Arr::get($this->header,'y'), diff --git a/app/Traits/EncodeUTF8.php b/app/Traits/EncodeUTF8.php index c1affdb..672110b 100644 --- a/app/Traits/EncodeUTF8.php +++ b/app/Traits/EncodeUTF8.php @@ -7,6 +7,38 @@ namespace App\Traits; trait EncodeUTF8 { + private function decode(array $values): void + { + $properties = (new \ReflectionClass($this))->getProperties(); + + $class = get_class($this); + + foreach ($properties as $property) { + if ($property->isStatic()) { + continue; + } + + $name = $property->getName(); + $decode = in_array($name,self::cast_utf8); + + if ($property->isPrivate()) { + $name = "\0{$class}\0{$name}"; + } elseif ($property->isProtected()) { + $name = "\0*\0{$name}"; + } + + if (! array_key_exists($name,$values)) { + continue; + } + + $property->setAccessible(true); + + $property->setValue( + $this,$decode ? utf8_decode($values[$name]) : $values[$name] + ); + } + } + private function encode(): array { $values = [];