#include "serverconnectionfactory.hpp" #include "global.hpp" #include "serverentry.hpp" #include "serverconnectiondirect.hpp" #include "serverconnectiontcp.hpp" #include "serverconnectiontcpudp.hpp" ServerConnection* ServerConnectionFactory::openConnection( ServerEntry& server ) { ServerConnection* connection = 0; switch ( server.type ) { case ServerEntry::DIRECT: { LOG( 2 ) INFO( "ClientCommunicator::openConnection: opening connection to local server\n" ); DirectServerEntry& directEntry = static_cast( server ); ServerConnectionDirect* directConnection = new ServerConnectionDirect( directEntry.server ); connection = directConnection; // m_clientID = directConnection->openConnection(); break; } case ServerEntry::REMOTE: LOG( 2 ) INFO( "ClientCommunicator::openConnection: opening connection to remote server\n" ); RemoteServerEntry& remoteEntry = static_cast( server ); // First try a TCP/UDP connection ServerConnectionTCPUDP* tcpudpConnection = new ServerConnectionTCPUDP( remoteEntry ); // check if connection was successful if ( !tcpudpConnection->openConnection() ) { delete tcpudpConnection; return 0; } if ( !tcpudpConnection->checkUdpConnection() ) { // fall back to pure TCP communication ServerConnectionTCP* tcpConnection = tcpudpConnection->createServerConnectionTCP(); delete tcpudpConnection; connection = tcpConnection; } else connection = tcpudpConnection; break; } return connection; }