ServerChannelManager.h

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #if !defined(__INCLUDE_ServerChannelManagerh_INCLUDE__)
00022 #define __INCLUDE_ServerChannelManagerh_INCLUDE__
00023 
00024 #include <coms/ComsMessageHandler.h>
00025 #include <server/ServerChannelFilter.h>
00026 #include <server/ServerChannelAuth.h>
00027 #include <time.h>
00028 #include <set>
00029 #include <map>
00030 
00031 class ServerChannelManager : 
00032         public ComsMessageHandlerI
00033 {
00034 public:
00035         static ServerChannelManager *instance();
00036 
00037         struct MessageEntry
00038         {
00039                 std::string message;
00040                 unsigned int messageid;
00041         };
00042 
00043         void sendText(const ChannelText &text, bool serverLog, bool filter = true);
00044         void sendText(const ChannelText &text, unsigned int destination, bool serverLog, bool filter = true);
00045         std::list<MessageEntry> &getLastMessages() { return lastMessages_; }
00046         std::list<std::string> getAllChannels();
00047 
00048         void simulate(float frameTime);
00049 
00050         // Notification of when players disconnect
00051         void destinationDisconnected(unsigned int destinationId);
00052         void refreshDestination(unsigned int destinationId);
00053 
00054         // Inherited from ComsMessageHandlerI
00055         virtual bool processMessage(
00056                 NetMessage &message,
00057                 const char *messageType,
00058                 NetBufferReader &reader);
00059 
00060 protected:
00061         static ServerChannelManager *instance_;
00062 
00063         class DestinationLocalEntry
00064         {
00065         public:
00066                 DestinationLocalEntry(unsigned int localId = 0);
00067 
00068                 unsigned int getLocalId() { return localId_; }
00069                 std::set<std::string> &getChannels() { return channels_; }
00070                 std::set<std::string> &getAvailableChannels() { return availableChannels_; }
00071 
00072         protected:
00073                 unsigned int localId_;
00074                 std::set<std::string> channels_; // Subscribed channels
00075                 std::set<std::string> availableChannels_; // Available channeld
00076         };
00077         class DestinationEntry 
00078         {
00079         public:
00080                 DestinationEntry(unsigned int destinationId);
00081 
00082                 unsigned int getDestinationId() { return destinationId_; }
00083 
00084                 bool hasChannel(const std::string &channel);
00085                 void addChannel(const std::string &channel, unsigned int localId, bool current);
00086                 void removeChannel(const std::string &channel, unsigned int localId);
00087 
00088                 bool hasLocalId(unsigned int localId);
00089                 void addLocalId(unsigned int localId);
00090                 void removeLocalId(unsigned int localId);
00091 
00092                 void setMessageCount(unsigned int count) { messageCount_ = count; }
00093                 unsigned int getMessageCount() { return messageCount_; }
00094 
00095                 time_t getMuteTime() { return muteTime_; }
00096                 void setMuteTime(time_t t) { muteTime_ = t; }
00097 
00098                 void getLocalIds(const std::string &channel, std::list<unsigned int> &ids);
00099                 std::map<unsigned int, DestinationLocalEntry> &getLocalEntries() { return localEntries_; }
00100 
00101         protected:
00102                 time_t muteTime_;
00103                 unsigned int messageCount_;
00104                 unsigned int destinationId_;
00105                 std::set<std::string> channels_; // Subscribed channeld for all localids
00106                 std::map<unsigned int, DestinationLocalEntry> localEntries_;
00107 
00108                 void updateChannels();
00109         };
00110         class ChannelEntry
00111         {
00112         public:
00113                 ChannelEntry(ChannelDefinition def,
00114                         ServerChannelFilter *filter = 0,
00115                         ServerChannelAuth *auth = 0);
00116                 virtual ~ChannelEntry();
00117 
00118                 const char *getName() { return channelDef_.getChannel(); }
00119                 ChannelDefinition &getDefinition() { return channelDef_; }
00120                 ServerChannelFilter *getFilter() { return filter_; }
00121                 ServerChannelAuth *getAuth() { return auth_; }
00122 
00123         protected:
00124                 ChannelDefinition channelDef_;
00125                 ServerChannelFilter *filter_;
00126                 ServerChannelAuth *auth_;
00127         };
00128 
00129         unsigned int lastMessageId_;
00130         float totalTime_;
00131         std::map<unsigned int, DestinationEntry *> destinationEntries_;
00132         std::list<ChannelEntry *> channelEntries_;
00133         std::list<MessageEntry> lastMessages_;
00134 
00135         ChannelEntry *getChannelEntryByName(const std::string &name);
00136         DestinationEntry *getDestinationEntryById(unsigned int destinationId);
00137 
00138         void registerClient(unsigned int destinationId, unsigned int localId,
00139                 std::list<ChannelDefinition> &startChannels);
00140         void deregisterClient(unsigned int destinationId, unsigned int localId);
00141         void joinClient(unsigned int destinationId, unsigned int localId,
00142                 std::list<ChannelDefinition> &startChannels);
00143         void actualSend(const ChannelText &constText,
00144                 std::map<unsigned int, DestinationEntry *> &destinations, 
00145                 bool serverLog, bool filter);
00146 
00147 private:
00148         ServerChannelManager();
00149         virtual ~ServerChannelManager();
00150 
00151 };
00152 
00153 #endif

Generated on Mon Feb 16 15:14:53 2009 for Scorched3D by  doxygen 1.5.3