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

📄 menuserver.cpp

📁 国内著名网络游戏dragon的服务端完整源码 内附完整数据库结构
💻 CPP
📖 第 1 页 / 共 5 页
字号:
			strcpy( packet.u.kein.do_party_ok.name, ch->Name );
		packet.h.header.size = sizeof( k_do_party_ok );
		QueuePacket( c, party_ch->GetServerID(), &packet, 1);
	}
}

inline CharacterParty *GetPartyPointer( CHARLIST *ch, int type, int count )
{
	CharacterParty *target_party;
	switch( type )
	{
		case PARTY :		target_party = &ch->party[count]; break;
		case RELATION :		target_party = &ch->relation[count]; break;
		case EMPLOYMENT :	target_party = &ch->employment[count]; break;
		default : return NULL;
	}
	return target_party;
}

int SendPartyInfo( int type, int ct, t_connection c[], const char* szName )	// 颇萍 辆幅, 颇萍 硅凯 锅龋		1何盒父 傈价
{
	CHARLIST *me = CheckServerName(szName);
	if( !me ) return 0;
	
	const int cn = me->GetServerID();	// kyo
	
	if( ct<0 && ct>=6 ) return 0;
	
	CharacterParty *target_party = GetPartyPointer( me, type, ct );
	if( !target_party ||  !target_party->Name[0] ) return 0; // 弊 锅龋俊 肝篮 颇萍盔捞 绝促.
	CHARLIST *pa = SearchIdByName(target_party->Name); // CSD-030320
	if( !pa ) return -1; 
	
	t_packet packet;
	memset( &packet, 0, sizeof( t_packet ) );
	//< CSD-030320	
	const int he_exist = ExistHe(pa->Name);
	const int sight = IsMySightInWhoById( he_exist, cn );
	//> CSD-030320
	packet.h.header.type = CMD_SERVER_PARTY;
	{
		packet.u.kein.party_info.type		= (short) type;
		packet.u.kein.party_info.index		= (char) ct;
		
		strcpy( packet.u.kein.party_info.m_Name, target_party->Name);
		packet.u.kein.party_info.m_Gender	= (char) pa->Gender;
		packet.u.kein.party_info.m_ImageNo	= (short) pa->Face;
		packet.u.kein.party_info.m_Class	= (char) pa->Class;
		if( sight && CompPartyBoth( me, pa ) )		// 郴矫具俊 甸绢吭阑 锭父 饭骇苞 塞 沥焊甫 焊郴霖促. 鞍捞 悼竿阑 肝阑 锭父..
		{
			packet.u.kein.party_info.m_Lv = pa->GetLevel(); // CSD-030806
			packet.u.kein.party_info.m_Str = pa->Str;
		}
		packet.u.kein.party_info.m_Join		= he_exist?1:0;
	}
	packet.h.header.size = sizeof(k_party_info);
	QueuePacket(connections, cn, &packet, 1);
	
	switch( type )
	{
	case PARTY : {
		for( int j=0; j<6; j++ )
		{
			if( !strcmp( me->Name, pa->party[j].Name ) ) 
			{
				SendPartyJoinOk( target_party->Name, cn );		// 刚历 皋矫瘤甫 焊辰 仇俊霸 ok甫 焊郴林绊
				SendPartyJoinOk( me->Name, pa->GetServerID());	// 惑措祈档 白俊 立加秦 乐栏搁 ok甫 焊郴霖促.
				//pa->party[j].Server_id = cn;
				break;
			}
		}
		break;
				 }
		
	}
	return 1;
}

void RecvDeleteParty( k_client_delete_party *p, t_connection c[], int cn )
{
	CHARLIST *ch = CheckServerId( cn );
	if( !ch ) return;

	CharacterParty *target;
	switch( p->type )
	{
		case PARTY : target = &ch->party[p->ct]; break;
		case RELATION :	target = &ch->relation[p->ct]; break;
		case EMPLOYMENT : target = &ch->employment[p->ct]; break;
		default : return;
	}
	//CHARLIST *party_ch = CheckServerId( target->Server_id );
	CHARLIST *party_ch = CheckServerName( target->Name );

	if( party_ch && strcmp( party_ch->Name, target->Name )==0 )			// 弊 仇捞 霸烙惑俊 粮犁窍绰 仇捞扼搁..
	{
		if( IsSameCharOfParty( PARTY, ch->Name, party_ch ) )		// 弊仇茄抛档 
		{
			//SendPacketDefault( CMD_PARTY_JOIN_RELEASE, ch->Name, strlen( ch->Name ), target->Server_id ); 
			CHARLIST *chTar = CheckServerName( target->Name );
			if( !chTar ) return;
			SendPacketDefault( CMD_PARTY_JOIN_RELEASE, ch->Name, strlen( ch->Name ), chTar->GetServerID()); // kyo
		}
	}
	memset( target, 0, sizeof( CharacterParty ));
}

void RecvLearnMagic( short int num, t_connection c[], int cn )
{
	CHARLIST	*ch = &c[cn].chrlst;
	if( !ch ) return;

	if( ch->Spell == WIZARD_SPELL )
	{
		if( ch->Ws[num] )	
		{
			SendServerResult( CM_LEARN_MAGIC, 2, cn );	// 捞固 硅奎促.
			return;
		}
	}
	else if( ch->Spell == PRIEST_SPELL )
	{
		if( ch->Ps[num] )	
		{
			SendServerResult( CM_LEARN_MAGIC, 2, cn );	// 捞固 硅奎促.
			return;
		}
	}

//	SendServerResult( CM_LEARN_MAGIC, 5, cn );	// 捣捞 何练秦
	int ret = CanLearnMagic( num, ch );

	switch( ret )
	{
		case 1  :	SendLearnMagicOk( num, cn );	break;
		case 3  :	SendServerResult( CM_LEARN_MAGIC, 3, cn );	return ;// 瓷仿捞 何练秦
		case 4  :	SendServerResult( CM_LEARN_MAGIC, 4, cn );	return ;// 弊繁 付过 绝绢
		default :	return;
	}

	if( ch->Spell == WIZARD_SPELL )
	{
		SubtractMoney( Magic_Ref[num].Price, ch );
		ch->Ws[num] = true;
	}
	else ch->Ps[num] = true;
}

int	CanLearnMagic( int num, CHARLIST *ch )		// 弊 付过阑 硅匡荐 乐唱?
{
	if( !ch ) return false;
//	return true;			// 烙矫
	int sptype=0;
	int sp;
	unsigned char *spell;
	if( ch->Spell )			// priest
	{
		sptype = 150;
		spell = ch->Ws;
		sp = TACTICS_Orison;
	}
	else 
	{
		spell = ch->Ps;
		sp = TACTICS_Magery;
	}

	int magic_num = num+sptype;
	if( magic_num == -1 ) return 4;
  int Wis  = ch->GetAbility(WIS);
	int Int  = ch->GetAbility(INT_);
	int wsps = ch->GetAbility(WSPS);
	if( Magic_Ref[magic_num].basic_magery> ch->Skill[sp]+1 )	return 3;			// 付过扁贱捞 面盒茄啊?
	if( Magic_Ref[magic_num].require_WP > Wis ) return 3;		// 夸备 瘤驱
	if( Magic_Ref[magic_num].require_IT > Int ) return 3;		// 夸备 瘤瓷
	if( Magic_Ref[magic_num].exhaust_MS > wsps ) return 3;		// 夸备 WSPS
	if( Magic_Ref[magic_num].point_WS > wsps ) return 3;		// 夸备 WSPS
	if( (DWORD) Magic_Ref[magic_num].Price > ch->Money ) return 3;		// 夸备 WSPS


	return 1;	
}

int GetMagicNumBySerial( int serial )
{
	for( int i=0; i<Num_Of_Magic; i++ )
	{
		if( Magic_Ref[i].serial_Num == serial ) return i;
	}
	
	return -1;
}

void SendLearnMagicOk( int num , int cn)
{
	t_packet packet;
	packet.h.header.type = CMD_LEARN_MAGIC_OK;
	{
		packet.u.kein.learn_magic_ok.magic_num = num;
	}
	packet.h.header.size = sizeof(k_learn_magic_ok);
	QueuePacket(connections, cn, &packet, 1);
}

//
//	龙捍 抗规, 己傍咯何 努扼捞攫飘 傈价
//
void SendPreventingOk( int num , int cn)
{
	t_packet packet;
	packet.h.header.type = CMD_PREVENTING;
	{
		packet.u.kein.client_disease.disease_num = num;
	}
	packet.h.header.size = sizeof(k_client_disease);
	QueuePacket(connections, cn, &packet, 1);
}

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

	int money=100;
	money = disease_tbl[num].price_prevent;	// 抗规厚

	if( num < 0 || num > 5 ) return;
	if( ch->Money < (DWORD)money ) 
	{
		SendServerResult( CM_PREVENTING, 2, cn );			// 捣捞 何练秦...
		ch->SendCharInfoBasic(MONEY, ch->Money );			// 盎脚等 沥焊甫 焊郴霖促.//020704 lsw
		return;
	}
	
// 010531 KHS
//	ch->nut1 = 100;
//	ch->nut2 = 100;
//	ch->nut3 = 100;
	
	SubtractMoney( money, ch );

	SendPreventingOk( num, cn );	// 己傍沁澜.
}

//
//	龙捍 摹丰
//
void SendCureDiseaseOk( short int num, int cn )
{
	t_packet packet;
	packet.h.header.type = CMD_CURE_DISEASE;
	{
		packet.u.kein.client_disease.disease_num = num;
	}
	packet.h.header.size = sizeof(k_client_disease);
	QueuePacket(connections, cn, &packet, 1);
}

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

	int money=100;

	if( num < 0 || num > 5 ) return;
	money = disease_tbl[num].price_heal;
	if( ch->Money < (DWORD)money ) 
	{
		SendServerResult( CM_CURE_DISEASE, 2, cn );
		return;
	}
	SubtractMoney( money, ch );
	SendCureDiseaseOk( num, cn );
}

//
// 酒捞袍 俺寸 啊拜 傈价 皋家靛甸 		
//
void SendItemValue( int item_no, int cn )
{
	int type, num;
	getItemIndex( item_no, type, num );

	CItem *item = ItemUnit( type, num );
	if( !item ) return;

	t_packet packet;
	packet.h.header.type = CMD_REQ_ITEM_VALUE;
	{
		packet.u.kein.server_item_money.item_no = item_no ;
		packet.u.kein.server_item_money.money = item->GetValue();
	}
	packet.h.header.size = sizeof(k_server_item_money);
	QueuePacket(connections, cn, &packet, 1);
}

void SendItemValue_Sell( POS *pos, int cn )
{
	CHARLIST *ch = CheckServerId( cn );
	if( !ch ) return;

	ItemAttr *item = GetItemByPOS( cn, *pos );
	if( !item ) return ;

	DWORD price_sell = GetItemValueSell( item );
	if( price_sell == 0 ) 
		SendDeleteItem( item, pos, ch );

	t_packet packet;
	packet.h.header.type = CMD_REQ_ITEM_VALUE_SELL;
	{
		packet.u.kein.server_item_money.item_no = item->item_no ;
		packet.u.kein.server_item_money.money = price_sell;
	}
	packet.h.header.size = sizeof(k_server_item_money);
	QueuePacket(connections, cn, &packet, 1);
}

void SendItemValue_Repair( int item_no, int cn )
{
	int type, num;
	getItemIndex( item_no, type, num );

	CItem *item = ItemUnit( type, num );
	if( !item ) return;

	t_packet packet;
	packet.h.header.type = CMD_REQ_ITEM_VALUE_REPAIR;
	{
		packet.u.kein.server_item_money.item_no = item_no ;
//		packet.u.kein.server_item_money.money = ;
	}
	packet.h.header.size = sizeof(k_server_item_money);
	QueuePacket(connections, cn, &packet, 1);
}

CHARLIST *SearchIdByName(const char* pName)
{	//< CSD-030320
	return g_pUserManager->GetCharList(pName);
}	//> CSD-030320


void RecvClientInn( char type, int cn )
{
	CHARLIST	*ch = CheckServerId( cn );
	if( !ch ) return;
//	ch->Money = GetMoneyByItem( ch );

	switch( type )
	{
		case 0: return;  // 俊矾..
		
		// 蒋锭..
		case INN_SINGLE :	if( ch->Money < 3 ) 
							{
								SendServerResult( CM_INN_REST, 2, cn );		 // 捣捞 何练钦聪促.
								return;
							}
							ch->Status = CS_REST;	
							SubtractMoney( 3, ch );
							break;
							
		case INN_DOUBLE :	ch->Status = CS_REST;	break;
		case INN_MULTI  :	ch->Status = CS_REST;	break;

		// 泪磊扁
		case INN_SINGLE+1 :	ch->Status = CS_SLEEP;	break;
		case INN_DOUBLE+1 :	ch->Status = CS_SLEEP;	break;
		case INN_MULTI+1  :	ch->Status = CS_SLEEP;	break;
	}
}

int GetItemValueSell( ItemAttr *item )//020925 lsw float 肺 官操绢 唱穿扁 窍霸阐 沁嚼聪促.
{
	int type;
	int num; 
	getItemIndex( item->item_no, type, num );

	CItem *t = ItemUnit( type , num );
	if( t ) 
	{
		int price = 0;
		int base = t->GetValue();
		int much;

		if( type == DISPOSABLE ) 
		{
			much = t->GetItemQuantity();	// dispoable老 版快
			if( !much ) much = 1;
			price = (int)(((float)base * .9+.5)*(((float)item->attr[IATTR_MUCH])/((float)much)));
			return price;
		}
		else if( t->GetRbutton()==DIVIDE_ITEM )		// 荐樊阑 狼固...
		{
			much = t->GetItemDuration();		// 10俺 窜困
			if( !much ) much = 1;
			price = (int)(((float)base * .9+.5)*(((float)item->attr[IATTR_MUCH])/((float)much)));
			return price;
		}

		WORD d_curr, d_max;

		GetItemDuration( *item, d_curr, d_max );
		WORD o_d_max = t->GetDuration();
		if( d_max < o_d_max ) d_max = o_d_max;

		if( d_max )
		{	
			if( (item->attr[IATTR_LIMIT]-g_curr_time) > 0 )		// 蜡烹扁茄捞 巢酒 乐绢具 茄促.
			{
				price = (int)( (float)(base*.9)*(float)d_curr/(float)d_max+.5 );
				return price;
			}
			// 蜡烹扁茄阑 持具 茄促.
			price = (int)( (float)(base*.9)*(float)d_curr/(float)d_max+.5 );		// 烙矫 
			return price;
		}
	}
	return 0;
}


ItemAttr *GetItemByPOS( int cn, POS item )
{
	CHARLIST *ch = CheckServerId( cn );
	if( !ch ) return NULL;
	return GetItemByPOS( ch, item );
}

ItemAttr *GetItemByPOS( CHARLIST *ch, POS item )
{//021030 lsw
	switch( item.type )
	{
		case	HAND	:	return &ch->handheld;
		case	INV		:	return &ch->inv[item.p1][item.p2][item.p3];
		case	EQUIP	:	return &ch->equip[item.p3];
		case	QUICK	:	return &ch->quick[item.p3];
		case	BANK	:	return &ch->bank[item.p1][item.p2][item.p3];
		case	BOX		:
		case	MAKE	:	
		case	AUCTION_DB :
		case	OTHER_CH:	break;
	}
	return NULL;
}


extern void SendCMD_REQUEST_CHECK_WARNO(const int cn);	// 010915 LTS//020903 lsw

void SendServerWeakUp( int cn )
{
	CHARLIST *ch = CheckServerId( cn );
	if( !ch ) return;
	ch->Status = 0;
	ch->can_memorize_time = g_curr_time;

	t_packet packet;
	packet.h.header.type = CMD_SERVER_WAKE_UP;
	packet.h.header.size = sizeof(0);
	QueuePacket(connections, cn, &packet, 1);
}

void SendJoinGameWho( int cn )		// cn捞鄂 仇捞 货肺 甸绢吭阑 版快 肺弊牢辑滚肺 郴 颇萍甸捞 乐绰瘤甫 夸没窍绊...
{
	CHARLIST *ch = CheckServerId( cn );
	if( !ch ) return;

	for( int a=0; MAX_PARTY_MEMBER > a ; a++ )
	{
		if(ch->party[a].Name[0])	
		{
			ReqPartyDB( cn, a, ch->party[a].Name );		// 郴啊 肝菌带 颇萍 沥焊甫 老窜 肺弊牢 辑滚俊 夸没茄促.
		}
	}
	SendCMD_REQUEST_CHECK_WARNO(cn);// 010915 LTS
}

CHARLIST *CheckServerIdAndName( int cn, char *name )
{
	CHARLIST *ch = CheckServerId( cn );

⌨️ 快捷键说明

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