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-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 
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 
44  Ea::PartyHandler()
45 {
46  partyHandler = this;
47 }
48 
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  {
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 
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 
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 
155 {
157 }
158 
160 {
161 }
162 
163 } // namespace TmwAthena
ActorManager * actorManager
#define CAST_S16
Definition: cast.h:28
#define CAST_S32
Definition: cast.h:30
Being * findBeingByName(const std::string &name, const ActorTypeT type) const
BeingId getId() const
Definition: actorsprite.h:64
BeingId getID() const
Definition: avatar.h:150
Definition: being.h:96
PartyMember * getMember(const BeingId id) const
Definition: party.cpp:99
void chat(const std::string &text) const
void setShareExperience(const PartyShareT share) const
void allowInvite(const bool allow) const
void inviteResponse(const int partyId, const bool accept) const
void create(const std::string &name) const
void changeLeader(const std::string &name) const
PartyShareT getShareAutoItems() const
void kick(const Being *const being) const
void setShareAutoItems(const PartyShareT share) const
void invite(const std::string &name) const
void setShareItems(const PartyShareT share) const
#define A_UNUSED
Definition: localconsts.h:160
LocalPlayer * localPlayer
#define createOutPacket(name)
Definition: messageout.h:37
PartyShareT mShareExp
Definition: partyrecv.cpp:52
PartyShareT mShareItems
Definition: partyrecv.cpp:53
Party * taParty
Definition: partyrecv.cpp:48
void notify(const unsigned int message)
@ PARTY_USER_NOT_IN_PARTY
Definition: notifytypes.h:83
@ NOT_POSSIBLE
Definition: partyshare.h:34
TcpNet::Socket accept(const TcpNet::Socket sock)
Definition: sdltcpnet.cpp:198
Net::PartyHandler * partyHandler
Definition: net.cpp:94
PartyShare ::T PartyShareT
Definition: partyshare.h:36