Ejemplo n.º 1
0
void CHostIce::postImage( const ::Types::TByteArray & data, const ::Ice::Current & c )
{
    IceUtil::Mutex::Lock lock( m_mut );
    
    bool sendList = false;
    for( TClientsIter i = m_clients.begin();
         i != m_clients.end();
         i++ )
    {
        Client::CClientPrx & client = i->second.client;
        try
        {
            client->cam()->acceptImage( data, c.ctx );
        }
        catch ( Ice::Exception & )
        {
            sendList = true;
        }
    }

    if ( sendList )
    {
        validateClientList( c );
        sendClientList( c );
    }
}
Ejemplo n.º 2
0
bool CHostIce::queryCtrl( const std::string & id, const ::Ice::Current & c )
{
    IceUtil::Mutex::Lock lock( m_mut );
    QLOG_TRACE() << "queryCtrl( "  << QString::fromStdString( id ) << " )";

    CClientDesc cd;
    if ( !client( id, cd ) )
        return false;
    
    for ( TClientsConstIter i = m_clients.begin();
          i != m_clients.end();
          i++ )
    {
        const CClientDesc & cd = i->second;
        if ( cd.access != TView )
        {
            QLOG_TRACE() << "query refused";
            return false;
        }
    }
    QLOG_TRACE() << "query granted";
    cd.access = TCtrl;
    updateClient( id, cd );
    validateClientList( c );
    sendClientList( c );
    return true;
}
Ejemplo n.º 3
0
void CHostIce::postMessage( const std::string & id, const ::std::string & stri, const ::Ice::Current & c )
{
    IceUtil::Mutex::Lock lock( m_mut );
    
    CClientDesc cd;
    if ( !client( id, cd ) )
        return;
    std::ostringstream msg;
    msg << cd.nickname << ": \'" << stri << "\'";
    QLOG_TRACE() << "postMessage( " << QString::fromUtf8( msg.str().data(), msg.str().size() ) << " )";
    
    bool sendList = false;
    for ( TClientsIter j = m_clients.begin();
          j != m_clients.end();
          j++ )
    {
        Client::CClientPrx client = j->second.client;
        try
        {
            client->chat()->acceptMessage( msg.str() );
        }
        catch ( Ice::Exception & )
        {
            sendList = true;
        }
    }
    if ( sendList )
    {
        validateClientList( c );
        sendClientList( c );
    }
}
Ejemplo n.º 4
0
void CHostIce::removeClient( const std::string & id, const ::Ice::Current & c )
{
    IceUtil::Mutex::Lock lock( m_mut );

    QLOG_TRACE() << "removeClient( " << QString::fromStdString( id ) << " )";
    remClient( id );
    sendClientList( c );
}
Ejemplo n.º 5
0
void Server::textRead(){
    QTcpSocket *source = dynamic_cast<QTcpSocket*>(sender());
    QByteArray data = source->readAll();

    QByteArray namePrefix = "/Name::";
    QByteArray challengePrefix = "/Challenge::";
    QByteArray challengeAcceptedPrefix = "/ChallengeAccepted::";
    QByteArray settingsPrefix = "/Settings::";
    QByteArray startPrefix = "/Start::";
    QByteArray turnPrefix = "/Turn::";
    QByteArray locationPrefix = "/Location::";
    QByteArray multiplayerMatchPrefix = "/MultiplayerMatch::";

    if (data.startsWith(namePrefix)){
        QString tempNick(data);
        QStringRef name(&tempNick, namePrefix.length(), tempNick.length() - namePrefix.length());
        QString validName = isAvailable(name.toString());
        nickContainer->append(validName);
        if (name != validName){
            source->write("/ValidName::" + validName.toLatin1());
        }
        sendClientList();
    } else if (data.startsWith(challengePrefix)){
        QString tempNick(data);
        QStringRef name(&tempNick, challengePrefix.length(), tempNick.length() - challengePrefix.length());
        sendChallenge(source, name);
    } else if (data.startsWith(challengeAcceptedPrefix)){
        QString tempNick(data);
        QStringRef name(&tempNick, challengeAcceptedPrefix.length(), tempNick.length() - challengeAcceptedPrefix.length());
        sendChallengeAccepted(name);
    } else if (data.startsWith(settingsPrefix)){
        QString tempString(data);
        QStringRef values(&tempString, settingsPrefix.length(), tempString.length() - settingsPrefix.length());
        sendSettingsData(values.toString());
    } else if (data.startsWith(startPrefix)){
        QString tempString(data);
        QStringRef values(&tempString, startPrefix.length(), tempString.length() - startPrefix.length());
        sendStartMessage(values);
    } else if (data.startsWith(turnPrefix)){
        QString tempString(data);
        QStringRef name(&tempString, turnPrefix.length(), tempString.length() - turnPrefix.length());
        sendTurnChangeMessage(name);
    } else if (data.startsWith(locationPrefix)){
        QString tempString(data);
        QStringRef values(&tempString, locationPrefix.length(), tempString.length() - locationPrefix.length());
        sendLocationMessage(values);
    } else if (data.startsWith(multiplayerMatchPrefix)){
        QString tempString(data);
        sendPrivateMessage(tempString, multiplayerMatchPrefix);
    } else {
        QTime time = QTime::currentTime();
        QString timeString = time.toString() + " ";
        for (int i = 0; i < clientContainer->size(); ++i){
            clientContainer->at(i)->write(timeString.toLatin1() + data);
        }
    }
}
Ejemplo n.º 6
0
void CHostIce::releaseCtrl( const std::string & id, const ::Ice::Current & c )
{
    IceUtil::Mutex::Lock lock( m_mut );
    QLOG_TRACE() << "releaseCtrl( "  << QString::fromStdString( id ) << " )";
    
    CClientDesc cd;
    if ( !client( id, cd ) )
        return;
    
    cd.access = TView;
    updateClient( id, cd );
    validateClientList( c );
    sendClientList( c );
}
Ejemplo n.º 7
0
bool CHostIce::registerClient( const ::Client::CClientPrx & client, const std::string & nickname, std::string & idOrErrMsg, const ::Ice::Current & c )
{
    IceUtil::Mutex::Lock lock( m_mut );
    QLOG_TRACE() << "registerClient( " << QString::fromUtf8( nickname.data(), nickname.size() ) << " )";
    try
    {
        //client->cam( c.ctx );
        //client->ice_id( c.ctx );

        if ( !nicknameUnique( nickname ) )
        {
            std::ostringstream msg;
            msg << "ERROR: \"" << nickname << "\" is aready in use";
            QLOG_TRACE() << QString::fromUtf8( msg.str().data(), msg.str().size() );
            idOrErrMsg = msg.str();
            return false;
        }
        std::string id = clientId( nickname, client );
        if ( hasClient( id ) )
        {
            std::ostringstream msg;
            msg << "ERROR: your client id is \"" << id << "\", it is aready in use. Failed to add client.";
            QLOG_TRACE() << QString::fromUtf8( msg.str().data(), msg.str().size() );
            idOrErrMsg = msg.str();
            return false;
        }
        QLOG_TRACE() << "Assigned id: " << QString::fromStdString( id );
        CClientDesc cd( nickname, client );
        idOrErrMsg = id;
        addClient( id, cd );
        validateClientList( c );
        sendClientList( c );
        return true;
    }
    catch( const Ice::Exception & ex )
    {
        QLOG_TRACE() << "Exception: " << ex.toString().c_str();
        idOrErrMsg = ex.toString().c_str();
        fprintf(stderr, "%s\n", ex.toString().c_str());
    }
    return false;
}
Ejemplo n.º 8
0
bool CHostIce::querySuper( const std::string & id, const ::std::string & passwd, const ::Ice::Current & c )
{
    IceUtil::Mutex::Lock lock( m_mut );
    QLOG_TRACE() << "querySuper( "  << QString::fromStdString( id ) << " )";
    
    if ( m_owner->m_passwd != passwd )
    {
        QLOG_TRACE() << "wrong password";
        return false;
    }

    CClientDesc cd;
    if ( !client( id, cd ) )
        return false;
    
    bool modified;
    do {
        modified = false;
        for ( TClientsIter i = m_clients.begin();
              i != m_clients.end();
              i++ )
        {
            if ( id != i->first )
            {
                CClientDesc & cd = i->second;
                if ( cd.access != TView )
                {
                    cd.access = TView;
                    modified = true;
                }
            }
        }
    } while ( modified );
    
    QLOG_TRACE() << "super privilegies granted";
    cd.access = TSuper;
    updateClient( id, cd );
    validateClientList( c );
    sendClientList( c );
    return true;
}