-
Notifications
You must be signed in to change notification settings - Fork 404
/
client_process.cpp
2436 lines (2130 loc) · 67.1 KB
/
client_process.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
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2003 EQEMu Development Team (http://eqemulator.net)
This program 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; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
client_process.cpp:
Handles client login sequence and packets sent from client to zone
*/
#include "../common/eqemu_logsys.h"
#include "../common/global_define.h"
#include <iostream>
#include <stdio.h>
#include <zlib.h>
#ifdef _WINDOWS
#include <windows.h>
#include <winsock.h>
#define snprintf _snprintf
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#else
#include <pthread.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#endif
#include "../common/rulesys.h"
#include "../common/skills.h"
#include "../common/spdat.h"
#include "../common/string_util.h"
#include "event_codes.h"
#include "guild_mgr.h"
#include "map.h"
#include "petitions.h"
#include "queryserv.h"
#include "quest_parser_collection.h"
#include "string_ids.h"
#include "worldserver.h"
#include "zone.h"
#include "zonedb.h"
extern QueryServ* QServ;
extern Zone* zone;
extern volatile bool ZoneLoaded;
extern WorldServer worldserver;
extern PetitionList petition_list;
extern EntityList entity_list;
bool Client::Process() {
bool ret = true;
if(Connected() || IsLD())
{
// try to send all packets that weren't sent before
if(!IsLD() && zoneinpacket_timer.Check())
{
SendAllPackets();
}
if(adventure_request_timer)
{
if(adventure_request_timer->Check())
{
safe_delete(adventure_request_timer);
}
}
if(adventure_create_timer)
{
if(adventure_create_timer->Check())
{
safe_delete(adventure_create_timer);
}
}
if(adventure_leave_timer)
{
if(adventure_leave_timer->Check())
{
safe_delete(adventure_leave_timer);
}
}
if(adventure_door_timer)
{
if(adventure_door_timer->Check())
{
safe_delete(adventure_door_timer);
}
}
if(adventure_stats_timer)
{
if(adventure_stats_timer->Check())
{
safe_delete(adventure_stats_timer);
}
}
if(adventure_leaderboard_timer)
{
if(adventure_leaderboard_timer->Check())
{
safe_delete(adventure_leaderboard_timer);
}
}
if(dead)
{
SetHP(-100);
if(RespawnFromHoverTimer.Check())
HandleRespawnFromHover(0);
}
if(IsTracking() && (GetClientVersion() >= ClientVersion::SoD) && TrackingTimer.Check())
DoTracking();
// SendHPUpdate calls hpupdate_timer.Start so it can delay this timer, so lets not reset with the check
// since the function will anyways
if(hpupdate_timer.Check(false))
SendHPUpdate();
if(mana_timer.Check())
SendManaUpdatePacket();
if(dead && dead_timer.Check()) {
database.MoveCharacterToZone(GetName(), database.GetZoneName(m_pp.binds[0].zoneId));
m_pp.zone_id = m_pp.binds[0].zoneId;
m_pp.zoneInstance = m_pp.binds[0].instance_id;
m_pp.x = m_pp.binds[0].x;
m_pp.y = m_pp.binds[0].y;
m_pp.z = m_pp.binds[0].z;
Save();
Group *mygroup = GetGroup();
if (mygroup)
{
entity_list.MessageGroup(this,true,15,"%s died.", GetName());
mygroup->MemberZoned(this);
}
Raid *myraid = entity_list.GetRaidByClient(this);
if (myraid)
{
myraid->MemberZoned(this);
}
return(false);
}
if(charm_update_timer.Check())
{
CalcItemScale();
}
if(TaskPeriodic_Timer.Check() && taskstate)
taskstate->TaskPeriodicChecks(this);
if(linkdead_timer.Check())
{
LeaveGroup();
Save();
if (GetMerc())
{
GetMerc()->Save();
GetMerc()->Depop();
}
Raid *myraid = entity_list.GetRaidByClient(this);
if (myraid)
{
myraid->MemberZoned(this);
}
return false; //delete client
}
if (camp_timer.Check())
{
LeaveGroup();
Save();
if (GetMerc())
{
GetMerc()->Save();
GetMerc()->Depop();
}
instalog = true;
}
if (IsStunned() && stunned_timer.Check())
Mob::UnStun();
if(!m_CheatDetectMoved)
{
m_TimeSinceLastPositionCheck = Timer::GetCurrentTime();
}
if (bardsong_timer.Check() && bardsong != 0) {
//NOTE: this is kinda a heavy-handed check to make sure the mob still exists before
//doing the next pulse on them...
Mob *song_target;
if(bardsong_target_id == GetID()) {
song_target = this;
} else {
song_target = entity_list.GetMob(bardsong_target_id);
}
if (song_target == nullptr) {
InterruptSpell(SONG_ENDS_ABRUPTLY, 0x121, bardsong);
} else {
if(!ApplyNextBardPulse(bardsong, song_target, bardsong_slot))
InterruptSpell(SONG_ENDS_ABRUPTLY, 0x121, bardsong);
//SpellFinished(bardsong, bardsong_target, bardsong_slot, spells[bardsong].mana);
}
}
if(GetMerc())
{
UpdateMercTimer();
}
if(GetMercInfo().MercTemplateID != 0 && GetMercInfo().IsSuspended)
{
CheckMercSuspendTimer();
}
if(IsAIControlled())
AI_Process();
// Don't reset the bindwound timer so we can check it in BindWound as well.
if (bindwound_timer.Check(false) && bindwound_target != 0) {
BindWound(bindwound_target, false);
}
if(KarmaUpdateTimer)
{
if(KarmaUpdateTimer->Check(false))
{
KarmaUpdateTimer->Start(RuleI(Chat, KarmaUpdateIntervalMS));
database.UpdateKarma(AccountID(), ++TotalKarma);
}
}
if(qGlobals)
{
if(qglobal_purge_timer.Check())
{
qGlobals->PurgeExpiredGlobals();
}
}
if(light_update_timer.Check()) {
UpdateEquipmentLight();
if(UpdateActiveLight()) {
SendAppearancePacket(AT_Light, GetActiveLightType());
}
}
bool may_use_attacks = false;
/*
Things which prevent us from attacking:
- being under AI control, the AI does attacks
- being dead
- casting a spell and bard check
- not having a target
- being stunned or mezzed
- having used a ranged weapon recently
*/
if(auto_attack) {
if(!IsAIControlled() && !dead
&& !(spellend_timer.Enabled() && casting_spell_id && !IsBardSong(casting_spell_id))
&& !IsStunned() && !IsFeared() && !IsMezzed() && GetAppearance() != eaDead && !IsMeleeDisabled()
)
may_use_attacks = true;
if(may_use_attacks && ranged_timer.Enabled()) {
//if the range timer is enabled, we need to consider it
if(!ranged_timer.Check(false)) {
//the ranged timer has not elapsed, cannot attack.
may_use_attacks = false;
}
}
}
if(AutoFireEnabled()){
ItemInst *ranged = GetInv().GetItem(MainRange);
if(ranged)
{
if(ranged->GetItem() && ranged->GetItem()->ItemType == ItemTypeBow){
if(ranged_timer.Check(false)){
if(GetTarget() && (GetTarget()->IsNPC() || GetTarget()->IsClient())){
if(GetTarget()->InFrontMob(this, GetTarget()->GetX(), GetTarget()->GetY())){
if(CheckLosFN(GetTarget())){
//client has built in los check, but auto fire does not.. done last.
RangedAttack(GetTarget());
if (CheckDoubleRangedAttack())
RangedAttack(GetTarget(), true);
}
else
ranged_timer.Start();
}
else
ranged_timer.Start();
}
else
ranged_timer.Start();
}
}
else if(ranged->GetItem() && (ranged->GetItem()->ItemType == ItemTypeLargeThrowing || ranged->GetItem()->ItemType == ItemTypeSmallThrowing)){
if(ranged_timer.Check(false)){
if(GetTarget() && (GetTarget()->IsNPC() || GetTarget()->IsClient())){
if(GetTarget()->InFrontMob(this, GetTarget()->GetX(), GetTarget()->GetY())){
if(CheckLosFN(GetTarget())){
//client has built in los check, but auto fire does not.. done last.
ThrowingAttack(GetTarget());
}
else
ranged_timer.Start();
}
else
ranged_timer.Start();
}
else
ranged_timer.Start();
}
}
}
}
Mob *auto_attack_target = GetTarget();
if (auto_attack && auto_attack_target != nullptr && may_use_attacks && attack_timer.Check())
{
//check if change
//only check on primary attack.. sorry offhand you gotta wait!
if(aa_los_them_mob)
{
if(auto_attack_target != aa_los_them_mob ||
m_AutoAttackPosition.x != GetX() ||
m_AutoAttackPosition.y != GetY() ||
m_AutoAttackPosition.z != GetZ() ||
m_AutoAttackTargetLocation.x != aa_los_them_mob->GetX() ||
m_AutoAttackTargetLocation.y != aa_los_them_mob->GetY() ||
m_AutoAttackTargetLocation.z != aa_los_them_mob->GetZ())
{
aa_los_them_mob = auto_attack_target;
m_AutoAttackPosition = GetPosition();
m_AutoAttackTargetLocation = glm::vec3(aa_los_them_mob->GetPosition());
los_status = CheckLosFN(auto_attack_target);
los_status_facing = IsFacingMob(aa_los_them_mob);
}
// If only our heading changes, we can skip the CheckLosFN call
// but above we still need to update los_status_facing
if (m_AutoAttackPosition.w != GetHeading()) {
m_AutoAttackPosition.w = GetHeading();
los_status_facing = IsFacingMob(aa_los_them_mob);
}
}
else
{
aa_los_them_mob = auto_attack_target;
m_AutoAttackPosition = GetPosition();
m_AutoAttackTargetLocation = glm::vec3(aa_los_them_mob->GetPosition());
los_status = CheckLosFN(auto_attack_target);
los_status_facing = IsFacingMob(aa_los_them_mob);
}
if (!CombatRange(auto_attack_target))
{
Message_StringID(MT_TooFarAway,TARGET_TOO_FAR);
}
else if (auto_attack_target == this)
{
Message_StringID(MT_TooFarAway,TRY_ATTACKING_SOMEONE);
}
else if (!los_status || !los_status_facing)
{
//you can't see your target
}
else if (auto_attack_target->GetHP() > -10) // -10 so we can watch people bleed in PvP
{
if(CheckAAEffect(aaEffectRampage))
{
entity_list.AEAttack(this, 30);
} else {
Attack(auto_attack_target, MainPrimary); // Kaiyodo - added attacking hand to arguments
}
ItemInst *wpn = GetInv().GetItem(MainPrimary);
TryWeaponProc(wpn, auto_attack_target, MainPrimary);
bool tripleAttackSuccess = false;
if( auto_attack_target && CanThisClassDoubleAttack() ) {
CheckIncreaseSkill(SkillDoubleAttack, auto_attack_target, -10);
if(CheckDoubleAttack()) {
//should we allow rampage on double attack?
if(CheckAAEffect(aaEffectRampage)) {
entity_list.AEAttack(this, 30);
} else {
Attack(auto_attack_target, MainPrimary, false);
}
}
//triple attack: rangers, monks, warriors, berserkers over level 60
if((((GetClass() == MONK || GetClass() == WARRIOR || GetClass() == RANGER || GetClass() == BERSERKER)
&& GetLevel() >= 60) || GetSpecialAbility(SPECATK_TRIPLE))
&& CheckDoubleAttack(true))
{
tripleAttackSuccess = true;
Attack(auto_attack_target, MainPrimary, false);
}
//quad attack, does this belong here??
if(GetSpecialAbility(SPECATK_QUAD) && CheckDoubleAttack(true))
{
Attack(auto_attack_target, MainPrimary, false);
}
}
//Live AA - Flurry, Rapid Strikes ect (Flurry does not require Triple Attack).
int16 flurrychance = aabonuses.FlurryChance + spellbonuses.FlurryChance + itembonuses.FlurryChance;
if (auto_attack_target && flurrychance)
{
if(zone->random.Int(0, 99) < flurrychance)
{
Message_StringID(MT_NPCFlurry, YOU_FLURRY);
Attack(auto_attack_target, MainPrimary, false);
Attack(auto_attack_target, MainPrimary, false);
}
}
int16 ExtraAttackChanceBonus = spellbonuses.ExtraAttackChance + itembonuses.ExtraAttackChance + aabonuses.ExtraAttackChance;
if (auto_attack_target && ExtraAttackChanceBonus) {
ItemInst *wpn = GetInv().GetItem(MainPrimary);
if(wpn){
if(wpn->GetItem()->ItemType == ItemType2HSlash ||
wpn->GetItem()->ItemType == ItemType2HBlunt ||
wpn->GetItem()->ItemType == ItemType2HPiercing )
{
if(zone->random.Int(0, 99) < ExtraAttackChanceBonus)
{
Attack(auto_attack_target, MainPrimary, false);
}
}
}
}
}
}
if (GetClass() == WARRIOR || GetClass() == BERSERKER) {
if (!dead && !IsBerserk() && GetHPRatio() < RuleI(Combat, BerserkerFrenzyStart)) {
entity_list.MessageClose_StringID(this, false, 200, 0, BERSERK_START, GetName());
berserk = true;
}
if (IsBerserk() && GetHPRatio() > RuleI(Combat, BerserkerFrenzyEnd)) {
entity_list.MessageClose_StringID(this, false, 200, 0, BERSERK_END, GetName());
berserk = false;
}
}
if(auto_attack && may_use_attacks && auto_attack_target != nullptr
&& CanThisClassDualWield() && attack_dw_timer.Check())
{
// Range check
if(!CombatRange(auto_attack_target)) {
// this is a duplicate message don't use it.
//Message_StringID(MT_TooFarAway,TARGET_TOO_FAR);
}
// Don't attack yourself
else if(auto_attack_target == this) {
//Message_StringID(MT_TooFarAway,TRY_ATTACKING_SOMEONE);
}
else if (!los_status || !los_status_facing)
{
//you can't see your target
}
else if(auto_attack_target->GetHP() > -10) {
float DualWieldProbability = 0.0f;
int16 Ambidexterity = aabonuses.Ambidexterity + spellbonuses.Ambidexterity + itembonuses.Ambidexterity;
DualWieldProbability = (GetSkill(SkillDualWield) + GetLevel() + Ambidexterity) / 400.0f; // 78.0 max
int16 DWBonus = spellbonuses.DualWieldChance + itembonuses.DualWieldChance;
DualWieldProbability += DualWieldProbability*float(DWBonus)/ 100.0f;
float random = zone->random.Real(0, 1);
CheckIncreaseSkill(SkillDualWield, auto_attack_target, -10);
if (random < DualWieldProbability){ // Max 78% of DW
if(CheckAAEffect(aaEffectRampage)) {
entity_list.AEAttack(this, 30, MainSecondary);
} else {
Attack(auto_attack_target, MainSecondary); // Single attack with offhand
}
ItemInst *wpn = GetInv().GetItem(MainSecondary);
TryWeaponProc(wpn, auto_attack_target, MainSecondary);
if( CanThisClassDoubleAttack() && CheckDoubleAttack()) {
if(CheckAAEffect(aaEffectRampage)) {
entity_list.AEAttack(this, 30, MainSecondary);
} else {
if(auto_attack_target && auto_attack_target->GetHP() > -10)
Attack(auto_attack_target, MainSecondary); // Single attack with offhand
}
}
}
}
}
if (position_timer.Check()) {
if (IsAIControlled())
{
if(IsMoving())
SendPosUpdate(2);
else
{
animation = 0;
m_Delta = glm::vec4(0.0f, 0.0f, 0.0f, m_Delta.w);
SendPosUpdate(2);
}
}
// Send a position packet every 8 seconds - if not done, other clients
// see this char disappear after 10-12 seconds of inactivity
if (position_timer_counter >= 36) { // Approx. 4 ticks per second
entity_list.SendPositionUpdates(this, pLastUpdateWZ, 500, GetTarget(), true);
pLastUpdate = Timer::GetCurrentTime();
pLastUpdateWZ = pLastUpdate;
position_timer_counter = 0;
}
else {
pLastUpdate = Timer::GetCurrentTime();
position_timer_counter++;
}
}
if(HasVirus()) {
if(viral_timer.Check()) {
viral_timer_counter++;
for(int i = 0; i < MAX_SPELL_TRIGGER*2; i+=2) {
if(viral_spells[i]) {
if(viral_timer_counter % spells[viral_spells[i]].viral_timer == 0) {
SpreadVirus(viral_spells[i], viral_spells[i+1]);
}
}
}
}
if(viral_timer_counter > 999)
viral_timer_counter = 0;
}
ProjectileAttack();
if(spellbonuses.GravityEffect == 1) {
if(gravity_timer.Check())
DoGravityEffect();
}
if (shield_timer.Check())
{
if (shield_target)
{
if (!CombatRange(shield_target))
{
entity_list.MessageClose_StringID(this, false, 100, 0,
END_SHIELDING, GetCleanName(), shield_target->GetCleanName());
for (int y = 0; y < 2; y++)
{
if (shield_target->shielder[y].shielder_id == GetID())
{
shield_target->shielder[y].shielder_id = 0;
shield_target->shielder[y].shielder_bonus = 0;
}
}
shield_target = 0;
shield_timer.Disable();
}
}
else
{
shield_target = 0;
shield_timer.Disable();
}
}
SpellProcess();
if (endupkeep_timer.Check() && !dead){
DoEnduranceUpkeep();
}
if (tic_timer.Check() && !dead) {
CalcMaxHP();
CalcMaxMana();
CalcATK();
CalcMaxEndurance();
CalcRestState();
DoHPRegen();
DoManaRegen();
DoEnduranceRegen();
BuffProcess();
DoStaminaUpdate();
if(tribute_timer.Check()) {
ToggleTribute(true); //re-activate the tribute.
}
if (fishing_timer.Check()) {
GoFish();
}
if (autosave_timer.Check()) {
Save(0);
}
if(m_pp.intoxication > 0)
{
--m_pp.intoxication;
CalcBonuses();
}
if(ItemTickTimer.Check())
{
TickItemCheck();
}
if(ItemQuestTimer.Check())
{
ItemTimerCheck();
}
}
}
if (client_state == CLIENT_KICKED) {
Save();
OnDisconnect(true);
std::cout << "Client disconnected (cs=k): " << GetName() << std::endl;
return false;
}
if (client_state == DISCONNECTED) {
OnDisconnect(true);
std::cout << "Client disconnected (cs=d): " << GetName() << std::endl;
database.SetMQDetectionFlag(this->AccountName(), GetName(), "/MQInstantCamp: Possible instant camp disconnect.", zone->GetShortName());
return false;
}
if (client_state == CLIENT_ERROR) {
OnDisconnect(true);
std::cout << "Client disconnected (cs=e): " << GetName() << std::endl;
return false;
}
if (client_state != CLIENT_LINKDEAD && !eqs->CheckState(ESTABLISHED)) {
OnDisconnect(true);
Log.Out(Logs::General, Logs::Zone_Server, "Client linkdead: %s", name);
if (GetGM()) {
if (GetMerc())
{
GetMerc()->Save();
GetMerc()->Depop();
}
return false;
}
else if(!linkdead_timer.Enabled()){
linkdead_timer.Start(RuleI(Zone,ClientLinkdeadMS));
client_state = CLIENT_LINKDEAD;
AI_Start(CLIENT_LD_TIMEOUT);
SendAppearancePacket(AT_Linkdead, 1);
}
}
/************ Get all packets from packet manager out queue and process them ************/
EQApplicationPacket *app = nullptr;
if(!eqs->CheckState(CLOSING))
{
while(ret && (app = (EQApplicationPacket *)eqs->PopPacket())) {
if(app)
ret = HandlePacket(app);
safe_delete(app);
}
}
#ifdef REVERSE_AGGRO
//At this point, we are still connected, everything important has taken
//place, now check to see if anybody wants to aggro us.
// only if client is not feigned
if(ret && !GetFeigned() && scanarea_timer.Check()) {
entity_list.CheckClientAggro(this);
}
#endif
if (client_state != CLIENT_LINKDEAD && (client_state == CLIENT_ERROR || client_state == DISCONNECTED || client_state == CLIENT_KICKED || !eqs->CheckState(ESTABLISHED)))
{
//client logged out or errored out
//ResetTrade();
if (client_state != CLIENT_KICKED) {
Save();
}
client_state = CLIENT_LINKDEAD;
if (zoning || instalog || GetGM())
{
Group *mygroup = GetGroup();
if (mygroup)
{
if (!zoning)
{
entity_list.MessageGroup(this, true, 15, "%s logged out.", GetName());
LeaveGroup();
}
else
{
entity_list.MessageGroup(this, true, 15, "%s left the zone.", GetName());
mygroup->MemberZoned(this);
if (GetMerc() && GetMerc()->HasGroup())
{
GetMerc()->RemoveMercFromGroup(GetMerc(), GetMerc()->GetGroup());
}
}
}
Raid *myraid = entity_list.GetRaidByClient(this);
if (myraid)
{
if (!zoning)
{
//entity_list.MessageGroup(this,true,15,"%s logged out.",GetName());
myraid->MemberZoned(this);
}
else
{
//entity_list.MessageGroup(this,true,15,"%s left the zone.",GetName());
myraid->MemberZoned(this);
}
}
OnDisconnect(false);
return false;
}
else
{
LinkDead();
}
OnDisconnect(true);
}
// Feign Death 2 minutes and zone forgets you
if (forget_timer.Check()) {
forget_timer.Disable();
entity_list.ClearZoneFeignAggro(this);
Message(0, "Your enemies have forgotten you!");
}
return ret;
}
/* Just a set of actions preformed all over in Client::Process */
void Client::OnDisconnect(bool hard_disconnect) {
if(hard_disconnect)
{
LeaveGroup();
if (GetMerc())
{
GetMerc()->Save();
GetMerc()->Depop();
}
Raid *MyRaid = entity_list.GetRaidByClient(this);
if (MyRaid)
MyRaid->MemberZoned(this);
parse->EventPlayer(EVENT_DISCONNECT, this, "", 0);
/* QS: PlayerLogConnectDisconnect */
if (RuleB(QueryServ, PlayerLogConnectDisconnect)){
std::string event_desc = StringFormat("Disconnect :: in zoneid:%i instid:%i", this->GetZoneID(), this->GetInstanceID());
QServ->PlayerLogEvent(Player_Log_Connect_State, this->CharacterID(), event_desc);
}
}
Mob *Other = trade->With();
if(Other)
{
Log.Out(Logs::Detail, Logs::Trading, "Client disconnected during a trade. Returning their items.");
FinishTrade(this);
if(Other->IsClient())
Other->CastToClient()->FinishTrade(Other);
/* Reset both sides of the trade */
trade->Reset();
Other->trade->Reset();
}
database.SetFirstLogon(CharacterID(), 0); //We change firstlogon status regardless of if a player logs out to zone or not, because we only want to trigger it on their first login from world.
/* Remove ourself from all proximities */
ClearAllProximities();
EQApplicationPacket *outapp = new EQApplicationPacket(OP_LogoutReply);
FastQueuePacket(&outapp);
Disconnect();
}
// Sends the client complete inventory used in character login
// DO WE STILL NEED THE 'ITEMCOMBINED' CONDITIONAL CODE?
//#ifdef ITEMCOMBINED
void Client::BulkSendInventoryItems() {
int16 slot_id = 0;
// LINKDEAD TRADE ITEMS
// Move trade slot items back into normal inventory..need them there now for the proceeding validity checks
for(slot_id = EmuConstants::TRADE_BEGIN; slot_id <= EmuConstants::TRADE_END; slot_id++) {
ItemInst* inst = m_inv.PopItem(slot_id);
if(inst) {
bool is_arrow = (inst->GetItem()->ItemType == ItemTypeArrow) ? true : false;
int16 free_slot_id = m_inv.FindFreeSlot(inst->IsType(ItemClassContainer), true, inst->GetItem()->Size, is_arrow);
Log.Out(Logs::Detail, Logs::Inventory, "Incomplete Trade Transaction: Moving %s from slot %i to %i", inst->GetItem()->Name, slot_id, free_slot_id);
PutItemInInventory(free_slot_id, *inst, false);
database.SaveInventory(character_id, nullptr, slot_id);
safe_delete(inst);
}
}
bool deletenorent = database.NoRentExpired(GetName());
if (deletenorent) { //client was offline for more than 30 minutes, delete no rent items
if (RuleB(Inventory, TransformSummonedBags))
DisenchantSummonedBags(false);
RemoveNoRent(false);
}
RemoveDuplicateLore(false);
MoveSlotNotAllowed(false);
// The previous three method calls took care of moving/removing expired/illegal item placements
//TODO: this function is just retarded... it re-allocates the buffer for every
//new item. It should be changed to loop through once, gather the
//lengths, and item packet pointers into an array (fixed length), and
//then loop again to build the packet.
//EQApplicationPacket *packets[50];
//unsigned long buflen = 0;
//unsigned long pos = 0;
//memset(packets, 0, sizeof(packets));
//foreach item in the invendor sections
// packets[pos++] = ReturnItemPacket(...)
// buflen += temp->size
//...
//allocat the buffer
//for r from 0 to pos
// put pos[r]->pBuffer into the buffer
//for r from 0 to pos
// safe_delete(pos[r]);
uint32 size = 0;
uint16 i = 0;
std::map<uint16, std::string> ser_items;
std::map<uint16, std::string>::iterator itr;
//Inventory items
for(slot_id = MAIN_BEGIN; slot_id < EmuConstants::MAP_POSSESSIONS_SIZE; slot_id++) {
const ItemInst* inst = m_inv[slot_id];
if(inst) {
std::string packet = inst->Serialize(slot_id);
ser_items[i++] = packet;
size += packet.length();
}
}
// Power Source
if(GetClientVersion() >= ClientVersion::SoF) {
const ItemInst* inst = m_inv[MainPowerSource];
if(inst) {
std::string packet = inst->Serialize(MainPowerSource);
ser_items[i++] = packet;
size += packet.length();
}
}
// Bank items
for(slot_id = EmuConstants::BANK_BEGIN; slot_id <= EmuConstants::BANK_END; slot_id++) {
const ItemInst* inst = m_inv[slot_id];
if(inst) {
std::string packet = inst->Serialize(slot_id);
ser_items[i++] = packet;
size += packet.length();
}
}
// Shared Bank items
for(slot_id = EmuConstants::SHARED_BANK_BEGIN; slot_id <= EmuConstants::SHARED_BANK_END; slot_id++) {
const ItemInst* inst = m_inv[slot_id];
if(inst) {
std::string packet = inst->Serialize(slot_id);
ser_items[i++] = packet;
size += packet.length();
}
}
EQApplicationPacket* outapp = new EQApplicationPacket(OP_CharInventory, size);
uchar* ptr = outapp->pBuffer;
for(itr = ser_items.begin(); itr != ser_items.end(); ++itr){
int length = itr->second.length();
if(length > 5) {
memcpy(ptr, itr->second.c_str(), length);
ptr += length;
}
}
QueuePacket(outapp);
safe_delete(outapp);
}
/*#else
void Client::BulkSendInventoryItems()
{
// Search all inventory buckets for items
bool deletenorent=database.NoRentExpired(GetName());
// Worn items and Inventory items
int16 slot_id = 0;
if(deletenorent){//client was offline for more than 30 minutes, delete no rent items
RemoveNoRent();
}
for (slot_id=EmuConstants::POSSESSIONS_BEGIN; slot_id<=EmuConstants::POSSESSIONS_END; slot_id++) {
const ItemInst* inst = m_inv[slot_id];
if (inst){
SendItemPacket(slot_id, inst, ItemPacketCharInventory);
}
}
// Bank items
for (slot_id=EmuConstants::BANK_BEGIN; slot_id<=EmuConstants::BANK_END; slot_id++) { // 2015...
const ItemInst* inst = m_inv[slot_id];
if (inst){
SendItemPacket(slot_id, inst, ItemPacketCharInventory);
}
}
// Shared Bank items
for (slot_id=EmuConstants::SHARED_BANK_BEGIN; slot_id<=EmuConstants::SHARED_BANK_END; slot_id++) {
const ItemInst* inst = m_inv[slot_id];
if (inst){
SendItemPacket(slot_id, inst, ItemPacketCharInventory);
}
}
// LINKDEAD TRADE ITEMS
// If player went LD during a trade, they have items in the trade inventory
// slots. These items are now being put into their inventory (then queue up on cursor)
for (int16 trade_slot_id=EmuConstants::TRADE_BEGIN; trade_slot_id<=EmuConstants::TRADE_END; trade_slot_id++) {
const ItemInst* inst = m_inv[slot_id];
if (inst) {
int16 free_slot_id = m_inv.FindFreeSlot(inst->IsType(ItemClassContainer), true, inst->GetItem()->Size);
DeleteItemInInventory(trade_slot_id, 0, false);
PutItemInInventory(free_slot_id, *inst, true);
}
}
}
#endif*/
void Client::BulkSendMerchantInventory(int merchant_id, int npcid) {
const Item_Struct* handyitem = nullptr;
uint32 numItemSlots = 80; //The max number of items passed in the transaction.
if (m_ClientVersionBit & BIT_RoFAndLater) { // RoF+ can send 200 items
numItemSlots = 200;
}
const Item_Struct *item;
std::list<MerchantList> merlist = zone->merchanttable[merchant_id];
std::list<MerchantList>::const_iterator itr;
Mob* merch = entity_list.GetMobByNpcTypeID(npcid);
if (merlist.size() == 0) { //Attempt to load the data, it might have been missed if someone spawned the merchant after the zone was loaded
zone->LoadNewMerchantData(merchant_id);
merlist = zone->merchanttable[merchant_id];
if (merlist.size() == 0)
return;
}
std::list<TempMerchantList> tmp_merlist = zone->tmpmerchanttable[npcid];
std::list<TempMerchantList>::iterator tmp_itr;
uint32 i = 1;
uint8 handychance = 0;
for (itr = merlist.begin(); itr != merlist.end() && i <= numItemSlots; ++itr) {
MerchantList ml = *itr;
if (merch->CastToNPC()->GetMerchantProbability() > ml.probability)
continue;
if (GetLevel() < ml.level_required)
continue;