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

📄 chatting.cpp

📁 国内著名网络游戏dragon的服务端完整源码 内附完整数据库结构
💻 CPP
字号:
#include "..\stdafx.h"
#include "DefaultHeader.h"
#include "Chatting.h"
#include "UserManager.h"
extern bool youvegotitInventory( int cn, ItemAttr *item );
extern bool youvegotitInventory( int cn, int target_id );

void SendChatSetResult(int cn, int result)
{
	t_packet p;
	p.h.header.type = CMD_CHAT_SET_RESULT;
	p.h.header.size = sizeof(t_chat_set_result);
	p.u.chat_set_result.result = result;
	QueuePacket(connections, cn, &p, 1);
}

void RecvChatSet( int cn, t_chat_set *p )
{	//< CSD-030415
	switch (p->chattype)
	{								
	case CHATTYPE_PARTY:	
		{
			for (int i = 0; i < MAX_PARTY_MEMBER; ++i)
			{	//0213 YGI
				if( connections[cn].chrlst.party[i].On ) break;
			}

			if( i != MAX_PARTY_MEMBER ) // party乐澜. 
			{
				connections[cn].chrlst.chattype = p->chattype;
				SendChatSetResult( cn, 10 );
			}
			else
			{
				connections[cn].chrlst.chattype = CHATTYPE_NORMAL;
				SendChatSetResult( cn, 11 );
			}
			break;
		}
	case CHATTYPE_WHISPER:
	case CHATTYPE_GUILD:
		{
			int tempid = -1;

			if (p->chatname[0])
			{
				tempid = g_pUserManager->GetServerID(p->chatname);
			}
				
			int result = 0;

			if (tempid != -1)
			{	
				connections[cn].chrlst.whisperid = tempid;
				strcpy(connections[cn].chrlst.chatname, p->chatname);
				connections[cn].chrlst.chattype = p->chattype;
				result = 1;
				SendChatSetResult(cn, result);
			}	
			else 
			{	
				if (p->chatname[0] == 0)	
				{
					SendChatSetResult(cn, 2); // 扁夯汲沥栏肺 官差菌嚼聪促. 
				}
				else
				{
					SendChatSetResult(cn, 0);	// '%s'鄂 捞抚阑 啊柳荤恩捞 绝嚼聪促. 
				}

				connections[cn].chrlst.chattype = CHATTYPE_NORMAL;
			}	

			break;	
		}						
	case CHATTYPE_NORMAL:	
		{
			connections[cn].chrlst.chattype = p->chattype;
			SendChatSetResult(cn, 2);// 扁夯汲沥栏肺 官差菌嚼聪促. 
			break;
		}
	}								
}	//> CSD-030415								
									
// 泅犁 庇加富肺 汲沥捞 登绢 乐促搁......
void SendWhisper(t_connection c[], int cn, t_packet *packet)
{				
	const int range	= (int)packet->u.client_chat_data.range;
	const int type	= (int)packet->u.client_chat_data.type;
	
	int length	= (int)packet->u.client_chat_data.length;
	
	if (length <= 0 || length >= TEXT_LENGTH)
	{
		return;
	}
	
	int wid = c[cn].chrlst.whisperid;
	
	if (IsConnectJoin(wid))
	{	//< CSD-030515
		wid  = g_pUserManager->GetServerID(c[cn].chrlst.chatname);
	}	//> CSD-030515
	
	if (IsConnectJoin(wid))
	{	//< CSD-030515
		CHARLIST* wch = &c[wid].chrlst; 
		CHARLIST* ch  = &c[ cn].chrlst;
								
		if (strcmp(wch->Name, c[cn].chrlst.chatname) == 0)
		{					
			t_packet p;
			p.h.header.type = CMD_CHAT_DATA;
			p.h.header.size = sizeof(t_server_chat_data)-TEXT_LENGTH+ length;
			p.u.server_chat_data.server_id	= cn;
			p.u.server_chat_data.type		= CHATTYPE_WHISPER; 
			p.u.server_chat_data.length = (unsigned char)length;
			char temp[FILENAME_MAX + NM_LENGTH + 5];
			sprintf(temp, "'%s':%s", c[cn].chrlst.Name, packet->u.client_chat_data.text);
			strncpy(p.u.server_chat_data.text, temp, TEXT_LENGTH);
			p.u.server_chat_data.text[TEXT_LENGTH - 1] = 0;
			QueuePacket(c, wid, &p, 1);
			return;
		}		
	}	//> CSD-030515
				
	c[cn].chrlst.chattype = CHATTYPE_NORMAL;
	SendChatSetResult(cn, 2);
}

void SendChatParty( t_connection c[], int cn, t_packet *packet )
{	//< CSD-030415
	char temp[FILENAME_MAX + NM_LENGTH + 5];
	
	int range	= (int)packet->u.client_chat_data.range;
	int type	= (int)packet->u.client_chat_data.type;
	int length	= (int)packet->u.client_chat_data.length;
	if(length <= 0 || length >= TEXT_LENGTH)	return;

	CHARLIST* pUser = &c[cn].chrlst;

	for (int i = 0 ; i < MAX_PARTY_MEMBER; ++i)
	{
		if (pUser->party[i].On)
		{
			const int idParty = g_pUserManager->GetServerID(pUser->party[i].Name);
			
			if (idParty != -1)
			{
				t_packet p;
				p.h.header.type = CMD_CHAT_DATA;
				p.h.header.size = sizeof(t_server_chat_data) - TEXT_LENGTH + length;
				p.u.server_chat_data.server_id = idParty;
				p.u.server_chat_data.type = CHATTYPE_PARTY; 
				p.u.server_chat_data.length = (unsigned char)length;
				sprintf(temp, "'%s':%s", c[cn].chrlst.Name, packet->u.client_chat_data.text);
				strncpy(p.u.server_chat_data.text, temp, TEXT_LENGTH);
				p.u.server_chat_data.text[TEXT_LENGTH - 1] = 0;
				length = strlen(p.u.server_chat_data.text);
				QueuePacket(c, idParty, &p, 1);
			}
		}
	}
}	//> CSD-030415

⌨️ 快捷键说明

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