📄 dbagent.cpp
字号:
pUser->m_sItemArray[empty_slot].sDuration = 10000;
break;
case 201:
pUser->m_sItemArray[empty_slot].nNum = 120050000;
pUser->m_sItemArray[empty_slot].sDuration = 5000;
break;
case 202:
pUser->m_sItemArray[empty_slot].nNum = 110050000;
pUser->m_sItemArray[empty_slot].sDuration = 4000;
break;
case 203:
pUser->m_sItemArray[empty_slot].nNum = 180050000;
pUser->m_sItemArray[empty_slot].sDuration = 5000;
break;
case 204:
pUser->m_sItemArray[empty_slot].nNum = 190050000;
pUser->m_sItemArray[empty_slot].sDuration = 10000;
break;
}
pUser->m_sItemArray[empty_slot].sCount = 1;
pUser->m_sItemArray[empty_slot].nSerialNum = 0;
}
return retval;
}
int CDBAgent::UpdateUser(const char *userid, int uid, int type )
{
SQLHSTMT hstmt;
SQLRETURN retcode;
TCHAR szSQL[1024];
SDWORD sStrItem, sStrSkill, sStrSerial;
_USER_DATA* pUser = NULL;
memset( szSQL, 0x00, 1024 );
DBProcessNumber( 3 );
pUser = (_USER_DATA*)m_UserDataArray[uid];
if( !pUser )
return -1;
if( _strnicmp( pUser->m_id, userid, MAX_ID_SIZE ) != 0 )
return -1;
if( type == UPDATE_PACKET_SAVE )
pUser->m_dwTime++;
else if( type == UPDATE_LOGOUT || type == UPDATE_ALL_SAVE )
pUser->m_dwTime = 0;
TCHAR strSkill[10];
TCHAR strItem[400];
TCHAR strSerial[400];
memset( strSkill, 0x00, 10 );
memset( strItem, 0x00, 400 );
memset( strSerial, 0x00, 400 );
sStrSkill = sizeof(strSkill);
sStrItem = sizeof(strItem);
sStrSerial = sizeof(strSerial);
int index = 0, serial_index = 0;
for(int i=0; i<9; i++)
SetByte(strSkill, pUser->m_bstrSkill[i], index);
index = 0;
for(i = 0; i < HAVE_MAX+SLOT_MAX; i++) // 馒侩肮荐 + 家蜡肮荐(14+28=42)
{
if( pUser->m_sItemArray[i].nNum > 0 ) {
if( m_pMain->m_ItemtableArray.GetData(pUser->m_sItemArray[i].nNum) == FALSE )
TRACE("Item Drop Saved(%d) : %d (%s)\n", i, pUser->m_sItemArray[i].nNum, pUser->m_id);
}
SetDWORD(strItem, pUser->m_sItemArray[i].nNum, index);
SetShort(strItem, pUser->m_sItemArray[i].sDuration, index );
SetShort(strItem, pUser->m_sItemArray[i].sCount, index);
SetInt64(strSerial, pUser->m_sItemArray[i].nSerialNum, serial_index );
}
// 累诀 : clan沥焊档 诀单捞飘
wsprintf( szSQL, TEXT( "{call UPDATE_USER_DATA ( \'%s\', %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,?,?,?)}" ),
pUser->m_id, pUser->m_bNation, pUser->m_bRace, pUser->m_sClass, pUser->m_bHairColor, pUser->m_bRank,
pUser->m_bTitle, pUser->m_bLevel, pUser->m_iExp, pUser->m_iLoyalty, pUser->m_bFace,
pUser->m_bCity, pUser->m_bKnights, pUser->m_bFame, pUser->m_sHp, pUser->m_sMp, pUser->m_sSp,
pUser->m_bStr, pUser->m_bSta, pUser->m_bDex, pUser->m_bIntel, pUser->m_bCha, pUser->m_bAuthority, pUser->m_bPoints, pUser->m_iGold, pUser->m_bZone, pUser->m_sBind,
(int)(pUser->m_curx*100), (int)(pUser->m_curz*100), (int)(pUser->m_cury*100), pUser->m_dwTime );
hstmt = NULL;
retcode = SQLAllocHandle( (SQLSMALLINT)SQL_HANDLE_STMT, m_GameDB.m_hdbc, &hstmt );
if (retcode == SQL_SUCCESS)
{
retcode = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(strSkill),0, strSkill,0, &sStrSkill );
retcode = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(strItem),0, strItem,0, &sStrItem );
retcode = SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(strSerial),0, strSerial,0, &sStrSerial );
if(retcode == SQL_SUCCESS)
{
retcode = SQLExecDirect (hstmt, (unsigned char *)szSQL, 1024);
if (retcode==SQL_ERROR)
{
if( DisplayErrorMsg(hstmt) == -1 ) {
m_GameDB.Close();
if( !m_GameDB.IsOpen() ) {
ReConnectODBC( &m_GameDB, m_pMain->m_strGameDSN, m_pMain->m_strGameUID, m_pMain->m_strGamePWD );
return 0;
}
}
SQLFreeHandle((SQLSMALLINT)SQL_HANDLE_STMT,hstmt);
char logstr[1024]; memset( logstr, 0x00, 1024 );
sprintf( logstr, "[Error-DB Fail] %s, Skill[%s] Item[%s] \r\n", szSQL, strSkill, strItem );
m_pMain->WriteLogFile( logstr );
//m_pMain->m_LogFile.Write(logstr, strlen(logstr));
return 0;
}
SQLFreeHandle((SQLSMALLINT)SQL_HANDLE_STMT,hstmt);
return 1;
}
else
SQLFreeHandle((SQLSMALLINT)SQL_HANDLE_STMT,hstmt);
}
return 0;
}
int CDBAgent::AccountLogInReq( char *id, char *pw )
{
SQLHSTMT hstmt = NULL;
SQLRETURN retcode;
TCHAR szSQL[1024];
memset( szSQL, 0x00, 1024 );
SQLSMALLINT sParmRet;
SQLINTEGER cbParmRet=SQL_NTS;
wsprintf( szSQL, TEXT( "{call ACCOUNT_LOGIN( \'%s\', \'%s\', ?)}" ), id, pw);
DBProcessNumber( 4 );
retcode = SQLAllocHandle( (SQLSMALLINT)SQL_HANDLE_STMT, m_GameDB.m_hdbc, &hstmt );
if (retcode == SQL_SUCCESS)
{
retcode = SQLBindParameter(hstmt,1, SQL_PARAM_OUTPUT, SQL_C_SSHORT, SQL_SMALLINT, 0,0, &sParmRet,0, &cbParmRet );
if(retcode == SQL_SUCCESS)
{
retcode = SQLExecDirect (hstmt, (unsigned char *)szSQL, 1024);
if( retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO )
{
SQLFreeHandle((SQLSMALLINT)SQL_HANDLE_STMT,hstmt);
if( sParmRet == 0 )
return -1;
else
return sParmRet-1; // sParmRet == Nation + 1....
}
else
{
if( DisplayErrorMsg(hstmt) == -1 ) {
m_GameDB.Close();
if( !m_GameDB.IsOpen() ) {
ReConnectODBC( &m_GameDB, m_pMain->m_strGameDSN, m_pMain->m_strGameUID, m_pMain->m_strGamePWD );
return FALSE;
}
}
SQLFreeHandle((SQLSMALLINT)SQL_HANDLE_STMT,hstmt);
return FALSE;
}
}
SQLFreeHandle((SQLSMALLINT)SQL_HANDLE_STMT,hstmt);
}
return FALSE;
}
BOOL CDBAgent::NationSelect(char *id, int nation)
{
SQLHSTMT hstmt = NULL;
SQLRETURN retcode;
TCHAR szSQL[1024];
memset( szSQL, 0x00, 1024 );
SQLSMALLINT sParmRet;
SQLINTEGER cbParmRet=SQL_NTS;
wsprintf( szSQL, TEXT( "{call NATION_SELECT ( ?, \'%s\', %d)}" ), id, nation);
DBProcessNumber( 5 );
retcode = SQLAllocHandle( (SQLSMALLINT)SQL_HANDLE_STMT, m_GameDB.m_hdbc, &hstmt );
if (retcode == SQL_SUCCESS)
{
retcode = SQLBindParameter(hstmt, 1, SQL_PARAM_OUTPUT, SQL_C_SSHORT, SQL_INTEGER, 0,0, &sParmRet,0, &cbParmRet );
if(retcode == SQL_SUCCESS)
{
retcode = SQLExecDirect (hstmt, (unsigned char *)szSQL, 1024);
if (retcode==SQL_ERROR)
{
if( DisplayErrorMsg(hstmt) == -1 ) {
m_GameDB.Close();
if( !m_GameDB.IsOpen() ) {
ReConnectODBC( &m_GameDB, m_pMain->m_strGameDSN, m_pMain->m_strGameUID, m_pMain->m_strGamePWD );
return FALSE;
}
}
SQLFreeHandle((SQLSMALLINT)SQL_HANDLE_STMT,hstmt);
return FALSE;
}
SQLFreeHandle((SQLSMALLINT)SQL_HANDLE_STMT,hstmt);
if( sParmRet < 0 )
return FALSE;
else
return TRUE;
}
}
return FALSE;
}
int CDBAgent::CreateNewChar(char *accountid, int index, char *charid, int race, int Class, int hair, int face, int str, int sta, int dex, int intel, int cha)
{
SQLHSTMT hstmt = NULL;
SQLRETURN retcode;
TCHAR szSQL[1024];
memset( szSQL, 0x00, 1024 );
SQLSMALLINT sParmRet;
SQLINTEGER cbParmRet=SQL_NTS;
wsprintf( szSQL, TEXT( "{call CREATE_NEW_CHAR ( ?, \'%s\', %d, \'%s\', %d,%d,%d,%d,%d,%d,%d,%d,%d)}" ), accountid, index, charid, race, Class, hair, face, str, sta, dex, intel, cha );
DBProcessNumber( 6 );
retcode = SQLAllocHandle( (SQLSMALLINT)SQL_HANDLE_STMT, m_GameDB.m_hdbc, &hstmt );
if (retcode == SQL_SUCCESS)
{
retcode = SQLBindParameter(hstmt, 1, SQL_PARAM_OUTPUT, SQL_C_SSHORT, SQL_INTEGER, 0,0, &sParmRet,0, &cbParmRet );
if(retcode == SQL_SUCCESS)
{
retcode = SQLExecDirect (hstmt, (unsigned char *)szSQL, 1024);
if (retcode==SQL_ERROR)
{
if( DisplayErrorMsg(hstmt) == -1 ) {
m_GameDB.Close();
if( !m_GameDB.IsOpen() ) {
ReConnectODBC( &m_GameDB, m_pMain->m_strGameDSN, m_pMain->m_strGameUID, m_pMain->m_strGamePWD );
return -1;
}
}
SQLFreeHandle((SQLSMALLINT)SQL_HANDLE_STMT,hstmt);
return sParmRet;
}
SQLFreeHandle((SQLSMALLINT)SQL_HANDLE_STMT,hstmt);
return sParmRet;
}
SQLFreeHandle((SQLSMALLINT)SQL_HANDLE_STMT,hstmt);
}
return -1;
}
BOOL CDBAgent::DeleteChar(int index, char *id, char *charid, char* socno)
{
SQLHSTMT hstmt = NULL;
SQLRETURN retcode;
TCHAR szSQL[1024];
memset( szSQL, 0x00, 1024 );
SQLSMALLINT sParmRet;
SQLINTEGER cbParmRet=SQL_NTS;
wsprintf( szSQL, TEXT( "{ call DELETE_CHAR ( \'%s\', %d, \'%s\', \'%s\', ? )}" ), id, index, charid, socno );
DBProcessNumber( 7 );
retcode = SQLAllocHandle( (SQLSMALLINT)SQL_HANDLE_STMT, m_GameDB.m_hdbc, &hstmt );
if (retcode == SQL_SUCCESS)
{
retcode = SQLBindParameter(hstmt, 1, SQL_PARAM_OUTPUT, SQL_C_SSHORT, SQL_INTEGER, 0,0, &sParmRet,0, &cbParmRet );
if(retcode == SQL_SUCCESS)
{
retcode = SQLExecDirect (hstmt, (unsigned char *)szSQL, 1024);
if (retcode==SQL_ERROR)
{
if( DisplayErrorMsg(hstmt) == -1 ) {
m_GameDB.Close();
if( !m_GameDB.IsOpen() ) {
ReConnectODBC( &m_GameDB, m_pMain->m_strGameDSN, m_pMain->m_strGameUID, m_pMain->m_strGamePWD );
return FALSE;
}
}
SQLFreeHandle((SQLSMALLINT)SQL_HANDLE_STMT,hstmt);
return FALSE;
}
SQLFreeHandle((SQLSMALLINT)SQL_HANDLE_STMT,hstmt);
return sParmRet;
}
}
return FALSE;
}
BOOL CDBAgent::LoadCharInfo( char *id, char* buff, int &buff_index)
{
SQLHSTMT hstmt;
SQLRETURN retcode;
TCHAR szSQL[1024];
BOOL retval;
CString userid;
userid = id;
userid.TrimRight();
strcpy( id, (char*)(LPCTSTR)userid );
memset(szSQL, 0x00, 1024);
wsprintf(szSQL, TEXT("{call LOAD_CHAR_INFO ('%s', ?)}"), id);
DBProcessNumber( 8 );
SQLCHAR Race = 0x00, HairColor = 0x00, Level = 0x00, Face = 0x00, Zone = 0x00;
SQLSMALLINT sRet, Class;
TCHAR strItem[400];
memset( strItem, 0x00, 400 );
SQLINTEGER Indexind = SQL_NTS;
hstmt = NULL;
retcode = SQLAllocHandle( (SQLSMALLINT)SQL_HANDLE_STMT, m_GameDB.m_hdbc, &hstmt );
if (retcode != SQL_SUCCESS) return FALSE;
retcode = SQLBindParameter(hstmt,1,SQL_PARAM_OUTPUT,SQL_C_SSHORT, SQL_SMALLINT,0,0, &sRet,0,&Indexind);
if (retcode != SQL_SUCCESS){
SQLFreeHandle((SQLSMALLINT)SQL_HANDLE_STMT,hstmt);
return FALSE;
}
retcode = SQLExecDirect (hstmt, (unsigned char *)szSQL, 1024);
if (retcode == SQL_SUCCESS|| retcode == SQL_SUCCESS_WITH_INFO){
retcode = SQLFetch(hstmt);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO){
SQLGetData(hstmt,1 ,SQL_C_TINYINT ,&Race, 0, &Indexind);
SQLGetData(hstmt,2 ,SQL_C_SSHORT ,&Class, 0, &Indexind);
SQLGetData(hstmt,3 ,SQL_C_TINYINT ,&HairColor,0, &Indexind);
SQLGetData(hstmt,4 ,SQL_C_TINYINT ,&Level, 0, &Indexind);
SQLGetData(hstmt,5 ,SQL_C_TINYINT ,&Face, 0, &Indexind);
SQLGetData(hstmt,6 ,SQL_C_TINYINT ,&Zone, 0, &Indexind);
SQLGetData(hstmt,7 ,SQL_C_CHAR ,strItem, 400, &Indexind);
retval =TRUE;
}
else retval = FALSE;
}
else {
if( DisplayErrorMsg(hstmt) == -1 ) {
m_GameDB.Close();
if( !m_GameDB.IsOpen() ) {
ReConnectODBC( &m_GameDB, m_pMain->m_strGameDSN, m_pMain->m_strGameUID, m_pMain->m_strGamePWD );
return FALSE;
}
}
retval= FALSE;
}
SQLFreeHandle((SQLSMALLINT)SQL_HANDLE_STMT,hstmt);
SetShort( buff, strlen( id ), buff_index );
SetString( buff, (char*)id, strlen( id ), buff_index );
SetByte( buff, Race, buff_index );
SetShort( buff, Class, buff_index );
SetByte( buff, Level, buff_index );
SetByte( buff, Face, buff_index );
SetByte( buff, HairColor, buff_index );
SetByte( buff, Zone, buff_index );
int tempid = 0, count = 0, index = 0, duration = 0;
for(int i = 0; i < SLOT_MAX; i++) {
tempid = GetDWORD( strItem, index );
duration = GetShort( strItem, index );
count = GetShort( strItem, index );
if( i == HEAD || i == BREAST || i == SHOULDER || i == LEG || i == GLOVE || i == FOOT ) {
SetDWORD( buff, tempid, buff_index );
SetShort( buff, duration, buff_index );
}
}
return retval;
}
BOOL CDBAgent::GetAllCharID(const char *id, char *char1, char *char2, char *char3, char *char4, char *char5)
{
SQLHSTMT hstmt;
SQLRETURN retcode;
TCHAR szSQL[1024];
BOOL retval;
_USER_DATA* pUser = NULL;
CString Item;
memset(szSQL, 0x00, 1024);
wsprintf(szSQL, TEXT("{? = call LOAD_ACCOUNT_CHARID ('%s')}"), id);
DBProcessNumber( 9 );
SQLSMALLINT sRet;
TCHAR charid1[21], charid2[21], charid3[21], charid4[21], charid5[21];
memset( charid1, 0x00, 21 ); memset( charid2, 0x00, 21 ); memset( charid3, 0x00, 21 ); memset( charid4, 0x00, 21 ); memset( charid5, 0x00, 21 );
SQLINTEGER Indexind = SQL_NTS;
hstmt = NULL;
retcode = SQLAllocHandle( (SQLSMALLINT)SQL_HANDLE_STMT, m_GameDB.m_hdbc, &hstmt );
if (retcode != SQL_SUCCESS) return FALSE;
retcode = SQLBindParameter(hstmt,1,SQL_PARAM_OUTPUT,SQL_C_SSHORT, SQL_SMALLINT,0,0, &sRet,0,&Indexind);
if (retcode != SQL_SUCCESS){
SQLFreeHandle((SQLSMALLINT)SQL_HANDLE_STMT,hstmt);
return FALSE;
}
retcode = SQLExecDirect (hstmt, (unsigned char *)szSQL, 1024);
if (retcode == SQL_SUCCESS|| retcode == SQL_SUCCESS_WITH_INFO){
retcode = SQLFetch(hstmt);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO){
SQLGetData(hstmt,1 ,SQL_C_CHAR ,charid1, 21, &Indexind);
SQLGetData(hstmt,2 ,SQL_C_CHAR ,charid2, 21, &Indexind);
SQLGetData(hstmt,3 ,SQL_C_CHAR ,charid3, 21, &Indexind);
SQLGetData(hstmt,4 ,SQL_C_CHAR ,charid4, 21, &Indexind);
SQLGetData(hstmt,5 ,SQL_C_CHAR ,charid5, 21, &Indexind);
retval = TRUE;
}
else retval = FALSE;
}
else {
if( DisplayErrorMsg(hstmt) == -1 ) {
m_GameDB.Close();
if( !m_GameDB.IsOpen() ) {
ReConnectODBC( &m_GameDB, m_pMain->m_strGameDSN, m_pMain->m_strGameUID, m_pMain->m_strGamePWD );
return FALSE;
}
}
retval= FALSE;
}
if( sRet == 0 )
retval = FALSE;
else {
strcpy( char1, charid1 );
strcpy( char2, charid2 );
strcpy( char3, charid3 );
strcpy( char4, charid4 );
strcpy( char5, charid5 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -