will35010 Posted October 15, 2008 Share Posted October 15, 2008 Hi All, Just wanted to say thanks in advanced. I'm a complete noob when it comes to php. I run a few game servers and I'm trying to put together a script that sends console messages. I have the messages in an array so I can add new ones easily, but it has a problem with line 15. Line 15 is send_msg($msg); Here is the script: <?php // - edit - this is Open Source of course.... /*-------------------------------------------------------------------------*/ // Set up the messages /*-------------------------------------------------------------------------*/ $msg = array(0 => '"Radio spammers will be killed!"', 1 => '"LG members are admins so shut up!"', 2 => '"Hax accusers will be tarred and beaten!"', 3 => '"Get a demo and shut up!"', 4 => '"Get your stats @ www.LowGravityURT.com"'); foreach ($msg as $key => $value) { print "$value\n"; } send_msg($msg); // ---------------------------------------- // function to connect to game server and // send the message to the q3a console // ---------------------------------------- function send_msg($msg){ $rconpassword = "urtlg"; $port = "27960"; // default quake port. Change if needed $start = "\xff\xff\xff\xffrcon " . $rconpassword . " "; // ---------------------------------------- // Open socket // ---------------------------------------- $fp = fsockopen("udp://8.12.16.171", $port, $errno, $errstr, 10); // ---------------------------------------- // Error checking // ---------------------------------------- if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { stream_set_timeout($fp, 2); // Set a low timeout // Send commands fputs($fp, $start . "say " . $msg . "\n"); fclose($fp); } // end if // ---------------------------------------- // Change to your liking sleep(seconds) // ---------------------------------------- sleep(4); } // end function send_msg ?> Quote Link to comment https://forums.phpfreaks.com/topic/128480-solved-need-help-with-short-script/ Share on other sites More sharing options...
Lamez Posted October 15, 2008 Share Posted October 15, 2008 USE THE CODE TAGS! Also, what is your question? Quote Link to comment https://forums.phpfreaks.com/topic/128480-solved-need-help-with-short-script/#findComment-665851 Share on other sites More sharing options...
iversonm Posted October 15, 2008 Share Posted October 15, 2008 first you never close off your foreach statement second you need a ; after print() and your send_msg($msg); doesnt make any sense because $msg=array so it should be send_msg($msg[0]); for message one in example or send_msg($msg[1]); for message 2 Quote Link to comment https://forums.phpfreaks.com/topic/128480-solved-need-help-with-short-script/#findComment-665854 Share on other sites More sharing options...
CroNiX Posted October 15, 2008 Share Posted October 15, 2008 maybe foreach ($msg as $key => $value) { print "$value\n"; } send_msg($msg); should be foreach ($msg as $key => $value) { print "$value\n"; send_msg($value); } Quote Link to comment https://forums.phpfreaks.com/topic/128480-solved-need-help-with-short-script/#findComment-665855 Share on other sites More sharing options...
will35010 Posted October 15, 2008 Author Share Posted October 15, 2008 first you never close off your foreach statement second you need a ; after print() and your send_msg($msg); doesnt make any sense because $msg=array so it should be send_msg($msg[0]); for message one in example or send_msg($msg[1]); for message 2 Thank you!!! That's what I was looking for. I was able to fix the other errors, but it would only print "array" on the console. I didn't know how to call each message. Can I put a wait between messages? Quote Link to comment https://forums.phpfreaks.com/topic/128480-solved-need-help-with-short-script/#findComment-665857 Share on other sites More sharing options...
CroNiX Posted October 15, 2008 Share Posted October 15, 2008 see my above post Quote Link to comment https://forums.phpfreaks.com/topic/128480-solved-need-help-with-short-script/#findComment-665858 Share on other sites More sharing options...
CroNiX Posted October 15, 2008 Share Posted October 15, 2008 and you are already have a 'wait' in your sleep(4); statement at the bottom of the script. It will put a 4 second delay at the very end of sending the message before it does anything else. Quote Link to comment https://forums.phpfreaks.com/topic/128480-solved-need-help-with-short-script/#findComment-665859 Share on other sites More sharing options...
iversonm Posted October 15, 2008 Share Posted October 15, 2008 well if you want a time space between each post you could use sleep($num_seconds_to_sleep) but if you want to send all messages you are going to have to do what CroNiX said foreach ($msg as $key => $value) { print "$value\n"; send_msg($value); } or you will have to call each message send_msg[0]; sleep(5);//sleep 5 seconds send_msg[1]; it all depends what you want to do Quote Link to comment https://forums.phpfreaks.com/topic/128480-solved-need-help-with-short-script/#findComment-665860 Share on other sites More sharing options...
will35010 Posted October 15, 2008 Author Share Posted October 15, 2008 Thanks all for the quick help!!! I will change it to what cronix said so I don't have to call each one. Here is the working script: <?php // - edit - this is Open Source of course.... /*-------------------------------------------------------------------------*/ // Set up the messages /*-------------------------------------------------------------------------*/ $msg = array(0 => '"Radio spammers will be killed!"', 1 => '"LG members are admins so shut up!"', 2 => '"Hax accusers will be tarred and beaten!"', 3 => '"Get a demo and shut up!"', 4 => '"Get your stats @ www.LowGravityURT.com"'); foreach ($msg as $key => $value) { print "$value\n"; } send_msg($msg[0]); sleep(3); send_msg($msg[1]); sleep(3); send_msg($msg[2]); sleep(3); send_msg($msg[3]); sleep(3); send_msg($msg[4]); // ---------------------------------------- // function to connect to game server and // send the message to the q3a console // ---------------------------------------- function send_msg($msg){ $rconpassword = "urtlg"; $port = "27960"; // default quake port. Change if needed $start = "\xff\xff\xff\xffrcon " . $rconpassword . " "; // ---------------------------------------- // Open socket // ---------------------------------------- $fp = fsockopen("udp://8.12.16.171", $port, $errno, $errstr, 10); // ---------------------------------------- // Error checking // ---------------------------------------- if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { stream_set_timeout($fp, 2); // Set a low timeout // Send commands fputs($fp, $start . "say " . $msg . "\n"); fclose($fp); } // end if // ---------------------------------------- // Change to your liking sleep(seconds) // ---------------------------------------- sleep(4); } // end function send_msg ?> Quote Link to comment https://forums.phpfreaks.com/topic/128480-solved-need-help-with-short-script/#findComment-665861 Share on other sites More sharing options...
iversonm Posted October 15, 2008 Share Posted October 15, 2008 topic solved? Quote Link to comment https://forums.phpfreaks.com/topic/128480-solved-need-help-with-short-script/#findComment-665862 Share on other sites More sharing options...
CroNiX Posted October 15, 2008 Share Posted October 15, 2008 I was also trying to point out that you already have a sleep() at the end of your send_msg() function, which is currently set to 4 seconds. So it will send a message, wait 4 seconds, send another message....until there are no more to send. Quote Link to comment https://forums.phpfreaks.com/topic/128480-solved-need-help-with-short-script/#findComment-665865 Share on other sites More sharing options...
will35010 Posted October 15, 2008 Author Share Posted October 15, 2008 topic solved? How do you mark it as solved? Quote Link to comment https://forums.phpfreaks.com/topic/128480-solved-need-help-with-short-script/#findComment-665868 Share on other sites More sharing options...
CroNiX Posted October 15, 2008 Share Posted October 15, 2008 should be a button or something under the last post made. Quote Link to comment https://forums.phpfreaks.com/topic/128480-solved-need-help-with-short-script/#findComment-665870 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.