forked from opentibia-xx/otserv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat.h
142 lines (111 loc) · 4.21 KB
/
chat.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//////////////////////////////////////////////////////////////////////
#ifndef __OTSERV_CHAT_H__
#define __OTSERV_CHAT_H__
#include "definitions.h"
#include <map>
#include <list>
#include <string>
#include "const.h"
class Player;
class Party;
typedef std::map<uint32_t, Player*> UsersMap;
enum ChannelID {
CHANNEL_GUILD = 0x00,
CHANNEL_RULE_REP = 0x03,
CHANNEL_GAME_CHAT = 0x04,
CHANNEL_TRADE = 0x05,
CHANNEL_TRADE_ROOK = 0x06,
CHANNEL_RL_CHAT = 0x07,
CHANNEL_PARTY = 0x08,
CHANNEL_HELP = 0x09,
CHANNEL_PRIVATE = 0xFFFF
};
class ChatChannel
{
public:
ChatChannel(uint16_t channelId, std::string channelName);
virtual ~ChatChannel(){}
bool addUser(Player* player);
bool removeUser(Player* player, bool sendCloseChannel = false);
bool talk(Player* fromPlayer, SpeakClasses type, const std::string& text, uint32_t time = 0);
bool sendInfo(SpeakClasses type, const std::string& text, uint32_t time = 0);
const std::string& getName() const { return m_name; }
const uint16_t getId() const { return m_id; }
const UsersMap& getUsers() const { return m_users; }
virtual const uint32_t getOwner(){ return 0; }
protected:
UsersMap m_users;
std::string m_name;
uint16_t m_id;
};
class PrivateChatChannel : public ChatChannel
{
public:
PrivateChatChannel(uint16_t channelId, std::string channelName);
virtual ~PrivateChatChannel(){};
virtual const uint32_t getOwner(){return m_owner;}
void setOwner(uint32_t id){m_owner = id;}
bool isInvited(const Player* player);
void invitePlayer(Player* player, Player* invitePlayer);
void excludePlayer(Player* player, Player* excludePlayer);
bool addInvited(Player* player);
bool removeInvited(Player* player);
void closeChannel();
protected:
typedef std::map<uint32_t, Player*> InvitedMap;
InvitedMap m_invites;
uint32_t m_owner;
};
typedef std::list<ChatChannel*> ChannelList;
class Chat
{
public:
Chat();
~Chat();
ChatChannel* createChannel(Player* player, uint16_t channelId);
bool deleteChannel(Player* player, uint16_t channelId);
bool deleteChannel(Party* party);
bool addUserToChannel(Player* player, uint16_t channelId);
bool removeUserFromChannel(Player* player, uint16_t channelId);
void removeUserFromAllChannels(Player* player);
uint16_t getFreePrivateChannelId();
bool isPrivateChannel(uint16_t channelId);
bool isMuteableChannel(uint16_t channelId, SpeakClasses type);
bool talkToChannel(Player* player, SpeakClasses type, const std::string& text, unsigned short channelId);
std::string getChannelName(Player* player, uint16_t channelId);
ChannelList getChannelList(Player* player);
ChatChannel* getChannel(Party* party);
ChatChannel* getChannel(Player* player, uint16_t channelId);
ChatChannel* getChannelById(uint16_t channelId);
ChatChannel* getGuildChannel(uint32_t guildId);
PrivateChatChannel* getPrivateChannel(Player* player);
private:
typedef std::map<uint16_t, ChatChannel*> NormalChannelMap;
typedef std::map<uint32_t, ChatChannel*> GuildChannelMap;
typedef std::map<Party*, PrivateChatChannel*> PartyChannelMap;
NormalChannelMap m_normalChannels;
GuildChannelMap m_guildChannels;
PartyChannelMap m_partyChannels;
typedef std::map<uint16_t, PrivateChatChannel*> PrivateChannelMap;
PrivateChannelMap m_privateChannels;
ChatChannel* dummyPrivate;
};
#endif