From: mh Date: Sat, 16 May 2020 17:03:58 +0000 (+0200) Subject: mh_secureonlychan_489.pl X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=42ebd99b92c9b9f7b03ce0327e258e4f919c4c9c;p=irssi-scripts.irssi.org.git mh_secureonlychan_489.pl Fix for Irssi not fully supporting numeric 489 ERR_SECUREONLYCHAN. --- diff --git a/scripts/mh_secureonlychan_489.pl b/scripts/mh_secureonlychan_489.pl new file mode 100644 index 0000000..84c1d66 --- /dev/null +++ b/scripts/mh_secureonlychan_489.pl @@ -0,0 +1,108 @@ +#!/usr/bin/env false +############################################################################## +# +# mh_secureonlychan_489 v1.00 +# +# Copyright (c) 2020 Michael Hansen +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +############################################################################## +# +# Fix for Irssi not fully supporting numeric 489 ERR_SECUREONLYCHAN. +# +# see https://github.com/irssi/irssi/issues/1193 for details about the issue. +# +# This script will display an error message in the status-window if you try to +# join a secure only channel without a secure connection. If you have the +# setting autoclose_windows off, you will still get the old raw message in the +# channel-window too. +# +# The script will die gracefully with a message if loaded in a version of +# Irssi that already have the source-code fixed (ABI version 29 or higher). +# +# see https://github.com/irssi/irssi/pull/1196 for details about the code fix. +# +############################################################################## + +use v5.14.2; + +use strict; +use warnings; + +use Irssi (); + +############################################################################## +# +# Irssi script header +# +############################################################################## + +our $VERSION = '1.00'; +our %IRSSI = +( + 'name' => 'mh_secureonlychan_489', + 'description' => 'Fix for Irssi not fully supporting numeric 489 ERR_SECUREONLYCHAN', + 'url' => 'https://github.com/irssi/scripts.irssi.org/tree/master/scripts', + 'license' => 'ISC/BSD', + 'authors' => 'Michael Hansen', + 'contact' => 'mh (IRCnet)', + 'changed' => '2020-05-16', +); + +############################################################################## +# +# Irssi signal handler +# +############################################################################## + +sub signal_server_event +{ + my ($serverrec, $data, $nick, $address) = @_; + + if (substr($data, 0, 3) eq '489') + { + (undef, undef, my $channelname, $data) = split(/ /, $data, 4); + + # numeric 489 is also used as ERR_VOICENEEDED, make sure this is an actual ERR_SECUREONLYCHAN + if (substr($data, 0, 20) eq ':Cannot join channel') + { + $serverrec->printformat('(status)', Irssi::MSGLEVEL_CRAP(), 'joinerror_secureonlychan_489', $channelname); + } + } + + return(1); +} + +############################################################################## +# +# script on load +# +############################################################################## + +# selfdestruct if Irssi is new enough to have the source-code fixed for this issue +if (Irssi::parse_special('$abiversion') and (Irssi::parse_special('$abiversion') >= 28)) +{ + die('The script is not needed for this version of Irssi.' . "\n"); +} + +Irssi::theme_register(['joinerror_secureonlychan_489', 'Cannot join to channel {channel $0} (Secure clients only)']); +Irssi::signal_add_last("server event", 'signal_server_event'); + +1; + +############################################################################## +# +# eof +# +##############################################################################