push code adverts
This commit is contained in:
@@ -60,12 +60,39 @@ class CoreParser {
|
||||
case CoreProtocol::RESP_CODE_CHANNEL_MSG_RECV_V3:
|
||||
case CoreProtocol::RESP_CODE_CHANNEL_MSG_RECV:
|
||||
return $payload;
|
||||
case CoreProtocol::PUSH_CODE_ADVERT:
|
||||
case CoreProtocol::PUSH_CODE_NEW_ADVERT:
|
||||
return self::parseAdvert($payload);
|
||||
default:
|
||||
echo "Unparsed response: " . \Menking\Meshcore\Util\Debug::hexDump($payload) . "\n";
|
||||
return $payload;
|
||||
}
|
||||
}
|
||||
|
||||
protected static function parseAdvert(string $payload): mixed {
|
||||
$data = [
|
||||
'code'=>ord($payload[0]),
|
||||
'pub_key'=>base64_encode(substr($payload, 1, CoreProtocol::PUB_KEY_SIZE))
|
||||
];
|
||||
|
||||
if( strlen($payload) > CoreProtocol::PUB_KEY_SIZE ) {
|
||||
$new_data = [
|
||||
'type'=>ord($payload[33]),
|
||||
'flags'=>ord($payload[34]),
|
||||
'out_path'=>substr($payload, 35, CoreProtocol::MAX_PATH_SIZE),
|
||||
'name'=>substr($payload, 99, 32),
|
||||
'last_advert_time'=>unpack('V', substr($payload, 203, 4))[1],
|
||||
'lat'=>unpack('V', substr($payload, 207, 4))[1],
|
||||
'lon'=>unpack('V', substr($payload, 211, 4))[1],
|
||||
'last_mod'=>unpack('V', substr($payload, 215, 4))[1],
|
||||
];
|
||||
|
||||
$data = array_merge($data, $new_data);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $payload
|
||||
|
||||
Reference in New Issue
Block a user