#!/usr/bin/perl use strict; use warnings; use LWP; @ARGV <= 2 or die "usage: $0 player:password\@server agent\n"; my $url = shift @ARGV; my( $player, $password, $server ) = $url =~ m#(?:http://)?(.*?):(.*?)@(.*)# or die "url not correctly formatted, should be player:password\@server\n"; $url = 'http://'.$server.'/upload.epl'; my $browser = LWP::UserAgent->new; undef $/; if ( @ARGV ) { open STDIN, '<', shift @ARGV or die "can't open file: $!\n"; } my $agent = ; # TODO spot when upload fails because of authorisation # TODO file:// scheme my @params = ( player => 'yanick', password => 'y', agent => $agent ); my $answer = $browser->post( $url, [ player => $player, password => $password, agent => $agent, ] ); if ( $answer->is_success ) { print "agent uploaded\n"; exit; } else { print "agent upload failed: ", $answer->status_line, "\n"; } __END__ =head1 NAME pwupload - upload a perlwar agent =head1 SYNOPSIS B I [ I ] =head1 DESCRIPTION Uploads the agent contained in I to the game located at I. The url must be of the form CIC<:>IC<@>I. E.g.: C< http://yanick:foo@www.perlwar.com/game234 >. If I is not provided, the agent is read from C.