-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathServer_player.h
4389 lines (4124 loc) · 160 KB
/
Server_player.h
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
#pragma once
#include "stdafx.h"
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <fstream>
#include <iostream>
#include <locale>
#include <string>
#include <thread>
#include <time.h>
#include <vector>
#include <experimental/filesystem>
#include "json.hpp"
#include "Server_core.h"
#include "enet/enet.h"
using namespace std;
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
using json = nlohmann::json;
int maxItems = 10388;
char _getch() {
return getchar();
}
#define cloth0 cloth_hair
#define cloth1 cloth_shirt
#define cloth2 cloth_pants
#define cloth3 cloth_feet
#define cloth4 cloth_face
#define cloth5 cloth_hand
#define cloth6 cloth_back
#define cloth7 cloth_mask
#define cloth8 cloth_necklace
#define cloth9 cloth_ances
#define STRINT(x, y) (*(int*)(&(x)[(y)]))
#define STR16(x, y) (*(uint16_t*)(&(x)[(y)]))
vector<string> guildmem;
vector<string> guildelder;
vector<string> guildco;
#ifdef _WIN32
#include <windows.h>
typedef __int8 __int8_t;
typedef __int16 __int16_t;
#elif __APPLE__ || __linux__
typedef unsigned int DWORD;
#endif
typedef unsigned char BYTE;
struct InventoryItem
{
__int16_t itemID;
__int16_t itemCount;
};
struct PlayerInventory
{
vector<InventoryItem> items;
};
struct PlayerInfo
{
/*notvend*/
string NickPrefix = "";
// achievements
int ThisLandIsMyLand = 0;
int ban = 0;
//rift cape
bool capeR = false;
bool capeG = false;
bool capeB = false;
bool collarR = false;
bool collarB = false;
bool collarG = false;
bool timedilation = false;
bool rifteffect = false;
bool collarcape = false;
bool checkbox_timedilation = false;
bool checkbox_capecollar = false;
bool checkbox_closedcape = false;
bool checkbox_opencapemovement = false;
bool checkbox_auraonoff = false;
bool checkbox_portalaura = false;
bool checkbox_starfieldaura = false;
bool checkbox_electricalaura = false;
bool udahsettingorno = false;
bool capeR2 = false;
bool capeG2 = false;
bool collarR2 = false;
bool collarB2 = false;
bool collarG2 = false;
bool capeB2 = false;
//end code//
/*Fishing*/
bool Fishing = false;
bool TriggerFish = false;
int FishPosX = 0;
int FishPosY = 0;
string LastBait = "None";
/*OnSuperMain*/
string zf = "";
/*ItemSuckers*/
int magplantitemid = 0;
int magplantx = 0;
int magplanty = 0;
string suckername = "";
int suckerid = 0;
/*PlayerLogin*/
string email = "";
bool HasLogged = false;
bool isBot = true;
/*Buffs*/
bool GemBuffDrop = false;
/*Consummables*/
bool blueBerry = false;
int usedBerry = 0;
int lastBerry = 0;
bool LuckyClover = false;
int usedClover = 0;
int lastClover = 0;
bool SpikeJuice = false;
int usedSpike = 0;
int lastSpike = 0;
bool PunchPotion = false;
int usedPunchPotion = 0;
int lastTradeItem;
int LastTradeItem1;
string currentTradeItems = "";
int lastTradeNetID = 0;
int lastTradeAcceptCount;
int isDoTrade;
int lastCT1;
int lastCT2;
int lastCT3;
int lastCT4;
int isTradingWithUser;
string lastvendbuycount = "";
int lastTD1;
int lastTD2;
int lastTD3;
int lastTD4;
bool isDoTheTrade = false;
bool istrading = false;
int item1 = 0;
int item1count = 0;
int item2 = 0;
int item2count = 0;
int item3 = 0;
int item3count = 0;
int item4 = 0;
int item4count = 0;
bool accepted = false;
string tradingme = "";
bool dotrade = false;
bool tradeSomeone = false;
int dyecolor = 0;
int eyecolor = 0;
int eyecolor2 = 0;
string trdStarter = "";
int lastPunchPotion = 0;
bool PlacePotion = false;
int usedPlacePotion = 0;
int lastPlacePotion = 0;
/*PlayerName*/
bool isDr = false;
/*Misc*/
bool passedname = false;
bool passedheight = false;
bool passedwidth = false;
bool passedbackground = false;
bool passedforeground = false;
bool passedbedrock = false;
string chatcolor = "";
/**/
bool isDisableMessages = false;
/*HPSystem | PVP*/
int lastPVPcoord = 0;
int lastPVPcoord2 = 0;
int lastPVPcoord3 = 0;
int lastPVPcoord4 = 0;
int lastPVPcoord5 = 0;
long long int LastScanMSG;
int lastPVPcoord6 = 0;
int lastPVPcoord7 = 0;
int health = 100;
int score = 0;
int noobCounter = 0;
bool Growid = false;
// end hp
int wrenchedBlockLocation = -1;
int displayfg = 0;
int displaybg = 0;
int displaypunchx = 0;
int LastX = 0;
bool UpdateFinisheds = true;
int LastY = 0;
int displaypunchy = 0;
int lastsavemyworld = 0;
int SubscribtionEndDay = 0;
int lastdailyGems = 0;
int packetinsec = 0;
long long int packetsec = 0;
int timeTogetToken = 0;
int trashgemmeritem = 0;
int eikiscia = 0;
int bootybreaken = 0;
bool startkit = false;
bool UpdateFinished = true;
string OriName = "";
int wrenchx;
int wrenchy;
long long int lastSPIN = 0;
int droppeditemcount = 0;
int lastdroppeditemid = 0;
int lastPunchX;
bool blockLogin = false;
int lastPunchY;
int lastPunchForeground;
int lastPunchBackground;
bool isInWorld = false;
bool GlobalChat = false;
bool isBannedWait = false;
bool usedCP = false;
int TotalKills = 0;
string skill = "None";
string sid = "none";
bool Console = false;
bool isIn = false;
string notebook = "";
int netID;
long long int startedTest = 0;
string Chatname = "";
bool Subscriber = false;
int lastdropitemcount = 0;
int lastdropitem = 0;
int lasttrashitem = 0;
int lasttrashitemcount = 0;
long long int lastwarn = 0;
int lastwarnCount = 0;
int violations = 0;
long long int lastcurse = 0;
int lastcurseCount = 0;
long long int lastban = 0;
int lastbanCount = 0;
long long int lastsuspend2w = 0;
int lastsuspend2wCount = 0;
long long int lastsuspend4w = 0;
int lastsuspend4wCount = 0;
long long int lastsuspend8w = 0;
int lastsuspend8wCount = 0;
long long int lastsuspendwrench = 0;
int lastsuspendwrenchCount = 0;
long long int lastbanipwrench = 0;
int lastbanipwrenchCount = 0;
long long int lastsuspend = 0;
int lastsuspendCount = 0;
int Awesomeness = 0;
long long int lastdelete = 0;
int lastdeleteCount = 0;
long long int lastbanip = 0;
int lastbanipCount = 0;
long long int lastdelstatus = 0;
int lastdelstatusCount = 0;
int wrenchsession;
bool ZiuriIKaire = false;
int bitShiftTest = 0;
bool canLeave = true;
bool haveGrowId = false;
bool needsaveinventory = false;
bool haveGuestId = false;
int valgem;
int fEarth = 0;
int fDark = 0;
int plantgems = 0;
int fFire = 0;
int lavaLevel = 0;
bool RotatedLeft = false;
int fWater = 0;
bool isRotatedLeft = false;
string tankIDName = "";
string tankIDPass = "";
string requestedName = "";
string rawName = "";
int warns = 0;
long long lastonline = 0;
int bans = 0;
int darkfragment = 0;
int earthfragment = 0;
int firefragment = 0;
int waterfragment = 0;
bool transsuccess = false;
bool isModState = false;
string displayName = "";
bool wrongpass = false;
int guildBg = 0;
int guildFg = 0;
string guildStatement = "";
string guildLeader = "";
string displayNamebackup = "";
string displayUsername = "";
vector<string> guildmatelist;
vector<string> guildMembers;
vector<string> worldsowned;
vector<string> lastworlds;
int guildlevel = 0;
int guildexp = 0;
bool isinvited = false;
string createGuildName = "";
string createGuildStatement = "";
string createGuildFlagBg = "";
string createGuildFlagFg = "";
string guild = "";
bool joinguild = false;
string lastgm = "";
string lastgmname = "";
string lastgmworld = "";
string guildlast = "";
string msgName = "";
bool isNicked = false;
string country = "";
string gameversion = "";
string rid = "none";
string gid = "none";
string aid = "none";
bool canExit = true;
string vid = "none";
string wkid = "";
string metaip = "";
string hash2 = "";
string hash = "";
string fhash = "";
string mac = "none";
string token = "";
string user = "";
string deviceversion = "";
string doorID = "";
string cbits = "";
string lmode = "";
string gdpr = "";
string f = "";
string fz = "";
string hpid = "";
string platformID = "";
string player_age = "1";
int adminLevel = 0;
string currentWorld = "EXIT";
bool radio = true;
int x;
int y;
int x1;
int y1;
int posXY;
int posX;
int posY;
int cpY;
int cpX;
int SignPosX;
int SignPosY;
bool characterLoaded = false;
string charIP = "none";
bool isDBanned = false;
vector<string> friendinfo;
vector<string> createfriendtable;
vector<string> createworldsowned;
string lastFrn = "";
string lastFrnName = "";
string lastFrnWorld = "";
string lastMsger = "";
string lastMsgerTrue = "";
string lastMsgWorld = "";
string lastSdbWorld = "";
string lastSbbWorld = "";
string lastfriend = "";
string lastInfo = "";
string lastInfoname = "";
string lastDisplayname = "";
string lastSeller = "";
string lastSellWorld = "";
string lastBuyer = "";
string lastInfoAboutPlayer = "none";
long int lastTradeAmount = 99999999999;
string addgems = "1000 gems";
int characterState = 0;
int level = 1;
int xp = 0;
bool game1bet = false;
bool game2bet = false;
bool isUpdating = false;
bool joinClothesUpdated = false;
int effect = 8421376;
int peffect = 8421376;
bool taped = false;
bool canCreate = false;
int cloth_hair = 0; // 0
int cloth_shirt = 0; // 1
int cloth_pants = 0; // 2
int cloth_feet = 0; // 3
int cloth_face = 0; // 4
int cloth_hand = 0; // 5
int cloth_back = 0; // 6
int cloth_mask = 0; // 7
int cloth_necklace = 0; // 8
int cloth_ances = 0; // 9
int cur = 0;
int ipID = 0;
bool canWalkInBlocks = false; // 1
bool canDoubleJump = false; // 2
bool cantsay = false;
bool isInvisible = false; // 4
bool noHands = false; // 8
bool noEyes = false; // 16
bool noBody = false; // 32
bool devilHorns = false; // 64
bool goldenHalo = false; // 128
bool isFrozen = false; // 2048
bool isCursed = false; // 4096
bool isDuctaped = false; // 8192
unsigned long long int lastMuted = 0;
unsigned long long int lastCursed = 0;
bool haveCigar = false; // 16384
bool isShining = false; // 32768
bool isAncients = false; // 32768
bool isAncients1 = false; // 32768
bool isAncients2 = false; // 32768
bool isAncients3 = false; // 32768
bool isAncients4 = false; // 32768
bool isAncients5 = false; // 32768
bool isAncients6 = false; // 32768
bool isZombie = false; // 65536
bool isHitByLava = false; // 131072
bool haveHauntedShadows = false; // 262144
bool haveGeigerRadiation = false; // 524288
bool haveReflector = false; // 1048576
bool isEgged = false; // 2097152
bool havePineappleFloag = false; // 4194304
bool haveFlyingPineapple = false; // 8388608
bool haveSuperSupporterName = false; // 16777216
bool haveSupperPineapple = false; // 33554432
bool isGhost = false;
bool isinv = false;
int skinColor = 0x8295C3FF;
PlayerInventory inventory;
/*surgery*/
int Ultrasound = 0;
bool PatientHeartStopped = false;
long long int SurgeryTime = 0;
bool SurgeryCooldown = false;
float PatientTemperatureRise = 0;
bool FixIt = false;
bool UnlockedAntibiotic = false;
bool PerformingSurgery = false;
int SurgerySkill = 0;
bool RequestedSurgery = false;
string TempColor = "";
bool HardToSee = false;
bool PatientLosingBlood = false;
int SurgItem1 = 4320;
int SurgItem2 = 4320;
int SurgItem3 = 4320;
int SurgItem4 = 4320;
int SurgItem5 = 4320;
int SurgItem6 = 4320;
int SurgItem7 = 4320;
int SurgItem8 = 4320;
int SurgItem9 = 4320;
int SurgItem10 = 4320;
int SurgItem11 = 4320;
int SurgItem12 = 4320;
int SurgItem13 = 4320;
string PatientDiagnosis = "";
string PatientPulse = "";
string PatientStatus = "";
float PatientTemperature = 0;
string OperationSite = "";
string IncisionsColor = "";
int PatientIncisions = 0;
string PatientRealDiagnosis = "";
//trade stars
long long int lastTrade = 0;
string lastTradeGrowid = "";
string MergeItem1 = "0";
string MergeItem2 = "0";
string MergeItem3 = "0";
string mySellingItem1 = "3308";
string mySellingItem2 = "3308";
string mySellingItem3 = "3308";
string mySellingItem4 = "3308";
string mySellingItem1Count = "0";
string mySellingItem2Count = "0";
string mySellingItem3Count = "0";
string mySellingItem4Count = "0";
string hisSellingItem1 = "3308";
string hisSellingItem2 = "3308";
string hisSellingItem3 = "3308";
string hisSellingItem4 = "3308";
string hisSellingItem1Count = "0";
string hisSellingItem2Count = "0";
string hisSellingItem3Count = "0";
string hisSellingItem4Count = "0";
string receivedFrom = "";
//trade ends
short currentInventorySize = 0;
long long int lastSB = 0;
long long int lastSDB = 0;
long long int lastSSB = 0;
long long int lastINV = 0;
long long int lastBREAK = 0;
long long int lastMute = 0;
long long int lastBan = 0;
long long int lastCurse = 0;
long long int lastATM = 0;
long long int lastSYNC = 0;
long long int lastDISPLAY = 0;
int blockx;
int blocky;
bool isUseCode = false;
bool isConfirmingCode = false;
string registercode = "";
string registermac = "";
string registerrid = "";
string registersid = "";
string registergid = "";
string registervid = "";
string registeraid = "";
string registerIP = "";
int lastUserID = 0;
int userID = 0;
int respawnX = 0;
int respawnY = 0;
bool ischeck = false;
int checkx = 0;
int checky = 0;
bool loadedInventory = false;
long long int lastPunchTime = 0;
long long int lastHitTime = 0;
long long int lastJoinReq = 0;
long long int lastsendclient = 0;
long long int lastpacketflood = 0;
long long int lastenterdoor = 0;
uint32_t lavaHitAt = 0;
uint32_t deadTime = 0;
};
PlayerInfo* pdata(ENetPeer* peer) {
return (PlayerInfo*)(peer->data);
}
struct PlayerMoving
{
int packetType;
int netID;
float x;
float y;
int characterState;
int plantingTree;
float XSpeed;
float YSpeed;
int punchX;
int punchY;
int secondnetID;
};
struct Admin
{
string username;
string password;
int level = 0;
long long int lastSB = 0;
long long int lastWarp = 0;
long long int lastSpawn = 0;
long long int lastasb = 0;
};
struct GamePacket
{
BYTE* data;
int len;
int indexes;
};
enum ClothTypes
{
HAIR,
SHIRT,
PANTS,
FEET,
FACE,
HAND,
BACK,
MASK,
NECKLACE,
ANCES,
NONE
};
bool replace(std::string& str, const std::string& from, const std::string& to) {
size_t start_pos = str.find(from);
if (start_pos == std::string::npos)
return false;
str.replace(start_pos, from.length(), to);
return true;
}
inline int getState(PlayerInfo* info)
{
auto val = 0;
val |= info->canWalkInBlocks << 0;
val |= info->canDoubleJump << 1;
val |= info->cantsay << 13;
val |= info->noHands << 3;
val |= info->noEyes << 4;
val |= info->noBody << 5;
val |= info->goldenHalo << 7;
val |= info->isFrozen << 8;
val |= info->isCursed << 12;
val |= info->isDuctaped << 13;
val |= info->haveSuperSupporterName << 24;
val |= info->isShining << 15;
val |= info->isZombie << 16;
val |= info->isHitByLava << 17;
return val;
}
class Player
{
public:
static void OnConsoleMessage(ENetPeer* peer, string text);
static void OnTalkBubble(ENetPeer* peer, int netID, string text, int chatColor, bool isOverlay);
static void OnAddNotification(ENetPeer* peer, string text, string audiosound, string interfaceimage);
static void OnRemove(ENetPeer* peer, int netID);
static void OnSendToServer(ENetPeer* peer, int userID, int token, string ip, int port, string doorId, int lmode); // no need other args, sub servers done&working already... using fake data etc.
static void PlayAudio(ENetPeer* peer, string audioFile, int delayMS);
static void OnZoomCamera(ENetPeer* peer, float value1, int value2);
static void SmoothZoom(ENetPeer* peer);
static void OnRaceStart(ENetPeer* peer, int netID);
static void OnRaceEnd(ENetPeer* peer, int netID);
static void OnSetCurrentWeather(ENetPeer* peer, int weather);
static void OnPlayPositioned(ENetPeer* peer, string audiofile, int netID, bool broadcastInWorld, ENetPacket* pk);
static void OnCountdownStart(ENetPeer* peer, int netID, int time, int score);
static void OnStartTrade(ENetPeer* peer, string displayName, int netID);
static void OnTextOverlay(ENetPeer* peer, string text);
static void OnForceTradeEnd(ENetPeer* peer);
static void OnFailedToEnterWorld(ENetPeer* peer);
static void OnTradeStatus(ENetPeer* peer, int netIDOther, string offerstatus, string offer);
static void OnNameChanged(ENetPeer* peer, int netID, string name);
static void OnDialogRequest(ENetPeer* peer, string args);
static void OnKilled(ENetPeer* peer, int netID);
static void OnSetFreezeState(ENetPeer* peer, int state, int netID);
static void OnSetPos(ENetPeer* peer, int netID, int x, int y);
static void OnInvis(ENetPeer* peer, int state, int netID);
static void OnChangeSkin(ENetPeer* peer, int skinColor, int netID);
static void SetRespawnPos(ENetPeer* peer, int posX, int posY, int netID);
static void OnSetBux(ENetPeer* peer, int gems, int accountstate);
static void onGiveGems(ENetPeer* peer, int gems);
static void OnParticleEffect(ENetPeer* peer, int effect, float x, float y, int delay);
static void SetHasGrowID(ENetPeer* peer, int status, string username, string password);
static void Ping(ENetPeer* peer);
};
class PlayerDB
{
public:
static string getProperName(string name);
static string fixColors(string text);
static int playerLogin(ENetPeer* peer, string username, string password);
static int playerRegister(ENetPeer* peer, string username, string password, string email, string code);
static int guildRegister(ENetPeer* peer, string guildName, string guildStatement, string guildFlagfg, string guildFlagbg);
};
inline string PlayerDB::getProperName(string name)
{
string newS;
for (auto c : name) newS += (c >= 'A' && c <= 'Z') ? c - ('A' - 'a') : c;
string ret;
for (auto i = 0; i < newS.length(); i++)
{
if (newS[i] == '`') i++;
else ret += newS[i];
}
string ret2;
for (auto c : ret) if ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) ret2 += c;
return ret2;
}
inline string PlayerDB::fixColors(string text)
{
string ret = "";
auto colorLevel = 0;
for (auto i = 0; i < text.length(); i++)
{
if (text[i] == '`')
{
ret += text[i];
if (i + 1 < text.length())
ret += text[i + 1];
if (i + 1 < text.length() && text[i + 1] == '`')
{
colorLevel--;
}
else
{
colorLevel++;
}
i++;
}
else
{
ret += text[i];
}
}
for (auto i = 0; i < colorLevel; i++)
{
ret += "``";
}
for (auto i = 0; i > colorLevel; i--)
{
ret += "`w";
}
return ret;
}
long long PlayTimeGame()
{
using namespace std::chrono;
return (duration_cast<hours>(system_clock::now().time_since_epoch())).count();
}
string PlayTimeGameMinutes(int n) {
string x;
int day = n / (24 * 3600);
if (day != 0) x.append(to_string(day) + " days, ");
n = n % (24 * 3600);
int hour = n / 3600;
if (hour != 0) x.append(to_string(hour) + " hours ");
n %= 3600;
int minutes = n / 60;
if (minutes != 0) x.append(to_string(minutes) + " minutes, & ");
n %= 60;
int seconds = n;
if (seconds != 0) x.append(to_string(seconds) + " seconds");
return x;
}
inline GamePacket appendFloat(GamePacket p, float val)
{
const auto n = new BYTE[p.len + 2 + 4];
memcpy(n, p.data, p.len);
delete p.data;
p.data = n;
n[p.len] = p.indexes;
n[p.len + 1] = 1;
memcpy(n + p.len + 2, &val, 4);
p.len = p.len + 2 + 4;
p.indexes++;
return p;
}
inline GamePacket appendFloat(GamePacket p, float val, float val2)
{
const auto n = new BYTE[p.len + 2 + 8];
memcpy(n, p.data, p.len);
delete p.data;
p.data = n;
n[p.len] = p.indexes;
n[p.len + 1] = 3;
memcpy(n + p.len + 2, &val, 4);
memcpy(n + p.len + 6, &val2, 4);
p.len = p.len + 2 + 8;
p.indexes++;
return p;
}
inline GamePacket appendFloat(GamePacket p, float val, float val2, float val3)
{
const auto n = new BYTE[p.len + 2 + 12];
memcpy(n, p.data, p.len);
delete p.data;
p.data = n;
n[p.len] = p.indexes;
n[p.len + 1] = 4;
memcpy(n + p.len + 2, &val, 4);
memcpy(n + p.len + 6, &val2, 4);
memcpy(n + p.len + 10, &val3, 4);
p.len = p.len + 2 + 12;
p.indexes++;
return p;
}
inline GamePacket appendInt(GamePacket p, int val)
{
const auto n = new BYTE[p.len + 2 + 4];
memcpy(n, p.data, p.len);
delete p.data;
p.data = n;
n[p.len] = p.indexes;
n[p.len + 1] = 9;
memcpy(n + p.len + 2, &val, 4);
p.len = p.len + 2 + 4;
p.indexes++;
return p;
}
inline GamePacket appendIntx(GamePacket p, int val)
{
const auto n = new BYTE[p.len + 2 + 4];
memcpy(n, p.data, p.len);
delete p.data;
p.data = n;
n[p.len] = p.indexes;
n[p.len + 1] = 5;
memcpy(n + p.len + 2, &val, 4);
p.len = p.len + 2 + 4;
p.indexes++;
return p;
}
inline GamePacket appendString(GamePacket p, string str)
{
const auto n = new BYTE[p.len + 2 + str.length() + 4];
memcpy(n, p.data, p.len);
delete p.data;
p.data = n;
n[p.len] = p.indexes;
n[p.len + 1] = 2;
int sLen = str.length();
memcpy(n + p.len + 2, &sLen, 4);
memcpy(n + p.len + 6, str.c_str(), sLen);
p.len = p.len + 2 + str.length() + 4;
p.indexes++;
return p;
}
inline GamePacket createPacket()
{
const auto data = new BYTE[61];
string asdf = "0400000001000000FFFFFFFF00000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
for (auto i = 0; i < asdf.length(); i += 2)
{
char x = ch2n(asdf[i]);
x = x << 4;
x += ch2n(asdf[i + 1]);
memcpy(data + (i / 2), &x, 1);
if (asdf.length() > 61 * 2) throw 0;
}
GamePacket packet;
packet.data = data;
packet.len = 61;
packet.indexes = 0;
return packet;
}
inline GamePacket packetEnd(GamePacket p)
{
const auto n = new BYTE[p.len + 1];
memcpy(n, p.data, p.len);
delete p.data;
p.data = n;
char zero = 0;
memcpy(p.data + p.len, &zero, 1);
p.len += 1;
*reinterpret_cast<int*>(p.data + 56) = p.indexes;
*static_cast<BYTE*>(p.data + 60) = p.indexes;
return p;
}
inline BYTE* packPlayerMoving(PlayerMoving* dataStruct)
{
const auto data = new BYTE[64];
for (auto i = 0; i < 64; i++)
{
data[i] = 0;
}
memcpy(data, &dataStruct->packetType, 4);
memcpy(data + 4, &dataStruct->netID, 4);
memcpy(data + 12, &dataStruct->characterState, 4);
memcpy(data + 20, &dataStruct->plantingTree, 4);
memcpy(data + 24, &dataStruct->x, 4);
memcpy(data + 28, &dataStruct->y, 4);
memcpy(data + 32, &dataStruct->XSpeed, 4);
memcpy(data + 36, &dataStruct->YSpeed, 4);
memcpy(data + 44, &dataStruct->punchX, 4);
memcpy(data + 48, &dataStruct->punchY, 4);
return data;
}
string packPlayerMoving2(PlayerMoving* dataStruct)
{
string data;
data.resize(56);
STRINT(data, 0) = dataStruct->packetType;
STRINT(data, 4) = dataStruct->netID;
STRINT(data, 12) = dataStruct->characterState;
STRINT(data, 20) = dataStruct->plantingTree;
STRINT(data, 24) = *(int*)&dataStruct->x;
STRINT(data, 28) = *(int*)&dataStruct->y;
STRINT(data, 32) = *(int*)&dataStruct->XSpeed;
STRINT(data, 36) = *(int*)&dataStruct->YSpeed;
STRINT(data, 44) = dataStruct->punchX;
STRINT(data, 48) = dataStruct->punchY;
return data;
}
inline PlayerMoving* unpackPlayerMoving(BYTE* data)
{
auto dataStruct = new PlayerMoving;
memcpy(&dataStruct->packetType, data, 4);
memcpy(&dataStruct->netID, data + 4, 4);
memcpy(&dataStruct->characterState, data + 12, 4);
memcpy(&dataStruct->plantingTree, data + 20, 4);
memcpy(&dataStruct->x, data + 24, 4);
memcpy(&dataStruct->y, data + 28, 4);
memcpy(&dataStruct->XSpeed, data + 32, 4);
memcpy(&dataStruct->YSpeed, data + 36, 4);
memcpy(&dataStruct->punchX, data + 44, 4);
memcpy(&dataStruct->punchY, data + 48, 4);
return dataStruct;
}
inline long long GetCurrentTimeInternal()
{
using namespace std::chrono;
return (duration_cast<milliseconds>(system_clock::now().time_since_epoch())).count();
}
inline long long GetCurrentTimeInternalSeconds()
{
using namespace std::chrono;
return (duration_cast<seconds>(system_clock::now().time_since_epoch())).count();
}
inline int calcBanDuration(const long long banDuration)
{
// ReSharper disable once CppInitializedValueIsAlwaysRewritten
auto duration = 0;
duration = banDuration - GetCurrentTimeInternalSeconds();
if (duration <= 0) return 0;
else return duration;
}
inline string OutputBanTime(int n)
{
string x;
const auto day = n / (24 * 3600);
if (day != 0) x.append(to_string(day) + " Days ");
n = n % (24 * 3600);
const auto hour = n / 3600;
if (hour != 0) x.append(to_string(hour) + " Hours ");
n %= 3600;
const auto minutes = n / 60;
if (minutes != 0) x.append(to_string(minutes) + " Minutes ");
n %= 60;
const auto seconds = n;
if (seconds != 0) x.append(to_string(seconds) + " Seconds");
return x;
}
inline void banLoginDevice(ENetPeer* peer, const long long banDurationDefault, string sid, string mac)
{
const auto bantimeleft = calcBanDuration(banDurationDefault);
if (bantimeleft < 1) return;
const auto text = "action|log\nmsg|`4Sorry, this device or location is still banned for `w" + OutputBanTime(calcBanDuration(banDurationDefault)) + " Need help? Contact Time#1337!";
const string dc = "https://growtopiacps.weebly.com/";
const auto url = "action|set_url\nurl|" + dc + "\nlabel|Join GrowtopiaCP Discord\n";
const auto data = new BYTE[5 + text.length()];
const auto dataurl = new BYTE[5 + url.length()];
BYTE zero = 0;
auto type = 3;
memcpy(data, &type, 4);
memcpy(data + 4, text.c_str(), text.length());
memcpy(data + 4 + text.length(), &zero, 1);
memcpy(dataurl, &type, 4);
memcpy(dataurl + 4, url.c_str(), url.length());
memcpy(dataurl + 4 + url.length(), &zero, 1);
const auto p = enet_packet_create(data, 5 + text.length(), ENET_PACKET_FLAG_RELIABLE);
enet_peer_send(peer, 0, p);
const auto p3 = enet_packet_create(dataurl, 5 + url.length(), ENET_PACKET_FLAG_RELIABLE);
enet_peer_send(peer, 0, p3);
delete data;
delete dataurl;
static_cast<PlayerInfo*>(peer->data)->blockLogin = true;
}
inline void SendInventory(ENetPeer* peer, PlayerInventory inventory)
{
if (static_cast<PlayerInfo*>(peer->data)->currentWorld == "EXIT") return;
const int inventoryLen = inventory.items.size();
const auto packetLen = 66 + (inventoryLen * 4) + 4;
auto* data2 = new BYTE[packetLen];
auto MessageType = 0x4;
auto PacketType = 0x9;
auto NetID = -1;
auto CharState = 0x8;
memset(data2, 0, packetLen);
memcpy(data2, &MessageType, 4);
memcpy(data2 + 4, &PacketType, 4);
memcpy(data2 + 8, &NetID, 4);
memcpy(data2 + 16, &CharState, 4);
//int endianInvVal = __builtin_bswap32(inventoryLen);
int endianInvVal = _byteswap_ulong(inventoryLen);