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

hg/feature/gsoc2012-fabien
kaetemi 11 years ago
parent 264de79088
commit e99bf91b20

@ -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. - 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: 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) -> Arguments: s(missionItems), s(missionText), c(groupToNotify) ->
@param[in] missionItems is the list of mission items, the string format is "item1:qty1;item2:qty2;...". @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; DEBUG_STOP;
return; 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; uint32 quantity;
NLMISC::fromString(itemAndQty[1], 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. - 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: 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) -> Arguments: s(missionItems), s(missionText), c(groupToNotify) ->
@param[in] missionItems is the list of mission items, the string format is "item1:qty1;item2:qty2;...". @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; 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; uint32 quantity;
NLMISC::fromString(itemAndQty[1], quantity); NLMISC::fromString(itemAndQty[1], quantity);
if (quantity == 0) if (quantity == 0)

@ -26,6 +26,7 @@
#include "player_manager/player_manager.h" #include "player_manager/player_manager.h"
#include "player_manager/character.h" #include "player_manager/character.h"
#include "server_share/log_item_gen.h" #include "server_share/log_item_gen.h"
#include "egs_sheets/egs_sheets.h"
using namespace std; using namespace std;
using namespace NLMISC; using namespace NLMISC;
@ -154,6 +155,17 @@ void CR2MissionItem::giveMissionItem(const NLMISC::CEntityId &eid, TSessionId se
{ {
std::vector< CGameItemPtr > itemDropToEgg; std::vector< CGameItemPtr > itemDropToEgg;
for( uint32 j = 0; j < items.size(); ++j ) 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); 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) ) 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); TMissionItemInstanciatedOwner::iterator it = _OwnerOfInstanciatedItemFromScenario.find(scenarioId);
if( it == _OwnerOfInstanciatedItemFromScenario.end() ) if( it == _OwnerOfInstanciatedItemFromScenario.end() )
{ {
@ -184,7 +196,7 @@ void CR2MissionItem::giveMissionItem(const NLMISC::CEntityId &eid, TSessionId se
} }
if ( ! found) { (*it).second.push_back(eid); } if ( ! found) { (*it).second.push_back(eid); }
} }
*/ */
keepR2ItemAssociation(eid, scenarioId); keepR2ItemAssociation(eid, scenarioId);
} }
else 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()); nlwarning("CR2MissionItem::giveMissionItem: can't create item %s", items[j].SheetId.toString().c_str());
} }
} }
}
if(itemDropToEgg.size() != 0) if(itemDropToEgg.size() != 0)
{ {
CR2EasterEgg::getInstance().dropMissionItem(itemDropToEgg, scenarioId, c->getInstanceNumber(), eid); 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; CSheetId itemSheetId = items[j].SheetId;
uint32 quantity = items[j].Quantity; 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); CInventoryPtr inv = c->getInventory(INVENTORIES::bag);
nlassert( inv != NULL ); nlassert( inv != NULL );
_destroyMissionItem( inv, itemSheetId, quantity ); _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 // 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)
// { // {
// } // }
}
} }
} }
} }

Loading…
Cancel
Save