예제 #1
0
void SessionServer::OnHandshakeComplete(const XSocketPtr& newConnection, SocketID socketID, HandshakeResult result)
{
    if (newConnection && result == HandshakeResult::Success)
	{
		Client newClient;

		newClient.m_connection = new NetworkConnectionImpl(m_messagePool);
		newClient.m_connection->SetSocket(newConnection);

		// Begin to listen for SessionControl messages from this connection.
		newClient.m_connection->AddListener(MessageID::SessionControl, this);
		newClient.m_receipt = CreateRegistrationReceipt(newClient.m_connection, &NetworkConnectionImpl::RemoveListener, MessageID::SessionControl, this);

		// Keep a reference to this connection so that it stays open.
		m_clients.push_back(newClient);

#if defined(MSTEST)
		m_broadcaster->AddConnection(newClient.m_connection);
#endif
	}
    else
    {
        LogInfo("ListServer: Handshake failed with error %u", result);
    }
	
	XTVERIFY(m_pendingConnections.erase(socketID));
}
예제 #2
0
ReceiptPtr XSocketImpl::RegisterListener(XSocketListener* listener)
{
	XTASSERT(m_listener == NULL);
	m_listener = listener;

	return CreateRegistrationReceipt(XSocketImplPtr(this), &XSocketImpl::UnregisterListener, listener);
}
예제 #3
0
void XSessionImpl::AddConnection(const XSocketPtr& socket)
{
	NetworkConnectionImplPtr netConnection = new NetworkConnectionImpl(m_messagePool);
	netConnection->SetSocket(socket);

	RemoteClientPtr remoteClient = new RemoteClient(netConnection);

	// Register for callbacks with the SessionStatus id
	remoteClient->m_primaryConnection->AddListener(MessageID::SessionControl, this);
	remoteClient->m_listenerReceipt = CreateRegistrationReceipt(remoteClient->m_primaryConnection, &NetworkConnection::RemoveListener, MessageID::SessionControl, this);

	// Add it to the pending list until we receive the a join request message from it
	m_pendingClients.push_back(remoteClient);
}
bool SyncManagerImpl::RegisterListener(SyncListener* listener)
{
	if (listener)
	{
		// If we do not already have a listener...
		if (!m_listener)
		{
			// If the listener is not already registered...
			if (!listener->IsRegistered())
			{
				m_listener = listener;
				RegistrationReceiptPtr receipt = CreateRegistrationReceipt(SyncManagerImplPtr(this), &SyncManagerImpl::UnregisterListener, listener);
				m_listener->AddRegistration(receipt, receipt->GetKey());
				return true;
			}
			else
			{
				LogError("Trying to register a listener that has already been registered");
				return false;
			}
		}
		else
		{
			if (m_listener == listener)
			{
				LogWarning("SyncListener registration failed because the given listener is already registered");
			}
			else
			{
				LogWarning("SyncListener registration failed because another listener is already registered");
			}

			return false;
		}
	}
	else
	{
		LogError("Trying to register a NULL pointer");
		return false;
	}
}
void SyncManagerImpl::AddConnection(const NetworkConnectionPtr& newConnection)
{
#if defined(SYNC_DEBUG)
	LogInfo("%s Adding Connection", m_syncContext->GetLocalUser()->GetName().GetString().c_str());
#endif

	newConnection->AddListener(m_messageID, this);

	m_remoteHosts.resize(m_remoteHosts.size() + 1, RemoteSyncPeer());

	RemoteSyncPeer& newPeer = m_remoteHosts.back();
	newPeer.m_connection = newConnection;

	// Automatically remove this object as a listener when newPeer is destroyed
	newPeer.m_listenerReceipt = CreateRegistrationReceipt(newConnection, &NetworkConnection::RemoveListener, m_messageID, this);

	if (newConnection->IsConnected())
	{
		SendHandshakeMessage(newPeer);
	}
}
예제 #6
0
ReceiptPtr XSessionImpl::RegisterCallback(SessionChangeCallback* cb)
{
	byte messageType = 0;
	m_callback = cb; // there is only one of these (for now)
	return CreateRegistrationReceipt(XSessionImplPtr(this), &XSessionImpl::UnregisterCallback, messageType);
}