GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/tmwa/buysellhandler.cpp Lines: 0 43 0.0 %
Date: 2019-10-15 Branches: 0 80 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-2019  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/tmwa/buysellhandler.h"
24
25
#include "configuration.h"
26
27
#include "gui/windows/chatwindow.h"
28
#include "gui/windows/shopwindow.h"
29
30
#include "net/chathandler.h"
31
32
#include "net/ea/buysellrecv.h"
33
34
#include "net/tmwa/chatrecv.h"
35
36
#include "utils/timer.h"
37
38
#include "debug.h"
39
40
namespace TmwAthena
41
{
42
43
BuySellHandler::BuySellHandler() :
44
    Ea::BuySellHandler()
45
{
46
    buySellHandler = this;
47
    Ea::BuySellRecv::mBuyDialog = nullptr;
48
}
49
50
BuySellHandler::~BuySellHandler()
51
{
52
    buySellHandler = nullptr;
53
}
54
55
void BuySellHandler::requestSellList(const std::string &nick) const
56
{
57
    if (nick.empty() || shopWindow == nullptr)
58
        return;
59
60
    const std::string data("!selllist " + toString(tick_time));
61
    shopWindow->setAcceptPlayer(nick);
62
    ChatRecv::mShopRequestName = nick;
63
    if (config.getBoolValue("hideShopMessages"))
64
    {
65
        chatHandler->privateMessage(nick, data);
66
    }
67
    else
68
    {
69
        if (chatWindow != nullptr)
70
            chatWindow->addWhisper(nick, data, ChatMsgType::BY_PLAYER);
71
    }
72
}
73
74
void BuySellHandler::requestBuyList(const std::string &nick) const
75
{
76
    if (nick.empty() || (shopWindow == nullptr))
77
        return;
78
79
    const std::string data("!buylist " + toString(tick_time));
80
    shopWindow->setAcceptPlayer(nick);
81
    ChatRecv::mShopRequestName = nick;
82
    if (config.getBoolValue("hideShopMessages"))
83
    {
84
        chatHandler->privateMessage(nick, data);
85
    }
86
    else
87
    {
88
        if (chatWindow != nullptr)
89
            chatWindow->addWhisper(nick, data, ChatMsgType::BY_PLAYER);
90
    }
91
}
92
93
void BuySellHandler::sendBuyRequest(const std::string &nick,
94
                                    const ShopItem *const item,
95
                                    const int amount) const
96
{
97
    if ((chatWindow == nullptr) || nick.empty() || (item == nullptr) ||
98
        amount < 1 || amount > item->getQuantity())
99
    {
100
        return;
101
    }
102
    const std::string data = strprintf("!buyitem %d %d %d",
103
        item->getId(), item->getPrice(), amount);
104
105
    if (config.getBoolValue("hideShopMessages"))
106
        chatHandler->privateMessage(nick, data);
107
    else
108
        chatWindow->addWhisper(nick, data, ChatMsgType::BY_PLAYER);
109
}
110
111
void BuySellHandler::sendSellRequest(const std::string &nick,
112
                                     const ShopItem *const item,
113
                                     const int amount) const
114
{
115
    if ((chatWindow == nullptr) || nick.empty() || (item == nullptr) ||
116
        amount < 1 || amount > item->getQuantity())
117
    {
118
        return;
119
    }
120
121
    const std::string data = strprintf("!sellitem %d %d %d",
122
        item->getId(), item->getPrice(), amount);
123
124
    if (config.getBoolValue("hideShopMessages"))
125
        chatHandler->privateMessage(nick, data);
126
    else
127
        chatWindow->addWhisper(nick, data, ChatMsgType::BY_PLAYER);
128
}
129
130
void BuySellHandler::close() const
131
{
132
}
133
134
}  // namespace TmwAthena