void parsePlayerUpdateMessage( Client *inC, char *inMessageLine ) {
    SimpleVector<char*> *tokens = tokenizeString( inMessageLine );

    //printf( "\n\nParsing PU line: %s\n\n", inMessageLine );
    
    if( tokens->size() > 16 ) {
        int id = -1;
        sscanf( tokens->getElementDirect(0), "%d", &( id ) );
    
        if( inC->id == -1 ) {
            inC->id = id;
            }
        
        if( inC->id == id ) {
            // update pos
            
            if( inC->moving ) {
                //printf( "Client %d done moving\n", inC->i );
                }
            if( strcmp( tokens->getElementDirect(14), "X" ) == 0 ) {
                // dead
                inC->dead = true;
                printf( "Client %d died with PU message:  %s\n",
                        inC->i, inMessageLine );
                }
            else {
                sscanf( tokens->getElementDirect(14), "%d", &( inC->x ) );
                sscanf( tokens->getElementDirect(15), "%d", &( inC->y ) );
                inC->moving = false;
                }
            }
        }
    
    
    tokens->deallocateStringElements();
    delete tokens;
    }
Exemple #2
0
void saveCategoryToDisk( int inParentID ) {
    CategoryRecord *r = getCategory( inParentID );
    

    if( r == NULL ) {
        return;
        }
    
    File categoriesDir( NULL, "categories" );
            
    if( !categoriesDir.exists() ) {
        categoriesDir.makeDirectory();
        }
    
    if( ! categoriesDir.exists() || ! categoriesDir.isDirectory() ) {

        printf( "Failed to make categories directory\n" );
        
        return;
        }


    
    File *cacheFile = categoriesDir.getChildFile( "cache.fcz" );

    cacheFile->remove();
    
    delete cacheFile;


        
    char *fileName = autoSprintf( "%d.txt", inParentID );


    File *categoryFile = categoriesDir.getChildFile( fileName );

    if( r->objectIDSet.size() == 0 ) {
        // empty category, simply remove it
        
        categoryFile->remove();
        }
    else {
        // resave
    
        SimpleVector<char*> lines;
        
        lines.push_back( autoSprintf( "parentID=%d", inParentID ) );

        if( r->isPattern ) {
            lines.push_back( stringDuplicate( "pattern" ) );
            }
        else if( r->isProbabilitySet ) {
            lines.push_back( stringDuplicate( "probSet" ) );
            }
        
        // start with 0 objects in a new category
        lines.push_back( autoSprintf( "numObjects=%d", 
                                      r->objectIDSet.size() ) );
        
        for( int i=0; i<r->objectIDSet.size(); i++ ) {
            if( r->isProbabilitySet ) {
                lines.push_back( 
                    autoSprintf( "%d %f", 
                                 r->objectIDSet.getElementDirect(i),
                                 r->objectWeights.getElementDirect(i) ) );
                }
            else {
                lines.push_back( 
                    autoSprintf( "%d", r->objectIDSet.getElementDirect(i) ) );
                }
            }
        
        
        char **linesArray = lines.getElementArray();
        
        
        char *contents = join( linesArray, lines.size(), "\n" );
        
        categoryFile->writeToFile( contents );
        
        delete [] contents;

        delete [] linesArray;
        lines.deallocateStringElements();
        }    
    
        
            
    delete [] fileName;
    delete categoryFile;
    
    return;
    }