Ejemplo n.º 1
0
/*
*******************************************************************
* Function: 
*
* Description: 
*    
* Parameters: 
*
* Returns: 
*
*******************************************************************
*/
xDistributedSession*ISession::getByUserID(int userID)
{

	if (!getNetInterface())	{		return NULL;	}
	if (!getNetInterface()->getDistributedObjects())return NULL;
	return static_cast<xDistributedSession*>(getNetInterface()->getDistObjectInterface()->getByUserID(userID,E_DC_BTYPE_SESSION));

}
Ejemplo n.º 2
0
/*
*******************************************************************
* Function: 
*
* Description: 
*    
* Parameters: 
*
* Returns: 
*
*******************************************************************
*/
xDistributedSession* ISession::get(xNString name)
{

	if (!getNetInterface())	{		return NULL;	}
	if (!getNetInterface()->getDistributedObjects())return NULL;

	xDistributedObjectsArrayType *distObjects = getNetInterface()->getDistributedObjects();
	return static_cast<xDistributedSession*>(getNetInterface()->getDistObjectInterface()->get(name,E_DC_BTYPE_SESSION));

}
Ejemplo n.º 3
0
/*
*******************************************************************
* Function: 
*
* Description: 
*    
* Parameters: 
*
* Returns: 
*
*******************************************************************
*/
int
ISession::create(xNString name,int maxUsers,xNString password,int type)
{

	int result  = -1 ;

	if (getNetInterface() && getNetInterface()->isValid() && !getNetInterface()->IsServer() )
	{
		vtConnection *con  = getNetInterface()->getConnection();
		con->c2sCreateSession_RPC(name,type,maxUsers,password);
	}

	return result ;

}
Ejemplo n.º 4
0
/*
*******************************************************************
* Function: 
*
* Description: 
*    
* Parameters: 
*
* Returns: 
*
*******************************************************************
*/
void xDistributedSession::onGhostRemove()
{
	xNetInterface *netInterface  = getNetInterface();

	if (getNetInterface())
	{

		if(!getNetInterface()->IsServer())
		{
			xDistributedObjectsArrayType *distObjects = netInterface->getDistributedObjects();
			xDistObjectIt begin = distObjects->begin();
			xDistObjectIt end = distObjects->end();

			while (begin!=end)
			{
				xDistributedObject *distObject  = *begin;
				if (distObject)
				{
					xDistributedClass *_class = distObject->getDistributedClass();
					if (_class)
					{
						if (_class->getEnitityType() == E_DC_BTYPE_CLIENT )
						{
							xDistributedClient *distClient  = static_cast<xDistributedClient*>(distObject);
							if (distClient && distClient->getSessionID() == getSessionID() )
							{
								distClient->setSessionID(-1);
								disableFlag(distClient->getClientFlags(),E_CF_SESSION_JOINED);
								enableFlag(distClient->getClientFlags(),E_CF_DELETING);
								enableFlag(distClient->getClientFlags(),E_CF_SESSION_DESTROYED);

							}
						}
					}
				}
				begin++;
			}
		}
		
		if(getNetInterface()->IsServer())
		{
			xLogger::xLog(XL_START,ELOGINFO,E_LI_SESSION,"Server : Session is going to be deleted : %s",this->GetName().getString());
		}
		
		getNetInterface()->getDistObjectInterface()->removeObject(this);
		
	}
}
Ejemplo n.º 5
0
/*
*******************************************************************
* Function: 
*
* Description: 
*    
* Parameters: 
*
* Returns: 
*
*******************************************************************
*/
void ISession::unlockSession(int userID,int sessionID)
{

	xNetInterface *netInterface = getNetInterface();

	if ( netInterface && !netInterface->IsServer() && netInterface->isValid())
	{
		xDistributedSession *session  = get(sessionID);
		if ( session)
		{

			if (session->getUserID() != userID)
			{
				xLogger::xLog(XL_START,ELOGERROR,E_LI_SESSION,"User %d must be session master !",userID);
				return;
			}
			
			int sessionLocked = 0;
			xDistributedInteger *pLocked= (xDistributedInteger *)session->getProperty(E_DC_S_NP_LOCKED);
			pLocked->updateValue(sessionLocked,0);
			pLocked->setFlags(E_DP_NEEDS_SEND);
			return ;
		}
	}
}
Ejemplo n.º 6
0
/*
*******************************************************************
* Function: 
*
* Description: 
*    
* Parameters: 
*
* Returns: 
*
*******************************************************************
*/
void xDistributedSession::performScopeQuery(TNL::GhostConnection *connection)
{
	xNetInterface *netInterface  = getNetInterface();
	if (!netInterface)
	{
		return;
	}
	xDistributedObjectsArrayType *distObjects = netInterface->getDistributedObjects();
	if (!distObjects)
	{ 
		return;
	}
	
	xDistObjectIt begin = distObjects->begin();
	xDistObjectIt end = distObjects->end();

	while (begin != end)
	{
		xDistributedObject*dobject = *begin;
		if (dobject)
		{	
			connection->objectInScope((TNL::NetObject*) dobject );
		}
		begin++;
	}
}
Ejemplo n.º 7
0
/*
*******************************************************************
* Function: 
*
* Description: 
*    
* Parameters: 
*
* Returns: 
*
*******************************************************************
*/
xDistributedSession*ISession::get(int sessionID)
{

	if (!getNetInterface())	{		return NULL;	}
	if (!getNetInterface()->getDistributedObjects())return NULL;

	xDistributedObjectsArrayType *distObjects = getNetInterface()->getDistributedObjects();
	xDistObjectIt begin = distObjects->begin();
	xDistObjectIt end = distObjects->end();
	while (begin!=end)
	{
		xDistributedObject* dobj = *begin;
		if (dobj  && dobj->getDistributedClass() && dobj->getDistributedClass()->getEnitityType() == E_DC_BTYPE_SESSION )
		{
			xDistributedSession *session  = static_cast<xDistributedSession*>(dobj);
			if (session && session->getSessionID()  == sessionID)
				return session;
		}
		begin++;
	}
	return NULL;

}
Ejemplo n.º 8
0
void ISession::deleteSession(int sessionID)
{
	xNetInterface *netInterface = getNetInterface();
	if ( netInterface && netInterface->IsServer())
	{
		xDistributedSession *session  = get(sessionID);
		if (session)
		{

			IDistributedObjects *doInterface  = netInterface->getDistObjectInterface();
			xDistributedObjectsArrayType *distObjects = netInterface->getDistributedObjects();
			xDistObjectIt begin = distObjects->begin();
			xDistObjectIt end = distObjects->end();

			while (begin!=end)
			{
				xDistributedObject *distObject  = *begin;
				if (distObject)
				{
					xDistributedClass *_class = distObject->getDistributedClass();
					if (_class)
					{
						if (_class->getEnitityType() == E_DC_BTYPE_CLIENT )
						{
							xDistributedClient *distClient  = static_cast<xDistributedClient*>(distObject);
							if (distClient && distClient->getSessionID() == sessionID )
							{
								distClient->setSessionID(-1);
								disableFlag(distClient->getClientFlags(),E_CF_SESSION_JOINED);

							}
						}
					}
				}
				begin++;
			}
		
			doInterface->deleteObject((xDistributedObject*)session);

		}else
			xLogger::xLog(XL_START,ELOGERROR,E_LI_SESSION,"couldn't find session %d",sessionID);
	}
}
Ejemplo n.º 9
0
/*
*******************************************************************
* Function: 
*
* Description: 
*    
* Parameters: 
*
* Returns: 
*
*******************************************************************
*/
int ISession::joinClient(xDistributedClient*client, int sessionID,xNString password)
{

	xNetInterface *netInterface = getNetInterface();
	
	if (netInterface && !netInterface->IsServer() && netInterface->isValid())
	{
		xDistributedSession *session  = get(sessionID);
		if (session)
		{
			vtConnection *con  = netInterface->getConnection();
			if ( con)
			{
				con->c2sJoinSession_RPC(client->getUserID(),sessionID,password);
				return 0;
			}
		}
	}
	return -1;
}
Ejemplo n.º 10
0
/*
*******************************************************************
* Function: 
*
* Description: 
*    
* Parameters: 
*
* Returns: 
*
*******************************************************************
*/
int ISession::removeClient(xDistributedClient*client,int sessionID,bool destroy/* =false */)
{

	xNetInterface *netInterface = getNetInterface();
	if (client && netInterface && !netInterface->IsServer() && netInterface->isValid())
	{
		vtConnection *con  = netInterface->getConnection();
		xDistributedSession *session  = get(sessionID);
		xDistributedClient *myClient  = netInterface->getMyClient();
		if ( con && session && myClient )
		{

			if (session->getUserID() !=myClient->getUserID() && myClient->getUserID()!=client->getUserID() )
			{
				xLogger::xLog(XL_START,ELOGERROR,E_LI_SESSION,"You must be session master to remove a client !");
				return -1;
			}

			xLogger::xLog(XL_START,ELOGINFO,E_LI_SESSION,"Removing user :%d from session %d",client->getUserID(),sessionID);
			//////////////////////////////////////////////////////////////////////////
			con->c2sLeaveSession_RPC(client->getUserID(),sessionID,destroy);
			client->getClientFlags().set(1 << E_CF_DELETING,true);
			client->getClientFlags().set(1 << E_CF_DELETED,false);
		}
	}else 
	{
		return -1;
	}

	//////////////////////////////////////////////////////////////////////////
	//its our self who leaves the session
	//we must remove all other clients from the dist array : 
	xDistributedClient *myClient  = netInterface->getMyClient();
	if (myClient && myClient->getUserID() == client->getUserID() && netInterface->getCurrentSession() )
	{

	
		IDistributedObjects *doInterface  = netInterface->getDistObjectInterface();
		xDistributedObjectsArrayType *distObjects = netInterface->getDistributedObjects();
		xDistObjectIt begin = distObjects->begin();
		xDistObjectIt end = distObjects->end();

		while (begin!=end)
		{
			xDistributedObject *distObject  = *begin;
			if (distObject)
			{
				xDistributedClass *_class = distObject->getDistributedClass();
				if (_class)
				{
					if (_class->getEnitityType() == E_DC_BTYPE_CLIENT )
					{
						xDistributedClient *distClient  = static_cast<xDistributedClient*>(distObject);
						if (distClient)
						{
							if (distClient->getUserID()  != myClient->getUserID() &&
								distClient->getSessionID()==sessionID )
							{
								distClient->getClientFlags().set(1 << E_CF_DELETING,true);
								distClient->getClientFlags().set(1 << E_CF_DELETED,false);
							}
						}
					}
				}
			}
			begin++;
		}
	}

	return 0;
}
Ejemplo n.º 11
0
/*
*******************************************************************
* Function: 
*
* Description: 
*    
* Parameters: 
*
* Returns: 
*
*******************************************************************
*/
void xDistributedSession::removeUser(xDistributedClient *client)
{
	xNetInterface *nInterface = getNetInterface();
	if (!nInterface)
	{
		return;
	}


	xDistributedClient *myClient  = nInterface->getMyClient();
	if (client && myClient && client->getUserID() == myClient->getUserID())
	{
		myClient->setSessionID(-1);
	}

	if (client)
	{
		if (isClientJoined(client->getUserID()))
		{

			//////////////////////////////////////////////////////////////////////////
			if (client->getUserID() == getUserID())
			{
				xLogger::xLog(XL_START,ELOGINFO,E_LI_SESSION,"Session master %d left session %d",client->getUserID(),getSessionID());
				
				if (nInterface)
				{

					//////////////////////////////////////////////////////////////////////////
					//we tag all existing users as new : 
					
					IDistributedObjects *doInterface  = nInterface->getDistObjectInterface();
					xDistributedObjectsArrayType *distObjects = nInterface->getDistributedObjects();
					xDistObjectIt begin = distObjects->begin();
					xDistObjectIt end = distObjects->end();

					while (begin!=end)
					{
						xDistributedObject *distObject  = *begin;
						if (distObject)
						{
							xDistributedClass *_class = distObject->getDistributedClass();
							if (_class)
							{
								if (_class->getEnitityType() == E_DC_BTYPE_CLIENT )
								{
									xDistributedClient *distClient  = static_cast<xDistributedClient*>(distObject);
									if (distClient && isClientJoined(distClient->getUserID()))
									{
										if (isFlagOn(distClient->getClientFlags(),E_CF_SESSION_JOINED))
										{

											//distClient->setSessionID(-1);
											disableFlag(distClient->getClientFlags(),E_CF_SESSION_JOINED);
											enableFlag(distClient->getClientFlags(),E_CF_DELETING);
											enableFlag(distClient->getClientFlags(),E_CF_SESSION_DESTROYED);
											xLogger::xLogExtro(0,"\tRemoving user %d from session",distClient->getUserID(),getSessionID());
										}
									}
								}
							}
						}
						begin++;
					}

					getClientTable().clear();
					goto ENDUPDATE;
					return;
				}
			}
		}
		if (client->getUserID() != getUserID())
		{
			enableFlag(client->getClientFlags(),E_CF_REMOVED);
			client->setSessionID(-1);
		}
		//////////////////////////////////////////////////////////////////////////
		for(int i = 0 ; i < getClientTable().size() ; i++)
		{

			std::vector<xDistributedClient*>::iterator begin = getClientTable().begin();
			std::vector<xDistributedClient*>::iterator end = getClientTable().end();
			while (begin !=end)
			{
				xDistributedClient *current = *begin;
				if (current && current->getUserID()  == client->getUserID() )
				{
                    getClientTable().erase(begin);						
				}
				begin++;
			}
		}

		goto ENDUPDATE;

		ENDUPDATE :
		xDistributedInteger *numUser= (xDistributedInteger *)getProperty(E_DC_S_NP_NUM_USERS);
		numUser->updateValue(getClientTable().size(),0);
		setNumUsers(getClientTable().size());
		int blockIndex = numUser->getBlockIndex();
		getUpdateBits().set(1<<blockIndex,true);
		setMaskBits(1<<blockIndex);
	}else
		xLogger::xLog(XL_START,ELOGERROR,E_LI_SESSION,"couldn't find client object");

	
	
}