Beispiel #1
0
void QxtRPCServicePrivate::clientConnected(QIODevice* dev, quint64 id)
{
    // QxtMetaObject::bind() is a nice piece of magic that allows parameters to a slot to be defined in the connection.
    QxtMetaObject::connect(dev, SIGNAL(readyRead()),
                           QxtMetaObject::bind(this, SLOT(clientData(quint64)), Q_ARG(quint64, id)));

    // Inform other objects that a new client has connected.
    emit qxt_p().clientConnected(id);

    // Initialize a new buffer for this connection.
    buffers[id] = QByteArray();

    // If there's any unread data in the device, go ahead and process it up front.
    if(dev->bytesAvailable() > 0)
        clientData(id);
}
Beispiel #2
0
void SpawnSoldiersMapElementSystem::Update( double DeltaTime )
{
    MapElementSystem::Update( DeltaTime );
    MapElementListFilter<MapSystem::All> mapElementListFilter( mMapSystem->GetMapElementList(), SpawnSoldiersMapElement::GetType_static() );
    for( MapElementListFilter<MapSystem::All>::const_iterator spawnSoldiersMapElementIt = mapElementListFilter.begin(), spawnSoldiersMapElementE = mapElementListFilter.end(); spawnSoldiersMapElementIt != spawnSoldiersMapElementE; ++spawnSoldiersMapElementIt )
    {
        Opt<SpawnSoldiersMapElement> spawnSoldiersMapElement( *spawnSoldiersMapElementIt );
        if ( spawnSoldiersMapElement->GetValueId( SpawnSoldiersMapElement::SpawnNodeId() ) > 0 )
        {
            if ( mProgramState.mMode == core::ProgramState::Server )
            {
                Opt<engine::SoldierSpawnSystem> soldierSpawnS( engine::SoldierSpawnSystem::Get() );
                for ( core::ProgramState::ClientDatas_t::iterator i = mProgramState.mClientDatas.begin(), e = mProgramState.mClientDatas.end(); i != e; ++i )
                {
                    std::auto_ptr<Actor> player( soldierSpawnS->Spawn( *i ) );

                    mScene.AddActor( player.release() );
                }
            }
            else if ( mProgramState.mMode == core::ProgramState::Local )
            {
                Opt<core::ClientData> clientData( mProgramState.FindClientDataByClientId( mProgramState.mClientId ) );
                if ( clientData.IsValid() )
                {
                    L2( "spawning local player" );
                    clientData->mClientActorGUID = -1;
                    std::auto_ptr<Actor> Pl( engine::SoldierSpawnSystem::Get()->Spawn( *clientData ) );
                    Opt<PlayerControllerComponent>playerCC(Pl->Get<IControllerComponent>());
                    playerCC->SetEnabled( true );
                    playerCC->mActive = true;
                    // TODO: positionC?
                    auto positionC=(Pl->Get<IPositionComponent>());
                    mScene.SetPlayerModels( Opt<Actor>( Pl.get() ) );
                    mProgramState.mControlledActorGUID = clientData->mClientActorGUID;
                    mScene.AddActor( Pl.release() );
                }
            }
            L1( "spawn soldiers!" );
        }
        spawnSoldiersMapElement->ResetValues();
    }
}
bool SetOwnershipMessageHandlerSubSystem::ProcessPending( Message const& message )
{
    SetOwnershipMessage const& msg = static_cast<SetOwnershipMessage const&>( message );
    Opt<Actor> actor = mScene.GetActor( msg.mActorGUID ); //guaranteed
    L1( "executing %s: actorGUID %d \n", __FUNCTION__, msg.mActorGUID );
    Opt<PlayerControllerComponent> playerControllerC( actor->Get<IControllerComponent>() );
    if ( !playerControllerC.IsValid() )
    {
        L1( "setownership is called on an actor that is not playerControllable \n" );
        return true;
    }

    playerControllerC->mControllerId = msg.mClientId;

    if ( msg.mClientId == mProgramState.mClientId )
    {
        L1( "thats my id! actorguid: %d,%d \n", msg.mActorGUID, PlayerControllerComponent::GetType_static() );
        Opt<Actor> oldActor = mScene.GetActor( mProgramState.mControlledActorGUID );
        if ( oldActor.IsValid() )
        {
            Opt<PlayerControllerComponent> pcc = oldActor->Get<IControllerComponent>();
            if( pcc.IsValid() )
            {
                pcc->SetEnabled( false );
                pcc->mActive = false;
            }
        }
        mProgramState.mControlledActorGUID = msg.mActorGUID;
        playerControllerC->SetEnabled( true );
        playerControllerC->mActive = true;
        mScene.SetPlayerModels( actor );
    }
    Opt<core::ClientData> clientData( mProgramState.FindClientDataByClientId( msg.mClientId ) );
    if ( clientData.IsValid() )
    {
        clientData->mClientActorGUID = msg.mActorGUID;
    }
    return true;
}
Beispiel #4
0
void *ProxyPlugin::processEvent(Event *e)
{
    if (e->type() == EventSocketConnect){
        ConnectParam *p = (ConnectParam*)(e->param());
        list<Proxy*>::iterator it;
        for (it = proxies.begin(); it != proxies.end(); ++it){
            if ((*it)->notify == p->socket)
                return NULL;
        }
        ProxyData data;
        clientData(p->client, data);
        Proxy *proxy = NULL;
        switch (data.Type.value){
        case PROXY_SOCKS4:
            proxy = new SOCKS4_Proxy(this, &data, p->client);
            break;
        case PROXY_SOCKS5:
            proxy = new SOCKS5_Proxy(this, &data, p->client);
            break;
        case PROXY_HTTPS:
            if (p->client == (TCPClient*)(-1)){
                proxy = new HTTP_Proxy(this, &data, p->client);
            }else{
                proxy = new HTTPS_Proxy(this, &data, p->client);
            }
            break;
        }
        if (proxy){
            proxy->setSocket(p->socket);
            return e->param();
        }
    }
    if (e->type() == EventSocketListen){
        ListenParam *p = (ListenParam*)(e->param());
        ProxyData data;
        clientData(p->client, data);
        Listener *listener = NULL;
        switch (data.Type.value){
        case PROXY_SOCKS4:
            listener = new SOCKS4_Listener(this, &data, p->notify, p->client->ip());
            break;
        case PROXY_SOCKS5:
            listener = new SOCKS5_Listener(this, &data, p->notify, p->client->ip());
            break;
        }
        if (listener)
            return e->param();
    }
    if (e->type() == EventRaiseWindow){
        QWidget *w = (QWidget*)(e->param());
        if (!w->inherits("NewProtocol"))
            return NULL;
        NewProtocol *p = static_cast<NewProtocol*>(w);
        if (p->m_client->protocol()->description()->flags & PROTOCOL_NOPROXY)
            return NULL;
        ProxyConfig *cfg = static_cast<ProxyConfig*>(findObject(w, "ProxyConfig"));
        if (cfg)
            return NULL;
        QTabWidget *tab  = static_cast<QTabWidget*>(findObject(w, "QTabWidget"));
        if (tab){
            cfg = new ProxyConfig(tab, this, tab, p->m_client);
            QObject::connect(tab->topLevelWidget(), SIGNAL(apply()), cfg, SLOT(apply()));
        }
    }
    if (e->type() == EventClientError){
        clientErrorData *data = (clientErrorData*)(e->param());
        if (data->code == ProxyErr){
            QString msg = i18n(data->err_str);
            if (data->err_str && *data->err_str){
                if (data->args){
                    msg = msg.arg(QString::fromUtf8(data->args));
                    free(data->args);
                }
            }
            ProxyError *err = new ProxyError(this, static_cast<TCPClient*>(data->client), msg);
            raiseWindow(err);
            return e->param();
        }
    }
    return NULL;
}
void ControllerAdapterSystem::Update(double DeltaTime)
{
    Opt<InputSystem> inputsys = InputSystem::Get();
    if( !inputsys.IsValid() )
    {
        return;
    }

    // collect controlled players by controller id
    std::map<int32_t, Opt<Actor> > controlledPlayers;
    static core::ProgramState& ps =  core::ProgramState::Get();
    Opt<Actor> actor( mScene.GetActor( ps.mControlledActorGUID ) );
    Opt<core::ClientData> clientData( ps.FindClientDataByActorGUID( ps.mControlledActorGUID ) );
    if( clientData.IsValid() && actor.IsValid() )
    {
        controlledPlayers[ clientData->mControlledLocalPlayerId ] = actor;
    }

    for( auto joy : getJoysticks() )
    {
        // get keymapping for joy name @ joy pos ( if custom, support per-slot mapping )
        ControllerState cs( joy );
        if( !cs.isValid() )
        {
            continue;
        }

        if( mCalibrate )
        {
            std::cout << "Joy " << joy << "\n";
            std::cout << "\tname: '" << cs.name << "'\n";
            std::cout << "\taxes: \n";
            int cnt = 0;
            for( auto const& a : cs.axes )
            {
                std::cout << "\t\ta" << cnt++ << " " << a << "\n";
            }
            std::cout << "\tbuttons: \n";
            cnt = 0;
            for( auto const& b : cs.buttons )
            {
                std::cout << "\t\tb" << cnt++ << " " << b << "\n";
            }
        }

        // get controlled player for joy
        int32_t controlledLocalPlayerId = 1;
        static input::PlayerControlDevice& pcd( input::PlayerControlDevice::Get() );
        if( pcd.GetControlDevice( controlledLocalPlayerId ) != input::PlayerControlDevice::Controller ||
            pcd.GetControllerIndex( controlledLocalPlayerId ) != joy )
        {
            continue;
        }

        // get InputState for player
        InputState is = inputsys->GetInputState( controlledLocalPlayerId );

        // fill inputstate for player
        is.mShoot = cs.getBool( "shoot" );
        is.mShootAlt = cs.getBool( "shoot_alt" );
        is.mUseNormalItem = cs.getBool( "use_normal" );
        is.mReload = cs.getBool( "reload" );
        is.mShowLeaderboard = cs.getBool( "show_leaderboard" );
        is.mPause = cs.getBool( "pause" );
        double vh = cs.getDouble( "view_horizontal" ), vv = cs.getDouble( "view_vertical" );
        static Settings& settings( Settings::Get() );
        static double const viewNullZone = settings.GetDouble( "controllers.view_null_zone", 0.4 );
        if( std::abs( vv ) >= viewNullZone || std::abs( vh ) >= viewNullZone )
        {
            is.mOrientation = atan2( vv, vh );
        }
        Opt<Actor> actor = controlledPlayers[ controlledLocalPlayerId ];
        if( actor.IsValid() )
        {
            Opt<IPositionComponent> actorPositionC = actor->Get<IPositionComponent>();
            static double const radius = settings.GetDouble( "controllers.cursor_radius", 400 );
            is.mCursorX = actorPositionC->GetX() + radius * cos( is.mOrientation );
            is.mCursorY = actorPositionC->GetY() + radius * sin( is.mOrientation );
        }
        double mh = cs.getDouble( "move_horizontal" ), mv = cs.getDouble( "move_vertical" );
        is.mHeading = atan2( mv, mh );
        static double const moveNullZone = settings.GetDouble( "controllers.move_null_zone", 0.2 );
        is.mMoving = std::abs( mv ) >= moveNullZone || std::abs( mh ) >= moveNullZone;
        inputsys->SetInputState( controlledLocalPlayerId, is );
        // TODO fill generic input state ( ui )
    }
}