BOOL KNetConnectPlayer::OnPlayerDisconnect( INT nPlayerIndex ) { INT nConnectId = m_pnPlayerIndex2ConnId[nPlayerIndex]; if (nConnectId > 0) m_pnConnId2PlayerIndex[nConnectId] = 0; m_pnPlayerIndex2ConnId[nPlayerIndex] = -1; KPlayer* pPlayer = g_cPlayerMgr.GetByIndex(nPlayerIndex); QCONFIRM_RET_FALSE(pPlayer); //Q_Printl("OnPlayerDisconnect [" << pPlayer->GetId() << "][" << pPlayer->GetName() << // "] PlayerIdx[" << pPlayer->GetPlayerIndex() << "] ConnIdx[" << nConnectId << "] ..."); // 通知coordinator玩家离开 g_RelayClient.DoPlayerLeaveGS(pPlayer->GetId()); m_mpAccount2Player.erase(pPlayer->m_cPlayerServer.GetAccount()); pPlayer->m_cPlayerServer.LogoutServer(); pPlayer->m_nTimer = 0; g_cPlayerMgr.RemoveByIndex(nPlayerIndex); return TRUE; }
BOOL KPlayerBaseProcess::OnSyncPlayer( LPCBYTE pData, UINT uDataLen ) { KS2C_SYNC_PLAYER* pReceived = (KS2C_SYNC_PLAYER*)pData; // CheckSize QCONFIRM_RET_FALSE(_offsetof(KS2C_SYNC_PLAYER, sVarSync.aMapVarSet) + sizeof(KMAP_VAR_VALUE) * (pReceived->sVarSync.wMapVarNum) == uDataLen); // TODO: improve KPlayer* pPlayer = g_cPlayerMgr.GetById(pReceived->dwPlayerId); if (pPlayer) { pPlayer->m_cPlayerClient.LoadSyncVarOther(pReceived->sVarSync); pPlayer->SetPosition(pReceived->nX, pReceived->nY, pReceived->nZ); pPlayer->SetMoveState((KE_MOVE_STATE)pReceived->nMoveState); pPlayer->m_nVelocityXY = pReceived->nVelocityXY; pPlayer->m_nDestX = pReceived->nDestX; pPlayer->m_nDestY = pReceived->nDestY; pPlayer->m_nDestZ = pReceived->nDestZ; pPlayer->m_nFaceDirection = pReceived->nDirectionXY; // 暂时用速度方向代替 pPlayer->SetKinName(pReceived->szKinName); pPlayer->SetKinId(pReceived->dwKinId); pPlayer->SetKinFigure(pReceived->dwKinFigure); QLogPrintf(LOG_LEVEL_WARNING, "[PlayerBaseProcess] %s :player_id=%d,already exists", __FUNCTION__, pReceived->dwPlayerId); return FALSE; } else { pPlayer = g_cOrpgWorld.AddPlayer(pReceived->szName, pReceived->dwPlayerId); QCONFIRM_RET_FALSE(pPlayer); pPlayer->m_cPlayerClient.LoadSyncVarOther(pReceived->sVarSync); // get client scene IKScene* pScene = g_pSceneMgr->FirstScene(); QCONFIRM_RET_FALSE(pScene); pScene->AddPlayer(pPlayer, pReceived->nX, pReceived->nY, pReceived->nZ); pPlayer->SetMoveState((KE_MOVE_STATE)pReceived->nMoveState); pPlayer->m_nVelocityXY = pReceived->nVelocityXY; pPlayer->m_nDestX = pReceived->nDestX; pPlayer->m_nDestY = pReceived->nDestY; pPlayer->m_nDestZ = pReceived->nDestZ; pPlayer->m_nFaceDirection = pReceived->nDirectionXY; // 暂时用速度方向代替 pPlayer->SetKinName(pReceived->szKinName); pPlayer->SetKinId(pReceived->dwKinId); pPlayer->SetKinFigure(pReceived->dwKinFigure); pPlayer->FireEvent(emKOBJEVENTTYPE_CHARACTER_ENTER_SCENE, pPlayer->GetId(), FALSE, 0); return TRUE; } return TRUE; }
BOOL KPlayerBaseProcess::OnSyncSelf( LPCBYTE pData, UINT uDataLen ) { KS2C_SYNC_SELF* pSData = (KS2C_SYNC_SELF* )pData; g_cOrpgWorld.m_dwClientSceneId = pSData->dwSceneId; KPlayer* pPlayer = g_cPlayerMgr.GetById(g_cOrpgWorld.m_dwClientPlayerId); QCONFIRM_RET_FALSE(pPlayer); // 为了加载地图时,加快3D地图的加载所作的优化 pPlayer->m_nX = pSData->nX; pPlayer->m_nY = pSData->nY; pPlayer->m_nZ = pSData->nZ; pPlayer->m_nFaceDirection = pSData->nDirectionXY; IKScene* pScene = g_cOrpgWorld.LoadScene(pSData->dwSceneId); QCONFIRM_RET_FALSE(pScene); //modify by wdb const KSCENE_CONFIG* pSceneCfg = g_pSceneMgr->GetSceneInfo(g_cOrpgWorld.m_dwClientSceneId); QCONFIRM_RET_FALSE(pSceneCfg); CHAR szNavPath[MAX_PATH] = {0}; snprintf(szNavPath, countof(szNavPath) - 1, "%s/%s%s", pSceneCfg->szPath, pSceneCfg->szClass, KD_SCENE_NAVFILE_EXT); IKPlayerFindPath* pIKPlayerFindPath = GetPlayerFindPath(pPlayer); QCONFIRM_RET_FALSE(pIKPlayerFindPath); BOOL bLoadRet = pIKPlayerFindPath->LoadNavPath(szNavPath); if (!bLoadRet) { QLogPrintf(LOG_INFO, "Load Scene Name:%s Navigate Path File %s Failed!\n", pSceneCfg->szClass, szNavPath); } pScene->AddPlayer(pPlayer, pSData->nX, pSData->nY, pSData->nZ); pPlayer->m_cPlayerClient.DynamicSceneFlag(pSData->nDynamicScene); pPlayer->m_nDirectionXY = pSData->nDirectionXY; pPlayer->m_nFaceDirection = pSData->nDirectionXY; pPlayer->m_sMoveCtrl.nMoveCount = 0; pPlayer->FireEvent(emKOBJEVENTTYPE_CHARACTER_ENTER_SCENE, pPlayer->GetId(), FALSE, 0); return TRUE; }
INT KPlayerMgr::GetAllPlayerId(std::vector<DWORD>* pvecPlayerId) { INT nResult = 0; INT nPlayerIndex = 0; LOG_PROCESS_ERROR(pvecPlayerId && "[KPlayerMgrSys]:非法的参数"); do { nPlayerIndex = m_cObjMgr.NextUsedIndex(nPlayerIndex); if (nPlayerIndex > 0) { KPlayer* pPlayer = m_cObjMgr.GetByIndex(nPlayerIndex); LOG_PROCESS_ERROR(pPlayer && "[KPlayerMgrSys]:遍历到未知的玩家"); pvecPlayerId->push_back(pPlayer->GetId()); } } while ( 0 < nPlayerIndex); nResult = 1; EXIT0: return nResult; }
VOID KItemTimeoutCtrl::RemoveItem(INT nItemIdx) { ASSERT(nItemIdx > 0); do { KItem* pItem = &Item[nItemIdx]; INT nPlayerIdx = pItem->GetBelong(); if (nPlayerIdx <= 0) { ASSERT(FALSE); break; } CHAR szMsg[1024]; sprintf(szMsg, "您的%s超过有效期已被删除!", pItem->GetOrgName()); KPlayer* pOwner = g_cPlayerMgr.GetByIndex(nPlayerIdx); if (m_pItemList->Remove(nItemIdx, emKLOSEITEM_TIMEOUT)) { g_cItemMgr.Remove( nItemIdx, emITEM_DATARECORD_REMOVE, emITEM_CONSUMEMODE_USINGTIMEOUT, pOwner ); g_ChatChannelManager.ProcessRespond(trLocalSys, emKSYSTEMMSG_NORMAL, pOwner->GetId(), "系统", szMsg, emQCHAT_PANEL); } else { QLogPrintf(LOG_ERR, "KItemTimeoutCtrl::RemoveItem failed Idx % Owner %s GDP %d,%d,%d", pItem->GetGameIndex(), pOwner->GetName(), pItem->GetGenre(), pItem->GetDetailType(), pItem->GetParticular()); } } while (0); }