1 | #! perl # depends=irc |
1 | #! perl # depends=irc |
2 | |
2 | |
3 | our $UPDATE_LOGINS = Event->idle (repeat => 0, min => 1, data => cf::WF_AUTOCANCEL, cb => Coro::unblock_sub { |
3 | use Fcntl; |
4 | my ($status, @pl) = ext::commands::who_listing; |
4 | use Coro::AIO; |
5 | |
5 | |
6 | #TODO: write files asynchronously |
6 | our $UPDATE_LOGINS = EV::idle sub { |
7 | open my $fh, ">", "$LOCALDIR/usercount"; |
7 | $_[0]->stop; |
8 | print $fh scalar @pl; |
|
|
9 | |
8 | |
10 | open my $fh, ">", "$LOCALDIR/userlisting.html"; |
9 | cf::async { |
|
|
10 | my ($status, @pl) = ext::commands::who_listing; |
|
|
11 | |
|
|
12 | my $fh = aio_open "$LOCALDIR/usercount", O_WRONLY | O_CREAT | O_TRUNC, 0644 |
|
|
13 | or return; |
|
|
14 | aio_write $fh, 0, undef, scalar @pl, 0; |
|
|
15 | aio_close $fh; |
|
|
16 | |
|
|
17 | my $who; |
11 | for ($status, @pl) { |
18 | for ($status, @pl) { |
12 | s/[<&]//g; |
19 | s/[<&]//g; |
13 | print $fh "$_<br />\n"; |
20 | $who .= "$_<br />\n"; |
|
|
21 | } |
|
|
22 | |
|
|
23 | my $fh = aio_open "$LOCALDIR/userlisting.html", O_WRONLY | O_CREAT | O_TRUNC, 0644 |
|
|
24 | or return; |
|
|
25 | aio_write $fh, 0, undef, $who, 0; |
|
|
26 | aio_close $fh; |
14 | } |
27 | }; |
15 | }); |
28 | }; |
16 | |
29 | |
17 | cf::player->attach ( |
30 | cf::player->attach ( |
18 | on_login => sub { |
31 | on_login => sub { |
19 | my ($pl) = @_; |
32 | my ($pl) = @_; |
20 | $pl->ob->set_ob_key_value (schmorplog_last_login => time); |
33 | $pl->ob->set_ob_key_value (schmorplog_last_login => time); |