Uebermorgen Posted November 1, 2014 Report Share Posted November 1, 2014 Hi, how can I send a message through php to the server, to all players like "ADMIN: Server restart in..." ? greets Link to comment Share on other sites More sharing options...
0 FPGElliot Posted November 1, 2014 Report Share Posted November 1, 2014 Use RCON Dart is a good RCON Link to comment Share on other sites More sharing options...
0 leodr99 Posted November 1, 2014 Report Share Posted November 1, 2014 Here you have it... Just call the script with the message that you wish to send. (php [name of the script file] "text message") Also set the RCON password ($pass variable), the IPADDR ($ip variable) and the PORT ($port variable). <?php $text = 'say -1 '; if(isset($argv[1])) { $text .= $argv[1]; } else { $text .= "WARNING!! Server Restart in X MINUTES!!!"; } //Settings $pass = "SET_YOUR_RCON_PASSWORD_HERE"; $ip = '127.0.0.1'; //set your server ip address $port = 2302; //set the server port //Dont touch $msgseq = 0; //Generate CRC32 for pass and msg $authCRC = crc32(chr(255).chr(00).trim($pass)); $authCRC = sprintf("%x", $authCRC); $msgCRC = crc32(chr(255).chr(01).chr(hexdec(sprintf('%01b',$msgseq))).$text); $msgCRC = sprintf("%x", $msgCRC); //Reverse the CRCs and put into array $authCRC = array(substr($authCRC,-2,2),substr($authCRC,-4,2),substr($authCRC,-6,2),substr($authCRC,0,2)); $msgCRC = array(substr($msgCRC,-2,2),substr($msgCRC,-4,2),substr($msgCRC,-6,2),substr($msgCRC,0,2)); //Socket comm $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); if(!$sock) { die("Socket create failed: ".socket_last_error()."\n"); } else { echo "Got Socket!\n"; } //header $loginmsg = "BE".chr(hexdec($authCRC[0])).chr(hexdec($authCRC[1])).chr(hexdec($authCRC[2])).chr(hexdec($authCRC[3])); //Add payload $loginmsg .= chr(hexdec('ff')).chr(hexdec('00')).$pass; $len = strlen($loginmsg); echo "Attempting Login\n"; $sent = socket_sendto($sock, $loginmsg, $len, 0, $ip, $port); if($sent == false) { die("failed to send login ".socket_last_error()."\n"); } else { //echo "Login sent: ".$sent." bytes\n"; } socket_recvfrom($sock, $buf, 64, 0, $ip, $port); //var_dump($buf); if(ord($buf[strlen($buf)-1]) == 1) { echo "Login Successful!\n"; } else if(ord($buf[strlen($buf)-1]) == 0) { echo "Login Failed!\n"; } else { echo "Unknown result from login!\n"; exit; } $recv = socket_recvfrom($sock, $buf, 64, 0, $ip, $port); if($recv == false) { die("failed to recv ".socket_last_error()."\n"); } else { //echo "Recieved: ".$recv." bytes\n\n"; } //var_dump($buf); echo substr($buf,9)."\n"; //Send a heartbeat packet $statusmsg = "BE".chr(hexdec("7d")).chr(hexdec("8f")).chr(hexdec("ef")).chr(hexdec("73")); $statusmsg .= chr(hexdec('ff')).chr(hexdec('02')).chr(hexdec('00')); $len = strlen($statusmsg); socket_sendto($sock, $statusmsg, $len, 0, $ip, $port); //header $saymsg = "BE".chr(hexdec($msgCRC[0])).chr(hexdec($msgCRC[1])).chr(hexdec($msgCRC[2])).chr(hexdec($msgCRC[3])); //msg $saymsg .= chr(hexdec('ff')).chr(hexdec('01')).chr(hexdec(sprintf('%01b',$msgseq))).$text; $len = strlen($saymsg); $sent = socket_sendto($sock, $saymsg, $len, 0, $ip, $port); $msgseq++; if($sent == false) { die("failed to send msg ".socket_last_error()."\n"); } else { echo $text."\n"; } //socket_recvfrom($sock, $buf, 64, 0, $ip, $port); //var_dump($buf); socket_close($sock); ?> Honestly I already don't remmember where i got this snippet, but the credits go to the author, whoever he is. I've turned to the BigBrotherBot for a good while, since it has more features that i give use. my 2cents. Cheers. Link to comment Share on other sites More sharing options...
0 Uebermorgen Posted November 1, 2014 Author Report Share Posted November 1, 2014 Thanks leodr99, but its not working for me. I changed the settings to my stuff, but the page is loading, loading and loading. i dont know why. :( Link to comment Share on other sites More sharing options...
0 jahangir13 Posted November 7, 2014 Report Share Posted November 7, 2014 @leodr99: the credits go to JPhix in the Linux Server port forum ( ) @Uebermorgen: I use the scripts since they are released and they work. I've copied the above code into my webserver and also works from there if executed in the browser. Then you may have set something wrong in your settings. Which message do you get in your browser? My messages: Got Socket! Attempting Login Login Successful! RCon admin #0 (127.0.0.1:37213) logged in say -1 WARNING!! Server Restart in X MINUTES!!! Link to comment Share on other sites More sharing options...
Question
Uebermorgen
Hi,
how can I send a message through php to the server, to all players like
"ADMIN: Server restart in..."
?
greets
Link to comment
Share on other sites
4 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now