void WorldSession::LoadAccountDataProc(QueryResult * result) { size_t len; const char * data; char * d; if(!result) { CharacterDatabase.Execute("INSERT INTO account_data VALUES(%u, '', '', '', '', '', '', '', '', '')", _accountId); return; } for(uint32 i = 0; i < 7; i++) { data = result->Fetch()[1+i].GetString(); len = data ? strlen(data) : 0; if(len > 1) { d = new char[len+1]; memcpy(d, data, len+1); SetAccountData(i, d, true, (uint32)len); } } }
bool CAccountManager::LoadXML ( CXMLNode* pParent ) { CLogger::LogPrint ( "Converting Accounts.xml into internal.db\n" ); //##Keep for backwards compatability with accounts.xml## #define ACCOUNT_VALUE_LENGTH 128 std::string strBuffer, strName, strPassword, strIP, strDataKey, strDataValue; if ( pParent ) { CXMLNode* pAccountNode = NULL; unsigned int uiAccountNodesCount = pParent->GetSubNodeCount (); for ( unsigned int i = 0 ; i < uiAccountNodesCount ; i++ ) { pAccountNode = pParent->GetSubNode ( i ); if ( pAccountNode == NULL ) continue; strBuffer = pAccountNode->GetTagName (); if ( strBuffer.compare ( "account" ) == 0 ) { CXMLAttribute* pAttribute = pAccountNode->GetAttributes ().Find ( "name" ); if ( pAttribute ) { strName = pAttribute->GetValue (); pAttribute = pAccountNode->GetAttributes ().Find ( "password" ); if ( pAttribute ) { strPassword = pAttribute->GetValue (); if ( !strName.empty () && !strPassword.empty () ) { pAttribute = pAccountNode->GetAttributes ().Find ( "ip" ); if ( pAttribute ) { strIP = pAttribute->GetValue (); CAccount* pAccount = NULL; pAttribute = pAccountNode->GetAttributes ().Find ( "serial" ); if ( pAttribute ) { //Insert the entry into the accounts database m_pDatabaseManager->Execf ( m_hDbConnection, "INSERT INTO accounts (name, ip, serial, password) VALUES(?,?,?,?)", SQLITE_TEXT, strName.c_str(), SQLITE_TEXT, strIP.c_str(), SQLITE_TEXT, pAttribute->GetValue ().c_str(), SQLITE_TEXT, strPassword.c_str() ); pAccount = new CAccount ( this, true, strName, strPassword, strIP, m_iAccounts++, pAttribute->GetValue () ); } else { //Insert the entry into the accounts database m_pDatabaseManager->Execf ( m_hDbConnection, "INSERT INTO accounts (name, ip, password) VALUES(?,?,?)", SQLITE_TEXT, strName.c_str(), SQLITE_TEXT, strIP.c_str(), SQLITE_TEXT, strPassword.c_str() ); pAccount = new CAccount ( this, true, strName, strPassword, strIP, m_iAccounts++ ); } // Grab the data on this account CXMLNode* pDataNode = NULL; int iType = LUA_TNIL; unsigned int uiDataNodesCount = pAccountNode->GetSubNodeCount (); for ( unsigned int j = 0 ; j < uiDataNodesCount ; j++ ) { pDataNode = pAccountNode->GetSubNode ( j ); if ( pDataNode == NULL ) continue; strBuffer = pDataNode->GetTagName (); if ( strBuffer == "nil_data" ) iType = LUA_TNIL; else if ( strBuffer == "boolean_data" ) iType = LUA_TBOOLEAN; else if ( strBuffer == "string_data" ) iType = LUA_TSTRING; else if ( strBuffer == "number_data" ) iType = LUA_TNUMBER; CXMLAttributes* pAttributes = &(pDataNode->GetAttributes ()); CXMLAttribute* pAttribute = NULL; unsigned int uiDataValuesCount = pAttributes->Count (); for ( unsigned int a = 0 ; a < uiDataValuesCount ; a++ ) { pAttribute = pAttributes->Get ( a ); strDataKey = pAttribute->GetName (); strDataValue = pAttribute->GetValue (); char szKey[128]; STRNCPY( szKey, strDataKey.c_str(), 128 ); SetAccountData( pAccount, szKey, strDataValue, iType ); } } } else { CAccount* pAccount = NULL; pAttribute = pAccountNode->GetAttributes ().Find ( "serial" ); if ( pAttribute ) { //Insert the entry into the accounts database m_pDatabaseManager->Execf ( m_hDbConnection, "INSERT INTO accounts (name, password, serial) VALUES(?,?,?)", SQLITE_TEXT, strName.c_str(), SQLITE_TEXT, strPassword.c_str(), SQLITE_TEXT, pAttribute->GetValue().c_str() ); pAccount = new CAccount ( this, true, strName, strPassword, "", m_iAccounts++, pAttribute->GetValue () ); } else { //Insert the entry into the accounts database m_pDatabaseManager->Execf ( m_hDbConnection, "INSERT INTO accounts (name, password) VALUES(?,?)", SQLITE_TEXT, strName.c_str(), SQLITE_TEXT, strPassword.c_str() ); pAccount = new CAccount ( this, true, strName, strPassword, "", m_iAccounts++, "" ); } } } else { if ( strName == CONSOLE_ACCOUNT_NAME ) { //Add Console to the SQL Database (You don't need to create an account since the server takes care of that m_pDatabaseManager->Execf ( m_hDbConnection, "INSERT INTO accounts (name, password) VALUES(?,?)", SQLITE_TEXT, "Console", SQLITE_TEXT, "" ); ++m_iAccounts; } } } } } else { //Load the settings from XML LoadSetting ( pAccountNode ); } } //Save the settings to SQL SaveSettings(); CLogger::LogPrint ( "Conversion Complete.\n" ); m_bChangedSinceSaved = false; return true; } return false; }