<?php 
defined('IN_HS') or exit('Access Denied');

require_once HS_ROOT.'/member/include/member.class.php';

function game_acc($id)
{
	$gamels = cache_read("gamelist_".$id.".php");

	return $gamels['dataacc'];
}

function game_fso($id)
{
	$gamels = cache_read("gamelist_".$id.".php");

	return $gamels['datafso'];
}

function check_con($id)
{
	$gamels = cache_read("gamelist_".$id.".php");
	@extract($gamels,EXTR_OVERWRITE);

  $msyqlco = @mysql_connect($serverip.':'.$port, $loginname, $loginpass,$dataacc);
	$return = (!$msyqlco) ? 0 : 1;
	return $return;
}

function real_con($id)
{
	$gamels = cache_read("gamelist_".$id.".php");
	@extract($gamels,EXTR_OVERWRITE);

	$thisdb = new db_mysql;
	$thisdb->connect($serverip.':'.$port, $loginname, $loginpass, $dataacc);
	$thisdb->query("SET NAMES DEFAULT");
	return $thisdb;
}

function is_badgamename($name)
{

		global $MOD;
		if(!$MOD['banname']) return FALSE;
		$bannames = explode(',', $MOD['banname']);
		foreach($bannames as $banname)
		{
			if(strpos($name, $banname)!==FALSE) return TRUE;
		}
		return FALSE;
}
function is_online($id)
{
  global $_username,$PHP_TIME;
  $sqldb = real_con($id);
  $sqldb->select_db(game_acc($id));
  
  $accinfo = $sqldb->get_one("SELECT idx,latest_login_date FROM user WHERE username='$_username' ORDER BY idx DESC limit 0,1");
  $aidx = $accinfo['idx'];
  $truetime = $accinfo['latest_login_date'];
  
	$leavel = $sqldb->get_one("SELECT leave_time FROM consume WHERE AccountID='$aidx' ORDER BY idx DESC limit 0,1");
	$outtime = $leavel['leave_time'];
	
	$sumdo = strtotime($truetime);
	$sumdt = strtotime($outtime);
	if ($sumdo > $sumdt)
	{
	  return TRUE;
    exit;
  }

  $sumto = $PHP_TIME - $sumdo;
  $sumtt = $PHP_TIME - $sumdt;
	
	if ($sumto < 180 || $sumtt < 180)
	{
	  return TRUE;
    exit;
  }
  return FALSE;
}
?>