GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/partyhandler.cpp Lines: 1 79 1.3 %
Date: 2017-11-29 Branches: 0 100 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/eathena/partyhandler.h"
23
24
#include "actormanager.h"
25
#include "notifymanager.h"
26
#include "party.h"
27
28
#include "being/localplayer.h"
29
30
#include "enums/resources/notifytypes.h"
31
32
#include "net/ea/partyrecv.h"
33
34
#include "net/eathena/messageout.h"
35
#include "net/eathena/partyrecv.h"
36
#include "net/eathena/protocolout.h"
37
38
#include "debug.h"
39
40
extern int packetVersion;
41
42
namespace EAthena
43
{
44
45
PartyHandler::PartyHandler() :
46
    Ea::PartyHandler()
47
{
48
    partyHandler = this;
49
}
50
51
PartyHandler::~PartyHandler()
52
{
53
    partyHandler = nullptr;
54
}
55
56
void PartyHandler::create(const std::string &name) const
57
{
58
    createOutPacket(CMSG_PARTY_CREATE);
59
    outMsg.writeString(name.substr(0, 23), 24, "party name");
60
}
61
62
void PartyHandler::invite(const std::string &name) const
63
{
64
    if (actorManager == nullptr)
65
        return;
66
    const Being *const being = actorManager->findBeingByName(
67
        name, ActorType::Player);
68
    if (being != nullptr)
69
    {
70
        createOutPacket(CMSG_PARTY_INVITE);
71
        outMsg.writeBeingId(being->getId(), "account id");
72
    }
73
    else
74
    {
75
        if (packetVersion < 20070227)
76
            return;
77
        createOutPacket(CMSG_PARTY_INVITE2);
78
        outMsg.writeString(name, 24, "nick");
79
    }
80
}
81
82
void PartyHandler::inviteResponse(const int partyId,
83
                                  const bool accept) const
84
{
85
    if (localPlayer != nullptr)
86
    {
87
        createOutPacket(CMSG_PARTY_INVITED2);
88
        outMsg.writeInt32(partyId, "party id");
89
        outMsg.writeInt8(CAST_S8(accept ? 1 : 0), "accept");
90
    }
91
}
92
93
void PartyHandler::leave() const
94
{
95
    createOutPacket(CMSG_PARTY_LEAVE);
96
}
97
98
void PartyHandler::kick(const Being *const being) const
99
{
100
    if (being != nullptr)
101
    {
102
        createOutPacket(CMSG_PARTY_KICK);
103
        outMsg.writeBeingId(being->getId(), "account id");
104
        outMsg.writeString(being->getName(), 24, "player name");
105
    }
106
}
107
108
void PartyHandler::kick(const std::string &name) const
109
{
110
    if (Ea::taParty == nullptr)
111
        return;
112
113
    const PartyMember *const m = Ea::taParty->getMember(name);
114
    if (m == nullptr)
115
    {
116
        NotifyManager::notify(NotifyTypes::PARTY_USER_NOT_IN_PARTY, name);
117
        return;
118
    }
119
120
    createOutPacket(CMSG_PARTY_KICK);
121
    outMsg.writeBeingId(m->getID(), "account id");
122
    outMsg.writeString(name, 24, "player name");
123
}
124
125
void PartyHandler::chat(const std::string &text) const
126
{
127
    createOutPacket(CMSG_PARTY_MESSAGE);
128
    const std::string mes = std::string(localPlayer->getName()).append(
129
        " : ").append(text);
130
    if (packetVersion >= 20151001)
131
    {
132
        outMsg.writeInt16(CAST_S16(mes.length() + 4), "len");
133
        outMsg.writeString(mes, CAST_S32(mes.length()), "nick : message");
134
    }
135
    else
136
    {
137
        outMsg.writeInt16(CAST_S16(mes.length() + 4 + 1), "len");
138
        outMsg.writeString(mes, CAST_S32(mes.length()), "nick : message");
139
        outMsg.writeInt8(0, "null char");
140
    }
141
}
142
143
// +++ must be 3 types item, exp, pickup
144
void PartyHandler::setShareExperience(const PartyShareT share) const
145
{
146
    if (share == PartyShare::NOT_POSSIBLE)
147
        return;
148
149
    createOutPacket(CMSG_PARTY_SETTINGS);
150
    if (packetVersion >= 20090603)
151
    {
152
        outMsg.writeInt32(CAST_S32(share), "share exp");
153
        outMsg.writeInt16(CAST_S16(Ea::PartyRecv::mShareItems),
154
            "share items");
155
    }
156
    else
157
    {
158
        outMsg.writeInt32(CAST_S32(share), "share exp");
159
    }
160
}
161
162
// +++ must be 3 types item, exp, pickup
163
void PartyHandler::setShareItems(const PartyShareT share) const
164
{
165
    if (share == PartyShare::NOT_POSSIBLE)
166
        return;
167
168
    createOutPacket(CMSG_PARTY_SETTINGS);
169
    if (packetVersion >= 20090603)
170
    {
171
        outMsg.writeInt32(CAST_S32(Ea::PartyRecv::mShareExp),
172
            "share exp");
173
        outMsg.writeInt16(CAST_S16(share), "share items");
174
    }
175
}
176
177
void PartyHandler::changeLeader(const std::string &name) const
178
{
179
    const Being *const being = actorManager->findBeingByName(
180
        name, ActorType::Player);
181
    if (being == nullptr)
182
        return;
183
    createOutPacket(CMSG_PARTY_CHANGE_LEADER);
184
    outMsg.writeBeingId(being->getId(), "account id");
185
}
186
187
void PartyHandler::allowInvite(const bool allow) const
188
{
189
    createOutPacket(CMSG_PARTY_ALLOW_INVITES);
190
    outMsg.writeInt8(CAST_S8(allow ? 1 : 0), "allow");
191
}
192
193
PartyShareT PartyHandler::getShareAutoItems() const
194
{
195
    return PartyRecv::mShareAutoItems;
196
}
197
198
void PartyHandler::setShareAutoItems(const PartyShareT share) const
199
{
200
    PartyRecv::mShareAutoItems = share;
201
}
202
203
4
}  // namespace EAthena