<?php
|
namespace CommonOperate;
|
#´´½¨ÈÕÆÚ£º2012-4-18 ÏÂÎç3:19:35
|
#×÷Õߣºzhouliang
|
#Ö÷Òª´æ·ÅÏîĿͨÓõĺ¯ÊýºÍÀà,ºÍÏîÄ¿ÆõºÏ±È½Ï½ôÃÜ
|
|
include_once 'Common/MongoCommon.php';
|
include_once 'Common/BufferOperate.php';
|
include_once "/Common/CommFunc.php";
|
|
#ÍøÓÎͨÓðüÍ·µÄ³¤¶ÈΪ9
|
const nWYCommonHeadLen=9;
|
|
#·Ö±ð´«È룬ÅäÖÃÎļþÃû£¬¶ÔÓ¦DBµÄsectionÃû»¹ÓÐÒ»¸ö$mongoOptÓÃÀ´´æ·Å·µ»ØÊý¾Ý¿â¶ÔÏó
|
function GetMongoDB( $strFileName, $strSection, &$mongoOpt )
|
{
|
$dbOpt=new \MongoCommon\MongoDBOpt( $strFileName , $strSection );
|
|
if( !$dbOpt->Init() )
|
{
|
return false;
|
}
|
|
$mongoOpt=$dbOpt;
|
|
return true;
|
}
|
|
#»ñµÃ·þÎñÆ÷µÄIDºÅÊý×é
|
function GetServerIDArray( &$strRet, $strConfigName='../../InterfaceConfig.php', $strSection='ServerInfo', $strIdent='ServerID', $strErrorPrintValue='' )
|
{
|
if( !\CommFunc\GetKeyFromConfig($strConfigName, $strSection, $strIdent, $strRet, $strErrorPrintValue) )
|
{
|
return false;
|
}
|
|
$strRet=explode( ',', $strRet );
|
|
\Logging\LogInfo( '»ñµÃµÄ·þÎñÆ÷Êý×éÊÇ:'.var_export( $strRet, true ) );
|
return true;
|
}
|
|
#»ñµÃĬÈϵÄ$ServerID,Èç¹ûÖ¸¶¨ÁË$ServerID£¬ÄÇôÔò¼ì²â$ServerIDµÄSectionÊÇ·ñ´æÔÚ£¬Èç¹û´æÔÚ£¬·µ»Ø$ServerID£¬Èç¹û²»´æÔÚ£¬Ôò·µ»ØServerName
|
function GetDefaultServerID( &$strServerID, $strConfigName='../../InterfaceConfig.php', $strSection='ServerInfo', $strIdent='ServerID', $strErrorPrintValue='', $serverID='' )
|
{
|
if( !\CommonOperate\GetServerIDArray( $strSrvIDArray, $strConfigName, $strSection, $strIdent, $strErrorPrintValue ) )
|
{
|
return false;
|
}
|
|
if( $serverID!='' )
|
{
|
if( \CommFunc\IsSectionExist($serverID, $strConfigName) )
|
{
|
$strServerID=$serverID;
|
\Logging\LogInfo("ServerID=".$strServerID.' Section´æÔÚ');
|
return true;
|
}
|
}
|
|
|
$strServerID='ServerName';
|
\Logging\LogInfo("ĬÈϵÄServerID=".$strServerID);
|
return true;
|
}
|
|
#»ñµÃÅäÖõÄʵ¼ÊµÄµÚÒ»¸öServerID
|
function GetFirstServerID( &$strServerID, $strConfigName='../../InterfaceConfig.php', $strSection='ServerInfo', $strIdent='ServerID', $strErrorPrintValue='' )
|
{
|
if( !\CommonOperate\GetServerIDArray( $strSrvIDArray, $strConfigName, $strSection, $strIdent, $strErrorPrintValue ) )
|
{
|
return false;
|
}
|
|
$strServerID=array_shift( $strSrvIDArray );
|
\Logging\LogInfo("ʵ¼ÊÅäÖõĵÚÒ»¸öServerID=".$strServerID);
|
return true;
|
}
|
|
#¼ì²é·þÎñÆ÷IDÊÇ·ñÔÚÁбíÖÐ
|
function IsServerIDInList( $strSrvID, $strConfigName= '..\\..\\InterfaceConfig.php' )
|
{
|
#»ñµÃ·þÎñÆ÷ID
|
$strSrvIDArray='';
|
if( !\CommonOperate\GetServerIDArray( $strSrvIDArray, $strConfigName ) )
|
{
|
return false;
|
}
|
$server_num = intval(substr($strSrvID, 1));
|
|
$bIn = false;
|
|
foreach ($strSrvIDArray as $value) {
|
if (strpos($value, '-') === false){
|
if ($strSrvID == $value){
|
$bIn = true;
|
break;}
|
}
|
else{
|
$strRet = explode( '-', $value );
|
$minNum = intval(substr($strRet[0], 1));
|
$maxNum = intval(substr($strRet[1], 1));
|
if ($server_num >= $minNum and $server_num<=$maxNum)
|
{
|
$bIn = true;
|
break;
|
}
|
}
|
|
}
|
|
if( !$bIn )
|
{
|
\Logging\LogInfo( "·þÎñÆ÷:".$strSrvID."²»ÔÚÅäÖÃÖÐ" );
|
}
|
|
return $bIn;
|
}
|
|
#ÅжÏÊÇ·ñ¶©µ¥ºÅ³¤¶ÈºÏ¸ñ£¬Èç¹û²»ºÏ¸ñ£¬ÄÇô³ÌÐò´òӡͬʱÍ˳ö
|
function CheckOrderIDEffective( $strOrderID, $strOnErrorPrintValue='', $bExitOnError=true )
|
{
|
#¶©µ¥ºÅ×î´ó³¤¶ÈΪ64
|
if( strlen($strOrderID)>0 && strlen($strOrderID)<=64 )
|
{
|
return true;
|
}
|
|
\Logging\LogError( '¶©µ¥ºÅ¼ì²â³¤¶È²»ºÏ¸ñ£¬¶©µ¥£º'.$strOrderID );
|
|
echo $strOnErrorPrintValue;
|
|
if( $bExitOnError )
|
{
|
exit(0);
|
}
|
|
return false;
|
}
|
|
#»ñµÃ·â°üµÄÀàÐÍ
|
function GetPackType( $strBuffer )
|
{
|
$strByte=\BufferOperate\ReadBYTE($strBuffer, $nPos);
|
|
return $strByte;
|
}
|
|
#×é°ü,´«Èë°üµÄʵÌåÄÚÈÝ
|
function PackData( $strBuffer, $nType=0, $nDstType=0, $nSrcType=0 )
|
{
|
$bufferRet='';
|
|
$bufferRet=$bufferRet.pack( 'v',0xccff);
|
|
#´ò°ü·þÎñÆ÷×é·â°üÍ·
|
#SessionID(DWORD)+PoolIndex(WORD)+Type(BYTE)+DestServerType+SrcServerType
|
$bufferServerCommonHead=pack( 'V1v1C3', 0, 0, $nType, $nDstType, $nSrcType );
|
|
#Ôö¼Ó³¤¶È
|
|
$nBodyLen=strlen( $bufferServerCommonHead )+strlen($strBuffer);
|
|
$bufferRet=$bufferRet.pack( 'V1', $nBodyLen );
|
$bufferRet=$bufferRet.$bufferServerCommonHead;
|
$bufferRet=$bufferRet.$strBuffer;
|
return $bufferRet;
|
}
|
|
#²ð°ü£¬³É¹¦·µ»Øtrue£¬·ñÔòfalse(×¢Òâ²ð°üµÄ¾ßÌ巽ʽÖаüº¬ Ö±½ÓÌø¹ýWY·þÎñÆ÷¼¯ÈºµÄÄÚ²¿°üÍ·£¬ÒòΪÔÝʱ²»ÐèÒªÕâ¸ö×Ö¶Î)
|
function UnPackData( &$strBuffer, &$customBodyBuffer )
|
{
|
\Logging\LogDebug( '°üµÄ³¤¶ÈÊÇ:'.strlen($strBuffer) );
|
\Logging\LogDebug( "ÊÕµ½µÄ°üÊÇ:" );
|
\Logging\LogDebug( \CommFunc\BinToStr( $strBuffer ) );
|
$nPos=0;
|
while( true )
|
{
|
#ÖÁÉÙÒªÓÐccff(2b)µÄ³¤¶È£¬·ñÔòÁ¬Í·¶¼ÎÞ·¨½âÎö,ÒÔ¼°·â°ü³¤¶È(4b)µÄÄÚÈÝ
|
if( strlen( $strBuffer )<6 )
|
{
|
\Logging\LogDebug( '°ü¹ý¶Ì£¬¼ÌÐøµÈ´ý·â°ü£¡' );
|
return false;
|
}
|
|
$nSign=\BufferOperate\ReadWORD( $strBuffer, $nPos );
|
\Logging\LogDebug( '»ñÈ¡µÄsignÊÇ:'.$nSign );
|
|
if( $nSign!=0xccff )
|
{
|
#¶ªÆúÍ·
|
$strBuffer=substr( $strBuffer, 1, strlen($strBuffer)-1 );
|
$nPos=0;
|
\Logging\LogDebug( 'ͷУÑé´íÎ󣬶ªÆú1BÊý¾Ý' );
|
continue;
|
}
|
|
#°Ñ·â°üÍùÇ°ÒÆ
|
$nLen=\BufferOperate\ReadDWORD( $strBuffer, $nPos );
|
\Logging\LogDebug( 'ͷУÑé³É¹¦,»ñµÃÕû¸ö·â°üµÄ³¤¶ÈΪ:'.$nLen );
|
if( $nLen > (strlen($strBuffer) - $nPos) )
|
{
|
return false;
|
}
|
else
|
{
|
#½â³öÍøÓηþÎñÆ÷ÄÚ²¿Í¨Ñ¶°üÍ·£¬¾ßÌå²Î¿´Ñ¹°üµÄ×ö·¨
|
$customBodyBuffer=substr( $strBuffer, $nPos, $nLen );
|
$nPos+=$nLen;
|
|
#ÔÝʱ²»¹ØÐÄÍ·£¬ËùÒÔÖ±½ÓÌø¹ýÍ·µÄ×Ö½Ú
|
$customBodyBuffer=substr( $customBodyBuffer, nWYCommonHeadLen, strlen($customBodyBuffer)-nWYCommonHeadLen );
|
|
\Logging\LogDebug( '°üÌ峤¶ÈΪ:'.strlen($customBodyBuffer) );
|
|
#ÅжÏÊDz»ÊÇGM¹¤¾ßµÄ°üÀàÐÍ114
|
if( \CommonOperate\GetPackType($customBodyBuffer)==114 )
|
{
|
return true;
|
}else{
|
$strBuffer=substr( $strBuffer , $nPos, strlen($strBuffer)-$nPos );
|
$nPos = 0;
|
\Logging\LogInfo('·Ç114ÀàÐÍ...'.\CommFunc\BinToStr( $strBuffer ));
|
}
|
}
|
}
|
|
}
|
|
#¶ÔÄÚÓëpython½»»¥µÄµÇ½»òÕß³äÖµ½Ó¿Ú¿ÉÓô˺¯Êý»ñµÃ·þÎñÆ÷ID
|
function GetToInnerPrjServerID( $strDirName )
|
{
|
//Èç¹ûÅäÖõÄÊÇĬÈϵÄÃû×Ö£¬ÄÇôȡÅäÖõĵÚÒ»¸ö·þÎñÆ÷Ãû£¬Èç¹ûÅäÖõIJ»ÊÇĬÈϵÄÃû×Ö£¬ÄÇôȡµ±Ç°Ä¿Â¼Îª·þÎñÆ÷ID
|
if( $strDirName=="ServerName" )
|
{
|
if( !\CommonOperate\GetServerIDArray( $strSrvIDArray, dirname(__FILE__).'\\..\\InterfaceConfig.php' ) )
|
{
|
exit();
|
}
|
#if( count($strSrvIDArray)!=1 )
|
#{
|
# \Logging\LogWarn( '·¢ÏÖÔÚÅäÖÃÖеķþÎñÆ÷ÁбíÓжà¸ö·þÎñÆ÷£¬µ«ÊǶÔÄÚÓëpython½»»¥µÄphp½Å±¾Îļþ¼ÐÃûûÓÐÐ޸ijÉÖ¸¶¨µÄ·þÎñÆ÷£¬ÊÇ·ñÍü¼ÇÐ޸ģ¿' );
|
#}
|
|
return array_shift( $strSrvIDArray );
|
}
|
|
else
|
{
|
return $strDirName;
|
}
|
|
}
|
|
|
|
#»ñÈ¡ÓÎÏ·Õ˺Å
|
function GetGameQid($opqid, $server_id, $OperatorID)
|
{
|
//#ĬÈÏ @ ƽ̨Õʺš¢Æ½Ì¨±êÖ¾ºÍ·þÎñÆ÷ID×éºÏ³ÉÓÎÏ·ÕʺŵÄÁ´½Ó±êÖ¾·ûºÅ£¬ÓÃÓںϿç·þºó²»Í¬ÇøµÄÕʺŵǼ
|
|
$strConfigName=dirname(__FILE__).'\\..\\InterfaceConfig.php';
|
|
\CommFunc\GetKeyFromConfig($strConfigName, 'ServerInfo', 'ServerGear', $ServerGear);
|
|
return strtolower($opqid.$ServerGear.$OperatorID.$ServerGear.$server_id);
|
}
|
|
#»ñȡƽ̨ÔʼÕ˺Å
|
function GetOperatorQid($userId)
|
{
|
//#ĬÈÏ @ ƽ̨Õʺš¢Æ½Ì¨±êÖ¾ºÍ·þÎñÆ÷ID×éºÏ³ÉÓÎÏ·ÕʺŵÄÁ´½Ó±êÖ¾·ûºÅ£¬ÓÃÓںϿç·þºó²»Í¬ÇøµÄÕʺŵǼ
|
|
$strConfigName=dirname(__FILE__).'\\..\\InterfaceConfig.php';
|
|
\CommFunc\GetKeyFromConfig($strConfigName, 'ServerInfo', 'ServerGear', $ServerGear);
|
|
$qidarr = explode($ServerGear, $userId);
|
return implode(array_slice($qidarr, 0, count($qidarr)-2), $ServerGear);
|
}
|
|
?>
|