dezkit Posted January 7, 2010 Share Posted January 7, 2010 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 https://forums.phpfreaks.com/topic/187527-how-do-you-send-rcon-commands-through-php-counter-strike-16half-life/ Share on other sites More sharing options...
Catfish Posted January 7, 2010 Share Posted January 7, 2010 I don't see any OOP in that code, and I don't know what is not working because you haven't told us. Link to comment https://forums.phpfreaks.com/topic/187527-how-do-you-send-rcon-commands-through-php-counter-strike-16half-life/#findComment-990138 Share on other sites More sharing options...
dezkit Posted January 7, 2010 Author Share Posted January 7, 2010 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 https://forums.phpfreaks.com/topic/187527-how-do-you-send-rcon-commands-through-php-counter-strike-16half-life/#findComment-990140 Share on other sites More sharing options...
Catfish Posted January 7, 2010 Share Posted January 7, 2010 I'm guessing: include 'rcon_hl_net.inc'; is being called twice by your script? Link to comment https://forums.phpfreaks.com/topic/187527-how-do-you-send-rcon-commands-through-php-counter-strike-16half-life/#findComment-990143 Share on other sites More sharing options...
chaiwei Posted January 7, 2010 Share Posted January 7, 2010 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 https://forums.phpfreaks.com/topic/187527-how-do-you-send-rcon-commands-through-php-counter-strike-16half-life/#findComment-990146 Share on other sites More sharing options...
dezkit Posted January 7, 2010 Author Share Posted January 7, 2010 Have I ever told how much I love you guys? Haha, thank you very much guys, thanks so much. Link to comment https://forums.phpfreaks.com/topic/187527-how-do-you-send-rcon-commands-through-php-counter-strike-16half-life/#findComment-990147 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.