-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpackets.cpp
1411 lines (1396 loc) · 47.1 KB
/
packets.cpp
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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright 2011 by Benjamin J. Land (a.k.a. BenLand100)
*
* This file is part of the CppCraft.
*
* CppCraft 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 3 of the License, or
* (at your option) any later version.
*
* CppCraft 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 CppCraft. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include "packets.h"
#include "client.h"
#include "SDL_endian.h"
inline int ucs2_to_utf8(int ucs2, char *utf8) {
if (ucs2 < 0x80) {
utf8[0] = ucs2;
return 1;
}
if (ucs2 >= 0x80 && ucs2 < 0x800) {
utf8[0] = (ucs2 >> 6) | 0xC0;
utf8[1] = (ucs2 & 0x3F) | 0x80;
return 2;
}
if (ucs2 >= 0x800 && ucs2 < 0xFFFF) {
utf8[0] = ((ucs2 >> 12) ) | 0xE0;
utf8[1] = ((ucs2 >> 6 ) & 0x3F) | 0x80;
utf8[2] = ((ucs2 ) & 0x3F) | 0x80;
return 3;
}
return -1;
}
inline int utf8_to_ucs2(char *input, char **end_ptr) {
*end_ptr = input;
if (input[0] == 0)
return 0;
if (input[0] < 0x80) {
*end_ptr = input + 1;
return input[0];
}
if ((input[0] & 0xE0) == 0xE0) {
if (input[1] == 0 || input[2] == 0)
return -1;
*end_ptr = input + 3;
return (input[0] & 0x0F)<<12 | (input[1] & 0x3F)<<6 | (input[2] & 0x3F);
}
if ((input[0] & 0xC0) == 0xC0) {
if (input[1] == 0)
return -1;
*end_ptr = input + 2;
return (input[0] & 0x1F)<<6 | (input[1] & 0x3F);
}
return -1;
}
class SocketIO {
public:
bool working;
private:
TCPsocket socket;
unsigned char buffer[16];
inline void read(unsigned char *buffer, int len) {
int read = 0, cur;
for (;;) { //Supposedly SDL should wait for the whole length, in practice however...
cur = SDLNet_TCP_Recv(socket, &buffer[read], len);
if (cur == -1 || cur == 0) {
for (int i = 0; i < 16; i++) buffer[i] = 0;
working = false;
return;
}
len -= cur;
if (len == 0) return;
std::cout << std::dec << cur << " bytes read - readunder\n";
read += cur;
}
}
inline void read(int len) {
read(buffer,len);
}
inline void write(int len) {
if (SDLNet_TCP_Send(socket, (void*)buffer, len) != len) {
working = false;
}
}
public:
SocketIO(TCPsocket _socket) : socket(_socket), working(true) { }
inline unsigned char r_ubyte() {
read(1);
return buffer[0];
}
inline void w_ubyte(unsigned char b) {
buffer[0] = b;
write(1);
}
inline char r_byte() {
read(1);
return (char) buffer[0];
}
inline void w_byte(char b) {
buffer[0] = (unsigned char)b;
write(1);
}
inline short r_short() {
read(2);
return SDL_SwapBE16(*(Uint16*)buffer);
}
inline void w_short(short s) {
*(short*)buffer = SDL_SwapBE16(s);
write(2);
}
inline int r_int() {
read(4);
return SDL_SwapBE32(*(Uint32*)buffer);
}
inline void w_int(int i) {
*(int*)buffer = SDL_SwapBE32(i);
write(4);
}
inline long long r_long() {
read(8);
return SDL_SwapBE64(*(Uint64*)buffer);
}
inline void w_long(long long l) {
*(long long*)buffer = SDL_SwapBE64(l);
write(8);
}
inline float r_float() {
read(4);
union { float f; Uint32 i; } swap;
swap.i = SDL_SwapBE32(*(Uint32*)buffer);
return swap.f;
}
inline void w_float(float f) {
union { float f; Uint32 i; } swap;
swap.f = f;
*(int*)buffer = SDL_SwapBE32(swap.i);
write(4);
}
inline double r_double() {
read(8);
union { double d; Uint64 l; } swap;
swap.l = SDL_SwapBE64(*(Uint64*)buffer);
return swap.d;
}
inline void w_double(double d) {
union { double d; Uint64 l; } swap;
swap.d = d;
*(long long*)buffer = SDL_SwapBE64(swap.l);
write(8);
}
inline bool r_bool() {
read(1);
return buffer[0];
}
inline void w_bool(bool flag) {
buffer[0] = flag ? '\1' : '\0';
write(1);
}
inline string8 r_string8() {
int len = r_short();
string8 str = new char[len+1];
if (SDLNet_TCP_Recv(socket, str, len) != len) {
working = false;
}
str[len] = '\0';
return str;
}
inline void w_string8(string8 str) {
int len = strlen(str);
w_short(len);
if (SDLNet_TCP_Send(socket, str, len) != len) {
working = false;
}
}
inline string16 r_string16() {
string16 res;
int len = r_short();
char *ucs2 = new char[len*2];
string16 str = new char[len*4+1]; //never allow an overflow
if (SDLNet_TCP_Recv(socket, ucs2, len*2) != len*2) {
working = false;
return NULL;
}
char *wchars = ucs2;
char *utf8chars = str;
for (int i = 0; i < len; i++, wchars += 2) {
int c = SDL_SwapBE16(*(Uint16*)wchars);
int s = ucs2_to_utf8(c,utf8chars);
if (s == -1) {
std::cout << "UFT-8 conversion error\n";
working = false;
return NULL;
}
utf8chars += s;
}
*utf8chars = '\0';
delete ucs2;
return str;
}
inline void w_string16(string16 str) {
int len = strlen(str);
short *ucs2 = new short[len];
short *chars = ucs2;
while (true) {
int c = utf8_to_ucs2(str,&str);
if (c <= 0) break;
*(chars++) = SDL_SwapBE16(c);
}
int nchars = chars - ucs2;
w_short(nchars);
if (SDLNet_TCP_Send(socket, ucs2, nchars*2) != nchars*2) {
working = false;
}
delete ucs2;
}
//Currently, this returns nothing useful
inline metadata* r_metadata() {
metadata *result = new metadata;
unsigned char id;
while ((id = r_ubyte()) != 0x7F && working) {
switch (id >> 5) {
case 0:
r_byte();
break;
case 1:
r_short();
break;
case 2:
r_int();
break;
case 3:
r_float();
break;
case 4:
r_string16();
break;
case 5:
r_short();
r_byte();
r_short();
break;
case 6:
r_int();
r_int();
r_int();
break;
default:
std::cout << "Unknown metadata id!\n";
working = false;
}
}
return result;
}
//This is even more useless than the reader
inline void w_metadata(metadata *data) {
}
//Currently, this returns nothing useful
inline item* r_itemarray(int len) {
item *result = new item[len];
for (int i = 0; i < len; i++) {
result[i].itemid = r_short();
if (result[i].itemid != -1) {
result[i].count = r_byte();
result[i].uses = r_short();
} else {
result[i].count = 0;
result[i].uses = 0;
}
}
return result;
}
//This is even more useless than the reader
inline void w_itemarray(item *data, int len) {
for (int i = 0; i < len; i++) {
w_short(data[i].itemid);
if (data[i].itemid != -1) {
w_byte(data[i].count);
w_short(data[i].uses);
}
}
}
inline char* r_bytearray(int len) {
char *array = new char[len];
read((unsigned char*)array, len);
return array;
}
inline void w_bytearray(char* array, int len) {
if (SDLNet_TCP_Send(socket, array, len) != len) {
working = false;
}
}
inline short* r_shortarray(int len) {
short *array = new short[len];
for (int i = 0; i < len; i++) {
array[i] = r_short();
}
return array;
}
inline void w_shortarray(short* array, int len) {
if (SDLNet_TCP_Send(socket, array, len) != len) {
working = false;
}
}
};
int packets_thread(Client *client) {
SocketIO io(client->socket);
unsigned char pid;
while (client->doPackets && io.working) {
pid = io.r_ubyte();
//std::cout << "Parsing 0x" << std::hex << (int)pid << '\n';
if (!io.working) break;
switch (pid) {
case 0x00:{
p_keep_alive *p = new p_keep_alive;
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x01:{
p_login_request_stc *p = new p_login_request_stc;
p->EntityID = io.r_int();
p->Unknown = io.r_string16();
p->MapSeed = io.r_long();
p->Dimension = io.r_byte();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p->Unknown;
delete p;
} break;
case 0x02:{
p_handshake_stc *p = new p_handshake_stc;
p->ConnectionHash = io.r_string16();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x03:{
p_chat_message *p = new p_chat_message;
p->Message = io.r_string16();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p->Message;
delete p;
} break;
case 0x04:{
p_time_update *p = new p_time_update;
p->Time = io.r_long();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x05:{
p_entity_equipment *p = new p_entity_equipment;
p->EntityID = io.r_int();
p->Slot = io.r_short();
p->ItemID = io.r_short();
p->Damage = io.r_short();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x06:{
p_spawn_position *p = new p_spawn_position;
p->X = io.r_int();
p->Y = io.r_int();
p->Z = io.r_int();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x07:{
p_use_entity *p = new p_use_entity;
p->UserEID = io.r_int();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x08:{
p_update_health *p = new p_update_health;
p->Health = io.r_short();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x09:{
p_respawn *p = new p_respawn;
p->World = io.r_byte();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x0A:{
p_player *p = new p_player;
p->OnGround = io.r_bool();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x0B:{
p_player_position *p = new p_player_position;
p->X = io.r_double();
p->Y = io.r_double();
p->Stance = io.r_double();
p->Z = io.r_double();
p->OnGround = io.r_bool();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x0C:{
p_player_look *p = new p_player_look;
p->Yaw = io.r_float();
p->Pitch = io.r_float();
p->OnGround = io.r_bool();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x0D:{
p_player_position_and_look_stc *p = new p_player_position_and_look_stc;
p->X = io.r_double();
p->Stance = io.r_double();
p->Y = io.r_double();
p->Z = io.r_double();
p->Yaw = io.r_float();
p->Pitch = io.r_float();
p->OnGround = io.r_bool();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x0E:{
p_player_digging *p = new p_player_digging;
p->Status = io.r_byte();
p->X = io.r_int();
p->Y = io.r_byte();
p->Z = io.r_int();
p->Face = io.r_byte();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x0F:{
p_player_block_placement *p = new p_player_block_placement;
p->X = io.r_int();
p->Y = io.r_byte();
p->Z = io.r_int();
p->Direction = io.r_byte();
p->BlockID = io.r_short();
if (p->BlockID >= 0) {
p->Amount = io.r_byte();
p->Damage = io.r_short();
} else {
p->Amount = -1;
p->Damage = -1;
}
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x10:{
p_holding_change *p = new p_holding_change;
p->SlotID = io.r_short();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x11:{
p_use_bed *p = new p_use_bed;
p->EntityID = io.r_int();
p->InBed = io.r_byte();
p->X = io.r_int();
p->Y = io.r_byte();
p->Z = io.r_int();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x12:{
p_animate *p = new p_animate;
p->EntityID = io.r_int();
p->Animate = io.r_byte();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x13:{
p_act *p = new p_act;
p->EntityID = io.r_int();
p->Action = io.r_byte();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x14:{
p_spawn_player *p = new p_spawn_player;
p->EID = io.r_int();
p->Name = io.r_string16();
p->X = io.r_int();
p->Y = io.r_int();
p->Z = io.r_int();
p->Yaw = io.r_byte();
p->Pitch = io.r_byte();
p->CurrentItem = io.r_short();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p->Name;
delete p;
} break;
case 0x15:{
p_pickup_spawn *p = new p_pickup_spawn;
p->EntityID = io.r_int();
p->Item = io.r_short();
p->Count = io.r_byte();
p->Damage = io.r_short();
p->X = io.r_int();
p->Y = io.r_int();
p->Z = io.r_int();
p->Yaw = io.r_byte();
p->Pitch = io.r_byte();
p->Roll = io.r_byte();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x16:{
p_collect_item *p = new p_collect_item;
p->CollectedEID = io.r_int();
p->CollectorEID = io.r_int();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x17:{
p_addobject *p = new p_addobject;
p->EntityID = io.r_int();
p->Type = io.r_byte();
p->X = io.r_int();
p->Y = io.r_int();
p->Z = io.r_int();
p->Flag = io.r_int();
if (p->Flag > 0) {
p->Xmap = io.r_short();
p->Ymap = io.r_short();
p->Zmap = io.r_short();
} else {
p->Xmap = 0;
p->Ymap = 0;
p->Zmap = 0;
}
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x18:{
p_spawn_mob *p = new p_spawn_mob;
p->EntityID = io.r_int();
p->Type = io.r_byte();
p->X = io.r_int();
p->Y = io.r_int();
p->Z = io.r_int();
p->Yaw = io.r_byte();
p->Pitch = io.r_byte();
p->Metadata = io.r_metadata();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p->Metadata;
delete p;
} break;
case 0x19:{
p_painting *p = new p_painting;
p->EntityID = io.r_int();
p->Title = io.r_string16();
p->X = io.r_int();
p->Y = io.r_int();
p->Z = io.r_int();
p->Direction = io.r_int();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p->Title;
delete p;
} break;
case 0x1B:{
p_stance_update *p = new p_stance_update;
p->A = io.r_float();
p->B = io.r_float();
p->C = io.r_float();
p->D = io.r_float();
p->E = io.r_bool();
p->F = io.r_bool();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x1C:{
p_entity_velocity *p = new p_entity_velocity;
p->EntityID = io.r_int();
p->vx = io.r_short();
p->vy = io.r_short();
p->vz = io.r_short();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x1D:{
p_destroy_entity *p = new p_destroy_entity;
p->EntityID = io.r_int();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x1E:{
p_entity *p = new p_entity;
p->EntityID = io.r_int();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x1F:{
p_entity_relative_move *p = new p_entity_relative_move;
p->EntityID = io.r_int();
p->dX = io.r_byte();
p->dY = io.r_byte();
p->dZ = io.r_byte();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x20:{
p_entity_look *p = new p_entity_look;
p->EntityID = io.r_int();
p->Yaw = io.r_byte();
p->Pitch = io.r_byte();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x21:{
p_entity_look_and_relative_move *p = new p_entity_look_and_relative_move;
p->EntityID = io.r_int();
p->dX = io.r_byte();
p->dY = io.r_byte();
p->dZ = io.r_byte();
p->Yaw = io.r_byte();
p->Pitch = io.r_byte();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x22:{
p_entity_teleport *p = new p_entity_teleport;
p->EntityID = io.r_int();
p->X = io.r_int();
p->Y = io.r_int();
p->Z = io.r_int();
p->Yaw = io.r_byte();
p->Pitch = io.r_byte();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x26:{
p_entity_status *p = new p_entity_status;
p->EntityID = io.r_int();
p->Status = io.r_byte();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x27:{
p_attach_entity *p = new p_attach_entity;
p->EntityID = io.r_int();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x28:{
p_entity_metadata *p = new p_entity_metadata;
p->EntityID = io.r_int();
p->Metadata = io.r_metadata();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p->Metadata;
delete p;
} break;
case 0x32:{
p_prechunk *p = new p_prechunk;
p->X = io.r_int();
p->Z = io.r_int();
p->Mode = io.r_bool();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x33:{
p_map_chunk *p = new p_map_chunk;
p->X = io.r_int();
p->Y = io.r_short();
p->Z = io.r_int();
p->SizeX = io.r_byte();
p->SizeY = io.r_byte();
p->SizeZ = io.r_byte();
p->CompressedSize = io.r_int();
p->CompressedData = io.r_bytearray(p->CompressedSize);
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p->CompressedData;
delete p;
} break;
case 0x34:{
p_multi_block_change *p = new p_multi_block_change;
p->ChunkX = io.r_int();
p->ChunkZ = io.r_int();
p->ArraySize = io.r_short();
p->CoordinateArray = io.r_shortarray(p->ArraySize);
p->TypeArray = io.r_bytearray(p->ArraySize);
p->MetadataArray = io.r_bytearray(p->ArraySize);
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p->CoordinateArray;
delete p->TypeArray;
delete p->MetadataArray;
delete p;
} break;
case 0x35:{
p_block_change *p = new p_block_change;
p->X = io.r_int();
p->Y = io.r_byte();
p->Z = io.r_int();
p->Type = io.r_byte();
p->Metadata = io.r_byte();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x36:{
p_block_action *p = new p_block_action;
p->X = io.r_int();
p->Y = io.r_short();
p->Z = io.r_int();
p->DataA = io.r_byte();
p->DataB = io.r_byte();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x3C:{
p_explosion *p = new p_explosion;
p->X = io.r_double();
p->Y = io.r_double();
p->Z = io.r_double();
p->Unknown = io.r_float();
p->RecordCount = io.r_int();
p->Records = io.r_bytearray(p->RecordCount*3);
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p->Records;
delete p;
} break;
case 0x3D:{
p_sound_effect *p = new p_sound_effect;
p->EffectID = io.r_int();
p->X = io.r_int();
p->Y = io.r_byte();
p->Z = io.r_int();
p->SoundData = io.r_int();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x46:{
p_new_state *p = new p_new_state;
p->Reason = io.r_byte();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x47:{
p_thunderbolt *p = new p_thunderbolt;
p->EntityID = io.r_int();
p->Unknown = io.r_bool();
p->X = io.r_int();
p->Y = io.r_int();
p->Z = io.r_int();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x64:{
p_open_window *p = new p_open_window;
p->WindowID = io.r_byte();
p->InventoryType = io.r_byte();
p->WindowTitle = io.r_string8();
p->NumberOfSlots = io.r_byte();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p->WindowTitle;
delete p;
} break;
case 0x65:{
p_close_window *p = new p_close_window;
p->WindowID = io.r_byte();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x66:{
p_window_click *p = new p_window_click;
p->WindowID = io.r_byte();
p->Slot = io.r_short();
p->RightClick = io.r_byte();
p->ActionNumber = io.r_short();
p->Shift = io.r_bool();
p->ItemID = io.r_short();
if (p->ItemID != -1) {
p->ItemCount = io.r_byte();
p->ItemUses = io.r_short();
} else {
p->ItemCount = -1;
p->ItemUses = -1;
}
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x67:{
p_set_slot *p = new p_set_slot;
p->WindowID = io.r_byte();
p->Slot = io.r_short();
p->ItemID = io.r_short();
if (p->ItemID != -1) {
p->ItemCount = io.r_byte();
p->ItemUses = io.r_short();
} else {
p->ItemCount = -1;
p->ItemUses = -1;
}
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x68:{
p_window_items *p = new p_window_items;
p->WindowID = io.r_byte();
p->Count = io.r_short();
p->items = io.r_itemarray(p->Count);
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p->items;
delete p;
} break;
case 0x69:{
p_update_progress_bar *p = new p_update_progress_bar;
p->WindowID = io.r_byte();
p->ProgressBar = io.r_short();
p->Value = io.r_short();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x6A:{
p_transaction *p = new p_transaction;
p->WindowID = io.r_byte();
p->ActionNumber = io.r_short();
p->Accepted = io.r_bool();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0x82:{
p_update_sign *p = new p_update_sign;
p->X = io.r_int();
p->Y = io.r_short();
p->Z = io.r_int();
p->Text1 = io.r_string16();
p->Text2 = io.r_string16();
p->Text3 = io.r_string16();
p->Text4 = io.r_string16();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p->Text1;
delete p->Text2;
delete p->Text3;
delete p->Text4;
delete p;
} break;
case 0x83:{
p_map_data *p = new p_map_data;
p->UnknownA = io.r_short();
p->UnknownB = io.r_short();
p->TextLength = io.r_ubyte();
p->Text = io.r_bytearray(p->TextLength);
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p->Text;
delete p;
} break;
case 0xC8:{
p_increment_statistic *p = new p_increment_statistic;
p->StatisticID = io.r_int();
p->Amount = io.r_byte();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p;
} break;
case 0xFF:{
p_kick *p = new p_kick;
p->Message = io.r_string16();
if (!io.working) break;
p->id = pid;
client->packet((p_generic*)p);
delete p->Message;
delete p;
} break;
default:
std::cout << "Undefined packet: 0x" << std::hex << (int)pid << '\n';
client->disconnect();
return 1;
}
}
if (!io.working) {
std::cout << "Socket Error 0x" << std::hex << (int)pid << '\n';
client->disconnect();
}
return 0;