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

📄 mysql.cpp

📁 国内著名网络游戏dragon的服务端完整源码 内附完整数据库结构
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		retCode = SQLFetch(hStmt);
		
		if(retCode == SQL_SUCCESS)
		{
			// "Select  BankMoney, LastTotal, LastLoan, LastLoan_time, "
			retCode = SQLGetData(hStmt,  1, SQL_C_CHAR, money, 11, &cbValue);		ch->BankMoney		= (DWORD )::atof( money );
			
			//retCode = SQLGetData(hStmt,  2, SQL_C_ULONG, &t, 0, &cbValue);			ch->LastTotal		= t;	// 010314 YGI
			retCode = SQLGetData(hStmt,  2, SQL_C_ULONG, &t, 0, &cbValue);			ch->LastLoan		= t;	
			//retCode = SQLGetData(hStmt,  4, SQL_C_ULONG, &t, 0, &cbValue);			ch->LastLoan_time	= t;
			
			//"nut1, nut2, nut3, killmon, killanimal, killpc, ", 
			retCode = SQLGetData(hStmt,  3, SQL_C_ULONG, &t, 0, &cbValue);			ch->nk[ N_VYSEUS] = (short )t;	
			retCode = SQLGetData(hStmt,  4, SQL_C_ULONG, &t, 0, &cbValue);			ch->nk[ N_ZYPERN] = (short )t;	
			retCode = SQLGetData(hStmt,  5, SQL_C_ULONG, &t, 0, &cbValue);			ch->nk[ N_YILSE]  = (short )t;	
			retCode = SQLGetData(hStmt,  6, SQL_C_ULONG, &t, 0, &cbValue);			ch->killmon 		= t;	
			retCode = SQLGetData(hStmt,  7, SQL_C_ULONG, &t, 0, &cbValue);			ch->killanimal		= t;	
			retCode = SQLGetData(hStmt,  8, SQL_C_ULONG, &t, 0, &cbValue);			ch->killpc			= t;	
			//"reserved_point ", 
			retCode = SQLGetData(hStmt,  9, SQL_C_ULONG, &t, 0, &cbValue);			ch->reserved_point	= (short )t;	
			// 
			retCode = SQLGetData(hStmt, 10, SQL_C_ULONG, &t, 0, &cbValue);			ch->Tactics			= (unsigned char )t;	
			
			//"win_defeat, LadderScore  ",
			retCode = SQLGetData(hStmt, 11, SQL_C_ULONG, &t, 0, &cbValue);			memcpy( &ch->WinLoseScore, &t, sizeof( DWORD ) );
			retCode = SQLGetData(hStmt, 12, SQL_C_ULONG, &t, 0, &cbValue);			ch->LadderScore	= t;
			
			
			SQLFreeStmt(hStmt, SQL_DROP);
			
			//---------------------------------- //DB俊辑 Data甫 啊廉柯第 拌魂且巴捞 乐栏搁 拌魂茄促. 
			//			ch->bAlive	= ALIVE_;
			//			ch->Condition = 0x00;
			//			if( ch->Hp <= 0 ) ch->Hp = 1;
			//-----------------------------------
			
			return(1);
		}
		else
		{
			SQLFreeStmt(hStmt, SQL_DROP);		// 0308 YGI
			return(-2);
		}
	}
	SQLFreeStmt(hStmt, SQL_DROP);		// 0308 YGI
	return(-1);
};


// 荤侩窍瘤 臼绰促. 0309 KHS 
int GetNameCount_SQL(LPSTR szUID)
{		
	HSTMT hStmt = NULL;
	RETCODE retCode;
	char szQuerry[255];
	int  Num;
	
	Num = 0;
	
	//sprintf(szQuerry, "select name from chr_info where login_id='%s'", szUID);
	/////////////////////////////////////////////////////////////////////////////
	sprintf(szQuerry, "EXEC up_get_char_reg_name '%s'", szUID);
	/////////////////////////////////////////////////////////////////////////////
	
	SQLAllocStmt(hDBC, &hStmt);
	retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
	if(retCode == SQL_SUCCESS || retCode == SQL_SUCCESS_WITH_INFO)
	{
		retCode = SQLFetch(hStmt);
		
		while(retCode == SQL_SUCCESS)
		{
			Num ++;
			
			retCode = SQLFetch(hStmt);
		}
		
		SQLFreeStmt(hStmt, SQL_DROP);
	}
	SQLFreeStmt(hStmt, SQL_DROP);		// 0308 YGI
	return(Num);
};

int CheckName2_SQL(LPSTR szUNM)
{
	char		szQuerry[255];
	HSTMT		hStmt = NULL;
	RETCODE		retCode;
	
	//sprintf(szQuerry, "select login_id from chr_info2 where name='%s'", szUNM);
	/////////////////////////////////////////////////////////////////////////////
	sprintf(szQuerry, "EXEC up_get_login_id2 '%s'", szUNM);
	/////////////////////////////////////////////////////////////////////////////
	
	SQLAllocStmt(hDBC, &hStmt);
	retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
	if(retCode == SQL_SUCCESS || retCode == SQL_SUCCESS_WITH_INFO)
	{	
		retCode = SQLFetch(hStmt);
		SQLFreeStmt(hStmt, SQL_DROP);
		
		if(retCode == SQL_SUCCESS || retCode == SQL_SUCCESS_WITH_INFO)
			return(1);
		else	return(0);
	}
	
	return(0); // Invalid Name
};

int CheckName_SQL(LPSTR szUNM)
{
	char		szQuerry[255];
	HSTMT		hStmt = NULL;
	RETCODE		retCode;
	
	//sprintf(szQuerry, "select login_id from chr_info where name='%s'", szUNM);
	/////////////////////////////////////////////////////////////////////////////
	sprintf(szQuerry, "EXEC up_get_login_id '%s'", szUNM);
	/////////////////////////////////////////////////////////////////////////////
	SQLAllocStmt(hDBC, &hStmt);
	retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
	if(retCode == SQL_SUCCESS || retCode == SQL_SUCCESS_WITH_INFO)
	{
		retCode = SQLFetch(hStmt);
		SQLFreeStmt(hStmt, SQL_DROP);
		
		if(retCode == SQL_SUCCESS || retCode == SQL_SUCCESS_WITH_INFO)
		{
			return 	1;
		}
		else	
		{
			int ret = CheckName2_SQL( szUNM );
			return ret;
		}
	}
	
	
	return(0); // Invalid Name
};


/*********************************************
**********************************************/
// Chr_info俊辑 login_id啊 啊瘤绊 乐绰  name阑 茫酒 chr_info 俊 持绰促. 
int CreateChar_SQL(t_connection c[], int cn, t_packet *packet)
{
	HSTMT hStmt = NULL;
	RETCODE retCode;
	char szQuerry[2048];
	//	int Count;
	LPCHARLIST ch = &c[cn].chrlst;
	DWORD total_id;
	
	char *cheak_name = packet->u.client_create_char.name;
	if( CheckName_SQL( cheak_name ) == 1 || 
		SearchStrWord( cheak_name ) || 
		SearchStrStr( cheak_name, " ") ||
		IsBlockedId(cheak_name)
		) // 捞抚捞 乐栏搁... // 0208 YGI
	{
		return(-100); // Invalid ID	// 捞固 乐绰 某腐磐
	}
	
	
	// DB俊辑 磊悼积汲等促. 
	//		Count = GetNameCount_SQL(c[cn].id);
	//		if(Count >= 4)
	//			return(-2); // Over
	
	CreateCharacter( c, cn, packet); // 弥檬 某腐磐狼  积己困摹, 扁夯荐摹, Item甸阑 Setting茄促. NPC_Pattern.cpp
	
	total_id = GetCharID_SQL();
	if( total_id == 0 )  return -1; // Total ID甫 且寸罐瘤 给沁绢夸..
	
	ch->total_id = total_id;
	
	DWORD nation=0;// 1004 YGI
	memcpy( &nation, &ch->name_status,  sizeof( DWORD ) );
	ConvertSave(ch->aStepInfo); // CSD-TW-030620

	sprintf(szQuerry, 	
		"insert into chr_info (name, login_id, gender, face, age, spritvalue, total_id,"
		"clothr, clothg, clothb, bodyr, bodyg, bodyb, "
		"tactics, job, spell, str, con, dex, wis, int, movep, char, reserved_point, "
		"endu, moral, luck, wsps, nation,  x, y, sprno,"
		"race, class, hp, hpmax, mana, manamax, hungry, hungrymax, money, " 
		"nut1, nut2, nut3, "
		"acc_equip1, acc_equip2, acc_equip3, acc_equip4, "
		"sight, lev, exp, MapName, condition, "
		"resist_poison, resist_stone, resist_magic, resist_fire, resist_ice, resist_elect, "
		"guildname, bankmoney  "
		") values "
		"('%s', '%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, "
		"%d, %d, %d, %d, %d, %d, %d, %d, %d, " 
		"%d, %d, %d, " 
		"%d, %d, %d, %d, " // accessory..
		"%d, %d, %d, '%s', %d, "
		"%d, %d, %d, %d, %d, %d, '%s', 0"
		")",
		ch->Name,
		c[cn].id,
		ch->Gender, 
		ch->Face, 
		ch->Age, 
		ch->nGuildCode, // CSD-030324
		ch->total_id,
		ch->ClothR,	ch->ClothG,	ch->ClothB,		// 鹅 祸彬 R.G.B
		ch->BodyR,	ch->BodyG,	ch->BodyB,		// 个 祸彬 R.G.B
		//"tactics, job, spell, str, con, dex, wis, int, movep, char, "
		ch->Tactics, 
		ch->Job, 
		ch->Spell, 
		ch->Str,
		ch->Con,
		ch->Dex,
		ch->Wis,
		ch->Int,
		ch->MoveP,
		ch->Char,
		ch->reserved_point,
		//"endu, moral, luck, wsps, nation,  x, y, sprno,"
		ch->Endu,
		ch->Moral,
		ch->Luck,
		ch->wsps,
		nation, // 1004 YGI
		ch->X,
		ch->Y,
		ch->Gender,
		//			"race, class, hp, hpmax, mana, manamax, hungry, hungrymax, money, " 
		ch->Race,
		ch->Class,
		ch->Hp,
		ch->HpMax,
		ch->Mana,
		ch->ManaMax,
		ch->Hungry,
		ch->HungryMax,
		ch->Money,
		//			"nut1, nut2, nut3, "
		ch->nk[ N_VYSEUS],
		ch->nk[ N_ZYPERN],
		ch->nk[ N_YILSE],
		
		//			"acc_equip1, acc_equip2, acc_equip3, acc_equip4, "
		ch->accessory[0],
		ch->accessory[1],
		ch->accessory[2],
		ch->accessory[3],
		//			"sight, lev, exp, MapName"
		ch->Sight,
		ch->Level,
		ch->Exp,
		ch->MapName,
		ch->Condition,
		//			"resis_poison, resis_stone,	resis_magic, resis_fire, resis_ice, resis_elect "
		ch->nPoison,
		ch->nCurse,
		ch->nHoly,
		ch->nFire,
		ch->nIce,
		ch->nElect,
		ch->aStepInfo); // CSD-TW-030620
	// 某腐磐狼 老馆 Data甫 chr_info俊 积己窍绊 ( 1-1窜拌 )
	SQLAllocStmt(hDBC, &hStmt);
	retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
	if(retCode == SQL_SUCCESS || retCode == SQL_SUCCESS_WITH_INFO)
	{
		//			SQLTransact(SQL_NULL_HENV, hDBC, SQL_COMMIT);
		SQLFreeStmt(hStmt, SQL_DROP);
		
		// 某腐磐狼 Binary Data甫 chr_info俊 积己窍绊 ( 1-2窜拌 )
		// 0218 YGI #######################
		//			EndsetPartyMenberForUpdate( ch );		// 颇萍盔甸 捞抚 弓澜	// 0219 Create俊辑绰 鞘夸 绝澜.
		// 某腐磐狼 Binary Data甫 chr_info俊 积己窍绊 ( 1-2窜拌 )
		int ret = update_BinaryData_to_Chr_Info
			(	(UCHAR *)ch->Ws,   
			(UCHAR *)ch->Ps,     
			(UCHAR *)ch->Skill,  
			(UCHAR *)ch->skillexp,
			(UCHAR *)ch->tac_skillEXP,
			(UCHAR *)var[ cn], 						// 1219 YGI
			(UCHAR *)ch->inv,  
			(UCHAR *)ch->equip, 
			(UCHAR *)ch->quick, 
			(UCHAR *)ch->party_str, 
			(UCHAR *)ch->relation_str, 
			(UCHAR *)ch->employment_str, 
			(UCHAR *)ch->Item, 
			c[cn].id, ch->Name );
		//####################################
		if( ret == 1 ) 
		{
			// 某腐磐狼 老馆 Data甫 chr_info2俊 积己窍绊 ( 2-1窜拌 )
			ret = CreateChar2_SQL(c, cn);
			if( ret == 1 ) // 己傍..
			{
				// 某腐磐狼 老馆 Data甫 chr_info2俊 积己窍绊 ( 2-1窜拌 ) -- Character积己 场.
				ret = update_BinaryData_to_Chr_Info2(  (UCHAR *)ch->bank, c[cn].id, ch->Name );
				
				if( ret == 1 ) 
				{
					
					return 1; // 己傍...
				}
				return ret; // 角菩.
			}
			else  return ret; // 角菩.
		}
		else   return ret; // 角菩.
	}
	else
	{
		FILE *fp;
		fp = fopen( "QuerryError.txt","at+" );
		if( fp )
		{
			fprintf( fp, szQuerry );
			fclose(fp);
		}
		
		//			SQLTransact(SQL_NULL_HENV, hDBC, SQL_ROLLBACK);
		SQLFreeStmt(hStmt, SQL_DROP);
		return(-3); // unknown error
	}
	
	return 0;
};	




int delete_char_create_fail( LPSTR name )		// 0411_2 YGI		// 捞扒 肋给 积己等 版快 昏力窍绰 窃荐
{	
	HSTMT		hStmt = NULL;
	RETCODE		retCode;
	char		szQuerry[255];
	
	sprintf(szQuerry, "DELETE chr_info WHERE name='%s'", name );
	SQLAllocStmt(hDBC, &hStmt);
	retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
	SQLFreeStmt(hStmt, SQL_DROP);
	
	sprintf(szQuerry, "DELETE chr_info2 WHERE name='%s'", name );
	SQLAllocStmt(hDBC, &hStmt);
	retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
	SQLFreeStmt(hStmt, SQL_DROP);
	
	return 1;
}	


/*****************************************************************************************
CreateChar_SQL()篮  DB狼 Chr_info狼  Table俊 货肺款 Character沥焊甫 Insert窍绊 
CreateChar2_SQL()篮 DB狼 Chr_info2 Table俊 Character沥焊甫 Insert茄促.
Insert登绰 field绰 

  name, login_id..
		
***********************************************************************************************/
int CreateChar2_SQL(t_connection c[], int cn )		// 0302 YGI
{
	HSTMT hStmt = NULL;
	RETCODE retCode;
	SDWORD cbValue ;
	char szQuerry[1024];
	char select_name[20] ={0, };
	//int Count;
	LPCHARLIST ch = &c[cn].chrlst;
	
	sprintf( szQuerry, 
		//	某腐磐檬扁拳	捞饶角青 0405 KHS
		"insert into chr_info2 (name, login_id , new) values "		// 0405 YGI new char
		"('%s', '%s', 0  )",
		ch->Name,	c[cn].id );
				
	SQLAllocStmt(hDBC, &hStmt);
	retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);

⌨️ 快捷键说明

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