Ashus (.ashus.net)

Developer's website
It is currently 08. 09. 2010 11:51

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Help? PHP RCon Messages Script
PostPosted: 30. 10. 2009 21:07 
Offline

Joined: 25. 04. 2009 21:44
Posts: 12
I wrote this script to run on crontab every 2 minutes
However, The problem I am having is it will send the same message twice sometimes....How can I get it to not do that?

<?php
// SNXRaven's RCon Connection Script.
//Chooses a random number
$num = Rand (1,7);
//Based on the random number, gives a quote
switch ($num)
{
case 1:
$command = "say Welcome to ^1[uBp],^7 You can join us at: UnitedBasePlayers.org Have a GREAT game!";
break;
case 2:
$command = "say We allow all parts of the game, all perks and guns.";
break;
case 3:
$command = "say There is no bad language allowed in any ^1[uBp]^7 Server";
break;
case 4:
$command = "say Hacking is not allowed in any ^1[uBp]^7 Server, if you are caught..you will be banned!";
break;
case 5:
$command = "say Feel free to join us in vent: IP vent.unitedbaseplayers.org:4224 Pass: Sabbath";
break;
case 6:
$command = "say United Base Players is a family based gaming community, please be respect all players.";
case 7:
$command = "say If you would like to join our Gaming Community do so at: UnitedBasePlayers.org";
}

// Server IP, Port & to connect to. 10.30.09
$server_ip = '127.0.0.1';
$server_port = '28960';
$rconpass = SomePass;

$ip = $_SERVER['REMOTE_ADDR'];
$hostaddress = gethostbyaddr($ip);
$browser = $_SERVER['HTTP_USER_AGENT'];

$server_ip = "udp://" . $server_ip;

$connect = fsockopen($server_ip, $server_port, $errno, $errstr, 30);

socket_set_timeout ($connect, 1, 000000);

$server_extra_footer = true; // true | false; if problems with receiving playerlist occur, enable
$send = "\xff\xff\xff\xff" . 'rcon "' . $rconpass . '" '.$command.(($server_extra_footer)?"\n":'');

fwrite($connect, $send);
fputs($connect, $send);

$output = fread ($connect, 1);
if (! empty ($output)) {
do {
$status_pre = socket_get_status ($connect);
$output = $output . fread ($connect, 1);
$status_post = socket_get_status ($connect);
}
while ($status_pre[unread_bytes] != $status_post[unread_bytes]);
};

fclose($connect);


?>


Top
 Profile E-mail  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group