Location: PHPKode > projects > Kbot > kbot_1.3/rconBots/includes/common.inc.php
<?PHP
/**
 *
 * $Id: common.inc.php 117 2006-09-30 07:37:15Z khaless $
 * $Revision: 117 $
 * $Author: khaless $
 * $Date: 2006-09-30 17:37:15 +1000 (Sat, 30 Sep 2006) $
 * 
 * Copyright (c) 2005 Mathew Rodley <hide@address.com>
 * 
 * Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

// bot is pluaged by notices, dont worry about them
error_reporting(E_ALL ^ E_NOTICE);

//define('STDIN',fopen("php://stdin","r"));
//define('STDOUT',fopen("php://stdout","w"));

$array1 = unserialize(fgets(STDIN, 4096));
$array2 = unserialize(fgets(STDIN, 4096));
$dataArray = array_merge($array1, $array2);

// for testing.
/*$dataArray = array('ip' => '202.92.32.20',
'port' => '27030',
'map' => 'de_dust',
'sv_password' => '12345',
'rconPassword' => 'rc4k3less',
'adminPassword' => 'test123',
'botIP' => '60.225.184.253',
'playerCount' => 2,
'rounds' => 2,
'maps' => 'de_dust2',
'msgTargetChannels' => serialize(array('#kbot-test')),
'teams' => array('team1', 'team2'), 
'teamMembers' => array(array('one', 'two'),array('one', 'two')));
*/

// now set to nonblocking after we have our $dataArray
stream_set_blocking (STDIN, FALSE);

// what OS are we running?
$os = PHP_OS;
if(stristr($os, 'WIN')) {
	define('KBOT_WINDOWSOS', true);
	$os = 'WIN';
}
else {
	define('KBOT_WINDOWSOS', false);
}
define('KBOT_OS', $os);

if(KBOT_WINDOWSOS) {
	// give it some setup time.
	fwrite(STDOUT,"BREAK\r\n");
}

// custom error handler stuff
// error handler function
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
	global $dataArray;
	if(!defined('KBOT_DEBUG') || !error_reporting()) return;
	switch ($errno) {
		case E_USER_ERROR:
		$errStr = 'ERROR ['.$errno.'] '.trim($errstr) . ' in '.$errfile . ' on line '. $errline;
		break;
		case E_USER_WARNING:
		$errStr = 'WARNING ['.$errno.'] '.trim($errstr) . ' in '.$errfile . ' on line '. $errline;
		break;
		case E_USER_NOTICE:
		$errStr = 'NOTICE ['.$errno.'] '.trim($errstr) . ' in '.$errfile . ' on line '. $errline;
		break;
		default:
		$errStr = 'UNKNOWN ERROR ['.$errno.'] '.trim($errstr) . ' in '.$errfile . ' on line '. $errline;
		break; 
	}
	fwrite(STDOUT,serialize(array('targets' => $dataArray['msgTargetChannels'], 'data' => 'ERR:2:'.$errStr))."\n");
	fwrite(STDOUT,"BREAK\r\n");
}
set_error_handler("myErrorHandler");
?>
Return current item: Kbot