Browse Source

Clean ansi<->unicode from account name code

Adam Johnson 10 years ago
parent
commit
0aa5a52a33
  1. 6
      Sources/Plasma/Apps/plClient/winmain.cpp
  2. 10
      Sources/Plasma/FeatureLib/pfPython/cyAccountManagement.cpp
  3. 6
      Sources/Plasma/FeatureLib/pfPython/cyAccountManagement.h
  4. 3
      Sources/Plasma/FeatureLib/pfPython/cyAccountManagementGlue.cpp
  5. 2
      Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrSend.cpp
  6. 21
      Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp
  7. 7
      Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h
  8. 41
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp
  9. 6
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h

6
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) {

10
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);
}

6
Sources/Plasma/FeatureLib/pfPython/cyAccountManagement.h

@ -50,10 +50,10 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
//
#include <vector>
#include <string>
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);
};

3
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")

2
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 );

21
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(

7
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 ();

41
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<plString> match = plString::FromWchar(s_accountName).RESearch("[^@]+@([^.]+\\.)*([^.]+)\\.[^.]+");
std::vector<plString> 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<uint16_t> 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<uint16_t> 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
) {

6
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
);

Loading…
Cancel
Save