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).

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)){

}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.