GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/traderecv.cpp Lines: 0 63 0.0 %
Date: 2017-11-29 Branches: 0 36 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#include "net/eathena/traderecv.h"
24
25
#include "itemcolormanager.h"
26
#include "notifymanager.h"
27
28
#include "being/playerinfo.h"
29
30
#include "enums/resources/notifytypes.h"
31
32
#include "gui/windows/tradewindow.h"
33
34
#include "net/messagein.h"
35
36
#include "net/ea/traderecv.h"
37
38
#include "resources/inventory/inventory.h"
39
40
#include "resources/item/item.h"
41
#include "resources/item/itemoptionslist.h"
42
43
#include "debug.h"
44
45
extern int serverVersion;
46
47
namespace EAthena
48
{
49
50
namespace TradeRecv
51
{
52
    int mQuantity = 0;
53
    int mItemIndex = -1;
54
}  // namespace TradeRecv
55
56
void TradeRecv::processTradeRequest(Net::MessageIn &msg)
57
{
58
    const std::string &partner = msg.readString(24, "name");
59
    if (msg.getVersion() >= 6)
60
    {
61
        msg.readInt32("char id");
62
        msg.readInt16("base level");
63
    }
64
    Ea::TradeRecv::processTradeRequestContinue(partner);
65
}
66
67
void TradeRecv::processTradeResponse(Net::MessageIn &msg)
68
{
69
    const uint8_t type = msg.readUInt8("type");
70
    msg.readInt32("char id");
71
    msg.readInt16("base level");
72
    Ea::TradeRecv::processTradeResponseContinue(type);
73
}
74
75
void TradeRecv::processTradeItemAdd(Net::MessageIn &msg)
76
{
77
    const int type = msg.readInt16("type");
78
    ItemTypeT itemType = ItemType::Unknown;
79
    if (msg.getVersion() >= 20100223)
80
    {
81
        itemType = static_cast<ItemTypeT>(
82
            msg.readUInt8("item type"));
83
    }
84
    const int amount = msg.readInt32("amount");
85
    const uint8_t identify = msg.readUInt8("identify");
86
    const Damaged damaged = fromBool(msg.readUInt8("attribute"), Damaged);
87
    const uint8_t refine = msg.readUInt8("refine");
88
    int cards[maxCards];
89
    for (int f = 0; f < maxCards; f++)
90
        cards[f] = msg.readUInt16("card");
91
    ItemOptionsList *options = nullptr;
92
    if (msg.getVersion() >= 20150226)
93
    {
94
        options = new ItemOptionsList;
95
        for (int f = 0; f < 5; f ++)
96
        {
97
            const uint16_t idx = msg.readInt16("option index");
98
            const uint16_t val = msg.readInt16("option value");
99
            msg.readUInt8("option param");
100
            options->add(idx, val);
101
        }
102
    }
103
104
    if (tradeWindow != nullptr)
105
    {
106
        if (type == 0)
107
        {
108
            tradeWindow->setMoney(amount);
109
        }
110
        else
111
        {
112
            tradeWindow->addItem2(type,
113
                itemType,
114
                cards,
115
                options,
116
                4,
117
                false,
118
                amount,
119
                refine,
120
                ItemColorManager::getColorFromCards(&cards[0]),
121
                fromBool(identify, Identified),
122
                damaged,
123
                Favorite_false,
124
                Equipm_false);
125
        }
126
    }
127
    delete options;
128
}
129
130
void TradeRecv::processTradeItemAddResponse(Net::MessageIn &msg)
131
{
132
    msg.readInt16("index");
133
    const uint8_t res = msg.readUInt8("fail");
134
    switch (res)
135
    {
136
        case 0:  // Successfully added item
137
        case 9:  // silent added item
138
        {
139
            Item *const item = PlayerInfo::getInventory()->getItem(
140
                mItemIndex);
141
            if (item == nullptr)
142
                return;
143
            if (tradeWindow != nullptr)
144
            {
145
                tradeWindow->addItem2(item->getId(),
146
                    item->getType(),
147
                    item->getCards(),
148
                    item->getOptions(),
149
                    4,
150
                    true,
151
                    mQuantity,
152
                    item->getRefine(),
153
                    item->getColor(),
154
                    item->getIdentified(),
155
                    item->getDamaged(),
156
                    item->getFavorite(),
157
                    item->isEquipment());
158
            }
159
            item->increaseQuantity(-mQuantity);
160
            mItemIndex = -1;
161
            mQuantity = 0;
162
            break;
163
        }
164
        case 1:
165
            // Add item failed - player overweighted
166
            NotifyManager::notify(NotifyTypes::
167
                TRADE_ADD_PARTNER_OVER_WEIGHT);
168
            break;
169
        case 2:
170
            NotifyManager::notify(NotifyTypes::TRADE_ADD_ERROR);
171
            break;
172
        default:
173
            NotifyManager::notify(NotifyTypes::TRADE_ADD_ERROR);
174
            UNIMPLEMENTEDPACKETFIELD(res);
175
            break;
176
    }
177
}
178
179
void TradeRecv::processTradeUndo(Net::MessageIn &msg)
180
{
181
    UNIMPLEMENTEDPACKET;
182
    // +++ here need clear trade window from partner side?
183
}
184
185
}  // namespace EAthena