<% my %args = AxKit::Apache::request->args; use Cwd; my $dir = (split '/' => getcwd )[-1]; %> <% if ( $args{agent} ) { process_agent( \%args ); } else { print_form(); } %>

return to main page

<%- sub print_form { %>
player: password:
agent:
<% } -%> <% sub process_agent { my %args = %{$_[0]}; my $auth; if ( findvalue( '//players/@list' ) eq 'adhoc' ) { $auth = authenticate_adhoc( %args ); } else { $auth = authenticate_predefined( %args ); } return unless $auth; my $existed; $existed = 1 if -e "mobil/$args{player}"; my $fagent; open $fagent, '>', "mobil/$args{player}" or die $!; print $fagent $args{agent}; close $fagent; if ( -e "mobil/$args{player}" ) { %>

agent uploaded

<% if ( $existed ) { %>

An agent was already present and has been removed.

<% } } else { %>

Agent couldn't be uploaded, looks like there is a problem. Please contact the Architect.

<% } } %> <% sub authenticate_predefined { my %args = @_; my ( $player ) = findnodes( "//players/player[\@name = '$args{player}']" ."[\@password = '$args{password}']" ); unless ( $player ) { %>

player not recognized or password not valid

<% return 0; } return 1; } sub authenticate_adhoc { my %args = @_; my( $community_file ) = findvalue( '//players/@community' ); unless( $community_file and -e $community_file ) { %>

Error: communauty file not found. Please contact the Architect.

<% return 0; } my $comm = eval { XML::LibXML->new->parse_file( $community_file ) }; if ( $@ ) { %>

Error: communauty file not properly formatted. Please contact the Architect.

<% return 0; } my ( $player ) = $comm->findnodes( "//players/player[\@name = '$args{player}']" ."[\@password = '$args{password}']" ); unless ( $player ) { %>

player not recognized or password not valid

<% return 0; } return 1; } %>