GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/cashshoprecv.cpp Lines: 1 82 1.2 %
Date: 2021-03-17 Branches: 0 56 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2019  The ManaPlus Developers
4
 *  Copyright (C) 2019-2021  Andrei Karas
5
 *
6
 *  This file is part of The ManaPlus Client.
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  any later version.
12
 *
13
 *  This program is distributed in the hope that it will be useful,
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *  GNU General Public License for more details.
17
 *
18
 *  You should have received a copy of the GNU General Public License
19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
#include "net/eathena/cashshoprecv.h"
23
24
#include "notifymanager.h"
25
26
#include "const/resources/currency.h"
27
28
#include "enums/resources/notifytypes.h"
29
30
#include "gui/windows/buydialog.h"
31
32
#include "gui/widgets/createwidget.h"
33
34
#include "net/messagein.h"
35
36
#include "net/eathena/npcrecv.h"
37
38
#include "resources/beinginfo.h"
39
40
#include "resources/db/npcdb.h"
41
42
#include "debug.h"
43
44
extern int packetVersion;
45
extern int itemIdLen;
46
47
namespace EAthena
48
{
49
50
namespace CashShopRecv
51
{
52
    BuyDialog *mBuyDialog;
53
}  // namespace CashShopRecv
54
55
void CashShopRecv::processCashShopOpen(Net::MessageIn &msg)
56
{
57
    int count;
58
    int blockSize = 11;
59
    if (itemIdLen == 4)
60
        blockSize += 2;
61
    if (packetVersion >= 20070711)
62
        count = (msg.readInt16("len") - 12) / blockSize;
63
    else
64
        count = (msg.readInt16("len") - 8) / blockSize;
65
66
    const BeingTypeId npcId = NpcRecv::mNpcTypeId;
67
    std::string currency;
68
69
    if (npcId != BeingTypeId_zero)
70
    {
71
        const BeingInfo *const info = NPCDB::get(npcId);
72
        if (info != nullptr)
73
            currency = info->getCurrency();
74
        else
75
            currency = DEFAULT_CURRENCY;
76
    }
77
    else
78
    {
79
        currency = DEFAULT_CURRENCY;
80
    }
81
    CREATEWIDGETV(mBuyDialog, BuyDialog,
82
        fromInt(BuyDialog::Cash, BeingId),
83
        currency);
84
    const int points = msg.readInt32("cash points");
85
86
    mBuyDialog->setMoney(points);
87
88
    if (packetVersion >= 20070711)
89
        msg.readInt32("kafra points");
90
    for (int f = 0; f < count; f ++)
91
    {
92
        msg.readInt32("price");
93
        const int value = msg.readInt32("discount price");
94
        const ItemTypeT type = static_cast<ItemTypeT>(
95
            msg.readUInt8("item type"));
96
        const int itemId = msg.readItemId("item id");
97
        const ItemColor color = ItemColor_one;
98
        mBuyDialog->addItem(itemId, type, color, 0, value);
99
    }
100
    mBuyDialog->sort();
101
}
102
103
void CashShopRecv::processCashShopBuyAck(Net::MessageIn &msg)
104
{
105
    msg.readInt32("cash points");
106
    msg.readInt32("kafra points");
107
    const uint16_t res = msg.readInt16("error");
108
    switch (res)
109
    {
110
        case 0:
111
            NotifyManager::notify(NotifyTypes::BUY_DONE);
112
            break;
113
        case 1:
114
            NotifyManager::notify(NotifyTypes::BUY_FAILED_NPC_NOT_FOUND);
115
            break;
116
        case 2:
117
            NotifyManager::notify(NotifyTypes::BUY_FAILED_SYSTEM_ERROR);
118
            break;
119
        case 3:
120
            NotifyManager::notify(NotifyTypes::BUY_FAILED_OVERWEIGHT);
121
            break;
122
        case 4:
123
            NotifyManager::notify(NotifyTypes::BUY_TRADE_FAILED);
124
            break;
125
        case 5:
126
            NotifyManager::notify(NotifyTypes::BUY_FAILED_WRONG_ITEM);
127
            break;
128
        case 6:
129
            NotifyManager::notify(NotifyTypes::BUY_FAILED_NO_MONEY);
130
            break;
131
        default:
132
            UNIMPLEMENTEDPACKETFIELD(res);
133
            break;
134
    }
135
}
136
137
void CashShopRecv::processCashShopPoints(Net::MessageIn &msg)
138
{
139
    UNIMPLEMENTEDPACKET;
140
    msg.readInt32("cash points");
141
    msg.readInt32("kafra points");
142
}
143
144
void CashShopRecv::processCashShopBuy(Net::MessageIn &msg)
145
{
146
    UNIMPLEMENTEDPACKET;
147
    msg.readInt32("id");
148
    msg.readInt16("result");
149
    msg.readInt32("cash points");
150
    msg.readInt32("kafra points");
151
}
152
153
void CashShopRecv::processCashShopTabPriceList(Net::MessageIn &msg)
154
{
155
    UNIMPLEMENTEDPACKET;
156
    const int count = (msg.readInt16("len") - 10) / 6;
157
    msg.readInt32("tab");
158
    const int itemsCount = msg.readInt16("count");
159
    if (count != itemsCount)
160
        logger->log("error: wrong list count");
161
162
    for (int f = 0; f < count; f ++)
163
    {
164
        msg.readInt16("item id");  // item id size always 16 bit
165
        msg.readInt32("price");
166
    }
167
}
168
169
void CashShopRecv::processCashShopSchedule(Net::MessageIn &msg)
170
{
171
    UNIMPLEMENTEDPACKET;
172
    int blockSize = 6;
173
    if (itemIdLen == 4)
174
        blockSize += 2;
175
    const int count = (msg.readInt16("len") - 8) / blockSize;
176
    const int itemsCount = msg.readInt16("count");
177
    msg.readInt16("tab");
178
    if (count != itemsCount)
179
        logger->log("error: wrong list count");
180
181
    for (int f = 0; f < count; f ++)
182
    {
183
        msg.readItemId("item id");
184
        msg.readInt32("price");
185
    }
186
}
187
188
2
}  // namespace EAthena