-# Copyright © 2008, 2010 Nick Bowler
+# Copyright © 2008, 2010, 2020 Nick Bowler
#
# License WTFPL2: Do What The Fuck You Want To Public License, version 2.
# This is free software: you are free to do what the fuck you want to.
# posting to public channels, you can piss off a wider audience.
use strict;
+use utf8;
+
use vars qw($VERSION %IRSSI);
-use utf8;
-use encoding 'utf8';
use IO::Socket::INET6;
+use IO::Socket::UNIX;
-$VERSION = '0.2';
+$VERSION = '1.0';
%IRSSI = (
authors => 'Nick Bowler',
contact => 'nbowler@draconx.ca',
);
# MPD Connection Settings
-$ENV{"MPD_HOST"} = "localhost" unless ($ENV{"MPD_HOST"});
-$ENV{"MPD_PORT"} = 6600 unless ($ENV{"MPD_PORT"});
+$ENV{"MPD_HOST"} //= "localhost";
+$ENV{"MPD_PORT"} //= 6600;
Irssi::settings_add_str("mpd", "mpd_host", $ENV{"MPD_HOST"});
Irssi::settings_add_int("mpd", "mpd_port", $ENV{"MPD_PORT"});
# Open a connection to MPD.
sub mpd_open {
- my $sock = new IO::Socket::INET6(
- PeerAddr => Irssi::settings_get_str("mpd_host"),
- PeerPort => Irssi::settings_get_int("mpd_port"),
- Proto => 'tcp',
- ) or do {
- print CLIENTERROR "failed to open MPD socket: $!.";
- return undef;
- };
+ my $host = Irssi::settings_get_str("mpd_host");
+ my $port = Irssi::settings_get_int("mpd_port");
+ my $sock;
+
+ if ($host =~ /^[@\/]/) {
+ $host =~ s/^@/\0/;
+ $sock = new IO::Socket::UNIX(Type => SOCK_STREAM(),
+ Peer => $host)
+ } else {
+ $sock = new IO::Socket::INET6(PeerAddr => $host,
+ PeerPort => $port,
+ Proto => 'tcp',
+ Timeout => 2)
+ }
+
+ unless ($sock) {
+ print CLIENTERROR "failed to open MPD socket: $!";
+ return;
+ }
+
binmode($sock, ":utf8");
# Grab the MPD version.
- if (!(<$sock> =~ /^OK MPD ([0-9]+)\.([0-9]+)\.([0-9]+)$/)) {
- print CLIENTERROR "failed MPD handshake: $!.";
- return undef;
+ unless (<$sock> =~ /^OK MPD ([0-9]+)\.([0-9]+)\.([0-9]+)$/) {
+ print CLIENTERROR "failed MPD handshake: $!";
+ return;
}
return $sock;
# If the active window is not a channel or query, display locally.
$local = 1 unless ($witem && ($witem->{type} eq "CHANNEL"
|| $witem->{type} eq "QUERY"));
-
+
if ($local) {
$window->print($text);
} elsif ($data) {