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