|
|
@ -107,6 +107,9 @@ class Ratchet implements MessageComponentInterface |
|
|
|
// Init connection counter |
|
|
|
// Init connection counter |
|
|
|
$connection->count = 0; |
|
|
|
$connection->count = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Init connection message |
|
|
|
|
|
|
|
$connection->message = ''; |
|
|
|
|
|
|
|
|
|
|
|
// Debug open event on enabled |
|
|
|
// Debug open event on enabled |
|
|
|
if ($config->event->open->debug->enabled) |
|
|
|
if ($config->event->open->debug->enabled) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -146,79 +149,152 @@ class Ratchet implements MessageComponentInterface |
|
|
|
// Init config namespace |
|
|
|
// Init config namespace |
|
|
|
$config = $this->_config->nps->event->message; |
|
|
|
$config = $this->_config->nps->event->message; |
|
|
|
|
|
|
|
|
|
|
|
// Captcha request first for unconfirmed connections |
|
|
|
// Debug message event on enabled |
|
|
|
if (!$connection->confirmed) |
|
|
|
if ($config->debug->enabled) |
|
|
|
{ |
|
|
|
|
|
|
|
// Request match captcha |
|
|
|
|
|
|
|
if ($request == $connection->captcha) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
$connection->confirmed = true; |
|
|
|
print( |
|
|
|
|
|
|
|
str_ireplace( |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
'{time}', |
|
|
|
|
|
|
|
'{host}', |
|
|
|
|
|
|
|
'{crid}', |
|
|
|
|
|
|
|
'{code}', |
|
|
|
|
|
|
|
'{iter}', |
|
|
|
|
|
|
|
'{sent}', |
|
|
|
|
|
|
|
'{size}' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
(string) date('c'), |
|
|
|
|
|
|
|
(string) $connection->remoteAddress, |
|
|
|
|
|
|
|
(string) $connection->resourceId, |
|
|
|
|
|
|
|
(string) $connection->captcha, |
|
|
|
|
|
|
|
(string) $connection->count, |
|
|
|
|
|
|
|
(string) str_replace('%', '%%', $request), |
|
|
|
|
|
|
|
(string) mb_strlen($request) |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
$config->debug->template |
|
|
|
|
|
|
|
) . PHP_EOL |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Connection confirmed |
|
|
|
|
|
|
|
if ($connection->confirmed) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Check message commit by dot |
|
|
|
|
|
|
|
if ($request == '.') |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Save massage to KevaCoin blockchain |
|
|
|
|
|
|
|
if ($txid = $this->_kevacoin->kevaPut($this->_config->kevacoin->wallet->namespace, time(), $connection->message)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Return success response |
|
|
|
$connection->send( |
|
|
|
$connection->send( |
|
|
|
|
|
|
|
str_replace( |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
'{name}', |
|
|
|
|
|
|
|
'{txid}' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
$this->_config->kevacoin->wallet->namespace, |
|
|
|
|
|
|
|
$txid |
|
|
|
|
|
|
|
], |
|
|
|
implode( |
|
|
|
implode( |
|
|
|
PHP_EOL, |
|
|
|
PHP_EOL, |
|
|
|
$config->response->captcha->success |
|
|
|
$config->response->submit->success |
|
|
|
) . PHP_EOL |
|
|
|
) . 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 |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Captcha request invalid |
|
|
|
// Could not receive transaction, something went wrong |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
$connection->confirmed = false; |
|
|
|
$connection->send( |
|
|
|
|
|
|
|
implode( |
|
|
|
|
|
|
|
PHP_EOL, |
|
|
|
|
|
|
|
$config->response->submit->failure->internal |
|
|
|
|
|
|
|
) . PHP_EOL |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Close connection at this point |
|
|
|
|
|
|
|
$connection->close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Complete message by new line sent |
|
|
|
|
|
|
|
$connection->message .= $request . PHP_EOL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check total message length limit allowed by KevaCoin protocol |
|
|
|
|
|
|
|
if (mb_strlen($connection->message) > 3074) |
|
|
|
|
|
|
|
{ |
|
|
|
$connection->send( |
|
|
|
$connection->send( |
|
|
|
implode( |
|
|
|
implode( |
|
|
|
PHP_EOL, |
|
|
|
PHP_EOL, |
|
|
|
$config->response->captcha->failure |
|
|
|
$config->response->submit->failure->length |
|
|
|
) . PHP_EOL |
|
|
|
) . PHP_EOL |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// Drop connection or do something else.. |
|
|
|
|
|
|
|
$connection->close(); |
|
|
|
$connection->close(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// @TODO compose request to KevaCoin, return transaction ID |
|
|
|
// Captcha request |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Save massage to kevacoin |
|
|
|
// Request match captcha |
|
|
|
/* |
|
|
|
if ($request == $connection->captcha) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$connection->confirmed = true; |
|
|
|
|
|
|
|
|
|
|
|
$connection->send( |
|
|
|
$connection->send( |
|
|
|
implode( |
|
|
|
implode( |
|
|
|
PHP_EOL, |
|
|
|
PHP_EOL, |
|
|
|
$config->response->captcha->failure |
|
|
|
$config->response->captcha->success |
|
|
|
) . PHP_EOL |
|
|
|
) . PHP_EOL |
|
|
|
); |
|
|
|
); |
|
|
|
*/ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Debug message event on enabled |
|
|
|
// Captcha request invalid |
|
|
|
if ($config->debug->enabled) |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
print( |
|
|
|
$connection->confirmed = false; |
|
|
|
str_ireplace( |
|
|
|
|
|
|
|
[ |
|
|
|
$connection->send( |
|
|
|
'{time}', |
|
|
|
implode( |
|
|
|
'{host}', |
|
|
|
PHP_EOL, |
|
|
|
'{crid}', |
|
|
|
$config->response->captcha->failure |
|
|
|
'{code}', |
|
|
|
|
|
|
|
'{iter}', |
|
|
|
|
|
|
|
'{sent}', |
|
|
|
|
|
|
|
'{size}' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
(string) date('c'), |
|
|
|
|
|
|
|
(string) $connection->remoteAddress, |
|
|
|
|
|
|
|
(string) $connection->resourceId, |
|
|
|
|
|
|
|
(string) $connection->captcha, |
|
|
|
|
|
|
|
(string) $connection->count, |
|
|
|
|
|
|
|
(string) str_replace('%', '%%', $request), |
|
|
|
|
|
|
|
(string) mb_strlen($request) |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
$config->debug->template |
|
|
|
|
|
|
|
) . PHP_EOL |
|
|
|
) . PHP_EOL |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$connection->close(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|