-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskynet
executable file
·38 lines (28 loc) · 883 Bytes
/
skynet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/perl
use v5.36;
use FindBin;
use lib "$FindBin::Bin/lib";
use Config::INI::Reader;
use IO::Async::Loop;
use IO::Async::Listener;
use Skynet::User;
use Skynet::DBI;
use Skynet::AllianceManager;
my $config = Config::INI::Reader->read_file('/etc/skynet.ini') or die "no config loaded: $!";
my $dbi = Skynet::DBI->new($config);
my $loop = IO::Async::Loop->new();
my $manager = Skynet::AllianceManager->new($dbi);
$loop->add($manager);
$loop->listen(
service => $config->{server}{port},
socktype => 'stream',
on_accept => sub{
my ($socket) = @_;
my $newuser = Skynet::User->new(handle => $socket);
$manager->assign_user($newuser);
my $address = $socket->peerhost . ":" . $socket->peerport;
say "new user connected at ".$address;
},
)->get;
say "Listening on port ".$config->{server}{port};
$loop->run;