1 ////////////////////////////////////////////////////////////////////////////////
2 //    Scorched3D (c) 2000-2011
3 //
4 //    This file is part of Scorched3D.
5 //
6 //    Scorched3D is free software; you can redistribute it and/or modify
7 //    it under the terms of the GNU General Public License as published by
8 //    the Free Software Foundation; either version 2 of the License, or
9 //    (at your option) any later version.
10 //
11 //    Scorched3D is distributed in the hope that it will be useful,
12 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //    GNU General Public License for more details.
15 //
16 //    You should have received a copy of the GNU General Public License along
17 //    with this program; if not, write to the Free Software Foundation, Inc.,
18 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ////////////////////////////////////////////////////////////////////////////////
20 
21 #if !defined(__INCLUDE_ClientChannelManagerh_INCLUDE__)
22 #define __INCLUDE_ClientChannelManagerh_INCLUDE__
23 
24 #include <coms/ComsMessageHandler.h>
25 #include <client/ClientChannelManagerI.h>
26 #include <console/ConsoleRule.h>
27 #include <set>
28 
29 class ClientChannelManager
30 {
31 public:
32 	static ClientChannelManager *instance();
33 
34 	void showText(const ChannelText &text);
35 	void sendText(const ChannelText &text);
36 
37 	bool channelActive(const std::string &channelName);
38 
getMutedPlayers()39 	std::set<unsigned int> &getMutedPlayers() { return mutedPlayers_; }
40 
41 	bool registerClient(ClientChannelManagerI *reciever,
42 		std::list<std::string> &channels);
43 	bool deregisterClient(ClientChannelManagerI *reciever);
44 	bool changeRegistration(ClientChannelManagerI *reciever,
45 		std::list<std::string> &channels);
46 
47 	void addChannel(const char *lookfor, const char *channel);
48 	void removeChannel(const char *channel);
49 
50 protected:
51 	static ClientChannelManager *instance_;
52 	static unsigned int nextRecieverId_;
53 
54 	class ChannelEntry
55 	{
56 	public:
57 		ChannelEntry(ClientChannelManagerI *user);
58 
getUser()59 		ClientChannelManagerI *getUser() { return user_; }
60 		void setChannels(std::list<ChannelDefinition> &channels);
getChannels()61 		std::set<std::string> &getChannels() { return channels_; }
62 
63 		bool hasChannel(const std::string &channel);
64 
65 	protected:
66 		ClientChannelManagerI *user_;
67 		std::set<std::string> channels_;
68 	};
69 
70 	std::set<unsigned int> mutedPlayers_;
71 	std::map<unsigned int, ChannelEntry *> recievers_;
72 	unsigned int getChannelEntry(ClientChannelManagerI *reciever);
73 	void say(std::vector<ConsoleRuleValue> &values);
74 	bool processChannelMessage(NetMessage &message, NetBufferReader &reader);
75 	bool processChannelTextMessage(NetMessage &message, NetBufferReader &reader);
76 
77 private:
78 	ClientChannelManager();
79 	virtual ~ClientChannelManager();
80 
81 };
82 
83 #endif
84