mirror of
https://github.com/kevachat/webapp.git
synced 2025-03-10 04:21:01 +00:00
add online sessions info
This commit is contained in:
parent
a5fa269d70
commit
fd3a601412
5
.env
5
.env
@ -19,7 +19,7 @@ APP_ENV=dev
|
||||
APP_SECRET=EDIT_ME
|
||||
###< symfony/framework-bundle ###
|
||||
|
||||
APP_VERSION=1.0.3
|
||||
APP_VERSION=1.1.0
|
||||
|
||||
APP_NAME=KevaChat
|
||||
|
||||
@ -61,6 +61,9 @@ APP_KEVACOIN_ROOM_NAMESPACE_DEFAULT=EDIT_ME
|
||||
# Allow users to read external node rooms
|
||||
APP_KEVACOIN_ROOM_NAMESPACES_EXTERNAL=
|
||||
|
||||
# Online session expiration timeout
|
||||
APP_SESSION_ONLINE_TIMEOUT=900
|
||||
|
||||
# Allow remotes to create new rooms (namespaces)
|
||||
APP_ADD_ROOM_REMOTE_IP_REGEX=/.*/
|
||||
|
||||
|
@ -23,6 +23,7 @@ parameters:
|
||||
app.kevacoin.explorer.url: '%env(APP_KEVACOIN_EXPLORER_URL)%'
|
||||
app.kevacoin.mine.pool.url: '%env(APP_KEVACOIN_MINE_POOL_URL)%'
|
||||
app.kevacoin.mine.solo.url: '%env(APP_KEVACOIN_MINE_SOLO_URL)%'
|
||||
app.session.online.timeout: '%env(APP_SESSION_ONLINE_TIMEOUT)%'
|
||||
app.add.room.remote.ip.regex: '%env(APP_ADD_ROOM_REMOTE_IP_REGEX)%'
|
||||
app.add.post.remote.ip.regex: '%env(APP_ADD_POST_REMOTE_IP_REGEX)%'
|
||||
app.add.post.remote.ip.delay: '%env(APP_ADD_POST_REMOTE_IP_DELAY)%'
|
||||
|
@ -10,8 +10,11 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class ModuleController extends AbstractController
|
||||
{
|
||||
public function info(): Response
|
||||
public function info(
|
||||
Request $request
|
||||
): Response
|
||||
{
|
||||
// Connect kevacoin
|
||||
$client = new \Kevachat\Kevacoin\Client(
|
||||
$this->getParameter('app.kevacoin.protocol'),
|
||||
$this->getParameter('app.kevacoin.host'),
|
||||
@ -20,9 +23,49 @@ class ModuleController extends AbstractController
|
||||
$this->getParameter('app.kevacoin.password')
|
||||
);
|
||||
|
||||
// Connect memcached
|
||||
$memcached = new \Memcached();
|
||||
$memcached->addServer(
|
||||
$this->getParameter('app.memcached.host'),
|
||||
$this->getParameter('app.memcached.port')
|
||||
);
|
||||
|
||||
// Get sessions registry
|
||||
$online = md5(
|
||||
sprintf(
|
||||
'%s.ModuleController::info:sessions',
|
||||
__DIR__
|
||||
)
|
||||
);
|
||||
|
||||
// Drop offline sessions
|
||||
$sessions = [];
|
||||
|
||||
foreach ((array) $memcached->get($online) as $ip => $time)
|
||||
{
|
||||
if (time() - $time < $this->getParameter('app.session.online.timeout'))
|
||||
{
|
||||
$sessions[$ip] = $time;
|
||||
}
|
||||
}
|
||||
|
||||
// Update current session time
|
||||
$sessions[$request->getClientIp()] = time();
|
||||
|
||||
// Update session registry
|
||||
$memcached->set(
|
||||
$online,
|
||||
$sessions,
|
||||
$this->getParameter('app.session.online.timeout')
|
||||
);
|
||||
|
||||
// Render the template
|
||||
return $this->render(
|
||||
'default/module/info.html.twig',
|
||||
[
|
||||
'online' => count(
|
||||
$sessions
|
||||
),
|
||||
'wallet' =>
|
||||
[
|
||||
'balance' => (float) $client->getBalance(),
|
||||
|
@ -20,7 +20,10 @@
|
||||
{{
|
||||
render(
|
||||
controller(
|
||||
'App\\Controller\\ModuleController::info'
|
||||
'App\\Controller\\ModuleController::info',
|
||||
{
|
||||
request : request
|
||||
}
|
||||
)
|
||||
)
|
||||
}}
|
||||
|
@ -1,4 +1,6 @@
|
||||
<div>
|
||||
{{ 'online:' | trans }} {{ online }}
|
||||
/
|
||||
{{ 'block:' | trans }} {{ wallet.block }}
|
||||
/
|
||||
{{ 'balance:' | trans }} {{ wallet.balance }}
|
||||
|
Loading…
x
Reference in New Issue
Block a user