void CLocalPlayer::DoDeathCheck() { // Have we not yet processed the death and is the local player dead? if(!CLocalPlayer::m_bIsDead && IsDead()) { // Get the kill info EntityId playerId = INVALID_ENTITY_ID; EntityId vehicleId = INVALID_ENTITY_ID; EntityId weaponId = INVALID_ENTITY_ID; GetKillInfo(&playerId, &vehicleId,&weaponId); CLogFile::Printf("HandleDeath(LocalPlayer, %d, %d, %d)", playerId, vehicleId, weaponId); g_pCore->GetChat()->Outputf(false, "HandleDeath(LocalPlayer, %d, %d, %d)", playerId, vehicleId, weaponId); // Send the death notification to the server CBitStream bsSend; bsSend.WriteCompressed(playerId); bsSend.WriteCompressed(vehicleId); bsSend.WriteCompressed(weaponId); //g_pCore->GetNetworkManager()->Call(NULL, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, 0, false); // Mark ourselves as dead CLocalPlayer::m_bIsDead = true; // Delete the object CIVScript::DeleteObject(&m_pObj); // Reset vehicle entry/exit flags SetExitFlag(true); ResetVehicleEnterExit(); // Get current day time so we don't have to set the time always.. CGameFunction::GetTime(&m_iRespawnTime[0], &m_iRespawnTime[1]); } }
void CObjectManager::HandleClientJoin(EntityId playerId) { if(GetObjectCount() > 0) { CBitStream bsSend; for(EntityId x = 0; x < MAX_OBJECTS; x++) { if(m_bActive[x]) { bsSend.WriteCompressed(x); bsSend.Write(m_Objects[x].dwModelHash); bsSend.Write(m_Objects[x].vecPosition); bsSend.Write(m_Objects[x].vecRotation); bsSend.Write(m_Objects[x].bAttached); bsSend.Write(m_Objects[x].bVehicleAttached); bsSend.Write(m_Objects[x].uiVehiclePlayerId); bsSend.Write(m_Objects[x].vecAttachPosition); bsSend.Write(m_Objects[x].vecAttachRotation); if(m_Objects[x].iBone == -1) bsSend.Write0(); else { bsSend.Write1(); bsSend.Write(m_Objects[x].iBone); } this->SetDimension(x, this->GetDimension(x)); } } g_pNetworkManager->RPC(RPC_NewObject, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, playerId, false); } }
LabelId C3DLabelManager::Add(const String& text, const CVector3& vecPosition, DWORD dwColor, bool bVisible, float fStreamingDistance) { for(LabelId i = 0; i < MAX_3D_LABELS; i++) { if(!DoesExist(i)) { m_Labels[i] = new C3DLabel(i, text, vecPosition, dwColor, bVisible, fStreamingDistance); m_Labels[i]->SetText(text); m_Labels[i]->SetPosition(vecPosition); m_Labels[i]->SetVisible(true); CBitStream bsSend; bsSend.WriteCompressed(i); bsSend.Write(m_Labels[i]->GetText()); bsSend.Write(m_Labels[i]->GetPosition()); bsSend.Write(m_Labels[i]->GetColor()); bsSend.Write(m_Labels[i]->GetStreamingDistance()); bsSend.Write(m_Labels[i]->GetDimension()); bsSend.WriteBit(m_Labels[i]->IsVisible()); g_pNetworkManager->RPC(RPC_New3DLabel, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, true); return i; } } return MAX_3D_LABELS; /* INVALID ID */ }
void CObjectManager::AttachToPlayer(EntityId objectId, EntityId playerId, const CVector3& vecPos, const CVector3& vecRot, int iBone) { if(DoesExist(objectId)) { m_Objects[objectId].bAttached = true; m_Objects[objectId].bVehicleAttached = false; m_Objects[objectId].uiVehiclePlayerId = playerId; m_Objects[objectId].vecAttachPosition = vecPos; m_Objects[objectId].vecAttachRotation = vecRot; m_Objects[objectId].iBone = iBone; CBitStream bsSend; bsSend.WriteCompressed(objectId); bsSend.Write(m_Objects[objectId].bAttached); bsSend.Write(m_Objects[objectId].bVehicleAttached); bsSend.Write(m_Objects[objectId].uiVehiclePlayerId); bsSend.Write(m_Objects[objectId].vecAttachPosition); bsSend.Write(m_Objects[objectId].vecAttachRotation); if(iBone != -1) { bsSend.Write1(); bsSend.Write(m_Objects[objectId].iBone); } else bsSend.Write0(); g_pNetworkManager->RPC(RPC_ScriptingAttachObject,&bsSend,PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, true); } }
void CPlayerManager::HandleClientJoin(EntityId playerId) { if(GetPlayerCount() > 1) { for(EntityId x = 0; x < MAX_PLAYERS; x++) { if(m_bActive[x] && x != playerId) { m_pPlayers[x]->AddForPlayer(playerId); m_pPlayers[x]->SpawnForPlayer(playerId); if(g_pBlipManager->DoesPlayerBlipExist(x)) { CBitStream bsSend; bsSend.WriteCompressed(x); bsSend.Write(g_pBlipManager->GetPlayerBlipSprite(x)); bsSend.Write(true); bsSend.Write(g_pBlipManager->GetPlayerBlipShow(x)); g_pNetworkManager->RPC(RPC_ScriptingCreatePlayerBlip, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, playerId, true); bsSend.Reset(); } m_pPlayers[x]->SetDimension(m_pPlayers[x]->GetDimension()); } else if(x == playerId) { m_pPlayers[x]->SetDimension(m_pPlayers[x]->GetDimension()); } } } }
void CServerRPCHandler::PlayerSync(CBitStream * pBitStream, CPlayerSocket senderSocket) { // Ensure we have a valid bitstream if(!pBitStream) { CLogFile::Printf("Warning: Invalid bitstream for PlayerSync RPC"); return; } // Get the player pointer CPlayer * pPlayer = g_pServer->GetPlayerManager()->Get(senderSocket.playerId); // Is the player pointer valid? if(pPlayer) { // Deserialize the player from the bit stream pPlayer->Deserialize(pBitStream); // Construct the bit stream CBitStream bitStream; // Write the player id bitStream.WriteCompressed(pPlayer->GetPlayerId()); // Serialize the player to the bit stream pPlayer->Serialize(&bitStream); // Send it to all other players g_pServer->GetNetworkManager()->RPC(RPC_PLAYER_SYNC, &bitStream, PRIORITY_LOW, RELIABILITY_UNRELIABLE_SEQUENCED, senderSocket.playerId, true); } }
void CServerRPCHandler::ChatInput(CBitStream * pBitStream, CPlayerSocket senderSocket) { CLogFile::Printf("Got ChatInput RPC from player %d", senderSocket.playerId); // Ensure we have a valid bitstream if(!pBitStream) { CLogFile::Printf("Warning: Invalid bitstream for ChatInput RPC"); return; } // Get the player pointer CPlayer * pPlayer = g_pServer->GetPlayerManager()->Get(senderSocket.playerId); // Is the player pointer valid? if(pPlayer) { // Read the data they sent us bool bIsCommand; String strInput; // Read if its a command or not bIsCommand = pBitStream->ReadBit(); // Read the input if(!pBitStream->Read(strInput)) return; // Prepare the event arguments CSquirrelArguments arguments; arguments.push(strInput); // Is it not a command? if(!bIsCommand) { // Trigger the event, if it is canceled, don't output the line to other players if(pPlayer->CallEvent("playerChat", &arguments)) { // Construct the chat input bit stream CBitStream bitStream; // Write the player id bitStream.WriteCompressed(senderSocket.playerId); // Write the input bitStream.Write(strInput); // Send it to all other players g_pServer->GetNetworkManager()->RPC(RPC_CHAT_INPUT, &bitStream, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, true); } } else { // Trigger the event pPlayer->CallEvent("playerCommand", &arguments); } CLogFile::Printf("Recieved chat input from player %d (Command?: %s, Input: %s)", senderSocket.playerId, bIsCommand ? "Yes" : "No", strInput.C_String()); } }
EntityId CObjectManager::Create(DWORD dwModelHash, const CVector3& vecPosition, const CVector3& vecRotation) { for(EntityId x = 0; x < MAX_OBJECTS; x++) { if(!m_bActive[x]) { CBitStream bsSend; bsSend.WriteCompressed(x); bsSend.Write(dwModelHash); bsSend.Write(vecPosition); bsSend.Write(vecRotation); g_pNetworkManager->RPC(RPC_NewObject, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, true); m_Objects[x].dwModelHash = dwModelHash; m_Objects[x].vecPosition = vecPosition; m_Objects[x].vecRotation = vecRotation; m_bActive[x] = true; m_Objects[x].iBone = -1; CSquirrelArguments pArguments; pArguments.push(x); g_pEvents->Call("objectCreate", &pArguments); return x; } } return INVALID_ENTITY_ID; }
void CServerRPCHandler::Chat(CBitStream * pBitStream, CPlayerSocket * pSenderSocket) { // Ensure we have a valid bit stream if(!pBitStream) return; EntityId playerId = pSenderSocket->playerId; CPlayer * pPlayer = g_pPlayerManager->GetAt(playerId); if(pPlayer) { String strChat; if(!pBitStream->Read(strChat)) return; strChat.Truncate(128); CSquirrelArguments pArguments; pArguments.push(playerId); pArguments.push(strChat); if(g_pEvents->Call("playerText", &pArguments).GetInteger() == 1) { CLogFile::Printf("[Chat] %s: %s", pPlayer->GetName().C_String(), strChat.Get()); CBitStream bsSend; bsSend.WriteCompressed(playerId); bsSend.Write(String(strChat)); g_pNetworkManager->RPC(RPC_Chat, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, true); } } }
void C3DLabel::SetPosition(const CVector3& vecPosition) { m_vecPosition = vecPosition; CBitStream bsSend; bsSend.WriteCompressed(m_labelId); bsSend.Write(m_vecPosition); g_pNetworkManager->RPC(RPC_ScriptingSet3DLabelPosition, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, false); }
void C3DLabel::SetDimension(DimensionId dimensionId) { m_dimensionId = dimensionId; CBitStream bsSend; bsSend.WriteCompressed(m_labelId); bsSend.Write(dimensionId); g_pNetworkManager->RPC(RPC_ScriptingSet3DLabelDimension, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, false); }
void C3DLabel::SetStreamingDistance(float fDistance) { m_fStreamingDistance = fDistance; CBitStream bsSend; bsSend.WriteCompressed(m_labelId); bsSend.Write(m_fStreamingDistance); g_pNetworkManager->RPC(RPC_ScriptingSet3DLabelStreamingDistance, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, false); }
void C3DLabel::SetVisible(bool bVisible) { m_bVisible = bVisible; CBitStream bsSend; bsSend.WriteCompressed(m_labelId); bsSend.Write(m_bVisible); g_pNetworkManager->RPC(RPC_ScriptingSet3DLabelVisible, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, false); }
void C3DLabel::SetColor(DWORD dwColor) { m_dwColor = dwColor; CBitStream bsSend; bsSend.WriteCompressed(m_labelId); bsSend.Write(m_dwColor); g_pNetworkManager->RPC(RPC_ScriptingSet3DLabelColor, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, false); }
void C3DLabel::SetText(const String& strText) { m_strText = strText; CBitStream bsSend; bsSend.WriteCompressed(m_labelId); bsSend.Write(m_strText); g_pNetworkManager->RPC(RPC_ScriptingSet3DLabelText, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, false); }
void CPlayer::DestroyForPlayer(EntityId playerId) { // Construct the BitStream CBitStream bitStream; bitStream.WriteCompressed(m_playerId); // Send it to the player g_pServer->GetNetworkManager()->RPC(RPC_DESTROY_PLAYER, &bitStream, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, playerId, false); }
void CVehicle::SetHealth(unsigned int uHealth) { m_uiHealth = uHealth; CBitStream bsSend; bsSend.WriteCompressed(m_vehicleId); bsSend.Write(uHealth); g_pNetworkManager->RPC(RPC_ScriptingSetVehicleHealth, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, true); }
void C3DLabelManager::Remove(LabelId id) { if(DoesExist(id)) { CBitStream bsSend; bsSend.WriteCompressed(id); g_pNetworkManager->RPC(RPC_Delete3DLabel, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, true); SAFE_DELETE(m_Labels[id]); } }
void CCheckpoint::SetDimension(unsigned char ucDimension) { m_ucDimension = ucDimension; CBitStream bsSend; bsSend.WriteCompressed(GetCheckpointId()); bsSend.Write(ucDimension); g_pNetworkManager->RPC(RPC_ScriptingSetCheckpointDimension, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, true); }
void CBlipManager::DeleteForPlayer(EntityId playerId) { // Check if we have a blip for the player if(!m_bPlayerActive[playerId]) return; CBitStream bsSend; bsSend.WriteCompressed(playerId); g_pNetworkManager->RPC(RPC_ScriptingRemovePlayerBlip, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, true); }
void CBlipManager::HandleClientJoin(EntityId playerId) { if(GetBlipCount() > 0) { CBitStream bsSend; for(EntityId x = 0; x < MAX_BLIPS; x++) { if(m_bActive[x]) { bsSend.WriteCompressed(x); bsSend.Write(m_Blips[x].iSprite); bsSend.Write(m_Blips[x].vecSpawnPos); bsSend.Write(m_Blips[x].uiColor); bsSend.Write(m_Blips[x].fSize); bsSend.Write(m_Blips[x].bShortRange); bsSend.Write(m_Blips[x].bRouteBlip); bsSend.Write(m_Blips[x].bShow); bsSend.Write(m_Blips[x].strName); g_pNetworkManager->RPC(RPC_NewBlip, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, playerId, false); bsSend.Reset(); } } } if(g_pPlayerManager->GetPlayerCount() > 0) { CBitStream bsSend; for(EntityId y = 0; y < MAX_PLAYERS; y++) { if(m_bPlayerActive[y]) { bsSend.WriteCompressed(y); bsSend.Write(m_PlayerBlips[y].iSprite); bsSend.Write(m_PlayerBlips[y].bShortRange); bsSend.Write(m_PlayerBlips[y].bShow); g_pNetworkManager->RPC(RPC_ScriptingCreatePlayerBlip, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, playerId, false); bsSend.Reset(); } } } }
void CObjectManager::SetInterior(EntityId objectId, int iInterior) { if(DoesExist(objectId)) { m_Objects[objectId].m_iInterior = iInterior; CBitStream bsSend; bsSend.WriteCompressed(objectId); bsSend.Write(iInterior); g_pNetworkManager->RPC(RPC_ScriptingSetObjectInterior, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, true); } }
void CObjectManager::SetDimension(EntityId objectId, unsigned char ucDimension) { if(DoesExist(objectId)) { m_Objects[objectId].ucDimension = ucDimension; CBitStream bsSend; bsSend.WriteCompressed(objectId); bsSend.Write(ucDimension); g_pNetworkManager->RPC(RPC_ScriptingSetObjectDimension, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, true); } }
void CObjectManager::RotateObject(EntityId objectId, const CVector3& vecMoveRot, int iTime) { if(DoesExist(objectId)) { CBitStream bsSend; bsSend.WriteCompressed(objectId); bsSend.Write(vecMoveRot); bsSend.Write(iTime); m_Objects[objectId].vecRotation = vecMoveRot; g_pNetworkManager->RPC(RPC_ScriptingRotateObject, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, true); } }
void CBlipManager::TogglePlayerShortRangeForPlayer(EntityId playerId, EntityId toPlayerId, bool bToggle) { // Check if we have a blip for the player if(!m_bPlayerActive[playerId]) return; CBitStream bsSend; bsSend.WriteCompressed(playerId); bsSend.Write(m_PlayerBlips[playerId].iSprite); bsSend.Write(bToggle); bsSend.Write(m_PlayerBlips[playerId].bShow); g_pNetworkManager->RPC(RPC_ScriptingChangePlayerBlip, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, toPlayerId, false); }
void CObjectManager::Delete(EntityId objectId) { if(!m_bActive[objectId]) return; CSquirrelArguments pArguments; pArguments.push(objectId); g_pEvents->Call("objectDelete", &pArguments); CBitStream bsSend; bsSend.WriteCompressed(objectId); g_pNetworkManager->RPC(RPC_DeleteObject, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, true); m_bActive[objectId] = false; }
void CBlipManager::Delete(EntityId blipId) { if(!DoesExist(blipId)) return; CSquirrelArguments pArguments; pArguments.push(blipId); g_pEvents->Call("blipDelete", &pArguments); CBitStream bsSend; bsSend.WriteCompressed(blipId); g_pNetworkManager->RPC(RPC_DeleteBlip, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, true); m_bActive[blipId] = false; }
void CBlipManager::SetSpriteForPlayer(EntityId playerId, int iToggle) { // Check if we have a blip for the player if(!m_bPlayerActive[playerId]) return; m_PlayerBlips[playerId].iSprite = iToggle; CBitStream bsSend; bsSend.WriteCompressed(playerId); bsSend.Write(m_PlayerBlips[playerId].iSprite); bsSend.Write(m_PlayerBlips[playerId].bShortRange); bsSend.Write(m_PlayerBlips[playerId].bShow); g_pNetworkManager->RPC(RPC_ScriptingChangePlayerBlip, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, true); }
void CObjectManager::Detach(EntityId objectId) { if(DoesExist(objectId)) { m_Objects[objectId].bAttached = false; m_Objects[objectId].bVehicleAttached = false; m_Objects[objectId].uiVehiclePlayerId = INVALID_ENTITY_ID; m_Objects[objectId].vecAttachPosition = CVector3(); m_Objects[objectId].vecAttachRotation = CVector3(); m_Objects[objectId].iBone = -1; CBitStream bsSend; bsSend.WriteCompressed(objectId); g_pNetworkManager->RPC(RPC_ScriptingDetachObject,&bsSend,PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, true); } }
bool CObjectManager::SetRotation(EntityId objectId, const CVector3& vecRotation) { if(DoesExist(objectId)) { m_Objects[objectId].vecRotation = vecRotation; CBitStream bsSend; bsSend.WriteCompressed(objectId); bsSend.Write(vecRotation); g_pNetworkManager->RPC(RPC_ScriptingSetObjectRotation, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, true); return true; } return false; }