/
clientlist.cpp
1669 lines (1473 loc) · 50.7 KB
/
clientlist.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-2016 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
*/
#include "../common/global_define.h"
#include "clientlist.h"
#include "zoneserver.h"
#include "zonelist.h"
#include "client.h"
#include "worlddb.h"
#include "../common/strings.h"
#include "../common/guilds.h"
#include "../common/races.h"
#include "../common/classes.h"
#include "../common/packet_dump.h"
#include "../common/misc.h"
#include "../common/misc_functions.h"
#include "../common/json/json.h"
#include "../common/event_sub.h"
#include "web_interface.h"
#include "wguild_mgr.h"
#include "../common/zone_store.h"
#include <set>
extern WebInterfaceList web_interface;
extern ZSList zoneserver_list;
uint32 numplayers = 0; //this really wants to be a member variable of ClientList...
ClientList::ClientList()
: CLStale_timer(10000)
{
NextCLEID = 1;
m_tick = std::make_unique<EQ::Timer>(5000, true, std::bind(&ClientList::OnTick, this, std::placeholders::_1));
}
ClientList::~ClientList() {
}
void ClientList::Process() {
if (CLStale_timer.Check())
CLCheckStale();
LinkedListIterator<Client*> iterator(list);
iterator.Reset();
while(iterator.MoreElements()) {
if (!iterator.GetData()->Process()) {
struct in_addr in;
in.s_addr = iterator.GetData()->GetIP();
LogInfo("Removing client from [{}]:[{}]", inet_ntoa(in), iterator.GetData()->GetPort());
iterator.RemoveCurrent();
}
else
iterator.Advance();
}
}
void ClientList::CLERemoveZSRef(ZoneServer* iZS) {
LinkedListIterator<ClientListEntry*> iterator(clientlist);
iterator.Reset();
while(iterator.MoreElements()) {
if (iterator.GetData()->Server() == iZS) {
iterator.GetData()->ClearServer(); // calling this before LeavingZone() makes CLE not update the number of players in a zone
iterator.GetData()->LeavingZone();
}
iterator.Advance();
}
}
//Check current CLE Entry IPs against incoming connection
void ClientList::GetCLEIP(uint32 in_ip) {
ClientListEntry* cle = nullptr;
LinkedListIterator<ClientListEntry*> iterator(clientlist);
int count = 0;
iterator.Reset();
while (iterator.MoreElements()) {
cle = iterator.GetData();
if (
cle->GetIP() == in_ip &&
(
cle->Admin() < RuleI(World, ExemptMaxClientsStatus) ||
RuleI(World, ExemptMaxClientsStatus) < 0
)
) { // If the IP matches, and the connection admin status is below the exempt status, or exempt status is less than 0 (no-one is exempt)
auto ip_string = long2ip(cle->GetIP());
count++; // Increment the occurences of this IP address
LogClientLogin("Account ID: [{}] Account Name: [{}] IP: [{}]", cle->LSID(), cle->LSName(), ip_string);
if (RuleB(World, EnableIPExemptions)) {
LogClientLogin(
"Account ID: [{}] Account Name: [{}] IP: [{}] IP Instances: [{}] Max IP Instances: [{}]",
cle->LSID(),
cle->LSName(),
ip_string,
count,
database.GetIPExemption(ip_string)
);
auto exemption_amount = database.GetIPExemption(ip_string);
if (exemption_amount > 0 && count > exemption_amount) {
if (RuleB(World, IPLimitDisconnectAll)) {
LogClientLogin("Disconnect: All Accounts on IP [{}]", ip_string);
DisconnectByIP(in_ip);
return;
} else {
LogClientLogin("Disconnect: Account [{}] on IP [{}]", cle->LSName(), ip_string);
cle->SetOnline(CLE_Status::Offline);
iterator.RemoveCurrent();
continue;
}
}
} else {
if (
RuleI(World, MaxClientsPerIP) > 0 &&
count > RuleI(World, MaxClientsPerIP)
) { // If the number of connections exceeds the lower limit
if (RuleB(World, MaxClientsSetByStatus)) { // If MaxClientsSetByStatus is set to True, override other IP Limit Rules
LogClientLogin(
"Account ID: [{}] Account Name: [{}] IP: [{}] IP Instances: [{}] Max IP Instances: [{}]",
cle->LSID(),
cle->LSName(),
ip_string,
count,
cle->Admin()
);
if (count > cle->Admin()) { // The IP Limit is set by the status of the account if status > MaxClientsPerIP
if (RuleB(World, IPLimitDisconnectAll)) {
LogClientLogin("Disconnect: All Accounts on IP [{}]", ip_string);
DisconnectByIP(in_ip);
return;
} else {
LogClientLogin("Disconnect: Account [{}] on IP [{}]", cle->LSName(), ip_string);
cle->SetOnline(CLE_Status::Offline); // Remove the connection
iterator.RemoveCurrent();
continue;
}
}
} else if (
cle->Admin() < RuleI(World, AddMaxClientsStatus) ||
RuleI(World, AddMaxClientsStatus) < 0
) { // Else if the Admin status of the connection is not eligible for the higher limit, or there is no higher limit (AddMaxClientStatus < 0)
if (RuleB(World, IPLimitDisconnectAll)) {
LogClientLogin("Disconnect: All Accounts on IP [{}]", ip_string);
DisconnectByIP(in_ip);
return;
} else {
LogClientLogin("Disconnect: Account [{}] on IP [{}]", cle->LSName(), ip_string);
cle->SetOnline(CLE_Status::Offline); // Remove the connection
iterator.RemoveCurrent();
continue;
}
} else if (
RuleI(World, AddMaxClientsPerIP) > 0 &&
count > RuleI(World, AddMaxClientsPerIP)
) { // else they are eligible for the higher limit, but if they exceed that
if (RuleB(World, IPLimitDisconnectAll)) {
LogClientLogin("Disconnect: All Accounts on IP [{}]", ip_string);
DisconnectByIP(in_ip);
return;
} else {
LogClientLogin("Disconnect: Account [{}] on IP [{}]", cle->LSName(), ip_string);
cle->SetOnline(CLE_Status::Offline); // Remove the connection
iterator.RemoveCurrent();
continue;
}
}
}
}
}
iterator.Advance();
}
}
void ClientList::DisconnectByIP(uint32 in_ip) {
ClientListEntry* cle = nullptr;
LinkedListIterator<ClientListEntry*> iterator(clientlist);
iterator.Reset();
while (iterator.MoreElements()) {
cle = iterator.GetData();
if (cle->GetIP() == in_ip) {
if (strlen(cle->name())) {
auto pack = new ServerPacket(ServerOP_KickPlayer, sizeof(ServerKickPlayer_Struct));
auto skp = (ServerKickPlayer_Struct*) pack->pBuffer;
strn0cpy(skp->adminname, "SessionLimit", sizeof(skp->adminname));
strn0cpy(skp->name, cle->name(), sizeof(skp->name));
skp->adminrank = 255;
zoneserver_list.SendPacket(pack);
safe_delete(pack);
}
cle->SetOnline(CLE_Status::Offline);
iterator.RemoveCurrent();
}
iterator.Advance();
}
}
ClientListEntry* ClientList::FindCharacter(const char* name) {
LinkedListIterator<ClientListEntry*> iterator(clientlist);
iterator.Reset();
while(iterator.MoreElements())
{
if (strcasecmp(iterator.GetData()->name(), name) == 0) {
return iterator.GetData();
}
iterator.Advance();
}
return nullptr;
}
ClientListEntry* ClientList::FindCLEByAccountID(uint32 iAccID) {
LinkedListIterator<ClientListEntry*> iterator(clientlist);
iterator.Reset();
while(iterator.MoreElements()) {
if (iterator.GetData()->AccountID() == iAccID) {
return iterator.GetData();
}
iterator.Advance();
}
return nullptr;
}
ClientListEntry* ClientList::FindCLEByCharacterID(uint32 iCharID) {
LinkedListIterator<ClientListEntry*> iterator(clientlist);
iterator.Reset();
while(iterator.MoreElements()) {
if (iterator.GetData()->CharID() == iCharID) {
return iterator.GetData();
}
iterator.Advance();
}
return nullptr;
}
void ClientList::SendCLEList(const int16& admin, const char* to, WorldTCPConnection* connection, const char* iName) {
LinkedListIterator<ClientListEntry*> iterator(clientlist);
int x = 0, y = 0;
int namestrlen = iName == 0 ? 0 : strlen(iName);
bool addnewline = false;
char newline[3];
if (connection->IsConsole())
strcpy(newline, "\r\n");
else
strcpy(newline, "^");
std::vector<char> out;
iterator.Reset();
while(iterator.MoreElements()) {
ClientListEntry* cle = iterator.GetData();
if (admin >= cle->Admin() && (iName == 0 || namestrlen == 0 || strncasecmp(cle->name(), iName, namestrlen) == 0 || strncasecmp(cle->AccountName(), iName, namestrlen) == 0 || strncasecmp(cle->LSName(), iName, namestrlen) == 0)) {
struct in_addr in;
in.s_addr = cle->GetIP();
if (addnewline) {
fmt::format_to(std::back_inserter(out), fmt::runtime(newline));
}
fmt::format_to(std::back_inserter(out), "ID: {} Acc# {} AccName: {} IP: {}", cle->GetID(), cle->AccountID(), cle->AccountName(), inet_ntoa(in));
fmt::format_to(std::back_inserter(out), "{} Stale: {} Online: {} Admin: {}", newline, cle->GetStaleCounter(), cle->Online(), cle->Admin());
if (cle->LSID())
fmt::format_to(std::back_inserter(out), "{} LSID: {} LSName: {} WorldAdmin: {}", newline, cle->LSID(), cle->LSName(), cle->WorldAdmin());
if (cle->CharID())
fmt::format_to(std::back_inserter(out), "{} CharID: {} CharName: {} Zone: {} ({})", newline, cle->CharID(), cle->name(), ZoneName(cle->zone()), cle->zone());
if (out.size() >= 3072) {
connection->SendEmoteMessageRaw(
to,
0,
AccountStatus::Player,
Chat::NPCQuestSay,
out.data()
);
addnewline = false;
out.clear();
} else {
addnewline = true;
}
y++;
}
iterator.Advance();
x++;
}
fmt::format_to(std::back_inserter(out), "{}{} CLEs in memory. {} CLEs listed. numplayers = {}.", newline, x, y, numplayers);
connection->SendEmoteMessageRaw(
to,
0,
AccountStatus::Player,
Chat::NPCQuestSay,
out.data()
);
}
void ClientList::CLEAdd(uint32 iLSID, const char *iLoginServerName, const char* iLoginName, const char* iLoginKey, int16 iWorldAdmin, uint32 ip, uint8 local) {
auto tmp = new ClientListEntry(GetNextCLEID(), iLSID, iLoginServerName, iLoginName, iLoginKey, iWorldAdmin, ip, local);
clientlist.Append(tmp);
}
void ClientList::CLCheckStale() {
LinkedListIterator<ClientListEntry*> iterator(clientlist);
iterator.Reset();
while(iterator.MoreElements()) {
if (iterator.GetData()->CheckStale()) {
iterator.RemoveCurrent();
}
else
iterator.Advance();
}
}
void ClientList::ClientUpdate(ZoneServer *zoneserver, ServerClientList_Struct *scl)
{
LinkedListIterator<ClientListEntry *> iterator(clientlist);
ClientListEntry *cle;
iterator.Reset();
while (iterator.MoreElements()) {
if (iterator.GetData()->GetID() == scl->wid) {
cle = iterator.GetData();
if (scl->remove == 2) {
cle->LeavingZone(zoneserver, CLE_Status::Offline);
}
else if (scl->remove == 1) {
cle->LeavingZone(zoneserver, CLE_Status::Zoning);
}
else {
cle->Update(zoneserver, scl);
}
return;
}
iterator.Advance();
}
if (scl->remove == 2) {
cle = new ClientListEntry(GetNextCLEID(), zoneserver, scl, CLE_Status::Online);
}
else if (scl->remove == 1) {
cle = new ClientListEntry(GetNextCLEID(), zoneserver, scl, CLE_Status::Zoning);
}
else {
cle = new ClientListEntry(GetNextCLEID(), zoneserver, scl, CLE_Status::InZone);
}
LogClientListDetail(
"[ClientUpdate] "
" remove [{}]"
" wid [{}]"
" IP [{}]"
" zone [{}]"
" instance_id [{}]"
" Admin [{}]"
" charid [{}]"
" name [{}]"
" AccountID [{}]"
" AccountName [{}]"
" LSAccountID [{}]"
" lskey [{}]"
" race [{}]"
" class_ [{}]"
" level [{}]"
" anon [{}]"
" tellsoff [{}]"
" guild_id [{}]"
" LFG [{}]"
" gm [{}]"
" ClientVersion [{}]"
" LFGFromLevel [{}]"
" LFGToLevel [{}]"
" LFGMatchFilter [{}]"
" LFGComments [{}]",
scl->remove,
scl->wid,
scl->IP,
scl->zone,
scl->instance_id,
scl->Admin,
scl->charid,
scl->name,
scl->AccountID,
scl->AccountName,
scl->LSAccountID,
scl->lskey,
scl->race,
scl->class_,
scl->level,
scl->anon,
scl->tellsoff,
scl->guild_id,
scl->LFG,
scl->gm,
scl->ClientVersion,
scl->LFGFromLevel,
scl->LFGToLevel,
scl->LFGMatchFilter,
scl->LFGComments
);
clientlist.Insert(cle);
zoneserver->ChangeWID(scl->charid, cle->GetID());
}
void ClientList::CLEKeepAlive(uint32 numupdates, uint32* wid) {
LinkedListIterator<ClientListEntry*> iterator(clientlist);
uint32 i;
iterator.Reset();
while(iterator.MoreElements()) {
for (i=0; i<numupdates; i++) {
if (wid[i] == iterator.GetData()->GetID())
iterator.GetData()->KeepAlive();
}
iterator.Advance();
}
}
ClientListEntry *ClientList::CheckAuth(uint32 iLSID, const char *iKey)
{
LinkedListIterator<ClientListEntry *> iterator(clientlist);
iterator.Reset();
while (iterator.MoreElements()) {
if (iterator.GetData()->CheckAuth(iLSID, iKey)) {
return iterator.GetData();
}
iterator.Advance();
}
return 0;
}
void ClientList::SendOnlineGuildMembers(uint32 FromID, uint32 GuildID)
{
int PacketLength = 8;
uint32 Count = 0;
ClientListEntry* from = FindCLEByCharacterID(FromID);
if(!from)
{
LogInfo("Invalid client. FromID=[{}] GuildID=[{}]", FromID, GuildID);
return;
}
LinkedListIterator<ClientListEntry*> Iterator(clientlist);
Iterator.Reset();
while(Iterator.MoreElements())
{
ClientListEntry* CLE = Iterator.GetData();
if(CLE && (CLE->GuildID() == GuildID))
{
PacketLength += (strlen(CLE->name()) + 5);
++Count;
}
Iterator.Advance();
}
Iterator.Reset();
auto pack = new ServerPacket(ServerOP_OnlineGuildMembersResponse, PacketLength);
char *Buffer = (char *)pack->pBuffer;
VARSTRUCT_ENCODE_TYPE(uint32, Buffer, FromID);
VARSTRUCT_ENCODE_TYPE(uint32, Buffer, Count);
while(Iterator.MoreElements())
{
ClientListEntry* CLE = Iterator.GetData();
if(CLE && (CLE->GuildID() == GuildID))
{
VARSTRUCT_ENCODE_STRING(Buffer, CLE->name());
VARSTRUCT_ENCODE_TYPE(uint32, Buffer, CLE->zone());
}
Iterator.Advance();
}
zoneserver_list.SendPacket(from->zone(), from->instance(), pack);
safe_delete(pack);
}
void ClientList::SendWhoAll(uint32 fromid,const char* to, int16 admin, Who_All_Struct* whom, WorldTCPConnection* connection) {
try{
LinkedListIterator<ClientListEntry*> iterator(clientlist);
LinkedListIterator<ClientListEntry*> countclients(clientlist);
ClientListEntry* cle = 0;
ClientListEntry* countcle = 0;
//char tmpgm[25] = "";
//char accinfo[150] = "";
char line[300] = "";
//char tmpguild[50] = "";
//char LFG[10] = "";
//uint32 x = 0;
int whomlen = 0;
if (whom) {
// fixes for client converting some queries into a race query instead of zone
if (whom->wrace == 221) {
whom->wrace = 0xFFFF;
strcpy(whom->whom, "scarlet");
}
if (whom->wrace == 327) {
whom->wrace = 0xFFFF;
strcpy(whom->whom, "crystal");
}
if (whom->wrace == 103) {
whom->wrace = 0xFFFF;
strcpy(whom->whom, "kedge");
}
if (whom->wrace == 230) {
whom->wrace = 0xFFFF;
strcpy(whom->whom, "akheva");
}
if (whom->wrace == 229) {
whom->wrace = 0xFFFF;
strcpy(whom->whom, "netherbian");
}
whomlen = strlen(whom->whom);
if(whom->wrace == 0x001A) // 0x001A is the old Froglok race number and is sent by the client for /who all froglok
whom->wrace = FROGLOK; // This is what EQEmu uses for the Froglok Race number.
}
uint32 totalusers=0;
uint32 totallength=0;
countclients.Reset();
while(countclients.MoreElements()){
countcle = countclients.GetData();
const char* tmpZone = ZoneName(countcle->zone());
if (
(countcle->Online() >= CLE_Status::Zoning) &&
(!countcle->GetGM() || countcle->Anon() != 1 || admin >= countcle->Admin()) &&
(whom == 0 || (
((countcle->Admin() >= AccountStatus::QuestTroupe && countcle->GetGM()) || whom->gmlookup == 0xFFFF) &&
(whom->lvllow == 0xFFFF || (countcle->level() >= whom->lvllow && countcle->level() <= whom->lvlhigh && (countcle->Anon()==0 || admin > countcle->Admin()))) &&
(whom->wclass == 0xFFFF || (countcle->class_() == whom->wclass && (countcle->Anon()==0 || admin > countcle->Admin()))) &&
(whom->wrace == 0xFFFF || (countcle->race() == whom->wrace && (countcle->Anon()==0 || admin > countcle->Admin()))) &&
(whomlen == 0 || (
(tmpZone != 0 && strncasecmp(tmpZone, whom->whom, whomlen) == 0) ||
strncasecmp(countcle->name(),whom->whom, whomlen) == 0 ||
(strncasecmp(guild_mgr.GetGuildName(countcle->GuildID()), whom->whom, whomlen) == 0) ||
(admin >= AccountStatus::GMAdmin && strncasecmp(countcle->AccountName(), whom->whom, whomlen) == 0)
))
))
) {
if((countcle->Anon()>0 && admin >= countcle->Admin() && admin > AccountStatus::Player) || countcle->Anon()==0 ){
totalusers++;
if(totalusers<=20 || admin >= AccountStatus::GMAdmin)
totallength=totallength+strlen(countcle->name())+strlen(countcle->AccountName())+strlen(guild_mgr.GetGuildName(countcle->GuildID()))+5;
}
else if((countcle->Anon()>0 && admin<=countcle->Admin()) || (countcle->Anon()==0 && !countcle->GetGM())) {
totalusers++;
if(totalusers<=20 || admin >= AccountStatus::GMAdmin)
totallength=totallength+strlen(countcle->name())+strlen(guild_mgr.GetGuildName(countcle->GuildID()))+5;
}
}
countclients.Advance();
}
uint32 plid=fromid;
uint32 playerineqstring=5001;
const char line2[]="---------------------------";
uint8 unknown35=0x0A;
uint32 unknown36=0;
uint32 playersinzonestring=5028;
if(totalusers>20 && admin<AccountStatus::GMAdmin){
totalusers=20;
playersinzonestring=5033;
}
else if(totalusers>1)
playersinzonestring=5036;
uint32 unknown44[2];
unknown44[0]=0;
unknown44[1]=0;
uint32 unknown52=totalusers;
uint32 unknown56=1;
auto pack2 = new ServerPacket(ServerOP_WhoAllReply, 64 + totallength + (49 * totalusers));
memset(pack2->pBuffer,0,pack2->size);
uchar *buffer=pack2->pBuffer;
uchar *bufptr=buffer;
//memset(buffer,0,pack2->size);
memcpy(bufptr,&plid, sizeof(uint32));
bufptr+=sizeof(uint32);
memcpy(bufptr,&playerineqstring, sizeof(uint32));
bufptr+=sizeof(uint32);
memcpy(bufptr,&line2, strlen(line2));
bufptr+=strlen(line2);
memcpy(bufptr,&unknown35, sizeof(uint8));
bufptr+=sizeof(uint8);
memcpy(bufptr,&unknown36, sizeof(uint32));
bufptr+=sizeof(uint32);
memcpy(bufptr,&playersinzonestring, sizeof(uint32));
bufptr+=sizeof(uint32);
memcpy(bufptr,&unknown44[0], sizeof(uint32));
bufptr+=sizeof(uint32);
memcpy(bufptr,&unknown44[1], sizeof(uint32));
bufptr+=sizeof(uint32);
memcpy(bufptr,&unknown52, sizeof(uint32));
bufptr+=sizeof(uint32);
memcpy(bufptr,&unknown56, sizeof(uint32));
bufptr+=sizeof(uint32);
memcpy(bufptr,&totalusers, sizeof(uint32));
bufptr+=sizeof(uint32);
iterator.Reset();
int idx=-1;
while(iterator.MoreElements()) {
cle = iterator.GetData();
const char* tmpZone = ZoneName(cle->zone());
if (
(cle->Online() >= CLE_Status::Zoning) &&
(!cle->GetGM() || cle->Anon() != 1 || admin >= cle->Admin()) &&
(whom == 0 || (
((cle->Admin() >= AccountStatus::QuestTroupe && cle->GetGM()) || whom->gmlookup == 0xFFFF) &&
(whom->lvllow == 0xFFFF || (cle->level() >= whom->lvllow && cle->level() <= whom->lvlhigh && (cle->Anon()==0 || admin>cle->Admin()))) &&
(whom->wclass == 0xFFFF || (cle->class_() == whom->wclass && (cle->Anon()==0 || admin>cle->Admin()))) &&
(whom->wrace == 0xFFFF || (cle->race() == whom->wrace && (cle->Anon()==0 || admin>cle->Admin()))) &&
(whomlen == 0 || (
(tmpZone != 0 && strncasecmp(tmpZone, whom->whom, whomlen) == 0) ||
strncasecmp(cle->name(),whom->whom, whomlen) == 0 ||
(strncasecmp(guild_mgr.GetGuildName(cle->GuildID()), whom->whom, whomlen) == 0) ||
(admin >= AccountStatus::GMAdmin && strncasecmp(cle->AccountName(), whom->whom, whomlen) == 0)
))
))
) {
line[0] = 0;
uint32 rankstring = 0xFFFFFFFF;
if((cle->Anon()==1 && cle->GetGM() && cle->Admin()>admin) || (idx>=20 && admin < AccountStatus::GMAdmin)){ //hide gms that are anon from lesser gms and normal players, cut off at 20
rankstring = 0;
iterator.Advance();
continue;
} else if (cle->GetGM()) {
if (cle->Admin() >= AccountStatus::GMImpossible)
rankstring = 5021;
else if (cle->Admin() >= AccountStatus::GMMgmt)
rankstring = 5020;
else if (cle->Admin() >= AccountStatus::GMCoder)
rankstring = 5019;
else if (cle->Admin() >= AccountStatus::GMAreas)
rankstring = 5018;
else if (cle->Admin() >= AccountStatus::QuestMaster)
rankstring = 5017;
else if (cle->Admin() >= AccountStatus::GMLeadAdmin)
rankstring = 5016;
else if (cle->Admin() >= AccountStatus::GMAdmin)
rankstring = 5015;
else if (cle->Admin() >= AccountStatus::GMStaff)
rankstring = 5014;
else if (cle->Admin() >= AccountStatus::EQSupport)
rankstring = 5013;
else if (cle->Admin() >= AccountStatus::GMTester)
rankstring = 5012;
else if (cle->Admin() >= AccountStatus::SeniorGuide)
rankstring = 5011;
else if (cle->Admin() >= AccountStatus::QuestTroupe)
rankstring = 5010;
else if (cle->Admin() >= AccountStatus::Guide)
rankstring = 5009;
else if (cle->Admin() >= AccountStatus::ApprenticeGuide)
rankstring = 5008;
else if (cle->Admin() >= AccountStatus::Steward)
rankstring = 5007;
}
idx++;
char guildbuffer[67]={0};
if (cle->GuildID() != GUILD_NONE && cle->GuildID()>0)
sprintf(guildbuffer,"<%s>", guild_mgr.GetGuildName(cle->GuildID()));
uint32 formatstring=5025;
if(cle->Anon()==1 && (admin<cle->Admin() || admin == AccountStatus::Player))
formatstring=5024;
else if(cle->Anon()==1 && admin>=cle->Admin() && admin > AccountStatus::Player)
formatstring=5022;
else if(cle->Anon()==2 && (admin<cle->Admin() || admin == AccountStatus::Player))
formatstring=5023;//display guild
else if(cle->Anon()==2 && admin>=cle->Admin() && admin > AccountStatus::Player)
formatstring=5022;//display everything
//war* wars2 = (war*)pack2->pBuffer;
uint32 plclass_=0;
uint32 pllevel=0;
uint32 pidstring=0xFFFFFFFF;//5003;
uint32 plrace=0;
uint32 zonestring=0xFFFFFFFF;
uint32 plzone=0;
uint32 unknown80[2];
if(cle->Anon()==0 || (admin>=cle->Admin() && admin> AccountStatus::Player)){
plclass_=cle->class_();
pllevel=cle->level();
if(admin>=AccountStatus::GMAdmin)
pidstring=5003;
plrace=cle->race();
zonestring=5006;
plzone=cle->zone();
}
if(admin>=cle->Admin() && admin > AccountStatus::Player)
unknown80[0]=cle->Admin();
else
unknown80[0]=0xFFFFFFFF;
unknown80[1]=0xFFFFFFFF;//1035
//char plstatus[20]={0};
//sprintf(plstatus, "Status %i",cle->Admin());
char plname[64]={0};
strcpy(plname,cle->name());
char placcount[30]={0};
if(admin>=cle->Admin() && admin > AccountStatus::Player)
strcpy(placcount,cle->AccountName());
memcpy(bufptr,&formatstring, sizeof(uint32));
bufptr+=sizeof(uint32);
memcpy(bufptr,&pidstring, sizeof(uint32));
bufptr+=sizeof(uint32);
memcpy(bufptr,&plname, strlen(plname)+1);
bufptr+=strlen(plname)+1;
memcpy(bufptr,&rankstring, sizeof(uint32));
bufptr+=sizeof(uint32);
memcpy(bufptr,&guildbuffer, strlen(guildbuffer)+1);
bufptr+=strlen(guildbuffer)+1;
memcpy(bufptr,&unknown80[0], sizeof(uint32));
bufptr+=sizeof(uint32);
memcpy(bufptr,&unknown80[1], sizeof(uint32));
bufptr+=sizeof(uint32);
memcpy(bufptr,&zonestring, sizeof(uint32));
bufptr+=sizeof(uint32);
memcpy(bufptr,&plzone, sizeof(uint32));
bufptr+=sizeof(uint32);
memcpy(bufptr,&plclass_, sizeof(uint32));
bufptr+=sizeof(uint32);
memcpy(bufptr,&pllevel, sizeof(uint32));
bufptr+=sizeof(uint32);
memcpy(bufptr,&plrace, sizeof(uint32));
bufptr+=sizeof(uint32);
uint32 ending=0;
memcpy(bufptr,&placcount, strlen(placcount)+1);
bufptr+=strlen(placcount)+1;
ending=207;
memcpy(bufptr,&ending, sizeof(uint32));
bufptr+=sizeof(uint32);
}
iterator.Advance();
}
//zoneserver_list.SendPacket(pack2); // NO NO NO WHY WOULD YOU SEND IT TO EVERY ZONE SERVER?!?
SendPacket(to,pack2);
safe_delete(pack2);
}
catch(...){
LogInfo("Unknown error in world's SendWhoAll (probably mem error), ignoring");
return;
}
}
void ClientList::SendFriendsWho(ServerFriendsWho_Struct *FriendsWho, WorldTCPConnection* connection) {
std::vector<ClientListEntry*> FriendsCLEs;
FriendsCLEs.reserve(100);
char Friend_[65];
char *FriendsPointer = FriendsWho->FriendsString;
// FriendsString is a comma delimited list of names.
char *Seperator = nullptr;
Seperator = strchr(FriendsPointer, ',');
if(!Seperator) Seperator = strchr(FriendsPointer, '\0');
uint32 TotalLength=0;
while(Seperator != nullptr) {
if((Seperator - FriendsPointer) > 64) return;
strncpy(Friend_, FriendsPointer, Seperator - FriendsPointer);
Friend_[Seperator - FriendsPointer] = 0;
ClientListEntry* CLE = FindCharacter(Friend_);
if(CLE && CLE->name() && (CLE->Online() >= CLE_Status::Zoning) && !(CLE->GetGM() && CLE->Anon())) {
FriendsCLEs.push_back(CLE);
TotalLength += strlen(CLE->name());
int GuildNameLength = strlen(guild_mgr.GetGuildName(CLE->GuildID()));
if(GuildNameLength>0)
TotalLength += (GuildNameLength + 2);
}
if(Seperator[0] == '\0') break;
FriendsPointer = Seperator + 1;
Seperator = strchr(FriendsPointer, ',');
if(!Seperator) Seperator = strchr(FriendsPointer, '\0');
}
try{
ClientListEntry* cle;
int FriendsOnline = FriendsCLEs.size();
int PacketLength = sizeof(WhoAllReturnStruct) + (47 * FriendsOnline) + TotalLength;
auto pack2 = new ServerPacket(ServerOP_WhoAllReply, PacketLength);
memset(pack2->pBuffer,0,pack2->size);
uchar *buffer=pack2->pBuffer;
uchar *bufptr=buffer;
WhoAllReturnStruct *WARS = (WhoAllReturnStruct *)bufptr;
WARS->id = FriendsWho->FromID;
WARS->playerineqstring = 0xffffffff;
strcpy(WARS->line, "");
WARS->unknown35 = 0x0a;
WARS->unknown36 = 0x00;
if(FriendsCLEs.size() == 1)
WARS->playersinzonestring = 5028; // 5028 There is %1 player in EverQuest.
else
WARS->playersinzonestring = 5036; // 5036 There are %1 players in EverQuest.
WARS->unknown44[0] = 0;
WARS->unknown44[1] = 0;
WARS->unknown52 = FriendsOnline;
WARS->unknown56 = 1;
WARS->playercount = FriendsOnline;
bufptr+=sizeof(WhoAllReturnStruct);
for(int CLEEntry = 0; CLEEntry < FriendsOnline; CLEEntry++) {
cle = FriendsCLEs[CLEEntry];
char GuildName[67]={0};
if (cle->GuildID() != GUILD_NONE && cle->GuildID()>0)
sprintf(GuildName,"<%s>", guild_mgr.GetGuildName(cle->GuildID()));
uint32 FormatMSGID=5025; // 5025 %T1[%2 %3] %4 (%5) %6 %7 %8 %9
if(cle->Anon()==1)
FormatMSGID=5024; // 5024 %T1[ANONYMOUS] %2 %3
else if(cle->Anon()==2)
FormatMSGID=5023; // 5023 %T1[ANONYMOUS] %2 %3 %4
uint32 PlayerClass=0;
uint32 PlayerLevel=0;
uint32 PlayerRace=0;
uint32 ZoneMSGID=0xffffffff;
uint32 PlayerZone=0;
if(cle->Anon()==0) {
PlayerClass=cle->class_();
PlayerLevel=cle->level();
PlayerRace=cle->race();
ZoneMSGID=5006; // 5006 ZONE: %1
PlayerZone=cle->zone();
}
char PlayerName[64]={0};
strcpy(PlayerName,cle->name());
WhoAllPlayerPart1* WAPP1 = (WhoAllPlayerPart1*)bufptr;
WAPP1->FormatMSGID = FormatMSGID;
WAPP1->PIDMSGID = 0xffffffff;
strcpy(WAPP1->Name, PlayerName);
bufptr += sizeof(WhoAllPlayerPart1) + strlen(PlayerName);
WhoAllPlayerPart2* WAPP2 = (WhoAllPlayerPart2*)bufptr;
WAPP2->RankMSGID = 0xffffffff;
strcpy(WAPP2->Guild, GuildName);
bufptr += sizeof(WhoAllPlayerPart2) + strlen(GuildName);
WhoAllPlayerPart3* WAPP3 = (WhoAllPlayerPart3*)bufptr;
WAPP3->Unknown80[0] = 0xffffffff;
WAPP3->Unknown80[1] = 0xffffffff;
WAPP3->ZoneMSGID = ZoneMSGID;
WAPP3->Zone = PlayerZone;
WAPP3->Class_ = PlayerClass;
WAPP3->Level = PlayerLevel;
WAPP3->Race = PlayerRace;
WAPP3->Account[0] = 0;
bufptr += sizeof(WhoAllPlayerPart3);
WhoAllPlayerPart4* WAPP4 = (WhoAllPlayerPart4*)bufptr;
WAPP4->Unknown100 = 207;
bufptr += sizeof(WhoAllPlayerPart4);
}
SendPacket(FriendsWho->FromName,pack2);
safe_delete(pack2);
}
catch(...){
LogInfo("Unknown error in world's SendFriendsWho (probably mem error), ignoring");
return;
}
}
void ClientList::SendLFGMatches(ServerLFGMatchesRequest_Struct *smrs) {
// Send back matches when someone searches player's Looking For A Group.
LinkedListIterator<ClientListEntry*> Iterator(clientlist);
ClientListEntry* CLE = 0;
int Matches = 0;
Iterator.Reset();
// We run the ClientList twice. The first time is to determine how big the outgoing packet needs to be.
while(Iterator.MoreElements()) {
CLE = Iterator.GetData();
if(CLE->LFG()) {
unsigned int BitMask = 1 << CLE->class_();
// First we check that the player meets the level and class criteria of the person
// doing the search.
if((CLE->level() >= smrs->FromLevel) && (CLE->level() <= smrs->ToLevel) &&
(BitMask & smrs->Classes))
// Then we check if if the player doing the search meets the level criteria specified
// by the player who is LFG.
//
// GetLFGMatchFilter returns the setting of the 'Only players who match my posted filters
// can query me' checkbox.
//
// FromLevel and ToLevel are the settings of the 'Want group levels:' boxes.
if(!CLE->GetLFGMatchFilter() || ((smrs->QuerierLevel >= CLE->GetLFGFromLevel()) &&
(smrs->QuerierLevel <= CLE->GetLFGToLevel())))
Matches++;
}
Iterator.Advance();
}
auto Pack = new ServerPacket(ServerOP_LFGMatches, (sizeof(ServerLFGMatchesResponse_Struct) * Matches) + 4);
char *Buf = (char *)Pack->pBuffer;
// FromID is the Entity ID of the player doing the search.
VARSTRUCT_ENCODE_TYPE(uint32, Buf, smrs->FromID);
ServerLFGMatchesResponse_Struct* Buffer = (ServerLFGMatchesResponse_Struct*)Buf;
Iterator.Reset();
if(Matches) {
while(Iterator.MoreElements() && (Matches > 0)) {
CLE = Iterator.GetData();
if(CLE->LFG()) {
unsigned int BitMask = 1 << CLE->class_();
if((CLE->level() >= smrs->FromLevel) && (CLE->level() <= smrs->ToLevel) &&
(BitMask & smrs->Classes)) {
Matches--;
strcpy(Buffer->Name, CLE->name());
Buffer->Class_ = CLE->class_();
Buffer->Level = CLE->level();
Buffer->Zone = CLE->zone();
// If the LFG player is anon, level and class are still displayed, but
// zone shows as UNAVAILABLE.
Buffer->Anon = (CLE->Anon() != 0);
// The client can filter on Guildname
Buffer->GuildID = CLE->GuildID();
strcpy(Buffer->Comments, CLE->GetLFGComments());
Buffer++;
}
}
Iterator.Advance();
}
}
SendPacket(smrs->FromName,Pack);
safe_delete(Pack);
}
void ClientList::ConsoleSendWhoAll(const char* to, int16 admin, Who_All_Struct* whom, WorldTCPConnection* connection) {
LinkedListIterator<ClientListEntry*> iterator(clientlist);
ClientListEntry* cle = 0;