Skip to content

Commit

Permalink
add checks in multiple places for queryExtension results
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady committed Sep 18, 2023
1 parent a5157d5 commit 4ca5aa9
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 62 deletions.
6 changes: 5 additions & 1 deletion Server/Components/Dialogs/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ class DialogsComponent final : public IDialogsComponent, public PlayerConnectEve
{
for (IPlayer* player : core->getPlayers().entries())
{
queryExtension<IPlayerDialogData>(player)->hide(*player);
auto data = queryExtension<IPlayerDialogData>(player);
if (data)
{
data->hide(*player);
}
}
}

Expand Down
84 changes: 48 additions & 36 deletions Server/Components/GangZones/gangzone.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,39 @@ class GangZone final : public IGangZone, public PoolIDProvider, public NoCopy
void hideForClient(IPlayer& player)
{
auto data = queryExtension<IPlayerGangZoneData>(player);
int id = data->toClientID(poolID);
if (id != INVALID_GANG_ZONE_ID)
if (data)
{
data->releaseClientID(id);
NetCode::RPC::HideGangZone hideGangZoneRPC;
hideGangZoneRPC.ID = id;
PacketHelper::send(hideGangZoneRPC, player);
int id = data->toClientID(poolID);
if (id != INVALID_GANG_ZONE_ID)
{
data->releaseClientID(id);
NetCode::RPC::HideGangZone hideGangZoneRPC;
hideGangZoneRPC.ID = id;
PacketHelper::send(hideGangZoneRPC, player);
}
}
}

void showForClient(IPlayer& player, const Colour& colour) const
{
auto data = queryExtension<IPlayerGangZoneData>(player);
int id = data->toClientID(poolID);
if (id == INVALID_GANG_ZONE_ID)
if (data)
{
id = data->reserveClientID();
}
if (id != INVALID_GANG_ZONE_ID)
{
data->setClientID(id, poolID);
NetCode::RPC::ShowGangZone showGangZoneRPC;
showGangZoneRPC.ID = id;
showGangZoneRPC.Min = pos.min;
showGangZoneRPC.Max = pos.max;
showGangZoneRPC.Col = colour;
PacketHelper::send(showGangZoneRPC, player);
int id = data->toClientID(poolID);
if (id == INVALID_GANG_ZONE_ID)
{
id = data->reserveClientID();
}
if (id != INVALID_GANG_ZONE_ID)
{
data->setClientID(id, poolID);
NetCode::RPC::ShowGangZone showGangZoneRPC;
showGangZoneRPC.ID = id;
showGangZoneRPC.Min = pos.min;
showGangZoneRPC.Max = pos.max;
showGangZoneRPC.Col = colour;
PacketHelper::send(showGangZoneRPC, player);
}
}
}

Expand Down Expand Up @@ -123,32 +129,38 @@ class GangZone final : public IGangZone, public PoolIDProvider, public NoCopy
void flashForPlayer(IPlayer& player, const Colour& colour) override
{
auto data = queryExtension<IPlayerGangZoneData>(player);
int id = data->toClientID(poolID);
const int pid = player.getID();
if (id != INVALID_GANG_ZONE_ID)
if (data)
{
NetCode::RPC::FlashGangZone flashGangZoneRPC;
flashGangZoneRPC.ID = id;
flashGangZoneRPC.Col = colour;
PacketHelper::send(flashGangZoneRPC, player);
int id = data->toClientID(poolID);
const int pid = player.getID();
if (id != INVALID_GANG_ZONE_ID)
{
NetCode::RPC::FlashGangZone flashGangZoneRPC;
flashGangZoneRPC.ID = id;
flashGangZoneRPC.Col = colour;
PacketHelper::send(flashGangZoneRPC, player);
}
flashColorForPlayer_[pid] = colour;
flashingFor_.set(pid);
}
flashColorForPlayer_[pid] = colour;
flashingFor_.set(pid);
}

void stopFlashForPlayer(IPlayer& player) override
{
auto data = queryExtension<IPlayerGangZoneData>(player);
int id = data->toClientID(poolID);
const int pid = player.getID();
if (id != INVALID_GANG_ZONE_ID)
if (data)
{
NetCode::RPC::StopFlashGangZone stopFlashGangZoneRPC;
stopFlashGangZoneRPC.ID = id;
PacketHelper::send(stopFlashGangZoneRPC, player);
int id = data->toClientID(poolID);
const int pid = player.getID();
if (id != INVALID_GANG_ZONE_ID)
{
NetCode::RPC::StopFlashGangZone stopFlashGangZoneRPC;
stopFlashGangZoneRPC.ID = id;
PacketHelper::send(stopFlashGangZoneRPC, player);
}
flashColorForPlayer_[pid] = Colour::None();
flashingFor_.reset(pid);
}
flashColorForPlayer_[pid] = Colour::None();
flashingFor_.reset(pid);
}

const Colour getFlashingColourForPlayer(IPlayer& player) const override
Expand Down
18 changes: 12 additions & 6 deletions Server/Components/Menus/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ class MenusComponent final : public IMenusComponent, public MenuEventHandler, pu

// Return false if menu id was invalid;
IPlayerMenuData* data = queryExtension<IPlayerMenuData>(peer);
if (!self.storage.get(data->getMenuID()))
if(data)
{
data->setMenuID(INVALID_MENU_ID);
return false;
if (!self.storage.get(data->getMenuID()))
{
data->setMenuID(INVALID_MENU_ID);
return false;
}
}

self.eventDispatcher.dispatch(
Expand Down Expand Up @@ -73,10 +76,13 @@ class MenusComponent final : public IMenusComponent, public MenuEventHandler, pu

// Return false if menu id was invalid;
IPlayerMenuData* data = queryExtension<IPlayerMenuData>(peer);
if (!self.storage.get(data->getMenuID()))
if(data)
{
data->setMenuID(INVALID_MENU_ID);
return false;
if (!self.storage.get(data->getMenuID()))
{
data->setMenuID(INVALID_MENU_ID);
return false;
}
}

self.eventDispatcher.dispatch(
Expand Down
44 changes: 25 additions & 19 deletions Server/Components/Pickups/pickup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,39 @@ class Pickup final : public IPickup, public PoolIDProvider, public NoCopy
void streamInForClient(IPlayer& player)
{
auto data = queryExtension<IPlayerPickupData>(player);
int id = data->toClientID(poolID);
if (id == INVALID_PICKUP_ID)
if (data)
{
id = data->reserveClientID();
}
if (id != INVALID_PICKUP_ID)
{
data->setClientID(id, poolID);
NetCode::RPC::PlayerCreatePickup createPickupRPC;
createPickupRPC.PickupID = id;
createPickupRPC.Model = modelId;
createPickupRPC.Type = type;
createPickupRPC.Position = pos;
PacketHelper::send(createPickupRPC, player);
int id = data->toClientID(poolID);
if (id == INVALID_PICKUP_ID)
{
id = data->reserveClientID();
}
if (id != INVALID_PICKUP_ID)
{
data->setClientID(id, poolID);
NetCode::RPC::PlayerCreatePickup createPickupRPC;
createPickupRPC.PickupID = id;
createPickupRPC.Model = modelId;
createPickupRPC.Type = type;
createPickupRPC.Position = pos;
PacketHelper::send(createPickupRPC, player);
}
}
}

void streamOutForClient(IPlayer& player)
{
auto data = queryExtension<IPlayerPickupData>(player);
int id = data->toClientID(poolID);
if (id != INVALID_PICKUP_ID)
if (data)
{
data->releaseClientID(id);
NetCode::RPC::PlayerDestroyPickup destroyPickupRPC;
destroyPickupRPC.PickupID = id;
PacketHelper::send(destroyPickupRPC, player);
int id = data->toClientID(poolID);
if (id != INVALID_PICKUP_ID)
{
data->releaseClientID(id);
NetCode::RPC::PlayerDestroyPickup destroyPickupRPC;
destroyPickupRPC.PickupID = id;
PacketHelper::send(destroyPickupRPC, player);
}
}
}

Expand Down

0 comments on commit 4ca5aa9

Please sign in to comment.