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

function is_badword($string)
{
	$badwords = array("\\",'&',' ',"'",'"','/','*',',','<','>',"\r","\t","\n","#");
	foreach($badwords as $value)
	{
	    if(strpos($string,$value) !== FALSE)
		{ 
	        return TRUE; 
	    }
	}
	return FALSE;
}
function Faction($Faction)
{
   if($Faction == '0')
   {
     if($Faction == '0')
      {
       $Faction = "周";
      }
  }else{
     $Faction = "商";
  }
   return $Faction;
}
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 game_log($id)
{
	$gamels = cache_read("gamelist_".$id.".php");

	return $gamels['datalog'];
}

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;
}

function is_logonline($id,$iduser)
{
  $sqldb = real_con($id);
  $sqldb->select_db(game_log($id));

  $rl = $sqldb->get_one("SELECT LogTime FROM t_log_user_history WHERE type='15' AND `longParam1`='1' AND userID='$iduser' ORDER BY OperateID DESC limit 0,1");
  $truetime = $rl['LogTime'];
  
  $ro = $sqldb->get_one("SELECT LogTime FROM t_log_user_history WHERE type='15' AND `longParam1`='2' AND userID='$iduser' ORDER BY OperateID DESC limit 0,1");
  $outtime = $ro['LogTime'];
  
  $sumdo = strtotime($truetime);
  $sumdt = strtotime($outtime);
  if ($sumdo > $sumdt)
  {
    return True;
  }else{
    return FALSE;
  }
}

function getmetiers($str,$str2)
{
   if($str == '0')
   {
     if($str2 == '1')
      {
       $metier = "狂战士";
      }
     elseif($str2 == '2')
      {
       $metier = "凤舞者";
	    }
	   elseif($str2 == '3')
	    {
       $metier = "邪灵术士";
	    }
	   elseif($str2 == '4')
	   {
       $metier = "神传道士";
	   }
   }
   elseif($str == '1')
   {
    if($str2 == '1')
     {
      $metier = "金甲武士";
     }
     elseif($str2 == '2')
     {
      $metier = "御兽玲珑";
	   }
	   elseif($str2 == '3')
	   {
      $metier = "幻世妖道";
	   }
	   elseif($str2 == '4')
	   {
      $metier = "素心真人";
	   }
    }
   elseif($str == '2')
   {
    if($str2 == '1')
     {
      $metier = "武斗神";
     }
     elseif($str2 == '2')
     {
      $metier = "虹云仙子";
	   }
	   elseif($str2 == '3')
	   {
      $metier = "逆天法魔";
	   }
	   elseif($str2 == '4')
	   {
      $metier = "圣灵天尊";
	   }
    }
   elseif($str == '3')
   {
    if($str2 == '1')
     {
      $metier = "九五至尊";
     }
     elseif($str2 == '2')
     {
      $metier = "瑶池圣女";
	   }
	   elseif($str2 == '3')
	   {
      $metier = "通天魔尊";
	   }
	   elseif($str2 == '4')
	   {
      $metier = "元始神尊";
	   }

  }else{
     $metier = "读取错误";
  }
   return $metier;
}

?>

