Move r2 plot item security off the AIS to the EGS and remove hardcoded sheet ids
This commit is contained in:
parent
264de79088
commit
e99bf91b20
2 changed files with 79 additions and 115 deletions
|
@ -1607,6 +1607,7 @@ Then user events are triggered on the group to inform it about what happens:
|
|||
- user_event_3: triggered after the player has given the mission items to the npc.
|
||||
|
||||
Warning: this function can only be called after the event "player_target_npc".
|
||||
Warning: only works on an R2 shard for R2 plot items.
|
||||
|
||||
Arguments: s(missionItems), s(missionText), c(groupToNotify) ->
|
||||
@param[in] missionItems is the list of mission items, the string format is "item1:qty1;item2:qty2;...".
|
||||
|
@ -1709,38 +1710,6 @@ void receiveMissionItems_ssc_(CStateInstance* entity, CScriptStack& stack)
|
|||
DEBUG_STOP;
|
||||
return;
|
||||
}
|
||||
// if LD use this the function outside a ring shard
|
||||
if (IsRingShard)
|
||||
{
|
||||
|
||||
// Here we destroy the item: so we do not want that a user create a scenario where we destroy
|
||||
// other players precious items
|
||||
|
||||
static std::set<CSheetId> r2PlotItemSheetId; // :TODO: use R2Share::CRingAccess
|
||||
// lazy intialisation
|
||||
if (r2PlotItemSheetId.empty())
|
||||
{
|
||||
for (uint32 i = 0 ; i <= 184 ; ++i)
|
||||
{
|
||||
r2PlotItemSheetId.insert( CSheetId( NLMISC::toString("r2_plot_item_%d.sitem", i)));
|
||||
}
|
||||
}
|
||||
|
||||
// A npc give a mission to take an item given by another npc
|
||||
// but the item instead of being a r2_plot_item is a normal item like system_mp or big armor
|
||||
if ( r2PlotItemSheetId.find(sheetId) == r2PlotItemSheetId.end())
|
||||
{
|
||||
nlwarning("!!!!!!!!!!!!");
|
||||
nlwarning("!!!!!!!!!!!! Someone is trying to hack us");
|
||||
nlwarning("!!!!!!!!!!!!");
|
||||
nlwarning("ERROR/HACK : an npc is trying to give to a player a item that is not a plot item SheetId='%s' sheetIdAsInt=%u",sheetId.toString().c_str(), sheetId.asInt());
|
||||
nlwarning("His ai instanceId is %u, use log to know the sessionId and the user ", msg.InstanceId );
|
||||
nlwarning("!!!!!!!!!!!!");
|
||||
nlwarning("!!!!!!!!!!!!");
|
||||
return ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint32 quantity;
|
||||
NLMISC::fromString(itemAndQty[1], quantity);
|
||||
|
@ -1774,6 +1743,7 @@ Then user events are triggered on the group to inform it about what happens:
|
|||
- user_event_1: triggered after the player has received the mission items from the npc.
|
||||
|
||||
Warning: this function can only be called after the event "player_target_npc".
|
||||
Warning: only works on an R2 shard for R2 plot items.
|
||||
|
||||
Arguments: s(missionItems), s(missionText), c(groupToNotify) ->
|
||||
@param[in] missionItems is the list of mission items, the string format is "item1:qty1;item2:qty2;...".
|
||||
|
@ -1877,37 +1847,6 @@ void giveMissionItems_ssc_(CStateInstance* entity, CScriptStack& stack)
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
// if LD use this the function outside a ring shard
|
||||
if (IsRingShard)
|
||||
{
|
||||
|
||||
static std::set<CSheetId> r2PlotItemSheetId; // :TODO: use R2Share::CRingAccess
|
||||
// lazy intialisation
|
||||
if (r2PlotItemSheetId.empty())
|
||||
{
|
||||
for (uint32 i = 0 ; i <= 184 ; ++i)
|
||||
{
|
||||
r2PlotItemSheetId.insert( CSheetId( NLMISC::toString("r2_plot_item_%d.sitem", i)));
|
||||
}
|
||||
}
|
||||
|
||||
// A npc give a mission to give a item to another npc
|
||||
// but the item instead of being a r2_plot_item is a normal item like system_mp or big armor
|
||||
if ( r2PlotItemSheetId.find(sheetId) == r2PlotItemSheetId.end())
|
||||
{
|
||||
nlwarning("!!!!!!!!!!!!");
|
||||
nlwarning("!!!!!!!!!!!! Someone is trying to hack us");
|
||||
nlwarning("!!!!!!!!!!!!");
|
||||
nlwarning("ERROR/HACK : an npc is trying to give to a player a item that is not a plot item SheetId='%s' sheetIdAsInt=%u",sheetId.toString().c_str(), sheetId.asInt());
|
||||
nlwarning("His ai instanceId is %u, use log to know the sessionId and the user ", msg.InstanceId );
|
||||
nlwarning("!!!!!!!!!!!!");
|
||||
nlwarning("!!!!!!!!!!!!");
|
||||
return ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint32 quantity;
|
||||
NLMISC::fromString(itemAndQty[1], quantity);
|
||||
if (quantity == 0)
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "player_manager/player_manager.h"
|
||||
#include "player_manager/character.h"
|
||||
#include "server_share/log_item_gen.h"
|
||||
#include "egs_sheets/egs_sheets.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace NLMISC;
|
||||
|
@ -155,46 +156,58 @@ void CR2MissionItem::giveMissionItem(const NLMISC::CEntityId &eid, TSessionId se
|
|||
std::vector< CGameItemPtr > itemDropToEgg;
|
||||
for( uint32 j = 0; j < items.size(); ++j )
|
||||
{
|
||||
CGameItemPtr item = c->createItem(1, items[j].Quantity, items[j].SheetId);
|
||||
|
||||
if( item != NULL )
|
||||
const CStaticItem* sitem = CSheets::getForm(items[j].SheetId);
|
||||
if (sitem == NULL)
|
||||
{
|
||||
if( c->addItemToInventory(INVENTORIES::bag, item) )
|
||||
{
|
||||
/* // check eid is registered as character have instantiated mission item for this scenario
|
||||
TMissionItemInstanciatedOwner::iterator it = _OwnerOfInstanciatedItemFromScenario.find(scenarioId);
|
||||
if( it == _OwnerOfInstanciatedItemFromScenario.end() )
|
||||
{
|
||||
pair< TMissionItemInstanciatedOwner::iterator, bool > ret = _OwnerOfInstanciatedItemFromScenario.insert( make_pair( scenarioId, vector< CEntityId >() ) );
|
||||
if( ret.second )
|
||||
{
|
||||
(*ret.first).second.push_back( eid );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bool found = false;
|
||||
for( uint32 i = 0; i < (*it).second.size(); ++ i )
|
||||
{
|
||||
if( (*it).second[i] == eid )
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( ! found) { (*it).second.push_back(eid); }
|
||||
}
|
||||
*/
|
||||
keepR2ItemAssociation(eid, scenarioId);
|
||||
}
|
||||
else
|
||||
{
|
||||
itemDropToEgg.push_back(item);
|
||||
}
|
||||
nlwarning("Attempted to give deprecated sitem sheet %s to player character %s in session %i", items[j].SheetId.toString().c_str(), c->getName().toUtf8().c_str(), sessionId.asInt());
|
||||
}
|
||||
else if (sitem->Family != ITEMFAMILY::SCROLL_R2)
|
||||
{
|
||||
nlwarning("Attempted hack to give non-R2 item %s to player character %s in session %i", items[j].SheetId.toString().c_str(), c->getName().toUtf8().c_str(), sessionId.asInt());
|
||||
}
|
||||
else
|
||||
{
|
||||
nlwarning("CR2MissionItem::giveMissionItem: can't create item %s", items[j].SheetId.toString().c_str());
|
||||
CGameItemPtr item = c->createItem(1, items[j].Quantity, items[j].SheetId);
|
||||
|
||||
if( item != NULL )
|
||||
{
|
||||
if( c->addItemToInventory(INVENTORIES::bag, item) )
|
||||
{
|
||||
/* // check eid is registered as character have instantiated mission item for this scenario
|
||||
TMissionItemInstanciatedOwner::iterator it = _OwnerOfInstanciatedItemFromScenario.find(scenarioId);
|
||||
if( it == _OwnerOfInstanciatedItemFromScenario.end() )
|
||||
{
|
||||
pair< TMissionItemInstanciatedOwner::iterator, bool > ret = _OwnerOfInstanciatedItemFromScenario.insert( make_pair( scenarioId, vector< CEntityId >() ) );
|
||||
if( ret.second )
|
||||
{
|
||||
(*ret.first).second.push_back( eid );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bool found = false;
|
||||
for( uint32 i = 0; i < (*it).second.size(); ++ i )
|
||||
{
|
||||
if( (*it).second[i] == eid )
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( ! found) { (*it).second.push_back(eid); }
|
||||
}
|
||||
*/
|
||||
keepR2ItemAssociation(eid, scenarioId);
|
||||
}
|
||||
else
|
||||
{
|
||||
itemDropToEgg.push_back(item);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nlwarning("CR2MissionItem::giveMissionItem: can't create item %s", items[j].SheetId.toString().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
if(itemDropToEgg.size() != 0)
|
||||
|
@ -273,24 +286,36 @@ void CR2MissionItem::destroyMissionItem(const NLMISC::CEntityId &eid, const std:
|
|||
CSheetId itemSheetId = items[j].SheetId;
|
||||
uint32 quantity = items[j].Quantity;
|
||||
|
||||
CInventoryPtr inv = c->getInventory(INVENTORIES::bag);
|
||||
nlassert( inv != NULL );
|
||||
_destroyMissionItem( inv, itemSheetId, quantity );
|
||||
if( quantity > 0)
|
||||
const CStaticItem* sitem = CSheets::getForm(items[j].SheetId);
|
||||
if (sitem == NULL)
|
||||
{
|
||||
for( uint32 j = INVENTORIES::pet_animal; j < INVENTORIES::max_pet_animal; ++j )
|
||||
{
|
||||
inv = c->getInventory((INVENTORIES::TInventory)j);
|
||||
nlassert(inv != NULL);
|
||||
_destroyMissionItem( inv, itemSheetId, quantity );
|
||||
if(quantity == 0)
|
||||
break;
|
||||
}
|
||||
nlwarning("Attempted to take deprecated sitem sheet %s from player character %s", items[j].SheetId.toString().c_str(), c->getName().toUtf8().c_str());
|
||||
}
|
||||
else if (sitem->Family != ITEMFAMILY::SCROLL_R2)
|
||||
{
|
||||
nlwarning("Attempted hack to take non-R2 item %s from player character %s", items[j].SheetId.toString().c_str(), c->getName().toUtf8().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
CInventoryPtr inv = c->getInventory(INVENTORIES::bag);
|
||||
nlassert( inv != NULL );
|
||||
_destroyMissionItem( inv, itemSheetId, quantity );
|
||||
if( quantity > 0)
|
||||
{
|
||||
for( uint32 j = INVENTORIES::pet_animal; j < INVENTORIES::max_pet_animal; ++j )
|
||||
{
|
||||
inv = c->getInventory((INVENTORIES::TInventory)j);
|
||||
nlassert(inv != NULL);
|
||||
_destroyMissionItem( inv, itemSheetId, quantity );
|
||||
if(quantity == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
// TODO: if we can't found enough quantity of item to destroy, we need decide if we must manage that as an error
|
||||
// if(quantity > 0)
|
||||
// {
|
||||
// }
|
||||
}
|
||||
// TODO: if we can't found enough quantity of item to destroy, we need decide if we must manage that as an error
|
||||
// if(quantity > 0)
|
||||
// {
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue