I have a PHP code here that I would like to get converted into Visual
Basic. I am already experienced in Winsock protocols, so I should have
no problems understanding any Visual Basic code you give me.
<?php
die();
/*
***************************************************************
| |
| A simple example how you can send rcon-commands via PHP to |
| a BFV-Server. |
| |
| All you have to do ist call the function |
| send_cmd(COMMAND, SOCKET, RCON-USERNAME, RCON-PASSWORD) |
| |
| This function will return a small array with three values: |
| $array['authentication'] = Auth-Status |
| $array['response_len'] = Length of the server-response |
| $array['response'] = The response (string) |
| |
| Thanks to Traxter for the Help with authentication and to |
| all the other guys in the lightcubed Forum i took some |
| code - snippets from! |
| |
| You are free to make anything you want to do with this |
| script, but it would be nice if you would share your changes |
| with me and the whole community. |
| |
| Greetinx |
| Surfer Lance, 22.07.2004 |
| www.charlysurftnicht.de / www.9thcav.de |
| mailto:
[email protected] |
| |
**************************************************************
*/
?><html>
<head>
<title>BFV Player Control</title>
</head>
<body>
<?php
error_reporting (E_ALL ^ E_NOTICE);
$ip = "83.73.100.173"; //CHANGE THIS! -> IP of your Server
$port= "4711"; //CHANGE THIS! -> rcon-port of your Server
$username= "mathy"; //CHANGE THIS! -> username
$password= "pindleskin"; //CHANGE THIS! -> password
$timeout= 5;
$fp = fsockopen($ip, $port, $errno, $errstr, $timeout);
if (!$fp) echo "Could not connect to " . $ip . ":" . $port . " !";
else {
// Run a command
if (isset($_GET['runcommand'])) send_cmd($_GET['runcommand'], $fp, $username, $password);
//$response = send_cmd("game.listplayers", $fp, $username, $password);
send_cmd("admin.changemap wake gpm_ctf bf1942", $fp, $username, $password);
// Set up the table title row
echo "
<table cellspacing=\"1\" cellpadding=\"1\" border=\"1\">
<tr>
<td>ID</td>
<td>Player Name</td>
<td>Remote IP</td>
<td>Hash</td>
<td>Admin Control</td>
</tr>";
// Explode out each player
$players = explode("\n", $response['response']);
// Operate on each player
foreach ($players as $player) {
if (strlen($player) > 30) {
$id = substr($player, 3, strpos($player, " ")-3);
$player_name = substr($player, 6+strlen($id), strpos($player, " is remote ip: ")-(6+strlen($id)));
$remote_ip = substr($player, 21+strlen($id)+strlen($player_name),
strpos($player, " hash:")-(21+strlen($id)+strlen($player_name)));
$hash = substr($player, -32);
echo "
<tr>
<td>$id</td>
<td>$player_name</td>
<td>$remote_ip</td>
<td>$hash</td>
<td><a href=\"?runcommand=admin.admin_killplayer
$id\">Kill</a> <a href=\"?runcommand=admin.kickplayer
$id\">Kick</a></td>
</tr>\n";
}
}
fclose($fp); // close socket
echo "</table>
</body>
</html>
";
}
//********************************************************************************
// Some functions:
//********************************************************************************
function send_cmd($command, $fp, $username, $password) {
if (isset($return)) unset($return);
$return = array();
$key = fread($fp,10); // read XOR key from socket
echo $key;
$username = xorcrypt($username,$key)."\x00"; // encrypt username with XOR
echo "<br>" . $username;
$password = xorcrypt($password,$key)."\x00"; // encrypt password with XOR
echo "<br>" . $password;
fwrite($fp,pack("L",strlen($username))); // write length of encrypted password to socket
echo "<br>" . pack("L",strlen($username));
fwrite($fp,$username);
fwrite($fp,pack("L",strlen($password))); // write length of encrypted password to socket
echo "<br>" . pack("L",strlen($password));
fwrite($fp,$password);
$result = fread($fp,1);
$response = xbyte_to_int($result);
if ($response == 1) {
echo "<br>Done";
$acstatus = "OK";
} else {
echo "<br>Error";
$acstatus = "ERR";
}
if ($acstatus== "OK") {
$comm_tmp = int_to_4byte(2);
fwrite($fp, $comm_tmp);
$comm_tmp = "ConsoleMessage 0";
$len = strlen($comm_tmp) + 1;
fwrite($fp, int_to_4byte($len));
fwrite($fp, $comm_tmp . chr(0));
$len = strlen($command) + 1;
fwrite($fp, int_to_4byte($len));
fwrite($fp, $command . chr(0));
$result = fread($fp,4);
$response = xbyte_to_int($result);
if ($response == 1) {
$result = fread($fp,4);
$len = xbyte_to_int($result);
$response_len = $len;
if ($len > 1) {
$result = fread($fp,$len);
}
else $result = "N/A";
$final_result = $result;
}
}
else { // $acstatus != "OK" :
$response_len = "N/A";
$final_result = "N/A";
}
$return = array('authentication' => $acstatus,
'response_len' => $response_len,
'response' => $final_result);
return $return;
} // ende function
function xorcrypt($string, $key) {
for($i=0; $i<strlen($string); $i++)
{ $string[$i] = $string[$i]^$key[$i]; }
return $string;
}
//--------------------------------------------------------------------------
// Convert number into one string 4 byte (number long 4 byte) -
//--------------------------------------------------------------------------
function int_to_4byte($numero_conv) {
$final_stri = "";
for ($x = 1; $x <= 3; $x++) {
$n_val = intval(floor($numero_conv/256));
$n_rest = intval($numero_conv % 256);
$final_stri .= chr($n_rest);
$numero_conv = $n_val;
}
$final_stri .= chr($n_val);
return $final_stri;
}
//----------------------------------------------------------------
// convert strings 4 byte (number long 4 byte) into number
//----------------------------------------------------------------
function xbyte_to_int($stri_conv) {
$val_finale = 0;
$len_stri = strlen($stri_conv);
for ($x = 0; $x < $len_stri; $x++) {
$val_finale = $val_finale + (ord(substr($stri_conv, $x, 1)) * pow(256, $x));
}
return $val_finale;
}
?>
</body>
</html>
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).