OregonCore  revision 3611e8a-git
Your Favourite TBC server
AddonHandler.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "zlib.h"
19 #include "AddonHandler.h"
20 #include "Opcodes.h"
21 #include "Log.h"
22 
24 
26 {
27 }
28 
30 {
31 }
32 
34 {
35  ByteBuffer AddOnPacked;
36  uLongf AddonRealSize;
37  uint32 CurrentPosition;
38  uint32 TempValue;
39 
40  unsigned char tdata[256] =
41  {
42  0xC3, 0x5B, 0x50, 0x84, 0xB9, 0x3E, 0x32, 0x42, 0x8C, 0xD0, 0xC7, 0x48, 0xFA, 0x0E, 0x5D, 0x54,
43  0x5A, 0xA3, 0x0E, 0x14, 0xBA, 0x9E, 0x0D, 0xB9, 0x5D, 0x8B, 0xEE, 0xB6, 0x84, 0x93, 0x45, 0x75,
44  0xFF, 0x31, 0xFE, 0x2F, 0x64, 0x3F, 0x3D, 0x6D, 0x07, 0xD9, 0x44, 0x9B, 0x40, 0x85, 0x59, 0x34,
45  0x4E, 0x10, 0xE1, 0xE7, 0x43, 0x69, 0xEF, 0x7C, 0x16, 0xFC, 0xB4, 0xED, 0x1B, 0x95, 0x28, 0xA8,
46  0x23, 0x76, 0x51, 0x31, 0x57, 0x30, 0x2B, 0x79, 0x08, 0x50, 0x10, 0x1C, 0x4A, 0x1A, 0x2C, 0xC8,
47  0x8B, 0x8F, 0x05, 0x2D, 0x22, 0x3D, 0xDB, 0x5A, 0x24, 0x7A, 0x0F, 0x13, 0x50, 0x37, 0x8F, 0x5A,
48  0xCC, 0x9E, 0x04, 0x44, 0x0E, 0x87, 0x01, 0xD4, 0xA3, 0x15, 0x94, 0x16, 0x34, 0xC6, 0xC2, 0xC3,
49  0xFB, 0x49, 0xFE, 0xE1, 0xF9, 0xDA, 0x8C, 0x50, 0x3C, 0xBE, 0x2C, 0xBB, 0x57, 0xED, 0x46, 0xB9,
50  0xAD, 0x8B, 0xC6, 0xDF, 0x0E, 0xD6, 0x0F, 0xBE, 0x80, 0xB3, 0x8B, 0x1E, 0x77, 0xCF, 0xAD, 0x22,
51  0xCF, 0xB7, 0x4B, 0xCF, 0xFB, 0xF0, 0x6B, 0x11, 0x45, 0x2D, 0x7A, 0x81, 0x18, 0xF2, 0x92, 0x7E,
52  0x98, 0x56, 0x5D, 0x5E, 0x69, 0x72, 0x0A, 0x0D, 0x03, 0x0A, 0x85, 0xA2, 0x85, 0x9C, 0xCB, 0xFB,
53  0x56, 0x6E, 0x8F, 0x44, 0xBB, 0x8F, 0x02, 0x22, 0x68, 0x63, 0x97, 0xBC, 0x85, 0xBA, 0xA8, 0xF7,
54  0xB5, 0x40, 0x68, 0x3C, 0x77, 0x86, 0x6F, 0x4B, 0xD7, 0x88, 0xCA, 0x8A, 0xD7, 0xCE, 0x36, 0xF0,
55  0x45, 0x6E, 0xD5, 0x64, 0x79, 0x0F, 0x17, 0xFC, 0x64, 0xDD, 0x10, 0x6F, 0xF3, 0xF5, 0xE0, 0xA6,
56  0xC3, 0xFB, 0x1B, 0x8C, 0x29, 0xEF, 0x8E, 0xE5, 0x34, 0xCB, 0xD1, 0x2A, 0xCE, 0x79, 0xC3, 0x9A,
57  0x0D, 0x36, 0xEA, 0x01, 0xE0, 0xAA, 0x91, 0x20, 0x54, 0xF0, 0x72, 0xD8, 0x1E, 0xC7, 0x89, 0xD2
58  };
59 
60  // broken addon packet, can't be received from real client
61  if (Source->rpos() + 4 > Source->size())
62  return false;
63 
64  *Source >> TempValue; // get real size of the packed structure
65 
66  // empty addon packet, nothing process, can't be received from real client
67  if (!TempValue)
68  return false;
69 
70  AddonRealSize = TempValue; // temp value because ZLIB only excepts uLongf
71 
72  CurrentPosition = Source->rpos(); // get the position of the pointer in the structure
73 
74  AddOnPacked.resize(AddonRealSize); // resize target for zlib action
75 
76  if (!uncompress(const_cast<uint8*>(AddOnPacked.contents()), &AddonRealSize, const_cast<uint8*>((*Source).contents() + CurrentPosition), (*Source).size() - CurrentPosition) != Z_OK)
77  {
78  Target->Initialize(SMSG_ADDON_INFO);
79 
80  while (AddOnPacked.rpos() < AddOnPacked.size())
81  {
82  std::string AddonNames;
83  uint8 unk6;
84  uint32 crc, unk7;
85 
86  // check next addon data format correctness
87  if (AddOnPacked.rpos() + 1 + 4 + 4 + 1 > AddOnPacked.size())
88  return false;
89 
90  AddOnPacked >> AddonNames;
91 
92  // recheck next addon data format correctness
93  if (AddOnPacked.rpos() + 4 + 4 + 1 > AddOnPacked.size())
94  return false;
95 
96  AddOnPacked >> crc >> unk7 >> unk6;
97 
98  //sLog.outDebug("ADDON: Name:%s CRC:%x Unknown1 :%x Unknown2 :%x", AddonNames.c_str(), crc, unk7, unk6);
99 
100  *Target << (uint8)2;
101 
102  uint8 unk1 = 1;
103  *Target << uint8(unk1);
104  if (unk1)
105  {
106  uint8 unk2 = (crc != 0x1c776d01LL); // If addon is Standard addon CRC
107  *Target << uint8(unk2);
108  if (unk2)
109  Target->append(tdata, sizeof(tdata));
110 
111  *Target << uint32(0);
112  }
113 
114  uint8 unk3 = 0;
115  *Target << uint8(unk3);
116  if (unk3)
117  {
118  // String, 256 (null terminated?)
119  }
120  }
121  }
122  else
123  {
124  sLog.outError("Addon packet uncompress error :(");
125  return false;
126  }
127  return true;
128 }
129 
130 /* Code use in 1.10.2 when client not ignore ban state sended for addons. Saved for reference if client switch to use server ban state information
131 void AddonHandler::BuildAddonPacket(WorldPacket* Source, WorldPacket* Target, uint32 Packetoffset)
132 {
133  ByteBuffer AddOnPacked;
134  uLongf AddonRealSize;
135  uint32 CurrentPosition;
136  uint32 TempValue;
137 
138  *Source >> TempValue; // get real size of the packed structure
139 
140  AddonRealSize = TempValue; // temp value becouse ZLIB only excepts uLongf
141 
142  CurrentPosition = Source->rpos(); // get the position of the pointer in the structure
143 
144  AddOnPacked.resize(AddonRealSize); // resize target for zlib action
145 
146  if (!uncompress((uint8*)AddOnPacked.contents(), &AddonRealSize, (uint8*)(*Source).contents() + CurrentPosition, (*Source).size() - CurrentPosition) != Z_OK)
147  {
148  bool* AddonAllowed = new bool; // handle addon check and enable-ing
149 
150  uint32 Unknown1;
151  uint8 Unknown0;
152 
153  AddOnPacked >> Unknown0;
154  AddOnPacked >> Unknown1;
155 
156  Target->Initialize(SMSG_ADDON_INFO);
157 
158  uint32 i = 5; // offset for addon extraction
159  while(i != AddOnPacked.size())
160  {
161  std::string AddonNames;
162  AddOns* Addonstr = new AddOns;
163  uint8 unk6;
164  uint64 CRCCHECK;
165  AddOnPacked >> AddonNames >> CRCCHECK >> unk6;
166 
167  //sLog.outDebug("ADDON: Name:%s CRC:%x Unknown:%x",AddonNames.c_str(), CRCCHECK,unk6);
168 
169  Addonstr->Name = AddonNames;
170  Addonstr->CRC = CRCCHECK;
171 
172  // if not allowed but unknown added to list
173  if (GetAddonStatus(Addonstr, AddonAllowed)) // If addon is new
174  {
175  Addonstr->Enabled = m_Addon_Default; // by default new addons are set from Config file
176  *AddonAllowed = m_Addon_Default; // Set addon allowed on default value
177  _AddAddon(Addonstr);
178  sLog.outDetail("Found new Addon, Name:%s CRC:%x Unknown:%x",AddonNames.c_str(), CRCCHECK, unk6);
179  }
180 
181  if (CRCCHECK == 0x4C1C776D01LL) // If addon is Standard addon CRC
182  {
183  // value's standard Addons
184  *Target << uint8(0) << uint8(2) << uint8(1) << uint8(0) << uint32(0);
185  }
186  else if (*AddonAllowed) // if addon is Custom addons
187  // value's enable addon
188  *Target << uint8(0x00) << uint8(0x01) << uint8(0x00) << uint8(0x01);
189  else
190  // value's disable addom
191  *Target << uint8(0x00) << uint8(0x0) << uint8(0x00) << uint8(0x0);
192 
193  i += AddonNames.size() + 10;
194  }
195  *Target << uint8(0x0);
196 
197  // delete mem allocation
198  delete AddonAllowed;
199  }
200  else
201  {
202  // handle uncompress error
203  }
204 }
205 */
206 
const uint8 * contents() const
Definition: ByteBuffer.h:331
void resize(size_t newsize)
Definition: ByteBuffer.h:345
#define sLog
Log class singleton.
Definition: Log.h:187
void Initialize(uint16 opcode, size_t newres=200)
Definition: WorldPacket.h:37
ACE_UINT8 uint8
Definition: Define.h:73
size_t size() const
Definition: ByteBuffer.h:336
INSTANTIATE_SINGLETON_1(AddonHandler)
Target
void append(const std::string &str)
Definition: ByteBuffer.h:358
size_t rpos() const
Definition: ByteBuffer.h:253
ACE_UINT32 uint32
Definition: Define.h:71
bool BuildAddonPacket(WorldPacket *Source, WorldPacket *Target)