bool matches (char const* file, SearchStruct* ss) { GameCache* game = &gcache[getGameInfo (file, GC_FLAGS)]; char ftitle[256]; _splitpath (file, NULL, NULL, ftitle, NULL); if (!str_matches (ss->ffunc, ftitle, ss->ftext)) return false; if (!str_matches (ss->nfunc, game->name, ss->ntext)) return false; if (!matchMode (game->mode, ss->mtext, ss->mfunc)) return false; if (game->count < ss->numa || game->count > ss->numb) return false; if (game->map < ss->vera || game->map > ss->verb) return false; if (game->patch < ss->pata || game->patch > ss->patb) return false; if (game->length < ss->lena || game->length > ss->lenb) return false; if (game->mod < ss->sava || game->mod > ss->savb) return false; for (int i = 0; i < 5; i++) { bool found = false; for (int j = 0; j < game->count && !found; j++) { if (str_matches (ss->pmode[i], game->pname[j], ss->pname[i]) && (ss->phero[i] == 0 || ss->phero[i] == game->phero[j])) found = true; } if (!found) return false; } return true; }
static int callback_command( int sckt ) { char buf[8192] = { 0 }; int ok = 1; int n, i; while( ok ) { char *p = NULL; memset( buf, 0, 8192 ); n = read( sckt, buf, 8191 ); if( n < 0 ) { fprintf( stderr, "! daemon: Error reading from socket\n" ); break; } /* Client closed socket */ if( n == 0 ) { close( sckt ); break; } buf[( unsigned int )n] = '\0'; /* extract keyword */ p = strchr( buf, ' ' ); if( p ) { *p++ = '\0'; for( i = 0; *( p + i ) >= 32 && *( p + i ) != '\0'; ++i ); *( p + i ) = '\0'; printf( "cmd[%s] param[%s]\n", buf, p ); } else { printf( "\n--Unknown command--\n" ); continue; } for( i = 0; callbacks[i].keyword != NULL; i++ ) if( str_matches( buf, callbacks[i].keyword ) ) { callbacks[i].call( sckt, p ); break; } } /*while */ close( sckt ); return 0; }