Jump to content

How do you send RCON commands through php (Counter-Strike 1.6/Half-Life)


dezkit

Recommended Posts

Hello guys, after months of contacting my webhosting to figure out why I keep getting connection refused when I try to connect to any of my gameservers (The problem was I have not been putting udp:// in the beginning), I have stumbled upon a new problem, I need to figure out how to send rcon commands through php in Counter-Strike 1.6, I have tried looking at code samples but I cannot understand OOP and grab all the needed code, I will be very happy if one of you guys can help me with my problem, I have a current code, here it is:

<?php
mysql_connect("localhost", "xxx", "xxx") or die(mysql_error());
mysql_select_db("quickgam_status") or die(mysql_error());
$result = mysql_query("SELECT * FROM servers") 
or die(mysql_error());  


echo "<table border='1'>";
echo "<tr> <td>Status</td> <td>Server Name</td> <td>Players</td> <td>Connect</td> </tr>";
echo "<tr>";
while($row = mysql_fetch_array($result)){
// Print out the contents of each row into a table
if(fsockopen("udp://".$row['ip'], $row['port'], $errno, $errstr, 2)){
	echo "<td><img src='./yes.gif'></td>";
} else {
	echo "<td><img src='./no.gif'></td>";
}
echo "<td>name</td>";
echo "<td>players</td>";
echo "<td><a href=\"steam://connect/".$row['ip']."".$row['port']."\">connect</a></td>";
echo "</tr>";	
} 

echo "</table>";
?>

 

$row['rcon'] can be the rcon password in my mysql table.

 

Please help me. Thank you, have a wonderful week(end).

Nevermind, I have found a class on google that can send data to the servers and it works

I am having trouble with this code:

<?php
mysql_connect("localhost", "xxx", "xxx") or die(mysql_error());
mysql_select_db("quickgam_status") or die(mysql_error());
$result = mysql_query("SELECT * FROM servers") 
or die(mysql_error());  




echo "<table border='1'>";
echo "<tr> <td>Status</td> <td>Server Name</td> <td>Players</td> <td>Connect</td> </tr>";
echo "<tr>";
while($row = mysql_fetch_array($result)){
// Print out the contents of each row into a table
if(fsockopen("udp://".$row['ip'], $row['port'], $errno, $errstr, 2)){
	echo "<td><img src='./yes.gif'></td>";
} else {
	echo "<td><img src='./no.gif'></td>";
}
	include 'rcon_hl_net.inc';
	$M=new Rcon();
	$M->Connect($row['ip'],$row['port'],$row['rcon']);
	$ret=$M->ServerInfo();
echo "<td>".$ret["name"]."</td>";
echo "<td>players</td>";
echo "<td><a href=\"steam://connect/".$row['ip'].":".$row['port']."\">connect</a></td>";
echo "</tr>";	
} 

echo "</table>";
?>

 

The error:

Fatal error: Cannot redeclare class Rcon in /home/quickgam/public_html/rcon_hl_net.inc on line 23

you put the include statement in a while loop..

 

while($row = mysql_fetch_array($result)){
  
  include 'rcon_hl_net.inc';


}

 

you should use the include statement outside the while loop in your case

include 'rcon_hl_net.inc';
while($row = mysql_fetch_array($result)){

}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.