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

📄 worldkernel.cpp

📁 魔域源代码需要的可以学习一下真么这么麻烦啊
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			OBJID* pId	= (OBJID*)buf;
			OBJID idSyn		= pId[0];
			OBJID idTarget	= pId[1];
			GameWorld()->QuerySynManager()->QueryModify()->DestroySyndicate(idSyn, idTarget);
		}
		break;
		
	case	KERNEL_COMBINESYNDICATE:
		{
			OBJID* pId	= (OBJID*)buf;
			OBJID idSyn		= pId[0];
			OBJID idTarget	= pId[1];
			GameWorld()->QuerySynManager()->QueryModify()->CombineSyndicate(idSyn, idTarget);
		}
		break;
	case	KERNEL_CHANGESYNDICATE:
		{
			SynFuncInfo0* pPacket = (SynFuncInfo0*)buf;
			CSyndicateWorld* pSyn = GameWorld()->QuerySynManager()->QuerySyndicate(pPacket->idSyn);
			IF_OK(pSyn)
			{
				pSyn->ChangeSyndicate(pPacket);
			}
		}
		break;
	case	WORLD_LEVELUP:
		{
			OBJID idUser = *(OBJID*)buf;
			CPlayer* pPlayer = GameWorld()->QueryUserList()->GetPlayer(idUser);
			IF_OK(pPlayer)
				pPlayer->m_nLevel	= LOGIN_FREE_LEVEL;
		}
		break;
	case	WORLD_QUERYFEE:
		{
			OBJID idAccount = *(OBJID*)buf;
			if(IsAccountLoginOK())
				SendQueryFee(idAccount, 0, 0, 0);
		}
		break;
	case	WORLD_SENDTIME:
		{
			SOCKET_ID idSocket = *(SOCKET_ID*)buf;
			IF_OK(idSocket != SOCKET_NONE)
				UserList()->SendTimeToSocket(idSocket);
		}
		break;
	case	KERNEL_SUPERMANLIST:
		{
			VARIANT_SET0* pInfo  = (VARIANT_SET0*)buf;
			OBJID	idUser	= pInfo->IntParam(0);
			int		nNumber	= pInfo->IntParam(1);
			if(nNumber)
				UserList()->QuerySupermanList()->AddMember(idUser, nNumber);
			else
				UserList()->QuerySupermanList()->QueryMember(idUser);
		}
		break;
	case	KERNEL_QUERYSUPERMANLIST:
		{
			VARIANT_SET0* pInfo  = (VARIANT_SET0*)buf;
			OBJID	idUser	= pInfo->IntParam(0);
			int		nIndex	= pInfo->IntParam(1);
			OBJID	idAction	= pInfo->IntParam(2);
			int		nNumber	= pInfo->IntParam(3);
			UserList()->QuerySupermanList()->SendList(idUser, nIndex, nNumber, idAction);
		}
		break;
	default:
		ASSERT(!"CWorldKernel::ProcessMsg()");
	}

	return true;		// return false : 消息处理异常,程序关闭。
}

//////////////////////////////////////////////////////////////////////
bool CWorldKernel::OnTimer(time_t tCurr)
{
	// TODO: 请在此添加时钟处理代码
	g_UserList.OnTimer(tCurr);
#ifdef	ACCOUNT_ENABLE
	// account server
	if(!m_sock.IsOpen())
	{
		m_nState = STATE_NONE;
		GameWorld()->PrintText("Connect to account server again...");
		if(m_sock.Open(0))
			m_nState = STATE_CONNECTOK;
	}
#endif
	if(m_sock.IsOpen())
	{
		if(m_nState == STATE_CONNECTOK)
		{
			SendAccount(m_szAccount, m_szPassword, m_szServer);
			m_nState = STATE_ACCOUNTOK;
		}

		ProcessAccountNetMsg();
	}

//	g_objChatRoomManager.OnTimer(tCurr);

	return true;		// return false : 消息处理异常,程序关闭。
}

//////////////////////////////////////////////////////////////////////
bool CWorldKernel::Release()
{
	// TODO: 请在此添加代码
	g_UserList.LogoutAllUser();

	SAFE_RELEASE (m_pUserList);
	SAFE_RELEASE (m_pMapList);
	SAFE_RELEASE (m_pSynManager);

	m_pMsgPort->Close();

	GameWorld()->SendFee(ID_NONE, CMsgFee_A::SERVER_CLOSE);

	m_sock.Close();

	SAFE_RELEASE (m_setConnectClient);
	SAFE_RELEASE (m_setConnectAccount);

	SAFE_RELEASE (m_pDb);
	
	delete this;
	return true;		// return false : 无意义。
}

//////////////////////////////////////////////////////////////////////
bool CWorldKernel::ProcessClientMsg(SOCKET_ID idSocket, OBJID idMsg, const char *pbufMsg, int nSize, int nTrans)
{
	// TODO: 请在此添加客户端上传消息的处理代码
	if(idMsg == _MSG_NONE || !pbufMsg || nSize <= 0 || nSize >_MAX_MSGSIZE)
        return false;

	CNetMsg* pMsg	=CNetMsg::CreateClientMsg(m_idProcess, idSocket, idMsg, pbufMsg, nSize, nTrans);
	if(pMsg)
	{
		try {
			pMsg->Process(this);
		}
		catch(...)
		{
//			CNetMsg::DumpMsg(pMsg);
			ASSERT(!"pMsg->Process(this);");
			::LogSave("exception catch at CGameSocket::ProcessMsg()! MsgType:%d, SocketID:%u", idMsg, idSocket);
		}
		delete pMsg;
	}

	return true;
}

//////////////////////////////////////////////////////////////////////
bool CWorldKernel::SendMsg(CNetMsg* pNetMsg)
{
	ASSERT(pNetMsg);
	if(!pNetMsg)
		return false;

	if(!pNetMsg->IsNpcMsg())
		return SendMsg(pNetMsg->GetSocketID(), pNetMsg->GetType(), pNetMsg->GetBuf(), pNetMsg->GetSize());
	else
		return SendNpcMsg(pNetMsg->GetNpcID(), pNetMsg->GetType(), pNetMsg->GetBuf(), pNetMsg->GetSize());
}

//////////////////////////////////////////////////////////////////////
bool CWorldKernel::SendMsg(SOCKET_ID idSocket, OBJID idMsg, const char *pBuf, int nMsgLen)
{
	// TODO: 请在此添加NPC服务器下传消息的代码
	if (!pBuf)
	{
		::LogSave("Error: null msg point found in CGameSocket::SendMsg.");
		return false;
	}

	if (_MSG_NONE == idMsg)
	{
		::LogSave("Error: invalid msg type in CGameSocket::SendMsg().");
		return false;
	}

	try {
		MESSAGESTR	bufPacket;
		SENDCLIENTMSG_PACKET0* pPacket = (SENDCLIENTMSG_PACKET0*)bufPacket;
		pPacket->idSocket	= idSocket;
		pPacket->idPacket	= idMsg;
		pPacket->nSize		= nMsgLen;
		memcpy(pPacket->buf, pBuf, nMsgLen);
		m_pMsgPort->Send(MSGPORT_SOCKET, SOCKET_SENDCLIENTMSG, STRUCT_TYPE(bufPacket), &bufPacket);
		return true;
	}
	catch(...)
	{
		ASSERT(!"catch");
		::LogSave("Error: exception catched in CGameSocket::SendMsg().");
		return false;
	}			

	return true;
}

//////////////////////////////////////////////////////////////////////
bool CWorldKernel::ProcessNpcMsg(OBJID idNpc, OBJID idMsg, const char *pbufMsg, int nSize, int nTrans)
{
	// TODO: 请在此添加NPC服务器上传消息的处理代码
	if(idMsg == _MSG_NONE || !pbufMsg || nSize <= 0 || nSize >_MAX_MSGSIZE)
        return false;

	CNetMsg* pMsg	=CNetMsg::CreateNpcMsg(m_idProcess, idNpc, idMsg, pbufMsg, nSize, nTrans);
	if(pMsg)
	{
		try {
			pMsg->Process(this);
		}
		catch(...)
		{
//			CNetMsg::DumpMsg(pMsg);
			ASSERT(!"pMsg->Process(this);");
			::LogSave("exception catch at CGameSocket::ProcessMsg()! MsgType:%d, NPCID:%u", idMsg, idNpc);
		}
		delete pMsg;
	}

	return true;
}

//////////////////////////////////////////////////////////////////////
bool CWorldKernel::SendNpcMsg(CNetMsg* pNetMsg)
{
	ASSERT(pNetMsg);
	if(!pNetMsg)
		return false;

	return SendNpcMsg(pNetMsg->GetNpcID(), pNetMsg->GetType(), pNetMsg->GetBuf(), pNetMsg->GetSize());
}

//////////////////////////////////////////////////////////////////////
bool CWorldKernel::SendNpcMsg(OBJID idNpc, OBJID idMsg, const char *pBuf, int nMsgLen)
{
	// TODO: 请在此添加NPC服务器下传消息的代码
	if (!pBuf)
	{
		::LogSave("Error: null msg point found in CGameSocket::SendMsg.");
		return false;
	}

	if (_MSG_NONE == idMsg)
	{
		::LogSave("Error: invalid msg type in CGameSocket::SendMsg().");
		return false;
	}

	try {
		MESSAGESTR	bufPacket;
		SENDNPCMSG_PACKET0* pPacket = (SENDNPCMSG_PACKET0*)bufPacket;
		pPacket->idNpc		= idNpc;
		pPacket->idPacket	= idMsg;
		pPacket->nSize		= nMsgLen;
		memcpy(pPacket->buf, pBuf, nMsgLen);
		m_pMsgPort->Send(MSGPORT_SOCKET, SOCKET_SENDNPCMSG, STRUCT_TYPE(bufPacket), &bufPacket);
		return true;
	}
	catch(...)
	{
		ASSERT(!"catch");
		::LogSave("Error: exception catched in CGameSocket::SendMsg().");
		return false;
	}			

	return true;

	return true;
}

//////////////////////////////////////////////////////////////////////
bool CWorldKernel::CloseSocket(SOCKET_ID idSocket)			// 直接关闭socket
{
	// TODO: 请在此添加关闭客户端SOCKET的代码
	m_pMsgPort->Send(MSGPORT_SOCKET, SOCKET_BREAKCONNECT, VARTYPE_INT, &idSocket);

	if(idSocket == m_idNpcSocket)
	{
		LOGMSG("CWorldKernel::CloseSocket break npc connect!", idSocket);
		m_idNpcSocket	= SOCKET_NONE;		//@???
	}

	return true;
}

//////////////////////////////////////////////////////////////////////
bool CWorldKernel::SendClientMsg(SOCKET_ID idSocket, CNetMsg* pMsg)
{
#ifdef _MYDEBUG
	::LogMsg("SendMsg:%d, size:%d", m_unMsgType, m_unMsgSize);

#endif

	pMsg->AppendInfo(MSGPORT_WORLD, idSocket, ID_NONE);
    return SendMsg(pMsg);
}

//////////////////////////////////////////////////////////////////////
bool CWorldKernel::SendNpcMsg(OBJID idNpc, CNetMsg* pMsg)
{
#ifdef _MYDEBUG
	::LogMsg("SendMsg:%d, size:%d", m_unMsgType, m_unMsgSize);

#endif

	pMsg->AppendInfo(MSGPORT_WORLD, SOCKET_NONE, idNpc);
    return SendNpcMsg(pMsg);
}

//////////////////////////////////////////////////////////////////////
bool CWorldKernel::PrintText			(LPCTSTR szText)
{
	return m_pMsgPort->Send(MSGPORT_SHELL, SHELL_PRINTTEXT, STRING_TYPE(szText), szText);
}

//////////////////////////////////////////////////////////////////////
bool CWorldKernel::ChangeCode(SOCKET_ID idSocket, DWORD dwData)
{
	CHANGE_USERDATA	st;
	st.idSocket		= idSocket;
	st.nData		= dwData;
	return m_pMsgPort->Send(MSGPORT_SOCKET, SOCKET_CHANGECODE, STRUCT_TYPE(CHANGE_USERDATA), &st);
}

///////////////////////////////////////////////////////////////////////////////////////
// account server
///////////////////////////////////////////////////////////////////////////////////////
bool CWorldKernel::SendAccount(LPCTSTR szAccount, LPCTSTR szPassword, LPCTSTR szServer)
{
	CMsgAccount_A::MSG_Info	msg;
	msg.unMsgSize	= sizeof(msg);
	msg.unMsgType	= _MSG_ACCOUNT_A;

	SafeCopy(msg.szAccount	, szAccount	, _MAX_NAMESIZE);
	SafeCopy(msg.szPassword	, szPassword, _MAX_NAMESIZE);
	SafeCopy(msg.szServer	, szServer	, _MAX_NAMESIZE);

	return m_sock.SendPacket((LPCTSTR)&msg, msg.unMsgSize, true);
}

///////////////////////////////////////////////////////////////////////////////////////
bool CWorldKernel::SendLogin(OBJID idAccount, DWORD dwCheckData, int usVersion, LPCTSTR szUserName)
{
	CMsgLogin_A::MSG_Info	msg;
	msg.unMsgSize	= sizeof(msg);
	msg.unMsgType	= _MSG_LOGIN_A;

	msg.idAccount	= idAccount;
	msg.dwCheckData	= dwCheckData;
	msg.usVersion	= usVersion;
	SafeCopy(msg.szUserName, szUserName);

	return m_sock.SendPacket((LPCTSTR)&msg, msg.unMsgSize, true);
}

///////////////////////////////////////////////////////////////////////////////////////
bool CWorldKernel::SendFee(OBJID idAccount, int nType)
{
	CMsgFee_A::MSG_Info	msg;
	msg.unMsgSize	= sizeof(msg);
	msg.unMsgType	= _MSG_FEE_A;

	msg.idAccount	= idAccount;
	msg.ucType		= nType;
	
	return m_sock.SendPacket((LPCTSTR)&msg, msg.unMsgSize, true);
}

///////////////////////////////////////////////////////////////////////////////////////
bool CWorldKernel::SendQueryFee(OBJID idAccount, DWORD dwData, int nTime, int ucType)

⌨️ 快捷键说明

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