Planeshift

chatmanager.h

Go to the documentation of this file.
00001 /*
00002  * chatmanager.h - Author: Matthias Braun <[email protected]>
00003  *
00004  * Copyright (C) 2001 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  * This implements a simple chatmanager which resend every chat packet to each
00019  * client...
00020  *
00021  */
00022 
00023 #ifndef __CHATMANAGER_H__
00024 #define __CHATMANAGER_H__
00025 
00026 //=============================================================================
00027 // Crystal Space Includes
00028 //=============================================================================
00029 #include <csutil/ref.h>
00030 #include <csutil/hashr.h>
00031 
00032 //=============================================================================
00033 // Project Space Includes
00034 //=============================================================================
00035 #include "util/gameevent.h"
00036 
00037 //=============================================================================
00038 // Local Space Includes
00039 //=============================================================================
00040 #include "msgmanager.h"             // parent class
00041 
00042 class Client;
00043 class ClientConnectionSet;
00044 class psServer;
00045 class psEndChatLoggingEvent;
00046 class NpcResponse;
00047 class psGuildInfo;
00048 class psGuildAlliance;
00049 class gemNPC;
00050 class gemActor;
00051 class psChatMessage;
00052 
00053 
00054 #define CHAT_SAY_RANGE 15
00055 
00056 struct CachedData
00057 {
00058     csString key;
00059     csString alternate;
00060     csRef<iDataBuffer> data;
00061 
00062     CachedData(iDataBuffer* buffer, const char* n, const char* alt)
00063     {
00064         data = buffer;
00065         key = n;
00066         alternate = alt;
00067     }
00068 };
00069 
00070 class ChatManager : public MessageManager<ChatManager>
00071 {
00072 public:
00073 
00074     ChatManager();
00075     virtual ~ChatManager();
00076 
00077     void HandleChatMessage(MsgEntry* me, Client* client);
00078     void HandleCacheMessage(MsgEntry* me, Client* client);
00079     void HandleChannelJoinMessage(MsgEntry* me, Client* client);
00080     void HandleChannelLeaveMessage(MsgEntry* me, Client* client);
00081 
00082     void SendNotice(psChatMessage &msg);
00083     void SendServerChannelMessage(psChatMessage &msg, uint32_t channelID);
00084 
00085     NpcResponse* CheckNPCEvent(Client* client,csString &trigger,gemNPC* &target);
00086 
00087     void RemoveAllChannels(Client* client);
00088 
00089     void SendGuild(const csString &sender, EID senderEID, psGuildInfo* guild, psChatMessage &msg);
00091     void SendAlliance(const csString &sender, EID senderEID, psGuildAlliance* alliance, psChatMessage &msg);
00092 
00094     void SendMultipleAudioFileHashes(Client* client, const char* voiceFile);
00095 
00096     csString channelsToString();
00097 
00098 protected:
00099     csPDelArray<CachedData> audioFileCache;
00100 
00101     void SendTell(psChatMessage &msg, const char* who, Client* client, Client* target);
00102     void SendSay(uint32_t clientNum, gemActor* actor, psChatMessage &msg, const char* who);
00103     void SendGuild(Client* client, psChatMessage &msg);
00105     void SendAlliance(Client* client, psChatMessage &msg);
00106     void SendGroup(Client* client, psChatMessage &msg);
00107     void SendShout(Client* client, psChatMessage &msg);
00108 
00110     void SendAudioFileHash(Client* client, const char* voiceFile, csTicks delay);
00112     void SendAudioFile(Client* client, const char* voiceFile);
00113 
00115     bool FloodControl(csString &newMessage, Client* client);
00116 
00117     // Chat channel state
00118     // uint32_t here to allow hashing
00119     // csHashReversible is not used because it does not allow a many to many mapping
00120     csHash<uint32_t, uint32_t> channelSubscriptions;
00121     csHash<uint32_t, uint32_t> channelSubscribers;
00122 
00123     // case-insensitive
00124     csHash<uint32_t, csString> channelIDs;
00125     // case-sensitive
00126     csHash<csString, uint32_t> channelNames;
00127 
00128     uint32_t nextChannelID;
00129 };
00130 
00131 
00132 class psEndChatLoggingEvent : public psGameEvent
00133 {
00134 public:
00135     uint32_t clientnum;
00136 
00137     psEndChatLoggingEvent(uint32_t clientNum, const int delayTicks);
00138 
00139     virtual void Trigger();
00140 
00141 };
00142 
00143 #endif
00144