Mana
Loading...
Searching...
No Matches
partyhandler.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2008-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana 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 "event.h"
25#include "log.h"
26#include "localplayer.h"
27
28#include "gui/socialwindow.h"
29
34
35#include "utils/gettext.h"
36#include "utils/stringutils.h"
37
38#include <iostream>
39
40#define PARTY_ID 1
41
43
44namespace ManaServ {
45
46extern Connection *chatServerConnection;
47extern Connection *gameServerConnection;
48
50 mParty(Party::getParty(PARTY_ID))
51{
52 static const Uint16 _messages[] = {
60 0
61 };
62 handledMessages = _messages;
63 partyHandler = this;
64
65 mParty->setName("Party");
66}
67
69{
70 switch (msg.getId())
71 {
73 {
74 std::string name = msg.readString();
75 serverNotice(strprintf(_("Party invite failed, because no player "
76 "called %s is within the visual range."),
77 name.c_str()));
78 } break;
79
81 {
83 } break;
84
86 {
87 switch (msg.readInt8())
88 {
89 case ERRMSG_OK:
91 while (msg.getUnreadLength())
92 {
93 std::string name = msg.readString();
94 mParty->addMember(0, name);
95 }
96 break;
97 case ERRMSG_TIME_OUT:
98 serverNotice(_("Joining party failed, because the "
99 "invitation has timed out on the server."));
100 break;
101 case ERRMSG_FAILURE:
102 serverNotice(_("Joining party failed, because the "
103 "inviter has left the game."));
104 break;
105 default:
106 Log::info("Unknown CPMSG_PARTY_INVITE_ANSWER_RESPONSE.");
107 break;
108 }
109 } break;
110
112 {
113 if (msg.readInt8() == ERRMSG_OK)
114 {
116 local_player->setParty(nullptr);
117 }
118 } break;
119
121 {
122 std::string name = msg.readString();
123 std::string inviter = msg.readString();
124 std::string notice;
125
126 if (inviter.empty())
127 notice = strprintf(_("%s joined the party."), name.c_str());
128 else
129 notice = strprintf(_("%s joined the party on invitation from %s."),
130 name.c_str(), inviter.c_str());
131
132 serverNotice(notice);
133
134 if (name == local_player->getName())
136
137 mParty->addMember(0, name);
138 } break;
139
141 {
142 // mParty->removeMember(msg.readString());
143 } break;
144
146 {
147 std::string name = msg.readString();
148 switch (msg.readInt8())
149 {
150 case ERRMSG_OK:
151 serverNotice(strprintf(_("%s rejected your invite."),
152 name.c_str()));
153 break;
155 serverNotice(_("Party invitation rejected by server, "
156 "because of too many invitations in a "
157 "short time."));
158 break;
159 case ERRMSG_FAILURE:
160 serverNotice(strprintf(_("%s is already in a party."),
161 name.c_str()));
162 break;
163 default:
164 Log::info("Unknown CPMSG_PARTY_REJECTED.");
165 break;
166 }
167 } break;
168 }
169}
170
171void PartyHandler::create(const std::string &name)
172{
173 // TODO
174}
175
176void PartyHandler::join(int partyId)
177{
178 // TODO
179}
180
182{
183 invite(being->getName());
184}
185
186void PartyHandler::invite(const std::string &name)
187{
189
190 msg.writeString(name);
191
193}
194
195void PartyHandler::inviteResponse(const std::string &inviter, bool accept)
196{
198
199 msg.writeString(inviter);
200 msg.writeInt8(accept);
201
203}
204
211
213{
214 // TODO
215}
216
217void PartyHandler::kick(const std::string &name)
218{
219 // TODO
220}
221
222void PartyHandler::chat(const std::string &text)
223{
224 // TODO
225}
226
228{
229 //MessageOut msg(PCMSG_GUILD_GET_MEMBERS);
230
231 //msg.writeInt16(guildId);
232
233 //chatServerConnection->send(msg);
234}
235
236} // namespace ManaServ
Definition being.h:65
const std::string & getName() const
Returns the name of the being.
Definition being.h:190
void setParty(Party *party)
Definition being.cpp:549
void send(const ManaServ::MessageOut &msg)
Sends a message.
Used for parsing an incoming message from manaserv.
Definition messagein.h:37
unsigned int getUnreadLength() const
Returns the length of unread data.
Definition messagein.h:54
std::string readString(int length=-1)
Reads a string.
Definition messagein.cpp:92
uint16_t getId() const
Returns the message ID.
Definition messagein.h:44
uint8_t readInt8()
Reads an unsigned 8-bit integer from the message.
Definition messagein.cpp:43
Used for building an outgoing message to manaserv.
Definition messageout.h:37
void writeInt8(uint8_t value)
Writes an unsigned 8-bit integer to the message.
void writeString(const std::string &string, int length=-1)
Writes a string.
void join(int partyId) override
void requestPartyMembers() override
void invite(Being *being) override
void create(const std::string &name=std::string()) override
void inviteResponse(const std::string &inviter, bool accept) override
void handleMessage(MessageIn &msg) override
void kick(Being *being) override
void chat(const std::string &text) override
const uint16_t * handledMessages
Definition party.h:59
PartyMember * addMember(int id, const std::string &name)
Adds member to the list.
Definition party.cpp:45
void setName(const std::string &name)
Set the party's name.
Definition party.h:65
void clearMembers()
Definition party.h:122
void showPartyInvite(const std::string &inviter, const std::string &partyName=std::string())
void serverNotice(const std::string &message)
Definition event.h:319
SocialWindow * socialWindow
Definition game.cpp:108
#define _(s)
Definition gettext.h:38
LocalPlayer * local_player
Net::PartyHandler * partyHandler
Definition net.cpp:55
#define PARTY_ID
void info(const char *log_text,...) LOG_PRINTF_ATTR
Connection * gameServerConnection
Connection * chatServerConnection
@ CPMSG_PARTY_INVITE_ANSWER_RESPONSE
std::string strprintf(char const *format,...)
A safe version of sprintf that returns a std::string of the result.