void PlayerHandler::TeleportPlayer(int playerid, WorldPositionObject pos) { SetPlayerVirtualWorld(playerid, pos.virtualWorld_); SetPlayerInterior(playerid, pos.sampInteriorId_); SetPlayerPos(playerid, pos.x_, pos.y_, pos.z_); if (GetPlayerState(playerid) == 2) { int vehicleId = GetPlayerVehicleID(playerid); LinkVehicleToInterior(vehicleId, pos.sampInteriorId_); SetVehicleVirtualWorld(vehicleId, pos.virtualWorld_); SetVehiclePos(vehicleId, pos.x_, pos.y_, pos.z_); PutPlayerInVehicle(playerid, vehicleId, 0); } SetPVarInt(playerid, "oldinterior", GetPVarInt(playerid, "currentinterior")); SetPVarInt(playerid, "currentinterior", pos.interiorId_); }
// Returns true if the controller inflicting the damage is in the same team, false otherwise bool AMurphysLawCharacter::IsFriendlyFire(class AController* OtherController) const { // If the controller of the actor that hit me is a player controller auto OtherPlayerController = Cast<AMurphysLawPlayerController>(OtherController); if (OtherPlayerController && OtherPlayerController != GetController()) { // And if we both have a player state auto OtherPlayerState = Cast<AMurphysLawPlayerState>(OtherPlayerController->PlayerState); if (OtherPlayerState && GetPlayerState()) { // We check if we are on the same team return OtherPlayerState->GetTeam() == GetPlayerState()->GetTeam(); } } return false; }
TEST_F(TestBufferQueue, testEnqueueExtraBuffer) { for (unsigned i = 0; i < sizeof(validNumBuffers) / sizeof(validNumBuffers[0]); ++i) { SLuint32 numBuffers = validNumBuffers[i]; PrepareValidBuffer(numBuffers); EnqueueMaxBuffer(numBuffers); EnqueueExtraBuffer(numBuffers); GetPlayerState(SL_PLAYSTATE_STOPPED); DestroyPlayer(); } }
void YouTubeWebPageView::CheckSeekToStart() { if (IsPlayerError()) return; // ignore state changes when already in error state T_enPlayerState enState = GetPlayerState(); if (playerStateUnknown == enState) return; ATLASSERT(enState == playerStateVideoCued || enState == playerStatePlaying || enState == playerStateBuffering); // pause video when at correct time index if (GetCurrentTime() >= m_dSeconds && enState == playerStatePlaying) PauseVideo(); }
double YouTubeWebPageView::GetDuration() { T_enPlayerState enState = GetPlayerState(); if (enState != playerStateVideoCued && enState != playerStatePlaying && enState != playerStateBuffering) return 1.0; CComVariant varResult; CallFunction(_T("getDuration"), std::vector<CComVariant>(), varResult); if (varResult.vt != VT_R8) return -1.0; return varResult.dblVal; }
void PAPlayer::CloseFileCB(StreamInfo &si) { IPlayerCallback *cb = &m_callback; CFileItem fileItem(si.m_fileItem); CBookmark bookmark; double total = si.m_decoder.TotalTime(); if (si.m_endOffset) total = si.m_endOffset; total -= si.m_startOffset; bookmark.totalTimeInSeconds = total / 1000; bookmark.timeInSeconds = (static_cast<double>(si.m_framesSent) / static_cast<double>(si.m_audioFormat.m_sampleRate)); bookmark.timeInSeconds -= si.m_stream->GetDelay(); bookmark.player = m_name; bookmark.playerState = GetPlayerState(); CJobManager::GetInstance().Submit([=]() { cb->OnPlayerCloseFile(fileItem, bookmark); }, CJob::PRIORITY_NORMAL); }
void udtPatternSearchPlugIn::ProcessSnapshotMessage(const udtSnapshotCallbackArg& info, udtBaseParser& parser) { const udtPatternSearchArg pi = GetInfo(); if(pi.PlayerIndex == (s32)udtPlayerIndex::FirstPersonPlayer) { idPlayerStateBase* const ps = GetPlayerState(info.Snapshot, parser._inProtocol); if(ps != NULL) { _trackedPlayerIndex = ps->clientNum; } } else if(pi.PlayerIndex == S32_MIN && pi.PlayerNameRules != NULL) { FindPlayerInConfigStrings(parser); } for(u32 i = 0, count = _analyzers.GetSize(); i < count; ++i) { _analyzers[i]->ProcessSnapshotMessage(info, parser); } }
// Update the statistics of players involved in the death void AMurphysLawCharacter::UpdateStatsOnKill(AController* InstigatedBy, AActor* DamageCauser) { AMurphysLawGameState* GameState = GetWorld()->GetGameState<AMurphysLawGameState>(); FString DeathMessage = ""; // Try to cast the DamageCauser to DamageZone to see if the player committed suicide auto DamageZone = Cast<AMurphysLawDamageZone>(DamageCauser); // Does the player committed suicide? if (InstigatedBy == GetController() || DamageCausedByDamageZone(DamageCauser)) { InstigatedBy = GetController(); DeathMessage = FString::Printf(TEXT("%s committed suicide."), *GetHumanReadableName()); if (GetPlayerState()) GetPlayerState()->IncrementNbDeaths(); if (GameState) GameState->PlayerCommitedSuicide(GetPlayerState()->GetTeam() == AMurphysLawGameMode::TEAM_A); } else if (IsFriendlyFire(InstigatedBy) && DamageCausedByExplosive(DamageCauser)) { // Or was he killed by a teammate because of explosion? DeathMessage = FString::Printf(TEXT("%s was killed by a teammate."), *GetHumanReadableName()); if (GetPlayerState()) GetPlayerState()->IncrementNbDeaths(); if (GameState) GameState->PlayerKilledTeammate(GetPlayerState()->GetTeam() == AMurphysLawGameMode::TEAM_A); } else { // If the player was killed by somebody else if (InstigatedBy) { DeathMessage = FString::Printf(TEXT("%s was killed by %s"), *GetHumanReadableName(), *InstigatedBy->GetHumanReadableName()); // Increment the number of kills of the other player auto OtherPlayerState = Cast<AMurphysLawPlayerState>(InstigatedBy->PlayerState); if (OtherPlayerState) OtherPlayerState->IncrementNbKills(); // And increment the number of deaths of the current player if (GetPlayerState()) GetPlayerState()->IncrementNbDeaths(); if (GameState) { if (GetPlayerState()) { GameState->PlayerWasKilled(OtherPlayerState->GetTeam() == AMurphysLawGameMode::TEAM_A); } else ShowError("PlayerState is null"); } else ShowError("GameState is null"); } } AMurphysLawGameMode* GameMode = Cast<AMurphysLawGameMode>(GetWorld()->GetAuthGameMode()); if (GameMode && DeathMessage != "") GameMode->SendDeathMessage(Cast<AMurphysLawPlayerController>(InstigatedBy), DeathMessage); }
void SetPlayerState(SLuint32 state) { res = (*playerPlay)->SetPlayState(playerPlay, state); CheckErr(res); //verify the state can set correctly GetPlayerState(state); }
void CGameContext::ConSwap(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *) pUserData; const int ClientID = pResult->m_ClientID; if(!g_Config.m_SvSwap) { pSelf->SendChatTarget(ClientID, "Swap is not activated"); return; } int ToSwap = pResult->GetVictim(); if(!CheckClientID(ToSwap) || ClientID == ToSwap) ToSwap = -1; if(!CheckClientID(ClientID)) return; pSelf->m_aSwapRequest[ClientID] = ToSwap; if(ToSwap == -1) return; if(pSelf->ProcessSpamProtection(ClientID)) // dont flood return; // check if ToSwap agrees char aBuf[128]; if(pSelf->m_aSwapRequest[ToSwap] != ClientID) { // send notification to ToSwap str_format(aBuf, sizeof(aBuf), "%s wants to swap places with you. Type \'/swap %d\' to accept.", pSelf->Server()->ClientName(ClientID), ClientID); pSelf->SendChatTarget(ToSwap, aBuf); str_format(aBuf, sizeof(aBuf), "Requst sent to %s.", pSelf->Server()->ClientName(ToSwap)); pSelf->SendChatTarget(ClientID, aBuf); } else { // ToSwap agreed CCharacter * pChar1 = pSelf->GetPlayerChar(ClientID); CCharacter * pChar2 = pSelf->GetPlayerChar(ToSwap); if(!pChar1 || !pChar2 || pChar1->Team() != pChar2->Team()) { // one is not alive or not in the same team const char * pStr = "Can\'t swap!"; pSelf->SendChatTarget(ToSwap, pStr); pSelf->SendChatTarget(ClientID, pStr); return; } CPlayerRescueState state1 = GetPlayerState(pChar1), state2 = GetPlayerState(pChar2); // swap ApplyPlayerState(state2, pChar1); ApplyPlayerState(state1, pChar2); str_format(aBuf, sizeof(aBuf), "%s swapped with %s.", pSelf->Server()->ClientName(ToSwap), pSelf->Server()->ClientName(ClientID)); pSelf->SendChat(-1, CGameContext::CHAT_ALL, aBuf); // reset swap requests pSelf->m_aSwapRequest[ToSwap] = -1; pSelf->m_aSwapRequest[ClientID] = -1; } }
void Streamer::performPlayerUpdate(Player &player, bool automatic) { Eigen::Vector3f delta = Eigen::Vector3f::Zero(), position = player.position; int state = GetPlayerState(player.playerID); bool update = true; if (automatic) { player.interiorID = GetPlayerInterior(player.playerID); player.worldID = GetPlayerVirtualWorld(player.playerID); GetPlayerPos(player.playerID, &player.position[0], &player.position[1], &player.position[2]); if (state != PLAYER_STATE_NONE && state != PLAYER_STATE_WASTED) { if (player.position != position) { position = player.position; Eigen::Vector3f velocity = Eigen::Vector3f::Zero(); if (state == PLAYER_STATE_ONFOOT) { GetPlayerVelocity(player.playerID, &velocity[0], &velocity[1], &velocity[2]); } else if (state == PLAYER_STATE_DRIVER || state == PLAYER_STATE_PASSENGER) { GetVehicleVelocity(GetPlayerVehicleID(player.playerID), &velocity[0], &velocity[1], &velocity[2]); } float velocityNorm = velocity.squaredNorm(); if (velocityNorm >= velocityBoundaries.get<0>() && velocityNorm <= velocityBoundaries.get<1>()) { delta = velocity * averageUpdateTime; player.position += delta; } } else { update = player.updateWhenIdle; } } else { update = false; } } std::vector<SharedCell> cells; if (update) { core->getGrid()->findAllCells(player, cells); if (!cells.empty()) { if (!core->getData()->objects.empty() && player.enabledItems[STREAMER_TYPE_OBJECT] && !IsPlayerNPC(player.playerID)) { processObjects(player, cells); } if (!core->getData()->checkpoints.empty() && player.enabledItems[STREAMER_TYPE_CP]) { processCheckpoints(player, cells); } if (!core->getData()->raceCheckpoints.empty() && player.enabledItems[STREAMER_TYPE_RACE_CP]) { processRaceCheckpoints(player, cells); } if (!core->getData()->mapIcons.empty() && player.enabledItems[STREAMER_TYPE_MAP_ICON] && !IsPlayerNPC(player.playerID)) { processMapIcons(player, cells); } if (!core->getData()->textLabels.empty() && player.enabledItems[STREAMER_TYPE_3D_TEXT_LABEL] && !IsPlayerNPC(player.playerID)) { processTextLabels(player, cells); } if (!core->getData()->areas.empty() && player.enabledItems[STREAMER_TYPE_AREA]) { if (!delta.isZero()) { player.position = position; } processAreas(player, cells); if (!delta.isZero()) { player.position += delta; } } } } if (automatic) { if (!core->getData()->pickups.empty()) { if (!update) { core->getGrid()->findMinimalCells(player, cells); } processPickups(player, cells); } if (!delta.isZero()) { player.position = position; } executeCallbacks(); } }
bool udtBaseParser::ParseSnapshot() { // // Read in the new snapshot to a temporary buffer // We will only save it if it is valid. // We will have read any new server commands in this // message before we got to svc_snapshot. // if(_inProtocol == udtProtocol::Dm3) { _inMsg.ReadLong(); // Client command sequence. } _inServerTime = _inMsg.ReadLong(); idLargestClientSnapshot newSnap; Com_Memset(&newSnap, 0, sizeof(newSnap)); newSnap.serverCommandNum = _inServerCommandSequence; newSnap.serverTime = _inServerTime; newSnap.messageNum = _inServerMessageSequence; s32 deltaNum = _inMsg.ReadByte(); if(!deltaNum) { newSnap.deltaNum = -1; } else { newSnap.deltaNum = newSnap.messageNum - deltaNum; } newSnap.snapFlags = _inMsg.ReadByte(); // // If the frame is delta compressed from data that we // no longer have available, we must suck up the rest of // the frame, but not use it, then ask for a non-compressed // message. // idClientSnapshotBase* oldSnap; if(newSnap.deltaNum <= 0) { newSnap.valid = true; // Uncompressed frame. oldSnap = NULL; } else { if(deltaNum >= PACKET_BACKUP) { _context->LogWarning("udtBaseParser::ParseSnapshot: deltaNum %d invalid.", deltaNum); } if(newSnap.deltaNum > _inServerMessageSequence) { _context->LogWarning("udtBaseParser::ParseSnapshot: Need delta from read ahead."); } oldSnap = GetClientSnapshot(newSnap.deltaNum & PACKET_MASK); if(!oldSnap->valid) { // Should never happen. _context->LogWarning("udtBaseParser::ParseSnapshot: Delta from invalid frame %d (not supposed to happen!).", deltaNum); } else if(oldSnap->messageNum != newSnap.deltaNum) { // The frame that the server did the delta from // is too old, so we can't reconstruct it properly. _context->LogWarning("udtBaseParser::ParseSnapshot: Delta frame %d too old.", deltaNum); } else if(_inParseEntitiesNum - oldSnap->parseEntitiesNum > ID_MAX_PARSE_ENTITIES - 128) { _context->LogWarning("udtBaseParser::ParseSnapshot: Delta parseEntitiesNum %d too old.", _inParseEntitiesNum); } else { newSnap.valid = true; } } // // Read the area mask. // const s32 areaMaskLength = _inMsg.ReadByte(); if(areaMaskLength > (s32)sizeof(newSnap.areamask)) { _context->LogError("udtBaseParser::ParseSnapshot: Invalid size %d for areamask (in file: %s)", areaMaskLength, GetFileNamePtr()); return false; } _inMsg.ReadData(&newSnap.areamask, areaMaskLength); // Read the player info. if(!_inMsg.ReadDeltaPlayer(oldSnap ? GetPlayerState(oldSnap, _inProtocol) : NULL, GetPlayerState(&newSnap, _inProtocol))) { return false; } // Read in all entities. if(!ParsePacketEntities(_inMsg, oldSnap, &newSnap)) { return false; } // Did we write enough snapshots already? const bool noDelta = _outSnapshotsWritten < deltaNum; if(noDelta) { deltaNum = 0; oldSnap = NULL; } // If not valid, dump the entire thing now that // it has been properly read. if(!newSnap.valid) { return true; } // // Clear the valid flags of any snapshots between the last // received and this one, so if there was a dropped packet // it won't look like something valid to delta from next // time we wrap around in the buffer. // s32 oldMessageNum = _inSnapshot.messageNum + 1; if(newSnap.messageNum - oldMessageNum >= PACKET_BACKUP) { oldMessageNum = newSnap.messageNum - (PACKET_BACKUP - 1); } for(; oldMessageNum < newSnap.messageNum; ++oldMessageNum) { GetClientSnapshot(oldMessageNum & PACKET_MASK)->valid = false; } // Copy to the current good spot. _inSnapshot = newSnap; // Save the frame off in the backup array for later delta comparisons. Com_Memcpy(GetClientSnapshot(_inSnapshot.messageNum & PACKET_MASK), &_inSnapshot, (size_t)_inProtocolSizeOfClientSnapshot); // Don't give the same stuff to the plug-ins more than once. if(newSnap.messageNum == _inLastSnapshotMessageNumber) { return true; } _inLastSnapshotMessageNumber = newSnap.messageNum; // // Process plug-ins now so that modifiers can alter the snapshots. // if(EnablePlugIns && !PlugIns.IsEmpty()) { udtSnapshotCallbackArg info; info.ServerTime = _inServerTime; info.SnapshotArrayIndex = _inSnapshot.messageNum & PACKET_MASK; info.Snapshot = &newSnap; info.OldSnapshot = oldSnap; info.Entities = _inChangedEntities.GetStartAddress(); info.EntityCount = _inChangedEntities.GetSize(); info.RemovedEntities = _inRemovedEntities.GetStartAddress(); info.RemovedEntityCount = _inRemovedEntities.GetSize(); info.CommandNumber = newSnap.serverCommandNum; info.MessageNumber = newSnap.messageNum; for(u32 i = 0, count = PlugIns.GetSize(); i < count; ++i) { PlugIns[i]->ProcessSnapshotMessage(info, *this); } } // // Write to the output message. // if(ShouldWriteMessage()) { _outMsg.WriteByte(svc_snapshot); _outMsg.WriteLong(newSnap.serverTime); _outMsg.WriteByte(deltaNum); _outMsg.WriteByte(newSnap.snapFlags); _outMsg.WriteByte(areaMaskLength); _outMsg.WriteData(&newSnap.areamask, areaMaskLength); _protocolConverter->StartSnapshot(newSnap.serverTime); if(_outProtocol == _inProtocol) { _outMsg.WriteDeltaPlayer(oldSnap ? GetPlayerState(oldSnap, _outProtocol) : NULL, GetPlayerState(&newSnap, _outProtocol)); EmitPacketEntities(deltaNum ? oldSnap : NULL, &newSnap); } else { idLargestClientSnapshot oldSnapOutProto; idLargestClientSnapshot newSnapOutProto; if(oldSnap) { _protocolConverter->ConvertSnapshot(oldSnapOutProto, *oldSnap); } _protocolConverter->ConvertSnapshot(newSnapOutProto, newSnap); _outMsg.WriteDeltaPlayer(oldSnap ? GetPlayerState(&oldSnapOutProto, _outProtocol) : NULL, GetPlayerState(&newSnapOutProto, _outProtocol)); EmitPacketEntities(deltaNum ? &oldSnapOutProto : NULL, &newSnapOutProto); } ++_outSnapshotsWritten; } return true; }