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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
/*
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRINITYCORE_CHATLINK_H
#define TRINITYCORE_CHATLINK_H
#include "SharedDefines.h"
#include <sstream>
#include <list>
struct ItemLocale;
struct ItemTemplate;
struct ItemRandomSuffixEntry;
struct ItemRandomPropertiesEntry;
class SpellInfo;
struct AchievementEntry;
struct GlyphPropertiesEntry;
class Quest;
///////////////////////////////////////////////////////////////////////////////////////////////////
// ChatLink - abstract base class for various links
class ChatLink
{
public:
ChatLink() : _color(0), _startPos(0), _endPos(0) { }
virtual ~ChatLink() { }
void SetColor(uint32 color) { _color = color; }
// This will allow to extract the whole link string from the message, if necessary.
void SetBounds(std::istringstream::pos_type startPos, std::istringstream::pos_type endPos) { _startPos = startPos; _endPos = endPos; }
virtual bool Initialize(std::istringstream& iss) = 0;
virtual bool ValidateName(char* buffer, const char* context) = 0;
protected:
uint32 _color;
std::string _name;
std::istringstream::pos_type _startPos;
std::istringstream::pos_type _endPos;
};
// ItemChatLink - link to item
class ItemChatLink : public ChatLink
{
public:
ItemChatLink() : ChatLink(), _item(NULL), _suffix(NULL), _property(NULL) { }
virtual bool Initialize(std::istringstream& iss);
virtual bool ValidateName(char* buffer, const char* context);
protected:
std::string FormatName(uint8 index, ItemLocale const* locale, char* const* suffixStrings) const;
ItemTemplate const* _item;
int32 _data[8];
ItemRandomSuffixEntry const* _suffix;
ItemRandomPropertiesEntry const* _property;
};
// QuestChatLink - link to quest
class QuestChatLink : public ChatLink
{
public:
QuestChatLink() : ChatLink(), _quest(NULL), _questLevel(0) { }
virtual bool Initialize(std::istringstream& iss);
virtual bool ValidateName(char* buffer, const char* context);
protected:
Quest const* _quest;
int32 _questLevel;
};
// SpellChatLink - link to quest
class SpellChatLink : public ChatLink
{
public:
SpellChatLink() : ChatLink(), _spell(NULL) { }
virtual bool Initialize(std::istringstream& iss);
virtual bool ValidateName(char* buffer, const char* context);
protected:
SpellInfo const* _spell;
};
// AchievementChatLink - link to quest
class AchievementChatLink : public ChatLink
{
public:
AchievementChatLink() : ChatLink(), _guid(0), _achievement(NULL) { }
virtual bool Initialize(std::istringstream& iss);
virtual bool ValidateName(char* buffer, const char* context);
protected:
uint32 _guid;
AchievementEntry const* _achievement;
uint32 _data[8];
};
// TradeChatLink - link to trade info
class TradeChatLink : public SpellChatLink
{
public:
TradeChatLink() : SpellChatLink(), _minSkillLevel(0), _maxSkillLevel(0), _guid(0) { }
virtual bool Initialize(std::istringstream& iss);
private:
int32 _minSkillLevel;
int32 _maxSkillLevel;
uint32 _guid;
std::string _base64;
};
// TalentChatLink - link to talent
class TalentChatLink : public SpellChatLink
{
public:
TalentChatLink() : SpellChatLink(), _talentId(0), _rankId(0) { }
virtual bool Initialize(std::istringstream& iss);
private:
uint32 _talentId;
int32 _rankId;
};
// EnchantmentChatLink - link to enchantment
class EnchantmentChatLink : public SpellChatLink
{
public:
EnchantmentChatLink() : SpellChatLink() { }
virtual bool Initialize(std::istringstream& iss);
};
// GlyphChatLink - link to glyph
class GlyphChatLink : public SpellChatLink
{
public:
GlyphChatLink() : SpellChatLink(), _slotId(0), _glyph(NULL) { }
virtual bool Initialize(std::istringstream& iss);
private:
uint32 _slotId;
GlyphPropertiesEntry const* _glyph;
};
class LinkExtractor
{
public:
explicit LinkExtractor(const char* msg);
~LinkExtractor();
bool IsValidMessage();
private:
typedef std::list<ChatLink*> Links;
Links _links;
std::istringstream _iss;
};
#endif // TRINITYCORE_CHATLINK_H
|