//------------------------------------------------------------------------ IMPLEMENT_RMI(CWeapon, SvRequestReload) { CHECK_OWNER_REQUEST(); CActor *pActor=GetActorByNetChannel(pNetChannel); if (!pActor || pActor->IsDead()) { SvSetReloadState(eNRS_CancelReload); } else if(!IsSelected()) { //If the weapon isn't selected but the client is requesting a reload, they probably have finished equipping the weapon // while the server is catching up. This can be due to latency or mismatched 1P/3P animation lengths. m_bReloadWhenSelected = true; } else { SvSetReloadState(eNRS_StartReload); if(m_fm) m_fm->Reload(0); } return true; }
//------------------------------------------------------------------------ IMPLEMENT_RMI(CWeapon, SvRequestWeaponRaised) { CHECK_OWNER_REQUEST(); CHANGED_NETWORK_STATE(this, ASPECT_STREAM); return true; }
//------------------------------------------------------------------------ IMPLEMENT_RMI(CWeapon, SvRequestCancelReload) { CHECK_OWNER_REQUEST(); SvCancelReload(); return true; }
//------------------------------------------------------------------------ IMPLEMENT_RMI(CWeapon, SvRequestFireMode) { CHECK_OWNER_REQUEST(); SetCurrentFireMode(params.id); return true; }
//------------------------------------------------------------------------ IMPLEMENT_RMI(CWeapon, SvRequestInstantReload) { CHECK_OWNER_REQUEST(); CFireMode *pFireMode = GetCFireMode(params.fireModeId); if (pFireMode) { pFireMode->FillAmmo(true); } return true; }
//------------------------------------------------------------------------ IMPLEMENT_RMI(CWeapon, SvRequestShoot) { CHECK_OWNER_REQUEST(); bool ok=true; CActor *pActor=GetActorByNetChannel(pNetChannel); if (!pActor || pActor->IsDead()) ok=false; if (ok) { m_fireCounter++; m_expended_ammo++; IActor *pLocalActor=m_pGameFramework->GetClientActor(); bool isLocal = pLocalActor && (pLocalActor->GetChannelId() == pActor->GetChannelId()); #ifdef SERVER_CHECKS const float fCurrentTime = gEnv->pTimer->GetAsyncCurTime(); const int kOldShotId = m_lastShotId; if(ShouldEndVerificationSample(fCurrentTime, params.shotId)) { EndVerificationSample(pActor, kOldShotId); StartVerificationSample(fCurrentTime); } m_fLastSampleTakenTime = fCurrentTime; m_fSampleNumShots += 1.0f; CPlayer * pPlayer = static_cast<CPlayer*>(pActor); pPlayer->GetShotCounter()->RecordShot(); #endif if (!isLocal) { NetShoot(params.hit, 0, params.fireModeId); } CHANGED_NETWORK_STATE(this, ASPECT_STREAM); } #ifdef SERVER_CHECKS CGameRules * pGameRules = static_cast<CGameRules*>(g_pGame->GetGameRules()); if(pGameRules) //really we should assert here. I struggle to think of a situation where someone is requesting a shot but there are no GameRules... { IGameRulesDamageHandlingModule * pDamageHandler = pGameRules->GetDamageHandlingModule(); assert(pDamageHandler); pDamageHandler->RegisterShotIdentification(pActor->GetEntityId(), this, params.shotId); } #endif return true; }
//------------------------------------------------------------------------ IMPLEMENT_RMI(CWeapon, SvStartedCharging) { CHECK_OWNER_REQUEST(); if(CFireMode* pFireMode = static_cast<CFireMode*>(GetFireMode(GetCurrentFireMode()))) { pFireMode->NetSetCharging(true); CHANGED_NETWORK_STATE(this, ASPECT_CHARGING); } return true; }
//------------------------------------------------------------------------ IMPLEMENT_RMI(CWeapon, SvRequestSetZoomState) { CHECK_OWNER_REQUEST(); if (params.zoomed) StartZoom(m_owner.GetId(), 1); else StopZoom(m_owner.GetId()); CHANGED_NETWORK_STATE(this, ASPECT_STREAM); return true; }
IMPLEMENT_RMI(CHeavyMountedWeapon, SvRequestRipOff) { CHECK_OWNER_REQUEST(); if (!m_rippingOff && !m_rippedOff) { PerformRipOff(GetOwnerActor()); CHANGED_NETWORK_STATE(this, ASPECT_RIPOFF); } return true; }
//------------------------------------------------------------------------ IMPLEMENT_RMI(CWeapon, SvRequestStopFire) { CHECK_OWNER_REQUEST(); CActor *pActor=GetActorByNetChannel(pNetChannel); IActor *pLocalActor=m_pGameFramework->GetClientActor(); bool isLocal = pLocalActor && pActor && (pLocalActor->GetChannelId() == pActor->GetChannelId()); if (!isLocal) { NetSetIsFiring(false); NetStopFire(); } return true; }
//------------------------------------------------------------------------ IMPLEMENT_RMI(CWeapon, SvRequestStartMeleeAttack) { CHECK_OWNER_REQUEST(); CActor *pActor=GetActorByNetChannel(pNetChannel); IActor *pLocalActor=m_pGameFramework->GetClientActor(); bool isLocal = pLocalActor && pActor && (pLocalActor->GetChannelId() == pActor->GetChannelId()); if (!isLocal) { NetStartMeleeAttack(params.boostedAttack, params.attackIndex); } m_attackIndex = params.attackIndex; m_meleeCounter = (m_meleeCounter + 1) % kMeleeCounterMax; CHANGED_NETWORK_STATE(this, ASPECT_MELEE); return true; }
//------------------------------------------------------------------------ IMPLEMENT_RMI(CWeapon, SvRequestShootEx) { CHECK_OWNER_REQUEST(); bool ok=true; CActor *pActor=GetActorByNetChannel(pNetChannel); if (!pActor || pActor->IsDead()) { ok=false; } #ifdef SERVER_CHECKS CAntiCheatManager * pAntiCheatManager = static_cast<CAntiCheatManager*>(g_pGame->GetAntiCheatManager()); bool validatePrediction = pAntiCheatManager ? pAntiCheatManager->GetAntiCheatVar(eAV_IP_UseTest_ValidatePredicatedSpawn, 1) != 0 : false; if(ok && validatePrediction && params.predictionHandle) { CFireMode *pFireMode = (CFireMode*)GetFireMode(params.fireModeId); if (pFireMode) { const SFireModeParams *pFireModeParams = pFireMode->GetShared(); if(pFireModeParams) { IEntityClass *pAmmoClass = pFireModeParams->fireparams.ammo_type_class; if(pAmmoClass) { int totalAmmoCount = GetAmmoCount(pAmmoClass) + GetInventoryAmmoCount(pAmmoClass); if(totalAmmoCount <= 0) { CryLog("actor %s does not have enough ammo for predicted spawn of %s, not spawning...", pActor->GetEntity()->GetName(), pAmmoClass->GetName()); ok = false; } } } } } #endif if (ok) { m_fireCounter++; m_expended_ammo++; IActor *pLocalActor=m_pGameFramework->GetClientActor(); bool isLocal = pLocalActor && (pLocalActor->GetChannelId() == pActor->GetChannelId()); if (!isLocal) { NetShootEx(params.pos, params.dir, params.vel, params.hit, params.extra, params.predictionHandle, params.fireModeId); } CHANGED_NETWORK_STATE(this, ASPECT_STREAM); } else { if(params.predictionHandle) { CGameRules::SPredictionParams predictionParams(params.predictionHandle); g_pGame->GetGameRules()->GetGameObject()->InvokeRMI(CGameRules::ClPredictionFailed(), predictionParams, eRMI_ToClientChannel, m_pGameFramework->GetGameChannelId(pNetChannel)); } } return true; }