int KSimulateRelay::DoSetProtocolVersion(int nLowerVersion, int nUpperVersion) { int nResult = false; int nRetCode = false; IKG_Buffer* piSendBuffer = false; size_t uSendBufferSize = 0; R2G_SET_GAME_WORLD_VERSION* pRespond = NULL; KG_PROCESS_ERROR(m_piSocket); uSendBufferSize = sizeof(R2G_SET_GAME_WORLD_VERSION); piSendBuffer = KG_MemoryCreateBuffer((unsigned)uSendBufferSize); KGLOG_PROCESS_ERROR(piSendBuffer); pRespond = (R2G_SET_GAME_WORLD_VERSION*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pRespond); pRespond->byProtocol = r2g_set_game_world_version; pRespond->nLowerVersion = nLowerVersion; pRespond->nUpperVersion = nUpperVersion; nRetCode = m_piSocket->Send(piSendBuffer); KGLOG_PROCESS_ERROR(nRetCode == 1); nResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return nResult; }
int KSimulateRelay::DoDeleteRoleRespond(DWORD dwPacketIdentity, int nRespondCode) { int nResult = false; int nRetCode = false; IKG_Buffer* piSendBuffer = false; size_t uSendBufferSize = 0; R2G_DELETE_ROLE_RESPOND* pRespond = NULL; KGLOG_PROCESS_ERROR(m_piSocket); uSendBufferSize = sizeof(R2G_DELETE_ROLE_RESPOND); piSendBuffer = KG_MemoryCreateBuffer((unsigned)uSendBufferSize); KGLOG_PROCESS_ERROR(piSendBuffer); pRespond = (R2G_DELETE_ROLE_RESPOND*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pRespond); pRespond->byProtocol = r2g_delete_role_respond; pRespond->nPlayerIndex = dwPacketIdentity; pRespond->byCode = nRespondCode; pRespond->dwRoleID = 0; nRetCode = m_piSocket->Send(piSendBuffer); KGLOG_PROCESS_ERROR(nRetCode == 1); nResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return nResult; }
BOOL KApexProxy::DoRoleLogout(DWORD dwRoleID) { BOOL bResult = false; APEX_ROLE_LOGOUT* pRoleLogout = NULL; IKG_Buffer* piBuffer = NULL; KRole* pRole = NULL; size_t nNameLen = 0; pRole = g_pSO3GameCenter->m_RoleManager.GetRole(dwRoleID); KGLOG_PROCESS_ERROR(pRole); piBuffer = KG_MemoryCreateBuffer((unsigned)sizeof(APEX_ROLE_LOGOUT)); KGLOG_PROCESS_ERROR(piBuffer); pRoleLogout = (APEX_ROLE_LOGOUT*)piBuffer->GetData(); KGLOG_PROCESS_ERROR(pRoleLogout); pRoleLogout->cMsgId = 'G'; pRoleLogout->nSendId = (int)dwRoleID; strncpy(pRoleLogout->szName, pRole->m_szName, sizeof(pRoleLogout->szName)); pRoleLogout->szName[sizeof(pRoleLogout->szName) - 1] = '\0'; Send(piBuffer); bResult = true; Exit0: KG_COM_RELEASE(piBuffer); return bResult; }
int KSimulateRelay::DoAccountExchangeRequest() { BOOL bResult = false; BOOL bRetCode = false; IKG_Buffer* piBuffer = NULL; R2G_ACCOUNT_EXCHANGE_REQUEST* pRequest = NULL; const char* pszAccountName = "0000"; // DWORD dwRoleID = 3333; assert(pszAccountName); piBuffer = KG_MemoryCreateBuffer((unsigned)sizeof(R2G_ACCOUNT_EXCHANGE_REQUEST)); KGLOG_PROCESS_ERROR(piBuffer); pRequest = (R2G_ACCOUNT_EXCHANGE_REQUEST*)piBuffer->GetData(); KGLOG_PROCESS_ERROR(pRequest); pRequest->byProtocol = r2g_account_exchange_request; bRetCode = m_piSocket->Send(piBuffer); KGLOG_PROCESS_ERROR(bRetCode); KGLogPrintf(KGLOG_INFO, "Relay, DoAccountExchangeRequest\n"); bResult = true; Exit0: KG_COM_RELEASE(piBuffer); return bResult; }
int KSimulateRelay::DoFreezeCoinRequest() { BOOL bResult = false; BOOL bRetCode = false; IKG_Buffer* piBuffer = NULL; R2G_FREEZE_COIN_REQUEST* pRequest = NULL; const char* pszAccountName = "0000"; DWORD dwRoleID = 3333; assert(pszAccountName); piBuffer = KG_MemoryCreateBuffer((unsigned)sizeof(R2G_FREEZE_COIN_REQUEST)); KGLOG_PROCESS_ERROR(piBuffer); pRequest = (R2G_FREEZE_COIN_REQUEST*)piBuffer->GetData(); KGLOG_PROCESS_ERROR(pRequest); pRequest->byProtocol = r2g_freeze_coin_request; strncpy(pRequest->szAccount, pszAccountName, sizeof(pRequest->szAccount)); pRequest->szAccount[sizeof(pRequest->szAccount) - 1] = '\0'; pRequest->dwRequestID = dwRoleID; bRetCode = m_piSocket->Send(piBuffer); KGLOG_PROCESS_ERROR(bRetCode); KGLogPrintf(KGLOG_INFO, "Relay, DoFreezeCoinRequest\n"); bResult = true; Exit0: KG_COM_RELEASE(piBuffer); return bResult; }
BOOL KLogServerAgency::Ping() { BOOL bResult = false; BOOL bRetCode = false; IKG_Buffer* piSendBuffer = NULL; tagProtocolHeader2* pPing = NULL; KG_PROCESS_ERROR(g_pSO3GameCenter->m_nTimeNow >= m_nNextPingTime); m_nNextPingTime = g_pSO3GameCenter->m_nTimeNow + m_nPingCycle; piSendBuffer = KG_MemoryCreateBuffer((unsigned)sizeof(tagProtocolHeader2)); KGLOG_PROCESS_ERROR(piSendBuffer); pPing = (tagProtocolHeader2*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pPing); pPing->ProtocolType = LOGC2S_PING; pPing->ulIdentity = 0; bRetCode = Send(piSendBuffer); KG_PROCESS_ERROR(bRetCode); bResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return bResult; }
BOOL KPlayerManager::DoRenameRespond(KPlayerAgency* pPlayer, BYTE byCode, DWORD dwRoleID, BYTE* pbyData, size_t uDataLen) { BOOL bResult = false; int nRetCode = 0; G2C_RENAME_RESPOND* pRespond = NULL; IKG_Buffer* piSendBuffer = NULL; piSendBuffer = KG_MemoryCreateBuffer((unsigned)(sizeof(G2C_RENAME_RESPOND) + uDataLen)); KGLOG_PROCESS_ERROR(piSendBuffer); pRespond = (G2C_RENAME_RESPOND*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pRespond); pRespond->byProtocol = g2c_rename_respond; pRespond->byCode = byCode; pRespond->dwRoleID = dwRoleID; if (pbyData) { memcpy(pRespond->byData, pbyData, uDataLen); } nRetCode = pPlayer->piSocket->Send(piSendBuffer); KGLOG_PROCESS_ERROR(nRetCode == 1); bResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return bResult; }
BOOL KLogClient::DoPingSignal() { BOOL bResult = false; BOOL bRetCode = false; DWORD dwNowTime = 0; IKG_Buffer* piSendBuffer = NULL; G2L_PING_SIGNAL* pPingSingal = NULL; dwNowTime = KG_GetTickCount(); KG_PROCESS_ERROR(dwNowTime >= m_dwNextPingTime); m_dwNextPingTime = dwNowTime + 1000 * m_nPingCycle; piSendBuffer = KG_MemoryCreateBuffer(sizeof(G2L_PING_SIGNAL)); KGLOG_PROCESS_ERROR(piSendBuffer); pPingSingal = (G2L_PING_SIGNAL*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pPingSingal); pPingSingal->wProtocolID = g2l_ping_signal; bRetCode = Send(piSendBuffer); KGLOG_PROCESS_ERROR(bRetCode); bResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return bResult; }
BOOL KPlayerManager::DoSyncQueueState(KPlayerAgency* pPlayer, int nPosition) { BOOL bResult = false; int nRetCode = 0; G2C_SYNC_QUEUE_STATE* pNotify = NULL; IKG_Buffer* piSendBuffer = NULL; assert(pPlayer); piSendBuffer = KG_MemoryCreateBuffer((unsigned)sizeof(G2C_SYNC_QUEUE_STATE)); KGLOG_PROCESS_ERROR(piSendBuffer); pNotify = (G2C_SYNC_QUEUE_STATE*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pNotify); pNotify->byProtocol = g2c_sync_queue_state; pNotify->nPosition = nPosition; nRetCode = pPlayer->piSocket->Send(piSendBuffer); KGLOG_PROCESS_ERROR(nRetCode == 1); bResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return bResult; }
BOOL KPlayerManager::DoGiveupQueueRespond(KPlayerAgency* pPlayer) { BOOL bResult = false; int nRetCode = 0; G2C_GIVEUP_QUEUE_RESPOND* pRespond = NULL; IKG_Buffer* piSendBuffer = NULL; assert(pPlayer); piSendBuffer = KG_MemoryCreateBuffer((unsigned)sizeof(G2C_GIVEUP_QUEUE_RESPOND)); KGLOG_PROCESS_ERROR(piSendBuffer); pRespond = (G2C_GIVEUP_QUEUE_RESPOND*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pRespond); pRespond->byProtocol = g2c_giveup_queue_respond; pRespond->byNothing = 0; nRetCode = pPlayer->piSocket->Send(piSendBuffer); KGLOG_PROCESS_ERROR(nRetCode == 1); bResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return bResult; }
BOOL KPlayerManager::DoGameLoginRespond( KPlayerAgency* pPlayer, BYTE byCode, DWORD dwRoleID, DWORD dwIP, int nPort, const GUID& crGuid ) { BOOL bResult = false; int nRetCode = 0; G2C_SYNC_LOGIN_KEY* pRespond = NULL; IKG_Buffer* piSendBuffer = NULL; piSendBuffer = KG_MemoryCreateBuffer((unsigned)sizeof(G2C_SYNC_LOGIN_KEY)); KGLOG_PROCESS_ERROR(piSendBuffer); pRespond = (G2C_SYNC_LOGIN_KEY*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pRespond); pRespond->byProtocol = g2c_sync_login_key; pRespond->byCode = byCode; pRespond->dwRoleID = dwRoleID; pRespond->dwIP = dwIP; pRespond->nPort = nPort; pRespond->guid = crGuid; nRetCode = pPlayer->piSocket->Send(piSendBuffer); KGLOG_PROCESS_ERROR(nRetCode == 1); bResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return bResult; }
BOOL KPlayerManager::DoDeleteRoleRespond(KPlayerAgency* pPlayer, BYTE byCode, DWORD dwRoleID, time_t nDeleteTime) { BOOL bResult = false; int nRetCode = 0; G2C_DELETE_ROLE_RESPOND* pRespond = NULL; IKG_Buffer* piSendBuffer = NULL; piSendBuffer = KG_MemoryCreateBuffer((unsigned)sizeof(G2C_DELETE_ROLE_RESPOND)); KGLOG_PROCESS_ERROR(piSendBuffer); pRespond = (G2C_DELETE_ROLE_RESPOND*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pRespond); pRespond->byProtocol = g2c_delete_role_respond; pRespond->byCode = byCode; pRespond->dwRoleID = dwRoleID; pRespond->nDeleteTime = nDeleteTime; nRetCode = pPlayer->piSocket->Send(piSendBuffer); KGLOG_PROCESS_ERROR(nRetCode == 1); bResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return bResult; }
BOOL KPlayerManager::DoSyncNewbieMaps(KPlayerAgency* pPlayer, DWORD dwMapID, KNEWBIE_MAP_COPY_INFO CopyInfo[], int nCopyCount) { BOOL bResult = false; int nRetCode = 0; IKG_Buffer* piSendBuffer = NULL; G2C_SYNC_NEWBIE_MAPS* pRespond = NULL; piSendBuffer = KG_MemoryCreateBuffer((unsigned)(sizeof(G2C_SYNC_NEWBIE_MAPS) + sizeof(KNEWBIE_MAP_COPY_INFO) * nCopyCount)); KGLOG_PROCESS_ERROR(piSendBuffer); pRespond = (G2C_SYNC_NEWBIE_MAPS*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pRespond); pRespond->byProtocol = g2c_sync_newbie_maps; pRespond->dwMapID = dwMapID; pRespond->nCopyCount = nCopyCount; memcpy(pRespond->CopyInfo, CopyInfo, sizeof(KNEWBIE_MAP_COPY_INFO) * nCopyCount); nRetCode = pPlayer->piSocket->Send(piSendBuffer); KGLOG_PROCESS_ERROR(nRetCode == 1); bResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return bResult; }
BOOL KPlayerManager::DoMibaoVerifyRespond(KPlayerAgency* pPlayer, int nRespondCode) { BOOL bResult = false; int nRetCode = 0; IKG_Buffer* piSendBuffer = NULL; G2C_MIBAO_VERIFY_RESPOND* pRespond = NULL; assert(pPlayer); piSendBuffer = KG_MemoryCreateBuffer((unsigned)sizeof(G2C_MIBAO_VERIFY_RESPOND)); KGLOG_PROCESS_ERROR(piSendBuffer); pRespond = (G2C_MIBAO_VERIFY_RESPOND*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pRespond); pRespond->byProtocol = g2c_mibao_verify_respond; pRespond->nCode = nRespondCode; strncpy(pRespond->szMatrixPosition, pPlayer->szMatrixPosition, sizeof(pRespond->szMatrixPosition)); pRespond->szMatrixPosition[sizeof(pRespond->szMatrixPosition) - 1] = '\0'; nRetCode = pPlayer->piSocket->Send(piSendBuffer); KGLOG_PROCESS_ERROR(nRetCode == 1); bResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return bResult; }
BOOL KPlayerManager::DoSndaVerifyRespond(KPlayerAgency* pPlayer, int nRespondCode) { BOOL bResult = false; int nRetCode = 0; G2C_SNDA_VERIFY_RESPOND* pRespond = NULL; IKG_Buffer* piSendBuffer = NULL; assert(pPlayer); piSendBuffer = KG_MemoryCreateBuffer((unsigned)(sizeof(G2C_SNDA_VERIFY_RESPOND))); KGLOG_PROCESS_ERROR(piSendBuffer); pRespond = (G2C_SNDA_VERIFY_RESPOND*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pRespond); pRespond->byProtocol = g2c_snda_verify_respond; pRespond->nRespondCode = nRespondCode; nRetCode = pPlayer->piSocket->Send(piSendBuffer); KGLOG_PROCESS_ERROR(nRetCode == 1); bResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return bResult; }
int KSimulateRelay::OnQueryAccountState(BYTE* pbyData, size_t uDataLen) { int nResult = false; int nRetCode = false; IKG_Buffer* piSendBuffer = NULL; G2R_QUERY_ACCOUNT_STATE* pQueryAccountState = (G2R_QUERY_ACCOUNT_STATE*)pbyData; R2G_SYNC_ACCOUNT_STATE* pSyncAccountState = NULL; pQueryAccountState->szAccount[sizeof(pQueryAccountState->szAccount) - 1] = '\0'; piSendBuffer = KG_MemoryCreateBuffer(sizeof(R2G_SYNC_ACCOUNT_STATE)); KGLOG_PROCESS_ERROR(piSendBuffer); pSyncAccountState = (R2G_SYNC_ACCOUNT_STATE*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pSyncAccountState); pSyncAccountState->byProtocol = r2g_sync_account_state; pSyncAccountState->nPlayerIndex = pQueryAccountState->nPlayerIndex; pSyncAccountState->bOnline = m_RelayConfig.nUserOnlineResult; nRetCode = m_piSocket->Send(piSendBuffer); KGLOG_PROCESS_ERROR(nRetCode == 1); nResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return nResult; }
int KBishopClient::login_state_request_login_game() { int nResult = false; int nRetCode = false; tagDBSelPlayer *pRoleLogin = NULL; IKG_Buffer *piSendBuffer = NULL; piSendBuffer = KG_MemoryCreateBuffer(sizeof(tagDBSelPlayer)); KGLOG_PROCESS_ERROR(piSendBuffer); pRoleLogin = (tagDBSelPlayer *)piSendBuffer->GetData(); ASSERT(pRoleLogin); // 注意: 一个刚创建的角色是不在m_RoleList里面的,所以不要在这里检验"在不在角色列表" pRoleLogin->cProtocol = C2B_GAME_LOGIN_REQUEST; pRoleLogin->ulIdentity = 0; // no use strncpy(pRoleLogin->szRoleName, m_szLoginRole, sizeof(pRoleLogin->szRoleName)); pRoleLogin->szRoleName[sizeof(pRoleLogin->szRoleName) - 1] = '\0'; nRetCode = m_piSocketStream->Send(piSendBuffer); KGLOG_PROCESS_ERROR(nRetCode == 1); m_CurrentState = LOGIN_STATE_WAIT_GAME_LOGIN_INFO; nResult = true; Exit0: if (!nResult) { m_nLoginResult = Login_RequestLoginGameserver; m_CurrentState = LOGIN_STATE_NONE; KG_COM_RELEASE(m_piSocketStream); } KG_COM_RELEASE(piSendBuffer); return nResult; }
int KSimulateRelay::DoPingRespond() { int nResult = false; int nRetCode = false; IKG_Buffer* piSendBuffer = NULL; BYTE* pbySendBuffer = NULL; tagProtocolHeader* ptagProtocolHeader = NULL; KGLOG_PROCESS_ERROR(m_piSocket); piSendBuffer = KG_MemoryCreateBuffer((unsigned)(sizeof(R2G_PING_SIGNAL))); KGLOG_PROCESS_ERROR(piSendBuffer); pbySendBuffer = (BYTE*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pbySendBuffer); ptagProtocolHeader = (tagProtocolHeader*)pbySendBuffer; ptagProtocolHeader->cProtocol = r2g_ping_signal; nRetCode = m_piSocket->Send(piSendBuffer); KGLOG_PROCESS_ERROR(nRetCode); nResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return nResult; }
BOOL KPlayerManager::DoHandshakeRespond(KPlayerAgency* pPlayer, int nCode) { BOOL bResult = false; int nRetCode = 0; IKG_Buffer* piBuffer = NULL; G2C_HANDSHAKE_RESPOND* pRespond = NULL; piBuffer = KG_MemoryCreateBuffer((unsigned)sizeof(G2C_HANDSHAKE_RESPOND)); KGLOG_PROCESS_ERROR(piBuffer); pRespond = (G2C_HANDSHAKE_RESPOND*)piBuffer->GetData(); KGLOG_PROCESS_ERROR(pRespond); pRespond->byProtocol = g2c_handshake_respond; pRespond->byCode = ghcHandshakeSucceed;//(BYTE)nCode; pRespond->bZoneChargeFlag = true; //m_pPaysysAgency->m_bZoneChargeFlag; nRetCode = pPlayer->piSocket->Send(piBuffer); KGLOG_PROCESS_ERROR(nRetCode == 1); bResult = true; Exit0: KG_COM_RELEASE(piBuffer); return bResult; }
BOOL KMapCopy::Load(BYTE* pbyData, size_t uDataLen) { BOOL bResult = false; BOOL bRetCode = false; BYTE* pbyOffset = pbyData; size_t uLeftSize = uDataLen; DWORD dwPlayerCount = 0; DWORD dwSceneDataLen = 0; IKG_Buffer* piSceneData = NULL; BYTE* pbySceneData = NULL; KGLOG_PROCESS_ERROR(uLeftSize >= sizeof(DWORD)); dwPlayerCount = *(DWORD*)pbyOffset; pbyOffset += sizeof(DWORD); uLeftSize -= sizeof(DWORD); for (DWORD i = 0; i < dwPlayerCount; i++) { KGLOG_PROCESS_ERROR(uLeftSize >= sizeof(DWORD)); m_PlayerList.insert(*(DWORD*)pbyOffset); pbyOffset += sizeof(DWORD); uLeftSize -= sizeof(DWORD); } KGLOG_PROCESS_ERROR(uLeftSize >= sizeof(DWORD)); dwSceneDataLen = *(DWORD*)pbyOffset; pbyOffset += sizeof(DWORD); uLeftSize -= sizeof(DWORD); KGLOG_PROCESS_ERROR(uLeftSize >= dwSceneDataLen); if (dwSceneDataLen > 0) { piSceneData = KG_MemoryCreateBuffer((unsigned)dwSceneDataLen); KGLOG_PROCESS_ERROR(piSceneData); pbySceneData = (BYTE*)piSceneData->GetData(); KGLOG_PROCESS_ERROR(pbySceneData); memcpy(pbySceneData, pbyOffset, dwSceneDataLen); assert(m_piSceneData == NULL); m_piSceneData = piSceneData; m_piSceneData->AddRef(); } pbyOffset += dwSceneDataLen; uLeftSize -= dwSceneDataLen; KGLOG_PROCESS_ERROR(uLeftSize == 0); bResult = true; Exit0: KG_COM_RELEASE(piSceneData); return bResult; }
int KBishopClient::login_state_wait_delete_respond() { int nResult = false; int nRetCode = false; tagNewDelRoleResponse *pDeleteRoleRespond = NULL; IKG_Buffer *piBuffer = NULL; unsigned uBufferSize = 0; timeval TimeoutValue = {0, 100 * 1000}; ASSERT(m_piSocketStream); nRetCode = m_piSocketStream->CheckCanRecv(&TimeoutValue); KGLOG_PROCESS_ERROR(nRetCode != -1); KG_PROCESS_SUCCESS(!nRetCode); nRetCode = m_piSocketStream->Recv(&piBuffer); KGLOG_PROCESS_ERROR(nRetCode == 1); uBufferSize = piBuffer->GetSize(); KGLOG_PROCESS_ERROR(uBufferSize == sizeof(tagNewDelRoleResponse)); pDeleteRoleRespond = (tagNewDelRoleResponse *)piBuffer->GetData(); ASSERT(pDeleteRoleRespond); KGLOG_PROCESS_ERROR(pDeleteRoleRespond->cProtocol == B2C_CREATE_OR_DELETE_ROLE_RESULT); pDeleteRoleRespond->szRoleName[sizeof(pDeleteRoleRespond->szRoleName) - 1] = '\0'; if (pDeleteRoleRespond->bSucceeded) { ROLE_LIST::iterator it; for (it = m_RoleList.begin(); it != m_RoleList.end(); ++it) { nRetCode = strcmp(it->szRoleName, pDeleteRoleRespond->szRoleName); if (!nRetCode) { m_RoleList.erase(it); break; } } } else { goto Exit0; } m_CurrentState = LOGIN_STATE_WAIT_PLAYER_OPERATE; Exit1: nResult = true; Exit0: if (!nResult) { m_nLoginResult = Login_DeleteRole; m_CurrentState = LOGIN_STATE_NONE; KG_COM_RELEASE(m_piSocketStream); } KG_COM_RELEASE(piBuffer); return nResult; }
const void *KClient::GetPackFromServer(unsigned int uLinkId, unsigned int &uLen) { void* pRet = NULL; uLen = 0; do { if (uLinkId >= (unsigned int)m_nMaxConnCount) { ASSERT(FALSE); break; } IKG_SocketStream* pConnection = m_ppConnections[uLinkId]; //ASSERT(pConnection); if (!pConnection) return NULL; timeval sTimeOut = {0, 0}; INT nResult = pConnection->CheckCanRecv(&sTimeOut); if (nResult == 0) { break; } else if (nResult == -1) { // 断线 OnConnectionClose(uLinkId); pConnection->Release(); break; } IKG_Buffer *pBuffer = NULL; nResult = pConnection->Recv(&pBuffer); if (nResult <= 0) { // 断线 OnConnectionClose(uLinkId); pConnection->Release(); break; } LPVOID pData = pBuffer->GetData(); size_t nLen = pBuffer->GetSize(); if (nLen > sizeof(m_szBuffer)) { ASSERT(FALSE); pBuffer->Release(); break; } memcpy(m_szBuffer, pData, nLen); uLen = nLen; pBuffer->Release(); pRet = m_szBuffer; } while(0); return pRet; }
int KBishopClient::login_state_request_create_role() { int nResult = false; int nRetCode = false; TProcessData *pTProcessData = NULL; IKG_Buffer *piSendBuffer = NULL; KROLE_GENERATOR_PARAM *pRoleCreateParam = NULL; piSendBuffer = KG_MemoryCreateBuffer(sizeof(TProcessData) + sizeof(KROLE_GENERATOR_PARAM)); KGLOG_PROCESS_ERROR(piSendBuffer); pTProcessData = (TProcessData *)piSendBuffer->GetData(); ASSERT(pTProcessData); pTProcessData->nProtoId = C2B_CREATE_ROLE; pTProcessData->bLeave = false; // no use pTProcessData->ulIdentity = 0; // no use pTProcessData->nDataLen = 1 + sizeof(KROLE_GENERATOR_PARAM); pTProcessData->pDataBuffer[0] = 0; // no use pRoleCreateParam = (KROLE_GENERATOR_PARAM *)(pTProcessData->pDataBuffer + 1); strncpy(pRoleCreateParam->szRoleName, m_RoleCreateParam.szRoleName, sizeof(pRoleCreateParam->szRoleName)); pRoleCreateParam->szRoleName[sizeof(pRoleCreateParam->szRoleName) - 1] = '\0'; strncpy(pRoleCreateParam->szAccountName, m_szAccountName, sizeof(pRoleCreateParam->szAccountName)); pRoleCreateParam->szAccountName[sizeof(pRoleCreateParam->szAccountName) - 1] = '\0'; pRoleCreateParam->cRoleType = (char)m_RoleCreateParam.nRoleType; pRoleCreateParam->dwMapID = m_RoleCreateParam.dwMapID; pRoleCreateParam->dwMapCopyIndex = m_RoleCreateParam.dwMapCopyIndex; memcpy(pRoleCreateParam->wRepresentID, m_RoleCreateParam.wRepresentID, sizeof(pRoleCreateParam->wRepresentID)); nRetCode = m_piSocketStream->Send(piSendBuffer); KGLOG_PROCESS_ERROR(nRetCode == 1); m_CurrentState = LOGIN_STATE_WAIT_CREATE_RESPOND; nResult = true; Exit0: if (!nResult) { m_nLoginResult = Login_CreateRole; m_CurrentState = LOGIN_STATE_NONE; KG_COM_RELEASE(m_piSocketStream); } KG_COM_RELEASE(piSendBuffer); return nResult; }
BOOL KLogServerAgency::LogPlayerAction( PLAYER_ACTION_TYPE eActionType, unsigned uActionLevel, const char* pszActionTarget, const char* pszAccountName, const char* pszRoleName, size_t uCommentSize, BYTE* pbyComment ) { BOOL bResult = false; BOOL bRetCode = false; size_t uExtendSize = 0; IKG_Buffer* piSendBuffer = NULL; KGPlayerActionLog* pLog = NULL; assert(pszActionTarget); assert(pszAccountName); assert(pszRoleName); uExtendSize = uCommentSize ? uCommentSize - 1 : 0; piSendBuffer = KG_MemoryCreateBuffer((unsigned)(sizeof(KGPlayerActionLog) + uExtendSize)); KGLOG_PROCESS_ERROR(piSendBuffer); pLog = (KGPlayerActionLog*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pLog); pLog->ProtocolType = LOGC2S_LOG_PLAYER_ACTION; pLog->ulIdentity = 0; pLog->uActionLevel = uActionLevel; pLog->eActionType = eActionType; strncpy(pLog->szActionTarget, pszActionTarget, sizeof(pLog->szActionTarget)); pLog->szActionTarget[sizeof(pLog->szActionTarget) - 1] = '\0'; strncpy(pLog->szAccountName, pszAccountName, sizeof(pLog->szAccountName)); pLog->szAccountName[sizeof(pLog->szAccountName) - 1] = '\0'; strncpy(pLog->szRoleName, pszRoleName, sizeof(pLog->szRoleName)); pLog->szRoleName[sizeof(pLog->szRoleName) - 1] = '\0'; pLog->uCommentSize = (unsigned)uCommentSize; if (pbyComment) { memcpy(pLog->pbyData, pbyComment, uCommentSize); } bRetCode = Send(piSendBuffer); KG_PROCESS_ERROR(bRetCode); bResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return bResult; }
BOOL KLogClient::Connect() { BOOL bResult = false; BOOL bRetCode = false; KG_SocketConnector Connector; struct timeval TimeVal; IKG_SocketStream* piSocketStream = NULL; IKG_Buffer* piPackage = NULL; G2L_HANDSHAKE_REQUEST* pHandshake = NULL; piSocketStream = Connector.Connect(m_szLogServerAddr, m_nRelayPort); KG_PROCESS_ERROR(piSocketStream); TimeVal.tv_sec = 0; TimeVal.tv_usec = 10000; bRetCode = piSocketStream->SetTimeout(&TimeVal); KGLOG_PROCESS_ERROR(bRetCode); m_bSocketError = false; //m_nWorldIndex = 0; m_nLastSendPacketTime = g_pSO3World->m_nCurrentTime; // 初始化的一些操作,注意多线程 piPackage = KG_MemoryCreateBuffer((unsigned)sizeof(G2L_HANDSHAKE_REQUEST)); KGLOG_PROCESS_ERROR(piPackage); pHandshake = (G2L_HANDSHAKE_REQUEST*)piPackage->GetData(); KGLOG_PROCESS_ERROR(pHandshake); pHandshake->wProtocolID = g2l_handshake_request; pHandshake->nServerTime = (int)time(NULL); pHandshake->nServerIndexInGC = g_pSO3World->m_nServerIndexInGC; bRetCode = piSocketStream->Send(piPackage); KGLOG_PROCESS_ERROR(bRetCode == 1); // 小心: 这里不能写成 "m_piSocket = piSocket; m_piSocket->AddRef(); ", 那样会导致线程安全隐患 piSocketStream->AddRef(); m_piSocketStream = piSocketStream; KGLogPrintf( KGLOG_INFO, "Connect to log server %s:%d ... ... [OK]", m_szLogServerAddr, m_nRelayPort ); bResult = true; Exit0: KG_COM_RELEASE(piPackage); KG_COM_RELEASE(piSocketStream); return bResult; }
int KBishopClient::login_state_wait_create_respond() { int nResult = false; int nRetCode = false; tagNewDelRoleResponse *pCreateRoleRespond = NULL; IKG_Buffer *piBuffer = NULL; unsigned uBufferSize = 0; timeval TimeoutValue = {0, 100 * 1000}; ASSERT(m_piSocketStream); nRetCode = m_piSocketStream->CheckCanRecv(&TimeoutValue); KGLOG_PROCESS_ERROR(nRetCode != -1); KG_PROCESS_SUCCESS(!nRetCode); nRetCode = m_piSocketStream->Recv(&piBuffer); KGLOG_PROCESS_ERROR(nRetCode == 1); uBufferSize = piBuffer->GetSize(); KGLOG_PROCESS_ERROR(uBufferSize == sizeof(tagNewDelRoleResponse)); pCreateRoleRespond = (tagNewDelRoleResponse *)piBuffer->GetData(); ASSERT(pCreateRoleRespond); KGLOG_PROCESS_ERROR(pCreateRoleRespond->cProtocol == B2C_CREATE_OR_DELETE_ROLE_RESULT); KGLOG_CHECK_ERROR(pCreateRoleRespond->bSucceeded); if (pCreateRoleRespond->bSucceeded) { strncpy(m_szLoginRole, m_RoleCreateParam.szRoleName, sizeof(m_szLoginRole)); m_szLoginRole[sizeof(m_szLoginRole) - 1] = '\0'; m_CurrentState = LOGIN_STATE_REQUEST_LOGIN_GAME; } else { //m_CurrentState = LOGIN_STATE_WAIT_PLAYER_OPERATE; goto Exit0; } Exit1: nResult = true; Exit0: if (!nResult) { m_nLoginResult = Login_CreateRole; m_CurrentState = LOGIN_STATE_NONE; KG_COM_RELEASE(m_piSocketStream); } KG_COM_RELEASE(piBuffer); return nResult; }
BOOL KLogServerAgency::LoginServer(const char cszIP[], int nPort, const char cszIdentity[]) { BOOL bResult = false; BOOL bRetCode = false; IKG_Buffer* piSendBuffer = NULL; KGCSLogServerLogin* pLogin = NULL; KG_SocketConnector Connector; struct timeval TimeVal; assert(m_piSocket == NULL); m_piSocket = Connector.Connect(cszIP, nPort); KG_PROCESS_ERROR(m_piSocket); TimeVal.tv_sec = 2; TimeVal.tv_usec = 0; bRetCode = m_piSocket->SetTimeout(&TimeVal); KGLOG_PROCESS_ERROR(bRetCode); piSendBuffer = KG_MemoryCreateBuffer((unsigned)sizeof(KGCSLogServerLogin)); KGLOG_PROCESS_ERROR(piSendBuffer); pLogin = (KGCSLogServerLogin*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pLogin); pLogin->ProtocolType = LOGC2S_LOG_LOGIN; pLogin->ulIdentity = 0; strncpy(pLogin->szGatewayName, cszIdentity, sizeof(pLogin->szGatewayName)); pLogin->szGatewayName[sizeof(pLogin->szGatewayName) - 1] = '\0'; bRetCode = Send(piSendBuffer); KGLOG_PROCESS_ERROR(bRetCode); bResult = true; Exit0: KGLogPrintf( KGLOG_INFO, "Connect to log server %s:%d ... ... [%s]", cszIP, nPort, bResult ? "OK" : "Failed" ); if (!bResult) { KG_COM_RELEASE(m_piSocket); } KG_COM_RELEASE(piSendBuffer); return bResult; }
int KSimulateRelay::OnQueryRoleList(BYTE* pbyData, size_t uDataLen) { int nResult = false; BYTE* pbyPos = NULL; IKG_Buffer* piSendBuffer = NULL; KROLE_LIST_INFO* pBaseData = NULL; int nRoleCount = 0; G2R_QUERY_ROLE_LIST* pQueryRoleList = (G2R_QUERY_ROLE_LIST*)pbyData; pQueryRoleList->szAccount[sizeof(pQueryRoleList->szAccount) - 1] = '\0'; nRoleCount = m_RelayConfig.nGetRoleListCount; if (nRoleCount > 0) { piSendBuffer = KG_MemoryCreateBuffer(sizeof(KROLE_LIST_INFO) * nRoleCount); KGLOG_PROCESS_ERROR(piSendBuffer); pbyPos = (BYTE*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pbyPos); } if (nRoleCount == 0) { DoSyncRoleList(pQueryRoleList->nPlayerIndex, 0, 0, NULL); } else { for (int nRoleIndex = 0; nRoleIndex < nRoleCount; nRoleIndex++) { pBaseData = (KROLE_LIST_INFO*)pbyPos; pBaseData->BaseInfo.byLevel = 0x3; pBaseData->BaseInfo.cRoleType = '6'; pBaseData->BaseInfo.CurrentPos.byFaceDirection = '6'; pBaseData->dwPlayerID = nRoleIndex; strncpy(pBaseData->szAccount, "AccountYeah", sizeof(pBaseData->szAccount)); strncpy(pBaseData->szRoleName, "RoleNameyaah", sizeof(pBaseData->szRoleName)); DoSyncRoleList(pQueryRoleList->nPlayerIndex, nRoleIndex + 1, nRoleCount, (KROLE_LIST_INFO*)pbyPos); pbyPos += sizeof(KROLE_LIST_INFO); } } nResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return nResult; }
int KSimulateRelay::DoSyncRoleList(int nPlayerIndex, int nRoleIndex, int nRoleCount, KROLE_LIST_INFO* pBaseData) { int nResult = false; int nRetCode = false; IKG_Buffer* piSendBuffer = false; size_t uSendBufferSize = 0; R2G_SYNC_ROLE_LIST* pRespond = NULL; KGLOG_PROCESS_ERROR(m_piSocket); uSendBufferSize = sizeof(R2G_SYNC_ROLE_LIST); if (nRoleCount > 0) { ASSERT(pBaseData); ASSERT(nRoleIndex > 0 && nRoleIndex <= nRoleCount); uSendBufferSize += sizeof(KROLE_LIST_INFO); } piSendBuffer = KG_MemoryCreateBuffer((unsigned)uSendBufferSize); KGLOG_PROCESS_ERROR(piSendBuffer); pRespond = (R2G_SYNC_ROLE_LIST*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pRespond); pRespond->byProtocol = r2g_sync_role_list; pRespond->nPlayerIndex = nPlayerIndex; pRespond->nRoleIndex = nRoleIndex; pRespond->nRoleCount = nRoleCount; //pRespond->nFreezeTime = 0; pRespond->dwRoleID = ERROR_ID; if (pBaseData != NULL) { pRespond->dwRoleID = pBaseData->dwPlayerID; memcpy(pRespond->byData, pBaseData, sizeof(KROLE_LIST_INFO)); } nRetCode = m_piSocket->Send(piSendBuffer); KGLOG_PROCESS_ERROR(nRetCode == 1); nResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return nResult; }
void KGatewayEyes::SendCustomInfo() { l2e_update_custom_info* pInfo = NULL; size_t uStrLen = 0; IKG_Buffer* piBuffer = NULL; int nConnectiontotal = 0; DWORD dwAccountVerifyTime = 0; int nWaitingQueuePlayer = 0; nConnectiontotal = m_pPlayerManager->GetConnectionCount(); dwAccountVerifyTime = m_pPaysysAgency->GetAccountVerifyTimeCost(); nWaitingQueuePlayer = m_pQueueManager->GetWaitingQueuePlayerCount(); piBuffer = KG_MemoryCreateBuffer(MAX_CUSTOM_INFO_PAK); KGLOG_PROCESS_ERROR(piBuffer); pInfo = (l2e_update_custom_info*)piBuffer->GetData(); KGLOG_PROCESS_ERROR(piBuffer); pInfo->wProtocol = l2e_header_def; pInfo->wServer = 0; pInfo->wSubProtocol = l2e_update_custom_info_def; uStrLen = snprintf( (char*)pInfo->byData, MAX_CUSTOM_INFO_PAK - sizeof(l2e_update_custom_info), "-------------------------------------\n" "Connection total ... .... %d\n" "Waiting queue ... ... ... %d\n" "Account verify respond .. %lu ms\n" "-------------------------------------\n", nConnectiontotal, nWaitingQueuePlayer, dwAccountVerifyTime ); KGLOG_PROCESS_ERROR(uStrLen > 0); KGLOG_PROCESS_ERROR(uStrLen < MAX_CUSTOM_INFO_PAK - sizeof(l2e_update_custom_info)); pInfo->uDataLen = uStrLen; m_Stream.PutPack(pInfo, sizeof(l2e_update_custom_info) + uStrLen); Exit0: KG_COM_RELEASE(piBuffer); return; }