コード例 #1
0
void CGameSocket::RecvUserInfo(Packet & pkt)
{
	CUser *pUser = new CUser();

	pUser->Initialize();

	pkt.SByte();
	pkt >> pUser->m_iUserId >> pUser->m_strUserID >> pUser->m_bZone >> pUser->m_bNation 
		>> pUser->m_bLevel >> pUser->m_sHP >> pUser->m_sMP >> pUser->m_sHitDamage
		>> pUser->m_sAC >> pUser->m_fHitrate >> pUser->m_fAvoidrate >> pUser->m_sItemAC 
		>> pUser->m_bMagicTypeLeftHand >> pUser->m_bMagicTypeRightHand
		>> pUser->m_sMagicAmountLeftHand >> pUser->m_sMagicAmountRightHand
		>> pUser->m_byIsOP >> pUser->m_bInvisibilityType;

	if (pUser->GetName().empty() || pUser->GetName().length() > MAX_ID_SIZE)
	{
		delete pUser;
		return;
	}

	pUser->m_pMap = g_pMain->GetZoneByID(pUser->m_bZone);
	pUser->m_bLive = AI_USER_LIVE;

	TRACE("****  RecvUserInfo()---> uid = %d, name=%s ******\n", 
		pUser->GetID(), pUser->GetName().c_str());

	if (pUser->GetID() < MAX_USER)
		g_pMain->m_pUser[pUser->GetID()] = pUser;
	else 
		delete pUser;
}
コード例 #2
0
void CGameSocket::RecvUserInfoAllData(Packet & pkt)
{
	uint8 byCount = pkt.read<uint8>();
	pkt.SByte();
	for (int i = 0; i < byCount; i++)
	{
		CUser* pUser = new CUser();

		pUser->Initialize();

		pkt >> pUser->m_iUserId >> pUser->m_strUserID >> pUser->m_bZone
			>> pUser->m_bNation >> pUser->m_bLevel 
			>> pUser->m_sHP >> pUser->m_sMP
			>> pUser->m_sHitDamage >> pUser->m_sAC
			>> pUser->m_fHitrate >> pUser->m_fAvoidrate
			>> pUser->m_sPartyNumber >> pUser->m_byIsOP
			>> pUser->m_bInvisibilityType;

		if (pUser->GetName().empty() || pUser->GetName().length() > MAX_ID_SIZE)
		{
			TRACE("###  RecvUserInfoAllData() Fail ---> uid = %d, name=%s, len=%d  ### \n", 
				pUser->GetID(), pUser->GetName().c_str(), pUser->GetName().length());

			delete pUser;
			continue;
		}

		pUser->m_pMap = g_pMain->GetZoneByID(pUser->GetZoneID());
		pUser->m_bLive = AI_USER_LIVE;
		if (pUser->m_sPartyNumber != -1)
			pUser->m_byNowParty = 1;

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

		if (pUser->GetID() < MAX_USER)
		{
			// Does a user already exist? Free them (I know, tacky...)
			if (g_pMain->m_pUser[pUser->GetID()] != nullptr)
				delete g_pMain->m_pUser[pUser->GetID()];

			g_pMain->m_pUser[pUser->GetID()] = pUser;
		}
		else
		{
			delete pUser;
		}
	}
}
コード例 #3
0
// function CChatRoom::Kick
//  boots a user from this chatroom.  if notify is true, then send a message to everyone else in the chatroom of this event
void CChatRoom::Kick(int user, bool notify )
{
	Pthread_mutex_lock(&m_InsideUsersMutex, __FUNCTION__);
	list<int>::iterator iter = m_UsersInside.begin();
	while ( iter != m_UsersInside.end() && (*iter) != user )
		iter++;
	if ( iter != m_UsersInside.end() )
	{
		CLog::Record("User %d kicked from %s", user, m_sName.c_str());

		m_UsersInside.erase(iter);
		
		char buff[5];
		char* temp = buff;
		*temp = PACK_BOOTFROMCHAT;
		temp++;
		(*(int*)temp) = this->m_ChatID;
		Pthread_mutex_lock(&CUser::m_UserMutex, __FUNCTION__);
		CUser* pUser = CUser::GetUser(user);
		if ( pUser != NULL )
		{
			CLog::Record("Sending PACK_BOOTFROMCHAT to %s", pUser->GetName());
			pUser->SendTo(buff, sizeof(buff));
		}
		Pthread_mutex_unlock(&CUser::m_UserMutex, __FUNCTION__);
	}
	else
		notify = false;
	Pthread_mutex_unlock(&m_InsideUsersMutex, __FUNCTION__);
	if ( notify )
		Kicked(user);
}
コード例 #4
0
ファイル: couplehelper.cpp プロジェクト: iceberry/flyffsf
void  CCoupleHelper::OnCoupleInfo( CUser* pUser,CAr & ar )
{
	u_long id ;
	ar>>id;
	CUser* pReq	= static_cast<CUser*>( prj.GetUserByID(id ) );
	if(!pReq)
		return;
	CCouple* pCouple	= m_pMgr->GetCouple( pReq->m_idPlayer );
	if( !pCouple )
	{
		pUser->SandCoupleInfo(pReq,0,NULL);
		return;
	}
	
	CUser* pPartner	= static_cast<CUser*>( prj.GetUserByID( pCouple->GetPartner(id ) ) );
	if(!pPartner)
	{
		return;
	}
	pUser->SandCoupleInfo(pReq,1,pPartner->GetName());
	//헙쩟bug
	//PlayerData* pPlayerData = CPlayerDataCenter::GetInstance()->GetPlayerData( pCouple->GetPartner(id ) );
	//if(!pPlayerData)
	//{
	//	return;
	//}
	//pUser->SandCoupleInfo(pReq,1,pPlayerData->szPlayer);
}
コード例 #5
0
ファイル: ChatHandler.cpp プロジェクト: Kocu/snoxd-koserver
void CUser::ChatTargetSelect(Packet & pkt)
{
	uint8 type = pkt.read<uint8>();

	// TO-DO: Replace this with an enum
	// Attempt to find target player in-game
	if (type == 1)
	{
		Packet result(WIZ_CHAT_TARGET, type);
		std::string strUserID;
		pkt >> strUserID;
		if (strUserID.empty() || strUserID.size() > MAX_ID_SIZE)
			return;

		CUser *pUser = g_pMain->GetUserPtr(strUserID, TYPE_CHARACTER);
		if (pUser == nullptr || pUser == this)
		{
			result << int16(0); 
		}
		else if (pUser->isBlockingPrivateChat())
		{
			result << int16(-1);
		}
		else
		{
			m_sPrivateChatUser = pUser->GetSocketID();
			result << int16(1) << pUser->GetName();
		}
		Send(&result);
	}
コード例 #6
0
void __CreateItem( DWORD dwIdMover, int v1, int v2 )	
#endif	// __JEFF_11
{
	CUser* pUser	= prj.GetUser( dwIdMover );
	ItemProp* pItemProp		= prj.GetItemProp( v1 );
	if( pItemProp )
		pUser->AddDefinedText( TID_EVE_REAPITEM, "\"%s\"", pItemProp->szName );
	CItemElem itemElem;
	itemElem.m_dwItemId		= v1;
	itemElem.m_nItemNum		= v2;
#ifdef __JEFF_11
	itemElem.SetAbilityOption( v3 );
#endif	// __JEFF_11
#if __VER >= 13 // __CHIPI_QUESTITEM_FLAG
	itemElem.SetFlag( v4 );
#endif // __CHIPI_QUESTITEM_FLAG
	if( pUser->CreateItem( &itemElem ) )
	{
		LogItemInfo aLogItem;
		aLogItem.Action = "Q";
		aLogItem.SendName = pUser->GetName();
		aLogItem.RecvName = "QUEST";
		aLogItem.WorldId = pUser->GetWorld()->GetID();
		aLogItem.Gold = aLogItem.Gold2 = pUser->GetGold();
		g_DPSrvr.OnLogItem( aLogItem, &itemElem, itemElem.m_nItemNum );
	}
}
コード例 #7
0
// function CChatRoom::Kicked
//  notifies everyone in the room that user has left
void CChatRoom::Kicked(int user)
{
	char message[1+2*sizeof(int)];
	list<int>::iterator iter;
	vector<int> toKick;

	message[0] = PACK_USERLEAVECHAT;
	*((int*)&message[1]) = this->m_ChatID;
	*((int*)&message[5]) = user;

	Pthread_mutex_lock(&m_InsideUsersMutex, __FUNCTION__);
	Pthread_mutex_lock(&CUser::m_UserMutex, __FUNCTION__);
	for ( iter = m_UsersInside.begin(); iter != m_UsersInside.end(); iter++ )
	{
		CUser* currUser = CUser::GetUser(*iter);
		// this shouldn't happen, but if a null user is found, just get rid of them from the room
		if ( currUser == 0 )
		{
			toKick.push_back(*iter);
			m_UsersInside.erase(iter);
			continue;
		}
		CLog::Record("Sending PACK_USERLEAVECHAT to %s", currUser->GetName());
		currUser->SendTo(message, sizeof(message));
	}
	Pthread_mutex_unlock(&CUser::m_UserMutex, __FUNCTION__);
	Pthread_mutex_unlock(&m_InsideUsersMutex, __FUNCTION__);

	if ( toKick.size() > 0 )
		Kicked(toKick);
}
コード例 #8
0
ファイル: PublicManage.cpp プロジェクト: obabywawa/UPIM
char* CPublicManage::GetServiceID(int nPublicID, char* szUserID, int tpid /* = 0 */)
{
	CLock m_csLock;
	CAutoLock autolock(&m_csLock);
	m_iCurPublic = nPublicID;
	COPYSTRARRAY(m_szCurUser,szUserID);
	m_iCurTp = tpid > 0?tpid:-1;

	BOOL bRet = FALSE;
	TpRelation tprelation;
	COPYSTRARRAY(m_pstrActiveID,"");
	for (int i = 0;i<m_vTpRelation.size();i++){//遍历公众号对应路由关系表{
		tprelation = m_vTpRelation[i];
		if (nPublicID == tprelation.publicid){
			if (tpid == -1) m_iCurTp = tprelation.tpid;
			std::vector<TpRule>::iterator it_tprule =
				find_if(m_vTpRule.begin(),m_vTpRule.end(),find_id<TpRule>(m_iCurTp));
			if (it_tprule != m_vTpRule.end()){
				switch(it_tprule->typtype){
				case TP_TIME:
					bRet = TimeTP(&(*it_tprule));
					break;
				case TP_PROBLEM:
					bRet = ProblemTP(m_iCurTp);
					break;
				case TP_INTERFACE:
					bRet = InterfaceTP(&(*it_tprule));
					break;
				case TP_CUSTOMERSERVICE:
					bRet = DirectCustomerService(&(*it_tprule));
					break;
				case TP_OTHER:
				default:
					bRet = FALSE;
					break;
				}
			}
		}
		if(bRet) break;
	}

	if (bRet)
	{
		if(m_listUser.size()){
			CUser *pCurUser = m_listUser.back();
			if(!strcmp(pCurUser->GetName(),szUserID)) 
				return pCurUser->GetCurCustomer()->GetName();
		}
		
		CUser *pUser = new CUser(szUserID);
		pUser->Attach(m_pCurCustomer);
		pUser->SetCurPublic(nPublicID);
		pUser->SetCurTp(m_iCurTp);
		m_listUser.push_back(pUser);	

		COPYSTRARRAY(m_pstrActiveID,m_pCurCustomer->GetName());
		
	}
	return m_pstrActiveID;
}
コード例 #9
0
ファイル: partyquest.cpp プロジェクト: iceberry/flyffsf
void CPartyQuestProcessor::SetPartyQuest( int nQuestId, int nState, int ns, int nf, u_long idParty, OBJID objidWormon )
{
	if( nQuestId >= MAX_PARTY_QUEST )
	{
		Error( "" );
		return;
	}
	PARTYQUESTPROP* pProp	= prj.GetPartyQuestProp( nQuestId );
	if( !pProp )
	{
		Error( "" );
		return;
	}

	TRACE( "SET_PARTY_QUEST, %d, %d, %d\n", nQuestId, idParty, objidWormon );
	PPARTYQUESTELEM	pElem	= &m_pElem[nQuestId];
	pElem->nId	= nQuestId;
	pElem->nState	= nState;
	pElem->idParty	= idParty;
	pElem->dwEndTime	= GetTickCount() + MIN( 60 );
	
	pElem->nProcess		= PQP_WORMON;
	pElem->ns	= ns;
	pElem->nf	= nf;
	pElem->objidWormon	= objidWormon;
	pElem->nCount	= 0;

	// 유저에게 공략시간을 넘겨준다...
	SendQuestLimitTime( PQP_WORMON, MIN( 60 ), idParty );

	// 파티퀘스트시작시 정보를 파일에 기록한다.
	CString strFileName = "StartPartyQuestInfo.txt";
	CString strQuestInfo;
	CString strMemberName;
	CString strDateTime;
	
	CTime time = CTime::GetCurrentTime();
	strDateTime.Format( "DATE : %d%.2d%.2d\nTIME : %d::%d::%d\n", time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond() );
	strQuestInfo.Format( "QUEST ID = %d, PARTY ID = %d, WORMON ID = %d\n", nQuestId, idParty, objidWormon );
	
	CParty* pParty	= g_PartyMng.GetParty( idParty );
	if( pParty )
	{
		int i; for( i = 0 ; i < pParty->GetSizeofMember() ; ++i )
		{
			CUser* pUsertmp = (CUser *)prj.GetUserByID( pParty->GetPlayerId( i ) );
			if( IsValidObj( pUsertmp ) )
			{
				strMemberName += pUsertmp->GetName();
				strMemberName += "\n";
			}
		}
	}

	FILEOUT( strFileName, "%s%s%s\n", strDateTime, strQuestInfo, strMemberName );
	////////////////////////////////////////////////////////////////////////////////////////////
}
コード例 #10
0
ファイル: PublicManage.cpp プロジェクト: obabywawa/UPIM
CCustomer* CPublicManage::GetCurMaxDispatchCustomer(int id,int disPatchType)
{
	if (m_listUser.size())
	{
		CUser* pCurUser = m_listUser.back();
		CCustomer* pCurCustomer = pCurUser->GetCurCustomer();
		if (pCurUser && pCurUser->GetState() && 
			m_iCurPublic == pCurUser->GetCurPublic() &&
			!strcmp(m_szCurUser,pCurUser->GetName()) &&
			m_iCurTp     == pCurUser->GetCurTp() &&
			pCurCustomer->GetCurIncode() == id &&
			pCurCustomer->GetDisType() == disPatchType
			){
			pCurCustomer->SetSessionState(FALSE);
			pCurCustomer->SetClientNum(pCurCustomer->GetClientNum()-1);
			return pCurCustomer;
		}
	}

	std::vector<char*> vCustName;
	for (int i = 0;i<m_vDispatchRelation.size();i++){
		if (m_vDispatchRelation[i].incodeid == id){
			vCustName.push_back(m_vDispatchRelation[i].customerservice);
		}
	}
	std::list<CCustomer*> list_tempCust; 
	std::vector<char*>::iterator itCustName = vCustName.begin();
	while (itCustName!=vCustName.end()){
		MYSTATE myState = (MYSTATE)0;
		std::list<CCustomer*>::iterator it_CustObj = m_listCustomer.begin();
		for (;it_CustObj!=m_listCustomer.end();it_CustObj++)
		{
			if(!strcmp((*it_CustObj)->GetName(),*itCustName))
				break;
		}
		GetCustomerState((*it_CustObj)->GetName(),myState);
		if (MYSTATE_NORMAL == myState &&
			(*it_CustObj)->GetDisType() == disPatchType && 
			(*it_CustObj)->GetClientNum() < MAX_CLIENTNUM){
				list_tempCust.push_back(*it_CustObj);
		}
		itCustName++;
	}
	
	std::list<CCustomer*>::iterator itmax_index = list_tempCust.begin();
	if (itmax_index== list_tempCust.end()) return NULL;
	std::list<CCustomer*>::iterator itmax_temp = list_tempCust.begin();
	if (list_tempCust.size() > 1) ++itmax_temp;
	for (;itmax_index != list_tempCust.end();itmax_index++){
		if((*itmax_index)->CmpByDisType(*itmax_temp,disPatchType) > 0 ){
			itmax_temp = itmax_index;
		}
	}
	return *itmax_temp;
}
コード例 #11
0
ファイル: couplehelper.cpp プロジェクト: iceberry/flyffsf
void CCoupleHelper::OnCoupleResult( CAr & ar )
{
	u_long idProposer, idTarget;
	int nResult;
	ar >> idProposer >> idTarget >> nResult;
	election::OutputDebugString( "S: CCoupleHelper.OnCoupleResult: %d, %d, %d", idProposer, idTarget, nResult );
	CUser* pProposer	= static_cast<CUser*>( prj.GetUserByID( idProposer ) );
	CUser* pTarget	= static_cast<CUser*>( prj.GetUserByID( idTarget ) );
	if( nResult == 0 )
	{
		m_pMgr->Couple( idProposer, idTarget );
		const char* pszProposer	= CPlayerDataCenter::GetInstance()->GetPlayerString( idProposer );
		const char* pszTarget	= CPlayerDataCenter::GetInstance()->GetPlayerString( idTarget );
		if( !pszProposer )	pszProposer	= "";
		if( !pszTarget )	pszTarget	= "";
		if( IsValidObj( pProposer ) )
		{
			pProposer->AddCoupleResult( idTarget, pszTarget );
#if __VER >= 13 // __HONORABLE_TITLE			// 달인
			pProposer->SetHonorAdd(	HS_COUPLE_COUNT,HI_COUNT_CHECK );
#endif	// __HONORABLE_TITLE
			g_UserMng.SandCoupleInfo(pProposer,1, pszTarget);
		}
		if( IsValidObj( pTarget ) )
		{
			pTarget->AddCoupleResult( idProposer, pszProposer );
#if __VER >= 13 // __HONORABLE_TITLE			// 달인
			pTarget->SetHonorAdd(HS_COUPLE_COUNT,HI_COUNT_CHECK );
#endif	// __HONORABLE_TITLE			// 달인
			g_UserMng.SandCoupleInfo(pTarget,1, pszProposer);
		}
		CString szString;
		szString.Format("鯤소 %s 宅鯤소 %s 써槨죄헙쩟,댕소龍르儉쳬!",pProposer->GetName(),pTarget->GetName());
		g_DPCoreClient.SendSystem( szString );
	}
	else
	{
		if( IsValidObj( pTarget ) )
			pTarget->AddDefinedText( nResult );
	}
}
コード例 #12
0
void CGameSocket::RecvZoneChange(Packet & pkt)
{
	uint16 uid = pkt.read<uint16>();
	uint8 byZoneNumber = pkt.read<uint8>();

	CUser* pUser = g_pMain->GetUserPtr(uid);
	if (pUser == nullptr)	
		return;

	pUser->m_pMap = g_pMain->GetZoneByID(byZoneNumber);
	pUser->m_bZone = byZoneNumber;

	TRACE("**** RecvZoneChange -- user(%s, %d), cur_zone = %d\n", pUser->GetName().c_str(), pUser->GetID(), byZoneNumber);
}
コード例 #13
0
ファイル: GameSocket.cpp プロジェクト: ZeusAFK/KOServer-1
void CGameSocket::RecvUserInfo(Packet & pkt)
{
	CUser *pUser = new CUser();
	pUser->Initialize();

	pkt >> pUser->m_iUserId;
	ReadUserInfo(pkt, pUser);

	if (pUser->GetName().empty() || pUser->GetName().length() > MAX_ID_SIZE)
	{
		delete pUser;
		return;
	}

	pUser->m_pMap = g_pMain->GetZoneByID(pUser->m_bZone);
	pUser->m_bLive = AI_USER_LIVE;

	TRACE("****  RecvUserInfo()---> uid = %d, name=%s ******\n", 
		pUser->GetID(), pUser->GetName().c_str());

	if (!g_pMain->SetUserPtr(pUser->GetID(), pUser))
		delete pUser;
}
コード例 #14
0
void CGameSocket::RecvUserRegene(Packet & pkt)
{
	uint16 uid, sHP;
	pkt >> uid >> sHP;

	CUser* pUser = g_pMain->GetUserPtr(uid);
	if(pUser == nullptr)	
		return;

	pUser->m_bLive = AI_USER_LIVE;
	pUser->m_sHP = sHP;

	TRACE("**** RecvUserRegene -- uid = (%s,%d), HP = %d\n", pUser->GetName().c_str(), pUser->GetID(), pUser->m_sHP);
}
コード例 #15
0
FriendAddResult CDBAgent::AddFriend(short sid, short tid)
{
	CUser *pSrcUser = g_pMain->GetUserPtr(sid), *pTargetUser = g_pMain->GetUserPtr(tid);
	if (pSrcUser == NULL || pTargetUser == NULL)
		return FRIEND_ADD_ERROR;

	auto_ptr<OdbcCommand> dbCommand(m_GameDB.CreateCommand());
	if (dbCommand.get() == NULL)
		return FRIEND_ADD_ERROR;

	int16 nRet = (int16)FRIEND_ADD_ERROR;

	dbCommand->AddParameter(SQL_PARAM_INPUT, pSrcUser->GetName(), strlen(pSrcUser->GetName()));
	dbCommand->AddParameter(SQL_PARAM_INPUT, pTargetUser->GetName(), strlen(pTargetUser->GetName()));
	dbCommand->AddParameter(SQL_PARAM_OUTPUT, &nRet);

	if (!dbCommand->Execute(_T("{CALL INSERT_FRIEND_LIST(?, ?, ?)}")))
		ReportSQLError(m_GameDB.GetError());

	if (nRet < 0 || nRet >= FRIEND_ADD_MAX)
		nRet = FRIEND_ADD_ERROR;
		
	return (FriendAddResult)nRet;
}
コード例 #16
0
ファイル: AISocket.cpp プロジェクト: MaKaVeLy/snoxd-koserver
void CAISocket::RecvUserFail(Packet & pkt)
{
	short nid, sid;
	pkt >> nid >> sid;
	CUser* pUser = g_pMain->GetUserPtr(nid);
	if (pUser == NULL)
		return;

	// wtf is this I don't even
	pUser->HpChange(-10000, NULL, false);

	Packet result(WIZ_ATTACK, uint8(1));
	result << uint8(2) << sid << nid;
	pUser->SendToRegion(&result);

	TRACE("### AISocket - RecvUserFail : sid=%d, tid=%d, id=%s ####\n", sid, nid, pUser->GetName());
}
コード例 #17
0
ファイル: couplehelper.cpp プロジェクト: iceberry/flyffsf
void CCoupleHelper::OnProposeResult( CAr & ar )
{
	u_long idProposer, idTarget;
	int nResult;
	time_t t;
	ar >> idProposer >> idTarget >> nResult >> t;
	election::OutputDebugString( "S: CCoupleHelper.OnProposeResult: %d, %d, %d, %d", idProposer, idTarget, nResult, t );

	CUser* pProposer	= static_cast<CUser*>( prj.GetUserByID( idProposer ) );
	if( !IsValidObj( pProposer ) )
		return;

	if( nResult == 0 )
	{
		CUser* pTarget	= static_cast<CUser*>( prj.GetUserByID( idTarget ) );
		if( IsValidObj( pTarget ) )
		{
			pTarget->SetProposer( idProposer );
			CString propose = m_Propose[pProposer->m_idPlayer];
			pTarget->AddProposeResult( idProposer, pProposer->GetName(), propose);
			m_Propose.erase(pProposer->m_idPlayer);
			PlayProposeAnimation( pProposer, pTarget );
		}
		const char* pszTarget	= CPlayerDataCenter::GetInstance()->GetPlayerString( idTarget );	
		if( !pszTarget )
			pszTarget	= "";
		pProposer->AddDefinedText( TID_GAME_COUPLE_S01, "%s", pszTarget );	// %s님에게 프러포즈 하였습니다.
	}
	else
	{
		if( t > 0 )
		{
			CTimeSpan ts( t );
			char szText[200]	= { 0,};
			// 프러포즈는 %d일 %d시간 %d분 후에 사용 가능합니다.
			sprintf( szText, prj.GetText( TID_GAME_COUPLE_M00 ), static_cast<int>( ts.GetDays() ), ts.GetHours(), ts.GetMinutes() );
			pProposer->AddText( szText );
		}
		else
			pProposer->AddDefinedText( nResult );
	}
}
コード例 #18
0
// function CChatRoom::Kill
//  Destroys the current chat room by sending boot messages to everyone
void CChatRoom::Kill()
{
	// set mutex here
	Pthread_mutex_lock(&m_InsideUsersMutex, __FUNCTION__);
	m_bActive = false;

	list<int>::iterator iter = m_UsersInside.begin();
	char buff[5];
	char* temp = buff;
	*temp = PACK_BOOTFROMCHAT;
	temp++;
	(*(int*)temp) = this->m_ChatID;
	Pthread_mutex_lock(&CUser::m_UserMutex, __FUNCTION__);
	while ( iter != m_UsersInside.end() )
	{
		CUser* pUser = CUser::GetUser(*iter);
		if ( pUser != NULL )
		{
			CLog::Record("Sending PACK_BOOTFROMCHAT to %s", pUser->GetName());
			pUser->SendTo(buff, sizeof(buff));
		}
		iter++;
	}

	map<int, CUser*>::iterator iter2 = CUser::m_Users.begin();
	buff[0] = PACK_CHATDESTROYED;

	while ( iter2 != CUser::m_Users.end() )
	{
		CLog::Record("Sending PACKCHATDESTROYED to %s", iter2->second->GetName());
		iter2->second->SendTo(buff, sizeof(buff));
		iter2++;
	}
	Pthread_mutex_unlock(&CUser::m_UserMutex, __FUNCTION__);
	m_UsersInside.empty();
	Pthread_mutex_unlock(&m_InsideUsersMutex, __FUNCTION__);
}
コード例 #19
0
// function CChatRoom::Join
//  Joins a user to this chatroom
bool CChatRoom::Join(int user)
{
	if ( !m_bActive )
	{
		CLog::Error("Could not join chat room - Chat not intialized", __FUNCTION__);
		return false;
	}
	Pthread_mutex_lock(&CUser::m_UserMutex, __FUNCTION__);
	CUser* currUser = CUser::GetUser(user);
	if ( currUser == 0 )
	{
		CLog::Error("User id %d not found", __FUNCTION__, user);
		Pthread_mutex_unlock(&CUser::m_UserMutex, __FUNCTION__);
		return false;
	}
	Pthread_mutex_lock(&m_InsideUsersMutex, __FUNCTION__);

	// the only time this is a linear search is when someone logs in and logs out

	list<int>::iterator iter = m_UsersInside.begin();

	while ( iter != m_UsersInside.end() )
	{
		if ( *iter == user )
		{
			// if user is already in the chat room, refuse entry
			CLog::Record("Failed to login to chat room %s - %d already in there", GetName().c_str(), *iter );
			Pthread_mutex_unlock(&m_InsideUsersMutex, __FUNCTION__);
			Pthread_mutex_unlock(&CUser::m_UserMutex, __FUNCTION__);
			return false;
		}
		iter++;
	}
/*
	//	size_t BufferSize = 9 + (MAXNAME+7)*users, namelen;
	if ( m_sName.length() >= MAXCHATNAMELEN )
		namelen = MAXCHATNAMELEN;
	else
		namelen = m_sName.length()+1;
//	BufferSize += namelen;
*/
//	char* LoggedInBuffer = new char[BufferSize];
	size_t users = m_UsersInside.size();

	char LoggedInBuffer[9];
	char* temp = LoggedInBuffer;
	*temp = PACK_JOINCHAT;
	temp++;
	*(int*)temp = this->m_ChatID;
	temp += 4;
	*(int*)temp = (int)users;
	temp += 4;

	currUser->SendTo(LoggedInBuffer, 9);

	vector<int> toKick;
	char CurrUserData[MAXNAME+MAXCLAN+9];
	temp = CurrUserData;
	*temp = PACK_USERENTERCHAT;
	temp++;
	*(int*)temp = this->m_ChatID;
	temp += sizeof(int);
	*(int*)temp = currUser->GetId();
	temp += sizeof(int);
	strncpy(temp, currUser->GetName(), MAXNAME);
	temp += MAXNAME;
	strncpy(temp, currUser->GetClan(), MAXCLAN);
	
	for ( iter = m_UsersInside.begin(); iter != m_UsersInside.end(); iter++ )
	{
		char UserData[MAXNAME+MAXCLAN+4];
		temp = UserData;
		CUser* currUser2 = CUser::GetUser(*iter);
		// this really shouldnt happen either, we checked for it earlier
		if ( *iter == user ) //|| currUser == 0 )
		{
			Pthread_mutex_unlock(&CUser::m_UserMutex, __FUNCTION__);
			Pthread_mutex_unlock(&m_InsideUsersMutex, __FUNCTION__);
			return false;
		}
		// this shouldn't happen, but if we come across a user with a null pointer, we kick him/her from the room
		if ( currUser2 == 0 )
		{
			//**** Send a boot message to everyone in the chatroom
			toKick.push_back(*iter);
			m_UsersInside.erase(iter);
			continue;
		}
		CLog::Record("Sending PACK_USERENTERCHAT to %s", currUser2->GetName());
		currUser2->SendTo(CurrUserData, MAXNAME+MAXCLAN+9);
		*(int*)temp = currUser2->GetId();
		temp += sizeof(int);
		strncpy(temp, currUser2->GetName(), MAXNAME);
		temp += MAXNAME;
		// in here goes the clan
		strncpy(temp, currUser2->GetClan(), MAXCLAN);
		temp += MAXCLAN;
		currUser->SendTo(UserData, MAXNAME+MAXCLAN+4);
	}
	m_UsersInside.push_back(user);
	Pthread_mutex_unlock(&m_InsideUsersMutex, __FUNCTION__);

//	currUser->SendTo(LoggedInBuffer, BufferSize);
	Pthread_mutex_unlock(&CUser::m_UserMutex, __FUNCTION__);

	if ( toKick.size() > 0 )
		Kicked(toKick);
	
//	delete[] LoggedInBuffer;
//	LoggedInBuffer = 0;

	return true;
}
コード例 #20
0
bool CGameSocket::SetUid(float x, float z, int id, int speed)
{
	int x1 = (int)x / TILE_SIZE;
	int z1 = (int)z / TILE_SIZE;
	int nRX = (int)x / VIEW_DIST;
	int nRZ = (int)z / VIEW_DIST;

	CUser* pUser = g_pMain->GetUserPtr(id);
	if(pUser == nullptr) 
	{
		TRACE("#### User등록 실패 sid = %d ####\n", id);
		return false;
	}

	MAP* pMap = pUser->GetMap();
	if (pMap == nullptr)
	{
		TRACE("#### User not in valid zone, sid = %d ####\n", id);
		return false;
	}
	
	if(x1 < 0 || z1 < 0 || x1 >= pMap->GetMapSize() || z1 >= pMap->GetMapSize())
	{
		TRACE("#### GameSocket ,, SetUid Fail : [nid=%d, name=%s], x1=%d, z1=%d #####\n", id, pUser->GetName().c_str(), x1, z1);
		return false;
	}
	if(nRX > pMap->GetXRegionMax() || nRZ > pMap->GetZRegionMax())
	{
		TRACE("#### GameSocket , SetUid Fail : [nid=%d, name=%s], nRX=%d, nRZ=%d #####\n", id, pUser->GetName().c_str(), nRX, nRZ);
		return false;
	}

	// if(pMap->m_pMap[x1][z1].m_sEvent == 0) return false;

	if (pUser != nullptr)
	{
		if (pUser->m_bLive == AI_USER_DEAD || pUser->m_sHP <= 0)
			return false;
		
		///// attack ~ 
		if( speed != 0 )	{
			pUser->m_curx = pUser->m_fWill_x;
			pUser->m_curz = pUser->m_fWill_z;
			pUser->m_fWill_x = x;
			pUser->m_fWill_z = z;
		}
		else	{
			pUser->m_curx = pUser->m_fWill_x = x;
			pUser->m_curz = pUser->m_fWill_z = z;
		}
		/////~ attack 

		if(pUser->m_sRegionX != nRX || pUser->m_sRegionZ != nRZ)
		{
			pMap->RegionUserRemove(pUser->m_sRegionX, pUser->m_sRegionZ, id);
			pUser->m_sRegionX = nRX;		pUser->m_sRegionZ = nRZ;
			pMap->RegionUserAdd(pUser->m_sRegionX, pUser->m_sRegionZ, id);
		}
	}

	// dungeon work
	int room = pMap->IsRoomCheck( x, z );

	return true;
}
コード例 #21
0
void CGameSocket::RecvUserInOut(Packet & pkt)
{
	std::string strUserID;
	uint8 bType;
	uint16 uid;
	float fX, fZ;
	pkt.SByte();
	pkt >> bType >> uid >> strUserID >> fX >> fZ;
	if (fX < 0 || fZ < 0)
	{
		TRACE("Error:: RecvUserInOut(),, uid = %d, fX=%.2f, fZ=%.2f\n", uid, fX, fZ);
		return;
	}

	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 = nullptr;
	CUser* pUser = g_pMain->GetUserPtr(uid);

	if(pUser != nullptr)
	{
	//	TRACE("##### Fail : ^^& RecvUserInOut() [name = %s]. state=%d, hp=%d\n", pUser->GetName().c_str(), pUser->m_bLive, pUser->m_sHP);
		
		if(pUser->m_bLive == AI_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->GetName().c_str(), 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->GetName().c_str(), pUser->m_bLive, pUser->m_sHP, fX, fZ);
				// 죽은 유저이므로 게임서버에 죽은 처리를 한다...
				//Send_UserError(uid);
				//return;
			}
		}

		pMap = pUser->GetMap();

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

		if(x1 < 0 || z1 < 0 || x1 >= pMap->GetMapSize() || z1 >= pMap->GetMapSize())
		{
			TRACE("#### RecvUserInOut Fail : [name=%s], x1=%d, z1=%d #####\n", pUser->GetName().c_str(), region_x, region_z);
			return;
		}

		//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->GetName().c_str(), region_x, region_z);
			return;
		}

		pUser->m_curx = pUser->m_fWill_x = fX;
		pUser->m_curz = pUser->m_fWill_z = fZ;

		// leaving a region
		if (bType == 2)	
		{
			pMap->RegionUserRemove(region_x, region_z, uid);
		}
		// entering a region
		else 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);
		}
	}
}
コード例 #22
0
ファイル: SettingsDlg.cpp プロジェクト: yy16313blasting/PSMS
void CSettingsDlg::SetUser(CUser user)
{
	m_user.SetName(user.GetName());
}
コード例 #23
0
ファイル: GameSocket.cpp プロジェクト: ZeusAFK/KOServer-1
void CGameSocket::RecvUserInOut(Packet & pkt)
{
	std::string strUserID;
	uint8 bType;
	uint16 uid;
	float fX, fZ;
	pkt.SByte();
	pkt >> bType >> uid >> strUserID >> fX >> fZ;
	if (fX < 0 || fZ < 0)
	{
		TRACE("Error:: RecvUserInOut(),, uid = %d, fX=%.2f, fZ=%.2f\n", uid, fX, fZ);
		return;
	}

	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;

	MAP* pMap = nullptr;
	CUser* pUser = g_pMain->GetUserPtr(uid);
	if (pUser == nullptr)
		return;

	pMap = pUser->GetMap();
	if (pMap == nullptr)
	{
		TRACE("#### Fail : pMap == nullptr ####\n");
		return;
	}

	if (x1 < 0 || z1 < 0 || x1 >= pMap->GetMapSize() || z1 >= pMap->GetMapSize())
	{
		TRACE("#### RecvUserInOut Fail : [name=%s], x1=%d, z1=%d #####\n", pUser->GetName().c_str(), region_x, region_z);
		return;
	}

	//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->GetName().c_str(), region_x, region_z);
		return;
	}

	pUser->m_curx = pUser->m_fWill_x = fX;
	pUser->m_curz = pUser->m_fWill_z = fZ;

	// leaving a region
	if (bType == 2)	
	{
		pMap->RegionUserRemove(region_x, region_z, uid);
	}
	// entering a region
	else 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);
	}
}
コード例 #24
0
ファイル: AttackHandler.cpp プロジェクト: 66gs/snoxd-koserver
void CUser::Attack(Packet & pkt)
{
    Packet result;
    int16 sid = -1, tid = -1, damage, delaytime, distance;
    uint8 bType, bResult;

    CUser* pTUser = NULL;

    pkt >> bType >> bResult >> tid >> delaytime >> distance;

//	delaytime = delaytime / 100.0f;
//	distance = distance / 10.0f;

    if (isBlinking()
            || isDead())
        return;

    // If you're holding a weapon, do a client-based (ugh, do not trust!) delay check.
    _ITEM_TABLE *pTable = GetItemPrototype(RIGHTHAND);
    if (pTable != NULL)
    {
        if (delaytime < pTable->m_sDelay
                || distance > pTable->m_sRange)
            return;
    }
    // Empty handed.
    else if (delaytime < 100)
        return;

    // We're attacking a player...
    if (tid < MAX_USER)
    {
        pTUser = g_pMain->GetUserPtr(tid);

        if (pTUser == NULL || pTUser->isDead() || pTUser->isBlinking()
                || (pTUser->GetNation() == GetNation() && GetZoneID() != 48 /* TO-DO: implement better checks */)
                || !isAttackZone())
            bResult = 0;
        else
        {
            damage = GetDamage(pTUser, NULL);
            if (GetZoneID() == ZONE_SNOW_BATTLE && g_pMain->m_byBattleOpen == SNOW_BATTLE)
                damage = 0;

            if (damage <= 0)
                bResult = 0;
            else
            {
                // TO-DO: Move all this redundant code into appropriate event-based methods so that all the other cases don't have to copypasta (and forget stuff).
                pTUser->HpChange(-damage, this);
                if (pTUser->isDead())
                    bResult = 2;

                ItemWoreOut(ATTACK, damage);
                pTUser->ItemWoreOut(DEFENCE, damage);
                SendTargetHP(0, tid, -damage);
            }
        }
    }
    // We're attacking an NPC...
    else if (tid >= NPC_BAND)
    {
        // AI hasn't loaded yet
        if (g_pMain->m_bPointCheckFlag == false)
            return;

        CNpc *pNpc = g_pMain->m_arNpcArray.GetData(tid);
        if (pNpc != NULL && pNpc->isAlive()
                && (pNpc->GetNation() == 0
                    || pNpc->GetNation() != GetNation()))
        {
            result.SetOpcode(AG_ATTACK_REQ);
            result	<< bType << bResult
                    << GetSocketID() << tid
                    << uint16(m_sTotalHit * m_bAttackAmount / 100)
                    << uint16(m_sTotalAc + m_sACAmount)
                    << m_sTotalHitrate /* this is actually a float. screwed up naming... */
                    << m_sTotalEvasionrate /* also a float */
                    << m_sItemAc
                    << m_bMagicTypeLeftHand << m_bMagicTypeRightHand
                    << m_sMagicAmountLeftHand << m_sMagicAmountRightHand;
            Send_AIServer(&result);
            return;
        }
    }

    result.SetOpcode(WIZ_ATTACK);
    result << bType << bResult << GetSocketID() << tid;
    SendToRegion(&result);

    if (tid < NPC_BAND
            && bResult == 2 // 2 means a player died.
            && pTUser)
    {
        pTUser->Send(&result);
        TRACE("*** User Attack Dead, id=%s, result=%d, type=%d, HP=%d\n", pTUser->GetName(), bResult, pTUser->m_bResHpType, pTUser->m_sHp);
    }
}
コード例 #25
0
ファイル: GuildCombat1to1.cpp プロジェクト: iceberry/flyffsf
// 현재 대전의 경기 시작과 결과를 대전장의 모든 유저에게 전달
void	CGuildCombat1to1::SendWarResultAllPlayer()
{
	CUser* pUser = NULL;
	for( int i=0; i<2; i++ )
	{
		for( int j=0; j<(int)( m_vecTenderGuild[m_nIndex[i]].vecMemberId.size() ); j++ )
		{
			pUser = (CUser*)prj.GetUserByID( m_vecTenderGuild[m_nIndex[i]].vecMemberId[j] );
			if( IsPossibleUser( pUser ) )
			{
				u_long uIdPlayer = NULL_ID;
				if( (int)( m_vecTenderGuild[m_nIndex[i]].vecMemberId.size() ) > m_nProgWarCount	)
					uIdPlayer = m_vecTenderGuild[m_nIndex[i]].vecMemberId[m_nProgWarCount];
				//else
				//	continue;

				switch( m_nState )
				{
					case GC1TO1WAR_WAR :	// 경기 시작시
					{
						pUser->AddGC1to1WarResult( g_GuildCombat1to1Mng.GC1TO1_PLAYER_WAR, uIdPlayer, 0, 0 );
						break;
					}

					case GC1TO1WAR_FINISH :		// 경기 종료시
					{
						int nOurWinCount = m_vecTenderGuild[m_nIndex[i]].nWinCount;
						int nOtherWinCount = m_vecTenderGuild[m_nIndex[(i+1)%2]].nWinCount;
						
						pUser->AddGC1to1WarResult( m_vecTenderGuild[m_nIndex[i]].nLastWinState, uIdPlayer, nOurWinCount, nOtherWinCount );
						
						// 전체 메세지 출력
						int nIndex = 2;	// 비겼을 때 
						if( m_vecTenderGuild[m_nIndex[0]].nLastWinState == g_GuildCombat1to1Mng.GC1TO1_PLAYER_WIN )
							nIndex = 0; // 0길드가 승리했을 때
						else if( m_vecTenderGuild[m_nIndex[1]].nLastWinState == g_GuildCombat1to1Mng.GC1TO1_PLAYER_WIN )
							nIndex = 1;	// 1길드가 승리했을 때
						
						// 대전장의 모든 선수에게 메세지 출력	
						if( nIndex == 2 ) // 비겼을 때
							pUser->AddDefinedCaption( TRUE, TID_GAME_GUILDCOMBAT1TO1_DRAWMSG, "%d", m_nProgWarCount+1 );
						else
						{
							CUser* pWinUser = NULL;
							if( (int)( m_vecTenderGuild[m_nIndex[nIndex]].vecMemberId.size() ) > m_nProgWarCount	)								
								pWinUser = (CUser*)prj.GetUserByID( m_vecTenderGuild[m_nIndex[nIndex]].vecMemberId[m_nProgWarCount] );
							if( IsValidObj( pWinUser ) )
							{
								CGuild* pGuild = pWinUser->GetGuild();
								if( pGuild )
									pUser->AddDefinedCaption( TRUE, TID_GAME_GUILDCOMBAT1TO1_WINMSG, "%d %s %s", m_nProgWarCount+1, pGuild->m_szGuild, pWinUser->GetName() );
							}
						}
						break;
					}
				} // switch
			} // if
		} // for j
	} // for i
}
コード例 #26
0
ファイル: EditDlg.cpp プロジェクト: yy16313blasting/PSMS
void CEditDlg::SetUser(CUser user)
{
	m_user.SetName(user.GetName());
}