… | |
… | |
89 | |
89 | |
90 | # initialize new socket and connection |
90 | # initialize new socket and connection |
91 | my $sock = new IO::Socket::INET PeerHost => KGS::Protocol::KGSHOST, PeerPort => KGS::Protocol::KGSPORT |
91 | my $sock = new IO::Socket::INET PeerHost => KGS::Protocol::KGSHOST, PeerPort => KGS::Protocol::KGSPORT |
92 | or die "connect: $!"; |
92 | or die "connect: $!"; |
93 | |
93 | |
94 | $sock->blocking(1); |
94 | $sock->blocking (1); |
95 | $self->{conn}->handshake($sock); |
95 | $self->{conn}->handshake ($sock); |
96 | $sock->blocking(0); |
96 | $sock->blocking (0); |
97 | |
97 | |
98 | my $input; $input = add_watch Glib::IO fileno $sock, [G_IO_IN, G_IO_ERR, G_IO_HUP], sub { |
98 | my $input; $input = add_watch Glib::IO fileno $sock, [G_IO_IN, G_IO_ERR, G_IO_HUP], sub { |
99 | # this is dorked |
99 | # this is dorked |
100 | my $buf; |
100 | my $buf; |
101 | my $len = sysread $sock, $buf, 16384; |
101 | my $len = sysread $sock, $buf, 16384; |
102 | if ($len) { |
102 | if ($len) { |
103 | $self->{conn}->feed_data($buf); |
103 | $self->{conn}->feed_data ($buf); |
104 | } elsif (defined $len || (!$!{EINTR} and !$!{EAGAIN})) { |
104 | } elsif (defined $len || (!$!{EINTR} and !$!{EAGAIN})) { |
105 | warn "disconnected";#d# |
105 | warn "disconnected";#d# |
106 | remove Glib::Source $input; |
106 | remove Glib::Source $input; |
107 | $self->event_disconnect; |
107 | $self->event_disconnect; |
108 | } |
108 | } |
… | |
… | |
191 | |
191 | |
192 | $userpic{$msg->{name}} = $msg->{data}; |
192 | $userpic{$msg->{name}} = $msg->{data}; |
193 | $_->($userpic{$msg->{name}}) for @{delete $userpic_cb{$msg->{name}} || []}; |
193 | $_->($userpic{$msg->{name}}) for @{delete $userpic_cb{$msg->{name}} || []}; |
194 | } |
194 | } |
195 | |
195 | |
196 | sub event_disconnect { } |
196 | sub event_disconnect { |
|
|
197 | $_->destroy |
|
|
198 | for values %{delete $self->{game} or {}}, values %{delete $self->{room} or {}}; |
|
|
199 | } |
197 | |
200 | |
198 | sub open_game { |
201 | sub open_game { |
199 | my ($self, %arg) = @_; |
202 | my ($self, %arg) = @_; |
200 | |
203 | |
201 | ($self->{game}{$arg{channel}} ||= new game %arg, conn => $self->{conn}, app => $self) |
204 | ($self->{game}{$arg{channel}} ||= new game %arg, conn => $self->{conn}, app => $self) |