Hello again,
i can´t figure out whats going wrong with the code. I try to read the bans.ban file but the function reads the main form captions and label captions :guilty: could it be that i made a mistake with a pointer?
i can´t figure out whats going wrong with the code. I try to read the bans.ban file but the function reads the main form captions and label captions :guilty: could it be that i made a mistake with a pointer?
//---------------Header File
#ifndef __int64
#define __int64 long long
#endif
#ifndef LFS_BAN_VER
#define LFS_BAN_VER 246
#endif
struct demo_ban
{
struct in_addr ip_address;
__int64 time;
long _pad;
};
//----
struct name_ban
{
char username[24];
__int64 time;
int banhours;
int _pad;
};
//----
struct core
{
char id[7]; // null terminated string LFSBAN\0
unsigned char version;
int Demobans;
struct demo_ban *demo;
int Namebans;
struct name_ban *name;
};
//-----------------------------------Function
struct core bancore;
FILE *file = NULL;
long fsize;
int i;
memset(&bancore, 0, sizeof(core));
file = fopen("F:\\Arbeitsordner\\LFS-Remote Manager\\data\\misc\\bans.ban", "rb");
if (file != NULL)
{
fseek(file , 0 , SEEK_END);
fsize = ftell(file);
rewind(file);
// minimum size for a ban
if (fsize >= 16)
{
fread((void *)&bancore.id, 7, 1, file);
bancore.id[6] = '\0';
// read ban file version
fread((void *)&bancore.version, 1, 1, file);
// read number of bans
fread((void *)&bancore.demo, 4, 1, file);
// Check the num_demo bans is > 0
if (bancore.demo > 0)
{
// get memory to store the bans
bancore.demo = (struct demo_ban *) malloc(sizeof(struct demo_ban) * bancore.Demobans);
// read demo bans
fread((void *)bancore.demo, bancore.Demobans, sizeof(struct demo_ban), file);
}
// read number of names
fread((void *)&bancore.Namebans, 4, 1, file);
if (bancore.Namebans > 0)
{
// get memory to store the names
bancore.name = (struct name_ban *) malloc(sizeof(struct name_ban) * bancore.Namebans);
// read name bans
fread((void *)bancore.name, bancore.Namebans, sizeof(struct name_ban), file);
}
for(i = 0; i < bancore.Namebans; i++)
{
Memo2->Lines->Add(bancore.name[i].username);
}
}
}
free(bancore.demo);
free(bancore.name);
fclose(file);