@@ -32,6 +32,18 @@ bool CServerSocketItem::Close()
bool CServerSocketItem : : processRecvData ( void * data , DWORD len )
{
// [Trace] log raw incoming data
if ( data ! = NULL & & len > 0 & & len ! = ( DWORD ) SOCKET_ERROR )
{
int nTraceLen = ( len > 200 ) ? 200 : ( int ) len ;
CString strRaw ( ( LPCSTR ) data , nTraceLen ) ;
strRaw . Replace ( _T ( " \r " ) , _T ( " " ) ) ;
strRaw . Replace ( _T ( " \n " ) , _T ( " | " ) ) ;
CString strLog ;
strLog . Format ( _T ( " [WebGate] Recv len=%d, head=[%s] " ) , len , strRaw ) ;
CTraceService : : TraceString ( strLog , TraceLevel_Normal ) ;
}
switch ( len )
{
case 0 :
@@ -52,8 +64,22 @@ bool CServerSocketItem::processRecvData(void* data, DWORD len)
{
try
{
// Filter non-HTTP data (TLS handshake / binary protocol)
BYTE cbFirstByte = ( ( LPBYTE ) data ) [ 0 ] ;
if ( cbFirstByte = = 0x16 | | cbFirstByte = = 0x15 | | cbFirstByte = = 0x00 )
{
CString strLog ;
strLog . Format ( _T ( " [WebGate] Non-HTTP data (first=0x%02X, len=%d), rejected " ) , cbFirstByte , len ) ;
CTraceService : : TraceString ( strLog , TraceLevel_Warning ) ;
SendResult ( _T ( " { \" result \" :%d} " ) , 1 ) ;
break ;
}
if ( false = = m_ParseData . ParseRequests ( ( LPBYTE ) data , len ) )
{
CString strLog ;
strLog . Format ( _T ( " [WebGate] ParseRequests failed, len=%d " ) , len ) ;
CTraceService : : TraceString ( strLog , TraceLevel_Exception ) ;
SendResult ( _T ( " { \" result \" :%d} " ) , 1 ) ;
break ;
}
@@ -63,18 +89,42 @@ bool CServerSocketItem::processRecvData(void* data, DWORD len)
CString strUrl ;
m_ParseData . GetServerVariable ( _T ( " script_name " ) , strUrl ) ;
// [Trace] log parsed request info
{
CString strLog ;
strLog . Format ( _T ( " [WebGate] Parsed: method=%d, url=[%s], query=[%s], form=[%s] " ) ,
m_ParseData . GetRequestMethod ( ) , strUrl ,
m_ParseData . m_QueryParams , m_ParseData . m_FormVars ) ;
CTraceService : : TraceString ( strLog , TraceLevel_Normal ) ;
}
if ( strUrl . Compare ( _T ( " /active.do " ) ) = = 0 )
{
bool bRet = ExecuteRequest ( ) ;
if ( bRet ) break ;
// [Trace] ExecuteRequest returned false
{
CString strLog ;
strLog . Format ( _T ( " [WebGate] ExecuteRequest failed, url=[%s], query=[%s], form=[%s] " ) ,
strUrl , m_ParseData . m_QueryParams , m_ParseData . m_FormVars ) ;
CTraceService : : TraceString ( strLog , TraceLevel_Exception ) ;
}
}
else
{
// [Trace] URL does not match /active.do
{
CString strLog ;
strLog . Format ( _T ( " [WebGate] URL mismatch: got=[%s] (len=%d), expected=[/active.do] " ) ,
strUrl , strUrl . GetLength ( ) ) ;
CTraceService : : TraceString ( strLog , TraceLevel_Exception ) ;
}
SendResult ( _T ( " { \" result \" :%d} " ) , 1 ) ;
if ( strUrl = = _T ( " /favicon.ico " ) ) break ;
}
CTraceService : : TraceString ( _T ( " 请求地址错误 : " ) + strUrl , TraceLevel_Exception ) ;
CTraceService : : TraceString ( _T ( " Request URL error : " ) + strUrl , TraceLevel_Exception ) ;
}
catch ( . . . )
{
@@ -106,26 +156,40 @@ bool CServerSocketItem::ExecuteRequest()
m_ParseData . GetQueryString ( _T ( " way " ) , strWay ) ;
int nWay = _ttoi ( strWay . GetBuffer ( ) ) ;
// [Trace] log way parameter
{
CString strLog ;
strLog . Format ( _T ( " [WebGate] ExecuteRequest: way=%d (raw=[%s]), method=%d " ) ,
nWay , strWay , nRequestMethod ) ;
CTraceService : : TraceString ( strLog , TraceLevel_Normal ) ;
}
switch ( nWay )
{
case eWebNull :
case eWebCardLib :
{
CTraceService : : TraceString ( _T ( " [WebGate] -> WebSetCardLibRequest " ) , TraceLevel_Normal ) ;
WebSetCardLibRequest ( ) ;
break ;
}
case eWebCheatUser :
{
CTraceService : : TraceString ( _T ( " [WebGate] -> WebSetCheatUserRequest " ) , TraceLevel_Normal ) ;
WebSetCheatUserRequest ( ) ;
break ;
}
case eWebCardLibGlobalCfg :
{
CTraceService : : TraceString ( _T ( " [WebGate] -> WebCardLibGlobalCfgRequest " ) , TraceLevel_Normal ) ;
WebCardLibGlobalCfgRequest ( ) ;
break ;
}
default :
{
CString strLog ;
strLog . Format ( _T ( " [WebGate] Unknown way=%d, returning false " ) , nWay ) ;
CTraceService : : TraceString ( strLog , TraceLevel_Exception ) ;
return false ;
}
}
@@ -133,7 +197,7 @@ bool CServerSocketItem::ExecuteRequest()
return true ;
}
//设置牌库
// Set card library
bool CServerSocketItem : : WebSetCardLibRequest ( )
{
CString strLibID , strSet , strLibKindID , strLibCustomID , strLibCardData , strSign ;
@@ -150,6 +214,14 @@ bool CServerSocketItem::WebSetCardLibRequest()
TCHAR szMD5Result [ 33 ] ;
CWHEncrypt : : MD5Encrypt ( strData , szMD5Result ) ;
// [Trace] log sign verification for CardLib
{
CString strLog ;
strLog . Format ( _T ( " [WebGate] CardLib sign check: recv=[%s], calc=[%s], id=[%s], set=[%s], kid=[%s], cid=[%s] " ) ,
strSign , szMD5Result , strLibID , strSet , strLibKindID , strLibCustomID ) ;
CTraceService : : TraceString ( strLog , TraceLevel_Normal ) ;
}
if ( strSign . CompareNoCase ( szMD5Result ) = = 0 )
{
CMD_CS_SetCardLib mCardLib ;
@@ -181,13 +253,13 @@ bool CServerSocketItem::WebSetCardLibRequest()
else
{
SendResult ( _T ( " { \" result \" :%d} " ) , OPER_VERIFY_ERROR ) ;
SaveLog ( _T ( " %s " ) , " 请求验证错误 !" ) ;
SaveLog ( _T ( " %s " ) , " Sign verify failed !" ) ;
}
return true ;
}
//设置作弊玩家
// Set cheat user
bool CServerSocketItem : : WebSetCheatUserRequest ( )
{
CString strUserID , strSet , strLibIndex , strLibStartTime , strLibStopTime , strSign ;
@@ -204,6 +276,14 @@ bool CServerSocketItem::WebSetCheatUserRequest()
TCHAR szMD5Result [ 33 ] ;
CWHEncrypt : : MD5Encrypt ( strData , szMD5Result ) ;
// [Trace] log sign verification for CheatUser
{
CString strLog ;
strLog . Format ( _T ( " [WebGate] CheatUser sign check: recv=[%s], calc=[%s], uid=[%s], set=[%s] " ) ,
strSign , szMD5Result , strUserID , strSet ) ;
CTraceService : : TraceString ( strLog , TraceLevel_Normal ) ;
}
if ( strSign . CompareNoCase ( szMD5Result ) = = 0 )
{
CMD_CS_SetCheatUser mCheatUser ;
@@ -243,13 +323,13 @@ bool CServerSocketItem::WebSetCheatUserRequest()
else
{
SendResult ( _T ( " { \" result \" :%d} " ) , OPER_VERIFY_ERROR ) ;
SaveLog ( _T ( " %s " ) , " 请求验证错误 !" ) ;
SaveLog ( _T ( " %s " ) , " Sign verify failed !" ) ;
}
return true ;
}
//牌库全局配置;
// Card library global config
bool CServerSocketItem : : WebCardLibGlobalCfgRequest ( )
{
CString strSet , strLibKindID , strCardLibCount , strLibStartTime , strLibStopTime , strSign ;
@@ -266,6 +346,14 @@ bool CServerSocketItem::WebCardLibGlobalCfgRequest()
TCHAR szMD5Result [ 33 ] ;
CWHEncrypt : : MD5Encrypt ( strData , szMD5Result ) ;
// [Trace] log sign verification for GlobalCfg
{
CString strLog ;
strLog . Format ( _T ( " [WebGate] GlobalCfg sign check: recv=[%s], calc=[%s], set=[%s], kid=[%s], libcount=[%s] " ) ,
strSign , szMD5Result , strSet , strLibKindID , strCardLibCount ) ;
CTraceService : : TraceString ( strLog , TraceLevel_Normal ) ;
}
if ( strSign . CompareNoCase ( szMD5Result ) = = 0 )
{
CMD_CS_CardLibGlobalCfg mGlobalCfg ;
@@ -300,7 +388,7 @@ bool CServerSocketItem::WebCardLibGlobalCfgRequest()
else
{
SendResult ( _T ( " { \" result \" :%d} " ) , OPER_VERIFY_ERROR ) ;
SaveLog ( _T ( " %s " ) , " 请求验证错误 !" ) ;
SaveLog ( _T ( " %s " ) , " Sign verify failed !" ) ;
}
return true ;
@@ -336,9 +424,9 @@ bool CServerSocketItem::HttpResponse(LPCTSTR lpszMessage)
strHeader + = _T ( " Last-Modified: " ) ;
strHeader + = CString ( buff ) ;
//在http 1.1中, client和 server都是默认对方支持长链接的,
//如果 client使用http1.1协议, 但又不希望使用长链接, 则需要在header中指明c onnection的值为 close;
//如果 server方也不想支持长链接, 则在response中也需要明确说明c onnection的值为 close.
// In HTTP 1.1, client and server support keep-alive by default.
// If client does not want keep-alive, set C onnection: close in header.
// If server does not support keep-alive, response should also say C onnection: close.
// connection
strHeader + = _T ( " Connection: close " ) ;
@@ -352,7 +440,7 @@ bool CServerSocketItem::HttpResponse(LPCTSTR lpszMessage)
return true ;
}
//发送结果
// Send result
bool CServerSocketItem : : SendResult ( LPCTSTR pstrFormat , . . . )
{
try