I'm having troubles reading a file, i looked into other codes but can't seem to find the answer.
It should check if the player's steamid is in the file on disconnect , and replace that line with a new one, or add a line when he's not in the file.
The problem is that it crashes my game when i disconnect.
PHP Code:
#pragma semicolon 1
#include <amxmodx>
#include <amxmisc>
#define VERSION "1.0"
new file[128];
new currentmap[64];
public plugin_init()
{
register_plugin("Player's time logger", VERSION, "Drekes");
// Start the log file.
new currentdate[15];
get_time("%d", currentdate, charsmax(currentdate));
new dir[64];
get_datadir(dir, charsmax(dir));
format(dir, charsmax(dir), "%s/timelogs", dir);
if(!dir_exists(dir))
mkdir(dir);
formatex(file, charsmax(file), "%s/log-%s.ini", dir, currentdate);
get_mapname(currentmap, charsmax(currentmap));
new mapchangeline[128];
formatex(mapchangeline, charsmax(mapchangeline), "*-- Mapchange to %s --*", currentmap);
write_file(file, mapchangeline);
}
public client_disconnect(id)
{
new playtime = get_user_time(id) / 60;
new authid[35];
get_user_authid(id, authid, charsmax(authid));
new data[128], filepos;
new fileid[35], filetime[20];
new writefile = fopen(file, "rw");
if(writefile)
{
while(!feof(writefile))
{
fgets(writefile, data, charsmax(data));
filepos++;
if(data[0] == '*')
continue;
parse(data, fileid, charsmax(fileid), filetime, charsmax(filetime));
if(equali(authid, fileid))
{
new filetimenum = str_to_num(filetime);
new writetime = playtime + filetimenum;
formatex(data, charsmax(data), "%s %i", authid, writetime);
break;
}
formatex(data, charsmax(data), "%s %i", authid, playtime);
}
write_file(file, data);
}
fclose(writefile);
}
__________________