• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Help with Locker/Sending Parcel/Market

dkangel83

Member
Joined
Mar 31, 2010
Messages
148
Reaction score
18
Location
Brazil
Hiho..

I want to create a depot place for no vocation players, but the problem is, anyone would be able to send to them a parcel from mainland, and even the char could buy from market..

is there anyway to block no vocation char from buying items in market also a player to send a parcel to a no vocation player? if yes, could explain detailed how?

i tried to take a look in many places and nothing..

Thanks in Advance

is there anyone able to help?
 
Last edited by a moderator:
http://pastebin.com/xVLdDs2y

It will still error but this is the best I've got so far. getWriter returns the name of the player, not the player pointer, so I have to see if I can work around that.

Thanks but still not able to build/rebuild :/

Code:
1>------ Build started: Project: theforgottenserver, Configuration: Release x64 ------
1>  mailbox.cpp
1>..\src\mailbox.cpp(120): error C2440: 'initializing' : cannot convert from 'const std::string' to 'Player *'
1>          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Code:
1>------ Rebuild All started: Project: theforgottenserver, Configuration: Release x64 ------
1>  otpch.cpp
1>  actions.cpp
1>  ban.cpp
1>  baseevents.cpp
1>  bed.cpp
1>  chat.cpp
1>  combat.cpp
1>  commands.cpp
1>  condition.cpp
1>  configmanager.cpp
1>  connection.cpp
1>  container.cpp
1>  creature.cpp
1>  creatureevent.cpp
1>  cylinder.cpp
1>  database.cpp
1>  databasemanager.cpp
1>  databasetasks.cpp
1>  depotchest.cpp
1>  depotlocker.cpp
1>  events.cpp
1>  fileloader.cpp
1>  game.cpp
1>  globalevent.cpp
1>  groups.cpp
1>  guild.cpp
1>  house.cpp
1>  housetile.cpp
1>  inbox.cpp
1>  ioguild.cpp
1>  iologindata.cpp
1>  iomap.cpp
1>  iomapserialize.cpp
1>  iomarket.cpp
1>  item.cpp
1>  items.cpp
1>  luascript.cpp
1>  mailbox.cpp
1>  map.cpp
1>..\src\mailbox.cpp(120): error C2440: 'initializing' : cannot convert from 'const std::string' to 'Player *'
1>          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>  monster.cpp
1>  monsters.cpp
1>  mounts.cpp
1>  movement.cpp
1>  networkmessage.cpp
1>  npc.cpp
1>  otserv.cpp
1>  outfit.cpp
1>  outputmessage.cpp
1>  party.cpp
1>  player.cpp
1>  position.cpp
1>  protocol.cpp
1>  protocolgame.cpp
1>  protocollogin.cpp
1>  protocolold.cpp
1>..\src\protocollogin.cpp(50): warning C4100: 'version' : unreferenced formal parameter
1>  protocolspectator.cpp
1>  quests.cpp
1>  raids.cpp
1>  rsa.cpp
1>  scheduler.cpp
1>  scriptmanager.cpp
1>  server.cpp
1>  spawn.cpp
1>  spells.cpp
1>  protocolstatus.cpp
1>  talkaction.cpp
1>  tasks.cpp
1>  teleport.cpp
1>  thing.cpp
1>  tile.cpp
1>  tools.cpp
1>  trashholder.cpp
1>  vocation.cpp
1>  waitlist.cpp
1>  weapons.cpp
1>  wildcardtree.cpp
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
 
Code:
/**
* The Forgotten Server - a free and open-source MMORPG server emulator
* Copyright (C) 2015  Mark Samman <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "otpch.h"

#include "mailbox.h"
#include "game.h"
#include "player.h"
#include "iologindata.h"
#include "town.h"

extern Game g_game;

ReturnValue Mailbox::queryAdd(int32_t, const Thing& thing, uint32_t, uint32_t, Creature*) const
{
    const Item* item = thing.getItem();
    if (item && Mailbox::canSend(item)) {
        return RETURNVALUE_NOERROR;
    }
    return RETURNVALUE_NOTPOSSIBLE;
}

ReturnValue Mailbox::queryMaxCount(int32_t, const Thing&, uint32_t count, uint32_t& maxQueryCount, uint32_t) const
{
    maxQueryCount = std::max<uint32_t>(1, count);
    return RETURNVALUE_NOERROR;
}

ReturnValue Mailbox::queryRemove(const Thing&, uint32_t, uint32_t) const
{
    return RETURNVALUE_NOTPOSSIBLE;
}

Cylinder* Mailbox::queryDestination(int32_t&, const Thing&, Item**, uint32_t&)
{
    return this;
}

void Mailbox::addThing(Thing* thing)
{
    return addThing(0, thing);
}

void Mailbox::addThing(int32_t, Thing* thing)
{
    Item* item = thing->getItem();
    if (item && Mailbox::canSend(item)) {
        sendItem(item);
    }
}

void Mailbox::updateThing(Thing*, uint16_t, uint32_t)
{
    //
}

void Mailbox::replaceThing(uint32_t, Thing*)
{
    //
}

void Mailbox::removeThing(Thing*, uint32_t)
{
    //
}

void Mailbox::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, cylinderlink_t)
{
    getParent()->postAddNotification(thing, oldParent, index, LINK_PARENT);
}

void Mailbox::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, cylinderlink_t)
{
    getParent()->postRemoveNotification(thing, newParent, index, LINK_PARENT);
}

bool Mailbox::sendItem(Item* item) const
{
    std::string receiver;
    if (!getReceiver(item, receiver)) {
        return false;
    }

    /**No need to continue if its still empty**/
    if (receiver.empty()) {
        return false;
    }

    Player* player = g_game.getPlayerByName(receiver);
    Container* cont = item->getContainer();
    ItemDeque temp(cont->getItemList());
    Item* itemlist[sizeof(temp)];
    for (int i = 0; i < sizeof(temp); i++) {
        itemlist[i] = temp[i];
    }

    int index = 0;
    for (uint16_t i = 1; i < cont->capacity(); i++) {
        if (itemlist[i]->getID() == ITEM_LABEL) {
            index = i;
        }
    }
    Item* label = itemlist[index];
    Player* writer = label->getWriter();
    if (player) {
        if (player->getVocationId() == VOCATION_NONE) {
            Player* writer = g_game.getPlayerByName(getWriterName(item));
            if (writer) {
                if (g_game.internalMoveItem(item->getParent(), writer->getInbox(), INDEX_WHEREEVER,
                    item, item->getItemCount(), nullptr, FLAG_NOLIMIT) == RETURNVALUE_NOERROR) {
                    g_game.transformItem(item, item->getID() + 1);
                    writer->onReceiveMail();
                    return true;
                }
            }

        }
        else {
            if (g_game.internalMoveItem(item->getParent(), player->getInbox(), INDEX_WHEREEVER,
                item, item->getItemCount(), nullptr, FLAG_NOLIMIT) == RETURNVALUE_NOERROR) {
                g_game.transformItem(item, item->getID() + 1);
                player->onReceiveMail();
                return true;
            }
        }

    }
    else {
        Player tmpPlayer(nullptr);
        if (!IOLoginData::loadPlayerByName(&tmpPlayer, receiver)) {
            return false;
        }

        if (g_game.internalMoveItem(item->getParent(), tmpPlayer.getInbox(), INDEX_WHEREEVER,
            item, item->getItemCount(), nullptr, FLAG_NOLIMIT) == RETURNVALUE_NOERROR) {
            g_game.transformItem(item, item->getID() + 1);
            IOLoginData::savePlayer(&tmpPlayer);
            return true;
        }
    }
    return false;
}

std::string Mailbox::getWriterName(Item* item) const
{
    std::ostringstream s;
    const Container* container = item->getContainer();
    if (container) {
        for (Item* containerItem : container->getItemList()) {
            if (containerItem->getID() == ITEM_LABEL) {
                s << containerItem->getWriter();
                break;
               
            }
           
        }
       
    }
   
        return s.str();
    }

bool Mailbox::getReceiver(Item* item, std::string& name) const
{
    const Container* container = item->getContainer();
    if (container) {
        for (Item* containerItem : container->getItemList()) {
            if (containerItem->getID() == ITEM_LABEL && getReceiver(containerItem, name)) {
                return true;
            }
        }
        return false;
    }

    const std::string& text = item->getText();
    if (text.empty()) {
        return false;
    }

    name = getFirstLine(text);
    trimString(name);
    return true;
}

bool Mailbox::canSend(const Item* item)
{
    return item->getID() == ITEM_PARCEL || item->getID() == ITEM_LETTER;
}

Code:
/**
* The Forgotten Server - a free and open-source MMORPG server emulator
* Copyright (C) 2015  Mark Samman <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef FS_MAILBOX_H_D231C6BE8D384CAAA3AE410C1323F9DB
#define FS_MAILBOX_H_D231C6BE8D384CAAA3AE410C1323F9DB

#include "item.h"
#include "cylinder.h"
#include "const.h"

class Mailbox final : public Item, public Cylinder
{
    public:
        explicit Mailbox(uint16_t itemId) : Item(itemId) {}

        Mailbox* getMailbox() final {
            return this;
        }
        const Mailbox* getMailbox() const final {
            return this;
        }

        //cylinder implementations
        ReturnValue queryAdd(int32_t index, const Thing& thing, uint32_t count,
                uint32_t flags, Creature* actor = nullptr) const final;
        ReturnValue queryMaxCount(int32_t index, const Thing& thing, uint32_t count,
                uint32_t& maxQueryCount, uint32_t flags) const final;
        ReturnValue queryRemove(const Thing& thing, uint32_t count, uint32_t flags) const final;
        Cylinder* queryDestination(int32_t& index, const Thing& thing, Item** destItem,
                uint32_t& flags) final;

        void addThing(Thing* thing) final;
        void addThing(int32_t index, Thing* thing) final;

        void updateThing(Thing* thing, uint16_t itemId, uint32_t count) final;
        void replaceThing(uint32_t index, Thing* thing) final;

        void removeThing(Thing* thing, uint32_t count) final;

        void postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, cylinderlink_t link = LINK_OWNER) final;
        void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, cylinderlink_t link = LINK_OWNER) final;

    private:
        std::string getWriterName(Item* item) const;
        bool getReceiver(Item* item, std::string& name) const;
        bool sendItem(Item* item) const;

        static bool canSend(const Item* item);
};

#endif

Code:
1>------ Build started: Project: theforgottenserver, Configuration: Release x64 ------
1>  item.cpp
1>  mailbox.cpp
1>  tile.cpp
1>..\src\mailbox.cpp(120): error C2440: 'initializing' : cannot convert from 'const std::string' to 'Player *'
1>          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
 
Forgot to mention, the diff were for the original mailbox code.
what should it do?

no error at build/rebuild.. server is running perfectly with no error.. but when i send a parcel from a vocation player to a non vocation player nothing happens..
the aprcel goes thru mailbox but nothing..

im not sure what happens with no vocation player cuz my previous build has the change that i've made to remove the inbox/market from no vocation player..

but theres no error in console and the player with vocation is able to send the parcel
 
It should work now, I've updated the diff from my previous post (once again the diff is for the original code).

just one warning when rebuild and i dont know if it is important
Code:
1>------ Rebuild All started: Project: theforgottenserver, Configuration: Release x64 ------
1>  otpch.cpp
1>  actions.cpp
1>  ban.cpp
1>  baseevents.cpp
1>  bed.cpp
1>  chat.cpp
1>  combat.cpp
1>  commands.cpp
1>  condition.cpp
1>  configmanager.cpp
1>  connection.cpp
1>  container.cpp
1>  creature.cpp
1>  creatureevent.cpp
1>  cylinder.cpp
1>  database.cpp
1>  databasemanager.cpp
1>  databasetasks.cpp
1>  depotchest.cpp
1>  depotlocker.cpp
1>  events.cpp
1>  fileloader.cpp
1>  game.cpp
1>  globalevent.cpp
1>  groups.cpp
1>  guild.cpp
1>  house.cpp
1>  housetile.cpp
1>  inbox.cpp
1>  ioguild.cpp
1>  iologindata.cpp
1>  iomap.cpp
1>  iomapserialize.cpp
1>  iomarket.cpp
1>  item.cpp
1>  items.cpp
1>  luascript.cpp
1>  mailbox.cpp
1>  map.cpp
1>  monster.cpp
1>  monsters.cpp
1>  mounts.cpp
1>  movement.cpp
1>  networkmessage.cpp
1>  npc.cpp
1>  otserv.cpp
1>  outfit.cpp
1>  outputmessage.cpp
1>  party.cpp
1>  player.cpp
1>  position.cpp
1>  protocol.cpp
1>  protocolgame.cpp
1>  protocollogin.cpp
1>  protocolold.cpp
1>  protocolspectator.cpp
1>..\src\protocollogin.cpp(50): warning C4100: 'version' : unreferenced formal parameter
1>  quests.cpp
1>  raids.cpp
1>  rsa.cpp
1>  scheduler.cpp
1>  scriptmanager.cpp
1>  server.cpp
1>  spawn.cpp
1>  spells.cpp
1>  protocolstatus.cpp
1>  talkaction.cpp
1>  tasks.cpp
1>  teleport.cpp
1>  thing.cpp
1>  tile.cpp
1>  tools.cpp
1>  trashholder.cpp
1>  vocation.cpp
1>  waitlist.cpp
1>  weapons.cpp
1>  wildcardtree.cpp
1>  Generating code
1>c:\testes\forgottenserver-master\src\mailbox.cpp(126): warning C4715: 'Mailbox::sendItem' : not all control paths return a value
1>  Finished generating code
1>  theforgottenserver.vcxproj -> C:\testes\forgottenserver-master\vc12\x64\Release\theforgottenserver.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

its done.. i was performing some tests.. its working fine.. Player with vocation cant send parcel to a no vocation player butr is able to send to any player with vocation..

no vocation player isnt able to send parcel to anyone..

Im just concerned about this little warning... anyway thanks both @RazorBlade and you @Ninja for helping.. since its a good thing i'd like to have your permission to share it.. ofc i'll give credits .. theres a guy with the same doubt and may be others.. if not its okay i understand..
 
Back
Top