int32_t CServerHelper::SendSSReq(int32_t nMsgID, RoomID nRoomID, UserID nUserID, IMsgBody *pMsgBody, EntityType nEntityType, ServerID nServerID) { CServerConfig *pServerConfig = (CServerConfig *)g_Frame.GetConfig(CONFIG_SERVER); uint32_t nOffset = 0; uint8_t arrBuf[enmMaxMessageSize]; MsgHeadSS stMsgHeadSS; stMsgHeadSS.m_nHeadSize = stMsgHeadSS.GetSize(); stMsgHeadSS.m_nMsgID = nMsgID; stMsgHeadSS.m_nRoomID = nRoomID; stMsgHeadSS.m_nUserID = nUserID; stMsgHeadSS.m_nTransType = enmTransType_P2P; stMsgHeadSS.m_nSrcType = pServerConfig->GetServerType(); stMsgHeadSS.m_nSrcID = pServerConfig->GetServerID(); stMsgHeadSS.m_nDstType = nEntityType; stMsgHeadSS.m_nDstID = nServerID; IIOSession *pIoSession = GetIoSession(nEntityType, nServerID); if(pIoSession == NULL) { WRITE_WARN_LOG(SERVER_NAME, "it's not found iosession!{EntityType=%d, ServerID=%d}\n", nEntityType, nServerID); return 0; } int32_t nRet = stMsgHeadSS.Encode(arrBuf, sizeof(arrBuf), nOffset); if(nRet < 0) { WRITE_WARN_LOG(SERVER_NAME, "msg head cs encode failed!\n"); return 0; } nRet = pMsgBody->Encode(arrBuf, sizeof(arrBuf) - nOffset, nOffset); if(nRet < 0) { WRITE_WARN_LOG(SERVER_NAME, "msg body encode failed!\n"); return 0; } stMsgHeadSS.m_nTotalSize = (uint16_t)nOffset; nOffset = 1; nRet = CCodeEngine::Encode(arrBuf, sizeof(arrBuf), nOffset, stMsgHeadSS.m_nTotalSize); if(nRet < 0) { WRITE_WARN_LOG(SERVER_NAME, "encode total size failed!\n"); return 0; } g_Frame.Dump(&stMsgHeadSS, pMsgBody, "send ss req "); return pIoSession->Write(arrBuf, stMsgHeadSS.m_nTotalSize); }
void IIOSession::onShutdownSession( void * context, int32_t way ) { IIOSession * session = static_cast<IIOSession *>( context ); session->onShutdown( way ); delete session; }
int32_t CServerHelper::SendSSNoti(int32_t nMsgID, IMsgBody *pMsgBody, RoomID nRoomID, UserID nUserID, TransType nTransType, EntityType nEntityType, ServerID nServerID) { CServerConfig *pServerConfig = (CServerConfig *)g_Frame.GetConfig(CONFIG_SERVER); MsgHeadSS stMsgHeadSS; stMsgHeadSS.m_nTotalSize = 0; stMsgHeadSS.m_nMsgID = nMsgID; stMsgHeadSS.m_nRoomID = nRoomID; stMsgHeadSS.m_nUserID = nUserID; stMsgHeadSS.m_nTransType = nTransType; stMsgHeadSS.m_nSrcType = pServerConfig->GetServerType(); stMsgHeadSS.m_nSrcID = pServerConfig->GetServerID(); stMsgHeadSS.m_nDstType = nEntityType; stMsgHeadSS.m_nDstID = nServerID; uint32_t nOffset = 0; uint8_t arrBuf[enmMaxMessageSize]; int32_t nRet = stMsgHeadSS.Encode(arrBuf, sizeof(arrBuf), nOffset); if(nRet < 0) { return 0; } nRet = pMsgBody->Encode(arrBuf, sizeof(arrBuf) - nOffset, nOffset); if(nRet < 0) { return 0; } stMsgHeadSS.m_nTotalSize = nOffset; nOffset = 1; nRet = CCodeEngine::Encode(arrBuf, sizeof(arrBuf), nOffset, stMsgHeadSS.m_nTotalSize); if(nRet < 0) { return 0; } switch(nTransType) { case enmTransType_P2P: { IIOSession *pIoSession = GetIoSession(nEntityType, nServerID); if(pIoSession == NULL) { return 0; } pIoSession->Write(arrBuf, stMsgHeadSS.m_nTotalSize); } break; case enmTransType_Room: break; case enmTransType_Server: for(IDMap::iterator it = m_stEntityMap[nEntityType].begin(); it != m_stEntityMap[nEntityType].end(); ++it) { if((it->first == nServerID) || (nServerID == enmInvalidServerID)) { it->second->Write(arrBuf, stMsgHeadSS.m_nTotalSize); } } break; case enmTransType_Random: { IIOSession *pIoSession = GetIoSession(nEntityType, nServerID); if(pIoSession == NULL) { return 0; } pIoSession->Write(arrBuf, stMsgHeadSS.m_nTotalSize); } break; default: break; } g_Frame.Dump(&stMsgHeadSS, pMsgBody, "send ss noti "); return 0; }
int32_t CHttpProcess::ProcessHttpLoginResp(IMsgHead *pMsgHead, IMsgBody *pMsgBody) { WebHeader *pWebHeader = dynamic_cast<WebHeader *>(pMsgHead); if(pWebHeader == NULL) { return 0; } CHttpLoginResp *pHttpLoginResp = dynamic_cast<CHttpLoginResp *>(pMsgBody); if(pHttpLoginResp == NULL) { return 0; } CSessionData *pSessionData = g_DataCenter.GetSessionMgt()->GetSessionData(pWebHeader->m_nSessionIndex); if(pSessionData == NULL) { return 0; } IIOSession *pIoSession = g_ConnMgt.GetConnection(pSessionData->GetSessionID()); if(pIoSession == NULL) { return 0; } uint8_t arrMsg[MAX_SERVER_MSG_LEN]; PkgHead stPkgHead; stPkgHead.m_nTag = 0; stPkgHead.m_nHeadSize = stPkgHead.GetSize(); stPkgHead.m_nTotalSize = 0; stPkgHead.m_nMsgID = MSGID_CLIENTAUTH_RESP; stPkgHead.m_nFlag = 0; stPkgHead.m_nVersion = 0; stPkgHead.m_nOptionLen = 0; uint32_t nOffset = 0; int32_t nRet = stPkgHead.Encode(arrMsg, sizeof(arrMsg), nOffset); if(nRet > 0) { return 0; } CAuthResp stAuthResp; stAuthResp.m_nResult = pHttpLoginResp->m_nResult; if(pHttpLoginResp->m_nResult == 200) { stAuthResp.m_nResult = 0; stAuthResp.m_nRoleID = pWebHeader->m_nRoleID; stAuthResp.m_nTokenLen = CServerHelper::MakeToken(stAuthResp.m_arrToken, pWebHeader->m_nRoleID); } else { pHttpLoginResp->m_nResult = 1; } int16_t nHeadSize = nOffset; nOffset = 0; uint8_t arrBody[MAX_SERVER_MSG_LEN]; nRet = stAuthResp.Encode(arrBody, sizeof(arrBody), nOffset); if(nRet > 0) { return 0; } int32_t nRealLen = CXTEA::Encrypt((char *)arrBody, nOffset, (char *)&arrMsg[nHeadSize], sizeof(arrMsg) - nHeadSize, "*****@*****.**"); if(nRealLen <= 0) { return 0; } uint16_t nTotalSize = nHeadSize + nRealLen; nOffset = 1; nRet = CCodeEngine::Encode(arrMsg, nTotalSize, nOffset, nTotalSize); if(nRet < 0) { return 0; } pIoSession->Write(arrMsg, nTotalSize); return 0; }