@@ -56,18 +56,18 @@ typedef struct AUTH_LOGON_CHALLENGE_C
56
56
uint8 cmd;
57
57
uint8 error;
58
58
uint16 size;
59
- uint8 gamename[ 4 ] ;
59
+ uint32 gamename;
60
60
uint8 version1;
61
61
uint8 version2;
62
62
uint8 version3;
63
63
uint16 build;
64
- uint8 platform[ 4 ] ;
65
- uint8 os[ 4 ] ;
66
- uint8 country[ 4 ] ;
64
+ uint32 platform;
65
+ uint32 os ;
66
+ uint32 country;
67
67
uint32 timezone_bias;
68
68
uint32 ip;
69
69
uint8 I_len;
70
- uint8 I[1 ];
70
+ char I[1 ];
71
71
} sAuthLogonChallenge_C ;
72
72
static_assert (sizeof (sAuthLogonChallenge_C ) == (1 + 1 + 2 + 4 + 1 + 1 + 1 + 2 + 4 + 4 + 4 + 4 + 4 + 1 + 1 ));
73
73
@@ -180,10 +180,10 @@ void AccountInfo::LoadResult(Field* fields)
180
180
// FROM account a LEFT JOIN account_access aa ON a.id = aa.AccountID LEFT JOIN account_banned ab ON ab.id = a.id AND ab.active = 1 WHERE a.username = ?
181
181
182
182
Id = fields[0 ].GetUInt32 ();
183
- Login = fields[1 ].GetString ();
183
+ Login = fields[1 ].GetStringView ();
184
184
IsLockedToIP = fields[2 ].GetBool ();
185
- LockCountry = fields[3 ].GetString ();
186
- LastIP = fields[4 ].GetString ();
185
+ LockCountry = fields[3 ].GetStringView ();
186
+ LastIP = fields[4 ].GetStringView ();
187
187
FailedLogins = fields[5 ].GetUInt32 ();
188
188
IsBanned = fields[6 ].GetUInt64 () != 0 ;
189
189
IsPermanenetlyBanned = fields[7 ].GetUInt64 () != 0 ;
@@ -196,7 +196,9 @@ void AccountInfo::LoadResult(Field* fields)
196
196
}
197
197
198
198
AuthSession::AuthSession (tcp::socket&& socket) : Socket(std::move(socket)),
199
- _status(STATUS_CHALLENGE), _build(0 ), _timezoneOffset(0min), _expversion(0 ) { }
199
+ _status(STATUS_CHALLENGE), _locale(LOCALE_enUS), _os(0 ), _build(0 ), _expversion(0 ), _timezoneOffset(0min)
200
+ {
201
+ }
200
202
201
203
void AuthSession::Start ()
202
204
{
@@ -311,28 +313,19 @@ bool AuthSession::HandleLogonChallenge()
311
313
if (challenge->size - (sizeof (sAuthLogonChallenge_C ) - AUTH_LOGON_CHALLENGE_INITIAL_SIZE - 1 ) != challenge->I_len )
312
314
return false ;
313
315
314
- std::string login (( char const *) challenge->I , challenge->I_len );
316
+ std::string_view login (challenge->I , challenge->I_len );
315
317
TC_LOG_DEBUG (" server.authserver" , " [AuthChallenge] '{}'" , login);
316
318
317
319
_build = challenge->build ;
318
320
_expversion = uint8 (AuthHelper::IsPostBCAcceptedClientBuild (_build) ? POST_BC_EXP_FLAG : (AuthHelper::IsPreBCAcceptedClientBuild (_build) ? PRE_BC_EXP_FLAG : NO_VALID_EXP_FLAG));
319
- std::array<char , 5 > os;
320
- os.fill (' \0 ' );
321
- memcpy (os.data (), challenge->os , sizeof (challenge->os ));
322
- _os = os.data ();
323
-
324
- // Restore string order as its byte order is reversed
325
- std::reverse (_os.begin (), _os.end ());
326
-
327
- _localizationName.resize (4 );
328
- for (int i = 0 ; i < 4 ; ++i)
329
- _localizationName[i] = challenge->country [4 - i - 1 ];
321
+ _os = challenge->os ;
322
+ _locale = GetLocaleByName (ClientBuild::ToCharArray (challenge->country ).data ());
330
323
331
324
_timezoneOffset = Minutes (challenge->timezone_bias );
332
325
333
326
// Get the account details from the account table
334
327
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement (LOGIN_SEL_LOGONCHALLENGE);
335
- stmt->setString (0 , login);
328
+ stmt->setStringView (0 , login);
336
329
337
330
_queryProcessor.AddCallback (LoginDatabase.AsyncQuery (stmt)
338
331
.WithPreparedCallback ([this ](PreparedQueryResult result) { LogonChallengeCallback (std::move (result)); }));
@@ -467,7 +460,7 @@ void AuthSession::LogonChallengeCallback(PreparedQueryResult result)
467
460
pkt << uint8 (1 );
468
461
469
462
TC_LOG_DEBUG (" server.authserver" , " '{}:{}' [AuthChallenge] account {} is using '{}' locale ({})" ,
470
- ipAddress, port, _accountInfo.Login , _localizationName, GetLocaleByName (_localizationName ));
463
+ ipAddress, port, _accountInfo.Login , localeNames[_locale], uint32 (_locale ));
471
464
472
465
_status = STATUS_LOGON_PROOF;
473
466
}
@@ -524,7 +517,7 @@ bool AuthSession::HandleLogonProof()
524
517
return true ;
525
518
}
526
519
527
- if (!VerifyVersion (logonProof->A . data (), logonProof-> A . size () , logonProof->crc_hash , false ))
520
+ if (!VerifyVersion (logonProof->A , logonProof->crc_hash , false ))
528
521
{
529
522
ByteBuffer packet;
530
523
packet << uint8 (AUTH_LOGON_PROOF);
@@ -542,8 +535,8 @@ bool AuthSession::HandleLogonProof()
542
535
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement (LOGIN_UPD_LOGONPROOF);
543
536
stmt->setBinary (0 , _sessionKey);
544
537
stmt->setString (1 , address);
545
- stmt->setUInt32 (2 , GetLocaleByName (_localizationName) );
546
- stmt->setString (3 , _os);
538
+ stmt->setUInt32 (2 , _locale );
539
+ stmt->setStringView (3 , ClientBuild::ToCharArray ( _os). data () );
547
540
stmt->setInt16 (4 , _timezoneOffset.count ());
548
541
stmt->setString (5 , _accountInfo.Login );
549
542
_queryProcessor.AddCallback (LoginDatabase.AsyncQuery (stmt)
@@ -651,28 +644,19 @@ bool AuthSession::HandleReconnectChallenge()
651
644
if (challenge->size - (sizeof (sAuthLogonChallenge_C ) - AUTH_LOGON_CHALLENGE_INITIAL_SIZE - 1 ) != challenge->I_len )
652
645
return false ;
653
646
654
- std::string login (( char const *) challenge->I , challenge->I_len );
647
+ std::string_view login (challenge->I , challenge->I_len );
655
648
TC_LOG_DEBUG (" server.authserver" , " [ReconnectChallenge] '{}'" , login);
656
649
657
650
_build = challenge->build ;
658
651
_expversion = uint8 (AuthHelper::IsPostBCAcceptedClientBuild (_build) ? POST_BC_EXP_FLAG : (AuthHelper::IsPreBCAcceptedClientBuild (_build) ? PRE_BC_EXP_FLAG : NO_VALID_EXP_FLAG));
659
- std::array<char , 5 > os;
660
- os.fill (' \0 ' );
661
- memcpy (os.data (), challenge->os , sizeof (challenge->os ));
662
- _os = os.data ();
663
-
664
- // Restore string order as its byte order is reversed
665
- std::reverse (_os.begin (), _os.end ());
666
-
667
- _localizationName.resize (4 );
668
- for (int i = 0 ; i < 4 ; ++i)
669
- _localizationName[i] = challenge->country [4 - i - 1 ];
652
+ _os = challenge->os ;
653
+ _locale = GetLocaleByName (ClientBuild::ToCharArray (challenge->country ).data ());
670
654
671
655
_timezoneOffset = Minutes (challenge->timezone_bias );
672
656
673
657
// Get the account details from the account table
674
658
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement (LOGIN_SEL_RECONNECTCHALLENGE);
675
- stmt->setString (0 , login);
659
+ stmt->setStringView (0 , login);
676
660
677
661
_queryProcessor.AddCallback (LoginDatabase.AsyncQuery (stmt)
678
662
.WithPreparedCallback ([this ](PreparedQueryResult result) { ReconnectChallengeCallback (std::move (result)); }));
@@ -724,7 +708,7 @@ bool AuthSession::HandleReconnectProof()
724
708
725
709
if (sha.GetDigest () == reconnectProof->R2 )
726
710
{
727
- if (!VerifyVersion (reconnectProof->R1 , sizeof (reconnectProof-> R1 ), reconnectProof->R3 , true ))
711
+ if (!VerifyVersion (reconnectProof->R1 , reconnectProof->R3 , true ))
728
712
{
729
713
ByteBuffer packet;
730
714
packet << uint8 (AUTH_RECONNECT_PROOF);
@@ -800,11 +784,7 @@ void AuthSession::RealmListCallback(PreparedQueryResult result)
800
784
801
785
std::string name = realm.Name ;
802
786
if (_expversion & PRE_BC_EXP_FLAG && flag & REALM_FLAG_SPECIFYBUILD)
803
- {
804
- std::ostringstream ss;
805
- ss << name << " (" << buildInfo->MajorVersion << ' .' << buildInfo->MinorVersion << ' .' << buildInfo->BugfixVersion << ' )' ;
806
- name = ss.str ();
807
- }
787
+ Trinity::StringFormatTo (std::back_inserter (name), " ({}.{}.{})" , buildInfo->MajorVersion , buildInfo->MinorVersion , buildInfo->BugfixVersion );
808
788
809
789
uint8 lock = (realm.AllowedSecurityLevel > _accountInfo.SecurityLevel ) ? 1 : 0 ;
810
790
@@ -886,7 +866,7 @@ bool AuthSession::HandleXferCancel()
886
866
return false ;
887
867
}
888
868
889
- bool AuthSession::VerifyVersion (uint8 const * a, int32 aLength , Trinity::Crypto::SHA1::Digest const & versionProof, bool isReconnect)
869
+ bool AuthSession::VerifyVersion (std::span< uint8 const > a , Trinity::Crypto::SHA1::Digest const & versionProof, bool isReconnect)
890
870
{
891
871
if (!sConfigMgr ->GetBoolDefault (" StrictVersionCheck" , false ))
892
872
return true ;
@@ -899,7 +879,7 @@ bool AuthSession::VerifyVersion(uint8 const* a, int32 aLength, Trinity::Crypto::
899
879
if (!buildInfo)
900
880
return false ;
901
881
902
- auto platformItr = std::ranges::find (buildInfo->ExecutableHashes , ClientBuild::ToFourCC ( _os) , &ClientBuild::ExecutableHash::Platform);
882
+ auto platformItr = std::ranges::find (buildInfo->ExecutableHashes , _os, &ClientBuild::ExecutableHash::Platform);
903
883
if (platformItr == buildInfo->ExecutableHashes .end ())
904
884
return true ; // not filled serverside
905
885
@@ -909,9 +889,9 @@ bool AuthSession::VerifyVersion(uint8 const* a, int32 aLength, Trinity::Crypto::
909
889
versionHash = &zeros;
910
890
911
891
Trinity::Crypto::SHA1 version;
912
- version.UpdateData (a, aLength );
892
+ version.UpdateData (a);
913
893
version.UpdateData (*versionHash);
914
894
version.Finalize ();
915
895
916
- return ( versionProof == version.GetDigest () );
896
+ return versionProof == version.GetDigest ();
917
897
}
0 commit comments