GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/ea/partyrecv.cpp Lines: 1 100 1.0 %
Date: 2017-11-29 Branches: 0 106 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2008  Lloyd Bryant <[email protected]>
4
 *  Copyright (C) 2011-2017  The ManaPlus Developers
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/ea/partyrecv.h"
23
24
#include "actormanager.h"
25
#include "configuration.h"
26
#include "notifymanager.h"
27
#include "party.h"
28
29
#include "being/localplayer.h"
30
31
#include "enums/resources/notifytypes.h"
32
33
#include "gui/windows/chatwindow.h"
34
#include "gui/windows/socialwindow.h"
35
36
#include "net/messagein.h"
37
38
#include "gui/widgets/tabs/chat/partytab.h"
39
40
#include "utils/delete2.h"
41
42
#include "debug.h"
43
44
namespace Ea
45
{
46
47
Party *taParty = nullptr;
48
49
namespace PartyRecv
50
{
51
    PartyShareT mShareExp = PartyShare::UNKNOWN;
52
    PartyShareT mShareItems = PartyShare::UNKNOWN;
53
}  // namespace PartyRecv
54
55
void PartyRecv::processPartyCreate(Net::MessageIn &msg)
56
{
57
    if (msg.readUInt8("flag") != 0u)
58
        NotifyManager::notify(NotifyTypes::PARTY_CREATE_FAILED);
59
    else
60
        NotifyManager::notify(NotifyTypes::PARTY_CREATED);
61
}
62
63
void PartyRecv::processPartyExpSettingsContinue(Net::MessageIn &msg,
64
                                                const PartyShareT exp)
65
{
66
    switch (exp)
67
    {
68
        case PartyShare::YES:
69
            if (mShareExp == PartyShare::YES)
70
                break;
71
            mShareExp = PartyShare::YES;
72
            NotifyManager::notify(NotifyTypes::PARTY_EXP_SHARE_ON);
73
            break;
74
        case PartyShare::NO:
75
            if (mShareExp == PartyShare::NO)
76
                break;
77
            mShareExp = PartyShare::NO;
78
            NotifyManager::notify(NotifyTypes::PARTY_EXP_SHARE_OFF);
79
            break;
80
        case PartyShare::NOT_POSSIBLE:
81
            if (mShareExp == PartyShare::NOT_POSSIBLE)
82
                break;
83
            mShareExp = PartyShare::NOT_POSSIBLE;
84
            NotifyManager::notify(NotifyTypes::PARTY_EXP_SHARE_ERROR);
85
            break;
86
        default:
87
        case PartyShare::UNKNOWN:
88
            UNIMPLEMENTEDPACKETFIELD(CAST_S32(exp));
89
            break;
90
    }
91
}
92
93
void PartyRecv::processPartyItemSettingsContinue(Net::MessageIn &msg,
94
                                                 const PartyShareT item)
95
{
96
    switch (item)
97
    {
98
        case PartyShare::YES:
99
            if (mShareItems == PartyShare::YES)
100
                break;
101
            mShareItems = PartyShare::YES;
102
            NotifyManager::notify(NotifyTypes::PARTY_ITEM_SHARE_ON);
103
            break;
104
        case PartyShare::NO:
105
            if (mShareItems == PartyShare::NO)
106
                break;
107
            mShareItems = PartyShare::NO;
108
            NotifyManager::notify(NotifyTypes::PARTY_ITEM_SHARE_OFF);
109
            break;
110
        case PartyShare::NOT_POSSIBLE:
111
            if (mShareItems == PartyShare::NOT_POSSIBLE)
112
                break;
113
            mShareItems = PartyShare::NOT_POSSIBLE;
114
            NotifyManager::notify(NotifyTypes::PARTY_ITEM_SHARE_ERROR);
115
            break;
116
        default:
117
        case PartyShare::UNKNOWN:
118
            UNIMPLEMENTEDPACKETFIELD(CAST_S32(item));
119
            break;
120
    }
121
}
122
123
void PartyRecv::processPartyLeave(Net::MessageIn &msg)
124
{
125
    const BeingId id = msg.readBeingId("account id");
126
    const std::string nick = msg.readString(24, "nick");
127
    const int reason = msg.readUInt8("flag");
128
    if (localPlayer == nullptr)
129
        return;
130
131
    if (id == localPlayer->getId())
132
    {
133
        switch (reason)
134
        {
135
            case 0:
136
            default:
137
                NotifyManager::notify(NotifyTypes::PARTY_LEFT);
138
                break;
139
140
            case 1:
141
                NotifyManager::notify(NotifyTypes::PARTY_KICKED);
142
                break;
143
144
            case 2:
145
                NotifyManager::notify(NotifyTypes::PARTY_LEFT_DENY);
146
                break;
147
148
            case 3:
149
                NotifyManager::notify(NotifyTypes::PARTY_KICK_DENY);
150
                break;
151
        }
152
153
        if (reason >= 2)
154
            return;
155
156
        if (Ea::taParty != nullptr)
157
        {
158
            Ea::taParty->removeFromMembers();
159
            Ea::taParty->clearMembers();
160
        }
161
162
        delete2(partyTab)
163
164
        if ((socialWindow != nullptr) && (Ea::taParty != nullptr))
165
            socialWindow->removeTab(Ea::taParty);
166
        localPlayer->setPartyName("");
167
    }
168
    else
169
    {
170
        switch (reason)
171
        {
172
            case 0:
173
            default:
174
                NotifyManager::notify(NotifyTypes::PARTY_USER_LEFT, nick);
175
                break;
176
177
            case 1:
178
                NotifyManager::notify(NotifyTypes::PARTY_USER_KICKED, nick);
179
                break;
180
181
            case 2:
182
                NotifyManager::notify(NotifyTypes::PARTY_USER_LEFT_DENY, nick);
183
                break;
184
185
            case 3:
186
                NotifyManager::notify(NotifyTypes::PARTY_USER_KICK_DENY, nick);
187
                break;
188
        }
189
190
        if (reason >= 2)
191
            return;
192
193
        if (actorManager != nullptr)
194
        {
195
            Being *const b = actorManager->findBeing(id);
196
            if ((b != nullptr) && b->getType() == ActorType::Player)
197
            {
198
                b->setParty(nullptr);
199
                b->setPartyName("");
200
            }
201
        }
202
        if (Ea::taParty != nullptr)
203
            Ea::taParty->removeMember(id);
204
    }
205
}
206
207
void PartyRecv::processPartyUpdateCoords(Net::MessageIn &msg)
208
{
209
    const BeingId id = msg.readBeingId("account id");
210
    PartyMember *m = nullptr;
211
    if (Ea::taParty != nullptr)
212
        m = Ea::taParty->getMember(id);
213
    if (m != nullptr)
214
    {
215
        m->setX(msg.readInt16("x"));
216
        m->setY(msg.readInt16("y"));
217
    }
218
    else
219
    {
220
        msg.readInt16("x");
221
        msg.readInt16("y");
222
    }
223
}
224
225
void PartyRecv::createTab()
226
{
227
    partyTab = new PartyTab(chatWindow);
228
    if (config.getBoolValue("showChatHistory"))
229
        partyTab->loadFromLogFile("#Party");
230
}
231
232
4
}  // namespace Ea