ManaPlus
partyhandler.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2008 Lloyd Bryant <[email protected]>
4  * Copyright (C) 2011-2018 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 
23 
24 #include "actormanager.h"
25 #include "notifymanager.h"
26 #include "party.h"
27 
28 #include "being/localplayer.h"
29 
31 
32 #include "net/ea/partyrecv.h"
33 
34 #include "net/eathena/messageout.h"
35 #include "net/eathena/partyrecv.h"
37 
38 #include "debug.h"
39 
40 extern int packetVersion;
41 
42 namespace EAthena
43 {
44 
46  Ea::PartyHandler()
47 {
48  partyHandler = this;
49 }
50 
52 {
53  partyHandler = nullptr;
54 }
55 
56 void PartyHandler::create(const std::string &name) const
57 {
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  {
71  outMsg.writeBeingId(being->getId(), "account id");
72  }
73  else
74  {
75  if (packetVersion < 20070227)
76  return;
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  {
88  outMsg.writeInt32(partyId, "party id");
89  outMsg.writeInt8(CAST_S8(accept ? 1 : 0), "accept");
90  }
91 }
92 
93 void PartyHandler::leave() const
94 {
96 }
97 
98 void PartyHandler::kick(const Being *const being) const
99 {
100  if (being != nullptr)
101  {
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  {
117  return;
118  }
119 
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 {
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
145 {
146  if (share == PartyShare::NOT_POSSIBLE)
147  return;
148 
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
164 {
165  if (share == PartyShare::NOT_POSSIBLE)
166  return;
167 
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  if (actorManager == nullptr)
180  return;
181  const Being *const being = actorManager->findBeingByName(
182  name, ActorType::Player);
183  if (being == nullptr)
184  return;
186  outMsg.writeBeingId(being->getId(), "account id");
187 }
188 
189 void PartyHandler::allowInvite(const bool allow) const
190 {
192  outMsg.writeInt8(CAST_S8(allow ? 1 : 0), "allow");
193 }
194 
196 {
198 }
199 
201 {
203 }
204 
205 } // namespace EAthena
int CMSG_PARTY_KICK
void setShareItems(const PartyShareT share) const
void changeLeader(const std::string &name) const
PartyShareT mShareExp
Definition: partyrecv.cpp:51
Party * taParty
Definition: partyrecv.cpp:47
BeingId getID() const
Definition: avatar.h:149
int CMSG_PARTY_INVITE
BeingId getId() const
Definition: actorsprite.h:63
PartyShare ::T PartyShareT
Definition: partyshare.h:35
int packetVersion
Definition: client.cpp:124
PartyShareT mShareAutoItems
Definition: partyrecv.cpp:52
void chat(const std::string &text) const
void notify(const unsigned int message)
int CMSG_PARTY_INVITE2
PartyShareT mShareItems
Definition: partyrecv.cpp:52
PartyShareT getShareAutoItems() const
int CMSG_PARTY_LEAVE
#define CAST_S32
Definition: cast.h:29
int CMSG_PARTY_CHANGE_LEADER
LocalPlayer * localPlayer
PartyMember * getMember(const BeingId id) const
Definition: party.cpp:98
#define CAST_S8
Definition: cast.h:25
void setShareExperience(const PartyShareT share) const
int CMSG_PARTY_ALLOW_INVITES
const std::string & getName() const
Definition: being.h:231
#define createOutPacket(name)
Definition: messageout.h:36
void inviteResponse(const int partyId, const bool accept) const
void invite(const std::string &name) const
void setShareAutoItems(const PartyShareT share) const
void create(const std::string &name) const
void allowInvite(const bool allow) const
Net::PartyHandler * partyHandler
Definition: net.cpp:91
Being * findBeingByName(const std::string &name, const ActorTypeT type) const
int CMSG_PARTY_SETTINGS
#define CAST_S16
Definition: cast.h:27
int CMSG_PARTY_INVITED2
int CMSG_PARTY_CREATE
int CMSG_PARTY_MESSAGE
Definition: being.h:93
void kick(const Being *const being) const
ActorManager * actorManager