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

📄 menuserver.cpp

📁 国内著名网络游戏dragon的服务端完整源码 内附完整数据库结构
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		if( token == NULL ) break;

		token = strtok(NULL, "\t\n\r");		// 迫扁 荤扁 加己
		if( token == NULL ) break;
		storelist_attr[num][i] = atoi( token );

		i++;		

		// 010522 KHS
		if( i >= MAX_STORE_ITEM_LIST ) 
		{
			MyLog( LOG_NORMAL, "**** Error :  %s ItemList Number is more than 'MAX_STORE_ITEM_LIST' ", filename );
			break;
		}
	}

	fclose( fp );

	SortingItem( storelist[num], storelist_attr[num], i );

	return i;
}

void swap_kein( void *a, void *b, void *t, int size )
{
	memcpy( t, a, size );
	memcpy( a, b, size );
	memcpy( b, t, size );
}

void SortingItem( ItemAttr *item_list, int *list_int, int &max )
{
	ItemAttr temp;	
	for( int i=0; i<max-1; i++ )
	{
		CItem *item_i = ItemUnit( item_list[i] );
		if( !item_i ) 
		{
			item_list[i] = item_list[max-1];
			list_int[i] = list_int[max-1];
			i=-1;
			max--;
			continue;
		}

		for( int j=i; j<max; j++ )
		{
			int type_i = item_list[i].item_no / 1000;
			int type_j = item_list[j].item_no / 1000;

			CItem *item_i = ItemUnit( item_list[i] );

			if( type_i > type_j ) 
			{
				swap_kein( &item_list[i], &item_list[j], &temp, sizeof( ItemAttr ) );
				swap( &list_int[i], &list_int[j] );
				continue;
			}

			if( type_i == type_j )
			{
				CItem *item_j = ItemUnit( item_list[j] );
				if( !item_j ) continue;
				
				//if( item_i->GetWearAble() > item_j->GetWearAble() )
				if( item_i->GetSkill_Ability() > item_j->GetSkill_Ability() )
				{
					swap_kein( &item_list[i], &item_list[j], &temp, sizeof( ItemAttr ) );
					swap( &list_int[i], &list_int[j] );
					continue;					
				}

				//if( item_i->GetWearAble() == item_j->GetWearAble() )
				if( item_i->GetSkill_Ability() == item_j->GetSkill_Ability() )
				{
					if( item_i->GetSkill_Ability() )
					{
						if( item_i->GetLevel() > item_j->GetLevel() )
						{
							swap_kein( &item_list[i], &item_list[j], &temp, sizeof( ItemAttr ) );
							swap( &list_int[i], &list_int[j] );
							continue;					
						}

						if( item_i->GetLevel() == item_j->GetLevel() )
						{
	//						if( list[i].item_no > list[j].item_no )
	//						{
	//							swap_kein( &list[i], &list[j], &temp, sizeof( ItemAttr ) );
	//							swap( &list_int[i], &list_int[j] );
	//							continue;					
	//						}
						}
					} 
				}
			}
		}
	}
}


void SendDecreaseItem( POS item_pos, DWORD dur, t_connection c[], int cn )	// 酒捞袍 皑家 郴备仿 傈价 窃荐
{
	t_packet p;

	p.h.header.type = CMD_DECREASE_ITEM;
	{
		p.u.kein.server_decrease_item.dur = dur;
		p.u.kein.server_decrease_item.item_pos = item_pos;
	}
	p.h.header.size = sizeof( k_server_decrease_item ); 
	QueuePacket(connections, cn, &p, 1);
}
void RecvLvUpPointEach(unsigned char type, t_connection c[], int cn)
{
	t_packet	packet;
	CHARLIST	*ch;
	ch = &c[cn].chrlst;
	if( !ch ) return;

	if (ch->GetReservedPoint() > 0)
	{
    ch->IncAbility(type);
    ResetAbility(ch);//020303 lsw
	}
	else 
	{	
		packet.h.header.type = CMD_LEVELUP_POINT_NO;
		packet.h.header.size = 0;
		QueuePacket(connections, cn, &packet, 1);
	}
}

void RecvLvDownPointEach( unsigned char type, t_connection c[], int cn )
{
	return;
	t_packet	packet;
	CHARLIST	*ch;
	ch = &c[cn].chrlst;

	if( !ch ) return;

	if (ch->GetReservedPoint() > 0)
	{
		if (ch->GetReservedPoint() >= 10)		// 巢酒乐绰 饭骇诀器牢飘啊 10捞惑捞搁 哗扁绰 救等促.
		{
			return;
		}
		switch( type )
		{
			case STR:		ch->Str--;		break;
			case CON:		ch->Con--;		break;
			case DEX:		ch->Dex--;		break;
			case WIS:		ch->Wis--;		break;
			case INT_:		ch->Int--;		break;
			case MOVP:		ch->MoveP--;	break;
			case CHA:		ch->Char--;		break;
			case ENDU:		ch->Endu--;		break;
			case MOR:		ch->Moral--;	break;
			case LUCK:		ch->Luck--;		break;
			case WSPS:		ch->wsps--;		break;
			default : return;
		}

		ch->IncReservedPoint();
		ResetAbility(ch);//020303 lsw

		packet.h.header.type = CMD_LEVELDOWN_OK;
		{
			packet.u.kein.client_lvup_point_each.type = type;
		}
		packet.h.header.size = sizeof( client_lvup_point_each );
		QueuePacket(connections, cn, &packet, 1);
	}
	else 
	{	
		packet.h.header.type = CMD_LEVELUP_POINT_NO;
		packet.h.header.size = 0;
		QueuePacket(connections, cn, &packet, 1);
	}	
}

void RecvLearnItem( k_client_learn_item *i, t_connection c[], int cn )
{
	CHARLIST *ch = &c[cn].chrlst;
	if( !ch ) return;

	int type, num;
	getItemIndex( i->item_no, type, num );
	CItem *t = ItemUnit( type, num );
	if( !t ) return;

	int join_num = GetItemJoinNumber( i->item_no );		// join抛捞喉俊辑狼 颇扼皋鸥 锅龋
	if( !item_join[join_num].item_id ) return;					// 绝绰 酒捞袍
	int value = item_join[join_num].tech_price;
	
//	ch->Money = GetMoneyByItem( ch );
	if( ch->Money < (DWORD)value ) return;				// 捣捞 何练窃.

	int ct = SkillMgr.FindLearnItem( ch, i->item_no ) ;
	if( ct == -1 ) return ;					// 硅款酒捞袍老 版快 0阑 府畔茄促.
	if( ct == MAX_LEARN_ITEM ) return;	// 葛滴 促 硅奎阑 锭...

	if( !SkillMgr.CanLearnItem( ch, join_num ) ) return;		// 硅匡 瓷仿捞 何练窍促.

	ch->Item[ct] = i->item_no;			// 硅款芭 殿废
	ch->ItemMax++;						// 父甸荐 乐绰 酒捞袍 弥措摹 ++
	SubtractMoney( value, ch );

	t_packet p;
	p.h.header.type = CMD_LEARN_ITEM;		// ok sign
	{
		p.u.kein.item_no.item_no = i->item_no;
	}
	p.h.header.size = sizeof( k_item_no );
	QueuePacket(c, cn, &p, 1);
}

void RecvItemRepair( t_client_item_sell *p, t_connection c[], int cn )
{
	CHARLIST *ch = &c[cn].chrlst;
	if( !ch ) return;
//	ch->Money = GetMoneyByItem( ch );

	int store_id = p->store_id;
	int pos = p->item_position;
	int x,y,z;
	int item_no, type;
	int price;
	int storeitemno;
	int i;

	x = ( pos & 0x0060 ) >> 5;
	y = ( pos & 0x0018 ) >> 3;
	z = ( pos & 0x0007 );
	ItemAttr &item= ch->inv[x][y][z];

	getItemIndex( item.item_no, type, item_no );
	CItem *t = ItemUnit( type, item_no );
	if( !t ) 
	{
		SendServerResult( CM_REPAIR, 3, cn );	// 酒捞袍捞 裹困甫 逞绢级...
		return;
	}

	storeitemno = MAX_STORE_ITEM_LIST;
	for( i = 0 ; i < storeitemno ; i ++)
	{
		if( storelist[store_id][i].item_no == item.item_no ) 
		{
			break;		// 沥富肺 弊 惑痢俊辑 秒鞭窍绰 拱前牢啊
		}
	}

	if( i == storeitemno || !t->GetRepairAble() )
	{
		SendServerResult( CM_REPAIR, 2, cn );	// 秒鞭 拱前捞 酒丛
		return;
	}

	WORD d_curr;
	WORD d_max;
	GetItemDuration( item, d_curr, d_max );

	if(!d_max) 
	{
		SendServerResult( CM_REPAIR, 4, cn );		// 郴备仿捞 窍唱档 绝寸...
		return;
	}
	price = (int)( (float)t->GetValue()/d_max * ((d_max - d_curr))*DUR_RATIO +.5); // 啊拜 拌魂 棺 魄窜 
	if(item.attr[IATTR_RARE_MAIN])// 饭绢绰 荐府厚 厚接
	{
		const int iRepairPoint = (int)( (float)((d_max - d_curr))*RARE_DUR_RATIO +.5); // 啊拜 拌魂 棺 魄窜 
		const int iRareGrade  = ((LPRareMain)(&item.attr[IATTR_RARE_MAIN]))->grade;
		price += (iRepairPoint/2) * ((iRareGrade*iRareGrade)+10) * 100; // 啊拜 拌魂 棺 魄窜 //020815 lsw
	}

	if( !price ) 
	{
		price = 1;
	}
	if(ch->Money < (DWORD) price ) 
	{
		SendServerResult( CM_REPAIR, 1, cn );		// 捣捞 绝澜
		return;
	}
	SubtractMoney( price, ch );

	if(item.attr[IATTR_RARE_MAIN])// 饭绢绰 荐府啦捞 促福促
	{
		d_max = (WORD)(d_curr+(d_max-d_curr)*RARE_DUR_RATIO);
	}
	else
	{
		d_max = (WORD)(d_curr+(d_max-d_curr)*DUR_RATIO);
	}
	
	DWORD d = MAKELONG(d_max, d_max);
	item.attr[IATTR_DURATION] = d;
	{
		t_packet packet;
		packet.h.header.type = CMD_ITEMREPAIR_OK;
		{
			packet.u.kein.server_item_repair_ok.item_pos=pos ;
			packet.u.kein.server_item_repair_ok.money= price;
			packet.u.kein.server_item_repair_ok.dur= d;			
		}
		packet.h.header.size = sizeof(k_server_item_repair_ok);
		QueuePacket(connections, cn, &packet, 1);
	}
}

void SendServerResult( BYTE type, BYTE result, int cn )		// 绢恫 搬苞甫 焊郴临锭..
{
	t_packet packet;
	packet.h.header.type = CMD_RESULT;
	{
		packet.u.kein.server_result.type= type;
		packet.u.kein.server_result.result= result;
	}
	packet.h.header.size = sizeof(k_server_result);
	QueuePacket(connections, cn, &packet, 1);
}

void GetItemDuration( ItemAttr item, WORD &d_curr, WORD &d_max )
{
	d_curr = LOWORD( item.attr[IATTR_DURATION] );
	d_max = HIWORD( item.attr[IATTR_DURATION] );
}

void SendStatusOpen( t_connection c[], int cn )
{ //< CSD-020821
	CHARLIST *ch = &c[cn].chrlst;
	if (!ch) return;

	t_packet packet;
	packet.h.header.type = CMD_OPEN_STATUS_REQ;
	{
		packet.u.kein.server_status_open.killmon	= ch->killmon;
		packet.u.kein.server_status_open.ac			= ch->GetExtendAc();
		packet.u.kein.server_status_open.fame			= ch->fame;
		packet.u.kein.server_status_open.mov = ch->MoveP;
	}
	packet.h.header.size = sizeof(k_server_status_open);
	QueuePacket(connections, cn, &packet, 1);
} //> CSD-020821

void SendBankInventory( int count, t_connection c[], int cn )		//1225
{
	int i,j;
	
	i=count /3;
	j=count %3;

	t_packet packet;
	packet.h.header.type = CMD_SEND_BANK_INV;
	packet.h.header.size = sizeof(k_server_bank_item);

	packet.u.kein.server_bank_item.first = i;
	packet.u.kein.server_bank_item.second = j;
	memcpy( (unsigned char *)packet.u.kein.server_bank_item.inv, 
			(unsigned char *)c[ cn].chrlst.bank[i][j],	sizeof( ItemAttr ) * 6 );

	QueuePacket( c, cn, &packet, 1);
}


int IsSameCharOfParty( int type, char *name, CHARLIST *ch )		// 鞍篮 捞抚捞 乐绰瘤 魄窜
{
	if( !ch ) return 0;
	int i;
	switch( type )
	{
		case PARTY :		for( i=0; i<6; i++ ) if( !strcmp( ch->party[i].Name, name ) ) return 1;
							break;
		case RELATION :		for( i=0; i<3; i++ ) if( !strcmp( ch->relation[i].Name, name ) ) return 1;
							break;
		case EMPLOYMENT :	for( i=0; i<6; i++ ) if( !strcmp( ch->employment[i].Name, name ) ) return 1;
							break;
	}
	return 0;
}

// 包拌甫 肝扁俊 啊瓷茄 饭骇牢瘤..
int IsCheckPartyLevel( int type, CHARLIST *target_ch, CHARLIST *ch )		
{
	if( !ch ) return 0;
	switch( type )
	{
		case PARTY:
		case RELATION:		
		case EMPLOYMENT:	return 1;
							
	}
	return 0;
}

void RecvDoParty( k_client_do_party *p, t_connection c[], int cn, int party_cn, int check_nation )
{
	CHARLIST *ch = &c[cn].chrlst;
	if( !ch ) return;

	if( !party_cn )
		party_cn = ExistHe( p->name );		// cn 蔼捞 乐促搁...

	if( party_cn == -1 ) return;
	
	CHARLIST *party_ch = &c[party_cn].chrlst;
	int ct = p->ct;

	if( IsSameCharOfParty( p->type, p->name, ch ) ) return;
	if( !IsCheckPartyLevel( p->type, party_ch, ch ) ) 
	{
		t_packet packet;
		packet.h.header.type = CMD_PARTY_NOT_BY_LEVEL;
			packet.u.kein.default_short_int = p->type;
		packet.h.header.size = sizeof(short int);
		QueuePacket( c, ch->GetServerID(), &packet, 1);
		return;
	}
	if( check_nation )
		if( !IsSameNation( party_ch, ch ) ) return;		// 唱扼啊 崔扼档 颇萍甫 肝绢具 且 版快

	switch( p->type )				// 火涝且 镑俊 促弗 颇萍盔捞 乐栏搁 弊 颇萍盔阑 颗扁绊 火涝茄促.
	{
		case PARTY :		if( ch->party[ct].On ) 
							{
								for( int i=0; i<6; i++ )
								{
									if( !ch->party[i].On ) 
									{
										ch->party[i] = ch->party[ct];
										ch->party[i].On = true;
										break;
									}
								}
							}
							strcpy( ch->party[ct].Name, p->name ); 
							ch->party[ct].On = true;
							break;

		case RELATION :		if( *ch->relation[ct].Name ) 
							{
								for( int i=0; i<3; i++ )
								{
									if( !*ch->relation[i].Name ) 
									{
										strcpy( ch->relation[i].Name, ch->relation[ct].Name );
										break;
									}
								}
							}
							strcpy( ch->relation[ct].Name, p->name ); break;
		case EMPLOYMENT :	if( *ch->employment[ct].Name ) 
							{
								for( int i=0; i<6; i++ )
								{
									if( !*ch->employment[i].Name ) 
									{
										strcpy( ch->employment[i].Name, ch->employment[ct].Name );
										break;
									}
								}
							}
							strcpy( ch->employment[ct].Name, p->name ); break;
	}
	// 弊 某腐磐狼 沥焊 焊郴林扁
	int ret = SendPartyInfo( p->type, p->ct, c, ch->Name );
	if( ret == -1 )
	{
		switch( p->type )
		{
			case PARTY :		memset( &ch->party[p->ct], 0 , sizeof( CharacterParty ) ); break;
//			case RELATION :		
//			case EMPLOYMENT :		
		}

	}	
	else		// 惑措祈捞 颇萍 肝菌澜阑 舅妨霖促.
	{
		t_packet packet;
		packet.h.header.type = CMD_DO_PARTY_OK;
			packet.u.kein.do_party_ok.type= p->type;

⌨️ 快捷键说明

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