GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/tmwa/partyhandler.cpp Lines: 1 59 1.7 %
Date: 2021-03-17 Branches: 0 68 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2008  Lloyd Bryant <[email protected]>
4
 *  Copyright (C) 2011-2019  The ManaPlus Developers
5
 *  Copyright (C) 2019-2021  Andrei Karas
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/partyhandler.h"
24
25
#include "actormanager.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 "net/ea/partyrecv.h"
34
35
#include "net/tmwa/messageout.h"
36
#include "net/tmwa/protocolout.h"
37
38
#include "debug.h"
39
40
namespace TmwAthena
41
{
42
43
PartyHandler::PartyHandler() :
44
    Ea::PartyHandler()
45
{
46
    partyHandler = this;
47
}
48
49
PartyHandler::~PartyHandler()
50
{
51
    partyHandler = nullptr;
52
}
53
54
void PartyHandler::create(const std::string &name) const
55
{
56
    createOutPacket(CMSG_PARTY_CREATE);
57
    outMsg.writeString(name.substr(0, 23), 24, "party name");
58
}
59
60
void PartyHandler::invite(const std::string &name) const
61
{
62
    if (actorManager == nullptr)
63
        return;
64
65
    const Being *const being = actorManager->findBeingByName(
66
        name, ActorType::Player);
67
    if (being != nullptr)
68
    {
69
        createOutPacket(CMSG_PARTY_INVITE);
70
        outMsg.writeBeingId(being->getId(), "account id");
71
    }
72
}
73
74
void PartyHandler::inviteResponse(const int partyId A_UNUSED,
75
                                  const bool accept) const
76
{
77
    if (localPlayer != nullptr)
78
    {
79
        createOutPacket(CMSG_PARTY_INVITED);
80
        outMsg.writeBeingId(localPlayer->getId(), "account id");
81
        outMsg.writeInt32(accept ? 1 : 0, "accept");
82
    }
83
}
84
85
void PartyHandler::leave() const
86
{
87
    createOutPacket(CMSG_PARTY_LEAVE);
88
}
89
90
void PartyHandler::kick(const Being *const being) const
91
{
92
    if (being != nullptr)
93
    {
94
        createOutPacket(CMSG_PARTY_KICK);
95
        outMsg.writeBeingId(being->getId(), "account id");
96
        outMsg.writeString("", 24, "unused");
97
    }
98
}
99
100
void PartyHandler::kick(const std::string &name) const
101
{
102
    if (Ea::taParty == nullptr)
103
        return;
104
105
    const PartyMember *const m = Ea::taParty->getMember(name);
106
    if (m == nullptr)
107
    {
108
        NotifyManager::notify(NotifyTypes::PARTY_USER_NOT_IN_PARTY, name);
109
        return;
110
    }
111
112
    createOutPacket(CMSG_PARTY_KICK);
113
    outMsg.writeBeingId(m->getID(), "member id");
114
    outMsg.writeString(name, 24, "unused");
115
}
116
117
void PartyHandler::chat(const std::string &text) const
118
{
119
    createOutPacket(CMSG_PARTY_MESSAGE);
120
    outMsg.writeInt16(CAST_S16(text.length() + 4), "len");
121
    outMsg.writeString(text, CAST_S32(text.length()), "text");
122
}
123
124
void PartyHandler::setShareExperience(const PartyShareT share) const
125
{
126
    if (share == PartyShare::NOT_POSSIBLE)
127
        return;
128
129
    createOutPacket(CMSG_PARTY_SETTINGS);
130
    outMsg.writeInt16(CAST_S16(share), "share exp");
131
    outMsg.writeInt16(CAST_S16(Ea::PartyRecv::mShareItems),
132
        "share items");
133
}
134
135
void PartyHandler::setShareItems(const PartyShareT share) const
136
{
137
    if (share == PartyShare::NOT_POSSIBLE)
138
        return;
139
140
    createOutPacket(CMSG_PARTY_SETTINGS);
141
    outMsg.writeInt16(CAST_S16(Ea::PartyRecv::mShareExp),
142
        "share exp");
143
    outMsg.writeInt16(CAST_S16(share), "share items");
144
}
145
146
void PartyHandler::changeLeader(const std::string &name A_UNUSED) const
147
{
148
}
149
150
void PartyHandler::allowInvite(const bool allow A_UNUSED) const
151
{
152
}
153
154
PartyShareT PartyHandler::getShareAutoItems() const
155
{
156
    return PartyShare::NOT_POSSIBLE;
157
}
158
159
void PartyHandler::setShareAutoItems(const PartyShareT share A_UNUSED) const
160
{
161
}
162
163
2
}  // namespace TmwAthena