add empty message validation

This commit is contained in:
ghost 2024-05-01 01:41:52 +03:00
parent 8cb4fe21ca
commit 185d68e909
2 changed files with 72 additions and 53 deletions

View File

@ -105,6 +105,10 @@
[ [
"\u001b[31mReached message length limit!\u001b[0m" "\u001b[31mReached message length limit!\u001b[0m"
], ],
"empty":
[
"\u001b[31mMessage could not be empty!\u001b[0m"
],
"internal": "internal":
[ [
"\u001b[31mSomething went wrong, please make your feedback!\u001b[0m", "\u001b[31mSomething went wrong, please make your feedback!\u001b[0m",

View File

@ -183,67 +183,82 @@ class Ratchet implements MessageComponentInterface
// Check message commit by dot // Check message commit by dot
if ($request == '.') if ($request == '.')
{ {
// Save massage to KevaCoin blockchain // Check message not empty
if ($txid = $this->_kevacoin->kevaPut($this->_config->kevacoin->wallet->namespace, time(), $connection->message)) if (empty(trim($connection->message)))
{
// Return success response
$connection->send(
str_replace(
[
'{name}',
'{txid}'
],
[
$this->_config->kevacoin->wallet->namespace,
$txid
],
implode(
PHP_EOL,
$config->response->submit->success
) . PHP_EOL
)
);
// Print transaction debug info on enabled
if ($this->_config->kevacoin->event->put->debug->enabled)
{
print(
str_ireplace(
[
'{time}',
'{host}',
'{crid}',
'{name}',
'{txid}',
'{keva}'
],
[
(string) date('c'),
(string) $connection->remoteAddress,
(string) $connection->resourceId,
(string) $this->_config->kevacoin->wallet->namespace,
(string) $txid,
(string) $this->_kevacoin->getBalance(
$this->_config->kevacoin->wallet->account
)
],
$this->_config->kevacoin->event->put->debug->template
) . PHP_EOL
);
}
}
// Could not receive transaction, something went wrong
else
{ {
$connection->send( $connection->send(
implode( implode(
PHP_EOL, PHP_EOL,
$config->response->submit->failure->internal $config->response->submit->failure->empty
) . PHP_EOL ) . PHP_EOL
); );
} }
// Max length already checked on input, begin message save
else
{
// Save massage to KevaCoin blockchain
if ($txid = $this->_kevacoin->kevaPut($this->_config->kevacoin->wallet->namespace, time(), $connection->message))
{
// Return success response
$connection->send(
str_replace(
[
'{name}',
'{txid}'
],
[
$this->_config->kevacoin->wallet->namespace,
$txid
],
implode(
PHP_EOL,
$config->response->submit->success
) . PHP_EOL
)
);
// Print transaction debug info on enabled
if ($this->_config->kevacoin->event->put->debug->enabled)
{
print(
str_ireplace(
[
'{time}',
'{host}',
'{crid}',
'{name}',
'{txid}',
'{keva}'
],
[
(string) date('c'),
(string) $connection->remoteAddress,
(string) $connection->resourceId,
(string) $this->_config->kevacoin->wallet->namespace,
(string) $txid,
(string) $this->_kevacoin->getBalance(
$this->_config->kevacoin->wallet->account
)
],
$this->_config->kevacoin->event->put->debug->template
) . PHP_EOL
);
}
}
// Could not receive transaction, something went wrong
else
{
$connection->send(
implode(
PHP_EOL,
$config->response->submit->failure->internal
) . PHP_EOL
);
}
}
// Close connection at this point // Close connection at this point
$connection->close(); $connection->close();
} }