Move r2 plot item security off the AIS to the EGS and remove hardcoded sheet ids

This commit is contained in:
kaetemi 2013-09-07 15:51:30 +02:00
parent 264de79088
commit e99bf91b20
2 changed files with 79 additions and 115 deletions

View file

@ -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)

View file

@ -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;
@ -154,6 +155,17 @@ void CR2MissionItem::giveMissionItem(const NLMISC::CEntityId &eid, TSessionId se
{
std::vector< CGameItemPtr > itemDropToEgg;
for( uint32 j = 0; j < items.size(); ++j )
{
const CStaticItem* sitem = CSheets::getForm(items[j].SheetId);
if (sitem == NULL)
{
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
{
CGameItemPtr item = c->createItem(1, items[j].Quantity, items[j].SheetId);
@ -161,7 +173,7 @@ void CR2MissionItem::giveMissionItem(const NLMISC::CEntityId &eid, TSessionId se
{
if( c->addItemToInventory(INVENTORIES::bag, item) )
{
/* // check eid is registered as character have instantiated mission item for this scenario
/* // check eid is registered as character have instantiated mission item for this scenario
TMissionItemInstanciatedOwner::iterator it = _OwnerOfInstanciatedItemFromScenario.find(scenarioId);
if( it == _OwnerOfInstanciatedItemFromScenario.end() )
{
@ -184,7 +196,7 @@ void CR2MissionItem::giveMissionItem(const NLMISC::CEntityId &eid, TSessionId se
}
if ( ! found) { (*it).second.push_back(eid); }
}
*/
*/
keepR2ItemAssociation(eid, scenarioId);
}
else
@ -197,6 +209,7 @@ void CR2MissionItem::giveMissionItem(const NLMISC::CEntityId &eid, TSessionId se
nlwarning("CR2MissionItem::giveMissionItem: can't create item %s", items[j].SheetId.toString().c_str());
}
}
}
if(itemDropToEgg.size() != 0)
{
CR2EasterEgg::getInstance().dropMissionItem(itemDropToEgg, scenarioId, c->getInstanceNumber(), eid);
@ -273,6 +286,17 @@ void CR2MissionItem::destroyMissionItem(const NLMISC::CEntityId &eid, const std:
CSheetId itemSheetId = items[j].SheetId;
uint32 quantity = items[j].Quantity;
const CStaticItem* sitem = CSheets::getForm(items[j].SheetId);
if (sitem == NULL)
{
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 );
@ -288,9 +312,10 @@ void CR2MissionItem::destroyMissionItem(const NLMISC::CEntityId &eid, const std:
}
}
// 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)
// {
// }
// if(quantity > 0)
// {
// }
}
}
}
}