/var/www/www.irssi.org-old/scripts/html/binary.pl


   1 # /binary huora
   2 # tuolostaa k.o. ikkunaan huora:n sijaan 01101001 ....
   3 #
   4 # and modified by carl 2004-03-09
   5 
   6 # Changelog
   7 # Version 1: original version by nchip
   8 # Version 1.1: added unbinary function
   9 # Verison 1.2: added server truncate detection (requested by André, thanks for spotting the problem) and choice to have spaces in the binary or not (reqested by Tapio)
  10 
  11 
  12 use strict;
  13 use Irssi;
  14 use Irssi qw(command_bind command signal_add_last signal_stop settings_get_bool settings_add_bool);
  15 
  16 use vars qw($VERSION %IRSSI);
  17 
  18 #%IRSSI = (
  19 #        authors     => "Riku Voipio",
  20 #        contact     => "riku.voipio\@iki.fi",
  21 #        name        => "binary",
  22 #        description => "adds /binary command that converts what you type into 2-base string representation",
  23 #        license     => "GPLv2",
  24 #        url         => "http://nchip.ukkosenjyly.mine.nu/irssiscripts/",
  25 #    );
  26 
  27 $VERSION = "1.2";
  28 %IRSSI = (
  29         authors     => "Carl Fischer",
  30         contact     => "carl.fischer\@netcourrier.com",
  31         name        => "binary",
  32         description => "adds /binary command that converts what you type into 2-base string representation, also decodes other peoples binary automatically",
  33         license     => "GPLv2",
  34 	  );
  35 
  36 
  37 sub cmd_binary {
  38 	$_=join(" ",$_[0]);
  39 	$_=reverse;
  40 	my (@r);
  41 	if (settings_get_bool('binary_spaces')) {
  42 	    $r[0]="/say";
  43 	} else {
  44 	    $r[0]="/say ";
  45 	}
  46 	while ($a = chop($_)) {
  47 	    push (@r,unpack ("B*", $a));}
  48 	
  49 	my $window = Irssi::active_win();
  50 	if (settings_get_bool('binary_spaces')) {
  51 	    $window->command(join (" ",@r));
  52 	} else {
  53 	    $window->command(join ("",@r));
  54 	}
  55     }
  56 
  57 # here ends the original code
  58 # some of the following was strongly inspired by the kenny script
  59 
  60 sub cmd_unbinary {
  61     pop @_;
  62     pop @_;
  63     my $window = Irssi::active_win();
  64     $window->print(unbinary($_[0]));
  65 }
  66 
  67 sub unbinary {
  68     my $r;
  69     if (settings_get_bool('binary_spaces')) {
  70 	$r=pack("B*", join ("", split(" ", @_[0])));
  71     } else {
  72 	$r=pack("B*", @_[0]);
  73     }
  74     return $r;
  75 }
  76 
  77 sub sig_binary {
  78     my ($server, $msg, $nick, $address, $target) = @_;
  79     if (($msg=~m/^([01]{8}( [01]{8})*)( [01]{1,7})*$/ and settings_get_bool('binary_spaces')) or ($msg=~m/^([01]{8}([01]{8})*)([01]{1,7})*$/ and not settings_get_bool('binary_spaces'))) {
  80 	my $leftover="";
  81 	$leftover="* (truncated by server)" if $3;
  82 	$target=$nick if $target eq "";
  83 	# the address may _never_ be emtpy, if it is its own_public
  84 	$nick=$server->{'nick'} if $address eq "";
  85 	$server->window_item_find($target)->print("[binary] <$nick> " .
  86 						  unbinary($1) . $leftover, 'MSGLEVEL_CRAP');
  87 	signal_stop() if not settings_get_bool('show_binary_too');
  88     }
  89 }
  90 
  91 signal_add_last('message own_public',  'sig_binary');
  92 signal_add_last('message public',      'sig_binary');
  93 signal_add_last('message own_private', 'sig_binary');
  94 signal_add_last('message private',     'sig_binary');
  95 
  96 settings_add_bool('lookandfeel', 'show_binary_too', 0);
  97 settings_add_bool('lookandfeel', 'binary_spaces', 1);
  98 
  99 Irssi::command_bind('binary', 'cmd_binary');
 100 Irssi::command_bind('unbinary', 'cmd_unbinary');
 101 
 102 Irssi::print("binary obfuscator vanity script loaded");
 103 Irssi::print("written by nchip and updated by carl");
 104 Irssi::print("--------------------------------------");
 105 Irssi::print("/binary message");
 106 Irssi::print("will send binary text to the current channel");
 107 Irssi::print("");
 108 Irssi::print("/unbinary obfuscated_text");
 109 Irssi::print("will print the unobfuscated equivalent to your window (and not to the channel)");
 110 Irssi::print("");
 111 Irssi::print("/set show_binary_too on");
 112 Irssi::print("will make this script print the binary equivalent as well as the translation to your screen whenever someone uses binary on the channel");
 113 Irssi::print("/set binary_spaces off");
 114 Irssi::print("will make the binary be printed as a single word with no spaces");