Example #1
0
void 
NetClient::onGroupPrepare( MessagePtr m )
{
	K_ASSERT( m_groupId == 0 );
	K_ASSERT( m_selfTag == 0 );

	m_groupId = 0;
	m_selfTag = 0;

	NmGroupPrepare* gp = static_cast<NmGroupPrepare*>( m.Get() );

	TcpConnection* c = m_tcp.FindById( gp->remote );

	if ( c == 0 )
	{
		LOG( FT_WARN, 
			 _T("NetClient::onGroupPrepare> Connection %d not found"), 
			 gp->remote );

		return;
	}
	
	m_udp.Fini();

	m_groupId = gp->groupId;
	m_selfTag = gp->connectionId;

	// init udp with c as a relay connection 
	// use same ip:port as TCP connection
	bool rc = m_udp.Init( this, 
						  &m_ios, 
						  c->GetSocket()->GetAddress(), 
						  m_selfTag, 
						  gp->sl, 
						  gp->challenge, 
						  c );

	if ( !rc )
	{
		LOG( FT_WARN, _T("NetClient::onGroupPrepare> Failed to init udp") );

		return;
	}

	NmGroupPrepared* p = new NmGroupPrepared;

	p->remote 		= gp->remote;
	p->groupId 		= gp->groupId;
	p->connectionId = gp->connectionId;
	p->in 			= c->GetSocket()->GetAddress();

	m_tcp.Send( m->remote, MessagePtr( p ) );

	LOG( FT_DEBUG, _T("NetClient::onGroupPrepare> Prepared group %d connection %d"), 
		 gp->groupId, 
		 gp->connectionId );
}
Example #2
0
void
NetServer::onJoinUdpGroup( const NetGroupOp& op )
{
	NetGroupMap::iterator i = m_groups.find( op.groupId );

	if ( i == m_groups.end() )
	{
		LOG( FT_WARN, _T("NetServer::onJoinUdpGroup> %d not found"), op.groupId );

		// TODO: error report

		return;
	}

	TcpConnection* c = m_tcp.FindById( op.connectionId );

	if ( c == 0 )
	{
		LOG( FT_WARN, 
			 _T("NetServer::onJoinUdpGroup> Connection %d not found"), 
			 op.connectionId );

		return;
	}

	NetGroup* group = i->second;
	K_ASSERT( group != 0 );

	c->SetGroup( op.groupId );

	(void)group->Join( op.connectionId, c->GetSocket()->GetPeerAddress(), op.extra );

	LOG( FT_DEBUG, 
		 _T("NetServer::onJoinUdpGroup> %d joined to %d"), 
		 op.connectionId, group->GetId() );
}