Browse Source

init kevacoin connection, debug server start event

main
ghost 7 months ago
parent
commit
c364226dd8
  1. 13
      config/example.json
  2. 40
      src/server.php

13
config/example.json

@ -8,6 +8,11 @@ @@ -8,6 +8,11 @@
"port":9992,
"username":"",
"password":""
},
"wallet":
{
"namespace":"",
"account":null
}
},
"nps":
@ -45,6 +50,14 @@ @@ -45,6 +50,14 @@
},
"action":
{
"start":
{
"debug":
{
"enabled":true,
"template":"[{time}] server started at {host}:{port} balance: {keva}"
}
},
"welcome":
{
"message":

40
src/server.php

@ -18,6 +18,17 @@ $config = json_decode( @@ -18,6 +18,17 @@ $config = json_decode(
)
); if (!$config) exit;
// Init KevaCoin
$kevacoin = new \Kevachat\Kevacoin\Client(
$config->kevacoin->server->protocol,
$config->kevacoin->server->host,
$config->kevacoin->server->port,
$config->kevacoin->server->username,
$config->kevacoin->server->password
);
if ((float) $kevacoin->getBalance($config->kevacoin->wallet->account) <= 0) exit;
// Init session
$session = [];
@ -103,7 +114,7 @@ $server->setWelcome( @@ -103,7 +114,7 @@ $server->setWelcome(
if ($config->nps->action->welcome->debug->enabled)
{
// Print debug from template
printf(
print(
str_ireplace(
[
'{time}',
@ -150,7 +161,7 @@ $server->setPending( @@ -150,7 +161,7 @@ $server->setPending(
if ($config->nps->action->pending->debug->enabled)
{
// Print debug from template
printf(
print(
str_ireplace(
[
'{time}',
@ -239,7 +250,7 @@ $server->setHandler( @@ -239,7 +250,7 @@ $server->setHandler(
if ($config->nps->action->handler->debug->enabled)
{
// Print debug from template
printf(
print(
str_ireplace(
[
'{time}',
@ -273,4 +284,27 @@ $server->setHandler( @@ -273,4 +284,27 @@ $server->setHandler(
);
// Start server
if ($config->nps->action->start->debug->enabled)
{
print(
str_ireplace(
[
'{time}',
'{host}',
'{port}',
'{keva}'
],
[
date('c'),
$config->nps->server->host,
$config->nps->server->port,
$kevacoin->getBalance(
$config->kevacoin->wallet->account
)
],
$config->nps->action->start->debug->template
) . PHP_EOL
);
}
$server->start();
Loading…
Cancel
Save