Planeshift
chatmanager.h
Go to the documentation of this file.
1 /*
2  * chatmanager.h - Author: Matthias Braun <MatzeBraun@gmx.de>
3  *
4  * Copyright (C) 2001 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * 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.
17  *
18  * This implements a simple chatmanager which resend every chat packet to each
19  * client...
20  *
21  */
22 
23 #ifndef __CHATMANAGER_H__
24 #define __CHATMANAGER_H__
25 
26 //=============================================================================
27 // Crystal Space Includes
28 //=============================================================================
29 #include <csutil/ref.h>
30 #include <csutil/hashr.h>
31 
32 //=============================================================================
33 // Project Space Includes
34 //=============================================================================
35 #include "util/gameevent.h"
36 
37 //=============================================================================
38 // Local Space Includes
39 //=============================================================================
40 #include "msgmanager.h" // parent class
41 
42 class Client;
44 class psServer;
46 class NpcResponse;
47 class psGuildInfo;
48 class psGuildAlliance;
49 class gemNPC;
50 class gemActor;
51 class psChatMessage;
52 
53 
54 #define CHAT_SAY_RANGE 15
55 
56 struct CachedData
57 {
58  csString key;
59  csString alternate;
60  csRef<iDataBuffer> data;
61 
62  CachedData(iDataBuffer* buffer, const char* n, const char* alt)
63  {
64  data = buffer;
65  key = n;
66  alternate = alt;
67  }
68 };
69 
70 class ChatManager : public MessageManager<ChatManager>
71 {
72 public:
73 
74  ChatManager();
75  virtual ~ChatManager();
76 
77  void HandleChatMessage(MsgEntry* me, Client* client);
78  void HandleCacheMessage(MsgEntry* me, Client* client);
79  void HandleChannelJoinMessage(MsgEntry* me, Client* client);
80  void HandleChannelLeaveMessage(MsgEntry* me, Client* client);
81 
82  void SendNotice(psChatMessage &msg);
83 
84  // Used from server console to send messages to all players, example /say Server is getting updated, be patient.
85  void SendServerChannelMessage(psChatMessage &msg, uint32_t channelID);
86 
87  NpcResponse* CheckNPCEvent(Client* client,csString &trigger,gemNPC* &target);
88 
89  void RemoveAllChannels(Client* client);
90 
91  void SendGuild(const csString &sender, EID senderEID, psGuildInfo* guild, psChatMessage &msg);
93  void SendAlliance(const csString &sender, EID senderEID, psGuildAlliance* alliance, psChatMessage &msg);
94 
96  void SendMultipleAudioFileHashes(Client* client, const char* voiceFile);
97 
98  csString channelsToString();
99 
100 protected:
101  csPDelArray<CachedData> audioFileCache;
102 
103  void SendTell(psChatMessage &msg, const char* who, Client* client, Client* target);
104  void SendSay(uint32_t clientNum, gemActor* actor, psChatMessage &msg, const char* who);
105  void SendGuild(Client* client, psChatMessage &msg);
107  void SendAlliance(Client* client, psChatMessage &msg);
108  void SendGroup(Client* client, psChatMessage &msg);
109  void SendShout(Client* client, psChatMessage &msg);
110 
112  void SendAudioFileHash(Client* client, const char* voiceFile, csTicks delay);
114  void SendAudioFile(Client* client, const char* voiceFile);
115 
117  bool FloodControl(csString &newMessage, Client* client);
118 
119  // Chat channel state
120  // uint32_t here to allow hashing
121  // csHashReversible is not used because it does not allow a many to many mapping
122  // values are : clientNumber, channelID
123  csHash<uint32_t, uint32_t> channelSubscriptions;
124 
125  // values are : channelID, clientNumber
126  csHash<uint32_t, uint32_t> channelSubscribers;
127 
128  // case-insensitive
129  csHash<uint32_t, csString> channelIDs;
130  // case-sensitive
131  csHash<csString, uint32_t> channelNames;
132 
133  uint32_t nextChannelID;
134 };
135 
136 
138 {
139 public:
140  uint32_t clientnum;
141 
142  psEndChatLoggingEvent(uint32_t clientNum, const int delayTicks);
143 
144  virtual void Trigger();
145 
146 };
147 
148 #endif
149 
uint32_t nextChannelID
Definition: chatmanager.h:133
Holds data for a guild.
Definition: psguildinfo.h:159
The structure of 1 queue entry (pointer to a message)
Definition: message.h:143
The main server class.
Definition: psserver.h:102
csHash< uint32_t, uint32_t > channelSubscriptions
Definition: chatmanager.h:123
A guild alliance between 2+ guilds.
Definition: psguildinfo.h:731
csPDelArray< CachedData > audioFileCache
Definition: chatmanager.h:101
Any semi-autonomous object, either a player or an NPC.
Definition: gem.h:1170
csString key
Definition: chatmanager.h:58
CachedData(iDataBuffer *buffer, const char *n, const char *alt)
Definition: chatmanager.h:62
This class collects data of a netclient.
Definition: client.h:95
Definition: gem.h:1910
This class holds several possible responses and an action script for the npc to run whenever an appro...
Definition: dictionary.h:394
Message sent with chat info.
Definition: messages.h:808
This class is a list of several CLient objects, it&#39;s designed for finding clients very fast based on ...
Definition: clients.h:58
All scheduled events must inherit from this class.
Definition: gameevent.h:36
csHash< csString, uint32_t > channelNames
Definition: chatmanager.h:131
csHash< uint32_t, uint32_t > channelSubscribers
Definition: chatmanager.h:126
csHash< uint32_t, csString > channelIDs
Definition: chatmanager.h:129
csRef< iDataBuffer > data
Definition: chatmanager.h:60
csString alternate
Definition: chatmanager.h:59
Provides a manager to facilitate subscriptions.
Definition: msgmanager.h:106