⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mysql.cpp

📁 国内著名网络游戏dragon的服务端完整源码 内附完整数据库结构
💻 CPP
📖 第 1 页 / 共 5 页
字号:
			
			if(retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) {
				MyLog(LOG_NORMAL, "Transact commit Error") ;
			}
			//printf("\n-----Transact & free----") ;
			return(1); // succeed
		}
		else
		{
			displaySQLError(hstmt) ;
			//SQLTransact(SQL_NULL_HENV, hDBC, SQL_ROLLBACK);
			SQLFreeStmt(hstmt, SQL_DROP);
			return(-3); 
		}
	}
	
	SQLFreeStmt(hstmt, SQL_DROP);
	return 1;
}

int updateCharacterStatus(t_connection c[], int char_id)
{		
	CHARLIST *chr= &c[char_id].chrlst;
	if(!::CanSaveUserData(chr,1)){return -1;}
		
	SQLRETURN retcode;
	SQLHSTMT  hstmt;
	char query[2048] = {0,};

	if( strcmp( chr->Name, c[ char_id].name ) )
	{
		MyLog( LOG_NORMAL, "Error :(a) chr->Name = %s   c[ char_id].name = %s", chr->Name, c[ char_id].name );
		return -1;
	}
	
	CheckFightMap(chr->MapName, chr->X, chr->Y, chr );		// 0910 YGI
	//< CSD-HK-030829
	DWORD temp_NWCharacter;
	memcpy(&temp_NWCharacter,&chr->NWCharacter,sizeof(DWORD));
	//> CSD-HK-030829
	char aStepInfo[20];
	chr->GetStepInfo(aStepInfo, sizeof(aStepInfo));
	ConvertSave(aStepInfo); // 历厘阑 困茄 单捞鸥 函屈(阿 鞘靛俊 1甫 歹窃)
	// 柠府巩 积己
	sprintf(query, 
		"UPDATE chr_info "
		"SET lev = %d, spritvalue = %d, social_status = %d, fame = %d, fame_pk = %d, guildname = '%s' "
		      "WHERE name= '%s'",
			  chr->GetLevel(),
			  chr->GetGuildCode(),
			  chr->social_status,
			  chr->fame,
			  temp_NWCharacter, // CSD-HK-030829
			  aStepInfo,
			  c[char_id].name);  // CSD-030806
	SQLAllocStmt(hDBC, &hstmt);
	retcode = SQLExecDirect(hstmt, (UCHAR *)query, SQL_NTS);
	if(retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) 
	{	
		displaySQLError(hstmt) ;
		//SQLTransact(SQL_NULL_HENV, hDBC, SQL_ROLLBACK);
		SQLFreeStmt(hstmt, SQL_DROP);
		return -1 ;
	}	
	else {
		//SQLTransact(SQL_NULL_HENV, hDBC, SQL_COMMIT);
		SQLFreeStmt(hstmt, SQL_DROP) ;
	}	
	
	DWORD nation;		//1004 YGI
	memcpy( &nation, &chr->name_status, sizeof( DWORD ) );
	
	sprintf(query, "UPDATE chr_info SET"
		" Str= %d, Con= %d, Dex= %d, Wis= %d, "
		" Int= %d, MoveP= %d, Char= %d, Endu= %d, Moral= %d, Luck= %d, wsps= %d, tactics= %d, nation = %d, Money= %d, Hp= %d, HpMax = %d, "
		" mana= %d, manamax= %d, condition= %d, mapname='%s', sight= %d, Age= %d, bAlive= %d "
		" where name= '%s'"
		, chr->Str, chr->Con, chr->Dex, chr->Wis,
		chr->Int, chr->MoveP, chr->Char, chr->Endu, chr->Moral, chr->Luck, chr->wsps, chr->Tactics, nation, chr->Money, chr->Hp, chr->HpMax,		//1004 YGI
		chr->Mana, chr->ManaMax, 
		chr->GetState(), 
		chr->MapName, 
		chr->Sight, 
		chr->Age, 
		chr->bAlive, 
		c[char_id].name);
	SQLAllocStmt(hDBC, &hstmt) ;
	retcode = SQLExecDirect(hstmt, (UCHAR *)query, SQL_NTS);
	if(retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) {
		displaySQLError(hstmt) ;
		//SQLTransact(SQL_NULL_HENV, hDBC, SQL_ROLLBACK);
		SQLFreeStmt(hstmt, SQL_DROP);
		return -1 ;
	}	
	else {
		//SQLTransact(SQL_NULL_HENV, hDBC, SQL_COMMIT);
		SQLFreeStmt(hstmt, SQL_DROP) ;
	}	
	
	sprintf(query, "UPDATE chr_info SET"
		" hungry= %d, hungrymax= %d, killmon= %d, "
		" killanimal= %d, killpc = %d, resist_poison= %d, resist_stone= %d, resist_magic= %d, resist_fire= %d, "
		" resist_ice= %d, resist_elect= %d, x=%d, y=%d, "
		" acc_equip1= %d, acc_equip2= %d, acc_equip3= %d, acc_equip4= %d "
		" where name= '%s'"
		,chr->Hungry, chr->HungryMax, chr->killmon,
		chr->killanimal, chr->killpc, 
		
		chr->GetBasicResist(RT_POISON), // 历林拌凯 付过俊 措茄 历亲仿
		chr->GetBasicResist(RT_CURSE),	 //	历林拌凯 付过俊 措茄 历亲仿
		chr->GetBasicResist(RT_HOLY),    // 脚仿拌凯 傍拜 付过俊 措茄 历亲仿
		chr->GetBasicResist(RT_FIRE),     //	阂拌凯 傍拜 付过俊 措茄 历亲仿
		chr->GetBasicResist(RT_ICE) ,      //	倔澜拌凯 傍拜 付过俊 措茄 历亲仿
		chr->GetBasicResist(RT_ELECT),   //	傈拜拌凯 傍拜 付过俊 措茄 历亲仿
		chr->X, chr->Y,
		chr->accessory[0], chr->accessory[1], chr->accessory[2], chr->accessory[3], 
		c[char_id].name) ;  
	
	SQLAllocStmt(hDBC, &hstmt) ;
	retcode = SQLExecDirect(hstmt, (UCHAR *)query, SQL_NTS);
	if(retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) {
		displaySQLError(hstmt) ;
		//SQLTransact(SQL_NULL_HENV, hDBC, SQL_ROLLBACK);
		SQLFreeStmt(hstmt, SQL_DROP);
		return -1 ;
	}	
	else {
		//SQLTransact(SQL_NULL_HENV, hDBC, SQL_COMMIT);
		SQLFreeStmt(hstmt, SQL_DROP) ;
	}	
	
	
	// 010406 YGI
	// 010531 KHS
	DWORD win_defeat;
	memcpy( &win_defeat, &chr->WinLoseScore, sizeof(DWORD) );
	
	sprintf(query, "UPDATE chr_info SET"
		" openhouse = %d, reserved_point= %d,"
		" bankmoney= %u, win_defeat = %d, LastLoan= %d, exp = %u, "
		" disease1=%d, disease2=%d, disease3=%d, disease4=%d, disease5=%d, disease6=%d, viewtype= %d, "
		" ladderscore = %d, nut1=%d, nut2=%d, nut3=%d "
		" where name= '%s'",
		chr->openhouse,
		chr->GetReservedPoint(),
		chr->GetBankMoney(),
		win_defeat,
		chr->LastLoan,
		//chr->LastLoan_time,
		chr->Exp,
		0, 0, 0, 0, 0, 0,
		chr->viewtype,
		chr->LadderScore,
		chr->nk[ N_VYSEUS], 
		chr->nk[ N_ZYPERN], 
		chr->nk[ N_YILSE], 
		c[char_id].name);  
	
	SQLAllocStmt(hDBC, &hstmt) ;
	retcode = SQLExecDirect(hstmt, (UCHAR *)query, SQL_NTS);
	if(retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) {
		printf("\n Update Character: Exec Direct Error ; %s", query) ;
		displaySQLError(hstmt) ;
		//SQLTransact(SQL_NULL_HENV, hDBC, SQL_ROLLBACK);
		SQLFreeStmt(hstmt, SQL_DROP);
		return -1 ;
	}
	else {
		//SQLTransact(SQL_NULL_HENV, hDBC, SQL_COMMIT);
		SQLFreeStmt(hstmt, SQL_DROP) ;
	}
	
	
	///////////////////////// 0218 YGI ////////////////////////
	
	EndsetPartyMenberForUpdate( chr );
	
	if( update_BinaryData_to_Chr_Info(	(UCHAR *)chr->Ws, 
		(UCHAR *)chr->Ps, 
		(UCHAR *)chr->Skill, 
		(UCHAR *)chr->skillexp, 
		(UCHAR *)chr->tac_skillEXP,
		(UCHAR *)var[ char_id],
		(UCHAR *)chr->inv, 
		(UCHAR *)chr->equip, 
		(UCHAR *)chr->quick, 
		(UCHAR *)chr->party_str, 
		(UCHAR *)chr->relation_str, 
		(UCHAR *)chr->employment_str, 
		(UCHAR *)chr->Item, 
		c[char_id].id, c[char_id].name) < 0) {		//1219 YGI
		printf("\n Update Character: Update BIN Error") ;
		return -2 ;
	}
	else 
	{
		if( update_BinaryData_to_Chr_Info2(  (UCHAR *)chr->bank, c[char_id].id, c[char_id].name) < 0) 
			return -2;
	}
	
	return 1 ;
}

void updateCharacterVeryImportantStatusToLoginServer( t_connection c[], int char_id )
{
	LPCHARLIST ch = &c[ char_id].chrlst;
	
	if(!::CanSaveUserData(ch,2)){return;}

	t_packet p;
	t_update_very_important_status *tp = NULL;
	p.h.header.type = CMD_UPDATE_VERY_IMPORTANT_STATUS;
	p.h.header.size = sizeof( t_update_very_important_status );
	tp = &p.u.update_very_important_status;
	
	strcpy( tp->name,	c[char_id].name );
	
	tp->Level = ch->GetLevel(); // CSD-030806
	
	tp->Str  				= ch->Str;
	tp->Con  				= ch->Con;
	tp->Dex  				= ch->Dex;
	tp->Wis  				= ch->Wis;
	tp->Int  				= ch->Int;
	tp->MoveP				= ch->MoveP;
	tp->Char 				= ch->Char;
	tp->Endu 				= ch->Endu;
	tp->Moral				= ch->Moral;
	tp->Luck 				= ch->Luck;
	tp->wsps 				= ch->wsps;
	tp->HpMax				= ch->HpMax ;
	tp->ManaMax				= ch->ManaMax;
	tp->HungryMax			= ch->HungryMax;
	tp->reserved_point = ch->GetReservedPoint();
	tp->Exp					= ch->Exp;
	
	QueuePacket( connections, DB_DEMON, &p, 1 );
}

void updateCharacterVeryImportant_TacticsSkillExp_ToLoginServer( t_connection c[], int char_id )
{
	LPCHARLIST ch = &c[ char_id].chrlst;
	
	if(!::CanSaveUserData(ch,3)){return;}
	
	t_packet p;
	t_update_very_important_tactics *tp = NULL;

	p.h.header.type = CMD_UPDATE_VERY_IMPORTANT_TACTICS;
	p.h.header.size = sizeof( t_update_very_important_tactics );
	tp = &p.u.update_very_important_tactics;
	
	strcpy( tp->name,	c[char_id].name );
	memcpy( tp->tac_skillEXP, c[ char_id].chrlst.tac_skillEXP, SIZE_OF_TAC_SKILL_EXP );
	
	QueuePacket( connections, DB_DEMON, &p, 1 );
}							


//acer5-----------------------------------
int AddCRC( void *pSource, int size, int step )
{
	int count = 0;
	for( int i=0; i<size; i+=step )
	{
		count += ((char*)pSource)[i];
	}
	return count;
}
// --------------------------------------------

void updateCharacterStatusToLoginServer( t_connection c[], int char_id)
{
	t_packet p;
	t_update_char_db *tp;
	LPCHARLIST ch = &c[ char_id].chrlst;
	
	if(!::CanSaveUserData(ch,4)){return;}
	
	p.h.header.type = CMD_UPDATE_CHAR_DB;
	tp = &p.u.update_char_db;
	
	strcpy( tp->id,		c[char_id].id );
	strcpy( tp->name,	c[char_id].name );
	
	tp->Level = ch->GetLevel(); // CSD-030806
	tp->nGuildCode		= ch->GetGuildCode(); // CSD-030324
	tp->social_status	= ch->social_status;
	tp->fame			= ch->fame;
	tp->NWCharacter		= ch->NWCharacter;			// 011015 LTS
	
	tp->Str  				= ch->Str;
	tp->Con  				= ch->Con;
	tp->Dex  				= ch->Dex;
	tp->Wis  				= ch->Wis;
	tp->Int  				= ch->Int;
	tp->MoveP				= ch->MoveP;
	tp->Char 				= ch->Char;
	tp->Endu 				= ch->Endu;
	tp->Moral				= ch->Moral;
	tp->Luck 				= ch->Luck;
	tp->wsps 				= ch->wsps;
	
	tp->Tactics 			= ch->Tactics;				// 急琶茄 傈捧扁贱 (焊咯林扁 困窃)
	memcpy( &tp->nation, &ch->name_status, sizeof( DWORD ) );		// 1004 YGI
	tp->Money = ch->Money;
	tp->Hp = ch->Hp;
	tp->HpMax = ch->HpMax ;
	tp->Mana = ch->Mana;					// 付过仿
	tp->ManaMax	= ch->ManaMax;
	tp->Hungry = ch->Hungry;	
	tp->HungryMax = ch->HungryMax;

	tp->Condition	= ch->GetState();
	memcpy( tp->MapName, MapName, 20 );
	tp->Sight = ch->Sight;
	tp->Age = ch->Age;
	tp->bAlive		= ch->bAlive;					// 某腐磐狼 积荤咯何(	REMOVE_:0 / ALIVE_:1 / DEAD_:2 / BUFE_:3)
	
	tp->killmon = ch->killmon;						// 1拌凯阁胶磐 懦傅胶
	tp->killanimal = ch->killanimal;				// 悼拱 懦傅荐
	tp->killpc = ch->killpc;						// 荤恩,NPC 懦傅荐
	//030227 lsw
	tp->nPoison = ch->GetBasicResist(RT_POISON); // 历林拌凯 付过俊 措茄 历亲仿
	tp->nCurse	= ch->GetBasicResist(RT_CURSE);	 //	历林拌凯 付过俊 措茄 历亲仿
	tp->nHoly	= ch->GetBasicResist(RT_HOLY);    // 脚仿拌凯 傍拜 付过俊 措茄 历亲仿
	tp->nFire	= ch->GetBasicResist(RT_FIRE);     //	阂拌凯 傍拜 付过俊 措茄 历亲仿
	tp->nIce	= ch->GetBasicResist(RT_ICE);       //	倔澜拌凯 傍拜 付过俊 措茄 历亲仿
	tp->nElect	= ch->GetBasicResist(RT_ELECT);   //	傈拜拌凯 傍拜 付过俊 措茄 历亲仿
	
	tp->X = ch->X;
	tp->Y = ch->Y;
	
	tp->accessory[0] = ch->accessory[0];
	tp->accessory[1] = ch->accessory[1];
	tp->accessory[2] = ch->accessory[2];
	tp->accessory[3] = ch->accessory[3];
	
	tp->openhouse		= ch->openhouse;
	tp->reserved_point  = ch->GetReservedPoint();
	tp->BankMoney		= ch->GetBankMoney();
	// 010406 YGI
	memcpy( &tp->win_defeat, &ch->WinLoseScore, sizeof( DWORD ) );
	tp->LadderScore	=	ch->LadderScore;
	
	tp->LastLoan		= ch->LastLoan;
	//tp->LastLoan_time	= ch->LastLoan_time;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -