Exemplo n.º 1
0
// 保存数据
bool CPlayer::SaveData(google::protobuf::Message *pMsg)
{
	// 没有加载数据的时候,不保存数据
	if (!m_LoadDataSucc)
		return true;

	if (!pMsg)
		return false;

	if (PackData())
	{
		svrData::LoadPlayerData *data = (svrData::LoadPlayerData *)pMsg;
		m_LastSaveTime = CTimer::GetTime();
		data->set_account(GetAccount());
		data->set_name(GetName());
		data->set_nguid(GetGuid());
		data->set_nsex(GetSex());
		data->set_njob(GetJob());
		data->set_nlevel(GetLevel());
		data->set_ncreatetime(GetCreateTime());
		data->set_nlogintime(GetLoginTime());
		data->set_nmapid(GetMapID());
		data->set_nx(GetNowPosX());
		data->set_ny(GetNowPosY());
		data->set_nz(GetNowPosZ());
		data->set_data(g_Base64Data);
		return true;
	}
	return false;
}
Exemplo n.º 2
0
void CInstance::CreateMonsterRun(const int64 &time)
{
	if (time > m_CreateTime + m_CreateMonsterDelayTime)
	{
		if (m_MonsterCount == 0)
		{
			CSVData::stInstanceMonster *monsterinfo;
			while (!m_InstanceMonster.empty())
			{
				monsterinfo = m_InstanceMonster.front();
				if (monsterinfo->nWave == m_NowWave)
				{
					if (AddMonster(monsterinfo->nMonsterID, monsterinfo->nX, monsterinfo->nY, monsterinfo->nZ))
					{
						++m_MonsterCount;
					}
					else
					{
						RunStateError("副本:%d 地图:%d 添加monster:%d 失败!", GetInstanceBaseID(), GetMapID(), monsterinfo->nMonsterID);
					}
					m_InstanceMonster.pop_front();
				}
			}
		}
	}
}
Exemplo n.º 3
0
//-------------------------------------------------------------
// 使用完成端口
//-------------------------------------------------------------
void CServerClient::OnReceive(int nErrorCode)
{	
	if(m_pServers==NULL)	return;


	long lPoint = 0;	// 当前有效缓冲区地址
	while( m_nSize >= 12 )
	{
		long lRLESize = *((long*)(&m_pBuffer[lPoint]));

		//对长度内容作校验
		DWORD dwLenCrc32;
		CCrc32Static::DataCrc32(&lRLESize,4,dwLenCrc32);
		DWORD lClientSize = *((DWORD*)(&m_pBuffer[lPoint]+4));
		if(dwLenCrc32 != lClientSize)
		{
			char str[256];
			sprintf(str, "%dSend MSG, Check Length ERROR.",GetMapID());
			PutDebugString(str);
			m_nSize=0;
			return;
		}

		// 缓冲区数据大于等于一个消息的长度
		if( lRLESize <= m_nSize )
		{
			CMessage* pMsg = CMessage::CreateMessage(&m_pBuffer[lPoint]+12, lRLESize-12);

			// 消息创建成功并压入消息队列
			if( pMsg )
			{
				DWORD dwConCrc32;
				CCrc32Static::DataCrc32(pMsg->GetMsgBuf(),pMsg->GetSize(),dwConCrc32);
				DWORD lClientConCrc32= *((DWORD*)(&m_pBuffer[lPoint]+8));
				//检测到内容不一致
				if(dwConCrc32 != lClientConCrc32)
				{
					char str[256];
					sprintf(str, "%d Send MSG %d, Check Content ERROR.",GetMapID(),pMsg->GetType());
					PutDebugString(str);
					m_nSize=0;
					return;
				}


				pMsg->SetClientSocketID(GetIndexID());
				pMsg->SetMapID(GetMapID());
				pMsg->SetCdkey(GetMapStr());
				pMsg->SetIP(GetDwordIP());
				
				m_pServers->GetRecvMessages()->PushMessage( pMsg );
				m_nSize -= lRLESize;
				lPoint += lRLESize;		// 移动缓冲区指针

				// 如果是超长的消息,把缓冲区大小调整回来
				if( m_nBufferSize > MAX_MESSAGE_LENGTH && m_nSize <= MAX_MESSAGE_LENGTH )
				{
					char *pTemp = new char[m_nSize];
					memcpy(pTemp, &m_pBuffer[lPoint], m_nSize);

					SAFE_DELETE(m_pBuffer);
					m_nBufferSize = MAX_MESSAGE_LENGTH;
					m_pBuffer = new char[m_nBufferSize];

					memcpy(m_pBuffer, pTemp, m_nSize);
					SAFE_DELETE(pTemp);
					lPoint = 0;
				}
			}
			else
			{
				// 出错,抛弃当前收到的所有数据
				m_nSize = 0;

				char str[256];
				sprintf(str, "CreateMessage ERROR");
				PutDebugString(str);
				return;
			}
		}
		else
		{
			// 出错,抛弃当前收到的所有数据
			if( lRLESize < 0 )
			{
				m_nSize = 0;

				char str[256];
				sprintf(str, "ERROR MSG(RleSize=%d), , Discard Recent Data.", lRLESize);
				PutDebugString(str);

				return;
			}

			// 收到消息大于最大消息缓冲区,开新的缓冲区
			if( lRLESize > m_nBufferSize )
			{
				char *pTemp = new char[m_nSize];
				memcpy(pTemp, &m_pBuffer[lPoint], m_nSize);
				SAFE_DELETE(m_pBuffer);
				m_nBufferSize = lRLESize;
				m_pBuffer = new char[m_nBufferSize];
				memcpy(m_pBuffer, pTemp, m_nSize);
				SAFE_DELETE(pTemp);

#ifdef _DEBUG
				char str[256];
				sprintf(str, "\nOverflaw MSG Size = %d\n", m_nBufferSize);
				OutputDebugString(str);
#endif
				return;
			}

#ifdef _DEBUG
			char str[256];
			sprintf(str, "\nHalf-baked MSG m_nSize = %d, Point = %d\n", m_nSize, lPoint);
			OutputDebugString(str);
#endif
			break;
		}
	}

	// 把不完全的消息移动到缓冲区头部
	if( lPoint > 0 )
	{
		memmove(m_pBuffer, &m_pBuffer[lPoint], m_nSize);
		lPoint = 0;
	}

}