/** * Reads GeoIP database and stores it into memory * geoip.cache should be freed after use! * http://dev.maxmind.com/geoip/legacy/geolite/ **/ void geoip_init(void) { int i, fno; char db_type = 1; unsigned char delim[3]; struct stat bufa; FILE *db; geoip.active = true; db = fopen("./db/GeoIP.dat","rb"); if(!db) { ShowError("[GeoDB] - Falha de leitura na base de dados GeoIP!\n"); geoip_final(false); return; } fno = fileno(db); if( fstat(fno, &bufa) < 0 ) { ShowError("[GeoDB] - Falha em determinar tamanho do arquivo!\n"); geoip_final(false); return; } geoip.cache = aMalloc( (sizeof(geoip.cache) * bufa.st_size) ); if( fread(geoip.cache, 1, bufa.st_size, db) != bufa.st_size ) { ShowError("[GeoDB]: Leitura incompleta do arquivo GeoIP!\n"); fclose(db); geoip_final(false); return; } // Search database type fseek(db, -3l, SEEK_END); for( i = 0; i < GEOIP_STRUCTURE_INFO_MAX_SIZE; i++ ) { (void)fread(delim, sizeof(delim[0]), 3, db); //(void) para remover aquele warning chato if( delim[0] == 255 && delim[1] == 255 && delim[2] == 255 ) { fread(&db_type, sizeof(db_type), 1, db); break; } else { fseek(db, -4l, SEEK_CUR); } } fclose(db); if( db_type != 1 ) { if( db_type ) ShowError("[GeoDB] - Arquivo insuportado! (Tipo: %d)\n", db_type); else ShowError("[GeoDB] - Arquivo CORROMPIDO. \n"); geoip_final(false); return; } ShowStatus("Finalizada leitura da base de dados "CL_GREEN"GeoIP"CL_RESET".\n"); }
/** * Reads GeoIP database and stores it into memory * geoip.cache should be freed after use! * http://dev.maxmind.com/geoip/legacy/geolite/ **/ void geoip_init(void) { int i, fno; char db_type = 1; unsigned char delim[3]; struct stat bufa; FILE *db; geoip.active = true; db = fopen("./db/GeoIP.dat","rb"); if( db == NULL ) { ShowError("geoip_readdb: Error reading GeoIP.dat!\n"); geoip_final(false); return; } fno = fileno(db); if( fstat(fno, &bufa) < 0 ) { ShowError("geoip_readdb: Error stating GeoIP.dat! Error %d\n", errno); geoip_final(false); return; } geoip.cache = aMalloc( (sizeof(geoip.cache) * bufa.st_size) ); if( fread(geoip.cache, sizeof(unsigned char), bufa.st_size, db) != bufa.st_size ) { ShowError("geoip_cache: Couldn't read all elements!\n"); fclose(db); geoip_final(false); return; } // Search database type fseek(db, -3l, SEEK_END); for( i = 0; i < GEOIP_STRUCTURE_INFO_MAX_SIZE; i++ ) { fread(delim, sizeof(delim[0]), 3, db); if( delim[0] == 255 && delim[1] == 255 && delim[2] == 255 ) { fread(&db_type, sizeof(db_type), 1, db); break; } else { fseek(db, -4l, SEEK_CUR); } } fclose(db); if( db_type != 1 ) { if( db_type ) ShowError("geoip_init(): Database type is not supported %d!\n", db_type); else ShowError("geoip_init(): GeoIP is corrupted!\n"); geoip_final(false); return; } ShowStatus("Finished Reading "CL_GREEN"GeoIP"CL_RESET" Database.\n"); }
// finalize void inter_final(void) { wis_db->destroy(wis_db, NULL); inter_guild_sql_final(); inter_storage_sql_final(); inter_party_sql_final(); inter_pet_sql_final(); inter_homunculus_sql_final(); inter_mercenary_sql_final(); inter_elemental_sql_final(); inter_mail_sql_final(); inter_auction_sql_final(); geoip_final(true); do_final_msg(); return; }