123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- #include "StdAfx.h"
- #include "Database.h"
- #include "CharacterDatabase.h"
- CCharacterDatabase::CCharacterDatabase(CDatabase *DB)
- {
- m_DB = DB;
- m_hSTMT = DB->m_hSTMT;
- }
- _CHARDESC *CCharacterDatabase::GetCharacterDesc(DWORD dwGUID, _CHARDESC *pBuffer)
- {
- char *command = csprintf("SELECT Account, Name, DeletePeriod, Instances, WorldClass FROM Characters WHERE ID=%u;", dwGUID);
- SQLPrepare(m_hSTMT, (unsigned char *)command, SQL_NTS);
- SQLExecute(m_hSTMT);
- pBuffer->dwGUID = dwGUID;
- *pBuffer->szAccount = 0;
- *pBuffer->szName = 0;
- pBuffer->dwDeletePeriod = 0;
- pBuffer->dwInstances = 0;
- *pBuffer->szWorldClass = 0;
- SQLBindCol(m_hSTMT, 1, SQL_C_CHAR, &pBuffer->szAccount, 60, NULL);
- SQLBindCol(m_hSTMT, 2, SQL_C_CHAR, &pBuffer->szName, 60, NULL);
- SQLBindCol(m_hSTMT, 3, SQL_C_ULONG, &pBuffer->dwDeletePeriod, sizeof(DWORD), NULL);
- SQLBindCol(m_hSTMT, 4, SQL_C_ULONG, &pBuffer->dwInstances, sizeof(DWORD), NULL);
- SQLBindCol(m_hSTMT, 5, SQL_C_CHAR, &pBuffer->szWorldClass, 40, NULL);
- RETCODE retcode = SQLFetch(m_hSTMT);
- if (!(retcode == SQL_SUCCESS) && !(retcode == SQL_SUCCESS_WITH_INFO))
- pBuffer = NULL;
- SQLCloseCursor(m_hSTMT);
- SQLFreeStmt(m_hSTMT, SQL_UNBIND);
- return pBuffer;
- }
- _CHARDESC *CCharacterDatabase::GetCharacterDesc(const char* szName, _CHARDESC *pBuffer)
- {
- char *command = csprintf("SELECT Account, ID, DeletePeriod, Instances, WorldClass FROM Characters WHERE ((Name = \'%s\'));", szName);
- SQLPrepare(m_hSTMT, (unsigned char *)command, SQL_NTS);
- SQLExecute(m_hSTMT);
- *pBuffer->szAccount = 0;
- pBuffer->dwGUID = 0;
- strncpy(pBuffer->szName, szName, 60);
- pBuffer->dwDeletePeriod = 0;
- pBuffer->dwInstances = 0;
- *pBuffer->szWorldClass = 0;
- SQLBindCol(m_hSTMT, 1, SQL_C_CHAR, &pBuffer->szAccount, 60, NULL);
- SQLBindCol(m_hSTMT, 2, SQL_C_ULONG, &pBuffer->dwGUID, sizeof(DWORD), NULL);
- SQLBindCol(m_hSTMT, 3, SQL_C_ULONG, &pBuffer->dwDeletePeriod, sizeof(DWORD), NULL);
- SQLBindCol(m_hSTMT, 4, SQL_C_ULONG, &pBuffer->dwInstances, sizeof(DWORD), NULL);
- SQLBindCol(m_hSTMT, 5, SQL_C_CHAR, &pBuffer->szWorldClass, 40, NULL);
- RETCODE retcode = SQLFetch(m_hSTMT);
- if (!(retcode == SQL_SUCCESS) && !(retcode == SQL_SUCCESS_WITH_INFO))
- pBuffer = NULL;
- SQLCloseCursor(m_hSTMT);
- SQLFreeStmt(m_hSTMT, SQL_UNBIND);
- return pBuffer;
- }
- void CCharacterDatabase::CreateCharacterDesc(const char* szAccount, DWORD dwGUID, const char* szName)
- {
- char *command;
- command = csprintf("INSERT INTO Characters (Account, ID, Name, DeletePeriod, Instances, WorldClass) VALUES ('%s', %lu, '%s', 0, 1, 'human-male');", szAccount, dwGUID, szName);
- SQLPrepare(m_hSTMT, (unsigned char *)command, SQL_NTS);
- SQLExecute(m_hSTMT);
- SQLFreeStmt(m_hSTMT, SQL_UNBIND);
- }
- DWORD CCharacterDatabase::IncCharacterInstance(DWORD dwGUID, DWORD dwLastInstance)
- {
- DWORD dwNewInstance = dwLastInstance + 1;
- char *command = csprintf("UPDATE Characters SET Instances=%u WHERE ID=%u;", dwNewInstance, dwGUID);
- SQLPrepare(m_hSTMT, (unsigned char *)command, SQL_NTS);
- SQLExecute(m_hSTMT);
- SQLCloseCursor(m_hSTMT);
- SQLFreeStmt(m_hSTMT, SQL_UNBIND);
- return dwNewInstance;
- }
- DWORD CCharacterDatabase::GetCharacters(const char *account, DWORD *dwGUIDs)
- {
- char *accountlwr = _strlwr(_strdup(account));
- char *command = csprintf("SELECT ID FROM Characters WHERE (LCase(Account) = \'%s\');", accountlwr);
- free(accountlwr);
- SQLPrepare(m_hSTMT, (unsigned char *)command, SQL_NTS);
- SQLExecute(m_hSTMT);
- DWORD dwCount = 0;
- DWORD dwGUID;
- SQLBindCol(m_hSTMT, 1, SQL_C_ULONG, &dwGUID, sizeof(DWORD), NULL);
- RETCODE rc;
- while (dwCount < 5)
- {
- rc = SQLFetch(m_hSTMT);
- if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO)
- {
- dwGUIDs[dwCount] = dwGUID;
- dwCount++;
- }
- else
- break;
- }
- //MsgBox("Chars: %lu", dwCount);
- SQLCloseCursor(m_hSTMT);
- SQLFreeStmt(m_hSTMT, SQL_UNBIND);
- return dwCount;
- }
|