From 0aa5a52a3359ff720f05081b37dfc498daf7489c Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 3 Jan 2015 01:26:18 -0500 Subject: [PATCH] Clean ansi<->unicode from account name code --- Sources/Plasma/Apps/plClient/winmain.cpp | 6 +-- .../pfPython/cyAccountManagement.cpp | 10 ++--- .../FeatureLib/pfPython/cyAccountManagement.h | 6 +-- .../pfPython/cyAccountManagementGlue.cpp | 3 +- .../plNetClient/plNetClientMgrSend.cpp | 2 +- .../plNetClientComm/plNetClientComm.cpp | 21 +++------- .../plNetClientComm/plNetClientComm.h | 7 ++-- .../plNetGameLib/Private/plNglAuth.cpp | 41 ++++++++++--------- .../plNetGameLib/Private/plNglAuth.h | 6 +-- 9 files changed, 44 insertions(+), 58 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/winmain.cpp b/Sources/Plasma/Apps/plClient/winmain.cpp index 7d7e15d6..0ec2804c 100644 --- a/Sources/Plasma/Apps/plClient/winmain.cpp +++ b/Sources/Plasma/Apps/plClient/winmain.cpp @@ -813,7 +813,7 @@ static void SaveUserPass(LoginDialogParam *pLoginParam, char *password) store->SetPassword(pLoginParam->username, plString::Null); } - NetCommSetAccountUsernamePassword(theUser.ToWchar(), pLoginParam->namePassHash); + NetCommSetAccountUsernamePassword(theUser, pLoginParam->namePassHash); // FIXME: Real OS detection NetCommSetAuthTokenAndOS(nil, L"win"); @@ -1270,9 +1270,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nC if (!doIntroDialogs && loginParam.remember) { ENetError auth; - wchar_t wusername[kMaxAccountNameLength]; - StrToUnicode(wusername, loginParam.username, arrsize(wusername)); - NetCommSetAccountUsernamePassword(wusername, loginParam.namePassHash); + NetCommSetAccountUsernamePassword(loginParam.username, loginParam.namePassHash); bool cancelled = AuthenticateNetClientComm(&auth, NULL); if (IS_NET_ERROR(auth) || cancelled) { diff --git a/Sources/Plasma/FeatureLib/pfPython/cyAccountManagement.cpp b/Sources/Plasma/FeatureLib/pfPython/cyAccountManagement.cpp index bcfb33bf..36c7501d 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyAccountManagement.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/cyAccountManagement.cpp @@ -96,13 +96,13 @@ PyObject* cyAccountManagement::GetPlayerList() return pList; } -std::wstring cyAccountManagement::GetAccountName() +plString cyAccountManagement::GetAccountName() { const NetCommAccount* acct = NetCommGetAccount(); if (acct) return acct->accountName; else - return L""; + return ""; } void cyAccountManagement::CreatePlayer(const char* playerName, const char* avatar, const char* invitationCode) @@ -135,9 +135,7 @@ void cyAccountManagement::UpgradeVisitorToExplorer(unsigned playerId) NetCommUpgradeVisitorToExplorer(playerId, nil); } -void cyAccountManagement::ChangePassword(const char* password) +void cyAccountManagement::ChangePassword(const plString& password) { - wchar_t* wpassword = StrDupToUnicode(password); - NetCommChangeMyPassword(wpassword); - free(wpassword); + NetCommChangeMyPassword(password); } diff --git a/Sources/Plasma/FeatureLib/pfPython/cyAccountManagement.h b/Sources/Plasma/FeatureLib/pfPython/cyAccountManagement.h index 4c8ccf8c..62ae866e 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyAccountManagement.h +++ b/Sources/Plasma/FeatureLib/pfPython/cyAccountManagement.h @@ -50,10 +50,10 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com // #include -#include typedef struct _object PyObject; typedef struct PyMethodDef PyMethodDef; +class plString; class cyAccountManagement { @@ -63,14 +63,14 @@ public: static bool IsSubscriptionActive(); static PyObject* GetPlayerList(); - static std::wstring GetAccountName(); + static plString GetAccountName(); static void CreatePlayer(const char* playerName, const char* avatar, const char* invitationCode); static void CreatePlayerW(const wchar_t* playerName, const wchar_t* avatar, const wchar_t* invitationCode); static void DeletePlayer(unsigned playerId); static void SetActivePlayer(unsigned playerId); static bool IsActivePlayerSet(); static void UpgradeVisitorToExplorer(unsigned playerId); - static void ChangePassword(const char* password); + static void ChangePassword(const plString& password); }; diff --git a/Sources/Plasma/FeatureLib/pfPython/cyAccountManagementGlue.cpp b/Sources/Plasma/FeatureLib/pfPython/cyAccountManagementGlue.cpp index d52dc8fc..5f43f53b 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyAccountManagementGlue.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/cyAccountManagementGlue.cpp @@ -61,8 +61,7 @@ PYTHON_GLOBAL_METHOD_DEFINITION_NOARGS(PtGetAccountPlayerList, "Returns list of PYTHON_GLOBAL_METHOD_DEFINITION_NOARGS(PtGetAccountName, "Returns the account name for the current account") { - std::wstring name = cyAccountManagement::GetAccountName(); - return PyUnicode_FromWideChar(name.c_str(), name.length()); + return PyUnicode_FromStringEx(cyAccountManagement::GetAccountName()); } PYTHON_GLOBAL_METHOD_DEFINITION(PtCreatePlayer, args, "Params: playerName, avatarShape, invitation\nCreates a new player") diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrSend.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrSend.cpp index b5758393..347e5ef4 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrSend.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrSend.cpp @@ -155,7 +155,7 @@ void plNetClientMgr::ISendCCRPetition(plCCRPetitionMsg* petMsg) info.AddValue( "Petition", "Content", note ); info.AddValue( "Petition", "Title", title ); info.AddValue( "Petition", "Language", plLocalization::GetLanguageName( plLocalization::GetLanguage() ) ); - info.AddValue( "Petition", "AcctName", NetCommGetAccount()->accountNameAnsi ); + info.AddValue( "Petition", "AcctName", NetCommGetAccount()->accountName.c_str() ); char buffy[20]; sprintf(buffy, "%u", GetPlayerID()); info.AddValue( "Petition", "PlayerID", buffy ); diff --git a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp index 6ef7b068..93f66d88 100644 --- a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp @@ -116,7 +116,7 @@ static plString s_fileSrvAddr; static char s_iniServerAddr[256]; static char s_iniFileServerAddr[256]; -static wchar_t s_iniAccountUsername[kMaxAccountNameLength]; +static plString s_iniAccountUsername; static ShaDigest s_namePassHash; static wchar_t s_iniAuthToken[kMaxPublisherAuthKeyLength]; static wchar_t s_iniOS[kMaxGTOSIdLength]; @@ -737,9 +737,7 @@ void NetCommSetAvatarLoaded (bool loaded /* = true */) { } //============================================================================ -void NetCommChangeMyPassword ( - const wchar_t password[] -) { +void NetCommChangeMyPassword (const plString& password) { NetCliAuthAccountChangePasswordRequest(s_account.accountName, password, INetCliAuthChangePasswordCallback, nil); } @@ -1023,10 +1021,10 @@ void NetCommSetMsgPreHandler ( //============================================================================ void NetCommSetAccountUsernamePassword ( - const wchar_t username[], + const plString& username, const ShaDigest & namePassHash ) { - StrCopy(s_iniAccountUsername, username, arrsize(s_iniAccountUsername)); + s_iniAccountUsername = username; memcpy(s_namePassHash, namePassHash, sizeof(ShaDigest)); s_iniReadAccountInfo = false; @@ -1059,16 +1057,7 @@ void NetCommAuthenticate ( ) { s_loginComplete = false; - StrCopy( - s_account.accountName, - s_iniAccountUsername, - arrsize(s_account.accountName) - ); - StrToAnsi( - s_account.accountNameAnsi, - s_iniAccountUsername, - arrsize(s_account.accountNameAnsi) - ); + s_account.accountName = s_iniAccountUsername; memcpy(s_account.accountNamePassHash, s_namePassHash, sizeof(ShaDigest)); NetCliAuthLoginRequest( diff --git a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h index 95c484f9..178517d2 100644 --- a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h +++ b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h @@ -80,9 +80,8 @@ struct NetCommPlayer { struct NetCommAccount { plUUID accountUuid; - wchar_t accountName[kMaxAccountNameLength]; + plString accountName; ShaDigest accountNamePassHash; - char accountNameAnsi[kMaxAccountNameLength]; unsigned accountFlags; unsigned billingType; }; @@ -108,13 +107,13 @@ const ARRAY(NetCommPlayer) & NetCommGetPlayerList (); unsigned NetCommGetPlayerCount (); bool NetCommIsLoginComplete (); void NetCommSetReadIniAccountInfo (bool readFromIni); -void NetCommSetAccountUsernamePassword (const wchar_t username[], const ShaDigest & namePassHash); +void NetCommSetAccountUsernamePassword (const plString& username, const ShaDigest & namePassHash); void NetCommSetAuthTokenAndOS (wchar_t authToken[], wchar_t os[]); ENetError NetCommGetAuthResult (); bool NetCommNeedToLoadAvatar (); void NetCommSetAvatarLoaded (bool loaded = true); -void NetCommChangeMyPassword (const wchar_t password[]); +void NetCommChangeMyPassword (const plString& password); void NetCommStartup (); void NetCommShutdown (); diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp index d3231ac4..cff07b97 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp @@ -400,13 +400,13 @@ struct AccountChangePasswordRequestTrans : NetAuthTrans { FNetCliAuthAccountChangePasswordRequestCallback m_callback; void * m_param; - // send - wchar_t m_accountName[kMaxAccountNameLength]; + // send + plString m_accountName; ShaDigest m_namePassHash; AccountChangePasswordRequestTrans ( - const wchar_t accountName[], - const wchar_t password[], + const plString& accountName, + const plString& password, FNetCliAuthAccountChangePasswordRequestCallback callback, void * param ); @@ -1203,7 +1203,7 @@ static bool s_running; static CCritSect s_critsect; static LISTDECL(CliAuConn, link) s_conns; static CliAuConn * s_active; -static wchar_t s_accountName[kMaxAccountNameLength]; +static plString s_accountName; static ShaDigest s_accountNamePassHash; static wchar_t s_authToken[kMaxPublisherAuthKeyLength]; static wchar_t s_os[kMaxGTOSIdLength]; @@ -2634,7 +2634,7 @@ bool LoginRequestTrans::Send () { uint32_t clientChallenge = 0; // Regex search for primary email domain - std::vector match = plString::FromWchar(s_accountName).RESearch("[^@]+@([^.]+\\.)*([^.]+)\\.[^.]+"); + std::vector match = s_accountName.RESearch("[^@]+@([^.]+\\.)*([^.]+)\\.[^.]+"); if (match.empty() || match[2].CompareI("gametap") == 0) { memcpy(challengeHash, s_accountNamePassHash, sizeof(ShaDigest)); } else { @@ -2651,11 +2651,13 @@ bool LoginRequestTrans::Send () { ); } + plStringBuffer accountName = s_accountName.ToUtf16(); + const uintptr_t msg[] = { kCli2Auth_AcctLoginRequest, m_transId, clientChallenge, - (uintptr_t) s_accountName, + (uintptr_t) accountName.GetData(), (uintptr_t) &challengeHash, (uintptr_t) s_authToken, (uintptr_t) s_os, @@ -3164,19 +3166,18 @@ bool SetPlayerRequestTrans::Recv ( //============================================================================ AccountChangePasswordRequestTrans::AccountChangePasswordRequestTrans ( - const wchar_t accountName[], - const wchar_t password[], + const plString& accountName, + const plString& password, FNetCliAuthAccountChangePasswordRequestCallback callback, void * param ) : NetAuthTrans(kAccountChangePasswordRequestTrans) +, m_accountName(accountName) , m_callback(callback) , m_param(param) { - StrCopy(m_accountName, accountName, arrsize(m_accountName)); - CryptHashPassword( - plString::FromWchar(m_accountName), - plString::FromWchar(password), + m_accountName, + password, m_namePassHash ); } @@ -3186,10 +3187,12 @@ bool AccountChangePasswordRequestTrans::Send () { if (!AcquireConn()) return false; + plStringBuffer accountName = m_accountName.ToUtf16(); + const uintptr_t msg[] = { kCli2Auth_AcctChangePasswordRequest, m_transId, - (uintptr_t) m_accountName, + (uintptr_t) accountName.GetData(), (uintptr_t) &m_namePassHash, }; @@ -5228,7 +5231,7 @@ void NetCliAuthAccountExistsRequest ( //============================================================================ void NetCliAuthLoginRequest ( - const wchar_t accountName[], + const plString& accountName, const ShaDigest * accountNamePassHash, const wchar_t authToken[], const wchar_t os[], @@ -5236,8 +5239,8 @@ void NetCliAuthLoginRequest ( void * param ) { // Cache updated login info if provided. - if (accountName) - StrCopy(s_accountName, accountName, arrsize(s_accountName)); + if (!accountName.IsEmpty()) + s_accountName = accountName; if (accountNamePassHash) memcpy(s_accountNamePassHash, *accountNamePassHash, sizeof(ShaDigest)); if (authToken) @@ -5437,8 +5440,8 @@ void NetCliAuthGetPublicAgeList ( //============================================================================ void NetCliAuthAccountChangePasswordRequest ( - const wchar_t accountName[], - const wchar_t password[], + const plString& accountName, + const plString& password, FNetCliAuthAccountChangePasswordRequestCallback callback, void * param ) { diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h index 484374d4..dacdb320 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h @@ -135,7 +135,7 @@ typedef void (*FNetCliAuthLoginRequestCallback)( unsigned playerCount ); void NetCliAuthLoginRequest ( - const wchar_t accountName[], // nil --> reuse previous acct name + const plString& accountName, // nil --> reuse previous acct name const ShaDigest * accountNamePassHash, // nil --> reuse previous acct pass const wchar_t authToken[], // nil --> reuse previous auth token const wchar_t os[], // nil --> reuse previous os @@ -271,8 +271,8 @@ typedef void (*FNetCliAuthAccountChangePasswordRequestCallback)( void * param ); void NetCliAuthAccountChangePasswordRequest ( - const wchar_t accountName[], - const wchar_t accountPass[], + const plString& accountName, + const plString& accountPass, FNetCliAuthAccountChangePasswordRequestCallback callback, void * param );