All pastes #606756 Raw Edit

Anonymous

public php v1 · immutable
·published 2007-07-07 02:15 UTC
rendered paste body
function Status_Antrix($aServer){	$sUptime = "N/A";	if (is_array($aServer))	{		$rMySql = mysql_connect($aServer['db_host'], $aServer['db_user'], $aServer['db_pass']);		if ($rMySql)		{			if (mysql_select_db($aServer['db_server'], $rMySql))			{				$rQuery = mysql_query("SELECT `online`, UNIX_TIMESTAMP(`timestamp`) AS `timestamp`											   FROM `server` LIMIT 1", $rMySql);				if ($rQuery && mysql_num_rows($rQuery) == 1)				{					$aRow = mysql_fetch_assoc($rQuery);					if ($aRow['online'] == 0)						return FALSE;										if ($aRow['timestamp'] > 0)					{						$iUptime = time() - $aRow['timestamp'];												// Calculate the Uptime						$iWeeks = floor($iUptime / (60 * 60 * 24 * 7));						$iUptime -= $iWeeks * 60 * 60 * 24 * 7;						$iDays = floor($iUptime / (60 * 60 * 24));						$iUptime -= $iDays * 60 * 60 * 24;						$iHours = floor($iUptime / (60 * 60));						$iUptime -= $iHours * 60 * 60;						$iMinutes = floor($iUptime / 60);												$sUptime = trim(str_replace(array("%w", "%d", "%h", "%m"),											   		array($iWeeks ? $iWeeks ."w" : "",													 	  $iDays ? $iDays ."d" : "", 													 	  $iHours ? $iHours ."h" : "", 													 	  $iMinutes ? $iMinutes ."m" : ""), UPTIME));					}					mysql_free_result($rQuery);				}				$rQuery = mysql_query("SELECT c.acct, c.name, c.level,											  c.class, c.race, c.mapId, c.zoneId, a.gm, a.lastip					  						  FROM `characters` AS c, `accounts` AS a						  					  WHERE `online` = 1 AND c.acct = a.acct", $rMySql);				if ($rQuery && mysql_num_rows($rQuery) > 0)				{					$aOutput[] = '<?xml version="1.0" encoding="UTF-8"?>';					$aOutput[] = "<stats>";					$aOutput[] = "\t<server>";					$aOutput[] = "\t\t<version>0.6</version>";					$aOutput[] = "\t\t<owner>0</owner>";					$aOutput[] = "\t\t<servername>0</servername>";					$aOutput[] = "\t\t<uptime>". $sUptime ."</uptime>";					$aOutput[] = "\t</server>";					$aOutput[] = "\t<serverload>";					$aOutput[] = "\t</serverload>";					$aOutput[] = "\t<players>";										// 0 = account					// 1 = name					// 2 = level					// 3 = class					// 4 = race					// 5 = mapId					// 6 = zoneId					// 7 = gm					// 8 = lastip					while ($aRow = mysql_fetch_row($rQuery)) {						$aOutput[] = "\t\t<player>";						$aOutput[] = "\t\t\t<name>". $aRow[1] ."</name>";						$aOutput[] = "\t\t\t<race>". $aRow[4] ."</race>";						$aOutput[] = "\t\t\t<class>". $aRow[3] ."</class>";						$aOutput[] = "\t\t\t<level>". $aRow[2] ."</level>";						$aOutput[] = "\t\t\t<map>". $aRow[5] ."</map>";						$aOutput[] = "\t\t\t<zone>". $aRow[6] ."</zone>";						$aOutput[] = "\t\t\t<ping>0</ping>";						$aOutput[] = "\t\t\t<plevel>". $aRow[7] ."</plevel>";						$aOutput[] = "\t\t\t<ip>". $aRow[8] ."</ip>";						$aOutput[] = "\t\t</player>";					}										mysql_free_result($rQuery);					mysql_close($rMySql);					$aOutput[] = "\t</players>";					$aOutput[] = "</stats>";					return utf8_encode(implode("\n", $aOutput));				}				mysql_close($rMySql);				exit(DEBUG ? "DEBUG: Unable to get list of players." : 0);			}			mysql_close($rMySql);			exit(DEBUG ? "DEBUG: Unable to select server database." : 0);		}		exit(DEBUG ? "DEBUG: Unable to connect to MySQL." : 0);	}}