Browse Source

init kevacoin connection, debug server start event

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

13
config/example.json

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

42
src/server.php

@ -18,6 +18,17 @@ $config = json_decode(
) )
); if (!$config) exit; ); 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 // Init session
$session = []; $session = [];
@ -103,7 +114,7 @@ $server->setWelcome(
if ($config->nps->action->welcome->debug->enabled) if ($config->nps->action->welcome->debug->enabled)
{ {
// Print debug from template // Print debug from template
printf( print(
str_ireplace( str_ireplace(
[ [
'{time}', '{time}',
@ -150,7 +161,7 @@ $server->setPending(
if ($config->nps->action->pending->debug->enabled) if ($config->nps->action->pending->debug->enabled)
{ {
// Print debug from template // Print debug from template
printf( print(
str_ireplace( str_ireplace(
[ [
'{time}', '{time}',
@ -239,7 +250,7 @@ $server->setHandler(
if ($config->nps->action->handler->debug->enabled) if ($config->nps->action->handler->debug->enabled)
{ {
// Print debug from template // Print debug from template
printf( print(
str_ireplace( str_ireplace(
[ [
'{time}', '{time}',
@ -273,4 +284,27 @@ $server->setHandler(
); );
// Start server // Start server
$server->start(); 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