2 * Copyright (C) 2005,2006 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 "WorldPacket.h"
21 #include "WorldSession.h"
32 bool owner
, moderator
, muted
;
34 typedef map
<Player
*,PlayerInfo
> PlayerList
;
38 bool announce
, constant
, moderate
;
43 WorldPacket
*MakeNotifyPacket(WorldPacket
*data
, uint8 code
)
45 data
->Initialize(SMSG_CHANNEL_NOTIFY
);
46 *data
<< code
<< name
.c_str();
49 void MakeJoined(WorldPacket
*data
, Player
*joined
) { *MakeNotifyPacket(data
,0x00) << joined
->GetGUID(); }
50 void MakeLeft(WorldPacket
*data
, Player
*left
) { *MakeNotifyPacket(data
,0x01) << left
->GetGUID(); }
51 void MakeYouJoined(WorldPacket
*data
, Player
*p
) { *MakeNotifyPacket(data
,0x02) << p
->GetGUID(); }
52 void MakeYouLeft(WorldPacket
*data
) { MakeNotifyPacket(data
,0x03); }
53 void MakeWrongPass(WorldPacket
*data
) { MakeNotifyPacket(data
,0x04); }
54 void MakeNotOn(WorldPacket
*data
) { MakeNotifyPacket(data
,0x05); }
55 void MakeNotModerator(WorldPacket
*data
) { MakeNotifyPacket(data
,0x06); }
56 void MakeSetPassword(WorldPacket
*data
, Player
*who
) { *MakeNotifyPacket(data
,0x07) << who
->GetGUID(); }
57 void MakeChangeOwner(WorldPacket
*data
, Player
*who
) { *MakeNotifyPacket(data
,0x08) << who
->GetGUID(); }
58 void MakeNotOn(WorldPacket
*data
, const char *who
) { *MakeNotifyPacket(data
,0x09) << who
; }
59 void MakeNotOwner(WorldPacket
*data
) { MakeNotifyPacket(data
,0x0A); }
60 void MakeWhoOwner(WorldPacket
*data
) { *MakeNotifyPacket(data
,0x0B) << ((constant
|| owner
== NULL
) ? "Nobody" : owner
->GetName()); }
62 void MakeModeChange(WorldPacket
*data
, Player
*who
, char moderator
, char voice
)
64 MakeNotifyPacket(data
,0x0C);
65 *data
<< who
->GetGUID();
66 uint8 byte1
= 0x00, byte2
= 0x00;
67 if(moderator
== 1) byte1
|= 0x02;
68 if(voice
== 1) byte1
|= 0x04;
70 if(moderator
== 2) byte2
|= 0x02;
71 if(voice
== 2) byte2
|= 0x04;
72 *data
<< byte1
<< byte2
;
74 void MakeEnabledAnnounce(WorldPacket
*data
, Player
*who
) { *MakeNotifyPacket(data
,0x0D) << who
->GetGUID(); }
75 void MakeDisabledAnnounce(WorldPacket
*data
, Player
*who
) { *MakeNotifyPacket(data
,0x0E) << who
->GetGUID(); }
76 void MakeAnnounce(WorldPacket
*data
, Player
*who
, bool set
) { set
? MakeEnabledAnnounce(data
,who
) : MakeDisabledAnnounce(data
,who
); }
77 void MakeModerated(WorldPacket
*data
, Player
*who
) { *MakeNotifyPacket(data
,0x0F) << who
->GetGUID(); }
78 void MakeUnmoderated(WorldPacket
*data
, Player
*who
) { *MakeNotifyPacket(data
,0x10) << who
->GetGUID(); }
79 void MakeModerate(WorldPacket
*data
, Player
*who
, bool set
) { set
? MakeModerated(data
,who
) : MakeUnmoderated(data
,who
); }
80 void MakeYouCantSpeak(WorldPacket
*data
) { MakeNotifyPacket(data
,0x11); }
81 void MakeKicked(WorldPacket
*data
, Player
*good
, Player
*bad
) { *MakeNotifyPacket(data
,0x12) << bad
->GetGUID() << good
->GetGUID(); }
82 void MakeYouAreBanned(WorldPacket
*data
) { MakeNotifyPacket(data
,0x13); }
83 void MakeBanned(WorldPacket
*data
, Player
*good
, Player
*bad
) { *MakeNotifyPacket(data
,0x14) << bad
->GetGUID() << good
->GetGUID(); }
84 void MakeUnbanned(WorldPacket
*data
, Player
*good
, Player
*bad
) { *MakeNotifyPacket(data
,0x15) << bad
->GetGUID() << good
->GetGUID(); }
86 void MakeAlreadyOn(WorldPacket
*data
, Player
*who
) { *MakeNotifyPacket(data
,0x17) << who
->GetGUID(); }
87 void MakeInvited(WorldPacket
*data
, Player
*who
) { *MakeNotifyPacket(data
,0x18) << who
->GetGUID(); }
88 void MakeWrongAlliance(WorldPacket
*data
, Player
*who
) { *MakeNotifyPacket(data
,0x19) << who
->GetGUID(); }
90 void MakeYouInvited(WorldPacket
*data
, Player
*who
) { *MakeNotifyPacket(data
,0x1D) << who
->GetName(); }
92 void SendToAll(WorldPacket
*data
, Player
*p
= NULL
)
94 PlayerList::iterator i
;
95 for(i
= players
.begin(); i
!=players
.end(); i
++)
96 if(!p
|| !i
->first
->HasInIgnoreList(p
->GetGUID()))
97 i
->first
->GetSession()->SendPacket(data
);
100 void SendToAllButOne(WorldPacket
*data
, Player
*who
)
102 PlayerList::iterator i
;
103 for(i
= players
.begin(); i
!=players
.end(); i
++)
105 i
->first
->GetSession()->SendPacket(data
);
108 void SendToOne(WorldPacket
*data
, Player
*who
)
110 who
->GetSession()->SendPacket(data
);
113 bool IsOn(Player
*who
)
115 return players
.count(who
) > 0;
118 bool IsBanned(const uint64 guid
)
120 list
<uint64
>::iterator i
;
121 for(i
= banned
.begin(); i
!=banned
.end(); i
++)
129 return !(players
.size() > 1);
132 void SetOwner(Player
*p
)
138 MakeChangeOwner(&data
,p
);
143 void SetModerator(Player
*p
, bool set
)
145 if(players
[p
].moderator
!= set
)
147 players
[p
].moderator
= set
;
149 MakeModeChange(&data
,p
,set
? 2 : 1,0);
154 void SetMute(Player
*p
, bool set
)
156 if(players
[p
].muted
!= set
)
158 players
[p
].muted
= set
;
161 MakeModeChange(&data
,p
,0,set
? 2 : 1);
167 Channel() : name(""), announce(true), constant(false), moderate(false), owner(NULL
), password("")
170 void SetName(string newname
) { name
= newname
; }
171 string
GetName() { return name
; }
172 bool IsConstant() { return constant
; }
173 bool IsAnnounce() { return announce
; }
174 string
GetPassword() { return password
; }
175 void SetConstant(bool nconstant
) { constant
= nconstant
; }
176 void SetPassword(string npassword
) { password
= npassword
; }
177 void SetAnnounce(bool nannounce
) { announce
= nannounce
; }
178 uint32
GetNumPlayers() { return players
.size(); }
180 void Join(Player
*p
, const char *pass
);
181 void Leave(Player
*p
, bool send
= true);
182 void KickOrBan(Player
*good
, const char *badname
, bool ban
);
183 void Kick(Player
*good
, const char *badname
) { KickOrBan(good
,badname
,false); }
184 void Ban(Player
*good
, const char *badname
) { KickOrBan(good
,badname
,true); }
185 void UnBan(Player
*good
, const char *badname
);
186 void Password(Player
*p
, const char *pass
);
187 void SetMode(Player
*p
, const char *p2n
, bool mod
, bool set
);
188 void SetOwner(Player
*p
, const char *newname
);
189 void GetOwner(Player
*p
);
190 void SetModerator(Player
*p
, const char *newname
) { SetMode(p
,newname
,true,true); }
191 void UnsetModerator(Player
*p
, const char *newname
) { SetMode(p
,newname
,true,false); }
192 void SetMute(Player
*p
, const char *newname
) { SetMode(p
,newname
,false,true); }
193 void UnsetMute(Player
*p
, const char *newname
) { SetMode(p
,newname
,false,false); }
194 void List(Player
*p
);
195 void Announce(Player
*p
);
196 void Moderate(Player
*p
);
197 void Say(Player
*p
, const char *what
, uint32 lang
);
198 void Invite(Player
*p
, const char *newp
);