Add infos into target window
[ryzomcore.git] / ryzom / server / src / general_utilities_service / ec_channel.h
blobd8c2136a19e8ffc000938722f3f0299f5ad1829f
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
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 Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef EC_CHANNEL_H
18 #define EC_CHANNEL_H
20 //-----------------------------------------------------------------------------
21 // includes
22 //-----------------------------------------------------------------------------
24 #include "gus_chat.h"
25 #include "ec_types.h"
28 //-----------------------------------------------------------------------------
29 // EC namespace
30 //-----------------------------------------------------------------------------
32 namespace EC
34 //-----------------------------------------------------------------------------
35 // Public typedefs
36 //-----------------------------------------------------------------------------
38 // a user id - this is a character name or account number stored as a string
39 typedef NLMISC::CSString TCharacterId;
41 // standard ranks for users in a chat channel
42 // - NO_RANK is used when a user is not present in any of the chat channel user groups
43 enum TChannelRank { NO_RANK, MEMBER, OFFICER, ARCH };
46 //-----------------------------------------------------------------------------
47 // class CUserGroup
48 //-----------------------------------------------------------------------------
50 class CUserGroup
52 public:
53 //-----------------------------------------------------------------------------
54 // public interface
56 // constructor requires a channel ptr as an argument as group belongs to a channel
57 CUserGroup(IChannel* parent);
59 // process a command to add, remove or display users
60 NLMISC::CSString processCommand(const NLMISC::CSString& command);
62 // test whether a given client id is listed in this user group
63 bool contains(const TCharacterId& id) const;
65 private:
66 //-----------------------------------------------------------------------------
67 // private data
69 IChannel* _Parent;
70 typedef std::vector<TCharacterId> TCharacterIds;
71 TCharacterIds _CharacterIds;
75 //-----------------------------------------------------------------------------
76 // class IChannel
77 //-----------------------------------------------------------------------------
79 class IChannel: private GUS::IChatCallback, public NLMISC::CRefCount
81 public:
82 //-----------------------------------------------------------------------------
83 // virtual interface exposed to derived classes
85 // virtual dtor
86 virtual ~IChannel();
88 // Callback called whenever a user who belongs to one of the channel's user groups logs in
89 // - also called if the user is already online when they are added to the user group
90 // - this callback is NOT called if the user rank is NO_RANK
91 virtual void cbAddUser(TChannelRank rank,const TCharacterId& id,GUS::TClientId clientId) =0;
93 // Callback called whenever a user is removed from the channel's user groups
94 virtual void cbRemoveUser(TChannelRank rank,const TCharacterId& idclientId,GUS::TClientId clientId) =0;
96 // Callback called whenever a text is received from a user
97 virtual void cbChatText(TChannelRank rank,const TCharacterId& id,GUS::TClientId clientId,const NLMISC::CSString& txt) =0;
100 public:
101 //-----------------------------------------------------------------------------
102 // Accessors for channel basics
104 const NLMISC::CSString& getChannelName() const;
105 const NLMISC::CSString& getChannelTitle() const;
106 void setChannelTitle(const NLMISC::CSString& title);
109 //-----------------------------------------------------------------------------
110 // Accessors for user lists
112 // add a user to a selected user group
113 // - removes the user from any other group that they may be in
114 void addMember(const TCharacterId& id);
115 void addOfficer(const TCharacterId& id);
116 void addArch(const TCharacterId& id);
118 // get the sets of members, officers or arch users
119 CUserGroup& getMembers();
120 CUserGroup& getOfficers();
121 CUserGroup& getArchs();
123 // remove a user from all groups
124 void removeUser(const TCharacterId& id);
126 // lookup a user in each of the user groups and determine their rank
127 // - returns NO_RANK if user not found
128 const TChannelRank getRank(const TCharacterId& id);
130 // set a user rank by adding them to one of the user groups
131 // - if the user is already in a user group they are removed before the operation begins
132 // - if the rank is 'NO-RANK' then this operation is equivalent to 'removeUser()'
133 void setRank(const TCharacterId& id,const TChannelRank& rank);
135 // display the lists of members & officers
136 void displayMembers();
137 void displayOfficers();
138 void displayArchs();
139 void displayAllUsers();
142 //-----------------------------------------------------------------------------
143 // Methods for message sending / broadcasting
145 void sendMessage(GUS::TClientId clientId,const NLMISC::CSString& speaker,const NLMISC::CSString& txt);
146 void broadcastMessage(const NLMISC::CSString& speaker,const NLMISC::CSString& txt);
149 protected:
150 //-----------------------------------------------------------------------------
151 // protected methods
153 // ctor
154 IChannel(const NLMISC::CSString& name);
156 // accessor for the chat channel
157 GUS::CChatChannel& getChannel();
160 private:
161 //-----------------------------------------------------------------------------
162 // IChatCallback Specialisation
164 virtual void receiveMessage(GUS::TClientId clientId,const ucstring& txt);
165 virtual void clientReadyInChannel(GUS::CChatChannel* chatChannel, GUS::TClientId clientId);
166 virtual bool isClientAllowedInChatChannel(GUS::TClientId clientId, GUS::CChatChannel *chatChannel);
169 private:
170 //-----------------------------------------------------------------------------
171 // private data
173 // smart pointer to the CChatChannel object
174 GUS::TChatChannelPtr _Chat;
176 // the vectors of users
177 CUserGroup _Members;
178 CUserGroup _Officers;
179 CUserGroup _Archs;
181 // the sets of names that have been added to or removes from _Members, _Officers or _Archs but
182 // have not yet been added to / removed from the _Chat
183 typedef std::set<TCharacterId> TUntreatedUserSet;
184 TUntreatedUserSet _ChatAdds;
185 TUntreatedUserSet _ChatRemoves;
188 //-----------------------------------------------------------------------------
189 // private methods used by CUserGroup objects
191 friend class CUserGroup;
192 // either add to the container's adds list or remove from its removes list
193 void _chatAdd(const TCharacterId& name);
194 // either add to the container's removes list or remove from its adds list
195 void _chatRemove(const TCharacterId& name);
196 // Update the chat channel, removing players in the _ChatRemoves set and adding players in the _ChatAdds set
197 void _chatUpdate();
202 //-----------------------------------------------------------------------------
203 #endif