Browse Source

remove key protocol dependency

main
ghost 8 months ago
parent
commit
61b86e264d
  1. 7
      example/config.json
  2. 35
      src/controller/room.php

7
example/config.json

@ -71,11 +71,11 @@
{ {
"key": "key":
{ {
"regex":"/^([\\d]{1,64})@([A-z0-9-_]{1,64})$/" "regex":"/^.{1,255}$/ui"
}, },
"value": "value":
{ {
"regex":"/.{1,3072}/ui" "regex":"/^.{1,3072}$/ui"
}, },
"pool": "pool":
{ {
@ -92,7 +92,8 @@
{ {
"name": "name":
{ {
"regex":"/^[0-9A-z-]{2,16}$/ui" "regex":"/^[0-9A-z-]{2,16}$/ui",
"guest":"anon"
} }
} }
} }

35
src/controller/room.php

@ -398,11 +398,7 @@ class Room
$this->_config->kevachat->post->pool->account $this->_config->kevachat->post->pool->account
), ),
':namespace' => $namespace, ':namespace' => $namespace,
':key' => sprintf( ':key' => time(),
'%d@%s',
time(),
'anon'
),
':value' => $message ':value' => $message
] ]
); );
@ -426,11 +422,7 @@ class Room
// Make blockchain record // Make blockchain record
return $this->_kevacoin->kevaPut( return $this->_kevacoin->kevaPut(
$namespace, $namespace,
sprintf(
'%d@%s',
time(), time(),
'anon'
),
$message $message
); );
} }
@ -527,25 +519,36 @@ class Room
} }
// Validate value format allowed in settings // Validate value format allowed in settings
if (!preg_match((string) $this->_config->kevachat->post->value->regex, $data['value'])) if (!preg_match($this->_config->kevachat->post->value->regex, $data['value']))
{ {
return null; return null;
} }
// Validate key format allowed in settings // Validate key format allowed in settings
if (!preg_match($this->_config->kevachat->post->key->regex, $data['key'], $key)) if (!preg_match($this->_config->kevachat->post->key->regex, $data['key']))
{ {
return null; return null;
} }
// Validate timestamp@username // Get transaction time
if (empty($key[1]) || empty($key[2])) if (!$transaction = $this->_kevacoin->getRawTransaction($data['txid']))
{ {
return null; return null;
} }
// Detect username (key @postfix)
if (preg_match('/@([^@]+)$/', $data['key'], $match))
{
$user = $match[1];
}
else
{
$user = $this->_config->kevachat->user->name->guest;
}
// Return timestamp // Return timestamp
$time = (int) $key[1]; $time = isset($transaction['time']) ? $transaction['time'] : time();
// Is raw field request // Is raw field request
if ($field) if ($field)
@ -664,11 +667,11 @@ class Room
[ [
// time // time
$this->_ago( $this->_ago(
$key[1] $time
), ),
// author // author
$key[2], $user,
// quote // quote
$quote, $quote,

Loading…
Cancel
Save