TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ItemChatLink Class Reference

#include <ChatLink.h>

Public Member Functions

 ItemChatLink ()
 
virtual bool Initialize (std::istringstream &iss) override
 
virtual bool ValidateName (char *buffer, const char *context) override
 

Protected Member Functions

std::string FormatName (uint8 index, LocalizedString *suffixStrings) const
 

Protected Attributes

ItemTemplate const_item
 
int32 _data [11]
 
std::vector< int32_bonusListIDs
 
ItemRandomSuffixEntry const_suffix
 
ItemRandomPropertiesEntry const_property
 

Constructor & Destructor Documentation

ItemChatLink::ItemChatLink ( )
inline
62  {
63  memset(_data, 0, sizeof(_data));
64  }
arena_t NULL
Definition: jemalloc_internal.h:624

Member Function Documentation

std::string ItemChatLink::FormatName ( uint8  index,
LocalizedString suffixStrings 
) const
protected
213 {
214  std::stringstream ss;
215  ss << _item->GetName(LocaleConstant(index));
216 
217  if (suffixStrings)
218  ss << ' ' << suffixStrings->Str[index];
219  return ss.str();
220 }
char const * Str[TOTAL_LOCALES]
Definition: Common.h:148
LocaleConstant
Definition: Common.h:115
char const * GetName(LocaleConstant locale) const
Definition: ItemTemplate.cpp:25

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ItemChatLink::Initialize ( std::istringstream &  iss)
overridevirtual

Implements ChatLink.

108 {
109  // Read item entry
110  uint32 itemEntry = 0;
111  if (!ReadUInt32(iss, itemEntry))
112  {
113  TC_LOG_TRACE("chat.system", "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading item entry", iss.str().c_str());
114  return false;
115  }
116 
117  // Validate item
118  _item = sObjectMgr->GetItemTemplate(itemEntry);
119  if (!_item)
120  {
121  TC_LOG_TRACE("chat.system", "ChatHandler::isValidChatMessage('%s'): got invalid itemEntry %u in |item command", iss.str().c_str(), itemEntry);
122  return false;
123  }
124 
125  // Validate item's color
126  uint32 colorQuality = _item->GetQuality();
128  colorQuality = ITEM_QUALITY_HEIRLOOM;
129 
130  if (_color != ItemQualityColors[colorQuality])
131  {
132  TC_LOG_TRACE("chat.system", "ChatHandler::isValidChatMessage('%s'): linked item has color %u, but user claims %u", iss.str().c_str(), ItemQualityColors[colorQuality], _color);
133  return false;
134  }
135 
136  // Number of various item properties after item entry
137  uint8 const propsCount = 11;
138  uint8 const randomPropertyPosition = 5;
139  uint8 const numBonusListIDsPosition = 10;
140  uint8 const maxBonusListIDs = 100;
141  for (uint8 index = 0; index < propsCount; ++index)
142  {
143  if (!CheckDelimiter(iss, DELIMITER, "item"))
144  return false;
145 
146  int32 id = 0;
147  if (!ReadInt32(iss, id))
148  {
149  TC_LOG_TRACE("chat.system", "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading item property (%u)", iss.str().c_str(), index);
150  return false;
151  }
152  if (id && (index == randomPropertyPosition))
153  {
154  // Validate random property
155  if (id > 0)
156  {
157  _property = sItemRandomPropertiesStore.LookupEntry(id);
158  if (!_property)
159  {
160  TC_LOG_TRACE("chat.system", "ChatHandler::isValidChatMessage('%s'): got invalid item property id %u in |item command", iss.str().c_str(), id);
161  return false;
162  }
163  }
164  else if (id < 0)
165  {
166  _suffix = sItemRandomSuffixStore.LookupEntry(-id);
167  if (!_suffix)
168  {
169  TC_LOG_TRACE("chat.system", "ChatHandler::isValidChatMessage('%s'): got invalid item suffix id %u in |item command", iss.str().c_str(), -id);
170  return false;
171  }
172  }
173  }
174  if (index == numBonusListIDsPosition)
175  {
176  if (id > maxBonusListIDs)
177  {
178  TC_LOG_TRACE("chat.system", "ChatHandler::isValidChatMessage('%s'): too many item bonus list IDs %u in |item command", iss.str().c_str(), id);
179  return false;
180  }
181 
182  _bonusListIDs.resize(id);
183  }
184 
185  _data[index] = id;
186  }
187 
188  for (uint32 index = 0; index < _bonusListIDs.size(); ++index)
189  {
190  if (!CheckDelimiter(iss, DELIMITER, "item"))
191  return false;
192 
193  int32 id = 0;
194  if (!ReadInt32(iss, id))
195  {
196  TC_LOG_TRACE("chat.system", "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading item bonus list id (%u)", iss.str().c_str(), index);
197  return false;
198  }
199 
200  if (!sDB2Manager.GetItemBonusList(id))
201  {
202  TC_LOG_TRACE("chat.system", "ChatHandler::isValidChatMessage('%s'): got invalid item bonus list id %d in |item command", iss.str().c_str(), id);
203  return false;
204  }
205 
206  _bonusListIDs[index] = id;
207  }
208 
209  return true;
210 }
#define sDB2Manager
Definition: DB2Stores.h:224
Definition: ItemTemplate.h:254
DB2Storage< ItemRandomSuffixEntry > sItemRandomSuffixStore("ItemRandomSuffix.db2", ItemRandomSuffixFormat, HOTFIX_SEL_ITEM_RANDOM_SUFFIX)
#define sObjectMgr
Definition: ObjectMgr.h:1567
Definition: SharedDefines.h:327
#define TC_LOG_TRACE(filterType__,...)
Definition: Log.h:195
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
uint32 GetFlags3() const
Definition: ItemTemplate.h:658
DB2Storage< ItemRandomPropertiesEntry > sItemRandomPropertiesStore("ItemRandomProperties.db2", ItemRandomPropertiesFormat, HOTFIX_SEL_ITEM_RANDOM_PROPERTIES)
const uint32 ItemQualityColors[MAX_ITEM_QUALITY]
Definition: SharedDefines.h:338
uint8_t uint8
Definition: Define.h:152
uint32 GetQuality() const
Definition: ItemTemplate.h:655

+ Here is the call graph for this function:

bool ItemChatLink::ValidateName ( char *  buffer,
const char *  context 
)
overridevirtual

Implements ChatLink.

223 {
224  ChatLink::ValidateName(buffer, context);
225 
226  LocalizedString* suffixStrings = _suffix ? _suffix->Name : (_property ? _property->Name : NULL);
227 
228  bool res = (FormatName(LOCALE_enUS, suffixStrings) == buffer);
229  if (!res)
230  {
231  for (uint8 index = LOCALE_koKR; index < TOTAL_LOCALES; ++index)
232  {
233  if (index == LOCALE_none)
234  continue;
235 
236  if (FormatName(index, suffixStrings) == buffer)
237  {
238  res = true;
239  break;
240  }
241  }
242  }
243  if (!res)
244  TC_LOG_TRACE("chat.system", "ChatHandler::isValidChatMessage('%s'): linked item (id: %u) name wasn't found in any localization", context, _item->GetId());
245  return res;
246 }
Definition: Common.h:126
Definition: Common.h:146
Definition: Common.h:118
LocalizedString * Name
Definition: DB2Structure.h:776
arena_t NULL
Definition: jemalloc_internal.h:624
LocalizedString * Name
Definition: DB2Structure.h:782
#define TC_LOG_TRACE(filterType__,...)
Definition: Log.h:195
Definition: Common.h:117
uint8_t uint8
Definition: Define.h:152
uint32 GetId() const
Definition: ItemTemplate.h:652
Definition: Common.h:130

+ Here is the call graph for this function:

Member Data Documentation

std::vector<int32> ItemChatLink::_bonusListIDs
protected
int32 ItemChatLink::_data[11]
protected
ItemTemplate const* ItemChatLink::_item
protected
ItemRandomPropertiesEntry const* ItemChatLink::_property
protected
ItemRandomSuffixEntry const* ItemChatLink::_suffix
protected

The documentation for this class was generated from the following files: