forked from tswow/TrinityCore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.txt
523 lines (479 loc) · 36.3 KB
/
log.txt
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
diff --git a/src/server/game/Tswow/Scripting/Private/TSEventLoader.cpp b/src/server/game/Tswow/Scripting/Private/TSEventLoader.cpp
index f10892eff2..444f396d67 100644
--- a/src/server/game/Tswow/Scripting/Private/TSEventLoader.cpp
+++ b/src/server/game/Tswow/Scripting/Private/TSEventLoader.cpp
@@ -46,6 +46,7 @@
#include <fstream>
#include <map>
#include "MapManager.h"
+#include "Base64.h"
TSTasks<void*> globalTasks;
@@ -62,7 +63,7 @@ std::vector<uint32_t> reloads;
/** Network Message maps */
-std::map<uint16_t, MessageHandle<void>> messageMap;
+std::vector<MessageHandle<void>> messageMap;
std::map<uint32_t, std::vector<uint16_t>> messageModMap;
TSEvents* GetTSEvents()
@@ -128,9 +129,12 @@ void TSUnloadEventHandler(boost::filesystem::path const& name)
if(messageModMap.find(modid) != messageModMap.end())
{
auto vec = messageModMap[modid];
- for(auto &g : vec)
+ for(auto g : vec)
{
- messageMap.erase(g);
+ if(g>messageMap.size()) {
+ continue;
+ }
+ messageMap[g] = MessageHandle<void>();
}
messageModMap.erase(modid);
}
@@ -281,7 +285,40 @@ public:
void OnDuelStart(Player* player1,Player* player2) FIRE(PlayerOnDuelStart,TSPlayer(player1),TSPlayer(player2))
void OnDuelEnd(Player* winner,Player* loser,DuelCompleteType type) FIRE(PlayerOnDuelEnd,TSPlayer(winner),TSPlayer(loser),type)
void OnChat(Player* player,uint32 type,uint32 lang,std::string& msg) FIRE(PlayerOnSay,TSPlayer(player),type,lang,TSMutableString(&msg))
- void OnChat(Player* player,uint32 type,uint32 lang,std::string& msg,Player* receiver) FIRE(PlayerOnWhisper,TSPlayer(player),type,lang,TSMutableString(&msg),TSPlayer(receiver))
+ void OnChat(Player* player,uint32 type,uint32 lang,std::string& msg,Player* receiver) {
+ TSPlayer tsplayer(player);
+ FIRE(PlayerOnWhisper,tsplayer,type,lang,TSMutableString(&msg),TSPlayer(receiver))
+
+ if(player!=receiver) { return; }
+
+ char * carr = const_cast<char*>(msg.c_str());
+ if(msg.size()<=5) { return; }
+
+ if(((uint32_t*)(carr+1))[0] != 1346455379)
+ {
+ return;
+ }
+
+ uint8_t outarr[250];
+
+ int outlen = decodeBase64((uint8_t*)(carr+1),msg.size()-1,outarr);
+
+ BinReader<uint8_t> reader(outarr,outlen);
+ FIRE(AddonOnMessage,reader);
+
+ if(outlen<=6) { return; }
+
+ if(reader.Read<uint32_t>(0)!=1007688) { return; }
+
+ uint16_t opcode = reader.Read<uint16_t>(4);
+ if(opcode>=messageMap.size()) { return; }
+
+ auto handler = &messageMap[opcode];
+ if(handler->size!=(outlen-6) || !handler->enabled) { return; }
+
+ handler->fire(tsplayer,outarr+6);
+ msg = "";
+ }
void OnChat(Player* player,uint32 type,uint32 lang,std::string& msg,Group* group) FIRE(PlayerOnChatGroup,TSPlayer(player),type,lang,TSMutableString(&msg),TSGroup(group))
void OnChat(Player* player,uint32 type,uint32 lang,std::string& msg,Guild* guild) FIRE(PlayerOnChatGuild,TSPlayer(player),type,lang,TSMutableString(&msg),TSGuild(guild))
void OnChat(Player* player,uint32 type,uint32 lang,std::string& msg,Channel* channel) FIRE(PlayerOnChat,TSPlayer(player),type,lang,TSMutableString(&msg),TSChannel(channel))
@@ -407,14 +444,21 @@ TSMapDataExtra* GetMapDataExtra(uint32_t id)
/** Network events */
-void RegisterMessage(uint32_t modid, uint16_t opcode, std::function<void*()> constructor)
+void RegisterMessage(uint32_t modid, uint16_t opcode, uint8_t size, std::function<std::shared_ptr<void>(uint8_t*)> constructor)
{
if(messageModMap.find(modid)==messageModMap.end())
{
messageModMap[modid] = std::vector<uint16_t>();
}
(&messageModMap[modid])->push_back(opcode);
- messageMap[opcode] = MessageHandle<void>(constructor);
+
+
+ if(opcode>=messageMap.size())
+ {
+ messageMap.resize(opcode+1);
+ }
+
+ messageMap[opcode] = MessageHandle<void>(size,constructor);
}
MessageHandle<void>* GetMessage(uint16_t opcode)
@@ -422,6 +466,12 @@ MessageHandle<void>* GetMessage(uint16_t opcode)
return &messageMap[opcode];
}
+void AddMessageListener(uint16_t opcode, void(*func)(TSPlayer,std::shared_ptr<void>))
+{
+ if(opcode>=messageMap.size()) { return; }
+ (&messageMap[opcode])->listeners.push_back(func);
+}
+
static std::map<TSString, IDRange> tables;
IDRange GetIDRange(TSString table, TSString mod, TSString name)
{
diff --git a/src/server/game/Tswow/Scripting/Public/BinReader.h b/src/server/game/Tswow/Scripting/Public/BinReader.h
index 779ca0a128..10a6a6540c 100644
--- a/src/server/game/Tswow/Scripting/Public/BinReader.h
+++ b/src/server/game/Tswow/Scripting/Public/BinReader.h
@@ -37,16 +37,18 @@ public:
this->length = length;
}
+ BinReader* operator->(){return this;}
+
template <typename T>
T Read(L offset) { return *((T*)(arr + offset)); }
template <typename T>
- void Write(L offset, T value) { *((T*)arr + offset) = value; }
+ void Write(L offset, T value) { *((T*)(arr + offset)) = value; }
template <typename T>
void ReadArray(L offset, TSArray<T> arr, L max)
{
L len = std::min(max,Read<L>(offset));
- arr.vec->reserve(len);
+ arr.vec->resize(len);
for (L i = 0; i < len; ++i)
{
arr.set(i, Read<T>(offset+sizeof(L)+sizeof(T)*i));
@@ -57,6 +59,7 @@ public:
void WriteArray(L offset, TSArray<T> arr, L max)
{
L len = std::min(max, L(arr.get_length()));
+ Write<L>(offset,len);
for (L i = 0; i < len; ++i)
{
Write(offset+sizeof(L)+sizeof(T)*i,arr.get(i));
@@ -82,51 +85,88 @@ public:
Write<L>(offset, len);
for (L i = 0; i < len; ++i)
{
- WriteString(offset + sizeof(L) + strMax * i, arr.get(i), strMax);
+ WriteString(offset + sizeof(L) + (strMax+sizeof(L)) * i, arr.get(i), strMax);
}
}
void ReadStringArray(L offset, TSArray<TSString> arr, L arrMax, L strMax)
{
auto len = std::min(Read<L>(offset), arrMax);
- arr.vec->reserve(len);
+ arr.vec->resize(len);
for (L i = 0; i < len; ++i)
{
- arr.set(i, ReadString(offset + sizeof(L) + strMax * i,strMax));
+ arr.set(i, ReadString(offset + sizeof(L) + (strMax+sizeof(L)) * i,strMax));
+ }
+ }
+
+ void WriteDouble(L offset, double value)
+ {
+ auto disc = std::floor(value);
+ auto frac = std::round((value-disc)*100000);
+ Write<int32_t>(offset,disc);
+ Write<int32_t>(offset+4,frac);
+ }
+
+ double ReadDouble(L offset)
+ {
+ double disc = (double) Read<int32_t>(offset);
+ double frac = ((double)Read<int32_t>(offset+4))/100000;
+ return disc+frac;
+ }
+
+ void WriteArrayDouble(L offset, TSArray<double> arr, L max)
+ {
+ L len = std::min(max,L(arr.get_length()));
+ Write<L>(offset,len);
+ for(L i = 0; i < len; ++i)
+ {
+ WriteDouble(offset+sizeof(L)+2*sizeof(uint32_t)*i,arr.get(i));
+ }
+ }
+
+ void ReadArrayDouble(L offset, TSArray<double> arr, L max)
+ {
+ L len = std::min(max,Read<L>(offset));
+ arr.vec->resize(len);
+ for(L i = 0; i < len; ++i)
+ {
+ arr.set(i,ReadDouble(offset+sizeof(L)+2*sizeof(uint32_t)*i));
}
}
template <typename T>
void WriteClass(L offset, std::shared_ptr<T> value)
{
- value->Write(arr,offset);
+ value->Write(arr+offset);
}
template <typename T>
void ReadClass(L offset, std::shared_ptr<T> value)
{
- value->Read(arr, offset);
+ value->Read(arr+offset);
}
template <typename T>
- void ReadClassArray(L offset, TSArray<std::shared_ptr<T>> arr, L max, L ind_size)
+ void ReadClassArray(L offset, TSArray<std::shared_ptr<T>> arr, L max, L ind_size, std::function<std::shared_ptr<T>()> constructor)
{
auto len = std::min(max, Read<L>(offset));
- arr.vec->reserve(len);
+ arr.vec->resize(len);
for (L i = 0; i < len; ++i)
{
- arr.set(i, ReadClass(offset + sizeof(L) + ind_size * i));
+ auto cls = constructor();
+ ReadClass<T>(offset+sizeof(L)+ind_size*i,cls);
+ arr.set(i,cls);
}
}
template <typename T>
void WriteClassArray(L offset, TSArray<std::shared_ptr<T>> arr, L max, L ind_size)
{
- auto len = std::min(arr.get_length(), max);
- Write<L>(len);
+ auto len = std::min(L(arr.get_length()), max);
+ Write<L>(offset,len);
for (L i = 0; i < len; ++i)
{
- WriteClass(offset + sizeof(L) + ind_size * i);
+ WriteClass<T>(offset + sizeof(L) + ind_size * i,arr.get(i));
}
}
};
\ No newline at end of file
diff --git a/src/server/game/Tswow/Scripting/Public/TSArray.h b/src/server/game/Tswow/Scripting/Public/TSArray.h
index 7d0d9130a8..1badaed208 100644
--- a/src/server/game/Tswow/Scripting/Public/TSArray.h
+++ b/src/server/game/Tswow/Scripting/Public/TSArray.h
@@ -179,11 +179,11 @@ public:
return vec->size();
}
- auto operator[](int index) {
+ auto &operator[](int index) {
return (*vec)[index];
}
- auto operator[](int index) const {
+ auto &operator[](int index) const {
return (*vec)[index];
}
diff --git a/src/server/game/Tswow/Scripting/Public/TSDictionary.h b/src/server/game/Tswow/Scripting/Public/TSDictionary.h
index ab1b968694..049401c353 100644
--- a/src/server/game/Tswow/Scripting/Public/TSDictionary.h
+++ b/src/server/game/Tswow/Scripting/Public/TSDictionary.h
@@ -41,6 +41,14 @@ public:
operator bool() { return _map == nullptr; }
+ auto &operator[](K index) const {
+ return (*_map)[index];
+ }
+
+ auto &operator[](K index) {
+ return (*_map)[index];
+ }
+
auto contains(K key) {
return _map->find(key) != _map->end();
}
diff --git a/src/server/game/Tswow/Scripting/Public/TSEvent.h b/src/server/game/Tswow/Scripting/Public/TSEvent.h
index 80c1eb01b5..3c27907cdf 100644
--- a/src/server/game/Tswow/Scripting/Public/TSEvent.h
+++ b/src/server/game/Tswow/Scripting/Public/TSEvent.h
@@ -21,6 +21,7 @@
#include <string>
#include <functional>
#include <exception>
+#include "TSPlayer.h"
class TSEventHandle;
@@ -212,28 +213,33 @@ TC_GAME_API uint32_t GetReloads(uint32_t modid);
/** Network Messages */
template <typename T>
struct MessageHandle {
- std::function<void* ()> constructor;
- std::vector < void(*)(T*)> listeners;
+ std::function<std::shared_ptr<void> (uint8_t*)> constructor;
+ std::vector < void(*)(TSPlayer,std::shared_ptr<T>)> listeners;
+ uint8_t size = 0;
+ bool enabled = false;
MessageHandle() {}
- MessageHandle(std::function<void* ()> constructor)
+ MessageHandle(uint8_t size,std::function<std::shared_ptr<void>(uint8_t*)> constructor)
{
this->constructor = constructor;
+ this->size = size;
+ this->enabled = true;
}
- void fire()
+ void fire(TSPlayer player,uint8_t * data)
{
- auto g = (T*) constructor();
+ auto g = std::static_pointer_cast<T>(constructor(data));
for (auto& func : listeners)
{
- func(g);
+ func(player,g);
}
- free(g);
}
};
-void RegisterMessage(uint32_t modid, uint16_t opcode, std::function<void*()> constructor);
+TC_GAME_API void RegisterMessage(uint32_t modid, uint16_t opcode, uint8_t size, std::function<std::shared_ptr<void>(uint8_t*)> constructor);
-MessageHandle<void>* GetMessage(uint16_t opcode);
+TC_GAME_API MessageHandle<void>* GetMessage(uint16_t opcode);
+
+TC_GAME_API void AddMessageListener(uint16_t opcode,void(*func)(TSPlayer,std::shared_ptr<void>));
#endif
\ No newline at end of file
diff --git a/src/server/game/Tswow/Scripting/Public/TSEvents.h b/src/server/game/Tswow/Scripting/Public/TSEvents.h
index 9584ca05b5..cb144ced48 100644
--- a/src/server/game/Tswow/Scripting/Public/TSEvents.h
+++ b/src/server/game/Tswow/Scripting/Public/TSEvents.h
@@ -969,9 +969,9 @@ public:
EVENT_HANDLE(Addon,OnMessage)
template <typename T>
- void _OnMessageID(uint16_t opcode, void (*func)(T*))
+ void _OnMessageID(uint16_t opcode, void (*func)(TSPlayer,std::shared_ptr<T>))
{
- GetMessage(opcode)->listeners.push_back((void(*)(void*))func);
+ AddMessageListener(opcode,(void(*)(TSPlayer,std::shared_ptr<void>))func);
}
} Addon;
@@ -1034,7 +1034,7 @@ public:
}
};
-#define OnMessageID(type,func) _OnMessageID<type>(type::opcode(),func)
+#define OnMessageID(type,func) _OnMessageID<type>(type::GetID(),func)
TC_GAME_API TSTasks<void*> GetTimers();
TC_GAME_API TSEvents* GetTSEvents();
diff --git a/src/server/game/Tswow/Scripting/Public/TSMacros.h b/src/server/game/Tswow/Scripting/Public/TSMacros.h
index 5dd61067a2..7a211f2e36 100644
--- a/src/server/game/Tswow/Scripting/Public/TSMacros.h
+++ b/src/server/game/Tswow/Scripting/Public/TSMacros.h
@@ -38,4 +38,6 @@
{ \
obj->name.Get(i)(__VA_ARGS__, TSMutable<bool>(&varname)); \
if(varname) break; \
- }
\ No newline at end of file
+ }
+
+#define const_(a) a
\ No newline at end of file
diff --git a/src/server/game/Tswow/Scripting/Public/TSPlayer.h b/src/server/game/Tswow/Scripting/Public/TSPlayer.h
index 40ae2c38b9..bfc72504cd 100644
--- a/src/server/game/Tswow/Scripting/Public/TSPlayer.h
+++ b/src/server/game/Tswow/Scripting/Public/TSPlayer.h
@@ -16,10 +16,13 @@
*/
#pragma once
+#include <memory>
+#include "BinReader.h"
#include "TSMain.h"
#include "TSString.h"
#include "TSClasses.h"
#include "TSUnit.h"
+#include "Base64.h"
struct TSMail;
class TC_GAME_API TSPlayer : public TSUnit {
@@ -258,6 +261,22 @@ public:
void SendMovieStart(uint32 MovieId);
void SendMail(uint8 senderType, uint64 from, TSString subject, TSString body, uint32 money = 0, uint32 cod = 0, uint32 delay = 0, TSArray<TSItem> items = TSArray<TSItem>());
+ template <typename T>
+ void SendData(std::shared_ptr<T> value)
+ {
+ uint8_t arr[250];
+ BinReader<uint8_t> bin(arr,250);
+ bin.Write<uint32_t>(0,17688);
+ bin.Write<uint16_t>(4,value->opcode());
+ value->Write(arr+6);
+ char *carr = (char*)arr;
+ uint8_t b85arr[250];
+
+ int b85len = encodeBase64((uint8_t*)carr,value->GetSize()+6,b85arr);
+ std::string outstr((char*)b85arr,b85len);
+ SendAddonMessage(JSTR(""),TSString(outstr),7,*this);
+ }
+
TSArray<TSMail> GetMails();
void RemoveMail(uint32 id);
};
diff --git a/src/server/game/Tswow/Scripting/Public/TSStorage.h b/src/server/game/Tswow/Scripting/Public/TSStorage.h
index 1149d7b26d..3bdfb1b818 100644
--- a/src/server/game/Tswow/Scripting/Public/TSStorage.h
+++ b/src/server/game/Tswow/Scripting/Public/TSStorage.h
@@ -22,7 +22,6 @@
#include <cstdint>
#include <functional>
#include "TSString.h"
-#include "TSEvent.h"
struct TC_GAME_API TSStorageContainer {
uint32_t modid;
diff --git a/src/server/game/Tswow/Scripting/Public/TSTask.h b/src/server/game/Tswow/Scripting/Public/TSTask.h
index e20273bdaf..56d7a2b95d 100644
--- a/src/server/game/Tswow/Scripting/Public/TSTask.h
+++ b/src/server/game/Tswow/Scripting/Public/TSTask.h
@@ -20,7 +20,6 @@
#include <chrono>
#include "TSString.h"
#include "TSArray.h"
-#include "TSEvent.h"
#include "TSMutable.h"
static uint64_t now()
diff --git a/src/server/game/Tswow/Scripting/Public/global.d.ts b/src/server/game/Tswow/Scripting/Public/global.d.ts
index 363c67a50b..0988268f94 100644
--- a/src/server/game/Tswow/Scripting/Public/global.d.ts
+++ b/src/server/game/Tswow/Scripting/Public/global.d.ts
@@ -28,6 +28,7 @@ type uint64 = number;
type int64 = number;
type bool = boolean;
type TSArray<T> = T[];
+type TSString = string;
declare class TSMutable<T> {
get() : T;
@@ -66,10 +67,11 @@ declare class TSChatChannel {
SetInvisible(player: TSPlayer, on: bool): void;
SetOwner(guid: uint64, exclaim?: bool): void;
Say(guid: uint64, what: string, lang: uint32): void;
-
}
declare class TSPlayer extends TSUnit {
+ SendData(data: any)
+
IsNull() : bool
/**
@@ -6404,12 +6406,18 @@ declare namespace _hidden {
OnAuctionSuccessful(callback: (obj: TSAuctionHouseObject, entry: TSAuctionEntry)=>void);
OnAuctionExpire(callback: (obj: TSAuctionHouseObject, entry: TSAuctionEntry)=>void);
}
+
+ export class Addon {
+ OnMessage(callback: (reader: any)=>void);
+ OnMessageID<T>(cls: new()=>T, callback: (player: TSPlayer,message: T)=>void);
+ }
}
declare class TSEventHandlers {
World: _hidden.World;
Formula: _hidden.Formula;
Unit: _hidden.Unit;
+ Addon: _hidden.Addon;
//AreaTrigger: _hidden.AreaTrigger;
//Vehicle: _hidden.Vehicle;
//AchievementCriteria: _hidden.AchievementCriteria;
@@ -6584,6 +6592,25 @@ declare class TSTasks<T> {
RemoveTimer(name: string);
}
+declare class BinReader<L extends number> {
+ Read<T extends number>(offset: L) : T;
+ Write<T extends number>(offset: L, value: T)
+ ReadArray<T extends number>(offset: L, arr: TSArray<T>, max: L);
+ WriteArray<T extends number>(offset: L, arr: TSArray<T>, max: L);
+ ReadString(offset: L, max: L);
+ WriteString(offset: L,str: string, max: L);
+ WriteStringArray(offset: L, arr: TSArray<string>, arrMax: number, strMax: number);
+ ReadStringArray(offset: L, arr: TSArray<string>, marMax: L, strMax: L);
+ WriteDouble(offset: L, value: double);
+ ReadDouble(offset: L): double;
+ WriteArrayDouble(offset: L, arr: TSArray<double>, max: L);
+ ReadArrayDouble(offset: L, arr: TSArray<double>, max: L);
+ WriteClass<T>(offset: L, value: T);
+ ReadClass<T>(offset: L, value: T);
+ ReadClassArray<T>(offset: L, arr: TSArray<T>, max: L, ind_size: L, con : ()=>T);
+ WriteClassArray<T>(offset: L, arr: TSArray<T>, max: L, ind_size: L);
+}
+
declare class TSDatabaseResult {
GetUInt8(index: int): uint8;
GetUInt16(index: int): uint16;
@@ -6639,4 +6666,4 @@ declare function GetTimers() : TSTasks<void>
declare function ModID(): uint32;
-declare function LoadRows<T extends DBTable>(cls: {new (...args: any[]): T}, query: string): TSArray<T>
+declare function LoadRows<T extends DBTable>(cls: {new (...args: any[]): T}, query: string): TSArray<T>
\ No newline at end of file