Repository navigation
Expand file tree
/
Copy pathclient.cpp
More file actions
2541 lines (2205 loc) · 77.8 KB
/
Copy pathclient.cpp
File metadata and controls
2541 lines (2205 loc) · 77.8 KB
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: EQEmulator
Copyright (C) 2001-2026 EQEmu Development Team
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; either version 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "client.h"
#include "common/classes.h"
#include "common/content/world_content_service.h"
#include "common/data_bucket.h"
#include "common/data_verification.h"
#include "common/emu_opcodes.h"
#include "common/emu_versions.h"
#include "common/eq_packet_structs.h"
#include "common/eq_packet.h"
#include "common/eq_stream_intf.h"
#include "common/eq_stream_intf.h"
#include "common/events/player_event_logs.h"
#include "common/extprofile.h"
#include "common/inventory_profile.h"
#include "common/misc.h"
#include "common/opcode_manager.h"
#include "common/packet_dump.h"
#include "common/races.h"
#include "common/random.h"
#include "common/repositories/account_repository.h"
#include "common/repositories/character_data_repository.h"
#include "common/repositories/group_id_repository.h"
#include "common/repositories/inventory_repository.h"
#include "common/repositories/player_event_logs_repository.h"
#include "common/rulesys.h"
#include "common/shareddb.h"
#include "common/skill_caps.h"
#include "common/skills.h"
#include "common/strings.h"
#include "common/zone_store.h"
#include "world/clientlist.h"
#include "world/login_server_list.h"
#include "world/login_server.h"
#include "world/sof_char_create_data.h"
#include "world/wguild_mgr.h"
#include "world/world_config.h"
#include "world/worlddb.h"
#include "world/zonelist.h"
#include "world/zoneserver.h"
#include "zlib.h"
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
// Disgrace: for windows compile
#ifdef _WINDOWS
#include <winsock2.h>
#include <windows.h>
#else
#ifdef FREEBSD //Timothy Whitman - January 7, 2003
#include <sys/types.h>
#endif
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#endif
std::vector<RaceClassAllocation> character_create_allocations;
std::vector<RaceClassCombos> character_create_race_class_combos;
extern uint32 numclients;
extern volatile bool RunLoops;
extern volatile bool UCSServerAvailable_;
// unused ATM, but here for reference, should match RoF2
enum class NameApprovalResponse : int {
NotValid = -1, // string ID 1576
Rejected = 0, // string ID 1581
Approved = 1,
CharacterLimit = 2, // string ID 1591 older clients mention 1 char on server
ThreeDeity = 3, // string ID 5502. 3 toons same deity team limit
HeadStartPreOoW = 4, // string ID 6862, head start failed due to OoW not being unlocked
HeadStartNoOoW = 5, // string ID 6863, head start failed due to not owning OoW
};
Client::Client(EQStreamInterface* ieqs)
: autobootup_timeout(RuleI(World, ZoneAutobootTimeoutMS)),
connect(1000),
eqs(ieqs)
{
// Live does not send datarate as of 3/11/2005
//eqs->SetDataRate(7);
ip = eqs->GetRemoteIP();
port = ntohs(eqs->GetRemotePort());
autobootup_timeout.Disable();
connect.Disable();
seen_character_select = false;
cle = 0;
zone_id = 0;
char_name[0] = 0;
charid = 0;
zone_waiting_for_bootup = 0;
enter_world_triggered = false;
StartInTutorial = false;
m_ClientVersion = eqs->ClientVersion();
m_ClientVersionBit = EQ::versions::ConvertClientVersionToClientVersionBit(m_ClientVersion);
numclients++;
}
Client::~Client() {
ClearDataBucketsCache();
if (RunLoops && cle && zone_id == 0)
cle->SetOnline(CLE_Status::Offline);
numclients--;
//let the stream factory know were done with this stream
eqs->Close();
eqs->ReleaseFromUse();
safe_delete(eqs);
}
void Client::SendLogServer()
{
auto outapp = new EQApplicationPacket(OP_LogServer, sizeof(LogServer_Struct));
LogServer_Struct *l=(LogServer_Struct *)outapp->pBuffer;
const char *wsn=WorldConfig::get()->ShortName.c_str();
memcpy(l->worldshortname,wsn,strlen(wsn));
if(RuleB(Mail, EnableMailSystem))
l->enablemail = 1;
if(RuleB(Chat, EnableVoiceMacros))
l->enablevoicemacros = 1;
l->enable_pvp = (RuleI(World, PVPSettings));
if(RuleB(World, IsGMPetitionWindowEnabled))
l->enable_petition_wnd = 1;
if (CanTradeFVNoDropItem()) {
l->enable_FV = 1;
}
QueuePacket(outapp);
safe_delete(outapp);
}
bool Client::CanTradeFVNoDropItem()
{
const int16 admin_status = GetAdmin();
const int no_drop_flag = RuleI(World, FVNoDropFlag);
const int no_drop_min_admin_status = RuleI(Character, MinStatusForNoDropExemptions);
switch (no_drop_flag) {
case FVNoDropFlagRule::Disabled:
return false;
case FVNoDropFlagRule::Enabled:
return true;
case FVNoDropFlagRule::AdminOnly:
return admin_status >= no_drop_min_admin_status;
default:
LogWarning("Invalid value {0} set for FVNoDropFlag", no_drop_flag);
return false;
}
return false;
}
void Client::SendEnterWorld(std::string name)
{
std::string live_name {};
if (is_player_zoning) {
live_name = database.GetLiveChar(GetAccountID());
if (database.GetAccountIDByChar(live_name) != GetAccountID()) {
eqs->Close();
return;
}
LogInfo("Zoning with live_name [{}] account_id [{}]", live_name, GetAccountID());
}
if (!is_player_zoning && RuleB(World, EnableAutoLogin)) {
live_name = AccountRepository::GetAutoLoginCharacterNameByAccountID(database, GetAccountID());
LogInfo("Attempting to auto login with live_name [{}] account_id [{}]", live_name, GetAccountID());
}
auto outapp = new EQApplicationPacket(OP_EnterWorld, live_name.length() + 1);
memcpy(outapp->pBuffer, live_name.c_str(), live_name.length() + 1);
QueuePacket(outapp);
safe_delete(outapp);
}
void Client::SendExpansionInfo() {
auto outapp = new EQApplicationPacket(OP_ExpansionInfo, sizeof(ExpansionInfo_Struct));
ExpansionInfo_Struct *eis = (ExpansionInfo_Struct*)outapp->pBuffer;
if (RuleI(World, CharacterSelectExpansionSettings) != -1) {
eis->Expansions = RuleI(World, CharacterSelectExpansionSettings);
}
else if (RuleB(World, UseClientBasedExpansionSettings)) {
eis->Expansions = EQ::expansions::ConvertClientVersionToExpansionsMask(eqs->ClientVersion());
}
else {
eis->Expansions = RuleI(World, ExpansionSettings);
}
QueuePacket(outapp);
safe_delete(outapp);
}
void Client::SendCharInfo() {
if (cle) {
cle->SetOnline(CLE_Status::CharSelect);
}
if (m_ClientVersionBit & EQ::versions::maskRoFAndLater) {
SendMaxCharCreate();
SendMembership();
SendMembershipSettings();
}
seen_character_select = true;
// Send OP_SendCharInfo
EQApplicationPacket *outapp = nullptr;
database.GetCharSelectInfo(GetAccountID(), &outapp, m_ClientVersionBit);
if (outapp) {
QueuePacket(outapp);
}
else {
LogError("Database did not return an OP_SendCharInfo packet for account [{}]", GetAccountID());
}
safe_delete(outapp);
}
void Client::SendMaxCharCreate() {
auto outapp = new EQApplicationPacket(OP_SendMaxCharacters, sizeof(MaxCharacters_Struct));
MaxCharacters_Struct* mc = (MaxCharacters_Struct*)outapp->pBuffer;
mc->max_chars = EQ::constants::StaticLookup(m_ClientVersion)->CharacterCreationLimit;
if (mc->max_chars > EQ::constants::CHARACTER_CREATION_LIMIT)
mc->max_chars = EQ::constants::CHARACTER_CREATION_LIMIT;
QueuePacket(outapp);
safe_delete(outapp);
}
void Client::SendMembership() {
auto outapp = new EQApplicationPacket(OP_SendMembership, sizeof(Membership_Struct));
Membership_Struct* mc = (Membership_Struct*)outapp->pBuffer;
/*
The remaining entry fields probably hold more membership restriction data that needs to be identified.
Here is a possible list based on the EQ Website membership comparison list:
1. Spell Ranks Allowed
2. Prestige Items Usable
3. In-Game Mail Service (send/recieve)
4. Parcel Delivery (send/recieve)
5. Loyalty Rewards Per-Week (30, 60, Max)
6. Mercenary Tiers (Apprentice 1-2, Apprentice All Tiers, All Tiers)
7. Neighborhood House
8. Active Journal Quests (Tasks?) (10, 15, Max)
9. Guild Function (join, join and create)
10. Broker System (restricted, unlimited)
11. Voice Chat
12. Chat Ability
13. Progression Server
14. Customer Support
15. In-Game Popup Advertising
That is 15 possible fields, and there are 15 unknowns in the struct...Coincidence?
*/
mc->membership = 2; //Hardcode to gold for now. We don't use anything else.
mc->races = 0x1ffff; // Available Races (4110 for silver)
mc->classes = 0x1ffff; // Available Classes (4614 for silver) - Was 0x101ffff
mc->entrysize = 21; // Number of membership setting entries below
mc->entries[0] = 0xffffffff; // Max AA Restriction
mc->entries[1] = 0xffffffff; // Max Level Restriction
mc->entries[2] = 0xffffffff; // Max Char Slots per Account (not used by client?)
mc->entries[3] = 0xffffffff; // 1 for Silver
mc->entries[4] = 0xffffffff; // Main Inventory Size (0xffffffff on Live for Gold, but limiting to 8 until 10 is supported)
mc->entries[5] = 0xffffffff; // Max Platinum per level
mc->entries[6] = 1; // 0 for Silver
mc->entries[7] = 1; // 0 for Silver
mc->entries[8] = 1; // 1 for Silver
mc->entries[9] = 0xffffffff; // Unknown - Maybe Loyalty Points every 12 hours? 60 per week for Silver
mc->entries[10] = 1; // 1 for Silver
mc->entries[11] = 0xffffffff; // Shared Bank Slots
mc->entries[12] = 0xffffffff; // Unknown - Maybe Max Active Tasks?
mc->entries[13] = 1; // 1 for Silver
mc->entries[14] = 1; // 0 for Silver
mc->entries[15] = 1; // 0 for Silver
mc->entries[16] = 1; // 1 for Silver
mc->entries[17] = 1; // 0 for Silver
mc->entries[18] = 1; // 0 for Silver
mc->entries[19] = 0xffffffff; // 0 for Silver
mc->entries[20] = 0xffffffff; // 0 for Silver
mc->exit_url_length = 0;
//mc->exit_url = 0; // Used on Live: "http://www.everquest.com/free-to-play/exit-silver"
QueuePacket(outapp);
safe_delete(outapp);
}
void Client::SendMembershipSettings() {
auto outapp = new EQApplicationPacket(OP_SendMembershipDetails, sizeof(Membership_Details_Struct));
Membership_Details_Struct* mds = (Membership_Details_Struct*)outapp->pBuffer;
mds->membership_setting_count = 66;
int32 gold_settings[22] = {-1,-1,-1,-1,-1,-1,1,1,1,-1,1,-1,-1,1,1,1,1,1,1,-1,-1,0};
uint32 entry_count = 0;
for (int setting_id=0; setting_id < 22; setting_id++)
{
for (int setting_index=0; setting_index < 3; setting_index++)
{
mds->settings[entry_count].setting_index = setting_index;
mds->settings[entry_count].setting_id = setting_id;
mds->settings[entry_count].setting_value = gold_settings[setting_id];
entry_count++;
}
}
mds->race_entry_count = 15;
mds->class_entry_count = 15;
uint32 cur_purchase_id = 90287;
uint32 cur_purchase_id2 = 90301;
uint32 cur_bitwise_value = 1;
for (int entry_id=0; entry_id < 15; entry_id++)
{
if (entry_id == 0)
{
mds->membership_races[entry_id].purchase_id = 1;
mds->membership_races[entry_id].bitwise_entry = 0x1ffff;
mds->membership_classes[entry_id].purchase_id = 1;
mds->membership_classes[entry_id].bitwise_entry = 0x1ffff;
}
else
{
mds->membership_races[entry_id].purchase_id = cur_purchase_id;
if (entry_id < 3)
{
mds->membership_classes[entry_id].purchase_id = cur_purchase_id;
}
else
{
mds->membership_classes[entry_id].purchase_id = cur_purchase_id2;
cur_purchase_id2++;
}
if (entry_id == 1)
{
mds->membership_races[entry_id].bitwise_entry = 4110;
mds->membership_classes[entry_id].bitwise_entry = 4614;
}
else if (entry_id == 2)
{
mds->membership_races[entry_id].bitwise_entry = 4110;
mds->membership_classes[entry_id].bitwise_entry = 4614;
}
else
{
if (entry_id == 12)
{
// Live Skips 4096
cur_bitwise_value *= 2;
}
mds->membership_races[entry_id].bitwise_entry = cur_bitwise_value;
mds->membership_classes[entry_id].bitwise_entry = cur_bitwise_value;
}
cur_purchase_id++;
}
cur_bitwise_value *= 2;
}
mds->exit_url_length = 0; // Live uses 42
//strcpy(eq->exit_url, "http://www.everquest.com/free-to-play/exit");
mds->exit_url_length2 = 0; // Live uses 49
//strcpy(eq->exit_url2, "http://www.everquest.com/free-to-play/exit-silver");
/*
Account Access Level Settings
ID - Free Silver Gold - Possible Setting
00 - 250 1000 -1 - Max AA Restriction
01 - -1 -1 -1 - Max Level Restriction
02 - 2 4 -1 - Max Char Slots per Account
03 - 1 1 -1 - Max Spell Rank
04 - 4 6 -1 - Main Inventory Size
05 - 100 500 -1 - Max Platinum per level
06 - 0 0 1 - Send Mail?
07 - 0 0 1 - Send Parcels?
08 - 1 1 1 - Voice Chat Unlimited?
09 - 2 5 -1 - Mercenary Tiers
10 - 0 1 1 - Create Guilds?
11 - 0 0 -1 - Shared Bank Slots
12 - 9 14 -1 - Max Journal Quests - 1
13 - 0 1 1 - Neighborhood-House Allowed?
14 - 0 0 1 - Prestige Enabled?
15 - 0 0 1 - Broker System Unlimited?
16 - 0 1 1 - Chat UnRestricted?
17 - 0 0 1 - Progression Server Access?
18 - 0 0 1 - Full Customer Support?
19 - 0 0 -1 - 0 for Silver
20 - 0 0 -1 - 0 for Silver
21 - 0 0 0 - Unknown 0
*/
QueuePacket(outapp);
safe_delete(outapp);
}
void Client::SendPostEnterWorld() {
auto outapp = new EQApplicationPacket(OP_PostEnterWorld, 1);
outapp->size=0;
QueuePacket(outapp);
safe_delete(outapp);
}
bool Client::HandleSendLoginInfoPacket(const EQApplicationPacket *app)
{
if (app->size != sizeof(LoginInfo)) {
return false;
}
auto *r = (LoginInfo *) app->pBuffer;
// Quagmire - max len for name is 18, pass 15
char name[19] = {0};
char password[16] = {0};
strn0cpy(name, (char *) r->login_info, 18);
strn0cpy(password, (char *) &(r->login_info[strlen(name) + 1]), 15);
LogDebug("Receiving login info packet from client | name [{}] password [{}]", name, password);
if (strlen(password) <= 1) {
LogInfo("Login without a password");
return false;
}
is_player_zoning = (r->zoning == 1);
uint32 id = Strings::ToInt(name);
if (id == 0) {
LogWarning("Receiving login info packet from client | account_id is 0 - disconnecting");
return false;
}
LogClientLogin("Checking authentication id [{}]", id);
if ((cle = ClientList::Instance()->CheckAuth(id, password))) {
LoadDataBucketsCache();
LogClientLogin("Checking authentication id [{}] passed", id);
if (!is_player_zoning) {
// Track who is in and who is out of the game
std::string in_out;
if (cle->GetOnline() == CLE_Status::Never) {
// Desktop -> Char Select
in_out = "in";
}
else {
// Game -> Char Select
in_out = "out";
}
// Always at Char select at this point.
// Either from a fresh client launch or coming back from the game.
// Exiting the game entirely does not come through here.
// Could use a Logging Out Completely message somewhere.
cle->SetOnline(CLE_Status::CharSelect);
LogInfo("Account ({}) Logging ({}) to character select :: LSID [{}] ", cle->AccountName(), in_out, cle->LSID());
}
else {
cle->SetOnline();
}
const WorldConfig *Config=WorldConfig::get();
if(Config->UpdateStats) {
auto pack = new ServerPacket;
pack->opcode = ServerOP_LSPlayerJoinWorld;
pack->size = sizeof(ServerLSPlayerJoinWorld_Struct);
pack->pBuffer = new uchar[pack->size];
memset(pack->pBuffer,0,pack->size);
ServerLSPlayerJoinWorld_Struct* join =(ServerLSPlayerJoinWorld_Struct*)pack->pBuffer;
strcpy(join->key,GetLSKey());
join->lsaccount_id = GetLSID();
LoginServerList::Instance()->SendPacket(pack);
safe_delete(pack);
}
if (!is_player_zoning)
SendGuildList();
SendLogServer();
SendApproveWorld();
SendEnterWorld(cle->name());
SendPostEnterWorld();
if (!is_player_zoning) {
const auto supported_clients = RuleS(World, SupportedClients);
bool skip_char_info = false;
if (!supported_clients.empty()) {
const std::string& name = EQ::versions::ClientVersionName(m_ClientVersion);
const auto& clients = Strings::Split(supported_clients, ",");
if (std::find(clients.begin(), clients.end(), name) == clients.end()) {
SendUnsupportedClientPacket(
fmt::format(
"Client Not In Supported List [{}]",
supported_clients
)
);
skip_char_info = true;
}
}
const auto& custom_files_key = RuleS(World, CustomFilesKey);
if (!skip_char_info && !custom_files_key.empty() && cle->Admin() < RuleI(World, CustomFilesAdminLevel)) {
// Modified clients can utilize this unused block in login_info to send custom payloads on login
// which indicates they are using custom client files with the correct version, based on key payload.
const auto client_key = std::string(reinterpret_cast<char*>(r->unknown064));
if (custom_files_key != client_key) {
std::string message = fmt::format("Missing Files [{}]", RuleS(World, CustomFilesUrl) );
SendUnsupportedClientPacket(message);
skip_char_info = true;
}
}
if (!skip_char_info) {
SendExpansionInfo();
SendCharInfo();
database.LoginIP(cle->AccountID(), long2ip(GetIP()));
}
}
cle->SetIP(GetIP());
return true;
}
else {
LogInfo("Bad/Expired session key [{}]", name);
return false;
}
}
bool Client::HandleNameApprovalPacket(const EQApplicationPacket *app)
{
if (GetAccountID() == 0) {
LogInfo("Name approval request with no logged in account");
return false;
}
auto n = (NameApproval_Struct*) app->pBuffer;
strn0cpy(char_name, n->name, sizeof(char_name));
const uint32 length = strlen(n->name);
const uint32 race_id = n->race_id;
const uint32 class_id = n->class_id;
if (!IsPlayerRace(race_id)) {
LogInfo("Invalid Race ID.");
return false;
}
if (!EQ::ValueWithin(class_id, Class::Warrior, Class::Berserker)) {
LogInfo("Invalid Class ID.");
return false;
}
LogInfo(
"char_name [{}] race_id [{}] class_id [{}]",
char_name,
GetRaceIDName(race_id),
GetClassIDName(class_id)
);
bool is_valid = true;
if (!EQ::ValueWithin(length, 4, 15)) { /* Name must be between 4 and 15 characters long, packet forged if this is true */
is_valid = false;
} else if (islower(char_name[0])) { /* Name must begin with an upper-case letter, can be sent with some tricking of the client */
is_valid = false;
} else if (strstr(char_name, " ")) { /* Name must not have any spaces, packet forged if this is true */
is_valid = false;
} else if (!database.CheckNameFilter(char_name)) { /* I would like to do this later, since it's likely more expensive, but oh well */
is_valid = false;
} else { /* Name must not contain any uppercase letters, can be sent with some tricking of the client */
for (int i = 1; i < length; ++i) {
if (isupper(char_name[i])) {
is_valid = false;
break;
}
}
}
if (is_valid) { /* Still not invalid, let's see if it's taken */
is_valid = database.ReserveName(GetAccountID(), char_name);
}
auto outapp = new EQApplicationPacket(OP_ApproveName, 1);
outapp->pBuffer[0] = is_valid ? 1 : 0;
QueuePacket(outapp);
safe_delete(outapp);
if (!is_valid) {
memset(char_name, 0, sizeof(char_name));
}
return true;
}
bool Client::HandleGenerateRandomNamePacket(const EQApplicationPacket *app) {
char newName[17] = {0};
bool unique = false;
while (!unique) {
std::string cons = "bcdfghjklmnpqrstvwxyz";
std::string vows = "aeou";
std::string allVows = "aeiou";
std::vector<std::string> endPhon = {"a", "e", "i", "o", "u", "os", "as", "us", "is", "y", "an", "en", "in", "on", "un"};
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<int> lenDist(5, 10);
std::uniform_int_distribution<int> firstCharDist(0, 1);
std::uniform_int_distribution<int> consDist(0, cons.size() - 1);
std::uniform_int_distribution<int> vowDist(0, vows.size() - 1);
std::uniform_int_distribution<int> allVowDist(0, allVows.size() - 1);
std::uniform_int_distribution<int> endPhonDist(0, endPhon.size() - 1);
int len = 0;
memset(newName, 0, sizeof(newName));
if (firstCharDist(gen) == 0) {
newName[len++] = vows[vowDist(gen)];
newName[len++] = cons[consDist(gen)];
} else {
newName[len++] = cons[consDist(gen)];
newName[len++] = allVows[allVowDist(gen)];
}
newName[0] = toupper(newName[0]);
while (len < lenDist(gen) - 1) {
if (len % 2 == 0) {
newName[len++] = cons[consDist(gen)];
} else {
newName[len++] = allVows[allVowDist(gen)];
}
}
std::string end = endPhon[endPhonDist(gen)];
for (char c : end) {
if (len < 10) newName[len++] = c;
}
if (database.CheckNameFilter(newName)) {
std::string query = StringFormat("SELECT `name` FROM `character_data` WHERE `name` = '%s'", newName);
auto res = database.QueryDatabase(query);
if (res.Success() && res.RowCount() == 0) {
unique = true;
}
}
}
NameGeneration_Struct* ngs = (NameGeneration_Struct*)app->pBuffer;
memset(ngs->name, 0, 64);
strcpy(ngs->name, newName);
QueuePacket(app);
return true;
}
bool Client::HandleCharacterCreateRequestPacket(const EQApplicationPacket *app) {
// New OpCode in SoF
uint32 allocs = character_create_allocations.size();
uint32 combos = character_create_race_class_combos.size();
uint32 len = sizeof(RaceClassAllocation) * allocs;
len += sizeof(RaceClassCombos) * combos;
len += sizeof(uint8);
len += sizeof(uint32);
len += sizeof(uint32);
auto outapp = new EQApplicationPacket(OP_CharacterCreateRequest, len);
unsigned char *ptr = outapp->pBuffer;
*((uint8*)ptr) = 0;
ptr += sizeof(uint8);
*((uint32*)ptr) = allocs;
ptr += sizeof(uint32);
for(int i = 0; i < allocs; ++i) {
RaceClassAllocation *alc = (RaceClassAllocation*)ptr;
alc->Index = character_create_allocations[i].Index;
for(int j = 0; j < 7; ++j) {
alc->BaseStats[j] = character_create_allocations[i].BaseStats[j];
alc->DefaultPointAllocation[j] = character_create_allocations[i].DefaultPointAllocation[j];
}
ptr += sizeof(RaceClassAllocation);
}
*((uint32*)ptr) = combos;
ptr += sizeof(uint32);
for(int i = 0; i < combos; ++i) {
RaceClassCombos *cmb = (RaceClassCombos*)ptr;
cmb->ExpansionRequired = character_create_race_class_combos[i].ExpansionRequired;
cmb->Race = character_create_race_class_combos[i].Race;
cmb->Class = character_create_race_class_combos[i].Class;
cmb->Deity = character_create_race_class_combos[i].Deity;
cmb->AllocationIndex = character_create_race_class_combos[i].AllocationIndex;
cmb->Zone = character_create_race_class_combos[i].Zone;
ptr += sizeof(RaceClassCombos);
}
QueuePacket(outapp);
safe_delete(outapp);
return true;
}
bool Client::HandleCharacterCreatePacket(const EQApplicationPacket *app) {
if (GetAccountID() == 0) {
LogInfo("Account ID not set; unable to create character");
return false;
}
else if (app->size != sizeof(CharCreate_Struct)) {
LogInfo("Wrong size on OP_CharacterCreate. Got: [{}], Expected: [{}]", app->size, sizeof(CharCreate_Struct));
DumpPacket(app);
// the previous behavior was essentially returning true here
// but that seems a bit odd to me.
return true;
}
CharCreate_Struct *cc = (CharCreate_Struct*)app->pBuffer;
if(OPCharCreate(char_name, cc) == false) {
database.DeleteCharacter(char_name);
auto outapp = new EQApplicationPacket(OP_ApproveName, 1);
outapp->pBuffer[0] = 0;
QueuePacket(outapp);
safe_delete(outapp);
}
else
{
if (m_ClientVersionBit & EQ::versions::maskTitaniumAndEarlier)
StartInTutorial = true;
SendCharInfo();
}
return true;
}
bool Client::HandleEnterWorldPacket(const EQApplicationPacket *app) {
auto account_id = GetAccountID();
if (!account_id) {
LogInfo("Enter world with no logged in account.");
eqs->Close();
return true;
}
if (GetAdmin() < 0) {
LogInfo("Account [{}] is banned or suspended.", account_id);
eqs->Close();
return true;
}
if (
RuleB(World, EnableIPExemptions) ||
RuleI(World, MaxClientsPerIP) > 0
) {
ClientList::Instance()->GetCLEIP(GetIP()); //Check current CLE Entry IPs against incoming connection
}
auto ew = (EnterWorld_Struct *) app->pBuffer;
strn0cpy(char_name, ew->name, sizeof(char_name));
const auto& l = CharacterDataRepository::GetWhere(
database,
fmt::format(
"`name` = '{}' LIMIT 1",
Strings::Escape(char_name)
)
);
if (l.empty()) {
LogInfo("Could not get CharInfo for [{}]", char_name);
eqs->Close();
return true;
}
auto r = WorldContentService::Instance()->FindZone(zone_id, instance_id);
if (r.zone_id && r.instance.id != instance_id) {
LogInfo(
"Zone [{}] has been remapped to instance_id [{}] from instance_id [{}] for client [{}]",
r.zone.short_name,
r.instance.id,
instance_id,
char_name
);
instance_id = r.instance.id;
}
const auto& e = l.front();
// Make sure this account owns this character
if (e.account_id != account_id) {
LogInfo(
"Account [{}] does not own the character named [{}] from account [{}]",
account_id,
char_name,
e.account_id
);
eqs->Close();
return true;
}
charid = e.id;
zone_id = e.zone_id;
instance_id = e.zone_instance;
// This can probably be moved outside and have another method return requested info (don't forget to remove the #include "../common/shareddb.h" above)
// (This is a literal translation of the original process..I don't see why it can't be changed to a single-target query over account iteration)
if (!is_player_zoning) {
size_t character_limit = EQ::constants::StaticLookup(eqs->ClientVersion())->CharacterCreationLimit;
if (character_limit > EQ::constants::CHARACTER_CREATION_LIMIT) {
character_limit = EQ::constants::CHARACTER_CREATION_LIMIT;
}
if (eqs->ClientVersion() == EQ::versions::ClientVersion::Titanium) {
character_limit = Titanium::constants::CHARACTER_CREATION_LIMIT;
}
auto query = fmt::format(
"SELECT `id`, `name`, `level`, `last_login` FROM character_data WHERE `account_id` = {} ORDER BY `name` LIMIT {}",
account_id,
character_limit
);
auto results = database.QueryDatabase(query);
/* Check GoHome */
if (ew->return_home && !ew->tutorial) {
bool home_enabled = false;
for (auto row : results) {
if (!strcasecmp(row[1], char_name)) {
if (RuleB(World, EnableReturnHomeButton)) {
int now = time(nullptr);
if ((now - Strings::ToInt(row[3])) >= RuleI(World, MinOfflineTimeToReturnHome)) {
home_enabled = true;
break;
}
}
}
}
if (home_enabled) {
zone_id = database.MoveCharacterToBind(charid, 4);
} else {
LogInfo("[{}] is trying to go home before they're able.", char_name);
RecordPossibleHack("[MQGoHome] player tried to go home before they were able");
eqs->Close();
return true;
}
}
/* Check Tutorial*/
if (RuleB(World, EnableTutorialButton) && (ew->tutorial || StartInTutorial)) {
bool tutorial_enabled = false;
for (auto row : results) {
if (!strcasecmp(row[1], char_name)) {
if (
RuleB(World, EnableTutorialButton) &&
Strings::ToInt(row[2]) <= RuleI(World, MaxLevelForTutorial)
) {
tutorial_enabled = true;
break;
}
}
}
if (tutorial_enabled) {
zone_id = RuleI(World, TutorialZoneID);
database.MoveCharacterToZone(charid, zone_id);
} else {
LogInfo("[{}] is trying to go to the Tutorial but they are not allowed.", char_name);
RecordPossibleHack("[MQTutorial] player tried to enter the tutorial without having tutorial enabled for this character");
eqs->Close();
return true;
}
}
}
if (!zone_id || !ZoneName(zone_id)) {
// This is to save people in an invalid zone, once it's removed from the DB
database.MoveCharacterToZone(charid, ZoneID("arena"));
LogInfo("Zone [{}] not found, moving [{}] to Arena.", zone_id, char_name);
}
if (instance_id) {
if (
!database.VerifyInstanceAlive(instance_id, GetCharID()) ||
!database.VerifyZoneInstance(zone_id, instance_id)
) {
zone_id = database.MoveCharacterToInstanceSafeReturn(charid, zone_id, instance_id);
instance_id = 0;
}
}
if(!is_player_zoning) {
GroupIdRepository::DeleteWhere(
database,
fmt::format(
"`character_id` = {} AND `name` = '{}'",
charid,
Strings::Escape(char_name)
)
);
database.SetLoginFlags(charid, false, false, 1);
} else {
auto group_id = database.GetGroupID(char_name);
if (group_id) {
auto leader_name = database.GetGroupLeaderForLogin(char_name);
if (!leader_name.empty()) {
auto pack = new EQApplicationPacket(OP_GroupUpdate, sizeof(GroupJoin_Struct));
auto gj = (GroupJoin_Struct*) pack->pBuffer;
gj->action=8;
strn0cpy(gj->yourname, char_name, sizeof(gj->yourname));
strn0cpy(gj->membername, leader_name.c_str(), sizeof(gj->membername));
QueuePacket(pack);
safe_delete(pack);
}
}
}
auto outapp = new EQApplicationPacket(OP_MOTD);
std::string motd = RuleS(World, MOTD);
if (!motd.empty()) {
outapp->size = motd.length() + 1;
outapp->pBuffer = new uchar[outapp->size];
memset(outapp->pBuffer, 0, outapp->size);
strcpy((char*) outapp->pBuffer, motd.c_str());
} else if (database.GetVariable("MOTD", motd)) {
outapp->size = motd.length() + 1;
outapp->pBuffer = new uchar[outapp->size];
memset(outapp->pBuffer, 0, outapp->size);
strcpy((char*) outapp->pBuffer, motd.c_str());
} else { // Null Message of the Day. :)
outapp->size = 1;
outapp->pBuffer = new uchar[outapp->size];
outapp->pBuffer[0] = 0;
}
QueuePacket(outapp);
safe_delete(outapp);
// set mailkey - used for duration of character session
uint32 mail_key = EQ::Random::Instance()->Int(1, INT_MAX);
database.SetMailKey(charid, GetIP(), mail_key);
if (UCSServerAvailable_) {
auto config = WorldConfig::get();
std::string buffer;
auto connection_type = EQ::versions::ucsUnknown;
// chat server packet
switch (GetClientVersion()) {
case EQ::versions::ClientVersion::Titanium:
connection_type = EQ::versions::ucsTitaniumChat;
break;
case EQ::versions::ClientVersion::SoF:
connection_type = EQ::versions::ucsSoFCombined;
break;
case EQ::versions::ClientVersion::SoD:
connection_type = EQ::versions::ucsSoDCombined;