From b07a7ebb5a13f5ce2dbe9c4c6b9cc2fd9c6ce1bb Mon Sep 17 00:00:00 2001 From: iAmir Date: Mon, 18 Sep 2023 04:54:38 +0330 Subject: [PATCH] add checks in multiple places for queryExtension results --- Server/Components/Dialogs/dialog.cpp | 6 +- Server/Components/GangZones/gangzone.hpp | 84 ++++++++++++++---------- Server/Components/Menus/menu.cpp | 18 +++-- Server/Components/Pickups/pickup.hpp | 44 +++++++------ 4 files changed, 90 insertions(+), 62 deletions(-) diff --git a/Server/Components/Dialogs/dialog.cpp b/Server/Components/Dialogs/dialog.cpp index bfacf1d41..e0d0342f7 100644 --- a/Server/Components/Dialogs/dialog.cpp +++ b/Server/Components/Dialogs/dialog.cpp @@ -207,7 +207,11 @@ class DialogsComponent final : public IDialogsComponent, public PlayerConnectEve { for (IPlayer* player : core->getPlayers().entries()) { - queryExtension(player)->hide(*player); + auto data = queryExtension(player); + if (data) + { + data->hide(*player); + } } } diff --git a/Server/Components/GangZones/gangzone.hpp b/Server/Components/GangZones/gangzone.hpp index f18bfa900..ccaab347d 100644 --- a/Server/Components/GangZones/gangzone.hpp +++ b/Server/Components/GangZones/gangzone.hpp @@ -37,33 +37,39 @@ class GangZone final : public IGangZone, public PoolIDProvider, public NoCopy void hideForClient(IPlayer& player) { auto data = queryExtension(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(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); + } } } @@ -123,32 +129,38 @@ class GangZone final : public IGangZone, public PoolIDProvider, public NoCopy void flashForPlayer(IPlayer& player, const Colour& colour) override { auto data = queryExtension(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(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 diff --git a/Server/Components/Menus/menu.cpp b/Server/Components/Menus/menu.cpp index 9a066cee7..eb54bb08d 100644 --- a/Server/Components/Menus/menu.cpp +++ b/Server/Components/Menus/menu.cpp @@ -41,10 +41,13 @@ class MenusComponent final : public IMenusComponent, public MenuEventHandler, pu // Return false if menu id was invalid; IPlayerMenuData* data = queryExtension(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( @@ -73,10 +76,13 @@ class MenusComponent final : public IMenusComponent, public MenuEventHandler, pu // Return false if menu id was invalid; IPlayerMenuData* data = queryExtension(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( diff --git a/Server/Components/Pickups/pickup.hpp b/Server/Components/Pickups/pickup.hpp index 46df64587..14bb4434b 100644 --- a/Server/Components/Pickups/pickup.hpp +++ b/Server/Components/Pickups/pickup.hpp @@ -37,33 +37,39 @@ class Pickup final : public IPickup, public PoolIDProvider, public NoCopy void streamInForClient(IPlayer& player) { auto data = queryExtension(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(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); + } } }