示例#1
0
TRIGGER( use )(obj user)
{
  int Q4Q1;
  obj Q491 = Q4SE(this);
  if(Q491 == NULL())
  {
    return(0x00);
  }
  if(isDead(user))
  {
    return(0x00);
  }
  if(isEditing(user) || Q4ZV(user, this))
  {
    Q4Q1 = openContainer(user, Q491);
  }
  else
  {
    if(testSkill(user, 0x1C))
    {
      Q4Q1 = openContainer(user, Q491);
    }
    else
    {
      ebarkTo(user, user, "You fail to peek into the animal's pack.");
    }
  }
  return(0x00);
}
示例#2
0
void CompanionWindow::open(MWWorld::Ptr npc)
{
    openContainer(npc);
    setTitle(MWWorld::Class::get(npc).getName(npc));
    drawItems();
    updateEncumbranceBar();
}
示例#3
0
static int decodeString( bsd_ctx_t *ctx, bsd_data_t *x, const uint8_t *buffer, int length, const bs_string_encoding_t *enc) {
  int nread = 0;
  uint8_t opcode = buffer[0];
  CHECK_LENGTH( 1);

  x->kind = BSD_STRING;
  if( enc->small_opcode <= opcode && opcode < enc->medium_opcode) {
    /* Small string */
    size_t len = opcode - enc->small_opcode;
    CHECK_LENGTH( len + 1);
    bsd_string( x, len, (const char *) buffer + 1);
  } else if( enc->medium_opcode <= opcode && opcode < enc->large_opcode) {
    /* Medium string */
    CHECK_LENGTH( 2);
    size_t len = ((opcode - enc->medium_opcode) << 8) + buffer[1] + enc->small_limit + 1;
    CHECK_LENGTH( len + 2);
    bsd_string( x, len, (const char *) buffer + 2);
  } else if( enc->large_opcode == opcode) {
    /* Large string */
    CHECK_LENGTH( 3);
    size_t len = ((buffer[1]) << 8) + buffer[2] + enc->medium_limit + 1;
    CHECK_LENGTH( len + 3);
    bsd_string( x, len, (const char *) buffer + 3);
  } else if( enc->chunked_opcode == opcode) {
    CHECK_ERROR( openContainer( ctx, BS_FCHUNKED, BS_CTXID_CHUNKED, -1, NULL));
    x->kind = BSD_CHUNKED_STRING;
  }
  else {
    return 0;
  }
  return nread;
}
示例#4
0
    InventoryWindow::InventoryWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop)
        : ContainerBase(dragAndDrop)
        , WindowPinnableBase("openmw_inventory_window.layout", parWindowManager)
        , mTrading(false)
    {
        static_cast<MyGUI::Window*>(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &InventoryWindow::onWindowResize);

        getWidget(mAvatar, "Avatar");
        getWidget(mEncumbranceBar, "EncumbranceBar");
        getWidget(mEncumbranceText, "EncumbranceBarT");
        getWidget(mFilterAll, "AllButton");
        getWidget(mFilterWeapon, "WeaponButton");
        getWidget(mFilterApparel, "ApparelButton");
        getWidget(mFilterMagic, "MagicButton");
        getWidget(mFilterMisc, "MiscButton");
        getWidget(mLeftPane, "LeftPane");
        getWidget(mRightPane, "RightPane");

        mAvatar->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onAvatarClicked);

        MyGUI::ScrollView* itemView;
        MyGUI::Widget* containerWidget;
        getWidget(containerWidget, "Items");
        getWidget(itemView, "ItemView");
        setWidgets(containerWidget, itemView);

        // adjust size of buttons to fit text
        int curX = 0;
        mFilterAll->setSize( mFilterAll->getTextSize().width + 24, mFilterAll->getSize().height );
        curX += mFilterAll->getTextSize().width + 24 + 4;

        mFilterWeapon->setPosition(curX, mFilterWeapon->getPosition().top);
        mFilterWeapon->setSize( mFilterWeapon->getTextSize().width + 24, mFilterWeapon->getSize().height );
        curX += mFilterWeapon->getTextSize().width + 24 + 4;

        mFilterApparel->setPosition(curX, mFilterApparel->getPosition().top);
        mFilterApparel->setSize( mFilterApparel->getTextSize().width + 24, mFilterApparel->getSize().height );
        curX += mFilterApparel->getTextSize().width + 24 + 4;

        mFilterMagic->setPosition(curX, mFilterMagic->getPosition().top);
        mFilterMagic->setSize( mFilterMagic->getTextSize().width + 24, mFilterMagic->getSize().height );
        curX += mFilterMagic->getTextSize().width + 24 + 4;

        mFilterMisc->setPosition(curX, mFilterMisc->getPosition().top);
        mFilterMisc->setSize( mFilterMisc->getTextSize().width + 24, mFilterMisc->getSize().height );

        mFilterAll->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged);
        mFilterWeapon->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged);
        mFilterApparel->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged);
        mFilterMagic->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged);
        mFilterMisc->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged);

        mFilterAll->setStateSelected(true);

        setCoord(0, 342, 498, 258);

        MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
        openContainer(player);
    }
示例#5
0
    void AlchemyWindow::open()
    {
        openContainer(MWBase::Environment::get().getWorld()->getPlayer().getPlayer());
        setFilter(ContainerBase::Filter_Ingredients);

        // pick the best available apparatus
        MWWorld::ContainerStore& store = MWWorld::Class::get(mPtr).getContainerStore(mPtr);

        MWWorld::Ptr bestAlbemic;
        MWWorld::Ptr bestMortarPestle;
        MWWorld::Ptr bestCalcinator;
        MWWorld::Ptr bestRetort;

        for (MWWorld::ContainerStoreIterator it(store.begin(MWWorld::ContainerStore::Type_Apparatus));
            it != store.end(); ++it)
        {
            MWWorld::LiveCellRef<ESM::Apparatus>* ref = it->get<ESM::Apparatus>();
            if (ref->base->mData.mType == ESM::Apparatus::Albemic
            && (bestAlbemic.isEmpty() || ref->base->mData.mQuality > bestAlbemic.get<ESM::Apparatus>()->base->mData.mQuality))
                bestAlbemic = *it;
            else if (ref->base->mData.mType == ESM::Apparatus::MortarPestle
            && (bestMortarPestle.isEmpty() || ref->base->mData.mQuality > bestMortarPestle.get<ESM::Apparatus>()->base->mData.mQuality))
                bestMortarPestle = *it;
            else if (ref->base->mData.mType == ESM::Apparatus::Calcinator
            && (bestCalcinator.isEmpty() || ref->base->mData.mQuality > bestCalcinator.get<ESM::Apparatus>()->base->mData.mQuality))
                bestCalcinator = *it;
            else if (ref->base->mData.mType == ESM::Apparatus::Retort
            && (bestRetort.isEmpty() || ref->base->mData.mQuality > bestRetort.get<ESM::Apparatus>()->base->mData.mQuality))
                bestRetort = *it;
        }

        if (!bestMortarPestle.isEmpty())
        {
            mApparatus1->setUserString("ToolTipType", "ItemPtr");
            mApparatus1->setUserData(bestMortarPestle);
            mApparatus1->setImageTexture(getIconPath(bestMortarPestle));
        }
        if (!bestAlbemic.isEmpty())
        {
            mApparatus2->setUserString("ToolTipType", "ItemPtr");
            mApparatus2->setUserData(bestAlbemic);
            mApparatus2->setImageTexture(getIconPath(bestAlbemic));
        }
        if (!bestCalcinator.isEmpty())
        {
            mApparatus3->setUserString("ToolTipType", "ItemPtr");
            mApparatus3->setUserData(bestCalcinator);
            mApparatus3->setImageTexture(getIconPath(bestCalcinator));
        }
        if (!bestRetort.isEmpty())
        {
            mApparatus4->setUserString("ToolTipType", "ItemPtr");
            mApparatus4->setUserData(bestRetort);
            mApparatus4->setImageTexture(getIconPath(bestRetort));
        }
    }
示例#6
0
static bsd_status_t bsd_object( bsd_ctx_t *ctx, bsd_data_t *x, bs_classid_t classid) {
  const bs_class_t *klass = bs_classcoll_get( &ctx->classcoll, classid);
  union bsd_stackframecontent_t *f = NULL;
  bsd_status_t status;
  if( NULL == klass) {
    return BSD_EBADCLASSID;
  }
  x->kind = BSD_OBJECT;
  x->content.classdef = klass;
  status = openContainer( ctx, BS_FOBJECT, BS_CTXID_GLOBAL, klass->nfields, &f);
  f->object.classdef = klass;
  return status;
}
示例#7
0
    InventoryWindow::InventoryWindow(DragAndDrop* dragAndDrop)
        : ContainerBase(dragAndDrop)
        , WindowPinnableBase("openmw_inventory_window.layout")
        , mTrading(false)
        , mLastXSize(0)
        , mLastYSize(0)
        , mPreview(MWBase::Environment::get().getWorld ()->getPlayer ().getPlayer ())
        , mPreviewDirty(true)
    {
        static_cast<MyGUI::Window*>(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &InventoryWindow::onWindowResize);

        getWidget(mAvatar, "Avatar");
        getWidget(mAvatarImage, "AvatarImage");
        getWidget(mEncumbranceBar, "EncumbranceBar");
        getWidget(mFilterAll, "AllButton");
        getWidget(mFilterWeapon, "WeaponButton");
        getWidget(mFilterApparel, "ApparelButton");
        getWidget(mFilterMagic, "MagicButton");
        getWidget(mFilterMisc, "MiscButton");
        getWidget(mLeftPane, "LeftPane");
        getWidget(mRightPane, "RightPane");
        getWidget(mArmorRating, "ArmorRating");

        mAvatar->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onAvatarClicked);

        MyGUI::ScrollView* itemView;
        MyGUI::Widget* containerWidget;
        getWidget(containerWidget, "Items");
        getWidget(itemView, "ItemView");
        setWidgets(containerWidget, itemView);

        mFilterAll->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged);
        mFilterWeapon->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged);
        mFilterApparel->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged);
        mFilterMagic->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged);
        mFilterMisc->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged);

        mFilterAll->setStateSelected(true);

        setCoord(0, 342, 498, 258);

        mPreview.setup();

        MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
        openContainer(player);
    }
示例#8
0
static int decodeCollection( bsd_ctx_t *ctx, bsd_data_t *x, const uint8_t *buffer, int length, union bsd_stackframecontent_t **f, const bs_coll_encoding_t *enc) {
  int nread = 0;
  uint8_t opcode = buffer[0];
  CHECK_LENGTH( 1);

  if( enc->empty_opcode == opcode) {
    /* empty container */
    x->kind = bsd_typeFromFrameKind( enc->fixed_kind);
    x->content.length = 0;
    CHECK_ERROR( openContainer( ctx, enc->fixed_kind, BS_CTXID_GLOBAL, 0, f));
  } else if( enc->small_untyped_opcode <= opcode && opcode <= enc->small_untyped_opcode + enc->small_limit - 1) {
    /* Small untyped container */
    x->kind = bsd_typeFromFrameKind( enc->fixed_kind);
    x->content.length = opcode - enc->small_untyped_opcode + 1;
    CHECK_ERROR( openContainer( ctx, enc->fixed_kind, BS_CTXID_GLOBAL, x->content.length, f));
  } else if( enc->long_untyped_opcode == opcode) {
    /* Long untyped container */
    CHECK_SUBDECODE( bsd_uis( ctx, x, buffer + 1, length + 1), BSD_INT);
    x->kind = bsd_typeFromFrameKind( enc->fixed_kind);
    x->content.length = x->content.i + enc->small_limit + 1;
    CHECK_ERROR( openContainer( ctx, enc->fixed_kind, BS_CTXID_GLOBAL, x->content.length, f));
  } else if( enc->variable_untyped_opcode == opcode) {
    /* Variable untyped container */
    x->kind = bsd_typeFromFrameKind( enc->variable_kind);
    CHECK_ERROR( openContainer( ctx, enc->variable_kind, BS_CTXID_GLOBAL, -1, f));
  } else if( enc->small_typed_opcode <= opcode && opcode <= enc->small_typed_opcode + enc->small_limit - 1) {
    /* Small typed container */
    CHECK_LENGTH( 2);
    x->kind = bsd_typeFromFrameKind( enc->fixed_kind);
    x->content.length = opcode - enc->small_typed_opcode + 1;
    CHECK_ERROR( openContainer( ctx, enc->fixed_kind, buffer[1], x->content.length, f));
  } else if( enc->long_typed_opcode == opcode) {
    /* Long typed container */
    CHECK_SUBDECODE( bsd_uis( ctx, x, buffer + 1, length + 1), BSD_INT);
    CHECK_LENGTH( nread + 1);
    x->kind = bsd_typeFromFrameKind( enc->fixed_kind);
    x->content.length = x->content.i + enc->small_limit + 1;
    CHECK_ERROR( openContainer( ctx, enc->fixed_kind, buffer[nread-1], x->content.length, f));
  } else if( enc->variable_typed_opcode == opcode) {
    /* Variable untyped container */
    CHECK_LENGTH( 2);
    x->kind = bsd_typeFromFrameKind( enc->variable_kind);
    CHECK_ERROR( openContainer( ctx, enc->variable_kind, buffer[1], -1, f));
  } else {
    return 0;
  }
  return nread;
}
示例#9
0
    void AlchemyWindow::open()
    {
        openContainer (MWBase::Environment::get().getWorld()->getPlayer().getPlayer()); // this sets mPtr
        setFilter (ContainerBase::Filter_Ingredients);

        mAlchemy.setAlchemist (mPtr);

        int index = 0;

        for (MWMechanics::Alchemy::TToolsIterator iter (mAlchemy.beginTools());
            iter!=mAlchemy.endTools() && index<static_cast<int> (mApparatus.size()); ++iter, ++index)
        {
            if (!iter->isEmpty())
            {
                mApparatus.at (index)->setUserString ("ToolTipType", "ItemPtr");
                mApparatus.at (index)->setUserData (*iter);
                mApparatus.at (index)->setImageTexture (getIconPath (*iter));
            }
        }

        update();
    }
示例#10
0
int main(int argc, char *argv[]) {
    namespace po = boost::program_options;

    std::string privateKeyFile;
    std::string publicKeyFile;

    po::options_description general("General options");
    general.add_options()
        ("help", "produce help message")
        ("generate-rsa,g",
            "generate RSA keys and save to public.key and private.key")
        ("publickey",
            po::value<std::string>(&publicKeyFile)
                ->default_value("public.key"),
            "path to publickey (default \"public.key\"")
        ("privatekey",
            po::value<std::string>(&privateKeyFile)
                ->default_value("private.key"),
            "path to private key (default \"private.key\"");

    po::options_description openContainer("Open existing container");
    openContainer.add_options()
        ("open,o", po::value<std::string>(), "open existing container")
        ("unpack,u", po::value<std::string>(),
            "unpack selected files to directory")
        ("unpackAll,U", po::value<std::string>(),
            "unpack all files to directory")
        ("add,a", "add selected files");

    po::options_description createContainer("Create new container");
    createContainer.add_options()
        ("create,c", po::value<std::string>(), "create new container");

    po::options_description hidden("Hidden options");
    hidden.add_options()
        ("input-file", po::value<std::vector<std::string>>(),
            "input container file");


    po::options_description cmdlineOptions;
    cmdlineOptions
        .add(general)
        .add(openContainer)
        .add(createContainer)
        .add(hidden);

    po::positional_options_description p;
    p.add("input-file", -1);

    po::variables_map vm;
    po::store(po::command_line_parser(argc, argv).
        options(cmdlineOptions).positional(p).run(), vm);
    po::notify(vm);

    if (vm.count("help")) {
        std::cout
            << "Usage: CryptoContainer [options] <input or output files>"
            << std::endl;
        std::cout << general << "\n";
        std::cout << openContainer << "\n";
        std::cout << createContainer << "\n";
        return 1;
    }

    if (vm.count("generate-rsa")) {
        std::cout << "Generating RSA keys" << std::endl;
        auto RSAKeys = cc::generateRSAKeys();

        // Save public key
        std::cout << "Public key... ";
        cc::saveKeyToFile<CryptoPP::RSA::PublicKey>("public.key",
                                                     RSAKeys.second);
        std::cout << "OK" << std::endl;

        // Save private key
        std::cout << "Private key... ";
        cc::saveKeyToFile<CryptoPP::RSA::PrivateKey>("private.key",
                                                     RSAKeys.first);
        std::cout << "OK" << std::endl;

        return 1;
    }

    if (vm.count("create")) {
        std::cout << "Create container" << std::endl;

        if (!vm.count("input-file")) {
            std::cout << "Error: Need select input files" << std::endl;
            return -1;
        }

        if (!boost::filesystem::exists(publicKeyFile)) {
            std::cout << "Error: Public key doesn't exists" << std::endl;
            return -1;
        }

        if (boost::filesystem::is_directory(vm["create"].as<std::string>())) {
            std::cout << "Error: Path direct to directory" << std::endl;
            return -1;
        }

        auto publicKey =
            cc::loadKeyFromFile<CryptoPP::RSA::PublicKey>(publicKeyFile);

        auto container =
            cc::Container::openNewContainer(vm["create"].as<std::string>(),
                                            publicKey);

        if (!container) {
            std::cout << "invalid key or can't open file" << std::endl;
            return -1;
        }

        const auto pathsToPack =
            vm["input-file"].as<std::vector<std::string>>();
        for (auto &input : pathsToPack) {
            container->addFileOrFolder(input);
        }

        std::cout << "Wait a while..." << std::endl;
        container->save();
        std::cout << "Created " << vm["create"].as<std::string>()
            << " container" << std::endl;

        return 0;
    }

    if (vm.count("open")) {
        std::cout << "Open existed container" << std::endl;

        if (!boost::filesystem::exists(publicKeyFile)) {
            std::cout << "Error: Public key doesn't exists" << std::endl;
            return -1;
        }

        if (!boost::filesystem::exists(privateKeyFile)) {
            std::cout << "Error: Private key doesn't exists" << std::endl;
            return -1;
        }

        auto privateKey =
            cc::loadKeyFromFile<CryptoPP::RSA::PrivateKey>(privateKeyFile);

        auto publicKey =
            cc::loadKeyFromFile<CryptoPP::RSA::PublicKey>(publicKeyFile);

        auto container = cc::Container::openExistedContainer(
            vm["open"].as<std::string>(), publicKey, privateKey);

        if (!container) {
            std::cout << "Can't open container" << std::endl;
            return -1;
        }

        std::cout << "Wait a while..." << std::endl;

        if (vm.count("unpackAll")) {
            const std::string path = vm["unpackAll"].as<std::string>();
            container->unpackAll(path);
            std::cout << "Unpacked all data to: " << path << std::endl;
            return 0;
        } else if (vm.count("unpack")) {
            const std::string targetPath = vm["unpack"].as<std::string>();

            const auto pathsToUnpack =
                vm["input-file"].as<std::vector<std::string>>();

            for (auto& path : pathsToUnpack) {
                std::cout << "Unpack: " << path << std::endl;
                container->unpack(path, targetPath);
            }

            std::cout << "Unpacked all data to: " << targetPath << std::endl;

            return 0;
        } else if (vm.count("add")) {
            const auto pathsToPack =
                vm["input-file"].as<std::vector<std::string>>();

            for (auto &input : pathsToPack) {
                container->addFileOrFolder(input);
            }

            container->save();
            std::cout << "Added" << std::endl;
        } else {
            std::cout << "Invalid command!" << std::endl;
        }
    }

    return 0;
}
示例#11
0
/*
 *   If containerFile is NULL, then we don't use that as a source for paths and we set the parent ID to 0.
 */
int TskL01Extract::extractFiles(TskFile * containerFile /*= NULL*/)
{
    static const std::string MSG_PREFIX = "TskL01Extract::extractFiles : ";
    
    try
    {
        m_containerFile = containerFile;

        if (m_archivePath.empty())
        {
            throw TskException(MSG_PREFIX + "No path to archive provided.");
        }

        std::string L01Path = TskUtilities::toUTF8(m_archivePath);
        if (m_containerFile != NULL)
        {
            L01Path = m_containerFile->getPath();
        }

        //m_db.addImageInfo((int)m_img_info->itype, m_img_info->sector_size);
        m_db.addImageName(L01Path.c_str());

        if (openContainer() != 0)
        {
            return -1;
        }

        if (m_imgInfo == NULL)
        {
            throw TskException(MSG_PREFIX +"Images not open yet");
        }

		// Create a map of directory names to file ids to use to 
		// associate files/directories with the correct parent.
		std::map<std::string, uint64_t> directoryMap;

        std::vector<ArchivedFile>::iterator it = m_archivedFiles.begin();
        for (; it != m_archivedFiles.end(); ++it)
        {
            Poco::Path path(it->path);
            Poco::Path parent = it->path.parent();
            std::string name;

            if (path.isDirectory())
            {
                name = path[path.depth() - 1];
            }
            else
            {
                name = path[path.depth()];
            }

            // Determine the parent id of the file.
            uint64_t parentId = 0;
            if (path.depth() == 0 || path.isDirectory() && path.depth() == 1)
            {
                // This file or directory lives at the root so our parent id
                // is the containing file id (if a containing file was provided).
                if (m_containerFile != NULL)
                {
                    parentId = m_containerFile->getId();
                }
            }
            else
            {
                // We are not at the root so we need to lookup the id of our
                // parent directory.
                std::map<std::string, uint64_t>::const_iterator pos;
                pos = directoryMap.find(parent.toString());

                if (pos == directoryMap.end())
                {
                    //error!
                    std::stringstream msg;
                    msg << "extractFiles: parent ID not mapped for " << it->path.toString();
                    LOGERROR(msg.str());
                }
                else
                {
                    parentId = pos->second;
                }
            }

            // Store some extra details about the derived (i.e, extracted) file.
            std::stringstream details;  ///@todo anything here?

            std::string fullpath = "";
            if (m_containerFile != NULL)
            {
                fullpath.append(m_containerFile->getFullPath());
            }
            fullpath.append("\\");
            fullpath.append(path.toString());

            uint64_t fileId;
            if (m_db.addDerivedFileInfo(name,
                parentId,
                path.isDirectory(),
                it->size,
                details.str(), 
                static_cast<int>(it->ctime),
                static_cast<int>(it->crtime),
                static_cast<int>(it->atime),
                static_cast<int>(it->mtime),
                fileId, fullpath) == -1) 
            {
                    std::wstringstream msg;
                    msg << L"addDerivedFileInfo failed for name="
                        << name.c_str();
                    LOGERROR(msg.str());
            }

            if (path.isDirectory())
            {
                directoryMap[path.toString()] = fileId;
            }
            else
            {
                // For file nodes, recreate file locally
                // Will save zero-length files
                if (saveFile(fileId, *it) == 0)
                {
                    // Schedule
                    m_db.updateFileStatus(fileId, TskImgDB::IMGDB_FILES_STATUS_READY_FOR_ANALYSIS);
                    TskServices::Instance().getScheduler().schedule(Scheduler::FileAnalysis, fileId, fileId);
                }
            }
        }

    }
    catch (TskException &ex)
    {
        std::ostringstream msg;
        msg << MSG_PREFIX << "TskException: " << ex.message();
        LOGERROR(msg.str());
        return -1;
    }
    catch (std::exception &ex)
    {
        std::ostringstream msg;
        msg << MSG_PREFIX << "std::exception: " << ex.what();
        LOGERROR(msg.str());
        return -1;
    }
    catch (...)
    {
        LOGERROR(MSG_PREFIX + "unrecognized exception");
        return -1;
    }

    return 0; //success
}
示例#12
0
bool Actions::UseItem(Player* player, const Position &pos,const unsigned char stack,
	const unsigned short itemid, const unsigned char index)
{
	if(canUse(player,pos)== TOO_FAR){
		player->sendCancel("Too far away.");
		return false;
	}
	Item *item = dynamic_cast<Item*>(game->getThing(pos,stack,player));
	if(!item){
		#ifdef __DEBUG__
		std::cout << "no item" << std::endl;
		#endif
		player->sendCancel("You can not use this object.");
		return false;
	}

	if(item->getID() != itemid){
		#ifdef __DEBUG__
		std::cout << "no id" << std::endl;
		#endif
		player->sendCancel("You can not use this object.");
		return false;
	}

#ifdef TLM_HOUSE_SYSTEM
	if (Item::items[itemid].isDoor)
	{
		Tile* tile = game->getTile(pos);
		House* house = tile? tile->getHouse() : NULL;

		if (house && player->access < g_config.ACCESS_HOUSE && house->getPlayerRights(pos, player->getName()) <= HOUSE_GUEST)
		{
			player->sendCancel("You are not allowed to open this door.");
			return false;
		}
	}
#endif //TLM_HOUSE_SYSTEM

	//look for the item in action maps
	Action *action = getAction(item);

	//if found execute it
	if(action){
		Position itempos = game->getThingMapPos(player, pos);
		game->autoCloseTrade(item);
		PositionEx posEx(pos,stack);
		if(action->executeUse(player,item,posEx,posEx)){
			return true;
		}
	}

	//if it is a container try to open it
	if(dynamic_cast<Container*>(item)){
		if(openContainer(player,dynamic_cast<Container*>(item),index))
			return true;
	}

  //we dont know what to do with this item
  player->sendCancel("You can not use this object.");
  return false;
}