aboutsummaryrefslogtreecommitdiff
path: root/t/release/servers/01-basic.pl
blob: fe5ea06ec032ae7082d94c9768b344c6f7c8c189 (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# A fairly simple example:
use strict;
use warnings;
use POE qw(Component::Server::IRC);

my %config = (
    servername => 'simple.poco.server.irc',
    nicklen    => 15,
    network    => 'SimpleNET'
);

my $pocosi = POE::Component::Server::IRC->spawn( config => \%config );

POE::Session->create(
    package_states => [
        'main' => [qw(_start _default)],
    ],
    heap => { ircd => $pocosi },
);

$poe_kernel->run();

sub _start {
    my ($kernel, $heap) = @_[KERNEL, HEAP];

    $heap->{ircd}->yield('register', 'all');

    # Anyone connecting from the loopback gets spoofed hostname
    # $heap->{ircd}->add_auth(
    #     mask     => '*@localhost',
    #     spoof    => 'm33p.com',
    #     no_tilde => 1,
    # );

    # We have to add an auth as we have specified one above.
    $heap->{ircd}->add_auth(mask => '*@*');

    # Start a listener on the 'standard' IRC port.
    $heap->{ircd}->add_listener(port => 5667);

    # Add an operator who can connect from localhost
    $heap->{ircd}->add_operator(
        {
            username => 'moo',
            password => 'fishdont',
        }
    );
}

sub _default {
    my ($event, @args) = @_[ARG0 .. $#_];

    print "$event: ";
    for my $arg (@args) {
        if (ref($arg) eq 'ARRAY') {
            print "[", join ( ", ", @$arg ), "] ";
        }
        elsif (ref($arg) eq 'HASH') {
            print "{", join ( ", ", %$arg ), "} ";
        }
        else {
            print "'$arg' ";
        }
    }

    print "\n";
 }