Example #1
0
void xrServer::Perform_transfer(NET_Packet &PR, NET_Packet &PT,	CSE_Abstract* what, CSE_Abstract* from, CSE_Abstract* to)
{
	// Sanity check
	R_ASSERT	(what && from && to);
	R_ASSERT	(from != to);
	R_ASSERT	(what->ID_Parent == from->ID);
	u32			time		= Device.dwTimeGlobal;

	// 1. Perform migration if need it
	if (from->owner != to->owner)	PerformMigration(what,from->owner,to->owner);
	//Log						("B");

	// 2. Detach "FROM"
	xr_vector<u16>& C			= from->children;
	xr_vector<u16>::iterator c	= std::find	(C.begin(),C.end(),what->ID);
	R_ASSERT				(C.end()!=c);
	C.erase					(c);
	PR.w_begin				(M_EVENT);
	PR.w_u32				(time);
	PR.w_u16				(GE_OWNERSHIP_REJECT);
	PR.w_u16				(from->ID);
	PR.w_u16				(what->ID);

	// 3. Attach "TO"
	what->ID_Parent			= to->ID;
	to->children.push_back	(what->ID);
	PT.w_begin				(M_EVENT);
	PT.w_u32				(time+1);
	PT.w_u16				(GE_OWNERSHIP_TAKE);
	PT.w_u16				(to->ID);
	PT.w_u16				(what->ID);

}
void xrServer::OnCL_Disconnected	(IClient* CL)
{
	//csPlayers.Enter			();
	
	// Game config (all, info includes deleted player now, excludes at the next cl-update)
	NET_Packet P;
	P.B.count = 0;
	P.w_clientID(CL->ID);
	xrClientData* xrCData = (xrClientData*)(CL);
	VERIFY(xrCData);
	
	if (!xrCData->ps)
		return;

	P.w_stringZ(xrCData->ps->getName());
	P.w_u16(xrCData->ps->GameID);
	P.r_pos = 0;
	
	ClientID clientID;
	clientID.set(0);
	
	game->AddDelayedEvent(P,GAME_EVENT_PLAYER_DISCONNECTED, 0, clientID);
	
	//
	xrS_entities::iterator	I=entities.begin(),E=entities.end();
	if (GetClientsCount()>1 && !CL->flags.bLocal)
	{
		// Migrate entities
		for (; I!=E; ++I)
		{
			CSE_Abstract*	entity		= I->second;
			if (entity->owner == CL)	PerformMigration	(entity,(xrClientData*)CL,SelectBestClientToMigrateTo(entity,TRUE));
		}
	} else {
		// Destroy entities
		while (!entities.empty())		{
			CSE_Abstract*	entity		= entities.begin()->second;
			entity_Destroy	(entity);
		}
	}	
	//csPlayers.Leave			();

	Server_Client_Check(CL);
}