Example #1
0
void CAISocket::RecvNpcMoveResult(char *pBuf)
{
	// sungyong tw
	char send_buff[256];
	int index = 0, send_index = 0;
	BYTE		flag;			// 01(INFO_MODIFY)	: NPC 정보 변경
								// 02(INFO_DELETE)	: NPC 정보 삭제
	short		nid;			// NPC index
	float		fPosX;			// X Position
	float		fPosZ;			// Z Position
	float		fPosY;			// Y Position
	float		fSecForMetor;	// Sec당 metor
	flag = GetByte(pBuf,index);
	nid = GetShort(pBuf,index);
	fPosX = Getfloat(pBuf, index);
	fPosZ = Getfloat(pBuf, index);
	fPosY = Getfloat(pBuf, index);
	fSecForMetor = Getfloat(pBuf, index);

	CNpc* pNpc = m_pMain->m_arNpcArray.GetData( nid );
	if(!pNpc)
		return;

	if( pNpc->m_NpcState == NPC_DEAD || pNpc->m_iHP <= 0 ) {	// Npc 상태 동기화 불량,, 재요청..
		SetByte( send_buff, AG_NPC_HP_REQ, send_index);
		SetShort( send_buff, nid, send_index );
		SetDWORD( send_buff, pNpc->m_iHP, send_index );
		Send( send_buff, send_index );
	}
	// ~sungyong tw
	
	pNpc->MoveResult(fPosX, fPosY, fPosZ, fSecForMetor);
}
void CGameSocket::RecvUserMoveEdge(char* pBuf)
{
//	TRACE("RecvUserMoveEdge()\n");
	int index = 0;
	short uid=-1, speed=0;
	float fX=-1.0f, fZ=-1.0f, fY=-1.0f;

	uid = GetShort( pBuf, index );
	fX = Getfloat(pBuf, index);
	fZ = Getfloat(pBuf, index);
	fY = Getfloat(pBuf, index);

	SetUid(fX, fZ, uid, speed);
//	TRACE("RecvUserMoveEdge()---> uid = %d, x=%f, z=%f \n", uid, fX, fZ);
}
Example #3
0
void CAISocket::RecvNpcInOut(char* pBuf)
{
	int index = 0, nid = 0, nType = 0;
	float fx = 0.0f, fz=0.0f, fy=0.0f;

	nType = GetByte( pBuf, index );
	nid = GetShort(pBuf, index);
	fx = Getfloat( pBuf, index );
	fz = Getfloat( pBuf, index );
	fy = Getfloat( pBuf, index );

	if(nid >= NPC_BAND)		{
		CNpc* pNpc = m_pMain->m_arNpcArray.GetData(nid);
		if(!pNpc)	return;
		pNpc->NpcInOut( nType, fx, fz, fy );
	}
}
void CGameSocket::RecvUserInfoAllData(char* pBuf)
{
	int index = 0;
	BYTE		byCount = 0;			// 마리수
	short uid=-1, sHp, sMp, len;
	BYTE bNation, bLevel, bZone, bAuthority=1;
	short sDamage, sAC, sPartyIndex=0;
	float fHitAgi, fAvoidAgi;
	char strName[MAX_ID_SIZE+1];

	TRACE(" ***** 유저의 모든 정보를 받기 시작합니다 ****** \n");

	byCount = GetByte(pBuf, index);
	for(int i=0; i<byCount; i++)
	{
		len = 0;
		memset(strName, 0x00, MAX_ID_SIZE+1);

		uid = GetShort( pBuf, index );
		len = GetShort( pBuf, index );
		GetString(strName, pBuf, len, index);
		bZone = GetByte( pBuf, index );
		bNation = GetByte( pBuf, index );
		bLevel = GetByte( pBuf, index );
		sHp = GetShort( pBuf, index );
		sMp = GetShort( pBuf, index );
		sDamage = GetShort( pBuf, index );
		sAC = GetShort( pBuf, index );
		fHitAgi = Getfloat( pBuf, index );
		fAvoidAgi = Getfloat( pBuf, index );
		sPartyIndex = GetShort( pBuf, index );
		bAuthority = GetByte( pBuf, index );

		if( len > MAX_ID_SIZE || len <= 0 ) {
			TRACE("###  RecvUserInfoAllData() Fail ---> uid = %d, name=%s, len=%d  ### \n", uid, strName, len);
			continue;
		}

		//CUser* pUser = m_pMain->GetActiveUserPtr(uid);
		//if(pUser == NULL)	continue;
		CUser* pUser = new CUser;
		pUser->Initialize();

		pUser->m_iUserId = uid;
		strcpy(pUser->m_strUserID, strName);
		pUser->m_curZone = bZone;
		pUser->m_pMap = m_pMain->GetZoneByID(bZone);
		pUser->m_bNation = bNation;
		pUser->m_sLevel = bLevel;
		pUser->m_sHP = sHp;
		pUser->m_sMP = sMp;
		//pUser->m_sSP = sSp;
		pUser->m_sHitDamage = sDamage;
		pUser->m_fHitrate = fHitAgi;
		pUser->m_fAvoidrate = fAvoidAgi;
		pUser->m_sAC = sAC;
		pUser->m_byIsOP = bAuthority;
		pUser->m_bLive = USER_LIVE;

		if(sPartyIndex != -1)	{
			pUser->m_byNowParty = 1;					// 파티중
			pUser->m_sPartyNumber = sPartyIndex;		// 파티 번호 셋팅
		}

		TRACE("****  RecvUserInfoAllData()---> uid = %d, %s, party_number=%d  ******\n", uid, strName, pUser->m_sPartyNumber);

		if(uid >= USER_BAND && uid < MAX_USER)	{
			m_pMain->m_pUser[uid] = pUser;
		}
	}

	TRACE(" ***** 유저의 모든 정보를 다 받았습니다 ****** \n");
}
void CGameSocket::RecvUserUpdate(char* pBuf)
{
	int index = 0;
	short uid=-1, sHP=0, sMP=0, sSP=0;
	BYTE byLevel;

	short sDamage, sAC;
	float fHitAgi, fAvoidAgi;
//
	short  sItemAC;
	BYTE   bTypeLeft;
	BYTE   bTypeRight;
	short  sAmountLeft;
	short  sAmountRight;
//

	uid = GetShort( pBuf, index );
	byLevel = GetByte(pBuf, index);
	sHP = GetShort( pBuf, index );
	sMP = GetShort( pBuf, index );
	sDamage = GetShort( pBuf, index );
	sAC = GetShort( pBuf, index );
	fHitAgi = Getfloat( pBuf, index );
	fAvoidAgi = Getfloat( pBuf, index );
//
	sItemAC = GetShort( pBuf, index ) ;
	bTypeLeft = GetByte(pBuf, index);
	bTypeRight = GetByte(pBuf, index);
	sAmountLeft = GetShort(pBuf, index);
	sAmountRight = GetShort(pBuf, index);
//

	// User List에서 User정보,, 삭제...
	CUser* pUser = m_pMain->GetUserPtr(uid);
	if(pUser == NULL)	return;

	if(pUser->m_sLevel < byLevel)		// level up
	{
		pUser->m_sHP = sHP;
		pUser->m_sMP = sMP;
		//pUser->m_sSP = sSP;
		_USERLOG* pUserLog = NULL;
		pUserLog = new _USERLOG;
		pUserLog->t = CTime::GetCurrentTime();
		pUserLog->byFlag = USER_LEVEL_UP;
		pUserLog->byLevel = byLevel;
		strcpy( pUserLog->strUserID, pUser->m_strUserID );
		pUser->m_UserLogList.push_back( pUserLog );
	}
	pUser->m_sLevel = byLevel;
	pUser->m_sHitDamage = sDamage;
	pUser->m_fHitrate = fHitAgi;
	pUser->m_fAvoidrate = fAvoidAgi;
	pUser->m_sAC = sAC;

//
	pUser->m_sItemAC = sItemAC ;
	pUser->m_bMagicTypeLeftHand = bTypeLeft;
	pUser->m_bMagicTypeRightHand = bTypeRight;
	pUser->m_sMagicAmountLeftHand = sAmountLeft;
	pUser->m_sMagicAmountRightHand = sAmountRight;
//
	char buff[256];	memset(buff, 0x00, 256);
	wsprintf(buff, "**** RecvUserUpdate -- uid = (%s,%d), HP = %d, level=%d->%d", pUser->m_strUserID, pUser->m_iUserId, pUser->m_sHP, byLevel, pUser->m_sLevel);
	//TimeTrace(buff);
	//TRACE("**** RecvUserUpdate -- uid = (%s,%d), HP = %d\n", pUser->m_strUserID, pUser->m_iUserId, pUser->m_sHP);
}
void CGameSocket::RecvAttackReq(char* pBuf)
{
	int index = 0;
	int sid = -1, tid = -1;
	BYTE type, result;
	char buff[256];
	memset( buff, 0x00, 256 );
	float rx=0.0f, ry=0.0f, rz=0.0f;
	float fDir = 0.0f;
	short sDamage, sAC;
	float fHitAgi, fAvoidAgi;
//
	short sItemAC;
	BYTE   bTypeLeft;
	BYTE   bTypeRight;
	short  sAmountLeft;
	short  sAmountRight;
//

	type = GetByte(pBuf,index);
	result = GetByte(pBuf,index);
	sid = GetShort(pBuf,index);
	tid = GetShort(pBuf,index);
	sDamage = GetShort( pBuf, index );
	sAC = GetShort( pBuf, index );
	fHitAgi = Getfloat( pBuf, index );
	fAvoidAgi = Getfloat( pBuf, index );
//
	sItemAC = GetShort(pBuf, index);
	bTypeLeft = GetByte(pBuf, index);
	bTypeRight = GetByte(pBuf, index);
	sAmountLeft = GetShort(pBuf, index);
	sAmountRight = GetShort(pBuf, index);
//

	//TRACE("RecvAttackReq : [sid=%d, tid=%d, zone_num=%d] \n", sid, tid, m_sSocketID);

	CUser* pUser = NULL;
	pUser = m_pMain->GetUserPtr(sid);
	if(pUser == NULL) return;
	//TRACE("RecvAttackReq 222 :  [id=%d, %s, bLive=%d, zone_num=%d] \n", pUser->m_iUserId, pUser->m_strUserID, pUser->m_bLive, m_sSocketID);

	if(pUser->m_bLive == USER_DEAD || pUser->m_sHP <= 0)
	{
		if(pUser->m_sHP > 0)
		{
			pUser->m_bLive = USER_LIVE;
			TRACE("##### CGameSocket-Attack Fail : User가 Heal된 경우.. [id=%d, %s, bLive=%d, hp=%d] ######\n", pUser->m_iUserId, pUser->m_strUserID, pUser->m_bLive, pUser->m_sHP);
		}		
		else
		{
			TRACE("##### CGameSocket-Attack Fail : UserDead  [id=%d, %s, bLive=%d, hp=%d] ######\n", pUser->m_iUserId, pUser->m_strUserID, pUser->m_bLive, pUser->m_sHP);
			// 죽은 유저이므로 게임서버에 죽은 처리를 한다...
			Send_UserError(sid, tid);
			return;
		}
	}
	pUser->m_sHitDamage = sDamage;
	pUser->m_fHitrate = fHitAgi;
	pUser->m_fAvoidrate = fAvoidAgi;
	pUser->m_sAC = sAC;
//
	pUser->m_sItemAC = sItemAC;
	pUser->m_bMagicTypeLeftHand = bTypeLeft;
	pUser->m_bMagicTypeRightHand = bTypeRight;
	pUser->m_sMagicAmountLeftHand = sAmountLeft;
	pUser->m_sMagicAmountRightHand = sAmountRight;
//

	pUser->Attack(sid, tid);
}
void CGameSocket::RecvUserInOut(char* pBuf)
{
	int index = 0;
	BYTE bType=-1;
	short uid=-1, len=0;
	char strName[MAX_ID_SIZE+1];
	memset(strName, 0x00, MAX_ID_SIZE+1);
	float fX=-1, fZ=-1;

	bType = GetByte( pBuf, index );
	uid = GetShort( pBuf, index );
	len = GetShort( pBuf, index );
	GetString(strName, pBuf, len, index);
	fX = Getfloat(pBuf, index);
	fZ = Getfloat(pBuf, index);

	if(fX < 0 || fZ < 0)
	{
		TRACE("Error:: RecvUserInOut(),, uid = %d, fX=%.2f, fZ=%.2f\n", uid, fX, fZ);
		return;
	}
//	TRACE("RecvUserInOut(),, uid = %d\n", uid);

	int region_x = 0, region_z=0;
	int x1 = (int)fX / TILE_SIZE;
	int z1 = (int)fZ / TILE_SIZE;
	region_x = (int)fX / VIEW_DIST; 
	region_z = (int)fZ / VIEW_DIST;

	// 수정할것,,, : 지금 존 번호를 0으로 했는데.. 유저의 존 정보의 번호를 읽어야,, 함,,
	MAP* pMap = NULL;
	//m_pMain->g_arZone[pUser->m_curZone];

	CUser* pUser = m_pMain->GetUserPtr(uid);

//	TRACE("^^& RecvUserInOut( type=%d )-> User(%s, %d),, zone=%d, index=%d, region_x=%d, y=%d\n", bType, pUser->m_strUserID, pUser->m_iUserId, pUser->m_curZone, pUser->m_sZoneIndex, region_x, region_z);

	if(pUser != NULL)
	{
	//	TRACE("##### Fail : ^^& RecvUserInOut() [name = %s]. state=%d, hp=%d\n", pUser->m_strUserID, pUser->m_bLive, pUser->m_sHP);
		BOOL bFlag = FALSE;
		
		if(pUser->m_bLive == USER_DEAD || pUser->m_sHP <= 0)
		{
			if(pUser->m_sHP > 0)
			{
				pUser->m_bLive = TRUE;
				TRACE("##### CGameSocket-RecvUserInOut Fail : UserHeal  [id=%s, bLive=%d, hp=%d], fX=%.2f, fZ=%.2f ######\n", pUser->m_strUserID, pUser->m_bLive, pUser->m_sHP, fX, fZ);
			}
			else
			{
				TRACE("##### CGameSocket-RecvUserInOut Fail : UserDead  [id=%s, bLive=%d, hp=%d], fX=%.2f, fZ=%.2f ######\n", pUser->m_strUserID, pUser->m_bLive, pUser->m_sHP, fX, fZ);
				// 죽은 유저이므로 게임서버에 죽은 처리를 한다...
				//Send_UserError(uid);
				//return;
			}
		}

		pMap = pUser->GetMap();

		if(pMap == NULL)
		{
			TRACE("#### Fail : pMap == NULL ####\n");
			return;
		}

		if(x1 < 0 || z1 < 0 || x1 > pMap->m_sizeMap.cx || z1 > pMap->m_sizeMap.cy)
		{
			TRACE("#### RecvUserInOut Fail : [name=%s], x1=%d, z1=%d #####\n", pUser->m_strUserID, region_x, region_z);
			return;
		}
		// map 이동이 불가능이면 User등록 실패..
		//if(pMap->m_pMap[x1][z1].m_sEvent == 0) return;
		if(region_x > pMap->GetXRegionMax() || region_z > pMap->GetZRegionMax())
		{
			TRACE("#### GameSocket-RecvUserInOut() Fail : [name=%s], nRX=%d, nRZ=%d #####\n", pUser->m_strUserID, region_x, region_z);
			return;
		}

		//strcpy(pUser->m_strUserID, strName);
		pUser->m_curx = pUser->m_fWill_x = fX;
		pUser->m_curz = pUser->m_fWill_z = fZ;

		//bFlag = pUser->IsOpIDCheck(strName);
		//if(bFlag)	pUser->m_byIsOP = 1;

		if(bType == 2)	{		// region out
			// 기존의 region정보에서 User의 정보 삭제..
			pMap->RegionUserRemove(region_x, region_z, uid);
			//TRACE("^^& RecvUserInOut()-> User(%s, %d)를 Region에서 삭제..,, zone=%d, index=%d, region_x=%d, y=%d\n", pUser->m_strUserID, pUser->m_iUserId, pUser->m_curZone, pUser->m_sZoneIndex, region_x, region_z);
		}
		else	{				// region in
			if(pUser->m_sRegionX != region_x || pUser->m_sRegionZ != region_z)	{
				pUser->m_sRegionX = region_x;		pUser->m_sRegionZ = region_z;
				pMap->RegionUserAdd(region_x, region_z, uid);
				//TRACE("^^& RecvUserInOut()-> User(%s, %d)를 Region에 등록,, zone=%d, index=%d, region_x=%d, y=%d\n", pUser->m_strUserID, pUser->m_iUserId, pUser->m_curZone, pUser->m_sZoneIndex, region_x, region_z);
			}
		}
	}
}
void CGameSocket::RecvUserInfo(char* pBuf)
{
//	TRACE("RecvUserInfo()\n");
	int index = 0;
	short uid=-1, sHp, sMp, sLength = 0;
	BYTE bNation, bLevel, bZone, bAuthority=1;
	short sDamage, sAC;
	float fHitAgi, fAvoidAgi;
	char strName[MAX_ID_SIZE+1];
	memset(strName, 0x00, MAX_ID_SIZE+1);
//
	short  sItemAC;
	BYTE   bTypeLeft;
	BYTE   bTypeRight;
	short  sAmountLeft;
	short  sAmountRight;
//
	uid = GetShort( pBuf, index );
	sLength = GetShort( pBuf, index );
	if( sLength > MAX_ID_SIZE || sLength <= 0 ) {
		char countstr[256];
		memset( countstr, NULL, 256 );
		CTime cur = CTime::GetCurrentTime();
		sprintf( countstr, "RecvUserInfo() Fail : %d월 %d일 %d시 %d분 - uid=%d, name=%s\r\n", cur.GetMonth(), cur.GetDay(), cur.GetHour(), cur.GetMinute(), uid, strName);
		LogFileWrite( countstr );
		TRACE("###  RecvUserInfo() Fail ---> uid = %d, name=%s  ### \n", uid, strName);
		return;
	}
	GetString(strName, pBuf, sLength, index);
	bZone = GetByte( pBuf, index );
	bNation = GetByte( pBuf, index );
	bLevel = GetByte( pBuf, index );
	sHp = GetShort( pBuf, index );
	sMp = GetShort( pBuf, index );
	sDamage = GetShort( pBuf, index );
	sAC = GetShort( pBuf, index );
	fHitAgi = Getfloat( pBuf, index );
	fAvoidAgi = Getfloat( pBuf, index );
//
	sItemAC = GetShort(pBuf, index);
	bTypeLeft = GetByte(pBuf, index);
	bTypeRight = GetByte(pBuf, index);
	sAmountLeft = GetShort(pBuf, index);
	sAmountRight = GetShort(pBuf, index);
	bAuthority = GetByte(pBuf, index);
//

	//CUser* pUser = m_pMain->GetActiveUserPtr(uid);
	//if( pUser == NULL )		return;
	CUser* pUser = new CUser;
	pUser->Initialize();

	pUser->m_iUserId = uid;
	strcpy(pUser->m_strUserID, strName);
	pUser->m_curZone = bZone;
	pUser->m_pMap = m_pMain->GetZoneByID(bZone);
	pUser->m_bNation = bNation;
	pUser->m_sLevel = bLevel;
	pUser->m_sHP = sHp;
	pUser->m_sMP = sMp;
	//pUser->m_sSP = sSp;
	pUser->m_sHitDamage = sDamage;
	pUser->m_fHitrate = fHitAgi;
	pUser->m_fAvoidrate = fAvoidAgi;
	pUser->m_sAC = sAC;
	pUser->m_bLive = USER_LIVE;
//
	pUser->m_sItemAC = sItemAC;
	pUser->m_bMagicTypeLeftHand = bTypeLeft;
	pUser->m_bMagicTypeRightHand = bTypeRight;
	pUser->m_sMagicAmountLeftHand = sAmountLeft;
	pUser->m_sMagicAmountRightHand = sAmountRight;
	pUser->m_byIsOP = bAuthority;
//

	TRACE("****  RecvUserInfo()---> uid = %d, name=%s, leng=%d  ******\n", uid, strName, sLength);

	if(uid >= USER_BAND && uid < MAX_USER)	{
		m_pMain->m_pUser[uid] = pUser;
	}

	_USERLOG* pUserLog = NULL;
	pUserLog = new _USERLOG;
	pUserLog->t = CTime::GetCurrentTime();
	pUserLog->byFlag = USER_LOGIN;
	pUserLog->byLevel = pUser->m_sLevel;
	strcpy( pUserLog->strUserID, pUser->m_strUserID );
	pUser->m_UserLogList.push_back( pUserLog );
}
Example #9
0
void CAISocket::RecvNpcGiveItem(char* pBuf)
{
	int index = 0, send_index = 0;
	char send_buff[1024];
	short sUid, sNid, sZone, regionx, regionz;
	float fX, fZ, fY;
	BYTE byCount;
	int nItemNumber[NPC_HAVE_ITEM_LIST];
	short sCount[NPC_HAVE_ITEM_LIST];
	_ZONE_ITEM* pItem = NULL;
	C3DMap* pMap = NULL;
	CUser* pUser = NULL;

	sUid = GetShort(pBuf,index);	// Item을 가져갈 사람의 아이디... (이것을 참조해서 작업하셈~)
	sNid = GetShort(pBuf,index);
	sZone = GetShort(pBuf, index);
	regionx = GetShort( pBuf, index );
	regionz = GetShort( pBuf, index );
	fX = Getfloat(pBuf,index);
	fZ = Getfloat(pBuf,index);
	fY = Getfloat(pBuf,index);
	byCount = GetByte(pBuf,index);
	for(int i=0; i<byCount; i++)
	{
		nItemNumber[i] = GetDWORD(pBuf, index);
		sCount[i] = GetShort(pBuf,index);
	}

	if( sUid < 0 || sUid >= MAX_USER ) return;
	pMap = m_pMain->GetZoneByID(sZone);
	if (pMap == NULL)
		return;

	pItem = new _ZONE_ITEM;
	for(int i=0; i<6; i++) {
		pItem->itemid[i] = 0;
		pItem->count[i] = 0;
	}
	pItem->bundle_index = pMap->m_wBundle;
	pItem->time = TimeGet();
	pItem->x = fX;
	pItem->z = fZ;
	pItem->y = fY;
	for(int i=0; i<byCount; i++) {
		if( m_pMain->m_ItemtableArray.GetData(nItemNumber[i]) ) {
			pItem->itemid[i] = nItemNumber[i];
			pItem->count[i] = sCount[i];
		}
	}

	if (!pMap->RegionItemAdd(regionx, regionz, pItem ))
	{
		delete pItem;
		return;
	}

	pUser = m_pMain->GetUserPtr(sUid);
	if (pUser == NULL) 
		return;
	
	send_index = 0;

	SetByte( send_buff, WIZ_ITEM_DROP, send_index );
	SetShort( send_buff, sNid, send_index );
	SetDWORD( send_buff, pItem->bundle_index, send_index );
	if( pUser->m_sPartyIndex == -1 )
		pUser->Send( send_buff, send_index );
	else
		m_pMain->Send_PartyMember( pUser->m_sPartyIndex, send_buff, send_index );
}
Example #10
0
void CAISocket::RecvNpcInfo(char* pBuf)
{
	int index = 0;

	BYTE		Mode;			// 01(INFO_MODIFY)	: NPC 정보 변경
								// 02(INFO_DELETE)	: NPC 정보 삭제
	short		nid;			// NPC index
	short		sid;			// NPC index
	short		sPid;			// NPC Picture Number
	short		sSize = 100;	// NPC Size
	int			iWeapon_1;		// 오른손 무기
	int			iWeapon_2;		// 왼손  무기
	BYTE        bZone;			// Current zone number
	char		szName[MAX_NPC_SIZE+1];		// NPC Name
	BYTE		byGroup;		// 소속 집단
	BYTE		byLevel;			// level
	float		fPosX;			// X Position
	float		fPosZ;			// Z Position
	float		fPosY;			// Y Position
	BYTE		byDirection;	// 방향
	BYTE		tState;			// NPC 상태
								// 00	: NPC Dead
								// 01	: NPC Live
	BYTE		tNpcKind;		// 00	: Monster
								// 01	: NPC
	int		iSellingGroup;
  	int		nMaxHP;			// 최대 HP
	int		nHP;			// 현재 HP
	BYTE		byGateOpen;
	short		sHitRate;		// 공격 성공률
	BYTE		byObjectType;	// 보통 : 0, 특수 : 1

	Mode = GetByte(pBuf, index);
	nid = GetShort(pBuf, index);
	sid = GetShort(pBuf, index);
	sPid = GetShort(pBuf, index);
	sSize = GetShort(pBuf, index);
	iWeapon_1 = GetDWORD(pBuf, index);
	iWeapon_2 = GetDWORD(pBuf, index);
	bZone = GetByte(pBuf, index);
	int nLength = GetVarString(szName, pBuf, sizeof(BYTE), index);
	if(nLength < 0 || nLength > MAX_NPC_SIZE) return;		// 잘못된 monster 아이디 
	byGroup = GetByte(pBuf, index);
	byLevel  = GetByte(pBuf, index);
	fPosX = Getfloat(pBuf, index);
	fPosZ = Getfloat(pBuf, index);
	fPosY = Getfloat(pBuf, index);
	byDirection = GetByte(pBuf, index);
	tState = GetByte(pBuf, index);
	tNpcKind = GetByte(pBuf, index);
	iSellingGroup = GetDWORD(pBuf, index);
	nMaxHP = GetDWORD(pBuf, index);
	nHP = GetDWORD(pBuf, index);
	byGateOpen = GetByte(pBuf, index);
	sHitRate = GetShort(pBuf, index);
	byObjectType = GetByte(pBuf, index);

	CNpc* pNpc = NULL;

	pNpc = m_pMain->m_arNpcArray.GetData(nid);
	if(!pNpc)	return;

	pNpc->m_NpcState = NPC_DEAD;

	if( pNpc->m_NpcState == NPC_LIVE )	{	// 살아 있는데 또 정보를 받는 경우
		char strLog[256]; 
		CTime t = CTime::GetCurrentTime();
		sprintf_s(strLog, sizeof(strLog), "## time(%d:%d-%d) npc regen check(%d) : nid=%d, name=%s, x=%d, z=%d, rx=%d, rz=%d ## \r\n", t.GetHour(), t.GetMinute(), t.GetSecond(), pNpc->m_NpcState, nid, szName, (int)pNpc->m_fCurX, (int)pNpc->m_fCurZ, pNpc->m_sRegion_X, pNpc->m_sRegion_Z);
		EnterCriticalSection( &g_LogFile_critical );
		m_pMain->m_RegionLogFile.Write( strLog, strlen(strLog) );
		LeaveCriticalSection( &g_LogFile_critical );
		TRACE(strLog);
		// to-do: replace with m_pMain->WriteRegionLog(...);
	}

	pNpc->m_NpcState = NPC_LIVE;
	
	pNpc->m_sNid = nid;
	pNpc->m_sSid = sid;
	pNpc->m_sPid = sPid;
	pNpc->m_sSize = sSize;
	pNpc->m_iWeapon_1 = iWeapon_1;
	pNpc->m_iWeapon_2 = iWeapon_2;
	strcpy(pNpc->m_strName, szName);
	pNpc->m_byGroup = byGroup;
	pNpc->m_byLevel = byLevel;
	pNpc->m_bCurZone = bZone;
	pNpc->m_pMap = m_pMain->GetZoneByID(bZone);
	pNpc->m_fCurX = fPosX;
	pNpc->m_fCurZ = fPosZ;
	pNpc->m_fCurY = fPosY;
	pNpc->m_byDirection = byDirection;
	pNpc->m_NpcState = tState;
	pNpc->m_tNpcType = tNpcKind;
	pNpc->m_iSellingGroup = iSellingGroup;
	pNpc->m_iMaxHP = nMaxHP;
	pNpc->m_iHP = nHP;
	pNpc->m_byGateOpen = byGateOpen;
	pNpc->m_sHitRate = sHitRate;
	pNpc->m_byObjectType = byObjectType;

	if (pNpc->GetMap() == NULL)
		return;

	int nRegX = (int)fPosX / VIEW_DISTANCE;
	int nRegZ = (int)fPosZ / VIEW_DISTANCE;

	pNpc->m_sRegion_X = nRegX;
	pNpc->m_sRegion_Z = nRegZ;

	_OBJECT_EVENT* pEvent = NULL;
	if( pNpc->m_byObjectType == SPECIAL_OBJECT )	{
		pEvent = pNpc->GetMap()->GetObjectEvent( pNpc->m_sSid );
		if( pEvent )	pEvent->byLife = 1;
	}

	if(Mode == 0)	{
		TRACE("RecvNpcInfo - dead monster nid=%d, name=%s\n", pNpc->m_sNid, pNpc->m_strName);
		return;
	}

	pNpc->NpcInOut(NPC_IN, fPosX, fPosZ, fPosY);
}
Example #11
0
// ai server에 처음 접속시 npc의 모든 정보를 받아온다..
void CAISocket::RecvNpcInfoAll(char* pBuf)
{
	int index = 0;
	BYTE		byCount = 0;			// 마리수
	BYTE        byType;				// 0:처음에 등장하지 않는 몬스터, 1:등장
	short		nid;				// NPC index
	short		sid;				// NPC index
	BYTE		bZone;				// Current zone number
	short		sPid;				// NPC Picture Number
	short		sSize = 100;				// NPC Size
	int			iweapon_1;
	int			iweapon_2;
	char		szName[MAX_NPC_SIZE+1];		// NPC Name
	BYTE		byGroup;		// 소속 집단
	BYTE		byLevel;		// level
	float		fPosX;			// X Position
	float		fPosZ;			// Z Position
	float		fPosY;			// Y Position
	BYTE		byDirection;	// 
	BYTE		tNpcType;		// 00	: Monster
								// 01	: NPC
	int		iSellingGroup;
  	int		nMaxHP;			// 최대 HP
	int		nHP;			// 현재 HP
	BYTE		byGateOpen;		// 성문일경우 열림과 닫힘 정보
	short		sHitRate;
	BYTE		byObjectType;	// 보통 : 0, 특수 : 1

	byCount = GetByte(pBuf, index);

	for(int i=0; i<byCount; i++)
	{
		byType = GetByte(pBuf, index);
		nid = GetShort(pBuf, index);
		sid = GetShort(pBuf, index);
		sPid = GetShort(pBuf, index);
		sSize = GetShort(pBuf, index);
		iweapon_1 = GetDWORD(pBuf, index);
		iweapon_2 = GetDWORD(pBuf, index);
		bZone = GetByte(pBuf, index);
		int nLength = GetVarString(szName, pBuf, sizeof(BYTE), index);
		byGroup = GetByte(pBuf, index);
		byLevel  = GetByte(pBuf, index);
		fPosX = Getfloat(pBuf, index);
		fPosZ = Getfloat(pBuf, index);
		fPosY = Getfloat(pBuf, index);
		byDirection = GetByte(pBuf, index);
		tNpcType = GetByte(pBuf, index);
		iSellingGroup = GetDWORD(pBuf, index);
		nMaxHP = GetDWORD(pBuf, index);
		nHP = GetDWORD(pBuf, index);
		byGateOpen = GetByte(pBuf, index);
		sHitRate = GetShort(pBuf, index);
		byObjectType = GetByte(pBuf, index);

		//TRACE("RecvNpcInfoAll  : nid=%d, szName=%s, count=%d\n", nid, szName, byCount);

		if(nLength < 0 || nLength > MAX_NPC_SIZE)	{
			TRACE("#### RecvNpcInfoAll Fail : szName=%s\n", szName);
			continue;		// 잘못된 monster 아이디 
		}

		//TRACE("Recv --> NpcUserInfo : uid = %d, x=%f, z=%f.. \n", nid, fPosX, fPosZ);

		CNpc* pNpc = NULL;
		pNpc = new CNpc;
		if(pNpc == NULL)	{ 
			TRACE("#### Recv --> NpcUserInfoAll POINT Fail: uid=%d, sid=%d, name=%s, zone=%d, x=%f, z=%f.. \n", nid, sPid, szName, bZone, fPosX, fPosZ);
			continue;
		}
		pNpc->Initialize();

		pNpc->m_sNid = nid;
		pNpc->m_sSid = sid;
		pNpc->m_sPid = sPid;
		pNpc->m_sSize = sSize;
		pNpc->m_iWeapon_1 = iweapon_1;
		pNpc->m_iWeapon_2 = iweapon_2;
		strcpy(pNpc->m_strName, szName);
		pNpc->m_byGroup = byGroup;
		pNpc->m_byLevel = byLevel;
		pNpc->m_bCurZone = bZone;
		pNpc->m_pMap = m_pMain->GetZoneByID(bZone);
		pNpc->m_fCurX = fPosX;
		pNpc->m_fCurZ = fPosZ;
		pNpc->m_fCurY = fPosY;
		pNpc->m_byDirection = byDirection;
		pNpc->m_NpcState = NPC_LIVE;
		pNpc->m_tNpcType = tNpcType;
		pNpc->m_iSellingGroup = iSellingGroup;
		pNpc->m_iMaxHP = nMaxHP;
		pNpc->m_iHP = nHP;
		pNpc->m_byGateOpen = byGateOpen;
		pNpc->m_sHitRate = sHitRate;
		pNpc->m_byObjectType = byObjectType;
		pNpc->m_NpcState = NPC_LIVE;

		int nRegX = (int)fPosX / VIEW_DISTANCE;
		int nRegZ = (int)fPosZ / VIEW_DISTANCE;

		pNpc->m_sRegion_X = nRegX;
		pNpc->m_sRegion_Z = nRegZ;

		if (pNpc->GetMap() == NULL)
		{
			delete pNpc;
			pNpc = NULL;
			continue;
		}

		_OBJECT_EVENT* pEvent = NULL;
		if (pNpc->m_byObjectType == SPECIAL_OBJECT)
		{
			pEvent = pNpc->GetMap()->GetObjectEvent(pNpc->m_sSid);
			if( pEvent )	pEvent->byLife = 1;
		}

	//	TRACE("Recv --> NpcUserInfoAll : uid=%d, sid=%d, name=%s, x=%f, z=%f. gate=%d, objecttype=%d \n", nid, sPid, szName, fPosX, fPosZ, byGateOpen, byObjectType);

		if( !m_pMain->m_arNpcArray.PutData( pNpc->m_sNid, pNpc) ) {
			TRACE("Npc PutData Fail - %d\n", pNpc->m_sNid);
			delete pNpc;
			pNpc = NULL;
			continue;
		}

		if( byType == 0 )	{
			TRACE("Recv --> NpcUserInfoAll : 등록하면 안돼여,, uid=%d, sid=%d, name=%s\n", nid, sPid, szName);
			continue;		// region에 등록하지 말기...
		}

		pNpc->GetMap()->RegionNpcAdd(pNpc->m_sRegion_X, pNpc->m_sRegion_Z, pNpc->m_sNid);
	}
}