~ubuntu-branches/ubuntu/vivid/manaplus/vivid-proposed

« back to all changes in this revision

Viewing changes to src/net/ea/tradehandler.cpp

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2014-10-12 12:23:57 UTC
  • mfrom: (1.1.36)
  • Revision ID: package-import@ubuntu.com-20141012122357-7836sgv1j1v02cs2
Tags: 1.4.10.11-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#include "net/ea/tradehandler.h"
24
24
 
25
 
#include "inventory.h"
26
 
#include "item.h"
27
 
#include "logger.h"
28
25
#include "notifymanager.h"
29
26
 
30
27
#include "being/playerinfo.h"
35
32
 
36
33
#include "net/messagein.h"
37
34
 
38
 
#include "net/ea/eaprotocol.h"
39
 
 
40
35
#include "utils/gettext.h"
41
36
 
42
37
#include "resources/notifytypes.h"
78
73
        respond(false);
79
74
        return;
80
75
    }
 
76
    const uint8_t type = msg.readUInt8("type");
 
77
    processTradeResponseContinue(type);
 
78
}
81
79
 
82
 
    switch (msg.readUInt8())
 
80
void TradeHandler::processTradeResponseContinue(const uint8_t type) const
 
81
{
 
82
    switch (type)
83
83
    {
84
84
        case 0:  // Too far away
85
85
            NotifyManager::notify(NotifyTypes::TRADE_FAIL_FAR_AWAY,
119
119
            }
120
120
            PlayerInfo::setTrading(false);
121
121
            break;
 
122
        case 5:
 
123
            NotifyManager::notify(NotifyTypes::TRADE_CANCELLED_BUSY,
 
124
                tradePartnerName);
 
125
            break;
122
126
        default:  // Shouldn't happen as well, but to be sure
123
127
            NotifyManager::notify(NotifyTypes::TRADE_ERROR_UNKNOWN,
124
128
                tradePartnerName);
128
132
    }
129
133
}
130
134
 
131
 
void TradeHandler::processTradeItemAddResponse(Net::MessageIn &msg)
132
 
{
133
 
    // Trade: New Item add response (was 0x00ea, now 01b1)
134
 
    const int index = msg.readInt16() - INVENTORY_OFFSET;
135
 
    Item *item = nullptr;
136
 
    if (PlayerInfo::getInventory())
137
 
        item = PlayerInfo::getInventory()->getItem(index);
138
 
 
139
 
    if (!item)
140
 
    {
141
 
        if (tradeWindow)
142
 
            tradeWindow->receivedOk(true);
143
 
        return;
144
 
    }
145
 
    const int quantity = msg.readInt16();
146
 
 
147
 
    const uint8_t res = msg.readUInt8();
148
 
    switch (res)
149
 
    {
150
 
        case 0:
151
 
            // Successfully added item
152
 
            if (tradeWindow)
153
 
            {
154
 
                tradeWindow->addItem2(item->getId(), true,
155
 
                    quantity, item->getRefine(), item->getColor(),
156
 
                    item->isEquipment());
157
 
            }
158
 
            item->increaseQuantity(-quantity);
159
 
            break;
160
 
        case 1:
161
 
            // Add item failed - player overweighted
162
 
            NotifyManager::notify(NotifyTypes::
163
 
                TRADE_ADD_PARTNER_OVER_WEIGHT);
164
 
            break;
165
 
        case 2:
166
 
            // Add item failed - player has no free slot
167
 
            NotifyManager::notify(NotifyTypes::TRADE_ADD_PARTNER_NO_SLOTS);
168
 
            break;
169
 
        case 3:
170
 
            // Add item failed - non tradable item
171
 
            NotifyManager::notify(NotifyTypes::TRADE_ADD_UNTRADABLE_ITEM);
172
 
            break;
173
 
        default:
174
 
            NotifyManager::notify(NotifyTypes::TRADE_ADD_ERROR);
175
 
            logger->log("QQQ SMSG_TRADE_ITEM_ADD_RESPONSE: "
176
 
                        + toString(res));
177
 
            break;
178
 
    }
179
 
}
180
 
 
181
135
void TradeHandler::processTradeOk(Net::MessageIn &msg)
182
136
{
183
137
    // 0 means ok from myself, 1 means ok from other;