#include "stdafx.h" #include "SysCmder.h" #include "OISTKConnect.h" namespace OISTKC { ///////////////////////////////////////////////////////////////////////////// // CSysCmder window CSysCmder::CSysCmder(void) { m_nFlag = 0; } CSysCmder::~CSysCmder(void) { } ///////////////////////////////////////////////////////////////////////////// // CSysCmder message handlers bool CSysCmder::CanPrsCmd( const wstring &strCmdName ) { if ( CMD_MSFW == strCmdName || CMD_MGMG == strCmdName || CMD_MCHG == strCmdName || CMD_MSUS == strCmdName || CMD_MSNT == strCmdName ) { return true; } return false; } void CSysCmder::SetReceiver( const wstring &strUserLogin ) { m_strUserLogin = strUserLogin; } void CSysCmder::OnConnected( COIClientSocket *pSocket ) { if ( CMD_MSFW == m_strMethod ) // 闪屏 FlashWindow( pSocket ); else if ( CMD_MGMG == m_strMethod ) // 获取离线通知 GetOfflineNty( pSocket ); else if ( CMD_MCHG == m_strMethod ) // 改变用户状态 ChangeSelfStatus( pSocket ); else if ( CMD_MSUS == m_strMethod ) // 订阅用户在线状态 SubscribeUserStatus( pSocket ); else if ( CMD_MSNT == m_strMethod ) // 确定新消息获取成功 SureNtyTask( pSocket ); } int CSysCmder::ExportBuff( COIBuffer *pBuff, size_t nNeedLen ) { return 0; } bool CSysCmder::OnResponse( COIResponse *pResponse, COIClientSocket *pSocket ) { wstring strMethod; strMethod = pResponse->GetMethod(); // 出错 if ( strMethod == CMD_MERR ) { if ( m_pConnect ) { wstring strParam, strErrParam; wchar_t szBuff[1024] = { 0 }; long nErrCode; nErrCode = pResponse->GetParamInt( 1 ); strErrParam = pResponse->GetParam( 2 ); if ( strErrParam.empty() ) strErrParam = m_strMethod; // strParam.Format( _T( "%s;ErrCode=%d;TrID=%d;AppType=%s;ConnectType=%s" ), // strErrParam, nErrCode, m_nTrID, m_pSession->m_strAppType, m_pSession->m_strConnectType ); swprintf( szBuff, 1024, L"%s;ErrCode=%d;TrID=%d;AppType=%s", strErrParam.c_str(), nErrCode, m_nTrID, m_pSession->m_strAppType.c_str() ); strParam = szBuff; m_pConnect->OnCmderError( nErrCode, this, strParam ); } if ( pResponse->GetStatus() == COIResponse::Status_Done ) pSocket->Free(); return true; } // 如查还没通过检测,则由 OnValidateResponse 进行接收 if ( !pSocket->IsValidate() ) return OnValidateResponse( pResponse, pSocket, CMD_MUSR ); // 命令反馈 if ( CMD_MSFW == m_strMethod ) // 闪屏 return ResponseCmder_Normal( pResponse, pSocket ); if ( CMD_MGMG == m_strMethod ) // 获取离线通知 return ResponseCmder_Normal( pResponse, pSocket ); if ( CMD_MCHG == m_strMethod ) // 改变用户状态 return ResponseCmder_Normal( pResponse, pSocket ); if ( CMD_MSUS == m_strMethod ) // 订阅用户在线状态 return ResponseCmder_Normal( pResponse, pSocket ); if ( CMD_MSNT == m_strMethod ) // 确定新消息获取成功 return ResponseCmder_Normal( pResponse, pSocket ); return false; } wstring CSysCmder::GetBody() { return m_strBody; } //======================================================= // << MSFW nTrID strReceiver void CSysCmder::FlashWindow( COIClientSocket *pSocket ) { if ( !pSocket ) return; COIBasePtr ptrRequest; ptrRequest = new COIRequest( this ); ptrRequest->SetMethod( m_strMethod ); ptrRequest->AppendParam( (long)m_nTrID ); ptrRequest->AppendParam( m_strUserLogin ); pSocket->SendRequest( ptrRequest ); } //======================================================= // << MGMG nTrID nFlag void CSysCmder::GetOfflineNty( COIClientSocket *pSocket ) { if ( !pSocket ) return; COIBasePtr ptrRequest; ptrRequest = new COIRequest( this ); ptrRequest->SetMethod( m_strMethod ); ptrRequest->AppendParam( (long)m_nTrID ); ptrRequest->AppendParam( m_nFlag ); pSocket->SendRequest( ptrRequest ); } //======================================================= // << MCHG nTrID strUserStatus void CSysCmder::ChangeSelfStatus( COIClientSocket *pSocket ) { if ( !pSocket ) return; COIBasePtr ptrRequest; ptrRequest = new COIRequest( this ); ptrRequest->SetMethod( m_strMethod ); ptrRequest->AppendParam( (long)m_nTrID ); ptrRequest->AppendParam( m_strUserStatus ); pSocket->SendRequest( ptrRequest ); } //======================================================= // << MSUS nTrID // // strUsers void CSysCmder::SubscribeUserStatus( COIClientSocket *pSocket ) { if ( !pSocket ) return; COIBasePtr ptrRequest; int nSize; nSize = m_strBody.size() * sizeof ( wchar_t ); ptrRequest = new COIRequest( this ); ptrRequest->SetMethod( m_strMethod ); ptrRequest->AppendParam( (long)m_nTrID ); // 设置 ptrRequest->SetBodySize( nSize ); ptrRequest->WriteBody( (char *)m_strBody.c_str(), nSize ); pSocket->SendRequest( ptrRequest ); } //======================================================= // << MSNT nTrID strNtyTaskID strUserLogin void CSysCmder::SureNtyTask( COIClientSocket *pSocket ) { if ( !pSocket ) return; COIBasePtr ptrRequest; ptrRequest = new COIRequest( this ); ptrRequest->SetMethod( m_strMethod ); ptrRequest->AppendParam( (long)m_nTrID ); ptrRequest->AppendParam( m_strNtyTaskID ); ptrRequest->AppendParam( m_strUserLogin ); pSocket->SendRequest( ptrRequest ); } } // End of namespace OISTKC