コード例 #1
0
void PintoManager::handleClientReceived(Sirikata::Network::Stream* stream, Chunk& data, const Network::Stream::PauseReceiveCallback& pause) {
    Sirikata::Protocol::MasterPinto::PintoMessage msg;
    bool parsed = parsePBJMessage(&msg, data);

    if (!parsed) {
        PINTO_LOG(error, "Couldn't parse message from client.");
        return;
    }

    ClientData& cdata = mClients[stream];

    if (msg.has_server()) {
        PINTO_LOG(debug, "Associated connection with space server " << msg.server().server());
        cdata.server = msg.server().server();

        TimedMotionVector3f default_loc( Time::null(), MotionVector3f( Vector3f::zero(), Vector3f::zero() ) );
        BoundingSphere3f default_region(BoundingSphere3f::null());
        float32 default_max = 0.f;
        SolidAngle default_min_angle(SolidAngle::Max);
        // FIXME max_results

        mLocCache->addSpaceServer(cdata.server, default_loc, default_region, default_max);

        Query* query = mQueryHandler->registerQuery(default_loc, default_region, default_max, default_min_angle);
        cdata.query = query;
        mClientsByQuery[query] = stream;
        query->setEventListener(this);
    }
    else {
        if (cdata.server == NullServerID) {
            PINTO_LOG(error, "Received initial message from client without a ServerID.");
            stream->close();
            mClients.erase(stream);
            return;
        }
    }

    if (msg.has_region()) {
        PINTO_LOG(debug, "Received region update from " << cdata.server << ": " << msg.region().bounds());
        mLocCache->updateSpaceServerRegion(cdata.server, msg.region().bounds());
        cdata.query->region( msg.region().bounds() );
    }

    if (msg.has_largest()) {
        PINTO_LOG(debug, "Received largest object update from " << cdata.server << ": " << msg.largest().radius());
        mLocCache->updateSpaceServerMaxSize(cdata.server, msg.largest().radius());
        cdata.query->maxSize( msg.largest().radius() );
    }

    if (msg.has_query()) {
        PINTO_LOG(debug, "Received query update from " << cdata.server << ": " << msg.query().min_angle());
        cdata.query->angle( SolidAngle(msg.query().min_angle()) );
        // FIXME max results
    }

    tick();
}
コード例 #2
0
void PintoManagerBase::handleClientReceived(Sirikata::Network::Stream* stream, Chunk& data, const Network::Stream::PauseReceiveCallback& pause) {
    Sirikata::Protocol::MasterPinto::PintoMessage msg;
    bool parsed = parsePBJMessage(&msg, data);

    if (!parsed) {
        PINTO_LOG(error, "Couldn't parse message from client.");
        return;
    }

    if (msg.has_server()) {
        PINTO_LOG(debug, "Associated connection with space server " << msg.server().server());
        mStreamServers[stream] = msg.server().server();

        TimedMotionVector3f default_loc( Time::null(), MotionVector3f( Vector3f::zero(), Vector3f::zero() ) );
        BoundingSphere3f default_region(BoundingSphere3f::null());
        float32 default_max = 0.f;
        mLocCache->addSpaceServer(msg.server().server(), default_loc, default_region, default_max);
        onInitialMessage(stream);
    }

    ServerID server = streamServerID(stream);
    if (server == NullServerID) {
        PINTO_LOG(error, "Received message without ServerID and don't already have one, killing the connection.");
        stream->close();
        onDisconnected(stream);
        return;
    }

    if (msg.has_region()) {
        PINTO_LOG(debug, "Received region update from " << server << ": " << msg.region().bounds());
        mLocCache->updateSpaceServerRegion(server, msg.region().bounds());
        onRegionUpdate(stream, msg.region().bounds());
    }

    if (msg.has_largest()) {
        PINTO_LOG(debug, "Received largest object update from " << server << ": " << msg.largest().radius());
        mLocCache->updateSpaceServerMaxSize(server, msg.largest().radius());
        onMaxSizeUpdate(stream, msg.largest().radius());
    }

    if (msg.has_query()) {
        PINTO_LOG(debug, "Received query update from " << server);
        onQueryUpdate(stream, msg.query());
    }
}