App-phoebe

 view release on metacpan or  search on metacpan

script/ijirait  view on Meta::CPAN

#!/usr/bin/env perl
# Copyright (C) 2017–2021  Alex Schroeder <alex@gnu.org>

# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.

=encoding utf8

=head1 NAME

Ijirait - a MUSH client for Ijirait

=head1 DESCRIPTION

This is a command-line client for Ijirait, a Gemini-based MUSH that can be run
by Phoebe. See L<App::Phoebe::Ijirait>.

First, generate your client certificate for as many or as few days as you like:

    openssl req -new -x509 -newkey ec -subj "/CN=Alex" \
      -pkeyopt ec_paramgen_curve:prime256v1 -days 100 \
      -nodes -out cert.pem -keyout key.pem

Then start this program to play:

    ijirait --cert=cert.pem --key=key.pem \
      --url=gemini://campaignwiki.org/play/ijirait

You can also use it to stream, i.e. get notified of events in real time:

    ijirait --cert=cert.pem --key=key.pem --stream \
      --url=gemini://campaignwiki.org/play/ijirait/stream

Here are the Debian package names to satisfy the dependencies. Use C<cpan> or
C<cpanm> to install them.

=over

=item L<Modern::Perl> from C<libmodern-perl-perl>

=item L<Mojo::IOLoop> from C<libmojolicious-perl>

=item L<Term::ReadLine::Gnu> from C<libterm-readline-gnu-perl>

=item L<URI::Escape> from C<liburi-escape-xs-perl>

=item L<Encode::Locale> from C<libencode-locale-perl>

=item L<Text::Wrapper> from C<libtext-wrapper-perl>

=back

=cut

use Modern::Perl '2018';
use Mojo::IOLoop;
use Pod::Text;
use Getopt::Long;
use Term::ReadLine; # install Term::ReadLine::Gnu
use Term::ANSIColor qw(colorstrip colored);
use URI::Escape qw(uri_escape uri_unescape);
use Encode::Locale;
use Encode qw(decode_utf8 encode_utf8 decode encode);
use Text::Wrapper;
use File::Slurper qw(read_text write_text);
use IPC::Open2;

my $cert;
my $key;
my $help;
my $url;
my $stream;
my $debug;
my $wrapper = Text::Wrapper->new();

GetOptions(
  'cert_file=s' => \$cert,
  'key_file=s' => \$key,
  'help' => \$help,
  'url=s' => \$url,
  'debug' => \$debug,
  'stream' => \$stream)
    or die("Error in command line arguments\n");

# Help
if ($help) {
  my $parser = Pod::Text->new();
  $parser->parse_file($0);
  exit;
}

die "âš  You must provide --url, e.g. --url=gemini://campaignwiki.org/play/ijirait\n" unless $url;
die "âš  You must provide --cert_file, e.g. --cert_file=cert.pem\n" unless $cert;
die "âš  You must provide --key_file, e.g. --key_file=key.pem\n" unless $key;
die "âš  You must provide an existing --cert_file\n" unless -f $cert;
die "âš  You must provide an existing --key_file\n" unless -f $key;

$stream = 1 if $url =~ /\/stream$/;

my $talk_url = "$url/type";

my($scheme, $authority, $path, $query, $fragment) =
    $url =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?|;

die "âš  The URL '$url' must use the gemini scheme\n" unless $scheme and $scheme eq 'gemini';

my ($host, $port) = split(/:/, $authority, 2);
$port //= 1965;

if ($stream) {
  stream();
} else {
  play();
}



( run in 1.187 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )