Skip to content

Commit

Permalink
Remove unnecessary presence updates
Browse files Browse the repository at this point in the history
We handle presence state updates primarily in CClientGame::DoPulsePostFrame() now
  • Loading branch information
Lpsd committed Oct 13, 2023
1 parent 148fb34 commit b67d252
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 119 deletions.
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,8 @@ void CClientGame::DoPulsePostFrame()

m_timeLastDiscordStateUpdate = time(nullptr);
}
else
discord->SetPresenceState("In-game", false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ struct SVehicleComponentData
bool m_bVisible;
};

const std::map<eClientVehicleType, std::string> g_vehicleTypePrefixes{
static const std::map<eClientVehicleType, std::string> g_vehicleTypePrefixes{
{CLIENTVEHICLE_CAR, "Cruising around"}, {CLIENTVEHICLE_PLANE, "Flying around"}, {CLIENTVEHICLE_BIKE, "Riding around"},
{CLIENTVEHICLE_HELI, "Flying around"}, {CLIENTVEHICLE_BOAT, "Riding the waves of"}, {CLIENTVEHICLE_TRAIN, "Riding the train in"},
{CLIENTVEHICLE_TRAILER, "Doing weird stuff in"}, {CLIENTVEHICLE_BMX, "Bunny hopping around"}, {CLIENTVEHICLE_MONSTERTRUCK, "Monster truckin' around"},
Expand Down
100 changes: 0 additions & 100 deletions Client/mods/deathmatch/logic/CPacketHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,18 +1136,6 @@ void CPacketHandler::Packet_PlayerSpawn(NetBitStreamInterface& bitStream)

// Reset return position so we can't warp back to where we were if local player
g_pClientGame->m_pNetAPI->ResetReturnPosition();

auto discord = g_pCore->GetDiscord();
if (discord->IsDiscordRPCEnabled())
{
CVector position;
SString zoneName;

pPlayer->GetPosition(position);
CStaticFunctionDefinitions::GetZoneName(position, zoneName, true);

discord->SetPresenceState(SString("Walking around %s", zoneName.c_str()), false);
}
}
else
{
Expand Down Expand Up @@ -1783,22 +1771,6 @@ void CPacketHandler::Packet_Vehicle_InOut(NetBitStreamInterface& bitStream)
Arguments2.PushElement(pPed); // player / ped
Arguments2.PushNumber(ucSeat); // seat
pVehicle->CallEvent("onClientVehicleEnter", Arguments2, true);

if (pPed->IsLocalPlayer())
{
auto discord = g_pCore->GetDiscord();
if (discord->IsDiscordRPCEnabled())
{
CVector position;
SString zoneName;

pPed->GetPosition(position);
CStaticFunctionDefinitions::GetZoneName(position, zoneName, true);

eClientVehicleType vehicleType = CClientVehicleManager::GetVehicleType(pVehicle->GetModel());
discord->SetPresenceState(SString("%s %s", g_vehicleTypePrefixes.at(vehicleType).c_str(), zoneName.c_str()), false);
}
}
break;
}

Expand Down Expand Up @@ -1924,21 +1896,6 @@ void CPacketHandler::Packet_Vehicle_InOut(NetBitStreamInterface& bitStream)
Arguments2.PushNumber(ucSeat); // seat
Arguments2.PushBoolean(false); // jacker
pVehicle->CallEvent("onClientVehicleExit", Arguments2, true);

if (pPed->IsLocalPlayer())
{
auto discord = g_pCore->GetDiscord();
if (discord->IsDiscordRPCEnabled())
{
CVector position;
SString zoneName;

pPed->GetPosition(position);
CStaticFunctionDefinitions::GetZoneName(position, zoneName, true);
discord->SetPresenceState(SString("Walking around %s", zoneName.c_str()), false);
}
}

break;
}

Expand Down Expand Up @@ -1986,22 +1943,6 @@ void CPacketHandler::Packet_Vehicle_InOut(NetBitStreamInterface& bitStream)
Arguments2.PushNumber(ucSeat); // seat
Arguments2.PushBoolean(false); // jacker
pVehicle->CallEvent("onClientVehicleExit", Arguments2, true);

if (pPed->IsLocalPlayer())
{
auto discord = g_pCore->GetDiscord();
if (discord->IsDiscordRPCEnabled())
{
CVector position;
SString zoneName;

pPed->GetPosition(position);
CStaticFunctionDefinitions::GetZoneName(position, zoneName, true);

eClientVehicleType vehicleType = CClientVehicleManager::GetVehicleType(pVehicle->GetModel());
discord->SetPresenceState(SString("Walking around %s", zoneName.c_str()), false);
}
}
break;
}

Expand Down Expand Up @@ -2055,27 +1996,6 @@ void CPacketHandler::Packet_Vehicle_InOut(NetBitStreamInterface& bitStream)
Arguments2.PushNumber(ucSeat); // seat
Arguments2.PushNumber(ucDoor); // door
pVehicle->CallEvent("onClientVehicleStartExit", Arguments2, true);

if (pPed->IsLocalPlayer() || pJacked->IsLocalPlayer())
{
auto discord = g_pCore->GetDiscord();
if (discord->IsDiscordRPCEnabled())
{
CVector position;
SString zoneName;

pPed->GetPosition(position);
CStaticFunctionDefinitions::GetZoneName(position, zoneName, true);

eClientVehicleType vehicleType = CClientVehicleManager::GetVehicleType(pVehicle->GetModel());

if (pPed->IsLocalPlayer())
discord->SetPresenceState(SString("%s %s", g_vehicleTypePrefixes.at(vehicleType).c_str(), zoneName.c_str()), false);
else if (pJacked->IsLocalPlayer())
discord->SetPresenceState(SString("Walking around %s", zoneName.c_str()), false);
}
}

break;
}

Expand Down Expand Up @@ -2164,26 +2084,6 @@ void CPacketHandler::Packet_Vehicle_InOut(NetBitStreamInterface& bitStream)
pInsidePed->CallEvent("onClientPlayerVehicleEnter", Arguments4, true);
else
pInsidePed->CallEvent("onClientPedVehicleEnter", Arguments4, true);

if (pInsidePed->IsLocalPlayer() || pOutsidePed->IsLocalPlayer())
{
auto discord = g_pCore->GetDiscord();
if (discord->IsDiscordRPCEnabled())
{
CVector position;
SString zoneName;

pInsidePed->GetPosition(position);
CStaticFunctionDefinitions::GetZoneName(position, zoneName, true);

eClientVehicleType vehicleType = CClientVehicleManager::GetVehicleType(pVehicle->GetModel());

if (pInsidePed->IsLocalPlayer())
discord->SetPresenceState(SString("%s %s", g_vehicleTypePrefixes.at(vehicleType).c_str(), zoneName.c_str()), false);
else if (pOutsidePed->IsLocalPlayer())
discord->SetPresenceState(SString("Walking around %s", zoneName.c_str()), false);
}
}
}
}

Expand Down
18 changes: 0 additions & 18 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9813,24 +9813,6 @@ bool CStaticFunctionDefinitions::WarpPedIntoVehicle(CClientPed* pPed, CClientVeh
Arguments2.PushNumber(uiSeat); // seat
pVehicle->CallEvent("onClientVehicleEnter", Arguments2, true);

if (pPed->IsLocalPlayer())
{
auto discord = g_pCore->GetDiscord();
if (discord->IsDiscordRPCEnabled())
{
CVector position;
SString zoneName;

pPed->GetPosition(position);
GetZoneName(position, zoneName, true);

eClientVehicleType vehicleType = CClientVehicleManager::GetVehicleType(pVehicle->GetModel());
std::string vehiclePrefix = g_vehicleTypePrefixes.at(vehicleType);

discord->SetPresenceState(SString("%s %s", vehiclePrefix.c_str(), zoneName.c_str()), false);
}
}

return true;
}

Expand Down

0 comments on commit b67d252

Please sign in to comment.