HJÆÆÆÆÆÆLP!!!!!!!!!
HJÆLP!Få dette script til at virke og du har fortjent nogle point!
Den giver Internal Server Error, og da jeg overhovedet ikke har forstand på cgi/perl håber jeg i har ;)
------------------------------------
#!usr/bin/perl
#####################################################
# Half-Spy - Half-Life query script #
# Written by Scott Wilson #
# #
# some code adapted from Half-Life Query #
# by Daniel Ditlev Pedersen. (although not much) :-)#
#####################################################
#####################################################
#Usage:
# Form Method GET Variables: mode ip port
#
#mode: \"list\" - Prints a server list to the screen with info on
# game type, map, number of players, ect...
# Takes the variables \"ip\" and \"port\" as arguments.
# You can define as many \"ip\" and \"port\" pairs as
# you like (upto the maximum url length of 256 chars or so).
#
# eg. half-spy.pl?mode=list&ip=203.9.148.10&port=27015&ip=202.139.226.3&port=27015&ip=198.142.1.145&port=27015
#
#mode: \"info\" - Prints server info and lists the players currently playing.
# Takes the variables \"ip\" and \"port\" as arguments.
# Only one server can be specified at a time.
#
# eg. half-spy.pl?mode=info&ip=203.9.148.10&port=27015
#
#mode: \"rules\" - Prints server info as above and lists the server\'s rules.
# Takes the variables \"ip\" and \"port\" as arguments.
# Only one server can be specified at a time.
#
# eg. half-spy.pl?mode=rules&ip=203.9.148.10&port=27015
#
#mode: \"form\" - This is the default mode if no data is passed to the script.
# Takes no variables. Prints a form to the screen to allow you to
# enter IP addresses and Ports to create a server list.
#
#####################################################
use Socket;
## HTML Variables
$h_title=\"Half-Spy - A Half-Life Query tool\";
$h_bgcolor=\"black\";
$h_bg=\"hs-bg.gif\";
$h_textcolor=\"white\";
$h_table_width=\"450\";
$h_table_bgcolor=\"#000099\";
$h_table_header_color=\"#990000\";
$h_br=\"<BR>\";
## Server Variables
$get_info = \"\\xff\\xff\\xff\\xffinfo\\x00\";
$get_players = \"\\xff\\xff\\xff\\xffplayers\\x00\";
$get_rules = \"\\xff\\xff\\xff\\xffrules\\x00\";
$mode=\"\";
$ip_addr = \"\";
$ip_port = \"\";
####################
###Program Start####
####################
&html_head_start;
&dhtml_style(\"Link1\",\"Times New Roman\",\"Times New Roman\",\"16\",\"16\",\"white\",\"yellow\",\"none\",\"none\");
&html_head_finish;
&get_form_data;
&setup_socket;
if($mode eq \"\")
{
$mode=\"form\";
}
if($mode eq \"list\")
{
if(@ip_list ne \"\")
{
&list_servers;
}
else
{
&print_form;
}
&html_finish;
}
if($mode eq \"info\")
{
&send_request($get_info,$ip_addr,$ip_port);
&recv_server_data;
&sort_info;
&send_request($get_players,$ip_addr,$ip_port);
&recv_player_data;
&sort_players;
&html_table_footer(450);
&html_finish;
}
if($mode eq \"rules\")
{
&send_request($get_info,$ip_addr,$ip_port);
&recv_server_data;
&sort_rule_info;
&send_request($get_rules,$ip_addr,$ip_port);
&recv_server_data;
&sort_rule_data;
&html_table_footer(350);
&html_finish;
}
if($mode eq \"form\")
{
&print_form;
&html_finish;
}
####################
###Program End######
####################
sub get_form_data
{
$fdata = $ENV{\'QUERY_STRING\'};
@key_value=split(\"&\",$fdata);
$data_ctr=0;
foreach $key_value (@key_value)
{
@key_value2=split(\"=\",$key_value);
$key=shift(@key_value2);
$value=shift(@key_value2);
$data_ctr++;
if($mode eq \"list\")
{
&do_ip_list($key,$value);
}
else
{
&process_form_data($key,$value);
}
}
}
####################
sub process_form_data($)
{
local($key,$value)=@_;
if($key eq \"mode\")
{
$mode=$value;
}
if($key eq \"ip\")
{
$ip_addr=$value;
}
if($key eq \"port\")
{
$ip_port=$value;
}
}
####################
sub do_ip_list($)
{
local($key,$value)=@_;
local(@temp)=\"\";
if($value ne \"\")
{
@temp=$value;
if($key eq \"ip\")
{
push(@ip_list,@temp);
}
if($key eq \"port\")
{
push(@ip_list,@temp);
}
}
}
####################
sub html_link($)
{
local($url,$style,$text)=@_;
print(\"<a href=\\\"$url\\\" class=\\\"\".$style.\"_off\\\" onMouseOver=\\\"this.className=\\\'\".$style.\"_on\\\'\\;\\\"onMouseOut=\\\"this.className=\\\'\".$style.\"_off\\\'\\;\\\">$text</a>\");
}
####################
sub dhtml_style($)
{
local($name,$face1,$face2,$size1,$size2,$color1,$color2,$style1,$style2)=@_;
print(\"<STYLE>.\".$name.\"_off{font-size: \".$size1.\"\\;text-decoration: \".$style1.\"\\;color: \".$color1.\"\\;face: \".$face1.\"\\;}\");
print(\".\".$name.\"_on{font-size: \".$size2.\"\\;text-decoration: \".$style2.\"\\;color: \".$color2.\"\\;face: \".$face2.\"\\;}</STYLE>\");
}
####################
sub html_table_footer($)
{
local($width)=@_;
&html_table_on($width,$h_table_header_color,\"right\");
&html_bold_on;
print(\"Half-Spy - \");
&html_italics_on;
print(\"Written by Scott Wilson\");
&html_bold_off;
&html_italics_off;
&html_table_off;
}
####################
sub html_head_start
{
print(\"Content-type: text/html\\n\\n\");
print(\"<HTML>\");
print(\"<HEAD><title>\".$h_title.\"</title>\");
}
####################
sub html_head_finish
{
print(\"<\\HEAD><BODY bgcolor=\".$h_bgcolor.\" text=\".$h_textcolor.\" background=\".$h_bg.\">\");
}
####################
sub html_finish
{
print(\"</body></HTML>\");
}
####################
sub html_center_on
{
print(\"<center>\");
}
####################
sub html_center_off
{
print(\"</center>\");
}
####################
sub html_line
{
print(\"<hr>\");
}
####################
sub html_table_on($)
{
local($width,$color,$align)=@_;
print(\"<TABLE border=0 width=\".$width.\"><TR><TD bgcolor=\".$color.\" align=\".$align.\" valign=center>\");
}
####################
sub html_table_cell_on($)
{
local($color,$align,$width)=@_;
print(\"<TD bgcolor=\".$color.\" align=\".$align.\" width=\".$width.\"%>\");
}
####################
sub html_table_cell_off
{
print(\"</TD>\");
}
####################
sub html_table_off
{
print(\"</TD></TR></TABLE>\");
}
####################
sub html_pbreak
{
print(\"<P>\");
}
####################
sub html_bold_on
{
print(\"<B>\");
}
####################
sub html_bold_off
{
print(\"</B>\");
}
####################
sub html_italics_on
{
print(\"<I>\");
}
####################
sub html_italics_off
{
print(\"</I>\");
}
####################
sub setup_socket
{
socket(SOCK, PF_INET, SOCK_DGRAM, getprotobyname(\"udp\")) or die \"socket Error: $!\";
}
####################
sub send_request($)
{
local($request,$ip_addr,$ip_port)=@_;
$serv_addr = inet_aton($ip_addr);
$send_addr = sockaddr_in($ip_port,$serv_addr);
send(SOCK,$request,0,$send_addr) or die \"Cannot connect to : $host:$portnr\";
}
####################
sub recv_player_data
{
$playerdata=0;
$serv_addr = recv(SOCK,$playerdata,4096,0) or die \"recv Error: $!\";
}
####################
sub recv_server_data
{
$data=0;
$serv_addr = recv(SOCK,$data,4096,0) or die \"recv Error: $!\";
}
####################
sub recv_server_list_data
{
$listdata=0;
$serv_addr = recv(SOCK,$listdata,4096,0) or die \"recv Error: $!\";
&sort_list_info($listdata);
}
####################
sub sort_info
{
@data = split(\"\\x\",$data);
foreach $line (@data)
{
$ctr++;
if ($ctr == 1)
{
$temp = substr $line,5;
$serv_ip=$temp;
}
if ($ctr == 2)
{
$serv_name=$line;
}
if ($ctr == 3)
{
$serv_map=$line;
}
if ($ctr == 4)
{
$serv_type=$line;
}
if ($ctr == 5)
{
$serv_game=$line;
}
if ($ctr == 6)
{
$temp = ord $line;
@temp = unpack (\"c c\",@data[5]);
$serv_players_curr=$temp;
if ($temp!=0)
{
$serv_players_max=$temp[1];
}
else
{
@temp = unpack (\"c\",@data[6]);
$serv_players_max=$temp[0];
}
}
}
&print_info($serv_ip,$serv_name,$serv_map,$serv_type,$serv_game,$serv_players_curr,$serv_players_max);
}
####################
sub sort_players
{
$ctr=0;
@temp = unpack(\"i c c c A*\", $playerdata);
$numplayers = @temp[2];
$temp = @temp[4];
@temp3 = split(\"\\x\",$temp);
$name = @temp3[0];
$length = length $name;
@playerdata = unpack(\"i c c A*\", $playerdata);
$rest = @playerdata[3];
while ($ctr<$numplayers)
{
if ($ctr<$numplayers)
{
@temp3 = split(\"\\x\",$rest);
$name = @temp3[0];
$length = length $name;
@playerdata = unpack(\"c A$length i f A*\", $rest);
$name = @playerdata[1];
$score = @playerdata[2];
$time = @playerdata[3]/60;
$rest = @playerdata[4];
&print_player($ctr,$name,$score,$time);
}
$ctr++;
}
}
####################
sub print_info($)
{
local($serv_ip,$serv_name,$serv_map,$serv_type,$serv_game,$serv_players_curr,$serv_players_max)=@_;
local($rules_ip,$rules_port)=\"\";
($rules_ip,$rules_port)=split(\":\",$serv_ip);
&html_center_on;
&html_table_on(\"450\",$h_table_header_color,\"right\");
&html_bold_on;
print($serv_name.$h_br.$serv_ip.$h_br.\"Click Player Name to view Stats on the CLQ...\");
&html_bold_off;
&html_table_off;
&html_table_on(\"450\",$h_table_bgcolor,\"right\");
&html_bold_on;
print(\"Game Type : \".$h_br.\"Map Name : \".$h_br.\"Players : \");
&html_bold_off;
&html_table_cell_on($h_table_bgcolor,\"left\",\"35\");
&html_bold_on;
print($serv_game.$h_br);
print($serv_map.$h_br);
print($serv_players_curr.\" / \".$serv_players_max);
&html_bold_off;
&html_table_cell_on($h_table_bgcolor,\"center\",\"40\");
&html_bold_on;
&html_link(\"half-spy.pl?mode=rules&ip=\".$rules_ip.\"&port=\".$rules_port,\"link1\",\"Server Rules\");
&html_table_off;
}
###################
sub print_player($)
{
local($num,$name,$score,$time)=@_;
$num++;
&html_center_on;
&html_table_on(\"450\",$h_table_bgcolor,\"left\");
&html_bold_on;
&html_link(\"http://www.theclq.com/asp/find.asp?name=\".$name,\"link1\",$num.\" - \".$name);
&html_bold_off;
&html_table_cell_on($h_table_bgcolor,\"left\",\"20\");
&html_bold_on;
print(\"Frags: \".$score);
&html_bold_off;
&html_table_cell_on($h_table_bgcolor,\"left\",\"30\");
&html_bold_on;
print(\"Time: \");
printf\"%.2f min\",$time;
&html_table_off;
}
####################
sub list_servers
{
&html_center_on;
&html_table_on(\"700\",$h_table_header_color,\"right\");
&html_bold_on;
print(\"Half-Life Server list... Click Server name to view info...\");
&html_table_off;
&html_table_on(\"700\",$h_table_bgcolor,\"center\");
&html_bold_on;
print(\"Server Name\");
&html_table_cell_on($h_table_bgcolor,\"center\",\"25\");
&html_bold_on;
print(\"IP Address\");
&html_table_cell_on($h_table_bgcolor,\"center\",\"10\");
&html_bold_on;
print(\"Game\");
&html_table_cell_on($h_table_bgcolor,\"center\",\"15\");
&html_bold_on;
print(\"Map Name\");
&html_table_cell_on($h_table_bgcolor,\"center\",\"10\");
&html_bold_on;
print(\"Players\");
&html_table_off;
$counter=@ip_list;
$counter=($counter/2);
while($counter >= 1)
{
$ip_addr=shift(@ip_list);
$ip_port=shift(@ip_list);
&send_request($get_info,$ip_addr,$ip_port);
&recv_server_list_data;
$counter--;
}
&html_table_footer(\"700\")
&html_center_off;
}
##################
sub sort_list_info($)
{
local($listdata)=@_;
local(@listdata,@temp,$temp,$ctr)=0;
local($serv_ip.$serv_name.$serv_map.$serv_type.$serv_game.$serv_players_curr.$serv_players_max)=0;
@listdata = split(\"\\x\",$listdata);
foreach $line (@listdata)
{
$ctr++;
if ($ctr == 1)
{
$temp = substr $line,5;
$serv_ip=$temp;
}
if ($ctr == 2)
{
$serv_name=$line;
}
if ($ctr == 3)
{
$serv_map=$line;
}
if ($ctr == 4)
{
$serv_type=$line;
}
if ($ctr == 5)
{
$serv_game=$line;
}
if ($ctr == 6)
{
$temp = ord $line;
@temp = unpack (\"c c\",@listdata[5]);
$serv_players_curr=$temp;
if ($temp!=0)
{
$serv_players_max=$temp[1];
}
else
{
@temp = unpack (\"c\",@dlistata[6]);
$serv_players_max=$temp[0];
}
}
}
&print_server_list($serv_ip,$serv_name,$serv_map,$serv_type,$serv_game,$serv_players_curr,$serv_players_max);
}
####################
sub print_server_list($)
{
local($serv_ip,$serv_name,$serv_map,$serv_type,$serv_game,$serv_players_curr,$serv_players_max)=@_;
local($info_ip,$info_port)=\"\";
($info_ip,$info_port)=split(\":\",$serv_ip);
&html_table_on(\"700\",$h_table_bgcolor,\"left\");
&html_bold_on;
&html_link(\"half-spy.pl?mode=info&ip=\".$info_ip.\"&port=\".$info_port,\"link1\",$serv_name);
&html_table_cell_on($h_table_bgcolor,\"center\",\"25\");
&html_bold_on;
print($serv_ip);
&html_table_cell_on($h_table_bgcolor,\"center\",\"10\");
&html_bold_on;
print($serv_type);
&html_table_cell_on($h_table_bgcolor,\"center\",\"15\");
&html_bold_on;
print($serv_map);
&html_table_cell_on($h_table_bgcolor,\"center\",\"10\");
&html_bold_on;
print($serv_players_curr.\" / \".$serv_players_max);
&html_table_off;
local($serv_ip,$serv_name,$serv_map,$serv_type,$serv_game,$serv_players_curr,$serv_players_max)=0;
}
####################
sub print_rule_info($)
{
local($serv_ip,$serv_name,$serv_map,$serv_type,$serv_game,$serv_players_curr,$serv_players_max)=@_;
local($rules_ip,$rules_port)=\"\";
($rules_ip,$rules_port)=split(\":\",$serv_ip);
&html_center_on;
&html_table_on(\"350\",$h_table_header_color,\"right\");
&html_bold_on;
print($serv_name.$h_br.$serv_ip);
&html_bold_off;
&html_table_off;
&html_table_on(\"350\",$h_table_bgcolor,\"right\");
&html_bold_on;
print(\"Game Type : \".$h_br.\"Map Name : \".$h_br.\"Players : \");
&html_bold_off;
&html_table_cell_on($h_table_bgcolor,\"left\",\"33\");
&html_bold_on;
print($serv_game.$h_br);
print($serv_map.$h_br);
print($serv_players_curr.\" / \".$serv_players_max);
&html_bold_off;
&html_table_cell_on($h_table_bgcolor,\"center\",\"38\");
&html_bold_on;
&html_link(\"half-spy.pl?mode=info&ip=\".$rules_ip.\"&port=\".$rules_port,\"link1\",\"Back to Players\");
&html_table_off;
}
####################
sub print_rules($)
{
local($s_var,$s_val)=@_;
&html_table_on(\"350\",$h_table_bgcolor,\"left\");
&html_bold_on;
print($s_var);
&html_table_cell_on($h_table_bgcolor,\"left\",\"25\");
&html_bold_on;
print($s_val);
&html_table_off;
}
####################
sub sort_rule_info
{
@data = split(\"\\x\",$data);
foreach $line (@data)
{
$ctr++;
if ($ctr == 1)
{
$temp = substr $line,5;
$serv_ip=$temp;
}
if ($ctr == 2)
{
$serv_name=$line;
}
if ($ctr == 3)
{
$serv_map=$line;
}
if ($ctr == 4)
{
$serv_type=$line;
}
if ($ctr == 5)
{
$serv_game=$line;
}
if ($ctr == 6)
{
$temp = ord $line;
@temp = unpack (\"c c\",@data[5]);
$serv_players_curr=$temp;
if ($temp!=0)
{
$serv_players_max=$temp[1];
}
else
{
@temp = unpack (\"c\",@data[6]);
$serv_players_max=$temp[0];
}
}
}
&print_rule_info($serv_ip,$serv_name,$serv_map,$serv_type,$serv_game,$serv_players_curr,$serv_players_max);
}
##################
sub sort_rule_data
{
@data = split(\"\\x\",$data);
shift(@data);
$ctr=@data;
&html_center_on;
while($ctr >= 1)
{
$s_var=shift(@data);
$s_val=shift(@data);
if($s_var ne \"\")
{
&print_rules($s_var,$s_val);
}
$ctr--;
}
}
##################
sub print_form
{
&html_center_on;
print(\"<FORM METHOD=\\\"GET\\\" ACTION=\\\"half-spy.pl\\\"><input type=hidden name=\\\"mode\\\" value=\\\"list\\\">\");
&html_table_on(\"350\",$h_table_header_color,\"right\");
&html_bold_on;
print(\"Enter IP addresses and Ports<br>to Generate Server List...\");
&html_table_off;
&html_table_on(\"350\",$h_table_bgcolor,\"center\");
&html_bold_on;
print(\"Server IP\");
&html_table_cell_on($h_table_bgcolor,\"center\",\"50\");
&html_bold_on;
print(\"Server Port\");
&html_table_off;
&html_table_on(\"350\",$h_table_bgcolor,\"center\");
print(\"<input type=text name=\\\"ip\\\" value=\\\"\\\">\");
&html_table_cell_on($h_table_bgcolor,\"center\",\"50\");
print(\"<input type=text name=\\\"port\\\" value=\\\"\\\">\");
&html_table_off;
&html_table_on(\"350\",$h_table_bgcolor,\"center\");
print(\"<input type=text name=\\\"ip\\\" value=\\\"\\\">\");
&html_table_cell_on($h_table_bgcolor,\"center\",\"50\");
print(\"<input type=text name=\\\"port\\\" value=\\\"\\\">\");
&html_table_off;
&html_table_on(\"350\",$h_table_bgcolor,\"center\");
print(\"<input type=text name=\\\"ip\\\" value=\\\"\\\">\");
&html_table_cell_on($h_table_bgcolor,\"center\",\"50\");
print(\"<input type=text name=\\\"port\\\" value=\\\"\\\">\");
&html_table_off;
&html_table_on(\"350\",$h_table_bgcolor,\"center\");
print(\"<input type=text name=\\\"ip\\\" value=\\\"\\\">\");
&html_table_cell_on($h_table_bgcolor,\"center\",\"50\");
print(\"<input type=text name=\\\"port\\\" value=\\\"\\\">\");
&html_table_off;
&html_table_on(\"350\",$h_table_bgcolor,\"center\");
print(\"<input type=text name=\\\"ip\\\" value=\\\"\\\">\");
&html_table_cell_on($h_table_bgcolor,\"center\",\"50\");
print(\"<input type=text name=\\\"port\\\" value=\\\"\\\">\");
&html_table_off;
&html_table_on(\"350\",$h_table_bgcolor,\"center\");
print(\"<input type=text name=\\\"ip\\\" value=\\\"\\\">\");
&html_table_cell_on($h_table_bgcolor,\"center\",\"50\");
print(\"<input type=text name=\\\"port\\\" value=\\\"\\\">\");
&html_table_off;
&html_table_on(\"350\",$h_table_bgcolor,\"right\");
print(\"<input type=submit value=\\\"Submit\\\">\");
&html_table_off;
&html_table_footer(\"350\");
}
--------------------------------
Hjælp!
Send evt. \"løsning\" til mattias@interactiveweb.dk
/MadD
