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