[3275] Divide AllowTwoSide.Interaction option in mangos.conf to more specialized...
[mangos-git.git] / src / game / Channel.cpp
blob8c0d1f7ac1c48efd0fd22c8f9cfb8acd13b5f007
1 /*
2 * Copyright (C) 2005,2006,2007 MaNGOS <http://www.mangosproject.org/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Channel.h"
20 #include "ObjectMgr.h"
22 void Channel::Join(Player *p, const char *pass)
24 WorldPacket data;
25 if(IsOn(p))
27 MakeAlreadyOn(&data,p);
28 SendToOne(&data,p);
30 else if(IsBanned(p->GetGUID()))
32 MakeYouAreBanned(&data);
33 SendToOne(&data,p);
35 else if(password.length() > 0 && strcmp(pass,password.c_str()))
37 MakeWrongPass(&data);
38 SendToOne(&data,p);
40 else
42 PlayerInfo pinfo;
43 pinfo.player = p;
44 pinfo.muted = false;
45 pinfo.owner = false;
46 pinfo.moderator = false;
48 //MakeJoined(&data,p);
49 p->JoinedChannel(this);
50 /*if(announce)
51 SendToAll(&data);*/
53 data.clear();
54 players[p] = pinfo;
56 MakeYouJoined(&data,p);
57 SendToOne(&data,p);
59 // if no owner first logged will become
60 // if(!constant && owner == NULL)
61 // {
62 // SetOwner(p);
63 // players[p].moderator = true;
64 // }
69 void Channel::Leave(Player *p, bool send)
71 WorldPacket data;
72 if(!IsOn(p))
74 MakeNotOn(&data);
75 if(send) SendToOne(&data,p);
77 else
79 MakeYouLeft(&data);
80 if(send)
82 SendToOne(&data,p);
83 p->LeftChannel(this);
85 data.clear();
87 players.erase(p);
88 /*MakeLeft(&data,p);
89 if(announce)
90 SendToAll(&data);
92 if(changeowner)
94 Player *newowner = players.size() > 0 ? players.begin()->second.player : NULL;
95 SetOwner(newowner);
96 }*/
100 void Channel::KickOrBan(Player *good, const char *badname, bool ban)
102 WorldPacket data;
103 if(!IsOn(good))
105 MakeNotOn(&data);
106 SendToOne(&data,good);
108 else if(!players[good].moderator && good->GetSession()->GetSecurity() < 2)
110 MakeNotModerator(&data);
111 SendToOne(&data,good);
113 else
115 Player *bad = objmgr.GetPlayer(badname);
116 if(bad == NULL || !IsOn(bad))
118 MakeNotOn(&data,badname);
119 SendToOne(&data,good);
121 else if(good->GetSession()->GetSecurity() < 2 && bad == owner && good != owner)
123 MakeNotOwner(&data);
124 SendToOne(&data,good);
126 else
128 bool changeowner = (owner == bad);
130 if(ban && !IsBanned(bad->GetGUID()))
132 banned.push_back(bad->GetGUID());
133 MakeBanned(&data,good,bad);
135 else
136 MakeKicked(&data,good,bad);
138 SendToAll(&data);
139 players.erase(bad);
141 if(changeowner)
143 Player *newowner = players.size() > 0 ? good : NULL;
144 SetOwner(newowner);
150 void Channel::UnBan(Player *good, const char *badname)
152 WorldPacket data;
153 if(!IsOn(good))
155 MakeNotOn(&data);
156 SendToOne(&data,good);
158 else if(!players[good].moderator && good->GetSession()->GetSecurity() < 2)
160 MakeNotModerator(&data);
161 SendToOne(&data,good);
163 else
165 Player *bad = objmgr.GetPlayer(badname);
166 if(bad == NULL || !IsBanned(bad->GetGUID()))
168 MakeNotOn(&data,badname);
169 SendToOne(&data,good);
171 else
173 banned.remove(bad->GetGUID());
174 MakeUnbanned(&data,good,bad);
175 SendToAll(&data);
180 void Channel::Password(Player *p, const char *pass)
182 WorldPacket data;
183 if(!IsOn(p))
185 MakeNotOn(&data);
186 SendToOne(&data,p);
188 else if(!players[p].moderator && p->GetSession()->GetSecurity() < 2)
190 MakeNotModerator(&data);
191 SendToOne(&data,p);
193 else
195 password = pass;
196 MakeSetPassword(&data,p);
197 SendToAll(&data);
201 void Channel::SetMode(Player *p, const char *p2n, bool mod, bool set)
203 WorldPacket data;
204 if(!IsOn(p))
206 MakeNotOn(&data);
207 SendToOne(&data,p);
209 else if(!players[p].moderator && p->GetSession()->GetSecurity() < 2)
211 MakeNotModerator(&data);
212 SendToOne(&data,p);
214 else
216 Player *newp = objmgr.GetPlayer(p2n);
217 PlayerInfo inf = players[newp];
218 if(p == owner && newp == owner && mod)
219 return;
220 if(newp == NULL || !IsOn(newp))
222 MakeNotOn(&data,p2n);
223 SendToOne(&data,p);
225 else if(owner == newp && owner != p)
227 MakeNotOwner(&data);
228 SendToOne(&data,p);
230 else
232 if(mod)
233 SetModerator(newp,set);
234 else
235 SetMute(newp,set);
240 void Channel::SetOwner(Player *p, const char *newname)
242 WorldPacket data;
243 if(!IsOn(p))
245 MakeNotOn(&data);
246 SendToOne(&data,p);
248 else if(p->GetSession()->GetSecurity() < 2 && p != owner)
250 MakeNotOwner(&data);
251 SendToOne(&data,p);
253 else
255 Player *newp = objmgr.GetPlayer(newname);
256 if(newp == NULL || !IsOn(newp))
258 MakeNotOn(&data,newname);
259 SendToOne(&data,p);
261 else
263 MakeChangeOwner(&data,newp);
264 SendToAll(&data);
266 SetModerator(newp,true);
267 owner = newp;
272 void Channel::GetOwner(Player *p)
274 WorldPacket data;
275 if(!IsOn(p))
277 MakeNotOn(&data);
278 SendToOne(&data,p);
280 else
282 MakeWhoOwner(&data);
283 SendToOne(&data,p);
287 void Channel::List(Player *p)
289 WorldPacket data;
290 if(!IsOn(p))
292 MakeNotOn(&data);
293 SendToOne(&data,p);
295 else
297 data.Initialize(SMSG_CHANNEL_LIST);
298 data << (uint8)3 << (uint32)players.size();
300 PlayerList::iterator i;
301 uint8 mode;
302 for(i = players.begin(); i!=players.end(); i++)
304 data << i->first->GetGUID();
305 mode = 0x00;
306 if(i->second.muted)
307 mode |= 0x04;
308 if(i->second.moderator)
309 mode |= 0x02;
310 data << mode;
312 SendToOne(&data,p);
316 void Channel::Announce(Player *p)
318 WorldPacket data;
319 if(!IsOn(p))
321 MakeNotOn(&data);
322 SendToOne(&data,p);
324 else if(!players[p].moderator && p->GetSession()->GetSecurity() < 2)
326 MakeNotModerator(&data);
327 SendToOne(&data,p);
329 else
331 announce = !announce;
332 MakeAnnounce(&data,p,announce);
333 SendToAll(&data);
337 void Channel::Moderate(Player *p)
339 WorldPacket data;
340 if(!IsOn(p))
342 MakeNotOn(&data);
343 SendToOne(&data,p);
345 else if(!players[p].moderator && p->GetSession()->GetSecurity() < 2)
347 MakeNotModerator(&data);
348 SendToOne(&data,p);
350 else
352 moderate = !moderate;
353 MakeModerate(&data,p,moderate);
354 SendToAll(&data);
358 void Channel::Say(Player *p, const char *what, uint32 lang)
360 if(!what)
361 return;
362 if (sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL))
363 lang = LANG_UNIVERSAL;
365 WorldPacket data;
366 if(!IsOn(p))
368 MakeNotOn(&data);
369 SendToOne(&data,p);
371 else if(players[p].muted)
373 MakeYouCantSpeak(&data);
374 SendToOne(&data,p);
376 else if(moderate && !players[p].moderator && p->GetSession()->GetSecurity() < 2)
378 MakeNotModerator(&data);
379 SendToOne(&data,p);
381 else
383 uint32 messageLength = strlen(what) + 1;
385 data.Initialize(SMSG_MESSAGECHAT);
386 data << (uint8)14;
387 data << (uint32)lang; //language
388 data << name.c_str();
389 data << (uint32)0;
390 data << p->GetGUID();
391 data << messageLength;
392 data << what;
393 data << p->chatTag();
395 SendToAll(&data,!players[p].moderator ? p : NULL);
399 void Channel::Invite(Player *p, const char *newname)
401 WorldPacket data;
402 if(!IsOn(p))
404 MakeNotOn(&data);
405 SendToOne(&data,p);
407 else
409 Player *newp = objmgr.GetPlayer(newname);
410 if(newp == NULL)
412 MakeNotOn(&data,newname);
413 SendToOne(&data,p);
415 else if(IsOn(newp))
417 MakeAlreadyOn(&data,newp);
418 SendToOne(&data,p);
420 else
422 if(!newp->HasInIgnoreList(p->GetGUID()))
424 MakeInvited(&data,p);
425 SendToOne(&data,newp);
426 data.clear();
428 MakeYouInvited(&data,newp);
429 SendToOne(&data,p);