Oldest known version of this page was edited on 2007-08-07 08:52:21 by JimLucas []
Page view:
This a proxy server for the tribes client
This works from the command line. You might need to adjust the location of the PHP CLI
#!/usr/local/bin/php -q
<?php
error_reporting(E_ALL);
ini_set('display_errors',
'On');
// Set time limit to indefinite execution
set_time_limit(0);
// Set the ip and port we will listen on
$OUT_IP =
'66.39.167.52';
$OUT_PORT =
28000;
$master_ip =
'198.74.35.18:28000';
$packet_size =
1024;
$timeout =
180;
$servers =
array();
echo "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
/* Open a server socket to port 1234 on localhost */
if ( $socket = @stream_socket_server
("udp://{$OUT_IP}:{$OUT_PORT}",
$errno,
$errstr, STREAM_SERVER_BIND
) ) {
echo "Listening for client connection\n";
echo "Receiving data from client ";
while ( true ) {
$output =
$raw_data = stream_socket_recvfrom
($socket,
$packet_size,
0,
$client_ip);
echo "[ Done ]\n";
echo "\n\tClient IP:{$client_ip}\n\n";
while ( $output !=
'' ) {
$str = GetPascalString
($output);
for($y=
0;
$y<strlen
($str);
$y++
) {
echo ord($str[$y]).
'.';
}
echo "\n";
}
echo "Sending client data to master server ";
stream_socket_sendto
($socket,
$raw_data,
0,
$master_ip);
echo "[ Done ]\n\n";
echo "Receiving data from master server ";
$output =
$raw_data = stream_socket_recvfrom
($socket,
$packet_size,
0,
$master_ip);
echo "[ Done ]\n";
echo "\n\tServer IP:{$master_ip}\n\n";
while ( $output !=
'' ) {
$str = GetPascalString
($output);
for($y=
0;
$y<strlen
($str);
$y++
) {
echo ord($str[$y]).
'.';
}
echo "\n";
}
echo "Sending data from master server back to client ";
stream_socket_sendto
($socket,
$raw_data,
0,
$client_ip);
echo "[ Done ]\n\n\n\n\n\n\n\n\n\n\n";
echo "Receiving data from client ";
}
fclose($socket);
} else {
echo "Socket Server Failure \n[{$errno}]: {$errstr}\n";
}
function GetByte
(&
$data) {
$d =
$data[0];
$data =
substr($data,
1);
return ord($d);
}
function GetInt16
(&
$data) {
for($i=
0,
$s=
"";
$i<
2;
$i++
) {
$s =
dechex(GetByte
($data)) .
$s;
$data =
substr($data,
1);
}
return hexdec($s);
}
function GetInt32
(&
$data) {
for($i=
0,
$s=
"";
$i<
4;
$i++
) {
$s =
dechex(GetByte
($data)) .
$s;
$data =
substr($data,
1);
}
return hexdec($s);
}
function GetPascalString
(&
$data) {
$len = GetByte
($data);
$str =
($len>
0)?
substr($data,
0,
$len):
"";
$data =
($len>
0)?
substr($data,
$len):
$data;
return $str;
}