Leser: 19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
sub addgame { my ($player_id, $command, $hostip, $hostport, $hostversion, $map, $players, $maxplayers, $techlvl) = @_; my @gamedata = [ # Gather Data in one Array {'player_id'=>$player_id, 'hostip'=>$hostip, 'hostport'=>$hostport, 'hostversion'=>$hostversion, 'map'=>$map, 'players'=>$players, 'maxplayers'=>$maxplayers, 'techlvl'=>$techlvl} ]; # Create XML from Array my $newgame_xml = new XML::Simple (NoAttr=>1, RootName=>'lobbyquery'); my @gamedata_xml = $newgame_xml->XMLout(\@gamedata); @gamedata_xml = stripxml(@gamedata_xml); # @gamedata xml strip chomp(@gamedata_xml); writelog("New Game:\n$gamedata_xml[0]"); push (@gameDB, $gamedata_xml[0]) }
1 2 3 4 5 6 7 8 9 10 11 12 13 14
sub chgame { my ($player_id, $command, $hostip, $hostport, $hostversion, $map, $players, $maxplayers, $techlvl) = @_; foreach(@gameDB) { my $host_id = parsexml($_, 'player_id'); if ($host_id eq $player_id) { print "allowed\n"; shift; addgame($player_id, $command, $hostip, $hostport, $hostversion, $map, $players, $maxplayers, $techlvl); } else { print "host doesent match\n"; } } broadcast($player_id, "chgame: $hostip"); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
# Handle Client Input sub client_input { my ($kernel, $session, $input) = @_[KERNEL, SESSION, ARG0]; my $user_id = $session->ID; if ($input =~/<lobbyquery>/) { my $command = parsexml($input, 'command'); if ($command eq 'addgame') { # Addgame command received # xml > variables my $hostip = parsexml($input, 'hostip'); my $hostport = parsexml($input, 'hostport'); my $hostversion = parsexml($input, 'hostversion'); my $map = parsexml($input, 'map'); my $players = 1; my $maxplayers = parsexml($input, 'maxplayers'); my $techlvl = parsexml($input, 'techlvl'); # Add the Game to the Lobby Database addgame($user_id, $command, $hostip, $hostport, $hostversion, $map, $players, $maxplayers, $techlvl); } elsif ($command eq 'chgame') { # Change game command received # xml > variables my $hostip = parsexml($input, 'hostip'); my $hostport = parsexml($input, 'hostport'); my $hostversion = parsexml($input, 'hostversion'); my $map = parsexml($input, 'map'); my $players = 1; my $maxplayers = parsexml($input, 'maxplayers'); my $techlvl = parsexml($input, 'techlvl'); # Change the Game chgame($user_id, $command, $hostip, $hostport, $hostversion, $map, $players, $maxplayers, $techlvl); } } elsif ($input eq 'listgames') { if (scalar(@gameDB) == 0) { $poe_kernel->post($user_id => send => "no games"); } else { $poe_kernel->post($user_id => send => "@gameDB"); print @gameDB; } } elsif ($input =~/^chat (.+)$/) { broadcast($user_id, "$user_id: $1"); } else { $poe_kernel->post($user_id => send => "error"); } }
1 2 3 4 5 6 7 8 9 10 11
$ perl -le 'my @gameDB = (1); foreach ( @gameDB ) { print $_; push @gameDB, $_+1; last if $_ == 10}' 1 2 3 4 5 6 7 8 9 10