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
20 #include "ObjectMgr.h"
22 void Channel::Join(Player
*p
, const char *pass
)
27 MakeAlreadyOn(&data
,p
);
30 else if(IsBanned(p
->GetGUID()))
32 MakeYouAreBanned(&data
);
35 else if(password
.length() > 0 && strcmp(pass
,password
.c_str()))
46 pinfo
.moderator
= false;
48 //MakeJoined(&data,p);
49 p
->JoinedChannel(this);
56 MakeYouJoined(&data
,p
);
59 // if no owner first logged will become
60 // if(!constant && owner == NULL)
63 // players[p].moderator = true;
69 void Channel::Leave(Player
*p
, bool send
)
75 if(send
) SendToOne(&data
,p
);
94 Player *newowner = players.size() > 0 ? players.begin()->second.player : NULL;
100 void Channel::KickOrBan(Player
*good
, const char *badname
, bool ban
)
106 SendToOne(&data
,good
);
108 else if(!players
[good
].moderator
&& good
->GetSession()->GetSecurity() < 2)
110 MakeNotModerator(&data
);
111 SendToOne(&data
,good
);
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
)
124 SendToOne(&data
,good
);
128 bool changeowner
= (owner
== bad
);
130 if(ban
&& !IsBanned(bad
->GetGUID()))
132 banned
.push_back(bad
->GetGUID());
133 MakeBanned(&data
,good
,bad
);
136 MakeKicked(&data
,good
,bad
);
143 Player
*newowner
= players
.size() > 0 ? good
: NULL
;
150 void Channel::UnBan(Player
*good
, const char *badname
)
156 SendToOne(&data
,good
);
158 else if(!players
[good
].moderator
&& good
->GetSession()->GetSecurity() < 2)
160 MakeNotModerator(&data
);
161 SendToOne(&data
,good
);
165 Player
*bad
= objmgr
.GetPlayer(badname
);
166 if(bad
== NULL
|| !IsBanned(bad
->GetGUID()))
168 MakeNotOn(&data
,badname
);
169 SendToOne(&data
,good
);
173 banned
.remove(bad
->GetGUID());
174 MakeUnbanned(&data
,good
,bad
);
180 void Channel::Password(Player
*p
, const char *pass
)
188 else if(!players
[p
].moderator
&& p
->GetSession()->GetSecurity() < 2)
190 MakeNotModerator(&data
);
196 MakeSetPassword(&data
,p
);
201 void Channel::SetMode(Player
*p
, const char *p2n
, bool mod
, bool set
)
209 else if(!players
[p
].moderator
&& p
->GetSession()->GetSecurity() < 2)
211 MakeNotModerator(&data
);
216 Player
*newp
= objmgr
.GetPlayer(p2n
);
217 PlayerInfo inf
= players
[newp
];
218 if(p
== owner
&& newp
== owner
&& mod
)
220 if(newp
== NULL
|| !IsOn(newp
))
222 MakeNotOn(&data
,p2n
);
225 else if(owner
== newp
&& owner
!= p
)
233 SetModerator(newp
,set
);
240 void Channel::SetOwner(Player
*p
, const char *newname
)
248 else if(p
->GetSession()->GetSecurity() < 2 && p
!= owner
)
255 Player
*newp
= objmgr
.GetPlayer(newname
);
256 if(newp
== NULL
|| !IsOn(newp
))
258 MakeNotOn(&data
,newname
);
263 MakeChangeOwner(&data
,newp
);
266 SetModerator(newp
,true);
272 void Channel::GetOwner(Player
*p
)
287 void Channel::List(Player
*p
)
297 data
.Initialize(SMSG_CHANNEL_LIST
);
298 data
<< (uint8
)3 << (uint32
)players
.size();
300 PlayerList::iterator i
;
302 for(i
= players
.begin(); i
!=players
.end(); i
++)
304 data
<< i
->first
->GetGUID();
308 if(i
->second
.moderator
)
316 void Channel::Announce(Player
*p
)
324 else if(!players
[p
].moderator
&& p
->GetSession()->GetSecurity() < 2)
326 MakeNotModerator(&data
);
331 announce
= !announce
;
332 MakeAnnounce(&data
,p
,announce
);
337 void Channel::Moderate(Player
*p
)
345 else if(!players
[p
].moderator
&& p
->GetSession()->GetSecurity() < 2)
347 MakeNotModerator(&data
);
352 moderate
= !moderate
;
353 MakeModerate(&data
,p
,moderate
);
358 void Channel::Say(Player
*p
, const char *what
, uint32 lang
)
362 if (sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL
))
363 lang
= LANG_UNIVERSAL
;
371 else if(players
[p
].muted
)
373 MakeYouCantSpeak(&data
);
376 else if(moderate
&& !players
[p
].moderator
&& p
->GetSession()->GetSecurity() < 2)
378 MakeNotModerator(&data
);
383 uint32 messageLength
= strlen(what
) + 1;
385 data
.Initialize(SMSG_MESSAGECHAT
);
387 data
<< (uint32
)lang
; //language
388 data
<< name
.c_str();
390 data
<< p
->GetGUID();
391 data
<< messageLength
;
393 data
<< p
->chatTag();
395 SendToAll(&data
,!players
[p
].moderator
? p
: NULL
);
399 void Channel::Invite(Player
*p
, const char *newname
)
409 Player
*newp
= objmgr
.GetPlayer(newname
);
412 MakeNotOn(&data
,newname
);
417 MakeAlreadyOn(&data
,newp
);
422 if(!newp
->HasInIgnoreList(p
->GetGUID()))
424 MakeInvited(&data
,p
);
425 SendToOne(&data
,newp
);
428 MakeYouInvited(&data
,newp
);